mirror of
https://github.com/mod-playerbots/mod-playerbots.git
synced 2026-01-13 17:09:08 +00:00
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:
@@ -64,8 +64,9 @@ ItemUsage ItemUsageValue::Calculate()
|
||||
|
||||
if (proto->Class == ITEM_CLASS_KEY)
|
||||
return ITEM_USAGE_USE;
|
||||
|
||||
if (proto->Class == ITEM_CLASS_CONSUMABLE)
|
||||
|
||||
if (proto->Class == ITEM_CLASS_CONSUMABLE &&
|
||||
(proto->MaxCount == 0 || AI_VALUE2(uint32, "item count", proto->Name1) < proto->MaxCount))
|
||||
{
|
||||
std::string const foodType = GetConsumableType(proto, bot->GetPower(POWER_MANA));
|
||||
|
||||
@@ -103,39 +104,67 @@ ItemUsage ItemUsageValue::Calculate()
|
||||
return ITEM_USAGE_QUEST;
|
||||
|
||||
if (proto->Class == ITEM_CLASS_PROJECTILE && bot->CanUseItem(proto) == EQUIP_ERR_OK)
|
||||
{
|
||||
if (bot->getClass() == CLASS_HUNTER || bot->getClass() == CLASS_ROGUE || bot->getClass() == CLASS_WARRIOR)
|
||||
{
|
||||
if (Item* const pItem = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_RANGED))
|
||||
Item* rangedWeapon = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_RANGED);
|
||||
uint32 requiredSubClass = 0;
|
||||
|
||||
if (rangedWeapon)
|
||||
{
|
||||
uint32 subClass = 0;
|
||||
switch (pItem->GetTemplate()->SubClass)
|
||||
switch (rangedWeapon->GetTemplate()->SubClass)
|
||||
{
|
||||
case ITEM_SUBCLASS_WEAPON_GUN:
|
||||
subClass = ITEM_SUBCLASS_BULLET;
|
||||
requiredSubClass = ITEM_SUBCLASS_BULLET;
|
||||
break;
|
||||
case ITEM_SUBCLASS_WEAPON_BOW:
|
||||
case ITEM_SUBCLASS_WEAPON_CROSSBOW:
|
||||
subClass = ITEM_SUBCLASS_ARROW;
|
||||
requiredSubClass = ITEM_SUBCLASS_ARROW;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (proto->SubClass == subClass)
|
||||
// Ensure the item is the correct ammo type for the equipped ranged weapon
|
||||
if (proto->SubClass == requiredSubClass)
|
||||
{
|
||||
float ammoCount = BetterStacks(proto, "ammo");
|
||||
float requiredAmmo = (bot->getClass() == CLASS_HUNTER) ? 8 : 2; // Hunters get 8 stacks, others 2
|
||||
uint32 currentAmmoId = bot->GetUInt32Value(PLAYER_AMMO_ID);
|
||||
|
||||
// Check if the bot has an ammo type assigned
|
||||
if (currentAmmoId == 0)
|
||||
{
|
||||
float ammo = BetterStacks(proto, "ammo");
|
||||
float needAmmo = (bot->getClass() == CLASS_HUNTER) ? 8 : 2;
|
||||
|
||||
if (ammo < needAmmo) // We already have enough of the current ammo.
|
||||
return ITEM_USAGE_EQUIP; // Equip the ammo if no ammo
|
||||
}
|
||||
// Compare new ammo vs current equipped ammo
|
||||
ItemTemplate const* currentAmmoProto = sObjectMgr->GetItemTemplate(currentAmmoId);
|
||||
if (currentAmmoProto)
|
||||
{
|
||||
uint32 currentAmmoDPS = (currentAmmoProto->Damage[0].DamageMin + currentAmmoProto->Damage[0].DamageMax) * 1000 / 2;
|
||||
uint32 newAmmoDPS = (proto->Damage[0].DamageMin + proto->Damage[0].DamageMax) * 1000 / 2;
|
||||
|
||||
if (newAmmoDPS > currentAmmoDPS) // New ammo meets upgrade condition
|
||||
{
|
||||
ammo += CurrentStacks(proto);
|
||||
|
||||
if (ammo < needAmmo) // Buy ammo to get to the proper supply
|
||||
return ITEM_USAGE_AMMO;
|
||||
else if (ammo < needAmmo + 1)
|
||||
return ITEM_USAGE_KEEP; // Keep the ammo until we have too much.
|
||||
return ITEM_USAGE_EQUIP;
|
||||
}
|
||||
if (newAmmoDPS < currentAmmoDPS) // New ammo is worse
|
||||
{
|
||||
return ITEM_USAGE_NONE;
|
||||
}
|
||||
}
|
||||
// Ensure we have enough ammo in the inventory
|
||||
if (ammoCount < requiredAmmo)
|
||||
{
|
||||
ammoCount += CurrentStacks(proto);
|
||||
|
||||
if (ammoCount < requiredAmmo) // Buy ammo to reach the proper supply
|
||||
return ITEM_USAGE_AMMO;
|
||||
else if (ammoCount < requiredAmmo + 1)
|
||||
return ITEM_USAGE_KEEP; // Keep the ammo if we don't have too much.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Need to add something like free bagspace or item value.
|
||||
if (proto->SellPrice > 0)
|
||||
|
||||
Reference in New Issue
Block a user