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)
|
void PlayerbotAIBase::YieldThread(bool delay)
|
||||||
{
|
{
|
||||||
if (nextAICheckDelay < sPlayerbotAIConfig->reactDelay)
|
if (nextAICheckDelay < sPlayerbotAIConfig->reactDelay)
|
||||||
nextAICheckDelay = delay ? sPlayerbotAIConfig->reactDelay * 10 : sPlayerbotAIConfig->reactDelay;
|
nextAICheckDelay = delay ? sPlayerbotAIConfig->reactDelay * 10 : sPlayerbotAIConfig->reactDelay * 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PlayerbotAIBase::IsActive()
|
bool PlayerbotAIBase::IsActive()
|
||||||
|
|||||||
@@ -63,20 +63,21 @@ void AttackersValue::AddAttackersOf(Player* player, std::set<Unit*>& targets)
|
|||||||
if (!player || !player->IsInWorld() || player->IsBeingTeleported())
|
if (!player || !player->IsInWorld() || player->IsBeingTeleported())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::list<Unit*> units;
|
HostileRefMgr& refManager = player->getHostileRefMgr();
|
||||||
Acore::AnyUnfriendlyUnitInObjectRangeCheck u_check(player, player, sPlayerbotAIConfig->sightDistance);
|
HostileReference *ref = refManager.getFirst();
|
||||||
Acore::UnitListSearcher<Acore::AnyUnfriendlyUnitInObjectRangeCheck> searcher(player, units, u_check);
|
if (!ref)
|
||||||
Cell::VisitAllObjects(player, searcher, sPlayerbotAIConfig->sightDistance);
|
return;
|
||||||
|
|
||||||
for (Unit* unit : units)
|
while( ref )
|
||||||
{
|
{
|
||||||
if (!player->GetGroup())
|
ThreatMgr *threatMgr = ref->GetSource();
|
||||||
{
|
Unit *attacker = threatMgr->GetOwner();
|
||||||
if (!unit->GetThreatMgr().GetThreat(player) && (!unit->GetThreatMgr().getCurrentVictim() || unit->GetThreatMgr().getCurrentVictim()->getTarget() != player))
|
Unit *victim = attacker->GetVictim();
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
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