示例#1
0
        void BombAbortPlant_Event(object sender, BombEventArgs e)
        {
            RoundBombPlantAttempt RoundBombAbortAttempt = CurrentRound.Players[e.Player.SteamID].BombPlantAttempts.LastOrDefault();

            RoundBombAbortAttempt.EndTick = parser.CurrentTick;
            RoundBombAbortAttempt.EndTime = parser.CurrentTime;
        }
示例#2
0
        void BombExploded_Event(object sender, BombEventArgs e)
        {
            RoundBombPlant RoundBombPlant = CurrentRound.Players[e.Player.SteamID].BombPlantAttempts.Last().BombPlant;

            RoundBombPlant.EndTick  = parser.CurrentTick;
            RoundBombPlant.EndTime  = parser.CurrentTime;
            RoundBombPlant.Exploded = true;
        }
示例#3
0
    private void OnBombDefused(object sender, BombEventArgs args)
    {
        // Console.WriteLine($"Bomb defused, round={roundNumber}, currentTick={currentTick}");

        isBombPlanted              = false;
        bombPlantedTick            = 0;
        bombPlantTotalElapsedTicks = 0;
    }
 internal BombEvents AssembleBomb(BombEventArgs be, string gameevent)
 {
     return(new BombEvents
     {
         GameeventType = gameevent,
         site = be.Site,
         Actor = AssemblePlayer(be.Player)
     });
 }
示例#5
0
    private void OnBombPlanted(object sender, BombEventArgs args)
    {
        // Console.WriteLine($"Bomb planted, round={roundNumber}, currentTick={currentTick}, site={args.Site}, player={args.Player.Name}");

        isBombPlanted              = true;
        bombPlantedTick            = _demoParser.CurrentTick;
        bombPlantTotalElapsedTicks = 0;
        bombsite = args.Site;
    }
示例#6
0
        private void HandleBombExploded(object sender, BombEventArgs e)
        {
            BombExplodedEvent newEvent = new BombExplodedEvent()
            {
                SteamID = e.Player?.SteamID,
                Site    = e.Site
            };

            CurrentTick.Events.Add(newEvent);
        }
示例#7
0
        void BombPlanted_Event(object sender, BombEventArgs e)
        {
            RoundBombPlantAttempt RoundBombPlantAttempt = CurrentRound.Players[e.Player.SteamID].BombPlantAttempts.LastOrDefault();

            RoundBombPlantAttempt.EndTick   = parser.CurrentTick;
            RoundBombPlantAttempt.EndTime   = parser.CurrentTime;
            RoundBombPlantAttempt.BombPlant = new RoundBombPlant {
                StartTick = parser.CurrentTick, StartTime = parser.CurrentTime, Player = CurrentRound.Players[e.Player.SteamID]
            };
            lastBombPlanter = e.Player.SteamID;
        }
示例#8
0
        void BombDefused_Event(object sender, BombEventArgs e)
        {
            RoundBombDefuseAttempt RoundBombDefused = CurrentRound.Players[e.Player.SteamID].BombDefuseAttempts.LastOrDefault();

            RoundBombDefused.EndTick = parser.CurrentTick;
            RoundBombDefused.EndTime = parser.CurrentTime;

            RoundBombPlant RoundBombPlant = CurrentRound.Players[lastBombPlanter].BombPlantAttempts.LastOrDefault().BombPlant;

            RoundBombPlant.EndTick = parser.CurrentTick;
            RoundBombPlant.EndTime = parser.CurrentTime;
            RoundBombPlant.Defused = true;

            CurrentRound.BombDefused = true;
        }
示例#9
0
 protected virtual void eventsManager_BombPlanted(object sender, BombEventArgs e)
 {
 }
示例#10
0
        public static void Apply(GameEvent rawEvent, DemoParser parser)
        {
            var descriptors  = parser.GEH_Descriptors;
            var blindPlayers = parser.GEH_BlindPlayers;

            if (descriptors == null)
            {
                return;
            }

            var eventDescriptor = descriptors[rawEvent.EventId];

            if (parser.Players.Count == 0 && eventDescriptor.Name != "player_connect")
            {
                return;
            }

            if (eventDescriptor.Name == "round_start")
            {
                parser.RaiseRoundStart();
            }

            if (eventDescriptor.Name == "begin_new_match")
            {
                parser.RaiseMatchStarted();
            }


            Dictionary <string, object> data;

            switch (eventDescriptor.Name)
            {
            case "weapon_fire":

                data = MapData(eventDescriptor, rawEvent);

                WeaponFiredEventArgs fire = new WeaponFiredEventArgs();
                fire.Shooter = parser.Players.ContainsKey((int)data ["userid"]) ? parser.Players [(int)data ["userid"]] : null;
                fire.Weapon  = new Equipment((string)data ["weapon"]);

                if (fire.Shooter != null && fire.Weapon.Class != EquipmentClass.Grenade)
                {
                    fire.Weapon = fire.Shooter.ActiveWeapon;
                }

                parser.RaiseWeaponFired(fire);
                break;

            case "player_death":
                data = MapData(eventDescriptor, rawEvent);

                PlayerKilledEventArgs kill = new PlayerKilledEventArgs();

                kill.DeathPerson = parser.Players.ContainsKey((int)data["userid"]) ? parser.Players[(int)data["userid"]] : null;
                kill.Killer      = parser.Players.ContainsKey((int)data["attacker"]) ? parser.Players[(int)data["attacker"]] : null;
                kill.Headshot    = (bool)data["headshot"];
                kill.Weapon      = new Equipment((string)data["weapon"], (string)data["weapon_itemid"]);

                if (kill.Killer != null && kill.Weapon.Class != EquipmentClass.Grenade && kill.Killer.Weapons.Count() != 0)
                {
                                        #if DEBUG
                    if (kill.Weapon.Weapon != kill.Killer.ActiveWeapon.Weapon)
                    {
                        throw new InvalidDataException();
                    }
                                        #endif
                    kill.Weapon = kill.Killer.ActiveWeapon;
                }


                kill.PenetratedObjects = (int)data["penetrated"];

                parser.RaisePlayerKilled(kill);
                break;

                #region Nades
            case "player_blind":
                data = MapData(eventDescriptor, rawEvent);
                if (parser.Players.ContainsKey((int)data["userid"]))
                {
                    blindPlayers.Add(parser.Players[(int)data["userid"]]);
                }
                break;

            case "flashbang_detonate":
                var args = FillNadeEvent <FlashEventArgs>(MapData(eventDescriptor, rawEvent), parser);
                args.FlashedPlayers = blindPlayers.ToArray();
                parser.RaiseFlashExploded(args);
                blindPlayers.Clear();
                break;

            case "hegrenade_detonate":
                parser.RaiseGrenadeExploded(FillNadeEvent <GrenadeEventArgs>(MapData(eventDescriptor, rawEvent), parser));
                break;

            case "decoy_started":
                parser.RaiseDecoyStart(FillNadeEvent <DecoyEventArgs>(MapData(eventDescriptor, rawEvent), parser));
                break;

            case "decoy_detonate":
                parser.RaiseDecoyEnd(FillNadeEvent <DecoyEventArgs>(MapData(eventDescriptor, rawEvent), parser));
                break;

            case "smokegrenade_detonate":
                parser.RaiseSmokeStart(FillNadeEvent <SmokeEventArgs>(MapData(eventDescriptor, rawEvent), parser));
                break;

            case "smokegrenade_expired":
                parser.RaiseSmokeEnd(FillNadeEvent <SmokeEventArgs>(MapData(eventDescriptor, rawEvent), parser));
                break;

            case "inferno_startburn":
                parser.RaiseFireStart(FillNadeEvent <FireEventArgs>(MapData(eventDescriptor, rawEvent), parser));
                break;

            case "inferno_expire":
                parser.RaiseFireEnd(FillNadeEvent <FireEventArgs>(MapData(eventDescriptor, rawEvent), parser));
                break;
                #endregion

            case "player_connect":
                data = MapData(eventDescriptor, rawEvent);

                PlayerInfo player = new PlayerInfo();
                player.UserID = (int)data["userid"];
                player.Name   = (string)data["name"];

                //player.IsFakePlayer = (bool)data["bot"];

                int index = (int)data["index"];

                parser.RawPlayers[index] = player;


                break;

            case "player_disconnect":
                data = MapData(eventDescriptor, rawEvent);
                int toDelete = (int)data["userid"];
                for (int i = 0; i < parser.RawPlayers.Length; i++)
                {
                    if (parser.RawPlayers[i] != null && parser.RawPlayers[i].UserID == toDelete)
                    {
                        parser.RawPlayers[i] = null;
                        break;
                    }
                }

                parser.Players.Remove(toDelete);

                break;

            case "bomb_beginplant":          //When the bomb is starting to get planted
            case "bomb_abortplant":          //When the bomb planter stops planting the bomb
            case "bomb_planted":             //When the bomb has been planted
            case "bomb_defused":             //When the bomb has been defused
            case "bomb_exploded":            //When the bomb has exploded
                data = MapData(eventDescriptor, rawEvent);

                var bombEventArgs = new BombEventArgs();
                bombEventArgs.Player = parser.Players.ContainsKey((int)data["userid"]) ? parser.Players[(int)data["userid"]] : null;

                int site = (int)data["site"];

                if (site == parser.bombsiteAIndex)
                {
                    bombEventArgs.Site = 'A';
                }
                else if (site == parser.bombsiteBIndex)
                {
                    bombEventArgs.Site = 'B';
                }
                else
                {
                    var relevantTrigger = parser.triggers.Single(a => a.Index == site);
                    if (relevantTrigger.IsInside(parser.bombsiteACenter))
                    {
                        //planted at A.
                        bombEventArgs.Site    = 'A';
                        parser.bombsiteAIndex = site;
                    }
                    else if (relevantTrigger.IsInside(parser.bombsiteBCenter))
                    {
                        //planted at B.
                        bombEventArgs.Site    = 'B';
                        parser.bombsiteBIndex = site;
                    }
                    else
                    {
                        throw new InvalidDataException("Was the bomb planted at C? Neither A nor B is inside the bombsite");
                    }
                }



                switch (eventDescriptor.Name)
                {
                case "bomb_beginplant":
                    parser.RaiseBombBeginPlant(bombEventArgs);
                    break;

                case "bomb_abortplant":
                    parser.RaiseBombAbortPlant(bombEventArgs);
                    break;

                case "bomb_planted":
                    parser.RaiseBombPlanted(bombEventArgs);
                    break;

                case "bomb_defused":
                    parser.RaiseBombDefused(bombEventArgs);
                    break;

                case "bomb_exploded":
                    parser.RaiseBombExploded(bombEventArgs);
                    break;
                }

                break;

            case "bomb_begindefuse":
                data = MapData(eventDescriptor, rawEvent);
                var e = new BombDefuseEventArgs();
                e.Player = parser.Players.ContainsKey((int)data["userid"]) ? parser.Players[(int)data["userid"]] : null;
                e.HasKit = (bool)data["haskit"];
                parser.RaiseBombBeginDefuse(e);
                break;

            case "bomb_abortdefuse":
                data = MapData(eventDescriptor, rawEvent);
                var e2 = new BombDefuseEventArgs();
                e2.Player = parser.Players.ContainsKey((int)data["userid"]) ? parser.Players[(int)data["userid"]] : null;
                e2.HasKit = e2.Player.HasDefuseKit;
                parser.RaiseBombAbortDefuse(e2);
                break;
            }
        }
示例#11
0
 private void Parser_BombDefused(object sender, BombEventArgs e)
 {
     defuserSteamId = e.Player?.SteamID;
 }
示例#12
0
 private void Parser_BombPlanted(object sender, BombEventArgs e)
 {
     planterSteamId = e.Player?.SteamID;
 }
 private void Parser_BombPlanted(object sender, BombEventArgs e)
 {
     results.Players[e.Player.SteamID].BombPlants.Add(this.currentRound);
     this.currentRound.bombPlanter = results.Players[e.Player.SteamID];
 }
示例#14
0
 private static void Parser_BombPlanted(object sender, BombEventArgs e)
 {
     _results.Players[e.Player.SteamID].BombPlants.Add(_currentRound);
     _currentRound.BombPlanter     = _results.Players[e.Player.SteamID];
     _currentRound.BombPlantedTime = GetRoundDuration();
 }
示例#15
0
 void BombBeginPlant_Event(object sender, BombEventArgs e)
 {
     CurrentRound.Players[e.Player.SteamID].BombPlantAttempts.Add(new RoundBombPlantAttempt {
         StartTick = parser.CurrentTick, StartTime = parser.CurrentTime, Site = e.Site, Player = CurrentRound.Players[e.Player.SteamID]
     });
 }
示例#16
0
        /// <summary>
        /// Apply the specified rawEvent to the parser.
        /// </summary>
        /// <param name="rawEvent">The raw event.</param>
        /// <param name="parser">The parser to mutate.</param>
        public static void Apply(GameEvent rawEvent, DemoParser parser)
        {
            var descriptors  = parser.GEH_Descriptors;
            var blindPlayers = parser.GEH_BlindPlayers;

            if (descriptors == null)
            {
                return;
            }

            Dictionary <string, object> data;
            var eventDescriptor = descriptors[rawEvent.EventId];

            if (parser.Players.Count == 0 && eventDescriptor.Name != "player_connect")
            {
                return;
            }

            if (eventDescriptor.Name == "round_start")
            {
                data = MapData(eventDescriptor, rawEvent);

                RoundStartedEventArgs rs = new RoundStartedEventArgs()
                {
                    TimeLimit = (int)data["timelimit"],
                    FragLimit = (int)data["fraglimit"],
                    Objective = (string)data["objective"]
                };

                parser.RaiseRoundStart(rs);
            }

            if (eventDescriptor.Name == "cs_win_panel_match")
            {
                parser.RaiseWinPanelMatch();
            }

            if (eventDescriptor.Name == "round_announce_final")
            {
                parser.RaiseRoundFinal();
            }

            if (eventDescriptor.Name == "round_announce_last_round_half")
            {
                parser.RaiseLastRoundHalf();
            }

            if (eventDescriptor.Name == "round_end")
            {
                data = MapData(eventDescriptor, rawEvent);

                Team t = Team.Spectate;

                int winner = (int)data ["winner"];

                if (winner == parser.tID)
                {
                    t = Team.Terrorist;
                }
                else if (winner == parser.ctID)
                {
                    t = Team.CounterTerrorist;
                }

                RoundEndedEventArgs roundEnd = new RoundEndedEventArgs()
                {
                    Reason  = (RoundEndReason)data["reason"],
                    Winner  = t,
                    Message = (string)data["message"],
                };

                parser.RaiseRoundEnd(roundEnd);
            }

            if (eventDescriptor.Name == "round_officially_ended")
            {
                parser.RaiseRoundOfficiallyEnd();
            }

            if (eventDescriptor.Name == "round_mvp")
            {
                data = MapData(eventDescriptor, rawEvent);

                RoundMVPEventArgs roundMVPArgs = new RoundMVPEventArgs();
                roundMVPArgs.Player = parser.Players.ContainsKey((int)data["userid"]) ? parser.Players[(int)data["userid"]] : null;
                roundMVPArgs.Reason = (RoundMVPReason)data["reason"];

                parser.RaiseRoundMVP(roundMVPArgs);
            }

            if (eventDescriptor.Name == "bot_takeover")
            {
                data = MapData(eventDescriptor, rawEvent);

                BotTakeOverEventArgs botTakeOverArgs = new BotTakeOverEventArgs();
                botTakeOverArgs.Taker = parser.Players.ContainsKey((int)data["userid"]) ? parser.Players[(int)data["userid"]] : null;

                parser.RaiseBotTakeOver(botTakeOverArgs);
            }

            if (eventDescriptor.Name == "begin_new_match")
            {
                parser.RaiseMatchStarted();
            }

            if (eventDescriptor.Name == "round_announce_match_start")
            {
                parser.RaiseRoundAnnounceMatchStarted();
            }

            if (eventDescriptor.Name == "round_freeze_end")
            {
                parser.RaiseFreezetimeEnded();
            }

            //if (eventDescriptor.Name != "player_footstep" && eventDescriptor.Name != "weapon_fire" && eventDescriptor.Name != "player_jump") {
            //	Console.WriteLine (eventDescriptor.Name);
            //}

            switch (eventDescriptor.Name)
            {
            case "weapon_fire":

                data = MapData(eventDescriptor, rawEvent);

                WeaponFiredEventArgs fire = new WeaponFiredEventArgs();
                fire.Shooter = parser.Players.ContainsKey((int)data ["userid"]) ? parser.Players [(int)data ["userid"]] : null;

                if (fire.Shooter != null && fire.Shooter.ActiveWeapon != null)
                {
                    fire.Weapon = fire.Shooter.ActiveWeapon;
                }
                else
                {
                    // should not happen but we never know
                    fire.Weapon = new Equipment((string)data["weapon"]);
                }

                // Workaround to detect who throw molo / inc
                if (fire.Weapon.Weapon == EquipmentElement.Molotov || fire.Weapon.Weapon == EquipmentElement.Incendiary)
                {
                    parser.LastPlayerIdsThrownFire.Enqueue((int)data["userid"]);
                }

                parser.RaiseWeaponFired(fire);
                break;

            case "player_death":
                data = MapData(eventDescriptor, rawEvent);

                PlayerKilledEventArgs kill = new PlayerKilledEventArgs();

                kill.Victim   = parser.Players.ContainsKey((int)data["userid"]) ? parser.Players[(int)data["userid"]] : null;
                kill.Killer   = parser.Players.ContainsKey((int)data["attacker"]) ? parser.Players[(int)data["attacker"]] : null;
                kill.Assister = parser.Players.ContainsKey((int)data["assister"]) ? parser.Players[(int)data["assister"]] : null;
                kill.Headshot = (bool)data["headshot"];
                kill.Weapon   = new Equipment((string)data["weapon"], (string)data["weapon_itemid"]);

                if (kill.Killer != null && kill.Killer.ActiveWeapon != null)
                {
                    // in case of grenade kills, killer's active weapon is not his grenade at this state
                    if (kill.Weapon == null || (kill.Weapon != null && kill.Weapon.Class != EquipmentClass.Grenade))
                    {
                        kill.Weapon        = kill.Killer.ActiveWeapon;
                        kill.Weapon.SkinID = (string)data["weapon_itemid"];
                    }
                }

                kill.PenetratedObjects = (int)data["penetrated"];

                parser.RaisePlayerKilled(kill);
                break;

            case "player_hurt":
                data = MapData(eventDescriptor, rawEvent);

                PlayerHurtEventArgs hurt = new PlayerHurtEventArgs();
                hurt.Player       = parser.Players.ContainsKey((int)data ["userid"]) ? parser.Players [(int)data ["userid"]] : null;
                hurt.Attacker     = parser.Players.ContainsKey((int)data ["attacker"]) ? parser.Players [(int)data ["attacker"]] : null;
                hurt.Health       = (int)data ["health"];
                hurt.Armor        = (int)data ["armor"];
                hurt.HealthDamage = (int)data ["dmg_health"];
                hurt.ArmorDamage  = (int)data ["dmg_armor"];
                hurt.Hitgroup     = (Hitgroup)((int)data ["hitgroup"]);
                hurt.Weapon       = new Equipment((string)data["weapon"]);

                if (hurt.Attacker != null && hurt.Attacker.ActiveWeapon != null)
                {
                    // in case of grenade attacks, attacker's active weapon is not his grenade at this state
                    if (hurt.Weapon == null || (hurt.Weapon != null && hurt.Weapon.Class != EquipmentClass.Grenade))
                    {
                        hurt.Weapon = hurt.Attacker.ActiveWeapon;
                    }
                }

                parser.RaisePlayerHurt(hurt);
                break;

                #region Nades
            case "player_blind":
                // BOT are ignored (thrower or not)
                data = MapData(eventDescriptor, rawEvent);
                if (parser.Players.ContainsKey((int)data["userid"]))
                {
                    Player p = parser.Players[(int)data["userid"]];

                    if (data.ContainsKey("attacker") && parser.Players.ContainsKey((int)data["attacker"]))
                    {
                        Player attacker         = parser.Players[(int)data["attacker"]];
                        PlayerBlindEventArgs ev = new PlayerBlindEventArgs
                        {
                            Player   = p,
                            Duration = (float)data["blind_duration"],
                            Attacker = attacker,
                        };
                        blindPlayers.Add(p);
                        parser.RaisePlayerBlind(ev);
                    }
                }
                break;

            case "flashbang_detonate":
                var args = FillNadeEvent <FlashEventArgs>(MapData(eventDescriptor, rawEvent), parser);
                args.FlashedPlayers = blindPlayers.ToArray();
                parser.RaiseFlashExploded(args);
                blindPlayers.Clear();
                break;

            case "hegrenade_detonate":
                parser.RaiseGrenadeExploded(FillNadeEvent <GrenadeEventArgs>(MapData(eventDescriptor, rawEvent), parser));
                break;

            case "decoy_started":
                parser.RaiseDecoyStart(FillNadeEvent <DecoyEventArgs>(MapData(eventDescriptor, rawEvent), parser));
                break;

            case "decoy_detonate":
                parser.RaiseDecoyEnd(FillNadeEvent <DecoyEventArgs>(MapData(eventDescriptor, rawEvent), parser));
                break;

            case "smokegrenade_detonate":
                parser.RaiseSmokeStart(FillNadeEvent <SmokeEventArgs>(MapData(eventDescriptor, rawEvent), parser));
                break;

            case "smokegrenade_expired":
                parser.RaiseSmokeEnd(FillNadeEvent <SmokeEventArgs>(MapData(eventDescriptor, rawEvent), parser));
                break;

            case "inferno_startburn":
                var fireData = MapData(eventDescriptor, rawEvent);
                // molotov / inc events doesn't contains thrower, this is a hack to retrieve it
                // WARNING: This hack is not 100% accurated since if a molotov never burn, the ids will be incorrect

                // 1. when a molo / inc is thrown (weapon_fire events), we add the userid to the queue
                // 2. when this event (inferno_startburn) occurs we retrieve the last userid from this queue (LastPlayerIdsThrownFire)
                // 3. we add the userid to the queue LastPlayerIdsStartFire to retrieve the player at the next inferno_expire event
                if (!fireData.ContainsKey("userid") && parser.LastPlayerIdsThrownFire.Count > 0)
                {
                    int throwerId = parser.LastPlayerIdsThrownFire.Dequeue();
                    fireData.Add("userid", throwerId);
                    // add this id to the queue to be able to detect it when the inferno_expire event occurs
                    parser.LastPlayerIdsStartFire.Enqueue(throwerId);
                }
                parser.RaiseFireStart(FillNadeEvent <FireEventArgs>(fireData, parser));
                break;

            case "inferno_expire":
                var fireEndData = MapData(eventDescriptor, rawEvent);
                if (!fireEndData.ContainsKey("userid") && parser.LastPlayerIdsStartFire.Count > 0)
                {
                    fireEndData.Add("userid", parser.LastPlayerIdsStartFire.Dequeue());
                }
                parser.RaiseFireEnd(FillNadeEvent <FireEventArgs>(fireEndData, parser));
                break;
                #endregion

            case "player_connect":
                data = MapData(eventDescriptor, rawEvent);

                PlayerInfo player = new PlayerInfo();
                player.UserID = (int)data ["userid"];
                player.Name   = (string)data ["name"];
                player.GUID   = (string)data ["networkid"];
                player.XUID   = player.GUID == "BOT" ? 0 : GetCommunityID(player.GUID);


                //player.IsFakePlayer = (bool)data["bot"];

                int index = (int)data["index"];

                parser.RawPlayers[index] = player;


                break;

            case "player_disconnect":
                data = MapData(eventDescriptor, rawEvent);

                PlayerDisconnectEventArgs disconnect = new PlayerDisconnectEventArgs
                {
                    Reason = (string)data["reason"],
                };
                disconnect.Player = parser.Players.ContainsKey((int)data["userid"]) ? parser.Players[(int)data["userid"]] : null;
                parser.RaisePlayerDisconnect(disconnect);

                int toDelete = (int)data["userid"];
                for (int i = 0; i < parser.RawPlayers.Length; i++)
                {
                    if (parser.RawPlayers[i] != null && parser.RawPlayers[i].UserID == toDelete)
                    {
                        parser.RawPlayers[i] = null;
                        break;
                    }
                }

                if (parser.Players.ContainsKey(toDelete))
                {
                    parser.Players.Remove(toDelete);
                }

                break;

            case "player_team":
                data = MapData(eventDescriptor, rawEvent);
                PlayerTeamEventArgs playerTeamEvent = new PlayerTeamEventArgs();

                Team t = Team.Spectate;

                int team = (int)data["team"];

                if (team == parser.tID)
                {
                    t = Team.Terrorist;
                }
                else if (team == parser.ctID)
                {
                    t = Team.CounterTerrorist;
                }
                playerTeamEvent.NewTeam = t;

                t    = Team.Spectate;
                team = (int)data["oldteam"];
                if (team == parser.tID)
                {
                    t = Team.Terrorist;
                }
                else if (team == parser.ctID)
                {
                    t = Team.CounterTerrorist;
                }
                playerTeamEvent.OldTeam = t;

                playerTeamEvent.Swapped = parser.Players.ContainsKey((int)data["userid"]) ? parser.Players[(int)data["userid"]] : null;
                playerTeamEvent.IsBot   = (bool)data["isbot"];
                playerTeamEvent.Silent  = (bool)data["silent"];

                parser.RaisePlayerTeam(playerTeamEvent);
                break;

            case "bomb_beginplant":          //When the bomb is starting to get planted
            case "bomb_abortplant":          //When the bomb planter stops planting the bomb
            case "bomb_planted":             //When the bomb has been planted
            case "bomb_defused":             //When the bomb has been defused
            case "bomb_exploded":            //When the bomb has exploded
                data = MapData(eventDescriptor, rawEvent);

                var bombEventArgs = new BombEventArgs();
                bombEventArgs.Player = parser.Players.ContainsKey((int)data["userid"]) ? parser.Players[(int)data["userid"]] : null;

                int site = (int)data["site"];

                if (site == parser.bombsiteAIndex)
                {
                    bombEventArgs.Site = 'A';
                }
                else if (site == parser.bombsiteBIndex)
                {
                    bombEventArgs.Site = 'B';
                }
                else
                {
                    var relevantTrigger = parser.triggers.Single(a => a.Index == site);
                    if (relevantTrigger.Contains(parser.bombsiteACenter))
                    {
                        //planted at A.
                        bombEventArgs.Site    = 'A';
                        parser.bombsiteAIndex = site;
                    }
                    else
                    {
                        //planted at B.
                        bombEventArgs.Site    = 'B';
                        parser.bombsiteBIndex = site;
                    }
                }



                switch (eventDescriptor.Name)
                {
                case "bomb_beginplant":
                    parser.RaiseBombBeginPlant(bombEventArgs);
                    break;

                case "bomb_abortplant":
                    parser.RaiseBombAbortPlant(bombEventArgs);
                    break;

                case "bomb_planted":
                    parser.RaiseBombPlanted(bombEventArgs);
                    break;

                case "bomb_defused":
                    parser.RaiseBombDefused(bombEventArgs);
                    break;

                case "bomb_exploded":
                    parser.RaiseBombExploded(bombEventArgs);
                    break;
                }

                break;

            case "bomb_begindefuse":
                data = MapData(eventDescriptor, rawEvent);
                var e = new BombDefuseEventArgs();
                e.Player = parser.Players.ContainsKey((int)data["userid"]) ? parser.Players[(int)data["userid"]] : null;
                e.HasKit = (bool)data["haskit"];
                parser.RaiseBombBeginDefuse(e);
                break;

            case "bomb_abortdefuse":
                data = MapData(eventDescriptor, rawEvent);
                var e2 = new BombDefuseEventArgs();
                e2.Player = parser.Players.ContainsKey((int)data["userid"]) ? parser.Players[(int)data["userid"]] : null;
                e2.HasKit = e2.Player.HasDefuseKit;
                parser.RaiseBombAbortDefuse(e2);
                break;
            }
        }
示例#17
0
        public bool TryApplyMessage(ProtoBuf.IExtensible message, DemoParser parser)
        {
            if (message is CSVCMsg_GameEventList)
            {
                gameEventdescriptors.Clear();

                foreach (var d in ((CSVCMsg_GameEventList)message).descriptors)
                {
                    gameEventdescriptors[d.eventid] = d;
                }

                return(true);
            }

            if (gameEventdescriptors.Count == 0)
            {
                return(false);
            }

            var rawEvent = message as CSVCMsg_GameEvent;

            if (rawEvent == null)
            {
                return(false);
            }

            var eventDescriptor = gameEventdescriptors[rawEvent.eventid];

            switch (eventDescriptor.name)
            {
            case "round_announce_match_start":
                parser.EventsManager.RaiseMatchStarted();
                break;

            case "round_start":
                parser.EventsManager.RaiseRoundStart();
                break;

            case "round_mvp":
                MapData(eventDescriptor, rawEvent);

                if (parser.players.ContainsKey((int)data["userid"]))
                {
                    RoundMvpEventArgs mvp = new RoundMvpEventArgs();
                    mvp.Player = parser.players[(int)data["userid"]];
                    mvp.Reason = (int)data["reason"];

                    parser.EventsManager.RaiseRoundMvp(mvp);
                }
                break;

            case "round_end":
                if (parser.teams.Count > 2)
                {
                    MapData(eventDescriptor, rawEvent);

                    RoundEndedEventArgs arg = new RoundEndedEventArgs();
                    arg.Team   = parser.teams[(int)data["winner"]];
                    arg.Reason = (int)data["reason"];

                    if ((string)data["message"] != null)
                    {
                        arg.Message = (string)data["message"];
                    }

                    parser.EventsManager.RaiseRoundEnd(arg);
                }
                break;

            case "round_freeze_end":
                break;

            case "round_officially_ended":
                parser.EventsManager.RaiseRoundOfficiallyEnded();
                break;

            case "cs_win_panel_match":
                parser.EventsManager.RaiseMatchEnded();
                break;

            case "player_connect":
                //TODO throw event
                break;

            case "player_disconnect":
                //TODO throw event
                break;

            case "player_chat":
                MapData(eventDescriptor, rawEvent);

                if (parser.players.ContainsKey((int)data["userid"]))
                {
                    PlayerChatEventArgs chat = new PlayerChatEventArgs();
                    chat.Player   = parser.players[(int)data["userid"]];
                    chat.TeamOnly = (bool)data["teamonly"];
                    chat.Message  = (string)data["text"];

                    parser.EventsManager.RaisePlayerChat(chat);
                }
                break;

            case "player_death":
                MapData(eventDescriptor, rawEvent);

                if (parser.players.ContainsKey((int)data["userid"]) && parser.players.ContainsKey((int)data["attacker"]))
                {
                    string weapon_itemid = (string)data.GetValueOrDefault <string, object>("weapon_itemid", string.Empty);

                    PlayerKilledEventArgs kill = new PlayerKilledEventArgs();
                    kill.Victim            = parser.players[(int)data["userid"]];
                    kill.Killer            = parser.players[(int)data["attacker"]];
                    kill.Headshot          = (bool)data["headshot"];
                    kill.Weapon            = new Equipment((string)data["weapon"], weapon_itemid);
                    kill.PenetratedObjects = (int)data["penetrated"];

                    if (parser.players.ContainsKey((int)data["assister"]))
                    {
                        kill.Assist = parser.players[(int)data["assister"]];
                    }

                    parser.EventsManager.RaisePlayerKilled(kill);
                }
                break;

                #region Bomb
            case "bomb_planted":                     //When the bomb has been planted
                MapData(eventDescriptor, rawEvent);

                BombEventArgs bombEventArgs = new BombEventArgs();
                bombEventArgs.Player   = parser.players[(int)data["userid"]];
                bombEventArgs.BombSite = (int)data["site"];                         //entity index of the bombsite.

                parser.EventsManager.RaiseBombPlanted(bombEventArgs);
                break;

            case "bomb_defused":                     //When the bomb has been defused
                MapData(eventDescriptor, rawEvent);

                BombEventArgs bombEventArg = new BombEventArgs();
                bombEventArg.Player   = parser.players[(int)data["userid"]];
                bombEventArg.BombSite = (int)data["site"];                         //entity index of the bombsite.

                parser.EventsManager.RaiseBombDefused(bombEventArg);
                break;

            case "bomb_exploded":                     //When the bomb has exploded
                MapData(eventDescriptor, rawEvent);

                BombEventArgs bombEvent = new BombEventArgs();
                bombEvent.Player   = parser.players[(int)data["userid"]];
                bombEvent.BombSite = (int)data["site"];                         //entity index of the bombsite.

                parser.EventsManager.RaiseBombExploded(bombEvent);
                break;

                #endregion

                #region Nades

            /*case "player_blind":
             *      MapData (eventDescriptor, rawEvent);
             *      if (parser.Players.ContainsKey((int)data["userid"] - 2))
             *              blindPlayers.Add(parser.Players[(int)data["userid"] - 2]);
             *      break;*/
            case "flashbang_detonate":
                MapData(eventDescriptor, rawEvent);
                parser.EventsManager.RaiseFlashExploded(FillNadeEvent <FlashEventArgs>(data, parser));
                break;

            case "hegrenade_detonate":
                MapData(eventDescriptor, rawEvent);
                parser.EventsManager.RaiseGrenadeExploded(FillNadeEvent <GrenadeEventArgs>(data, parser));
                break;

            case "decoy_started":
                MapData(eventDescriptor, rawEvent);
                parser.EventsManager.RaiseDecoyStart(FillNadeEvent <DecoyEventArgs>(data, parser));
                break;

            case "decoy_detonate":
                MapData(eventDescriptor, rawEvent);
                parser.EventsManager.RaiseDecoyEnd(FillNadeEvent <DecoyEventArgs>(data, parser));
                break;

            case "smokegrenade_detonate":
                MapData(eventDescriptor, rawEvent);
                parser.EventsManager.RaiseSmokeStart(FillNadeEvent <SmokeEventArgs>(data, parser));
                break;

            case "smokegrenade_expired":
                MapData(eventDescriptor, rawEvent);
                parser.EventsManager.RaiseSmokeEnd(FillNadeEvent <SmokeEventArgs>(data, parser));
                break;

            case "inferno_startburn":
                MapData(eventDescriptor, rawEvent);
                parser.EventsManager.RaiseFireStart(FillNadeEvent <FireEventArgs>(data, parser));
                break;

            case "inferno_expire":
                MapData(eventDescriptor, rawEvent);
                parser.EventsManager.RaiseFireEnd(FillNadeEvent <FireEventArgs>(data, parser));
                break;
                #endregion
            }

            return(true);
        }
示例#18
0
 private void CurrentDemoParser_BombDefused(object sender, BombEventArgs e)
 {
     SteamController.LogToConsole((e.Player != null ? e.Player.Name : "Nobody") + " defused the bomb at " + e.Site + " site");
 }
示例#19
0
 private static void Parser_BombExploded(object sender, BombEventArgs e)
 {
     _results.Players[_currentRound.BombPlanter.SteamID].BombExplosions.Add(_currentRound);
     _currentRound.IsBombExploded = true;
 }
示例#20
0
 private void CurrentDemoParser_BombBeginPlant(object sender, BombEventArgs e)
 {
     SteamController.LogToConsole((e.Player != null ? e.Player.Name : "Nobody") + " started planting the bomb at " + e.Site + " site");
 }
示例#21
0
        /// <summary>
        /// Apply the specified rawEvent to the parser.
        /// </summary>
        /// <param name="rawEvent">The raw event.</param>
        /// <param name="parser">The parser to mutate.</param>
        public static void Apply(GameEvent rawEvent, DemoParser parser)
        {
            var descriptors  = parser.GEH_Descriptors;
            var blindPlayers = parser.GEH_BlindPlayers;

            if (descriptors == null)
            {
                return;
            }

            Dictionary <string, object> data;
            var eventDescriptor = descriptors[rawEvent.EventId];

            if (parser.Players.Count == 0 && eventDescriptor.Name != "player_connect")
            {
                return;
            }

            if (eventDescriptor.Name == "round_start")
            {
                data = MapData(eventDescriptor, rawEvent);

                RoundStartedEventArgs rs = new RoundStartedEventArgs()
                {
                    TimeLimit = (int)data["timelimit"],
                    FragLimit = (int)data["fraglimit"],
                    Objective = (string)data["objective"]
                };

                parser.RaiseRoundStart(rs);
            }

            if (eventDescriptor.Name == "cs_win_panel_match")
            {
                parser.RaiseWinPanelMatch();
            }

            if (eventDescriptor.Name == "round_announce_final")
            {
                parser.RaiseRoundFinal();
            }

            if (eventDescriptor.Name == "round_announce_last_round_half")
            {
                parser.RaiseLastRoundHalf();
            }

            if (eventDescriptor.Name == "round_end")
            {
                data = MapData(eventDescriptor, rawEvent);

                Team t = Team.Spectate;

                int winner = (int)data ["winner"];

                if (winner == parser.tID)
                {
                    t = Team.Terrorist;
                }
                else if (winner == parser.ctID)
                {
                    t = Team.CounterTerrorist;
                }

                RoundEndedEventArgs roundEnd = new RoundEndedEventArgs()
                {
                    Reason  = (RoundEndReason)data["reason"],
                    Winner  = t,
                    Message = (string)data["message"],
                };

                parser.RaiseRoundEnd(roundEnd);
            }

            if (eventDescriptor.Name == "round_officially_ended")
            {
                parser.RaiseRoundOfficiallyEnd();
            }

            if (eventDescriptor.Name == "round_mvp")
            {
                data = MapData(eventDescriptor, rawEvent);

                RoundMVPEventArgs roundMVPArgs = new RoundMVPEventArgs();
                roundMVPArgs.Player = parser.Players.ContainsKey((int)data["userid"]) ? parser.Players[(int)data["userid"]] : null;
                roundMVPArgs.Reason = (RoundMVPReason)data["reason"];

                parser.RaiseRoundMVP(roundMVPArgs);
            }

            if (eventDescriptor.Name == "bot_takeover")
            {
                data = MapData(eventDescriptor, rawEvent);

                BotTakeOverEventArgs botTakeOverArgs = new BotTakeOverEventArgs();
                botTakeOverArgs.Taker = parser.Players.ContainsKey((int)data["userid"]) ? parser.Players[(int)data["userid"]] : null;

                parser.RaiseBotTakeOver(botTakeOverArgs);
            }

            if (eventDescriptor.Name == "begin_new_match")
            {
                parser.RaiseMatchStarted();
            }

            if (eventDescriptor.Name == "round_announce_match_start")
            {
                parser.RaiseRoundAnnounceMatchStarted();
            }

            if (eventDescriptor.Name == "round_freeze_end")
            {
                parser.RaiseFreezetimeEnded();
            }

            //if (eventDescriptor.Name != "player_footstep" && eventDescriptor.Name != "weapon_fire" && eventDescriptor.Name != "player_jump") {
            //	Console.WriteLine (eventDescriptor.Name);
            //}

            switch (eventDescriptor.Name)
            {
            case "weapon_fire":

                data = MapData(eventDescriptor, rawEvent);

                WeaponFiredEventArgs fire = new WeaponFiredEventArgs();
                fire.Shooter = parser.Players.ContainsKey((int)data ["userid"]) ? parser.Players [(int)data ["userid"]] : null;
                fire.Weapon  = new Equipment((string)data ["weapon"]);

                if (fire.Shooter != null && fire.Weapon.Class != EquipmentClass.Grenade)
                {
                    fire.Weapon = fire.Shooter.ActiveWeapon;
                }

                parser.RaiseWeaponFired(fire);
                break;

            case "player_death":
                data = MapData(eventDescriptor, rawEvent);

                PlayerKilledEventArgs kill = new PlayerKilledEventArgs();

                kill.Victim   = parser.Players.ContainsKey((int)data["userid"]) ? parser.Players[(int)data["userid"]] : null;
                kill.Killer   = parser.Players.ContainsKey((int)data["attacker"]) ? parser.Players[(int)data["attacker"]] : null;
                kill.Assister = parser.Players.ContainsKey((int)data["assister"]) ? parser.Players[(int)data["assister"]] : null;
                kill.Headshot = (bool)data["headshot"];
                kill.Weapon   = new Equipment((string)data["weapon"], (string)data["weapon_itemid"]);

                if (kill.Killer != null && kill.Weapon.Class != EquipmentClass.Grenade &&
                    kill.Weapon.Weapon != EquipmentElement.Revolver &&
                    kill.Killer.Weapons.Any() && kill.Weapon.Weapon != EquipmentElement.World)
                {
                                        #if DEBUG
                    if (kill.Weapon.Weapon != kill.Killer.ActiveWeapon.Weapon)
                    {
                        throw new InvalidDataException();
                    }
                                        #endif
                    kill.Weapon = kill.Killer.ActiveWeapon;
                }


                kill.PenetratedObjects = (int)data["penetrated"];

                parser.RaisePlayerKilled(kill);
                break;

            case "player_hurt":
                data = MapData(eventDescriptor, rawEvent);

                PlayerHurtEventArgs hurt = new PlayerHurtEventArgs();
                hurt.Player       = parser.Players.ContainsKey((int)data ["userid"]) ? parser.Players [(int)data ["userid"]] : null;
                hurt.Attacker     = parser.Players.ContainsKey((int)data ["attacker"]) ? parser.Players [(int)data ["attacker"]] : null;
                hurt.Health       = (int)data ["health"];
                hurt.Armor        = (int)data ["armor"];
                hurt.HealthDamage = (int)data ["dmg_health"];
                hurt.ArmorDamage  = (int)data ["dmg_armor"];
                hurt.Hitgroup     = (Hitgroup)((int)data ["hitgroup"]);

                hurt.Weapon = new Equipment((string)data ["weapon"], "");

                if (hurt.Attacker != null && hurt.Weapon.Class != EquipmentClass.Grenade && hurt.Attacker.Weapons.Any())
                {
                    hurt.Weapon = hurt.Attacker.ActiveWeapon;
                }

                parser.RaisePlayerHurt(hurt);
                break;

                #region Nades
            case "player_blind":
                data = MapData(eventDescriptor, rawEvent);
                if (parser.Players.ContainsKey((int)data["userid"]))
                {
                    blindPlayers.Add(parser.Players[(int)data["userid"]]);
                }
                break;

            case "flashbang_detonate":
                var args = FillNadeEvent <FlashEventArgs>(MapData(eventDescriptor, rawEvent), parser);
                args.FlashedPlayers = blindPlayers.ToArray();
                parser.RaiseFlashExploded(args);
                blindPlayers.Clear();
                break;

            case "hegrenade_detonate":
                parser.RaiseGrenadeExploded(FillNadeEvent <GrenadeEventArgs>(MapData(eventDescriptor, rawEvent), parser));
                break;

            case "decoy_started":
                parser.RaiseDecoyStart(FillNadeEvent <DecoyEventArgs>(MapData(eventDescriptor, rawEvent), parser));
                break;

            case "decoy_detonate":
                parser.RaiseDecoyEnd(FillNadeEvent <DecoyEventArgs>(MapData(eventDescriptor, rawEvent), parser));
                break;

            case "smokegrenade_detonate":
                parser.RaiseSmokeStart(FillNadeEvent <SmokeEventArgs>(MapData(eventDescriptor, rawEvent), parser));
                break;

            case "smokegrenade_expired":
                parser.RaiseSmokeEnd(FillNadeEvent <SmokeEventArgs>(MapData(eventDescriptor, rawEvent), parser));
                break;

            case "inferno_startburn":
                parser.RaiseFireStart(FillNadeEvent <FireEventArgs>(MapData(eventDescriptor, rawEvent), parser));
                break;

            case "inferno_expire":
                parser.RaiseFireEnd(FillNadeEvent <FireEventArgs>(MapData(eventDescriptor, rawEvent), parser));
                break;
                #endregion

            case "player_connect":
                data = MapData(eventDescriptor, rawEvent);

                PlayerInfo player = new PlayerInfo();
                player.UserID = (int)data ["userid"];
                player.Name   = (string)data ["name"];
                player.GUID   = (string)data ["networkid"];
                player.XUID   = player.GUID == "BOT" ? 0 : GetCommunityID(player.GUID);


                //player.IsFakePlayer = (bool)data["bot"];

                int index = (int)data["index"];

                parser.RawPlayers[index] = player;


                break;

            case "player_disconnect":
                data = MapData(eventDescriptor, rawEvent);

                PlayerDisconnectEventArgs disconnect = new PlayerDisconnectEventArgs();
                disconnect.Player = parser.Players.ContainsKey((int)data["userid"]) ? parser.Players[(int)data["userid"]] : null;
                parser.RaisePlayerDisconnect(disconnect);

                int toDelete = (int)data["userid"];
                for (int i = 0; i < parser.RawPlayers.Length; i++)
                {
                    if (parser.RawPlayers[i] != null && parser.RawPlayers[i].UserID == toDelete)
                    {
                        parser.RawPlayers[i] = null;
                        break;
                    }
                }

                if (parser.Players.ContainsKey(toDelete))
                {
                    parser.Players.Remove(toDelete);
                }

                break;

            case "player_team":
                data = MapData(eventDescriptor, rawEvent);
                PlayerTeamEventArgs playerTeamEvent = new PlayerTeamEventArgs();

                Team t = Team.Spectate;

                int team = (int)data["team"];

                if (team == parser.tID)
                {
                    t = Team.Terrorist;
                }
                else if (team == parser.ctID)
                {
                    t = Team.CounterTerrorist;
                }
                playerTeamEvent.NewTeam = t;

                t    = Team.Spectate;
                team = (int)data["oldteam"];
                if (team == parser.tID)
                {
                    t = Team.Terrorist;
                }
                else if (team == parser.ctID)
                {
                    t = Team.CounterTerrorist;
                }
                playerTeamEvent.OldTeam = t;

                playerTeamEvent.Swapped = parser.Players.ContainsKey((int)data["userid"]) ? parser.Players[(int)data["userid"]] : null;
                playerTeamEvent.IsBot   = (bool)data["isbot"];
                playerTeamEvent.Silent  = (bool)data["silent"];

                parser.RaisePlayerTeam(playerTeamEvent);
                break;

            case "bomb_beginplant":          //When the bomb is starting to get planted
            case "bomb_abortplant":          //When the bomb planter stops planting the bomb
            case "bomb_planted":             //When the bomb has been planted
            case "bomb_defused":             //When the bomb has been defused
            case "bomb_exploded":            //When the bomb has exploded
                data = MapData(eventDescriptor, rawEvent);

                var bombEventArgs = new BombEventArgs();
                bombEventArgs.Player = parser.Players.ContainsKey((int)data["userid"]) ? parser.Players[(int)data["userid"]] : null;

                int site = (int)data["site"];

                if (site == parser.bombsiteAIndex)
                {
                    bombEventArgs.Site = 'A';
                }
                else if (site == parser.bombsiteBIndex)
                {
                    bombEventArgs.Site = 'B';
                }
                else
                {
                    var relevantTrigger = parser.triggers.Single(a => a.Index == site);
                    if (relevantTrigger.Contains(parser.bombsiteACenter))
                    {
                        //planted at A.
                        bombEventArgs.Site    = 'A';
                        parser.bombsiteAIndex = site;
                    }
                    else
                    {
                        //planted at B.
                        bombEventArgs.Site    = 'B';
                        parser.bombsiteBIndex = site;
                    }
                }



                switch (eventDescriptor.Name)
                {
                case "bomb_beginplant":
                    parser.RaiseBombBeginPlant(bombEventArgs);
                    break;

                case "bomb_abortplant":
                    parser.RaiseBombAbortPlant(bombEventArgs);
                    break;

                case "bomb_planted":
                    parser.RaiseBombPlanted(bombEventArgs);
                    break;

                case "bomb_defused":
                    parser.RaiseBombDefused(bombEventArgs);
                    break;

                case "bomb_exploded":
                    parser.RaiseBombExploded(bombEventArgs);
                    break;
                }

                break;

            case "bomb_begindefuse":
                data = MapData(eventDescriptor, rawEvent);
                var e = new BombDefuseEventArgs();
                e.Player = parser.Players.ContainsKey((int)data["userid"]) ? parser.Players[(int)data["userid"]] : null;
                e.HasKit = (bool)data["haskit"];
                parser.RaiseBombBeginDefuse(e);
                break;

            case "bomb_abortdefuse":
                data = MapData(eventDescriptor, rawEvent);
                var e2 = new BombDefuseEventArgs();
                e2.Player = parser.Players.ContainsKey((int)data["userid"]) ? parser.Players[(int)data["userid"]] : null;
                e2.HasKit = e2.Player.HasDefuseKit;
                parser.RaiseBombAbortDefuse(e2);
                break;
            }
        }
示例#22
0
 private static void Parser_BombDefused(object sender, BombEventArgs e)
 {
     _results.Players[e.Player.SteamID].BombDefuses.Add(_currentRound);
     _currentRound.BombDefuser = _results.Players[e.Player.SteamID];
 }