public ActionResult Tag(int id, int?sea, int?hills, bool?assymetrical, string author, bool?isTeams, bool?is1v1, bool?ffa, bool?chickens, int?ffaTeams, bool?special, string springieCommands, MapSupportLevel mapSupportLevel) { var db = new ZkDataContext(); var r = db.Resources.Single(x => x.ResourceID == id); r.TaggedByAccountID = Global.AccountID; r.MapIsSpecial = special; r.MapWaterLevel = sea; r.MapHills = hills; r.MapIsAssymetrical = assymetrical; r.AuthorName = author; r.MapIsTeams = isTeams; r.MapIs1v1 = is1v1; r.MapIsFfa = ffa; r.MapIsChickens = chickens; r.MapSupportLevel = mapSupportLevel; r.MapFFAMaxTeams = ffaTeams; r.MapSpringieCommands = springieCommands; db.SaveChanges(); Global.Server.OnServerMapsChanged(); return(RedirectToAction("Detail", new { id = id })); }
public void UpdateWith(Autohost autohost) { IsAutohost = true; MinimalMapSupportLevelAutohost = autohost.MinimumMapSupportLevel; Mode = autohost.AutohostMode; InviteMMPlayers = autohost.InviteMMPlayers; MaxElo = autohost.MaxElo; MinElo = autohost.MinElo; MaxLevel = autohost.MaxLevel; MinLevel = autohost.MinLevel; MaxRank = autohost.MaxRank; MinRank = autohost.MinRank; Title = autohost.Title; MaxPlayers = autohost.MaxPlayers; dbAutohostIndex = autohost.AutohostID; FounderName = "Autohost #" + BattleID; ValidateAndFillDetails(); RunCommandDirectly <CmdMap>(null); }
public async Task <ActionResult> Tag(int id, int?sea, int?hills, bool?assymetrical, string author, bool?isTeams, bool?is1v1, bool?ffa, bool?chickens, int?ffaTeams, bool?special, string springieCommands, MapSupportLevel mapSupportLevel) { var db = new ZkDataContext(); var r = db.Resources.Single(x => x.ResourceID == id); if (r.MapSupportLevel != mapSupportLevel) { await Global.Server.GhostChanSay(GlobalConst.ModeratorChannel, string.Format("{0} has changed level of map {1} from {2} to {3}", Global.Account.Name, r.InternalName, r.MapSupportLevel, mapSupportLevel)); } r.TaggedByAccountID = Global.AccountID; r.MapIsSpecial = special; r.MapWaterLevel = sea; r.MapHills = hills; r.MapIsAssymetrical = assymetrical; r.AuthorName = author; r.MapIsTeams = isTeams; r.MapIs1v1 = is1v1; r.MapIsFfa = ffa; r.MapIsChickens = chickens; r.MapSupportLevel = mapSupportLevel; r.MapFFAMaxTeams = ffaTeams; r.MapSpringieCommands = springieCommands; db.SaveChanges(); await Global.Server.OnServerMapsChanged(); return(RedirectToAction("Detail", new { id = id })); }
/// <summary> /// Picks a map and writes a message if applicable /// </summary> /// <param name="context">The battle whose map needs selection</param> /// <remarks> /// <para> /// For Planetwars, picks the map given by the Planetwars matchmaker; else picks a featured map with the /// appropriate tags /// </para> /// <para>For team and chickens games, picks a map of appropriate size based on current player count</para> /// <para> /// For FFA, prefer maps that have a number of boxes equal to player count, or at least a number of boxes that is /// a multiple of player count /// </para> /// </remarks> public static Resource GetRecommendedMap(LobbyHostingContext context, MapSupportLevel minimumSupportLevel = MapSupportLevel.Featured, IQueryable <Resource> candidates = null) { var mode = context.Mode; using (var db = new ZkDataContext()) { List <Resource> list = null; var humanPlayers = context.Players.Count(x => !x.IsSpectator); var botPlayers = context.Bots.Count; var allyteams = context.Players.Where(x => !x.IsSpectator).Select(p => p.AllyID).Union(context.Bots.Select(b => b.AllyID)).Distinct().Count(); var level = context.IsMatchMakerGame ? MapSupportLevel.MatchMaker : minimumSupportLevel; switch (mode) { case AutohostMode.GameChickens: if (!context.Bots.Any(b => b.IsChicken)) { mode = AutohostMode.Teams; } break; case AutohostMode.GameFFA: allyteams = humanPlayers; break; case AutohostMode.None: if (allyteams > 2) { mode = AutohostMode.GameFFA; } if (context.Players.Where(x => !x.IsSpectator).Select(p => p.AllyID).Distinct().Count() == 1 && botPlayers > 0 && context.Bots.Any(b => b.IsChicken)) { mode = AutohostMode.GameChickens; } if (humanPlayers == 2 && botPlayers == 0 && allyteams == 2) { mode = AutohostMode.Game1v1; } break; } var ret = candidates ?? db.Resources.AsQueryable(); switch (mode) { case AutohostMode.Teams: case AutohostMode.None: ret = ret.Where( x => x.TypeID == ResourceType.Map && x.MapSupportLevel >= level && x.MapIsTeams != false && x.MapIsSpecial != true); if (humanPlayers > 11) { ret = ret.Where(x => x.MapHeight * x.MapHeight + x.MapWidth * x.MapWidth > 16 * 16); } else if (humanPlayers > 8) { ret = ret.Where( x => x.MapHeight * x.MapHeight + x.MapWidth * x.MapWidth > 16 * 16 && x.MapHeight * x.MapHeight + x.MapWidth * x.MapWidth <= 24 * 24); } else if (humanPlayers > 5) { ret = ret.Where(x => x.MapHeight * x.MapHeight + x.MapWidth * x.MapWidth <= 24 * 24 || x.MapIs1v1 == true); } else { ret = ret.Where(x => x.MapHeight * x.MapHeight + x.MapWidth * x.MapWidth <= 16 * 16 || x.MapIs1v1 == true); } list = ret.ToList(); break; case AutohostMode.Game1v1: list = ret.Where( x => x.TypeID == ResourceType.Map && x.MapSupportLevel >= level && x.MapIs1v1 == true && x.MapIsSpecial != true).ToList(); break; case AutohostMode.GameChickens: if (!UseNormalMapForChickens) { ret = ret.Where( x => x.TypeID == ResourceType.Map && x.MapSupportLevel >= level && x.MapIsSpecial != true && x.MapIsChickens == true); } if (!ret.Any() || UseNormalMapForChickens) { ret = ret.Where( x => x.TypeID == ResourceType.Map && x.MapSupportLevel >= level && x.MapIsSpecial != true && (x.MapWaterLevel == 1)); if (humanPlayers > 5) { ret = ret.Where(x => x.MapHeight * x.MapHeight + x.MapWidth * x.MapWidth > 16 * 16); } else if (humanPlayers > 4) { ret = ret.Where( x => x.MapHeight * x.MapHeight + x.MapWidth * x.MapWidth > 16 * 16 && x.MapHeight * x.MapHeight + x.MapWidth * x.MapWidth <= 24 * 24); } else if (humanPlayers > 2) { ret = ret.Where(x => x.MapHeight * x.MapHeight + x.MapWidth * x.MapWidth <= 24 * 24 || x.MapIs1v1 == true); } else { ret = ret.Where(x => x.MapHeight * x.MapHeight + x.MapWidth * x.MapWidth <= 16 * 16 || x.MapIs1v1 == true); } } list = ret.ToList(); break; case AutohostMode.GameFFA: list = ret.Where( x => x.TypeID == ResourceType.Map && x.MapSupportLevel >= level && x.MapIsFfa == true && x.MapFFAMaxTeams == allyteams) .ToList(); if (!list.Any()) { list = ret.Where( x => x.TypeID == ResourceType.Map && x.MapSupportLevel >= level && x.MapIsFfa == true && (humanPlayers % x.MapFFAMaxTeams == 0)).ToList(); } if (!list.Any()) { list = ret.Where(x => x.TypeID == ResourceType.Map && x.MapSupportLevel >= level && x.MapIsFfa == true).ToList(); } break; } if (list != null) { var r = new Random(); if (list.Count > 0) { var resource = list[r.Next(list.Count)]; return(resource); } } } return(null); }
public static IQueryable <Resource> FindResources(ResourceType type, string term, MapSupportLevel minimumSupportLevel = MapSupportLevel.None, bool ignoreExactMatches = false) { var db = new ZkDataContext(); var ret = db.Resources.AsQueryable(); ret = ret.Where(x => x.TypeID == type && x.MapSupportLevel >= minimumSupportLevel); var test = ret.Where(x => x.RapidTag == term || x.InternalName == term); if (test.Any() && !ignoreExactMatches) { return(test.OrderByDescending(x => x.MapSupportLevel).ThenByDescending(x => x.ResourceID)); } int i; var words = term.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (words.Length == 1 && int.TryParse(words[0], out i)) { ret = ret.Where(x => x.ResourceID == i); } else { foreach (var w in words) { var w1 = w; ret = ret.Where(x => SqlFunctions.PatIndex("%" + w1 + "%", x.InternalName) > 0); } } return(ret.OrderByDescending(x => x.MapSupportLevel).ThenByDescending(x => x.InternalName == term || x.RapidTag == term).ThenByDescending(x => x.ResourceID)); }
public async Task SwitchMinMapSupportLevel(MapSupportLevel lvl) { MinimalMapSupportLevelAutohost = lvl; }