File tree Expand file tree Collapse file tree 3 files changed +57
-1
lines changed
src/modules/Bots/playerbot/strategy Expand file tree Collapse file tree 3 files changed +57
-1
lines changed Original file line number Diff line number Diff line change 11#pragma once
22
3+ #include " DBCStore.h"
4+ #include " DBCStores.h"
5+
36char * strstri (const char * str1, const char * str2);
47
58namespace ai
@@ -280,6 +283,15 @@ namespace ai
280283 map<uint32, int > count;
281284 };
282285
286+ inline bool IsBuffFood (const ItemPrototype* proto)
287+ {
288+ if (proto->Class != ITEM_CLASS_CONSUMABLE ||
289+ proto->Spells [0 ].SpellCategory != SPELLCATEGORY_FOOD)
290+ return false ;
291+ SpellEntry const * sp = sSpellStore .LookupEntry (proto->Spells [0 ].SpellId );
292+ return sp && ((sp->AttributesEx2 & SPELL_ATTR_EX2_FOOD_BUFF) || sp->Effect [1 ] != 0 || sp->Effect [2 ] != 0 );
293+ }
294+
283295 class FindFoodVisitor : public FindUsableItemVisitor
284296 {
285297 public:
@@ -297,6 +309,36 @@ namespace ai
297309 uint32 spellCategory;
298310 };
299311
312+ class FindBuffFoodVisitor : public FindUsableItemVisitor
313+ {
314+ public:
315+ FindBuffFoodVisitor (Player* bot) : FindUsableItemVisitor(bot) {}
316+
317+ virtual bool Accept (const ItemPrototype* proto)
318+ {
319+ return IsBuffFood (proto);
320+ }
321+ };
322+
323+ inline bool HasFoodBuff (Player* bot, const list<Item*>& buffFoods)
324+ {
325+ for (Item* item : buffFoods)
326+ {
327+ SpellEntry const * sp = sSpellStore .LookupEntry (item->GetProto ()->Spells [0 ].SpellId );
328+ if (!sp)
329+ continue ;
330+ if (bot->HasAura (sp->Id ))
331+ return true ;
332+ for (int i = 1 ; i < MAX_EFFECT_INDEX; ++i)
333+ {
334+ uint32 triggerSpell = sp->EffectTriggerSpell [i];
335+ if (triggerSpell && bot->HasAura (triggerSpell))
336+ return true ;
337+ }
338+ }
339+ return false ;
340+ }
341+
300342 class FindConjuredFoodVisitor : public FindUsableItemVisitor
301343 {
302344 public:
Original file line number Diff line number Diff line change @@ -278,6 +278,13 @@ list<Item*> InventoryAction::parseItems(string text)
278278 found.insert (visitor.GetResult ().begin (), visitor.GetResult ().end ());
279279 }
280280
281+ if (text == " buff food" )
282+ {
283+ FindBuffFoodVisitor visitor (bot);
284+ IterateItems (&visitor, ITERATE_ITEMS_IN_BAGS);
285+ found.insert (visitor.GetResult ().begin (), visitor.GetResult ().end ());
286+ }
287+
281288 if (text == " drink" )
282289 {
283290 FindFoodVisitor visitor (bot, SPELLCATEGORY_DRINK);
Original file line number Diff line number Diff line change 33#include " ../Action.h"
44#include " UseItemAction.h"
55#include " ../../PlayerbotAIConfig.h"
6+ #include " ../ItemVisitors.h"
67
78namespace ai
89{
@@ -55,7 +56,13 @@ namespace ai
5556 if (ai->IsEating ())
5657 return true ;
5758
58- bool result = UseItemAction::Execute (event);
59+ bool result = false ;
60+ list<Item*> buffFoods = AI_VALUE2 (list<Item*>, " inventory items" , " buff food" );
61+ if (!buffFoods.empty () && !HasFoodBuff (bot, buffFoods))
62+ result = UseItemAuto (*buffFoods.begin ());
63+ if (!result)
64+ result = UseItemAction::Execute (event);
65+
5966 if (result)
6067 ai->SetEating ();
6168 return result;
You can’t perform that action at this time.
0 commit comments