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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/modules/Bots/playerbot/strategy/ItemVisitors.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ namespace ai
{
return FindItemVisitor::Visit(item);
}

return true;
}

Expand Down Expand Up @@ -286,6 +285,7 @@ namespace ai
inline bool IsBuffFood(const ItemPrototype* proto)
{
if (proto->Class != ITEM_CLASS_CONSUMABLE ||
proto->SubClass == ITEM_SUBCLASS_BANDAGE ||
proto->Spells[0].SpellCategory != SPELLCATEGORY_FOOD)
return false;
SpellEntry const* sp = sSpellStore.LookupEntry(proto->Spells[0].SpellId);
Expand Down Expand Up @@ -355,4 +355,20 @@ namespace ai
private:
uint32 spellCategory;
};

class FindLikeItemVisitor : public FindItemVisitor
{
public:
FindLikeItemVisitor(Item *item) : FindItemVisitor()
{
this->itemId = item->GetProto()->ItemId;
}

virtual bool Accept(const ItemPrototype* proto)
{
return proto->ItemId == itemId;
}
private:
uint32 itemId;
};
}
12 changes: 10 additions & 2 deletions src/modules/Bots/playerbot/strategy/actions/NonCombatActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ namespace ai
if (!buffFoods.empty() && !HasFoodBuff(bot, buffFoods))
result = UseItemAuto(*buffFoods.begin());
if (!result)
result = UseItemAction::Execute(event);
{
list<Item*> foods = AI_VALUE2(list<Item*>, "inventory items", "food");
if (!foods.empty())
result = UseItemAuto(*foods.begin());
}

if (result)
ai->SetEating();
Expand All @@ -70,7 +74,11 @@ namespace ai

virtual bool isPossible()
{
return ai->IsEating() || UseItemAction::isPossible();
if (ai->IsEating())
return true;
if(AI_VALUE2(list<Item*>, "inventory items", "food").empty())
return false;
return UseItemAction::isPossible();
}

virtual bool isUseful()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ void GenericMageNonCombatStrategy::InitTriggers(std::list<TriggerNode*> &trigger
NULL)));

triggers.push_back(new TriggerNode(
"no drink",
"no conjured drink",
NextAction::array(0, new NextAction("conjure water", 16.0f), NULL)));

triggers.push_back(new TriggerNode(
"no food",
"no conjured food",
NextAction::array(0, new NextAction("conjure food", 15.0f), NULL)));

triggers.push_back(new TriggerNode(
Expand Down
26 changes: 11 additions & 15 deletions src/modules/Bots/playerbot/strategy/mage/MageActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Value<Unit*>* CastPolymorphAction::GetTargetValue()
return context->GetValue<Unit*>("cc target", getName());
}

static Player* FindPartyMemberWithoutSustenance(Player* bot, bool food)
static Player* FindPartyMemberWithoutSustenance(Player* bot, Item *item)
{
Group* group = bot->GetGroup();
if (!group)
Expand All @@ -30,21 +30,17 @@ static Player* FindPartyMemberWithoutSustenance(Player* bot, bool food)
{
continue;
}
if (!food && player->GetPowerType() != POWER_MANA)
if (bot->CanUseItem(item->GetProto()) != EQUIP_ERR_OK)
{
continue;
}
bool hasItem;
if (food)
bool isWater = item->GetProto()->Spells[0].SpellCategory == SPELLCATEGORY_DRINK;
if (isWater && player->GetPowerType() != POWER_MANA)
{
FindConjuredFoodVisitor foodVisitor(player, SPELLCATEGORY_FOOD);
hasItem = InventoryAction::FindPlayerItem(player, &foodVisitor) != NULL;
}
else
{
FindConjuredFoodVisitor drinkVisitor(player, SPELLCATEGORY_DRINK);
hasItem = InventoryAction::FindPlayerItem(player, &drinkVisitor) != NULL;
continue;
}
FindLikeItemVisitor itemVisitor(item);
bool hasItem = InventoryAction::FindPlayerItem(player, &itemVisitor) != NULL;
if (!hasItem)
return player;
}
Expand All @@ -71,7 +67,7 @@ bool GiveConjuredFoodAction::Execute(Event event)
}
Item* food = foods.front();

Player* target = FindPartyMemberWithoutSustenance(bot, true);
Player* target = FindPartyMemberWithoutSustenance(bot, food);
if (!target)
{
return false;
Expand All @@ -81,7 +77,7 @@ bool GiveConjuredFoodAction::Execute(Event event)
uint32 count = food->GetCount();

Item* newItem = target->StoreNewItemInInventorySlot(itemId, count);
if (!newItem)
if (!newItem || target->CanUseItem(newItem->GetProto()) != EQUIP_ERR_OK)
return false;

bot->DestroyItem(food->GetBagSlot(), food->GetSlot(), true);
Expand Down Expand Up @@ -117,15 +113,15 @@ bool GiveConjuredWaterAction::Execute(Event event)
return false;
Item* water = drinks.front();

Player* target = FindPartyMemberWithoutSustenance(bot, false);
Player* target = FindPartyMemberWithoutSustenance(bot, water);
if (!target)
return false;

uint32 itemId = water->GetEntry();
uint32 count = water->GetCount();

Item* newItem = target->StoreNewItemInInventorySlot(itemId, count);
if (!newItem)
if (!newItem || target->CanUseItem(newItem->GetProto()) != EQUIP_ERR_OK)
return false;

bot->DestroyItem(water->GetBagSlot(), water->GetSlot(), true);
Expand Down
12 changes: 12 additions & 0 deletions src/modules/Bots/playerbot/strategy/triggers/GenericTriggers.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,24 @@ namespace ai
virtual bool IsActive() { return AI_VALUE2(list<Item*>, "inventory items", "food").empty(); }
};

class NoConjuredFoodTrigger : public Trigger {
public:
NoConjuredFoodTrigger(PlayerbotAI* ai) : Trigger(ai, "no conjured food trigger") {}
virtual bool IsActive() { return AI_VALUE2(list<Item*>, "inventory items", "conjured food").empty(); }
};

class NoDrinkTrigger : public Trigger {
public:
NoDrinkTrigger(PlayerbotAI* ai) : Trigger(ai, "no drink trigger") {}
virtual bool IsActive() { return AI_VALUE2(list<Item*>, "inventory items", "drink").empty(); }
};

class NoConjuredDrinkTrigger : public Trigger {
public:
NoConjuredDrinkTrigger(PlayerbotAI* ai) : Trigger(ai, "no conjured drink trigger") {}
virtual bool IsActive() { return AI_VALUE2(list<Item*>, "inventory items", "conjured drink").empty(); }
};

class LightAoeTrigger : public AoeTrigger
{
public:
Expand Down
4 changes: 4 additions & 0 deletions src/modules/Bots/playerbot/strategy/triggers/TriggerContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ namespace ai
creators["no possible targets"] = &TriggerContext::no_possible_targets;

creators["no drink"] = &TriggerContext::no_drink;
creators["no conjured drink"] = &TriggerContext::no_conjured_drink;
creators["no food"] = &TriggerContext::no_food;
creators["no conjured food"] = &TriggerContext::no_conjured_food;

creators["panic"] = &TriggerContext::panic;
creators["behind target"] = &TriggerContext::behind_target;
Expand Down Expand Up @@ -110,7 +112,9 @@ namespace ai
static Trigger* not_facing_target(PlayerbotAI* ai) { return new IsNotFacingTargetTrigger(ai); }
static Trigger* panic(PlayerbotAI* ai) { return new PanicTrigger(ai); }
static Trigger* no_drink(PlayerbotAI* ai) { return new NoDrinkTrigger(ai); }
static Trigger* no_conjured_drink(PlayerbotAI* ai) { return new NoConjuredDrinkTrigger(ai); }
static Trigger* no_food(PlayerbotAI* ai) { return new NoFoodTrigger(ai); }
static Trigger* no_conjured_food(PlayerbotAI* ai) { return new NoConjuredFoodTrigger(ai); }
static Trigger* LightAoe(PlayerbotAI* ai) { return new LightAoeTrigger(ai); }
static Trigger* MediumAoe(PlayerbotAI* ai) { return new MediumAoeTrigger(ai); }
static Trigger* HighAoe(PlayerbotAI* ai) { return new HighAoeTrigger(ai); }
Expand Down
Loading