mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
SkipNextUntapTargetEffect for multi targets.
This commit is contained in:
parent
5d19c9cfee
commit
7c1ca96936
1 changed files with 36 additions and 5 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue