public HeatmapService(MapService mapService, Demo demo, ComboboxSelector eventSelector, ComboboxSelector sideSelector, PlayerExtended selectedPlayer, Round selectedRound)
		{
			MapService = mapService;
			_demo = demo;
			_eventSelector = eventSelector;
			_sideSelector = sideSelector;
			_selectedPlayer = selectedPlayer;
			_selectedRound = selectedRound;
		}
Exemple #2
0
 public void ResetStats(bool resetTeams = true)
 {
     DispatcherHelper.CheckBeginInvokeOnUI(
         () =>
     {
         _onekillCount         = 0;
         _twokillCount         = 0;
         _threekillCount       = 0;
         _fourkillCount        = 0;
         _fivekillCount        = 0;
         _scoreTeam1           = 0;
         _scoreTeam2           = 0;
         _scoreFirstHalfTeam1  = 0;
         _scoreFirstHalfTeam2  = 0;
         _scoreSecondHalfTeam1 = 0;
         _scoreSecondHalfTeam2 = 0;
         if (resetTeams)
         {
             _players.Clear();
             _playersTeam1.Clear();
             _playersTeam2.Clear();
             _teams.Clear();
         }
         else
         {
             foreach (PlayerExtended playerExtended in Players)
             {
                 playerExtended.ResetStats();
             }
         }
         _rounds.Clear();
         WeaponFired.Clear();
         _kills.Clear();
         _overtimes.Clear();
         PositionsPoint.Clear();
         MolotovFireStarted.Clear();
         DecoyStarted.Clear();
         _bombPlanted.Clear();
         _bombDefused.Clear();
         _bombExploded.Clear();
         _bombPlanted.Clear();
         _bombDefused.Clear();
         _bombExploded.Clear();
         _mostBombPlantedPlayer = null;
         _mostEntryKillPlayer   = null;
         _mostHeadshotPlayer    = null;
         _mostKillingWeapon     = null;
         _hasCheater            = false;
     });
 }
		public Task<List<Demo>> GetDemosHeader(List<string> folders)
		{
			List<Demo> demos = new List<Demo>();

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

				ObservableCollection<EntryKillEvent> entryKills = new ObservableCollection<EntryKillEvent>();
				for (int indexEntryKill = 0; indexEntryKill < random.Next(5); indexEntryKill++)
				{
					EntryKillEvent entryKill = new EntryKillEvent(random.Next(7000, 100000))
					{
						KilledName = "killed" + indexEntryKill,
						KilledSteamId = random.Next(8000000),
						KilledTeam = Team.Terrorist,
						KillerName = "killer" + indexEntryKill,
						KillerSteamId = random.Next(800000),
						KillerTeam = Team.CounterTerrorist
					};
					entryKills.Add(entryKill);
				}

				for (int j = 0; j < 10; j++)
				{
					PlayerExtended player = new PlayerExtended
					{
						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),
						Clutch1V1Count = random.Next(1),
						Clutch1V2Count = random.Next(1),
						Clutch1V3Count = random.Next(1),
						Clutch1V4Count = random.Next(1),
						Clutch1V5Count = random.Next(1),
						BombDefusedCount = random.Next(0, 2),
						BombPlantedCount = random.Next(0, 2),
						EntryKills = entryKills,
						DeathCount = random.Next(0, 32),
						KillsCount = 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,
					PlayersTeam1 = new ObservableCollection<PlayerExtended>(players.Take(5)),
					PlayersTeam2 = new ObservableCollection<PlayerExtended>(players.Skip(5).Take(5)),
					MostBombPlantedPlayer = players.ElementAt(random.Next(10)),
					MostHeadshotPlayer = players.ElementAt(random.Next(10)),
					Rounds = rounds
				};

				demos.Add(demo);
			}

			return Task.FromResult(demos);
		}
		private void AddTeams()
		{
			// We must set team1 as CT and team2 as T
			TeamExtended team1 = new TeamExtended()
			{
				Name = Parser.CTClanName
			};

			TeamExtended team2 = new TeamExtended()
			{
				Name = Parser.TClanName
			};

			Demo.ClanTagNameTeam1 = team1.Name;
			Demo.ClanTagNameTeam2 = team2.Name;

			// Add all players to our ObservableCollection of PlayerExtended and teams
			foreach (Player player in Parser.PlayingParticipants)
			{
				if (player.SteamID != 0)
				{
					PlayerExtended pl = new PlayerExtended
					{
						SteamId = player.SteamID,
						Name = player.Name,
						Team = player.Team
					};

					Application.Current.Dispatcher.Invoke(delegate
					{
						if (!Demo.Players.Contains(pl)) Demo.Players.Add(pl);

						if (pl.Team == Team.CounterTerrorist)
						{
							// Check swap
							if (Demo.PlayersTeam2.Contains(pl))
							{
								Demo.PlayersTeam1.Add(Demo.PlayersTeam2.First(p => p.Equals(pl)));
								Demo.PlayersTeam2.Remove(pl);
							}
							else
							{
								if (!Demo.PlayersTeam1.Contains(pl)) Demo.PlayersTeam1.Add(pl);
							}
							team1.Players.Add(Demo.Players.First(p => p.Equals(pl)));
						}

						if (pl.Team == Team.Terrorist)
						{
							// Check swap
							if (Demo.PlayersTeam1.Contains(pl))
							{
								Demo.PlayersTeam2.Add(Demo.PlayersTeam1.First(p => p.Equals(pl)));
								Demo.PlayersTeam1.Remove(pl);
							}
							else
							{
								if (!Demo.PlayersTeam2.Contains(pl)) Demo.PlayersTeam2.Add(pl);
							}
							team2.Players.Add(Demo.Players.First(p => p.Equals(pl)));
						}
					});
				}
			}

			// Add teams
			Application.Current.Dispatcher.Invoke(delegate
			{
				Demo.Teams.Clear();
				Demo.Teams.Add(team1);
				Demo.Teams.Add(team2);
			});
		}
		private void UpdatePlayerClutchCount(PlayerExtended player)
		{
			switch (player.OpponentClutchCount)
			{
				case 1:
					player.Clutch1V1Count++;
					break;
				case 2:
					player.Clutch1V2Count++;
					break;
				case 3:
					player.Clutch1V3Count++;
					break;
				case 4:
					player.Clutch1V4Count++;
					break;
				case 5:
					player.Clutch1V5Count++;
					break;
			}
		}
		/// <summary>
		/// Check if there is any clutch situation and if so add clutch to player
		/// </summary>
		protected void ProcessClutches()
		{
			int terroristAliveCount = Demo.Players.Count(p => p.Team == Team.Terrorist && p.IsAlive);
			int counterTerroristAliveCount = Demo.Players.Count(p => p.Team == Team.CounterTerrorist && p.IsAlive);

			// First dectection of a 1vX situation, a terro is in clutch
			if (_playerInClutch1 == null && terroristAliveCount == 1)
			{
				// Set the number of opponent in his clutch
				_playerInClutch1 = Demo.Players.FirstOrDefault(p => p.Team == Team.Terrorist && p.IsAlive);
				if (_playerInClutch1 != null && _playerInClutch1.OpponentClutchCount == 0)
				{
					_playerInClutch1.OpponentClutchCount = Demo.Players.Count(p => p.Team == Team.CounterTerrorist && p.IsAlive);
					_playerInClutch1.ClutchCount++;
					return;
				}
			}

			// First dectection of a 1vX situation, a CT is in clutch
			if (_playerInClutch1 == null && counterTerroristAliveCount == 1)
			{
				_playerInClutch1 = Demo.Players.FirstOrDefault(p => p.Team == Team.CounterTerrorist && p.IsAlive);
				if (_playerInClutch1 != null && _playerInClutch1.OpponentClutchCount == 0)
				{
					_playerInClutch1.OpponentClutchCount = Demo.Players.Count(p => p.Team == Team.Terrorist && p.IsAlive);
					_playerInClutch1.ClutchCount++;
					return;
				}
			}

			// 1v1 detection
			if (counterTerroristAliveCount == 1 && terroristAliveCount == 1 && _playerInClutch1 != null)
			{
				Team player2Team = _playerInClutch1.Team == Team.CounterTerrorist ? Team.Terrorist : Team.CounterTerrorist;
				_playerInClutch2 = Demo.Players.FirstOrDefault(p => p.Team == player2Team && p.IsAlive);
				if (_playerInClutch2 == null) return;
				_playerInClutch2.ClutchCount++;
				_playerInClutch2.OpponentClutchCount = 1;
			}
		}
		protected void CreateNewRound()
		{
			CurrentRound = new Round
			{
				Tick = Parser.IngameTick,
				Number = ++RoundCount
			};

			// Sometimes parser return wrong money values on 1st round of side
			if (CurrentRound.Number == 1 || CurrentRound.Number == 16)
			{
				CurrentRound.StartMoneyTeam1 = 4000;
				CurrentRound.StartMoneyTeam2 = 4000;
			}
			else
			{
				CurrentRound.StartMoneyTeam1 = Parser.Participants.Where(a => a.Team == Team.CounterTerrorist).Sum(a => a.Money);
				CurrentRound.StartMoneyTeam2 = Parser.Participants.Where(a => a.Team == Team.Terrorist).Sum(a => a.Money);
			}

			IsEntryKillDone = false;
			IsOpeningKillDone = false;
			IsFirstShotOccured = false;
			_playerInClutch1 = null;
			_playerInClutch2 = null;

			KillsThisRound.Clear();

			// Nobody is controlling a BOT at the beginning of a round
			foreach (PlayerExtended pl in Demo.Players)
			{
				pl.OpponentClutchCount = 0;
				pl.HasEntryKill = false;
				pl.HasOpeningKill = false;
				pl.IsControllingBot = false;
				Player player = Parser.PlayingParticipants.FirstOrDefault(p => p.SteamID == pl.SteamId);
				if (player != null)
				{
					pl.RoundPlayedCount++;
					pl.IsAlive = true;
					pl.Team = player.Team;
				}
			}
		}
		private void AddTeams()
		{
			// Add all players to our ObservableCollection of PlayerExtended
			foreach (Player player in Parser.PlayingParticipants)
			{
				if (player.SteamID != 0)
				{
					PlayerExtended pl = new PlayerExtended
					{
						SteamId = player.SteamID,
						Name = player.Name,
						Side = player.Team
					};

					Application.Current.Dispatcher.Invoke(delegate
					{
						if (!Demo.Players.Contains(pl)) Demo.Players.Add(pl);

						if (pl.Side == Team.CounterTerrorist)
						{
							pl.TeamName = Demo.TeamCT.Name;
							// Check swap
							if (Demo.TeamT.Players.Contains(pl))
							{
								Demo.TeamCT.Players.Add(Demo.TeamT.Players.First(p => p.Equals(pl)));
								Demo.TeamT.Players.Remove(pl);
							}
							else
							{
								if (!Demo.TeamCT.Players.Contains(pl)) Demo.TeamCT.Players.Add(pl);
							}
						}

						if (pl.Side == Team.Terrorist)
						{
							pl.TeamName = Demo.TeamT.Name;
							// Check swap
							if (Demo.TeamCT.Players.Contains(pl))
							{
								Demo.TeamT.Players.Add(Demo.TeamCT.Players.First(p => p.Equals(pl)));
								Demo.TeamCT.Players.Remove(pl);
							}
							else
							{
								if (!Demo.TeamT.Players.Contains(pl)) Demo.TeamT.Players.Add(pl);
							}
						}
					});
				}
			}
		}
		protected override void HandleRoundStart(object sender, RoundStartedEventArgs e)
		{
			if (!IsMatchStarted) return;
			// Check players count to prevent missing players who was connected after the match started event
			if (Demo.Players.Count < 10)
			{
				// Add all players to our ObservableCollection of PlayerExtended
				foreach (Player player in Parser.PlayingParticipants)
				{
					// don't add bot and already known players
					if (player.SteamID != 0 && Demo.Players.FirstOrDefault(p => p.SteamId == player.SteamID) == null)
					{
						PlayerExtended pl = new PlayerExtended
						{
							SteamId = player.SteamID,
							Name = player.Name,
							Team = player.Team
						};
						Application.Current.Dispatcher.Invoke(delegate
						{
							Demo.Players.Add(pl);
							if (pl.Team == Team.CounterTerrorist)
							{
								Demo.PlayersTeam1.Add(pl);
							}
							else
							{
								Demo.PlayersTeam2.Add(pl);
							}
						});
					}
				}
			}
			CreateNewRound();
		}
		private void InitPlayers()
		{
			// We must set team1 as CT and team2 as T
			TeamExtended team1 = new TeamExtended()
			{
				Name= !string.IsNullOrWhiteSpace(Parser.CTClanName) ? Parser.CTClanName : TEAM1_NAME
			};

			TeamExtended team2 = new TeamExtended()
			{
				Name = !string.IsNullOrWhiteSpace(Parser.TClanName) ? Parser.TClanName : TEAM2_NAME
			};

			Demo.ClanTagNameTeam1 = team1.Name;
			Demo.ClanTagNameTeam2 = team2.Name;

			// Add all players to our ObservableCollection of PlayerExtended and teams
			foreach (Player player in Parser.PlayingParticipants)
			{
				PlayerExtended pl = new PlayerExtended
				{
					SteamId = player.SteamID,
					Name = player.Name,
					Team = player.Team
				};

				Application.Current.Dispatcher.Invoke(delegate
				{
					if (!Demo.Players.Contains(pl)) Demo.Players.Add(pl);

					if (pl.Team == Team.CounterTerrorist)
					{
						if (!Demo.PlayersTeam1.Contains(pl)) Demo.PlayersTeam1.Add(pl);
						if (!team1.Players.Contains(pl)) team1.Players.Add(pl);
					}

					if (pl.Team == Team.Terrorist)
					{
						if (!Demo.PlayersTeam2.Contains(pl)) Demo.PlayersTeam2.Add(pl);
						if (!team2.Players.Contains(pl)) team2.Players.Add(pl);
					}
				});
			}

			// Add teams
			Application.Current.Dispatcher.Invoke(delegate
			{
				Demo.Teams.Clear();
				Demo.Teams.Add(team1);
				Demo.Teams.Add(team2);
			});
		}
		protected override void HandleMatchStarted(object sender, MatchStartedEventArgs e)
		{
			if(IsMatchStarted) Demo.ResetStats(false);
			RoundCount = 0;
			IsMatchStarted = true;

			TeamExtended team1 = new TeamExtended()
			{
				Name = !string.IsNullOrWhiteSpace(Parser.CTClanName) ? Parser.CTClanName : TEAM1_NAME
			};
			TeamExtended team2 = new TeamExtended()
			{
				Name = !string.IsNullOrWhiteSpace(Parser.TClanName) ? Parser.TClanName : TEAM2_NAME
			};

			Demo.ClanTagNameTeam1 = team1.Name;
			Demo.ClanTagNameTeam2 = team2.Name;

			// Add all players to our ObservableCollection of PlayerExtended
			foreach (Player player in Parser.PlayingParticipants)
			{
				// don't add bot
				if (player.SteamID != 0)
				{
					PlayerExtended pl = new PlayerExtended
					{
						SteamId = player.SteamID,
						Name = player.Name,
						Team = player.Team
					};
					if (!Demo.Players.Contains(pl))
					{
						Application.Current.Dispatcher.Invoke(delegate
						{
							Demo.Players.Add(pl);
							if (pl.Team == Team.CounterTerrorist && !Demo.PlayersTeam1.Contains(pl))
							{
								Demo.PlayersTeam1.Add(pl);
								if (!team1.Players.Contains(pl))
								{
									team1.Players.Add(pl);
								}
							}

							if (pl.Team == Team.Terrorist && !Demo.PlayersTeam2.Contains(pl))
							{
								Demo.PlayersTeam2.Add(pl);
								if (!team2.Players.Contains(pl))
								{
									team2.Players.Add(pl);
								}
							}
						});
					}
				}
			}

			Application.Current.Dispatcher.Invoke(delegate
			{
				if (!Demo.Teams.Contains(team1)) Demo.Teams.Add(team1);
				if (!Demo.Teams.Contains(team2)) Demo.Teams.Add(team2);
			});

			// First round handled here because round_start is raised before begin_new_match
			CreateNewRound();
		}
Exemple #12
0
		public void ResetStats(bool resetTeams = true)
		{
			DispatcherHelper.CheckBeginInvokeOnUI(
				() =>
				{
					_onekillCount = 0;
					_twokillCount = 0;
					_threekillCount = 0;
					_fourkillCount = 0;
					_fivekillCount = 0;
					_scoreTeam1 = 0;
					_scoreTeam2 = 0;
					_scoreFirstHalfTeam1 = 0;
					_scoreFirstHalfTeam2 = 0;
					_scoreSecondHalfTeam1 = 0;
					_scoreSecondHalfTeam2 = 0;
					if (resetTeams)
					{
						_players.Clear();
						_playersTeam1.Clear();
						_playersTeam2.Clear();
						_teams.Clear();
					}
					else
					{
						foreach (PlayerExtended playerExtended in Players)
						{
							playerExtended.ResetStats();
						}
					}
					_rounds.Clear();
					WeaponFired.Clear();
					_kills.Clear();
					_overtimes.Clear();
					PositionsPoint.Clear();
					MolotovFireStarted.Clear();
					DecoyStarted.Clear();
					_bombPlanted.Clear();
					_bombDefused.Clear();
					_bombExploded.Clear();
					_bombPlanted.Clear();
					_bombDefused.Clear();
					_bombExploded.Clear();
					_mostBombPlantedPlayer = null;
					_mostEntryKillPlayer = null;
					_mostHeadshotPlayer = null;
					_mostKillingWeapon = null;
					_hasCheater = false;
				});
		}
		protected override void HandleMatchStarted(object sender, MatchStartedEventArgs e)
		{
			if (IsMatchStarted) Demo.ResetStats(false);
			RoundCount = 0;
			IsMatchStarted = true;

			if (!string.IsNullOrWhiteSpace(Parser.CTClanName)) Demo.TeamCT.Name = Parser.CTClanName;
			if (!string.IsNullOrWhiteSpace(Parser.TClanName)) Demo.TeamT.Name = Parser.TClanName;

			// Add all players to our ObservableCollection of PlayerExtended
			foreach (Player player in Parser.PlayingParticipants)
			{
				// don't add bot
				if (player.SteamID != 0)
				{
					PlayerExtended pl = new PlayerExtended
					{
						SteamId = player.SteamID,
						Name = player.Name,
						Side = player.Team
					};
					if (!Demo.Players.Contains(pl))
					{
						Application.Current.Dispatcher.Invoke(delegate
						{
							Demo.Players.Add(pl);
							if (pl.Side == Team.CounterTerrorist && !Demo.TeamCT.Players.Contains(pl))
							{
								Demo.TeamCT.Players.Add(pl);
								if (!Demo.TeamCT.Players.Contains(pl))
								{
									Demo.TeamCT.Players.Add(pl);
								}
								pl.TeamName = Demo.TeamCT.Name;
							}

							if (pl.Side == Team.Terrorist && !Demo.TeamT.Players.Contains(pl))
							{
								Demo.TeamT.Players.Add(pl);
								if (!Demo.TeamT.Players.Contains(pl))
								{
									Demo.TeamT.Players.Add(pl);
								}
								pl.TeamName = Demo.TeamT.Name;
							}
						});
					}
				}
			}

			// First round handled here because round_start is raised before begin_new_match
			CreateNewRound();
		}
		public Task<Demo> AnalyzeDemo(Demo demo)
		{
			Random random = new Random();

			ObservableCollection<PlayerExtended> players = new ObservableCollection<PlayerExtended>();
			for (int i = 0; i < 10; i++)
			{
				PlayerExtended player = new PlayerExtended
				{
					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),
					Clutch1V1Count = random.Next(1),
					Clutch1V2Count = random.Next(1),
					Clutch1V3Count = random.Next(1),
					Clutch1V4Count = random.Next(1),
					Clutch1V5Count = random.Next(1),
					BombDefusedCount = random.Next(0, 2),
					BombPlantedCount = random.Next(0, 2),
					DeathCount = random.Next(0, 32),
					KillsCount = 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)
				};

				players.Add(player);

				ObservableCollection<EntryKillEvent> entryKills = new ObservableCollection<EntryKillEvent>();
				for (int indexEntryKill = 0; indexEntryKill < random.Next(5); indexEntryKill++)
				{
					EntryKillEvent entryKill = new EntryKillEvent(random.Next(7000, 100000))
					{
						Killed = players.ElementAt(random.Next(0, 9)),
						KilledTeam = Team.Terrorist,
						Killer = players.ElementAt(random.Next(0, 9)),
						KillerTeam = Team.CounterTerrorist
					};
					entryKills.Add(entryKill);
				}

				ObservableCollection<OpenKillEvent> openKills = new ObservableCollection<OpenKillEvent>();
				for (int indexOpenKill = 0; indexOpenKill < random.Next(5); indexOpenKill++)
				{
					OpenKillEvent openKill = new OpenKillEvent(random.Next(7000, 100000))
					{
						Killed = players.ElementAt(random.Next(0, 9)),
						KilledTeam = Team.Terrorist,
						Killer = players.ElementAt(random.Next(0, 9)),
						KillerTeam = Team.CounterTerrorist
					};
					openKills.Add(openKill);
				}

				players.Last().EntryKills = entryKills;
				players.Last().OpeningKills = openKills;
			}

			ObservableCollection<TeamExtended> teams = new ObservableCollection<TeamExtended>
			{
				new TeamExtended
				{
					Name = "Team 1",
					Players = new ObservableCollection<PlayerExtended>(players.Take(5))
				},
				new TeamExtended
				{
					Name = "Team 2",
					Players = new ObservableCollection<PlayerExtended>(players.Skip(5).Take(5))
				}
			};

			ObservableCollection<Round> rounds = new ObservableCollection<Round>();
			for (int i = 0; i < 32; i++)
			{
				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),
					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),
					WinnerClanName = teams[random.Next(0, 2)].Name
				};

				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.ScoreTeam1 = 16;
			demo.ScoreTeam2 = 6;
			demo.Type = "GOTV";
			demo.Comment = "comment";
			demo.ScoreFirstHalfTeam1 = 10;
			demo.ScoreFirstHalfTeam2 = 5;
			demo.ScoreSecondHalfTeam1 = 6;
			demo.ScoreSecondHalfTeam2 = 1;
			demo.Players = players;
			demo.PlayersTeam1 = teams[0].Players;
			demo.PlayersTeam2 = teams[1].Players;
			demo.MostBombPlantedPlayer = players.ElementAt(random.Next(10));
			demo.MostHeadshotPlayer = players.ElementAt(random.Next(10));
			demo.MostEntryKillPlayer = players.ElementAt(random.Next(10));
			demo.MostKillingWeapon = new Weapon
			{
				Name = "AK-47"
			};
			demo.Teams = teams;
			demo.Rounds = rounds;

			return Task.FromResult(demo);
		}
		/// <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, ComboboxSelector teamSelector, PlayerExtended selectedPlayer, Round round)
		{
			List<List<PositionPoint>> points = new List<List<PositionPoint>>();

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

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

							for (int i = demo.PositionsPoint.Count - 1; i >= 0; i--)
							{
								if (!demo.PositionsPoint[i].Round.Equals(round)) continue;

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

								if (demo.PositionsPoint[i].Team != Team.CounterTerrorist) continue;

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

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

								if (demo.PositionsPoint[i].Player != null
								&& demo.PositionsPoint[i].Player.Equals(playerExtended))
								{
									playerPoints.Add(demo.PositionsPoint[i]);
									demo.PositionsPoint.RemoveAt(i);
								}
							}
							if (playerPoints.Any()) points.Add(playerPoints);
						}
						break;
					case "T":
						demo.PositionsPoint.Reverse();

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

							for (int i = demo.PositionsPoint.Count - 1; i >= 0; i--)
							{
								if (!demo.PositionsPoint[i].Round.Equals(round)) continue;

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

								if (demo.PositionsPoint[i].Team != Team.Terrorist) continue;

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

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

								if (demo.PositionsPoint[i].Player != null
								&& demo.PositionsPoint[i].Player.Equals(playerExtended))
								{
									playerPoints.Add(demo.PositionsPoint[i]);
									demo.PositionsPoint.RemoveAt(i);
								}
							}
							if (playerPoints.Any()) points.Add(playerPoints);
						}
						break;
					case "BOTH":
						points.AddRange(
							demo.Players.Select(
								playerExtended => demo.PositionsPoint.Where(
									point => point.Round.Number == round.Number
									&& point.Player.SteamId == playerExtended.SteamId).ToList())
									.Where(pts => pts.Any()));
						break;
				}
			}

			if (selectedPlayer != null)
			{
				await Task.Run(delegate
				{
					List<PositionPoint> pt = demo.PositionsPoint.ToList().Where(
						positionPoint => positionPoint.Player.SteamId == selectedPlayer.SteamId
						&& positionPoint.Round.Number == round.Number
						|| (positionPoint.Event != null
						&& positionPoint.Event.GetType() == typeof(KillEvent))
						&& positionPoint.Round.Number == 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;
		}
		protected void HandleFlashNadeExploded(object sender, FlashEventArgs e)
		{
			if(!IsMatchStarted || e.ThrownBy == null || !PlayersFlashQueue.Any()) return;

			if (PlayersFlashQueue.Any())
			{
				LastPlayerExplodedFlashbang = PlayersFlashQueue.Dequeue();
				// update flash intensity value for each player when the flash poped
				foreach (Player player in Parser.PlayingParticipants)
				{
					PlayerExtended pl = Demo.Players.FirstOrDefault(p => p.SteamId == player.SteamID);
					if (pl != null) pl.FlashDurationTemp = player.FlashDuration;
				}
				// set it to true to start analyzing flashbang status at each tick
				AnalyzeFlashbang = true;
			}

			if (!AnalyzePlayersPosition && !AnalyzeHeatmapPoint) return;

			PlayerExtended thrower = Demo.Players.FirstOrDefault(player => player.SteamId == e.ThrownBy.SteamID);
			FlashbangExplodedEvent flashbangEvent = new FlashbangExplodedEvent(Parser.IngameTick, Parser.CurrentTime)
			{
				ThrowerSteamId = thrower?.SteamId ?? 0,
				ThrowerName = thrower == null ? string.Empty : thrower.Name
			};

			if (e.FlashedPlayers != null)
			{
				foreach (Player player in e.FlashedPlayers)
				{
					PlayerExtended playerExtended = Demo.Players.FirstOrDefault(p => p.SteamId == player.SteamID);
					if (playerExtended != null)
					{
						flashbangEvent.FlashedPlayerSteamIdList.Add(playerExtended.SteamId);
					}
				}
			}

			if (AnalyzeHeatmapPoint && thrower != null)
			{
				flashbangEvent.Point = new HeatmapPoint
				{
					X = e.Position.X,
					Y = e.Position.Y,
					Player = thrower,
					Team = e.ThrownBy.Team,
					Round = CurrentRound
				};
			}

			CurrentRound.FlashbangsExploded.Add(flashbangEvent);

			if (AnalyzePlayersPosition && thrower != null)
			{
				PositionPoint positionPoint = new PositionPoint
				{
					X = e.Position.X,
					Y = e.Position.Y,
					PlayerSteamId = e.ThrownBy.SteamID,
					PlayerName = e.ThrownBy.Name,
					Team = e.ThrownBy.Team,
					RoundNumber = CurrentRound.Number,
					Event = flashbangEvent
				};
				Demo.PositionsPoint.Add(positionPoint);
			}
		}
		private void InitPlayers()
		{
			// Add all players to our ObservableCollection of PlayerExtended and teams
			foreach (Player player in Parser.PlayingParticipants)
			{
				PlayerExtended pl = new PlayerExtended
				{
					SteamId = player.SteamID,
					Name = player.Name,
					Side = player.Team
				};

				Application.Current.Dispatcher.Invoke(delegate
				{
					if (!Demo.Players.Contains(pl)) Demo.Players.Add(pl);

					if (pl.Side == Team.CounterTerrorist)
					{
						pl.TeamName = Demo.TeamCT.Name;
						if (!Demo.TeamCT.Players.Contains(pl)) Demo.TeamCT.Players.Add(pl);
					}

					if (pl.Side == Team.Terrorist)
					{
						pl.TeamName = Demo.TeamT.Name;
						if (!Demo.TeamT.Players.Contains(pl)) Demo.TeamT.Players.Add(pl);
					}
				});
			}
		}
		public Task<Demo> AnalyzeDemo(Demo demo, CancellationToken token)
		{
			Random random = new Random();

			ObservableCollection<PlayerExtended> players = new ObservableCollection<PlayerExtended>();
			for (int i = 0; i < 10; i++)
			{
				PlayerExtended player = new PlayerExtended
				{
					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),
					Clutch1V1Count = random.Next(1),
					Clutch1V2Count = random.Next(1),
					Clutch1V3Count = random.Next(1),
					Clutch1V4Count = random.Next(1),
					Clutch1V5Count = random.Next(1),
					BombDefusedCount = random.Next(0, 2),
					BombPlantedCount = random.Next(0, 2),
					DeathCount = random.Next(0, 32),
					KillsCount = 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,
					ClutchCount = random.Next(5),
					ClutchLostCount = random.Next(5),
					KillDeathRatio = (decimal)random.NextDouble(),
					MatchCount = random.Next(100),
					OpponentClutchCount = random.Next(5),
					RoundPlayedCount = random.Next(100)
				};

				players.Add(player);
			}
			TeamExtended teamT = new TeamExtended
			{
				Name = "Team 1",
				Players = new ObservableCollection<PlayerExtended>(players.Take(5))
			};
			TeamExtended teamCt = new TeamExtended
			{
				Name = "Team 2",
				Players = new ObservableCollection<PlayerExtended>(players.Skip(5).Take(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++)
				{
					PlayerExtended killer = players.ElementAt(random.Next(9));
					PlayerExtended 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),
					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),
					WinnerName = teamCt.Name,
					WinnerSide = Team.CounterTerrorist,
					MolotovThrownCount = random.Next(5),
					DecoyThrownCount = random.Next(5),
					IncendiaryThrownCount = random.Next(5),
					SmokeThrownCount = random.Next(5),
					FlashbangThrownCount = random.Next(5),
					StartTimeSeconds = random.Next(1),
					HeGrenadeThrownCount = random.Next(5),
					BombDefused = null,
					EndTimeSeconds = random.Next(100),
					BombPlanted = null,
					BombExploded = null,
					Type = RoundType.NORMAL,
					EndReason = RoundEndReason.CTWin,
					EntryKillEvent = new EntryKillEvent(random.Next(1, 10000), random.Next(1, 100))
					{
						HasWin = 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 = Team.CounterTerrorist,
						KillerSide = Team.Terrorist
					},
					OpenKillEvent = new OpenKillEvent(random.Next(1, 10000), random.Next(1, 100))
					{
						HasWin = 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 = Team.CounterTerrorist,
						KillerSide = Team.Terrorist
					},
					SideTrouble = Team.Spectate,
					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.ScoreTeam1 = 16;
			demo.ScoreTeam2 = 6;
			demo.Type = "GOTV";
			demo.Comment = "comment";
			demo.ScoreFirstHalfTeam1 = 10;
			demo.ScoreFirstHalfTeam2 = 5;
			demo.ScoreSecondHalfTeam1 = 6;
			demo.ScoreSecondHalfTeam2 = 1;
			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);
		}