-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4670bbe
commit 3fe2043
Showing
18 changed files
with
582 additions
and
261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ continuation_indent_width: 1 | |
use_tab: true | ||
tab_width: 4 | ||
chop_down_table: true | ||
column_limit: 100 | ||
column_limit: 90 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
function onLogout(player) | ||
local playerId = player:getId() | ||
if nextUseStaminaTime[playerId] then nextUseStaminaTime[playerId] = nil end | ||
nextUseStaminaTime[playerId] = nil | ||
return true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,97 @@ | ||
local deathListEnabled = true | ||
local maxDeathRecords = 5 | ||
local playerDeathQuery = | ||
"INSERT INTO `player_deaths` (`player_id`, `time`, `level`, `killed_by`, `is_player`, `mostdamage_by`, `mostdamage_is_player`, `unjustified`, `mostdamage_unjustified`) VALUES (%d, %d, %d, %s, %d, %s, %d, %d, %d)" | ||
|
||
local format = string.format | ||
|
||
---@param killer Creature | ||
---@return boolean, string | ||
local function getKiller(killer) | ||
if not killer then return false, "field item" end | ||
|
||
if killer:isPlayer() then return true, killer:getName() end | ||
|
||
local master = killer:getMaster() | ||
if master and master ~= killer and master:isPlayer() then | ||
return true, master:getName() | ||
end | ||
if master and master ~= killer and master:isPlayer() then return true, master:getName() end | ||
|
||
return false, killer:getName() | ||
end | ||
|
||
function onDeath(player, corpse, killer, mostDamageKiller, lastHitUnjustified, | ||
mostDamageUnjustified) | ||
local playerId = player:getId() | ||
if nextUseStaminaTime[playerId] then nextUseStaminaTime[playerId] = nil end | ||
|
||
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You are dead.") | ||
if not deathListEnabled then return end | ||
|
||
local byPlayer, killerName = getKiller(killer) | ||
local byPlayerMostDamage, killerNameMostDamage = getKiller(mostDamageKiller) | ||
|
||
local playerGuid = player:getGuid() | ||
db.query( | ||
"INSERT INTO `player_deaths` (`player_id`, `time`, `level`, `killed_by`, `is_player`, `mostdamage_by`, `mostdamage_is_player`, `unjustified`, `mostdamage_unjustified`) VALUES (" .. | ||
playerGuid .. ", " .. os.time() .. ", " .. player:getLevel() .. ", " .. | ||
db.escapeString(killerName) .. ", " .. (byPlayer and 1 or 0) .. ", " .. | ||
db.escapeString(killerNameMostDamage) .. ", " .. | ||
(byPlayerMostDamage and 1 or 0) .. ", " .. (lastHitUnjustified and 1 or 0) .. | ||
", " .. (mostDamageUnjustified and 1 or 0) .. ")") | ||
local resultId = db.storeQuery( | ||
"SELECT `player_id` FROM `player_deaths` WHERE `player_id` = " .. | ||
playerGuid) | ||
---@param playerId integer | ||
---@param playerName string | ||
---@param killerId integer | ||
---@param playerGuid integer | ||
---@param byPlayer boolean | ||
---@param killerName string | ||
---@param playerGuildId integer | ||
---@param killerGuildId integer | ||
---@param timeNow integer | ||
---@return nil | ||
local function playerDeathSuccess(playerId, playerName, killerId, playerGuid, byPlayer, killerName, playerGuildId, killerGuildId, | ||
timeNow) | ||
local resultId = db.storeQuery("SELECT `player_id` FROM `player_deaths` WHERE `player_id` = " .. playerGuid) | ||
if not resultId then return end | ||
|
||
local deathRecords = 0 | ||
local tmpResultId = resultId | ||
while tmpResultId ~= false do | ||
local tmpResultId = true | ||
while tmpResultId do | ||
tmpResultId = result.next(resultId) | ||
deathRecords = deathRecords + 1 | ||
end | ||
|
||
if resultId ~= false then result.free(resultId) end | ||
result.free(resultId) | ||
|
||
local limit = deathRecords - maxDeathRecords | ||
if limit > 0 then | ||
db.asyncQuery( | ||
"DELETE FROM `player_deaths` WHERE `player_id` = " .. playerGuid .. | ||
" ORDER BY `time` LIMIT " .. limit) | ||
db.asyncQuery(format("DELETE FROM `player_deaths` WHERE `player_id` = %d ORDER BY `time` LIMIT %d", playerGuid, limit)) | ||
end | ||
|
||
if byPlayer then | ||
local targetGuild = player:getGuild() | ||
targetGuild = targetGuild and targetGuild:getId() or 0 | ||
if targetGuild ~= 0 then | ||
local killerGuild = killer:getGuild() | ||
killerGuild = killerGuild and killerGuild:getId() or 0 | ||
if killerGuild ~= 0 and targetGuild ~= killerGuild and | ||
isInWar(playerId, killer:getId()) then | ||
local warId = false | ||
resultId = db.storeQuery( | ||
"SELECT `id` FROM `guild_wars` WHERE `status` = 1 AND ((`guild1` = " .. | ||
killerGuild .. " AND `guild2` = " .. targetGuild .. | ||
") OR (`guild1` = " .. targetGuild .. " AND `guild2` = " .. | ||
killerGuild .. "))") | ||
if resultId ~= false then | ||
if playerGuildId ~= 0 then | ||
if killerGuildId ~= 0 and playerGuildId ~= killerGuildId and isInWar(playerId, killerId) then | ||
resultId = db.storeQuery(format( | ||
"SELECT `id` FROM `guild_wars` WHERE `status` = 1 AND ((`guild1` = %d AND `guild2` = %d) OR (`guild1` = %d AND `guild2` = %d))", | ||
killerGuildId, playerGuildId, playerGuildId, killerGuildId)) | ||
|
||
local warId = nil | ||
if resultId then | ||
warId = result.getNumber(resultId, "id") | ||
result.free(resultId) | ||
end | ||
|
||
if warId ~= false then | ||
db.asyncQuery( | ||
"INSERT INTO `guildwar_kills` (`killer`, `target`, `killerguild`, `targetguild`, `time`, `warid`) VALUES (" .. | ||
db.escapeString(killerName) .. ", " .. db.escapeString(player:getName()) .. | ||
", " .. killerGuild .. ", " .. targetGuild .. ", " .. os.time() .. ", " .. | ||
warId .. ")") | ||
if warId then | ||
db.asyncQuery(format( | ||
"INSERT INTO `guildwar_kills` (`killer`, `target`, `killerguild`, `targetguild`, `time`, `warid`) VALUES (%s, %s, %d, %d, %d, %d)", | ||
db.escapeString(killerName), db.escapeString(playerName), killerGuildId, playerGuildId, timeNow, warId)) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
function onDeath(player, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified) | ||
local playerId = player:getId() | ||
nextUseStaminaTime[playerId] = nil | ||
|
||
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You are dead.") | ||
if not deathListEnabled then return end | ||
|
||
local timeNow = os.time() | ||
local byPlayer, killerName = getKiller(killer) | ||
local byPlayerMostDamage, killerNameMostDamage = getKiller(mostDamageKiller) | ||
local playerGuid = player:getGuid() | ||
local playerName = player:getName() | ||
local playerGuild = player:getGuild() | ||
local playerGuildId = playerGuild and playerGuild:getId() or 0 | ||
local killerGuild = byPlayer and killer:getGuild() or nil | ||
local killerGuildId = killerGuild and killerGuild:getId() or 0 | ||
local killerId = byPlayer and killer:getId() or 0 | ||
db.asyncQuery(format(playerDeathQuery, playerGuid, timeNow, player:getLevel(), db.escapeString(killerName), byPlayer and 1 or 0, | ||
db.escapeString(killerNameMostDamage), byPlayerMostDamage and 1 or 0, lastHitUnjustified and 1 or 0, | ||
mostDamageUnjustified and 1 or 0), function(success) | ||
if success then | ||
playerDeathSuccess(playerId, playerName, killerId, playerGuid, byPlayer, killerName, playerGuildId, killerGuildId, timeNow) | ||
end | ||
end) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.