Skip to content

Commit

Permalink
Lua code format - (Stylua)
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Nov 13, 2024
1 parent 4591bbb commit 2094b04
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions data/scripts/creaturescripts/player/death.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ end

local function saveDeathRecord(playerGuid, player, killerName, byPlayer, mostDamageName, byPlayerMostDamage, unjustified, mostDamageUnjustified)
local query = string.format(
"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)",
"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)",
playerGuid,
os.time(),
player:getLevel(),
Expand Down Expand Up @@ -96,10 +95,7 @@ local function getDeathRecords(playerGuid)
end

local function checkForGuildWar(targetGuildId, killerGuildId)
local resultId = db.storeQuery(string.format(
"SELECT `id` FROM `guild_wars` WHERE `status` = 1 AND ((`guild1` = %d AND `guild2` = %d) OR (`guild1` = %d AND `guild2` = %d))",
killerGuildId, targetGuildId, targetGuildId, killerGuildId
))
local resultId = db.storeQuery(string.format("SELECT `id` FROM `guild_wars` WHERE `status` = 1 AND ((`guild1` = %d AND `guild2` = %d) OR (`guild1` = %d AND `guild2` = %d))", killerGuildId, targetGuildId, targetGuildId, killerGuildId))

local warId = false
if resultId then
Expand All @@ -112,20 +108,21 @@ end

local function recordGuildWarKill(killer, player, killerGuildId, targetGuildId, warId)
local playerName = player:getName()
db.asyncQuery(string.format(
"INSERT INTO `guildwar_kills` (`killer`, `target`, `killerguild`, `targetguild`, `time`, `warid`) VALUES ('%s', '%s', %d, %d, %d, %d)",
db.escapeString(killer:getName()), db.escapeString(playerName), killerGuildId, targetGuildId, os.time(), warId
))
db.asyncQuery(string.format("INSERT INTO `guildwar_kills` (`killer`, `target`, `killerguild`, `targetguild`, `time`, `warid`) VALUES ('%s', '%s', %d, %d, %d, %d)", db.escapeString(killer:getName()), db.escapeString(playerName), killerGuildId, targetGuildId, os.time(), warId))
end

local function checkAndUpdateGuildWarScore(warId, targetGuildId, killerGuildId, playerName, killerName, mostDamageName)
local resultId = db.storeQuery(string.format(
"SELECT `guild_wars`.`id`, `guild_wars`.`frags_limit`, " ..
"(SELECT COUNT(1) FROM `guildwar_kills` WHERE `guildwar_kills`.`warid` = `guild_wars`.`id` AND `guildwar_kills`.`killerguild` = `guild_wars`.`guild1`) AS guild1_kills, " ..
"(SELECT COUNT(1) FROM `guildwar_kills` WHERE `guildwar_kills`.`warid` = `guild_wars`.`id` AND `guildwar_kills`.`killerguild` = `guild_wars`.`guild2`) AS guild2_kills " ..
"FROM `guild_wars` WHERE (`guild1` = %d OR `guild2` = %d) AND `status` = 1 AND `id` = %d",
killerGuildId, targetGuildId, warId
))
local resultId = db.storeQuery(
string.format(
"SELECT `guild_wars`.`id`, `guild_wars`.`frags_limit`, "
.. "(SELECT COUNT(1) FROM `guildwar_kills` WHERE `guildwar_kills`.`warid` = `guild_wars`.`id` AND `guildwar_kills`.`killerguild` = `guild_wars`.`guild1`) AS guild1_kills, "
.. "(SELECT COUNT(1) FROM `guildwar_kills` WHERE `guildwar_kills`.`warid` = `guild_wars`.`id` AND `guildwar_kills`.`killerguild` = `guild_wars`.`guild2`) AS guild2_kills "
.. "FROM `guild_wars` WHERE (`guild1` = %d OR `guild2` = %d) AND `status` = 1 AND `id` = %d",
killerGuildId,
targetGuildId,
warId
)
)

if resultId then
local guild1Kills = Result.getNumber(resultId, "guild1_kills")
Expand All @@ -144,18 +141,12 @@ end
local function updateGuildWarScore(killerGuild, targetGuild, playerName, killerName, guild1Kills, guild2Kills, fragsLimit)
local members = killerGuild:getMembersOnline()
for _, member in ipairs(members) do
member:sendChannelMessage(member, string.format(
"%s was killed by %s. The new score is: %s %d:%d %s (frags limit: %d)", playerName, killerName,
targetGuild:getName(), guild1Kills, guild2Kills, killerGuild:getName(), fragsLimit
), TALKTYPE_CHANNEL_R1, CHANNEL_GUILD)
member:sendChannelMessage(member, string.format("%s was killed by %s. The new score is: %s %d:%d %s (frags limit: %d)", playerName, killerName, targetGuild:getName(), guild1Kills, guild2Kills, killerGuild:getName(), fragsLimit), TALKTYPE_CHANNEL_R1, CHANNEL_GUILD)
end

local enemyMembers = targetGuild:getMembersOnline()
for _, enemy in ipairs(enemyMembers) do
enemy:sendChannelMessage(enemy, string.format(
"%s was killed by %s. The new score is: %s %d:%d %s (frags limit: %d)", playerName, killerName,
targetGuild:getName(), guild1Kills, guild2Kills, killerGuild:getName(), fragsLimit
), TALKTYPE_CHANNEL_R1, CHANNEL_GUILD)
enemy:sendChannelMessage(enemy, string.format("%s was killed by %s. The new score is: %s %d:%d %s (frags limit: %d)", playerName, killerName, targetGuild:getName(), guild1Kills, guild2Kills, killerGuild:getName(), fragsLimit), TALKTYPE_CHANNEL_R1, CHANNEL_GUILD)
end
end

Expand Down

0 comments on commit 2094b04

Please sign in to comment.