Hunter ammo equip bug and other issues with BuyAction.cpp (#986)

Resolves #947

Equip logic was failing as projectiles were never returning ITEM_USAGE_EQUIP in ItemUsageValue.cpp, added two cases where equip is returned:

If no ammo is currently set
If new ammo has higher DPS than old/currently equipped ammo
While testing this using "b [itemlink]" and "b vendor" to purchase arrows I noticed some issues with BuyAction.cpp and have resolved them:

Bots will now perform the "equip upgrades" action for any bought item that has an equip usage
When using "b vendor" to buy all useful items from vendors within interaction distance, it now sorts the list of available items by calculated item score and buys the highest scoring item (if it is higher than the currently equipped item) for each slot. It should not buy multiple items for the same slot anymore, saving gold/emblems/etc.
"b vendor" will now only attempt to buy 1 of each item. Consumable and projectile item types can be bought up to 10 times per execution as long as it is still useful to buy the item in each iteration of the for loop. All items were following this behaviour previously and since the equip command was only given after the for loop it would buy 10 of an item before triggering it wasn't useful to buy more.
And finally, resolved issues where a bot runs out of ammo mid-fight:

Re-enabled combat and non-combat "no ammo" strategies to perform "equip upgrades" action.
Modified GenericTriggers.cpp; AmmoCountTrigger::IsActive to return true when the bot has ammo but it is not equipped yet.
This commit is contained in:
avirar
2025-02-22 04:32:10 +11:00
committed by GitHub
parent e33c61e90a
commit a0278f1efb
8 changed files with 181 additions and 34 deletions

View File

@@ -4867,6 +4867,40 @@ Item* PlayerbotAI::FindPoison() const
{ return pItemProto->Class == ITEM_CLASS_CONSUMABLE && pItemProto->SubClass == 6; });
}
// Find Ammo
Item* PlayerbotAI::FindAmmo() const
{
// Get equipped ranged weapon
if (Item* rangedWeapon = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_RANGED))
{
uint32 weaponSubClass = rangedWeapon->GetTemplate()->SubClass;
uint32 requiredAmmoType = 0;
// Determine the correct ammo type based on the weapon
switch (weaponSubClass)
{
case ITEM_SUBCLASS_WEAPON_GUN:
requiredAmmoType = ITEM_SUBCLASS_BULLET;
break;
case ITEM_SUBCLASS_WEAPON_BOW:
case ITEM_SUBCLASS_WEAPON_CROSSBOW:
requiredAmmoType = ITEM_SUBCLASS_ARROW;
break;
default:
return nullptr; // Not a ranged weapon that requires ammo
}
// Search inventory for the correct ammo type
return FindItemInInventory([requiredAmmoType](ItemTemplate const* pItemProto) -> bool
{
return pItemProto->Class == ITEM_CLASS_PROJECTILE &&
pItemProto->SubClass == requiredAmmoType;
});
}
return nullptr; // No ranged weapon equipped
}
// Find Consumable
Item* PlayerbotAI::FindConsumable(uint32 displayId) const
{