mirror of
https://github.com/correl/mage.git
synced 2025-03-16 01:06:34 -09:00
* Kira, Great Glass-Spinner - Some fixes to the triggered ability that controlled creatures gain.
This commit is contained in:
parent
8b02e6805f
commit
c024318489
1 changed files with 67 additions and 24 deletions
|
@ -31,8 +31,10 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import mage.MageInt;
|
import mage.MageInt;
|
||||||
|
import mage.MageObjectReference;
|
||||||
import mage.abilities.TriggeredAbilityImpl;
|
import mage.abilities.TriggeredAbilityImpl;
|
||||||
import mage.abilities.common.SimpleStaticAbility;
|
import mage.abilities.common.SimpleStaticAbility;
|
||||||
|
import mage.abilities.effects.Effect;
|
||||||
import mage.abilities.effects.common.CounterTargetEffect;
|
import mage.abilities.effects.common.CounterTargetEffect;
|
||||||
import mage.abilities.effects.common.continuous.GainAbilityControlledEffect;
|
import mage.abilities.effects.common.continuous.GainAbilityControlledEffect;
|
||||||
import mage.abilities.keyword.FlyingAbility;
|
import mage.abilities.keyword.FlyingAbility;
|
||||||
|
@ -40,12 +42,15 @@ import mage.cards.CardImpl;
|
||||||
import mage.constants.CardType;
|
import mage.constants.CardType;
|
||||||
import mage.constants.Duration;
|
import mage.constants.Duration;
|
||||||
import mage.constants.Rarity;
|
import mage.constants.Rarity;
|
||||||
|
import mage.constants.WatcherScope;
|
||||||
import mage.constants.Zone;
|
import mage.constants.Zone;
|
||||||
import mage.filter.common.FilterCreaturePermanent;
|
import mage.filter.common.FilterCreaturePermanent;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.events.GameEvent;
|
import mage.game.events.GameEvent;
|
||||||
import mage.game.events.GameEvent.EventType;
|
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.subtype.add("Spirit");
|
||||||
this.supertype.add("Legendary");
|
this.supertype.add("Legendary");
|
||||||
|
|
||||||
|
|
||||||
this.power = new MageInt(2);
|
this.power = new MageInt(2);
|
||||||
this.toughness = new MageInt(2);
|
this.toughness = new MageInt(2);
|
||||||
|
|
||||||
|
@ -67,7 +71,10 @@ public class KiraGreatGlassSpinner extends CardImpl {
|
||||||
this.addAbility(FlyingAbility.getInstance());
|
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."
|
// 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);
|
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 {
|
class KiraGreatGlassSpinnerAbility extends TriggeredAbilityImpl {
|
||||||
|
|
||||||
protected Map<UUID,Integer> turnUsed = new HashMap<>();
|
public KiraGreatGlassSpinnerAbility(Effect effect) {
|
||||||
|
super(Zone.BATTLEFIELD, effect, false);
|
||||||
public KiraGreatGlassSpinnerAbility() {
|
|
||||||
super(Zone.BATTLEFIELD, new CounterTargetEffect(), false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public KiraGreatGlassSpinnerAbility(final KiraGreatGlassSpinnerAbility ability) {
|
public KiraGreatGlassSpinnerAbility(final KiraGreatGlassSpinnerAbility ability) {
|
||||||
super(ability);
|
super(ability);
|
||||||
turnUsed = ability.turnUsed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -110,20 +111,15 @@ class KiraGreatGlassSpinnerAbility extends TriggeredAbilityImpl {
|
||||||
@Override
|
@Override
|
||||||
public boolean checkTrigger(GameEvent event, Game game) {
|
public boolean checkTrigger(GameEvent event, Game game) {
|
||||||
if (event.getTargetId().equals(this.getSourceId())) {
|
if (event.getTargetId().equals(this.getSourceId())) {
|
||||||
Integer turn = turnUsed.get(event.getTargetId());
|
Permanent permanent = game.getPermanent(event.getTargetId());
|
||||||
if (turn == null || turn < game.getTurnNum()) {
|
if (permanent.getCardType().contains(CardType.CREATURE)) {
|
||||||
this.getTargets().clear();
|
CreatureWasTargetedThisTurnWatcher watcher = (CreatureWasTargetedThisTurnWatcher) game.getState().getWatchers().get("CreatureWasTargetedThisTurn");
|
||||||
TargetStackObject target = new TargetStackObject();
|
if (watcher != null && watcher.notMoreThanOnceTargetedThisTurn(permanent, game)) {
|
||||||
target.add(event.getSourceId(), game);
|
for (Effect effect : getEffects()) {
|
||||||
this.addTarget(target);
|
effect.setTargetPointer(new FixedTarget(event.getSourceId()));
|
||||||
if (turnUsed.containsKey(event.getTargetId())) {
|
}
|
||||||
turnUsed.remove(event.getTargetId());
|
return true;
|
||||||
turnUsed.put(event.getTargetId(), game.getTurnNum());
|
|
||||||
} else {
|
|
||||||
turnUsed.put(event.getTargetId(), game.getTurnNum());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue