math.randomseed(os.time())
dofile('data/lib/lib.lua')
ropeSpots = {384, 418, 8278, 8592}
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
}
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
}
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
}
openExtraDoors = {1540, 1542, 6796, 6798, 6800, 6802, 7055, 7057}
closedExtraDoors = {1539, 1541, 6795, 6797, 6799, 6801, 7054, 7056}
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
}
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
}
--[[ (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
}
]] --
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
}
--[[ (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
}
]] --
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
}
function getDistanceBetween(firstPosition, secondPosition)
local xDif = math.abs(firstPosition.x - secondPosition.x)
local yDif = math.abs(firstPosition.y - secondPosition.y)
local posDif = math.max(xDif, yDif)
if firstPosition.z ~= secondPosition.z then posDif = posDif + 15 end
return posDif
end
function getFormattedWorldTime()
local worldTime = getWorldTime()
local hours = math.floor(worldTime / 60)
local minutes = worldTime % 60
if minutes < 10 then minutes = '0' .. minutes end
return hours .. ':' .. minutes
end
function getLootRandom()
return math.random(0, MAX_LOOTCHANCE) /
configManager.getNumber(configKeys.RATE_LOOT)
end
table.contains = function(array, value)
for _, targetColumn in pairs(array) do
if targetColumn == value then return true end
end
return false
end
string.split = function(str, sep)
local res = {}
for v in str:gmatch("([^" .. sep .. "]+)") do res[#res + 1] = v end
return res
end
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
do
local function tchelper(first, rest) return first:upper() .. rest:lower() end
-- Add extra characters to the pattern if you need to. _ and ' are
-- found in the middle of identifiers and English words.
-- We must also put %w_' into [%w_'] to make it handle normal stuff
-- and extra stuff the same.
-- This also turns hex numbers into, eg. 0Xa7d4
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 = ""
if type(name_or_guid) == 'string' then
sql_where = "WHERE `p`.`name`=" .. db.escapeString(name_or_guid) .. ""
elseif type(name_or_guid) == 'number' then
sql_where = "WHERE `p`.`id`='" .. name_or_guid .. "'"
else
return false
end
local sql_query = [[
SELECT
`p`.`id` as `guid`,
`p`.`name`,
CASE WHEN `po`.`player_id` IS NULL
THEN 0
ELSE 1
END AS `online`,
`p`.`group_id`,
`p`.`level`,
`p`.`experience`,
`p`.`vocation`,
`p`.`maglevel`,
`p`.`skill_fist`,
`p`.`skill_club`,
`p`.`skill_sword`,
`p`.`skill_axe`,
`p`.`skill_dist`,
`p`.`skill_shielding`,
`p`.`skill_fishing`,
`p`.`town_id`,
`p`.`balance`,
`gm`.`guild_id`,
`gm`.`nick`,
`g`.`name` AS `guild_name`,
CASE WHEN `p`.`id` = `g`.`ownerid`
THEN 1
ELSE 0
END AS `is_leader`,
`gr`.`name` AS `rank_name`,
`gr`.`level` AS `rank_level`,
`h`.`id` AS `house_id`,
`h`.`name` AS `house_name`,
`h`.`town_id` AS `house_town`
FROM `players` AS `p`
LEFT JOIN `players_online` AS `po`
ON `p`.`id` = `po`.`player_id`
LEFT JOIN `guild_membership` AS `gm`
ON `p`.`id` = `gm`.`player_id`
LEFT JOIN `guilds` AS `g`
ON `gm`.`guild_id` = `g`.`id`
LEFT JOIN `guild_ranks` AS `gr`
ON `gm`.`rank_id` = `gr`.`id`
LEFT JOIN `houses` AS `h`
ON `p`.`id` = `h`.`owner`
]] .. sql_where
local query = db.storeQuery(sql_query)
if not query then return false end
local info = {
["guid"] = result.getNumber(query, "guid"),
["name"] = result.getString(query, "name"),
["online"] = result.getNumber(query, "online"),
["group_id"] = result.getNumber(query, "group_id"),
["level"] = result.getNumber(query, "level"),
["experience"] = result.getNumber(query, "experience"),
["vocation"] = result.getNumber(query, "vocation"),
["maglevel"] = result.getNumber(query, "maglevel"),
["skill_fist"] = result.getNumber(query, "skill_fist"),
["skill_club"] = result.getNumber(query, "skill_club"),
["skill_sword"] = result.getNumber(query, "skill_sword"),
["skill_axe"] = result.getNumber(query, "skill_axe"),
["skill_dist"] = result.getNumber(query, "skill_dist"),
["skill_shielding"] = result.getNumber(query, "skill_shielding"),
["skill_fishing"] = result.getNumber(query, "skill_fishing"),
["town_id"] = result.getNumber(query, "town_id"),
["balance"] = result.getNumber(query, "balance"),
["guild_id"] = result.getNumber(query, "guild_id"),
["nick"] = result.getString(query, "nick"),
["guild_name"] = result.getString(query, "guild_name"),
["is_leader"] = result.getNumber(query, "is_leader"),
["rank_name"] = result.getString(query, "rank_name"),
["rank_level"] = result.getNumber(query, "rank_level"),
["house_id"] = result.getNumber(query, "house_id"),
["house_name"] = result.getString(query, "house_name"),
["house_town"] = result.getNumber(query, "house_town")
}
result.free(query)
return info
end