Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/modules/Bots/playerbot/strategy/ItemVisitors.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#pragma once

#include "DBCStore.h"
#include "DBCStores.h"

Comment on lines +3 to +5
char * strstri (const char* str1, const char* str2);

namespace ai
Expand Down Expand Up @@ -280,6 +283,15 @@ namespace ai
map<uint32, int> count;
};

inline bool IsBuffFood(const ItemPrototype* proto)
{
if (proto->Class != ITEM_CLASS_CONSUMABLE ||
proto->Spells[0].SpellCategory != SPELLCATEGORY_FOOD)
return false;
SpellEntry const* sp = sSpellStore.LookupEntry(proto->Spells[0].SpellId);
return sp && ((sp->AttributesEx2 & SPELL_ATTR_EX2_FOOD_BUFF) || sp->Effect[1] != 0 || sp->Effect[2] != 0);
Comment on lines +291 to +292
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those effect indexes were what I found used in the actual game with actual buff food, and which does not match non-buff food. I think Copilot is off here, but shrug.

}

class FindFoodVisitor : public FindUsableItemVisitor
{
public:
Expand All @@ -297,6 +309,36 @@ namespace ai
uint32 spellCategory;
};

class FindBuffFoodVisitor : public FindUsableItemVisitor
{
public:
FindBuffFoodVisitor(Player* bot) : FindUsableItemVisitor(bot) {}

virtual bool Accept(const ItemPrototype* proto)
{
return IsBuffFood(proto);
}
};

inline bool HasFoodBuff(Player* bot, const list<Item*>& buffFoods)
{
for (Item* item : buffFoods)
{
SpellEntry const* sp = sSpellStore.LookupEntry(item->GetProto()->Spells[0].SpellId);
if (!sp)
continue;
if (bot->HasAura(sp->Id))
return true;
for (int i = 1; i < MAX_EFFECT_INDEX; ++i)
{
uint32 triggerSpell = sp->EffectTriggerSpell[i];
if (triggerSpell && bot->HasAura(triggerSpell))
return true;
Comment on lines +330 to +336
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as before.

}
}
return false;
}

class FindConjuredFoodVisitor : public FindUsableItemVisitor
{
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,13 @@ list<Item*> InventoryAction::parseItems(string text)
found.insert(visitor.GetResult().begin(), visitor.GetResult().end());
}

if (text == "buff food")
{
FindBuffFoodVisitor visitor(bot);
IterateItems(&visitor, ITERATE_ITEMS_IN_BAGS);
found.insert(visitor.GetResult().begin(), visitor.GetResult().end());
}

if (text == "drink")
{
FindFoodVisitor visitor(bot, SPELLCATEGORY_DRINK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "../Action.h"
#include "UseItemAction.h"
#include "../../PlayerbotAIConfig.h"
#include "../ItemVisitors.h"

namespace ai
{
Expand Down Expand Up @@ -55,7 +56,13 @@ namespace ai
if (ai->IsEating())
return true;

bool result = UseItemAction::Execute(event);
bool result = false;
list<Item*> buffFoods = AI_VALUE2(list<Item*>, "inventory items", "buff food");
if (!buffFoods.empty() && !HasFoodBuff(bot, buffFoods))
result = UseItemAuto(*buffFoods.begin());
Comment on lines +59 to +62
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If Copilot is not hallucinating here, then this is a good change. It's true that I did not make any assumptions about what might be listed as a buff spell for buff food like Copilot is here. This means that I'm ONLY preventing a bot from re-applying the same buff food spell as it currently knows about from its own inventory.

if (!result)
result = UseItemAction::Execute(event);

if (result)
ai->SetEating();
return result;
Expand Down
Loading