Skip to content
Merged
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
1 change: 1 addition & 0 deletions src/game/Server/SharedDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -2058,6 +2058,7 @@ enum CorpseDynFlags
#define SPELL_ID_PASSIVE_RESURRECTION_SICKNESS 15007
#define SPELL_ID_WEAPON_SWITCH_COOLDOWN_1_5s 6119
#define SPELL_ID_WEAPON_SWITCH_COOLDOWN_1_0s 6123
#define SPELL_ID_RECENTLY_BANDAGED 11196

enum WeatherType
{
Expand Down
2 changes: 1 addition & 1 deletion src/game/WorldHandlers/Spell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3207,7 +3207,7 @@ void Spell::cast(bool skipCheck)
// Bandages
if (m_spellInfo->Mechanic == MECHANIC_BANDAGE)
{
AddPrecastSpell(11196); // Recently Bandaged
AddPrecastSpell(SPELL_ID_RECENTLY_BANDAGED);
}
// Divine Shield, Divine Protection (Blessing of Protection in paladin switch case)
else if (m_spellInfo->Mechanic == MECHANIC_INVULNERABILITY)
Expand Down
8 changes: 8 additions & 0 deletions src/modules/Bots/playerbot/strategy/Strategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ActionNodeFactoryInternal : public NamedObjectFactory<ActionNode>
creators["drink"] = &drink;
creators["mana potion"] = &mana_potion;
creators["healing potion"] = &healing_potion;
creators["bandage"] = &bandage;
creators["flee"] = &flee;
}

Expand Down Expand Up @@ -96,6 +97,13 @@ class ActionNodeFactoryInternal : public NamedObjectFactory<ActionNode>
/*A*/ NextAction::array(0, new NextAction("food"), NULL),
/*C*/ NULL);
}
static ActionNode* bandage(PlayerbotAI* ai)
{
return new ActionNode ("bandage",
/*P*/ NULL,
/*A*/ NULL,
/*C*/ NULL);
}
static ActionNode* flee(PlayerbotAI* ai)
{
return new ActionNode ("flee",
Expand Down
2 changes: 2 additions & 0 deletions src/modules/Bots/playerbot/strategy/actions/ActionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace ai
creators["end pull"] = &ActionContext::end_pull;
creators["healthstone"] = &ActionContext::healthstone;
creators["healing potion"] = &ActionContext::healing_potion;
creators["bandage"] = &ActionContext::bandage;
creators["mana potion"] = &ActionContext::mana_potion;
creators["food"] = &ActionContext::food;
creators["drink"] = &ActionContext::drink;
Expand Down Expand Up @@ -109,6 +110,7 @@ namespace ai
static Action* food(PlayerbotAI* ai) { return new EatAction(ai); }
static Action* mana_potion(PlayerbotAI* ai) { return new UseManaPotion(ai); }
static Action* healing_potion(PlayerbotAI* ai) { return new UseHealingPotion(ai); }
static Action* bandage(PlayerbotAI* ai) { return new UseBandage(ai); }
static Action* healthstone(PlayerbotAI* ai) { return new UseItemAction(ai, "healthstone"); }
static Action* move_out_of_enemy_contact(PlayerbotAI* ai) { return new MoveOutOfEnemyContactAction(ai); }
static Action* set_facing(PlayerbotAI* ai) { return new SetFacingTargetAction(ai); }
Expand Down
19 changes: 19 additions & 0 deletions src/modules/Bots/playerbot/strategy/actions/InventoryAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ class FindPotionVisitor : public FindUsableItemVisitor
uint32 effectId;
};

class FindBandageVisitor : public FindUsableItemVisitor
{
public:
explicit FindBandageVisitor(Player* bot) : FindUsableItemVisitor(bot) {}

virtual bool Accept(const ItemPrototype* proto)
{
return proto->Class == ITEM_CLASS_CONSUMABLE &&
proto->SubClass == ITEM_SUBCLASS_BANDAGE;
}
};

class FindManaGemVisitor : public FindUsableItemVisitor
{
public:
Expand Down Expand Up @@ -313,6 +325,13 @@ list<Item*> InventoryAction::parseItems(string text)
found.insert(visitor.GetResult().begin(), visitor.GetResult().end());
}

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

if (text == "mana gem")
{
FindManaGemVisitor visitor(bot);
Expand Down
49 changes: 49 additions & 0 deletions src/modules/Bots/playerbot/strategy/actions/UseItemAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,55 @@ namespace ai
virtual bool isUseful() { return AI_VALUE2(bool, "combat", "self target"); }
};

class UseBandage : public UseItemAction
{
public:
UseBandage(PlayerbotAI* ai) : UseItemAction(ai, "bandage"), m_isBandaging(false) {}

virtual bool Execute(Event event)
{
if (m_isBandaging)
{
ai->SetNextCheckDelay(500);
return true;
}

list<Item*> items = AI_VALUE2(list<Item*>, "inventory items", "bandage");
if (items.empty())
return false;

bool result = UseItemAuto(*items.begin());
if (result)
{
m_isBandaging = true;
ai->SetNextCheckDelay(500);
}
return result;
}

virtual bool isPossible()
{
if (m_isBandaging && !bot->GetCurrentSpell(CURRENT_CHANNELED_SPELL))
m_isBandaging = false;
if (m_isBandaging)
return true;
return UseItemAction::isPossible();
}

virtual bool isUseful()
{
if (bot->HasAura(SPELL_ID_RECENTLY_BANDAGED))
return false;
if (AI_VALUE2(bool, "combat", "self target"))
return bot->getAttackers().empty();
return bot->GetGroup() &&
AI_VALUE2(list<Item*>, "inventory items", "food").empty();
}

private:
bool m_isBandaging;
};

class UseManaPotion : public UseItemAction
{
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ void UseFoodStrategy::InitTriggers(std::list<TriggerNode*> &triggers)
triggers.push_back(new TriggerNode(
"thirsty",
NextAction::array(0, new NextAction("drink", 2.0f), NULL)));

triggers.push_back(new TriggerNode(
"hungry",
NextAction::array(0, new NextAction("bandage", 1.5f), NULL)));
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ void UsePotionsStrategy::InitTriggers(std::list<TriggerNode*> &triggers)
{
Strategy::InitTriggers(triggers);

triggers.push_back(new TriggerNode(
"critical health",
NextAction::array(0, new NextAction("bandage", ACTION_MEDIUM_HEAL + 1), NULL)));

triggers.push_back(new TriggerNode(
"critical health",
NextAction::array(0, new NextAction("healing potion", ACTION_MEDIUM_HEAL), NULL)));
Expand Down
Loading