mirror of
https://github.com/liyunfan1223/mod-playerbots.git
synced 2026-02-21 10:30:01 +01:00
Make better move point for follow and reach combat
This commit is contained in:
parent
78cdc11ba5
commit
b0c0002206
@ -790,14 +790,27 @@ bool MovementAction::ReachCombatTo(Unit* target, float distance)
|
|||||||
float dx = cos(angle) * needToGo + bx;
|
float dx = cos(angle) * needToGo + bx;
|
||||||
float dy = sin(angle) * needToGo + by;
|
float dy = sin(angle) * needToGo + by;
|
||||||
float dz; // = std::max(bz, tz); // calc accurate z position to avoid stuck
|
float dz; // = std::max(bz, tz); // calc accurate z position to avoid stuck
|
||||||
if (distanceToTarget > CONTACT_DISTANCE)
|
|
||||||
|
if (target->HasUnitMovementFlag(MOVEMENTFLAG_FORWARD)) // target is moving forward, predict the position
|
||||||
{
|
{
|
||||||
|
float timeToGo = MoveDelay(abs(needToGo));
|
||||||
|
float targetMoveDist = timeToGo * target->GetSpeed(MOVE_RUN);
|
||||||
|
targetMoveDist = std::min(5.0f, targetMoveDist);
|
||||||
|
dx += targetMoveDist * cos(target->GetOrientation());
|
||||||
|
dy += targetMoveDist * sin(target->GetOrientation());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (distanceToTarget > CONTACT_DISTANCE) {
|
||||||
dz = bz + (tz - bz) * (needToGo / distanceToTarget);
|
dz = bz + (tz - bz) * (needToGo / distanceToTarget);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dz = tz;
|
dz = tz;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!bot->GetMap()->CheckCollisionAndGetValidCoords(bot, bot->GetPositionX(), bot->GetPositionY(), bot->GetPositionZ(), dx, dy, dz))
|
||||||
|
return false;
|
||||||
|
|
||||||
return MoveTo(target->GetMapId(), dx, dy, dz);
|
return MoveTo(target->GetMapId(), dx, dy, dz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -48,8 +48,7 @@ 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(), master->GetPositionZ(), x, y, z))
|
||||||
if (ground <= INVALID_HEIGHT)
|
|
||||||
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);
|
||||||
|
|||||||
@ -89,12 +89,8 @@ 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(), master->GetPositionZ(), x, y, z))
|
||||||
if (ground <= INVALID_HEIGHT)
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,6 +103,16 @@ public:
|
|||||||
ChaosFormation(PlayerbotAI* botAI) : MoveAheadFormation(botAI, "chaos"), lastChangeTime(0) {}
|
ChaosFormation(PlayerbotAI* botAI) : MoveAheadFormation(botAI, "chaos"), lastChangeTime(0) {}
|
||||||
|
|
||||||
WorldLocation GetLocationInternal() override
|
WorldLocation GetLocationInternal() override
|
||||||
|
{
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
Player* master = botAI->GetGroupMaster();
|
Player* master = botAI->GetGroupMaster();
|
||||||
if (!master)
|
if (!master)
|
||||||
@ -127,12 +133,17 @@ public:
|
|||||||
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(), master->GetPositionZ(), x, y, z))
|
||||||
if (ground <= INVALID_HEIGHT)
|
|
||||||
return Formation::NullLocation;
|
return Formation::NullLocation;
|
||||||
|
// bot->GetMap()->CheckCollisionAndGetValidCoords(bot, bot->GetPositionX(), bot->GetPositionY(), bot->GetPositionZ(), x, y, z);
|
||||||
|
return WorldLocation(master->GetMapId(), x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
z += CONTACT_DISTANCE;
|
float x = master->GetPositionX() + cos(angle) * range + dx;
|
||||||
bot->UpdateAllowedPositionZ(x, y, z);
|
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;
|
||||||
return WorldLocation(master->GetMapId(), x, y, z);
|
return WorldLocation(master->GetMapId(), x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,13 +195,9 @@ 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(), master->GetPositionZ(), x, y, z))
|
||||||
if (ground <= INVALID_HEIGHT)
|
|
||||||
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 +357,16 @@ public:
|
|||||||
|
|
||||||
if (minDist)
|
if (minDist)
|
||||||
{
|
{
|
||||||
z += CONTACT_DISTANCE;
|
if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(), master->GetPositionZ(), x, y, z))
|
||||||
bot->UpdateAllowedPositionZ(minX, minY, 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(), master->GetPositionZ(), x, y, z))
|
||||||
bot->UpdateAllowedPositionZ(x, y, z);
|
return Formation::NullLocation;
|
||||||
return WorldLocation(bot->GetMapId(), x, y, z);
|
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 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user