示例#1
0
        public static void saveDemo(demodatainstance instance, mapstatus stat)
        {
            DateTime now      = DateTime.Now;
            string   filePath = Environment.CurrentDirectory + "/demos/" + now.Year + "-" + now.Month + "-" + now.Day + "-" + now.Hour + "-" + now.Minute + "-" + now.Second + "_" + stat.filename + ".replay";

            serialwrite.Binary.WriteToBinaryFile <demodatainstance>(filePath, instance);
            serialwrite.Binary.WriteToBinaryFile <demostat>(filePath + "ts", instance.info);
        }
示例#2
0
        //Initialisation step, should fire when parsing the demo for first time
        public static void getDataInstanceAsync(DemoParser parser, Action <float> updateProgress = null, Action <demodatainstance> getResult = null) //Report progress
        {
            BackgroundWorker bg = new BackgroundWorker();

            demodatainstance testinstance = new demodatainstance(null);

            //Assign basic information
            testinstance.info.mapname    = parser.Map;
            testinstance.info.ctName     = parser.CTClanName;
            testinstance.info.tName      = parser.TClanName;
            testinstance.info.serverName = parser.Header.ServerName;
            testinstance.info.ctScore    = parser.CTScore;
            testinstance.info.tScore     = parser.TScore;

            bg.DoWork += (sender, ee) =>
            {
                //Subscribe to events here
                parser.WeaponFired += (object o, WeaponFiredEventArgs e) =>
                {
                    //Add the weapon fired position to that players most recent round
                    testinstance.players[e.Shooter.EntityID].rounds.Last().shotsFired.Add(new vector3(
                                                                                              e.Shooter.Position.X,
                                                                                              e.Shooter.Position.Y,
                                                                                              e.Shooter.Position.Z));
                };

                //Add a new round to each player on each team, on round start
                parser.RoundStart += (object o, RoundStartedEventArgs e) =>
                {
                    //foreach (p_Team recTeam in teams)
                    //foreach (p_Player player in testinstance.players.Values.ToList())
                    //     player.rounds.Add(new p_Round());

                    //Loop over each player on round start and assign the team to it
                    foreach (DemoInfo.Player player in parser.PlayingParticipants)
                    {
                        if (player.IsAlive)
                        {
                            testinstance.players[player.EntityID].rounds.Add(new p_Round());

                            p_Team_Identifier tIdentify = p_Team_Identifier.counterterrorist;
                            if (player.Team == Team.Terrorist)
                            {
                                tIdentify = p_Team_Identifier.terrorist;
                            }

                            testinstance.players[player.EntityID].rounds.Last().teamPlayedOnRound = tIdentify;
                        }
                    }
                };

                //Log all player deaths
                parser.PlayerKilled += (object o, PlayerKilledEventArgs e) =>
                {
                    //Do a team check
                    int team = 0;
                    if (e.Victim.Team == Team.Terrorist)
                    {
                        team = 1;
                    }

                    //Add the player death
                    testinstance.players[e.Victim.EntityID].deathPositions.Add(new vector3(
                                                                                   e.Victim.Position.X,
                                                                                   e.Victim.Position.Y,
                                                                                   e.Victim.Position.Z));
                };

                int uProg      = 0;
                int tickSwitch = 0;

                //Loop through ticks here
                while (parser.ParseNextTick() != false)
                {
                    foreach (DemoInfo.Player player in parser.PlayingParticipants)
                    {
                        //Check if the player exists on the teams
                        if (!testinstance.players.ContainsKey(player.EntityID))
                        {
                            testinstance.players.Add(player.EntityID, new p_Player(player.Name, player.SteamID));
                        }
                    }

                    if (tickSwitch > 5)
                    {
                        foreach (DemoInfo.Player player in parser.PlayingParticipants)
                        {
                            //Check if the player is alive
                            if (player.IsAlive)
                            {
                                //Add the players position
                                testinstance.players[player.EntityID].rounds.Last().positions.Add(new vector3(player.Position.X, player.Position.Y, player.Position.Z));
                            }
                        }

                        tickSwitch = 0;
                    }

                    tickSwitch++;

                    //Report its progress
                    //updateProgress?.Invoke(parser.ParsingProgess);
                    uProg++;
                    if (uProg > 1000)
                    {
                        bg.ReportProgress(Convert.ToInt32(parser.ParsingProgess * 100));
                        uProg = 0;
                    }
                }


                ee.Result = testinstance;
            };
            bg.RunWorkerCompleted += (sender, e) =>
            {
                demodatainstance result = (demodatainstance)e.Result;
                getResult?.Invoke(result);
            };
            bg.WorkerReportsProgress = true;
            bg.ProgressChanged      += (sender, e) =>
            {
                updateProgress(e.ProgressPercentage);
            };

            bg.RunWorkerAsync();
        }