Make better move point for follow and reach combat

This commit is contained in:
Yunfan Li
2024-08-03 11:52:02 +08:00
parent 78cdc11ba5
commit b0c0002206
3 changed files with 57 additions and 39 deletions

View File

@@ -83,19 +83,15 @@ public:
if (!master)
return WorldLocation();
float range = sPlayerbotAIConfig->followDistance;
float angle = GetFollowAngle();
float x = master->GetPositionX() + cos(angle) * range;
float y = master->GetPositionY() + sin(angle) * range;
float z = master->GetPositionZ();
float ground = master->GetMapHeight(x, y, z + 30.0f);
if (ground <= INVALID_HEIGHT)
return Formation::NullLocation;
// z += CONTACT_DISTANCE;
// bot->UpdateAllowedPositionZ(x, y, z);
return WorldLocation(master->GetMapId(), x, y, z);
float range = sPlayerbotAIConfig->followDistance;
float angle = GetFollowAngle();
float x = master->GetPositionX() + cos(angle) * range;
float y = master->GetPositionY() + sin(angle) * range;
float z = master->GetPositionZ();
if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(), master->GetPositionZ(), x, y, z))
return Formation::NullLocation;
return WorldLocation(master->GetMapId(), x, y, z);
}
float GetMaxDistance() override { return sPlayerbotAIConfig->followDistance; }
@@ -118,21 +114,36 @@ 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 +195,9 @@ 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 +357,16 @@ 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 +625,11 @@ 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);
}