Struct AIRetreatBudget
- Namespace
- FishMMO.Server.Implementation.World.SceneServer.AI
- Assembly
- FishMMO.Server.dll
The memory a retreating NPC needs to stop retreating: how long it has been running, how many times it has run during this fight, and whether it has committed to fighting instead.
public struct AIRetreatBudget
- Inherited Members
Remarks
Why memory is the whole point. Fleeing used to be decided from the current tick's distance and health alone, so the same inputs produced the same answer forever and a pursued NPC ran until it hit the leash. Every field here exists so a later tick can tell it is in the same situation as an earlier one and reach a different answer.
One per NPC (on AIController), never on the shared state asset. A retreat state
asset is referenced by every NPC that flees, so a seconds-retreating counter stored on it
would be one counter shared by the whole server — one NPC's chase spending another's budget,
and the same mistake makes a template's authored data unreadable as authored data. This
mirrors AIKiteBudget exactly, which solves the identical "the NPC never stands
and fights" problem for backing away.
Fields
ConsecutiveRetreats
Retreats taken during the current fight.
public int ConsecutiveRetreats
Field Value
Remarks
Deliberately not cleared by Reset(float): it counts episodes within one fight, and Reset(float) runs whenever the budget refills mid-fight. It is cleared only by Clear(), which is a genuine end to combat. Clearing it on a lost target instead would mean it never accumulated at all — every retreat drops the target on the way out — and the ramp driven by it would be dead code.
DecisionTimer
Seconds until the next re-engagement roll is allowed.
public float DecisionTimer
Field Value
REFUND_RATE
Fraction of elapsed time refunded while not retreating.
public const float REFUND_RATE = 0.25
Field Value
Remarks
Slower than the kite budget's half. Kiting is a positioning choice made every few seconds and should come back readily; running for your life is a decision an NPC should have to earn again, so the budget refills at a rate that makes a long fight with several retreats progressively harder to flee from — which is what ends the loop.
RecoveryTimer
Seconds left of the hold imposed once the cumulative cap was spent.
public float RecoveryTimer
Field Value
ReengageHold
Seconds left of the hold imposed when the NPC chose to turn and fight.
public float ReengageHold
Field Value
Remaining
Seconds of retreating left in the cumulative window.
public float Remaining
Field Value
Properties
Exhausted
True while the NPC must not flee.
public bool Exhausted { get; }
Property Value
Remarks
Derived, never assigned. Two independent things can refuse a retreat — the cumulative cap for this fight being spent, and a hold imposed because the NPC chose to turn and fight — and they overlap and expire on different clocks. A hand-maintained flag had to be set by both, cleared by whichever expired first, and re-derived on the way out; reading it off the two timers instead means it cannot disagree with them.
Methods
Clear()
Clears everything, for pooling and for a genuine end to combat.
public void Clear()
NoteReengage(float)
Records that the NPC chose to stop running and fight.
public void NoteReengage(float holdSeconds)
Parameters
holdSecondsfloatSeconds during which fleeing is refused.
Remarks
The hold is what makes the choice stick. Without it the attacking state re-plans on the very next tick, finds the same health or distance threshold still violated, and hands straight back to the retreat — which is exactly the loop this whole change is fixing.
NoteRetreatStart(float)
Records that a retreat episode has begun.
public void NoteRetreatStart(float checkIntervalSeconds)
Parameters
checkIntervalSecondsfloatSeconds before the first re-engagement roll.
Reset(float)
Primes the budget for a new fight.
public void Reset(float budgetSeconds)
Parameters
budgetSecondsfloatSeconds of retreating allowed before the hold.
Tick(bool, float, float, float)
Advances the budget by one AI tick.
public void Tick(bool retreating, float deltaTime, float budgetSeconds, float recoverySeconds)
Parameters
retreatingboolTrue if the NPC spent this tick running away.
deltaTimefloatSeconds elapsed since the previous AI tick.
budgetSecondsfloatSeconds of retreating allowed per fight. 0 disables the cap.
recoverySecondsfloatSeconds of hold once the cap is spent.
Remarks
Called on every tick regardless of state, because the refund and both holds have to run while the NPC is not retreating — a budget that only ticked inside the retreat state could never refill, and both holds would be permanent.