예제 #1
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);
        }
예제 #2
0
 public ActivationContext(Player controller, ActivationPrerequisites prerequisites)
 {
     Controller       = controller;
     Card             = prerequisites.Card;
     MaxX             = prerequisites.MaxX;
     Selector         = prerequisites.Selector;
     DistributeAmount = prerequisites.DistributeAmount;
     MaxRepetitions   = prerequisites.MaxRepetitions;
 }
예제 #3
0
 public ActivationContext(Player controller, ActivationPrerequisites prerequisites)
 {
     Controller = controller;
       Card = prerequisites.Card;
       MaxX = prerequisites.MaxX;
       Selector = prerequisites.Selector;
       DistributeAmount = prerequisites.DistributeAmount;
       MaxRepetitions = prerequisites.MaxRepetitions;
 }
예제 #4
0
        private bool SelectTargets(ActivationPrerequisites prerequisites, ActivationParameters parameters)
        {
            if (prerequisites.Selector.RequiresCostTargets)
            {
                var dialog = ShowSelectorDialog(
                    prerequisites.Selector.Cost.FirstOrDefault(),
                    parameters.X);

                if (dialog.WasCanceled)
                {
                    return(false);
                }

                foreach (var target in dialog.Selection)
                {
                    parameters.Targets.AddCost(target);
                }
            }

            if (prerequisites.Selector.RequiresEffectTargets)
            {
                foreach (var selector in prerequisites.Selector.Effect)
                {
                    var dialog = ShowSelectorDialog(selector, parameters.X);

                    if (dialog.WasCanceled)
                    {
                        return(false);
                    }

                    // this can occur when game is terminated
                    if (dialog.Selection.Count == 0)
                    {
                        return(false);
                    }

                    foreach (var target in dialog.Selection)
                    {
                        parameters.Targets.AddEffect(target);
                    }
                }
            }

            if (prerequisites.DistributeAmount > 0)
            {
                parameters.Targets.Distribution = DistributeAmount(parameters.Targets.Effect, prerequisites.DistributeAmount);
            }

            return(prerequisites.Selector.ValidateTargetDependencies(
                       new ValidateTargetDependenciesParam
            {
                Cost = parameters.Targets.Cost,
                Effect = parameters.Targets.Effect
            }
                       ));
        }
예제 #5
0
        public static bool SelectX(ActivationPrerequisites prerequisites, ActivationParameters activation, bool canCancel)
        {
            if (prerequisites.HasXInCost)
            {
                var dialog = Ui.Dialogs.SelectXCost.Create(prerequisites.MaxX.Value, canCancel);
                Ui.Shell.ShowModalDialog(dialog, DialogType.Small, InteractionState.Disabled);

                if (dialog.WasCanceled)
                {
                    return(false);
                }

                activation.X = dialog.ChosenX;
            }

            return(true);
        }
예제 #6
0
        public static bool SelectTargets(ActivationPrerequisites prerequisites, ActivationParameters parameters,
                                         bool canCancel)
        {
            if (parameters.PayManaCost && prerequisites.Selector.RequiresCostTargets)
            {
                var dialog = ShowSelectTargetDialog(
                    prerequisites.Selector.Cost.FirstOrDefault(),
                    parameters.X, canCancel);

                if (dialog.WasCanceled)
                {
                    return(false);
                }

                foreach (var target in dialog.Selection)
                {
                    parameters.Targets.AddCost(target);
                }
            }

            if (prerequisites.Selector.RequiresEffectTargets)
            {
                foreach (var selector in prerequisites.Selector.Effect)
                {
                    var dialog = ShowSelectTargetDialog(selector, parameters.X, canCancel);

                    if (dialog.WasCanceled)
                    {
                        return(false);
                    }

                    foreach (var target in dialog.Selection)
                    {
                        parameters.Targets.AddEffect(target);
                    }
                }
            }

            return(prerequisites.Selector.ValidateTargetDependencies(
                       new ValidateTargetDependenciesParam
            {
                Cost = parameters.Targets.Cost,
                Effect = parameters.Targets.Effect
            }
                       ));
        }
예제 #7
0
        private bool SelectX(ActivationPrerequisites prerequisites, ActivationParameters parameters)
        {
            if (prerequisites.HasXInCost)
            {
                var dialog = ViewModels.SelectXCost.Create(prerequisites.MaxX.Value);
                Shell.ShowModalDialog(dialog, DialogType.Small, InteractionState.Disabled);

                if (dialog.WasCanceled)
                {
                    return(false);
                }

                parameters.X = dialog.ChosenX;
            }

            return(true);
        }
예제 #8
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;
        }