global.lua

main 238 lines · 11.3 KB Raw
Alex Alex Commit Server upload 18/10/2026 23:38
1math.randomseed(os.time())
2dofile('data/lib/lib.lua')
3
4ropeSpots = {384, 418, 8278, 8592, 13189, 14435, 14436, 14857, 15635, 19518, 24621, 24622, 24623, 24624, 26019}
5
6doors = {[1209] = 1211, [1210] = 1211, [1212] = 1214, [1213] = 1214, [1219] = 1220, [1221] = 1222, [1231] = 1233, [1232] = 1233, [1234] = 1236, [1235] = 1236, [1237] = 1238, [1239] = 1240, [1249] = 1251, [1250] = 1251, [1252] = 1254, [1253] = 1254, [1539] = 1540, [1541] = 1542, [3535] = 3537, [3536] = 3537, [3538] = 3539, [3544] = 3546, [3545] = 3546, [3547] = 3548, [4913] = 4915, [4914] = 4915, [4916] = 4918, [4917] = 4918, [5082] = 5083, [5084] = 5085, [5098] = 5100, [5099] = 5100, [5101] = 5102, [5107] = 5109, [5108] = 5109, [5110] = 5111, [5116] = 5118, [5117] = 5118, [5119] = 5120, [5125] = 5127, [5126] = 5127, [5128] = 5129, [5134] = 5136, [5135] = 5136, [5137] = 5139, [5138] = 5139, [5140] = 5142, [5141] = 5142, [5143] = 5145, [5144] = 5145, [5278] = 5280, [5279] = 5280, [5281] = 5283, [5282] = 5283, [5284] = 5285, [5286] = 5287, [5515] = 5516, [5517] = 5518, [5732] = 5734, [5733] = 5734, [5735] = 5737, [5736] = 5737, [6192] = 6194, [6193] = 6194, [6195] = 6197, [6196] = 6197, [6198] = 6199, [6200] = 6201, [6249] = 6251, [6250] = 6251, [6252] = 6254, [6253] = 6254, [6255] = 6256, [6257] = 6258, [6795] = 6796, [6797] = 6798, [6799] = 6800, [6801] = 6802, [6891] = 6893, [6892] = 6893, [6894] = 6895, [6900] = 6902, [6901] = 6902, [6903] = 6904, [7033] = 7035, [7034] = 7035, [7036] = 7037, [7042] = 7044, [7043] = 7044, [7045] = 7046, [7054] = 7055, [7056] = 7057, [8541] = 8543, [8542] = 8543, [8544] = 8546, [8545] = 8546, [8547] = 8548, [8549] = 8550, [9165] = 9167, [9166] = 9167, [9168] = 9170, [9169] = 9170, [9171] = 9172, [9173] = 9174, [9267] = 9269, [9268] = 9269, [9270] = 9272, [9271] = 9272, [9273] = 9274, [9275] = 9276, [10276] = 10277, [10274] = 10275, [10268] = 10270, [10269] = 10270, [10271] = 10273, [10272] = 10273, [10471] = 10472, [10480] = 10481, [10477] = 10479, [10478] = 10479, [10468] = 10470, [10469] = 10470, [10775] = 10777, [10776] = 10777, [12092] = 12094, [12093] = 12094, [12188] = 12190, [12189] = 12190, [19840] = 19842, [19841] = 19842, [19843] = 19844, [19980] = 19982, [19981] = 19982, [19983] = 19984, [20273] = 20275, [20274] = 20275, [20276] = 20277, [17235] = 17236, [18208] = 18209, [13022] = 13023, [10784] = 10786, [10785] = 10786, [12099] = 12101, [12100] = 12101, [12197] = 12199, [12198] = 12199, [19849] = 19851, [19850] = 19851, [19852] = 19853, [19989] = 19991, [19990] = 19991, [19992] = 19993, [20282] = 20284, [20283] = 20284, [20285] = 20286, [17237] = 17238, [13020] = 13021, [10780] = 10781, [12095] = 12096, [12195] = 12196, [19845] = 19846, [19985] = 19986, [20278] = 20279, [10789] = 10790, [12102] = 12103, [12204] = 12205, [19854] = 19855, [19994] = 19995, [20287] = 20288, [10782] = 10783, [12097] = 12098, [12193] = 12194, [19847] = 19848, [19987] = 19988, [20280] = 20281, [10791] = 10792, [12104] = 12105, [12202] = 12203, [19856] = 19857, [19996] = 19997, [20289] = 20290, [25158] = 25159, [25160] = 25161}
7verticalOpenDoors = {1211, 1220, 1224, 1228, 1233, 1238, 1242, 1246, 1251, 1256, 1260, 1540, 3546, 3548, 3550, 3552, 4915, 5083, 5109, 5111, 5113, 5115, 5127, 5129, 5131, 5133, 5142, 5145, 5283, 5285, 5289, 5293, 5516, 5737, 5749, 6194, 6199, 6203, 6207, 6251, 6256, 6260, 6264, 6798, 6802, 6902, 6904, 6906, 6908, 7044, 7046, 7048, 7050, 7055, 8543, 8548, 8552, 8556, 9167, 9172, 9269, 9274, 9274, 9269, 9278, 9282, 10270, 10275, 10279, 10283, 10479, 10481, 10485, 10483, 10786, 12101, 12199, 19851, 19853, 19991, 19993, 20284, 20286, 17238, 13021, 10790, 12103, 12205, 19855, 19995, 20288, 10792, 12105, 12203, 19857, 19997, 20290}
8horizontalOpenDoors = {1214, 1222, 1226, 1230, 1236, 1240, 1244, 1248, 1254, 1258, 1262, 1542, 3537, 3539, 3541, 3543, 4918, 5085, 5100, 5102, 5104, 5106, 5118, 5120, 5122, 5124, 5136, 5139, 5280, 5287, 5291, 5295, 5518, 5734, 5746, 6197, 6201, 6205, 6209, 6254, 6258, 6262, 6266, 6796, 6800, 6893, 6895, 6897, 6899, 7035, 7037, 7039, 7041, 7057, 8546, 8550, 8554, 8558, 9170, 9174, 9272, 9276, 9280, 9284, 10273, 10277, 10281, 10285, 10470, 10472, 10476, 10474, 10777, 12094, 12190, 19842, 19844, 19982, 19984, 20275, 20277, 17236, 18209, 13023, 10781, 12096, 12196, 19846, 19986, 20279, 10783, 12098, 12194, 19848, 19988, 20281}
9openSpecialDoors = {1224, 1226, 1228, 1230, 1242, 1244, 1246, 1248, 1256, 1258, 1260, 1262, 3541, 3543, 3550, 3552, 5104, 5106, 5113, 5115, 5122, 5124, 5131, 5133, 5289, 5291, 5293, 5295, 6203, 6205, 6207, 6209, 6260, 6262, 6264, 6266, 6897, 6899, 6906, 6908, 7039, 7041, 7048, 7050, 8552, 8554, 8556, 8558, 9176, 9178, 9180, 9182, 9278, 9280, 9282, 9284, 10279, 10281, 10283, 10285, 10474, 10476, 10483, 10485, 10781, 12096, 12196, 19846, 19986, 20279, 10783, 12098, 12194, 19848, 19988, 20281, 10790, 12103, 12205, 19855, 19995, 20288, 10792, 12105, 12203, 19857, 19997, 20290, 25163, 25165}
10questDoors = {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, 19847, 19856, 19987, 19996, 20280, 20289, 25162, 25164}
11levelDoors = {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, 10780, 12095, 12102, 12204, 12195, 19845, 19854, 19985, 19994, 20278, 20287}
12keys = {2086, 2087, 2088, 2089, 2090, 2091, 2092, 10032}
13
14MONSTER_STORAGE = MONSTER_STORAGE or {}
15
16function Monster.setStorageValue(self, key, value)
17 local cid = self:getId()
18 local storageMap = MONSTER_STORAGE[cid]
19 if not storageMap then
20 MONSTER_STORAGE[cid] = {[key] = value}
21 else
22 storageMap[key] = value
23 end
24end
25
26function Monster.getStorageValue(self, key)
27 local storageMap = MONSTER_STORAGE[self:getId()]
28 if storageMap then
29 return storageMap[key] or -1
30 end
31 return -1
32end
33
34function getDistanceBetween(firstPosition, secondPosition)
35 local xDif = math.abs(firstPosition.x - secondPosition.x)
36 local yDif = math.abs(firstPosition.y - secondPosition.y)
37 local posDif = math.max(xDif, yDif)
38 if firstPosition.z ~= secondPosition.z then
39 posDif = posDif + 15
40 end
41 return posDif
42end
43
44function getFormattedWorldTime()
45 local worldTime = getWorldTime()
46 local hours = math.floor(worldTime / 60)
47
48 local minutes = worldTime % 60
49 if minutes < 10 then
50 minutes = '0' .. minutes
51 end
52 return hours .. ':' .. minutes
53end
54
55function getLootRandom()
56 return math.random(0, MAX_LOOTCHANCE) / configManager.getNumber(configKeys.RATE_LOOT)
57end
58
59table.contains = function(array, value)
60 for _, targetColumn in pairs(array) do
61 if targetColumn == value then
62 return true
63 end
64 end
65 return false
66end
67
68string.split = function(str, sep)
69 local res = {}
70 for v in str:gmatch("([^" .. sep .. "]+)") do
71 res[#res + 1] = v
72 end
73 return res
74end
75
76string.splitTrimmed = function(str, sep)
77 local res = {}
78 for v in str:gmatch("([^" .. sep .. "]+)") do
79 res[#res + 1] = v:trim()
80 end
81 return res
82end
83
84string.trim = function(str)
85 return str:match'^()%s*$' and '' or str:match'^%s*(.*%S)'
86end
87
88if not nextUseStaminaTime then
89 nextUseStaminaTime = {}
90end
91
92function getPlayerDatabaseInfo(name_or_guid)
93 local sql_where = ""
94
95 if type(name_or_guid) == 'string' then
96 sql_where = "WHERE `p`.`name`=" .. db.escapeString(name_or_guid) .. ""
97 elseif type(name_or_guid) == 'number' then
98 sql_where = "WHERE `p`.`id`='" .. name_or_guid .. "'"
99 else
100 return false
101 end
102
103 local sql_query = [[
104 SELECT
105 `p`.`id` as `guid`,
106 `p`.`name`,
107 CASE WHEN `po`.`player_id` IS NULL
108 THEN 0
109 ELSE 1
110 END AS `online`,
111 `p`.`group_id`,
112 `p`.`level`,
113 `p`.`experience`,
114 `p`.`vocation`,
115 `p`.`maglevel`,
116 `p`.`skill_fist`,
117 `p`.`skill_club`,
118 `p`.`skill_sword`,
119 `p`.`skill_axe`,
120 `p`.`skill_dist`,
121 `p`.`skill_shielding`,
122 `p`.`skill_fishing`,
123 `p`.`town_id`,
124 `p`.`balance`,
125 `gm`.`guild_id`,
126 `gm`.`nick`,
127 `g`.`name` AS `guild_name`,
128 CASE WHEN `p`.`id` = `g`.`ownerid`
129 THEN 1
130 ELSE 0
131 END AS `is_leader`,
132 `gr`.`name` AS `rank_name`,
133 `gr`.`level` AS `rank_level`,
134 `h`.`id` AS `house_id`,
135 `h`.`name` AS `house_name`,
136 `h`.`town_id` AS `house_town`
137 FROM `players` AS `p`
138 LEFT JOIN `players_online` AS `po`
139 ON `p`.`id` = `po`.`player_id`
140 LEFT JOIN `guild_membership` AS `gm`
141 ON `p`.`id` = `gm`.`player_id`
142 LEFT JOIN `guilds` AS `g`
143 ON `gm`.`guild_id` = `g`.`id`
144 LEFT JOIN `guild_ranks` AS `gr`
145 ON `gm`.`rank_id` = `gr`.`id`
146 LEFT JOIN `houses` AS `h`
147 ON `p`.`id` = `h`.`owner`
148 ]] .. sql_where
149
150 local query = db.storeQuery(sql_query)
151 if not query then
152 return false
153 end
154
155 local info = {
156 ["guid"] = result.getNumber(query, "guid"),
157 ["name"] = result.getString(query, "name"),
158 ["online"] = result.getNumber(query, "online"),
159 ["group_id"] = result.getNumber(query, "group_id"),
160 ["level"] = result.getNumber(query, "level"),
161 ["experience"] = result.getNumber(query, "experience"),
162 ["vocation"] = result.getNumber(query, "vocation"),
163 ["maglevel"] = result.getNumber(query, "maglevel"),
164 ["skill_fist"] = result.getNumber(query, "skill_fist"),
165 ["skill_club"] = result.getNumber(query, "skill_club"),
166 ["skill_sword"] = result.getNumber(query, "skill_sword"),
167 ["skill_axe"] = result.getNumber(query, "skill_axe"),
168 ["skill_dist"] = result.getNumber(query, "skill_dist"),
169 ["skill_shielding"] = result.getNumber(query, "skill_shielding"),
170 ["skill_fishing"] = result.getNumber(query, "skill_fishing"),
171 ["town_id"] = result.getNumber(query, "town_id"),
172 ["balance"] = result.getNumber(query, "balance"),
173 ["guild_id"] = result.getNumber(query, "guild_id"),
174 ["nick"] = result.getString(query, "nick"),
175 ["guild_name"] = result.getString(query, "guild_name"),
176 ["is_leader"] = result.getNumber(query, "is_leader"),
177 ["rank_name"] = result.getString(query, "rank_name"),
178 ["rank_level"] = result.getNumber(query, "rank_level"),
179 ["house_id"] = result.getNumber(query, "house_id"),
180 ["house_name"] = result.getString(query, "house_name"),
181 ["house_town"] = result.getNumber(query, "house_town")
182 }
183
184 result.free(query)
185 return info
186end
187
188local function allowMovementEvent(cid, allow, oldPosition)
189 local creature = Creature(cid)
190 if not creature then
191 return false
192 end
193
194 if allow then
195 return stopEvent(event)
196 else
197 stopEvent(event)
198 end
199
200 creature:teleportTo(oldPosition, true)
201
202 event = addEvent(allowMovementEvent, 100, cid, allow, oldPosition)
203end
204
205function Creature.allowMovement(self, allow)
206 allowMovementEvent(self:getId(), allow, self:getPosition())
207end
208
209local CODE = 107
210
211function sendSoundToPlayer(player, soundFile)
212 local json_data = json.encode({action = "play", data = soundFile})
213 player:sendExtendedOpcode(CODE, json_data)
214end
215
216
217
218function playSound(creature, soundFile)
219 local spectators = Game.getSpectators(creature:getPosition(), false, true, 7, 7, 7, 7)
220 for _, spectator in ipairs(spectators) do
221 if spectator:isPlayer() then
222 sendSoundToPlayer(spectator, soundFile)
223 end
224 end
225end
226
227local CODE = 108
228
229function sendSoundToPlayer(player, soundFile)
230 local json_data = json.encode({action = "play", data = soundFile})
231 player:sendExtendedOpcode(CODE, json_data)
232end
233
234function playSoundPlayer(player, soundFile)
235 if player:isPlayer() then
236 sendSoundToPlayer(player, soundFile)
237 end
238end
Top