Exemple #1
0
        private void OnGameFlowUpdate(object sender, LeagueEvent e)
        {
            string phase = e.Data.ToString();

            if (phase == "ReadyCheck" && autoAcceptQueue)
            {
                API.client.MakeApiRequest(HttpMethod.Post, "/lol-matchmaking/v1/ready-check/decline");
            }
            // returned to lobby for whatever reason
            else if (phase == "Lobby")
            {
                UnavailableChampsID.Clear();
                HandledActionIDs.Clear();
            }
        }
Exemple #2
0
        private void OnChampSelectSessionUpdate(object sender, LeagueEvent e)
        {
            // exit if no actions (usually when leaving champ select)
            // or auto champ select not enabled
            if (!e.Data["actions"].HasValues || !autoChampSelect)
            {
                return;
            }

            WriteSafe("formdebug", e.Data.ToString());

            JToken bans        = e.Data["bans"];
            var    ourBans     = bans["myTeamBans"];
            var    theirBans   = bans["theirTeamBans"];
            int    localCellId = Convert.ToInt32(e.Data["localPlayerCellId"]);
            int    roleID      = 0;

            // empty bans array is "[]". we only want to parse bans if there are any
            if (ourBans.ToString().Length > 2)
            {
                ParseBans(ourBans);
            }
            if (theirBans.ToString().Length > 2)
            {
                ParseBans(theirBans);
            }

            JToken actionsTop = e.Data["actions"];
            JToken myTeamTop  = e.Data["myTeam"];

            for (int i = 0; i < myTeamTop.Count(); i++)
            {
                var curPlayer = myTeamTop.ElementAt(i);
                int curCellId = Convert.ToInt32(curPlayer["cellId"]);

                if (localCellId == curCellId)
                {
                    string role = curPlayer["assignedPosition"].ToString().ToLower();
                    switch (role)
                    {
                    case "top":     // top
                        roleID = 0;
                        break;

                    case "jungle":     // jg
                        roleID = 1;
                        break;

                    case "middle":     // mid
                        roleID = 2;
                        break;

                    case "bottom":     // adc
                        roleID = 3;
                        break;

                    case "utility":     // support
                        roleID = 4;
                        break;

                    default:
                        roleID = 5;
                        break;
                    }
                }
            }

            // iterate through each action (we have to do this becaused 1 action
            // is generated for each player at the same time meaning the last action
            // is only your action if you are last pick)
            for (int i = actionsTop.Count() - 1; i >= 0; i--)
            {
                var curAction = actionsTop.ElementAt(i).First;

                int    curCellId = Convert.ToInt32(curAction["actorCellId"]);
                int    actionId  = Convert.ToInt32(curAction["id"]);
                bool   myTurn    = Convert.ToBoolean(curAction["isInProgress"]);
                string type      = curAction["type"].ToString();

                // current cell belongs to us and hasn't
                if (curCellId == localCellId && myTurn && !HandledActionIDs.Contains(curCellId))
                {
                    HandledActionIDs.Add(curCellId);

                    if (type == "pick")
                    {
                        int[]    currentPrefs = GetChampionPrefsByRoleID(roleID);
                        string[] currentRunes = GetRunesByRoleID(roleID);

                        // automatically pick based on preferred list
                        for (int j = 0; j < PrefPoolSize; j++)
                        {
                            if (currentPrefs[j] != -1 && !UnavailableChampsID.Contains(currentPrefs[j]))
                            {
                                // lock in based on order of prefernce
                                string str = "{\"actorCellId\": " + curCellId + ", \"championId\":" + currentPrefs[j] + ", \"completed\": true, \"id\": " + actionId + ", \"type\": \"string\"}";
                                API.client.MakeApiRequest(HttpMethod.Patch, "/lol-champ-select/v1/session/actions/" + actionId, str);

                                // select runes
                                RuneManager runeManager = new RuneManager(API.client);
                                var         allPages    = runeManager.GetRunePages();
                                RunePage    autoPage    = null;

                                // find page named "auto"
                                foreach (RunePage p in allPages)
                                {
                                    if (p.Name == "auto")
                                    {
                                        autoPage = p;
                                        break;
                                    }
                                }
                                if (autoPage != null) // if page named "auto" is found
                                {
                                    // delete it
                                    API.client.MakeApiRequest(HttpMethod.Delete, "/lol-perks/v1/pages/" + autoPage.Id);
                                }

                                // convert runes string to int array
                                // right side is runes, left side is tree ids (-)
                                string primaryIdstr   = currentRunes[j].Split('-')[0].Split(',')[0];
                                int    primaryId      = Convert.ToInt32(primaryIdstr);
                                string secondaryIdstr = currentRunes[j].Split('-')[0].Split(',')[1];
                                int    secondaryId    = Convert.ToInt32(secondaryIdstr);

                                string[] splitRunes       = currentRunes[j].Split('-')[1].Split(',');
                                int[]    selectedRunesArr = new int[9];
                                for (int k = 0; k < splitRunes.Length; k++)
                                {
                                    selectedRunesArr[k] = Convert.ToInt32(splitRunes[k]);
                                }

                                RunePage newPage = new RunePage()
                                {
                                    IsActive        = true,
                                    IsCurrentPage   = true,
                                    Name            = "auto",
                                    PrimaryTreeId   = primaryId,
                                    SelectedRunes   = selectedRunesArr,
                                    SecondaryTreeId = secondaryId,
                                };

                                // create new rune page with runes chosen in form
                                API.client.MakeApiRequest(HttpMethod.Post, "/lol-perks/v1/pages/", newPage);

                                break;
                            }
                        }
                    }
                    else if (type == "ban")
                    {
                        // automatically ban based on preferred list
                        for (int j = 0; j < PreferredBans.Length; j++)
                        {
                            if (PreferredBans[j] != -1 && !UnavailableChampsID.Contains(PreferredBans[j]))
                            {
                                // lock in based on order of prefernce
                                string str = "{\"actorCellId\": " + curCellId + ", \"championId\":" + PreferredBans[j] + ", \"completed\": true, \"id\": " + actionId + ", \"type\": \"string\"}";
                                API.client.MakeApiRequest(HttpMethod.Patch, "/lol-champ-select/v1/session/actions/" + actionId, str);
                                break;
                            } //if
                        }     //for
                    }         // else if
                }             // if
            }                 // for
        }                     //OnChampSelectSessionUpdate