string GetItem(RiotSharp.StaticDataEndpoint.ItemListStatic it, int id)
 {
     if (it.Items.ContainsKey(id))
     {
         return(it.Items[id].Name);
     }
     else
     {
         return("Item " + id);
     }
 }
        string EventToString(Event ev, RiotSharp.StaticDataEndpoint.ItemListStatic items)
        {
            switch (ev.EventType)
            {
            case EventType.ItemPurchased:

                return("[ " + string.Format("{0:0}:{1:00}", ev.Timestamp.Minutes, ev.Timestamp.Seconds) + "  |Item Event]     " + GetParticipant(ev.ParticipantId) + " purchased " + GetItem(items, ev.ItemId));

            case EventType.ItemSold:
                return("[ " + string.Format("{0:0}:{1:00}", ev.Timestamp.Minutes, ev.Timestamp.Seconds) + "  |Item Event]     " + GetParticipant(ev.ParticipantId) + " sold " + GetItem(items, ev.ItemId));

            case EventType.ItemDestroyed:
                return("[ " + string.Format("{0:0}:{1:00}", ev.Timestamp.Minutes, ev.Timestamp.Seconds) + "  |Item Event]     " + GetParticipant(ev.ParticipantId) + " destroyed " + GetItem(items, ev.ItemId));

            case EventType.ItemUndo:
                return("[ " + string.Format("{0:0}:{1:00}", ev.Timestamp.Minutes, ev.Timestamp.Seconds) + "  |Item Event]     " + GetParticipant(ev.ParticipantId) + " undid " + GetItem(items, ev.ItemId));

            case EventType.SkillLevelUp:
                return("[ " + string.Format("{0:0}:{1:00}", ev.Timestamp.Minutes, ev.Timestamp.Seconds) + "  |Skill Level Up Event]     " + GetParticipant(ev.ParticipantId) + " leveled up his " + GetSkill(ev.SkillSlot));

            case EventType.WardKill:
                return("[ " + string.Format("{0:0}:{1:00}", ev.Timestamp.Minutes, ev.Timestamp.Seconds) + "  |Ward Kill Event]     " + GetParticipant(ev.KillerId) + " killed a " + ev.WardType.Value.ToString());

            case EventType.WardPlaced:
                return("[ " + string.Format("{0:0}:{1:00}", ev.Timestamp.Minutes, ev.Timestamp.Seconds) + "  |Ward Placed Event]     " + GetParticipant(ev.CreatorId) + " placed a " + ev.WardType.Value.ToString());

            case EventType.EliteMonsterKill:
                return("[ " + string.Format("{0:0}:{1:00}", ev.Timestamp.Minutes, ev.Timestamp.Seconds) + "  |Elite Monster Kill Event]     " + GetParticipant(ev.KillerId) + " has slained " + ev.MonsterType.Value.ToString());

            case EventType.ChampionKill:
                string assist = "";
                if (ev.AssistingParticipantIds != null)
                {
                    foreach (int aid in ev.AssistingParticipantIds)
                    {
                        assist += GetParticipant(aid) + ", ";
                    }
                    assist = (assist == "") ? "" : "Assisted by " + assist.Remove(assist.Length - 3, 2);
                }
                return("[ " + string.Format("{0:0}:{1:00}", ev.Timestamp.Minutes, ev.Timestamp.Seconds) + "  |Champion Kill Event]     " + GetParticipant(ev.KillerId) + " has slained " + GetParticipant(ev.VictimId) + " " + assist);

            case EventType.BuildingKill:
                return("[ " + string.Format("{0:0}:{1:00}", ev.Timestamp.Minutes, ev.Timestamp.Seconds) + "  |Building Kill Event]     " + ((ev.TeamId == 100) ? "Red Team has destoryed " : "Blue Team has destoryed ") + ev.LaneType.Value.ToString() + " " + ev.BuildingType.ToString() + ((ev.TowerType.Value == TowerType.UndefinedTurret) ? "" : " (" + ev.TowerType.Value + ")") + " by " + GetParticipant(ev.KillerId));

            default:
                return("");
            }
        }
        void LoadEvents()
        {
            try
            {
                string cachefile = Application.StartupPath + @"\Temp\" + META.gameKey.gameId + "-" + META.gameKey.platformId + ".cached";


                StringBuilder sb = new StringBuilder();
                RiotSharp.StaticDataEndpoint.ItemListStatic items = RiotSharp.StaticRiotApi.GetInstance(SettingsManager.Settings.ApiKey).GetItems(RiotTool.PlatformToRegion(META.gameKey.platformId));
                RiotSharp.MatchEndpoint.MatchDetail         m     = Program.MainFormInstance.API.GetMatch(RiotTool.PlatformToRegion(META.gameKey.platformId), META.gameKey.gameId, true, cachefile, true);
                foreach (Participant p in m.Participants)
                {
                    parts.Add(p.ParticipantId, FindParticipant(p.ChampionId, p.TeamId));
                }


                foreach (Frame f in m.Timeline.Frames)
                {
                    sb.AppendLine("***" + string.Format("{0:0}:{1:00}", f.Timestamp.Minutes, f.Timestamp.Seconds) + "***********************************************************************************");
                    if (f.Events != null)
                    {
                        foreach (Event ev in f.Events)
                        {
                            sb.AppendLine(EventToString(ev, items));
                        }
                    }
                }
                metroTabControl1.Invoke(new MethodInvoker(delegate
                {
                    nsTextBox1.Text = sb.ToString();

                    metroTabControl1.TabPages.Add(metroTabPage4);
                    metroTabControl1.SelectedIndex = 0;
                }));
                sb.Length = 0;
                sb        = null;
            }
            catch
            {
            }
        }