Ejemplo n.º 1
0
        public static bool IsGoodTargetForSpell(
            ITarget target,
            Card spell,
            Player controller,
            TargetSelector selector,
            IEnumerable <TargetingRule> rules,
            int distributeAmount)
        {
            var activation = new ActivationContext(controller, spell, selector, distributeAmount);

            foreach (var rule in rules)
            {
                rule.Process(activation);
            }

            foreach (var targetsCombination in activation.TargetsCombinations())
            {
                if (targetsCombination.Targets.Effect.Contains(target))
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 2
0
        private List <Playable> GeneratePlayables(ActivationPrerequisites prerequisites, Func <Playable> createPlayable)
        {
            var context = new ActivationContext(_player, prerequisites);
            var result  = new List <Playable>();

            var work = prerequisites.Rules.ToList();

            var pass = 1;

            while (work.Count > 0)
            {
                var newWork = new List <MachinePlayRule>();

                foreach (var rule in work)
                {
                    var isFinished = rule.Process(pass, context);

                    if (context.CancelActivation)
                    {
                        return(result);
                    }

                    if (!isFinished)
                    {
                        newWork.Add(rule);
                    }
                }
                pass++;
                work = newWork;
            }

            if (context.HasTargets == false)
            {
                var playable = createPlayable();

                playable.Card  = prerequisites.Card;
                playable.Index = prerequisites.Index;
                playable.ActivationParameters.X      = context.X;
                playable.ActivationParameters.Repeat = context.Repeat;

                result.Add(playable);
                return(result);
            }

            foreach (var targetsCombination in context.TargetsCombinations().Take(Ai.CurrentTargetCount))
            {
                var playable = createPlayable();

                playable.Card  = prerequisites.Card;
                playable.Index = prerequisites.Index;
                playable.ActivationParameters.Targets = targetsCombination.Targets;
                playable.ActivationParameters.X       = targetsCombination.X;
                playable.ActivationParameters.Repeat  = targetsCombination.Repeat;

                result.Add(playable);
            }

            return(result);
        }
Ejemplo n.º 3
0
        public static IEnumerable<Targets> GenerateTargets(Card owningCard, 
      TargetSelector selector, IEnumerable<TargetingRule> rules, bool force = false, 
      object triggerMessage = null)
        {
            var activation = new ActivationContext(owningCard.Controller, owningCard, selector);
              activation.CanCancel = !force;
              activation.TriggerMessage = triggerMessage;

              foreach (var rule in rules)
              {
            rule.Process(activation);
              }

              foreach (var targetsCombination in activation.TargetsCombinations())
              {
            yield return targetsCombination.Targets;
              }

              yield break;
        }
Ejemplo n.º 4
0
        public static IEnumerable <Targets> GenerateTargets(Card owningCard,
                                                            TargetSelector selector, IEnumerable <TargetingRule> rules, bool force = false,
                                                            object triggerMessage = null)
        {
            var activation = new ActivationContext(owningCard.Controller, owningCard, selector);

            activation.CanCancel      = !force;
            activation.TriggerMessage = triggerMessage;

            foreach (var rule in rules)
            {
                rule.Process(activation);
            }

            foreach (var targetsCombination in activation.TargetsCombinations())
            {
                yield return(targetsCombination.Targets);
            }

            yield break;
        }
Ejemplo n.º 5
0
        public static bool IsGoodTargetForSpell(
      ITarget target, 
      Card spell, 
      Player controller,
      TargetSelector selector, 
      IEnumerable<TargetingRule> rules)
        {
            var activation = new ActivationContext(controller, spell, selector);

              foreach (var rule in rules)
              {
            rule.Process(activation);
              }

              foreach (var targetsCombination in activation.TargetsCombinations())
              {
            if (targetsCombination.Targets.Effect.Contains(target))
              return true;
              }

              return false;
        }
Ejemplo n.º 6
0
        private List<Playable> GeneratePlayables(ActivationPrerequisites prerequisites, Func<Playable> createPlayable)
        {
            var context = new ActivationContext(_player, prerequisites);
              var result = new List<Playable>();

              var work = prerequisites.Rules.ToList();

              var pass = 1;
              while (work.Count > 0)
              {
            var newWork = new List<MachinePlayRule>();

            foreach (var rule in work)
            {
              var isFinished = rule.Process(pass, context);

              if (context.CancelActivation)
              {
            return result;
              }

              if (!isFinished)
              {
            newWork.Add(rule);
              }
            }
            pass++;
            work = newWork;
              }

              if (context.HasTargets == false)
              {
            var playable = createPlayable();

            playable.Card = prerequisites.Card;
            playable.Index = prerequisites.Index;
            playable.ActivationParameters.X = context.X;
            playable.ActivationParameters.Repeat = context.Repeat;

            result.Add(playable);
            return result;
              }

              foreach (var targetsCombination in context.TargetsCombinations().Take(Ai.CurrentTargetCount))
              {
            var playable = createPlayable();

            playable.Card = prerequisites.Card;
            playable.Index = prerequisites.Index;
            playable.ActivationParameters.Targets = targetsCombination.Targets;
            playable.ActivationParameters.X = targetsCombination.X;
            playable.ActivationParameters.Repeat = targetsCombination.Repeat;

            result.Add(playable);
              }

              return result;
        }