mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-06-20 13:44:21 +00:00
fix: enemies snapping to the incorrect position if they had a path and trying to use the path if they were aggro'd to an enemy (#2005)
* fix: enemies snapping to the incorrect position if they had a path tested that ags enemies no longer snap backwards a large amount * fix: move the home point so we can aggro correctly
This commit is contained in:
@@ -37,8 +37,6 @@ MovementAIComponent::MovementAIComponent(Entity* parent, const int32_t component
|
|||||||
m_Info = info;
|
m_Info = info;
|
||||||
m_AtFinalWaypoint = true;
|
m_AtFinalWaypoint = true;
|
||||||
|
|
||||||
m_BaseCombatAI = nullptr;
|
|
||||||
|
|
||||||
m_BaseCombatAI = m_Parent->GetComponent<BaseCombatAIComponent>();
|
m_BaseCombatAI = m_Parent->GetComponent<BaseCombatAIComponent>();
|
||||||
|
|
||||||
//Try and fix the insane values:
|
//Try and fix the insane values:
|
||||||
@@ -131,7 +129,11 @@ void MovementAIComponent::Update(const float deltaTime) {
|
|||||||
|
|
||||||
m_TimeTravelled += deltaTime;
|
m_TimeTravelled += deltaTime;
|
||||||
|
|
||||||
SetPosition(ApproximateLocation());
|
const auto approxPos = ApproximateLocation();
|
||||||
|
SetPosition(approxPos);
|
||||||
|
// Set the AIs new home based on where our current waypoint is IF we're idle, that way we can return to this
|
||||||
|
// when resuming the pathing after losing aggro while moving the aggro hitbox with us
|
||||||
|
if (m_BaseCombatAI && m_BaseCombatAI->GetState() == AiState::idle) m_BaseCombatAI->SetStartingPosition(approxPos);
|
||||||
|
|
||||||
if (m_TimeTravelled < m_TimeToTravel) return;
|
if (m_TimeTravelled < m_TimeToTravel) return;
|
||||||
m_TimeTravelled = 0.0f;
|
m_TimeTravelled = 0.0f;
|
||||||
@@ -166,32 +168,34 @@ void MovementAIComponent::Update(const float deltaTime) {
|
|||||||
SetRotation(QuatUtils::LookAt(source, m_NextWaypoint));
|
SetRotation(QuatUtils::LookAt(source, m_NextWaypoint));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Check if there are more waypoints in the queue, if so set our next destination to the next waypoint
|
// Only try to renew or continue the path if we're in the idle or spawn state and we actually have a combatAI component
|
||||||
const auto waypointNum = m_IsBounced ? m_CurrentPath.size() : m_CurrentPathWaypointCount - m_CurrentPath.size() - 1;
|
if (!m_BaseCombatAI || (m_BaseCombatAI && m_BaseCombatAI->GetState() == AiState::idle)) {
|
||||||
RunWaypointCommands(waypointNum);
|
// Check if there are more waypoints in the queue, if so set our next destination to the next waypoint
|
||||||
if (m_CurrentPath.empty()) {
|
const auto waypointNum = m_IsBounced ? m_CurrentPath.size() : m_CurrentPathWaypointCount - m_CurrentPath.size() - 1;
|
||||||
if (m_Path) {
|
RunWaypointCommands(waypointNum);
|
||||||
if (m_Path->pathBehavior == PathBehavior::Loop) {
|
if (m_CurrentPath.empty()) {
|
||||||
SetPath(m_Path->pathWaypoints);
|
if (m_Path) {
|
||||||
} else if (m_Path->pathBehavior == PathBehavior::Bounce) {
|
if (m_Path->pathBehavior == PathBehavior::Loop) {
|
||||||
m_IsBounced = !m_IsBounced;
|
SetPath(m_Path->pathWaypoints);
|
||||||
std::vector<PathWaypoint> waypoints = m_Path->pathWaypoints;
|
} else if (m_Path->pathBehavior == PathBehavior::Bounce) {
|
||||||
if (m_IsBounced) std::ranges::reverse(waypoints);
|
m_IsBounced = !m_IsBounced;
|
||||||
SetPath(waypoints);
|
std::vector<PathWaypoint> waypoints = m_Path->pathWaypoints;
|
||||||
} else if (m_Path->pathBehavior == PathBehavior::Once) {
|
if (m_IsBounced) std::ranges::reverse(waypoints);
|
||||||
// In this case we intended to follow a path and once we've followed it we camp there, otherwise we'd just wander home again.
|
SetPath(waypoints);
|
||||||
if (m_BaseCombatAI) m_BaseCombatAI->SetStartingPosition(m_SourcePosition);
|
} else if (m_Path->pathBehavior == PathBehavior::Once) {
|
||||||
|
// In this case we intended to follow a path and once we've followed it we camp there, otherwise we'd just wander home again.
|
||||||
|
Stop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
Stop();
|
Stop();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Stop();
|
SetDestination(m_CurrentPath.top().position);
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
SetDestination(m_CurrentPath.top().position);
|
|
||||||
|
|
||||||
m_CurrentPath.pop();
|
m_CurrentPath.pop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,8 +222,7 @@ NiPoint3 MovementAIComponent::GetCurrentWaypoint() const {
|
|||||||
|
|
||||||
NiPoint3 MovementAIComponent::ApproximateLocation() const {
|
NiPoint3 MovementAIComponent::ApproximateLocation() const {
|
||||||
auto source = m_SourcePosition;
|
auto source = m_SourcePosition;
|
||||||
|
if (AtFinalWaypoint()) return m_Parent->GetPosition();
|
||||||
if (AtFinalWaypoint()) return source;
|
|
||||||
|
|
||||||
auto destination = m_NextWaypoint;
|
auto destination = m_NextWaypoint;
|
||||||
|
|
||||||
@@ -473,7 +476,7 @@ void MovementAIComponent::RunWaypointCommands(uint32_t waypointNum) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case eWaypointCommandType::DELAY: {
|
case eWaypointCommandType::DELAY: {
|
||||||
// Pause(GeneralUtils::TryParse<float>(data).value_or(0.0f));
|
// Pause(GeneralUtils::TryParse<float>(data).value_or(0.0f));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case eWaypointCommandType::EMOTE: {
|
case eWaypointCommandType::EMOTE: {
|
||||||
@@ -521,6 +524,7 @@ bool MovementAIComponent::OnGetObjectReportInfo(GameMessages::GetObjectReportInf
|
|||||||
movementInfo.PushDebug<AMFBoolValue>("Lock Rotation") = m_LockRotation;
|
movementInfo.PushDebug<AMFBoolValue>("Lock Rotation") = m_LockRotation;
|
||||||
movementInfo.PushDebug<AMFBoolValue>("Paused") = m_Paused;
|
movementInfo.PushDebug<AMFBoolValue>("Paused") = m_Paused;
|
||||||
movementInfo.PushDebug<AMFDoubleValue>("Pulling To Point") = m_PullingToPoint;
|
movementInfo.PushDebug<AMFDoubleValue>("Pulling To Point") = m_PullingToPoint;
|
||||||
|
movementInfo.PushDebug<AMFBoolValue>("At Final Waypoint") = m_AtFinalWaypoint;
|
||||||
|
|
||||||
auto& pullPointInfo = movementInfo.PushDebug("Pull Point");
|
auto& pullPointInfo = movementInfo.PushDebug("Pull Point");
|
||||||
pullPointInfo.PushDebug<AMFDoubleValue>("X") = m_PullPoint.x;
|
pullPointInfo.PushDebug<AMFDoubleValue>("X") = m_PullPoint.x;
|
||||||
|
|||||||
Reference in New Issue
Block a user