Class CharacterState
Mutable runtime state for a generic character instance. Tracks identity (via Serenity's CharacterId), lifecycle status, and hit points. Designed for inheritance: specialized character types (e.g., Character) can override lifecycle transitions. Engine-agnostic. Will be migrated to Serenity later.
Inherited Members
Namespace: Serenity.Character.Domain.Entities
Assembly: Serenity.Character.Domain.dll
Syntax
public class CharacterState
Constructors
CharacterState(CharacterId, int)
Creates a new CharacterState in the Spawning status.
Declaration
public CharacterState(CharacterId id, int maxHealth)
Parameters
| Type | Name | Description |
|---|---|---|
| CharacterId | id | The character identity. |
| int | maxHealth | Maximum hit points. |
Properties
Id
Gets the identity of this character.
Declaration
public CharacterId Id { get; protected set; }
Property Value
| Type | Description |
|---|---|
| CharacterId |
MaxHealth
Maximum hit points.
Declaration
public int MaxHealth { get; protected set; }
Property Value
| Type | Description |
|---|---|
| int |
RemainingHealth
Remaining hit points.
Declaration
public int RemainingHealth { get; protected set; }
Property Value
| Type | Description |
|---|---|
| int |
Status
Gets the current lifecycle status.
Declaration
public CharacterStatus Status { get; protected set; }
Property Value
| Type | Description |
|---|---|
| CharacterStatus |
Methods
Activate()
Activates the character — transitions from Spawning to Active.
Declaration
public virtual void Activate()
FinishDeath()
Marks the character as fully dead (after death transition completes).
Declaration
public virtual void FinishDeath()
Reset(CharacterId, int)
Resets the character state for reuse (e.g., returning from a pool). Assigns a new identity and restores hit points to maximum.
Declaration
public virtual void Reset(CharacterId newId, int maxHealth)
Parameters
| Type | Name | Description |
|---|---|---|
| CharacterId | newId | The new identity for the reused character. |
| int | maxHealth | The new maximum hit points. |
TakeHit(int)
Applies damage to this character, reducing HP. Returns true if this damage killed the character (HP reached zero). Only processes hits when the character's status Is(CharacterStatus) Active.
Declaration
public virtual bool TakeHit(int damage = 1)
Parameters
| Type | Name | Description |
|---|---|---|
| int | damage | Damage to apply. Must be >= 1. |
Returns
| Type | Description |
|---|---|
| bool | True if character was killed by this damage. |
ToSnapshot()
Creates an immutable snapshot of the current character state.
Declaration
public virtual CharacterSnapshot ToSnapshot()
Returns
| Type | Description |
|---|---|
| CharacterSnapshot |