Skip to content

Commit fab6a0a

Browse files
authored
Equip: Prevent equipping wrong weapon types (#230)
1 parent 5ec860e commit fab6a0a

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

playerbot/RandomItemMgr.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ bool RandomItemMgr::ShouldEquipWeaponForSpec(uint8 playerclass, uint8 spec, Item
600600
else
601601
{
602602
mh_weapons = { ITEM_SUBCLASS_WEAPON_SWORD, ITEM_SUBCLASS_WEAPON_AXE, ITEM_SUBCLASS_WEAPON_MACE, ITEM_SUBCLASS_WEAPON_FIST };
603+
oh_weapons = { ITEM_SUBCLASS_WEAPON_SWORD, ITEM_SUBCLASS_WEAPON_AXE, ITEM_SUBCLASS_WEAPON_MACE, ITEM_SUBCLASS_WEAPON_FIST };
603604
r_weapons = { ITEM_SUBCLASS_WEAPON_BOW, ITEM_SUBCLASS_WEAPON_CROSSBOW, ITEM_SUBCLASS_WEAPON_GUN };
604605
}
605606
break;

playerbot/strategy/values/ItemUsageValue.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ ItemUsage ItemUsageValue::QueryItemUsageForEquip(ItemQualifier& itemQualifier, P
578578
}
579579

580580
bool shouldEquip = false;
581+
bool isAllowedForSpec = true;
581582

582583
uint32 specId = sRandomItemMgr.GetPlayerSpecId(bot);
583584

@@ -591,6 +592,19 @@ ItemUsage ItemUsageValue::QueryItemUsageForEquip(ItemQualifier& itemQualifier, P
591592
shouldEquip = false;
592593

593594
Item* oldItem = bot->GetItemByPos(dest);
595+
Item* oldMH = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND);
596+
Item* oldOH = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_OFFHAND);
597+
598+
bool mhEmpty = !oldMH;
599+
bool ohEmpty = !oldOH;
600+
bool bothHandsEmpty = mhEmpty && ohEmpty;
601+
602+
if (itemProto->Class == ITEM_CLASS_WEAPON &&
603+
!sRandomItemMgr.ShouldEquipWeaponForSpec(bot->getClass(), specId, itemProto))
604+
{
605+
if (!bothHandsEmpty)
606+
return ItemUsage::ITEM_USAGE_NONE;
607+
}
594608

595609
//No item equiped
596610
if (!oldItem)
@@ -667,7 +681,7 @@ ItemUsage ItemUsageValue::QueryItemUsageForEquip(ItemQualifier& itemQualifier, P
667681
Item* item = CurrentItem(itemProto, bot);
668682
bool itemIsBroken = item && item->GetUInt32Value(ITEM_FIELD_DURABILITY) == 0 && item->GetUInt32Value(ITEM_FIELD_MAXDURABILITY) > 0;
669683
bool oldItemIsBroken = oldItem->GetUInt32Value(ITEM_FIELD_DURABILITY) == 0 && oldItem->GetUInt32Value(ITEM_FIELD_MAXDURABILITY) > 0;
670-
if (itemProto->ItemId != oldItemProto->ItemId && (shouldEquip || !existingShouldEquip) && isBetter)
684+
if (isAllowedForSpec && itemProto->ItemId != oldItemProto->ItemId && (shouldEquip || !existingShouldEquip) && isBetter)
671685
{
672686
switch (itemProto->Class)
673687
{

0 commit comments

Comments
 (0)