Beispiel #1
0
        public async Task <LeagueEvent[]> GetEvents()
        {
            JToken json = await basicApi.CallApiForJson(Requests.EVENT_LIST);

            JArray eventJson = (JArray)json["Events"];

            if (eventJson.Count == 0 || eventJson == null)
            {
                return(null);
            }

            LeagueEvent[] events = new LeagueEvent[eventJson.Count];

            for (int i = 0; i < events.Length; i++)
            {
                events[i] = ParseEvent(eventJson[i]);
                Console.WriteLine("parse " + i);
            }

            return(events);
        }
        private async void ListenLeagueEvent(object sender, DoWorkEventArgs e)
        {
            while (!workerLeagueEvent.CancellationPending)
            {
                Task endLoop = Task.Delay(delayLeagueEvent);

                LeagueEvent leagueEvent = await api.GetLastEvent();

                if (leagueEvent != null && leagueEvent.id != lastLeagueEventIndex)
                {
                    int thisEventIndex = leagueEvent.id;
                    //If only one event has happened since the last check.
                    if (thisEventIndex == lastLeagueEventIndex + 1)
                    {
                        RaiseEvent(leagueEvent);
                    }
                    //If more than one event happened since the last check, get all events and trigger all events from [last + 1] until the last one.
                    else
                    {
                        LeagueEvent[] allGameEvents = await api.GetEvents();

                        for (int i = lastLeagueEventIndex + 1; i <= thisEventIndex; i++)
                        {
                            RaiseEvent(allGameEvents[i]);
                        }
                    }

                    lastLeagueEventIndex = leagueEvent.id;
                }

                await endLoop;
            }

            void RaiseEvent(LeagueEvent thisEvent)
            {
                LeagueEventArgs args = new LeagueEventArgs(thisEvent);

                OnLeagueEventHappened(args);
                if (thisEvent is Event_GameStart)
                {
                    OnGameStart(args);
                }
                else if (thisEvent is Event_MinionsFirstSpawn)
                {
                    OnMinionsFirstSpawn(args);
                }
                else if (thisEvent is Event_FirstTurretKill)
                {
                    OnFirstTurretKill(args);
                }
                else if (thisEvent is Event_TurretKill)
                {
                    OnTurretKill(args);
                }
                else if (thisEvent is Event_InhibKill)
                {
                    OnInhibKill(args);
                }
                else if (thisEvent is Event_DragonKill)
                {
                    OnDragonKill(args);
                }
                else if (thisEvent is Event_HeraldKill)
                {
                    OnHeraldKill(args);
                }
                else if (thisEvent is Event_BaronKill)
                {
                    OnBaronKill(args);
                }
                else if (thisEvent is Event_ChampionKill)
                {
                    OnChampionKill(args);
                }
                else if (thisEvent is Event_MultiKill)
                {
                    OnMultiKill(args);
                }
                else if (thisEvent is Event_Ace)
                {
                    OnAce(args);
                }
                else if (thisEvent is Event_FirstBlood)
                {
                    OnFirstBlood(args);
                }
                else if (thisEvent is Event_GameEnd)
                {
                    OnGameEnd(args);
                }
            }
        }
 public LeagueEventArgs(LeagueEvent leagueEvent)
 {
     this.leagueEvent = leagueEvent;
 }