diff --git a/Mage/src/mage/abilities/effects/common/DetainAllEffect.java b/Mage/src/mage/abilities/effects/common/DetainAllEffect.java index aee623896ff..30937a00243 100644 --- a/Mage/src/mage/abilities/effects/common/DetainAllEffect.java +++ b/Mage/src/mage/abilities/effects/common/DetainAllEffect.java @@ -28,17 +28,19 @@ package mage.abilities.effects.common; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; import mage.Constants; import mage.Constants.Outcome; import mage.abilities.Ability; import mage.abilities.effects.OneShotEffect; -import mage.abilities.effects.ReplacementEffectImpl; import mage.abilities.effects.RestrictionEffect; import mage.filter.FilterPermanent; import mage.game.Game; -import mage.game.events.GameEvent; import mage.game.permanent.Permanent; import mage.game.turn.Step; +import mage.target.targetpointer.FixedTarget; /** * @@ -67,81 +69,43 @@ public class DetainAllEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { + List detainedObjects = new ArrayList(); for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { game.informPlayers("Detained permanent: " + permanent.getName()); + FixedTarget fixedTarget = new FixedTarget(permanent.getId()); + fixedTarget.init(game, source); + detainedObjects.add(fixedTarget); } - game.getContinuousEffects().addEffect(new DetainAllReplacementEffect(filter), source); - game.getContinuousEffects().addEffect(new DetainAllRestrictionEffect(filter), source); - return false; - } -} -class DetainAllReplacementEffect extends ReplacementEffectImpl { - - private FilterPermanent filter = new FilterPermanent(); - - public DetainAllReplacementEffect(FilterPermanent filter) { - super(Constants.Duration.Custom, Constants.Outcome.LoseAbility); - this.filter = filter; - staticText = ""; - } - - public DetainAllReplacementEffect(final DetainAllReplacementEffect effect) { - super(effect); - this.filter = effect.filter; - } - - @Override - public DetainAllReplacementEffect copy() { - return new DetainAllReplacementEffect(this); - } - - @Override - public boolean isInactive(Ability source, Game game) { - if (game.getPhase().getStep().getType() == Constants.PhaseStep.UNTAP && game.getStep().getStepPart() == Step.StepPart.PRE) - { - if (game.getActivePlayerId().equals(source.getControllerId())) { - return true; - } - } - return false; - } - - @Override - public boolean apply(Game game, Ability source) { - return true; - } - - @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - return true; - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.ACTIVATE_ABILITY) { - Permanent permanent = game.getPermanent(event.getSourceId()); - if (permanent != null && filter.match(permanent, source.getSourceId(), source.getControllerId(), game)) { - return true; - } - } + game.addEffect(new DetainAllRestrictionEffect(detainedObjects), source); return false; } } class DetainAllRestrictionEffect extends RestrictionEffect { - private FilterPermanent filter = new FilterPermanent(); + private List detainedObjects; - public DetainAllRestrictionEffect(FilterPermanent filter) { + public DetainAllRestrictionEffect(List detainedObjects) { super(Constants.Duration.Custom); - this.filter = filter; + this.detainedObjects = detainedObjects; staticText = ""; } public DetainAllRestrictionEffect(final DetainAllRestrictionEffect effect) { super(effect); - this.filter = effect.filter; + this.detainedObjects = effect.detainedObjects; + } + + @Override + public void init(Ability source, Game game) { + super.init(source, game); + for(FixedTarget fixedTarget :this.detainedObjects) { + Permanent permanent = game.getPermanent(fixedTarget.getFirst(game, source)); + if (permanent != null) { + permanent.addInfo(new StringBuilder("detain").append(getId()).toString(),"[Detained]"); + } + } } @Override @@ -149,6 +113,12 @@ class DetainAllRestrictionEffect extends RestrictionEffect { game.informPlayers("Detained permanent: " + permanent.getName()); } } - game.getContinuousEffects().addEffect(new DetainReplacementEffect(), source); - game.getContinuousEffects().addEffect(new DetainRestrictionEffect(), source); + DetainRestrictionEffect effect = new DetainRestrictionEffect(); + effect.getTargetPointer().init(game, source); // needed to init zoneChangeCounter + game.addEffect(effect, source); return true; } @@ -123,55 +122,6 @@ public class DetainTargetEffect extends OneShotEffect { return sb.toString(); } } - - -class DetainReplacementEffect extends ReplacementEffectImpl { - - public DetainReplacementEffect() { - super(Constants.Duration.Custom, Constants.Outcome.LoseAbility); - staticText = ""; - } - - public DetainReplacementEffect(final DetainReplacementEffect effect) { - super(effect); - } - - @Override - public DetainReplacementEffect copy() { - return new DetainReplacementEffect(this); - } - - @Override - public boolean isInactive(Ability source, Game game) { - if (game.getPhase().getStep().getType() == Constants.PhaseStep.UNTAP && game.getStep().getStepPart() == Step.StepPart.PRE) - { - if (game.getActivePlayerId().equals(source.getControllerId())) { - return true; - } - } - return false; - } - - @Override - public boolean apply(Game game, Ability source) { - return true; - } - - @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - return true; - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.ACTIVATE_ABILITY) { - if (this.targetPointer.getTargets(game, source).contains(event.getSourceId())) { - return true; - } - } - return false; - } -} class DetainRestrictionEffect extends RestrictionEffect { @@ -183,12 +133,29 @@ class DetainRestrictionEffect extends RestrictionEffect public DetainRestrictionEffect(final DetainRestrictionEffect effect) { super(effect); } - + + @Override + public void init(Ability source, Game game) { + super.init(source, game); + for(UUID targetId :this.getTargetPointer().getTargets(game, source)) { + Permanent permanent = game.getPermanent(targetId); + if (permanent != null) { + permanent.addInfo(new StringBuilder("detain").append(getId()).toString(),"[Detained]"); + } + } + } + @Override public boolean isInactive(Ability source, Game game) { if (game.getPhase().getStep().getType() == Constants.PhaseStep.UNTAP && game.getStep().getStepPart() == Step.StepPart.PRE) { if (game.getActivePlayerId().equals(source.getControllerId())) { + for(UUID targetId :this.getTargetPointer().getTargets(game, source)) { + Permanent permanent = game.getPermanent(targetId); + if (permanent != null) { + permanent.addInfo(new StringBuilder("detain").append(getId()).toString(),""); + } + } return true; } } @@ -212,10 +179,15 @@ class DetainRestrictionEffect extends RestrictionEffect public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game) { return false; } - + + @Override + public boolean canUseActivatedAbilities(Permanent permanent, Ability source, Game game) { + return false; + } + @Override public DetainRestrictionEffect copy() { return new DetainRestrictionEffect(this); } -} \ No newline at end of file +}