bool Monster::walkToSpawn()
{
if (walkingToSpawn || !spawn || !targetList.empty()) {
return false;
}
int32_t distance = std::max<int32_t>(Position::getDistanceX(position, masterPos), Position::getDistanceY(position, masterPos));
if (distance == 0) {
return false;
}
// Check if the monster is outside the walking-to-spawn area
const int32_t walkingToSpawnRadius = 20; // Adjust this radius as needed
if (distance > walkingToSpawnRadius) {
// Spawn a new monster and return false to indicate that walking to spawn is not possible
handleOverspawn();
return false;
}
listWalkDir.clear();
if (!getPathTo(masterPos, listWalkDir, 0, std::max<int32_t>(0, distance - 5), true, true, distance)) {
return false;
}
walkingToSpawn = true;
startAutoWalk();
return true;
}