mirror of
https://github.com/magefree/mage.git
synced 2025-12-26 05:22:02 -08:00
Replace more custom effects with SavedDamageValue
This commit is contained in:
parent
ca9b2ea135
commit
081b2f2f39
48 changed files with 318 additions and 1226 deletions
|
|
@ -1,16 +1,12 @@
|
|||
|
||||
|
||||
package mage.abilities.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.dynamicvalue.common.SavedDamageValue;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.constants.Outcome;
|
||||
import mage.abilities.effects.common.GainLifeEffect;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.players.Player;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -20,7 +16,7 @@ import mage.players.Player;
|
|||
public class DealsDamageGainLifeSourceTriggeredAbility extends TriggeredAbilityImpl {
|
||||
|
||||
public DealsDamageGainLifeSourceTriggeredAbility() {
|
||||
super(Zone.BATTLEFIELD, new GainThatMuchLifeEffect(), false);
|
||||
super(Zone.BATTLEFIELD, new GainLifeEffect(SavedDamageValue.MUCH), false);
|
||||
}
|
||||
|
||||
public DealsDamageGainLifeSourceTriggeredAbility(final DealsDamageGainLifeSourceTriggeredAbility ability) {
|
||||
|
|
@ -53,34 +49,3 @@ public class DealsDamageGainLifeSourceTriggeredAbility extends TriggeredAbilityI
|
|||
return "Whenever {this} deals damage, " ;
|
||||
}
|
||||
}
|
||||
|
||||
class GainThatMuchLifeEffect extends OneShotEffect {
|
||||
|
||||
public GainThatMuchLifeEffect() {
|
||||
super(Outcome.GainLife);
|
||||
this.staticText = "you gain that much life";
|
||||
}
|
||||
|
||||
public GainThatMuchLifeEffect(final GainThatMuchLifeEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GainThatMuchLifeEffect copy() {
|
||||
return new GainThatMuchLifeEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
int amount = (Integer) getValue("damage");
|
||||
if (amount > 0) {
|
||||
controller.gainLife(amount, game, source);
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,45 +0,0 @@
|
|||
package mage.abilities.dynamicvalue.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
/**
|
||||
* @author MTGfan
|
||||
*/
|
||||
public enum AttachedPermanentToughnessValue implements DynamicValue {
|
||||
instance;
|
||||
|
||||
@Override
|
||||
public int calculate(Game game, Ability sourceAbility, Effect effect) {
|
||||
// In the case that the enchantment is blinked
|
||||
Permanent enchantment = (Permanent) game.getLastKnownInformation(sourceAbility.getSourceId(), Zone.BATTLEFIELD);
|
||||
if (enchantment == null) {
|
||||
// It was not blinked, use the standard method
|
||||
enchantment = game.getPermanentOrLKIBattlefield(sourceAbility.getSourceId());
|
||||
}
|
||||
if (enchantment == null) {
|
||||
return 0;
|
||||
}
|
||||
Permanent enchanted = game.getPermanentOrLKIBattlefield(enchantment.getAttachedTo());
|
||||
return enchanted.getToughness().getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttachedPermanentToughnessValue copy() {
|
||||
return AttachedPermanentToughnessValue.instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "equal to";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return "that creature's toughness";
|
||||
}
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@ public enum SavedDamageValue implements DynamicValue {
|
|||
private final String message;
|
||||
|
||||
SavedDamageValue(String message) {
|
||||
this.message = message;
|
||||
this.message = "that " + message;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -30,7 +30,7 @@ public enum SavedDamageValue implements DynamicValue {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "that " + message;
|
||||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -875,6 +875,12 @@ public final class StaticFilters {
|
|||
FILTER_ATTACKING_CREATURES.setLockedFilter(true);
|
||||
}
|
||||
|
||||
public static final FilterAttackingOrBlockingCreature FILTER_ATTACKING_OR_BLOCKING_CREATURE = new FilterAttackingOrBlockingCreature();
|
||||
|
||||
static {
|
||||
FILTER_ATTACKING_OR_BLOCKING_CREATURE.setLockedFilter(true);
|
||||
}
|
||||
|
||||
public static final FilterAttackingOrBlockingCreature FILTER_ATTACKING_OR_BLOCKING_CREATURES = new FilterAttackingOrBlockingCreature("attacking or blocking creatures");
|
||||
|
||||
static {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
|
||||
|
||||
package mage.target.common;
|
||||
|
||||
import mage.filter.StaticFilters;
|
||||
import mage.filter.common.FilterAttackingOrBlockingCreature;
|
||||
import mage.target.TargetPermanent;
|
||||
|
||||
|
|
@ -12,11 +11,11 @@ import mage.target.TargetPermanent;
|
|||
public class TargetAttackingOrBlockingCreature extends TargetPermanent {
|
||||
|
||||
public TargetAttackingOrBlockingCreature() {
|
||||
this(1, 1, new FilterAttackingOrBlockingCreature(), false);
|
||||
this(1, 1, StaticFilters.FILTER_ATTACKING_OR_BLOCKING_CREATURE, false);
|
||||
}
|
||||
|
||||
public TargetAttackingOrBlockingCreature(int numTargets) {
|
||||
this(numTargets, numTargets, new FilterAttackingOrBlockingCreature(), false);
|
||||
this(numTargets, numTargets, StaticFilters.FILTER_ATTACKING_OR_BLOCKING_CREATURE, false);
|
||||
}
|
||||
|
||||
public TargetAttackingOrBlockingCreature(int minNumTargets, int maxNumTargets, FilterAttackingOrBlockingCreature filter, boolean notTarget) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue