deduplicated X loyalty value

This commit is contained in:
Evan Kranzler 2020-11-01 16:47:47 -05:00
parent 96092d84bc
commit 54b2b98819
5 changed files with 50 additions and 228 deletions

View file

@ -4,10 +4,7 @@ import mage.abilities.Ability;
import mage.abilities.LoyaltyAbility;
import mage.abilities.common.CantBeCounteredSourceAbility;
import mage.abilities.common.PlaneswalkerEntersWithLoyaltyCountersAbility;
import mage.abilities.costs.Cost;
import mage.abilities.costs.common.PayVariableLoyaltyCost;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect;
import mage.abilities.dynamicvalue.common.GetXLoyaltyValue;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.DamageAllEffect;
import mage.abilities.effects.common.DamageTargetEffect;
@ -55,7 +52,7 @@ public final class ChandraAwakenedInferno extends CardImpl {
this.addAbility(new LoyaltyAbility(new DamageAllEffect(3, filter), -3));
// -X: Chandra, Awakened Inferno deals X damage to target creature or planeswalker. If a permanent dealt damage this way would die this turn, exile it instead.
Ability ability = new LoyaltyAbility(new DamageTargetEffect(ChandraAwakenedInfernoXValue.instance));
Ability ability = new LoyaltyAbility(new DamageTargetEffect(GetXLoyaltyValue.instance));
ability.addEffect(
new ExileTargetIfDiesEffect()
.setText("If a permanent dealt damage this way would die this turn, exile it instead.")
@ -99,32 +96,3 @@ class ChandraAwakenedInfernoEffect extends OneShotEffect {
return true;
}
}
enum ChandraAwakenedInfernoXValue implements DynamicValue {
instance;
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
for (Cost cost : sourceAbility.getCosts()) {
if (cost instanceof PayVariableLoyaltyCost) {
return ((PayVariableLoyaltyCost) cost).getAmount();
}
}
return 0;
}
@Override
public DynamicValue copy() {
return instance;
}
@Override
public String getMessage() {
return "";
}
@Override
public String toString() {
return "X";
}
}

View file

@ -3,10 +3,7 @@ package mage.cards.c;
import mage.abilities.Ability;
import mage.abilities.LoyaltyAbility;
import mage.abilities.common.PlaneswalkerEntersWithLoyaltyCountersAbility;
import mage.abilities.costs.Cost;
import mage.abilities.costs.common.PayVariableLoyaltyCost;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect;
import mage.abilities.dynamicvalue.common.GetXLoyaltyValue;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.CreateTokenEffect;
import mage.abilities.effects.common.DamageAllEffect;
@ -42,7 +39,9 @@ public final class ChandraFlamecaller extends CardImpl {
this.addAbility(new LoyaltyAbility(new ChandraDrawEffect(), 0));
// -X: Chandra, Flamecaller deals X damage to each creature.
this.addAbility(new LoyaltyAbility(new DamageAllEffect(ChandraXValue.getDefault(), StaticFilters.FILTER_PERMANENT_CREATURE)));
this.addAbility(new LoyaltyAbility(new DamageAllEffect(
GetXLoyaltyValue.instance, StaticFilters.FILTER_PERMANENT_CREATURE
)));
}
public ChandraFlamecaller(final ChandraFlamecaller card) {
@ -112,37 +111,3 @@ class ChandraDrawEffect extends OneShotEffect {
return true;
}
}
class ChandraXValue implements DynamicValue {
private static final ChandraXValue defaultValue = new ChandraXValue();
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
for (Cost cost : sourceAbility.getCosts()) {
if (cost instanceof PayVariableLoyaltyCost) {
return ((PayVariableLoyaltyCost) cost).getAmount();
}
}
return 0;
}
@Override
public DynamicValue copy() {
return defaultValue;
}
@Override
public String getMessage() {
return "";
}
@Override
public String toString() {
return "X";
}
public static ChandraXValue getDefault() {
return defaultValue;
}
}

View file

@ -4,12 +4,9 @@ import mage.abilities.Ability;
import mage.abilities.LoyaltyAbility;
import mage.abilities.Mode;
import mage.abilities.common.PlaneswalkerEntersWithLoyaltyCountersAbility;
import mage.abilities.costs.Cost;
import mage.abilities.costs.common.PayVariableLoyaltyCost;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.GetXLoyaltyValue;
import mage.abilities.dynamicvalue.common.GreatestPowerAmongControlledCreaturesValue;
import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.CreateTokenEffect;
import mage.abilities.effects.common.GainLifeEffect;
@ -49,8 +46,8 @@ public final class HuatliWarriorPoet extends CardImpl {
this.addAbility(new LoyaltyAbility(new CreateTokenEffect(new DinosaurToken()), 0));
// -X: Huatli, Warrior Poet deals X damage divided as you choose among any number of target creatures. Creatures dealt damage this way can't block this turn.
Ability ability = new LoyaltyAbility(new HuatliWarriorPoetDamageEffect(HuatliXValue.instance));
ability.addTarget(new TargetCreaturePermanentAmount(HuatliXValue.instance));
Ability ability = new LoyaltyAbility(new HuatliWarriorPoetDamageEffect());
ability.addTarget(new TargetCreaturePermanentAmount(GetXLoyaltyValue.instance));
this.addAbility(ability);
}
@ -64,51 +61,14 @@ public final class HuatliWarriorPoet extends CardImpl {
}
}
enum HuatliXValue implements DynamicValue {
instance;
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
for (Cost cost : sourceAbility.getCosts()) {
if (cost instanceof PayVariableLoyaltyCost) {
return ((PayVariableLoyaltyCost) cost).getAmount();
}
}
return 0;
}
@Override
public DynamicValue copy() {
return instance;
}
@Override
public String getMessage() {
return "";
}
@Override
public String toString() {
return "X";
}
public static HuatliXValue getDefault() {
return instance;
}
}
class HuatliWarriorPoetDamageEffect extends OneShotEffect {
protected DynamicValue amount;
HuatliWarriorPoetDamageEffect(DynamicValue amount) {
HuatliWarriorPoetDamageEffect() {
super(Outcome.Damage);
this.amount = amount;
}
private HuatliWarriorPoetDamageEffect(final HuatliWarriorPoetDamageEffect effect) {
super(effect);
this.amount = effect.amount;
}
@Override
@ -118,15 +78,16 @@ class HuatliWarriorPoetDamageEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
if (!source.getTargets().isEmpty()) {
Target multiTarget = source.getTargets().get(0);
for (UUID target : multiTarget.getTargets()) {
Permanent permanent = game.getPermanent(target);
if (permanent != null && permanent.damage(multiTarget.getTargetAmount(target), source.getSourceId(), game, false, true) > 0) {
ContinuousEffect effect = new CantBlockTargetEffect(Duration.EndOfTurn);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
}
if (source.getTargets().isEmpty()) {
return true;
}
Target multiTarget = source.getTargets().get(0);
for (UUID target : multiTarget.getTargets()) {
Permanent permanent = game.getPermanent(target);
if (permanent != null && permanent.damage(multiTarget.getTargetAmount(target), source.getSourceId(), game, false, true) > 0) {
ContinuousEffect effect = new CantBlockTargetEffect(Duration.EndOfTurn);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
}
}
return true;
@ -137,9 +98,7 @@ class HuatliWarriorPoetDamageEffect extends OneShotEffect {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
return "{this} deals "
+ amount.toString()
+ " damage divided as you choose among any number of target "
return "{this} deals X damage divided as you choose among any number of target "
+ mode.getTargets().get(0).getTargetName()
+ ". Creatures dealt damage this way can't block this turn";
}

View file

@ -5,12 +5,9 @@ import mage.abilities.LoyaltyAbility;
import mage.abilities.common.PlaneswalkerEntersWithLoyaltyCountersAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.condition.common.MyTurnCondition;
import mage.abilities.costs.Cost;
import mage.abilities.costs.common.PayVariableLoyaltyCost;
import mage.abilities.decorator.ConditionalContinuousEffect;
import mage.abilities.decorator.ConditionalCostModificationEffect;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect;
import mage.abilities.dynamicvalue.common.GetXLoyaltyValue;
import mage.abilities.effects.common.DamageTargetEffect;
import mage.abilities.effects.common.continuous.GainAbilityControlledEffect;
import mage.abilities.effects.common.cost.AbilitiesCostReductionControllerEffect;
@ -27,7 +24,6 @@ import mage.filter.FilterPermanent;
import mage.filter.StaticFilters;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.permanent.TappedPredicate;
import mage.game.Game;
import mage.target.TargetPermanent;
import java.util.UUID;
@ -67,7 +63,7 @@ public final class NahiriStormOfStone extends CardImpl {
this.addAbility(ability);
// -X: Nahiri, Storm of Stone deals X damage to target tapped creature.
ability = new LoyaltyAbility(new DamageTargetEffect(NahiriStormOfStoneValue.instance));
ability = new LoyaltyAbility(new DamageTargetEffect(GetXLoyaltyValue.instance));
ability.addTarget(new TargetPermanent(filter));
this.addAbility(ability);
}
@ -81,32 +77,3 @@ public final class NahiriStormOfStone extends CardImpl {
return new NahiriStormOfStone(this);
}
}
enum NahiriStormOfStoneValue implements DynamicValue {
instance;
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
for (Cost cost : sourceAbility.getCosts()) {
if (cost instanceof PayVariableLoyaltyCost) {
return ((PayVariableLoyaltyCost) cost).getAmount();
}
}
return 0;
}
@Override
public DynamicValue copy() {
return instance;
}
@Override
public String toString() {
return "X";
}
@Override
public String getMessage() {
return "";
}
}

View file

@ -1,13 +1,9 @@
package mage.cards.s;
import mage.abilities.Ability;
import mage.abilities.LoyaltyAbility;
import mage.abilities.common.PlaneswalkerEntersWithLoyaltyCountersAbility;
import mage.abilities.costs.Cost;
import mage.abilities.costs.common.PayVariableLoyaltyCost;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect;
import mage.abilities.dynamicvalue.common.GetXLoyaltyValue;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.CreateTokenEffect;
import mage.abilities.effects.common.DamageTargetEffect;
@ -38,9 +34,9 @@ public final class SorinGrimNemesis extends CardImpl {
this.addAbility(new LoyaltyAbility(new SorinGrimNemesisRevealEffect(), 1));
// -X: Sorin, Grim Nemesis deals X damage to target creature or planeswalker and you gain X life.
Ability ability = new LoyaltyAbility(new DamageTargetEffect(SorinXValue.getDefault()));
Ability ability = new LoyaltyAbility(new DamageTargetEffect(GetXLoyaltyValue.instance));
ability.addTarget(new TargetCreatureOrPlaneswalker());
ability.addEffect(new GainLifeEffect(SorinXValue.getDefault()));
ability.addEffect(new GainLifeEffect(GetXLoyaltyValue.instance).concatBy("and"));
this.addAbility(ability);
// -9: Create a number of 1/1 black Vampire Knight creature tokens with lifelink equal to the highest life total among all players.
@ -104,69 +100,36 @@ class SorinGrimNemesisRevealEffect extends OneShotEffect {
}
}
class SorinXValue implements DynamicValue {
private static final SorinXValue defaultValue = new SorinXValue();
class SorinTokenEffect extends OneShotEffect {
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
for (Cost cost : sourceAbility.getCosts()) {
if (cost instanceof PayVariableLoyaltyCost) {
return ((PayVariableLoyaltyCost) cost).getAmount();
}
}
return 0;
}
@Override
public DynamicValue copy() {
return defaultValue;
}
@Override
public String getMessage() {
return "";
}
@Override
public String toString() {
return "X";
}
public static SorinXValue getDefault() {
return defaultValue;
}
SorinTokenEffect() {
super(Outcome.GainLife);
staticText = "Create a number of 1/1 black Vampire Knight creature tokens with lifelink equal to the highest life total among all players";
}
class SorinTokenEffect extends OneShotEffect {
private SorinTokenEffect(final SorinTokenEffect effect) {
super(effect);
}
SorinTokenEffect() {
super(Outcome.GainLife);
staticText = "Create a number of 1/1 black Vampire Knight creature tokens with lifelink equal to the highest life total among all players";
}
SorinTokenEffect(final SorinTokenEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
int maxLife = 0;
PlayerList playerList = game.getState().getPlayersInRange(source.getControllerId(), game);
for (UUID pid : playerList) {
Player p = game.getPlayer(pid);
if (p != null) {
if (maxLife < p.getLife()) {
maxLife = p.getLife();
}
@Override
public boolean apply(Game game, Ability source) {
int maxLife = 0;
PlayerList playerList = game.getState().getPlayersInRange(source.getControllerId(), game);
for (UUID pid : playerList) {
Player p = game.getPlayer(pid);
if (p != null) {
if (maxLife < p.getLife()) {
maxLife = p.getLife();
}
}
new CreateTokenEffect(new VampireKnightToken(), maxLife).apply(game, source);
return true;
}
@Override
public SorinTokenEffect copy() {
return new SorinTokenEffect(this);
}
new CreateTokenEffect(new VampireKnightToken(), maxLife).apply(game, source);
return true;
}
@Override
public SorinTokenEffect copy() {
return new SorinTokenEffect(this);
}
}