-
Notifications
You must be signed in to change notification settings - Fork 4
/
magical_items_lib.lua
1472 lines (1358 loc) · 54 KB
/
magical_items_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
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---------------------------------------------------------
-- MAGICAL ITEMS by Codex NG aka Yodex :)
---------------------------------------------------------
-- DROP THIS IN data/items/
---------------------------------------------------------
unpack = _VERSION == 'Lua 5.1' and unpack or table.unpack
EQ = {}
EQ.__index = EQ
setmetatable(EQ, {
__call = function(cls, ...)
return cls.new(...)
end,
})
function EQ.new()
local self = setmetatable({}, EQ)
self.conditions = {
['manashield'] = CONDITION_MANASHIELD,
['invisible'] = CONDITION_INVISIBLE,
['outfit'] = CONDITION_OUTFIT,
['haste'] = CONDITION_HASTE,
['paralyze'] = CONDITION_PARALYZE,
['regen'] = CONDITION_REGENERATION,
['attributes'] = CONDITION_ATTRIBUTES,
['light'] = CONDITION_LIGHT,
['soul'] = CONDITION_SOUL,
['fire'] = CONDITION_FIRE,
['energy'] = CONDITION_ENERGY,
['poison'] = CONDITION_POISON,
['drown'] = CONDITION_DROWN,
['freeze'] = CONDITION_FREEZING,
['dazzle'] = CONDITION_DAZZLED,
['cursed'] = CONDITION_CURSED,
['bleed'] = CONDITION_BLEEDING,
['combat physical'] = COMBAT_PHYSICALDAMAGE,
['combat energy'] = COMBAT_ENERGYDAMAGE,
['combat earth'] = COMBAT_EARTHDAMAGE,
['combat fire'] = COMBAT_FIREDAMAGE,
['combat undefined'] = COMBAT_UNDEFINEDDAMAGE,
['combat life'] = COMBAT_LIFEDRAIN,
['combat mana'] = COMBAT_MANADRAIN,
['combat heal'] = COMBAT_HEALING,
['combat drown'] = COMBAT_DROWNDAMAGE,
['combat ice'] = COMBAT_ICEDAMAGE,
['combat holy'] = COMBAT_HOLYDAMAGE,
['combat death'] = COMBAT_DEATHDAMAGE,
['defense physical'] = COMBAT_PHYSICALDAMAGE,
['defense energy'] = COMBAT_ENERGYDAMAGE,
['defesne earth'] = COMBAT_EARTHDAMAGE,
['defense fire'] = COMBAT_FIREDAMAGE,
['defense undefined'] = COMBAT_UNDEFINEDDAMAGE,
['defense life'] = COMBAT_LIFEDRAIN,
['defense mana'] = COMBAT_MANADRAIN,
['defense heal'] = COMBAT_HEALING,
['defense drown'] = COMBAT_DROWNDAMAGE,
['defense ice'] = COMBAT_ICEDAMAGE,
['defense holy'] = COMBAT_HOLYDAMAGE,
['defense death'] = COMBAT_DEATHDAMAGE
}
self.subtypes = {
["manashield"] = 1,
['invisible'] = 2,
["outfit"] = 3,
["haste"] = 4,
["regen"] = 5,
["attributes"] = 6,
["light"] = 7,
["soul"] = 8,
["fire"] = 9,
["energy"] = 10,
["poison"] = 11,
["drown"] = 12,
["freeze"] = 13,
["dazzle"] = 14,
["cursed"] = 15,
["bleed"] = 16,
["paralyze"] = 17,
['attack'] = 18,
['defense'] = 19,
['critical'] = 20,
['combat physical'] = 21,
['combat energy'] = 22,
['combat earth'] = 23,
['combat fire'] = 24,
['combat undefined'] = 25,
['combat life'] = 26,
['combat mana'] = 27,
['combat heal'] = 28,
['combat drown'] = 29,
['combat ice'] = 30,
['combat holy'] = 31,
['combat death'] = 32,
['defense physical'] = 33,
['defense energy'] = 34,
['defense earth'] = 35,
['defense fire'] = 36,
['defense undefined'] = 37,
['defense life'] = 38,
['defense mana'] = 39,
['defense heal'] = 41,
['defense drown'] = 42,
['defense ice'] = 43,
['defense holy'] = 44,
['defense death'] = 45,
['spells'] = 46,
['transform'] = 47,
}
self.spells = {}
self.slot = 1
self.name = ''
self.tier = 1
self.subid = {}
self.description = {}
self.const = {}
self.condition = {}
self.transform = {}
self.serialTable = {}
self.serial = ''
self.weapon = {}
self.words = {}
self.chance = 100
self.itemSlots = {}
self.shield = {}
self.reduction = {}
return self
end
function generateSerial(length)
local str = ''
for i = 1, length do
str = str .. '0|'
end
return str:sub(1, #str-1)
end
BASESERIAL = generateSerial(47)
function EQ.getSubType(self, sub)
return self.subtypes[sub]
end
function EQ.getAllSubTypes(self)
return self.subtypes
end
-- if we change this it will change all items associated with it
-- this is only used as a base value, do not use this on items
function EQ.setSerial(self, name)
if not self.serialTable[name] then
self.serialTable[name] = BASESERIAL
end
end
function EQ.getSerial(self, name)
return self.serialTable[name] and self.serialTable[name] or ''
end
-- x:setTier(slot, name, tier)
function EQ.setTier(self, slot, name, tier)
self.slot = slot
self.name = name
self.tier = tier
end
function EQ.updateTable(self, t, typ, val)
if not t[self.slot] then
t[self.slot] = {}
end
if not t[self.slot][self.name] then
t[self.slot][self.name] = {}
end
if not t[self.slot][self.name][typ] then
t[self.slot][self.name][typ] = {}
end
if not t[self.slot][self.name][typ][self.tier] then
t[self.slot][self.name][typ][self.tier] = val or {}
end
return t
end
function EQ.updateOtherTable(self, t, val)
if not t[self.slot] then
t[self.slot] = {}
end
if not t[self.slot][self.name] then
t[self.slot][self.name] = {}
end
if not t[self.slot][self.name][self.tier] then
t[self.slot][self.name][self.tier] = val or {}
end
return t
end
function EQ.updateDescription(self, name, type, tier)
if not self.description[name] then
self.description[name] = {}
end
if not self.description[name][type] then
self.description[name][type] = {}
end
if not self.description[name][type][tier] then
self.description[name][type][tier] = ''
end
end
function f(v)
if v and v ~= '' then
if tonumber(v) >= 0 then
return '+'..v
end
end
return v
end
function EQ.setSlots(item, slot)
local name = item:getName()
if not self.itemSlots[name] then
self.itemSlots[name] = {}
self.itemSlots[name].slot = slot
end
end
function EQ.sp(self, str, p)
local words = {}
for word in str:gmatch("([^"..p.."]+)") do
table.insert(words, word)
end
return words
end
function EQ.getArgs(self, arg, delimiter)
local t = {}
local s = self:sp(arg, "|")
for _, v in pairs(s) do
table.insert(t, self:sp(v, delimiter or ","))
end
return t
end
function EQ.updateFlags(self, str, index, replace)
local attr = {}
local i = 1
for value in str:gmatch("([^|]+)") do
if i == index then
table.insert(attr, replace)
else
table.insert(attr, value)
end
i = i + 1
end
return table.concat(attr, "|")
end
-- returns a number the tier value or position rather of the serial or text
function Player:getMagicItemTier(item, subtype)
local itemText = item:getAttribute(ITEM_ATTRIBUTE_TEXT)
itemText = itemText == '' and x:getSerial(item:getName()) or itemText
if itemText and itemText ~= '' then
local flags = x:getArgs(itemText)
local tier = flags[x:getSubType(subtype)]
if tier and next(tier) then
return tonumber(tier[1])
end
end
return 1
end
function Player:upradeItem(item, subtype, tier)
local t = tier or 1
local nextTier = self:getMagicItemTier(item, subtype) + t
if nextTier < self:getMaxTier(item, subtype) then
x:setMagicItemTier(item, subtype, nextTier)
end
end
-- this returns the description of all the buffs, damage type/reductions
function Player:getMagicItemDescription(item)
if not item:isItem() then
return ''
end
local itemText = item:getAttribute(ITEM_ATTRIBUTE_TEXT)
local name = item:getName()
itemText = (itemText and itemText ~= '') and itemText or x:getSerial(name)
if itemText and itemText ~= '' then
local subtypes, desc = x:getAllSubTypes(), {}
local flags = x:getArgs(itemText)
for flagName, flagIndex in pairs(subtypes) do
local tier = flags[flagIndex]
if tier and next(tier) then
tier = tonumber(tier[1])
if tier and tier ~= 0 then
print(name, flagName, tier)
desc[#desc+1] = x.description[name][flagName][tier]
end
end
end
return next(desc) and table.concat(desc) or ''
end
return ''
end
function Player:getMaxTier(item, subtype)
if item then
local name = item:getName()
local tiers = x.description[name][subtype]
if tiers and #tiers > 1 then
return #tiers
end
end
return 0
end
-- this method allows you to upgrade an item which uses this system
-- it will not work on items which are not defined in magical_items.lua
--[[
Example Usage:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
if target then
x:setMagicItemTier(target, 'attributes', 2)
end
return true
end
]]
-- x:setMagicItemTier(item, subtype, tier)
function EQ.setMagicItemTier(self, item, subtype, tier)
local index = self.subtypes[subtype]
if index and item then
local name = item:getName()
if name then
if item:getAttribute(ITEM_ATTRIBUTE_TEXT) == '' then
local attrText = self:getSerial(name)
if attrText and attrText ~= '' then
item:setAttribute(ITEM_ATTRIBUTE_TEXT, attrText)
else
return
end
end
if tier then
local text = item:getAttribute(ITEM_ATTRIBUTE_TEXT)
item:setAttribute(ITEM_ATTRIBUTE_TEXT, self:updateFlags(text, index, tier))
end
end
end
end
function EQ.getTier(self)
return self.tier
end
-- manashield does not stack or scale
-- x:manashield([description[, isCustomItem]])
function EQ.manashield(self, description, isCustomItem)
local slot = self.slot
local name = self.name
local tier = self.tier
local t = 'manashield'
self:setSerial(name)
self.condition = self:updateTable(self.condition, t)
self.const = self:updateTable(self.const, t)
self.subid = self:updateTable(self.subid, t, 0)
self:updateDescription(name, t, tier)
self.condition[slot][name][t][tier] = Condition(self.conditions[t], self.subid[slot][name][t][tier])
self.condition[slot][name][t][tier]:setTicks(-1)
self.const[slot][name][t][tier] = self.conditions[t]
self.description[name][t][tier] = (description or "\nYe who bears this mystical "..name.." is granted an ancient magical shield.")
if tier == 1 or isCustomItem then
self.serialTable[name] = self:updateFlags(self.serialTable[name], self:getSubType(t), tier)
end
end
-- invisible does not stack or scale
-- x:invisible([description[, isCustomItem]])
function EQ.invisible(self, description, isCustomItem)
local slot = self.slot
local name = self.name
local tier = self.tier
local t = 'invisible'
self:setSerial(name)
self.condition = self:updateTable(self.condition, t)
self.const = self:updateTable(self.const, t)
self.subid = self:updateTable(self.subid, t, 0)
self:updateDescription(name, t, tier)
self.condition[slot][name][t][tier] = Condition(self.conditions[t], self.subid[slot][name][t][tier])
self.condition[slot][name][t][tier]:setTicks(-1)
self.const[slot][name][t][tier] = self.conditions[t]
self.description[name][t][tier] = (description or "\nThose who adorn this magical "..name.." can slip into the shadows.")
if tier == 1 or isCustomItem then
self.serialTable[name] = self:updateFlags(self.serialTable[name], self:getSubType(t), tier)
end
end
-- outfit does not stack or scale
-- the outfitIndex corresponds to both v & d table's index
-- x:outfit(outfitIndex[, description[, isCustomItem]])
function EQ.outfit(self, lt, description, isCustomItem)
local slot = self.slot
local name = self.name
local tier = self.tier
local t = 'outfit'
self:setSerial(name)
local v = { -- value
-- these are examples, list all the outfits u want to use for all the items
[1] = {{lookType = 116}}, -- creature lookType
[2] = {1, 899}, -- player outfits
[3] = 2175, -- item lookTypes
[4] = {0, 230, 0, 0, 0, 0, 0} -- not sure yet :p
}
self.condition = self:updateTable(self.condition, t)
self.const = self:updateTable(self.const, t)
self.subid = self:updateTable(self.subid, t, 0)
self:updateDescription(name, t, tier)
self.condition[slot][name][t][tier] = Condition(self.conditions[t], self.subid[slot][name][t][tier])
local value = type(v[lt or 1]) ~= 'table' and {v[lt or 1]} or v[lt or 1]
local d = { -- examples
[1] = "\nPutting on this "..name.." will mask your true identity.",
[2] = "\nBy dressing "..name.." your true identity will be masked.",
[3] = "\nAdorning the "..name.." grants the wearer an illusion of a ".. ItemType(v[3]):getName() .. ".",
[4] = "\nPutting on this "..name.." will mask your true identity."
}
self.condition[slot][name][t][tier]:setOutfit(unpack(value))
self.condition[slot][name][t][tier]:setTicks(-1)
self.const[slot][name][t][tier] = self.conditions[t]
self.description[name][t][tier] = (description or d[lt])
if tier == 1 or isCustomItem then
self.serialTable[name] = self:updateFlags(self.serialTable[name], self:getSubType(t), tier)
end
end
-- the hasteIndex corresponds to the v table's index
-- x:haste(hasteIndex[, description[, isCustomItem]])
function EQ.haste(self, h, description, isCustomItem)
local slot = self.slot
local name = self.name
local tier = self.tier
local t = 'haste'
local v = { -- put all your haste formulas here
{0.3, -24, 0.3, -24}, -- haste
{0.7, -56, 0.7, -56}, -- strong haste
{0.8, -64, 0.8, -64}, -- swift foot
{0.9, -72, 0.9, -72}, -- charge
}
self:setSerial(name)
self.condition = self:updateTable(self.condition, t)
self.const = self:updateTable(self.const, t)
self.subid = self:updateTable(self.subid, t, 1)
self:updateDescription(name, t, tier)
self.condition[slot][name][t][tier] = Condition(self.conditions[t], self.subid[slot][name][t][tier])
local value = type(v[h]) == 'function' and {v[h]()} or v[h]
self.condition[slot][name][t][tier]:setFormula(unpack(value))
self.condition[slot][name][t][tier]:setTicks(-1)
self.const[slot][name][t][tier] = self.conditions[t]
self.description[name][t][tier] = (description or "\nPutting on this "..name.." will increase your speed significantly.")
if tier == 1 or isCustomItem then
self.serialTable[name] = self:updateFlags(self.serialTable[name], self:getSubType(t), tier)
end
end
-- the paralyzeIndex corresponds to the v table's index
-- x:paralyze(paralyzeIndex[, description[, isCustomItem]])
function EQ.paralyze(self, p, description, isCustomItem)
local slot = self.slot
local name = self.name
local tier = self.tier
local t = 'paralyze'
self:setSerial(name)
local v = { -- put all your paralyze formulas here
{-1, 80, -1, 80},
{-1, 80, -1, 80},
function() return -1, 80, -1, 80 end,
{-1, 80, -1, 80},
{-1, 80, -1, 80},
}
self.condition = self:updateTable(self.condition, t)
self.const = self:updateTable(self.const, t)
self.subid = self:updateTable(self.subid, t, slot)
self:updateDescription(name, t, tier)
self.condition[slot][name][t][tier] = Condition(self.conditions[t], self.subid[slot][name][t][tier])
local value = type(v[p]) == 'function' and {v[p]()} or v[p]
self.condition[slot][name][t][tier]:setFormula(unpack(value))
self.condition[slot][name][t][tier]:setTicks(-1)
self.const[slot][name][t][tier] = self.conditions['paralyze']
self.description[name][t][tier] = (description or "")
if tier == 1 or isCustomItem then
self.serialTable[name] = self:updateFlags(self.serialTable[name], self:getSubType(t), tier)
end
end
function capitalize(str)
return str:gsub("(%l)(%w*)", function(a, b) return string.upper(a)..b end)
end
function tableconcat(a, b, d)
local l = ''
for i = 1, #a do
l = l .. '[' ..capitalize(a[i]) .. d .. (type(b) == 'table' and b[i] or b) .. '] '
end
return l
end
-- both attributeType & attribute can be a table/variable, if attributeType is a variable so should attribute
-- x:regen(attributeType, attribute[, description[, isCustomItem]])
function EQ.regen(self, typ, attribute, description, isCustomItem)
local slot = self.slot
local name = self.name
local tier = self.tier
local t = 'regen'
self:setSerial(name)
local desc = ''
local v = {
['hp'] = CONDITION_PARAM_HEALTHGAIN,
['mana'] = CONDITION_PARAM_MANAGAIN
}
self.condition = self:updateTable(self.condition, t)
self.const = self:updateTable(self.const, t)
self.subid = self:updateTable(self.subid, t, slot)
self:updateDescription(name, t, tier)
self.condition[slot][name][t][tier] = Condition(self.conditions[t], self.subid[slot][name][t][tier])
if type(typ) == 'table' then
for i = 1, #typ do
self.condition[slot][name][t][tier]:setParameter(v[typ[i]], type(attribute) == 'table' and attribute[i] or attribute)
end
desc = tableconcat(typ, attribute, ':')
else
self.condition[slot][name][t][tier]:setParameter(v[typ], attribute)
desc = '['..capitalize(typ) .. ":" .. attribute..'] '
end
self.condition[slot][name][t][tier]:setTicks(-1)
self.const[slot][name][t][tier] = self.conditions[t]
self.description[name][t][tier] = (description or "\nWearing this "..name.." will grant the bearer a boost in " .. desc .."regen.")
if tier == 1 or isCustomItem then
self.serialTable[name] = self:updateFlags(self.serialTable[name], self:getSubType(t), tier)
end
end
-- both type and attribute can be a table/variable, if type is not a table then attribute has to be a variable
-- x:attributes(type, attribute[, description[, isCustomItem]])
function EQ.attributes(self, typ, attribute, description, isCustomItem)
local slot = self.slot
local name = self.name
local tier = self.tier
local t = 'attributes'
self:setSerial(name)
local desc = ''
local v = {
['melee'] = CONDITION_PARAM_SKILL_MELEE,
['fist'] = CONDITION_PARAM_SKILL_FIST,
['club'] = CONDITION_PARAM_SKILL_CLUB,
['sword'] = CONDITION_PARAM_SKILL_SWORD,
['axe'] = CONDITION_PARAM_SKILL_AXE,
['distance'] = CONDITION_PARAM_SKILL_DISTANCE,
['shielding'] = CONDITION_PARAM_SKILL_SHIELD,
['fishing'] = CONDITION_PARAM_SKILL_FISHING,
['max health'] = CONDITION_PARAM_STAT_MAXHITPOINTS,
['max mana'] = CONDITION_PARAM_STAT_MAXMANAPOINTS,
['magic'] = CONDITION_PARAM_STAT_MAGICPOINTS,
['max health%'] = CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT,
['max mana%'] = CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT,
['magic%'] = CONDITION_PARAM_STAT_MAGICPOINTSPERCENT,
['melee%'] = CONDITION_PARAM_SKILL_MELEEPERCENT,
['fist%'] = CONDITION_PARAM_SKILL_FISTPERCENT,
['club%'] = CONDITION_PARAM_SKILL_CLUBPERCENT,
['sword%'] = CONDITION_PARAM_SKILL_SWORDPERCENT,
['axe%'] = CONDITION_PARAM_SKILL_AXEPERCENT,
['distance%'] = CONDITION_PARAM_SKILL_DISTANCEPERCENT,
['shield%'] = CONDITION_PARAM_SKILL_SHIELDPERCENT,
['fishing%'] = CONDITION_PARAM_SKILL_FISHINGPERCENT,
}
self.condition = self:updateTable(self.condition, t)
self.const = self:updateTable(self.const, t)
self.subid = self:updateTable(self.subid, t, slot)
self:updateDescription(name, t, tier)
self.condition[slot][name][t][tier] = Condition(self.conditions[t], self.subid[slot][name][t][tier])
if type(typ) == 'table' then
for i = 1, #typ do
self.condition[slot][name][t][tier]:setParameter(v[typ[i]], type(attribute) == 'table' and attribute[i] or attribute)
end
desc = tableconcat(typ, attribute, ':')
else
self.condition[slot][name][t][tier]:setParameter(v[typ], attribute)
desc = '['..capitalize(typ) .. ":" .. attribute..'] '
end
self.condition[slot][name][t][tier]:setTicks(-1)
self.const[slot][name][t][tier] = self.conditions[t]
self.description[name][t][tier] = (description or "\nWearing this "..name.." will grant the bearer these attributes " .. desc .."in stats.")
if tier == 1 or isCustomItem then
self.serialTable[name] = self:updateFlags(self.serialTable[name], self:getSubType(t), tier)
end
end
-- color is anything in the v table, level is a range value of 1 being the lowest and 8 possibly being the highest
-- x:light([color[, level[, description[, isCustomItem]]]])
function EQ.light(self, color, level, description, isCustomItem)
local slot = self.slot
local name = self.name
local tier = self.tier
local t = 'light'
self:setSerial(name)
local v = {
["blue"] = 5,
["light green"] = 30,
['light blue'] = 35,
['maya blue'] = 95,
['dark red'] = 108,
['light grey'] = 129,
['sky blue'] = 143,
['purple'] = 155,
['red'] = 180,
['orange'] = 198,
['yellow'] = 210,
['white'] = 215,
}
self.condition = self:updateTable(self.condition, t)
self.const = self:updateTable(self.const, t)
self.subid = self:updateTable(self.subid, t, slot)
self:updateDescription(name, t, tier)
self.condition[slot][name][t][tier] = Condition(self.conditions[t], self.subid[slot][name][t][tier])
self.condition[slot][name][t][tier]:setParameter(CONDITION_PARAM_LIGHT_LEVEL, level or 8)
self.condition[slot][name][t][tier]:setParameter(CONDITION_PARAM_LIGHT_COLOR, v[color] or v['yellow'])
self.condition[slot][name][t][tier]:setTicks((60 * 1000) * 60 * 24)
self.const[slot][name][t][tier] = self.conditions[t]
self.description[name][t][tier] = (description or "\nThis "..name.." is inbued with the power of a mighty "..(color or "yellow" ).." star.")
if tier == 1 or isCustomItem then
self.serialTable[name] = self:updateFlags(self.serialTable[name], self:getSubType(t), tier)
end
end
-- gain is how much soul to gain and ticks is how often to gain them
-- x:soul(gain, ticks[, description[, isCustomItem]])
function EQ.soul(self, gain, ticks, description, isCustomItem)
local slot = self.slot
local name = self.name
local tier = self.tier
local t = 'soul'
self:setSerial(name)
local tickstime = (ticks * 1000)
self.condition = self:updateTable(self.condition, t)
self.const = self:updateTable(self.const, t)
self.subid = self:updateTable(self.subid, t, slot)
self:updateDescription(name, t, tier)
self.condition[slot][name][t][tier] = Condition(self.conditions[t], self.subid[slot][name][t][tier])
self.condition[slot][name][t][tier]:setParameter(CONDITION_PARAM_SOULGAIN, value)
self.condition[slot][name][t][tier]:setParameter(CONDITION_PARAM_SOULTICKS, tickstime)
self.condition[slot][name][t][tier]:setTicks(-1)
self.const[slot][name][t][tier] = self.conditions[t]
self.description[name][t][tier] = (description or "\nThe "..name.." grants the bearer [Soul:"..value.."].")
if tier == 1 or isCustomItem then
self.serialTable[name] = self:updateFlags(self.serialTable[name], self:getSubType(t), tier)
end
end
-- time, round or interval can be a table/variable, if time is a variable the rest should be aswell
-- this can not be applied to weapon damage... yet ;)
-- x:dot(time, round, interval, damage[, description[, isCustomItem]])
function EQ.dot(self, t, round, interval, damage, description, isCustomItem)
local slot = self.slot
local name = self.name
local tier = self.tier
local desc = ''
self:setSerial(name)
self:updateDescription(name, t, tier)
if type(t) == 'table' then
for i = 1, #t do
self.condition = self:updateTable(self.condition, t[i])
self.const = self:updateTable(self.const, t[i])
self.subid = self:updateTable(self.subid, t[i], slot)
self.condition[slot][name][t[i]][tier] = Condition(self.conditions[t[i]], self.subid[slot][name][t[i]][tier])
self.condition[slot][name][t[i]][tier]:addDamage( (type(round) == 'table' and round[i] or round), (type(interval) == 'table' and interval[i] or interval), (type(damage) == 'table' and damage[i] or damage) )
self.const[slot][name][t[i]][tier] = self.conditions[t[i]]
if tier == 1 or isCustomItem then
self.serialTable[name] = self:updateFlags(self.serialTable[name], self:getSubType(t[i]), tier)
end
end
desc = tableconcat(t, damage, ':')
else
self.condition = self:updateTable(self.condition, t)
self.const = self:updateTable(self.const, t)
self.subid = self:updateTable(self.subid, t, slot)
self.condition[slot][name][t][tier] = Condition(self.conditions[t], self.subid[slot][name][t][tier])
self.condition[slot][name][t][tier]:addDamage(round, interval, damage)
self.const[slot][name][t][tier] = self.conditions[t]
if tier == 1 or isCustomItem then
self.serialTable[name] = self:updateFlags(self.serialTable[name], self:getSubType(t), tier)
end
desc = '['..capitalize(t) .. ":" .. damage ..'] '
end
self.description[name][t][tier] = (description or "\nYe who adorns this "..name.."is doomed to forever be cursed in, " .. desc .."damage.")
end
damageTypes = {
[1] = "physical damage",
[2] = 'energy damage',
[4] = 'poison damage',
[8] = 'fire damage',
[16] = 'undefined damage',
[32] = 'life drain',
[64] = 'mana drain',
[128] = 'healing',
[256] = 'drowning damage',
[512] = 'ice damage',
[1024] = 'holy damage',
[2048] = 'death damage',
}
-- manashield doesn't seem to work like it use to, this is the reason for this code
function EQ.hasManashield(self, cid, aid, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
local creature = Creature(cid)
local attacker = Creature(aid)
if creature and creature:isPlayer() then
if creature:getCondition(CONDITION_MANASHIELD) then
local mana = 0
local total = primaryDamage + secondaryDamage
local test = creature:getMana()
if total > 0 and test > total then
local thing = (attacker and attacker:isCreature()) and 'an attack by a ' .. attacker:getName():lower() or damageTypes[primaryType]
local text = "You lose "..total.." mana points due to "..thing.."."
if primaryDamage ~= 0 then
mana = creature:getMana()
if mana >= primaryDamage then
creature:addMana(-primaryDamage)
primaryDamage = 0
else
creature:addMana(-mana)
primaryDamage = primaryDamage - mana
end
end
if secondaryDamage ~= 0 then
mana = creature:getMana()
if mana >= secondaryDamage then
creature:addMana(-secondaryDamage)
secondaryDamage = 0
else
creature:addMana(-mana)
secondaryDamage = secondaryDamage - mana
end
end
creature:sendTextMessage(MESSAGE_DAMAGE_RECEIVED, text, creature:getPosition(), total, TEXTCOLOR_PURPLE)
creature:getPosition():sendMagicEffect(CONST_ME_LOSEENERGY)
else
if primaryDamage > 0 then
if primaryDamage >= test then
creature:addMana(-primaryDamage)
primaryDamage = primaryDamage - test
else
creature:addMana(-primaryDamage)
primaryDamage = test - primaryDamage
end
test = primaryDamage
end
if secondaryDamage > 0 then
if secondaryDamage >= test then
creature:addMana(-secondaryDamage)
secondaryDamage = secondaryDamage - test
else
creature:addMana(-secondaryDamage)
secondaryDamage = test - secondaryDamage
end
end
end
end
self:autoHeal(creature:getId(), nil, 'mana')
end
return primaryDamage, primaryType, secondaryDamage, secondaryType, origin
end
combat_t = {
['combat physical'] = 21,
['combat energy'] = 22,
['combat earth'] = 23,
['combat fire'] = 24,
['combat undefined'] = 25,
['combat life'] = 26,
['combat mana'] = 27,
['combat heal'] = 28,
['combat drown'] = 29,
['combat ice'] = 30,
['combat holy'] = 31,
['combat death'] = 32
}
combat_const = {
['combat physical'] = COMBAT_PHYSICALDAMAGE,
['combat energy'] = COMBAT_ENERGYDAMAGE,
['combat earth'] = COMBAT_EARTHDAMAGE,
['combat fire'] = COMBAT_FIREDAMAGE,
['combat undefined'] = COMBAT_UNDEFINEDDAMAGE,
['combat life'] = COMBAT_LIFEDRAIN,
['combat mana'] = COMBAT_MANADRAIN,
['combat heal'] = COMBAT_HEALING,
['combat drown'] = COMBAT_DROWNDAMAGE,
['combat ice'] = COMBAT_ICEDAMAGE,
['combat holy'] = COMBAT_HOLYDAMAGE,
['combat death'] = COMBAT_DEATHDAMAGE
}
function EQ.updateWeaponTable(self, primaryType, secondaryType, primaryDamage, secondaryDamage)
if not self.weapon[self.name] then
self.weapon[self.name] = {}
end
if primaryType then
if not self.weapon[self.name][primaryType] then
self.weapon[self.name][primaryType] = {}
end
if not self.weapon[self.name][primaryType][self.tier] then
self.weapon[self.name][primaryType][self.tier] = {
primaryType = combat_const[primaryType] or nil,
primaryDamage = primaryDamage or 0
}
end
end
if secondaryType then
if not self.weapon[self.name][secondaryType] then
self.weapon[self.name][secondaryType] = {}
end
if not self.weapon[self.name][secondaryType][self.tier] then
self.weapon[self.name][secondaryType][self.tier] = {
secondaryType = combat_const[secondaryType] or nil,
secondaryDamage = secondaryDamage or 0
}
end
end
end
-- x:directDamage(primaryType, primaryValue, secondaryType, secondaryValue, isCustomItem)
function EQ.directDamage(self, primaryType, primaryValue, secondaryType, secondaryValue, isCustomItem)
local slot = self.slot
local name = self.name
local tier = self.tier
local chance = chance or 100
local words = words or {}
local cid = cid or 0
local desc = '\nAttack Damage '
self:setSerial(name)
local d = {
['combat physical'] = "Physical: ",
['combat energy'] = "Energy: ",
['combat earth'] = "Earth: ",
['combat fire'] = "Fire: ",
['combat undefined'] = "Undefined: ",
['combat life'] = "Life: ",
['combat mana'] = "Mana: ",
['combat heal'] = "Heal: ",
['combat drown'] = "Drown: ",
['combat ice'] = "Ice: ",
['combat holy'] = "Holy: ",
['combat death'] = "Death: ",
}
self:updateWeaponTable(primaryType, secondaryType, primaryValue, secondaryValue)
if primaryType and primaryValue then
self:updateDescription(name, primaryType, tier)
self.description[name][primaryType][tier] = '\nPD [' .. d[primaryType] .. f(primaryValue) .. ']'
if tier == 1 or isCustomItem then
self.serialTable[name] = self:updateFlags(self.serialTable[name], combat_t[primaryType], tier)
end
end
if secondaryType and secondaryValue then
self:updateDescription(name, secondaryType, tier)
self.description[name][secondaryType][tier] = '\nSD [' .. d[secondaryType] .. f(secondaryValue) .. ']'
if tier == 1 or isCustomItem then
self.serialTable[name] = self:updateFlags(self.serialTable[name], combat_t[secondaryType], tier)
end
end
end
defense_const = {
['defense physical'] = COMBAT_PHYSICALDAMAGE,
['defense energy'] = COMBAT_ENERGYDAMAGE,
['defense earth'] = COMBAT_EARTHDAMAGE,
['defense fire'] = COMBAT_FIREDAMAGE,
['defense undefined'] = COMBAT_UNDEFINEDDAMAGE,
['defense life'] = COMBAT_LIFEDRAIN,
['defense mana'] = COMBAT_MANADRAIN,
['defense heal'] = COMBAT_HEALING,
['defense drown'] = COMBAT_DROWNDAMAGE,
['defense ice'] = COMBAT_ICEDAMAGE,
['defense holy'] = COMBAT_HOLYDAMAGE,
['defense death'] = COMBAT_DEATHDAMAGE
}
function EQ.updateDefenseTable(self, primaryType, secondaryType, primaryDamage, secondaryDamage)
if not self.shield[self.name] then
self.shield[self.name] = {}
end
if primaryType then
if not self.shield[self.name][primaryType] then
self.shield[self.name][primaryType] = {}
end
if not self.shield[self.name][primaryType][self.tier] then
self.shield[self.name][primaryType][self.tier] = {
primaryType = defense_const[primaryType] or nil,
primaryDamage = primaryDamage or 0
}
end
end
if secondaryType then
if not self.shield[self.name][secondaryType] then
self.shield[self.name][secondaryType] = {}
end
if not self.shield[self.name][secondaryType][self.tier] then
self.shield[self.name][secondaryType][self.tier] = {
secondaryType = defense_const[secondaryType] or nil,
secondaryDamage = secondaryDamage or 0
}
end
end
end
defense_t = {
['defense physical'] = 33,
['defense energy'] = 34,
['defense earth'] = 35,
['defense fire'] = 36,
['defense undefined'] = 37,
['defense life'] = 38,
['defense mana'] = 39,
['defense heal'] = 41,
['defense drown'] = 42,
['defense ice'] = 43,
['defense holy'] = 44,
['defense death'] = 45,
}
defenseTypes = {
[1] = "defense physical",
[2] = 'defense energy',
[4] = 'defense poison',
[8] = 'defense fire',
[16] = 'defense undefined',
[32] = 'defense life',
[64] = 'defense mana',
[128] = 'defense heal',
[256] = 'defense drown',
[512] = 'defense ice',
[1024] = 'defense holy',
[2048] = 'defense death',
}
-- x:damageReduction(primaryType, secondaryType, primaryValue, secondaryValue, isCustomItem)
function EQ.damageReduction(self, primaryType, primaryValue, secondaryType, secondaryValue, isCustomItem)
local slot = self.slot
local name = self.name
local tier = self.tier
local chance = chance or 100
local words = words or {}
local cid = cid or 0
local desc = '\nDamage Reduction '
self:setSerial(name)
local d = {
['defense physical'] = "Physical: ",
['defense energy'] = "Energy: ",
['defense earth'] = "Earth: ",
['defense fire'] = "Fire: ",
['defense undefined'] = "Undefined: ",
['defense life'] = "Life: ",
['defense mana'] = "Mana: ",
['defense heal'] = "Heal: ",
['defense drown'] = "Drown: ",
['defense ice'] = "Ice: ",
['defense holy'] = "Holy: ",
['defense death'] = "Death: ",
}
self:updateDefenseTable(primaryType, secondaryType, primaryValue, secondaryValue)
if primaryType and primaryValue then
self:updateDescription(name, primaryType, tier)
self.description[name][primaryType][tier] = '\nPDR[' .. d[primaryType] .. f(primaryValue) .. ']'
if tier == 1 or isCustomItem then
self.serialTable[name] = self:updateFlags(self.serialTable[name], defense_t[primaryType], tier)
end