예제 #1
0
        private void Bytecode_SetClientName(string param, Player exec)
        {
            if (Players.Contains(exec))
            {
                string newname      = param + "{0}";
                string lastname     = param;
                int    name_counter = 0;
                foreach (Player name in Players)
                {
                    if (name.PlayerName == lastname) //Don't allow duplicate names, add a number to them.
                    {
                        lastname = string.Format(newname, name_counter);
                        name_counter++;
                    }
                }

                if (name_counter != 0)
                {
                    newname = string.Format(newname, name_counter);
                }
                else
                {
                    newname = param;
                }

                exec.PlayerName = newname;
                //PlayerNames.Add(newname);
                BroadcastInstruction(BoggleInstructions.PLAYER_JOINED, newname);
            }
        }
예제 #2
0
 public void RemovePlayer(Player player)
 {
     if (Players.Contains(player))
     {
         Players.Remove(player);
     }
 }
예제 #3
0
 private void Bytecode_ClientClickReady(Player exec)
 {
     if (Players.Contains(exec))
     {
         exec.Ready = true;
     }
 }
예제 #4
0
        public virtual void AddPlayer(Mobile player)
        {
            if (Open && !Players.Contains(player))
            {
                if (((PlayerMobile)player).CurrentEvent != null)
                {
                    throw new EventException("The player " + player.Name + " is already in an event");
                }
                m_Players.Add(player);
            }
            if (GiveSupplies && !m_PlayerSupplies.ContainsKey((PlayerMobile)player))
            {
                GiveSuppliesToPlayer(player);
            }
            if (Running)
            {
                ((PlayerMobile)player).CurrentEvent = this;

                player.LogoutLocation = Lobby;
                player.LogoutMap      = LobbyMap;

                player.Hits    = player.HitsMax;
                player.Mana    = player.ManaMax;
                player.Stam    = player.StamMax;
                player.Blessed = false;
            }
            else
            {
                player.Blessed = true;
            }
            SendPlayerGumps();
        }
예제 #5
0
 public void Put(NFLPlayer player)
 {
     if (!Players.Contains(player))
     {
         Players.Add(player);
     }
 }
예제 #6
0
 public void removePlayer(ConnectedPlayer player)
 {
     if (Players.Contains(player))
     {
         Players.Remove(player);
     }
 }
예제 #7
0
 public void RemovePlayerFromList(Player.PlayerInfo obj)
 {
     if (players.Contains(obj))
     {
         players.Remove(obj);
     }
 }
예제 #8
0
        public void RollAndMove(Player player)
        {
            if (!Players.Contains(player))
            {
                throw new ArgumentException($"This player is not in the game: { player.Name }");
            }

            if (player.Token == null)
            {
                throw new ArgumentException($"This player has no token: { player.Name }");
            }

            if (!Board.Tokens.Any(t => t == player.Token))
            {
                throw new ArgumentException($"This player's token is not on the board: { player.Name }");
            }

            player.Roll();

            if (player.Token.Position + player.Dice.LastNumber <= Board.EndPosition)
            {
                Board.MoveToken(player.Token, player.Dice.LastNumber.Value);

                if (Winner == null && player.Token.Position == Board.EndPosition)
                {
                    Winner = player;
                }
            }

            LastPlayer = player;
        }
예제 #9
0
        internal void PlaceWager(BlackjackGamePlayer player, double amount)
        {
            if (!Players.Contains(player))
            {
                throw new InvalidOperationException("'player' is null or invalid");
            }

            if (player.IsLive)
            {
                throw new InvalidOperationException("Player is in live round");
            }

            if (RoundPlayersQueuedForNextRound.Any(a => a.Player.Id == player.Id))
            {
                throw new InvalidOperationException();
            }

            if (amount > player.Account.Balance)
            {
                throw new InvalidOperationException("Insufficient funds");
            }

            if (amount < MinWager || amount > MaxWager)
            {
                throw new InvalidOperationException("Player wager is out of range");
            }

            player.Account.Debit(amount);
            RoundPlayersQueuedForNextRound.Add(new BlackjackGameRoundPlayer(player, amount));
        }
예제 #10
0
 /// <summary>
 /// <para>This accepts a network connection and adds it to the server.</para>
 /// <para>This connection will use the callbacks registered with the server.</para>
 /// </summary>
 /// <param name="player">Network connection to add.</param>
 public void AddConnection(INetworkPlayer player)
 {
     if (!Players.Contains(player))
     {
         connections.Add(player.Connection, player);
     }
 }
예제 #11
0
        /// <summary>
        /// Removes the participant.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="participant">The participant.</param>
        private void RemoveParticipant <T>(T participant)
        {
            if (participant != null)
            {
                if (participant is Player)
                {
                    var player = participant as Player;

                    if (Players != null && Players.Contains(player))
                    {
                        Players.Remove(player);
                    }
                }
                else if (participant is Referee)
                {
                    var referee = participant as Referee;

                    if (Referees != null && Referees.Contains(referee))
                    {
                        Referees.Remove(referee);
                    }
                }
                else if (participant is GameMaster)
                {
                    GameMaster = null;
                }
            }
        }
예제 #12
0
        public override void OnRunning()
        {
            for (int index = 0; index < RedTeam.Count; index++)
            {
                if (!Players.Contains(RedTeam[index]))
                {
                    if (_blueFlagHolder == RedTeam[index])
                    {
                        _blueFlagHolder = null;
                        SendMessageToAllPlayers($"{RedTeam[index].Name}'s flag has dropped.");
                    }
                    RedTeam.Remove(RedTeam[index]);
                    index--;
                }
            }

            for (int index = 0; index < BlueTeam.Count; index++)
            {
                if (!Players.Contains(BlueTeam[index]))
                {
                    if (_redFlagHolder == BlueTeam[index])
                    {
                        _redFlagHolder = null;
                        SendMessageToAllPlayers($"{BlueTeam[index].Name}'s flag has dropped.");
                    }
                    BlueTeam.Remove(BlueTeam[index]);
                    index--;
                }
            }

            _scoreboardTick++;
            if (_scoreboardTick / 60 == 1)
            {
                string teamWinning = _redScore > _blueScore ? "Red Team is winning!" : "Blue Team is winning!";
                if (_redScore == _blueScore)
                {
                    teamWinning = "Red and Blue are equal!";
                }
                string bodyMessage = $"{teamWinning}\n" +
                                     $"Red Players: {RedTeam.Count}\n" +
                                     $"Blue Players: {BlueTeam.Count}\n" +
                                     $"Score: {_scoreText}";

                if (_redFlagHolder != null)
                {
                    bodyMessage += $"\n{_redFlagHolder.Name} has the red flag.";
                }

                if (_blueFlagHolder != null)
                {
                    bodyMessage += $"\n{_blueFlagHolder.Name} has the blue flag.";
                }

                foreach (var player in Players)
                {
                    player.DisplayInterface("Capture The Flag Score", bodyMessage);
                }
                _scoreboardTick = 0;
            }
        }
예제 #13
0
        /// <summary>
        /// Allow the user to enter a room from a list as a spectator.
        /// </summary>
        /// <param name="room">to enter</param>
        /// <returns>
        /// Session ID of the new player for this user, for the user to store as a cookie
        /// </returns>
        /// <see cref="https://docs.google.com/document/d/1OTee6BGDWK2usL53jdoeBOI-1Jh8wyNejbQ0ZroUhcA/edit#heading=h.tzy1eb1jifgr"/>
        public Player EnterRoom(Room room)
        {
            // check that the user doesn't have already a player in the room
            if (Players.Count > 0 && room.Players.Count > 0)
            {
                var result = from player in room.Players
                             where Players.Contains(player, new Utility.AddressComparer <Player>())
                             select player;

                if (result.Count() > 0)
                {
                    throw new RoomRulesException(
                              string.Format("the user already play this room: {0} with player nickname: {1}",
                                            room.Preferences.Name, result.First().Nickname));
                }
            }

            // entering the room
            var freshPlayer = gameCenter.EnterRoom(room);

            // logging
            logger.Log(string.Format("User {0} has player {1}", UserName, freshPlayer.GetHashCode()),
                       this, "Medium");

            //registering to an event: the player got the turn
            freshPlayer.TurnChanged += ChoosePlayMove;

            //Adding the player to players collection
            Players.Add(freshPlayer);

            return(freshPlayer);
        }
예제 #14
0
        public override void OnPlayerSpawn(Player player)
        {
            if (Players.Contains(player))
            {
                return;
            }

            player.SetModel("models/citizen/citizen.vmdl");

            player.Controller = new WalkController();
            player.Camera     = new FirstPersonCamera();

            player.EnableAllCollisions       = true;
            player.EnableDrawing             = true;
            player.EnableHideInFirstPerson   = true;
            player.EnableShadowInFirstPerson = true;

            if (Rand.Int(1, 2) == 1 && !HiddenChoosen)
            {
                player.Team   = Game.HiddenTeam;
                HiddenChoosen = true;
            }
            else
            {
                player.Team = Game.MilitaryTeam;
            }

            player.ClearAmmo();
            player.Inventory.DeleteContents();

            AddPlayer(player);

            base.OnPlayerSpawn(player);
        }
예제 #15
0
 public void RemovePlayer(string playerId)
 {
     if (Players.Contains(playerId))
     {
         Players.Remove(playerId);
     }
 }
 void SelectFirstPlayerIfSelectedPlayerIsNotAtTheTableAnymore()
 {
     if (!Players.Contains(SelectedPlayer))
     {
         SelectedPlayer = Players.First();
     }
 }
예제 #17
0
        public Game(string name, IEnumerable <Player> players, Player currentPlayer = null)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException("This is not a valid player name", nameof(name));
            }

            Name = name;

            Players = players.ToArray();

            if (Players.Length < 2)
            {
                throw new ArgumentException("A game must contain at least 2 players");
            }

            currentPlayer = currentPlayer ?? players.First();

            if (!Players.Contains(currentPlayer))
            {
                throw new ArgumentException($"Player {currentPlayer} is not part of Game {name}", nameof(currentPlayer));
            }

            CurrentPlayer = currentPlayer;
        }
예제 #18
0
        private void Start()
        {
            if (!isServer)
            {
                return;
            }

            var connected_players = FindObjectsOfType <PlayerBehaviour>().ToList();

            connected_players.ForEach(player =>
            {
                if (!Players.Contains(player))
                {
                    Players.Add(player);
                }
            });


            OriginalPreStormTimer = PreStormTimer;
            OriginalStormPosition = Storm.position;
            OriginalStormRotation = Storm.rotation;

            StormPosition      = Storm.position;
            StormRotation      = Storm.rotation;
            TotalStormDistance = Vector3.Distance(StormPosition, Finish.position);
        }
예제 #19
0
        /// <summary>
        /// Fetches the player previous in the turn order before a given player.
        /// </summary>
        /// <param name="player">The player being compared to.</param>
        /// <returns>The previous active player.</returns>
        /// <exception cref="ArgumentException">The given player is not part of this game.</exception>
        /// <exception cref="InvalidOperationException">There is only one player left in the game.</exception>
        public Player PlayerBefore(Player player)
        {
            if (!Players.Contains(player))
            {
                throw new ArgumentException(string.Format("{0} is not part of this game!", player.Name));
            }
            else
            {
                int index = Players.IndexOf(player);
                do
                {
                    // Move to previous index
                    if (index == 0)
                    {
                        index = Players.Count - 1;
                    }
                    else
                    {
                        index--;
                    }

                    // Return if this player is active (skipping over those that aren't)
                    if (Players[index].IsActive)
                    {
                        return(Players[index]);
                    }
                } while (index != Players.IndexOf(player));
                // If we looped all the way around back to the original player, then they're clearly the only person still in the game!
                throw new InvalidOperationException(string.Format("{0} is the only player still in the game...", player.Name)); // replace with "Game.End" event?
            }
        }
 public void AddPlayer(Player player)
 {
     if (!Players.Contains(player))
     {
         Players.Add(player);
     }
 }
예제 #21
0
        public bool AddPlayer(Player p)
        {
            if (Players.Contains(p))
            {
                Player pp = GetPlayer(p.Name);
                if (pp != null)
                {
                    if (pp.IsAvailable)
                    {
                        return(false);
                    }
                    else
                    {
                        RemovePlayer(pp.Name);
                    }
                }
            }

            Locker.EnterWriteLock();
            try
            {
                Players.Add(p);
            }
            finally
            {
                Locker.ExitWriteLock();
            }

            AddAction(p, String.Format("{0}#{1}", "new_player", p.Name));

            return(true);
        }
예제 #22
0
 public void AddPlayer(PlayerControl player)
 {
     if (Players.Contains(player))
     {
         return;
     }
     Players.Add(player);
 }
예제 #23
0
        /// <summary>
        /// Send a frame to a specific player
        /// </summary>
        /// <param name="frame">The frame to send to that specific player</param>
        /// <param name="targetPlayer">The specific player to receive the frame</param>
        public void SendToPlayer(FrameStream frame, NetworkingPlayer targetPlayer)
        {
            if (frame.Receivers == Receivers.AllBuffered || frame.Receivers == Receivers.OthersBuffered)
            {
                bufferedMessages.Add(frame);
            }

            lock (Players)
            {
                if (Players.Contains(targetPlayer))
                {
                    NetworkingPlayer player = Players[Players.IndexOf(targetPlayer)];
                    if (!player.Accepted && !player.PendingAccepted)
                    {
                        return;
                    }

                    if (player == frame.Sender)
                    {
                        // Don't send a message to the sending player if it was meant for others
                        if (frame.Receivers == Receivers.Others || frame.Receivers == Receivers.OthersBuffered || frame.Receivers == Receivers.OthersProximity || frame.Receivers == Receivers.OthersProximityGrid)
                        {
                            return;
                        }
                    }

                    // Check to see if the request is based on proximity
                    if (frame.Receivers == Receivers.AllProximity || frame.Receivers == Receivers.OthersProximity)
                    {
                        // If the target player is not in the same proximity zone as the sender
                        // then it should not be sent to that player
                        if (player.ProximityLocation.DistanceSquared(frame.Sender.ProximityLocation) > ProximityDistance * ProximityDistance)
                        {
                            return;
                        }
                    }

                    if (frame.Receivers == Receivers.AllProximityGrid || frame.Receivers == Receivers.OthersProximityGrid)
                    {
                        // If the target player is not in the same proximity zone as the sender
                        // then it should not be sent to that player
                        if (player.gridPosition.IsSameOrNeighbourCell(frame.Sender.gridPosition))
                        {
                            return;
                        }
                    }

                    try
                    {
                        Send(player.TcpClientHandle, frame);
                    }
                    catch
                    {
                        Disconnect(player, true);
                    }
                }
            }
        }
예제 #24
0
 public void AddPlayer(string player)
 {
     if (Players.Contains(player))
     {
         return;
     }
     Players.Add(player);
     Update();
 }
예제 #25
0
        public void FillMMR(Game game)
        {
            int autoCloseSec = App.CustomConfigurationSettings.MMRAutoCloseTime;

            if (autoCloseSec > 0)
            {
                _eventAggregator.PublishOnUIThread(new InvokeScriptMessage
                {
                    ScriptName = "setAutoCloseSeconds",
                    Args       = new[] { autoCloseSec.ToString() }
                }, "MMRChanel");
            }

            _eventAggregator.PublishOnUIThread(new InvokeScriptMessage
            {
                ScriptName = "setLanguageForMessage",
                Args       = new[] { App.CustomConfigurationSettings.LanguageForMessage }
            }, "MMRChanel");

            // 取得地区ID
            var regionId = ((int)game.Region).ToString();
            // 玩家BattleTags
            var battleTags = string.Join("|", game.Players
                                         .Select(p => p.Tag + "#" + p.SelectedHero));

            Players = game.Players.Select(p => p.Tag).ToList();
            string defaultPlayer = Players.First();

            if (App.UserDataSettings.PlayerTags.Any(p => Players.Contains(p)))
            {
                defaultPlayer = App.UserDataSettings.PlayerTags.First(p => Players.Contains(p));
                App.UserDataSettings.PlayerTags.Remove(defaultPlayer);
                App.UserDataSettings.PlayerTags.Insert(0, defaultPlayer);
            }
            else if (LastMatchPlayers.Count(p => Players.Contains(p)) == 1)
            {
                defaultPlayer = LastMatchPlayers.First(p => Players.Contains(p));
                App.UserDataSettings.PlayerTags.Insert(0, defaultPlayer);
            }

            int defaultPlayerIndex = Players.IndexOf(defaultPlayer);

            LastMatchPlayers.Clear();
            LastMatchPlayers.AddRange(Players);

            _eventAggregator.PublishOnUIThread(new InvokeScriptMessage
            {
                ScriptName = "setMap",
                Args       = new[] { game.Map }
            }, "MMRChanel");

            _eventAggregator.PublishOnUIThread(new InvokeScriptMessage
            {
                ScriptName = "setPlayers",
                Args       = new[] { regionId, defaultPlayerIndex.ToString(), battleTags }
            }, "MMRChanel");
        }
예제 #26
0
        // 将格子中的信息同步给某个玩家,返回值是实际同步的玩家数量
        public int AsyncMapCellDataToClient(PlayerInstance player, int maxCount, Random rand, RPC.DataWriter data)
        {
            int retValue = maxCount;

            if (Players.Count <= maxCount)
            {
                if (Players.Contains(player))
                {
                    retValue = Players.Count - 1;
                }
                else
                {
                    retValue = Players.Count;
                }

                data.Write((Byte)retValue);

                foreach (var role in Players)
                {
                    if (role.Id == player.Id)
                    {
                        continue;
                    }

                    data.Write(role.PlayerData.RoleDetail, true);
                    data.Write(role.Id);
                }
            }
            else
            {
                int startIdx = rand.Next(Players.Count - maxCount);

                if (Players.IndexOf(player) >= startIdx)
                {
                    retValue = maxCount - 1;
                }
                else
                {
                    retValue = maxCount;
                }

                data.Write((Byte)retValue);

                for (int i = startIdx; i < startIdx + maxCount; i++)
                {
                    if (Players[i].Id == player.Id)
                    {
                        continue;
                    }

                    data.Write(Players[i].PlayerData.RoleDetail, true);
                    data.Write(Players[i].Id);
                }
            }

            return(retValue);
        }
예제 #27
0
        public void JoinNextHand(Player player, int seatIndex, double buyIn)
        {
            if (!Players.Contains(player, new Utility.AddressComparer <Player>()))
            {
                throw new PlayerNotFoundException("the user doesn't have this player");
            }

            gameCenter.JoinNextHand(player, seatIndex, buyIn);
            UserBank.Withdraw(buyIn);
        }
예제 #28
0
        /// <summary>
        /// プレイヤー追加
        /// </summary>
        /// <param name="player">追加プレイヤー</param>
        public void AddPlayer(Player player)
        {
            // すでにいるプレイヤーは追加しない
            if (Players == null || Players.Contains(player))
            {
                return;
            }

            Players.Add(player);
        }
예제 #29
0
 public void RemovePlayer(string player)
 {
     if (!Players.Contains(player))
     {
         return;
     }
     Players.Remove(player);
     Spec.Players = Spec.Players.Where(n => n != player).ToArray();
     Update();
 }
예제 #30
0
 private void PlayerDisconnected(string username)
 {
     if (Players.Contains(username))
     {
         Application.Current.Dispatcher.Invoke(() =>
         {
             Players.Remove(username);
         });
     }
 }