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;
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<DetainAllEffect> {
@Override
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)) {
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> {
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<DetainAllRestrictionEffect> {
private FilterPermanent filter = new FilterPermanent();
private List<FixedTarget> detainedObjects;
public DetainAllRestrictionEffect(FilterPermanent filter) {
public DetainAllRestrictionEffect(List<FixedTarget> 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<DetainAllRestrictionE
if (game.getPhase().getStep().getType() == Constants.PhaseStep.UNTAP && game.getStep().getStepPart() == Step.StepPart.PRE)
{
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;
}
}
@ -157,8 +127,11 @@ class DetainAllRestrictionEffect extends RestrictionEffect<DetainAllRestrictionE
@Override
public boolean applies(Permanent permanent, Ability source, Game game) {
if (filter.match(permanent, source.getSourceId(), source.getControllerId(), game)) {
return true;
for(FixedTarget fixedTarget :this.detainedObjects) {
UUID targetId = fixedTarget.getFirst(game, source);
if (targetId != null && targetId.equals(permanent.getId())) {
return true;
}
}
return false;
}
@ -172,6 +145,11 @@ class DetainAllRestrictionEffect extends RestrictionEffect<DetainAllRestrictionE
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 DetainAllRestrictionEffect copy() {

View file

@ -33,10 +33,8 @@ import mage.Constants;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.RestrictionEffect;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.game.turn.Step;
import mage.target.Target;
@ -85,8 +83,9 @@ public class DetainTargetEffect extends OneShotEffect<DetainTargetEffect> {
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<DetainTargetEffect> {
return sb.toString();
}
}
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> {
@ -183,12 +133,29 @@ class DetainRestrictionEffect extends RestrictionEffect<DetainRestrictionEffect>
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<DetainRestrictionEffect>
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);
}
}
}