internal static string DeriveGamemodeFlags(Gamemode gamemode) { var gamemodes = new List <string>(); if (gamemode.HasFlag(Gamemode.Casual)) { gamemodes.Add(Constant.GamemodeToString(Gamemode.Casual)); } if (gamemode.HasFlag(Gamemode.Unranked)) { gamemodes.Add(Constant.GamemodeToString(Gamemode.Unranked)); } if (gamemode.HasFlag(Gamemode.Ranked)) { gamemodes.Add(Constant.GamemodeToString(Gamemode.Ranked)); } if (gamemode.HasFlag(Gamemode.All)) { gamemodes.Add(Constant.GamemodeToString(Gamemode.All)); } return(string.Join(',', gamemodes)); }
/// <summary> /// Toggles maps in Overwatch. /// </summary> /// <param name="modesEnabled">The modes enabled in the overwatch game.</param> /// <param name="currentEvent">The current Overwatch event.</param> /// <param name="toggleAction">Determines if all maps should be enabled, disabled or neither before toggling.</param> /// <param name="maps">Maps that should be toggled.</param> /// <remarks> /// <include file="docs.xml" path="doc/getMaps" /> /// </remarks> /// <include file='docs.xml' path='doc/ToggleMap2/example'></include> /// <seealso cref="Map"/> /// <seealso cref="ToggleMap(ToggleAction, Map[])"/> public void ToggleMap(Gamemode modesEnabled, OWEvent currentEvent, ToggleAction toggleAction, params Map[] maps) { using (LockHandler.Interactive) { int waitTime = 1; GoToSettings(); LeftClick(Points.SETTINGS_MAPS, 1000); // Clicks "Maps" button (SETTINGS/MAPS/) // Click Disable All or Enable All in custom games if ta doesnt equal ToggleAction.None. if (toggleAction == ToggleAction.DisableAll) { LeftClick(Points.SETTINGS_MAPS_DISABLE_ALL, 250); } else if (toggleAction == ToggleAction.EnableAll) { LeftClick(Points.SETTINGS_MAPS_ENABLE_ALL, 250); } // Get the modes enabled state in a bool in alphabetical order. bool[] enabledModes = new bool[] { modesEnabled.HasFlag(Gamemode.Assault), modesEnabled.HasFlag(Gamemode.AssaultEscort), modesEnabled.HasFlag(Gamemode.CaptureTheFlag), modesEnabled.HasFlag(Gamemode.Control), modesEnabled.HasFlag(Gamemode.Deathmatch), modesEnabled.HasFlag(Gamemode.Elimination), modesEnabled.HasFlag(Gamemode.Escort), modesEnabled.HasFlag(Gamemode.JunkensteinsRevenge), modesEnabled.HasFlag(Gamemode.Lucioball), modesEnabled.HasFlag(Gamemode.MeisSnowballOffensive), modesEnabled.HasFlag(Gamemode.Skirmish), modesEnabled.HasFlag(Gamemode.TeamDeathmatch), modesEnabled.HasFlag(Gamemode.YetiHunter), }; if (enabledModes.Length != Enum.GetNames(typeof(Gamemode)).Length) { throw new NotImplementedException("The length of enabledModes does not equal the length of the gamemodes in the Gamemode enum."); } List <int> selectMap = new List <int>(); int mapcount = 0; // For each enabled mode... for (int i = 0; i < enabledModes.Length; i++) { if (enabledModes[i]) { Gamemode emi = (Gamemode)Enum.Parse(typeof(Gamemode), Enum.GetNames(typeof(Gamemode))[i]); //enabledmodesindex List <Map> allowedmaps = Map.GetMapsInGamemode(emi, currentEvent).ToList(); // ...And for each map... for (int mi = 0; mi < maps.Length; mi++) { // ...Check if the maps mode equals the enabledModes index and check if the map is in allowed maps... if (maps[mi].GameMode == emi && allowedmaps.Contains(maps[mi])) { // ...then add the map index to the selectmap list. 1, 5, 10 will toggle the first map in overwatch, the fifth, then the tenth... selectMap.Add(mapcount + allowedmaps.IndexOf(maps[mi]) + 1); } } // ...then finally add the number of maps in the mode to the mapcount. mapcount += allowedmaps.Count; } } mapcount++; // Toggle maps for (int i = 0; i < mapcount; i++) { for (int mi = 0; mi < selectMap.Count; mi++) { if (selectMap[mi] == i) { KeyPress(Keys.Space); Thread.Sleep(waitTime); } } KeyPress(Keys.Down); Thread.Sleep(waitTime); } GoBack(2, 0); } }
/// <summary> /// Gets all maps in a gamemode. /// </summary> /// <param name="gamemode">The gamemode to get the maps from.</param> /// <param name="owEvent">Filter by Overwatch event.</param> /// <returns>An array of maps in the <paramref name="gamemode"/>.</returns> public static Map[] GetMapsInGamemode(Gamemode gamemode, OWEvent owEvent = OWEvent.None) { return(GetMaps().Where(v => (v.GameEvent == OWEvent.None || v.GameEvent == owEvent) && gamemode.HasFlag(v.GameMode)).ToArray()); }