Module fight

Source
Expand description

Native Rust fight logic.

These are the pure-Rust fight primitives (attack, try_cast, spawn_wave, …) used by the native combat ports in crate::behaviors. Results are emitted through the FightSink abstraction and effect reactions through the EffectCb abstraction; the shipped reactions live in crate::mechanics::effect_cb::OverlordEffectCb.

Structs§

AttackParams
Typed form of the attack params.
NativeSink
Sink that collects fight results as typed values for native callers. Mirrors start_behaviors fill casts.
NoopEffectCb
Effect callback that does nothing — for callers that don’t want effect reactions dispatched.
SpellHealParams
Typed form of the spell_heal params.
WaveEntityPower
WaveFightData
Typed form of the fight_data prepare-fight blob fed to spawn_wave.
WaveSpawn

Traits§

EffectCb
Invokes an effect’s on_apply / on_change reaction.
FightSink
Where a fight method emits its results.

Functions§

add_entity_attr
Native: ctx.add_entity_attr(entity, attr, value) — push an IncrAttribute
add_entity_stat_mod
Native: ctx.add_entity_stat_mod(entity, stat, value) — push an IncrAttribute on "{stat}.mod" by value. Mirrors the engine’s add_entity_stat_mod (which lowers to add_entity_attr(entity, "{stat}.mod", value)); used by the native effect-callback dispatcher to replicate the
advance_entity
Native: move entity toward the enemy line in a single multi-cell run (one StartMove instead of one per cell — every per-cell seam quantizes to the 100ms game tick and gives the client a chance to stutter).
apply_entity_effect
Native: apply effect_code to target for duration_seconds (converted to ticks). Effect on_apply reactions are dispatched through effects.
apply_entity_over_time_effect
Native: apply a damage-/heal-over-time effect (kind = "dot" / "hot"), splitting amount over 5 ticks. No effect callbacks, no RNG.
attack
Native: perform an attack from caster on target. Returns the floored damage dealt (None => the no-damage paths: evasion, or no power given). RNG is consumed in the exact original order: evasion, counterattack_chance, deceit (+ randint(0,2) if it lands), crit_chance, then damage_entity’s block roll.
cast
Native: queue casts attack actions for caster against valid_targets. Consumes multicast_chance from rng, then (per cast after the first, when there are multiple targets) a randint for target selection. _ability is unused, matching the original signature.
change_entity_effect_duration
Native: add duration ticks of effect_code to target (capped at the effect’s max_duration_ticks), emitting EntityApplyEffect on first application and dispatching the effect’s on_apply reaction.
damage_entity
Native: apply raw_dmg to entity (armor, shield, block roll, received damage multiplier). Returns the floored post-mitigation damage value; None only for the no-damage early-outs (godmode / a missing received_damage base value — a content-extraction regression), which short-circuit before the block roll. When a shield fully absorbs the hit the function still returns Some(floored_damage) (and emits the shield decrement) — this value drives attack’s return / lifesteal, so it must not be None or the caller would discard the shield event. Consumes one block stat_throw from rng when it is reached.
entity_run
Native: emit a run action moving entity to to (no-op if speed is 0 or the move covers no distance).
get_entity_stat
ctx.get_entity_stat(entity, "armor") — applies attribute base value (from content_raw), additive bonus, and multiplicative mod (+10000 == +1.0).
heal_entity
Native: heal entity, capping at its missing HP. Returns the applied heal (None if no heal was applied).
init_fight
Native: emit the per-entity init events for a fight (regen effect, low-chapter effect, party power adjustment, dungeon/boss talent attack mods). No RNG, no effect callbacks. fight supplies player/party ids + the entity roster + party_adjusted_power; reads talent levels / chapter from state.
on_cast
Native: the ability on_cast hook. Rolls bravery; on success applies a random buff (protection/empower). Consumes bravery then (if it lands) a randint(0,2) from rng. Effect on_apply reactions dispatch via effects.
remove_entity_effect
Native: remove all stacks of effect_code from target, dispatching the effect’s on_change reaction with (new_stacks=0, old_stacks=current).
screen_shake
Native: emit a screen_shake visual event.
set_entity_attr
Native: ctx.set_entity_attr(entity, attr, value) — push an IncrAttribute that moves the attr TO value (delta = round(value - current)). Emitted
spawn_wave
Native: the prepare_fight interpreter. Computes normalised enemy stats from the chapter power curve + the typed wave blob, then emits spawn events for the current wave. RNG is consumed once per spawned enemy (the spawn-entity uuid), in iteration order — identical to the original. fight supplies current_wave + the live entities (for the multi-wave x-offset).
spell_heal
Native: heal target from caster’s attack stat. Returns the applied heal (None when no heal). Consumes crit_chance from rng (unless is_crit is forced), then heal_entity’s path (no RNG).
stat_throw
touch_enemy
Native: returns whether target is touched (i.e. did NOT evade). Balance v2: dodge probability follows the DR curve ev/(ev+K_DODGE) (asymptote < 100%, no 100%-dodge cliff) instead of the old linear ev/10000. Consumes exactly one rng draw iff the target has positive evasion rating — matching the old stat_throw’s “draw only when stat > 0” so draw-count is preserved.
try_cast
Native: attempt to cast ability_id from caster. Picks valid targets and delegates to cast; if there are none and the caster is not static, advances toward the enemy. casts is the natural cast count (default 1). Consumes RNG only via cast / advance_entity.
wave_data_from_config
Convert the typed config mirror (prepare_fight_waves) into the runtime WaveFightData consumed by spawn_wave. This is the native data source for the prepare_fight interpreter.