From 95c2ba9105b574e6d811c0274c2296cb8a16f16e Mon Sep 17 00:00:00 2001 From: Yunfan Li <56597220+liyunfan1223@users.noreply.github.com> Date: Mon, 24 Feb 2025 03:09:59 +0800 Subject: [PATCH] Permission check and readability improvements (#997) * AiFactory check by spell instead of level * Ignore group security for guild invitation --- src/AiFactory.cpp | 4 ++-- src/PlayerbotAI.cpp | 2 +- src/PlayerbotSecurity.cpp | 4 ++-- src/strategy/actions/LfgActions.cpp | 7 ++++--- src/strategy/actions/MovementActions.cpp | 5 ----- 5 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/AiFactory.cpp b/src/AiFactory.cpp index b57f7686..6f5f459a 100644 --- a/src/AiFactory.cpp +++ b/src/AiFactory.cpp @@ -322,7 +322,7 @@ void AiFactory::AddDefaultCombatStrategies(Player* player, PlayerbotAI* const fa case CLASS_WARRIOR: if (tab == 2) engine->addStrategiesNoInit("tank", "tank assist", "aoe", nullptr); - else if (player->GetLevel() < 36 || tab == 0) + else if (tab == 0 || !player->HasSpell(1680)) // Whirlwind engine->addStrategiesNoInit("arms", "aoe", "dps assist", /*"behind",*/ nullptr); else engine->addStrategiesNoInit("fury", "aoe", "dps assist", /*"behind",*/ nullptr); @@ -356,7 +356,7 @@ void AiFactory::AddDefaultCombatStrategies(Player* player, PlayerbotAI* const fa engine->addStrategiesNoInit("heal", "cure", "dps assist", nullptr); else { - if (player->GetLevel() >= 20 && !player->HasAura(16931) /*thick hide*/) + if (player->HasSpell(768) /*cat form*/&& !player->HasAura(16931) /*thick hide*/) { engine->addStrategiesNoInit("cat", "dps assist", nullptr); } diff --git a/src/PlayerbotAI.cpp b/src/PlayerbotAI.cpp index f5a1720d..2d88fc09 100644 --- a/src/PlayerbotAI.cpp +++ b/src/PlayerbotAI.cpp @@ -2068,7 +2068,7 @@ bool PlayerbotAI::IsMainTank(Player* player) Group* group = player->GetGroup(); if (!group) { - return false; + return IsTank(player); } ObjectGuid mainTank = ObjectGuid(); Group::MemberSlotList const& slots = group->GetMemberSlots(); diff --git a/src/PlayerbotSecurity.cpp b/src/PlayerbotSecurity.cpp index 8813cde4..5b7638e5 100644 --- a/src/PlayerbotSecurity.cpp +++ b/src/PlayerbotSecurity.cpp @@ -139,7 +139,7 @@ PlayerbotSecurityLevel PlayerbotSecurity::LevelFor(Player* from, DenyReason* rea return PLAYERBOT_SECURITY_INVITE; } - if (group->IsFull()) + if (!ignoreGroup && group->IsFull()) { if (reason) *reason = PLAYERBOT_DENY_FULL_GROUP; @@ -147,7 +147,7 @@ PlayerbotSecurityLevel PlayerbotSecurity::LevelFor(Player* from, DenyReason* rea return PLAYERBOT_SECURITY_TALK; } - if (group->GetLeaderGUID() != bot->GetGUID()) + if (!ignoreGroup && group->GetLeaderGUID() != bot->GetGUID()) { if (reason) *reason = PLAYERBOT_DENY_NOT_LEADER; diff --git a/src/strategy/actions/LfgActions.cpp b/src/strategy/actions/LfgActions.cpp index 48890077..aee25473 100644 --- a/src/strategy/actions/LfgActions.cpp +++ b/src/strategy/actions/LfgActions.cpp @@ -36,8 +36,8 @@ uint32 LfgJoinAction::GetRoles() case CLASS_DRUID: if (spec == 2) return PLAYER_ROLE_HEALER; - else if (spec == 1) - return (PLAYER_ROLE_TANK | PLAYER_ROLE_DAMAGE); + else if (spec == 1 && bot->HasAura(16931) /* thick hide */) + return PLAYER_ROLE_TANK; else return PLAYER_ROLE_DAMAGE; break; @@ -206,6 +206,7 @@ bool LfgAcceptAction::Execute(Event event) if (bot->IsInCombat() || bot->isDead()) { + /// @FIXME: Race condition LOG_INFO("playerbots", "Bot {} {}:{} <{}> is in combat and refuses LFG proposal {}", bot->GetGUID().ToString().c_str(), bot->GetTeamId() == TEAM_ALLIANCE ? "A" : "H", bot->GetLevel(), bot->GetName().c_str(), id); @@ -219,7 +220,7 @@ bool LfgAcceptAction::Execute(Event event) botAI->GetAiObjectContext()->GetValue("lfg proposal")->Set(0); bot->ClearUnitState(UNIT_STATE_ALL_STATE); - + /// @FIXME: Race condition sLFGMgr->UpdateProposal(id, bot->GetGUID(), true); if (sRandomPlayerbotMgr->IsRandomBot(bot) && !bot->GetGroup()) diff --git a/src/strategy/actions/MovementActions.cpp b/src/strategy/actions/MovementActions.cpp index 26a6e105..232617aa 100644 --- a/src/strategy/actions/MovementActions.cpp +++ b/src/strategy/actions/MovementActions.cpp @@ -1583,11 +1583,6 @@ bool MovementAction::MoveAway(Unit* target, float distance, bool backwards) // just calculates average position of group and runs away from that position bool MovementAction::MoveFromGroup(float distance) { - // LOG_ERROR("playerbots", "MovementAction::MoveFromGroup"); - //if (Player* master = botAI->GetMaster()) - //{ - // return MoveAway(master); - //} if (Group* group = bot->GetGroup()) { uint32 mapId = bot->GetMapId();