private static void ProcessMatchEvent(MatchResultDbClass matchResult, Event evnt, MatchTimeLineEntry logEntry,
                                              ref int[] kills, ref int[] deaths, ref int[] assists, ref int[] gold,
                                              ref int DL_towerStatus, ref int DL_inhibitorsStatus,
                                              ref int UR_towerStatus, ref int UR_inhibitorsStatus)
        {
            switch (evnt.type)
            {
            case "CHAMPION_KILL":
                var champKillEntry = logEntry.Clone() as MatchTimeLineEntry;
                champKillEntry.timestamp = TimeSpan.FromMilliseconds(evnt.timestamp);

                var killer    = evnt.killerId;
                var victim    = evnt.victimId;
                var assisters = evnt.assistingParticipantIds;

                if (killer > 0)
                {
                    kills[killer - 1]++;
                }
                if (victim > 0)
                {
                    deaths[victim - 1]++;
                }
                if (assisters != null && assisters.Length > 0)
                {
                    foreach (var assister in assisters)
                    {
                        if (assister > 0)
                        {
                            assists[assister - 1]++;
                        }
                    }
                }

                champKillEntry.kills   = kills.ToArray();
                champKillEntry.deaths  = deaths.ToArray();
                champKillEntry.assists = assists.ToArray();
                champKillEntry.gold    = gold.ToArray();

                champKillEntry.DWNLEFT_InhibitorsStatus = DL_inhibitorsStatus;
                champKillEntry.DWNLEFT_TurretsStatus    = DL_towerStatus;
                champKillEntry.UPRIGHT_InhibitorsStatus = UR_inhibitorsStatus;
                champKillEntry.UPRIGHT_TurretsStatus    = UR_towerStatus;

                matchResult.MatchLog.Add(champKillEntry);
                break;

            case "BUILDING_KILL":
                var buildKillEntry = logEntry.Clone() as MatchTimeLineEntry;
                buildKillEntry.timestamp = TimeSpan.FromMilliseconds(evnt.timestamp);

                if (evnt.buildingType == "INHIBITOR_BUILDING")
                {
                    if (evnt.teamId == 100)     // Убили у радиантов
                    {
                        DL_inhibitorsStatus = BuildingManager.KillInhibitor(evnt.laneType, DL_inhibitorsStatus);
                    }
                    else if (evnt.teamId == 200)     // у дайров
                    {
                        UR_inhibitorsStatus = BuildingManager.KillInhibitor(evnt.laneType, UR_inhibitorsStatus);
                    }
                }
                else if (evnt.buildingType == "TOWER_BUILDING")
                {
                    if (evnt.teamId == 100)     // Убили у радиантов
                    {
                        var wasNexusDestroyedBefore = (DL_towerStatus >> 10 & 1) == 0;
                        DL_towerStatus = BuildingManager.KillTower(evnt.towerType, evnt.laneType, DL_towerStatus, wasNexusDestroyedBefore);
                    }
                    else if (evnt.teamId == 200)     // у дайров
                    {
                        var wasNexusDestroyedBefore = (UR_towerStatus >> 10 & 1) == 0;
                        UR_towerStatus = BuildingManager.KillTower(evnt.towerType, evnt.laneType, UR_towerStatus, wasNexusDestroyedBefore);
                    }
                }

                buildKillEntry.DWNLEFT_InhibitorsStatus = DL_inhibitorsStatus;
                buildKillEntry.DWNLEFT_TurretsStatus    = DL_towerStatus;
                buildKillEntry.UPRIGHT_InhibitorsStatus = UR_inhibitorsStatus;
                buildKillEntry.UPRIGHT_TurretsStatus    = UR_towerStatus;

                buildKillEntry.kills   = kills.ToArray();
                buildKillEntry.deaths  = deaths.ToArray();
                buildKillEntry.assists = assists.ToArray();
                buildKillEntry.gold    = gold.ToArray();

                matchResult.MatchLog.Add(buildKillEntry);
                break;
            }
        }
        private void FillMatchLogData(MatchDetailsResponse response, MatchTimeLineResponse timelineResponse, MatchResultDbClass matchResult)
        {
            var participantStats = response.participants;

            if (participantStats != null)
            {
                foreach (var participantStat in participantStats)
                {
                    var entry = new ParticipantStatsEntry()
                    {
                        ParticipantId                  = participantStat.participantId,
                        ChampionId                     = participantStat.championId,
                        TeamId                         = participantStat.teamId,
                        Spell1                         = participantStat.spell1Id,
                        Spell2                         = participantStat.spell2Id,
                        Role                           = participantStat.timeline.role,
                        Lane                           = participantStat.timeline.lane,
                        Kills                          = participantStat.stats.kills,
                        Deaths                         = participantStat.stats.deaths,
                        Assists                        = participantStat.stats.assists,
                        TotalMinionsKilled             = participantStat.stats.totalMinionsKilled,
                        TotalDamageDealt               = participantStat.stats.totalDamageDealt,
                        TotalDamageDealtToChampions    = participantStat.stats.totalDamageDealtToChampions,
                        MagicDamageDealt               = participantStat.stats.magicDamageDealt,
                        MagicDamageDealtToChampions    = participantStat.stats.magicDamageDealtToChampions,
                        PhysicalDamageDealt            = participantStat.stats.physicalDamageDealt,
                        PhysicalDamageDealtToChampions = participantStat.stats.physicalDamageDealtToChampions,
                        GoldEarned                     = participantStat.stats.goldEarned,
                        GoldSpent                      = participantStat.stats.goldSpent,
                        ChampLevel                     = participantStat.stats.champLevel,
                        WardsPlaced                    = participantStat.stats.wardsPlaced,
                        WardsKilled                    = participantStat.stats.wardsKilled,
                    };
                    matchResult.ParticipantStats.Add(entry);
                }
            }
            else
            {
                throw new ArgumentNullException(nameof(participantStats));
            }

            var frames   = timelineResponse.frames;
            var interval = timelineResponse.frameInterval;

            var kills   = new int[10];
            var deaths  = new int[10];
            var assists = new int[10];

            var uprightTurretsStatus    = 2047;
            var dwnleftTurretsStatus    = 2047;
            var uprightInhibitorsStatus = 7;
            var dwnleftInhibitorsStatus = 7;

            foreach (var frame in frames)
            {
                var gold     = new int[10];
                var logEntry = new MatchTimeLineEntry
                {
                    timestamp = TimeSpan.FromMilliseconds(frame.timestamp),
                };

                foreach (var frameParticipantFrame in frame.participantFrames)
                {
                    var participant = frameParticipantFrame.Key; // какой чувак
                    var gld         = frameParticipantFrame.Value.totalGold;
                    gold[participant - 1] = gld;
                }

                logEntry.gold = gold.ToArray();
                matchResult.MatchLog.Add(logEntry);

                var frameEvents = frame.events;
                if (frameEvents != null && frameEvents.Length > 0)
                {
                    foreach (var evnt in frameEvents)
                    {
                        ProcessMatchEvent(
                            matchResult, evnt, logEntry,
                            ref kills, ref deaths, ref assists, ref gold,
                            ref dwnleftTurretsStatus, ref dwnleftInhibitorsStatus,
                            ref uprightTurretsStatus, ref uprightInhibitorsStatus);
                    }
                }

                logEntry.DWNLEFT_InhibitorsStatus = dwnleftInhibitorsStatus;
                logEntry.DWNLEFT_TurretsStatus    = dwnleftTurretsStatus;
                logEntry.UPRIGHT_InhibitorsStatus = uprightInhibitorsStatus;
                logEntry.UPRIGHT_TurretsStatus    = uprightTurretsStatus;
                logEntry.kills   = kills.ToArray();
                logEntry.deaths  = deaths.ToArray();
                logEntry.assists = assists.ToArray();
            }
        }