Exemple #1
0
        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;
 }
Exemple #3
0
        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;
        }
Exemple #4
0
        /// <summary>
        /// 刷新对手
        /// </summary>
        /// <param name="managerId">经理id</param>
        /// <param name="danGrading">段位</param>
        /// <param name="matchOpponent">打过的对手</param>
        /// <returns></returns>
        private ArenaOpponent RefreshOpponent(Guid managerId, int danGrading, List <Guid> matchOpponent)
        {
            var result       = new ArenaOpponent();
            var opponentList = new List <OpponentEntity>();
            var resultList   = new List <Guid>();

            for (int i = 1; i < 4; i++)                                  //选3个对手
            {
                var key = CacheFactory.ArenaCache.GetKey(danGrading, i); //获取key
                if (!_OpponentDic.ContainsKey(key))
                {
                    return(null);
                }
                var list = new List <ArenaManagerinfoEntity>();
                //循环添加。避免操作list影响对手池
                foreach (var item in _OpponentDic[key])
                {
                    list.Add(item);
                }
                int index = 0;
                while (index < 10 && list.Count > 0) //循环10次排除重复
                {
                    var listIndex = RandomHelper.GetInt32WithoutMax(0, list.Count);
                    var info      = list[listIndex]; //随机一个对手
                    list.RemoveAt(listIndex);        //移除随机过的项
                    if (managerId == info.ManagerId) //排除自己
                    {
                        continue;
                    }
                    if (!resultList.Exists(r => r == info.ManagerId)) //结果里面已经包含了该对手
                    {
                        if (matchOpponent != null && matchOpponent.Count < 5 &&
                            matchOpponent.Exists(r => r == info.ManagerId)) //打过比赛的对手里面已经包含了该对手
                        {
                            index++;
                            continue;
                        }
                        var entity = new OpponentEntity();
                        entity.OpponentManagerId = info.ManagerId;
                        entity.OpponentZoneName  = info.SiteId;
                        if (info.IsNpc)
                        {
                            entity.OpponentKpi  = info.Kpi;
                            entity.OpponentName = info.ManagerName;
                        }
                        else
                        {
                            entity.OpponentName = info.ZoneName + "." + info.ManagerName;
                            var arenaFrame = new ArenaTeammemberFrame(entity.OpponentManagerId,
                                                                      (EnumArenaType)this.ArenaType,
                                                                      entity.OpponentZoneName);
                            entity.OpponentKpi = arenaFrame.Kpi;
                        }

                        entity.IsNpc              = info.IsNpc;
                        entity.OpponentLogo       = info.Logo;
                        entity.OpponentIntegral   = info.Integral;
                        entity.OpponentDanGrading = info.DanGrading;

                        resultList.Add(entity.OpponentManagerId);
                        opponentList.Add(entity);
                        break;
                    }
                    index++;
                }
                if (index >= 10 || list.Count == 0)
                {
                    return(null);
                }
            }
            CheckOpponent(ref opponentList);
            result.OpponentList  = opponentList;
            result.MatchOpponent = matchOpponent;
            return(result);
        }