diff --git a/Mage.Sets/src/mage/sets/commander2014/DomineeringWill.java b/Mage.Sets/src/mage/sets/commander2014/DomineeringWill.java index 147aa03c71..33926bb248 100644 --- a/Mage.Sets/src/mage/sets/commander2014/DomineeringWill.java +++ b/Mage.Sets/src/mage/sets/commander2014/DomineeringWill.java @@ -28,17 +28,26 @@ package mage.sets.commander2014; import java.util.UUID; +import mage.abilities.Ability; +import mage.abilities.effects.ContinuousEffect; +import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.effects.Effect; -import mage.abilities.effects.common.UntapTargetEffect; -import mage.abilities.effects.common.combat.BlocksIfAbleTargetEffect; -import mage.abilities.effects.common.continious.GainControlTargetEffect; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.RequirementEffect; import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Duration; +import mage.constants.Layer; +import mage.constants.Outcome; import mage.constants.Rarity; +import mage.constants.SubLayer; import mage.filter.common.FilterCreaturePermanent; import mage.filter.predicate.Predicates; import mage.filter.predicate.permanent.AttackingPredicate; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.target.TargetPlayer; import mage.target.common.TargetCreaturePermanent; /** @@ -60,14 +69,10 @@ public class DomineeringWill extends CardImpl { this.color.setBlue(true); // Target player gains control of up to three target nonattacking creatures until end of turn. Untap those creatures. They block this turn if able. - this.getSpellAbility().addEffect(new GainControlTargetEffect(Duration.EndOfTurn)); - Effect effect = new UntapTargetEffect(); - effect.setText("Untap those creatures"); - this.getSpellAbility().addEffect(effect); - effect = new BlocksIfAbleTargetEffect(Duration.EndOfTurn); - effect.setText("They block this turn if able"); - this.getSpellAbility().addEffect(effect); - this.getSpellAbility().addTarget(new TargetCreaturePermanent(0,3, filter, false)); + this.getSpellAbility().addEffect(new DomineeringWillEffect()); + this.getSpellAbility().addTarget(new TargetPlayer()); + this.getSpellAbility().addTarget(new TargetCreaturePermanent(0, 3, filter, false)); + } public DomineeringWill(final DomineeringWill card) { @@ -79,3 +84,143 @@ public class DomineeringWill extends CardImpl { return new DomineeringWill(this); } } + +class DomineeringWillEffect extends OneShotEffect { + + public DomineeringWillEffect() { + super(Outcome.Benefit); + staticText = "Target player gains control of up to three target nonattacking creatures until end of turn. Untap those creatures. They block this turn if able"; + } + + public DomineeringWillEffect(final DomineeringWillEffect effect) { + super(effect); + } + + @Override + public DomineeringWillEffect copy() { + return new DomineeringWillEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source)); + if (targetPlayer != null) { + ContinuousEffect effect = new DomineeringWillControlEffect(); + game.addEffect(effect, source); + Effect effect2 = new DomineeringWillUntapTargetEffect(); + effect2.setText("Untap those creatures"); + effect2.apply(game, source); + RequirementEffect effect3 = new DomineeringWillBlocksIfAbleTargetEffect(Duration.EndOfTurn); + effect3.setText("They block this turn if able"); + game.addEffect(effect3, source); + return true; + } + return false; + } +} + +class DomineeringWillControlEffect extends ContinuousEffectImpl { + + public DomineeringWillControlEffect() { + super(Duration.EndOfTurn, Layer.ControlChangingEffects_2, SubLayer.NA, Outcome.GainControl); + } + + public DomineeringWillControlEffect(final DomineeringWillControlEffect effect) { + super(effect); + } + + @Override + public DomineeringWillControlEffect copy() { + return new DomineeringWillControlEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source)); + if (targetPlayer != null) { + boolean targetStillExists = false; + for (UUID permanentId : source.getTargets().get(1).getTargets()) { + Permanent permanent = game.getPermanent(permanentId); + if (permanent != null) { + targetStillExists = true; + if (targetPlayer != null) { + permanent.changeControllerId(targetPlayer.getId(), game); + permanent.getAbilities().setControllerId(targetPlayer.getId()); + } else { + permanent.changeControllerId(source.getControllerId(), game); + permanent.getAbilities().setControllerId(source.getControllerId()); + } + } + } + if (!targetStillExists) { + // no valid target exists, effect can be discarded + discard(); + } + return true; + } + return false; + } +} + +class DomineeringWillUntapTargetEffect extends OneShotEffect { + + public DomineeringWillUntapTargetEffect() { + super(Outcome.Untap); + } + + public DomineeringWillUntapTargetEffect(final DomineeringWillUntapTargetEffect effect) { + super(effect); + } + + @Override + public DomineeringWillUntapTargetEffect copy() { + return new DomineeringWillUntapTargetEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + for (UUID target : source.getTargets().get(1).getTargets()) { + Permanent permanent = game.getPermanent(target); + if (permanent != null) { + permanent.untap(game); + } + } + return true; + } +} + +class DomineeringWillBlocksIfAbleTargetEffect extends RequirementEffect { + + public DomineeringWillBlocksIfAbleTargetEffect(Duration duration) { + super(duration); + } + + public DomineeringWillBlocksIfAbleTargetEffect(final DomineeringWillBlocksIfAbleTargetEffect effect) { + super(effect); + } + + @Override + public DomineeringWillBlocksIfAbleTargetEffect copy() { + return new DomineeringWillBlocksIfAbleTargetEffect(this); + } + + @Override + public boolean applies(Permanent permanent, Ability source, Game game) { + return source.getTargets().get(1).getTargets().contains(permanent.getId()); + } + + @Override + public boolean mustAttack(Game game) { + return false; + } + + @Override + public boolean mustBlock(Game game) { + return false; + } + + @Override + public boolean mustBlockAny(Game game) { + return true; + } +}