-
Notifications
You must be signed in to change notification settings - Fork 409
Expand file tree
/
Copy pathTestTamedBeastMods_spec.lua
More file actions
325 lines (283 loc) · 13.1 KB
/
Copy pathTestTamedBeastMods_spec.lua
File metadata and controls
325 lines (283 loc) · 13.1 KB
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
describe("TestTamedBeastMods", function()
before_each(function()
newBuild()
end)
local sampleProperties = {
{
name = "Monster Modifiers:\n{0}",
values = {
{ "[PlayerMonsterFlaskRemovalAura1|Siphons Flask Charges]\n[PlayerMonsterLifeRegenerationRatePercentage1|Regenerates Life]\nPeriodically unleashes [Cold|Ice]\n[PlayerMonsterAdditionalProjectiles1|Additional Projectiles]", 0 },
},
displayMode = 3,
},
}
describe("ImportTab.ParseTamedBeastProperties", function()
it("parses mod-id tokens and resolves display-only lines", function()
local list = build.importTab:ParseTamedBeastProperties(sampleProperties)
assert.are.equals(4, #list)
assert.are.equals("PlayerMonsterFlaskRemovalAura1", list[1].modId)
assert.are.equals("Siphons Flask Charges", list[1].display)
assert.are.equals("PlayerMonsterLifeRegenerationRatePercentage1", list[2].modId)
-- No leading [ModId|...] token; resolved by display line lookup
assert.are.equals("Periodically unleashes Ice", list[3].display)
assert.are.equals("PlayerMonsterChilledGroundOnDeath1", list[3].modId)
assert.are.equals("PlayerMonsterAdditionalProjectiles1", list[4].modId)
for _, entry in ipairs(list) do
assert.True(entry.enabled)
end
end)
it("keeps unresolvable lines with display text only", function()
local list = build.importTab:ParseTamedBeastProperties({
{ values = { { "[MonsterMadeUpModDoesNotExist1|Made Up Mod]", 0 } } },
})
assert.are.equals(1, #list)
assert.is_nil(list[1].modId)
assert.are.equals("Made Up Mod", list[1].display)
end)
it("returns nil for absent or empty input", function()
assert.is_nil(build.importTab:ParseTamedBeastProperties(nil))
assert.is_nil(build.importTab:ParseTamedBeastProperties({ }))
end)
end)
describe("Exported data shape", function()
it("contains only Player-prefixed companion mods with spawn weights", function()
local count = 0
for modId, beastMod in pairs(build.data.tamedBeastMods) do
count = count + 1
assert.is_not_nil(modId:match("^PlayerMonster"), modId.." is not Player-prefixed")
assert.is_nil(beastMod.rollable, modId.." still carries the removed rollable flag")
assert.are.equals("string", type(beastMod.name))
assert.True(beastMod.type == "Prefix" or beastMod.type == "Suffix")
assert.are.equals("table", type(beastMod.statDescriptions))
assert.are.equals("table", type(beastMod.modList))
assert.are.equals("table", type(beastMod.spawnWeights))
assert.True(#beastMod.spawnWeights > 0, modId.." has no spawn weights")
for _, entry in ipairs(beastMod.spawnWeights) do
assert.are.equals("string", type(entry.tag))
assert.are.equals("number", type(entry.weight))
end
end
-- ~68 as of 0.5; loose band so balance patches don't break the suite
assert.True(count >= 50 and count <= 100, "unexpected mod count: "..count)
-- Script-applied twin (generation type 3) must not pass the prefix/suffix filter
assert.is_nil(build.data.tamedBeastMods["PlayerMonsterGlacialPrison1"])
end)
it("marks boss-only beasts via the object template is_boss flag", function()
local silverfist = build.data.minions["Metadata/Monsters/Quadrilla/QuadrillaBossMinion1"]
assert.is_not_nil(silverfist)
assert.True(isValueInArray(silverfist.monsterTags, "boss") ~= nil)
local wolf = build.data.minions["WolfMinion"]
assert.is_not_nil(wolf)
assert.is_nil(isValueInArray(wolf.monsterTags, "boss"))
end)
end)
describe("data.beastModCanSpawn", function()
it("blocks zero-weight tag matches ahead of the default entry", function()
local hasteAura = build.data.tamedBeastMods["PlayerMonsterIncreasedSpeedAura1"]
assert.is_not_nil(hasteAura)
assert.False(build.data.beastModCanSpawn(hasteAura, { "fast_movement", "beast" }))
assert.True(build.data.beastModCanSpawn(hasteAura, { "beast" }))
end)
it("requires positive-gate tags when the default weight is zero", function()
local alwaysBleeds = build.data.tamedBeastMods["PlayerMonsterAlwaysBleed1"]
assert.is_not_nil(alwaysBleeds)
assert.True(build.data.beastModCanSpawn(alwaysBleeds, { "physical_affinity" }))
assert.False(build.data.beastModCanSpawn(alwaysBleeds, { "beast" }))
assert.False(build.data.beastModCanSpawn(alwaysBleeds, nil))
end)
it("falls through to false when no entry matches and there is no default", function()
local beastMod = { spawnWeights = { { tag = "caster", weight = 1 } } }
assert.False(build.data.beastModCanSpawn(beastMod, { "beast" }))
assert.True(build.data.beastModCanSpawn(beastMod, { "caster" }))
end)
end)
describe("SkillsTab persistence", function()
it("saves tamed beast mods as Gem child elements", function()
build.skillsTab.skillSets[1].socketGroupList = { {
enabled = true,
gemList = { {
nameSpec = "Companion: Mighty Silverfist",
level = 20, quality = 0, enabled = true, enableGlobal1 = true, enableGlobal2 = true,
count = 1, corrupted = false, corruptLevel = 0,
tamedBeastModList = {
{ modId = "PlayerMonsterDamageGainedAsCold1", enabled = true },
{ display = "Periodically unleashes Ice", enabled = false },
},
} },
} }
local xml = { }
build.skillsTab:Save(xml)
local gemNode
for _, skillSetNode in ipairs(xml) do
if skillSetNode.elem == "SkillSet" then
for _, skillNode in ipairs(skillSetNode) do
if skillNode.elem == "Skill" then
gemNode = skillNode[1]
end
end
end
end
assert.is_not_nil(gemNode)
assert.are.equals("Gem", gemNode.elem)
local beastModNodes = { }
for _, child in ipairs(gemNode) do
if child.elem == "TamedBeastMod" then
table.insert(beastModNodes, child)
end
end
assert.are.equals(2, #beastModNodes)
assert.are.equals("PlayerMonsterDamageGainedAsCold1", beastModNodes[1].attrib.modId)
assert.are.equals("true", beastModNodes[1].attrib.enabled)
assert.is_nil(beastModNodes[2].attrib.modId)
assert.are.equals("Periodically unleashes Ice", beastModNodes[2].attrib.display)
assert.are.equals("false", beastModNodes[2].attrib.enabled)
end)
it("loads TamedBeastMod elements back onto the gem instance", function()
local node = { elem = "Skill", attrib = { enabled = "true" },
{ elem = "Gem", attrib = { nameSpec = "Companion: Mighty Silverfist", level = "20", quality = "0", enabled = "true" },
{ elem = "TamedBeastMod", attrib = { modId = "PlayerMonsterDamageGainedAsCold1", enabled = "true" } },
{ elem = "TamedBeastMod", attrib = { display = "Periodically unleashes Ice", enabled = "false" } },
},
}
build.skillsTab:LoadSkill(node, 1)
local socketGroupList = build.skillsTab.skillSets[1].socketGroupList
local gemInstance = socketGroupList[#socketGroupList].gemList[1]
assert.is_not_nil(gemInstance.tamedBeastModList)
assert.are.equals(2, #gemInstance.tamedBeastModList)
assert.are.equals("PlayerMonsterDamageGainedAsCold1", gemInstance.tamedBeastModList[1].modId)
assert.True(gemInstance.tamedBeastModList[1].enabled)
assert.is_nil(gemInstance.tamedBeastModList[2].modId)
assert.are.equals("Periodically unleashes Ice", gemInstance.tamedBeastModList[2].display)
assert.False(gemInstance.tamedBeastModList[2].enabled)
end)
it("loads legacy gems without beast mods as nil", function()
local node = { elem = "Skill", attrib = { enabled = "true" },
{ elem = "Gem", attrib = { nameSpec = "Fireball", level = "20", quality = "0", enabled = "true" } },
}
build.skillsTab:LoadSkill(node, 1)
local socketGroupList = build.skillsTab.skillSets[1].socketGroupList
assert.is_nil(socketGroupList[#socketGroupList].gemList[1].tamedBeastModList)
end)
end)
describe("Calculation wiring", function()
-- Mighty Silverfist: monsterTags include both fast_movement and boss, so it can
-- never roll Haste Aura (fast_movement = 0) or Regenerates Life (boss = 0)
local beastId = "Metadata/Monsters/Quadrilla/QuadrillaBossMinion1"
local function buildCompanionGroup(tamedBeastModList)
table.insert(build.beastList, beastId)
local gemInstance = {
nameSpec = "Companion: Mighty Silverfist",
gemId = "Metadata/Items/Gems/SkillGemSummonBeast",
level = 20, quality = 0, enabled = true, enableGlobal1 = true, enableGlobal2 = true,
count = 1, corrupted = false, corruptLevel = 0,
skillMinion = beastId,
skillMinionCalcs = beastId,
tamedBeastModList = tamedBeastModList,
}
local group = { label = "", enabled = true, gemList = { gemInstance } }
table.insert(build.skillsTab.socketGroupList, group)
build.skillsTab:ProcessSocketGroup(group)
build.mainSocketGroup = #build.skillsTab.socketGroupList
build.buildFlag = true
runCallback("OnFrame")
return gemInstance
end
it("applies enabled beast mods to the companion minion", function()
buildCompanionGroup({ { modId = "PlayerMonsterDamageGainedAsCold1", enabled = true } })
local minion = build.calcsTab.mainEnv.minion
assert.is_not_nil(minion)
assert.are.equals(40, minion.modDB:Sum("BASE", nil, "DamageGainAsCold"))
end)
it("skips disabled and unresolved beast mods", function()
local gemInstance = buildCompanionGroup({
{ modId = "PlayerMonsterDamageGainedAsCold1", enabled = false },
{ display = "Periodically unleashes Ice", enabled = true },
})
local minion = build.calcsTab.mainEnv.minion
assert.is_not_nil(minion)
assert.are.equals(0, minion.modDB:Sum("BASE", nil, "DamageGainAsCold"))
gemInstance.tamedBeastModList[1].enabled = true
build.buildFlag = true
runCallback("OnFrame")
assert.are.equals(40, build.calcsTab.mainEnv.minion.modDB:Sum("BASE", nil, "DamageGainAsCold"))
end)
it("ignores enabled mods the selected beast can never roll", function()
buildCompanionGroup({
{ modId = "PlayerMonsterLifeRegenerationRatePercentage1", enabled = true }, -- boss = 0
{ modId = "PlayerMonsterDamageGainedAsCold1", enabled = true },
})
local minion = build.calcsTab.mainEnv.minion
assert.is_not_nil(minion)
assert.are.equals(0, minion.modDB:Sum("BASE", nil, "LifeRegenPercent"))
assert.are.equals(40, minion.modDB:Sum("BASE", nil, "DamageGainAsCold"))
end)
it("does not affect companions without beast mods", function()
buildCompanionGroup(nil)
local minion = build.calcsTab.mainEnv.minion
assert.is_not_nil(minion)
assert.are.equals(0, minion.modDB:Sum("BASE", nil, "DamageGainAsCold"))
end)
it("does not apply a stale beast mod list when the gem is not a Companion", function()
build.skillsTab:PasteSocketGroup("Skeletal Sniper 20/0 1")
runCallback("OnFrame")
local srcInstance = build.skillsTab.socketGroupList[1].gemList[1]
srcInstance.tamedBeastModList = { { modId = "PlayerMonsterDamageGainedAsCold1", enabled = true } }
build.buildFlag = true
runCallback("OnFrame")
local minion = build.calcsTab.mainEnv.minion
assert.is_not_nil(minion)
assert.are.equals(0, minion.modDB:Sum("BASE", nil, "DamageGainAsCold"))
end)
it("applies entries beyond the fourth and creates UI rows for them", function()
buildCompanionGroup({
{ modId = "PlayerMonsterIncreasedSpeedAura1", enabled = false },
{ modId = "PlayerMonsterLifeRegenerationRatePercentage1", enabled = false },
{ modId = "PlayerMonsterAdditionalProjectiles1", enabled = false },
{ modId = "PlayerMonsterFlaskRemovalAura1", enabled = false },
{ modId = "PlayerMonsterDamageGainedAsCold1", enabled = true },
})
assert.are.equals(40, build.calcsTab.mainEnv.minion.modDB:Sum("BASE", nil, "DamageGainAsCold"))
local skillsTab = build.skillsTab
skillsTab:SetDisplayGroup(skillsTab.socketGroupList[#skillsTab.socketGroupList])
skillsTab:UpdateBeastModSlots()
assert.is_not_nil(skillsTab.beastModSlots[6])
local slot5 = skillsTab.beastModSlots[5]
assert.are.equals("PlayerMonsterDamageGainedAsCold1", slot5.select.list[slot5.select.selIndex].modId)
end)
end)
describe("Re-import preservation", function()
local function companionPayload()
return {
level = 12,
equipment = { },
skills = { {
support = false,
typeLine = "Companion: Mighty Silverfist",
properties = { { name = "Level", values = { { "17", 0 } } } },
tamedBeastProperties = { {
name = "Monster Modifiers:\n{0}",
values = { { "[PlayerMonsterDamageGainedAsCold1|Extra Cold Damage]\n[PlayerMonsterIncreasedSpeedAura1|Haste Aura]", 0 } },
displayMode = 3,
} },
} },
}
end
it("keeps user enable choices for surviving mods when re-importing", function()
build.importTab.controls.charImportItemsClearSkills.state = true
build.importTab.controls.charImportItemsClearItems.state = false
build.importTab:ImportItemsAndSkills(companionPayload())
runCallback("OnFrame")
local gem = build.skillsTab.socketGroupList[1].gemList[1]
assert.are.equals(2, #gem.tamedBeastModList)
assert.True(gem.tamedBeastModList[1].enabled)
gem.tamedBeastModList[1].enabled = false
build.importTab:ImportItemsAndSkills(companionPayload())
runCallback("OnFrame")
gem = build.skillsTab.socketGroupList[1].gemList[1]
assert.are.equals(2, #gem.tamedBeastModList)
assert.are.equals("PlayerMonsterDamageGainedAsCold1", gem.tamedBeastModList[1].modId)
assert.False(gem.tamedBeastModList[1].enabled)
assert.True(gem.tamedBeastModList[2].enabled)
end)
end)
end)