-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNPCFollowersSkills.lua
426 lines (355 loc) · 9.48 KB
/
NPCFollowersSkills.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
--------------------------------
---- Hireling's skills ----
--------------------------------
local NPCBonuses = {}
NPCBonuses.Skills = {}
NPCBonuses.Stats = {}
NPCBonuses.Gold = nil
vars.ProfUsed = vars.ProfUsed or {}
local ProfUsed = vars.ProfUsed
---- Service functions
local function SetProfUsed(NPC)
local Prof = NPC or GetCurrentNPC()
ProfUsed[Prof] = Game.DayOfMonth
end
local function CanUseProf(NPC)
local Prof = NPC or GetCurrentNPC()
local State = ProfUsed[Prof]
--去掉每天一次的限制
-- return State == nil or State ~= Game.DayOfMonth
return true
end
local function CastFollowersSpell(Spell, Skill, Mastery)
if CanUseProf(NPC) then
CastSpellDirect(Spell,Skill,Mastery)
SetProfUsed(NPC)
Message(Game.GlobalTxt[569])
else
Message(Game.GlobalTxt[561])
end
end
---- Skill bonuses ----
-- SkillID = {ProfID = Bonus}
local SkillBonuses
local function CountSkillBonus(skill)
local Bonus = SkillBonuses[skill]
local res = 0
if Bonus then
for k,v in pairs(vars.NPCFollowers) do
local Amount = Bonus[Game.NPC[v].Profession]
if Amount then
res = res + Amount
end
end
end
NPCBonuses.Skills[skill] = res
return res
end
function events.GetSkill(t)
local Skill, Mas = SplitSkill(t.Result)
Skill = Skill + (NPCBonuses.Skills[t.Skill] or CountSkillBonus(t.Skill))
t.Result = JoinSkill(Skill, Mas)
end
---- Crossing map bonuses ----
-- ProfID == Amount of days to subtract
local CrossMapBonuses
local function CountCrossMapBonus()
local res = 0
for k,v in pairs(vars.NPCFollowers) do
local Bonus = CrossMapBonuses[Game.NPC[v].Profession]
if Bonus then
res = res + Bonus
end
end
return res
end
function events.WalkToMap(t)
t.Days = math.max(1, t.Days-CountCrossMapBonus())
end
---- Boat/stable travels bonuses
local BoatBonuses
local StableBonuses
local function CountBSBonuses(t)
local res = 0
for k,v in pairs(vars.NPCFollowers) do
local Bonus = t[Game.NPC[v].Profession]
if Bonus then
res = res + Bonus
end
end
return res
end
function events.GetTravelDaysCost(t)
local Type = Game.Houses[t.House].Type
if Type == 27 then
t.Days = math.max(1, t.Days - CountBSBonuses(StableBonuses))
else
t.Days = math.max(1, t.Days - CountBSBonuses(BoatBonuses))
end
end
---- Food consumption
-- ProfID == Amount to subtract
local FoodConBonuses
function events.CalcRestFoodCost(t)
for k,v in pairs(vars.NPCFollowers) do
local Bonus = FoodConBonuses[Game.NPC[v].Profession]
if Bonus then
t.Amount = math.max(1, t.Amount - Bonus)
end
end
end
---- Stat bonuses
-- StatID = {ProfID = Bonus}
local StatsBonuses
local function CountStatBonus(stat)
local Bonus = StatsBonuses[stat]
local res = 0
if Bonus then
for k,v in pairs(vars.NPCFollowers) do
local Amount = Bonus[Game.NPC[v].Profession]
if Amount then
res = res + Amount
end
end
end
NPCBonuses.Stats[stat] = res
return res
end
function events.CalcStatBonusByItems(t)
t.Result = t.Result + (NPCBonuses.Stats[t.Stat] or CountStatBonus(t.Stat))
t.Result = t.Result
end
---- Constant party buffs
local TimerPeriod = 8*const.Minute
-- ProfID = {Buff = PartyBuff, Skill = , Power = }
local FollowersBuffs
local function SetBuffs()
for k,v in pairs(vars.NPCFollowers) do
local Buff = FollowersBuffs[Game.NPC[v].Profession]
if Buff then
local cBuff = Party.SpellBuffs[Buff.Buff]
cBuff.ExpireTime = Game.Time + TimerPeriod + const.Minute
cBuff.Power = Buff.Power
cBuff.Skill = Buff.Skill
end
end
end
function events.AfterLoadMap()
Timer(SetBuffs, TimerPeriod, true)
end
---- Repair items
function events.CanRepairItem(t)
local Type = Game.ItemsTxt[t.Item.Number].EquipStat + 1
if Type >= 4 and Type <= 10 then -- armors
if NPCFollowers.HaveProfession(2) then
t.CanRepair = true
end
elseif Type >= 11 and Type <= 18 then -- magic items
if NPCFollowers.HaveProfession(3) then
t.CanRepair = true
end
else -- weapons
if NPCFollowers.HaveProfession(1) then
t.CanRepair = true
end
end
end
------------------------------------------------
---- Payments
local GoldFindBonuses = {}
local function CountGoldBonus()
local res = 0
for k,v in pairs(vars.NPCFollowers) do
local Bonus = GoldFindBonuses[Game.NPC[v].Profession]
if Bonus then
res = res + Bonus
end
end
NPCBonuses.Gold = res
return res
end
NPCFollowers.LastGoldTaken = 0
function events.BeforeGotGold(t)
-- Gold bonuses
t.Amount = t.Amount + t.Amount*(NPCBonuses.Gold or CountGoldBonus())
-- Payments
if Game.CurrentScreen == 13 then
NPCFollowers.LastGoldTaken = 0
else
NPCFollowers.LastGoldTaken = NPCFollowers.GetTotalFee(t.Amount)
t.Amount = math.max(0, t.Amount - NPCFollowers.LastGoldTaken)
end
end
----
local function NeedBonusesRecount(topic)
if not topic or not NPCFollowers.HireState then
NPCBonuses.Skills = {}
NPCBonuses.Stats = {}
NPCBonuses.Gold = nil
end
end
NPCFollowers.NeedBonusesRecount = NeedBonusesRecount
evt.Global[NPCFollowers.DismissNPCTopic] = NeedBonusesRecount
evt.Global[NPCFollowers.HireNPCTopic] = NeedBonusesRecount
------------------------------------------------
---- Values ----
------------------------------------------------
---- Find gold bonuses
GoldFindBonuses = {[31] = 0.10, [32] = 0.20, [45] = 0.10}
---- Skill bonuses
SkillBonuses = {
[const.Skills.Learning] = {[4] = 5, [13] = 10, [14] = 15},
[const.Skills.Staff] = {[15] = 2, [16] = 3, [46] = 2},
[const.Skills.Sword] = {[15] = 2, [16] = 3, [46] = 2},
[const.Skills.Dagger] = {[15] = 2, [16] = 3, [46] = 2},
[const.Skills.Axe] = {[15] = 2, [16] = 3, [46] = 2},
[const.Skills.Spear] = {[15] = 2, [16] = 3, [46] = 2},
[const.Skills.Bow] = {[15] = 2, [16] = 3, [46] = 2},
[const.Skills.Mace] = {[15] = 2, [16] = 3, [46] = 2},
[const.Skills.Leather] = {[46] = 2},
[const.Skills.Chain] = {[46] = 2},
[const.Skills.Plate] = {[46] = 2},
[const.Skills.Fire] = {[17] = 2, [18] = 3, [19] = 4},
[const.Skills.Air] = {[17] = 2, [18] = 3, [19] = 4},
[const.Skills.Water] = {[17] = 2, [18] = 3, [19] = 4},
[const.Skills.Earth] = {[17] = 2, [18] = 3, [19] = 4},
[const.Skills.Spirit] = {[17] = 2, [18] = 3, [19] = 4},
[const.Skills.Mind] = {[17] = 2, [18] = 3, [19] = 4},
[const.Skills.Body] = {[17] = 2, [18] = 3, [19] = 4},
[const.Skills.Light] = {[17] = 2, [18] = 3, [19] = 4},
[const.Skills.Dark] = {[17] = 2, [18] = 3, [19] = 4},
[const.Skills.Merchant] = {[20] = 4, [21] = 6},
[const.Skills.DisarmTraps] = {[25] = 4, [26] = 6},
[const.Skills.Perception] = {[22] = 6, [47] = 5},
[const.Skills.IdentifyItem] = {[4] = JoinSkill(10,4)}
}
------------------------------------------------
---- Crossing map bonuses
-- ProfID == Amount of days to subtract
CrossMapBonuses = {
[5] = 1,
[6] = 2,
[7] = 3,
[44] = 1
}
------------------------------------------------
---- Travel days bonuses
-- ProfID == Amount of days to subtract
BoatBonuses = {[8] = 2, [9] = 3, [44] = 1, [45] = 2}
StableBonuses = {[35] = 2, [44] = 1}
------------------------------------------------
---- Food consumption
FoodConBonuses = {
[29] = 1,
[30] = 2
}
------------------------------------------------
---- Stat bonuses
-- StatID = {ProfID = Bonus}
StatsBonuses = {
[const.Stats.AirResistance] = {[37] = 20},
[const.Stats.FireResistance] = {[37] = 20},
[const.Stats.WaterResistance] = {[37] = 20},
[const.Stats.EarthResistance] = {[37] = 20},
[const.Stats.Luck] = {[27] = 10, [28] = 20}
}
------------------------------------------------
---- Constant party buffs
-- ProfID = {Buff = PartyBuff, Skill = , Power = }
FollowersBuffs = {
[38] = {Buff = const.PartyBuff.WizardEye, Skill = 4, Power = 2},
-- 追風大師加上巫師之眼
[39] = {Buff = const.PartyBuff.WizardEye, Skill = 4, Power = 4},
-- 護門大師加上火炬
[41] = {Buff = const.PartyBuff.TorchLight, Skill = 4, Power = 4}
}
------------------------------------------------
---- Follower's skill-topic functions
local function MakeFollowersFood()
local cNPC = GetCurrentNPC()
if not cNPC then
return
end
local Amount = Game.NPC[cNPC].Profession == 34 and 2 or 1
if Party.Food > 14 then
Message(Game.GlobalTxt[140])
elseif CanUseProf() then
evt.ForPlayer("Current").Add{"Food", Amount}
SetProfUsed()
Message(Game.GlobalTxt[569])
else
Message(Game.GlobalTxt[561])
end
end
local function HealFollowersParty()
local cNPC = GetCurrentNPC()
if not cNPC then
return
end
if CanUseProf() then
local Prof = Game.NPC[cNPC].Profession
if Prof == 12 then
CastSpellDirect(88,10,10)
elseif Prof == 11 then
CastSpellDirect(77,10,10)
evt.ForPlayer("All")
for i = 113, 118 do
evt.Subtract{i, 1}
end
for i = 107, 112 do
evt.Subtract{i, 1}
end
for i,v in Party do
v.HP = v:GetFullHP()
end
else
CastSpellDirect(77,10,10)
for i,v in Party do
v.HP = v:GetFullHP()
end
end
SetProfUsed()
Message(Game.GlobalTxt[569])
else
Message(Game.GlobalTxt[561])
end
end
-- Cast heroism
evt.Global[1720] = function()
CastFollowersSpell(51, 5, 3)
end
-- Cast bless
evt.Global[1719] = function()
CastFollowersSpell(46, 5, 3)
end
-- Cast town portal
evt.Global[1718] = function()
local NPC = GetCurrentNPC()
if CanUseProf(NPC) then
if Party.EnemyDetectorRed or Party.EnemyDetectorYellow then
Message(Game.GlobalTxt[480])
else
SetProfUsed()
ExitCurrentScreen(false, true)
CastSpellDirect(31, 10, 4)
end
else
Message(Game.GlobalTxt[561])
end
end
-- Cast water walk
evt.Global[1717] = function()
CastFollowersSpell(27, 3, 10)
end
-- Cast fly
evt.Global[1716] = function()
CastFollowersSpell(21, 4, 4)
end
-- Make food
evt.Global[1715] = function()
MakeFollowersFood()
end
-- Heal party
evt.Global[1714] = function()
HealFollowersParty()
end