public void ApplyNewState(LCUSharp.Websocket.LeagueEvent e)
        {
            Data.Client.LCU.Session tempSession = e.Data.ToObject <Data.Client.LCU.Session>();
            var newState = new CurrentState(true, tempSession);

            if (!State.Client.State.data.champSelectActive)
            {
                Logging.Info("ChampSelect started!");
                State.Client.State.OnChampSelectStarted();
                // Also cache information about summoners
                //Logging.Verbose(e.Data.ToString());
                var t = (Task)StateController.CacheSummoners(newState.session);
                t.Wait();
            }

            lastTime = State.Client.State.data.timer;

            var cleanedData = Converter.ConvertState(newState);

            var currentActionBefore = State.Client.State.data.GetCurrentAction();

            State.Client.State.NewState(cleanedData);

            var currentActionAfter = State.Client.State.data.GetCurrentAction();

            if (!currentActionBefore.Equals(currentActionAfter))
            {
                var action = State.Client.State.data.RefreshAction(currentActionBefore);

                State.Client.State.OnNewAction(action);
            }
        }
Example #2
0
        public static async Task CacheSummoners(Data.Client.LCU.Session session)
        {
            //Clear to reset summoners before caching
            summoners.Clear();

            List <Cell> blueTeam = session.myTeam;
            List <Cell> redTeam  = session.theirTeam;

            Dictionary <Cell, Task <string> > jobs = FetchPlayersFromTeam(blueTeam);

            jobs = jobs.Concat(FetchPlayersFromTeam(redTeam)).ToDictionary(x => x.Key, x => x.Value);
            var completedJobs = jobs.Values.ToList();

            while (completedJobs.Any())
            {
                Task <string> finished = await Task.WhenAny(completedJobs);

                summoners.Add(JsonConvert.DeserializeObject <Summoner>(await finished));
                completedJobs.Remove(finished);
            }
        }
 public CurrentState(bool IsChampSelectActive, Data.Client.LCU.Session Session)
 {
     this.isChampSelectActive = IsChampSelectActive;
     this.session             = Session;
 }