Merge branch 'liyunfan1223:master' into master

This commit is contained in:
Atidote
2024-08-05 16:23:19 +02:00
committed by GitHub
16 changed files with 184 additions and 107 deletions

View File

@@ -48,8 +48,8 @@ WorldLocation ArrowFormation::GetLocationInternal()
float y = master->GetPositionY() - masterUnit->GetY() + botUnit->GetY();
float z = master->GetPositionZ();
float ground = master->GetMapHeight(x, y, z + 30.0f);
if (ground <= INVALID_HEIGHT)
if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(),
master->GetPositionZ(), x, y, z))
return Formation::NullLocation;
// master->UpdateGroundPositionZ(x, y, z);
return WorldLocation(master->GetMapId(), x, y, z);

View File

@@ -89,12 +89,9 @@ public:
float y = master->GetPositionY() + sin(angle) * range;
float z = master->GetPositionZ();
float ground = master->GetMapHeight(x, y, z + 30.0f);
if (ground <= INVALID_HEIGHT)
if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(),
master->GetPositionZ(), x, y, z))
return Formation::NullLocation;
// z += CONTACT_DISTANCE;
// bot->UpdateAllowedPositionZ(x, y, z);
return WorldLocation(master->GetMapId(), x, y, z);
}
@@ -118,21 +115,39 @@ public:
time_t now = time(nullptr);
if (!lastChangeTime || now - lastChangeTime >= 3)
{
lastChangeTime = now;
dx = (urand(0, 10) / 10.0 - 0.5) * sPlayerbotAIConfig->tooCloseDistance;
dy = (urand(0, 10) / 10.0 - 0.5) * sPlayerbotAIConfig->tooCloseDistance;
dr = sqrt(dx * dx + dy * dy);
Player* master = botAI->GetGroupMaster();
if (!master)
return WorldLocation();
float range = sPlayerbotAIConfig->followDistance;
float angle = GetFollowAngle();
time_t now = time(nullptr);
if (!lastChangeTime || now - lastChangeTime >= 3)
{
lastChangeTime = now;
dx = (urand(0, 10) / 10.0 - 0.5) * sPlayerbotAIConfig->tooCloseDistance;
dy = (urand(0, 10) / 10.0 - 0.5) * sPlayerbotAIConfig->tooCloseDistance;
dr = sqrt(dx * dx + dy * dy);
}
float x = master->GetPositionX() + cos(angle) * range + dx;
float y = master->GetPositionY() + sin(angle) * range + dy;
float z = master->GetPositionZ();
if (!master->GetMap()->CheckCollisionAndGetValidCoords(
master, master->GetPositionX(), master->GetPositionY(), master->GetPositionZ(), x, y, z))
return Formation::NullLocation;
// bot->GetMap()->CheckCollisionAndGetValidCoords(bot, bot->GetPositionX(), bot->GetPositionY(),
// bot->GetPositionZ(), x, y, z);
return WorldLocation(master->GetMapId(), x, y, z);
}
float x = master->GetPositionX() + cos(angle) * range + dx;
float y = master->GetPositionY() + sin(angle) * range + dy;
float z = master->GetPositionZ();
float ground = master->GetMapHeight(x, y, z + 30.0f);
if (ground <= INVALID_HEIGHT)
if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(),
master->GetPositionZ(), x, y, z))
return Formation::NullLocation;
z += CONTACT_DISTANCE;
bot->UpdateAllowedPositionZ(x, y, z);
return WorldLocation(master->GetMapId(), x, y, z);
}
@@ -184,13 +199,10 @@ public:
float x = target->GetPositionX() + cos(angle) * range;
float y = target->GetPositionY() + sin(angle) * range;
float z = target->GetPositionZ();
float ground = target->GetMapHeight(x, y, z + 30.0f);
if (ground <= INVALID_HEIGHT)
if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(),
master->GetPositionZ(), x, y, z))
return Formation::NullLocation;
z += CONTACT_DISTANCE;
bot->UpdateAllowedPositionZ(x, y, z);
return WorldLocation(bot->GetMapId(), x, y, z);
}
};
@@ -350,16 +362,18 @@ public:
if (minDist)
{
z += CONTACT_DISTANCE;
bot->UpdateAllowedPositionZ(minX, minY, z);
if (!master->GetMap()->CheckCollisionAndGetValidCoords(
master, master->GetPositionX(), master->GetPositionY(), master->GetPositionZ(), x, y, z))
return Formation::NullLocation;
return WorldLocation(bot->GetMapId(), minX, minY, z);
}
return Formation::NullLocation;
}
z += CONTACT_DISTANCE;
bot->UpdateAllowedPositionZ(x, y, z);
if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(),
master->GetPositionZ(), x, y, z))
return Formation::NullLocation;
return WorldLocation(bot->GetMapId(), x, y, z);
}
};
@@ -618,12 +632,12 @@ WorldLocation MoveFormation::MoveSingleLine(std::vector<Player*> line, float dif
float lx = x + cos(angle) * radius;
float ly = y + sin(angle) * radius;
float lz = cz;
float ground = bot->GetMapHeight(lx, ly, lz + 30.0f);
if (ground <= INVALID_HEIGHT)
Player* master = botAI->GetMaster();
if (!master->GetMap()->CheckCollisionAndGetValidCoords(
master, master->GetPositionX(), master->GetPositionY(), master->GetPositionZ(), lx, ly, lz))
return Formation::NullLocation;
lz += CONTACT_DISTANCE;
bot->UpdateAllowedPositionZ(lx, ly, lz);
return WorldLocation(bot->GetMapId(), lx, ly, lz);
}

View File

@@ -6,6 +6,7 @@
#include "LastMovementValue.h"
#include "Playerbots.h"
#include "Timer.h"
LastMovement::LastMovement() { clear(); }
@@ -38,17 +39,19 @@ void LastMovement::clear()
lastAreaTrigger = 0;
lastFlee = 0;
nextTeleport = 0;
msTime = 0;
lastdelayTime = 0;
}
void LastMovement::Set(Unit* follow)
{
Set(0, 0.0f, 0.0f, 0.0f, 0.0f);
Set(0, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
setShort(WorldPosition());
setPath(TravelPath());
lastFollow = follow;
}
void LastMovement::Set(uint32 mapId, float x, float y, float z, float ori)
void LastMovement::Set(uint32 mapId, float x, float y, float z, float ori, float delayTime)
{
lastMoveToMapId = mapId;
lastMoveToX = x;
@@ -57,6 +60,8 @@ void LastMovement::Set(uint32 mapId, float x, float y, float z, float ori)
lastMoveToOri = ori;
lastFollow = nullptr;
lastMoveShort = WorldPosition(mapId, x, y, z, ori);
msTime = getMSTime();
lastdelayTime = delayTime;
}
void LastMovement::setShort(WorldPosition point)

View File

@@ -35,7 +35,7 @@ public:
void clear();
void Set(Unit* follow);
void Set(uint32 mapId, float x, float y, float z, float ori);
void Set(uint32 mapId, float x, float y, float z, float ori, float delayTime);
void setShort(WorldPosition point);
void setPath(TravelPath path);
@@ -50,7 +50,9 @@ public:
float lastMoveToY;
float lastMoveToZ;
float lastMoveToOri;
float lastdelayTime;
WorldPosition lastMoveShort;
uint32 msTime;
TravelPath lastPath;
time_t nextTeleport;
std::future<TravelPath> future;

View File

@@ -82,8 +82,7 @@ bool PartyMemberToHeal::Check(Unit* player)
// sServerFacade->GetDistance2d(bot, player) < (player->IsPlayer() && botAI->IsTank((Player*)player) ? 50.0f
// : 40.0f);
return player->GetMapId() == bot->GetMapId() && !player->IsCharmed() &&
bot->GetDistance2d(player) < sPlayerbotAIConfig->healDistance * 2 &&
bot->IsWithinLOS(player->GetPositionX(), player->GetPositionY(), player->GetPositionZ());
bot->GetDistance2d(player) < sPlayerbotAIConfig->healDistance * 2 && bot->IsWithinLOSInMap(player);
}
Unit* PartyMemberToProtect::Calculate()