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; }
/// <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; }