Table of Contents

Class PredictedCombatEvents

Namespace
FishMMO.Shared
Assembly
FishMMO.Shared.dll

Tracks combat numbers a client has drawn from its OWN predicted hits, and reconciles them against the server's combat report.

public static class PredictedCombatEvents
Inheritance
PredictedCombatEvents
Inherited Members

Remarks

Why the client draws first. Damage numbers used to come only from CombatEventBroadcast, so a player's own hit showed nothing until the report came back — half a round trip of nothing happening, on the one action combat is built around. The caster predicted the cast and owns the input that produced it, so it can draw the number the moment its predicted projectile connects.

Why the amounts agree. Damage variance is drawn from the ability object's DeterministicRNG (RandomRangeValue reads EventData.RNG), whose state is carried in the reconcile and corrected every tick. Client and server draw the same number from the same state. A hit-count divergence advances the two generators differently until the next reconcile realigns them, so a mismatch is possible, bounded, and self-healing — which is why TryConfirm(ICharacter, ICharacter, Kind, int, DamageAttributeTemplate) matches on source, target and kind rather than on the amount.

Why absence is the general rejection signal. The server cannot tell a client "that hit did not land", because it never knew the client predicted one — it simply resolves its own simulation and reports what happened. So a prediction that goes unconfirmed for ConfirmationWindowSeconds is treated as rejected. That costs no bandwidth and needs no new message.

The one exception is a hit the target turned away. An evading NPC or an immortal one refuses the hit on the server, and the server reports THAT (Evade, Immune) — not because it knows about the prediction, but because what happened is worth saying. TryRefuse(ICharacter, ICharacter, CombatEventKind, int, DamageAttributeTemplate) settles the matching predictions at once, as refused, so the display can turn the number into the reason instead of greying it out a second later with no explanation.

Pure bookkeeping with no Unity or rendering dependency, so the policy is unit tested. The client's display layer subscribes to the events below; nothing here draws anything.

Fields

HealthPushStampOf

Reads a target's health-push count when a prediction is made; set by CharacterDamageController.

public static Func<ICharacter, int> HealthPushStampOf

Field Value

Func<ICharacter, int>

Properties

ConfirmationWindowSeconds

How long a predicted number waits for the server to confirm it before being treated as rejected.

public static float ConfirmationWindowSeconds { get; set; }

Property Value

float

Remarks

Must comfortably exceed a round trip plus the server's report cadence (combat events flush every tick, so the cadence term is one tick). Too short invalidates good hits on a laggy connection — far worse than the occasional wrong number lingering, because it makes a working hit look broken.

PendingCount

Predicted entries still waiting on the server.

public static int PendingCount { get; }

Property Value

int

Methods

Clear()

Drops every pending prediction without raising rejections.

public static void Clear()

Remarks

For a scene change or disconnect, where the numbers and the characters they were drawn over are both gone. Raising rejections here would ask the display to grey out labels that no longer exist.

CurrentHealth(ICharacter)

Network object id for a character, or 0 when it has no network identity.

public static float CurrentHealth(ICharacter target)

Parameters

target ICharacter

Returns

float

HealthMoved(float, float)

How far a prediction moved a bar, from its value before and after: what undoing it must put back. The amount the prediction asked for is not it: damage of 50 on a target at 10 moves the bar 10, and a heal of 20 on one at 95 of 100 moves it 5, so undoing the amount left the bar 40 above or 15 below the server's.

public static int HealthMoved(float before, float after)

Parameters

before float
after float

Returns

int

PendingAmount(ICharacter, ICharacter, Kind, int, DamageAttributeTemplate)

How much of a report this client already applied as predictions: the summed amounts of the pending predictions the report would settle (same pairing as TryConfirm(ICharacter, ICharacter, Kind, int, DamageAttributeTemplate): source, target, kind, damage type, oldest first, up to occurrences). Nothing is settled; the display still does that.

public static int PendingAmount(ICharacter source, ICharacter target, PredictedCombatEvents.Kind kind, int occurrences = 1, DamageAttributeTemplate damageAttribute = null)

Parameters

source ICharacter
target ICharacter
kind PredictedCombatEvents.Kind
occurrences int
damageAttribute DamageAttributeTemplate

Returns

int

The predicted amount the report stands for; 0 when none was predicted.

Remarks

The caster's predicted hit already moved the target's health bar on this client, so the report's health delta must not move it again: the receive seam applies only the part of the report nothing here predicted. Every other client holds no predictions for this source and gets 0, so it applies the whole report as before.

Predict(ICharacter, ICharacter, int, Kind, DamageAttributeTemplate, float, int)

Records and announces a number this client predicted.

public static void Predict(ICharacter source, ICharacter target, int amount, PredictedCombatEvents.Kind kind, DamageAttributeTemplate damageAttribute, float now, int movedHealth = -1)

Parameters

source ICharacter

The character that dealt it — this client's own, since only an owner predicts.

target ICharacter

The character the number belongs to.

amount int

The predicted amount.

kind PredictedCombatEvents.Kind

Damage or heal.

damageAttribute DamageAttributeTemplate

Damage type, for colouring. Null for heals and typeless damage.

now float

Current unscaled time, in seconds.

movedHealth int

Sweep(float)

Rejects predictions the server never confirmed. Call once per frame or tick.

public static void Sweep(float now)

Parameters

now float

Current unscaled time, in seconds.

TryConfirm(ICharacter, ICharacter, Kind, int, DamageAttributeTemplate)

Consumes a pending prediction matching an arriving server report.

public static bool TryConfirm(ICharacter source, ICharacter target, PredictedCombatEvents.Kind kind, int occurrences = 1, DamageAttributeTemplate damageAttribute = null)

Parameters

source ICharacter

The attacker named by the report. A report with none matches nothing.

target ICharacter

The character named by the report.

kind PredictedCombatEvents.Kind

Damage or heal.

occurrences int

How many separate hits the report's amount was merged from — CombatEventBroadcast.Occurrences. That many pending predictions are settled, because the caster drew one label per hit while the server sent one message for all of them. Values below one are treated as one.

damageAttribute DamageAttributeTemplate

Damage type named by the report; null for heals and typeless damage. Matched against the type recorded at Predict(ICharacter, ICharacter, int, Kind, DamageAttributeTemplate, float, int) time.

Returns

bool

True when this report was already drawn as a prediction.

Remarks

Matched on SOURCE, target, kind and damage TYPE, oldest first. The source is what makes this a pairing rather than a guess: a combat report is broadcast to everyone observing the victim, so with source ignored any other player's hit on the same target consumed this client's pending entry. Two players on one mob was enough — the other player's real number was swallowed (the caller draws nothing on a match) and this client's own report, arriving to find no pending entry left, was then drawn a second time. The damage type is in the key for the same reason within one source: the server coalesces per (source, kind, type), and this caster can have several streams onto one victim at once — a poison it applied earlier ticks server-side with no prediction here, and with type ignored that DoT report consumed the pending projectile entry, leaving the poison undrawn and the projectile drawn twice.

Deliberately NOT matched on the amount. The two numbers agree whenever the RNG states agree, but a transient divergence would otherwise leave the prediction unmatched and produce the worst outcome available: the predicted number greyed out AND the server's number drawn beside it, for a hit that landed. Trusting the pairing and letting the amount differ is the lesser error.

The caller draws the server's number only when this returns false — that is, only when the report settled NOTHING. A report that settles some but not all of what it claims does not produce a second label: the numbers already on screen are the caster's own predictions of the same hits, and drawing the server's merged total beside them would show the damage twice.

TryRefuse(ICharacter, ICharacter, CombatEventKind, int, DamageAttributeTemplate)

Settles the pending predictions a REFUSAL report stands for: the hits the target turned away, Evade or Immune.

public static bool TryRefuse(ICharacter source, ICharacter target, CombatEventKind reason, int occurrences = 1, DamageAttributeTemplate damageAttribute = null)

Parameters

source ICharacter

The attacker named by the report. A report with none matches nothing.

target ICharacter

The character that refused the hits.

reason CombatEventKind

The refusal kind; anything that is not a refusal matches nothing.

occurrences int

How many hits the report says were refused. Values below one are treated as one.

damageAttribute DamageAttributeTemplate

The refused hits' damage type; null for typeless damage.

Returns

bool

True when at least one prediction was settled as refused.

Remarks

Paired exactly as TryConfirm(ICharacter, ICharacter, Kind, int, DamageAttributeTemplate) pairs — source, target, damage type, oldest first, up to occurrences — against DAMAGE predictions only: a heal is never refused. Each match raises OnPredictionRefused instead of OnPredictionConfirmed, so the number already on screen can become the reason.

As with a confirmation, the caller draws the report itself only when this returns false — nothing was predicted, which is the normal case for an immortal target: the caster's own copy of the flag refused the hit locally and drew nothing, so the word is new.

Events

OnPredicted

Raised when this client predicts a combat number. The display draws it immediately.

public static event Action<long, ICharacter, int, PredictedCombatEvents.Kind, DamageAttributeTemplate> OnPredicted

Event Type

Action<long, ICharacter, int, PredictedCombatEvents.Kind, DamageAttributeTemplate>

Remarks

The long is a handle the display keeps, so a later OnPredictionRejected can name the number to grey out.

OnPredictionConfirmed

Raised when the server's report confirmed a predicted number. Nothing needs redrawing — the number on screen was already right — but the display holds a handle per prediction so it can grey one out later, and without this it would only ever release the handles for predictions that turned out WRONG. A session's worth of correct hits leaked one entry each.

public static event Action<long> OnPredictionConfirmed

Event Type

Action<long>

OnPredictionRefused

Raised when the server reported that the hit a prediction stands for was REFUSED by its target — the second argument is Evade or Immune. The display should replace the number with the reason; like a confirmation, this releases the handle.

public static event Action<long, CombatEventKind> OnPredictionRefused

Event Type

Action<long, CombatEventKind>

OnPredictionRejected

Raised when a predicted number went unconfirmed past the window. The display should mark it invalid rather than deleting it — a number that vanishes reads as a rendering glitch, one that greys out reads as "that did not land".

public static event Action<long> OnPredictionRejected

Event Type

Action<long>

OnPredictionUndone

Raised when a prediction is given up (the server never confirmed it, or refused it): the target's object id, the amount this client moved its health by, the kind, and the target's health-push count when it was predicted.

public static event Action<int, int, PredictedCombatEvents.Kind, int> OnPredictionUndone

Event Type

Action<int, int, PredictedCombatEvents.Kind, int>

Remarks

The label was greyed out and the BAR was left where the prediction put it. A hit the server absorbed with a shield, evaded or refused changes nothing there, so nothing was ever sent to put the bar back, and the caster watched a target sit at a health it did not have until something else moved it. The listener (CharacterDamageController) undoes the amount, unless the server has sent that target's health since, in which case the bar is already the server's.