SkipNextUntapTargetEffect for multi targets.

This commit is contained in:
magenoxx 2011-08-12 17:39:52 +04:00
parent 5d19c9cfee
commit 7c1ca96936

View file

@ -38,18 +38,28 @@ import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class SkipNextUntapTargetEffect extends ReplacementEffectImpl<SkipNextUntapTargetEffect> {
protected Set<UUID> usedFor = new HashSet<UUID>();
protected int count;
public SkipNextUntapTargetEffect() {
super(Duration.OneUse, Outcome.Detriment);
}
public SkipNextUntapTargetEffect(final SkipNextUntapTargetEffect effect) {
super(effect);
for (UUID uuid : effect.usedFor) {
this.usedFor.add(uuid);
}
this.count = effect.count;
}
@Override
@ -64,16 +74,37 @@ public class SkipNextUntapTargetEffect extends ReplacementEffectImpl<SkipNextUnt
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
used = true;
if (source.getTargets().get(0).getTargets().size() < 2) {
used = true;
} else {
count++;
}
// not clear how to turn off the effect for more than one target
// especially as some targets may leave the battlefield since the effect creation
// so handling this in applies method is the only option for now for such cases
if (count == source.getTargets().get(0).getTargets().size()) {
// this won't work for targets disappeared before applies() return true
used = true;
}
return true;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (game.getTurn().getStepType() == PhaseStep.UNTAP &&
event.getType() == EventType.UNTAP &&
event.getTargetId().equals(source.getFirstTarget())) {
return true;
event.getType() == EventType.UNTAP) {
for (UUID target : source.getTargets().get(0).getTargets()) {
if (event.getTargetId().equals(target)) {
if (!usedFor.contains(target)) {
usedFor.add(target);
return true;
}
break;
}
}
return false;
}
return false;
}