Esempio n. 1
0
        private static void HandleMatchComplete(Model.MatchData toObject, Lobby lob)
        {
            var mod = Mods.Mods.ByID(lob.mod);

            if (mod != null)
            {
                toObject.mod = mod.name;
            }
            else
            {
                toObject.mod = lob.mod;
            }
            LobbyManager.OnMatchComplete(toObject);
        }
Esempio n. 2
0
        public static void CalculateAfterMatch(Model.MatchData pMatchData)
        {
            //get the users and their MMR
            List <User> radiantPlayers = pMatchData.teams[0].players.Where(m => m != null).Select(player => Mongo.Users.FindOneAs <User>(Query.EQ("steam.steamid", player.steam_id))).ToList();
            List <User> direPlayers    = pMatchData.teams[1].players.Where(m => m != null).Select(player => Mongo.Users.FindOneAs <User>(Query.EQ("steam.steamid", player.steam_id))).ToList();

            var mod = Mods.Mods.ByName(pMatchData.mod);
            //avg the MMR
            double radiantAvg = radiantPlayers.Average(a => a.profile.mmr[mod.name]);
            double direAvg    = direPlayers.Average(a => a.profile.mmr[mod.name]);

            //calculate probability to win
            double qa             = Math.Pow(10, (radiantAvg / 400.0));
            double qb             = Math.Pow(10, (direAvg / 400.0));
            double radiantWinProb = qa / (qa + qb);
            double direWinProb    = qb / (qa + qb);

            //get factors for increment or decrement
            KFactor radiantFactor = KFactors.First(a => radiantAvg >= a.MinMmr && radiantAvg <= a.MaxMmr);
            KFactor direFactor    = KFactors.First(a => direAvg >= a.MinMmr && direAvg <= a.MaxMmr);

            //calculate the increments and decrements based on win only
            int incRadiant = 0;
            int incDire    = 0;

            if (pMatchData.good_guys_win)
            {
                incRadiant = (int)Math.Round(radiantFactor.Factor * (1.0 - radiantWinProb));
                incDire    = (int)Math.Round(direFactor.Factor * -direWinProb);
            }
            else
            {
                incRadiant = (int)Math.Round(radiantFactor.Factor * -radiantWinProb);
                incDire    = (int)Math.Round(direFactor.Factor * (1.0 - direWinProb));
            }

            foreach (var player in radiantPlayers)
            {
                if (player.profile.metrics == null)
                {
                    player.profile.metrics = new Dictionary <string, ModMetric>();
                }
                if (!player.profile.metrics.ContainsKey(mod.name))
                {
                    player.profile.metrics[mod.name] = new ModMetric();
                }
                if (pMatchData.good_guys_win)
                {
                    player.profile.metrics[mod.name].wins++;
                }
                else
                {
                    player.profile.metrics[mod.name].losses++;
                }
            }
            foreach (var player in direPlayers)
            {
                if (player.profile.metrics == null)
                {
                    player.profile.metrics = new Dictionary <string, ModMetric>();
                }
                if (!player.profile.metrics.ContainsKey(mod.name))
                {
                    player.profile.metrics[mod.name] = new ModMetric();
                }
                if (pMatchData.good_guys_win)
                {
                    player.profile.metrics[mod.name].losses++;
                }
                else
                {
                    player.profile.metrics[mod.name].wins++;
                }
            }

            //increment results
            radiantPlayers.ForEach(player => player.profile.mmr[mod.name] += incRadiant);
            direPlayers.ForEach(player => player.profile.mmr[mod.name]    += incDire);

            //todo: add individual increment and/or decrement based on gameplay

            //check roof, floor and save
            foreach (var player in radiantPlayers.Union(direPlayers))
            {
                if (player.profile.mmr[mod.name] > MmrRoof)
                {
                    player.profile.mmr[mod.name] = MmrRoof;
                }

                if (player.profile.mmr[mod.name] < MmrFloor)
                {
                    player.profile.mmr[mod.name] = MmrFloor;
                }

                foreach (var browser in Browsers.Find(m => m.user != null && m.user.Id == player.Id))
                {
                    browser.user = player;
                }
                Mongo.Users.Save(player);
            }
        }