Skip to content

Commit

Permalink
refactor: improved ability's modes code (related to #11333)
Browse files Browse the repository at this point in the history
  • Loading branch information
JayDi85 committed Oct 28, 2023
1 parent fec5de8 commit b7ce9c8
Show file tree
Hide file tree
Showing 32 changed files with 162 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2409,7 +2409,7 @@ public Mode chooseMode(Modes modes, Ability source, Game game) {
Mode selectedMode = modes.get(selectedModeId);
if (mode.getId().equals(selectedMode.getId())) {
// mode selected
if (modes.isEachModeMoreThanOnce()) {
if (modes.isMayChooseSameModeMoreThanOnce()) {
// can select again
} else {
// hide mode from dialog
Expand All @@ -2423,7 +2423,7 @@ public Mode chooseMode(Modes modes, Ability source, Game game) {
if (obj != null) {
modeText = modeText.replace("{this}", obj.getName());
}
if (modes.isEachModeMoreThanOnce()) {
if (modes.isMayChooseSameModeMoreThanOnce()) {
if (timesSelected > 0) {
modeText = "(selected " + timesSelected + "x) " + modeText;
}
Expand Down
3 changes: 1 addition & 2 deletions Mage.Sets/src/mage/cards/b/BreechesEagerPillager.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ public BreechesEagerPillager(UUID ownerId, CardSetInfo setInfo) {
new CreateTokenEffect(new TreasureToken()), false, filter
);
ability.setModeTag("treasure");
ability.getModes().setEachModeOnlyOnce(true);
ability.getModes().setResetEachTurn(true);
ability.getModes().setLimitUsageByOnce(true);

// * Target creature can't block this turn.
Mode mode = new Mode(new CantBlockTargetEffect(Duration.EndOfTurn))
Expand Down
2 changes: 1 addition & 1 deletion Mage.Sets/src/mage/cards/b/BrokersConfluence.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public BrokersConfluence(UUID ownerId, CardSetInfo setInfo) {
// Choose three. You may choose the same mode more than once.
this.getSpellAbility().getModes().setMinModes(3);
this.getSpellAbility().getModes().setMaxModes(3);
this.getSpellAbility().getModes().setEachModeMoreThanOnce(true);
this.getSpellAbility().getModes().setMayChooseSameModeMoreThanOnce(true);

// • Proliferate.
this.getSpellAbility().addEffect(new ProliferateEffect());
Expand Down
2 changes: 1 addition & 1 deletion Mage.Sets/src/mage/cards/c/CabarettiConfluence.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public CabarettiConfluence(UUID ownerId, CardSetInfo setInfo) {
// Choose three. You may choose the same mode more than once.
this.getSpellAbility().getModes().setMinModes(3);
this.getSpellAbility().getModes().setMaxModes(3);
this.getSpellAbility().getModes().setEachModeMoreThanOnce(true);
this.getSpellAbility().getModes().setMayChooseSameModeMoreThanOnce(true);

// • Create a token that's a copy of target creature you control. It gains haste. Sacrifice it at the beginning of the next end step.
this.getSpellAbility().addEffect(new CabarettiConfluenceEffect());
Expand Down
2 changes: 1 addition & 1 deletion Mage.Sets/src/mage/cards/c/CaptiveAudience.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public CaptiveAudience(UUID ownerId, CardSetInfo setInfo) {
new SetPlayerLifeSourceEffect(4), TargetController.YOU, false
);
ability.setModeTag("life total becomes 4");
ability.getModes().setEachModeOnlyOnce(true);
ability.getModes().setLimitUsageByOnce(false);

// • Discard your hand.
ability.addMode(
Expand Down
2 changes: 1 addition & 1 deletion Mage.Sets/src/mage/cards/d/DemonicPact.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public DemonicPact(UUID ownerId, CardSetInfo setInfo) {
// - Demonic Pact deals 4 damage to any target and you gain 4 life;
Ability ability = new BeginningOfUpkeepTriggeredAbility(new DamageTargetEffect(4), TargetController.YOU, false);
ability.setModeTag("deals damage and gain life");
ability.getModes().setEachModeOnlyOnce(true);
ability.getModes().setLimitUsageByOnce(false);
ability.addTarget(new TargetAnyTarget());
Effect effect = new GainLifeEffect(4);
effect.setText("and you gain 4 life");
Expand Down
2 changes: 1 addition & 1 deletion Mage.Sets/src/mage/cards/f/FatalLore.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public FatalLore(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{2}{B}{B}");

// An opponent chooses one —
this.getSpellAbility().getModes().setModeChooser(TargetController.OPPONENT);
this.getSpellAbility().getModes().setChooseController(TargetController.OPPONENT);

// • You draw three cards.
this.getSpellAbility().addEffect(new DrawCardSourceControllerEffect(1).setText("you draw three cards"));
Expand Down
2 changes: 1 addition & 1 deletion Mage.Sets/src/mage/cards/f/FieryConfluence.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public FieryConfluence(UUID ownerId, CardSetInfo setInfo) {
// Choose three. You may choose the same mode more than once.
this.getSpellAbility().getModes().setMinModes(3);
this.getSpellAbility().getModes().setMaxModes(3);
this.getSpellAbility().getModes().setEachModeMoreThanOnce(true);
this.getSpellAbility().getModes().setMayChooseSameModeMoreThanOnce(true);

// - Fiery Confluence deals 1 damage to each creature;
this.getSpellAbility().addEffect(new DamageAllEffect(1, new FilterCreaturePermanent()));
Expand Down
3 changes: 1 addition & 2 deletions Mage.Sets/src/mage/cards/g/GalaGreeters.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public GalaGreeters(UUID ownerId, CardSetInfo setInfo) {
// • Put a +1/+1 counter on Gala Greeters.
Ability ability = new AllianceAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance()));
ability.setModeTag("put +1/+1 counter");
ability.getModes().setEachModeOnlyOnce(true);
ability.getModes().setResetEachTurn(true);
ability.getModes().setLimitUsageByOnce(true);

// • Create a tapped Treasure token.
ability.addMode(
Expand Down
3 changes: 1 addition & 2 deletions Mage.Sets/src/mage/cards/g/GaladrielLightOfValinor.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ public GaladrielLightOfValinor(UUID ownerId, CardSetInfo setInfo) {
// • Add {G}{G}{G}.
Ability ability = new AllianceAbility(new AddManaToManaPoolSourceControllerEffect(Mana.GreenMana(3)));
ability.setModeTag("add mana");
ability.getModes().setEachModeOnlyOnce(true);
ability.getModes().setResetEachTurn(true);
ability.getModes().setLimitUsageByOnce(true);

// • Put a +1/+1 counter on each creature you control.
ability.addMode(
Expand Down
2 changes: 1 addition & 1 deletion Mage.Sets/src/mage/cards/g/GandalfTheGrey.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public GandalfTheGrey(UUID ownerId, CardSetInfo setInfo) {
);
ability.setModeTag("tap or untap");
ability.addTarget(new TargetPermanent());
ability.getModes().setEachModeOnlyOnce(true);
ability.getModes().setLimitUsageByOnce(false);

// * Gandalf the Grey deals 3 damage to each opponent.
ability.addMode(
Expand Down
2 changes: 1 addition & 1 deletion Mage.Sets/src/mage/cards/h/HenrikaDomnathi.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public HenrikaDomnathi(UUID ownerId, CardSetInfo setInfo) {
1, StaticFilters.FILTER_CONTROLLED_CREATURE_SHORT_TEXT
), TargetController.YOU, false);
ability.setModeTag("each player sacrifice");
ability.getModes().setEachModeOnlyOnce(true);
ability.getModes().setLimitUsageByOnce(false);

// • You draw a card and you lose 1 life.
Mode mode = new Mode(new DrawCardSourceControllerEffect(1).setText("you draw a card"));
Expand Down
3 changes: 1 addition & 2 deletions Mage.Sets/src/mage/cards/k/KarganIntimidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public KarganIntimidator(UUID ownerId, CardSetInfo setInfo) {
new BoostSourceEffect(1, 1, Duration.EndOfTurn), new GenericManaCost(1)
);
ability.setModeTag("gets +1/+1");
ability.getModes().setEachModeOnlyOnce(true);
ability.getModes().setResetEachTurn(true);
ability.getModes().setLimitUsageByOnce(true);

// • Target creature becomes a Coward until end of turn.
Mode mode = new Mode(new BecomesCreatureTypeTargetEffect(
Expand Down
2 changes: 1 addition & 1 deletion Mage.Sets/src/mage/cards/l/LibraryOfLatNam.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public LibraryOfLatNam(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{4}{U}");

// An opponent chooses one
this.getSpellAbility().getModes().setModeChooser(TargetController.OPPONENT);
this.getSpellAbility().getModes().setChooseController(TargetController.OPPONENT);

// You draw three cards at the beginning of the next turn's upkeep;
this.getSpellAbility().addEffect(new CreateDelayedTriggeredAbilityEffect(new AtTheBeginOfNextUpkeepDelayedTriggeredAbility(new DrawCardSourceControllerEffect(3).setText("you draw three cards")), false));
Expand Down
2 changes: 1 addition & 1 deletion Mage.Sets/src/mage/cards/m/MaestrosConfluence.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public MaestrosConfluence(UUID ownerId, CardSetInfo setInfo) {
// Choose three. You may choose the same mode more than once.
this.getSpellAbility().getModes().setMinModes(3);
this.getSpellAbility().getModes().setMaxModes(3);
this.getSpellAbility().getModes().setEachModeMoreThanOnce(true);
this.getSpellAbility().getModes().setMayChooseSameModeMoreThanOnce(true);

// • Return target monocolored instant or sorcery card from your graveyard to your hand.
this.getSpellAbility().addEffect(new ReturnFromGraveyardToHandTargetEffect());
Expand Down
2 changes: 1 addition & 1 deletion Mage.Sets/src/mage/cards/m/Misfortune.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public Misfortune(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{1}{B}{R}{G}");

// An opponent chooses one —
this.getSpellAbility().getModes().setModeChooser(TargetController.OPPONENT);
this.getSpellAbility().getModes().setChooseController(TargetController.OPPONENT);

// • You put a +1/+1 counter on each creature you control and gain 4 life.
this.getSpellAbility().addEffect(new AddCountersAllEffect(
Expand Down
2 changes: 1 addition & 1 deletion Mage.Sets/src/mage/cards/m/MysticConfluence.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public MysticConfluence(UUID ownerId, CardSetInfo setInfo) {
// Choose three. You may choose the same mode more than once.
this.getSpellAbility().getModes().setMinModes(3);
this.getSpellAbility().getModes().setMaxModes(3);
this.getSpellAbility().getModes().setEachModeMoreThanOnce(true);
this.getSpellAbility().getModes().setMayChooseSameModeMoreThanOnce(true);

// - Counter target spell unless its controller pays {3};
this.getSpellAbility().addEffect(new CounterUnlessPaysEffect(new GenericManaCost(3)));
Expand Down
2 changes: 1 addition & 1 deletion Mage.Sets/src/mage/cards/o/ObscuraConfluence.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public ObscuraConfluence(UUID ownerId, CardSetInfo setInfo) {
// Choose three. You may choose the same mode more than once.
this.getSpellAbility().getModes().setMinModes(3);
this.getSpellAbility().getModes().setMaxModes(3);
this.getSpellAbility().getModes().setEachModeMoreThanOnce(true);
this.getSpellAbility().getModes().setMayChooseSameModeMoreThanOnce(true);

// • Until end of turn, target creature loses all abilities and has base power and toughness 1/1.
this.getSpellAbility().addEffect(new LoseAllAbilitiesTargetEffect(Duration.EndOfTurn)
Expand Down
2 changes: 1 addition & 1 deletion Mage.Sets/src/mage/cards/p/PlanewideCelebration.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public PlanewideCelebration(UUID ownerId, CardSetInfo setInfo) {
// Choose four. You may choose the same mode more than once.
this.getSpellAbility().getModes().setMinModes(4);
this.getSpellAbility().getModes().setMaxModes(4);
this.getSpellAbility().getModes().setEachModeMoreThanOnce(true);
this.getSpellAbility().getModes().setMayChooseSameModeMoreThanOnce(true);

// • Create a 2/2 Citizen creature token that's all colors.
this.getSpellAbility().addEffect(new CreateTokenEffect(new PlanewideCelebrationToken()));
Expand Down
2 changes: 1 addition & 1 deletion Mage.Sets/src/mage/cards/r/RighteousConfluence.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public RighteousConfluence(UUID ownerId, CardSetInfo setInfo) {
// Choose three - You may choose the same mode more than once.
this.getSpellAbility().getModes().setMinModes(3);
this.getSpellAbility().getModes().setMaxModes(3);
this.getSpellAbility().getModes().setEachModeMoreThanOnce(true);
this.getSpellAbility().getModes().setMayChooseSameModeMoreThanOnce(true);

// - Create a 2/2 white Knight creature token with vigilance;
this.getSpellAbility().addEffect(new CreateTokenEffect(new KnightToken()));
Expand Down
2 changes: 1 addition & 1 deletion Mage.Sets/src/mage/cards/r/RiveteersConfluence.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public RiveteersConfluence(UUID ownerId, CardSetInfo setInfo) {
// Choose three. You may choose the same mode more than once.
this.getSpellAbility().getModes().setMinModes(3);
this.getSpellAbility().getModes().setMaxModes(3);
this.getSpellAbility().getModes().setEachModeMoreThanOnce(true);
this.getSpellAbility().getModes().setMayChooseSameModeMoreThanOnce(true);

//• You draw a card and you lose 1 life.
this.getSpellAbility().addEffect(new DrawCardSourceControllerEffect(1).setText("you draw a card"));
Expand Down
2 changes: 1 addition & 1 deletion Mage.Sets/src/mage/cards/s/SolKanarTheTainted.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public SolKanarTheTainted(UUID ownerId, CardSetInfo setInfo) {
new DrawCardSourceControllerEffect(1), TargetController.YOU, false
);
ability.setModeTag("draw");
ability.getModes().setEachModeOnlyOnce(true);
ability.getModes().setLimitUsageByOnce(false);

// * Each opponent loses 2 life and you gain 2 life.
ability.addMode(new Mode(new LoseLifeOpponentsEffect(2))
Expand Down
2 changes: 1 addition & 1 deletion Mage.Sets/src/mage/cards/t/ThreeBowlsOfPorridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public ThreeBowlsOfPorridge(UUID ownerId, CardSetInfo setInfo) {
ability.addCost(new TapSourceCost());
ability.addTarget(new TargetCreaturePermanent());
ability.setModeTag("deals damage");
ability.getModes().setEachModeOnlyOnce(true);
ability.getModes().setLimitUsageByOnce(false);

// * Tap target creature.
Mode mode = new Mode(new TapTargetEffect());
Expand Down
2 changes: 1 addition & 1 deletion Mage.Sets/src/mage/cards/u/UniteTheCoalition.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public UniteTheCoalition(UUID ownerId, CardSetInfo setInfo) {
// Choose five. You may choose the same mode more than once.
this.getSpellAbility().getModes().setMinModes(5);
this.getSpellAbility().getModes().setMaxModes(5);
this.getSpellAbility().getModes().setEachModeMoreThanOnce(true);
this.getSpellAbility().getModes().setMayChooseSameModeMoreThanOnce(true);

// • Target permanent phases out.
this.getSpellAbility().addEffect(new PhaseOutTargetEffect());
Expand Down
2 changes: 1 addition & 1 deletion Mage.Sets/src/mage/cards/v/VerdantConfluence.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public VerdantConfluence(UUID ownerId, CardSetInfo setInfo) {
// Choose three. You may choose the same mode more than once.
this.getSpellAbility().getModes().setMinModes(3);
this.getSpellAbility().getModes().setMaxModes(3);
this.getSpellAbility().getModes().setEachModeMoreThanOnce(true);
this.getSpellAbility().getModes().setMayChooseSameModeMoreThanOnce(true);

// - Put two +1/+1 counters on target creature;
this.getSpellAbility().addEffect(new AddCountersTargetEffect(CounterType.P1P1.createInstance(2)));
Expand Down
2 changes: 1 addition & 1 deletion Mage.Sets/src/mage/cards/v/VindictiveLich.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public VindictiveLich(UUID ownerId, CardSetInfo setInfo) {
));
ability.getModes().setMinModes(1);
ability.getModes().setMaxModes(3);
ability.getModes().setEachModeOnlyOnce(true);
ability.getModes().setLimitUsageByOnce(false);
ability.getModes().setMaxModesFilter(filter0);
ability.addTarget(new TargetPlayer(filter1).setTargetTag(1).withChooseHint("to sacrifice a creature"));

Expand Down
2 changes: 1 addition & 1 deletion Mage.Sets/src/mage/cards/w/WretchedConfluence.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public WretchedConfluence(UUID ownerId, CardSetInfo setInfo) {
// Choose three. You may choose the same mode more than once.
this.getSpellAbility().getModes().setMinModes(3);
this.getSpellAbility().getModes().setMaxModes(3);
this.getSpellAbility().getModes().setEachModeMoreThanOnce(true);
this.getSpellAbility().getModes().setMayChooseSameModeMoreThanOnce(true);

// - Target player draws a card and loses 1 life;
Effect effect = new LoseLifeTargetEffect(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ private boolean handleNonPlayerTargetTarget(String target, Ability ability, Game
Mode selectedMode;
if (targetName.startsWith("mode=")) {
int modeNr = Integer.parseInt(targetName.substring(5, 6));
if (modeNr == 0 || modeNr > (ability.getModes().isEachModeMoreThanOnce() ? ability.getModes().getSelectedModes().size() : ability.getModes().size())) {
if (modeNr == 0 || modeNr > (ability.getModes().isMayChooseSameModeMoreThanOnce() ? ability.getModes().getSelectedModes().size() : ability.getModes().size())) {
throw new UnsupportedOperationException("Given mode number (" + modeNr + ") not available for " + ability.toString());
}
UUID modeId = ability.getModes().getModeId(modeNr);
Expand Down
2 changes: 1 addition & 1 deletion Mage/src/main/java/mage/abilities/AbilityImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ protected static boolean canChooseTargetAbility(Ability ability, Modes modes, Ga

if (validTargets) {
found++;
if (modes.isEachModeMoreThanOnce()) {
if (modes.isMayChooseSameModeMoreThanOnce()) {
return true;
}
if (found >= modes.getMinModes()) {
Expand Down
Loading

0 comments on commit b7ce9c8

Please sign in to comment.