/// <summary> /// Get The matched mods /// </summary> public string[] GetMatchedMods(Matchmake pMatch) { //get intersection mods only return(this.Mods.Intersect(pMatch.Mods) .Where(modName => Math.Abs(this.Ratings[modName] - pMatch.Ratings[modName]) < this.TryCount * RatingMargin)//and it has to fall in range .ToArray()); }
public static void TransmitMatchmakeUpdate(Matchmake matchmake, string[] fields) { //Generate message var upd = new JObject(); upd["msg"] = "colupd"; upd["ops"] = new JArray { matchmake.Update("matchmake", fields) }; Browsers.AsyncSendTo(m => m.matchmake != null && m.matchmake.id == matchmake.id, new TextArgs(upd.ToString(Formatting.None), "lobby"), req => { }); }
/// <summary> /// Merge pMatch into this /// </summary> public void MergeMatches(Matchmake pMatch) { this.Users = this.Users.Union(pMatch.Users).ToList <User>(); this.Mods = this.GetMatchedMods(pMatch); //give priority to localized matches if (pMatch.Region != ServerRegion.UNKNOWN) { this.Region = pMatch.Region; } this.UpdateRating(); }
/// <summary> /// Check if the two matches match the criteria /// </summary> /// <param name="pTeam">Is this a team MM?</param> public bool IsMatch(Matchmake pMatch, bool pTeam = false) { bool result = false; //not the same match if (this != pMatch && pMatch.Status != MatchmakeStatus.AlreadyMatched && //not already matched (this.Region == ServerRegion.UNKNOWN || pMatch.Region == ServerRegion.UNKNOWN || this.Region == pMatch.Region) && //all or same region (pTeam || this.Users.Count <= (MatchmakeManager.TEAM_PLAYERS - pMatch.Users.Count))) //there is room for everybody { result = this.GetMatchedMods(pMatch).Length > 0; } return(result); }
public static Matchmake CreateMatchmake(User[] users, Mod[] mods) { var Users = new List <User>(TEAM_PLAYERS); foreach (var user in users) { //loop through each mod foreach (var mod in mods) { //if the user does not have a MMR for it if (user.profile.mmr == null) { user.profile.mmr = new Dictionary <string, int>(); } if (!user.profile.mmr.ContainsKey(mod.name)) { //Assign base user.profile.mmr.Add(mod.name, BaseMmr); } } Mongo.Users.Save(user); Users.Add(user); } var matchmake = new Matchmake() { id = Utils.RandomString(17), Users = Users, Mods = mods.Select(x => x.name).ToArray(), TryCount = 1 }; matchmake.UpdateRating(); log.InfoFormat("User {0} started matchmaking in a party.", Users.FirstOrDefault().profile.name); //add to the queue lock (inMatchmaking) { inMatchmaking.Add(matchmake); } return(matchmake); }
public static Matchmake CreateMatchmake(User user, Mod[] mods, ServerRegion region = ServerRegion.UNKNOWN) { //loop through each mod foreach (var mod in mods) { //if the user does not have a MMR for it if (user.profile.mmr == null) { user.profile.mmr = new Dictionary <string, int>(); } if (!user.profile.mmr.ContainsKey(mod.name)) { //Assign base user.profile.mmr.Add(mod.name, BaseMmr); } } Mongo.Users.Save(user); var matchmake = new Matchmake() { id = Utils.RandomString(17), Users = new List <User>(TEAM_PLAYERS) { user }, Mods = mods.Select(x => x.name).ToArray(), Region = region, Ratings = user.profile.mmr.Where(x => mods.Any(y => x.Key == y.name)).ToDictionary(x => x.Key, x => x.Value), TryCount = 1 }; log.InfoFormat("User {0} started matchmaking.", user.profile.name); //add to the queue lock (inMatchmaking) { inMatchmaking.Add(matchmake); } return(matchmake); }