public async Task PickChampion(Position pos, LolChampSelectChampSelectAction myAction, bool intent)
        {
            LogTo.Debug("Trying to pick champion" + (intent ? " intent" : ""));

            Dictionary <Position, int> picks = Config.ChampionsToPick;
            var pickable = await LoL.ChampSelect.GetPickableChampions();

            //Build list of possible champion candidates
            var possiblePicks = new List <int>();

            possiblePicks.Add(picks[pos]);
            possiblePicks.Add(picks[Position.Fill]);
            LogTo.Debug("possiblePicks: {0}", string.Join(", ", picks.Values.ToArray()));

            //Get the first valid one
            int preferredPick = possiblePicks.FirstOrDefault(pickable.championIds.Contains);

            LogTo.Debug("Preferred champ: {0}", preferredPick);

            if (preferredPick == 0)
            {
                LogTo.Info("Couldn't pick preferred champion");

                //TODO Add translatable string
                if (!intent)
                {
                    Main.ShowNotification("Couldn't pick any champion",
                                          "Maybe all of your selected champions were banned", NotificationType.Error);
                }
                return;
            }

            LogTo.Debug("Candidate found, picking...");
            myAction.championId = preferredPick;
            myAction.completed  = !intent;

            try
            {
                await LoL.ChampSelect.PatchActionById(myAction, myAction.id);

                LogTo.Debug("Champion picked");
            }
            catch (APIErrorException ex)
            {
                LogTo.DebugException("Couldn't pick champion", ex);
            }

            if (Config.DisablePickChampion && !intent)
            {
                LogTo.Debug("Unset auto pick champion");

                Config.AutoPickChampion = false;
                Config.Save();
            }
        }
        public async Task BanChampion(Position pos, LolChampSelectChampSelectAction myAction, LolChampSelectChampSelectPlayerSelection[] myTeam)
        {
            LogTo.Debug("Trying to ban champion");

            Dictionary <Position, int> bans = Config.Current.ChampionsToBan;
            var bannable = await LoL.ChampSelect.GetBannableChampions();

            var possibleBans = new List <int>();

            possibleBans.Add(bans[pos]);
            possibleBans.Add(bans[Position.Fill]);
            LogTo.Debug("possibleBans: {0}", string.Join(", ", possibleBans));

            int preferredBan = possibleBans.FirstOrDefault(bannable.championIds.Contains);
            var banName      = preferredBan > 0 ? Riot.GetChampion(preferredBan).Name : "None";

            LogTo.Debug("Preferred ban: {0}", banName);

            if (preferredBan == 0)
            {
                LogTo.Debug("Couldn't ban any champion");

                //TODO Add translatable string
                Main.ShowNotification("Couldn't ban any champion",
                                      "Maybe all of your selected champions were banned", NotificationType.Error);
                return;
            }

            var teamIntents = myTeam.Select(o => o.championPickIntent);

            if (teamIntents.Contains(preferredBan))
            {
                LogTo.Info("Wanted to ban {0}, but someone wants to play it", banName);

                Main.ShowNotification("Hey", $"Couldn't ban {banName} because someone wants to play it", NotificationType.Error);
                SystemSounds.Exclamation.Play();

                return;
            }

            LogTo.Debug("Candidate found ({0}), banning...", banName);
            myAction.championId = preferredBan;
            myAction.completed  = true;

            try
            {
                await LoL.ChampSelect.PatchActionById(myAction, myAction.id);

                LogTo.Debug("Champion banned");
            }
            catch (APIErrorException ex)
            {
                LogTo.DebugException("Couldn't ban champion", ex);
            }

            if (Config.DisableBanChampion)
            {
                LogTo.Debug("Unset auto ban champion");

                Config.AutoBanChampion = false;
                Config.Save();
            }
        }
 public static Task <object> PatchLolChampSelectV1SessionActionsById([Parameter("id", "path")] long id, [Parameter("data", "body")] LolChampSelectChampSelectAction data)
 => Sender.Request <object>("patch", $"/lol-champ-select/v1/session/actions/{id}", data);
Exemple #4
0
 /// <summary>
 /// </summary>
 /// <param name="session">The session object</param>
 /// <param name="id"></param>
 /// <param name="data"></param>
 /// <returns></returns>
 public static Task <dynamic> Patch(LeagueClientSession session,
                                    long id, LolChampSelectChampSelectAction data) =>
 session.SendRequestAsync <dynamic>("PATCH",
                                    $"/lol-champ-select/v1/session/actions/{id}", body: data);
Exemple #5
0
 public Task PatchActionById(LolChampSelectChampSelectAction action, int id)
 => Client.MakeRequestAsync(Endpoint + $"/actions/{id}", Method.PATCH, action);