-
Notifications
You must be signed in to change notification settings - Fork 1
/
pets_lib.lua
450 lines (391 loc) · 12.4 KB
/
pets_lib.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
---- based on Jordanhenry pet system version 1.77 (changelog)
---- edited by hellboy
-- config
PETS = {
PREFIX = "PET_",
CHANNELID = 10,
CONFIG = {
introduction = "You may catch pets using command '!petcatch'. If your pet dies, you have to revive it in order to re-summon it. Some pets have a special requirement in order to catch them, some cannot be catched at all and can only be gotten by evolution. Type 'commands' for a list of available commands.",
sameSpeed = true,
healSoulCost = 0.1,
healSoulBase = 10,
healOnLevelUp = true,
standardHpAdd = 5,
expMultipler = 1,
shareExpMultipler = 0.3,
maxLevel = 30,
reviveSoulBaseCost = 50,
reviveSoulLevelCost = 0.2
},
SYSTEM = {
EVOLUTION = true,
MOUNTS = false,
TELEPORT = true,
PLAYER_SHARE_EXPERIENCE = false,
DUELS_ONLY = false
},
IDENTIFICATION = {
[1] = {
name = "Cat",
health = 100,
evolve = {
to = 3,
at = 10
},
check = true
},
[2] = {
name = "Dog",
health = 100,
evolve = {
to = 4,
at = 10
},
check = true
},
[3] = {
name = "Tiger",
health = 300,
check = false,
info = "Evolves from Cat."
},
[4] = {
name = "Lion",
health = 300,
mountId = 40,
check = false,
info = "Evolves from Dog."
},
[5] = {
name = "Husky",
health = 150,
check = function(player) return player:getPremiumDays() > 0 end,
info = "Requires a premium account."
},
[6] = {
name = "Wolf",
health = 200,
evolve = {
to = 7,
at = 4
},
check = function(player) return player:getLevel() >= 10 end,
info = "Requires level 10."
},
[7] = {
name = "War Wolf",
health = 500,
evolve = {
to = 8,
at = 55
},
check = false,
info = "Evolves from Wolf."
},
[8] = {
name = "Werewolf",
health = 1000,
check = false,
info = "Evolves from War Wolf."
},
[9] = {
name = "Bear",
health = 300,
mountId = 3,
check = function(player) return player:isDruid() and player:getLevel() >= 10 end,
info = "Only available to druids above level 10."
},
[10] = {
name = "Panda",
health = 300,
mountId = 19,
check = function(player) return player:isDruid() and player:getLevel() >= 10 end,
info = "Only available to druids above level 10."
},
[11] = {
name = "Chicken",
health = 50,
check = true
},
[12] = {
name = "Sheep",
health = 50,
check = true
},
[13] = {
name = "Seagull",
health = 100,
check = function(player) return player:getPremiumDays() > 0 end,
info = "Requires a premium account."
},
[14] = {
name = "Parrot",
health = 100,
check = function(player) return player:getPremiumDays() > 0 end,
info = "Requires a premium account."
},
[15] = {
name = "Penguin",
health = 100,
check = function(player) return player:getPremiumDays() > 0 end,
info = "Requires a premium account."
},
[16] = {
name = "Elephant",
health = 300,
check = function(player) return player:getPremiumDays() > 0 and player:getLevel() >= 10 end,
contain = 5,
info = "Only available to Premium accounts above level 10."
},
[17] = {
name = "Dragon Hatchling",
health = 300,
evolve = {
to = 18,
at = 20
},
check = function(player) return player:getPremiumDays() > 0 and player:getLevel() >= 25 and player:isSorcerer() end,
info = "Only available to Premium Sorcerers above level 25."
},
[18] = {
name = "Dragon",
health = 1000,
check = false,
info = "Evolves from Dragon Hatchling."
}
},
STORAGE = {
TYPE = 10000,
UID = 10001,
LOSTHEALTH = 10002,
MAXHEALTH = 10003,
EXPERIENCE = 10004,
LEVEL = 10005
},
CONSTANS = {
STATUS_OK = 0,
STATUS_DOESNT_EXIST = -1,
STATUS_DEAD = -2,
STATUS_MOUNT = -3
}
}
--/ config
function Player.petSystemMessage(self, txt, talkType)
local playerId = self:getId()
talkType = (talkType == nil) and TALKTYPE_CHANNEL_O or talkType
local function eventMessage(playerId, text, talkType)
local player = Player(playerId)
if not player then
return false
end
player:sendChannelMessage('[PET-SYSTEM]', txt, talkType, PETS.CHANNELID)
end
addEvent(eventMessage, 150, playerId, text, talkType)
--self:sendChannelMessage('[PET-SYSTEM]', txt, ((talkType == nil) and TALKTYPE_CHANNEL_O or talkType), PETS.CHANNELID)
--self:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, '[PET-SYSTEM] '..txt)
return true
end
-- get
function Player.getPetExperience(self)
return self:getStorageValue(PETS.STORAGE.EXPERIENCE)
end
function Player.getPetLevel(self)
return self:getStorageValue(PETS.STORAGE.LEVEL)
end
function Player.getPetType(self)
return self:getStorageValue(PETS.STORAGE.TYPE)
end
function Player.getPetUid(self)
return self:getStorageValue(PETS.STORAGE.UID)
end
function Player.getPetMaxHealth(self)
return self:getStorageValue(PETS.STORAGE.MAXHEALTH)
end
function Player.getPetLostHealth(self)
return self:getStorageValue(PETS.STORAGE.LOSTHEALTH)
end
function Player.getPetMountId(self)
local petType = self:getPetType()
local mountId = PETS.IDENTIFICATION[petType].mountId
return mountId
end
-- set
function Player.setPetExperience(self, experience)
return self:setStorageValue(PETS.STORAGE.EXPERIENCE, experience)
end
function Player.setPetLevel(self, petLevel)
return self:setStorageValue(PETS.STORAGE.LEVEL, petLevel)
end
function Player.setPetType(self, petType)
return self:setStorageValue(PETS.STORAGE.TYPE, petType)
end
function Player.setPetUid(self, petUid)
return self:setStorageValue(PETS.STORAGE.UID, petUid)
end
function Player.setPetMaxHealth(self, health)
return self:setStorageValue(PETS.STORAGE.MAXHEALTH, health)
end
function Player.setPetLostHealth(self, health)
return self:setStorageValue(PETS.STORAGE.LOSTHEALTH, health)
end
-- other
function Player.doAddPet(self, petType)
local pet = Creature(self:getStorageValue(PETS.STORAGE.UID))
if pet then
return false
end
self:setPetUid(PETS.CONSTANS.STATUS_OK)
self:setPetExperience(0)
self:setPetLevel(1)
self:setPetType(petType)
self:setPetMaxHealth(PETS.IDENTIFICATION[petType].health)
self:setPetLostHealth(0)
if PETS.SYSTEM.MOUNTS then
local mountId = self:getPetMountId()
if mountId ~= nil and mountId ~= 0 then
self:addMount(mountId)
end
end
return true
end
function Player.doResetPet(self)
for _, i in pairs(PETS.STORAGE) do
self:setStorageValue(i, -1)
end
return true
end
function Player.doRemovePet(self)
local petUid = self:getPetUid()
local pet = Creature(petUid)
if not pet or not pet:isCreature() then
return true
end
local maxHealth = pet:getMaxHealth()
self:setPetMaxHealth(maxHealth)
self:setPetLostHealth(maxHealth - pet:getHealth() )
self:setPetUid(PETS.CONSTANS.STATUS_OK)
pet:remove()
if PETS.SYSTEM.MOUNTS then
local mountId = self:getPetMountId()
if mountId ~= nil then
self:addMount(mountId)
end
end
return true
end
function Player.doKillPet(self, removeBody)
if removeBody then
self:doRemovePet()
end
self:setPetUid(PETS.CONSTANS.STATUS_DEAD)
self:setPetLostHealth(0)
if PETS.SYSTEM.MOUNTS then
local mountId = self:getPetMountId()
if mountId ~= nil then
self:removeMount(mountId)
end
end
return true
end
function Player.summonPet(self, position)
local petUid = self:getPetUid()
local pet = Creature(petUid)
if pet and pet:isCreature() then
return false
end
if (Tile(position)):hasFlag(TILESTATE_PROTECTIONZONE) then
return false
end
if PETS.SYSTEM.MOUNTS then
local mountId = self:getPetMountId()
local currentMount = self:getOutfit()['lookMount']
if mountId ~= nil and currentMount ~= nil and currentMount ~= 0 and currentMount == mountId then
return false
end
end
local pet = Game.createMonster(PETS.PREFIX .. (PETS.IDENTIFICATION[self:getPetType()].name), position)
if pet then
position:sendMagicEffect(CONST_ME_TELEPORT)
pet:setMaster(self)
local maxHealth = self:getPetMaxHealth()
pet:setMaxHealth(maxHealth)
pet:addHealth(maxHealth - pet:getHealth() - self:getPetLostHealth() )
self:setPetUid( pet:getId() )
pet:setSkull(SKULL_GREEN)
pet:changeSpeed(PETS.CONFIG.sameSpeed and (self:getBaseSpeed() - pet:getBaseSpeed()) or 0)
for _, eventName in pairs({"PetDeath", "PetKill"}) do
pet:registerEvent(eventName)
end
if PETS.SYSTEM.TELEPORT then
pet:registerEvent("PetTeleport")
end
if PETS.SYSTEM.DUELS_ONLY then
pet:registerEvent("PetHealthChange")
end
if PETS.SYSTEM.MOUNTS then
local mountId = self:getPetMountId()
if mountId ~= nil then
self:removeMount(mountId)
end
end
return pet
end
return false
end
function getExpNeeded(level)
return ( (50 *level^3) -(150 *level^2) +(400 *level) )/3 *PETS.CONFIG.expMultipler
end
function Player.addPetExp(self, amount)
if self:getPetLevel() >= PETS.CONFIG.maxLevel then
return false
end
local totalExp = self:getPetExperience() + amount
self:setPetExperience(totalExp)
local petLevel, petType, petUid = self:getPetLevel(), self:getPetType(), self:getPetUid()
if totalExp >= getExpNeeded(petLevel + 1) then
local pet = Creature(petUid)
pet:setMaxHealth(pet:getMaxHealth() + (PETS.IDENTIFICATION[petType].hpAdd or PETS.CONFIG.standardHpAdd))
self:setPetLevel(petLevel +1)
self:petSystemMessage("Your pet "..PETS.IDENTIFICATION[petType].name.." has advanced to level "..(petLevel +1)..".")
if PETS.CONFIG.healOnLevelUp then
pet:addHealth( pet:getMaxHealth() )
end
if PETS.SYSTEM.EVOLUTION and (PETS.IDENTIFICATION[petType]).evolve and ((PETS.IDENTIFICATION[petType]).evolve.at <= (petLevel +1)) then
local position = pet:getPosition()
self:doRemovePet()
self:setPetType( (PETS.IDENTIFICATION[petType]).evolve.to)
self:setPetMaxHealth( (PETS.IDENTIFICATION[(PETS.IDENTIFICATION[petType]).evolve.to]).health )
self:setPetLostHealth(0)
self:petSystemMessage("Your pet "..(PETS.IDENTIFICATION[petType]).name.." has evolved to a "..((PETS.IDENTIFICATION[(PETS.IDENTIFICATION[petType]).evolve.to]).name)..".")
self:summonPet(position)
end
-- save max hp fix
self:setPetMaxHealth(pet:getMaxHealth())
end
return true
end
function Player.canGetPet(self, petId)
if self:getGroup():getId() >= 3 then
return true
end
if type(PETS.IDENTIFICATION[petId].check) == "function" then
return PETS.IDENTIFICATION[petId].check(self)
end
return PETS.IDENTIFICATION[petId].check
end
-- is Pet
function Player.isPet(self)
return false
end
function Npc.isPet(self)
return false
end
function Monster.isPet(self)
if self:isSummon() then
local owner = self:getMaster()
if owner:isPlayer() and owner:getPetUid() == self:getId() then
return true
end
end
return false
end