refactor: replacement effects don't use apply method now (#11484)

This commit is contained in:
xenohedron 2023-11-28 02:17:28 -05:00 committed by GitHub
parent 8ad3238109
commit 05e2cf11e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
275 changed files with 171 additions and 1545 deletions

View file

@ -92,11 +92,6 @@ class CantHaveMoreThanAmountCountersSourceEffect extends ReplacementEffectImpl {
&& permanent.getCounters(game).getCount(this.counterType) == this.amount;
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public CantHaveMoreThanAmountCountersSourceEffect copy() {
return new CantHaveMoreThanAmountCountersSourceEffect(this);

View file

@ -108,11 +108,6 @@ class PutIntoGraveFromAnywhereEffect extends ReplacementEffectImpl {
return false;
}
@Override
public boolean apply(Game game, Ability source) {
return false;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
if (optional) {
@ -149,4 +144,4 @@ class PutIntoGraveFromAnywhereEffect extends ReplacementEffectImpl {
return new PutIntoGraveFromAnywhereEffect(this);
}
}
}

View file

@ -97,11 +97,6 @@ public class ConditionalPreventionEffect extends PreventionEffectImpl {
return false;
}
@Override
public boolean apply(Game game, Ability source) {
return false;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return effect.checksEventType(event, game)

View file

@ -87,11 +87,6 @@ public class ConditionalReplacementEffect extends ReplacementEffectImpl {
return true;
}
@Override
public boolean apply(Game game, Ability source) {
return false;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return effect.checksEventType(event, game)

View file

@ -43,11 +43,6 @@ public class AsTurnedFaceUpEffect extends ReplacementEffectImpl {
return event.getTargetId().equals(source.getSourceId());
}
@Override
public boolean apply(Game game, Ability source) {
return false;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
if (optional) {

View file

@ -48,11 +48,6 @@ public class AuraReplacementEffect extends ReplacementEffectImpl {
return new AuraReplacementEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Zone fromZone = ((ZoneChangeEvent) event).getFromZone();

View file

@ -34,11 +34,6 @@ public class PhantomPreventionEffect extends PreventionEffectImpl {
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);

View file

@ -36,11 +36,6 @@ public class PreventDamageAndRemoveCountersEffect extends PreventionEffectImpl {
return new PreventDamageAndRemoveCountersEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
int damage = event.getAmount();

View file

@ -20,15 +20,15 @@ public abstract class PreventionEffectImpl extends ReplacementEffectImpl impleme
protected final boolean onlyCombat;
protected boolean consumable;
public PreventionEffectImpl(Duration duration) {
protected PreventionEffectImpl(Duration duration) {
this(duration, Integer.MAX_VALUE, false);
}
public PreventionEffectImpl(Duration duration, int amountToPrevent, boolean onlyCombat) {
protected PreventionEffectImpl(Duration duration, int amountToPrevent, boolean onlyCombat) {
this(duration, amountToPrevent, onlyCombat, true);
}
public PreventionEffectImpl(Duration duration, int amountToPrevent, boolean onlyCombat, boolean consumable) {
protected PreventionEffectImpl(Duration duration, int amountToPrevent, boolean onlyCombat, boolean consumable) {
this(duration, amountToPrevent, onlyCombat, consumable, null);
}
@ -40,7 +40,7 @@ public abstract class PreventionEffectImpl extends ReplacementEffectImpl impleme
* @param amountToPreventDynamic if set, on init amountToPrevent is set to
* calculated value of amountToPreventDynamic
*/
public PreventionEffectImpl(Duration duration, int amountToPrevent, boolean onlyCombat, boolean consumable, DynamicValue amountToPreventDynamic) {
protected PreventionEffectImpl(Duration duration, int amountToPrevent, boolean onlyCombat, boolean consumable, DynamicValue amountToPreventDynamic) {
super(duration, Outcome.PreventDamage);
this.effectType = EffectType.PREVENTION;
this.amountToPrevent = amountToPrevent;
@ -65,12 +65,6 @@ public abstract class PreventionEffectImpl extends ReplacementEffectImpl impleme
}
}
@Override
public boolean apply(Game game, Ability source) {
// not used for prevention effect
return true;
}
protected PreventionEffectData preventDamageAction(GameEvent event, Ability source, Game game) {
PreventionEffectData preventionData = game.preventDamage(event, source, game, amountToPrevent);
if (!preventionData.isError() && !preventionData.isReplaced()) {

View file

@ -1,4 +1,3 @@
package mage.abilities.effects;
import mage.abilities.Ability;
@ -24,7 +23,7 @@ public abstract class ReplacementEffectImpl extends ContinuousEffectImpl impleme
// continuous effects from any other source that would affect it.
protected boolean selfScope;
public ReplacementEffectImpl(Duration duration, Outcome outcome) {
protected ReplacementEffectImpl(Duration duration, Outcome outcome) {
this(duration, outcome, true);
}
@ -34,7 +33,7 @@ public abstract class ReplacementEffectImpl extends ContinuousEffectImpl impleme
* @param selfScope - is only relevant while permanents entering the
* battlefield events
*/
public ReplacementEffectImpl(Duration duration, Outcome outcome, boolean selfScope) {
protected ReplacementEffectImpl(Duration duration, Outcome outcome, boolean selfScope) {
super(duration, outcome);
this.effectType = EffectType.REPLACEMENT;
this.selfScope = selfScope;
@ -51,8 +50,8 @@ public abstract class ReplacementEffectImpl extends ContinuousEffectImpl impleme
}
@Override
public boolean apply(Game game, Ability source) {
throw new UnsupportedOperationException("Not used for replacemnt effect.");
public final boolean apply(Game game, Ability source) {
throw new UnsupportedOperationException("Wrong code usage: apply() not used for replacement effect.");
}
}

View file

@ -74,11 +74,6 @@ public class DevourEffect extends ReplacementEffectImpl {
return false;
}
@Override
public boolean apply(Game game, Ability source) {
return false;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent creature = ((EntersTheBattlefieldEvent) event).getTarget();

View file

@ -39,11 +39,6 @@ public class EnterBattlefieldPayCostOrPutGraveyardEffect extends ReplacementEffe
return new EnterBattlefieldPayCostOrPutGraveyardEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Player player = game.getPlayer(source.getControllerId());

View file

@ -78,11 +78,6 @@ public class PreventAllDamageToAllEffect extends PreventionEffectImpl {
return new PreventAllDamageToAllEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (super.applies(event, source, game)) {

View file

@ -27,11 +27,6 @@ public class PreventAllDamageToPlayersEffect extends PreventionEffectImpl {
return new PreventAllDamageToPlayersEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (super.applies(event, source, game) && event.getType() == GameEvent.EventType.DAMAGE_PLAYER) {

View file

@ -37,11 +37,6 @@ public class PreventDamageToSourceEffect extends PreventionEffectImpl {
}
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
return super.applies(event, source, game) && event.getTargetId().equals(source.getSourceId());

View file

@ -72,11 +72,6 @@ public class PreventDamageToTargetMultiAmountEffect extends PreventionEffectImpl
}
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
int targetAmount = targetAmountMap.get(event.getTargetId());

View file

@ -31,19 +31,6 @@ public class RegenerateSourceEffect extends ReplacementEffectImpl {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
//20110204 - 701.11
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null
&& permanent.regenerate(source, game)) {
this.used = true;
discard();
return true;
}
return false;
}
@Override
public void init(Ability source, Game game) {
super.init(source, game);
@ -58,7 +45,14 @@ public class RegenerateSourceEffect extends ReplacementEffectImpl {
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
return apply(game, source);
//20110204 - 701.11
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null && permanent.regenerate(source, game)) {
this.used = true;
discard();
return true;
}
return false;
}
@Override

View file

@ -3,6 +3,7 @@ package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.abilities.common.delayed.ReflexiveTriggeredAbility;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.target.targetpointer.FixedTarget;
/**
@ -34,8 +35,8 @@ public class RegenerateSourceWithReflexiveEffect extends RegenerateSourceEffect
}
@Override
public boolean apply(Game game, Ability source) {
if (super.apply(game, source)) {
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
if (super.replaceEvent(event, source, game)) {
if (this.setReflexiveTarget) {
reflexive.getEffects().setTargetPointer(
new FixedTarget(targetPointer.getFirst(game, source), game)

View file

@ -23,17 +23,6 @@ public class RegenerateTargetEffect extends ReplacementEffectImpl {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
//20110204 - 701.11
Permanent permanent = game.getPermanent(targetPointer.getFirst(game, source));
if (permanent != null && permanent.regenerate(source, game)) {
this.used = true;
return true;
}
return false;
}
@Override
public void init(Ability source, Game game) {
super.init(source, game);
@ -47,7 +36,13 @@ public class RegenerateTargetEffect extends ReplacementEffectImpl {
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
return apply(game, source);
//20110204 - 701.11
Permanent permanent = game.getPermanent(targetPointer.getFirst(game, source));
if (permanent != null && permanent.regenerate(source, game)) {
this.used = true;
return true;
}
return false;
}
@Override

View file

@ -27,11 +27,6 @@ public class SkipCombatStepEffect extends ReplacementEffectImpl {
return new SkipCombatStepEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
return true;

View file

@ -57,11 +57,6 @@ public class SkipDrawStepEffect extends ReplacementEffectImpl {
return new SkipDrawStepEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
return true;
@ -76,4 +71,4 @@ public class SkipDrawStepEffect extends ReplacementEffectImpl {
public boolean applies(GameEvent event, Ability source, Game game) {
return event.getPlayerId().equals(source.getControllerId());
}
}
}

View file

@ -27,11 +27,6 @@ public class SkipNextDrawStepTargetEffect extends ReplacementEffectImpl {
return new SkipNextDrawStepTargetEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
return true;
@ -46,4 +41,4 @@ public class SkipNextDrawStepTargetEffect extends ReplacementEffectImpl {
public boolean applies(GameEvent event, Ability source, Game game) {
return event.getPlayerId().equals(source.getFirstTarget());
}
}
}

View file

@ -32,11 +32,6 @@ public class AssignNoCombatDamageSourceEffect extends ReplacementEffectImpl {
return new AssignNoCombatDamageSourceEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
return true;

View file

@ -32,11 +32,6 @@ public class AssignNoCombatDamageTargetEffect extends ReplacementEffectImpl {
return new AssignNoCombatDamageTargetEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
return true;

View file

@ -48,11 +48,6 @@ public class CommanderManaReplacementEffect extends ReplacementEffectImpl {
return new CommanderManaReplacementEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Mana mana = ((ManaEvent) event).getMana();

View file

@ -85,11 +85,6 @@ public class CommanderReplacementEffect extends ReplacementEffectImpl {
return new CommanderReplacementEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public void init(Ability source, Game game) {
super.init(source, game);

View file

@ -35,11 +35,6 @@ public class DealtDamageToCreatureBySourceDies extends ReplacementEffectImpl {
return new DealtDamageToCreatureBySourceDies(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
((ZoneChangeEvent) event).setToZone(Zone.EXILED);

View file

@ -36,11 +36,6 @@ public class DiesReplacementEffect extends ReplacementEffectImpl {
return new DiesReplacementEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent permanent = ((ZoneChangeEvent) event).getTarget();

View file

@ -27,11 +27,6 @@ public class GainPlusOneLifeReplacementEffect extends ReplacementEffectImpl {
return new GainPlusOneLifeReplacementEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
event.setAmount(CardUtil.overflowInc(event.getAmount(), 1));

View file

@ -57,11 +57,6 @@ public class ModifyCountersAddedEffect extends ReplacementEffectImpl {
return permanent != null && filter.match(permanent, source.getControllerId(), source, game);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public ModifyCountersAddedEffect copy() {
return new ModifyCountersAddedEffect(this);

View file

@ -49,9 +49,4 @@ public class FinalityCounterEffect extends ReplacementEffectImpl {
Permanent permanent = game.getPermanent(event.getTargetId());
return permanent != null && permanent.getCounters(game).getCount(CounterType.FINALITY) > 0;
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
}

View file

@ -204,11 +204,6 @@ class BuybackEffect extends ReplacementEffectImpl {
return false;
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Card card = game.getCard(source.getSourceId());

View file

@ -57,11 +57,6 @@ class DredgeEffect extends ReplacementEffectImpl {
return new DredgeEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Card sourceCard = game.getCard(source.getSourceId());

View file

@ -77,11 +77,6 @@ class EnlistEffect extends ReplacementEffectImpl {
return event.getSourceId().equals(source.getSourceId());
}
@Override
public boolean apply(Game game, Ability source) {
return false;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent creature = game.getPermanent(event.getSourceId());

View file

@ -98,11 +98,6 @@ class ExertReplacementEffect extends ReplacementEffectImpl {
return event.getSourceId().equals(source.getSourceId());
}
@Override
public boolean apply(Game game, Ability source) {
return false;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent creature = game.getPermanent(event.getSourceId());

View file

@ -200,11 +200,6 @@ class FlashbackReplacementEffect extends ReplacementEffectImpl {
return new FlashbackReplacementEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Player controller = game.getPlayer(source.getControllerId());

View file

@ -102,11 +102,6 @@ class JumpStartReplacementEffect extends ReplacementEffectImpl {
return new JumpStartReplacementEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Player controller = game.getPlayer(source.getControllerId());

View file

@ -119,11 +119,6 @@ class MadnessReplacementEffect extends ReplacementEffectImpl {
return new MadnessReplacementEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Player controller = game.getPlayer(source.getControllerId());

View file

@ -60,11 +60,6 @@ class RiotReplacementEffect extends ReplacementEffectImpl {
return event.getTargetId().equals(source.getSourceId());
}
@Override
public boolean apply(Game game, Ability source) {
return false;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent creature = ((EntersTheBattlefieldEvent) event).getTarget();
@ -90,4 +85,4 @@ class RiotReplacementEffect extends ReplacementEffectImpl {
return new RiotReplacementEffect(this);
}
}
}

View file

@ -75,11 +75,6 @@ class TotemArmorEffect extends ReplacementEffectImpl {
return sourcePermanent != null && event.getTargetId().equals(sourcePermanent.getAttachedTo());
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public TotemArmorEffect copy() {
return new TotemArmorEffect(this);

View file

@ -63,11 +63,6 @@ class UnleashReplacementEffect extends ReplacementEffectImpl {
return event.getTargetId().equals(source.getSourceId());
}
@Override
public boolean apply(Game game, Ability source) {
return false;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent creature = ((EntersTheBattlefieldEvent) event).getTarget();

View file

@ -52,11 +52,6 @@ class AjaniSteadfastPreventEffect extends PreventionEffectImpl {
return false;
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == GameEvent.EventType.DAMAGE_PLAYER

View file

@ -95,11 +95,6 @@ class JayaBallardReplacementEffect extends ReplacementEffectImpl {
return new JayaBallardReplacementEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Player controller = game.getPlayer(source.getControllerId());

View file

@ -70,11 +70,6 @@ class SerraTheBenevolentEmblemEffect extends ReplacementEffectImpl {
return false;
}
@Override
public boolean apply(Game game, Ability source) {
return false;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
return false;