Replace more custom effects with SavedDamageValue

This commit is contained in:
Alex W. Jackson 2022-04-02 02:11:12 -04:00
parent ca9b2ea135
commit 081b2f2f39
48 changed files with 318 additions and 1226 deletions

View file

@ -1,10 +1,13 @@
package mage.abilities.effects.common;
import mage.constants.Outcome;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.filter.FilterPermanent;
import mage.filter.StaticFilters;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
@ -15,20 +18,43 @@ import mage.players.Player;
*/
public class DamageAllControlledTargetEffect extends OneShotEffect {
private FilterPermanent filter;
private int amount;
private final DynamicValue amount;
private final FilterPermanent filter;
private String sourceName = "{this}";
public DamageAllControlledTargetEffect(int amount) {
this(amount, StaticFilters.FILTER_PERMANENT_CREATURE);
}
public DamageAllControlledTargetEffect(int amount, String whoDealDamageName) {
this(amount, StaticFilters.FILTER_PERMANENT_CREATURE);
this.sourceName = whoDealDamageName;
}
public DamageAllControlledTargetEffect(DynamicValue amount) {
this(amount, StaticFilters.FILTER_PERMANENT_CREATURE);
}
public DamageAllControlledTargetEffect(DynamicValue amount, String whoDealDamageName) {
this(amount, StaticFilters.FILTER_PERMANENT_CREATURE);
this.sourceName = whoDealDamageName;
}
public DamageAllControlledTargetEffect(int amount, FilterPermanent filter) {
this(StaticValue.get(amount), filter);
}
public DamageAllControlledTargetEffect(DynamicValue amount, FilterPermanent filter) {
super(Outcome.Damage);
this.amount = amount;
this.filter = filter;
getText();
}
public DamageAllControlledTargetEffect(final DamageAllControlledTargetEffect effect) {
super(effect);
this.amount = effect.amount;
this.amount = effect.amount.copy();
this.filter = effect.filter.copy();
this.sourceName = effect.sourceName;
}
@Override
@ -38,19 +64,29 @@ public class DamageAllControlledTargetEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayerOrPlaneswalkerController(source.getFirstTarget());
Player player = game.getPlayerOrPlaneswalkerController(targetPointer.getFirst(game, source));
if (player == null) {
return false;
}
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, player.getId(), game)) {
permanent.damage(amount, source.getSourceId(), source, game, false, true);
permanent.damage(amount.calculate(game, source, this), source.getSourceId(), source, game, false, true);
}
return true;
}
private void getText() {
StringBuilder sb = new StringBuilder("{this} deals ");
sb.append(amount).append(" damage to each ").append(filter.getMessage()).append(" controlled by target player");
staticText = sb.toString();
@Override
public String getText(Mode mode) {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
StringBuilder sb = new StringBuilder(sourceName);
sb.append(" deals ").append(amount).append(" damage to each ").append(filter.getMessage());
if (mode.getTargets().isEmpty()) {
sb.append(" that player");
} else {
sb.append(" target ").append(mode.getTargets().get(0).getTargetName());
}
sb.append(" controls");
return sb.toString();
}
}

View file

@ -19,13 +19,13 @@ public class DamageAttachedControllerEffect extends OneShotEffect {
protected DynamicValue amount;
public DamageAttachedControllerEffect(int amount) {
super(Outcome.Damage);
this.amount = StaticValue.get(amount);
this(StaticValue.get(amount));
}
public DamageAttachedControllerEffect(DynamicValue amount) {
super(Outcome.Damage);
this.amount = amount;
this.staticText = "{this} deals " + amount + " damage to that creature's controller";
}
public DamageAttachedControllerEffect(final DamageAttachedControllerEffect effect) {
@ -60,15 +60,4 @@ public class DamageAttachedControllerEffect extends OneShotEffect {
}
return false;
}
@Override
public String getText(Mode mode) {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
if ("equal to".equals(amount.toString())) {
return "{this} deals damage " + amount + " that creatures toughness to that creature's controller";
}
return "{this} deals " + amount + " damage to that creature's controller";
}
}

View file

@ -1,5 +1,3 @@
package mage.abilities.effects.common;
import mage.abilities.Ability;
@ -19,27 +17,28 @@ import mage.game.permanent.Permanent;
public class DamageAttachedEffect extends OneShotEffect {
protected DynamicValue amount;
private String sourceName = "{this}";
public DamageAttachedEffect(int amount) {
super(Outcome.Damage);
this.amount = StaticValue.get(amount);
this(StaticValue.get(amount), "{this}");
}
public DamageAttachedEffect(int amount, String whoDealDamageName) {
this(amount);
this.sourceName = whoDealDamageName;
this(StaticValue.get(amount), whoDealDamageName);
}
public DamageAttachedEffect(DynamicValue amount) {
this(amount, "{this}");
}
public DamageAttachedEffect(DynamicValue amount, String whoDealDamageName) {
super(Outcome.Damage);
this.amount = amount;
this.staticText = whoDealDamageName + " deals " + amount + " damage to enchanted creature";
}
public DamageAttachedEffect(final DamageAttachedEffect effect) {
super(effect);
this.amount = effect.amount;
this.sourceName = effect.sourceName;
}
@Override
@ -65,23 +64,4 @@ public class DamageAttachedEffect extends OneShotEffect {
enchanted.damage(amount.calculate(game, source, this), source.getSourceId(), source, game, false, true);
return true;
}
@Override
public String getText(Mode mode) {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
if ("equal to".equals(amount.toString())) {
return this.sourceName + " deals damage " + amount + " that creatures toughness to enchanted creature";
}
return this.sourceName + " deals " + amount + " damage to enchanted creature";
}
public String getSourceName() {
return sourceName;
}
public void setSourceName(String sourceName) {
this.sourceName = sourceName;
}
}

View file

@ -1,5 +1,3 @@
package mage.abilities.effects.common;
import mage.constants.Outcome;
@ -21,39 +19,35 @@ public class DamageControllerEffect extends OneShotEffect {
protected boolean preventable;
private String sourceName = "{this}";
public DamageControllerEffect(int amount, String whoDealDamageName) {
this(amount, true, whoDealDamageName);
}
public DamageControllerEffect(int amount) {
this(amount, true);
}
public DamageControllerEffect(int amount, boolean preventable, String whoDealDamageName) {
super(Outcome.Damage);
this.amount = StaticValue.get(amount);
this.preventable = preventable;
this.sourceName = whoDealDamageName;
public DamageControllerEffect(int amount, boolean preventable) {
this(amount, preventable, "{this}");
}
public DamageControllerEffect(int amount, boolean preventable) {
super(Outcome.Damage);
this.amount = StaticValue.get(amount);
this.preventable = preventable;
public DamageControllerEffect(int amount, String whoDealDamageName) {
this(amount, true, whoDealDamageName);
}
public DamageControllerEffect(int amount, boolean preventable, String whoDealDamageName) {
this(StaticValue.get(amount), preventable, whoDealDamageName);
}
public DamageControllerEffect(DynamicValue amount) {
this(amount, "{this}");
}
public DamageControllerEffect(DynamicValue amount, String whoDealDamageName) {
this(amount, true, whoDealDamageName);
}
public DamageControllerEffect(DynamicValue amount, boolean preventable, String whoDealDamageName) {
super(Outcome.Damage);
this.amount = amount;
this.preventable = true;
}
public int getAmount() {
if (amount instanceof StaticValue) {
return amount.calculate(null, null, this);
} else {
return 0;
}
this.preventable = preventable;
this.sourceName = whoDealDamageName;
}
public DamageControllerEffect(final DamageControllerEffect effect) {
@ -77,7 +71,7 @@ public class DamageControllerEffect extends OneShotEffect {
}
return false;
}
@Override
public String getText(Mode mode) {
if (staticText != null && !staticText.isEmpty()) {
@ -107,12 +101,4 @@ public class DamageControllerEffect extends OneShotEffect {
}
return sb.toString();
}
public String getSourceName() {
return sourceName;
}
public void setSourceName(String sourceName) {
this.sourceName = sourceName;
}
}

View file

@ -60,13 +60,11 @@ public class GainLifeEffect extends OneShotEffect {
StringBuilder sb = new StringBuilder();
String message = life.getMessage();
sb.append("you gain ");
if (message.startsWith("that")) {
sb.append(message).append(' ');
} else if (message.isEmpty() || !life.toString().equals("1")) {
if (message.isEmpty() || !life.toString().equals("1")) {
sb.append(life).append(' ');
}
sb.append("life");
if (!message.isEmpty() && !message.startsWith("that")) {
if (!message.isEmpty()) {
sb.append(life.toString().equals("1") ? " equal to the number of " : " for each ");
sb.append(message);
}

View file

@ -1,12 +1,13 @@
package mage.abilities.effects.common;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.game.stack.Spell;
@ -18,9 +19,13 @@ import mage.players.Player;
*/
public class LoseLifeTargetControllerEffect extends OneShotEffect {
protected int amount;
private final DynamicValue amount;
public LoseLifeTargetControllerEffect(int amount) {
this(StaticValue.get(amount));
}
public LoseLifeTargetControllerEffect(DynamicValue amount) {
super(Outcome.Damage);
this.amount = amount;
staticText = "Its controller loses " + amount + " life";
@ -28,7 +33,7 @@ public class LoseLifeTargetControllerEffect extends OneShotEffect {
public LoseLifeTargetControllerEffect(final LoseLifeTargetControllerEffect effect) {
super(effect);
this.amount = effect.amount;
this.amount = effect.amount.copy();
}
@Override
@ -38,16 +43,11 @@ public class LoseLifeTargetControllerEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
MageObject targetCard = game.getLastKnownInformation(targetPointer.getFirst(game, source), Zone.BATTLEFIELD);
MageObject targetCard = targetPointer.getFirstTargetPermanentOrLKI(game, source);
// if target is a countered spell
if ( targetCard == null ) {
MageObject obj = game.getObject(targetPointer.getFirst(game, source));
if ( obj instanceof Card ) {
targetCard = (Card)obj;
} else {
// if target is a countered spell
targetCard = game.getLastKnownInformation(targetPointer.getFirst(game, source), Zone.STACK);
}
targetCard = game.getLastKnownInformation(targetPointer.getFirst(game, source), Zone.STACK);
}
if ( targetCard != null ) {
@ -65,11 +65,10 @@ public class LoseLifeTargetControllerEffect extends OneShotEffect {
}
if ( controller != null ) {
controller.loseLife(amount, game, source, false);
controller.loseLife(amount.calculate(game, source, this), game, source, false);
return true;
}
}
return false;
}
}

View file

@ -55,18 +55,10 @@ public class DiscardControllerEffect extends OneShotEffect {
private void setText() {
StringBuilder sb = new StringBuilder("discard ");
if (amount.toString().equals("1")) {
sb.append('a');
if (amount.toString().equals("1") || amount.toString().equals("a")) {
sb.append("a card");
} else {
sb.append(CardUtil.numberToText(amount.toString()));
}
sb.append(" card");
try {
if (Integer.parseInt(amount.toString()) > 1) {
sb.append('s');
}
} catch (Exception e) {
sb.append('s');
sb.append(CardUtil.numberToText(amount.toString())).append(" cards");
}
if (randomDiscard) {
sb.append(" at random");