mirror of
https://github.com/mod-playerbots/mod-playerbots
synced 2025-11-29 15:58:20 +08:00
Fixes equip bug with random suffix rings (#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.
This commit is contained in:
@@ -271,19 +271,38 @@ void EquipAction::EquipItem(Item* item)
|
|||||||
{
|
{
|
||||||
if (equippedItems[1])
|
if (equippedItems[1])
|
||||||
{
|
{
|
||||||
// Both slots are full - pick the worst item to replace
|
// Both slots are full - pick the worst item to replace, but only if new item is better
|
||||||
StatsWeightCalculator calc(bot);
|
StatsWeightCalculator calc(bot);
|
||||||
calc.SetItemSetBonus(false);
|
calc.SetItemSetBonus(false);
|
||||||
calc.SetOverflowPenalty(false);
|
calc.SetOverflowPenalty(false);
|
||||||
|
|
||||||
float firstItemScore = calc.CalculateItem(equippedItems[0]->GetTemplate()->ItemId);
|
// Calculate new item score with random properties
|
||||||
float secondItemScore = calc.CalculateItem(equippedItems[1]->GetTemplate()->ItemId);
|
int32 newItemRandomProp = item->GetItemRandomPropertyId();
|
||||||
|
float newItemScore = calc.CalculateItem(itemId, newItemRandomProp);
|
||||||
|
|
||||||
// If the second slot is worse, place the new item there
|
// Calculate equipped items scores with random properties
|
||||||
if (firstItemScore > secondItemScore)
|
int32 firstRandomProp = equippedItems[0]->GetItemRandomPropertyId();
|
||||||
|
int32 secondRandomProp = equippedItems[1]->GetItemRandomPropertyId();
|
||||||
|
float firstItemScore = calc.CalculateItem(equippedItems[0]->GetTemplate()->ItemId, firstRandomProp);
|
||||||
|
float secondItemScore = calc.CalculateItem(equippedItems[1]->GetTemplate()->ItemId, secondRandomProp);
|
||||||
|
|
||||||
|
// Determine which slot (if any) should be replaced
|
||||||
|
bool betterThanFirst = newItemScore > firstItemScore;
|
||||||
|
bool betterThanSecond = newItemScore > secondItemScore;
|
||||||
|
|
||||||
|
// Early return if new item is not better than either equipped item
|
||||||
|
if (!betterThanFirst && !betterThanSecond)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (betterThanFirst && betterThanSecond)
|
||||||
{
|
{
|
||||||
dstSlot++;
|
// New item is better than both - replace the worse of the two equipped items
|
||||||
|
if (firstItemScore > secondItemScore)
|
||||||
|
dstSlot++; // Replace second slot (worse)
|
||||||
|
// else: keep dstSlot as-is (replace first slot)
|
||||||
}
|
}
|
||||||
|
else if (betterThanSecond)
|
||||||
|
dstSlot++; // Only better than second slot - replace it
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user