Merge pull request #435 from liyunfan1223/mount0804

Follow waypoints and mount
This commit is contained in:
Yunfan Li
2024-08-05 09:46:59 +08:00
committed by GitHub
3 changed files with 51 additions and 40 deletions

View File

@@ -18,31 +18,28 @@ bool CheckMountStateAction::Execute(Event event)
AI_VALUE2(bool, "combat", "self target") ? (AI_VALUE(uint8, "attacker count") > 0 ? false : true) : true; AI_VALUE2(bool, "combat", "self target") ? (AI_VALUE(uint8, "attacker count") > 0 ? false : true) : true;
bool enemy = AI_VALUE(Unit*, "enemy player target"); bool enemy = AI_VALUE(Unit*, "enemy player target");
// ignore grind target in BG or bots will dismount near any creature (eg: the rams in AV) // ignore grind target in BG or bots will dismount near any creature (eg: the rams in AV)
bool dps = (AI_VALUE(Unit*, "dps target") || (!bot->InBattleground() && AI_VALUE(Unit*, "grind target"))); bool dps = AI_VALUE(Unit*, "dps target");
bool fartarget = bool fartarget =
(enemy && sServerFacade->IsDistanceGreaterThan(AI_VALUE2(float, "distance", "enemy player target"), 40.0f)) || (enemy && sServerFacade->IsDistanceGreaterThan(AI_VALUE2(float, "distance", "enemy player target"), 40.0f)) ||
(dps && sServerFacade->IsDistanceGreaterThan(AI_VALUE2(float, "distance", "dps target"), 50.0f)); (dps && sServerFacade->IsDistanceGreaterThan(AI_VALUE2(float, "distance", "dps target"), 50.0f));
bool attackdistance = false; bool attackdistance = false;
bool chasedistance = false; // bool chasedistance = false;
float attack_distance = 35.0f; float attack_distance = 35.0f;
if (PlayerbotAI::IsMelee(bot)) if (PlayerbotAI::IsMelee(bot))
{ {
attack_distance = 10.0f; attack_distance = 5.0f;
} }
else else
{ {
attack_distance = 40.0f; attack_distance = 30.0f;
} }
if (enemy)
attack_distance /= 2;
if (dps || enemy) if (dps || enemy)
{ {
attackdistance = (enemy || dps) && sServerFacade->IsDistanceLessThan( Unit* currentTarget = AI_VALUE(Unit*, "current target");
AI_VALUE2(float, "distance", "current target"), attack_distance); attackdistance =
chasedistance = (enemy || dps) && currentTarget &&
enemy && sServerFacade->IsDistanceGreaterThan(AI_VALUE2(float, "distance", "enemy player target"), 45.0f) && sServerFacade->IsDistanceLessThan(AI_VALUE2(float, "distance", "current target"), attack_distance);
AI_VALUE2(bool, "moving", "enemy player target");
} }
if (bot->IsMounted() && attackdistance) if (bot->IsMounted() && attackdistance)

View File

@@ -48,8 +48,8 @@ WorldLocation ArrowFormation::GetLocationInternal()
float y = master->GetPositionY() - masterUnit->GetY() + botUnit->GetY(); float y = master->GetPositionY() - masterUnit->GetY() + botUnit->GetY();
float z = master->GetPositionZ(); float z = master->GetPositionZ();
float ground = master->GetMapHeight(x, y, z + 30.0f); if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(),
if (ground <= INVALID_HEIGHT) master->GetPositionZ(), x, y, z))
return Formation::NullLocation; return Formation::NullLocation;
// master->UpdateGroundPositionZ(x, y, z); // master->UpdateGroundPositionZ(x, y, z);
return WorldLocation(master->GetMapId(), 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 y = master->GetPositionY() + sin(angle) * range;
float z = master->GetPositionZ(); float z = master->GetPositionZ();
float ground = master->GetMapHeight(x, y, z + 30.0f); if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(),
if (ground <= INVALID_HEIGHT) master->GetPositionZ(), x, y, z))
return Formation::NullLocation; return Formation::NullLocation;
// z += CONTACT_DISTANCE;
// bot->UpdateAllowedPositionZ(x, y, z);
return WorldLocation(master->GetMapId(), x, y, z); return WorldLocation(master->GetMapId(), x, y, z);
} }
@@ -118,21 +115,39 @@ public:
time_t now = time(nullptr); time_t now = time(nullptr);
if (!lastChangeTime || now - lastChangeTime >= 3) if (!lastChangeTime || now - lastChangeTime >= 3)
{ {
lastChangeTime = now; Player* master = botAI->GetGroupMaster();
dx = (urand(0, 10) / 10.0 - 0.5) * sPlayerbotAIConfig->tooCloseDistance; if (!master)
dy = (urand(0, 10) / 10.0 - 0.5) * sPlayerbotAIConfig->tooCloseDistance; return WorldLocation();
dr = sqrt(dx * dx + dy * dy);
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 x = master->GetPositionX() + cos(angle) * range + dx;
float y = master->GetPositionY() + sin(angle) * range + dy; float y = master->GetPositionY() + sin(angle) * range + dy;
float z = master->GetPositionZ(); float z = master->GetPositionZ();
float ground = master->GetMapHeight(x, y, z + 30.0f); if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(),
if (ground <= INVALID_HEIGHT) master->GetPositionZ(), x, y, z))
return Formation::NullLocation; return Formation::NullLocation;
z += CONTACT_DISTANCE;
bot->UpdateAllowedPositionZ(x, y, z);
return WorldLocation(master->GetMapId(), x, y, z); return WorldLocation(master->GetMapId(), x, y, z);
} }
@@ -184,13 +199,10 @@ public:
float x = target->GetPositionX() + cos(angle) * range; float x = target->GetPositionX() + cos(angle) * range;
float y = target->GetPositionY() + sin(angle) * range; float y = target->GetPositionY() + sin(angle) * range;
float z = target->GetPositionZ(); float z = target->GetPositionZ();
float ground = target->GetMapHeight(x, y, z + 30.0f); if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(),
if (ground <= INVALID_HEIGHT) master->GetPositionZ(), x, y, z))
return Formation::NullLocation; return Formation::NullLocation;
z += CONTACT_DISTANCE;
bot->UpdateAllowedPositionZ(x, y, z);
return WorldLocation(bot->GetMapId(), x, y, z); return WorldLocation(bot->GetMapId(), x, y, z);
} }
}; };
@@ -350,16 +362,18 @@ public:
if (minDist) if (minDist)
{ {
z += CONTACT_DISTANCE; if (!master->GetMap()->CheckCollisionAndGetValidCoords(
bot->UpdateAllowedPositionZ(minX, minY, z); master, master->GetPositionX(), master->GetPositionY(), master->GetPositionZ(), x, y, z))
return Formation::NullLocation;
return WorldLocation(bot->GetMapId(), minX, minY, z); return WorldLocation(bot->GetMapId(), minX, minY, z);
} }
return Formation::NullLocation; return Formation::NullLocation;
} }
z += CONTACT_DISTANCE; if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(),
bot->UpdateAllowedPositionZ(x, y, z); master->GetPositionZ(), x, y, z))
return Formation::NullLocation;
return WorldLocation(bot->GetMapId(), x, y, z); 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 lx = x + cos(angle) * radius;
float ly = y + sin(angle) * radius; float ly = y + sin(angle) * radius;
float lz = cz; 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; return Formation::NullLocation;
lz += CONTACT_DISTANCE;
bot->UpdateAllowedPositionZ(lx, ly, lz);
return WorldLocation(bot->GetMapId(), lx, ly, lz); return WorldLocation(bot->GetMapId(), lx, ly, lz);
} }