mirror of
https://github.com/mod-playerbots/mod-playerbots
synced 2025-11-29 15:58:20 +08:00
Improve performance by ZoneHasRealPlayers and MoveFarTo
This commit is contained in:
@@ -39,6 +39,7 @@
|
|||||||
#include "Playerbots.h"
|
#include "Playerbots.h"
|
||||||
#include "PointMovementGenerator.h"
|
#include "PointMovementGenerator.h"
|
||||||
#include "PositionValue.h"
|
#include "PositionValue.h"
|
||||||
|
#include "RandomPlayerbotMgr.h"
|
||||||
#include "SayAction.h"
|
#include "SayAction.h"
|
||||||
#include "ScriptMgr.h"
|
#include "ScriptMgr.h"
|
||||||
#include "ServerFacade.h"
|
#include "ServerFacade.h"
|
||||||
@@ -4107,20 +4108,11 @@ inline bool ZoneHasRealPlayers(Player* bot)
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map::PlayerList const& players = bot->GetMap()->GetPlayers();
|
for (auto& player : sRandomPlayerbotMgr->GetPlayers())
|
||||||
if (players.IsEmpty())
|
|
||||||
{
|
{
|
||||||
return false;
|
if (player->GetMapId() != bot->GetMapId())
|
||||||
}
|
|
||||||
|
|
||||||
for (auto const& itr : players)
|
|
||||||
{
|
|
||||||
Player* player = itr.GetSource();
|
|
||||||
if (!player || !player->IsVisible())
|
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
if (player->GetZoneId() == bot->GetZoneId())
|
if (player->GetZoneId() == bot->GetZoneId())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ bool NewRpgStatusUpdateAction::Execute(Event event)
|
|||||||
case NewRpgStatus::GO_INNKEEPER:
|
case NewRpgStatus::GO_INNKEEPER:
|
||||||
{
|
{
|
||||||
WorldPosition& originalPos = info.innKeeperPos;
|
WorldPosition& originalPos = info.innKeeperPos;
|
||||||
assert(info.grindPos != WorldPosition());
|
assert(info.innKeeperPos != WorldPosition());
|
||||||
// GO_INNKEEPER -> NEAR_NPC
|
// GO_INNKEEPER -> NEAR_NPC
|
||||||
if (bot->GetExactDist(originalPos) < 10.0f)
|
if (bot->GetExactDist(originalPos) < 10.0f)
|
||||||
{
|
{
|
||||||
@@ -217,17 +217,17 @@ bool NewRpgGoFarAwayPosAction::MoveFarTo(WorldPosition dest)
|
|||||||
return MoveTo(dest.getMapId(), dest.GetPositionX(), dest.GetPositionY(), dest.GetPositionZ());
|
return MoveTo(dest.getMapId(), dest.GetPositionX(), dest.GetPositionY(), dest.GetPositionZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
int attempt = 10;
|
|
||||||
float minDelta = M_PI;
|
float minDelta = M_PI;
|
||||||
const float x = bot->GetPositionX();
|
const float x = bot->GetPositionX();
|
||||||
const float y = bot->GetPositionY();
|
const float y = bot->GetPositionY();
|
||||||
const float z = bot->GetPositionZ();
|
const float z = bot->GetPositionZ();
|
||||||
float rx, ry, rz;
|
float rx, ry, rz;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
int attempt = 5;
|
||||||
while (--attempt)
|
while (--attempt)
|
||||||
{
|
{
|
||||||
float angle = bot->GetAngle(&dest);
|
float angle = bot->GetAngle(&dest);
|
||||||
float delta = (rand_norm() - 0.5) * M_PI;
|
float delta = (rand_norm() - 0.5) * M_PI * 0.6;
|
||||||
angle += delta;
|
angle += delta;
|
||||||
float dis = rand_norm() * pathFinderDis;
|
float dis = rand_norm() * pathFinderDis;
|
||||||
float dx = x + cos(angle) * dis;
|
float dx = x + cos(angle) * dis;
|
||||||
@@ -241,14 +241,11 @@ bool NewRpgGoFarAwayPosAction::MoveFarTo(WorldPosition dest)
|
|||||||
if (canReach)
|
if (canReach)
|
||||||
{
|
{
|
||||||
G3D::Vector3 endPos = path.GetPath().back();
|
G3D::Vector3 endPos = path.GetPath().back();
|
||||||
if (fabs(delta) < minDelta)
|
found = true;
|
||||||
{
|
rx = endPos.x;
|
||||||
found = true;
|
ry = endPos.y;
|
||||||
minDelta = fabs(delta);
|
rz = endPos.z;
|
||||||
rx = endPos.x;
|
break;
|
||||||
ry = endPos.y;
|
|
||||||
rz = endPos.z;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (found)
|
if (found)
|
||||||
|
|||||||
Reference in New Issue
Block a user