Exemple #1
0
        private Dictionary <string, object> GetCustomizationDictionary()
        {
            var customizations  = new Dictionary <string, object>();
            var customizationId = "";

            var players = new List <object>();

            if ((PlayerChoice & 1) == 1)
            {
                players.Add(MatchManager.Match.FirstPlayer);
            }
            if ((PlayerChoice & 2) == 2)
            {
                players.Add(MatchManager.Match.SecondPlayer);
            }
            if ((PlayerChoice & 4) == 4)
            {
                var bothPlayers = new List <Player> {
                    MatchManager.Match.FirstPlayer, MatchManager.Match.SecondPlayer
                };
                players.Add(bothPlayers);
            }
            customizations["players"] = players;
            customizationId          += "8" + PlayerChoice.ToString("X");
            // adding a number in front ensures any two setting choices that are the same (e.g. 00010) will still get different encodings

            var customizationSets = new Dictionary <string, List <Rally> >();

            // 'all' sets
            if ((SetChoice & 1) == 1)
            {
                customizationSets["all"] = new List <Rally>(MatchManager.Match.Rallies);
            }

            // 'crunch time sets
            if (CrunchTimeChoice)
            {
                customizationSets["crunchtime"] = new List <Rally>(MatchManager.Match.Rallies.Where(r => r.CurrentRallyScore.First + r.CurrentRallyScore.Second >= 16));
            }

            // sets 1-7
            foreach (var set in Sets.Keys)
            {
                var mask = 1 << int.Parse(set);
                if ((mask & _setChoice) == mask)
                {
                    customizationSets[set] = Sets[set];
                }
            }
            customizationId += "9" + SetChoice.ToString("X");

            // set combis
            var selectedCombisSorted = new List <int>(SelectedCombis);

            selectedCombisSorted.Sort();
            customizationId += "A";
            foreach (var combi in selectedCombisSorted)
            {
                var combiName = "";
                var rallyList = new List <Rally>();
                for (var i = 1; i < Math.Ceiling(Math.Log(combi, 2)); i++)
                {
                    var mask = 1 << i;
                    if ((mask & combi) == mask)
                    {
                        combiName += i + ",";
                        foreach (var rally in MatchManager.Match.Rallies)
                        {
                            if (rally.CurrentSetScore.First + rally.CurrentSetScore.Second + 1 == i)
                            {
                                rallyList.Add(rally);
                            }
                        }
                    }
                }
                customizationSets[combiName.Substring(0, combiName.Length - 1)] = rallyList;
                customizationId += combi.ToString("X");
            }

            customizationId += "B" + (CrunchTimeChoice ? 1 : 0);

            customizations["sets"] = customizationSets;

            customizations["service_stats"] = new List <string>();
            customizations["return_stats"]  = new List <string>();
            customizations["third_stats"]   = new List <string>();
            customizations["fourth_stats"]  = new List <string>();
            customizations["last_stats"]    = new List <string>();
            customizations["all_stats"]     = new List <string>();
            foreach (var key in StrokeStats.Keys)
            {
                if ((ServiceStatsChoice & key) == key)
                {
                    ((List <string>)customizations["service_stats"]).Add(StrokeStats[key][0]);
                }
                if ((ReturnStatsChoice & key) == key)
                {
                    ((List <string>)customizations["return_stats"]).Add(StrokeStats[key][0]);
                }
                if ((ThirdStatsChoice & key) == key)
                {
                    ((List <string>)customizations["third_stats"]).Add(StrokeStats[key][0]);
                }
                if ((FourthStatsChoice & key) == key)
                {
                    ((List <string>)customizations["fourth_stats"]).Add(StrokeStats[key][0]);
                }
                if ((LastStatsChoice & key) == key)
                {
                    ((List <string>)customizations["last_stats"]).Add(StrokeStats[key][0]);
                }
                if ((AllStatsChoice & key) == key)
                {
                    ((List <string>)customizations["all_stats"]).Add(StrokeStats[key][0]);
                }
            }

            if (ServiceStatsChoice != 0)
            {
                customizationId += "1" + ServiceStatsChoice.ToString("X");
            }
            if (ReturnStatsChoice != 0)
            {
                customizationId += "2" + ReturnStatsChoice.ToString("X");
            }
            if (ThirdStatsChoice != 0)
            {
                customizationId += "3" + ThirdStatsChoice.ToString("X");
            }
            if (FourthStatsChoice != 0)
            {
                customizationId += "4" + FourthStatsChoice.ToString("X");
            }
            if (LastStatsChoice != 0)
            {
                customizationId += "5" + LastStatsChoice.ToString("X");
            }
            if (AllStatsChoice != 0)
            {
                customizationId += "6" + AllStatsChoice.ToString("X");
            }

            customizations["general"] = new List <string>();
            foreach (var key in GeneralStats.Keys)
            {
                if ((GeneralChoice & key) == key)
                {
                    ((List <string>)customizations["general"]).Add(GeneralStats[key][0]);
                }
            }
            customizationId += "7" + GeneralChoice.ToString("X");

            Debug.WriteLine($"customization id={customizationId}");

            customizations["id"] = customizationId;
            return(customizations);
        }
 // Save players class choices
 public void SaveToPlayerPreferences()
 {
     PlayerPrefs.SetString("Player1Class", player1Choice.ToString());
     PlayerPrefs.SetString("Player2Class", player2Choice.ToString());
 }