private void CreateNewPlayers(InputManager input) { List <KeyCode> keysUp = input.KeyUpList; for (int i = 0; i < keysUp.Count; i++) { KeyCode key = keysUp[i]; Rob_CharacterController player; if (_playerDict.TryGetValue(key, out player)) { player.PickRandomSkin(); } else { player = CreateNewPlayer(key); if (PlayerCreated != null) { PlayerCreated.Invoke(key, player, _playerList.AsReadOnly()); } if (!_enoughInvoked && _playerList.Count > 1 && EnoughPlayers != null) { EnoughPlayers.Invoke(); _enoughInvoked = true; } } } }
private void OnReceivedPacket(Packet packet) { // Record.Log($"Receiving packet: {packet.TypeCase}"); switch (packet.TypeCase) { case Packet.TypeOneofCase.UpdateObject: ObjectUpdated?.Invoke(packet.UpdateObject); break; case Packet.TypeOneofCase.UpdatePosition: ObjectMoved?.Invoke(packet.UpdatePosition); break; case Packet.TypeOneofCase.UpdateRotation: ObjectRotated?.Invoke(packet.UpdateRotation); break; case Packet.TypeOneofCase.DestroyObject: ObjectDestroyed?.Invoke(packet.DestroyObject); break; case Packet.TypeOneofCase.CreatePlayer: PlayerCreated?.Invoke(packet.CreatePlayer); Record.Log($"Creating player {packet.CreatePlayer}"); break; default: // TODO: https://docs.microsoft.com/en-us/dotnet/standard/exceptions/how-to-create-user-defined-exceptions Record.Log($"Unimplemented packet handler ! {packet.TypeCase}", LogLevel.Error); break; } }
public PlayerCoordinatorActor() { Command <CreatePlayer>(message => { WriteLine($"PlayerCoordinatorActor received CreatePlayer command for {message.PlayerName}"); var @event = new PlayerCreated(message.PlayerName); Persist(@event, createPlayerEvent => { WriteLine($"PlayerCoordinatorActor persisted a CreatePlayerMessage for {createPlayerEvent.PlayerName}"); Context.ActorOf( Props.Create(() => new PlayerActor(createPlayerEvent.PlayerName, DefaultStartingHealth)), createPlayerEvent.PlayerName); }); }); Recover <PlayerCreated>(createPlayerEvent => { WriteLine($"PlayerCoordinatorActor replaying CreatePlayerMessage for {createPlayerEvent.PlayerName}"); Context.ActorOf( Props.Create(() => new PlayerActor(createPlayerEvent.PlayerName, DefaultStartingHealth)), createPlayerEvent.PlayerName); }); }
public static void OnPlayerCreated(Player player) { if (PlayerCreated != null) { PlayerCreated.Invoke(player); } }
public PlayerCoordinatorActor() { Command <CreatePlayer>(command => { DisplayHelper.WriteLine($"PlayerCoordinatorActor received CreatePlayer command for {command.PlayerName}"); var @event = new PlayerCreated(command.PlayerName); Persist(@event, playerCreatedEvent => { DisplayHelper.WriteLine($"PlayerCoordinatorActor persisted a PlayerCreated event command for {playerCreatedEvent.PlayerName}"); Context.ActorOf( Props.Create(() => new PlayerActor(playerCreatedEvent.PlayerName, DefaultStartingHealth)), playerCreatedEvent.PlayerName); }); }); Recover <PlayerCreated>(playerCreatedEvent => { DisplayHelper.WriteLine($"PlayerCoordinatorActor replaying a PlayerCreated event command for {playerCreatedEvent.PlayerName}"); Context.ActorOf( Props.Create(() => new PlayerActor(playerCreatedEvent.PlayerName, DefaultStartingHealth)), playerCreatedEvent.PlayerName); }); }
public PlayerCoordinatorActor() { Command <CreatePlayer>(command => { Log.Information("Received {CommandType} for {PlayerName}", nameof(CreatePlayer), command.PlayerName); var @event = new PlayerCreated(command.PlayerName); Persist(@event, playerCreatedEvent => { Log.Information("Persisted a {EventType} for {PlayerName}", nameof(PlayerCreated), playerCreatedEvent.PlayerName); Context.ActorOf(Props.Create(() => new PlayerActor(playerCreatedEvent.PlayerName, DefaultStartingHealth)), playerCreatedEvent.PlayerName); }); }); Recover <PlayerCreated>(playerCreatedEvent => { Log.Information("Replaying {EventType} for {PlayerName}", nameof(PlayerCreated), playerCreatedEvent.PlayerName); Context.ActorOf(Props.Create(() => new PlayerActor(playerCreatedEvent.PlayerName, DefaultStartingHealth)), playerCreatedEvent.PlayerName); }); }
public void Apply(PlayerCreated @event) { Id = @event.Id; UserName = @event.UserName; Email = @event.Email; CountryCode = @event.CountryCode; Version++; }
public override EntityId GetEntityId(object instance) { return(instance switch { (TenantId t, PlayerId p) => GetIdForPlayer(t, p), Player p => GetIdForPlayer(p.Tenant, p.Id), PlayerDto dto => GetIdForPlayer(dto.Tenant, dto.Id), TestPlayerDto test => GetIdForPlayer(base.CurrentTenant, test.Id), PlayerCreated pce => GetIdForPlayer(pce.TenantId, pce.PlayerId), PlayerNameCorrected pnce => GetIdForPlayer(pnce.TenantId, pnce.PlayerId), CorrectName.Request cnr => GetIdForPlayer(base.CurrentTenant, cnr.PlayerId), _ => null });
public PlayerCoordinatorActor() { Command <CreatePlayer>(command => { ColorConsole.WriteLine($"{ActorPaths.PlayerCoordinatorActor.Name} received CreatePlayer command for {command.PlayerName}", ConsoleColor.Cyan); var @event = new PlayerCreated(command.PlayerName); Persist(@event, playerCreatedEvent => { ColorConsole.WriteLine($"{ActorPaths.PlayerCoordinatorActor.Name} persisted a PlayerCreated event for {playerCreatedEvent.PlayerName}", ConsoleColor.Cyan); Context.ActorOf(Props.Create(() => new PlayerActor(playerCreatedEvent.PlayerName, DefaultStartingHealth)), playerCreatedEvent.PlayerName); }); }); Recover <PlayerCreated>(playerCreatedEvent => { ColorConsole.WriteLine($"{ActorPaths.PlayerCoordinatorActor.Name} replaying a PlayerCreated event for {playerCreatedEvent.PlayerName} from journal", ConsoleColor.Cyan); Context.ActorOf(Props.Create(() => new PlayerActor(playerCreatedEvent.PlayerName, DefaultStartingHealth)), playerCreatedEvent.PlayerName); }); }
public async Task Connect() { _hubConnection = new HubConnectionBuilder().WithUrl(_hubUri).Build(); _hubConnection.On(GameEvents.GameSessionStarted, () => GameSessionStarted?.Invoke()); _hubConnection.On <bool>(nameof(IsSessionOpen), (isOpen) => IsSessionOpen?.Invoke(isOpen)); _hubConnection.On(GameEvents.PlayerCreated, () => PlayerCreated?.Invoke()); _hubConnection.On <ICollection <string> >(nameof(IncomingPlayers), (players) => IncomingPlayers?.Invoke(players)); _hubConnection.On(GameEvents.GameStarted, () => GameStarted?.Invoke()); _hubConnection.On <int>(GameEvents.TimeElapsed, countDownSeconds => TimeElapsed?.Invoke(countDownSeconds)); _hubConnection.On(GameEvents.GameStopped, () => GameStopped?.Invoke()); _hubConnection.On <int>(GameEvents.RightAnswer, newScore => SentRightAnswer?.Invoke(newScore)); _hubConnection.On <int>(GameEvents.WrongAnswer, newScore => SentWrongAnswer?.Invoke(newScore)); _hubConnection.On(GameEvents.RoundEnded, () => RoundEnded?.Invoke()); _hubConnection.On <string>(GameEvents.Question, question => QuestionSent?.Invoke(question)); _hubConnection.On <AnswerAndPlayers>(GameEvents.AnswerAndPlayers, answerAndPlayers => GotAnswerAndPlayers?.Invoke(answerAndPlayers)); _hubConnection.On(GameEvents.NextRoundStarted, () => NextRoundStarted?.Invoke()); await _hubConnection.StartAsync(); }
public void Start() { Delegate onPlayerCreated = Player.onPlayerCreated; if (LevelObjects.< > f__mg$cache3 == null) { LevelObjects.< > f__mg$cache3 = new PlayerCreated(LevelObjects.onPlayerCreated); } Player.onPlayerCreated = (PlayerCreated)Delegate.Combine(onPlayerCreated, LevelObjects.< > f__mg$cache3); if (LevelObjects.< > f__mg$cache4 == null) { LevelObjects.< > f__mg$cache4 = new EditorAreaRegisteredHandler(LevelObjects.handleEditorAreaRegistered); } EditorArea.registered += LevelObjects.< > f__mg$cache4; if (LevelObjects.< > f__mg$cache5 == null) { LevelObjects.< > f__mg$cache5 = new LevelHierarchyReady(LevelObjects.handleLevelHierarchyReady); } LevelHierarchy.ready += LevelObjects.< > f__mg$cache5; }
public PlayerCoordinatorActor() { Command <CreatePlayer>(command => { Console.WriteLine($"PlayerCoordinatorActor received CreatePlayer for {command.PlayerName}"); var eventReceived = new PlayerCreated(command.PlayerName); Persist(eventReceived, playerCreatedEvent => { Console.WriteLine($"PlayerCoordinatorActor persisted a PlayerCreated for {playerCreatedEvent.PlayerName}"); CreatePlayer(playerCreatedEvent); }); }); Recover <PlayerCreated>((playerCreatedEvent => { Console.WriteLine($"PlayerCoordinator replaying a PlayerCreated {playerCreatedEvent} from journal"); CreatePlayer(playerCreatedEvent); })); }
public Player CreatePlayer(Guid playerId, string username, PlayerPermissions permissions = PlayerPermissions.Standard, PlayerState state = PlayerState.ConnectedUnauthenticated) { if (connectedPlayers.Values.Any(p => p.Name == username)) { throw new UsernameTakenException(); } Player player = new Player(playerId, username, permissions, state); connectedPlayers.Add(playerId, player); Console.WriteLine($"Player created: {playerId}"); PlayerJoinedPacket playerJoinedPacket = new PlayerJoinedPacket(player); server.SendPacketToAllExcept(playerJoinedPacket, playerId); PlayerEventArgs playerEventArgs = new PlayerEventArgs(playerId); PlayerCreated?.Invoke(this, playerEventArgs); return(player); }
protected virtual void OnPlayerCreated(PlayerEventArgs e) { PlayerCreated?.Invoke(this, e); }
public void Apply(PlayerCreated e) { Id = e.Id; Name = e.Name; Password = e.Password; }
private static void CreatePlayer(PlayerCreated playerEvent) { Context.ActorOf(Props.Create(() => new PlayerActor(playerEvent.PlayerName, DefaultStartingHealth)), playerEvent.PlayerName); }
public void Apply(PlayerCreated e) { }
//======= Event senders =======// protected virtual void OnPlayersCreated(object sender, Player[] players) => PlayerCreated?.Invoke(this, new Tuple <Player[], int>(players, fieldSize));