mirror of
https://github.com/mod-playerbots/mod-playerbots.git
synced 2026-02-13 23:33:47 +00:00
Fix melee reach target
This commit is contained in:
@@ -149,7 +149,7 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
|
||||
// if (bot->Unit::IsFalling()) {
|
||||
// bot->Say("I'm falling", LANG_UNIVERSAL);
|
||||
// }
|
||||
float distance = bot->GetDistance(x, y, z);
|
||||
float distance = bot->GetExactDist(x, y, z);
|
||||
if (distance > sPlayerbotAIConfig->contactDistance)
|
||||
{
|
||||
WaitForReach(distance);
|
||||
@@ -671,7 +671,41 @@ bool MovementAction::MoveTo(Unit* target, float distance)
|
||||
float ty = target->GetPositionY();
|
||||
float tz = target->GetPositionZ();
|
||||
|
||||
float distanceToTarget = bot->GetDistance2d(target);
|
||||
float distanceToTarget = bot->GetDistance(target);
|
||||
float angle = bot->GetAngle(target);
|
||||
float needToGo = distanceToTarget - distance;
|
||||
|
||||
float maxDistance = sPlayerbotAIConfig->spellDistance;
|
||||
if (needToGo > 0 && needToGo > maxDistance)
|
||||
needToGo = maxDistance;
|
||||
else if (needToGo < 0 && needToGo < -maxDistance)
|
||||
needToGo = -maxDistance;
|
||||
|
||||
float dx = cos(angle) * needToGo + bx;
|
||||
float dy = sin(angle) * needToGo + by;
|
||||
float dz; // = std::max(bz, tz); // calc accurate z position to avoid stuck
|
||||
if (distanceToTarget > CONTACT_DISTANCE) {
|
||||
dz = bz + (tz - bz) * (needToGo / distanceToTarget);
|
||||
} else {
|
||||
dz = tz;
|
||||
}
|
||||
return MoveTo(target->GetMapId(), dx, dy, dz);
|
||||
}
|
||||
|
||||
bool MovementAction::ReachCombatTo(Unit* target, float distance)
|
||||
{
|
||||
if (!IsMovingAllowed(target))
|
||||
return false;
|
||||
|
||||
float bx = bot->GetPositionX();
|
||||
float by = bot->GetPositionY();
|
||||
float bz = bot->GetPositionZ();
|
||||
|
||||
float tx = target->GetPositionX();
|
||||
float ty = target->GetPositionY();
|
||||
float tz = target->GetPositionZ();
|
||||
float combatDistance = bot->GetCombatReach() + target->GetCombatReach();
|
||||
float distanceToTarget = bot->GetExactDist(target) - combatDistance;
|
||||
float angle = bot->GetAngle(target);
|
||||
float needToGo = distanceToTarget - distance;
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ class MovementAction : public Action
|
||||
bool Follow(Unit* target, float distance = sPlayerbotAIConfig->followDistance);
|
||||
bool Follow(Unit* target, float distance, float angle);
|
||||
bool ChaseTo(WorldObject* obj, float distance = 0.0f, float angle = 0.0f);
|
||||
bool ReachCombatTo(Unit* target, float distance = 0.0f);
|
||||
float MoveDelay(float distance);
|
||||
void WaitForReach(float distance);
|
||||
bool IsMovingAllowed(Unit* target);
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
bool ReachTargetAction::Execute(Event event)
|
||||
{
|
||||
return MoveTo(AI_VALUE(Unit*, GetTargetName()), distance);
|
||||
return ReachCombatTo(AI_VALUE(Unit*, GetTargetName()), distance);
|
||||
}
|
||||
|
||||
bool ReachTargetAction::isUseful()
|
||||
@@ -19,8 +19,9 @@ bool ReachTargetAction::isUseful()
|
||||
if (bot->GetCurrentSpell(CURRENT_CHANNELED_SPELL) != nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return AI_VALUE2(float, "distance", GetTargetName()) > (distance + sPlayerbotAIConfig->contactDistance);
|
||||
Unit* target = GetTarget();
|
||||
// float dis = distance + CONTACT_DISTANCE;
|
||||
return target && !bot->IsWithinCombatRange(target, distance); // sServerFacade->IsDistanceGreaterThan(AI_VALUE2(float, "distance", GetTargetName()), distance);
|
||||
}
|
||||
|
||||
std::string const ReachTargetAction::GetTargetName()
|
||||
|
||||
Reference in New Issue
Block a user