Class HittableState
Mutable runtime state for a hittable world object (props, destructibles, reactive scenery). Tracks an optional health pool and reacts to hits with a HitOutcome.
Inherited Members
Namespace: Serenity.Hittable.Domain.Entities
Assembly: Serenity.Hittable.Domain.dll
Syntax
public class HittableState
Remarks
This aggregate is exclusively for NON-Character world objects. Characters own their own health lifecycle via CharacterState (RemainingHealth / TakeHit / death) in the Character module and must never be registered as a hittable.
Constructors
HittableState(HittableId, int)
Creates a new hittable state.
Declaration
public HittableState(HittableId id, int maxHealth)
Parameters
| Type | Name | Description |
|---|---|---|
| HittableId | id | The hittable identity. |
| int | maxHealth | The maximum health. A negative value makes the hittable indestructible (hit-reactive, never breaks). Zero starts the hittable already at zero health: it survives a hit that deals no damage, but is destroyed by the first hit that deals positive damage. |
Properties
Id
The hittable identity.
Declaration
public HittableId Id { get; }
Property Value
| Type | Description |
|---|---|
| HittableId |
IsDestroyed
True once this hittable has been destroyed.
Declaration
public bool IsDestroyed { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsIndestructible
True when this hittable can never be destroyed by hits (still reacts to them).
Declaration
public bool IsIndestructible { get; }
Property Value
| Type | Description |
|---|---|
| bool |
MaxHealth
The configured maximum health. A negative value means the hittable is indestructible, and is normalized to -1 for a stable, comparable sentinel.
Declaration
public int MaxHealth { get; }
Property Value
| Type | Description |
|---|---|
| int |
RemainingHealth
The current remaining health, clamped at 0. Always -1 when IsIndestructible.
Declaration
public int RemainingHealth { get; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
Reset()
Restores full health and un-destroys the hittable.
Declaration
public virtual void Reset()
TakeHit(int)
Applies a hit and returns its outcome.
Declaration
public virtual HitOutcome TakeHit(int damage = 1)
Parameters
| Type | Name | Description |
|---|---|---|
| int | damage | The damage to apply. Defaults to 1. Non-positive values are treated as 0 (no health change) and report Damaged as long as the hittable is not already destroyed - a "no-op hit" still reaches a live object, it just does not affect it. |
Returns
| Type | Description |
|---|---|
| HitOutcome | Ignored if already destroyed (no state change); Damaged if indestructible, or if damage was applied but health remains above zero, or if damage was non-positive; Destroyed exactly once, on the hit that reduces remaining health to zero. |
ToSnapshot()
Creates an immutable snapshot of the current hittable state.
Declaration
public virtual HittableSnapshot ToSnapshot()
Returns
| Type | Description |
|---|---|
| HittableSnapshot |