Skip to content

Commit 25d5468

Browse files
committed
Fix 2H weapons not removing off-hand items in comparisons
1 parent 661a9ad commit 25d5468

2 files changed

Lines changed: 141 additions & 11 deletions

File tree

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
describe("MiscCalculator", function()
2+
before_each(function()
3+
newBuild()
4+
end)
5+
describe("repItem behaviour", function()
6+
local calcFunc
7+
before_each(function ()
8+
calcFunc = build.calcsTab:GetMiscCalculator()
9+
end)
10+
11+
local function pasteAndEquipItem(itemText)
12+
build.itemsTab:CreateDisplayItemFromRaw(itemText)
13+
build.itemsTab:AddDisplayItem()
14+
runCallback("OnFrame")
15+
end
16+
17+
local function allocateKeystone(keystoneText)
18+
build.configTab.input.customMods = keystoneText
19+
build.configTab:BuildModList()
20+
runCallback("OnFrame")
21+
calcFunc = build.calcsTab:GetMiscCalculator()
22+
end
23+
24+
local function equipInSlot(item, slotName)
25+
build.itemsTab:AddItem(item, true)
26+
build.itemsTab.slots[slotName]:SetSelItemId(item.id)
27+
runCallback("OnFrame")
28+
end
29+
local focus = [[Rarity: RARE
30+
+2 Energy Shield
31+
Hallowed Focus
32+
Energy Shield: 57
33+
Crafted: true
34+
Prefix: {range:0.8}LocalIncreasedEnergyShield8
35+
Prefix: {range:0.8}LocalIncreasedEnergyShieldPercent6
36+
Prefix: None
37+
Suffix: {range:0.8}GlobalSpellGemsLevel2
38+
Suffix: None
39+
Suffix: None
40+
Quality: 0
41+
LevelReq: 61
42+
Implicits: 0
43+
+71 to maximum Energy Shield
44+
89% increased Energy Shield
45+
+2 to Level of all Spell Skills]]
46+
47+
local quiver = [[Test Subject
48+
Rarity: Rare
49+
Toxic Quiver
50+
Crafted: true
51+
Implicits: 1
52+
+100 to maximum energy shield]]
53+
54+
local bow = new("Item", [[Rarity: Rare
55+
Test Subject
56+
Gemini Bow]])
57+
58+
local talisman = new("Item", [[Rarity: Rare
59+
Test Subject
60+
Spiny Talisman]])
61+
62+
local staff = new("Item", [[Rarity: Rare
63+
Test Subject
64+
Chiming Staff]])
65+
66+
local mace = new("Item", [[Rarity: Rare
67+
Test Subject
68+
Ironwood Greathammer]])
69+
70+
local sceptre = new("Item", [[Rarity: Rare
71+
Test Subject
72+
Rattling Sceptre
73+
+100 to maximum Energy Shield]])
74+
local wand = new("Item", [[Rarity: Rare
75+
Test Subject
76+
Dueling Wand]])
77+
it("calculates off-hand without a weapon", function ()
78+
pasteAndEquipItem(focus)
79+
local output = calcFunc()
80+
assert.True(output.EnergyShield > 0)
81+
end)
82+
it("unequips the off-hand focus when replacing weapon 1 with two-handed weapons", function()
83+
pasteAndEquipItem(focus)
84+
for _, item in ipairs({ bow, talisman, staff, mace }) do
85+
local output = calcFunc({ repSlotName = "Weapon 1", repItem = item })
86+
assert.True(output.EnergyShield == 0)
87+
end
88+
end)
89+
it("keeps the off-hand quiver when using bow", function()
90+
-- quivers need a bow to be equipped first
91+
pasteAndEquipItem(bow:BuildRaw())
92+
pasteAndEquipItem(quiver)
93+
local output = calcFunc({ repSlotName = "Weapon 1", repItem = bow })
94+
assert.True(output.EnergyShield > 0)
95+
end)
96+
it("keeps the off-hand focus when using a two-handed weapon with Giant's Blood", function()
97+
pasteAndEquipItem(focus)
98+
allocateKeystone("You can wield Two-Handed Axes, Maces and Swords in one hand")
99+
local output = calcFunc({ repSlotName = "Weapon 1", repItem = mace })
100+
assert.True(output.EnergyShield > 0)
101+
end)
102+
it("keeps the off-hand focus when using a staff with Instruments of Power", function()
103+
pasteAndEquipItem(focus)
104+
allocateKeystone("You can equip a Focus while wielding a Staff")
105+
local output = calcFunc({ repSlotName = "Weapon 1", repItem = staff })
106+
assert.True(output.EnergyShield > 0)
107+
end)
108+
it("keeps rare off-hand sceptre when using a talisman with Lord of the Wilds", function()
109+
equipInSlot(sceptre, "Weapon 2")
110+
allocateKeystone("You can equip a non-Unique Sceptre while wielding a Talisman")
111+
local output = calcFunc({ repSlotName = "Weapon 1", repItem = talisman })
112+
assert.True(output.EnergyShield > 0)
113+
end)
114+
it("unequips unique off-hand sceptre when using a talisman with Lord of the Wilds", function()
115+
equipInSlot(new("Item", "Rarity: Unique\n" .. sceptre:BuildRaw()), "Weapon 2")
116+
allocateKeystone("You can equip a non-Unique Sceptre while wielding a Talisman")
117+
local output = calcFunc({ repSlotName = "Weapon 1", repItem = talisman })
118+
assert.True(output.EnergyShield == 0)
119+
end)
120+
it("keeps off-hand when using one-handed weapon", function()
121+
pasteAndEquipItem(focus)
122+
local output = calcFunc({ repSlotName = "Weapon 1", repItem = wand })
123+
assert.True(output.EnergyShield > 0)
124+
end)
125+
end)
126+
end)

src/Modules/CalcSetup.lua

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -854,9 +854,9 @@ function calcs.initEnv(build, mode, override, specEnv)
854854
modDB:NewMod("Condition:WeaponSet" .. (build.itemsTab.activeItemSet.useSecondWeaponSet and 2 or 1) , "FLAG", true, "Weapon Set")
855855

856856
local weaponFlagState = {
857-
giantsBlood = nodesModsList:Flag(nil, "GiantsBlood") or false,
858-
instrumentsOfPower = nodesModsList:Flag(nil, "InstrumentsOfPower") or false,
859-
lordOfTheWilds = nodesModsList:Flag(nil, "LordOfTheWilds") or false,
857+
giantsBlood = nodesModsList:Flag(nil, "GiantsBlood") or modDB:Flag(nil, "GiantsBlood") or false,
858+
instrumentsOfPower = nodesModsList:Flag(nil, "InstrumentsOfPower") or modDB:Flag(nil, "InstrumentsOfPower") or false,
859+
lordOfTheWilds = nodesModsList:Flag(nil, "LordOfTheWilds") or modDB:Flag(nil, "LordOfTheWilds") or false,
860860
}
861861
-- Only mutate equipped items in the real build pass; calculator overrides (e.g. node power) are transient.
862862
if mode == "MAIN" then
@@ -896,19 +896,23 @@ function calcs.initEnv(build, mode, override, specEnv)
896896
local item
897897
if slotName == override.repSlotName then
898898
item = override.repItem
899-
elseif override.repItem and override.repSlotName:match("^Weapon 1") and slotName:match("^Weapon 2") and
900-
(
901-
(not lordOfTheWilds and override.repItem.base.type == "Talisman" and item and item.base.type ~= "Sceptre" and item.rarity ~= "UNIQUE" and item.rarity ~= "RELIC")
902-
or (not instrumentsOfPower and override.repItem.base.type == "Staff" and item and item.base.type ~= "Focus")
903-
or (not giantsBlood and (override.repItem.base.type == "Two Hand Sword" or override.repItem.base.type == "Two Hand Axe" or override.repItem.base.type == "Two Hand Mace"))
904-
or (override.repItem.base.type == "Bow" and item and item.base.type ~= "Quiver")
905-
) then
906-
goto continue
907899
elseif slot.nodeId and override.spec then
908900
item = build.itemsTab.items[env.spec.jewels[slot.nodeId]]
909901
else
910902
item = build.itemsTab.items[slot.selItemId]
911903
end
904+
-- if we are replacing the main hand weapon, we should unequip the off hand weapon if it's not allowed
905+
local overrideTwoHand = override.repItem and override.repItem.base.type and not (env.data.weaponTypeInfo[override.repItem.base.type] or {}).oneHand
906+
if overrideTwoHand and override.repSlotName and override.repSlotName:match("^Weapon 1") and slotName:match("^Weapon 2") then
907+
local allowLordOfTheWilds = lordOfTheWilds and override.repItem.base.type == "Talisman" and item and item.base.type == "Sceptre" and item.rarity ~= "UNIQUE" and item.rarity ~= "RELIC"
908+
local allowInstrumentsOfPower = instrumentsOfPower and override.repItem.base.type == "Staff" and item and item.base.type == "Focus"
909+
local allowGiantsBlood = giantsBlood and (override.repItem.base.type == "Two Hand Sword" or override.repItem.base.type == "Two Hand Axe" or override.repItem.base.type == "Two Hand Mace")
910+
local allowQuiver = (override.repItem.base.type == "Bow" and item and item.base.type == "Quiver")
911+
local allowOffHand = allowLordOfTheWilds or allowInstrumentsOfPower or allowGiantsBlood or allowQuiver
912+
if not allowOffHand then
913+
goto continue
914+
end
915+
end
912916
if item and item.grantedSkills then
913917
-- Find skills granted by this item
914918
for _, skill in ipairs(item.grantedSkills) do

0 commit comments

Comments
 (0)