chore(value): attackers value

This commit is contained in:
Yunfan Li
2023-06-13 01:02:37 +08:00
parent c9367debeb
commit 209fdbd6b5
4 changed files with 30 additions and 4 deletions

View File

@@ -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);

View File

@@ -1670,6 +1670,9 @@ bool RandomPlayerbotMgr::HandlePlayerbotConsoleCommand(ChatHandler* handler, cha
uint32 botId = fields[0].Get<uint32>();
ObjectGuid guid = ObjectGuid::Create<HighGuid::Player>(botId);
if (!sRandomPlayerbotMgr->IsRandomBot(guid.GetCounter())) {
continue;
}
Player* bot = ObjectAccessor::FindPlayer(guid);
if (!bot)
continue;

View File

@@ -83,20 +83,41 @@ void AttackersValue::AddAttackersOf(Player* player, std::set<Unit*>& targets)
void AttackersValue::RemoveNonThreating(std::set<Unit*>& targets)
{
for (std::set<Unit*>::iterator tIter = targets.begin(); tIter != targets.end();)
for(std::set<Unit *>::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<Unit*>::iterator tIter2 = tIter;
std::set<Unit *>::iterator tIter2 = tIter;
++tIter;
targets.erase(tIter2);
}
else
++tIter;
}
// Unit* unit = *tIter;
// if (!IsValidTarget(unit, bot) || !bot->IsWithinLOSInMap(unit))
// {
// std::set<Unit*>::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<Player*>(attacker));
}
bool AttackersValue::IsPossibleTarget(Unit* attacker, Player* bot, float range)
{
Creature* c = attacker->ToCreature();

View File

@@ -25,7 +25,8 @@ class AttackersValue : public ObjectGuidListCalculatedValue
private:
void AddAttackersOf(Group* group, std::set<Unit*>& targets);
void AddAttackersOf(Player* player, std::set<Unit*>& targets);
void RemoveNonThreating(std::set<Unit*>& targets);
void RemoveNonThreating(std::set<Unit*>& targets);
bool hasRealThreat(Unit* attacker);
};
class PossibleAddsValue : public BoolCalculatedValue