private void GetBlockersDeclarationsLure(List <Card> attackers, List <ChosenBlockers> strategies) { var chosenBlockers = new ChosenBlockers(); var candidates = new HashSet <Card>(D.Controller.Battlefield.CreaturesThatCanBlock); foreach (var attacker in attackers.Where(x => x.Has().Lure).OrderBy(x => x.Toughness)) { foreach (var blocker in candidates.Where(x => attacker.CanBeBlockedBy(x)).ToList()) { chosenBlockers.Add(blocker, attacker); candidates.Remove(blocker); } } if (candidates.Count > 0) { var remaining = BlockStrategy.ChooseBlockers(new BlockStrategyParameters { Attackers = attackers, BlockerCandidates = candidates.ToList(), DefendersLife = D.Controller.Life }); foreach (var attackerBlockerPair in remaining) { chosenBlockers.Add(attackerBlockerPair.Blocker, attackerBlockerPair.Attacker); } } strategies.Add(chosenBlockers); }
public ScenarioStep DeclareBlockers(params Card[] pairs) { Debug.Assert(pairs.Length % 2 == 0, "Pairs lenght must be even number, did you forget to match a blocker?"); var chosenBlockers = new ChosenBlockers(); for (var i = 0; i < pairs.Length; i = i + 2) { var attacker = pairs[i]; var blocker = pairs[i + 1]; chosenBlockers.Add(blocker, attacker); } _results.Add(new DecisionResult(chosenBlockers, null)); return(this); }
protected override void ExecuteQuery() { var result = new ChosenBlockers(); var lureAttackers = Combat.Attackers .Select(x => x.Card) .Where(x => x.Has().Lure) .ToList(); while (true) { var blockerTarget = new TargetValidatorParameters { MinCount = IsValidBlockerDeclaration(result, lureAttackers) ? 0 : 1, MaxCount = 1, Message = "Select a blocker." } .Is.Card(c => c.CanBlock() && c.Controller == D.Controller) .On.Battlefield(); blockerTarget.MustBeTargetable = false; var blockerValidator = new TargetValidator(blockerTarget); blockerValidator.Initialize(Game, D.Controller); var selectBlocker = Ui.Dialogs.SelectTarget.Create(new SelectTargetParameters { Validator = blockerValidator, CanCancel = false, Instructions = IsValidBlockerDeclaration(result, lureAttackers) ? null : "(Additional blockers required.)" }); Ui.Shell.ShowModalDialog(selectBlocker, DialogType.Small, InteractionState.SelectTarget); if (selectBlocker.Selection.Count == 0) { break; } var blocker = (Card)selectBlocker.Selection[0]; if (result.ContainsBlocker(blocker)) { result.Remove(blocker); Ui.Publisher.Publish(new BlockerUnselected { Blocker = blocker }); continue; } var attackerTarget = new TargetValidatorParameters { MinCount = 1, MaxCount = 1, Message = "Select an attacker to block." } .Is.Card(c => { // if any attacker has lure, we must block it if (lureAttackers.Any(x => x.CanBeBlockedBy(blocker)) && !c.Has().Lure) { return(false); } return(c.IsAttacker && c.CanBeBlockedBy(blocker)); }) .On.Battlefield(); attackerTarget.MustBeTargetable = false; var attackerValidator = new TargetValidator(attackerTarget); attackerValidator.Initialize(Game, D.Controller); var selectAttacker = Ui.Dialogs.SelectTarget.Create(new SelectTargetParameters { Validator = attackerValidator, CanCancel = true, Instructions = "(Press Esc to cancel.)" }); Ui.Shell.ShowModalDialog(selectAttacker, DialogType.Small, InteractionState.SelectTarget); if (selectAttacker.WasCanceled) { continue; } var attacker = (Card)selectAttacker.Selection[0]; Ui.Publisher.Publish(new BlockerSelected { Blocker = blocker, Attacker = attacker }); result.Add(blocker, attacker); } Result = result; }