Skip to content

Commit b3f996e

Browse files
committed
bandages for bots
1 parent 2ec8982 commit b3f996e

8 files changed

Lines changed: 88 additions & 1 deletion

File tree

src/game/Server/SharedDefines.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,6 +2058,7 @@ enum CorpseDynFlags
20582058
#define SPELL_ID_PASSIVE_RESURRECTION_SICKNESS 15007
20592059
#define SPELL_ID_WEAPON_SWITCH_COOLDOWN_1_5s 6119
20602060
#define SPELL_ID_WEAPON_SWITCH_COOLDOWN_1_0s 6123
2061+
#define SPELL_ID_RECENTLY_BANDAGED 11196
20612062

20622063
enum WeatherType
20632064
{

src/game/WorldHandlers/Spell.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3207,7 +3207,7 @@ void Spell::cast(bool skipCheck)
32073207
// Bandages
32083208
if (m_spellInfo->Mechanic == MECHANIC_BANDAGE)
32093209
{
3210-
AddPrecastSpell(11196); // Recently Bandaged
3210+
AddPrecastSpell(SPELL_ID_RECENTLY_BANDAGED);
32113211
}
32123212
// Divine Shield, Divine Protection (Blessing of Protection in paladin switch case)
32133213
else if (m_spellInfo->Mechanic == MECHANIC_INVULNERABILITY)

src/modules/Bots/playerbot/strategy/Strategy.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class ActionNodeFactoryInternal : public NamedObjectFactory<ActionNode>
2222
creators["drink"] = &drink;
2323
creators["mana potion"] = &mana_potion;
2424
creators["healing potion"] = &healing_potion;
25+
creators["bandage"] = &bandage;
2526
creators["flee"] = &flee;
2627
}
2728

@@ -96,6 +97,13 @@ class ActionNodeFactoryInternal : public NamedObjectFactory<ActionNode>
9697
/*A*/ NextAction::array(0, new NextAction("food"), NULL),
9798
/*C*/ NULL);
9899
}
100+
static ActionNode* bandage(PlayerbotAI* ai)
101+
{
102+
return new ActionNode ("bandage",
103+
/*P*/ NULL,
104+
/*A*/ NULL,
105+
/*C*/ NULL);
106+
}
99107
static ActionNode* flee(PlayerbotAI* ai)
100108
{
101109
return new ActionNode ("flee",

src/modules/Bots/playerbot/strategy/actions/ActionContext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace ai
3333
creators["end pull"] = &ActionContext::end_pull;
3434
creators["healthstone"] = &ActionContext::healthstone;
3535
creators["healing potion"] = &ActionContext::healing_potion;
36+
creators["bandage"] = &ActionContext::bandage;
3637
creators["mana potion"] = &ActionContext::mana_potion;
3738
creators["food"] = &ActionContext::food;
3839
creators["drink"] = &ActionContext::drink;
@@ -109,6 +110,7 @@ namespace ai
109110
static Action* food(PlayerbotAI* ai) { return new EatAction(ai); }
110111
static Action* mana_potion(PlayerbotAI* ai) { return new UseManaPotion(ai); }
111112
static Action* healing_potion(PlayerbotAI* ai) { return new UseHealingPotion(ai); }
113+
static Action* bandage(PlayerbotAI* ai) { return new UseBandage(ai); }
112114
static Action* healthstone(PlayerbotAI* ai) { return new UseItemAction(ai, "healthstone"); }
113115
static Action* move_out_of_enemy_contact(PlayerbotAI* ai) { return new MoveOutOfEnemyContactAction(ai); }
114116
static Action* set_facing(PlayerbotAI* ai) { return new SetFacingTargetAction(ai); }

src/modules/Bots/playerbot/strategy/actions/InventoryAction.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ class FindPotionVisitor : public FindUsableItemVisitor
4242
uint32 effectId;
4343
};
4444

45+
class FindBandageVisitor : public FindUsableItemVisitor
46+
{
47+
public:
48+
FindBandageVisitor(Player* bot) : FindUsableItemVisitor(bot) {}
49+
50+
virtual bool Accept(const ItemPrototype* proto)
51+
{
52+
return proto->Class == ITEM_CLASS_CONSUMABLE &&
53+
proto->SubClass == ITEM_SUBCLASS_BANDAGE;
54+
}
55+
};
56+
4557
class FindManaGemVisitor : public FindUsableItemVisitor
4658
{
4759
public:
@@ -313,6 +325,13 @@ list<Item*> InventoryAction::parseItems(string text)
313325
found.insert(visitor.GetResult().begin(), visitor.GetResult().end());
314326
}
315327

328+
if (text == "bandage")
329+
{
330+
FindBandageVisitor visitor(bot);
331+
IterateItems(&visitor, ITERATE_ITEMS_IN_BAGS);
332+
found.insert(visitor.GetResult().begin(), visitor.GetResult().end());
333+
}
334+
316335
if (text == "mana gem")
317336
{
318337
FindManaGemVisitor visitor(bot);

src/modules/Bots/playerbot/strategy/actions/UseItemAction.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,55 @@ namespace ai
4040
virtual bool isUseful() { return AI_VALUE2(bool, "combat", "self target"); }
4141
};
4242

43+
class UseBandage : public UseItemAction
44+
{
45+
public:
46+
UseBandage(PlayerbotAI* ai) : UseItemAction(ai, "bandage"), m_isBandaging(false) {}
47+
48+
virtual bool Execute(Event event)
49+
{
50+
if (m_isBandaging)
51+
{
52+
ai->SetNextCheckDelay(500);
53+
return true;
54+
}
55+
56+
list<Item*> items = AI_VALUE2(list<Item*>, "inventory items", "bandage");
57+
if (items.empty())
58+
return false;
59+
60+
bool result = UseItemAuto(*items.begin());
61+
if (result)
62+
{
63+
m_isBandaging = true;
64+
ai->SetNextCheckDelay(500);
65+
}
66+
return result;
67+
}
68+
69+
virtual bool isPossible()
70+
{
71+
if (m_isBandaging && !bot->GetCurrentSpell(CURRENT_CHANNELED_SPELL))
72+
m_isBandaging = false;
73+
if (m_isBandaging)
74+
return true;
75+
return UseItemAction::isPossible();
76+
}
77+
78+
virtual bool isUseful()
79+
{
80+
if (bot->HasAura(SPELL_ID_RECENTLY_BANDAGED))
81+
return false;
82+
if (AI_VALUE2(bool, "combat", "self target"))
83+
return bot->getAttackers().empty();
84+
return bot->GetGroup() &&
85+
AI_VALUE2(list<Item*>, "inventory items", "food").empty();
86+
}
87+
88+
private:
89+
bool m_isBandaging;
90+
};
91+
4392
class UseManaPotion : public UseItemAction
4493
{
4594
public:

src/modules/Bots/playerbot/strategy/generic/UseFoodStrategy.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ void UseFoodStrategy::InitTriggers(std::list<TriggerNode*> &triggers)
1515
triggers.push_back(new TriggerNode(
1616
"thirsty",
1717
NextAction::array(0, new NextAction("drink", 2.0f), NULL)));
18+
19+
triggers.push_back(new TriggerNode(
20+
"hungry",
21+
NextAction::array(0, new NextAction("bandage", 1.5f), NULL)));
1822
}

src/modules/Bots/playerbot/strategy/generic/UsePotionsStrategy.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ void UsePotionsStrategy::InitTriggers(std::list<TriggerNode*> &triggers)
88
{
99
Strategy::InitTriggers(triggers);
1010

11+
triggers.push_back(new TriggerNode(
12+
"critical health",
13+
NextAction::array(0, new NextAction("bandage", ACTION_MEDIUM_HEAL + 1), NULL)));
14+
1115
triggers.push_back(new TriggerNode(
1216
"critical health",
1317
NextAction::array(0, new NextAction("healing potion", ACTION_MEDIUM_HEAL), NULL)));

0 commit comments

Comments
 (0)