Пример #1
0
 public static Definitions Get(CustomProcess p, string version, Game.GameType gameType)
 {
     try
     {
         return(new Definitions());
     }
     catch (WebException exc)
     {
         throw new Exception("Could not get definitions for version", exc);
     }
 }
        private void onSceneLoaded(Scene newScene, LoadSceneMode mode)
        {
            //Debug.LogError ("Load finished");

            gameController = GameObject.FindGameObjectWithTag("ServerController").GetComponent <Game.ServerController>().getController();
            wrapper.init(gameController.getProtocol(), gameController);
            currentGameType = gameController.getGameType();

            Action <string>             printFunc  = DllManager.printMsg;
            Action <object, int, short> networkMsg = wrapper.sendMsg;

            gameController.init(printFunc, networkMsg, shutdownGameServer, wrapper, preGamePlayers);
            onClientLeft += wrapper.clientLeft;
            initManagers();
        }
Пример #3
0
 public String TestCheckBoxes(int a_AmountActiveElements, Game.GameType a_GameType)
 {
     if (a_GameType == Game.GameType.VictoryPoints)
     {
         return(TestAtLeastOneBoxChecked(a_AmountActiveElements));
     }
     else if (a_GameType == Game.GameType.WinLose)
     {
         return(TestNotAllBoxesChecked(a_AmountActiveElements));
     }
     else if (a_GameType == Game.GameType.Ranks)
     {
         return("");
     }
     else
     {
         return("Not Implemented.");
     }
 }
Пример #4
0
        public static Definitions Get(NhaamaProcess p, string version, Game.GameType gameType)
        {
            using (WebClient client = new WebClient())
            {
                var uri = new Uri(DefinitionStoreUrl, $"{gameType.ToString().ToLower()}/{version}.json");

                try
                {
                    var definitionJson         = client.DownloadString(uri);
                    var serializer             = p.GetSerializer();
                    var deserializedDefinition = serializer.DeserializeObject <Definitions>(definitionJson);

                    return(deserializedDefinition);
                }
                catch (WebException exc)
                {
                    throw new Exception("Could not get definitions for version: " + uri, exc);
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Calculates individual player ResultRows for the given game family ID.
        /// </summary>
        /// <param name="a_GameFamilyId">Id of the game family to calculate results for.</param>
        /// <returns>A collection of result row objects filled with players which played games from the family of given ID.</returns>
        public IEnumerable <object> CalculateResultsGameFamilies(Guid a_GameFamilyId)
        {
            // First: Get all games from the given game family.
            var v_AllGamesFromFamily = Games.Where(p => p.IdGamefamilies.Contains(a_GameFamilyId));

            if (v_AllGamesFromFamily.Count() < 1)
            {
                return(null);
            }

            // Second: Get all results with games of the given game family.
            var v_Results = Results.Join(v_AllGamesFromFamily,
                                         result => result.IdGame,
                                         game => game.Id,
                                         (result, game) => result);

            // Peek at the game type.
            Game.GameType        v_ActualType = v_AllGamesFromFamily.First().Type;
            IEnumerable <object> v_ResultRows = null;

            if (v_ActualType == Game.GameType.VictoryPoints)
            {
                v_ResultRows = CalculateResultsVictoryPoints(v_Results);
            }
            else if (v_ActualType == Game.GameType.Ranks || v_ActualType == Game.GameType.TeamedRanks)
            {
                v_ResultRows = CalculateResultsRanks(v_Results);
            }
            else if (v_ActualType == Game.GameType.WinLose)
            {
                v_ResultRows = CalculateResultsWinLose(v_Results);
            }
            else
            {
                // Do nothing, result rows have been init'd with null anyway.
            }

            return(v_ResultRows);
        }
Пример #6
0
 public void SwitchTextBoxAndRankVisibility(Game.GameType a_GameType)
 {
     for (int i = 0; i < m_PlayerAmount; ++i)
     {
         if (a_GameType == Game.GameType.VictoryPoints)
         {
             PlayerRanksComboBoxes[i].Visibility  = Visibility.Hidden;
             PlayerResultTextBoxes[i].Visibility  = Visibility.Visible;
             PlayerResultCheckBoxes[i].Visibility = Visibility.Visible;
         }
         else if (a_GameType == Game.GameType.Ranks)
         {
             PlayerRanksComboBoxes[i].Visibility  = Visibility.Visible;
             PlayerResultTextBoxes[i].Visibility  = Visibility.Hidden;
             PlayerResultCheckBoxes[i].Visibility = Visibility.Hidden;
         }
         else if (a_GameType == Game.GameType.WinLose)
         {
             PlayerRanksComboBoxes[i].Visibility  = Visibility.Hidden;
             PlayerResultTextBoxes[i].Visibility  = Visibility.Hidden;
             PlayerResultCheckBoxes[i].Visibility = Visibility.Visible;
         }
     }
 }
Пример #7
0
            public GameInfoPacket createGameInfoPacket(GameInfoType infoType, string roomID, string hostName, int maxPlayers, int playerAmount, Game.GameType type)
            {
                return(new GameInfoPacket()
                {
                    infoType = infoType,
                    Name = hostName,
                    OnlinePlayers = playerAmount,
                    MaxPlayers = maxPlayers,
                    IsPasswordProtected = false,
                    Properties = new Dictionary <string, string>()
                    {
                        { MsfDictKeys.MapName, type.ToString() },
                        { MsfDictKeys.IsPreGame, true.ToString() },
                        { MsfDictKeys.GameType, type.ToString() }
                    },

                    Id = roomID,
                    Address = "MasterIP"
                });
            }
Пример #8
0
 public static MapSelection getMatchingMapSelection(Game.GameType type)
 {
     return(localSingleton.maps.Find(x => x.type == type));
 }
Пример #9
0
        private void CalculateEloResults(Dictionary <Guid, ResultHelper> a_StartResults, DateTime a_MatchDate, Game.GameType a_GameType)
        {
            // We need to increment the count for all players.
            foreach (KeyValuePair <Guid, ResultHelper> i_Kvp in a_StartResults)
            {
                i_Kvp.Value.AmountGamesPlayed++;
            }

            Dictionary <Guid, KeyValuePair <DateTime, int> > v_TempResults = new Dictionary <Guid, KeyValuePair <DateTime, int> >();

            // We only want to do it ONCE for each entry.
            foreach (KeyValuePair <Guid, ResultHelper> i_Kvp in a_StartResults)
            {
                // Get the standings for given player.
                Dictionary <Modifier, List <Guid> > v_Standings = CalculateStandings(i_Kvp.Key, a_GameType);
                List <double> v_TempEloScores = new List <double>();

                // Iterates over all standings. Standings contains n-1 individual Ids (where n is the amount of players in a match).
                foreach (KeyValuePair <Modifier, List <Guid> > i_KvpInner in v_Standings)
                {
                    double v_ModifierPlayer = EloCalculator.EstablishedStatusToModifier[i_Kvp.Value.IsEstablished][i_KvpInner.Key];

                    foreach (Guid i_OpponentId in i_KvpInner.Value)
                    {
                        /// The +1 is needed because we only increment the amount of played games inside AddResult.
                        /// In the old implementation was actually a defect because the counter for the active player
                        /// was incremented and the calculation used the old value for the opponent.
                        double v_TempEloScore = EloCalculator.CalculateEloRanking(
                            i_Kvp.Value.EloScore,
                            i_Kvp.Value.AmountGamesPlayed,
                            i_Kvp.Value.IsEstablished,
                            a_StartResults[i_OpponentId].EloScore,
                            a_StartResults[i_OpponentId].AmountGamesPlayed,
                            a_StartResults[i_OpponentId].IsEstablished,
                            v_ModifierPlayer
                            );

                        v_TempEloScores.Add(v_TempEloScore);
                    }
                }

                double v_NewEloScore = 0;

                foreach (double i_TempScore in v_TempEloScores)
                {
                    v_NewEloScore += i_TempScore;
                }

                if (v_TempEloScores.Count > 0)
                {
                    v_NewEloScore = v_NewEloScore / v_TempEloScores.Count;
                    // Must NOT be applied immediately! We're putting the reults aside and apply them afterwards.
                    v_TempResults.Add(i_Kvp.Key, new KeyValuePair <DateTime, int>(a_MatchDate, (int)Math.Round(v_NewEloScore, 0)));
                }
            }

            // Now we add the new results.
            foreach (KeyValuePair <Guid, ResultHelper> i_Kvp in a_StartResults)
            {
                i_Kvp.Value.AddResult(v_TempResults[i_Kvp.Key].Key, v_TempResults[i_Kvp.Key].Value);
            }
        }
Пример #10
0
        /// <summary>
        /// Takes the scores in result object and looks how the given player did againts the other players. The resulting dict
        /// is used in the CalculateEloResults method or in GenerateYearsOverGames.
        /// </summary>
        /// <param name="a_PlayerId">Guid of the player for which the standings will be considered.</param>
        /// <returns>A dict with elements of the  Modifier enum from the EloCalculator as a key and a List of IDs as the value.
        /// </returns>
        internal Dictionary <Modifier, List <Guid> > CalculateStandings(Guid a_PlayerId, Game.GameType a_GameType)
        {
            Dictionary <Modifier, List <Guid> > v_Standings = new Dictionary <Modifier, List <Guid> >
            {
                { Modifier.Lose, new List <Guid>() },
                { Modifier.Stalemate, new List <Guid>() },
                { Modifier.Win, new List <Guid>() }
            };

            // All scores *without* the active player.
            var    v_ScoresWithoutActivePlayer = Scores.Where(p => p.IdPlayer != a_PlayerId);
            bool   v_IsWinner          = ScoresById[a_PlayerId].IsWinner;
            double v_ScoreActivePlayer = double.Parse(ScoresById[a_PlayerId].ActualScore);

            foreach (Score i_Score in v_ScoresWithoutActivePlayer)
            {
                double v_TempScore = double.Parse(i_Score.ActualScore);

                if (v_IsWinner)
                {
                    if (a_GameType == Game.GameType.TeamedRanks)
                    {
                        // Filter out: These are our team members.
                    }
                    else if (i_Score.IsWinner)
                    {
                        v_Standings[Modifier.Stalemate].Add(i_Score.IdPlayer);
                    }
                    else
                    {
                        v_Standings[Modifier.Win].Add(i_Score.IdPlayer);
                    }
                }
                else if (v_ScoreActivePlayer == v_TempScore)
                {
                    if (a_GameType == Game.GameType.TeamedRanks)
                    {
                        // Filter out: These are our team members.
                    }
                    else if (i_Score.IsWinner)
                    {
                        v_Standings[Modifier.Lose].Add(i_Score.IdPlayer);
                    }
                    else
                    {
                        v_Standings[Modifier.Stalemate].Add(i_Score.IdPlayer);
                    }
                }
                else if (v_ScoreActivePlayer > v_TempScore)
                {
                    // In a ranked game the actual score is the rank and if it's greater than the temp we've lost.
                    if (a_GameType == Game.GameType.Ranks || a_GameType == Game.GameType.TeamedRanks)
                    {
                        v_Standings[Modifier.Lose].Add(i_Score.IdPlayer);
                    }
                    else if (i_Score.IsWinner)
                    {
                        v_Standings[Modifier.Lose].Add(i_Score.IdPlayer);
                    }
                    else
                    {
                        v_Standings[Modifier.Win].Add(i_Score.IdPlayer);
                    }
                }
                else if (v_ScoreActivePlayer < v_TempScore)
                {
                    // In a ranked game the actual score is the rank and if it's smaller than the temp we've won.
                    if (a_GameType == Game.GameType.Ranks || a_GameType == Game.GameType.TeamedRanks)
                    {
                        v_Standings[Modifier.Win].Add(i_Score.IdPlayer);
                    }
                    else if (i_Score.IsWinner)
                    {
                        v_Standings[Modifier.Lose].Add(i_Score.IdPlayer);
                    }
                    else
                    {
                        v_Standings[Modifier.Lose].Add(i_Score.IdPlayer);
                    }
                }
            }

            return(v_Standings);
        }