add targets pointer

This commit is contained in:
Loki 2011-06-07 22:13:42 +03:00
parent 52b4858f99
commit 0b10a3a121
4 changed files with 53 additions and 1 deletions

View file

@ -32,6 +32,8 @@ import java.util.UUID;
import mage.Constants.EffectType;
import mage.Constants.Outcome;
import mage.abilities.Ability;
import mage.target.targetpointer.FirstTargetPointer;
import mage.target.targetpointer.TargetPointer;
/**
*
@ -42,6 +44,7 @@ public abstract class EffectImpl<T extends Effect<T>> implements Effect<T> {
protected UUID id;
protected final Outcome outcome;
protected EffectType effectType;
protected TargetPointer targetPointer = FirstTargetPointer.getInstance();
protected String staticText = "";
public EffectImpl(Outcome outcome) {
@ -54,6 +57,7 @@ public abstract class EffectImpl<T extends Effect<T>> implements Effect<T> {
this.outcome = effect.outcome;
this.effectType = effect.effectType;
this.staticText = effect.staticText;
this.targetPointer = effect.targetPointer.copy();
}
@Override
@ -87,4 +91,8 @@ public abstract class EffectImpl<T extends Effect<T>> implements Effect<T> {
public EffectType getEffectType() {
return effectType;
}
public void setTargetPointer(TargetPointer targetPointer) {
this.targetPointer = targetPointer;
}
}

View file

@ -63,7 +63,7 @@ public class AddPoisonCounterTargetEffect extends OneShotEffect<AddPoisonCounter
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getFirstTarget());
Player player = game.getPlayer(targetPointer.getFirst(source));
if (player != null) {
player.getCounters().addCounter(CounterType.POISON.createInstance(amount));
return true;

View file

@ -0,0 +1,32 @@
package mage.target.targetpointer;
import mage.abilities.Ability;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class FirstTargetPointer implements TargetPointer {
private static FirstTargetPointer instance = new FirstTargetPointer();
public static FirstTargetPointer getInstance() {
return instance;
}
@Override
public List<UUID> getTargets(Ability source) {
ArrayList<UUID> target = new ArrayList<UUID>();
target.add(source.getFirstTarget());
return target;
}
@Override
public UUID getFirst(Ability source) {
return source.getFirstTarget();
}
@Override
public TargetPointer copy() {
return instance;
}
}

View file

@ -0,0 +1,12 @@
package mage.target.targetpointer;
import mage.abilities.Ability;
import java.util.List;
import java.util.UUID;
public interface TargetPointer {
List<UUID> getTargets(Ability source);
UUID getFirst(Ability source);
TargetPointer copy();
}