public ZkLobbyServer(string geoIPpath, IPlanetwarsEventCreator creator, ITopPlayerProvider topPlayerProvider) { RatingSystems.Init(); TopPlayerProvider = topPlayerProvider; PlanetWarsEventCreator = creator; var entry = Assembly.GetExecutingAssembly(); Version = entry.GetName().Version.ToString(); Engine = MiscVar.DefaultEngine; SpringPaths = new SpringPaths(GlobalConst.SpringieDataDir, false, false); Downloader = new PlasmaDownloader.PlasmaDownloader(null, SpringPaths); Downloader.GetResource(DownloadType.ENGINE, MiscVar.DefaultEngine); Downloader.PackageDownloader.DoMasterRefresh(); Game = Downloader.PackageDownloader.GetByTag(GlobalConst.DefaultZkTag).InternalName; LoginChecker = new LoginChecker(this, geoIPpath); SteamWebApi = new SteamWebApi(GlobalConst.SteamAppID, new Secrets().GetSteamWebApiKey()); chatRelay = new ChatRelay(this, new List <string>() { "zkdev", "sy", "moddev", "weblobbydev", "ai", "zk", "zkmap", "springboard", GlobalConst.ModeratorChannel, GlobalConst.CoreChannel }); textCommands = new ServerTextCommands(this); ChannelManager = new ChannelManager(this); MatchMaker = new MatchMaker(this); battleListUpdater = new BattleListUpdater(this); PartyManager = new PartyManager(this); PlanetWarsMatchMaker = new PlanetWarsMatchMaker(this); }
/// <summary> /// Go to home page; also updates news read dates /// </summary> public ActionResult Index() { // TODO: make two separate pages -- one for logged in users, one for not-logged in users // logged in users see their user profile // non-logged in users see promotional page var db = new ZkDataContext(); if (!Global.IsAccountAuthorized) { return(View("Splash")); } // TODO: randomized backgrounds move here var result = new IndexResult { Spotlight = SpotlightHandler.GetRandom(), Top10Players = RatingSystems.GetRatingSystem(RatingCategory.MatchMaking).GetTopPlayers(10), WikiRecentChanges = MediaWikiRecentChanges.LoadRecentChanges(), LobbyStats = MemCache.GetCached("lobby_stats", GetCurrentLobbyStats, 60 * 2), News = db.News.Where(x => x.Created < DateTime.UtcNow).OrderByDescending(x => x.Created), Headlines = GetHeadlines(db), NewThreads = GetNewForumThreads(db) }; return(View("HomeIndex", result)); }
public ActionResult DeleteFromRatings(int accountID) { var db = new ZkDataContext(); Account acc = db.Accounts.SingleOrDefault(x => x.AccountID == accountID); if (acc == null) { return(Content("Invalid accountID")); } Account adminAcc = Global.Account; Global.Server.GhostChanSay(GlobalConst.ModeratorChannel, string.Format("Ratings deleted for {0} {1} by {2}", acc.Name, Url.Action("Detail", "Users", new { id = acc.AccountID }, "http"), adminAcc.Name)); var battles = db.SpringBattles.Where(x => x.SpringBattlePlayers.Where(p => !p.IsSpectator).Any(p => p.AccountID == accountID)) .Include(x => x.ResourceByMapResourceID) .Include(x => x.SpringBattlePlayers) .Include(x => x.SpringBattleBots); battles.Update(x => new SpringBattle() { ApplicableRatings = 0 }); db.SaveChanges(); battles.ToList().ForEach(x => RatingSystems.RemoveResult(x)); return(RedirectToAction("Detail", "Users", new { id = acc.AccountID })); }
private static void ProcessElos(SpringBattleContext result, ZkLobbyServer.ZkLobbyServer server, ZkDataContext db, SpringBattle sb) { bool noElo = result.OutputExtras.Any(x => x?.StartsWith("noElo", true, System.Globalization.CultureInfo.CurrentCulture) == true); sb.CalculateAllElo(noElo); if (!noElo) { RatingSystems.ProcessResult(sb); } foreach (var u in sb.SpringBattlePlayers.Where(x => !x.IsSpectator)) { u.Account.CheckLevelUp(); } db.SaveChanges(); try { foreach (Account a in sb.SpringBattlePlayers.Where(x => !x.IsSpectator).Select(x => x.Account)) { server.PublishAccountUpdate(a); server.PublishUserProfileUpdate(a); } } catch (Exception ex) { Trace.TraceError("error updating extension data: {0}", ex); } }
public List <float> GetAllyteamWinChances() { if (!IsRatedMatch()) { return(new List <float>()); } return(RatingSystems.GetRatingSystem(GetRatingCategory()).PredictOutcome(SpringBattlePlayers.Where(x => !x.IsSpectator).OrderBy(x => x.AllyNumber).GroupBy(x => x.AllyNumber).Select(x => x.Select(y => y.Account).ToList()).ToList(), StartTime)); }
public IList <GraphPoint> GetDailyValues(DateTime fromTime, DateTime toTime) { Dictionary <DateTime, float> ratings = RatingSystems.GetRatingSystem(Category).GetPlayerRatingHistory(AccountID); return(ratings.Where(x => x.Key >= fromTime && x.Key <= toTime).Select(x => new GraphPoint() { Day = x.Key, Value = x.Value, }).ToList()); }
public PlayerEntry(User user, List <MatchMakerSetup.Queue> queueTypes, PartyManager.Party party) { Party = party; QueueTypes = queueTypes; LobbyUser = user; float recentWinChance = RatingSystems.GetRatingSystem(RatingCategory.MatchMaking).GetAverageRecentWinChance(user.AccountID); double bonusElo = -400 * Math.Log(1 / recentWinChance - 1) / Math.Log(10); bonusElo = Math.Min(300, Math.Max(-300, bonusElo)); MinConsideredElo = (int)Math.Round(LobbyUser.EffectiveMmElo + DynamicConfig.Instance.MmEloBonusMultiplier * bonusElo); //Trace.TraceInformation($"Player {user.AccountID} with recent win chance {recentWinChance} receives {DynamicConfig.Instance.MmEloBonusMultiplier} * {bonusElo} bonusElo => {MinConsideredElo} Effective Elo"); }
public BattleModel(SpringBattle bat) { WholeHistoryRating whr = RatingSystems.GetRatingSystem(bat.GetRatingCategory()) as WholeHistoryRating; players = bat.SpringBattlePlayers.Where(x => !x.IsSpectator).Select(player => new PlayerModel() { rating = whr.GetInternalRating(player.AccountID, bat.StartTime)?.GetElo() + WholeHistoryRating.RatingOffset, stdev = whr.GetInternalRating(player.AccountID, bat.StartTime)?.GetEloStdev(), accountId = player.AccountID, }).ToList(); id = bat.SpringBattleID; }
public List <float> GetAllyteamWinChances() { try { if (IsRatedMatch()) { return(RatingSystems.GetRatingSystem(GetRatingCategory()).PredictOutcome(SpringBattlePlayers.Where(x => !x.IsSpectator).OrderBy(x => x.AllyNumber).GroupBy(x => x.AllyNumber).Select(x => x.Select(y => y.Account).ToList()).ToList(), StartTime)); } } catch (Exception ex) { Trace.TraceWarning("Invalid rating settings for B" + SpringBattleID + ", unable to calculate win chances. \n" + ex); } return(new List <float>(new float[GetAllyteamIds().Count])); }
public ZkLobbyServer(string geoIPpath, IPlanetwarsEventCreator creator) { RatingSystems.Init(); MapRatings.Init(); PlanetWarsEventCreator = creator; var entry = Assembly.GetExecutingAssembly(); Version = entry.GetName().Version.ToString(); Engine = MiscVar.DefaultEngine; SpringPaths = new SpringPaths(GlobalConst.SpringieDataDir, false, false); Downloader = new PlasmaDownloader.PlasmaDownloader(null, SpringPaths); Downloader.GetResource(DownloadType.ENGINE, MiscVar.DefaultEngine); Downloader.PackageDownloader.DoMasterRefresh(); Game = MiscVar.LastRegisteredZkVersion; LoginChecker = new LoginChecker(this, geoIPpath); SteamWebApi = new SteamWebApi(GlobalConst.SteamAppID, new Secrets().GetSteamWebApiKey()); chatRelay = new ChatRelay(this, new List <string>() { "zkdev", "sy", "moddev", "weblobbydev", "ai", "zk", "zkmap", "springboard", GlobalConst.ModeratorChannel, GlobalConst.CoreChannel, "off-topic", "support", "modding", "crashreports" }); textCommands = new ServerTextCommands(this); ChannelManager = new ChannelManager(this); MatchMaker = new MatchMaker(this); battleListUpdater = new BattleListUpdater(this); PartyManager = new PartyManager(this); PlanetWarsMatchMaker = new PlanetWarsMatchMaker(this); NewsListManager = new NewsListManager(this); LadderListManager = new LadderListManager(this); ForumListManager = new ForumListManager(this); SpawnAutohosts(); RatingSystems.GetRatingSystems().ForEach(x => x.RatingsUpdated += (sender, data) => { var db = new ZkDataContext(); var updatedUsers = ConnectedUsers.Select(c => c.Value.User.AccountID).Intersect(data.affectedPlayers).ToHashSet(); db.Accounts.Where(acc => updatedUsers.Contains(acc.AccountID)).ForEach(p => { PublishAccountUpdate(p); PublishUserProfileUpdate(p); }); }); }
public bool IsTop20(int lobbyID) { if (topPlayersExceptions.Contains(lobbyID)) { return(true); } if (RatingSystems.GetRatingSystem(RatingCategory.Casual).GetPlayerRating(lobbyID).Rank <= 20) { return(true); } if (RatingSystems.GetRatingSystem(RatingCategory.MatchMaking).GetPlayerRating(lobbyID).Rank <= 20) { return(true); } return(false); }
public ActionResult SetApplicableRatings(int BattleID, bool MatchMaking, bool Casual, bool PlanetWars) { SpringBattle battle; using (var db = new ZkDataContext()) { battle = db.SpringBattles.Where(x => x.SpringBattleID == BattleID) .Include(x => x.ResourceByMapResourceID) .Include(x => x.SpringBattlePlayers) .Include(x => x.SpringBattleBots) .FirstOrDefault(); battle.ApplicableRatings = (MatchMaking ? Ratings.RatingCategoryFlags.MatchMaking : 0) | (Casual ? Ratings.RatingCategoryFlags.Casual : 0) | (PlanetWars ? Ratings.RatingCategoryFlags.Planetwars : 0); db.SaveChanges(); } RatingSystems.ReprocessResult(battle); return(Detail(BattleID)); }
public void CalculateAllElo(bool noElo = false) { if (IsEloProcessed) { return; } if (!noElo) { ResetApplicableRatings(); } if (IsRatedMatch()) { Rank = SpringBattlePlayers.Select(x => x.Account.Rank).Max(); } if (Duration > GlobalConst.MinDurationForXP) { if (!IsRatedMatch()) { WinnerTeamXpChange = GlobalConst.XpForMissionOrBotsVictory; LoserTeamXpChange = GlobalConst.XpForMissionOrBots; } else { var losers = SpringBattlePlayers.Where(x => !x.IsSpectator && !x.IsInVictoryTeam).Select(x => x.Account).ToList(); var winners = SpringBattlePlayers.Where(x => !x.IsSpectator && x.IsInVictoryTeam).Select(x => x.Account).ToList(); if ((losers.Count > 0) && (winners.Count > 0)) { List <float> probabilities = RatingSystems.GetRatingSystem(GetRatingCategory()).PredictOutcome(new List <ICollection <Account> > { winners, losers }, StartTime); var eWin = probabilities[0]; var eLose = probabilities[1]; WinnerTeamXpChange = (int)(20 + (300 + 600 * (1 - eWin)) / (3.0 + winners.Count)); // a bit ugly this sets to battle directly LoserTeamXpChange = (int)(20 + (200 + 400 * (1 - eLose)) / (2.0 + losers.Count)); } } ApplyXpChanges(); } IsEloProcessed = true; }
// GET: Charts/Ratings public ActionResult Ratings(ChartsModel model) { model = model ?? new ChartsModel(); var to = model.To.Date; var from = model.From.Date; var providers = new List <IGraphDataProvider>(); if (model.UserId != null) { providers.AddRange(model.UserId.Select(x => (IGraphDataProvider) new RatingHistory(x, model.RatingCategory)).ToList()); //providers.AddRange(model.UserId.Select(x => (IGraphDataProvider)new LadderRatingHistory(x, model.RatingCategory)).ToList()); //75% confidence } var series = new List <GraphSeries>(); foreach (var prov in providers) { series.Add(new GraphSeries() { Title = prov.Title, Data = prov.GetDailyValues(from, to) }); } model.GraphingData = series; if (model.UserId != null) { using (var db = new ZkDataContext()) { model.UserStats = model.UserId.Select(id => new UserStats() { Account = db.Accounts.Where(x => x.AccountID == id).Include(x => x.Faction).Include(x => x.Clan).FirstOrDefault(), RankStats = RatingSystems.ratingCategories.Select(s => new RankStats() { System = s.ToString(), CurrentRating = RatingSystems.GetRatingSystem(s).GetPlayerRating(id), Bracket = RatingSystems.GetRatingSystem(s).GetPercentileBracket(db.Accounts.FirstOrDefault(a => a.AccountID == id).Rank), }).ToList(), }).ToList(); } } return(View("ChartsRatings", model)); }
public Dictionary <int, float> GetAllyteamWinChances() { var allyteams = SpringBattlePlayers.Where(x => !x.IsSpectator).OrderBy(x => x.AllyNumber).Select(x => x.AllyNumber).Distinct().ToList(); try { if (IsRatedMatch()) { var chances = RatingSystems.GetRatingSystem(GetRatingCategory()).PredictOutcome(SpringBattlePlayers.Where(x => !x.IsSpectator).OrderBy(x => x.AllyNumber).GroupBy(x => x.AllyNumber).Select(x => x.Select(y => y.Account).ToList()).ToList(), StartTime); return(allyteams.Zip(chances, (k, v) => new { k, v }).ToDictionary(x => x.k, x => x.v)); } } catch (Exception ex) { Trace.TraceWarning("Invalid rating settings for B" + SpringBattleID + ", unable to calculate win chances. \n" + ex); } return(allyteams.ToDictionary(x => x, x => 1f / allyteams.Count)); }
public PlayerRating GetBestRating() { var casual = RatingSystems.GetRatingSystem(RatingCategory.Casual).GetPlayerRating(AccountID); var mm = RatingSystems.GetRatingSystem(RatingCategory.MatchMaking).GetPlayerRating(AccountID); var pw = RatingSystems.GetRatingSystem(RatingCategory.Planetwars).GetPlayerRating(AccountID); if ((casual.Elo >= mm.Elo || mm.Rank == int.MaxValue) && casual.Rank < int.MaxValue) { return(casual); } if ((mm.Elo >= casual.Elo || casual.Rank == int.MaxValue) && mm.Rank < int.MaxValue) { return(mm); } //ignore pw return(WholeHistoryRating.DefaultRating); }
public PlayerRating GetBestRating() { var casual = RatingSystems.GetRatingSystem(RatingCategory.Casual).GetPlayerRating(this); var mm = RatingSystems.GetRatingSystem(RatingCategory.MatchMaking).GetPlayerRating(this); var pw = RatingSystems.GetRatingSystem(RatingCategory.Planetwars).GetPlayerRating(this); if ((casual.Elo >= mm.Elo || mm.Uncertainty > GlobalConst.MaxLadderUncertainty) && casual.Uncertainty < GlobalConst.MaxLadderUncertainty) { return(casual); } if ((mm.Elo >= casual.Elo || casual.Uncertainty > GlobalConst.MaxLadderUncertainty) && mm.Uncertainty < GlobalConst.MaxLadderUncertainty) { return(mm); } //ignore pw return(new PlayerRating(int.MaxValue, 1, 0, float.PositiveInfinity)); }
public ActionResult SetApplicableRatings(int BattleID, bool MatchMaking, bool Casual, bool PlanetWars) { SpringBattle battle; using (var db = new ZkDataContext()) { battle = db.SpringBattles.Where(x => x.SpringBattleID == BattleID) .Include(x => x.ResourceByMapResourceID) .Include(x => x.SpringBattlePlayers) .Include(x => x.SpringBattleBots) .FirstOrDefault(); if (battle.HasBots || battle.SpringBattlePlayers.Select(x => x.AllyNumber).Distinct().Count() < 2) { return(Content("Battle type currently not supported for ratings")); } battle.ApplicableRatings = (MatchMaking ? RatingCategoryFlags.MatchMaking : 0) | (Casual ? RatingCategoryFlags.Casual : 0) | (PlanetWars ? RatingCategoryFlags.Planetwars : 0); db.SaveChanges(); } RatingSystems.ReprocessResult(battle); return(Detail(BattleID)); }
public ActionResult ResetRatings() { using (var db = new ZkDataContext()) { db.SpringBattles.Where(x => x.ApplicableRatings == RatingCategoryFlags.Planetwars || x.ApplicableRatings == (RatingCategoryFlags.Planetwars | RatingCategoryFlags.Casual)).Update(x => new SpringBattle() { ApplicableRatings = RatingCategoryFlags.Casual }); db.AccountRatings.Where(x => x.RatingCategory == RatingCategory.Planetwars).Update(x => new AccountRating() { Percentile = WholeHistoryRating.DefaultRating.Percentile, Rank = WholeHistoryRating.DefaultRating.Rank, RealElo = WholeHistoryRating.DefaultRating.RealElo, Uncertainty = 1000, Elo = WholeHistoryRating.DefaultRating.Elo, }); } (RatingSystems.GetRatingSystem(RatingCategory.Planetwars) as WholeHistoryRating).ResetAll(); return(RedirectToAction("Index")); }
public ActionResult SetWhrAlias(int accountID, string alias) { int aliasId; if (!int.TryParse(alias, out aliasId)) { return(Content("Not a valid number")); } using (var db = new ZkDataContext()) { var aliasAcc = db.Accounts.Find(aliasId); if (aliasAcc == null) { return(Content("No account found with this id")); } var acc = db.Accounts.Find(accountID); if (acc == null) { return(Content("Invalid accountID")); } var battles = db.SpringBattles.Where(x => x.SpringBattlePlayers.Where(p => !p.IsSpectator).Any(p => p.AccountID == accountID)) .Include(x => x.ResourceByMapResourceID) .Include(x => x.SpringBattlePlayers) .Include(x => x.SpringBattleBots) .ToList(); battles.ForEach(x => RatingSystems.RemoveResult(x)); acc.WhrAlias = aliasId; db.SaveChanges(); RatingSystems.UpdateRatingIds(); battles.ForEach(x => RatingSystems.ReprocessResult(x)); return(Content(string.Format("{0} now plays for {1}", acc, aliasAcc))); } }
/// <summary> /// Mark all users as disconnected, fixes chat history repeat /// </summary> public void Shutdown() { Broadcast(ConnectedUsers.Values, new Say() { User = GlobalConst.NightwatchName, Text = "Zero-K server restarted for upgrade, be back soon", Place = SayPlace.MessageBox, }); RatingSystems.BackupToDB(); var db = new ZkDataContext(); foreach (var u in ConnectedUsers.Values) { if (u != null && u.IsLoggedIn) { var acc = db.Accounts.Find(u.User.AccountID); acc.LastLogout = DateTime.UtcNow; } } db.SaveChanges(); // close all existing client connections foreach (var usr in ConnectedUsers.Values) { if (usr != null) { foreach (var con in usr.Connections.Keys) { con?.RequestClose(); } } } //foreach (var bat in Battles.Values) if (bat != null && bat.spring.IsRunning) bat.spring.ExitGame(); }
public PlayerRating GetRating(RatingCategory category) { return(RatingSystems.GetRatingSystem(category).GetPlayerRating(AccountID)); }
//stores replay, springbattle, processes rating and xp, returns whether battle ended normally public static bool SubmitSpringBattleResult(SpringBattleContext result, ZkLobbyServer.ZkLobbyServer server, Action <BattleDebriefing> consumer) { var ret = new BattleDebriefing(); try { bool isValidGame = true; if (!result.GameEndedOk) { ret.Message = "Game didn't end properly"; isValidGame = false; } if (result.IsCheating) { ret.Message = "Cheats were enabled during this game"; isValidGame = false; } var db = new ZkDataContext(); var text = new StringBuilder(); var sb = SaveSpringBattle(result, db); if (isValidGame) { StoreAwards(result.OutputExtras, sb, db); } StoreLogs(result.OutputExtras, sb, db); if (result.LobbyStartContext.Mode == AutohostMode.Planetwars) { ProcessPlanetWars(result, server, sb, db, text); } Dictionary <int, int> orgLevels = sb.SpringBattlePlayers.Select(x => x.Account).ToDictionary(x => x.AccountID, x => x.Level); //fill in applicable ratings bool noElo = !isValidGame || result.LobbyStartContext.ModOptions.Any(x => x.Key.ToLower() == "noelo" && x.Value != "0" && x.Value != "false"); if (!noElo) { RatingSystems.FillApplicableRatings(sb, result); } if (isValidGame) { ProcessXP(result, server, db, sb); } ret.Url = string.Format("{1}/Battles/Detail/{0}", sb.SpringBattleID, GlobalConst.BaseSiteUrl); ret.ServerBattleID = sb.SpringBattleID; server.GhostSay( new Say() { Text = string.Format("BATTLE DETAILS AND REPLAY ----> {0} <-----", ret.Url), IsEmote = true, Place = SayPlace.Battle, User = GlobalConst.NightwatchName }, result.LobbyStartContext.BattleID); foreach (var p in sb.SpringBattlePlayers.Where(x => !x.IsSpectator)) { ret.DebriefingUsers[p.Account.Name] = new BattleDebriefing.DebriefingUser() { AccountID = p.AccountID, LoseTime = p.LoseTime ?? -1, AllyNumber = p.AllyNumber, IsInVictoryTeam = p.IsInVictoryTeam, EloChange = 0, IsRankdown = false, IsRankup = false, NewElo = -1, NextRankElo = -1, PrevRankElo = -1, NewRank = p.Account.Rank, XpChange = p.XpChange ?? 0, NewXp = p.Account.Xp, NextLevelXp = Account.GetXpForLevel(p.Account.Level + 1), PrevLevelXp = Account.GetXpForLevel(p.Account.Level), IsLevelUp = orgLevels[p.AccountID] < p.Account.Level, Awards = sb.AccountBattleAwards.Where(x => x.AccountID == p.AccountID).Select(x => new BattleDebriefing.DebriefingAward() { Value = x.Value, Key = x.AwardKey, Description = x.AwardDescription }).ToList() }; } //send to rating if (!noElo) { RatingSystems.ProcessResult(sb, result, new PendingDebriefing() { debriefingConsumer = consumer, partialDebriefing = ret, battle = sb, }); } Trace.TraceInformation("Battle ended: Server exited for B" + sb.SpringBattleID); db.SaveChanges(); return(true); } catch (Exception ex) { var data = JsonConvert.SerializeObject(result); Trace.TraceError($"{ex}\nData:\n{data}"); ret.Message = "Error processing game result: " + ex.Message; return(false); } }
/// <summary> /// Go to home page; also updates news read dates /// </summary> public ActionResult Index() { var db = new ZkDataContext(); var result = new IndexResult() { Spotlight = SpotlightHandler.GetRandom(), Top10Players = RatingSystems.GetRatingSystem(RatingCategory.MatchMaking).GetTopPlayers(10), WikiRecentChanges = MediaWikiRecentChanges.LoadRecentChanges() }; result.LobbyStats = MemCache.GetCached("lobby_stats", GetCurrentLobbyStats, 60 * 2); result.News = db.News.Where(x => x.Created < DateTime.UtcNow).OrderByDescending(x => x.Created); if (Global.Account != null) { result.Headlines = db.News.Where( x => x.Created <DateTime.UtcNow && x.HeadlineUntil != null && x.HeadlineUntil> DateTime.UtcNow && !x.ForumThread.ForumThreadLastReads.Any(y => y.AccountID == Global.AccountID && y.LastRead != null)). OrderByDescending(x => x.Created).ToList(); if (result.Headlines.Any()) { foreach (var h in result.Headlines) { h.ForumThread.UpdateLastRead(Global.AccountID, false); } db.SaveChanges(); } } else { result.Headlines = new List <News>(); } var accessibleThreads = db.ForumThreads.Where(x => x.RestrictedClanID == null || x.RestrictedClanID == Global.ClanID); accessibleThreads = accessibleThreads.Where(x => x.ForumCategory.ForumMode != ForumMode.Archive); if (!Global.IsAccountAuthorized) { result.NewThreads = accessibleThreads.OrderByDescending(x => x.LastPost).Take(10).Select(x => new NewThreadEntry() { ForumThread = x }); } else { result.NewThreads = (from t in accessibleThreads let read = t.ForumThreadLastReads.FirstOrDefault(x => x.AccountID == Global.AccountID) let readForum = t.ForumCategory.ForumLastReads.FirstOrDefault(x => x.AccountID == Global.AccountID) where (read == null || t.LastPost > read.LastRead) && (readForum == null || t.LastPost > readForum.LastRead) orderby t.LastPost descending select new NewThreadEntry { ForumThread = t, WasRead = read != null, WasWritten = read != null && read.LastPosted != null }). Take(10); } return(View("HomeIndex", result)); }
public LadderListManager(ZkLobbyServer zkLobbyServer) { server = zkLobbyServer; RatingSystems.GetRatingSystem(RatingCategory.MatchMaking).AddTopPlayerUpdateListener(this, LadderListLength); TopPlayersUpdated(RatingSystems.GetRatingSystem(RatingCategory.MatchMaking).GetTopPlayers(LadderListLength)); //make sure ladderlist is never null }
public override async Task ExecuteArmed(ServerBattle battle, Say e) { var b = battle; List <IEnumerable <Account> > teams; RatingCategory cat = RatingCategory.Casual; if (b.IsMatchMakerBattle) { cat = RatingCategory.MatchMaking; } if (b.Mode == PlasmaShared.AutohostMode.Planetwars) { cat = RatingCategory.Planetwars; } using (var db = new ZkDataContext()) { if (battle.IsInGame) { teams = b.spring.LobbyStartContext?.Players.Where(u => !u.IsSpectator) .GroupBy(u => u.AllyID) .Select(x => x.Select(p => Account.AccountByName(db, p.Name))).ToList(); } else { switch (battle.Mode) { case PlasmaShared.AutohostMode.Game1v1: teams = b.Users.Values.Where(u => !u.IsSpectator) .GroupBy(u => u.Name) .Select(x => x.Select(p => Account.AccountByName(db, p.Name))).ToList(); break; case PlasmaShared.AutohostMode.Teams: await battle.SayBattle($"The battle will be balanced when it starts"); return; default: teams = b.Users.Values.Where(u => !u.IsSpectator) .GroupBy(u => u.AllyNumber) .Select(x => x.Select(p => Account.AccountByName(db, p.Name))).ToList(); break; } } if (teams.Count < 2) { await battle.SayBattle($"!predict needs at least two human teams to work"); return; } var chances = RatingSystems.GetRatingSystem(cat).PredictOutcome(teams, DateTime.UtcNow); for (int i = 0; i < teams.Count; i++) { await battle.SayBattle($"Team {teams[i].OrderByDescending(x => x.GetRating(cat).Elo).First().Name} has a {Math.Round(1000 * chances[i]) / 10}% chance to win"); } } }
public override async Task ExecuteArmed(ServerBattle battle, Say e) { var b = battle; List <IEnumerable <Account> > teams; RatingCategory cat = RatingCategory.Casual; if (b.IsMatchMakerBattle) { cat = RatingCategory.MatchMaking; } if (b.Mode == PlasmaShared.AutohostMode.Planetwars) { cat = RatingCategory.Planetwars; } using (var db = new ZkDataContext()) { if (battle.IsInGame) { teams = b.spring.LobbyStartContext?.Players.Where(u => !u.IsSpectator) .GroupBy(u => u.AllyID) .Select(x => x.Select(p => Account.AccountByName(db, p.Name))).ToList(); } else { switch (battle.Mode) { case PlasmaShared.AutohostMode.Game1v1: teams = b.Users.Values.Where(u => !u.IsSpectator) .GroupBy(u => u.Name) .Select(x => x.Select(p => Account.AccountByName(db, p.Name))).ToList(); break; case PlasmaShared.AutohostMode.Teams: teams = PartitionBalance.Balance(battle.IsCbalEnabled ? Balancer.BalanceMode.ClanWise : Balancer.BalanceMode.Normal, b.Users.Values.Where(u => !u.IsSpectator).Select(x => x.LobbyUser).Select(x => new PartitionBalance.PlayerItem(x.AccountID, x.EffectiveElo, x.Clan, x.PartyID)).ToList()) .Players .GroupBy(u => u.AllyID) .Select(x => x.Select(p => db.Accounts.Where(a => a.AccountID == p.LobbyID).FirstOrDefault())).ToList(); break; default: teams = b.Users.Values.Where(u => !u.IsSpectator) .GroupBy(u => u.AllyNumber) .Select(x => x.Select(p => Account.AccountByName(db, p.Name))).ToList(); break; } } if (teams.Count < 2) { await battle.SayBattle($"!predict needs at least two human teams to work"); return; } var chances = RatingSystems.GetRatingSystem(cat).PredictOutcome(teams, DateTime.UtcNow); for (int i = 0; i < teams.Count; i++) { await battle.SayBattle($"Team {teams[i].OrderByDescending(x => x.GetRating(cat).Elo).Select(x => x.Name).Aggregate((a, y) => a + ", " + y)} has a {Math.Round(1000 * chances[i]) / 10}% chance to win"); } } }
public PlayerRating GetRating(RatingCategory category) { return(RatingSystems.GetRatingSystem(category).GetPlayerRating(this)); }