* Kira, Great Glass-Spinner - Some fixes to the triggered ability that controlled creatures gain.

This commit is contained in:
LevelX2 2015-08-24 01:53:24 +02:00
parent 8b02e6805f
commit c024318489

View file

@ -31,8 +31,10 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import mage.MageInt;
import mage.MageObjectReference;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.CounterTargetEffect;
import mage.abilities.effects.common.continuous.GainAbilityControlledEffect;
import mage.abilities.keyword.FlyingAbility;
@ -40,12 +42,15 @@ import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Rarity;
import mage.constants.WatcherScope;
import mage.constants.Zone;
import mage.filter.common.FilterCreaturePermanent;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.target.TargetStackObject;
import mage.game.permanent.Permanent;
import mage.target.targetpointer.FixedTarget;
import mage.watchers.Watcher;
/**
*
@ -59,7 +64,6 @@ public class KiraGreatGlassSpinner extends CardImpl {
this.subtype.add("Spirit");
this.supertype.add("Legendary");
this.power = new MageInt(2);
this.toughness = new MageInt(2);
@ -67,7 +71,10 @@ public class KiraGreatGlassSpinner extends CardImpl {
this.addAbility(FlyingAbility.getInstance());
// Creatures you control have "Whenever this creature becomes the target of a spell or ability for the first time in a turn, counter that spell or ability."
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new GainAbilityControlledEffect(new KiraGreatGlassSpinnerAbility(), Duration.WhileOnBattlefield, new FilterCreaturePermanent("Creatures you control"))));
Effect effect = new CounterTargetEffect();
effect.setText("counter that spell or ability");
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new GainAbilityControlledEffect(new KiraGreatGlassSpinnerAbility(effect), Duration.WhileOnBattlefield, new FilterCreaturePermanent("Creatures you control"))),
new CreatureWasTargetedThisTurnWatcher());
}
@ -80,21 +87,15 @@ public class KiraGreatGlassSpinner extends CardImpl {
return new KiraGreatGlassSpinner(this);
}
}
// TODO:
// not perfectly implemented. It doesnt't handles if a creature was already targeted the turn Kira comes into play.
// Maybe it's better to implement it with a watcher
class KiraGreatGlassSpinnerAbility extends TriggeredAbilityImpl {
protected Map<UUID,Integer> turnUsed = new HashMap<>();
public KiraGreatGlassSpinnerAbility() {
super(Zone.BATTLEFIELD, new CounterTargetEffect(), false);
public KiraGreatGlassSpinnerAbility(Effect effect) {
super(Zone.BATTLEFIELD, effect, false);
}
public KiraGreatGlassSpinnerAbility(final KiraGreatGlassSpinnerAbility ability) {
super(ability);
turnUsed = ability.turnUsed;
}
@Override
@ -110,20 +111,15 @@ class KiraGreatGlassSpinnerAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getTargetId().equals(this.getSourceId())) {
Integer turn = turnUsed.get(event.getTargetId());
if (turn == null || turn < game.getTurnNum()) {
this.getTargets().clear();
TargetStackObject target = new TargetStackObject();
target.add(event.getSourceId(), game);
this.addTarget(target);
if (turnUsed.containsKey(event.getTargetId())) {
turnUsed.remove(event.getTargetId());
turnUsed.put(event.getTargetId(), game.getTurnNum());
} else {
turnUsed.put(event.getTargetId(), game.getTurnNum());
Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent.getCardType().contains(CardType.CREATURE)) {
CreatureWasTargetedThisTurnWatcher watcher = (CreatureWasTargetedThisTurnWatcher) game.getState().getWatchers().get("CreatureWasTargetedThisTurn");
if (watcher != null && watcher.notMoreThanOnceTargetedThisTurn(permanent, game)) {
for (Effect effect : getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getSourceId()));
}
return true;
}
return true;
}
}
return false;
@ -135,3 +131,50 @@ class KiraGreatGlassSpinnerAbility extends TriggeredAbilityImpl {
}
}
class CreatureWasTargetedThisTurnWatcher extends Watcher {
private final Map<MageObjectReference, Integer> creaturesTargeted = new HashMap<>();
public CreatureWasTargetedThisTurnWatcher() {
super("CreatureWasTargetedThisTurn", WatcherScope.GAME);
}
public CreatureWasTargetedThisTurnWatcher(final CreatureWasTargetedThisTurnWatcher watcher) {
super(watcher);
this.creaturesTargeted.putAll(creaturesTargeted);
}
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.TARGETED) {
Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent.getCardType().contains(CardType.CREATURE)) {
MageObjectReference mor = new MageObjectReference(permanent, game);
int amount = 0;
if (creaturesTargeted.containsKey(mor)) {
amount = creaturesTargeted.get(mor);
}
creaturesTargeted.put(mor, ++amount);
}
}
}
public boolean notMoreThanOnceTargetedThisTurn(Permanent creature, Game game) {
if (creaturesTargeted.containsKey(new MageObjectReference(creature, game))) {
return creaturesTargeted.get(new MageObjectReference(creature, game)) < 2;
}
return true;
}
@Override
public void reset() {
super.reset();
creaturesTargeted.clear();
}
@Override
public CreatureWasTargetedThisTurnWatcher copy() {
return new CreatureWasTargetedThisTurnWatcher(this);
}
}