コード例 #1
0
ファイル: PlayerManager.cs プロジェクト: rjkward/cowabunga
    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;
                }
            }
        }
    }
コード例 #2
0
        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;
            }
        }
コード例 #3
0
        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);
            });
        }
コード例 #4
0
 public static void OnPlayerCreated(Player player)
 {
     if (PlayerCreated != null)
     {
         PlayerCreated.Invoke(player);
     }
 }
コード例 #5
0
        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);
            });
        }
コード例 #6
0
        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);
            });
        }
コード例 #7
0
ファイル: Player.cs プロジェクト: juliofederal/101mngr
 public void Apply(PlayerCreated @event)
 {
     Id          = @event.Id;
     UserName    = @event.UserName;
     Email       = @event.Email;
     CountryCode = @event.CountryCode;
     Version++;
 }
コード例 #8
0
 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
     });
コード例 #9
0
        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);
            });
        }
コード例 #10
0
ファイル: QuizService.cs プロジェクト: GregorBiswanger/QuizeR
        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();
        }
コード例 #11
0
ファイル: LevelObjects.cs プロジェクト: sky-xk-nge/Unturned
        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;
        }
コード例 #12
0
        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);
            }));
        }
コード例 #13
0
        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);
        }
コード例 #14
0
 protected virtual void OnPlayerCreated(PlayerEventArgs e)
 {
     PlayerCreated?.Invoke(this, e);
 }
コード例 #15
0
ファイル: Player.cs プロジェクト: Marebor/DXGame
 public void Apply(PlayerCreated e)
 {
     Id       = e.Id;
     Name     = e.Name;
     Password = e.Password;
 }
コード例 #16
0
 private static void CreatePlayer(PlayerCreated playerEvent)
 {
     Context.ActorOf(Props.Create(() => new PlayerActor(playerEvent.PlayerName, DefaultStartingHealth)), playerEvent.PlayerName);
 }
コード例 #17
0
 public void Apply(PlayerCreated e)
 {
 }
コード例 #18
0
ファイル: GameStarter.cs プロジェクト: Stryse/SquareGame
 //======= Event senders =======//
 protected virtual void OnPlayersCreated(object sender, Player[] players)
 => PlayerCreated?.Invoke(this, new Tuple <Player[], int>(players, fieldSize));