private Entity GetHero(int controller) { var heroEntityId = controller == _playerController ? PlayerEntity.GetTag(GAME_TAG.HERO_ENTITY) : OpponentEntity.GetTag(GAME_TAG.HERO_ENTITY); return(_currentGameState.Data.FirstOrDefault(x => x.Id == heroEntityId) ?? new Entity()); }
public void Load(List <ReplayKeyPoint> replay) { if (replay == null || replay.Count == 0) { return; } Replay = replay; _currentGameState = Replay[0]; _playerController = PlayerEntity.GetTag(GAME_TAG.CONTROLLER); _opponentController = OpponentEntity.GetTag(GAME_TAG.CONTROLLER); _treeViewTurnItems = new List <TreeViewItem>(); foreach (var kp in Replay) { var tvItem = _treeViewTurnItems.FirstOrDefault(x => (string)x.Header == "Turn " + kp.Turn); if (tvItem == null) { tvItem = new TreeViewItem { Header = "Turn " + kp.Turn, IsExpanded = true }; _treeViewTurnItems.Add(tvItem); } var entity = kp.Data.FirstOrDefault(x => x.Id == kp.Id); if (entity == null || string.IsNullOrEmpty(entity.CardId)) { continue; } if (kp.Type == KeyPointType.Summon && entity.GetTag(GAME_TAG.CARDTYPE) == (int)TAG_CARDTYPE.ENCHANTMENT) { continue; } tvItem.Items.Add(kp); } foreach (var tvi in _treeViewTurnItems) { TreeViewKeyPoints.Items.Add(tvi); } DataContext = this; }
public void Load(List <ReplayKeyPoint> replay) { if (replay == null || replay.Count == 0) { return; } var selectedKeypoint = DataGridKeyPoints.SelectedItem as TurnViewItem; DataGridKeyPoints.Items.Clear(); Replay = replay; _currentGameState = Replay.FirstOrDefault(r => r.Data.Any(x => x.HasTag(GAME_TAG.PLAYER_ID))); if (_currentGameState == null) { Logger.WriteLine("Error loading replay. No player entity found."); return; } _playerController = PlayerEntity.GetTag(GAME_TAG.CONTROLLER); _opponentController = OpponentEntity.GetTag(GAME_TAG.CONTROLLER); var currentTurn = -1; TurnViewItem tvi = null; foreach (var kp in Replay) { var entity = kp.Data.FirstOrDefault(x => x.Id == kp.Id); if (entity == null || (string.IsNullOrEmpty(entity.CardId) && kp.Type != KeyPointType.Victory && kp.Type != KeyPointType.Defeat)) { continue; } if (kp.Type == KeyPointType.Summon && entity.GetTag(GAME_TAG.CARDTYPE) == (int)TAG_CARDTYPE.ENCHANTMENT) { continue; } var turn = (kp.Turn + 1) / 2; if (turn == 1) { if (!kp.Data.Any(x => x.HasTag(GAME_TAG.PLAYER_ID) && x.GetTag(GAME_TAG.RESOURCES) == 1)) { turn = 0; } } if (turn > currentTurn) { currentTurn = turn; if (tvi != null && tvi.IsTurnRow && tvi.Turn.HasValue && !_collapsedTurns.Contains(tvi.Turn.Value)) { DataGridKeyPoints.Items.Remove(tvi); //remove empty turns } tvi = new TurnViewItem { Turn = turn, IsCollapsed = _collapsedTurns.Contains(turn), ShowAll = _showAllTurns.Contains(turn) }; DataGridKeyPoints.Items.Add(tvi); } if (!_showAllTurns.Contains(turn)) { switch (kp.Type) { case KeyPointType.Attack: if (!Config.Instance.ReplayViewerShowAttack) { continue; } break; case KeyPointType.Death: if (!Config.Instance.ReplayViewerShowDeath) { continue; } break; case KeyPointType.Mulligan: case KeyPointType.DeckDiscard: case KeyPointType.HandDiscard: if (!Config.Instance.ReplayViewerShowDiscard) { continue; } break; case KeyPointType.Draw: case KeyPointType.Obtain: case KeyPointType.PlayToDeck: case KeyPointType.PlayToHand: if (!Config.Instance.ReplayViewerShowDraw) { continue; } break; case KeyPointType.HeroPower: if (!Config.Instance.ReplayViewerShowHeroPower) { continue; } break; case KeyPointType.SecretStolen: case KeyPointType.SecretTriggered: if (!Config.Instance.ReplayViewerShowSecret) { continue; } break; case KeyPointType.Play: case KeyPointType.PlaySpell: case KeyPointType.SecretPlayed: if (!Config.Instance.ReplayViewerShowPlay) { continue; } break; case KeyPointType.Summon: if (!Config.Instance.ReplayViewerShowSummon) { continue; } break; } } if (_collapsedTurns.Contains(turn)) { continue; } tvi = new TurnViewItem(); if (kp.Player == ActivePlayer.Player) { tvi.PlayerAction = kp.Type.ToString(); tvi.AdditionalInfoPlayer = kp.GetAdditionalInfo(); } else { tvi.OpponentAction = kp.Type.ToString(); tvi.AdditionalInfoOpponent = kp.GetAdditionalInfo(); } tvi.KeyPoint = kp; DataGridKeyPoints.Items.Add(tvi); } if (selectedKeypoint != null) { var newSelection = selectedKeypoint.Turn.HasValue ? DataGridKeyPoints.Items.Cast <TurnViewItem>() .FirstOrDefault(x => x.Turn.HasValue && x.Turn.Value == selectedKeypoint.Turn.Value) : DataGridKeyPoints.Items.Cast <TurnViewItem>().FirstOrDefault(x => x.KeyPoint == selectedKeypoint.KeyPoint); if (newSelection != null) { DataGridKeyPoints.SelectedItem = newSelection; DataGridKeyPoints.ScrollIntoView(newSelection); var index = DataGridKeyPoints.Items.IndexOf(newSelection); DataGridRow dgrow = (DataGridRow)DataGridKeyPoints.ItemContainerGenerator.ContainerFromItem(DataGridKeyPoints.Items[index]); dgrow.MoveFocus(new TraversalRequest(FocusNavigationDirection.Up)); } } DataContext = this; }