From 8d524cdaf044d64118a103144d72ac122cfead0b Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Thu, 26 Sep 2024 20:01:10 +0800 Subject: [PATCH] [Combat formation] Compatible with naxx and avoid aoe --- src/PlayerbotAI.cpp | 25 +++++++++-- src/PlayerbotAI.h | 1 + src/PlayerbotMgr.cpp | 5 ++- src/strategy/actions/MovementActions.cpp | 42 ++++++++++++++----- .../raids/naxxramas/RaidNaxxMultipliers.cpp | 13 +++--- 5 files changed, 66 insertions(+), 20 deletions(-) diff --git a/src/PlayerbotAI.cpp b/src/PlayerbotAI.cpp index c4f4cfac..9e5ed5a5 100644 --- a/src/PlayerbotAI.cpp +++ b/src/PlayerbotAI.cpp @@ -326,9 +326,9 @@ void PlayerbotAI::UpdateAI(uint32 elapsed, bool minimal) } if (nextTransportCheck > elapsed) - nextTransportCheck -= elapsed; - else - nextTransportCheck = 0; + nextTransportCheck -= elapsed; + else + nextTransportCheck = 0; if (!nextTransportCheck) { @@ -2090,6 +2090,25 @@ bool PlayerbotAI::IsMainTank(Player* player) return false; } +uint32 PlayerbotAI::GetGroupTankNum(Player* player) +{ + Group* group = player->GetGroup(); + if (!group) + { + return 0; + } + uint32 result = 0; + for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next()) + { + Player* member = ref->GetSource(); + if (IsTank(member) && member->IsAlive()) + { + result++; + } + } + return result; +} + bool PlayerbotAI::IsAssistTank(Player* player) { return IsTank(player) && !IsMainTank(player); } bool PlayerbotAI::IsAssistTankOfIndex(Player* player, int index) diff --git a/src/PlayerbotAI.h b/src/PlayerbotAI.h index 20dd42b2..093ebf41 100644 --- a/src/PlayerbotAI.h +++ b/src/PlayerbotAI.h @@ -410,6 +410,7 @@ public: static bool IsCombo(Player* player, bool bySpec = false); static bool IsRangedDps(Player* player, bool bySpec = false); static bool IsMainTank(Player* player); + static uint32 GetGroupTankNum(Player* player); bool IsAssistTank(Player* player); bool IsAssistTankOfIndex(Player* player, int index); bool IsHealAssistantOfIndex(Player* player, int index); diff --git a/src/PlayerbotMgr.cpp b/src/PlayerbotMgr.cpp index d1b92d7a..34e107d1 100644 --- a/src/PlayerbotMgr.cpp +++ b/src/PlayerbotMgr.cpp @@ -525,7 +525,10 @@ void PlayerbotHolder::OnBotLogin(Player* const bot) sGroupMgr->AddGroup(newGroup); newGroup->AddMember(bot); } - + // if (master) + // { + // // bot->TeleportTo(master); + // } uint32 accountId = bot->GetSession()->GetAccountId(); bool isRandomAccount = sPlayerbotAIConfig->IsInRandomAccountList(accountId); diff --git a/src/strategy/actions/MovementActions.cpp b/src/strategy/actions/MovementActions.cpp index 9b5214e5..7bc9a493 100644 --- a/src/strategy/actions/MovementActions.cpp +++ b/src/strategy/actions/MovementActions.cpp @@ -1883,16 +1883,7 @@ bool AvoidAoeAction::AvoidGameObjectWithDamage() float radius = (float)goInfo->trap.diameter / 2 + go->GetCombatReach(); if (!radius || radius > sPlayerbotAIConfig->maxAoeAvoidRadius) continue; - // for (int i = 0; i < MAX_SPELL_EFFECTS; i++) { - // if (spellInfo->Effects[i].Effect == SPELL_EFFECT_APPLY_AURA) { - // if (spellInfo->Effects[i].ApplyAuraName == SPELL_AURA_PERIODIC_DAMAGE) { - // radius = spellInfo->Effects[i].CalcRadius(); - // break; - // } - // } else if (spellInfo->Effects[i].Effect == SPELL_EFFECT_SCHOOL_DAMAGE) { - // break; - // } - // } + if (bot->GetDistance(go) > radius) { continue; @@ -2353,12 +2344,26 @@ bool TankFaceAction::Execute(Event event) if (bot->GetMap()->CheckCollisionAndGetValidCoords(bot, bot->GetPositionX(), bot->GetPositionY(), bot->GetPositionZ(), x, y, z)) { - availablePos.push_back(Position(x, y, z)); + /// @todo: movement control now is a mess, prepare to rewrite + std::list& infoList = AI_VALUE(std::list&, "recently flee info"); + Position pos(x, y, z); + float angle = bot->GetAngle(&pos); + if (CheckLastFlee(angle, infoList)) + { + availablePos.push_back(Position(x, y, z)); + } } target->GetNearPoint(bot, x, y, z, 0.0f, dist, goodAngle2); if (bot->GetMap()->CheckCollisionAndGetValidCoords(bot, bot->GetPositionX(), bot->GetPositionY(), bot->GetPositionZ(), x, y, z)) { + std::list& infoList = AI_VALUE(std::list&, "recently flee info"); + Position pos(x, y, z); + float angle = bot->GetAngle(&pos); + if (CheckLastFlee(angle, infoList)) + { + availablePos.push_back(Position(x, y, z)); + } availablePos.push_back(Position(x, y, z)); } if (availablePos.empty()) @@ -2531,12 +2536,27 @@ bool SetBehindTargetAction::Execute(Event event) if (bot->GetMap()->CheckCollisionAndGetValidCoords(bot, bot->GetPositionX(), bot->GetPositionY(), bot->GetPositionZ(), x, y, z)) { + /// @todo: movement control now is a mess, prepare to rewrite + std::list& infoList = AI_VALUE(std::list&, "recently flee info"); + Position pos(x, y, z); + float angle = bot->GetAngle(&pos); + if (CheckLastFlee(angle, infoList)) + { + availablePos.push_back(Position(x, y, z)); + } availablePos.push_back(Position(x, y, z)); } target->GetNearPoint(bot, x, y, z, 0.0f, dist, goodAngle2); if (bot->GetMap()->CheckCollisionAndGetValidCoords(bot, bot->GetPositionX(), bot->GetPositionY(), bot->GetPositionZ(), x, y, z)) { + std::list& infoList = AI_VALUE(std::list&, "recently flee info"); + Position pos(x, y, z); + float angle = bot->GetAngle(&pos); + if (CheckLastFlee(angle, infoList)) + { + availablePos.push_back(Position(x, y, z)); + } availablePos.push_back(Position(x, y, z)); } if (availablePos.empty()) diff --git a/src/strategy/raids/naxxramas/RaidNaxxMultipliers.cpp b/src/strategy/raids/naxxramas/RaidNaxxMultipliers.cpp index bdf5831e..0bb3b876 100644 --- a/src/strategy/raids/naxxramas/RaidNaxxMultipliers.cpp +++ b/src/strategy/raids/naxxramas/RaidNaxxMultipliers.cpp @@ -27,7 +27,7 @@ float GrobbulusMultiplier::GetValue(Action* action) { return 1.0f; } - if (dynamic_cast(action)) + if (dynamic_cast(action) || dynamic_cast(action)) { return 0.0f; } @@ -48,7 +48,7 @@ float HeiganDanceMultiplier::GetValue(Action* action) uint32 curr_dance = eventMap->GetNextEventTime(4); uint32 curr_timer = eventMap->GetTimer(); uint32 curr_erupt = eventMap->GetNextEventTime(3); - if (dynamic_cast(action)) + if (dynamic_cast(action)) { return 0.0f; } @@ -87,7 +87,8 @@ float LoathebGenericMultiplier::GetValue(Action* action) context->GetValue("neglect threat")->Set(true); if (botAI->GetState() == BOT_STATE_COMBAT && (dynamic_cast(action) || dynamic_cast(action) || - dynamic_cast(action) || dynamic_cast(action))) + dynamic_cast(action) || dynamic_cast(action) || + dynamic_cast(action))) { return 0.0f; } @@ -113,7 +114,8 @@ float ThaddiusGenericMultiplier::GetValue(Action* action) if (helper.IsPhasePet() && (dynamic_cast(action) || dynamic_cast(action) || dynamic_cast(action) || - dynamic_cast(action) || dynamic_cast(action))) + dynamic_cast(action) || dynamic_cast(action) || + dynamic_cast(action))) { return 0.0f; } @@ -151,7 +153,8 @@ float SapphironGenericMultiplier::GetValue(Action* action) { return 1.0f; } - if (dynamic_cast(action) || dynamic_cast(action)) + if (dynamic_cast(action) || dynamic_cast(action) || + dynamic_cast(action)) { return 0.0f; }