mirror of
https://github.com/mod-playerbots/mod-playerbots
synced 2025-11-29 15:58:20 +08:00
feat(performance): reduce lag impact by attackers and yieldthread
This commit is contained in:
@@ -54,7 +54,7 @@ bool PlayerbotAIBase::CanUpdateAI()
|
||||
void PlayerbotAIBase::YieldThread(bool delay)
|
||||
{
|
||||
if (nextAICheckDelay < sPlayerbotAIConfig->reactDelay)
|
||||
nextAICheckDelay = delay ? sPlayerbotAIConfig->reactDelay * 10 : sPlayerbotAIConfig->reactDelay;
|
||||
nextAICheckDelay = delay ? sPlayerbotAIConfig->reactDelay * 10 : sPlayerbotAIConfig->reactDelay * 5;
|
||||
}
|
||||
|
||||
bool PlayerbotAIBase::IsActive()
|
||||
|
||||
@@ -63,20 +63,21 @@ void AttackersValue::AddAttackersOf(Player* player, std::set<Unit*>& targets)
|
||||
if (!player || !player->IsInWorld() || player->IsBeingTeleported())
|
||||
return;
|
||||
|
||||
std::list<Unit*> units;
|
||||
Acore::AnyUnfriendlyUnitInObjectRangeCheck u_check(player, player, sPlayerbotAIConfig->sightDistance);
|
||||
Acore::UnitListSearcher<Acore::AnyUnfriendlyUnitInObjectRangeCheck> searcher(player, units, u_check);
|
||||
Cell::VisitAllObjects(player, searcher, sPlayerbotAIConfig->sightDistance);
|
||||
HostileRefMgr& refManager = player->getHostileRefMgr();
|
||||
HostileReference *ref = refManager.getFirst();
|
||||
if (!ref)
|
||||
return;
|
||||
|
||||
for (Unit* unit : units)
|
||||
while( ref )
|
||||
{
|
||||
if (!player->GetGroup())
|
||||
{
|
||||
if (!unit->GetThreatMgr().GetThreat(player) && (!unit->GetThreatMgr().getCurrentVictim() || unit->GetThreatMgr().getCurrentVictim()->getTarget() != player))
|
||||
continue;
|
||||
}
|
||||
ThreatMgr *threatMgr = ref->GetSource();
|
||||
Unit *attacker = threatMgr->GetOwner();
|
||||
Unit *victim = attacker->GetVictim();
|
||||
|
||||
targets.insert(unit);
|
||||
if (player->IsValidAttackTarget(attacker) && player->GetDistance2d(attacker) < sPlayerbotAIConfig->sightDistance) {
|
||||
targets.insert(attacker);
|
||||
}
|
||||
ref = ref->next();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user