mirror of
https://github.com/magefree/mage.git
synced 2026-01-26 21:29:17 -08:00
Rework CombatDamageByToughness effects (#11068)
* split effect into three classes for convenience * added static filter * refactored cards using effect * fixed issues as per PR comments * changed predicate and fixed text * added unit test, fixed text issues with Baldin * set static text * changed outcome * added stop to test * fixs issues as per PR comments
This commit is contained in:
parent
3f25b93e91
commit
a65c2204ce
18 changed files with 223 additions and 225 deletions
|
|
@ -0,0 +1,48 @@
|
|||
|
||||
package mage.abilities.effects.common.ruleModifying;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.ContinuousEffectImpl;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Layer;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.SubLayer;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public class CombatDamageByToughnessAllEffect extends ContinuousEffectImpl {
|
||||
|
||||
private final FilterCreaturePermanent filter;
|
||||
|
||||
|
||||
public CombatDamageByToughnessAllEffect(FilterCreaturePermanent filter) {
|
||||
this(filter, Duration.WhileOnBattlefield);
|
||||
}
|
||||
|
||||
public CombatDamageByToughnessAllEffect(FilterCreaturePermanent filter, Duration duration) {
|
||||
super(duration, Layer.RulesEffects, SubLayer.NA, Outcome.Neutral);
|
||||
this.filter = filter;
|
||||
this.staticText = filter.getMessage() + " assigns combat damage equal to its toughness rather than its power";
|
||||
}
|
||||
|
||||
|
||||
private CombatDamageByToughnessAllEffect(final CombatDamageByToughnessAllEffect effect) {
|
||||
super(effect);
|
||||
this.filter = effect.filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CombatDamageByToughnessAllEffect copy() {
|
||||
return new CombatDamageByToughnessAllEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
game.getCombat().setUseToughnessForDamage(true);
|
||||
game.getCombat().addUseToughnessForDamageFilter(filter);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
|
||||
package mage.abilities.effects.common.ruleModifying;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.effects.ContinuousEffectImpl;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Layer;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.SubLayer;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.filter.predicate.permanent.ControllerIdPredicate;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public class CombatDamageByToughnessEffect extends ContinuousEffectImpl {
|
||||
|
||||
private final FilterCreaturePermanent filter;
|
||||
private final boolean onlyControlled;
|
||||
|
||||
|
||||
public CombatDamageByToughnessEffect(FilterCreaturePermanent filter, boolean onlyControlled) {
|
||||
this(filter, onlyControlled, Duration.WhileOnBattlefield);
|
||||
}
|
||||
|
||||
public CombatDamageByToughnessEffect(FilterCreaturePermanent filter, boolean onlyControlled, Duration duration) {
|
||||
super(duration, Layer.RulesEffects, SubLayer.NA, Outcome.Detriment);
|
||||
this.filter = filter;
|
||||
this.onlyControlled = onlyControlled;
|
||||
}
|
||||
|
||||
|
||||
private CombatDamageByToughnessEffect(final CombatDamageByToughnessEffect effect) {
|
||||
super(effect);
|
||||
this.filter = effect.filter;
|
||||
this.onlyControlled = effect.onlyControlled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CombatDamageByToughnessEffect copy() {
|
||||
return new CombatDamageByToughnessEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
FilterCreaturePermanent filterPermanent;
|
||||
if (onlyControlled) {
|
||||
filterPermanent = filter.copy();
|
||||
filterPermanent.add(new ControllerIdPredicate(source.getControllerId()));
|
||||
} else {
|
||||
filterPermanent = filter;
|
||||
}
|
||||
game.getCombat().setUseToughnessForDamage(true);
|
||||
game.getCombat().addUseToughnessForDamageFilter(filterPermanent);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText(Mode mode) {
|
||||
if (staticText != null && !staticText.isEmpty()) {
|
||||
return staticText;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder("Each ");
|
||||
sb.append(filter.getMessage());
|
||||
if (onlyControlled && !filter.getMessage().contains("you control")) {
|
||||
sb.append(" you control");
|
||||
}
|
||||
sb.append(" assigns combat damage equal to its toughness rather than its power");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
package mage.abilities.effects.common.ruleModifying;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.ContinuousEffectImpl;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Layer;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.SubLayer;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.filter.predicate.mageobject.MageObjectReferencePredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
public class CombatDamageByToughnessSourceEffect extends ContinuousEffectImpl {
|
||||
|
||||
public CombatDamageByToughnessSourceEffect(Duration duration) {
|
||||
super(duration, Layer.RulesEffects, SubLayer.NA, Outcome.Neutral);
|
||||
this.staticText = "{this} assigns combat damage equal to its toughness rather than its power";
|
||||
}
|
||||
|
||||
private CombatDamageByToughnessSourceEffect(final CombatDamageByToughnessSourceEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CombatDamageByToughnessSourceEffect copy() {
|
||||
return new CombatDamageByToughnessSourceEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
|
||||
if (permanent == null) {
|
||||
discard();
|
||||
return false;
|
||||
}
|
||||
|
||||
FilterCreaturePermanent filter = new FilterCreaturePermanent();
|
||||
filter.add(new MageObjectReferencePredicate(permanent.getId(), game));
|
||||
game.getCombat().setUseToughnessForDamage(true);
|
||||
game.getCombat().addUseToughnessForDamageFilter(filter);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
package mage.abilities.effects.common.ruleModifying;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.effects.ContinuousEffectImpl;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Layer;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.SubLayer;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.filter.predicate.permanent.PermanentReferenceInCollectionPredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
public class CombatDamageByToughnessTargetEffect extends ContinuousEffectImpl {
|
||||
|
||||
public CombatDamageByToughnessTargetEffect(Duration duration) {
|
||||
super(duration, Layer.RulesEffects, SubLayer.NA, Outcome.Neutral);
|
||||
}
|
||||
|
||||
private CombatDamageByToughnessTargetEffect(final CombatDamageByToughnessTargetEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CombatDamageByToughnessTargetEffect copy() {
|
||||
return new CombatDamageByToughnessTargetEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Set<Permanent> set = targetPointer.getTargets(game, source).stream()
|
||||
.map(game::getPermanent)
|
||||
.filter(Objects::isNull)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
FilterCreaturePermanent filter = new FilterCreaturePermanent();
|
||||
filter.add(new PermanentReferenceInCollectionPredicate(set, game));
|
||||
game.getCombat().setUseToughnessForDamage(true);
|
||||
game.getCombat().addUseToughnessForDamageFilter(filter);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText(Mode mode) {
|
||||
return getTargetPointer().describeTargets(mode.getTargets(), "that creature")
|
||||
+ " assigns combat damage equal to its toughness rather than its power";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1228,4 +1228,11 @@ public final class StaticFilters {
|
|||
static {
|
||||
FILTER_CONTROLLED_FOOD.setLockedFilter(true);
|
||||
}
|
||||
|
||||
public static final FilterCreaturePermanent FILTER_CONTROLLED_CREATURE_EACH = new FilterCreaturePermanent("each creature you control");
|
||||
|
||||
static {
|
||||
FILTER_CONTROLLED_CREATURE_EACH.add(TargetController.YOU.getPlayerPredicate());
|
||||
FILTER_CONTROLLED_CREATURE_EACH.setLockedFilter(true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue