Fixed two bug of detain (DetainAll did not lock in targets, DetainTarget did not take zoneChangeCounter into account). Added info text to tooltip of detained permanents.

This commit is contained in:
LevelX2 2013-05-31 17:42:25 +02:00
parent 1677373c13
commit b46dab1c96
2 changed files with 68 additions and 118 deletions

View file

@ -28,17 +28,19 @@
package mage.abilities.effects.common; package mage.abilities.effects.common;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.Constants; import mage.Constants;
import mage.Constants.Outcome; import mage.Constants.Outcome;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.RestrictionEffect; import mage.abilities.effects.RestrictionEffect;
import mage.filter.FilterPermanent; import mage.filter.FilterPermanent;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.game.turn.Step; import mage.game.turn.Step;
import mage.target.targetpointer.FixedTarget;
/** /**
* *
@ -67,81 +69,43 @@ public class DetainAllEffect extends OneShotEffect<DetainAllEffect> {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
List<FixedTarget> detainedObjects = new ArrayList<FixedTarget>();
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
game.informPlayers("Detained permanent: " + permanent.getName()); 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<DetainAllReplacementEffect> { game.addEffect(new DetainAllRestrictionEffect(detainedObjects), source);
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;
}
}
return false; return false;
} }
} }
class DetainAllRestrictionEffect extends RestrictionEffect<DetainAllRestrictionEffect> { class DetainAllRestrictionEffect extends RestrictionEffect<DetainAllRestrictionEffect> {
private FilterPermanent filter = new FilterPermanent(); private List<FixedTarget> detainedObjects;
public DetainAllRestrictionEffect(FilterPermanent filter) { public DetainAllRestrictionEffect(List<FixedTarget> detainedObjects) {
super(Constants.Duration.Custom); super(Constants.Duration.Custom);
this.filter = filter; this.detainedObjects = detainedObjects;
staticText = ""; staticText = "";
} }
public DetainAllRestrictionEffect(final DetainAllRestrictionEffect effect) { public DetainAllRestrictionEffect(final DetainAllRestrictionEffect effect) {
super(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 @Override
@ -149,6 +113,12 @@ class DetainAllRestrictionEffect extends RestrictionEffect<DetainAllRestrictionE
if (game.getPhase().getStep().getType() == Constants.PhaseStep.UNTAP && game.getStep().getStepPart() == Step.StepPart.PRE) if (game.getPhase().getStep().getType() == Constants.PhaseStep.UNTAP && game.getStep().getStepPart() == Step.StepPart.PRE)
{ {
if (game.getActivePlayerId().equals(source.getControllerId())) { if (game.getActivePlayerId().equals(source.getControllerId())) {
for(FixedTarget fixedTarget :this.detainedObjects) {
Permanent permanent = game.getPermanent(fixedTarget.getFirst(game, source));
if (permanent != null) {
permanent.addInfo(new StringBuilder("detain").append(getId()).toString(),"");
}
}
return true; return true;
} }
} }
@ -157,8 +127,11 @@ class DetainAllRestrictionEffect extends RestrictionEffect<DetainAllRestrictionE
@Override @Override
public boolean applies(Permanent permanent, Ability source, Game game) { public boolean applies(Permanent permanent, Ability source, Game game) {
if (filter.match(permanent, source.getSourceId(), source.getControllerId(), game)) { for(FixedTarget fixedTarget :this.detainedObjects) {
return true; UUID targetId = fixedTarget.getFirst(game, source);
if (targetId != null && targetId.equals(permanent.getId())) {
return true;
}
} }
return false; return false;
} }
@ -173,6 +146,11 @@ class DetainAllRestrictionEffect extends RestrictionEffect<DetainAllRestrictionE
return false; return false;
} }
@Override
public boolean canUseActivatedAbilities(Permanent permanent, Ability source, Game game) {
return false;
}
@Override @Override
public DetainAllRestrictionEffect copy() { public DetainAllRestrictionEffect copy() {
return new DetainAllRestrictionEffect(this); return new DetainAllRestrictionEffect(this);

View file

@ -33,10 +33,8 @@ import mage.Constants;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.Mode; import mage.abilities.Mode;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.RestrictionEffect; import mage.abilities.effects.RestrictionEffect;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.game.turn.Step; import mage.game.turn.Step;
import mage.target.Target; import mage.target.Target;
@ -85,8 +83,9 @@ public class DetainTargetEffect extends OneShotEffect<DetainTargetEffect> {
game.informPlayers("Detained permanent: " + permanent.getName()); game.informPlayers("Detained permanent: " + permanent.getName());
} }
} }
game.getContinuousEffects().addEffect(new DetainReplacementEffect(), source); DetainRestrictionEffect effect = new DetainRestrictionEffect();
game.getContinuousEffects().addEffect(new DetainRestrictionEffect(), source); effect.getTargetPointer().init(game, source); // needed to init zoneChangeCounter
game.addEffect(effect, source);
return true; return true;
} }
@ -124,55 +123,6 @@ public class DetainTargetEffect extends OneShotEffect<DetainTargetEffect> {
} }
} }
class DetainReplacementEffect extends ReplacementEffectImpl<DetainReplacementEffect> {
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<DetainRestrictionEffect> { class DetainRestrictionEffect extends RestrictionEffect<DetainRestrictionEffect> {
public DetainRestrictionEffect() { public DetainRestrictionEffect() {
@ -184,11 +134,28 @@ class DetainRestrictionEffect extends RestrictionEffect<DetainRestrictionEffect>
super(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 @Override
public boolean isInactive(Ability source, Game game) { public boolean isInactive(Ability source, Game game) {
if (game.getPhase().getStep().getType() == Constants.PhaseStep.UNTAP && game.getStep().getStepPart() == Step.StepPart.PRE) if (game.getPhase().getStep().getType() == Constants.PhaseStep.UNTAP && game.getStep().getStepPart() == Step.StepPart.PRE)
{ {
if (game.getActivePlayerId().equals(source.getControllerId())) { 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; return true;
} }
} }
@ -213,6 +180,11 @@ class DetainRestrictionEffect extends RestrictionEffect<DetainRestrictionEffect>
return false; return false;
} }
@Override
public boolean canUseActivatedAbilities(Permanent permanent, Ability source, Game game) {
return false;
}
@Override @Override
public DetainRestrictionEffect copy() { public DetainRestrictionEffect copy() {
return new DetainRestrictionEffect(this); return new DetainRestrictionEffect(this);