phantom effect code duplication

This commit is contained in:
ingmargoudt 2017-03-22 10:24:50 +01:00
parent 1f9b51d833
commit b154bf58f9
8 changed files with 121 additions and 560 deletions

View file

@ -27,35 +27,28 @@
*/
package mage.cards.p;
import java.util.UUID;
import mage.MageInt;
import mage.ObjectColor;
import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.PreventionEffectImpl;
import mage.abilities.effects.PhantomPreventionEffect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.abilities.keyword.ProtectionAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import mage.counters.CounterType;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.game.turn.Step;
import java.util.UUID;
/**
*
* @author LevelX2
*/
public class PhantomCentaur extends CardImpl {
public PhantomCentaur(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{2}{G}{G}");
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{G}{G}");
this.subtype.add("Centaur");
this.subtype.add("Spirit");
@ -69,7 +62,7 @@ public class PhantomCentaur extends CardImpl {
this.addAbility(new EntersBattlefieldAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance(3)), "with three +1/+1 counters on it"));
// If damage would be dealt to Phantom Centaur, prevent that damage. Remove a +1/+1 counter from Phantom Centaur.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PhantomCentaurPreventionEffect()));
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PhantomPreventionEffect()));
}
public PhantomCentaur(final PhantomCentaur card) {
@ -82,70 +75,3 @@ public class PhantomCentaur extends CardImpl {
}
}
class PhantomCentaurPreventionEffect extends PreventionEffectImpl {
// remember turn and phase step to check if counter in this step was already removed
private int turn = 0;
private Step combatPhaseStep = null;
public PhantomCentaurPreventionEffect() {
super(Duration.WhileOnBattlefield);
staticText = "If damage would be dealt to {this}, prevent that damage. Remove a +1/+1 counter from {this}";
}
public PhantomCentaurPreventionEffect(final PhantomCentaurPreventionEffect effect) {
super(effect);
this.turn = effect.turn;
this.combatPhaseStep = effect.combatPhaseStep;
}
@Override
public PhantomCentaurPreventionEffect copy() {
return new PhantomCentaurPreventionEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
preventDamageAction(event, source, game);
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
boolean removeCounter = true;
// check if in the same combat damage step already a counter was removed
if (game.getTurn().getPhase().getStep().getType().equals(PhaseStep.COMBAT_DAMAGE)) {
if (game.getTurnNum() == turn
&& game.getTurn().getStep().equals(combatPhaseStep)) {
removeCounter = false;
} else {
turn = game.getTurnNum();
combatPhaseStep = game.getTurn().getStep();
}
}
if(removeCounter && permanent.getCounters(game).containsKey(CounterType.P1P1)) {
StringBuilder sb = new StringBuilder(permanent.getName()).append(": ");
permanent.removeCounters(CounterType.P1P1.createInstance(), game);
sb.append("Removed a +1/+1 counter ");
game.informPlayers(sb.toString());
}
}
return false;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (super.applies(event, source, game)) {
if (event.getTargetId().equals(source.getSourceId())) {
return true;
}
}
return false;
}
}

View file

@ -27,34 +27,27 @@
*/
package mage.cards.p;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.PreventionEffectImpl;
import mage.abilities.effects.PhantomPreventionEffect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.abilities.keyword.FlyingAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import mage.counters.CounterType;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.game.turn.Step;
import java.util.UUID;
/**
*
* @author emerald000
*/
public class PhantomFlock extends CardImpl {
public PhantomFlock(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{3}{W}{W}");
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{3}{W}{W}");
this.subtype.add("Bird");
this.subtype.add("Soldier");
this.subtype.add("Spirit");
@ -63,12 +56,12 @@ public class PhantomFlock extends CardImpl {
// Flying
this.addAbility(FlyingAbility.getInstance());
// Phantom Flock enters the battlefield with three +1/+1 counters on it.
this.addAbility(new EntersBattlefieldAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance(3)), "with three +1/+1 counters on it"));
// If damage would be dealt to Phantom Flock, prevent that damage. Remove a +1/+1 counter from Phantom Flock.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PhantomFlockPreventionEffect()));
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PhantomPreventionEffect()));
}
public PhantomFlock(final PhantomFlock card) {
@ -79,72 +72,4 @@ public class PhantomFlock extends CardImpl {
public PhantomFlock copy() {
return new PhantomFlock(this);
}
}
class PhantomFlockPreventionEffect extends PreventionEffectImpl {
// remember turn and phase step to check if counter in this step was already removed
private int turn = 0;
private Step combatPhaseStep = null;
PhantomFlockPreventionEffect() {
super(Duration.WhileOnBattlefield);
staticText = "If damage would be dealt to {this}, prevent that damage. Remove a +1/+1 counter from {this}";
}
PhantomFlockPreventionEffect(final PhantomFlockPreventionEffect effect) {
super(effect);
this.turn = effect.turn;
this.combatPhaseStep = effect.combatPhaseStep;
}
@Override
public PhantomFlockPreventionEffect copy() {
return new PhantomFlockPreventionEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
preventDamageAction(event, source, game);
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
boolean removeCounter = true;
// check if in the same combat damage step already a counter was removed
if (game.getTurn().getPhase().getStep().getType().equals(PhaseStep.COMBAT_DAMAGE)) {
if (game.getTurnNum() == turn
&& game.getTurn().getStep().equals(combatPhaseStep)) {
removeCounter = false;
} else {
turn = game.getTurnNum();
combatPhaseStep = game.getTurn().getStep();
}
}
if(removeCounter && permanent.getCounters(game).containsKey(CounterType.P1P1)) {
StringBuilder sb = new StringBuilder(permanent.getName()).append(": ");
permanent.removeCounters(CounterType.P1P1.createInstance(), game);
sb.append("Removed a +1/+1 counter ");
game.informPlayers(sb.toString());
}
}
return false;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (super.applies(event, source, game)) {
if (event.getTargetId().equals(source.getSourceId())) {
return true;
}
}
return false;
}
}
}

View file

@ -27,27 +27,21 @@
*/
package mage.cards.p;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldAbility;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.effects.PreventionEffectImpl;
import mage.abilities.effects.PhantomPreventionEffect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.abilities.keyword.TrampleAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import mage.counters.CounterType;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.game.turn.Step;
import java.util.UUID;
/**
*
@ -68,7 +62,7 @@ public class PhantomNantuko extends CardImpl {
// Phantom Nantuko enters the battlefield with two +1/+1 counters on it.
this.addAbility(new EntersBattlefieldAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance(2), true), "with two +1/+1 counters on it"));
// If damage would be dealt to Phantom Nantuko, prevent that damage. Remove a +1/+1 counter from Phantom Nantuko.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PhantomNantukoPreventionEffect()));
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PhantomPreventionEffect()));
// {tap}: Put a +1/+1 counter on Phantom Nantuko.
this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new AddCountersSourceEffect(CounterType.P1P1.createInstance()), new TapSourceCost()));
}
@ -83,70 +77,3 @@ public class PhantomNantuko extends CardImpl {
}
}
class PhantomNantukoPreventionEffect extends PreventionEffectImpl {
// remember turn and phase step to check if counter in this step was already removed
private int turn = 0;
private Step combatPhaseStep = null;
public PhantomNantukoPreventionEffect() {
super(Duration.WhileOnBattlefield);
staticText = "If damage would be dealt to {this}, prevent that damage. Remove a +1/+1 counter from {this}";
}
public PhantomNantukoPreventionEffect(final PhantomNantukoPreventionEffect effect) {
super(effect);
this.turn = effect.turn;
this.combatPhaseStep = effect.combatPhaseStep;
}
@Override
public PhantomNantukoPreventionEffect copy() {
return new PhantomNantukoPreventionEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
preventDamageAction(event, source, game);
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
boolean removeCounter = true;
// check if in the same combat damage step already a counter was removed
if (game.getTurn().getPhase().getStep().getType() == PhaseStep.COMBAT_DAMAGE) {
if (game.getTurnNum() == turn
&& game.getTurn().getStep().equals(combatPhaseStep)) {
removeCounter = false;
} else {
turn = game.getTurnNum();
combatPhaseStep = game.getTurn().getStep();
}
}
if(removeCounter && permanent.getCounters(game).containsKey(CounterType.P1P1)) {
StringBuilder sb = new StringBuilder(permanent.getName()).append(": ");
permanent.removeCounters(CounterType.P1P1.createInstance(), game);
sb.append("Removed a +1/+1 counter ");
game.informPlayers(sb.toString());
}
}
return false;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (super.applies(event, source, game)) {
if (event.getTargetId().equals(source.getSourceId())) {
return true;
}
}
return false;
}
}

View file

@ -27,35 +27,28 @@
*/
package mage.cards.p;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.DealsDamageGainLifeSourceTriggeredAbility;
import mage.abilities.common.EntersBattlefieldAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.PreventionEffectImpl;
import mage.abilities.effects.PhantomPreventionEffect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.abilities.keyword.TrampleAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import mage.counters.CounterType;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.game.turn.Step;
import java.util.UUID;
/**
*
* @author fireshoes
*/
public class PhantomNishoba extends CardImpl {
public PhantomNishoba(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{5}{G}{W}");
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{5}{G}{W}");
this.subtype.add("Cat");
this.subtype.add("Beast");
this.subtype.add("Spirit");
@ -64,15 +57,15 @@ public class PhantomNishoba extends CardImpl {
// Trample
this.addAbility(TrampleAbility.getInstance());
// Phantom Nishoba enters the battlefield with seven +1/+1 counters on it.
this.addAbility(new EntersBattlefieldAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance(7), true), "with seven +1/+1 counters on it"));
// Whenever Phantom Nishoba deals damage, you gain that much life.
this.addAbility(new DealsDamageGainLifeSourceTriggeredAbility());
// If damage would be dealt to Phantom Nishoba, prevent that damage. Remove a +1/+1 counter from Phantom Nishoba.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PhantomNishobaPreventionEffect()));
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PhantomPreventionEffect()));
}
public PhantomNishoba(final PhantomNishoba card) {
@ -83,72 +76,4 @@ public class PhantomNishoba extends CardImpl {
public PhantomNishoba copy() {
return new PhantomNishoba(this);
}
}
class PhantomNishobaPreventionEffect extends PreventionEffectImpl {
// remember turn and phase step to check if counter in this step was already removed
private int turn = 0;
private Step combatPhaseStep = null;
public PhantomNishobaPreventionEffect() {
super(Duration.WhileOnBattlefield);
staticText = "If damage would be dealt to {this}, prevent that damage. Remove a +1/+1 counter from {this}";
}
public PhantomNishobaPreventionEffect(final PhantomNishobaPreventionEffect effect) {
super(effect);
this.turn = effect.turn;
this.combatPhaseStep = effect.combatPhaseStep;
}
@Override
public PhantomNishobaPreventionEffect copy() {
return new PhantomNishobaPreventionEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
preventDamageAction(event, source, game);
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
boolean removeCounter = true;
// check if in the same combat damage step already a counter was removed
if (game.getTurn().getPhase().getStep().getType().equals(PhaseStep.COMBAT_DAMAGE)) {
if (game.getTurnNum() == turn
&& game.getTurn().getStep().equals(combatPhaseStep)) {
removeCounter = false;
} else {
turn = game.getTurnNum();
combatPhaseStep = game.getTurn().getStep();
}
}
if(removeCounter && permanent.getCounters(game).containsKey(CounterType.P1P1)) {
StringBuilder sb = new StringBuilder(permanent.getName()).append(": ");
permanent.removeCounters(CounterType.P1P1.createInstance(), game);
sb.append("Removed a +1/+1 counter ");
game.informPlayers(sb.toString());
}
}
return false;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (super.applies(event, source, game)) {
if (event.getTargetId().equals(source.getSourceId())) {
return true;
}
}
return false;
}
}

View file

@ -27,24 +27,18 @@
*/
package mage.cards.p;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.PreventionEffectImpl;
import mage.abilities.effects.PhantomPreventionEffect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import mage.counters.CounterType;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.game.turn.Step;
import java.util.UUID;
/**
*
@ -65,7 +59,7 @@ public class PhantomNomad extends CardImpl {
"two +1/+1 counters on it"));
// If damage would be dealt to Phantom Nomad, prevent that damage. Remove a +1/+1 counter from Phantom Nomad.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PhantomNomadPreventionEffect()));
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PhantomPreventionEffect()));
}
@ -78,72 +72,4 @@ public class PhantomNomad extends CardImpl {
public PhantomNomad copy() {
return new PhantomNomad(this);
}
}
class PhantomNomadPreventionEffect extends PreventionEffectImpl {
// remember turn and phase step to check if counter in this step was already removed
private int turn = 0;
private Step combatPhaseStep = null;
public PhantomNomadPreventionEffect() {
super(Duration.WhileOnBattlefield);
staticText = "If damage would be dealt to {this}, prevent that damage. Remove a +1/+1 counter from {this}";
}
public PhantomNomadPreventionEffect(final PhantomNomadPreventionEffect effect) {
super(effect);
this.turn = effect.turn;
this.combatPhaseStep = effect.combatPhaseStep;
}
@Override
public PhantomNomadPreventionEffect copy() {
return new PhantomNomadPreventionEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
preventDamageAction(event, source, game);
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
boolean removeCounter = true;
// check if in the same combat damage step already a counter was removed
if (game.getTurn().getPhase().getStep().getType().equals(PhaseStep.COMBAT_DAMAGE)) {
if (game.getTurnNum() == turn
&& game.getTurn().getStep().equals(combatPhaseStep)) {
removeCounter = false;
} else {
turn = game.getTurnNum();
combatPhaseStep = game.getTurn().getStep();
}
}
if(removeCounter && permanent.getCounters(game).containsKey(CounterType.P1P1)) {
StringBuilder sb = new StringBuilder(permanent.getName()).append(": ");
permanent.removeCounters(CounterType.P1P1.createInstance(), game);
sb.append("Removed a +1/+1 counter ");
game.informPlayers(sb.toString());
}
}
return false;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (super.applies(event, source, game)) {
if (event.getTargetId().equals(source.getSourceId())) {
return true;
}
}
return false;
}
}
}

View file

@ -27,25 +27,18 @@
*/
package mage.cards.p;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.PreventionEffectImpl;
import mage.abilities.effects.PhantomPreventionEffect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import mage.counters.CounterType;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.game.turn.Step;
import java.util.UUID;
/**
* @author Temba
@ -63,7 +56,7 @@ public class PhantomTiger extends CardImpl {
this.addAbility(new EntersBattlefieldAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance(2)), "with two +1/+1 counters on it"));
// If damage would be dealt to Phantom Tiger, prevent that damage. Remove a +1/+1 counter from Phantom Tiger.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PhantomTigerPreventionEffect()));
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PhantomPreventionEffect()));
}
public PhantomTiger(final PhantomTiger card) {
@ -74,72 +67,4 @@ public class PhantomTiger extends CardImpl {
public PhantomTiger copy() {
return new PhantomTiger(this);
}
}
class PhantomTigerPreventionEffect extends PreventionEffectImpl {
// remember turn and phase step to check if counter in this step was already removed
private int turn = 0;
private Step combatPhaseStep = null;
public PhantomTigerPreventionEffect() {
super(Duration.WhileOnBattlefield);
staticText = "If damage would be dealt to {this}, prevent that damage. Remove a +1/+1 counter from {this}";
}
public PhantomTigerPreventionEffect(final PhantomTigerPreventionEffect effect) {
super(effect);
this.turn = effect.turn;
this.combatPhaseStep = effect.combatPhaseStep;
}
@Override
public PhantomTigerPreventionEffect copy() {
return new PhantomTigerPreventionEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
preventDamageAction(event, source, game);
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
boolean removeCounter = true;
// check if in the same combat damage step already a counter was removed
if (game.getTurn().getPhase().getStep().getType() == PhaseStep.COMBAT_DAMAGE) {
if (game.getTurnNum() == turn
&& game.getTurn().getStep().equals(combatPhaseStep)) {
removeCounter = false;
} else {
turn = game.getTurnNum();
combatPhaseStep = game.getTurn().getStep();
}
}
if (removeCounter && permanent.getCounters(game).getCount(CounterType.P1P1) > 0) {
StringBuilder sb = new StringBuilder(permanent.getName()).append(": ");
permanent.removeCounters(CounterType.P1P1.createInstance(), game);
sb.append("Removed a +1/+1 counter ");
game.informPlayers(sb.toString());
}
}
return false;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (super.applies(event, source, game)) {
if (event.getTargetId().equals(source.getSourceId())) {
return true;
}
}
return false;
}
}
}

View file

@ -27,24 +27,18 @@
*/
package mage.cards.p;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.PreventionEffectImpl;
import mage.abilities.effects.PhantomPreventionEffect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import mage.counters.CounterType;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.game.turn.Step;
import java.util.UUID;
/**
*
@ -65,7 +59,7 @@ public class PhantomWurm extends CardImpl {
"with four +1/+1 counters on it"));
// If damage would be dealt to Phantom Wurm, prevent that damage. Remove a +1/+1 counter from Phantom Wurm.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PhantomWurmPreventionEffect()));
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PhantomPreventionEffect()));
}
public PhantomWurm(final PhantomWurm card) {
@ -76,72 +70,4 @@ public class PhantomWurm extends CardImpl {
public PhantomWurm copy() {
return new PhantomWurm(this);
}
}
class PhantomWurmPreventionEffect extends PreventionEffectImpl {
// remember turn and phase step to check if counter in this step was already removed
private int turn = 0;
private Step combatPhaseStep = null;
public PhantomWurmPreventionEffect() {
super(Duration.WhileOnBattlefield);
staticText = "If damage would be dealt to {this}, prevent that damage. Remove a +1/+1 counter from {this}";
}
public PhantomWurmPreventionEffect(final PhantomWurmPreventionEffect effect) {
super(effect);
this.turn = effect.turn;
this.combatPhaseStep = effect.combatPhaseStep;
}
@Override
public PhantomWurmPreventionEffect copy() {
return new PhantomWurmPreventionEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
preventDamageAction(event, source, game);
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
boolean removeCounter = true;
// check if in the same combat damage step already a counter was removed
if (game.getTurn().getPhase().getStep().getType() == PhaseStep.COMBAT_DAMAGE) {
if (game.getTurnNum() == turn
&& game.getTurn().getStep().equals(combatPhaseStep)) {
removeCounter = false;
} else {
turn = game.getTurnNum();
combatPhaseStep = game.getTurn().getStep();
}
}
if(removeCounter && permanent.getCounters(game).containsKey(CounterType.P1P1)) {
StringBuilder sb = new StringBuilder(permanent.getName()).append(": ");
permanent.removeCounters(CounterType.P1P1.createInstance(), game);
sb.append("Removed a +1/+1 counter ");
game.informPlayers(sb.toString());
}
}
return false;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (super.applies(event, source, game)) {
if (event.getTargetId().equals(source.getSourceId())) {
return true;
}
}
return false;
}
}
}

View file

@ -0,0 +1,81 @@
package mage.abilities.effects;
import mage.abilities.Ability;
import mage.constants.Duration;
import mage.constants.PhaseStep;
import mage.counters.CounterType;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.game.turn.Step;
/**
* Created by IGOUDT on 22-3-2017.
*/
public class PhantomPreventionEffect extends PreventionEffectImpl {
// remember turn and phase step to check if counter in this step was already removed
private int turn = 0;
private Step combatPhaseStep = null;
public PhantomPreventionEffect() {
super(Duration.WhileOnBattlefield);
staticText = "If damage would be dealt to {this}, prevent that damage. Remove a +1/+1 counter from {this}";
}
public PhantomPreventionEffect(final PhantomPreventionEffect effect) {
super(effect);
this.turn = effect.turn;
this.combatPhaseStep = effect.combatPhaseStep;
}
@Override
public PhantomPreventionEffect copy() {
return new PhantomPreventionEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
preventDamageAction(event, source, game);
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
boolean removeCounter = true;
// check if in the same combat damage step already a counter was removed
if (game.getTurn().getPhase().getStep().getType() == PhaseStep.COMBAT_DAMAGE) {
if (game.getTurnNum() == turn
&& game.getTurn().getStep().equals(combatPhaseStep)) {
removeCounter = false;
} else {
turn = game.getTurnNum();
combatPhaseStep = game.getTurn().getStep();
}
}
if(removeCounter && permanent.getCounters(game).containsKey(CounterType.P1P1)) {
StringBuilder sb = new StringBuilder(permanent.getName()).append(": ");
permanent.removeCounters(CounterType.P1P1.createInstance(), game);
sb.append("Removed a +1/+1 counter ");
game.informPlayers(sb.toString());
}
}
return false;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (super.applies(event, source, game)) {
if (event.getTargetId().equals(source.getSourceId())) {
return true;
}
}
return false;
}
}