forked from PathOfBuildingCommunity/PathOfBuilding
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalcs.lua
413 lines (390 loc) · 12.6 KB
/
Calcs.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
-- Path of Building
--
-- Module: Calcs
-- Manages the calculation system.
--
local targetVersion = ...
local pairs = pairs
local ipairs = ipairs
local t_insert = table.insert
local t_remove = table.remove
local s_format = string.format
local calcs = { }
calcs.targetVersion = targetVersion
calcs.breakdownModule = "Modules/CalcBreakdown"
LoadModule("Modules/CalcSetup", calcs)
LoadModule("Modules/CalcPerform", calcs)
LoadModule("Modules/CalcActiveSkill", calcs)
LoadModule("Modules/CalcDefence-"..targetVersion, calcs)
LoadModule("Modules/CalcOffence-"..targetVersion, calcs)
-- Print various tables to the console
local function infoDump(env)
if env.modDB.parent then
env.modDB.parent:Print()
end
env.modDB:Print()
if env.minion then
ConPrintf("=== Minion Mod DB ===")
env.minion.modDB:Print()
end
ConPrintf("=== Enemy Mod DB ===")
env.enemyDB:Print()
local mainSkill = env.minion and env.minion.mainSkill or env.player.mainSkill
ConPrintf("=== Main Skill ===")
for _, skillEffect in ipairs(mainSkill.effectList) do
ConPrintf("%s %d/%d", skillEffect.grantedEffect.name, skillEffect.level, skillEffect.quality)
end
ConPrintf("=== Main Skill Flags ===")
ConPrintf("Mod: %s", modLib.formatFlags(mainSkill.skillCfg.flags, ModFlag))
ConPrintf("Keyword: %s", modLib.formatFlags(mainSkill.skillCfg.keywordFlags, KeywordFlag))
ConPrintf("=== Main Skill Mods ===")
mainSkill.skillModList.parent:Print()
mainSkill.skillModList:Print()
ConPrintf("=== Main Skill Data ===")
prettyPrintTable(mainSkill.skillData)
ConPrintf("== Aux Skills ==")
for i, aux in ipairs(env.auxSkillList) do
ConPrintf("Skill #%d:", i)
for _, skillEffect in ipairs(aux.effectList) do
ConPrintf(" %s %d/%d", skillEffect.grantedEffect.name, skillEffect.level, skillEffect.quality)
end
end
ConPrintf("== Output Table ==")
prettyPrintTable(env.player.output)
end
-- Generate a function for calculating the effect of some modification to the environment
local function getCalculator(build, fullInit, modFunc)
-- Initialise environment
local env = calcs.initEnv(build, "CALCULATOR")
-- Save a copy of the initial mod database
local initModDB = new("ModDB")
initModDB:AddDB(env.modDB)
initModDB.conditions = copyTable(env.modDB.conditions)
initModDB.multipliers = copyTable(env.modDB.multipliers)
local initEnemyDB = new("ModDB")
initEnemyDB:AddDB(env.enemyDB)
initEnemyDB.conditions = copyTable(env.enemyDB.conditions)
initEnemyDB.multipliers = copyTable(env.enemyDB.multipliers)
-- Run base calculation pass
calcs.perform(env)
local baseOutput = env.player.output
env.modDB.parent = initModDB
env.enemyDB.parent = initEnemyDB
return function(...)
-- Remove mods added during the last pass
wipeTable(env.modDB.mods)
wipeTable(env.modDB.conditions)
wipeTable(env.modDB.multipliers)
wipeTable(env.enemyDB.mods)
wipeTable(env.enemyDB.conditions)
wipeTable(env.enemyDB.multipliers)
-- Call function to make modifications to the environment
modFunc(env, ...)
-- Run calculation pass
calcs.perform(env)
return env.player.output
end, baseOutput
end
-- Get fast calculator for adding tree node modifiers
function calcs.getNodeCalculator(build)
return getCalculator(build, true, function(env, nodeList)
-- Build and merge modifiers for these nodes
env.modDB:AddList(calcs.buildModListForNodeList(env, nodeList))
end)
end
-- Get calculator for other changes (adding/removing nodes, items, gems, etc)
function calcs.getMiscCalculator(build)
-- Run base calculation pass
local env = calcs.initEnv(build, "CALCULATOR")
calcs.perform(env)
local baseOutput = env.player.output
return function(override)
env = calcs.initEnv(build, "CALCULATOR", override)
calcs.perform(env)
return env.player.output
end, baseOutput
end
-- Build output for display in the side bar or calcs tab
function calcs.buildOutput(build, mode)
-- Build output
local env = calcs.initEnv(build, mode)
calcs.perform(env)
local output = env.player.output
if mode == "MAIN" then
output.ExtraPoints = env.modDB:Sum("BASE", nil, "ExtraPoints")
local specCfg = {
source = "Tree"
}
output["Spec:LifeInc"] = env.modDB:Sum("INC", specCfg, "Life")
output["Spec:ManaInc"] = env.modDB:Sum("INC", specCfg, "Mana")
output["Spec:ArmourInc"] = env.modDB:Sum("INC", specCfg, "Armour", "ArmourAndEvasion")
output["Spec:EvasionInc"] = env.modDB:Sum("INC", specCfg, "Evasion", "ArmourAndEvasion")
output["Spec:EnergyShieldInc"] = env.modDB:Sum("INC", specCfg, "EnergyShield")
env.skillsUsed = { }
for _, activeSkill in ipairs(env.player.activeSkillList) do
for _, skillEffect in ipairs(activeSkill.effectList) do
env.skillsUsed[skillEffect.grantedEffect.name] = true
end
if activeSkill.minion then
for _, activeSkill in ipairs(activeSkill.minion.activeSkillList) do
env.skillsUsed[activeSkill.activeEffect.grantedEffect.id] = true
end
end
end
env.conditionsUsed = { }
env.multipliersUsed = { }
env.minionConditionsUsed = { }
env.enemyConditionsUsed = { }
env.enemyMultipliersUsed = { }
local function addCond(out, var, mod)
if not out[var] then
out[var] = { }
end
t_insert(out[var], mod)
end
local function addCondTag(out, tag, mod)
if tag.varList then
for _, var in ipairs(tag.varList) do
addCond(out, var, mod)
end
else
addCond(out, tag.var, mod)
end
end
local function addMult(out, var, mod)
if not out[var] then
out[var] = { }
end
t_insert(out[var], mod)
end
local function addMultTag(out, tag, mod)
if tag.varList then
for _, var in ipairs(tag.varList) do
addMult(out, var, mod)
end
else
addMult(out, tag.var, mod)
end
end
local function addModTags(actor, mod)
for _, tag in ipairs(mod) do
if tag.type == "IgnoreCond" then
break
elseif tag.type == "Condition" then
if actor == env.player then
addCondTag(env.conditionsUsed, tag, mod)
else
addCondTag(env.minionConditionsUsed, tag, mod)
end
elseif tag.type == "ActorCondition" and tag.actor == "enemy" then
addCondTag(env.enemyConditionsUsed, tag, mod)
elseif tag.type == "Multiplier" or tag.type == "MultiplierThreshold" then
if not tag.actor then
if actor == env.player then
addMultTag(env.multipliersUsed, tag, mod)
end
elseif tag.actor == "enemy" then
addMultTag(env.enemyMultipliersUsed, tag, mod)
end
end
end
end
for _, actor in ipairs({env.player, env.minion}) do
for modName, modList in pairs(actor.modDB.mods) do
for _, mod in ipairs(modList) do
addModTags(actor, mod)
end
end
end
for _, activeSkill in pairs(env.player.activeSkillList) do
for _, mod in ipairs(activeSkill.baseSkillModList) do
addModTags(env.player, mod)
end
if activeSkill.minion then
for _, activeSkill in pairs(activeSkill.minion.activeSkillList) do
for _, mod in ipairs(activeSkill.baseSkillModList) do
addModTags(env.minion, mod)
end
end
end
end
for modName, modList in pairs(env.enemyDB.mods) do
for _, mod in ipairs(modList) do
for _, tag in ipairs(mod) do
if tag.type == "IgnoreCond" then
break
elseif tag.type == "Condition" then
addCondTag(env.enemyConditionsUsed, tag, mod)
elseif tag.type == "Multiplier" or tag.type == "MultiplierThreshold" then
if not tag.actor then
addMultTag(env.enemyMultipliersUsed, tag, mod)
end
end
end
end
end
-- ConPrintf("=== Cond ===")
-- ConPrintTable(env.conditionsUsed)
-- ConPrintf("=== Mult ===")
-- ConPrintTable(env.multipliersUsed)
-- ConPrintf("=== Minion Cond ===")
-- ConPrintTable(env.minionConditionsUsed)
-- ConPrintf("=== Enemy Cond ===")
-- ConPrintTable(env.enemyConditionsUsed)
-- ConPrintf("=== Enemy Mult ===")
-- ConPrintTable(env.enemyMultipliersUsed)
elseif mode == "CALCS" then
local buffList = { }
local combatList = { }
local curseList = { }
if output.PowerCharges > 0 then
t_insert(combatList, s_format("%d Power Charges", output.PowerCharges))
end
if output.FrenzyCharges > 0 then
t_insert(combatList, s_format("%d Frenzy Charges", output.FrenzyCharges))
end
if output.EnduranceCharges > 0 then
t_insert(combatList, s_format("%d Endurance Charges", output.EnduranceCharges))
end
if output.SiphoningCharges > 0 then
t_insert(combatList, s_format("%d Siphoning Charges", output.SiphoningCharges))
end
if output.ChallengerCharges > 0 then
t_insert(combatList, s_format("%d Challenger Charges", output.ChallengerCharges))
end
if output.BlitzCharges > 0 then
t_insert(combatList, s_format("%d Blitz Charges", output.BlitzCharges))
end
if output.InspirationCharges > 0 then
t_insert(combatList, s_format("%d Inspiration Charges", output.InspirationCharges))
end
if output.GhostShrouds > 0 then
t_insert(combatList, s_format("%d Ghost Shrouds", output.GhostShrouds))
end
if output.CrabBarriers > 0 then
t_insert(combatList, s_format("%d Crab Barriers", output.CrabBarriers))
end
if env.modDB:Flag(nil, "Fortify") then
t_insert(combatList, "Fortify")
end
if env.modDB:Flag(nil, "Onslaught") then
t_insert(combatList, "Onslaught")
end
if env.modDB:Flag(nil, "UnholyMight") then
t_insert(combatList, "Unholy Might")
end
if env.modDB:Flag(nil, "Tailwind") then
t_insert(combatList, "Tailwind")
end
if env.modDB:Flag(nil, "Adrenaline") then
t_insert(combatList, "Adrenaline")
end
if env.modDB:Flag(nil, "HerEmbrace") then
t_insert(combatList, "Her Embrace")
end
for name in pairs(env.buffs) do
t_insert(buffList, name)
end
if env.modDB:Flag(nil, "Elusive") then
t_insert(combatList, "Elusive")
end
table.sort(buffList)
env.player.breakdown.SkillBuffs = { modList = { } }
for _, name in ipairs(buffList) do
for _, mod in ipairs(env.buffs[name]) do
local value = env.modDB:EvalMod(mod)
if value and value ~= 0 then
t_insert(env.player.breakdown.SkillBuffs.modList, {
mod = mod,
value = value,
})
end
end
end
env.player.breakdown.SkillDebuffs = { modList = { } }
for name, modList in pairs(env.debuffs) do
t_insert(curseList, name)
end
table.sort(curseList)
for index, name in ipairs(curseList) do
for _, mod in ipairs(env.debuffs[name]) do
local value = env.enemy.modDB:EvalMod(mod)
if value and value ~= 0 then
t_insert(env.player.breakdown.SkillDebuffs.modList, {
mod = mod,
value = value,
})
end
end
local stackCount = env.debuffs[name]:Sum("BASE", nil, "Multiplier:"..name.."Stack")
if stackCount > 0 then
curseList[index] = name .. " (" .. stackCount .. " stack" .. (stackCount > 1 and "s" or "") .. ")"
end
end
for _, slot in ipairs(env.curseSlots) do
t_insert(curseList, slot.name)
if slot.modList then
for _, mod in ipairs(slot.modList) do
local value = env.enemy.modDB:EvalMod(mod)
if value and value ~= 0 then
t_insert(env.player.breakdown.SkillDebuffs.modList, {
mod = mod,
value = value,
})
end
end
end
end
output.BuffList = table.concat(buffList, ", ")
output.CombatList = table.concat(combatList, ", ")
output.CurseList = table.concat(curseList, ", ")
if env.minion then
local buffList = { }
local combatList = { }
if output.Minion.PowerCharges > 0 then
t_insert(combatList, s_format("%d Power Charges", output.Minion.PowerCharges))
end
if output.Minion.FrenzyCharges > 0 then
t_insert(combatList, s_format("%d Frenzy Charges", output.Minion.FrenzyCharges))
end
if output.Minion.EnduranceCharges > 0 then
t_insert(combatList, s_format("%d Endurance Charges", output.Minion.EnduranceCharges))
end
if env.minion.modDB:Flag(nil, "Fortify") then
t_insert(combatList, "Fortify")
end
if env.minion.modDB:Flag(nil, "Onslaught") then
t_insert(combatList, "Onslaught")
end
if env.minion.modDB:Flag(nil, "UnholyMight") then
t_insert(combatList, "Unholy Might")
end
if env.minion.modDB:Flag(nil, "Tailwind") then
t_insert(combatList, "Tailwind")
end
for name in pairs(env.minionBuffs) do
t_insert(buffList, name)
end
table.sort(buffList)
env.minion.breakdown.SkillBuffs = { modList = { } }
for _, name in ipairs(buffList) do
for _, mod in ipairs(env.minionBuffs[name]) do
local value = env.minion.modDB:EvalMod(mod)
if value and value ~= 0 then
t_insert(env.minion.breakdown.SkillBuffs.modList, {
mod = mod,
value = value,
})
end
end
end
env.minion.breakdown.SkillDebuffs = env.player.breakdown.SkillDebuffs
output.Minion.BuffList = table.concat(buffList, ", ")
output.Minion.CombatList = table.concat(combatList, ", ")
output.Minion.CurseList = output.CurseList
end
infoDump(env)
end
return env
end
return calcs