Class RetreatState
- Namespace
- FishMMO.Server.Implementation.World.SceneServer.AI
- Assembly
- FishMMO.Server.dll
Moves the NPC away from its target until a safe distance is reached, then disengages.
[CreateAssetMenu(fileName = "New AI Retreat State", menuName = "FishMMO/Character/NPC/AI/Retreat State", order = 0)]
public class RetreatState : BaseAIState, ICachedObject
- Inheritance
-
ObjectScriptableObjectRetreatState
- Implements
- Inherited Members
-
ScriptableObject.SetDirty()ScriptableObject.CreateInstance<T>()Object.GetEntityId()Object.MemberwiseClone()Object.GetInstanceID()Object.GetHashCode()Object.InstantiateAsync<T>(T)Object.InstantiateAsync<T>(T, Transform)Object.InstantiateAsync<T>(T, Vector3, Quaternion)Object.InstantiateAsync<T>(T, Transform, Vector3, Quaternion)Object.Instantiate(Object, Vector3, Quaternion)Object.Instantiate(Object, Vector3, Quaternion, Transform)Object.Instantiate(Object)Object.Instantiate(Object, Scene)Object.Instantiate<T>(T, InstantiateParameters)Object.Instantiate<T>(T, Vector3, Quaternion, InstantiateParameters)Object.Instantiate(Object, Transform)Object.Instantiate<T>(T)Object.Instantiate<T>(T, Vector3, Quaternion)Object.Instantiate<T>(T, Vector3, Quaternion, Transform)Object.Instantiate<T>(T, Transform)Object.Destroy(Object)Object.DestroyImmediate(Object)Object.DontDestroyOnLoad(Object)Object.DestroyObject(Object)Object.FindObjectsOfType<T>()Object.FindObjectsByType<T>(FindObjectsSortMode)Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)Object.FindObjectOfType<T>()Object.FindFirstObjectByType<T>()Object.FindAnyObjectByType<T>()Object.FindFirstObjectByType<T>(FindObjectsInactive)Object.FindAnyObjectByType<T>(FindObjectsInactive)Object.FindObjectsByType<T>()Object.FindObjectsByType<T>(FindObjectsInactive)Object.ToString()Object.nameObject.hideFlags
Remarks
Used both as the flee state for a Pathetic or Cautious personality and as a caster's emergency-retreat hand-off. Enable KeepsCombatTarget on assets of this type: the retreat direction is computed from the target, so clearing it on the way in would leave the NPC with no idea which way to run.
Fleeing is the movement most likely to run out of room — the NPC is by definition being pushed toward whatever is behind it — so every step of it is bounded. A cornered NPC that cannot retreat gives up and re-engages rather than standing against a wall being hit while a "retreating" state reports success.
Fields
MaxCumulativeRetreatSeconds
[Header("Cumulative Limit")]
[Tooltip("Total seconds of retreating allowed per fight. 0 = unlimited, which is the old behaviour.")]
public float MaxCumulativeRetreatSeconds
Field Value
MaxRetreatSeconds
Seconds the NPC will keep trying to retreat before accepting that it cannot.
[Tooltip("Seconds spent retreating before giving up. 0 = retreat until safe.")]
public float MaxRetreatSeconds
Field Value
MinRetreatSeconds
[Header("Turning Back")]
[Tooltip("Seconds to retreat before turning back is considered. 0 allows turning back immediately.")]
public float MinRetreatSeconds
Field Value
ReengageChance
Base chance, per check, that the NPC turns around and fights instead of continuing to run.
[Tooltip("Base chance per check of turning back to fight. 0 = never turns back on chance alone.")]
[Range(0, 1)]
public float ReengageChance
Field Value
ReengageChanceRamp
Added to ReengageChance for each retreat taken this fight, counting the one in progress.
[Tooltip("Added to the re-engagement chance per retreat taken this fight, the one in progress included. This is what guarantees a long chase ends in a fight.")]
[Range(0, 1)]
public float ReengageChanceRamp
Field Value
Remarks
This ramp is what guarantees a long chase ends in a fight. A flat chance can lose the same roll a hundred times; a chance that climbs with every retreat the NPC has already made against the same opponent converges on certainty, so an NPC being chased across the zone will always eventually stop and turn.
ReengageCheckInterval
Seconds between re-engagement checks.
[Tooltip("Seconds between re-engagement checks while retreating.")]
public float ReengageCheckInterval
Field Value
ReengageCooldownSeconds
Seconds during which fleeing is refused after the NPC turns back to fight.
[Tooltip("Seconds during which fleeing is refused after turning back to fight.")]
public float ReengageCooldownSeconds
Field Value
Remarks
Without this the attacking state re-plans on the very next tick, finds the same health threshold still violated, and hands straight back to this state — the NPC turns to fight and flees again before either is visible.
RetreatDistance
How far the NPC moves away from its target on each retreat leg.
public float RetreatDistance
Field Value
RetreatRecoverySeconds
Seconds the NPC must stand and fight once the cumulative cap is spent.
[Tooltip("Seconds of hold once the cumulative cap is spent.")]
public float RetreatRecoverySeconds
Field Value
SafeDistance
Distance from the target at which the NPC stops retreating.
public float SafeDistance
Field Value
Methods
Enter(AIController)
Picks the first retreat destination.
public override void Enter(AIController controller)
Parameters
controllerAIControllerThe AI controller managing this NPC.
Exit(AIController)
Called when the state is exited.
public override void Exit(AIController controller)
Parameters
controllerAIControllerThe AI controller managing this NPC.
UpdateState(AIController, float)
Keeps backing away until safe, cornered, or out of patience.
public override void UpdateState(AIController controller, float deltaTime)
Parameters
controllerAIControllerThe AI controller managing this NPC.
deltaTimefloatSeconds since the previous AI tick.