This repository has been archived by the owner on Dec 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 221
/
Copy pathbluemagic.lua
450 lines (381 loc) · 14.5 KB
/
bluemagic.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
require("scripts/globals/status")
require("scripts/globals/magic")
-- The TP modifier
TPMOD_NONE = 0;
TPMOD_CRITICAL = 1;
TPMOD_DAMAGE = 2;
TPMOD_ACC = 3;
TPMOD_ATTACK = 4;
-- The SC the spell makes
SC_IMPACTION = 0;
SC_TRANSFIXION = 1;
SC_DETONATION = 2;
SC_REVERBERATION = 3;
SC_SCISSION = 4;
SC_INDURATION = 5;
SC_LIQUEFACTION = 6;
SC_COMPRESSION = 7;
SC_FUSION = 8;
SC_FRAGMENTATION = 9;
SC_DISTORTION = 10;
SC_GRAVITATION = 11;
SC_DARK = 12;
SC_LIGHT = 13;
INT_BASED = 1;
CHR_BASED = 2;
MND_BASED = 3;
-- Get the damage for a blue magic physical spell.
-- caster - The entity casting the spell.
-- target - The target of the spell.
-- spell - The blue magic spell itself.
-- params - The parameters for the spell. Broken down into:
-- .tpmod - The TP modifier for the spell (e.g. damage varies, critical varies with TP, etc). Should be a TPMOD_xxx enum.
-- .numHits - The number of hits in the spell.
-- .multiplier - The base multiplier for the spell (not under Chain Affinity) - Every spell must specify this. (equivalent to TP 0%)
-- .tp150 - The TP modifier @ 150% TP (damage multiplier, crit chance, etc. 1.0 = 100%, 2.0 = 200% NOT 100=100%).
-- This value is interpreted as crit chance or dmg multiplier depending on the TP modifier (tpmod).
-- .tp300 - The TP modifier @ 300% TP (damage multiplier, crit chance, etc. 1.0 = 100%, 2.0 = 200% NOT 100=100%)
-- This value is interpreted as crit chance or dmg multiplier depending on the TP modifier (tpmod).
-- .azuretp - The TP modifier under Azure Lore (damage multiplier, crit chance, etc. 1.0 = 100%, 2.0 = 200% NOT 100=100%)
-- This value is interpreted as crit chance or dmg multiplier depending on the TP modifier (tpmod).
-- .duppercap - The upper cap for D for this spell.
-- .str_wsc - The decimal % value for STR % (e.g. STR 20% becomes 0.2)
-- .dex_wsc - Same as above.
-- .vit_wsc - Same as above.
-- .int_wsc - Same as above.
-- .mnd_wsc - Same as above.
-- .chr_wsc - Same as above.
-- .agi_wsc - Same as above.
function BluePhysicalSpell(caster, target, spell, params)
-- store related values
local magicskill = caster:getSkillLevel(tpz.skill.BLUE_MAGIC); -- skill + merits + equip bonuses
-- TODO: Under Chain affinity?
-- TODO: Under Efflux?
-- TODO: Merits.
-- TODO: Under Azure Lore.
---------------------------------
-- Calculate the final D value -
---------------------------------
-- worked out from http://wiki.ffxiclopedia.org/wiki/Calculating_Blue_Magic_Damage
-- Final D value ??= floor(D+fSTR+WSC) * Multiplier
local D = math.floor((magicskill * 0.11)) * 2 + 3;
-- cap D
if (D > params.duppercap) then
D = params.duppercap;
end
-- print("D val is ".. D);
local fStr = BluefSTR(caster:getStat(tpz.mod.STR) - target:getStat(tpz.mod.VIT));
if (fStr > 22) then
fStr = 22; -- TODO: Smite of Rage doesn't have this cap applied.
end
-- print("fStr val is ".. fStr);
local WSC = BlueGetWsc(caster, params);
-- print("wsc val is ".. WSC);
local multiplier = params.multiplier;
-- If under CA, replace multiplier with fTP(multiplier, tp150, tp300)
local chainAffinity = caster:getStatusEffect(tpz.effect.CHAIN_AFFINITY);
if chainAffinity ~= nil then
-- Calculate the total TP available for the fTP multiplier.
local tp = caster:getTP() + caster:getMerit(tpz.merit.ENCHAINMENT);
if tp > 3000 then
tp = 3000;
end;
multiplier = BluefTP(tp, multiplier, params.tp150, params.tp300);
end;
-- TODO: Modify multiplier to account for family bonus/penalty
local finalD = math.floor(D + fStr + WSC) * multiplier;
-- print("Final D is ".. finalD);
----------------------------------------------
-- Get the possible pDIF range and hit rate --
----------------------------------------------
if (params.offcratiomod == nil) then -- default to attack. Pretty much every physical spell will use this, Cannonball being the exception.
params.offcratiomod = caster:getStat(tpz.mod.ATT)
end;
-- print(params.offcratiomod)
local cratio = BluecRatio(params.offcratiomod / target:getStat(tpz.mod.DEF), caster:getMainLvl(), target:getMainLvl());
local hitrate = BlueGetHitRate(caster,target,true);
-- print("Hit rate "..hitrate);
-- print("pdifmin "..cratio[1].." pdifmax "..cratio[2]);
-------------------------
-- Perform the attacks --
-------------------------
local hitsdone = 0;
local hitslanded = 0;
local finaldmg = 0;
while (hitsdone < params.numhits) do
local chance = math.random();
if (chance <= hitrate) then -- it hit
-- TODO: Check for shadow absorbs.
-- Generate a random pDIF between min and max
local pdif = math.random((cratio[1]*1000),(cratio[2]*1000));
pdif = pdif/1000;
-- Apply it to our final D
if (hitsdone == 0) then -- only the first hit benefits from multiplier
finaldmg = finaldmg + (finalD * pdif);
else
finaldmg = finaldmg + ((math.floor(D + fStr + WSC)) * pdif); -- same as finalD but without multiplier (it should be 1.0)
end
hitslanded = hitslanded + 1;
-- increment target's TP (100TP per hit landed)
target:addTP(100);
end
hitsdone = hitsdone + 1;
end
-- print("Hits landed "..hitslanded.."/"..hitsdone.." for total damage: "..finaldmg);
return finaldmg;
end;
-- Blue Magical type spells
function BlueMagicalSpell(caster, target, spell, params, statMod)
local D = caster:getMainLvl() + 2;
if (D > params.duppercap) then
D = params.duppercap;
end
local ST = BlueGetWsc(caster, params); -- According to Wiki ST is the same as WSC, essentially Blue mage spells that are magical use the dmg formula of Magical type Weapon skills
if (caster:hasStatusEffect(tpz.effect.BURST_AFFINITY)) then
ST = ST * 2;
end
local convergenceBonus = 1.0;
if (caster:hasStatusEffect(tpz.effect.CONVERGENCE)) then
convergenceEffect = getStatusEffect(tpz.effect.CONVERGENCE);
local convLvl = convergenceEffect:getPower();
if (convLvl == 1) then
convergenceBonus = 1.05;
elseif (convLvl == 2) then
convergenceBonus = 1.1;
elseif (convLvl == 3) then
convergenceBonus = 1.15;
end
end
local statBonus = 0;
local dStat = 0; -- Please make sure to add an additional stat check if there is to be a spell that uses neither INT, MND, or CHR. None currently exist.
if (statMod == INT_BASED) then -- Stat mod is INT
dStat = caster:getStat(tpz.mod.INT) - target:getStat(tpz.mod.INT)
statBonus = (dStat)* params.tMultiplier;
elseif (statMod == CHR_BASED) then -- Stat mod is CHR
dStat = caster:getStat(tpz.mod.CHR) - target:getStat(tpz.mod.CHR)
statBonus = (dStat)* params.tMultiplier;
elseif (statMod == MND_BASED) then -- Stat mod is MND
dStat = caster:getStat(tpz.mod.MND) - target:getStat(tpz.mod.MND)
statBonus = (dStat)* params.tMultiplier;
end
D =(((D + ST) * params.multiplier * convergenceBonus) + statBonus);
-- At this point according to wiki we apply standard magic attack calculations
local magicAttack = 1.0;
local multTargetReduction = 1.0; -- TODO: Make this dynamically change, temp static till implemented.
magicAttack = math.floor(D * multTargetReduction);
local rparams = {};
rparams.diff = dStat;
rparams.skillType = tpz.skill.BLUE_MAGIC;
magicAttack = math.floor(magicAttack * applyResistance(caster, target, spell, rparams));
dmg = math.floor(addBonuses(caster, spell, target, magicAttack));
caster:delStatusEffectSilent(tpz.effect.BURST_AFFINITY);
return dmg;
end;
function BlueFinalAdjustments(caster, target, spell, dmg, params)
if (dmg < 0) then
dmg = 0
end
dmg = dmg * BLUE_POWER
dmg = dmg - target:getMod(tpz.mod.PHALANX)
if (dmg < 0) then
dmg = 0
end
-- handling stoneskin
dmg = utils.stoneskin(target, dmg)
local damageType = params.dmgType or tpz.damageType.NONE
target:takeSpellDamage(caster, spell, dmg, tpz.attackType.PHYSICAL, damageType)
target:updateEnmityFromDamage(caster,dmg)
target:handleAfflatusMiseryDamage(dmg)
-- TP has already been dealt with.
return dmg
end
------------------------------
-- Utility functions below ---
------------------------------
function BlueGetWsc(attacker, params)
wsc = (attacker:getStat(tpz.mod.STR) * params.str_wsc + attacker:getStat(tpz.mod.DEX) * params.dex_wsc +
attacker:getStat(tpz.mod.VIT) * params.vit_wsc + attacker:getStat(tpz.mod.AGI) * params.agi_wsc +
attacker:getStat(tpz.mod.INT) * params.int_wsc + attacker:getStat(tpz.mod.MND) * params.mnd_wsc +
attacker:getStat(tpz.mod.CHR) * params.chr_wsc) * BlueGetAlpha(attacker:getMainLvl());
return wsc;
end;
-- Given the raw ratio value (atk/def) and levels, returns the cRatio (min then max)
function BluecRatio(ratio,atk_lvl,def_lvl)
-- Level penalty...
local levelcor = 0;
if (atk_lvl < def_lvl) then
levelcor = 0.05 * (def_lvl - atk_lvl);
end
ratio = ratio - levelcor;
-- apply caps
if (ratio<0) then
ratio = 0;
elseif (ratio>2) then
ratio = 2;
end
-- Obtaining cRatio_MIN
local cratiomin = 0;
if (ratio<1.25) then
cratiomin = 1.2 * ratio - 0.5;
elseif (ratio>=1.25 and ratio<=1.5) then
cratiomin = 1;
elseif (ratio>1.5 and ratio<=2) then
cratiomin = 1.2 * ratio - 0.8;
end
-- Obtaining cRatio_MAX
local cratiomax = 0;
if (ratio<0.5) then
cratiomax = 0.4 + 1.2 * ratio;
elseif (ratio<=0.833 and ratio>=0.5) then
cratiomax = 1;
elseif (ratio<=2 and ratio>0.833) then
cratiomax = 1.2 * ratio;
end
cratio = {};
if (cratiomin < 0) then
cratiomin = 0;
end
cratio[1] = cratiomin;
cratio[2] = cratiomax;
return cratio;
end;
-- Gets the fTP multiplier by applying 2 straight lines between ftp1-ftp2 and ftp2-ftp3
-- tp - The current TP
-- ftp1 - The TP 0% value
-- ftp2 - The TP 150% value
-- ftp3 - The TP 300% value
function BluefTP(tp,ftp1,ftp2,ftp3)
if (tp >= 0 and tp < 1500) then
return ftp1 + ( ((ftp2-ftp1)/100) * (tp / 10));
elseif (tp >= 1500 and tp <= 3000) then
-- generate a straight line between ftp2 and ftp3 and find point @ tp
return ftp2 + ( ((ftp3-ftp2)/100) * ((tp-1500) / 10));
else
print("blue fTP error: TP value is not between 0-3000!");
end
return 1; -- no ftp mod
end;
function BluefSTR(dSTR)
local fSTR2 = nil;
if (dSTR >= 12) then
fSTR2 = ((dSTR+4)/2);
elseif (dSTR >= 6) then
fSTR2 = ((dSTR+6)/2);
elseif (dSTR >= 1) then
fSTR2 = ((dSTR+7)/2);
elseif (dSTR >= -2) then
fSTR2 = ((dSTR+8)/2);
elseif (dSTR >= -7) then
fSTR2 = ((dSTR+9)/2);
elseif (dSTR >= -15) then
fSTR2 = ((dSTR+10)/2);
elseif (dSTR >= -21) then
fSTR2 = ((dSTR+12)/2);
else
fSTR2 = ((dSTR+13)/2);
end
return fSTR2;
end;
function BlueGetHitRate(attacker,target,capHitRate)
local acc = attacker:getACC();
local eva = target:getEVA();
if (attacker:getMainLvl() > target:getMainLvl()) then -- acc bonus!
acc = acc + ((attacker:getMainLvl()-target:getMainLvl())*4);
elseif (attacker:getMainLvl() < target:getMainLvl()) then -- acc penalty :(
acc = acc - ((target:getMainLvl()-attacker:getMainLvl())*4);
end
local hitdiff = 0;
local hitrate = 75;
if (acc>eva) then
hitdiff = (acc-eva)/2;
end
if (eva>acc) then
hitdiff = ((-1)*(eva-acc))/2;
end
hitrate = hitrate+hitdiff;
hitrate = hitrate/100;
-- Applying hitrate caps
if (capHitRate) then -- this isn't capped for when acc varies with tp, as more penalties are due
if (hitrate>0.95) then
hitrate = 0.95;
end
if (hitrate<0.2) then
hitrate = 0.2;
end
end
return hitrate;
end;
-- Function to stagger duration of effects by using the resistance to change the value
function getBlueEffectDuration(caster,resist,effect)
local duration = 0;
if (resist == 0.125) then
resist = 1;
elseif (resist == 0.25) then
resist = 2;
elseif (resist == 0.5) then
resist = 3;
else
resist = 4;
end
if (effect == tpz.effect.BIND) then
duration = math.random(0,5) + resist * 5;
elseif (effect == tpz.effect.STUN) then
duration = math.random(2,3) + resist;
-- printf("Duration of stun is %i",duration);
elseif (effect == tpz.effect.WEIGHT) then
duration = math.random(20,24) + resist * 9; -- 20-24
elseif (effect == tpz.effect.PARALYSIS) then
duration = math.random(50,60) + resist * 15; -- 50- 60
elseif (effect == tpz.effect.SLOW) then
duration = math.random(60,120) + resist * 15; -- 60- 120 -- Needs confirmation but capped max duration based on White Magic Spell Slow
elseif (effect == tpz.effect.SILENCE) then
duration = math.random(60,180) + resist * 15; -- 60- 180 -- Needs confirmation but capped max duration based on White Magic Spell Silence
elseif (effect == tpz.effect.POISON) then
duration = math.random(20,30) + resist * 9; -- 20-30 -- based on magic spell poison
end
return duration;
end;
-- obtains alpha, used for working out WSC
function BlueGetAlpha(level)
local alpha = 1.00;
if (level <= 5) then
alpha = 1.00;
elseif (level <= 11) then
alpha = 0.99;
elseif (level <= 17) then
alpha = 0.98;
elseif (level <= 23) then
alpha = 0.97;
elseif (level <= 29) then
alpha = 0.96;
elseif (level <= 35) then
alpha = 0.95;
elseif (level <= 41) then
alpha = 0.94;
elseif (level <= 47) then
alpha = 0.93;
elseif (level <= 53) then
alpha = 0.92;
elseif (level <= 59) then
alpha = 0.91;
elseif (level <= 61) then
alpha = 0.90;
elseif (level <= 63) then
alpha = 0.89;
elseif (level <= 65) then
alpha = 0.88;
elseif (level <= 67) then
alpha = 0.87;
elseif (level <= 69) then
alpha = 0.86;
elseif (level <= 71) then
alpha = 0.85;
elseif (level <= 73) then
alpha = 0.84;
elseif (level <= 75) then
alpha = 0.83;
elseif (level <= 99) then
alpha = 0.85;
end
return alpha;
end;