Skip to content

Commit

Permalink
refactor: additional improves for mana choice in some cards, related …
Browse files Browse the repository at this point in the history
…to Naked Singularity from 81039d6
  • Loading branch information
JayDi85 committed Sep 23, 2023
1 parent 81039d6 commit 0bf4b63
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 30 deletions.
32 changes: 20 additions & 12 deletions Mage.Sets/src/mage/cards/b/BenthicExplorers.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@
import mage.players.Player;
import mage.target.common.TargetLandPermanent;

import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.*;

/**
* @author jeffwadsworth
Expand Down Expand Up @@ -110,22 +106,32 @@ public List<Mana> getNetMana(Game game, Ability source) {
@Override
public Mana produceMana(Game game, Ability source) {
Mana mana = new Mana();
if (game == null) { return mana; }
if (game == null) {
return mana;
}

Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return mana;
}

Choice choice = ManaType.getChoiceOfManaTypes(getManaTypes(game, source), false);
if (choice.getChoices().isEmpty()) { return mana; }
if (choice.getChoices().isEmpty()) {
return mana;
}


Player player = game.getPlayer(source.getControllerId());
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
if (player == null
|| !player.choose(Outcome.Neutral, choice, game)) {
if (!player.choose(Outcome.PutManaInPool, choice, game)) {
return mana;
}
}

if (choice.getChoice() == null) { return mana; }
if (choice.getChoice() == null) {
return mana;
}

switch (choice.getChoice()) {
case "Black":
Expand Down Expand Up @@ -160,7 +166,9 @@ private Set<ManaType> getManaTypes(Game game, Ability source) {
List<UUID> untapped = (List<UUID>) game.getState()
.getValue("UntapTargetCost" + source.getSourceId().toString());
Permanent land = game.getPermanentOrLKIBattlefield(untapped.get(0));
if (land == null) { return types; }
if (land == null) {
return types;
}

Abilities<ActivatedManaAbilityImpl> mana = land.getAbilities().getActivatedManaAbilities(Zone.BATTLEFIELD);
for (ActivatedManaAbilityImpl ability : mana) {
Expand Down
2 changes: 1 addition & 1 deletion Mage.Sets/src/mage/cards/c/ChromeMox.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public Mana produceMana(Game game, Ability source) {
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
if (!player.choose(outcome, choice, game)) {
if (!player.choose(Outcome.PutManaInPool, choice, game)) {
return mana;
}
}
Expand Down
3 changes: 2 additions & 1 deletion Mage.Sets/src/mage/cards/c/CorruptedGrafstone.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import mage.choices.ChoiceColor;
import mage.constants.CardType;
import mage.constants.ColoredManaSymbol;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
import mage.players.Player;
Expand Down Expand Up @@ -148,7 +149,7 @@ public Mana produceMana(Game game, Ability source) {
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
if (!player.choose(outcome, choice, game)) {
if (!player.choose(Outcome.PutManaInPool, choice, game)) {
return mana;
}
}
Expand Down
6 changes: 5 additions & 1 deletion Mage.Sets/src/mage/cards/i/IncubationDruid.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import mage.choices.Choice;
import mage.choices.ChoiceColor;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.counters.CounterType;
Expand Down Expand Up @@ -140,9 +141,12 @@ public Mana produceMana(Game game, Ability source) {
}
if (!choice.getChoices().isEmpty()) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return mana;
}
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else if (player == null || !player.choose(outcome, choice, game)) {
} else if (!player.choose(Outcome.PutManaInPool, choice, game)) {
return mana;
}
if (choice.getChoice() != null) {
Expand Down
2 changes: 1 addition & 1 deletion Mage.Sets/src/mage/cards/k/KatildaDawnhartPrime.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public Mana produceMana(Game game, Ability source) {
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
controller.choose(outcome, choice, game);
controller.choose(Outcome.PutManaInPool, choice, game);
}
if (choice.getChoice() == null) {
return new Mana();
Expand Down
10 changes: 8 additions & 2 deletions Mage.Sets/src/mage/cards/m/MeteorCrater.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import mage.choices.Choice;
import mage.constants.CardType;
import mage.constants.ManaType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.StaticFilters;
import mage.game.Game;
Expand Down Expand Up @@ -72,12 +73,17 @@ public Mana produceMana(Game game, Ability source) {
if (types.isEmpty()) {
return null;
}

Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return null;
}

Choice choice = ManaType.getChoiceOfManaTypes(types, true);
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
Player player = game.getPlayer(source.getControllerId());
if (player == null || !player.choose(outcome, choice, game)) {
if (!player.choose(Outcome.PutManaInPool, choice, game)) {
return null;
}
}
Expand Down
14 changes: 12 additions & 2 deletions Mage.Sets/src/mage/cards/r/RealityTwist.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,16 @@ public boolean replaceEvent(GameEvent event, Ability source, Game game) {
String chosenColor;
if (choice.getChoices().size() == 1) {
chosenColor = choice.getChoices().iterator().next();
} else if (choice.getChoices().size() == 0) {
chosenColor = null;
} else {
controller.choose(Outcome.PutManaInPool, choice, game);
chosenColor = choice.getChoice();
// workaround to skip choose dialog in check playable state
if (game.inCheckPlayableState()) {
chosenColor = "Any";
} else {
controller.choose(Outcome.PutManaInPool, choice, game);
chosenColor = choice.getChoice();
}
}
if (chosenColor == null) {
return false;
Expand All @@ -117,6 +124,9 @@ public boolean replaceEvent(GameEvent event, Ability source, Game game) {
case "Green":
mana.setToMana(Mana.GreenMana(amount));
break;
case "Any":
mana.setToMana(Mana.AnyMana(amount));
break;
}
return false;
}
Expand Down
18 changes: 14 additions & 4 deletions Mage.Sets/src/mage/cards/s/SasayaOrochiAscendant.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,21 @@ public Mana produceMana(Game game, Ability source) {

for (int i = 0; i < count; i++) {
choice.clearChoice();
String chosenColor;
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
chosenColor = choice.getChoices().iterator().next();
} else {
if (!controller.choose(outcome, choice, game)) {
return newMana;
// workaround to skip choose dialog in check playable state
if (game.inCheckPlayableState()) {
chosenColor = "Any";
} else {
if (!controller.choose(Outcome.PutManaInPool, choice, game)) {
return newMana;
}
chosenColor = choice.getChoice();
}
}
switch (choice.getChoice()) {
switch (chosenColor) {
case "Black":
newMana.increaseBlack();
break;
Expand All @@ -252,6 +259,9 @@ public Mana produceMana(Game game, Ability source) {
case "Colorless":
newMana.increaseColorless();
break;
case "Any":
newMana.increaseAny();
break;
}
}

Expand Down
3 changes: 2 additions & 1 deletion Mage.Sets/src/mage/cards/s/SquanderedResources.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import mage.choices.Choice;
import mage.constants.CardType;
import mage.constants.ManaType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.StaticFilters;
import mage.filter.common.FilterControlledLandPermanent;
Expand Down Expand Up @@ -100,7 +101,7 @@ public Mana produceMana(Game game, Ability source) {
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
if (!player.choose(outcome, choice, game)) {
if (!player.choose(Outcome.PutManaInPool, choice, game)) {
return mana;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Mage.Sets/src/mage/cards/t/TazriStalwartSurvivor.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public Mana produceMana(Game game, Ability source) {
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
controller.choose(outcome, choice, game);
controller.choose(Outcome.PutManaInPool, choice, game);
}
if (choice.getChoice() == null) {
return new Mana();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import mage.cards.Card;
import mage.choices.Choice;
import mage.constants.ManaType;
import mage.constants.Outcome;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.filter.FilterCard;
Expand Down Expand Up @@ -88,7 +89,7 @@ public Mana produceMana(Game game, Ability source) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
Player player = game.getPlayer(source.getControllerId());
if (player == null || !player.choose(outcome, choice, game)) {
if (player == null || !player.choose(Outcome.PutManaInPool, choice, game)) {
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.effects.mana.ManaEffect;
import mage.choices.Choice;
import mage.constants.Outcome;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.filter.FilterPermanent;
Expand Down Expand Up @@ -117,7 +118,7 @@ public Mana produceMana(Game game, Ability source) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
Player player = game.getPlayer(source.getControllerId());
if (player == null || !player.choose(outcome, choice, game)) {
if (player == null || !player.choose(Outcome.PutManaInPool, choice, game)) {
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import mage.abilities.effects.mana.ManaEffect;
import mage.choices.Choice;
import mage.constants.ManaType;
import mage.constants.Outcome;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.filter.FilterPermanent;
Expand Down Expand Up @@ -90,7 +91,7 @@ public Mana produceMana(Game game, Ability source) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
Player player = game.getPlayer(source.getControllerId());
if (player == null || !player.choose(outcome, choice, game)) {
if (player == null || !player.choose(Outcome.PutManaInPool, choice, game)) {
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import mage.choices.ChoiceImpl;
import mage.constants.ColoredManaSymbol;
import mage.constants.CommanderCardType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.FilterMana;
import mage.game.Game;
Expand Down Expand Up @@ -132,7 +133,7 @@ public Mana produceMana(Game game, Ability source) {
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
if (!controller.choose(outcome, choice, game)) {
if (!controller.choose(Outcome.PutManaInPool, choice, game)) {
return mana;
}
}
Expand Down

0 comments on commit 0bf4b63

Please sign in to comment.