default actions

This commit is contained in:
Yunfan Li
2023-10-22 12:50:17 +08:00
parent 38f8ea5fd9
commit 45d0ae00ab
28 changed files with 98 additions and 79 deletions

View File

@@ -146,7 +146,8 @@ bool Engine::DoNextAction(Unit* unit, uint32 depth, bool minimal)
time_t currentTime = time(nullptr);
aiObjectContext->Update();
ProcessTriggers(minimal);
PushDefaultActions();
uint32 iterations = 0;
uint32 iterationsPerTick = queue.Size() * (minimal ? 2 : sPlayerbotAIConfig->iterationsPerTick);
do
@@ -265,15 +266,15 @@ bool Engine::DoNextAction(Unit* unit, uint32 depth, bool minimal)
}
while (basket && ++iterations <= iterationsPerTick);
if (!basket)
{
lastRelevance = 0.0f;
PushDefaultActions();
// if (!basket)
// {
// lastRelevance = 0.0f;
// PushDefaultActions();
// prevent the delay after pushing default actions
if (queue.Peek() && depth < 1 && !minimal)
return DoNextAction(unit, depth + 1, minimal);
}
// // prevent the delay after pushing default actions
// if (queue.Peek() && depth < 1 && !minimal)
// return DoNextAction(unit, depth + 1, minimal);
// }
// MEMORY FIX TEST
/*

View File

@@ -132,7 +132,7 @@ bool MovementAction::MoveToLOS(WorldObject* target, bool ranged)
return false;
}
bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle, bool react)
bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle, bool react, bool normal_only)
{
UpdateMovementState();
if (!IsMovingAllowed(mapId, x, y, z)) {
@@ -166,7 +166,11 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
MotionMaster &mm = *bot->GetMotionMaster();
mm.Clear();
mm.MovePoint(mapId, x, y, SearchBestGroundZForPath(x, y, z, generatePath), generatePath);
float modifiedZ = SearchBestGroundZForPath(x, y, z, generatePath, normal_only);
if (modifiedZ == INVALID_HEIGHT) {
return false;
}
mm.MovePoint(mapId, x, y, modifiedZ, generatePath);
AI_VALUE(LastMovement&, "last movement").Set(mapId, x, y, z, bot->GetOrientation());
return true;
}
@@ -1257,7 +1261,7 @@ bool MovementAction::MoveAway(Unit* target)
float dx = bot->GetPositionX() + cos(angle) * sPlayerbotAIConfig->fleeDistance;
float dy = bot->GetPositionY() + sin(angle) * sPlayerbotAIConfig->fleeDistance;
float dz = bot->GetPositionZ();
return MoveTo(target->GetMapId(), dx, dy, dz);
return MoveTo(target->GetMapId(), dx, dy, dz, false, false, true);
}
bool MovementAction::MoveInside(uint32 mapId, float x, float y, float z, float distance)
@@ -1268,7 +1272,7 @@ bool MovementAction::MoveInside(uint32 mapId, float x, float y, float z, float d
return MoveNear(mapId, x, y, z, distance);
}
float MovementAction::SearchBestGroundZForPath(float x, float y, float z, bool generatePath, float range)
float MovementAction::SearchBestGroundZForPath(float x, float y, float z, bool generatePath, float range, bool normal_only)
{
if (!generatePath) {
return z;
@@ -1299,6 +1303,9 @@ float MovementAction::SearchBestGroundZForPath(float x, float y, float z, bool g
return modified_z;
}
}
if (normal_only) {
return INVALID_HEIGHT;
}
return z;
}

View File

@@ -22,7 +22,7 @@ class MovementAction : public Action
protected:
bool MoveNear(uint32 mapId, float x, float y, float z, float distance = sPlayerbotAIConfig->contactDistance);
bool MoveToLOS(WorldObject* target, bool ranged = false);
bool MoveTo(uint32 mapId, float x, float y, float z, bool idle = false, bool react = false);
bool MoveTo(uint32 mapId, float x, float y, float z, bool idle = false, bool react = false, bool normal_only = false);
bool MoveTo(Unit* target, float distance = 0.0f);
bool MoveNear(WorldObject* target, float distance = sPlayerbotAIConfig->contactDistance);
float GetFollowAngle();
@@ -41,7 +41,7 @@ class MovementAction : public Action
bool MoveInside(uint32 mapId, float x, float y, float z, float distance = sPlayerbotAIConfig->followDistance);
void CreateWp(Player* wpOwner, float x, float y, float z, float o, uint32 entry, bool important = false);
private:
float SearchBestGroundZForPath(float x, float y, float z, bool generatePath, float range = 10.0f);
float SearchBestGroundZForPath(float x, float y, float z, bool generatePath, float range = 10.0f, bool normal_only = false);
};
class FleeAction : public MovementAction

View File

@@ -140,12 +140,12 @@ BearTankDruidStrategy::BearTankDruidStrategy(PlayerbotAI* botAI) : FeralDruidStr
NextAction** BearTankDruidStrategy::getDefaultActions()
{
return NextAction::array(0,
new NextAction("mangle (bear)", ACTION_NORMAL + 5),
new NextAction("faerie fire (feral)", ACTION_NORMAL + 4),
new NextAction("lacerate", ACTION_NORMAL + 3),
new NextAction("maul", ACTION_NORMAL + 2),
new NextAction("enrage", ACTION_NORMAL + 1),
new NextAction("melee", ACTION_NORMAL),
new NextAction("mangle (bear)", ACTION_DEFAULT + 0.5f),
new NextAction("faerie fire (feral)", ACTION_DEFAULT + 0.4f),
new NextAction("lacerate", ACTION_DEFAULT + 0.3f),
new NextAction("maul", ACTION_DEFAULT + 0.2f),
new NextAction("enrage", ACTION_DEFAULT + 0.1f),
new NextAction("melee", ACTION_DEFAULT),
nullptr);
}

View File

@@ -105,8 +105,8 @@ CasterDruidStrategy::CasterDruidStrategy(PlayerbotAI* botAI) : GenericDruidStrat
NextAction** CasterDruidStrategy::getDefaultActions()
{
return NextAction::array(0,
new NextAction("starfall", ACTION_NORMAL + 2),
new NextAction("wrath", ACTION_NORMAL + 1),
new NextAction("starfall", ACTION_DEFAULT + 0.2f),
new NextAction("wrath", ACTION_DEFAULT + 0.1f),
// new NextAction("starfire", ACTION_NORMAL),
nullptr);
}

View File

@@ -120,7 +120,7 @@ CatDpsDruidStrategy::CatDpsDruidStrategy(PlayerbotAI* botAI) : FeralDruidStrateg
NextAction** CatDpsDruidStrategy::getDefaultActions()
{
return NextAction::array(0, new NextAction("mangle (cat)", ACTION_NORMAL + 1), nullptr);
return NextAction::array(0, new NextAction("mangle (cat)", ACTION_DEFAULT + 0.1f), nullptr);
}
void CatDpsDruidStrategy::InitTriggers(std::vector<TriggerNode*>& triggers)

View File

@@ -12,8 +12,8 @@ MeleeDruidStrategy::MeleeDruidStrategy(PlayerbotAI* botAI) : CombatStrategy(botA
NextAction** MeleeDruidStrategy::getDefaultActions()
{
return NextAction::array(0,
new NextAction("faerie fire", ACTION_NORMAL + 1),
new NextAction("melee", ACTION_NORMAL),
new NextAction("faerie fire", ACTION_DEFAULT + 0.1f),
new NextAction("melee", ACTION_DEFAULT),
nullptr);
}

View File

@@ -12,9 +12,9 @@ NextAction** GrindingStrategy::getDefaultActions()
void GrindingStrategy::InitTriggers(std::vector<TriggerNode*>& triggers)
{
triggers.push_back(new TriggerNode("timer", NextAction::array(0, new NextAction("drink", 7.0f), nullptr)));
triggers.push_back(new TriggerNode("timer", NextAction::array(0, new NextAction("food", 6.0f), nullptr)));
triggers.push_back(new TriggerNode("no target", NextAction::array(0, new NextAction("attack anything", 5.0f), nullptr)));
triggers.push_back(new TriggerNode("timer", NextAction::array(0, new NextAction("drink", 4.2f), nullptr)));
triggers.push_back(new TriggerNode("timer", NextAction::array(0, new NextAction("food", 4.1f), nullptr)));
triggers.push_back(new TriggerNode("no target", NextAction::array(0, new NextAction("attack anything", 4.0f), nullptr)));
}
void MoveRandomStrategy::InitTriggers(std::vector<TriggerNode*>& triggers)

View File

@@ -31,13 +31,13 @@ DpsHunterStrategy::DpsHunterStrategy(PlayerbotAI* botAI) : GenericHunterStrategy
NextAction** DpsHunterStrategy::getDefaultActions()
{
return NextAction::array(0,
new NextAction("kill shot", 16.0f),
new NextAction("chimera shot", 15.0f),
new NextAction("explosive shot", 15.0f),
new NextAction("aimed shot", 14.0f),
new NextAction("arcane shot", 13.0f),
new NextAction("steady shot", 12.0f),
new NextAction("auto shot", 10.0f),
new NextAction("kill shot", ACTION_DEFAULT + 0.6f),
new NextAction("chimera shot", ACTION_DEFAULT + 0.5f),
new NextAction("explosive shot", ACTION_DEFAULT + 0.4f),
new NextAction("aimed shot", ACTION_DEFAULT + 0.3f),
new NextAction("arcane shot", ACTION_DEFAULT + 0.2f),
new NextAction("steady shot", ACTION_DEFAULT + 0.1f),
new NextAction("auto shot", ACTION_DEFAULT),
nullptr);
// return NextAction::array(0, new NextAction("explosive shot", 11.0f), new NextAction("auto shot", 10.0f), new NextAction("auto attack", 9.0f), nullptr);
}

View File

@@ -57,7 +57,10 @@ ArcaneMageStrategy::ArcaneMageStrategy(PlayerbotAI* botAI) : GenericMageStrategy
NextAction** ArcaneMageStrategy::getDefaultActions()
{
return NextAction::array(0, new NextAction("arcane blast", 10.0f), NULL);
return NextAction::array(0,
new NextAction("arcane blast", ACTION_DEFAULT + 0.1f),
new NextAction("shoot", ACTION_DEFAULT),
NULL);
}
void ArcaneMageStrategy::InitTriggers(std::vector<TriggerNode*>& triggers)

View File

@@ -7,7 +7,10 @@
NextAction** FireMageStrategy::getDefaultActions()
{
return NextAction::array(0, new NextAction("fireball", ACTION_NORMAL + 1), NULL);
return NextAction::array(0,
new NextAction("fireball", ACTION_DEFAULT + 0.1f),
new NextAction("shoot", ACTION_DEFAULT),
NULL);
}
void FireMageStrategy::InitTriggers(std::vector<TriggerNode*>& triggers)

View File

@@ -11,7 +11,11 @@ FrostMageStrategy::FrostMageStrategy(PlayerbotAI* botAI) : GenericMageStrategy(b
NextAction** FrostMageStrategy::getDefaultActions()
{
return NextAction::array(0, new NextAction("frostbolt", 7.0f), nullptr);
return NextAction::array(0,
new NextAction("frostbolt", ACTION_DEFAULT + 0.1f),
new NextAction("shoot", ACTION_DEFAULT),
nullptr);
}
void FrostMageStrategy::InitTriggers(std::vector<TriggerNode*>& triggers)

View File

@@ -80,11 +80,11 @@ DpsPaladinStrategy::DpsPaladinStrategy(PlayerbotAI* botAI) : GenericPaladinStrat
NextAction** DpsPaladinStrategy::getDefaultActions()
{
return NextAction::array(0,
new NextAction("judgement of wisdom", ACTION_NORMAL + 6),
new NextAction("crusader strike", ACTION_NORMAL + 5),
new NextAction("divine storm", ACTION_NORMAL + 4),
new NextAction("consecration", ACTION_NORMAL + 3),
new NextAction("melee", ACTION_NORMAL),
new NextAction("judgement of wisdom", ACTION_DEFAULT + 0.4f),
new NextAction("crusader strike", ACTION_DEFAULT + 0.3f),
new NextAction("divine storm", ACTION_DEFAULT + 0.2f),
new NextAction("consecration", ACTION_DEFAULT + 0.1f),
new NextAction("melee", ACTION_DEFAULT),
NULL);
}

View File

@@ -25,7 +25,7 @@ HealPaladinStrategy::HealPaladinStrategy(PlayerbotAI* botAI) : GenericPaladinStr
NextAction** HealPaladinStrategy::getDefaultActions()
{
return NextAction::array(0, new NextAction("judgement of light", ACTION_NORMAL + 2), nullptr);
return NextAction::array(0, new NextAction("judgement of light", ACTION_DEFAULT + 2), nullptr);
}
void HealPaladinStrategy::InitTriggers(std::vector<TriggerNode*>& triggers)

View File

@@ -59,12 +59,12 @@ TankPaladinStrategy::TankPaladinStrategy(PlayerbotAI* botAI) : GenericPaladinStr
NextAction** TankPaladinStrategy::getDefaultActions()
{
return NextAction::array(0,
new NextAction("shield of righteousness", ACTION_NORMAL + 6),
new NextAction("hammer of the righteous", ACTION_NORMAL + 5),
new NextAction("judgement of wisdom", ACTION_NORMAL + 4),
new NextAction("shield of righteousness", ACTION_DEFAULT + 0.6f),
new NextAction("hammer of the righteous", ACTION_DEFAULT + 0.5f),
new NextAction("judgement of wisdom", ACTION_DEFAULT + 0.4f),
// new NextAction("avenger's shield", ACTION_NORMAL + 3),
// new NextAction("consecration", ACTION_NORMAL + 2),
new NextAction("melee", ACTION_NORMAL),
new NextAction("melee", ACTION_DEFAULT),
NULL);
}

View File

@@ -13,7 +13,7 @@ HealPriestStrategy::HealPriestStrategy(PlayerbotAI* botAI) : GenericPriestStrate
NextAction** HealPriestStrategy::getDefaultActions()
{
return NextAction::array(0, new NextAction("shoot", 10.0f), nullptr);
return NextAction::array(0, new NextAction("shoot", ACTION_DEFAULT), nullptr);
}
void HealPriestStrategy::InitTriggers(std::vector<TriggerNode*>& triggers)

View File

@@ -30,7 +30,7 @@ HolyPriestStrategy::HolyPriestStrategy(PlayerbotAI* botAI) : HealPriestStrategy(
NextAction** HolyPriestStrategy::getDefaultActions()
{
return NextAction::array(0, new NextAction("smite", 10.0f), new NextAction("mana burn", 9.0f), new NextAction("starshards", 8.0f), nullptr);
return NextAction::array(0, new NextAction("smite", ACTION_DEFAULT + 0.2f), new NextAction("mana burn", ACTION_DEFAULT + 0.1f), new NextAction("starshards", ACTION_DEFAULT), nullptr);
}
void HolyPriestStrategy::InitTriggers(std::vector<TriggerNode*>& triggers)

View File

@@ -14,10 +14,10 @@ ShadowPriestStrategy::ShadowPriestStrategy(PlayerbotAI* botAI) : GenericPriestSt
NextAction** ShadowPriestStrategy::getDefaultActions()
{
return NextAction::array(0,
new NextAction("mind blast", 13.0f),
new NextAction("mind blast", ACTION_DEFAULT + 0.2f),
// new NextAction("shadow word: death", 12.0f),
new NextAction("mind flay", 11.0f),
// new NextAction("shoot", 10.0f),
new NextAction("mind flay", ACTION_DEFAULT + 0.1f),
new NextAction("shoot", ACTION_DEFAULT),
NULL);
}

View File

@@ -35,7 +35,7 @@ AssassinationRogueStrategy::AssassinationRogueStrategy(PlayerbotAI* ai) : MeleeC
NextAction** AssassinationRogueStrategy::getDefaultActions()
{
return NextAction::array(0,
new NextAction("melee", ACTION_NORMAL),
new NextAction("melee", ACTION_DEFAULT),
NULL);
}

View File

@@ -71,8 +71,8 @@ DpsRogueStrategy::DpsRogueStrategy(PlayerbotAI* botAI) : MeleeCombatStrategy(bot
NextAction** DpsRogueStrategy::getDefaultActions()
{
return NextAction::array(0,
new NextAction("killing spree", ACTION_NORMAL + 1),
new NextAction("melee", ACTION_NORMAL), NULL);
new NextAction("killing spree", ACTION_DEFAULT + 0.1f),
new NextAction("melee", ACTION_DEFAULT), NULL);
}
void DpsRogueStrategy::InitTriggers(std::vector<TriggerNode*>& triggers)

View File

@@ -39,8 +39,8 @@ CasterShamanStrategy::CasterShamanStrategy(PlayerbotAI* botAI) : GenericShamanSt
NextAction** CasterShamanStrategy::getDefaultActions()
{
return NextAction::array(0,
new NextAction("lava burst", 11.0f),
new NextAction("lightning bolt", 10.0f),
new NextAction("lava burst", ACTION_DEFAULT + 0.1f),
new NextAction("lightning bolt", ACTION_DEFAULT),
NULL);
}

View File

@@ -50,11 +50,11 @@ MeleeShamanStrategy::MeleeShamanStrategy(PlayerbotAI* botAI) : GenericShamanStra
NextAction** MeleeShamanStrategy::getDefaultActions()
{
return NextAction::array(0,
new NextAction("stormstrike", ACTION_NORMAL + 6),
new NextAction("earth shock", ACTION_NORMAL + 5),
new NextAction("fire nova", ACTION_NORMAL + 4),
new NextAction("lava lash", ACTION_NORMAL + 1),
new NextAction("melee", ACTION_NORMAL),
new NextAction("stormstrike", ACTION_DEFAULT + 0.4f),
new NextAction("earth shock", ACTION_DEFAULT + 0.3f),
new NextAction("fire nova", ACTION_DEFAULT + 0.2f),
new NextAction("lava lash", ACTION_DEFAULT + 0.1f),
new NextAction("melee", ACTION_DEFAULT),
NULL);
}

View File

@@ -217,7 +217,7 @@ class TriggerContext : public NamedObjectContext<Trigger>
static Trigger* critical_aoe_heal(PlayerbotAI* botAI) { return new AoeHealTrigger(botAI, "critical aoe heal", "critical", 2); }
static Trigger* low_aoe_heal(PlayerbotAI* botAI) { return new AoeHealTrigger(botAI, "low aoe heal", "low", 2); }
static Trigger* medium_aoe_heal(PlayerbotAI* botAI) { return new AoeHealTrigger(botAI, "medium aoe heal", "medium", 2); }
static Trigger* group_heal_occasion(PlayerbotAI* ai) { return new AoeInGroupTrigger(ai, "group heal occasion", "almost full", 0.4); }
static Trigger* group_heal_occasion(PlayerbotAI* ai) { return new AoeInGroupTrigger(ai, "group heal occasion", "almost full", 0.6); }
static Trigger* medium_group_heal_occasion(PlayerbotAI* ai) { return new AoeInGroupTrigger(ai, "group heal occasion", "medium", 0.4); }
static Trigger* target_changed(PlayerbotAI* botAI) { return new TargetChangedTrigger(botAI); }
static Trigger* swimming(PlayerbotAI* botAI) { return new IsSwimmingTrigger(botAI); }

View File

@@ -47,9 +47,10 @@ DpsWarlockStrategy::DpsWarlockStrategy(PlayerbotAI* botAI) : GenericWarlockStrat
NextAction** DpsWarlockStrategy::getDefaultActions()
{
return NextAction::array(0,
new NextAction("haunt", 14.0f),
new NextAction("demonic empowerment", 13.0f),
new NextAction("shadow bolt", 10.0f),
new NextAction("haunt", ACTION_DEFAULT + 0.3f),
new NextAction("demonic empowerment", ACTION_DEFAULT + 0.2f),
new NextAction("shadow bolt", ACTION_DEFAULT + 0.1f),
new NextAction("shoot", ACTION_DEFAULT),
nullptr);
}

View File

@@ -57,7 +57,7 @@ TankWarlockStrategy::TankWarlockStrategy(PlayerbotAI* botAI) : GenericWarlockStr
NextAction** TankWarlockStrategy::getDefaultActions()
{
return NextAction::array(0, new NextAction("shoot", 10.0f), nullptr);
return NextAction::array(0, new NextAction("shoot", ACTION_DEFAULT), nullptr);
}
void TankWarlockStrategy::InitTriggers(std::vector<TriggerNode*>& triggers)

View File

@@ -32,7 +32,7 @@ ArmsWarriorStrategy::ArmsWarriorStrategy(PlayerbotAI* botAI) : GenericWarriorStr
NextAction** ArmsWarriorStrategy::getDefaultActions()
{
return NextAction::array(0, new NextAction("heroic strike", ACTION_NORMAL), nullptr);
return NextAction::array(0, new NextAction("heroic strike", ACTION_DEFAULT), nullptr);
}
void ArmsWarriorStrategy::InitTriggers(std::vector<TriggerNode*>& triggers)

View File

@@ -35,12 +35,12 @@ FuryWarriorStrategy::FuryWarriorStrategy(PlayerbotAI* botAI) : GenericWarriorStr
NextAction** FuryWarriorStrategy::getDefaultActions()
{
return NextAction::array(0,
new NextAction("bloodthirst", ACTION_NORMAL + 5),
new NextAction("whirlwind", ACTION_NORMAL + 4),
new NextAction("sunder armor", ACTION_NORMAL + 3),
new NextAction("execute", ACTION_NORMAL + 2),
new NextAction("overpower", ACTION_NORMAL + 1),
new NextAction("melee", ACTION_NORMAL),
new NextAction("bloodthirst", ACTION_DEFAULT + 0.5f),
new NextAction("whirlwind", ACTION_DEFAULT + 0.4f),
new NextAction("sunder armor", ACTION_DEFAULT + 0.3f),
new NextAction("execute", ACTION_DEFAULT + 0.2f),
new NextAction("overpower", ACTION_DEFAULT + 0.1f),
new NextAction("melee", ACTION_DEFAULT),
NULL);
}

View File

@@ -43,9 +43,9 @@ TankWarriorStrategy::TankWarriorStrategy(PlayerbotAI* botAI) : GenericWarriorStr
NextAction** TankWarriorStrategy::getDefaultActions()
{
return NextAction::array(0,
new NextAction("devastate", ACTION_NORMAL + 2),
new NextAction("revenge", ACTION_NORMAL + 1),
new NextAction("melee", ACTION_NORMAL),
new NextAction("devastate", ACTION_DEFAULT + 0.2f),
new NextAction("revenge", ACTION_DEFAULT + 0.1f),
new NextAction("melee", ACTION_DEFAULT),
NULL);
}