Ejemplo n.º 1
0
        public void ApplySkillForUI(List <SkillTargetData> targets, CardSkill skill)
        {
#if UNITY_EDITOR || DEVELOPMENT_BUILD
            if (skill.ExecutionTime == SkillExecutionTime.OnDeployAutomatic)
            {
                throw new ArgumentException("skill", "this method should be used only for manually resolved skills");
            }
#endif

            var models = new List <CardModel>(targets.Count);
            foreach (SkillTargetData target in targets)
            {
                // parse target to model
                CardModel model = _lines[(int)target.Line][target.SlotNumber];
                models.Add(model);
                skill.Effect(model); // apply the skill
            }

            // it's important to evaluate strengths before RemoveDeadOnes is called
            // as we want our data match the upper logic's data
            // UI removes its elements later on
            List <List <int> > cardStrengths = GetCardStrengths();

            // remove dead ones
            RemoveDeadOnes();

            // inform status panel
            BroadcastSkillEffect_LogUpdate(CurrentPlayer, models, skill);

            // inform upper logic about new strengths
            BroadcastUpdateStrength_StatusUpdate(cardStrengths);
        }
Ejemplo n.º 2
0
 public CardData(string title, string description, int strength, CardSkill skill = null)
 {
     Skill       = skill;
     Title       = title;
     Description = description;
     Strength    = strength;
 }
Ejemplo n.º 3
0
        List <SkillTargetData> GetTargetsOnDeployAutomatic(CardSkill skill, LineIndicator targetLine, int slotNumber)
        {
            var targets = new List <SkillTargetData>();

            foreach (SkillTarget target in skill.Targets)
            {
                targets.AddRange(ParseOnDeployAutomatic(targetLine, slotNumber, target));
            }

            return(targets);
        }
Ejemplo n.º 4
0
        internal void ApplySkillEffectForAISingleTarget(CardSkill skill, LineIndicator targetLine, int slotNumber)
        {
            CardModel card = _lines[(int)targetLine][slotNumber];

            skill.Effect(card);

            BroadcastSkillEffect_LogUpdate(CurrentPlayer, new List <CardModel>(1)
            {
                card
            }, skill);
        }
Ejemplo n.º 5
0
        internal void ApplySkillEffectForAI(CardSkill skill, List <SkillTargetData> targets)
        {
            var models = new List <CardModel>(targets.Count);

            foreach (SkillTargetData target in targets)
            {
                CardModel model = _lines[(int)target.Line][target.SlotNumber];
                models.Add(model);
                skill.Effect(model);
            }

            BroadcastSkillEffect_LogUpdate(CurrentPlayer, models, skill);
        }
 // 结算
 private void PlayProcess()
 {
     // 将选中的手牌加入堆叠
     playerHand.ForEach(c =>
     {
         if (c.selected)
         {
             playerStack.Add(c);
             c.nowIsIn = CardPosition.Graveyard;
         }
     });
     // 将牌组中符合生效区域的卡牌加入堆叠
     playerStack.AddRange(playerDeck.Where(c => CardSkill.checkAera(c.Id, c.nowIsIn)).ToList());
     // 开始结算
     playerStack.ForEach(c => CardSkill.CardEffectProcess(c.Id, this));
 }
Ejemplo n.º 7
0
        void ApplySkillEffectIfAny(CardModel card, LineIndicator deployLine, int slotNumber)
        {
            CardSkill skill = DB[card.CardId].Skill;

            if (skill != null)
            {
                var targets = new List <CardModel>();

                foreach (SkillTarget target in skill.Targets)
                {
                    targets.AddRange(ParseOnDeployAutomaticSkillTarget(deployLine, slotNumber, target));
                }

                foreach (CardModel target in targets)
                {
                    skill.Effect(target);
                }

                BroadcastSkillEffect_LogUpdate(CurrentPlayer, targets, skill);
            }
        }
Ejemplo n.º 8
0
        internal async void StartAITurn()
        {
            _taskQueue.Clear();

            Task <MoveData> task = CalculateMove(); // this already starts the task
            await Task.WhenAll(task);

            MoveData move = task.Result;

            _gameLogic.MoveCardForAI(_myIndicator, move); // you moved this card
            // upper logic knows nothing at this point yet

            // create the rest of the plan
            CardSkill skill = GameLogic.DB[move.Card.CardId].Skill;

            if (skill != null)
            {
                var targets = new List <SkillTargetData>(); // can be empty

                if (skill.ExecutionTime == SkillExecutionTime.OnDeployAutomatic)
                {
                    targets = GetTargetsOnDeployAutomatic(skill, move.TargetLine, move.TargetSlotNumber);
                }
                else if (skill.ExecutionTime == SkillExecutionTime.OnDeployManual)
                {
                    foreach (SkillTarget target in skill.Targets)
                    {
                        if (target == SkillTarget.SingleEnemy)
                        {
                            var singleTarget = ChooseSingleTarget();
                            if (singleTarget != null)
                            {
                                targets.Add(singleTarget);
                            }
                        }
                        else if (target == SkillTarget.EnemyLine)
                        {
                            targets.AddRange(GetEnemyLineTargets());
                        }
                        else if (target == SkillTarget.AllyLine)
                        {
                            targets.AddRange(GetAllyLineTargets());
                        }
                        else
                        {
                            throw new Exception("Unreachable code reached! "
                                                + "SkillTarget must have been extended without extending the AI's logic.");
                        }
                    }
                }

                // upon execution of this task the upper logic should start playing skill's animation
                _taskQueue.Enqueue(() => PlaySkillVFX(skill, targets));

                // upon execution of this task the upper logic should start applying skill's effect
                _taskQueue.Enqueue(() => ApplySkill(skill, targets));
            }

            // upon execution the upper logic should update card strengths
            _taskQueue.Enqueue(UpdateStrength);

            // upon execution the upper logic should give away the control to other player (human or AI)
            _taskQueue.Enqueue(EndTurn);

            // inform the upper logic about the card move you have done
            _gameLogic.BroadcastMoveCard_StatusUpdate(move);
        }
Ejemplo n.º 9
0
 void ApplySkill(CardSkill skill, List <SkillTargetData> targets)
 {
     _gameLogic.ApplySkillEffectForAI(skill, targets);
     _gameLogic.BroadcastUpdateStrength_StatusUpdate();
 }
Ejemplo n.º 10
0
 void PlaySkillVFX(CardSkill skill, List <SkillTargetData> targets)
 => _gameLogic.BroadcastPlayVFX_StatusUpdate(targets, skill.VisualEffect);
Ejemplo n.º 11
0
        internal void BroadcastSkillEffect_LogUpdate(PlayerIndicator player, List <CardModel> targets, CardSkill skill)
        {
#if UNITY_EDITOR || DEVELOPMENT_BUILD
            if (skill == null)
            {
                throw new ArgumentNullException("skill", "Skill argument cannot be null in this context.");
            }
#endif

            if (targets == null || targets.Count == 0)
            {
                return;
            }

            // a bit of a hack
            CardModel dummy = new CardModel(0, PlayerIndicator.Bot);
            skill.Effect(dummy);                                              // see what this spell does to a dummy
            bool heals       = dummy.CurrentStrength > dummy.DefaultStrength; // true - heals, false - damages
            int  howPowerful = Math.Abs(dummy.DefaultStrength - dummy.CurrentStrength);

            string lastExecutedCommand = $"<b>{CurrentPlayer.ToString()} Player's</b> card ";
            lastExecutedCommand += targets.Count == 1
                ? $"{HealsOrDamages()} <color=yellow>{DB[targets[0].CardId].Title}</color> for {howPowerful} point(s)"
                : $"{HealsOrDamages()} following cards: " + string.Join(", ", targets) // many targets
                                   + $" for total of {howPowerful * targets.Count} point(s)";

            string HealsOrDamages() => heals ? "<color=green>heals</color>" : "<color=red>damages</color>";

            GameLogicLogUpdateEventHandler?.Invoke(
                this,
                new GameLogicLogUpdateEventArgs(
                    player, GetCurrentStatus(), lastExecutedCommand, TopTotalStrength, BotTotalStrength));
        }