Esempio n. 1
0
    public void RpcYourTurn(bool isYourTurn)
    {
        // make player who is having current turn green
        Color c = new Color(1, 1, 1, 0.5f);

        if (isYourTurn)
        {
            c = Color.red;
        }

        playerPanel.GetComponent <PlayerPanel>().ColorImage(c);
        Debug.Log("Powinno dac kolorek");


        if (isYourTurn && isLocalPlayer)
        {
            //playerPanel.GetCardStatus();
            Debug.Log("MOJA TURA");
            if (!isObserver)
            {
                isObserver = true;
                playerPanel.CreateInstances();
            }
            //CardManager.singleton.EnablePlayHandButtons();
            //playerPanel.CreateInstances();
        }
        else
        {
            Debug.Log("TU WYPIERDALA BUGA");

            //CardManager.singleton.ClientDisableAllButtons();
        }
    }
Esempio n. 2
0
    void Start()
    {
        RectTransform rectTransform = playerPanel.GetComponent <RectTransform>();

        robotImage.rectTransform.sizeDelta = rectTransform.rect.size * 0.45f;

        Refresh();
    }
Esempio n. 3
0
        /// <summary>
        /// Initialize player panel to UI.
        /// </summary>
        /// <param name="initOrderNumber">Initialized order number of a player. 0 = The first player has been initialized. 1 = the 2nd player has been initialized. etc.</param>
        private void InitializePlayerPanel(int initOrderNumber)
        {
            if (initOrderNumber == 0)
            {
                // Setup player UI.
                PlayerPanelReference = UserInterfaceGameplayManager.Instance.InstantiatePlayerPanel(false);
                PlayerPanelReference.PlayerManagerReference = this;
                // Set player colors.
                //PlayerPanelReference.PlayerInventory.GetComponent<Image>().color = PlayerColor;

                // Player 1.
                // Set default scale & position.
                PlayerPanelReference.GetComponent <RectTransform>().localScale         = new Vector3(1f, 1f, 1f);
                PlayerPanelReference.GetComponent <RectTransform>().anchoredPosition3D = new Vector3(
                    0f,
                    0f,
                    0f
                    );
            }
            else if (initOrderNumber == 1)
            {
                // Setup player UI.
                PlayerPanelReference = UserInterfaceGameplayManager.Instance.InstantiatePlayerPanel(true);
                PlayerPanelReference.PlayerManagerReference = this;
                // Set player colors.
                //PlayerPanelReference.PlayerInventory.GetComponent<Image>().color = PlayerColor;

                // Player 2.
                // Set default scale & position.
                PlayerPanelReference.GetComponent <RectTransform>().localScale         = new Vector3(1f, 1f, 1f);
                PlayerPanelReference.GetComponent <RectTransform>().anchoredPosition3D = new Vector3(
                    -(PlayerPanelReference.GetComponent <RectTransform>().rect.width),
                    0f,
                    0f
                    );

                PlayerPanelReference.GetComponent <RectTransform>().anchorMin = new Vector2(1f, 0f);
                PlayerPanelReference.GetComponent <RectTransform>().anchorMax = new Vector2(1f, 0f);
            }
        }
Esempio n. 4
0
    public void RpcYourTurn(bool isYourTurn)//control the turn and the buttons
    {
        // make player who is having current turn green
        Color c = new Color(1, 1, 1, 0.5f);

        if (isYourTurn)
        {
            c = Color.green;
        }

        playerPanel.GetComponent <PlayerPanel>().ColorImage(c);

        if (isYourTurn && isLocalPlayer)
        {
            RoomManager.singleton.EnablePlayHandButtons();
        }
        else
        {
            RoomManager.singleton.ClientDisableAllButtons();
        }
    }
    /// <summary>
    /// Sets up the info to sent to the MatchResultScreen
    /// </summary>
    /// <param name="p"></param>
    private void SetUpInfo(PlayerData p)
    {
        PlayerPanel pp = Instantiate(PlayerPanelClass);

        pp.GetComponent <PlayerPanel>().playerName.text = p.Name;
        pp.GetComponent <PlayerPanel>().crownImg.sprite = GetRightImg(p.place);

        pp.GetComponent <PlayerPanel>().firstWord.text  = (p.BestWords.ElementAtOrDefault(0) != null) ? p.BestWords[0].ToUpper() : "";
        pp.GetComponent <PlayerPanel>().secondWord.text = (p.BestWords.ElementAtOrDefault(1) != null) ? p.BestWords[1].ToUpper() : "";;
        pp.GetComponent <PlayerPanel>().thirdWord.text  = (p.BestWords.ElementAtOrDefault(2) != null) ? p.BestWords[2].ToUpper() : "";;

        pp.transform.SetParent(PlayerPanelHolder.transform, false);

        if (GameInstance.instance.IsMultiplayer && !p.localPlayer && !AccountManager.instance.AlreadyFriends(p.playfabId))
        {
            Button addFriend = pp.GetComponent <PlayerPanel>().addFriend;
            addFriend.gameObject.SetActive(true);
            addFriend.GetComponent <AddFriendBtnScript>().OnAddFriendBtnTouched = () =>
            {
                AccountManager.instance.AddFriend(p.playfabId);
                addFriend.GetComponentInChildren <Text>().text = I2.Loc.LocalizationManager.GetTranslation("friend_added_friend");
                addFriend.interactable = false;
            };
        }
        else if (AccountManager.instance.AlreadyFriends(p.playfabId))
        {
            pp.GetComponent <PlayerPanel>().alreadyFriendsImg.gameObject.SetActive(true);
        }

        StartCoroutine(AddTimeToPlayerScore(p, pp));

        if (p.localPlayer)
        {
            PlayFabClientAPI.WritePlayerEvent(new WriteClientPlayerEventRequest()
            {
                Body = new Dictionary <string, object>()
                {
                    { "PlayerScore", p.Points },
                    { "PlayerPlace", p.place },
                    { "PlayerPlacedWordCount", p.WordCount }
                },
                EventName = "player_finished_game"
            },
                                              result => Debug.Log("Success saving scores"),
                                              error => Debug.LogError(error.GenerateErrorReport()));

            #region statistics
            // Check if there are statistics present. If so, set previousScore & statisticsPresent to true
            int  previousScore              = 0;
            int? previousWins               = 0;
            int? gamesPlayed                = 0;
            int? totalScore                 = 0;
            int? wordCount                  = 0;
            int? AmountOfWordsPerMin        = 0;
            int? AmountOfWordLenghtOfTwelve = 0;
            bool statisticsPresent          = false;
            if (AccountManager.CurrentPlayer.Statistics.Count > 0)
            {
                statisticsPresent = true;
                if (GameInstance.instance.difficulty == Difficulty.Easy && AccountManager.CurrentPlayer.Statistics.Find(model => model.Name == "easy_score") != null)
                {
                    previousScore = AccountManager.CurrentPlayer.Statistics.Find(model => model.Name == "easy_score")
                                    .Value;
                }
                else if (GameInstance.instance.difficulty == Difficulty.Medium && AccountManager.CurrentPlayer.Statistics.Find(model => model.Name == "medium_score") != null)
                {
                    previousScore = AccountManager.CurrentPlayer.Statistics.Find(model => model.Name == "medium_score")
                                    .Value;
                }
                else if (GameInstance.instance.difficulty == Difficulty.Hard && AccountManager.CurrentPlayer.Statistics.Find(model => model.Name == "hard_score") != null)
                {
                    previousScore = AccountManager.CurrentPlayer.Statistics.Find(model => model.Name == "hard_score")
                                    .Value;
                }
                previousWins               = AccountManager.CurrentPlayer.Statistics.Find(model => model.Name == "Wins")?.Value;
                gamesPlayed                = AccountManager.CurrentPlayer.Statistics.Find(model => model.Name == "GamesPlayed")?.Value;
                totalScore                 = AccountManager.CurrentPlayer.Statistics.Find(model => model.Name == "TotalScore")?.Value;
                wordCount                  = AccountManager.CurrentPlayer.Statistics.Find(model => model.Name == "WordCount")?.Value;
                AmountOfWordsPerMin        = AccountManager.CurrentPlayer.Statistics.Find(model => model.Name == "AmountOfWordsPerMin")?.Value;
                AmountOfWordLenghtOfTwelve = AccountManager.CurrentPlayer.Statistics.Find(model => model.Name == "WordLengthOfTwelve")?.Value;
            }

            var updateStatisticsRequest = new UpdatePlayerStatisticsRequest();
            var statistics = new List <StatisticUpdate>();
            var statistic  = new StatisticUpdate();

            // if new points are more than other points, put the new points
            if (p.Points > previousScore || p.Points == previousScore || previousScore == 0)
            {
                if (GameInstance.instance.difficulty == Difficulty.Easy)
                {
                    statistic = new StatisticUpdate {
                        StatisticName = "easy_score", Value = (int)p.Points
                    };
                    statistics.Add(statistic);
                    if (previousScore == 0)
                    {
                        AccountManager.CurrentPlayer.Statistics = new List <StatisticModel>
                        {
                            new StatisticModel
                            {
                                Value = (int)p.Points,
                                Name  = "easy_score"
                            }
                        };
                    }
                    else
                    {
                        // If they are present, make sure the new score is added to currentPlayer
                        AccountManager.CurrentPlayer.Statistics.Find(model => model.Name == "easy_score").Value =
                            (int)p.Points;
                    }
                }
                else if (GameInstance.instance.difficulty == Difficulty.Medium)
                {
                    statistic = new StatisticUpdate {
                        StatisticName = "medium_score", Value = (int)p.Points
                    };
                    statistics.Add(statistic);
                    if (previousScore == 0)
                    {
                        AccountManager.CurrentPlayer.Statistics = new List <StatisticModel>
                        {
                            new StatisticModel
                            {
                                Value = (int)p.Points,
                                Name  = "medium_score"
                            }
                        };
                    }
                    else
                    {
                        // If they are present, make sure the new score is added to currentPlayer
                        AccountManager.CurrentPlayer.Statistics.Find(model => model.Name == "medium_score").Value =
                            (int)p.Points;
                    }
                }
                else if (GameInstance.instance.difficulty == Difficulty.Hard)
                {
                    statistic = new StatisticUpdate {
                        StatisticName = "hard_score", Value = (int)p.Points
                    };
                    statistics.Add(statistic);
                    if (previousScore == 0)
                    {
                        AccountManager.CurrentPlayer.Statistics = new List <StatisticModel>
                        {
                            new StatisticModel
                            {
                                Value = (int)p.Points,
                                Name  = "hard_score"
                            }
                        };
                    }
                    else
                    {
                        // If they are present, make sure the new score is added to currentPlayer
                        AccountManager.CurrentPlayer.Statistics.Find(model => model.Name == "hard_score").Value =
                            (int)p.Points;
                    }
                }
            }

            if (p.place == 1)
            {
                StatisticModel newModel = new StatisticModel();
                // if previousWins is not null, put previousWins + 1, else put 1
                statistic = new StatisticUpdate {
                    Value = previousWins + 1 ?? 1, StatisticName = "Wins"
                };
                statistics.Add(statistic);
                if (AccountManager.CurrentPlayer.Statistics.Find(model => model.Name == "Wins") != null)
                {
                    AccountManager.CurrentPlayer.Statistics.Find(model => model.Name == "Wins").Value++;
                }
                else
                {
                    AccountManager.CurrentPlayer.Statistics.Add(
                        new StatisticModel
                    {
                        Value = 1,
                        Name  = "Wins"
                    }
                        );
                }
            }

            statistic = new StatisticUpdate {
                Value = gamesPlayed + 1 ?? 1, StatisticName = "GamesPlayed"
            };
            statistics.Add(statistic);
            if (AccountManager.CurrentPlayer.Statistics.Find(model => model.Name == "GamesPlayed") != null)
            {
                AccountManager.CurrentPlayer.Statistics.Find(model => model.Name == "GamesPlayed").Value++;
            }
            else
            {
                AccountManager.CurrentPlayer.Statistics.Add(
                    new StatisticModel
                {
                    Value = 1,
                    Name  = "GamesPlayed"
                }
                    );
            }

            statistic = new StatisticUpdate
            {
                Value = totalScore + (int)p.Points ?? (int)p.Points, StatisticName = "TotalScore"
            };
            statistics.Add(statistic);
            if (AccountManager.CurrentPlayer.Statistics.Find(model => model.Name == "TotalScore") == null)
            {
                AccountManager.CurrentPlayer.Statistics.Add(
                    new StatisticModel
                {
                    Value = (int)p.Points,
                    Name  = "TotalScore"
                }
                    );
            }

            statistic = new StatisticUpdate
            {
                Value = wordCount + p.WordCount ?? p.WordCount, StatisticName = "WordCount"
            };
            statistics.Add(statistic);
            if (AccountManager.CurrentPlayer.Statistics.Find(model => model.Name == "WordCount") != null)
            {
                AccountManager.CurrentPlayer.Statistics.Find(model => model.Name == "WordCount").Value += p.WordCount;
            }
            else
            {
                AccountManager.CurrentPlayer.Statistics.Add(
                    new StatisticModel
                {
                    Value = p.WordCount,
                    Name  = "WordCount"
                }
                    );
            }


            statistic = new StatisticUpdate {
                StatisticName = "WordLengthOfTwelve", Value = p.WordCountTwelveLetters + (AmountOfWordLenghtOfTwelve ?? 0)
            };
            statistics.Add(statistic);

            // When statistics aren't present, set these to currentPlayer
            if (!statisticsPresent || AccountManager.CurrentPlayer.Statistics.Find(model => model.Name == "WordLengthOfTwelve") == null)
            {
                AccountManager.CurrentPlayer.Statistics = new List <StatisticModel>
                {
                    new StatisticModel
                    {
                        Value = p.WordCountTwelveLetters + (AmountOfWordLenghtOfTwelve ?? 0),
                        Name  = "WordLengthOfTwelve"
                    }
                };
            }
            else
            {
                // If they are present, make sure the new score is added to currentPlayer
                AccountManager.CurrentPlayer.Statistics.Find(model => model.Name == "WordLengthOfTwelve").Value = p.WordCountTwelveLetters + (AmountOfWordLenghtOfTwelve ?? 0);
            }

            int finalAmount;
            if (p.FinalWordCountPerMinute > AmountOfWordsPerMin)
            {
                finalAmount = p.FinalWordCountPerMinute;
            }
            else
            {
                finalAmount = AmountOfWordsPerMin ?? 0;
            }
            statistic = new StatisticUpdate {
                StatisticName = "AmountOfWordsPerMin", Value = finalAmount
            };
            statistics.Add(statistic);

            // When statistics aren't present, set these to currentPlayer
            if (!statisticsPresent)
            {
                AccountManager.CurrentPlayer.Statistics = new List <StatisticModel>
                {
                    new StatisticModel
                    {
                        Value = p.FinalWordCountPerMinute,
                        Name  = "AmountOfWordsPerMin"
                    }
                };
            }


            if (statistics.Count <= 0)
            {
                return;
            }
            updateStatisticsRequest.Statistics = statistics;
            PlayFabClientAPI.UpdatePlayerStatistics(updateStatisticsRequest, OnSuccess, OnFailure);
            #endregion
        }
    }