diff --git a/src/game/Server/SharedDefines.h b/src/game/Server/SharedDefines.h index 79f0b7512..42dd259fb 100644 --- a/src/game/Server/SharedDefines.h +++ b/src/game/Server/SharedDefines.h @@ -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 { diff --git a/src/game/WorldHandlers/Spell.cpp b/src/game/WorldHandlers/Spell.cpp index 02b382ee6..52549f196 100644 --- a/src/game/WorldHandlers/Spell.cpp +++ b/src/game/WorldHandlers/Spell.cpp @@ -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) diff --git a/src/modules/Bots/playerbot/strategy/Strategy.cpp b/src/modules/Bots/playerbot/strategy/Strategy.cpp index 1ef653527..6afd97344 100644 --- a/src/modules/Bots/playerbot/strategy/Strategy.cpp +++ b/src/modules/Bots/playerbot/strategy/Strategy.cpp @@ -22,6 +22,7 @@ class ActionNodeFactoryInternal : public NamedObjectFactory creators["drink"] = &drink; creators["mana potion"] = &mana_potion; creators["healing potion"] = &healing_potion; + creators["bandage"] = &bandage; creators["flee"] = &flee; } @@ -96,6 +97,13 @@ class ActionNodeFactoryInternal : public NamedObjectFactory /*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", diff --git a/src/modules/Bots/playerbot/strategy/actions/ActionContext.h b/src/modules/Bots/playerbot/strategy/actions/ActionContext.h index 15d7b1fef..bb84dc7d0 100644 --- a/src/modules/Bots/playerbot/strategy/actions/ActionContext.h +++ b/src/modules/Bots/playerbot/strategy/actions/ActionContext.h @@ -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; @@ -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); } diff --git a/src/modules/Bots/playerbot/strategy/actions/InventoryAction.cpp b/src/modules/Bots/playerbot/strategy/actions/InventoryAction.cpp index 829c48f06..ba71fd36c 100644 --- a/src/modules/Bots/playerbot/strategy/actions/InventoryAction.cpp +++ b/src/modules/Bots/playerbot/strategy/actions/InventoryAction.cpp @@ -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: @@ -313,6 +325,13 @@ list 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); diff --git a/src/modules/Bots/playerbot/strategy/actions/UseItemAction.h b/src/modules/Bots/playerbot/strategy/actions/UseItemAction.h index 929f28c1d..4b095598f 100644 --- a/src/modules/Bots/playerbot/strategy/actions/UseItemAction.h +++ b/src/modules/Bots/playerbot/strategy/actions/UseItemAction.h @@ -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 items = AI_VALUE2(list, "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, "inventory items", "food").empty(); + } + + private: + bool m_isBandaging; + }; + class UseManaPotion : public UseItemAction { public: diff --git a/src/modules/Bots/playerbot/strategy/generic/UseFoodStrategy.cpp b/src/modules/Bots/playerbot/strategy/generic/UseFoodStrategy.cpp index 5e80c3e92..c0e7eed24 100644 --- a/src/modules/Bots/playerbot/strategy/generic/UseFoodStrategy.cpp +++ b/src/modules/Bots/playerbot/strategy/generic/UseFoodStrategy.cpp @@ -15,4 +15,8 @@ void UseFoodStrategy::InitTriggers(std::list &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))); } diff --git a/src/modules/Bots/playerbot/strategy/generic/UsePotionsStrategy.cpp b/src/modules/Bots/playerbot/strategy/generic/UsePotionsStrategy.cpp index 4abcf746f..6d6dc9e0f 100644 --- a/src/modules/Bots/playerbot/strategy/generic/UsePotionsStrategy.cpp +++ b/src/modules/Bots/playerbot/strategy/generic/UsePotionsStrategy.cpp @@ -8,6 +8,10 @@ void UsePotionsStrategy::InitTriggers(std::list &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)));