Skip to content

Commit

Permalink
update data
Browse files Browse the repository at this point in the history
  • Loading branch information
MillhioreBT committed Apr 28, 2024
1 parent 4670bbe commit 3fe2043
Show file tree
Hide file tree
Showing 18 changed files with 582 additions and 261 deletions.
2 changes: 1 addition & 1 deletion .lua-format
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ continuation_indent_width: 1
use_tab: true
tab_width: 4
chop_down_table: true
column_limit: 100
column_limit: 90
5 changes: 4 additions & 1 deletion data/creaturescripts/scripts/login.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ function onLogin(player)
local promotion = vocation:getPromotion()
if player:isPremium() then
local value = player:getStorageValue(PlayerStorageKeys.promotion)
if value == 1 then player:setVocation(promotion) end
if value and value == 1 then player:setVocation(promotion) end
elseif not promotion then
player:setVocation(vocation:getDemotion())
end

-- Events
player:registerEvent("PlayerDeath")
player:registerEvent("DropLoot")

-- Update Experience Rate Stamina
player:updateStamina()
return true
end
2 changes: 1 addition & 1 deletion data/creaturescripts/scripts/logout.lua
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
114 changes: 63 additions & 51 deletions data/creaturescripts/scripts/playerdeath.lua
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
16 changes: 8 additions & 8 deletions data/events/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<events>
<!-- Creature methods -->
<event class="Creature" method="onChangeOutfit" enabled="0" />
<event class="Creature" method="onAreaCombat" enabled="0" />
<event class="Creature" method="onTargetCombat" enabled="0" />
<event class="Creature" method="onAreaCombat" enabled="1" />
<event class="Creature" method="onTargetCombat" enabled="1" />
<event class="Creature" method="onHear" enabled="0" />
<event class="Creature" method="onChangeZone" enabled="0" />
<event class="Creature" method="onUpdateStorage" enabled="1" />
Expand All @@ -23,14 +23,14 @@
<event class="Player" method="onLookInTrade" enabled="1" />
<event class="Player" method="onLookInShop" enabled="1" />
<event class="Player" method="onMoveItem" enabled="1" />
<event class="Player" method="onItemMoved" enabled="0" />
<event class="Player" method="onMoveCreature" enabled="0" />
<event class="Player" method="onItemMoved" enabled="1" />
<event class="Player" method="onMoveCreature" enabled="1" />
<event class="Player" method="onReportBug" enabled="1" />
<event class="Player" method="onReportRuleViolation" enabled="1" />
<event class="Player" method="onTurn" enabled="1" />
<event class="Player" method="onTradeRequest" enabled="0" />
<event class="Player" method="onTradeAccept" enabled="0" />
<event class="Player" method="onTradeCompleted" enabled="0" />
<event class="Player" method="onTradeRequest" enabled="1" />
<event class="Player" method="onTradeAccept" enabled="1" />
<event class="Player" method="onTradeCompleted" enabled="1" />
<event class="Player" method="onGainExperience" enabled="1" />
<event class="Player" method="onLoseExperience" enabled="0" />
<event class="Player" method="onGainSkillTries" enabled="1" />
Expand All @@ -42,5 +42,5 @@

<!-- Monster methods -->
<event class="Monster" method="onDropLoot" enabled="1" />
<event class="Monster" method="onSpawn" enabled="0" />
<event class="Monster" method="onSpawn" enabled="1" />
</events>
111 changes: 65 additions & 46 deletions data/global.lua
Original file line number Diff line number Diff line change
@@ -1,70 +1,84 @@
math.randomseed(os.time())
dofile('data/lib/lib.lua')

ropeSpots = {384, 418, 8278, 8592}
-- LuaFormatter off
ropeSpots = {
384, 418, 8278, 8592, 13189, 14435, 14436, 14857, 15635, 19518, 24621, 24622, 24623, 24624, 26019
}

keys = {2086, 2087, 2088, 2089, 2090, 2091, 2092, 10032}
keys = {
2086, 2087, 2088, 2089, 2090, 2091, 2092, 10032
}

openDoors = {
1211, 1214, 1233, 1236, 1251, 1254, 3546, 3537, 4915, 4918, 5100, 5109, 5118,
5127, 5136, 5139, 5142, 5145, 5280, 5283, 5734, 5737, 6194, 6197, 6251, 6254,
6893, 6902, 7035, 7044, 8543, 8546, 9167, 9170, 9269, 9272, 10270, 10273,
10470, 10479, 10777, 10786, 12094, 12101, 12190, 12199
1211, 1214, 1233, 1236, 1251, 1254, 3537, 3546, 4915, 4918, 5100, 5109, 5118, 5127, 5136, 5139, 5142,
5145, 5280, 5283, 5734, 5737, 6194, 6197, 6251, 6254, 6893, 6902, 7035, 7044, 8543, 8546, 9167, 9170,
9269, 9272, 10270, 10273, 10470, 10479, 10777, 10786, 12094, 12101, 12190, 12199, 12695, 12703, 14635,
17435, 19842, 19851, 19982, 19991, 20275, 20284, 22816, 22825, 25285, 25292, 26533, 26534, 31176, 31024,
31025, 32691, 32692, 32695, 32696, 33432, 33433, 33493, 33494, 36292, 36293, 36869, 36872, 37293, 37296,
37299, 37302, 37596, 37597, 39119, 39120
}
closedDoors = {
1210, 1213, 1232, 1235, 1250, 1253, 3536, 3545, 4914, 4917, 5099, 5108, 5117,
5126, 5135, 5138, 5141, 5144, 5279, 5282, 5733, 5736, 6193, 6196, 6250, 6253,
6892, 6901, 7034, 7043, 8542, 8545, 9166, 9169, 9268, 9271, 10269, 10272,
10766, 10785, 10469, 10478, 12093, 12100, 12189, 12198
1210, 1213, 1232, 1235, 1250, 1253, 3536, 3545, 4914, 4917, 5099, 5108, 5117, 5126, 5135, 5138, 5141,
5144, 5279, 5282, 5733, 5736, 6193, 6196, 6250, 6253, 6892, 6901, 7034, 7043, 8542, 8545, 9166, 9169,
9268, 9271, 10269, 10272, 10469, 10478, 10776, 10785, 12093, 12100, 12189, 12198, 12692, 12701, 14633,
14640, 19841, 19850, 19981, 19990, 20274, 20283, 22815, 22824, 25284, 25291, 26529, 26531, 27559, 31020,
31022, 32689, 32690, 32693, 32694, 33428, 33430, 33489, 33491, 36288, 36290, 36868, 36871, 37292, 37295,
37298, 37301, 37592, 37594, 39115, 39117
}
lockedDoors = {
1209, 1212, 1231, 1234, 1249, 1252, 3535, 3544, 4913, 4916, 5098, 5107, 5116,
5125, 5134, 5137, 5140, 5143, 5278, 5281, 5732, 5735, 6192, 6195, 6249, 6252,
6891, 6900, 7033, 7042, 8541, 8544, 9165, 9168, 9267, 9270, 10268, 10271,
10468, 10477, 10775, 10784, 12092, 12099, 12188, 12197
1209, 1212, 1231, 1234, 1249, 1252, 3535, 3544, 4913, 4916, 5098, 5107, 5116, 5125, 5134, 5137, 5140,
5143, 5278, 5281, 5732, 5735, 6192, 6195, 6249, 6252, 6891, 6900, 7033, 7042, 8541, 8544, 9165, 9168,
9267, 9270, 10268, 10271, 10468, 10477, 10775, 10784, 12092, 12099, 12188, 12197, 13236, 13237, 14634,
14641, 19840, 19849, 19980, 19989, 20273, 20282, 22814, 22823, 25283, 25290, 26530, 26532, 31175, 31021,
31023, 32705, 32706, 32707, 32708, 33429, 33431, 33490, 33492, 36289, 36291, 36867, 36870, 37291, 37294,
37297, 37300, 37593, 37595, 39116, 39118
}

openExtraDoors = {1540, 1542, 6796, 6798, 6800, 6802, 7055, 7057}
closedExtraDoors = {1539, 1541, 6795, 6797, 6799, 6801, 7054, 7056}
openExtraDoors = {
1540, 1542, 6796, 6798, 6800, 6802, 6960, 6962, 7055, 7057, 25159, 25161, 27198, 27200, 27243, 27245,
31541, 31542, 34152, 34153, 36878, 36880, 39204
}
closedExtraDoors = {
1539, 1541, 6795, 6797, 6799, 6801, 6959, 6961, 7054, 7056, 25158, 25160, 27197, 27199, 27242, 27244,
31314, 31315, 34150, 34151, 36877, 36879, 39203
}

openHouseDoors = {
1220, 1222, 1238, 1240, 3539, 3548, 5083, 5085, 5102, 5111, 5120, 5129, 5285,
5287, 5516, 5518, 6199, 6201, 6256, 6258, 6895, 6904, 7037, 7046, 8548, 8550,
9172, 9174, 9274, 9276, 10275, 10277, 10472, 10481
1220, 1222, 1238, 1240, 3539, 3548, 5083, 5085, 5102, 5111, 5120, 5129, 5285, 5287, 5516, 5518, 6199,
6201, 6256, 6258, 6895, 6904, 7037, 7046, 8548, 8550, 9172, 9174, 9274, 9276, 10275, 10277, 10472, 10481,
13021, 13023, 17236, 17238, 18209, 19844, 19853, 19984, 19993, 20277, 20286, 22818, 22827, 35928, 35930
}
closedHouseDoors = {
1219, 1221, 1237, 1239, 3538, 3547, 5082, 5084, 5101, 5110, 5119, 5128, 5284,
5286, 5515, 5517, 6198, 6200, 6255, 6257, 6894, 6903, 7036, 7045, 8547, 8549,
9171, 9173, 9273, 9275, 10274, 10276, 10471, 10480
1219, 1221, 1237, 1239, 3538, 3547, 5082, 5084, 5101, 5110, 5119, 5128, 5284, 5286, 5515, 5517, 6198,
6200, 6255, 6257, 6894, 6903, 7036, 7045, 8547, 8549, 9171, 9173, 9273, 9275, 10274, 10276, 10471, 10480,
13020, 13022, 17235, 17237, 18208, 19843, 19852, 19983, 19992, 20276, 20285, 22817, 22826, 35927, 35929
}

--[[ (Not currently used, but probably useful to keep up to date)
openQuestDoors = {
1224, 1226, 1242, 1244, 1256, 1258, 3543, 3552, 5106, 5115, 5124, 5133, 5289, 5291, 5746, 5749, 6203,
6205, 6260, 6262, 6899, 6908, 7041, 7050, 8552, 8554, 9176, 9178, 9278, 9280, 10279, 10281, 10476, 10485,
10783, 10792, 12098, 12105, 12194, 12203
10783, 10792, 12098, 12105, 12196, 12205, 14639, 14646, 19848, 19857, 19988, 19997, 20281, 20290, 22822,
22831, 25163, 25165, 25289, 25296, 32698, 32700, 32702, 32704, 34320, 34322, 34225, 34227
}
]] --
closedQuestDoors = {
1223, 1225, 1241, 1243, 1255, 1257, 3542, 3551, 5105, 5114, 5123, 5132, 5288,
5290, 5745, 5748, 6202, 6204, 6259, 6261, 6898, 6907, 7040, 7049, 8551, 8553,
9175, 9177, 9277, 9279, 10278, 10280, 10475, 10484, 10782, 10791, 12097, 12104,
12193, 12202
1223, 1225, 1241, 1243, 1255, 1257, 3542, 3551, 5105, 5114, 5123, 5132, 5288, 5290, 5745, 5748, 6202,
6204, 6259, 6261, 6898, 6907, 7040, 7049, 8551, 8553, 9175, 9177, 9277, 9279, 10278, 10280, 10475, 10484,
10782, 10791, 12097, 12104, 12195, 12204, 14638, 14645, 19847, 19856, 19987, 19996, 20280, 20289, 22821,
22830, 25162, 25164, 25288, 25295, 32697, 32699, 32701, 32703, 34319, 34321, 34224, 34226
}

--[[ (Not currently used, but probably useful to keep up to date)
openLevelDoors = {
1228, 1230, 1246, 1248, 1260, 1262, 3541, 3550, 5104, 5113, 5122, 5131, 5293, 5295, 6207, 6209, 6264,
6266, 6897, 6906, 7039, 7048, 8556, 8558, 9180, 9182, 9282, 9284, 10283, 10285, 10474, 10483, 10781,
10790, 12096, 12103, 12196, 12205
10790, 12096, 12103, 12194, 12203, 19846, 19855, 19986, 19995, 20279, 20288, 22820, 22829, 25287, 25294
}
]] --
closedLevelDoors = {
1227, 1229, 1245, 1247, 1259, 1261, 3540, 3549, 5103, 5112, 5121, 5130, 5292,
5294, 6206, 6208, 6263, 6265, 6896, 6905, 7038, 7047, 8555, 8557, 9179, 9181,
9281, 9283, 10282, 10284, 10473, 10482, 10780, 10789, 12095, 12102, 12195,
12204
1227, 1229, 1245, 1247, 1259, 1261, 3540, 3549, 5103, 5112, 5121, 5130, 5292, 5294, 6206, 6208, 6263,
6265, 6896, 6905, 7038, 7047, 8555, 8557, 9179, 9181, 9281, 9283, 10282, 10284, 10473, 10482, 10780,
10789, 12095, 12102, 12193, 12202, 19845, 19854, 19985, 19994, 20278, 20287, 22819, 22828, 25286, 25293
}
-- LuaFormatter on

function getDistanceBetween(firstPosition, secondPosition)
local xDif = math.abs(firstPosition.x - secondPosition.x)
Expand All @@ -84,32 +98,39 @@ function getFormattedWorldTime()
end

function getLootRandom()
return math.random(0, MAX_LOOTCHANCE) /
configManager.getNumber(configKeys.RATE_LOOT)
return math.random(0, MAX_LOOTCHANCE) / configManager.getNumber(configKeys.RATE_LOOT)
end

---@generic T: table, K, V
---@param array T The table to search in
---@param value K The value to search for
---@return boolean found Whether the value was found
table.contains = function(array, value)
for _, targetColumn in pairs(array) do
if targetColumn == value then return true end
end
for _, targetColumn in pairs(array) do if targetColumn == value then return true end end
return false
end

---@param str string
---@param sep string
---@return table<integer, string>
string.split = function(str, sep)
local res = {}
for v in str:gmatch("([^" .. sep .. "]+)") do res[#res + 1] = v end
return res
end

---@param str string
---@param sep string
---@return table<integer, string>
string.splitTrimmed = function(str, sep)
local res = {}
for v in str:gmatch("([^" .. sep .. "]+)") do res[#res + 1] = v:trim() end
return res
end

string.trim = function(str)
return str:match '^()%s*$' and '' or str:match '^%s*(.*%S)'
end
---@param str string
---@return string
string.trim = function(str) return str:match '^()%s*$' and '' or str:match '^%s*(.*%S)' end

do
local function tchelper(first, rest) return first:upper() .. rest:lower() end
Expand All @@ -122,8 +143,6 @@ do
string.titleCase = function(str) return str:gsub("(%a)([%w_']*)", tchelper) end
end

if not nextUseStaminaTime then nextUseStaminaTime = {} end

function getPlayerDatabaseInfo(name_or_guid)
local sql_where = ""

Expand Down
Loading

0 comments on commit 3fe2043

Please sign in to comment.