示例#1
0
        public TeamSetUp(List <Player> AllPlayers, Map_JSON info)
        {
            A = new SetUp();
            B = new SetUp();
            List <PlayerBombSite> Players = new List <PlayerBombSite>();

            foreach (Player p in AllPlayers)
            {
                if (p.TeamSide == Team.CounterTerrorist)
                {
                    Players.Add(new PlayerBombSite(p.Name, p.Position));
                }
            }
            A.DetermineSetUp(Players, info, SetUp.BombSite.A);
            B.DetermineSetUp(Players, info, SetUp.BombSite.B);
        }
        /// <summary>
        /// Determine the SetUp on a bomb site
        /// </summary>
        /// <param name="Players"></param>
        /// <param name="mapInfo"></param>
        public void DetermineSetUp(List <PlayerBombSite> Players, Map_JSON mapInfo, BombSite site)
        {
            this.Site = site;

            float BombSiteX;
            float BombSiteY;

            // Get the bomb site information
            if (site == BombSite.A)
            {
                BombSiteX = mapInfo.bombA_x;
                BombSiteY = mapInfo.bombA_y;
            }
            else
            {
                BombSiteX = mapInfo.bombB_x;
                BombSiteY = mapInfo.bombB_y;
            }

            // We need to find a better measure but we say that a player is a player of a
            // bomb site if he is at a distance inferior to the bombsite

            // Iterate over the players to determine their site
            foreach (PlayerBombSite p in Players)
            {
                if (Distance(new Vector(BombSiteX, BombSiteY, 0), p.Position,
                             mapInfo.pos_x, mapInfo.pos_y, mapInfo.scale) < 0.3f)
                {
                    // The player is a player of this bombsite
                    if (Program.VERBOSE)
                    {
                        Console.WriteLine("{0} is a player of {1} bombsite", p.Name, site);
                    }
                    players.Add(new PlayerBombSite(p));
                }
            }
        }
        /// <summary>
        /// Get all the informations from the game
        /// </summary>
        /// <param name="parser"></param>
        public void ParseGame(DemoParser parser)
        {
            List <Death> deaths = new List <Death>();

            float timeBeginningRound = 0f;

            Round currentRound        = new Round();
            bool  setUpDetermined     = false;
            bool  roundTypeDetermined = false;

            parser.ParseHeader();
            mapName = parser.Map;

            Map_JSON     map          = new Map_JSON();
            MapPositions mapPositions = new MapPositions(mapName);

            // Get information from the assoiated JSON file.
            try {
                map = JsonConvert.DeserializeObject <Map_JSON>(File.ReadAllText("Maps_json/" + mapName + ".json"));
            }
            catch (FileNotFoundException) {
                Console.WriteLine("File was not found {0}", mapName);
                Environment.Exit(1);
            }

            int numberCT = 5;
            int numberT  = 5;

            parser.MatchStarted += (sender, e) => {
                // When the match starts we create a new scoreboard
                board = new Scoreboard();
            };

            // Make a print on round-start so you can see the actual frags per round.
            parser.RoundStart += (sender, e) => {
                if (!board.IsInitialized())
                {
                    foreach (var player in parser.PlayingParticipants)
                    {
                        board.AddPlayerToScoreboard(new PlayerScoreboard(player.Name));
                    }
                }

                foreach (var player in parser.PlayingParticipants)
                {
                    AllPlayers[player.Name].TeamSide = player.Team;
                }

                timeBeginningRound = parser.CurrentTime;

                // Console.WriteLine("New Round, Current Score: T {0} : {1} CT", parser.TScore, parser.CTScore);

                numberCT = 5;
                numberT  = 5;

                deaths = new List <Death>();

                currentRound = new Round {
                    CTTeam = parser.CTClanName,
                    TTeam  = parser.TClanName,
                    Number = parser.CTScore + parser.TScore
                };

                setUpDetermined     = false;
                roundTypeDetermined = false;

                board.UpdateScoreBoardNewRound();
            };

            parser.RoundEnd += (sender, e) => {
                AllRounds.Add(currentRound);

                //Console.WriteLine("NumberCT alive " + numberCT.ToString() + " Number T alive " + numberT.ToString());
                //Console.WriteLine();
            };

            parser.TickDone += (sender, e) => {
                float currentTime = parser.CurrentTime - timeBeginningRound;

                if (currentTime > 35 && !setUpDetermined)
                {
                    setUpDetermined = true;
                    List <Player> PlayersList = new List <Player>();
                    foreach (KeyValuePair <string, Player> entry in AllPlayers)
                    {
                        PlayersList.Add(new Player(entry.Value));
                    }
                    currentRound.DefenseSetUp = new TeamSetUp(PlayersList, map);

                    List <Player> PlayerToDraw = new List <Player>();
                    foreach (Player p in PlayersList)
                    {
                        Player p2 = new Player(p)
                        {
                            Position = GetPositionMiniMap(p.Position, map.pos_x, map.pos_y, map.scale)
                        };
                        PlayerToDraw.Add(p2);
                    }

                    GenerateHeatMaps.GenerateMap(PlayerToDraw, mapName, currentRound.Number);
                }

                // Updated every frame
                foreach (var player in parser.PlayingParticipants)
                {
                    // We multiply it by the time of one tick
                    // Since the velocity is given in
                    // ingame-units per second
                    // Console.WriteLine("{0} {1}", player.Name, player.Position);
                    if (AllPlayers.ContainsKey(player.Name))
                    {
                        Player current = AllPlayers[player.Name];
                        if (player.IsAlive)
                        {
                            current.Update(player.Position,
                                           GetPositionMiniMap(player.Position, map.pos_x, map.pos_y, map.scale),
                                           player.ActiveWeapon.AmmoInMagazine);
                        }
                    }
                    else
                    {
                        if (player.ActiveWeapon == null)
                        {
                            AllPlayers.Add(player.Name, new Player(player.Name, player.Position, player.Position,
                                                                   0, EquipmentElement.Knife, player.Team,
                                                                   (player.Team == Team.CounterTerrorist) ? parser.CTClanName : parser.TClanName));
                        }
                        else
                        {
                            AllPlayers.Add(player.Name, new Player(player.Name, player.Position, player.Position,
                                                                   player.ActiveWeapon.AmmoInMagazine, player.ActiveWeapon.Weapon, player.Team,
                                                                   (player.Team == Team.CounterTerrorist) ? parser.CTClanName : parser.TClanName));
                        }
                    }

                    // When a first player starts moving, we determine the eco type
                    if ((player.Velocity.X != 0) && !roundTypeDetermined)
                    {
                        currentRound.DetermineEcoType(parser.PlayingParticipants);
                        roundTypeDetermined = true;
                    }
                }
            };

            parser.PlayerKilled += (sender, e) => {
                board.UpdateScoreBoardPlayerKilled(e);
                // Add death
                AllPlayers[e.Victim.Name].AddDeath(new Death(GetPositionMiniMap(e.Victim.Position, map.pos_x, map.pos_y, map.scale)
                                                             , e.Victim.Team));
                // Add kill
                AllPlayers[e.Killer.Name].AddKill(new Kill(GetPositionMiniMap(e.Killer.Position, map.pos_x, map.pos_y, map.scale)
                                                           , e.Killer.Team));
            };

            // Occurs when a player gets hurt.
            parser.PlayerHurt += (sender, e) => {
                board.UpdatePlayerHurt(e);
            };

            parser.ParseToEnd();
        }
示例#4
0
        public static void GenerateFrags(DemoParser parser)
        {
            Dictionary <string, Player> AllPlayers = new Dictionary <string, Player>();
            List <Death> deaths       = new List <Death>();
            var          outputStream = new StreamWriter("round.txt");

            float timeBeginningRound = 0f;

            parser.ParseHeader();

            string   mapName = parser.Map;
            Map_JSON map     = new Map_JSON();

            // Get information from the assoiated JSON file.
            try {
                map = JsonConvert.DeserializeObject <Map_JSON>(File.ReadAllText("Maps_json/" + mapName + ".json"));
            } catch (FileNotFoundException) {
                Console.WriteLine("File was not found {0}", mapName);
                System.Environment.Exit(1);
            }

            int numberCT = 5;
            int numberT  = 5;

            outputStream.WriteLine(parser.Map);

            // Make a print on round-start so you can see the actual frags per round.
            parser.RoundStart += (sender, e) => {
                timeBeginningRound = parser.CurrentTime;
                outputStream.WriteLine("Round {0}", parser.CTScore + parser.TScore);
                // Console.WriteLine("New Round, Current Score: T {0} : {1} CT", parser.TScore, parser.CTScore);

                numberCT = 5;
                numberT  = 5;

                AllPlayers = new Dictionary <string, Player>();
                deaths     = new List <Death>();

                //foreach (var player in parser.PlayingParticipants) {
                //    AllPlayers.Add(player.Name, new Player(player.Name, player.Position, player.Position,
                //        player.ActiveWeapon.AmmoInMagazine, player.ActiveWeapon.Weapon));
                //}
            };

            parser.PlayerKilled += (sender, e) => {
                if (e.Killer == null)
                {
                    // The player has murdered himself (falling / own nade / ...)
                    Console.WriteLine("<World><0><None>");
                }
                else
                {
                    Console.Write("<{0}><{1}> killed ", e.Killer.Name, ShortTeam(e.Killer.Team));
                }

                if (e.Assister == null)
                {
                    // nothing
                }
                else
                {
                    Console.Write(" + <{0}><{1}> assist ", e.Assister.Name, ShortTeam(e.Assister.Team));
                }

                Console.Write(" [{0}]", e.Weapon.Weapon);

                if (e.Headshot)
                {
                    Console.Write("[HS]");
                }

                if (e.PenetratedObjects > 0)
                {
                    Console.Write("[Wall]");
                }

                Console.Write(" ");

                Console.Write(" <{0}><{1}>", e.Victim.Name, ShortTeam(e.Victim.Team));
                Console.Write(" Weapon {0} Ammo in Magazine {1} {2}", e.Victim.ActiveWeapon.Weapon,
                              e.Victim.ActiveWeapon.AmmoInMagazine.ToString(),
                              e.Victim.ActiveWeapon.AmmoInMagazine == WeaponInfo.WeaponAmmoMagazine(e.Victim.ActiveWeapon.Weapon) ?
                              "Ammo Max" : "");

                if (BackStabbing(e))
                {
                    Console.Write("  Not Looking player");
                }
                else
                {
                    Console.Write("  LookingPlayer");
                }

                if (e.Victim.Team == Team.CounterTerrorist)
                {
                    numberCT--;
                }
                else
                {
                    numberT--;
                }

                Console.WriteLine();
                WriteToFileDeadPlayers(outputStream, AllPlayers[e.Victim.Name]);
                deaths.Add(new Death(GetPositionMiniMap(e.Victim.Position, map.pos_x, map.pos_y, map.scale), e.Victim.Team));
            };

            parser.RoundEnd += (sender, e) => {
                Console.WriteLine("NumberCT alive " + numberCT.ToString() + " Number T alive " + numberT.ToString());
                Console.WriteLine();

                GenerateHeatMaps.GenerateMap(deaths, parser.CTScore + parser.TScore);
            };

            parser.TickDone += (sender, e) => {
                float currentTime = parser.CurrentTime - timeBeginningRound;

                // Updated every frame
                foreach (var player in parser.PlayingParticipants)
                {
                    // We multiply it by the time of one tick
                    // Since the velocity is given in
                    // ingame-units per second
                    // Console.WriteLine("{0} {1}", player.Name, player.Position);
                    if (AllPlayers.ContainsKey(player.Name))
                    {
                        Player current = AllPlayers[player.Name];
                        //if (player.IsAlive) {
                        //    current.Update(player.Position, player.ActiveWeapon.AmmoInMagazine);
                        //}
                    }
                    else
                    {
                        AllPlayers.Add(player.Name, new Player(player.Name, player.Position, player.Position,
                                                               player.ActiveWeapon.AmmoInMagazine, player.ActiveWeapon.Weapon, player.Team,
                                                               (player.Team == Team.CounterTerrorist) ? parser.CTClanName : parser.TClanName));
                    }
                }
            };

            parser.ParseToEnd();
            outputStream.Close();
        }