refactor: simplify DistributeCountersEffect constructors

This commit is contained in:
xenohedron 2024-11-29 03:07:41 -05:00
parent d12b34e05b
commit 4edce76732
33 changed files with 53 additions and 46 deletions

View file

@ -43,7 +43,7 @@ public final class AbzanCharm extends CardImpl {
this.getSpellAbility().addMode(mode);
// *Distribute two +1/+1 counters among one or two target creatures.
mode = new Mode(new DistributeCountersEffect(CounterType.P1P1, 2, false, "one or two target creatures"));
mode = new Mode(new DistributeCountersEffect(2, "one or two target creatures"));
mode.addTarget(new TargetCreaturePermanentAmount(2));
this.getSpellAbility().addMode(mode);

View file

@ -38,7 +38,7 @@ public final class AjaniMentorOfHeroes extends CardImpl {
this.setStartingLoyalty(4);
// +1: Distribute three +1/+1 counters among one, two, or three target creatures you control
Ability ability = new LoyaltyAbility(new DistributeCountersEffect(CounterType.P1P1, 3, false, "one, two, or three target creatures you control"), 1);
Ability ability = new LoyaltyAbility(new DistributeCountersEffect(3, "one, two, or three target creatures you control"), 1);
ability.addTarget(new TargetCreaturePermanentAmount(3, StaticFilters.FILTER_CONTROLLED_CREATURES));
this.addAbility(ability);

View file

@ -42,7 +42,7 @@ public final class AjaniSleeperAgent extends CardImpl {
this.addAbility(new LoyaltyAbility(new AjaniSleeperAgentEffect(), 1));
// 3: Distribute three +1/+1 counters among up to three target creatures. They gain vigilance until end of turn.
Ability ability = new LoyaltyAbility(new DistributeCountersEffect(CounterType.P1P1, 3, false, "up to three target creatures"), -3);
Ability ability = new LoyaltyAbility(new DistributeCountersEffect(3, "up to three target creatures"), -3);
ability.addEffect(new GainAbilityTargetEffect(VigilanceAbility.getInstance()).setText("They gain vigilance until end of turn"));
Target target = new TargetCreaturePermanentAmount(3);
target.setMinNumberOfTargets(0);

View file

@ -28,7 +28,7 @@ public final class ArmamentCorps extends CardImpl {
this.toughness = new MageInt(4);
// When Armament Corps enters the battlefield, distribute two +1/+1 counters among one or two target creatures you control.
Ability ability = new EntersBattlefieldTriggeredAbility(new DistributeCountersEffect(CounterType.P1P1, 2, false, "one or two target creatures you control"), false);
Ability ability = new EntersBattlefieldTriggeredAbility(new DistributeCountersEffect(2, "one or two target creatures you control"), false);
ability.addTarget(new TargetCreaturePermanentAmount(2, StaticFilters.FILTER_CONTROLLED_CREATURES));
this.addAbility(ability);
}

View file

@ -27,7 +27,7 @@ public final class BiogenicUpgrade extends CardImpl {
// Distribute three +1/+1 counters among one, two, or three target creatures, then double the number of +1/+1 counters on each of those creatures.
this.getSpellAbility().addEffect(new DistributeCountersEffect(
CounterType.P1P1, 3, false,
3,
"one, two, or three target creatures"
));
this.getSpellAbility().addTarget(new TargetCreaturePermanentAmount(3));
@ -75,4 +75,4 @@ class BiogenicUpgradeEffect extends OneShotEffect {
}
return true;
}
}
}

View file

@ -19,7 +19,7 @@ public final class BlessingsOfNature extends CardImpl {
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{4}{G}");
// Distribute four +1/+1 counters among any number of target creatures.
this.getSpellAbility().addEffect(new DistributeCountersEffect(CounterType.P1P1, 4, false, "any number of target creatures"));
this.getSpellAbility().addEffect(new DistributeCountersEffect(4, "any number of target creatures"));
this.getSpellAbility().addTarget(new TargetCreaturePermanentAmount(4));
this.addAbility(new MiracleAbility("{G}"));

View file

@ -35,9 +35,9 @@ public final class BountyOfTheHunt extends CardImpl {
// Distribute three +1/+1 counters among one, two, or three target creatures. For each +1/+1 counter you put on a creature this way, remove a +1/+1 counter from that creature at the beginning of the next cleanup step.
this.getSpellAbility().addEffect(new DistributeCountersEffect(
CounterType.P1P1, 3, true,
3,
"one, two, or three target creatures"
));
).withRemoveAtEndOfTurn());
this.getSpellAbility().addTarget(new TargetCreaturePermanentAmount(3));
}

View file

@ -40,7 +40,7 @@ public final class CaseOfTheTrampledGarden extends CardImpl {
this.subtype.add(SubType.CASE);
// When this Case enters the battlefield, distribute two +1/+1 counters among one or two target creatures you control.
Ability initialAbility = new EntersBattlefieldTriggeredAbility(new DistributeCountersEffect(CounterType.P1P1, 2,
Ability initialAbility = new EntersBattlefieldTriggeredAbility(new DistributeCountersEffect(2,
"one or two target creatures you control"));
TargetPermanentAmount target = new TargetPermanentAmount(2, StaticFilters.FILTER_CONTROLLED_CREATURES);
target.setMinNumberOfTargets(1);

View file

@ -39,7 +39,7 @@ public final class Contagion extends CardImpl {
// Distribute two -2/-1 counters among one or two target creatures.
this.getSpellAbility().addTarget(new TargetCreaturePermanentAmount(2));
this.getSpellAbility().addEffect(new DistributeCountersEffect(
CounterType.M2M1, 2, false,
CounterType.M2M1, 2,
"one or two target creatures"
));
}

View file

@ -33,7 +33,7 @@ public final class CourtOfGarenbrig extends CardImpl {
// At the beginning of your upkeep, distribute two +1/+1 counters among up to two target creatures. Then if you're the monarch, double the number of +1/+1 counters on each creature you control.
Ability ability = new BeginningOfUpkeepTriggeredAbility(
new DistributeCountersEffect(
CounterType.P1P1, 2, false, "up to two target creatures"
2, "up to two target creatures"
)
);
TargetCreaturePermanentAmount target = new TargetCreaturePermanentAmount(2);

View file

@ -20,7 +20,7 @@ public final class DefendTheCelestus extends CardImpl {
// Distribute three +1/+1 counters among one, two, or three target creatures you control.
this.getSpellAbility().addEffect(new DistributeCountersEffect(
CounterType.P1P1, 3, false,
3,
"one, two, or three target creatures you control"
));
this.getSpellAbility().addTarget(new TargetCreaturePermanentAmount(

View file

@ -38,7 +38,7 @@ public final class ElusiveOtter extends AdventureCard {
// Grove's Bounty
// Distribute X +1/+1 counters among any number of target creatures you control.
this.getSpellCard().getSpellAbility().addEffect(new DistributeCountersEffect(
CounterType.P1P1, GetXValue.instance, false,
CounterType.P1P1, GetXValue.instance,
"any number of target creatures you control"
));
Target target = new TargetCreaturePermanentAmount(GetXValue.instance, StaticFilters.FILTER_CONTROLLED_CREATURES);

View file

@ -19,7 +19,7 @@ public final class ElvenRite extends CardImpl {
super(ownerId,setInfo,new CardType[]{CardType.SORCERY},"{1}{G}");
// Distribute two +1/+1 counters among one or two target creatures.
this.getSpellAbility().addEffect(new DistributeCountersEffect(CounterType.P1P1, 2, false, "one or two target creatures"));
this.getSpellAbility().addEffect(new DistributeCountersEffect(2, "one or two target creatures"));
this.getSpellAbility().addTarget(new TargetCreaturePermanentAmount(2));
}

View file

@ -33,7 +33,7 @@ public final class GlintWeaver extends CardImpl {
// When Glint Weaver enters the battlefield, distribute three +1/+1 counters among one, two, or three target creatures, then you gain life equal to the greatest toughness among creatures you control.
Ability ability = new EntersBattlefieldTriggeredAbility(new DistributeCountersEffect(
CounterType.P1P1, 3, "one, two, or three target creatures"
3, "one, two, or three target creatures"
));
ability.addEffect(new GainLifeEffect(GreatestToughnessAmongControlledCreaturesValue.instance)
.setText(", then you gain life equal to the greatest toughness among creatures you control"));

View file

@ -24,7 +24,7 @@ public final class JadeSeedstones extends CardImpl {
// When Jade Seedstones enters the battlefield, distribute three +1/+1 counters among one, two, or three target creatures you control.
Ability ability = new EntersBattlefieldTriggeredAbility(new DistributeCountersEffect(
CounterType.P1P1, 3, "one, two, or three target creatures you control"
3, "one, two, or three target creatures you control"
));
TargetPermanentAmount target = new TargetPermanentAmount(3, StaticFilters.FILTER_CONTROLLED_CREATURES);
target.setMinNumberOfTargets(1);

View file

@ -33,7 +33,7 @@ public final class JuganTheRisingStar extends CardImpl {
// Flying
this.addAbility(FlyingAbility.getInstance());
// When Jugan, the Rising Star dies, you may distribute five +1/+1 counters among any number of target creatures.
Ability ability = new DiesSourceTriggeredAbility(new DistributeCountersEffect(CounterType.P1P1, 5, false, "any number of target creatures"), true);
Ability ability = new DiesSourceTriggeredAbility(new DistributeCountersEffect(5, "any number of target creatures"), true);
ability.addTarget(new TargetCreaturePermanentAmount(5));
this.addAbility(ability);
}

View file

@ -45,7 +45,7 @@ public final class LathielTheBounteousDawn extends CardImpl {
// At the beginning of each end step, if you gained life this turn, distribute up to that many +1/+1 counters among any number of other target creatures.
Ability ability = new ConditionalInterveningIfTriggeredAbility(
new BeginningOfEndStepTriggeredAbility(TargetController.ANY, new DistributeCountersEffect(
CounterType.P1P1, 1, false, ""
1, ""
), false),
condition, "At the beginning of each end step, if you gained life this turn, " +
"distribute up to that many +1/+1 counters among any number of other target creatures."

View file

@ -45,7 +45,7 @@ public final class MyojinOfToweringMight extends CardImpl {
// Remove an indestructible counter from Myojin of Towering Might: Distribute eight +1/+1 counters among any number of target creatures you control. They gain trample until end of turn.
Ability ability = new SimpleActivatedAbility(new DistributeCountersEffect(
CounterType.P1P1, 8, false,
8,
"any number of target creatures you control"
), new RemoveCountersSourceCost(CounterType.INDESTRUCTIBLE.createInstance()));
ability.addEffect(new GainAbilityTargetEffect(

View file

@ -88,7 +88,7 @@ class NumaJoragaChieftainEffect extends OneShotEffect {
return false;
}
ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(
new DistributeCountersEffect(CounterType.P1P1, costX, false, ""),
new DistributeCountersEffect(costX, ""),
false, "distribute " + costX + " +1/+1 counters among any number of target Elves"
);
ability.addTarget(new TargetCreaturePermanentAmount(costX, filter));

View file

@ -52,7 +52,7 @@ public final class OnduKnotmaster extends AdventureCard {
// Distribute two +1/+1 counters among one or two target creatures.
this.getSpellCard().getSpellAbility().addEffect(
new DistributeCountersEffect(
CounterType.P1P1, 2, false,
2,
"one or two target creatures"
)
);

View file

@ -42,7 +42,7 @@ public final class PicnicRuiner extends AdventureCard {
// Distribute three +1/+1 counters among any number of target creatures you control.
this.getSpellCard().getSpellAbility().addEffect(
new DistributeCountersEffect(
CounterType.P1P1, 3, false,
3,
"any number of target creatures you control"
)
);

View file

@ -40,7 +40,7 @@ public final class QuirionBeastcaller extends CardImpl {
// When Quirion Beastcaller dies, distribute X +1/+1 counters among any number of target creatures you control, where X is the number of +1/+1 counters on Quirion Beastcaller.
Ability ability = new DiesSourceTriggeredAbility(new DistributeCountersEffect(
// Amount here is only used for text generation. Real amount is set in target.
CounterType.P1P1, 1, false, "any number of target creatures you control"
1, "any number of target creatures you control"
).setText("distribute X +1/+1 counters among any number of target creatures you control, where X is the number of +1/+1 counters on {this}"));
ability.addTarget(new TargetPermanentAmount(new CountersSourceCount(CounterType.P1P1), StaticFilters.FILTER_CONTROLLED_CREATURES));
this.addAbility(ability);

View file

@ -26,7 +26,9 @@ public final class ShamblingSwarm extends CardImpl {
this.toughness = new MageInt(3);
// When Shambling Swarm dies, distribute three -1/-1 counters among one, two, or three target creatures. For each -1/-1 counter you put on a creature this way, remove a -1/-1 counter from that creature at the beginning of the next end step.
Ability ability = new DiesSourceTriggeredAbility(new DistributeCountersEffect(CounterType.M1M1, 3, true, "one, two, or three target creatures"), false);
Ability ability = new DiesSourceTriggeredAbility(new DistributeCountersEffect(
CounterType.M1M1, 3, "one, two, or three target creatures"
).withRemoveAtEndOfTurn(), false);
ability.addTarget(new TargetCreaturePermanentAmount(3));
this.addAbility(ability);
}

View file

@ -19,7 +19,7 @@ public final class SplendidAgony extends CardImpl {
super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{2}{B}");
// Distribute two -1/-1 counters among one or two target creatures.
getSpellAbility().addEffect(new DistributeCountersEffect(CounterType.M1M1, 2, false, "one or two target creatures"));
getSpellAbility().addEffect(new DistributeCountersEffect(CounterType.M1M1, 2, "one or two target creatures"));
getSpellAbility().addTarget(new TargetCreaturePermanentAmount(2));
}

View file

@ -25,7 +25,7 @@ public final class StormTheSeedcore extends CardImpl {
// Distribute four +1/+1 counter among up to four target creatures you control. Creatures you control gain vigilance and trample until end of turn.
this.getSpellAbility().addEffect(new DistributeCountersEffect(
CounterType.P1P1, 4, false,
4,
"up to four target creatures you control"
));
TargetPermanentAmount target = new TargetCreaturePermanentAmount(4, StaticFilters.FILTER_CONTROLLED_CREATURES);

View file

@ -46,7 +46,7 @@ public final class TheGrandEvolution extends CardImpl {
sagaAbility.addChapterEffect(
this, SagaChapter.CHAPTER_II, SagaChapter.CHAPTER_II,
new DistributeCountersEffect(
CounterType.P1P1, 7,
7,
"any number of target creatures you control"
), new TargetPermanentAmount(7, StaticFilters.FILTER_CONTROLLED_CREATURES)
);

View file

@ -30,7 +30,7 @@ public final class UndercityUpheaval extends CardImpl {
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{1}{G}{G}");
// Undergrowth -- Distribute X +1/+1 counters among any number of target creatures you control, where X is the number of creature cards in your graveyard as you cast this spell. Creatures you control gain vigilance until end of turn.
this.getSpellAbility().addEffect(new DistributeCountersEffect(CounterType.P1P1, 1, "")
this.getSpellAbility().addEffect(new DistributeCountersEffect(1, "")
.setText("distribute X +1/+1 counters among any number of target creatures you control, " +
"where X is the number of creature cards in your graveyard as you cast this spell"));
this.getSpellAbility().addEffect(new GainAbilityControlledEffect(

View file

@ -144,7 +144,7 @@ class UrzaAcademyHeadmasterRandomEffect extends OneShotEffect {
break;
case 2: // AJANI MENTOR OF HEROES 1
sb.append("Distribute three +1/+1 counters among one, two, or three target creatures you control.");
effects.add(new DistributeCountersEffect(CounterType.P1P1, 3, false, "one, two, or three target creatures you control"));
effects.add(new DistributeCountersEffect(3, "one, two, or three target creatures you control"));
target = new TargetCreaturePermanentAmount(3, filter1);
break;
case 3: // NICOL BOLAS PLANESWALKER 1

View file

@ -31,7 +31,7 @@ public final class VerdurousGearhulk extends CardImpl {
this.addAbility(TrampleAbility.getInstance());
// When Verdurous Gearhulk enters the battlefield, distribute four +1/+1 counters among any number of target creatures you control.
Ability ability = new EntersBattlefieldTriggeredAbility(new DistributeCountersEffect(CounterType.P1P1, 4, false, "any number of target creatures you control"), false);
Ability ability = new EntersBattlefieldTriggeredAbility(new DistributeCountersEffect(4, "any number of target creatures you control"), false);
ability.addTarget(new TargetCreaturePermanentAmount(4, StaticFilters.FILTER_CONTROLLED_CREATURES));
this.addAbility(ability);
}

View file

@ -36,7 +36,7 @@ public final class VivienArkbowRanger extends CardImpl {
// +1: Distribute two +1/+1 counters among up to two target creatures. They gain trample until end of turn.
Ability ability = new LoyaltyAbility(new DistributeCountersEffect(
CounterType.P1P1, 2, false, "up to two target creatures"), 1);
2, "up to two target creatures"), 1);
ability.addEffect(new GainAbilityTargetEffect(
TrampleAbility.getInstance(), Duration.EndOfTurn,
"They gain trample until end of turn"

View file

@ -27,7 +27,7 @@ public final class WurmskinForger extends CardImpl {
this.toughness = new MageInt(2);
// When Wurmskin Forger enters the battlefield, distribute three +1/+1 counters among one, two, or three target creatures.
Ability ability = new EntersBattlefieldTriggeredAbility(new DistributeCountersEffect(CounterType.P1P1, 3, false, "one, two, or three target creatures"), false);
Ability ability = new EntersBattlefieldTriggeredAbility(new DistributeCountersEffect(3, "one, two, or three target creatures"), false);
ability.addTarget(new TargetCreaturePermanentAmount(3));
this.addAbility(ability);
}

View file

@ -99,9 +99,8 @@ class YannikScavengingSentinelEffect extends OneShotEffect {
game.addDelayedTriggeredAbility(new OnLeaveReturnExiledAbility(), source);
if (game.getState().getZone(permanent.getId()) != Zone.BATTLEFIELD) {
ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(
new DistributeCountersEffect(
CounterType.P1P1, power, false, ""
), false, "distribute X +1/+1 counters among any number of target creatures, " +
new DistributeCountersEffect(power, ""), false,
"distribute X +1/+1 counters among any number of target creatures, " +
"where X is the exiled creature's power"
);
ability.addTarget(new TargetCreaturePermanentAmount(power));

View file

@ -1,4 +1,3 @@
package mage.abilities.effects.common.counter;
import mage.abilities.Ability;
@ -24,22 +23,24 @@ public class DistributeCountersEffect extends OneShotEffect {
private final CounterType counterType;
private final DynamicValue amount;
private final boolean removeAtEndOfTurn;
private boolean removeAtEndOfTurn = false;
private final String targetDescription;
/**
* Distribute +1/+1 counters among targets
*/
public DistributeCountersEffect(int amount, String targetDescription) {
this(CounterType.P1P1, StaticValue.get(amount), targetDescription);
}
public DistributeCountersEffect(CounterType counterType, int amount, String targetDescription) {
this(counterType, amount, false, targetDescription);
this(counterType, StaticValue.get(amount), targetDescription);
}
public DistributeCountersEffect(CounterType counterType, int amount, boolean removeAtEndOfTurn, String targetDescription) {
this(counterType, StaticValue.get(amount), removeAtEndOfTurn, targetDescription);
}
public DistributeCountersEffect(CounterType counterType, DynamicValue amount, boolean removeAtEndOfTurn, String targetDescription) {
public DistributeCountersEffect(CounterType counterType, DynamicValue amount, String targetDescription) {
super(Outcome.BoostCreature);
this.counterType = counterType;
this.amount = amount;
this.removeAtEndOfTurn = removeAtEndOfTurn;
this.targetDescription = targetDescription;
}
@ -56,6 +57,11 @@ public class DistributeCountersEffect extends OneShotEffect {
return new DistributeCountersEffect(this);
}
public DistributeCountersEffect withRemoveAtEndOfTurn() {
this.removeAtEndOfTurn = true;
return this;
}
@Override
public boolean apply(Game game, Ability source) {
if (!source.getTargets().isEmpty()) {
@ -99,7 +105,7 @@ class RemoveCountersAtEndOfTurn extends OneShotEffect {
private final CounterType counterType;
public RemoveCountersAtEndOfTurn(CounterType counterType) {
RemoveCountersAtEndOfTurn(CounterType counterType) {
super(Outcome.Detriment);
this.counterType = counterType;
String name = counterType.getName();