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();
}
}