Пример #1
0
        /// <summary>
        /// send the player all the existing network views
        /// </summary>
        /// <param name="player"></param>
        internal void SendViewInstantiates(Player player)
        {
            CleanupInvalidNetworkViewOwners();

            foreach (var view in NetworkManager.AllViews)
            {
                if (view == null)
                {
                    continue;
                }
                if (!view.OnPlayerEnteredRoom(player))
                {
                    continue;
                }

                var pos = view.GetPosition();
                var rot = view.GetRotation();

                var msg = ConstructInstMessage(view, pos, rot);
                ImplSendToPlayer(player, msg, ReliabilityMode.Ordered);
            }

            try
            {
                PlayerAdded?.Invoke(player);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
        }
 public void OnPlayerAdded(Player player)
 {
     if (PlayerAdded != null)
     {
         PlayerAdded.Invoke(player);
     }
 }
Пример #3
0
        private void addPlayerExecute()
        {
            Player newPlayer = Player.CreateNewPlayer(PlayerName);

            PlayerAdded?.Invoke(newPlayer);
            PlayerName = "";
        }
Пример #4
0
        public MessengerSet(GameHost host, IMessenger serverCommands, IMessenger serverBroadcast, IMessenger localPlayer, string localPlayerName)
        {
            Host            = host;
            ServerCommands  = serverCommands;
            ServerBroadcast = serverBroadcast;
            LocalPlayer     = localPlayer;
            LocalPlayerName = localPlayerName;

            var tmp = new ObservableCollection <IMessenger>();

            tmp.CollectionChanged += (s, e) =>
            {
                if (e.NewItems != null)
                {
                    foreach (IMessenger item in e.NewItems)
                    {
                        PlayerAdded?.Invoke(this, item);
                    }
                }

                if (e.OldItems != null)
                {
                    foreach (IMessenger item in e.OldItems)
                    {
                        PlayerRemoved?.Invoke(this, item);
                    }
                }
            };
            OtherPlayers = tmp;
        }
Пример #5
0
        async void OnSave(object sender, System.EventArgs e)
        {
            var player = BindingContext as Player;

            if (String.IsNullOrWhiteSpace(player.PlayerName))
            {
                await DisplayAlert("Hey!", "Please enter a name", "Okay");

                return;
            }

            if (String.IsNullOrWhiteSpace(player.PlayerNumber))
            {
                await DisplayAlert("Hey!", "Please enter the player's number", "Okay");

                return;
            }

            if (player.ID == 0)
            {
                await _connection.InsertAsync(player);

                PlayerAdded?.Invoke(this, player);
            }
            else
            {
                await _connection.UpdateAsync(player);

                PlayerUpdated?.Invoke(this, player);
            }

            await Navigation.PopAsync();
        }
Пример #6
0
    public void RegisterPlayer(Player player, int fieldSideID)
    {
        if (!_players.Contains(player))
        {
            LogEx.Log <BattleSystem>("Registered player: '{0}'", player.name);

            _players.Add(player);

            fieldSideID = Mathf.Clamp(fieldSideID, 0, _fieldSides.Count - 1);

            player.AssignFieldSide(_fieldSides[fieldSideID]);

            // TEMP!!!
            //RegisterCharacter(player.ActiveCharacter);

            // TEMP!!!
            //player.ActiveCharacter.BattleEntities.ForEach(x => x.Initialize(this));

            if (PlayerAdded != null)
            {
                PlayerAdded.Invoke(player);
            }
        }
        else
        {
            LogEx.LogError <BattleSystem>("Cannot register player '{0}' as they are already registered.", player.name);
        }
    }
Пример #7
0
        // Event Handlers

        void OnConnect(NetworkConnection connection)
        {
            var client = new NetworkClientPlayer(connection, LowestAvailablePlayerID(connection));

            client.Config.PlayerID = client.PlayerID;
            clients[connection]    = client;
            PlayerAdded?.Invoke(client);
        }
Пример #8
0
 public void AddPlayer(Player player)
 {
     PlayerAdded?.Invoke(this, new PlayerEventArgs(player));
     if (!PlayerExists(player.Name))
     {
         characters.Add(player.Name, player);
     }
 }
Пример #9
0
 protected void OnPlayerAdded(string playerName, int playerNumber)
 {
     PlayerAdded?.Invoke(this, new PlayerAddedEventArgs
     {
         PlayerName   = playerName,
         PlayerNumber = playerNumber,
     });
 }
Пример #10
0
        /// <summary>
        ///     Adds a <see cref="PlayerManager" />
        /// </summary>
        /// <param name="netId"></param>
        /// <param name="playerManager"></param>
        public static void AddPlayer(string netId, PlayerManager playerManager)
        {
            string playerId = PlayerIdPrefix + netId;

            playerManager.gameObject.name = playerId;
            Players.Add(playerId, playerManager);

            PlayerAdded?.Invoke(playerId);
            Logger.Debug("Added player {@PlayerId}.", playerId);
        }
        public bool AddCharacter(Character character)
        {
            var success = Characters.TryAdd(character.Id, character);

            if (success)
            {
                PlayerAdded?.Invoke(this, new CharacterArgs(character));
            }
            return(success);
        }
        public bool AddToQueue(Guid playerId)
        {
            var success = PlayerWaitingQueue.AddToQueue(playerId);

            if (success)
            {
                PlayerAdded?.Invoke(this, new EventArgs());
            }

            return(success);
        }
Пример #13
0
        private void OnLobbyNetworkReceived(NetPeer peer, NetDataReader dataReader)
        {
            NetMessage instruction = (NetMessage)dataReader.GetInt();

            switch (instruction)
            {
            case NetMessage.ServerClosed:
                OnServerClosed();
                break;

            case NetMessage.ClientsCount:
                int count = dataReader.GetInt();
                OnClientsCount(count);
                break;

            case NetMessage.AddPlayer:
                PlayerAdded?.Invoke(this, new LobbyPlayerEventArgs()
                {
                    PlayerID        = dataReader.GetString(),
                    ControllerIndex = (PlayerControllerIndex)dataReader.GetInt()
                });
                break;

            case NetMessage.RemovePlayer:
                PlayerRemoved?.Invoke(this, new LobbyPlayerEventArgs()
                {
                    PlayerID = dataReader.GetString()
                });
                break;

            case NetMessage.PrepareToStartGame:
                PreparingGameToStart?.Invoke(this, new LobbyOptionsArgs {
                    PlayersCount = dataReader.GetInt(),
                    Map          = dataReader.GetInt(),
                    Biome        = dataReader.GetInt(),
                });
                break;

            case NetMessage.InstantiateCharacter:
                InstantiateCharacter?.Invoke(this, new LobbyPlayerEventArgs {
                    PlayerID        = dataReader.GetString(),
                    ControllerIndex = (PlayerControllerIndex)dataReader.GetInt(),
                    Type            = (Pj.Type)dataReader.GetInt(),
                    X = dataReader.GetFloat(), Y = dataReader.GetFloat()
                });
                break;

            case NetMessage.StartGame:
                this.SetGameplay();
                GameStarted?.Invoke(this, EventArgs.Empty);
                break;
            }
        }
Пример #14
0
        /// <summary>
        /// send the player all the existing network views
        /// </summary>
        /// <param name="player"></param>
        internal void SendViewInstantiates(Player player)
        {
            CleanupInvalidNetworkViewOwners();

            try
            {
                PlayerAdded?.Invoke(player);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
        }
Пример #15
0
 public void Add(ServerPlayer player)
 {
     lock (Members)
     {
         if (Members.Count == 0)
         {
             Wins   = 0;
             Losses = 0;
         }
         Members.Add(player);
     }
     player.Info.Team = this;
     PlayerAdded?.Invoke(this, this);
 }
Пример #16
0
        public INetworkClient CreateLocalClient()
        {
            // TODO(james7132): Make this dynamic
            var clientToServer  = new LocalInterface();
            var serverInterface = clientToServer.Mirror;
            var serverToClient  = serverInterface.Connection;
            var localClient     = new NetworkClientPlayer(serverToClient, LowestAvailablePlayerID(serverToClient));

            localClient.Config.PlayerID = localClient.PlayerID;
            clients[serverToClient]     = localClient;
            PlayerAdded?.Invoke(localClient);
            AddNetworkInterface(serverInterface);
            return(new NetworkGameClient(clientToServer.Connection));
        }
Пример #17
0
        internal void FinalizePlayerAdd(Player player)
        {
            if (player.Id == 0)
            {
                return;
            }

            //update the slot with the correct player.
            lock (_players)
                _players.Add(player.Id, player);

            try
            {
                PlayerAdded?.Invoke(player);
            }
            catch (Exception e) { Debug.LogException(e); }
        }
Пример #18
0
        /*********
        ** Private methods
        *********/
        private static void OnUpdateTicked(object sender, EventArgs e)
        {
            if (!Context.IsWorldReady)
            {
                return;
            }

            var currentLength = MegaStorageMod.ModHelper.Multiplayer.GetConnectedPlayers().Count();

            if (currentLength > _prevLength)
            {
                PlayerAdded?.Invoke(null, null);
            }
            else if (currentLength < _prevLength)
            {
                PlayerRemoved?.Invoke(null, null);
            }
            _prevLength = currentLength;
        }
Пример #19
0
        public void HandleAddPlayer(NetworkMessage msg)
        {
            MsgAddPlayer ap = msg as MsgAddPlayer;

            if (!PlayerList.ContainsKey(ap.PlayerID))
            {
                if (LocalPlayerID == ap.PlayerID)
                {
                    PlayerList.Add(ap.PlayerID, new LocalPlayer(null));
                }
                else
                {
                    PlayerList.Add(ap.PlayerID, new Player());
                }
            }

            Player player = PlayerList[ap.PlayerID];

            player.PlayerID = ap.PlayerID;

            player.Callsign = ap.Callsign;
            player.Motto    = ap.Motto;

            player.PlayerType = (PlayerTypes)ap.PlayerType;
            player.Team       = ap.Team;
            player.Wins       = ap.Wins;
            player.Losses     = ap.Losses;
            player.TeamKills  = ap.TeamKills;

            if (player.IsLocalPlayer) // hey it's us!
            {
                Me = player as LocalPlayer;
                if (SelfAdded != null)
                {
                    SelfAdded.Invoke(this, player);
                }
            }

            if (PlayerAdded != null)
            {
                PlayerAdded.Invoke(this, player);
            }
        }
Пример #20
0
        public string LoginPlayer(string guestId, string playerName)
        {
            var board = _hostService.GetBoardForGuest(guestId);

            var game = Games.FirstOrDefault(x => x.BoardId == board.Id);

            if (game == null)
            {
                return("Invalid Room Code");
            }
            else if (string.IsNullOrEmpty(playerName))
            {
                return("Name is required.");
            }
            else
            {
                lock (_loginLock)
                {
                    var player = game.Players.FirstOrDefault(x => x.Name == playerName);

                    if (player != null)
                    {
                        return("Name is already taken.");
                    }
                    else if (game.Players.Count < game.MaxPlayers)
                    {
                        game.Players.Add(new Player {
                            Name = playerName
                        });

                        PlayerAdded?.Invoke(this, new GameChangedEventArgs
                        {
                            BoardId     = board.Id,
                            Action      = GameChangedEventActions.PlayerAdded,
                            PlayerIndex = game.Players.Count - 1
                        });
                    }
                }

                return(null);
            }
        }
Пример #21
0
        public bool AddPlayer(LobbyUserExtension playerExt, out string error)
        {
            error = null;

            if (playerExt.CurrentLobby != null)
            {
                error = "You're already in a lobby";
                return(false);
            }

            var username = TryGetUsername(playerExt.Peer);

            if (username == null)
            {
                error = "Invalid username";
                return(false);
            }

            if (Members.ContainsKey(username))
            {
                error = "Already in the lobby";
                return(false);
            }

            if (IsDestroyed)
            {
                error = "Lobby is destroyed";
                return(false);
            }

            if (!IsPlayerAllowed(username, playerExt))
            {
                error = "You're not allowed";
                return(false);
            }

            if (Members.Values.Count >= MaxPlayers)
            {
                error = "Lobby is full";
                return(false);
            }

            if (!Config.AllowJoiningWhenGameIsLive && State != LobbyState.Preparations)
            {
                error = "Game is already in progress";
                return(false);
            }

            // Create an "instance" of the member
            var member = CreateMember(username, playerExt);

            // Add it to a team
            var team = PickTeamForPlayer(member);

            if (team == null)
            {
                error = "Invalid lobby team";
                return(false);
            }

            if (!team.AddMember(member))
            {
                error = "Not allowed to join a team";
                return(false);
            }

            Members[member.Username]           = member;
            MembersByPeerId[playerExt.Peer.Id] = member;

            // Set this lobby as player's current lobby
            playerExt.CurrentLobby = this;

            if (GameMaster == null)
            {
                PickNewGameMaster(false);
            }

            Subscribe(playerExt.Peer);

            playerExt.Peer.Disconnected += OnPeerDisconnected;

            OnPlayerAdded(member);

            if (PlayerAdded != null)
            {
                PlayerAdded.Invoke(member);
            }


            return(true);
        }
Пример #22
0
 public void AddPlayer(Player player)
 {
     _players.Add(player);
     PlayerAdded?.Invoke(player);
 }
Пример #23
0
 public void AddPlayer(PlayerInfo player)
 {
     Players.Add(player);
     PlayerAdded?.Invoke(player);
 }
Пример #24
0
 private void OnPlayerAdded(List <PlayerDto> players)
 {
     PlayerAdded?.Invoke(this, players);
 }
Пример #25
0
 protected virtual void OnPlayerAdded(Player player)
 {
     PlayerAdded?.Invoke(this, player);
     _ghostObjectTimer.Start();
 }
Пример #26
0
 protected virtual void OnPlayerAdded(Player player)
 {
     PlayerAdded?.Invoke(this, player);
 }
Пример #27
0
 internal void RaisePlayerAdded(PlayerState state)
 {
     Logger.Debug($"event {nameof(RaisePlayerAdded)}({state.Player.DisplayName})");
     Core.Logger.Flush();
     PlayerAdded?.Invoke(state);
 }
Пример #28
0
 public void RaisePlayerAddedEvent(Entity entity)
 {
     PlayerAdded?.Invoke(entity);
 }