From 209fdbd6b5106f07669e98f5001a697d86951a79 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Tue, 13 Jun 2023 01:02:37 +0800 Subject: [PATCH] chore(value): attackers value --- src/PlayerbotMgr.cpp | 1 + src/RandomPlayerbotMgr.cpp | 3 +++ src/strategy/values/AttackersValue.cpp | 27 +++++++++++++++++++++++--- src/strategy/values/AttackersValue.h | 3 ++- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/PlayerbotMgr.cpp b/src/PlayerbotMgr.cpp index 5d31b072..85b16dd9 100644 --- a/src/PlayerbotMgr.cpp +++ b/src/PlayerbotMgr.cpp @@ -431,6 +431,7 @@ void PlayerbotHolder::OnBotLogin(Player* const bot) uint32 accountId = bot->GetSession()->GetAccountId(); bool isRandomAccount = sPlayerbotAIConfig->IsInRandomAccountList(accountId); + bot->SaveToDB(false, false); if (master && isRandomAccount && master->GetLevel() < bot->GetLevel()) { PlayerbotFactory factory(bot, master->getLevel()); factory.Randomize(false); diff --git a/src/RandomPlayerbotMgr.cpp b/src/RandomPlayerbotMgr.cpp index 863ee80e..8eb405dd 100644 --- a/src/RandomPlayerbotMgr.cpp +++ b/src/RandomPlayerbotMgr.cpp @@ -1670,6 +1670,9 @@ bool RandomPlayerbotMgr::HandlePlayerbotConsoleCommand(ChatHandler* handler, cha uint32 botId = fields[0].Get(); ObjectGuid guid = ObjectGuid::Create(botId); + if (!sRandomPlayerbotMgr->IsRandomBot(guid.GetCounter())) { + continue; + } Player* bot = ObjectAccessor::FindPlayer(guid); if (!bot) continue; diff --git a/src/strategy/values/AttackersValue.cpp b/src/strategy/values/AttackersValue.cpp index c5ec4847..6ebd1870 100644 --- a/src/strategy/values/AttackersValue.cpp +++ b/src/strategy/values/AttackersValue.cpp @@ -83,20 +83,41 @@ void AttackersValue::AddAttackersOf(Player* player, std::set& targets) void AttackersValue::RemoveNonThreating(std::set& targets) { - for (std::set::iterator tIter = targets.begin(); tIter != targets.end();) + for(std::set::iterator tIter = targets.begin(); tIter != targets.end();) { Unit* unit = *tIter; - if (!IsValidTarget(unit, bot) || !bot->IsWithinLOSInMap(unit)) + if(!bot->IsWithinLOSInMap(unit) || bot->GetMapId() != unit->GetMapId() || !hasRealThreat(unit)) { - std::set::iterator tIter2 = tIter; + std::set::iterator tIter2 = tIter; ++tIter; targets.erase(tIter2); } else ++tIter; } + // Unit* unit = *tIter; + // if (!IsValidTarget(unit, bot) || !bot->IsWithinLOSInMap(unit)) + // { + // std::set::iterator tIter2 = tIter; + // ++tIter; + // targets.erase(tIter2); + // } + // else + // ++tIter; } +bool AttackersValue::hasRealThreat(Unit *attacker) +{ + return attacker && + attacker->IsInWorld() && + attacker->IsAlive() && + // !attacker->IsPolymorphed() && + // !attacker->isInRoots() && + !attacker->IsFriendlyTo(bot) && + (attacker->GetThreatMgr().getCurrentVictim() || dynamic_cast(attacker)); +} + + bool AttackersValue::IsPossibleTarget(Unit* attacker, Player* bot, float range) { Creature* c = attacker->ToCreature(); diff --git a/src/strategy/values/AttackersValue.h b/src/strategy/values/AttackersValue.h index 014dd383..4ccf1e63 100644 --- a/src/strategy/values/AttackersValue.h +++ b/src/strategy/values/AttackersValue.h @@ -25,7 +25,8 @@ class AttackersValue : public ObjectGuidListCalculatedValue private: void AddAttackersOf(Group* group, std::set& targets); void AddAttackersOf(Player* player, std::set& targets); - void RemoveNonThreating(std::set& targets); + void RemoveNonThreating(std::set& targets); + bool hasRealThreat(Unit* attacker); }; class PossibleAddsValue : public BoolCalculatedValue