mirror of
https://github.com/magefree/mage.git
synced 2025-12-26 05:22:02 -08:00
refactor: Cleanup CopyTargetStackObjectEffect (#12220)
* simplify constructors * rename class * adjust to accommodate any stack object * adjust all usages to main common class
This commit is contained in:
parent
b1b83dc5b8
commit
fa728eafb1
84 changed files with 204 additions and 265 deletions
|
|
@ -2,7 +2,7 @@ package mage.abilities.common.delayed;
|
|||
|
||||
import mage.abilities.DelayedTriggeredAbility;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.abilities.effects.common.CopyTargetSpellEffect;
|
||||
import mage.abilities.effects.common.CopyTargetStackObjectEffect;
|
||||
import mage.constants.Duration;
|
||||
import mage.filter.FilterSpell;
|
||||
import mage.filter.StaticFilters;
|
||||
|
|
@ -24,7 +24,7 @@ public class CopyNextSpellDelayedTriggeredAbility extends DelayedTriggeredAbilit
|
|||
}
|
||||
|
||||
public CopyNextSpellDelayedTriggeredAbility(FilterSpell filter) {
|
||||
this(filter, new CopyTargetSpellEffect(true), null);
|
||||
this(filter, new CopyTargetStackObjectEffect(true), null);
|
||||
}
|
||||
|
||||
public CopyNextSpellDelayedTriggeredAbility(FilterSpell filter, Effect effect, String rule) {
|
||||
|
|
|
|||
|
|
@ -1,47 +0,0 @@
|
|||
package mage.abilities.effects.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.constants.Outcome;
|
||||
import mage.game.Game;
|
||||
import mage.game.stack.StackAbility;
|
||||
|
||||
public class CopyTargetStackAbilityEffect extends OneShotEffect {
|
||||
|
||||
/**
|
||||
* Copy target (activated/triggered) ability on the stack, choosing new targets for the copy
|
||||
*/
|
||||
public CopyTargetStackAbilityEffect() {
|
||||
super(Outcome.Copy);
|
||||
}
|
||||
|
||||
protected CopyTargetStackAbilityEffect(final CopyTargetStackAbilityEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(getTargetPointer().getFirst(game, source));
|
||||
if (stackAbility == null) {
|
||||
return false;
|
||||
}
|
||||
stackAbility.createCopyOnStack(game, source, source.getControllerId(), true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CopyTargetStackAbilityEffect copy() {
|
||||
return new CopyTargetStackAbilityEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText(Mode mode) {
|
||||
if (staticText != null && !staticText.isEmpty()) {
|
||||
return staticText;
|
||||
}
|
||||
return "copy " + getTargetPointer().describeTargets(mode.getTargets(), "that spell")
|
||||
+ ". You may choose new targets for the copy";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -2,44 +2,35 @@ package mage.abilities.effects.common;
|
|||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.stack.Spell;
|
||||
import mage.game.stack.StackObject;
|
||||
import mage.util.functions.StackObjectCopyApplier;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class CopyTargetSpellEffect extends OneShotEffect {
|
||||
public class CopyTargetStackObjectEffect extends OneShotEffect {
|
||||
|
||||
private final boolean useController;
|
||||
private final boolean useLKI;
|
||||
private String copyThatSpellName = "that spell";
|
||||
private String objectName = "that spell";
|
||||
private final boolean chooseTargets;
|
||||
private final int amount;
|
||||
private final StackObjectCopyApplier applier;
|
||||
|
||||
public CopyTargetSpellEffect() {
|
||||
public CopyTargetStackObjectEffect() {
|
||||
this(false);
|
||||
}
|
||||
|
||||
public CopyTargetSpellEffect(boolean useLKI) {
|
||||
this(false, useLKI);
|
||||
public CopyTargetStackObjectEffect(boolean useLKI) {
|
||||
this(false, useLKI, true);
|
||||
}
|
||||
|
||||
public CopyTargetSpellEffect(boolean useController, boolean useLKI) {
|
||||
this(useController, useLKI, true);
|
||||
}
|
||||
|
||||
public CopyTargetSpellEffect(boolean useController, boolean useLKI, boolean chooseTargets) {
|
||||
this(useController, useLKI, chooseTargets, 1);
|
||||
}
|
||||
|
||||
public CopyTargetSpellEffect(boolean useController, boolean useLKI, boolean chooseTargets, int amount) {
|
||||
this(useController, useLKI, chooseTargets, amount, null);
|
||||
public CopyTargetStackObjectEffect(boolean useController, boolean useLKI, boolean chooseTargets) {
|
||||
this(useController, useLKI, chooseTargets, 1, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -50,8 +41,8 @@ public class CopyTargetSpellEffect extends OneShotEffect {
|
|||
* @param amount The amount of copies to create
|
||||
* @param applier An applier to apply to the newly created copies. Used to change copiable values of the copy, such as types or name
|
||||
*/
|
||||
public CopyTargetSpellEffect(boolean useController, boolean useLKI, boolean chooseTargets, int amount,
|
||||
StackObjectCopyApplier applier) {
|
||||
public CopyTargetStackObjectEffect(boolean useController, boolean useLKI, boolean chooseTargets, int amount,
|
||||
StackObjectCopyApplier applier) {
|
||||
super(Outcome.Copy);
|
||||
this.useController = useController;
|
||||
this.useLKI = useLKI;
|
||||
|
|
@ -60,34 +51,35 @@ public class CopyTargetSpellEffect extends OneShotEffect {
|
|||
this.applier = applier;
|
||||
}
|
||||
|
||||
protected CopyTargetSpellEffect(final CopyTargetSpellEffect effect) {
|
||||
protected CopyTargetStackObjectEffect(final CopyTargetStackObjectEffect effect) {
|
||||
super(effect);
|
||||
this.useLKI = effect.useLKI;
|
||||
this.useController = effect.useController;
|
||||
this.copyThatSpellName = effect.copyThatSpellName;
|
||||
this.objectName = effect.objectName;
|
||||
this.chooseTargets = effect.chooseTargets;
|
||||
this.amount = effect.amount;
|
||||
this.applier = effect.applier;
|
||||
}
|
||||
|
||||
public Effect withSpellName(String copyThatSpellName) {
|
||||
this.copyThatSpellName = copyThatSpellName;
|
||||
public CopyTargetStackObjectEffect withText(String objectName) {
|
||||
this.objectName = objectName;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Spell spell;
|
||||
StackObject stackObject;
|
||||
if (useLKI) {
|
||||
spell = game.getSpellOrLKIStack(getTargetPointer().getFirst(game, source));
|
||||
stackObject = game.getSpellOrLKIStack(getTargetPointer().getFirst(game, source));
|
||||
} else {
|
||||
spell = game.getStack().getSpell(getTargetPointer().getFirst(game, source));
|
||||
stackObject = game.getStack().getStackObject(getTargetPointer().getFirst(game, source));
|
||||
}
|
||||
if (spell == null) {
|
||||
spell = (Spell) game.getLastKnownInformation(getTargetPointer().getFirst(game, source), Zone.STACK);
|
||||
if (stackObject == null) {
|
||||
stackObject = (StackObject) game.getLastKnownInformation(getTargetPointer().getFirst(game, source), Zone.STACK);
|
||||
}
|
||||
if (spell != null) {
|
||||
spell.createCopyOnStack(game, source, useController ? spell.getControllerId() : source.getControllerId(),
|
||||
if (stackObject != null) {
|
||||
stackObject.createCopyOnStack(game, source,
|
||||
useController ? stackObject.getControllerId() : source.getControllerId(),
|
||||
chooseTargets, amount, applier);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -95,8 +87,8 @@ public class CopyTargetSpellEffect extends OneShotEffect {
|
|||
}
|
||||
|
||||
@Override
|
||||
public CopyTargetSpellEffect copy() {
|
||||
return new CopyTargetSpellEffect(this);
|
||||
public CopyTargetStackObjectEffect copy() {
|
||||
return new CopyTargetStackObjectEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -105,7 +97,7 @@ public class CopyTargetSpellEffect extends OneShotEffect {
|
|||
return staticText;
|
||||
}
|
||||
return "copy " +
|
||||
getTargetPointer().describeTargets(mode.getTargets(), copyThatSpellName) +
|
||||
getTargetPointer().describeTargets(mode.getTargets(), objectName) +
|
||||
(chooseTargets ? ". You may choose new targets for the copy" : "");
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@ package mage.game.command.emblems;
|
|||
|
||||
import mage.abilities.common.SpellCastControllerTriggeredAbility;
|
||||
import mage.abilities.costs.mana.GenericManaCost;
|
||||
import mage.abilities.effects.common.CopyTargetSpellEffect;
|
||||
import mage.abilities.effects.common.CopyTargetStackObjectEffect;
|
||||
import mage.abilities.effects.common.DoIfCostPaid;
|
||||
import mage.constants.SetTargetPointer;
|
||||
import mage.constants.Zone;
|
||||
|
|
@ -18,7 +18,7 @@ public final class RowanScholarOfSparksEmblem extends Emblem {
|
|||
public RowanScholarOfSparksEmblem() {
|
||||
super("Emblem Rowan");
|
||||
this.getAbilities().add(new SpellCastControllerTriggeredAbility(
|
||||
Zone.COMMAND, new DoIfCostPaid(new CopyTargetSpellEffect(true), new GenericManaCost(2)),
|
||||
Zone.COMMAND, new DoIfCostPaid(new CopyTargetStackObjectEffect(true), new GenericManaCost(2)),
|
||||
StaticFilters.FILTER_SPELL_AN_INSTANT_OR_SORCERY, false, SetTargetPointer.SPELL
|
||||
));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package mage.game.command.emblems;
|
||||
|
||||
import mage.abilities.common.SpellCastControllerTriggeredAbility;
|
||||
import mage.abilities.effects.common.CopyTargetSpellEffect;
|
||||
import mage.abilities.effects.common.CopyTargetStackObjectEffect;
|
||||
import mage.constants.SetTargetPointer;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.StaticFilters;
|
||||
|
|
@ -17,7 +17,7 @@ public final class WillKenrithEmblem extends Emblem {
|
|||
super("Emblem Will Kenrith");
|
||||
this.getAbilities().add(new SpellCastControllerTriggeredAbility(
|
||||
Zone.COMMAND,
|
||||
new CopyTargetSpellEffect(true).withSpellName("it"),
|
||||
new CopyTargetStackObjectEffect(true).withText("it"),
|
||||
StaticFilters.FILTER_SPELL_AN_INSTANT_OR_SORCERY,
|
||||
false,
|
||||
SetTargetPointer.SPELL
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue