Files
mod-playerbots/src/Ai/Base/Value/ItemUsageValue.h
Keleborn 3db2a5a193 Refactor of EquipActions (#1994)
#PR Description 

The root cause of issue #1987 was the AI Value item usage becoming a
very expensive call when bots gained professions accidentally.

My original approach was to eliminate it entirely, but after inputs and
testing I decided to introduce a more focused Ai value "Item upgrade"
that only checks equipment and ammo inheriting directly from item usage,
so the logic is unified between them.

Upgrades are now only assessed when receiving an item that can be
equipped.

Additionally, I noticed that winning loot rolls did not trigger the
upgrade action, so I added a new package handler for that.


Performance needs to be re-evaluated, but I expect a reduction in calls
and in the cost of each call.

I tested with bots and selfbot in deadmines and ahadowfang keep.

---------

Co-authored-by: bashermens <31279994+hermensbas@users.noreply.github.com>
2026-02-08 12:41:33 +01:00

83 lines
2.4 KiB
C++

/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license, you may redistribute it
* and/or modify it under version 3 of the License, or (at your option), any later version.
*/
#ifndef _PLAYERBOT_ITEMUSAGEVALUE_H
#define _PLAYERBOT_ITEMUSAGEVALUE_H
#include "NamedObjectContext.h"
#include "Value.h"
class Item;
class Player;
class PlayerbotAI;
struct ItemTemplate;
struct ParsedItemUsage
{
uint32 itemId = 0;
int32 randomPropertyId = 0;
};
enum ItemUsage : uint32
{
ITEM_USAGE_NONE = 0,
ITEM_USAGE_EQUIP = 1,
ITEM_USAGE_REPLACE = 2,
ITEM_USAGE_BAD_EQUIP = 3,
ITEM_USAGE_BROKEN_EQUIP = 4,
ITEM_USAGE_QUEST = 5,
ITEM_USAGE_SKILL = 6,
ITEM_USAGE_USE = 7,
ITEM_USAGE_GUILD_TASK = 8,
ITEM_USAGE_DISENCHANT = 9,
ITEM_USAGE_AH = 10,
ITEM_USAGE_KEEP = 11,
ITEM_USAGE_VENDOR = 12,
ITEM_USAGE_AMMO = 13
};
class ItemUsageValue : public CalculatedValue<ItemUsage>, public Qualified
{
public:
ItemUsageValue(PlayerbotAI* botAI, std::string const name = "item usage") : CalculatedValue<ItemUsage>(botAI, name)
{
}
ItemUsage Calculate() override;
protected:
ItemUsage QueryItemUsageForEquip(ItemTemplate const* proto, int32 randomPropertyId = 0);
ItemUsage QueryItemUsageForAmmo(ItemTemplate const* proto);
ParsedItemUsage GetItemIdFromQualifier();
private:
uint32 GetSmallestBagSize();
bool IsItemUsefulForQuest(Player* player, ItemTemplate const* proto);
bool IsItemNeededForSkill(ItemTemplate const* proto);
bool IsItemUsefulForSkill(ItemTemplate const* proto);
bool IsItemNeededForUsefullSpell(ItemTemplate const* proto, bool checkAllReagents = false);
bool HasItemsNeededForSpell(uint32 spellId, ItemTemplate const* proto);
Item* CurrentItem(ItemTemplate const* proto);
float CurrentStacks(ItemTemplate const* proto);
float BetterStacks(ItemTemplate const* proto, std::string const usageType = "");
public:
static std::vector<uint32> SpellsUsingItem(uint32 itemId, Player* bot);
static bool SpellGivesSkillUp(uint32 spellId, Player* bot);
static std::string const GetConsumableType(ItemTemplate const* proto, bool hasMana);
};
class ItemUpgradeValue : public ItemUsageValue
{
public:
ItemUpgradeValue(PlayerbotAI* botAI, std::string const name = "item upgrade") : ItemUsageValue(botAI, name)
{
}
ItemUsage Calculate() override;
};
#endif