mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 21:12:04 -08:00
phantom effect code duplication
This commit is contained in:
parent
1f9b51d833
commit
b154bf58f9
8 changed files with 121 additions and 560 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue