public PlayerActor(string playerName, int startingHealth) { _state = new PlayerActorState() { PlayerName = playerName, Health = startingHealth }; ColorConsole.WriteLine($"{_state.PlayerName} created", ConsoleColor.Magenta); Command <HitPlayer>(command => HitPlayer(command)); Command <DisplayStatus>(command => DisplayStatusMessage()); Command <SimulateError>(command => SimulateError()); Recover <PlayerHit>(playerHitEvent => { ColorConsole.WriteLine($"{_state.PlayerName} replaying PlayerHit event {playerHitEvent} from journal", ConsoleColor.Magenta); _state.Health -= playerHitEvent.DamageTaken; }); Recover <SnapshotOffer>(offer => { ColorConsole.WriteLine($"{_state.PlayerName} received SnapshotOffer from snapshot store, updating state", ConsoleColor.Magenta); _state = (PlayerActorState)offer.Snapshot; ColorConsole.WriteLine($"{_state.PlayerName} state {_state} set from snapshot", ConsoleColor.Magenta); }); }
public PlayerActor(string playerName, int health) { _state = new PlayerActorState { PlayerName = playerName, Health = health }; Log.Information("{PlayerName} created", _state.PlayerName); Command <HitPlayer>(msg => HitPlayer(msg)); Command <DisplayStatus>(_ => DisplayPlayerStatus()); Command <SimulateError>(_ => SimulateError()); Recover <PlayerHit>(playerHitEvent => { Log.Information("{PlayerName} replaying {EventType} for {Damage} damage from journal", _state.PlayerName, nameof(PlayerHit), playerHitEvent.DamageTaken); _state.Health -= playerHitEvent.DamageTaken; }); Recover <SnapshotOffer>(offer => { Log.Information("{PlayerName} received SnapshotOffer from snapshot store, updating state", _state.PlayerName); _state = (PlayerActorState)offer.Snapshot; Log.Information("{PlayerName} state {State} set from snapshot", _state.PlayerName, _state); }); }
public PlayerActor(string playerName, int health) { PlayerActorState = new PlayerActorState { PlayerName = playerName, Health = health }; Console.WriteLine($"{PlayerActorState.PlayerName} created"); Command <HitPlayer>(message => HitPlayer(message)); Command <DisplayStatus>(message => DisplayPlayerStatus(message)); Command <SimulateError>(message => SimulateError()); Recover <PlayerHit>(message => { Console.WriteLine($"{PlayerActorState.PlayerName} replaying PlayerHit event from journal"); PlayerActorState.Health -= message.DamageTaken; }); Recover <SnapshotOffer>(offer => { Console.WriteLine($"{PlayerActorState.PlayerName} received SnapshotOffer from snapshot store, updating state"); PlayerActorState = offer.Snapshot as PlayerActorState; Console.WriteLine($"{PlayerActorState.PlayerName} state {PlayerActorState} set from snapshot"); }); }