Skip to content

Commit 80dbd22

Browse files
authored
Fixes equip bug with random suffix rings (mod-playerbots#1757)
* Check item score of rings/trinkets to determine the correct slot to equip * Early return, removed unecessary if statements, single line statements Simplify logic for equipping items by reducing nested conditions.
1 parent 26a135a commit 80dbd22

1 file changed

Lines changed: 25 additions & 6 deletions

File tree

src/strategy/actions/EquipAction.cpp

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,19 +271,38 @@ void EquipAction::EquipItem(Item* item)
271271
{
272272
if (equippedItems[1])
273273
{
274-
// Both slots are full - pick the worst item to replace
274+
// Both slots are full - pick the worst item to replace, but only if new item is better
275275
StatsWeightCalculator calc(bot);
276276
calc.SetItemSetBonus(false);
277277
calc.SetOverflowPenalty(false);
278278

279-
float firstItemScore = calc.CalculateItem(equippedItems[0]->GetTemplate()->ItemId);
280-
float secondItemScore = calc.CalculateItem(equippedItems[1]->GetTemplate()->ItemId);
279+
// Calculate new item score with random properties
280+
int32 newItemRandomProp = item->GetItemRandomPropertyId();
281+
float newItemScore = calc.CalculateItem(itemId, newItemRandomProp);
281282

282-
// If the second slot is worse, place the new item there
283-
if (firstItemScore > secondItemScore)
283+
// Calculate equipped items scores with random properties
284+
int32 firstRandomProp = equippedItems[0]->GetItemRandomPropertyId();
285+
int32 secondRandomProp = equippedItems[1]->GetItemRandomPropertyId();
286+
float firstItemScore = calc.CalculateItem(equippedItems[0]->GetTemplate()->ItemId, firstRandomProp);
287+
float secondItemScore = calc.CalculateItem(equippedItems[1]->GetTemplate()->ItemId, secondRandomProp);
288+
289+
// Determine which slot (if any) should be replaced
290+
bool betterThanFirst = newItemScore > firstItemScore;
291+
bool betterThanSecond = newItemScore > secondItemScore;
292+
293+
// Early return if new item is not better than either equipped item
294+
if (!betterThanFirst && !betterThanSecond)
295+
return;
296+
297+
if (betterThanFirst && betterThanSecond)
284298
{
285-
dstSlot++;
299+
// New item is better than both - replace the worse of the two equipped items
300+
if (firstItemScore > secondItemScore)
301+
dstSlot++; // Replace second slot (worse)
302+
// else: keep dstSlot as-is (replace first slot)
286303
}
304+
else if (betterThanSecond)
305+
dstSlot++; // Only better than second slot - replace it
287306
}
288307
else
289308
{

0 commit comments

Comments
 (0)