예제 #1
0
        /// <summary>
        /// Return PositionPoint for each players determined by selection
        /// </summary>
        /// <param name="demo"></param>
        /// <param name="teamSelector"></param>
        /// <param name="selectedPlayer"></param>
        /// <param name="round"></param>
        /// <returns></returns>
        public async Task <List <List <PositionPoint> > > GetPoints(Demo demo, string teamSelector, Player selectedPlayer, Round round)
        {
            List <List <PositionPoint> > points = new List <List <PositionPoint> >();

            if (teamSelector != null)
            {
                switch (teamSelector)
                {
                case "CT":
                    demo.PositionPoints.Reverse();

                    foreach (Player playerExtended in demo.Players)
                    {
                        List <PositionPoint> playerPoints = new List <PositionPoint>();

                        for (int i = demo.PositionPoints.Count - 1; i >= 0; i--)
                        {
                            if (demo.PositionPoints[i].RoundNumber != round.Number)
                            {
                                continue;
                            }

                            // Keep kills from terrorists
                            if (demo.PositionPoints[i].Event != null &&
                                demo.PositionPoints[i].Team == Side.Terrorist &&
                                demo.PositionPoints[i].Event.GetType() == typeof(KillEvent))
                            {
                                KillEvent e = (KillEvent)demo.PositionPoints[i].Event;
                                if (e.KillerSteamId == playerExtended.SteamId)
                                {
                                    playerPoints.Add(demo.PositionPoints[i]);
                                    demo.PositionPoints.RemoveAt(i);
                                    continue;
                                }
                            }

                            if (demo.PositionPoints[i].Team != Side.CounterTerrorist)
                            {
                                continue;
                            }

                            // Molotov started
                            if (demo.PositionPoints[i].Event != null &&
                                demo.PositionPoints[i].Event.GetType() == typeof(MolotovFireStartedEvent))
                            {
                                MolotovFireStartedEvent e = (MolotovFireStartedEvent)demo.PositionPoints[i].Event;
                                if (e.ThrowerSteamId == playerExtended.SteamId)
                                {
                                    playerPoints.Add(demo.PositionPoints[i]);
                                    demo.PositionPoints.RemoveAt(i);
                                    continue;
                                }
                            }

                            // Molotov ended
                            if (demo.PositionPoints[i].Event != null &&
                                demo.PositionPoints[i].Event.GetType() == typeof(MolotovFireEndedEvent))
                            {
                                MolotovFireEndedEvent e = (MolotovFireEndedEvent)demo.PositionPoints[i].Event;
                                if (e.ThrowerSteamId == playerExtended.SteamId)
                                {
                                    playerPoints.Add(demo.PositionPoints[i]);
                                    demo.PositionPoints.RemoveAt(i);
                                    continue;
                                }
                            }

                            if (demo.PositionPoints[i].PlayerSteamId != 0 &&
                                demo.PositionPoints[i].PlayerSteamId == playerExtended.SteamId)
                            {
                                playerPoints.Add(demo.PositionPoints[i]);
                                demo.PositionPoints.RemoveAt(i);
                            }
                        }
                        if (playerPoints.Any())
                        {
                            points.Add(playerPoints);
                        }
                    }
                    break;

                case "T":
                    demo.PositionPoints.Reverse();

                    foreach (Player playerExtended in demo.Players)
                    {
                        List <PositionPoint> playerPoints = new List <PositionPoint>();

                        for (int i = demo.PositionPoints.Count - 1; i >= 0; i--)
                        {
                            if (demo.PositionPoints[i].RoundNumber != round.Number)
                            {
                                continue;
                            }

                            // Keep kills from CT
                            if (demo.PositionPoints[i].Event != null &&
                                demo.PositionPoints[i].Team == Side.CounterTerrorist &&
                                demo.PositionPoints[i].Event.GetType() == typeof(KillEvent))
                            {
                                KillEvent e = (KillEvent)demo.PositionPoints[i].Event;
                                if (e.KilledSteamId == playerExtended.SteamId)
                                {
                                    playerPoints.Add(demo.PositionPoints[i]);
                                    demo.PositionPoints.RemoveAt(i);
                                    continue;
                                }
                            }

                            if (demo.PositionPoints[i].Team != Side.Terrorist)
                            {
                                continue;
                            }

                            // Molotov started
                            if (demo.PositionPoints[i].Event != null &&
                                demo.PositionPoints[i].Event.GetType() == typeof(MolotovFireStartedEvent))
                            {
                                MolotovFireStartedEvent e = (MolotovFireStartedEvent)demo.PositionPoints[i].Event;
                                if (e.ThrowerSteamId == playerExtended.SteamId)
                                {
                                    playerPoints.Add(demo.PositionPoints[i]);
                                    demo.PositionPoints.RemoveAt(i);
                                    continue;
                                }
                            }

                            // Molotov ended
                            if (demo.PositionPoints[i].Event != null &&
                                demo.PositionPoints[i].Event.GetType() == typeof(MolotovFireEndedEvent))
                            {
                                MolotovFireEndedEvent e = (MolotovFireEndedEvent)demo.PositionPoints[i].Event;
                                if (e.ThrowerSteamId == playerExtended.SteamId)
                                {
                                    playerPoints.Add(demo.PositionPoints[i]);
                                    demo.PositionPoints.RemoveAt(i);
                                    continue;
                                }
                            }

                            if (demo.PositionPoints[i].PlayerSteamId == playerExtended.SteamId)
                            {
                                playerPoints.Add(demo.PositionPoints[i]);
                                demo.PositionPoints.RemoveAt(i);
                            }
                        }
                        if (playerPoints.Any())
                        {
                            points.Add(playerPoints);
                        }
                    }
                    break;

                case "BOTH":
                    points.AddRange(
                        demo.Players.Select(
                            playerExtended => demo.PositionPoints.Where(
                                point => point.RoundNumber == round.Number &&
                                point.PlayerSteamId == playerExtended.SteamId).ToList())
                        .Where(pts => pts.Any()));
                    break;
                }
            }

            if (selectedPlayer != null)
            {
                await Task.Run(delegate
                {
                    List <PositionPoint> pt = demo.PositionPoints.ToList().Where(
                        positionPoint => positionPoint.PlayerSteamId == selectedPlayer.SteamId &&
                        positionPoint.RoundNumber == round.Number ||
                        (positionPoint.Event != null &&
                         positionPoint.Event.GetType() == typeof(KillEvent)) &&
                        positionPoint.RoundNumber == round.Number).ToList();
                    if (pt.Any())
                    {
                        points.Add(pt);
                    }
                });
            }

            // Set players color
            await Task.Run(delegate
            {
                int index = 0;
                foreach (List <PositionPoint> positionPoints in points.ToList())
                {
                    foreach (PositionPoint positionPoint in positionPoints)
                    {
                        positionPoint.X     = MapService.CalculatePointToResolutionX(positionPoint.X);
                        positionPoint.Y     = MapService.CalculatePointToResolutionY(positionPoint.Y);
                        positionPoint.Color = ColorToInt(_colors[index]);
                    }
                    index++;
                }
            });

            return(points);
        }
        public Task <Demo> AnalyzeDemo(Demo demo, CancellationToken token, Action <string, float> progressCallback = null)
        {
            Random random = new Random();

            ObservableCollection <Player> players = new ObservableCollection <Player>();

            for (int i = 0; i < 10; i++)
            {
                Player player = new Player
                {
                    Name                  = "player" + (i + 1),
                    HeadshotCount         = random.Next(14),
                    OneKillCount          = random.Next(10, 30),
                    TwoKillCount          = random.Next(10, 20),
                    ThreeKillCount        = random.Next(0, 10),
                    FourKillCount         = random.Next(0, 5),
                    FiveKillCount         = random.Next(0, 2),
                    BombDefusedCount      = random.Next(0, 2),
                    BombPlantedCount      = random.Next(0, 2),
                    DeathCount            = random.Next(0, 32),
                    KillCount             = random.Next(30),
                    AssistCount           = random.Next(15),
                    Score                 = random.Next(10, 80),
                    RoundMvpCount         = random.Next(6),
                    RankNumberNew         = 5,
                    RankNumberOld         = 4,
                    RatingHltv            = (float)random.NextDouble(),
                    SteamId               = random.Next(1000, 800000),
                    IsOverwatchBanned     = random.Next(100) < 40,
                    IsVacBanned           = random.Next(100) < 40,
                    TeamKillCount         = random.Next(0, 1),
                    WinCount              = random.Next(10, 687),
                    MolotovThrownCount    = random.Next(0, 10),
                    DecoyThrownCount      = random.Next(0, 10),
                    IncendiaryThrownCount = random.Next(20),
                    SmokeThrownCount      = random.Next(20),
                    FlashbangThrownCount  = random.Next(20),
                    HeGrenadeThrownCount  = random.Next(20),
                    BombExplodedCount     = random.Next(5),
                    AvatarUrl             = string.Empty,
                    KillDeathRatio        = (decimal)random.NextDouble(),
                    MatchCount            = random.Next(100),
                    RoundPlayedCount      = random.Next(100)
                };

                players.Add(player);
            }
            Team teamCt = new Team
            {
                Name            = "Team 1",
                Players         = new ObservableCollection <Player>(players.Take(5)),
                Score           = 6,
                ScoreFirstHalf  = 6,
                ScoreSecondHalf = 1,
            };
            Team teamT = new Team
            {
                Name            = "Team 2",
                Players         = new ObservableCollection <Player>(players.Skip(5).Take(5)),
                Score           = 16,
                ScoreFirstHalf  = 10,
                ScoreSecondHalf = 5,
            };

            ObservableCollection <Round> rounds = new ObservableCollection <Round>();

            for (int i = 0; i < 32; i++)
            {
                ObservableCollection <KillEvent> kills = new ObservableCollection <KillEvent>();
                for (int j = 0; j < random.Next(1, 9); j++)
                {
                    Player killer = players.ElementAt(random.Next(9));
                    Player killed = players.ElementAt(random.Next(9));
                    kills.Add(new KillEvent(random.Next(1, 10000), random.Next(1, 100))
                    {
                        KillerName    = killer.Name,
                        KillerSteamId = killer.SteamId,
                        KillerSide    = killer.Side,
                        KilledName    = killed.Name,
                        KilledSteamId = killed.SteamId,
                        KilledSide    = killed.Side,
                        RoundNumber   = i,
                        Weapon        = Weapon.WeaponList.ElementAt(random.Next(44))
                    });
                }

                // generate open / entry kills for this round
                Round round = new Round
                {
                    Number                = i + 1,
                    OneKillCount          = random.Next(5),
                    TwoKillCount          = random.Next(2),
                    ThreeKillCount        = random.Next(1),
                    FourKillCount         = random.Next(1),
                    FiveKillCount         = random.Next(1),
                    EquipementValueTeamCt = random.Next(4200, 30000),
                    EquipementValueTeamT  = random.Next(4200, 30000),
                    StartMoneyTeamCt      = random.Next(4200, 50000),
                    StartMoneyTeamT       = random.Next(4200, 50000),
                    Tick              = random.Next(7000, 100000),
                    EndTick           = random.Next(7000, 100000),
                    FreezetimeEndTick = random.Next(7000, 100000),
                    WinnerName        = teamCt.Name,
                    WinnerSide        = Side.CounterTerrorist,
                    BombDefused       = null,
                    BombPlanted       = null,
                    BombExploded      = null,
                    Type              = RoundType.NORMAL,
                    EndReason         = RoundEndReason.CTWin,
                    EntryKillEvent    = new EntryKillEvent(random.Next(1, 10000), random.Next(1, 100))
                    {
                        HasWon        = random.Next(100) < 50,
                        KillerSteamId = players.ElementAt(random.Next(9)).SteamId,
                        KillerName    = players.ElementAt(random.Next(9)).Name,
                        KilledSteamId = players.ElementAt(random.Next(9)).SteamId,
                        KilledName    = players.ElementAt(random.Next(9)).Name,
                        Weapon        = Weapon.WeaponList.ElementAt(random.Next(44)),
                        KilledSide    = Side.CounterTerrorist,
                        KillerSide    = Side.Terrorist
                    },
                    SideTrouble = Side.None,
                    Kills       = kills
                };
                rounds.Add(round);
            }

            demo.Id                = "de_dust25445648778447878";
            demo.Source            = new Valve();
            demo.Name              = "esea_nip_vs_titan.dem";
            demo.Tickrate          = 15;
            demo.ServerTickrate    = 128;
            demo.MapName           = "de_dust2";
            demo.ClientName        = "localhost";
            demo.Hostname          = "local";
            demo.OneKillCount      = 90;
            demo.TwoKillCount      = 30;
            demo.ThreeKillCount    = 25;
            demo.FourKillCount     = 3;
            demo.FiveKillCount     = 1;
            demo.Path              = "C:\\mydemo.dem";
            demo.Type              = "GOTV";
            demo.Comment           = "comment";
            demo.TeamCT            = teamCt;
            demo.TeamT             = teamT;
            demo.Players           = players;
            demo.Rounds            = rounds;
            demo.MostKillingWeapon = Weapon.WeaponList[random.Next(44)];
            foreach (KillEvent e in rounds.SelectMany(round => round.Kills))
            {
                demo.Kills.Add(e);
            }

            return(Task.FromResult(demo));
        }
예제 #3
0
        public Task <List <Demo> > GetDemosHeader(List <string> folders, List <Demo> currentDemos = null, bool limit = false)
        {
            List <Demo> demos = new List <Demo>();

            for (int i = 0; i < 20; i++)
            {
                ObservableCollection <Player> players = new ObservableCollection <Player>();
                Random random = new Random();

                ObservableCollection <EntryKillEvent> entryKills = new ObservableCollection <EntryKillEvent>();
                for (int indexEntryKill = 0; indexEntryKill < random.Next(5); indexEntryKill++)
                {
                    Player         killer    = players.ElementAt(random.Next(0, 9));
                    Player         killed    = players.ElementAt(random.Next(0, 9));
                    EntryKillEvent entryKill = new EntryKillEvent(random.Next(7000, 100000), random.Next(1, 50000))
                    {
                        KilledSteamId = killed.SteamId,
                        KilledName    = killed.Name,
                        KilledSide    = killed.Side,
                        KillerSteamId = killer.SteamId,
                        KillerName    = killer.Name,
                        KillerSide    = killer.Side
                    };
                    entryKills.Add(entryKill);
                }

                for (int j = 0; j < 10; j++)
                {
                    Player player = new Player
                    {
                        Name             = "player" + (j + 1),
                        HeadshotCount    = random.Next(14),
                        OneKillCount     = random.Next(10, 30),
                        TwoKillCount     = random.Next(10, 20),
                        ThreeKillCount   = random.Next(0, 10),
                        FourKillCount    = random.Next(0, 5),
                        FiveKillCount    = random.Next(0, 2),
                        BombDefusedCount = random.Next(0, 2),
                        BombPlantedCount = random.Next(0, 2),
                        EntryKills       = entryKills,
                        DeathCount       = random.Next(0, 32),
                        KillCount        = random.Next(30),
                        AssistCount      = random.Next(15),
                        Score            = random.Next(10, 80),
                        RoundMvpCount    = random.Next(6)
                    };

                    players.Add(player);
                }

                ObservableCollection <Round> rounds = new ObservableCollection <Round>();
                for (int k = 0; k < 32; k++)
                {
                    Round round = new Round
                    {
                        Number               = k + 1,
                        OneKillCount         = random.Next(5),
                        TwoKillCount         = random.Next(2),
                        ThreeKillCount       = random.Next(1),
                        FourKillCount        = random.Next(1),
                        FiveKillCount        = random.Next(1),
                        EquipementValueTeam1 = random.Next(4200, 30000),
                        EquipementValueTeam2 = random.Next(4200, 30000),
                        StartMoneyTeam1      = random.Next(4200, 50000),
                        StartMoneyTeam2      = random.Next(4200, 50000),
                        Tick = random.Next(7000, 100000)
                    };

                    rounds.Add(round);
                }

                Demo demo = new Demo
                {
                    Id                    = "de_dust25445648778447878",
                    Name                  = "mydemo" + (i + 1) + ".dem",
                    Tickrate              = 128,
                    MapName               = "de_dust2",
                    ClientName            = "localhost",
                    Hostname              = "local",
                    OneKillCount          = random.Next(50, 90),
                    TwoKillCount          = random.Next(20, 50),
                    ThreeKillCount        = random.Next(10),
                    FourKillCount         = random.Next(3),
                    FiveKillCount         = random.Next(1),
                    Path                  = "C:\\mydemo.dem",
                    ScoreTeam1            = 16,
                    ScoreTeam2            = 6,
                    Type                  = "GOTV",
                    Comment               = "comment",
                    ScoreFirstHalfTeam1   = 10,
                    ScoreFirstHalfTeam2   = 5,
                    ScoreSecondHalfTeam1  = 6,
                    ScoreSecondHalfTeam2  = 1,
                    Players               = players,
                    MostBombPlantedPlayer = players.ElementAt(random.Next(10)),
                    MostHeadshotPlayer    = players.ElementAt(random.Next(10)),
                    Rounds                = rounds
                };

                demos.Add(demo);
            }

            return(Task.FromResult(demos));
        }
        private static Demo GenerateDemo()
        {
            int currentTick = 1;
            ObservableCollection <Player> players = new ObservableCollection <Player>();
            Random random = new Random();

            ObservableCollection <EntryKillEvent> entryKills = new ObservableCollection <EntryKillEvent>();

            for (int indexEntryKill = 0; indexEntryKill < random.Next(5); indexEntryKill++)
            {
                currentTick *= indexEntryKill;
                Player         killer    = players.ElementAt(random.Next(0, 9));
                Player         killed    = players.ElementAt(random.Next(0, 9));
                EntryKillEvent entryKill = new EntryKillEvent(currentTick, random.Next(1, 50000))
                {
                    KilledSteamId = killed.SteamId,
                    KilledName    = killed.Name,
                    KilledSide    = killed.Side,
                    KillerSteamId = killer.SteamId,
                    KillerName    = killer.Name,
                    KillerSide    = killer.Side
                };
                entryKills.Add(entryKill);
            }

            for (int j = 0; j < 10; j++)
            {
                Player player = new Player
                {
                    Name             = "player" + (j + 1),
                    HeadshotCount    = random.Next(14),
                    OneKillCount     = random.Next(10, 30),
                    TwoKillCount     = random.Next(10, 20),
                    ThreeKillCount   = random.Next(0, 10),
                    FourKillCount    = random.Next(0, 5),
                    FiveKillCount    = random.Next(0, 2),
                    BombDefusedCount = random.Next(0, 2),
                    BombPlantedCount = random.Next(0, 2),
                    EntryKills       = entryKills,
                    DeathCount       = random.Next(0, 32),
                    KillCount        = random.Next(30),
                    AssistCount      = random.Next(15),
                    Score            = random.Next(10, 80),
                    RoundMvpCount    = random.Next(6)
                };

                players.Add(player);
            }

            currentTick = 1;
            ObservableCollection <Round> rounds = new ObservableCollection <Round>();

            for (int k = 0; k < 32; k++)
            {
                Round round = new Round
                {
                    Number                = k + 1,
                    OneKillCount          = random.Next(5),
                    TwoKillCount          = random.Next(2),
                    ThreeKillCount        = random.Next(1),
                    FourKillCount         = random.Next(1),
                    FiveKillCount         = random.Next(1),
                    EquipementValueTeamCt = random.Next(4200, 30000),
                    EquipementValueTeamT  = random.Next(4200, 30000),
                    StartMoneyTeamCt      = random.Next(4200, 50000),
                    StartMoneyTeamT       = random.Next(4200, 50000),
                    Tick    = currentTick * k,
                    EndTick = currentTick + 5000,
                };
                currentTick += 5000;
                rounds.Add(round);
            }

            Demo demo = new Demo
            {
                Id                    = "de_dust25445648778447878",
                Name                  = "mydemo.dem",
                Tickrate              = 32,
                ServerTickrate        = 64,
                MapName               = "de_dust2",
                ClientName            = "localhost",
                Hostname              = "local",
                OneKillCount          = random.Next(50, 90),
                TwoKillCount          = random.Next(20, 50),
                ThreeKillCount        = random.Next(10),
                FourKillCount         = random.Next(3),
                FiveKillCount         = random.Next(1),
                Path                  = "C:\\mydemo.dem",
                Type                  = "GOTV",
                Comment               = "comment",
                Players               = players,
                MostBombPlantedPlayer = players.ElementAt(random.Next(10)),
                MostHeadshotPlayer    = players.ElementAt(random.Next(10)),
                Rounds                = rounds,
                Duration              = 2651.65625f,
            };

            Team teamCt = new Team
            {
                Name            = "Team 1",
                Players         = new ObservableCollection <Player>(players.Take(5)),
                Score           = 6,
                ScoreFirstHalf  = 6,
                ScoreSecondHalf = 1,
            };
            Team teamT = new Team
            {
                Name            = "Team 2",
                Players         = new ObservableCollection <Player>(players.Skip(5).Take(5)),
                Score           = 16,
                ScoreFirstHalf  = 10,
                ScoreSecondHalf = 5,
            };

            demo.TeamT  = teamT;
            demo.TeamCT = teamCt;

            return(demo);
        }
예제 #5
0
        public Round Clone()
        {
            Round round = new Round
            {
                Number                       = Number,
                DecoyThrownCount             = DecoyThrownCount,
                BombDefusedCount             = BombDefusedCount,
                SmokeThrownCount             = SmokeThrownCount,
                TradeKillCount               = TradeKillCount,
                KillCount                    = KillCount,
                BombExplodedCount            = BombExplodedCount,
                AverageHealthDamagePerPlayer = AverageHealthDamagePerPlayer,
                BombDefused                  = BombDefused,
                BombPlantedCount             = BombPlantedCount,
                BombExploded                 = BombExploded,
                BombPlanted                  = BombPlanted,
                SideTrouble                  = SideTrouble,
                CrouchKillCount              = CrouchKillCount,
                DamageArmorCount             = DamageArmorCount,
                DamageHealthCount            = DamageHealthCount,
                EndReason                    = EndReason,
                EndTimeSeconds               = EndTimeSeconds,
                EntryHoldKillEvent           = EntryHoldKillEvent,
                EntryKillEvent               = EntryKillEvent,
                EquipementValueTeamCt        = EquipementValueTeamCt,
                EquipementValueTeamT         = EquipementValueTeamT,
                FiveKillCount                = FiveKillCount,
                FourKillCount                = FourKillCount,
                ThreeKillCount               = ThreeKillCount,
                TwoKillCount                 = TwoKillCount,
                OneKillCount                 = OneKillCount,
                FlashbangThrownCount         = FlashbangThrownCount,
                HeGrenadeThrownCount         = HeGrenadeThrownCount,
                IncendiaryThrownCount        = IncendiaryThrownCount,
                JumpKillCount                = JumpKillCount,
                MolotovThrownCount           = MolotovThrownCount,
                StartMoneyTeamCt             = StartMoneyTeamCt,
                StartMoneyTeamT              = StartMoneyTeamT,
                StartTimeSeconds             = StartTimeSeconds,
                TeamCtName                   = TeamCtName,
                TeamTname                    = TeamTname,
                TeamTroubleName              = TeamTroubleName,
                Tick                      = Tick,
                Type                      = Type,
                WinnerName                = WinnerName,
                WinnerSide                = WinnerSide,
                PlayersHurted             = new ObservableCollection <PlayerHurtedEvent>(),
                Kills                     = new ObservableCollection <KillEvent>(),
                WeaponFired               = new ObservableCollection <WeaponFireEvent>(),
                ExplosiveGrenadesExploded = new ObservableCollection <ExplosiveNadeExplodedEvent>(),
                FlashbangsExploded        = new ObservableCollection <FlashbangExplodedEvent>(),
                SmokeStarted              = new ObservableCollection <SmokeNadeStartedEvent>(),
            };

            foreach (PlayerHurtedEvent e in PlayersHurted)
            {
                round.PlayersHurted.Add(e);
            }
            foreach (ExplosiveNadeExplodedEvent e in ExplosiveGrenadesExploded)
            {
                round.ExplosiveGrenadesExploded.Add(e);
            }
            foreach (FlashbangExplodedEvent e in FlashbangsExploded)
            {
                round.FlashbangsExploded.Add(e);
            }
            foreach (SmokeNadeStartedEvent e in SmokeStarted)
            {
                round.SmokeStarted.Add(e);
            }
            foreach (KillEvent k in Kills)
            {
                round.Kills.Add(k);
            }
            foreach (WeaponFireEvent e in WeaponFired)
            {
                round.WeaponFired.Add(e);
            }

            return(round);
        }