Skip to content

Commit d913136

Browse files
committed
spell target reach
1 parent 050a010 commit d913136

4 files changed

Lines changed: 36 additions & 16 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ namespace ai
6969
creators["drop target"] = &ActionContext::drop_target;
7070
creators["jump"] = &ActionContext::jump;
7171
creators["jump up"] = &ActionContext::jump_up;
72+
creators["back off"] = &ActionContext::back_off;
7273
}
7374

7475
private:
@@ -82,6 +83,7 @@ namespace ai
8283
static Action* melee(PlayerbotAI* ai) { return new MeleeAction(ai); }
8384
static Action* ReachSpell(PlayerbotAI* ai) { return new ReachSpellAction(ai); }
8485
static Action* ReachMelee(PlayerbotAI* ai) { return new ReachMeleeAction(ai); }
86+
static Action* back_off(PlayerbotAI* ai) { return new BackOffAction(ai); }
8587
static Action* flee(PlayerbotAI* ai) { return new FleeAction(ai); }
8688
static Action* gift_of_the_naaru(PlayerbotAI* ai) { return new CastGiftOfTheNaaruAction(ai); }
8789
static Action* lifeblood(PlayerbotAI* ai) { return new CastLifeBloodAction(ai); }

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

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,27 +77,22 @@ namespace ai
7777

7878
virtual NextAction** getPrerequisites()
7979
{
80-
float currentDistance = AI_VALUE2(float, "distance", GetTargetName());
81-
82-
if (currentDistance <= range)
83-
{
84-
if (range > ATTACK_DISTANCE)
85-
{
86-
return Action::getPrerequisites();
87-
}
88-
else
89-
{
90-
return NextAction::merge(NextAction::array(0, new NextAction("reach melee"), NULL), Action::getPrerequisites());
91-
}
92-
}
93-
9480
if (range > sPlayerbotAIConfig.spellDistance)
9581
{
9682
return NULL;
9783
}
9884
else if (range > ATTACK_DISTANCE)
9985
{
100-
return NextAction::merge( NextAction::array(0, new NextAction("reach spell"), NULL), Action::getPrerequisites());
86+
float currentDistance = AI_VALUE2(float, "distance", GetTargetName());
87+
if (currentDistance <= range)
88+
{
89+
return NextAction::merge(NextAction::array(0, new NextAction("back off"), NULL), Action::getPrerequisites());
90+
}
91+
else
92+
{
93+
context->GetValue<float>("reach spell distance")->Set(range);
94+
return NextAction::merge( NextAction::array(0, new NextAction("reach spell"), NULL), Action::getPrerequisites());
95+
}
10196
}
10297
else
10398
{

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,30 @@ namespace ai
5454
}
5555
};
5656

57+
class BackOffAction : public ReachTargetAction
58+
{
59+
public:
60+
BackOffAction(PlayerbotAI* ai) : ReachTargetAction(ai, "back off", sPlayerbotAIConfig.meleeDistance) {}
61+
62+
virtual bool isUseful()
63+
{
64+
return AI_VALUE2(float, "distance", "current target") < distance + sPlayerbotAIConfig.contactDistance + bot->GetObjectBoundingRadius();
65+
}
66+
};
67+
5768
class ReachSpellAction : public ReachTargetAction
5869
{
5970
public:
60-
ReachSpellAction(PlayerbotAI* ai, float distance = sPlayerbotAIConfig.spellDistance) : ReachTargetAction(ai, "reach spell", distance) {}
71+
ReachSpellAction(PlayerbotAI* ai) : ReachTargetAction(ai, "reach spell", sPlayerbotAIConfig.spellDistance) {}
72+
virtual bool Execute(Event event)
73+
{
74+
distance = AI_VALUE(float, "reach spell distance");
75+
return ReachTargetAction::Execute(event);
76+
}
77+
virtual bool isUseful()
78+
{
79+
distance = AI_VALUE(float, "reach spell distance");
80+
return ReachTargetAction::isUseful();
81+
}
6182
};
6283
}

src/modules/Bots/playerbot/strategy/values/ValueContext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,12 @@ namespace ai
139139
creators["bag space"] = &ValueContext::bag_space;
140140
creators["enemy healer target"] = &ValueContext::enemy_healer_target;
141141
creators["item usage"] = &ValueContext::item_usage;
142+
creators["reach spell distance"] = &ValueContext::reach_spell_distance;
142143
}
143144

144145
private:
145146
static UntypedValue* item_usage(PlayerbotAI* ai) { return new ItemUsageValue(ai); }
147+
static UntypedValue* reach_spell_distance(PlayerbotAI* ai) { return new ManualSetValue<float>(ai, sPlayerbotAIConfig.spellDistance, "reach spell distance"); }
146148
static UntypedValue* mana_save_level(PlayerbotAI* ai) { return new ManaSaveLevelValue(ai); }
147149
static UntypedValue* invalid_target(PlayerbotAI* ai) { return new InvalidTargetValue(ai); }
148150
static UntypedValue* balance(PlayerbotAI* ai) { return new BalancePercentValue(ai); }

0 commit comments

Comments
 (0)