示例#1
0
        public void RPC_SetPlayerList(string[] names, string[] tags)
        {
            bool skipFirst = false;

            foreach (Transform child in listRect.transform)
            {
                if (!skipFirst)
                {
                    skipFirst = true;
                    continue;
                }

                Destroy(child.gameObject);
            }

            int i = 0;

            foreach (string s in tags)
            {
                GameObject go = Instantiate(listElement, listRect.transform, false);

                PlayerTags playerTag = (PlayerTags)Enum.Parse(typeof(PlayerTags), s);

                go.GetComponent <PlayerInfoElement>().SetInfo(names[i], playerTag);

                i++;
            }
        }
 private void OnPlayerChange(PlayerTags playerTags)
 {
     _playerController = GameHandler.Current.GetPlayerController(playerTags);
     _playerController.AddInventoryObserver(this);
     GlobalMethods.UpdateArrows(arrows.transform, _playerController);
     UpdatePlayerSelectionPanel();
 }
        private void UpdatePlayerPalette(PlayerTags playerTags)
        {
            _currentPlayer = playerTags;

            for (int j = 0; j < 16; j++)
            {
                GetPlayerColor(j).GetComponent <Image>().color = new Color32(0, 0, 0, 0);
            }

            int i = 0;

            foreach (PlayerController controller in GameHandler.Current.GetPlayers())
            {
                if (controller == _playerController)
                {
                    continue;
                }

                Image img = GetPlayerColor(i).GetComponent <Image>();

                img.color = ColorPalette.current.GetPlayerColor(controller.playerTag);

                _colorOrder[i] = controller.playerTag;
                i++;
            }
        }
示例#4
0
    public void AddBlock(string id)
    {
        //Had to trim this f*****g string - caused random errors. F**k unity.
        string input = id.Trim();

        if (!ContainsElement(input) && listOfBlock.Count < maxAmountOfBlocks)
        {
            Direction state;
            if (scanByColor)
            {
                state = DetermineMoveByColor(input);
            }
            else
            {
                state = DetermineMove();
            }


            PlayerTags p = _playerController.playerTag;

            Block _block = new Block(input, state, p);
            listOfBlock.Add(_block);
            Debug.Log($"added block with id {input} and it's state is: {state}");
        }
    }
示例#5
0
        public async Task GetPlayerInformationInALoopWithoutThrottling()
        {
            // Arrange
            var tokenCount        = 0;
            var playerTag         = PlayerTags.First();
            var requestCount      = 200;
            var requestsPerSecond = 50;
            var sw = new Stopwatch();

            _coc.Configure(options =>
            {
                tokenCount = options.Tokens.Count;
                Assert.IsTrue(options.MaxRequestsPerSecond == requestsPerSecond);
            });

            // Act
            try
            {
                sw.Start();
                var results = Enumerable.Range(1, requestCount).Select(i => _coc.Players.GetPlayerAsync(playerTag));
                _ = await Task.WhenAll(results);

                sw.Stop();

                Trace.WriteLine($"{requestCount} requests took {sw.ElapsedMilliseconds} ms with {tokenCount} token(s) and {requestsPerSecond} requests/second rate");
            }
            catch (Exception ex)
            {
                // Assert
                Assert.Fail(ex.ToString());
            }
        }
示例#6
0
 /*
  * im lazy, so here is another readyObserver... For the stattracker
  */
 public void OnPlayerReadyNotify(bool boolValue, PlayerTags player)
 {
     if (OnPlayerReady != null)
     {
         OnPlayerReady(boolValue, player);
     }
 }
        /// <summary>
        /// Spawns a specific player on a preselected position
        /// </summary>
        /// <param name="playerTag"></param>
        public virtual void SpawnNewPlayer(PlayerTags playerTag)
        {
            //Checks
            if (_players.Count >= numberOfPlayers)
            {
                throw new InvalidOperationException("Max players have already been reached");
            }
            if (_players.IndexOf(GetPlayerController(playerTag)) != -1)
            {
                throw new ArgumentException($"player {playerTag} already exist");
            }

            //Code
            int spawnNr = _playerTags.IndexOf(playerTag);

            Vector3 spawnPosition = new Vector3(_spawnPositions[spawnNr].x, 1.55f, _spawnPositions[spawnNr].y);

            _occupiedPositions[_playerTags[spawnNr]] = _spawnPositions[spawnNr];

            GameObject g = Instantiate(playerPrefab, spawnPosition, new Quaternion(0, 0, 0, 0));

            g.name = _playerTags[spawnNr].ToString();

            PlayerController p = g.GetComponent <PlayerController>();

            p.SetPlayer(_playerTags[spawnNr]);
            AddPlayerController(p);

            p.AddReadyObserver(this);
            numberOfSpawnedPlayers++;
        }
        /// <summary>
        /// Adds a move to the common sequence
        /// </summary>
        /// <param name="p"></param>
        /// <param name="d"></param>
        /// <param name="index"></param>
        public virtual void AddMoveToSequence(PlayerTags p, Direction d, int moveId, int index)
        {
            PlayerController playerController = GetPlayerController(p);

            if (playerController == null)
            {
                throw new ArgumentException(p + " is not active");
            }

            if (playerController.GetIndexForDirection(d) == -1)
            {
                throw new InvalidOperationException($"{playerPrefab} does not posses the {d} move");
            }

            if (d == Direction.Blank)
            {
                throw new ArgumentException("Can't add blank moves");
            }

            StoredPlayerMove playerMove = new StoredPlayerMove(p, d, index, moveId);

            _sequenceMoves.Add(playerMove);

            playerController.RemoveMove(index);

            playerController.NotifyInventoryObservers();
            NotifySequenceObservers(SequenceActions.NewMoveAdded, playerMove);
        }
 public StoredPlayerMove(PlayerTags pc, Direction d, int moveIndex, int id)
 {
     PlayerTags     = pc;
     Direction      = d;
     this.moveIndex = moveIndex;
     Id             = id;
 }
示例#10
0
        public virtual void OnReadyStateChanged(bool state, PlayerTags player)
        {
            switch (state)
            {
            case true:
                _numberOfReadyPlayers++;
                break;

            case false:
                _numberOfReadyPlayers--;
                break;
            }

            /*
             * This is a stupid network fix. Basically, all client will report back to
             * the master and say they are not ready. At the same time, the master itself will also set
             * players to not be ready. The result is that the master thinks that -4 players are ready
             * after a sequence have been played, which should be 0.
             */

            if (_numberOfReadyPlayers < 0)
            {
                _numberOfReadyPlayers = 0;
            }

            /*if (_numberOfReadyPlayers == numberOfSpawnedPlayers)
             * {
             *  Debug.Log("Performing sequence on local gamehandler");
             *  StartCoroutine(PerformSequence());
             * }*/
        }
示例#11
0
        private void OnBtnHit(Button button)
        {
            if (button.name.Equals("SpawnPlayers"))
            {
                Dictionary <string, PlayerTags> loggerPlayerList = new Dictionary <string, PlayerTags>();

                button.interactable = false;
                foreach (Player player in PhotonNetwork.PlayerList)
                {
                    if (GlobalMethods.GetRole(player.NickName) != "Participant")
                    {
                        continue;
                    }

                    PlayerTags pTag = GameHandler.Current.SpawnNewPlayer();
                    _playerDictionary.Add(player.NickName, pTag);

                    _photonView.RPC("RPC_SetPlayerTag", player, pTag);

                    loggerPlayerList.Add(player.NickName, pTag);
                }

                statTracker.playerList = loggerPlayerList;
                SetPlayerList();
            }
        }
示例#12
0
        public Color32 GetPlayerColor(PlayerTags playerTags)
        {
            switch (playerTags)
            {
            case PlayerTags.Red:
                return(playerRed);

            case PlayerTags.Blue:
                return(playerBlue);

            case PlayerTags.Green:
                return(playerGreen);

            case PlayerTags.Yellow:
                return(playerYellow);

            case PlayerTags.Black:
                return(playerBlack);

            case PlayerTags.Sand:
                return(playerSand);

            case PlayerTags.Pink:
                return(playerPink);

            case PlayerTags.Gray:
                return(playerGray);

            case PlayerTags.Orange:
                return(playerOrange);

            case PlayerTags.Purple:
                return(playerPurple);

            case PlayerTags.DarkGreen:
                return(playerDarkGreen);

            case PlayerTags.LightBlue:
                return(playerLightBlue);

            case PlayerTags.White:
                return(playerWhite);

            case PlayerTags.Turquoise:
                return(playerTurquoise);

            case PlayerTags.NavyBlue:
                return(playerNavyBlue);

            case PlayerTags.LightGreen:
                return(playerLightGreen);

            case PlayerTags.Blank:
                return(playerRed);

            default:
                throw new ArgumentOutOfRangeException(nameof(playerTags), playerTags, null);
            }
        }
        /*
         * Buttons
         */
        public void PlayerButtonHit(int nr)
        {
            SelectMovePanelIn();

            playerTag.text       = _playerTagDictionary[nr].ToString();
            playerTagColor.color = ColorPalette.current.GetPlayerColor(_playerTagDictionary[nr]);
            _receivingPlayer     = _playerTagDictionary[nr];
        }
示例#14
0
 private void OnPlayerChange(PlayerTags playerTags)
 {
     if (PlayerController != null)
     {
         PlayerController.RemoveTradeObserver(this);
     }
     PlayerController = GameHandler.Current.GetPlayerController(playerTags);
     PlayerController.AddTradeObserver(this);
 }
示例#15
0
        public virtual void NotifyGameProgressObservers(PlayerTags player1)
        {
            foreach (IFinishPointObserver observer in _gameProgressObservers)
            {
                observer.OnGameProgressUpdate(player1);
            }

            _playersFinished++;
            CheckIfGameIsDone();
        }
示例#16
0
        public void CancelTrade(PlayerTags cancellingPlayerTags)
        {
            if (cancellingPlayerTags != OfferingPlayerTags)
            {
                throw new ArgumentException("Only the player that created the trade can cancel it");
            }

            NotifyObservers(TradeActions.TradeCanceled);
            CancelTrade();
        }
示例#17
0
 public PlayerTrade(PlayerTags offeringPlayerTags, PlayerTags receivingPlayerTags, Direction directionOffer, GameHandler gameHandler, int storedMoveIndex, List <ITradeObserver> observers, int tradeId)
 {
     TradeID             = tradeId;
     OfferingPlayerTags  = offeringPlayerTags;
     DirectionOffer      = directionOffer;
     _gameHandler        = gameHandler;
     _storedMoveIndex    = storedMoveIndex;
     ReceivingPlayerTags = receivingPlayerTags;
     _statObservers      = observers;
 }
        private void OnPlayerChange(PlayerTags obj)
        {
            if (_playerController != null)
            {
                _playerController.RemoveTradeObserver(this);
            }

            _playerController = GameHandler.Current.GetPlayerController(obj);
            _playerController.AddTradeObserver(this);
        }
示例#19
0
 /// <summary>
 /// Gets a specific playercontroller based on the playertag.
 /// </summary>
 /// <param name="p"></param>
 /// <returns>PlayerController</returns>
 public virtual PlayerController GetPlayerController(PlayerTags p)
 {
     foreach (var playerController in _players)
     {
         if (playerController.playerTag == p)
         {
             return(playerController);
         }
     }
     return(null);
 }
示例#20
0
        private void OnPlayerChange(PlayerTags playerTags)
        {
            if (_playerController != null)
            {
                _playerController.RemoveTradeObserver(this);
            }
            _playerController = GameHandler.Current.GetPlayerController(playerTags);
            _playerController.AddTradeObserver(this);

            StartCoroutine(UpdatePlayerInformation());
        }
        public void SetPlayerController(PlayerTags newPlayerTags)
        {
            if (_playerController != null)
            {
                _playerController.RemoveInventoryObserver(this);
            }

            _playerController = GameHandler.Current.GetPlayerController(newPlayerTags);
            _playerController.AddInventoryObserver(this);

            GlobalMethods.UpdateArrows(SecondChoice.transform, _playerController);
        }
        public void OnReadyStateChanged(bool state, PlayerTags player)
        {
            switch (state)
            {
            case true:
                SetReady();
                break;

            case false:
                SetUnready();
                break;
            }
        }
示例#23
0
        public async Task VerifyPlayerTokenIsInvalid()
        {
            // Arrange
            var playerTag = PlayerTags.First();
            var apiToken  = "12345678";

            // Act
            var response = await _coc.Players.VerifyTokenAsync(playerTag, apiToken);

            // Assert
            Assert.IsNotNull(response);
            Assert.AreEqual(Status.Invalid, response.Status);
        }
示例#24
0
        protected void PlayerChange(PlayerTags newPlayerTags)
        {
            if (_playerController != null)
            {
                _playerController.RemoveInventoryObserver(this);
            }


            _playerController = GameHandler.Current.GetPlayerController(newPlayerTags);
            _playerController.AddInventoryObserver(this);

            GlobalMethods.UpdateArrows(arrows.transform.GetChild(0), _playerController);
        }
示例#25
0
        public void OnReadyStateChanged(bool state, PlayerTags player)
        {
            Debug.Log($"Contacting master with new state: {state}");
            photonView.RPC("RPC_OnReadyStateChanged", RpcTarget.MasterClient, state, player);

            Debug.Log($"Contacting observers with new state: {state}");
            foreach (Player player1 in PhotonNetwork.PlayerList)
            {
                if (GlobalMethods.IsObserver(player1.NickName))
                {
                    _photonView.RPC("RPC_Observer_OnReadyStateChanged", player1, state, player);
                }
            }
        }
 private void OnPlayerReady(bool state, PlayerTags player)
 {
     if (player == _playerController.playerTag)
     {
         if (state)
         {
             playerTagText.text = _playerController.playerTag + " | Ready!";
         }
         else
         {
             playerTagText.text = _playerController.playerTag + " | Not Ready";
         }
     }
 }
        private void OnPlayerChange(PlayerTags playerTags)
        {
            if (_playerController != null)
            {
                _playerController.RemoveReadyObserver(this);
            }

            _playerController = GameHandler.Current.GetPlayerController(playerTags);
            _playerController.AddReadyObserver(this);

            if (_playerController.ready)
            {
                SetReady();
            }
            else
            {
                SetUnready();
            }
        }
示例#28
0
        /*
         * Networked
         */
        public override void OnReadyStateChanged(bool state, PlayerTags player)
        {
            if (PhotonNetwork.IsMasterClient)
            {
                GUIEvents.current.OnPlayerReadyNotify(state, player);
                switch (state)
                {
                case true:
                    _numberOfReadyPlayers++;
                    break;

                case false:
                    _numberOfReadyPlayers--;
                    break;
                }

                /*
                 * This is a stupid network fix. Basically, all client will report back to
                 * the master and say they are not ready. At the same time, the master itself will also set
                 * players to not be ready. The result is that the master thinks that -4 players are ready
                 * after a sequence have been played, which should be 0.
                 */
                if (_numberOfReadyPlayers < 0)
                {
                    _numberOfReadyPlayers = 0;
                }

                UpdateReadyCounter();

                if (_numberOfReadyPlayers == localGameHandler.numberOfSpawnedPlayers)
                {
                    StartCoroutine(MyNetworkedAgent.PerformSequence());
                    _numberOfReadyPlayers = 0;
                }
            }

            if (!PhotonNetwork.IsMasterClient)
            {
                MyNetworkedAgent.OnReadyStateChanged(state, player);
            }
        }
示例#29
0
        public void RPC_OnNewTradeActivity(int tradeId, TradeActions tradeAction, PlayerTags offeringPlayer, PlayerTags receivingPlayer, Direction counterMove)
        {
            print($"Received: {tradeId}, {tradeAction}, {offeringPlayer}, {receivingPlayer}, {counterMove}");
            _processingNewTradeAction = true;

            foreach (PlayerTrade trade in gameHandler.GetTrades())
            {
                if (trade.TradeID == tradeId)
                {
                    switch (tradeAction)
                    {
                    case TradeActions.TradeOffered:
                        //Will not happen
                        break;

                    case TradeActions.TradeRejected:
                        trade.RejectTrade(gameHandler.GetPlayerController(receivingPlayer));
                        break;

                    case TradeActions.TradeAccepted:
                        trade.AcceptTrade(counterMove, gameHandler.GetPlayerController(receivingPlayer));
                        break;

                    case TradeActions.TradeCanceled:
                        trade.CancelTrade(offeringPlayer);
                        break;

                    case TradeActions.TradeCanceledByGameHandler:
                        trade.CancelTrade(gameHandler);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(tradeAction), tradeAction, null);
                    }

                    return;
                }
            }
        }
示例#30
0
        /*
         * Other network related methods
         */
        public override void OnPlayerLeftRoom(Player otherPlayer)
        {
            if (otherPlayer.NickName.Equals(GlobalValues.HostTag))
            {
                Disconnect();
            }

            if (PhotonNetwork.IsMasterClient)
            {
                hostNotification.titleObj.text       = "Player Left";
                hostNotification.descriptionObj.text = $"{otherPlayer.NickName}|{_playerDictionary[otherPlayer.NickName]} disconnected from the room";
                hostNotification.OpenNotification();

                if (GlobalMethods.GetRole(otherPlayer.NickName) == "Participant")
                {
                    _vacantPlayerTag = _playerDictionary[otherPlayer.NickName];
                    _playerDictionary.Remove(otherPlayer.NickName);

                    statTracker.OnPlayerDisconnect(otherPlayer.NickName, _vacantPlayerTag);
                }
            }
        }