1
0
Fork 0
mirror of https://github.com/correl/mage.git synced 2025-04-08 17:00:07 -09:00

Refactoring and cleaning up based on previous commit

This commit is contained in:
Alex Vasile 2022-08-12 21:33:20 -04:00
parent c0c5c63284
commit 19a896df57
3 changed files with 126 additions and 266 deletions
Mage.Sets/src/mage/cards
Mage/src/main/java/mage/abilities/mana

View file

@ -11,6 +11,7 @@ import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.choices.ChoiceColor;
import mage.constants.CardType;
import mage.constants.ManaType;
import mage.constants.Zone;
import mage.counters.CounterType;
import mage.game.Game;
@ -48,17 +49,13 @@ public final class AstralCornucopia extends CardImpl {
class AstralCornucopiaManaEffect extends ManaEffect {
private final Mana computedMana;
public AstralCornucopiaManaEffect() {
super();
computedMana = new Mana();
this.staticText = "Choose a color. Add one mana of that color for each charge counter on {this}";
}
public AstralCornucopiaManaEffect(final AstralCornucopiaManaEffect effect) {
super(effect);
this.computedMana = effect.computedMana.copy();
}
@Override
@ -69,59 +66,47 @@ class AstralCornucopiaManaEffect extends ManaEffect {
@Override
public List<Mana> getNetMana(Game game, Ability source) {
List<Mana> netMana = new ArrayList<>();
if (game != null) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent != null) {
int counters = sourcePermanent.getCounters(game).getCount(CounterType.CHARGE.getName());
if (counters > 0) {
netMana.add(Mana.AnyMana(counters));
}
}
if (game == null) {
return netMana;
}
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent == null) {
return netMana;
}
int counters = sourcePermanent.getCounters(game).getCount(CounterType.CHARGE.getName());
if (counters > 0) {
netMana.add(Mana.WhiteMana(counters));
netMana.add(Mana.BlueMana(counters));
netMana.add(Mana.BlackMana(counters));
netMana.add(Mana.GreenMana(counters));
netMana.add(Mana.RedMana(counters));
}
return netMana;
}
@Override
public Mana produceMana(Game game, Ability source) {
Mana mana = new Mana();
if (game == null) {
return mana;
return null;
}
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent != null) {
int counters = sourcePermanent.getCounters(game).getCount(CounterType.CHARGE.getName());
if (counters > 0) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
ChoiceColor choice = new ChoiceColor();
choice.setMessage("Choose a color to add mana of that color");
if (controller.choose(outcome, choice, game)) {
if (choice.getChoice() != null) {
String color = choice.getChoice();
switch (color) {
case "Red":
mana.setRed(counters);
break;
case "Blue":
mana.setBlue(counters);
break;
case "White":
mana.setWhite(counters);
break;
case "Black":
mana.setBlack(counters);
break;
case "Green":
mana.setGreen(counters);
break;
}
}
}
}
}
Player controller = game.getPlayer(source.getControllerId());
if (sourcePermanent == null || controller == null) {
return null;
}
int counters = sourcePermanent.getCounters(game).getCount(CounterType.CHARGE.getName());
if (counters == 0) {
return null;
}
return mana;
}
ChoiceColor choice = new ChoiceColor();
choice.setMessage("Choose a color to add mana of that color");
if (!controller.choose(outcome, choice, game)) {
return null;
}
ManaType chosenType = ManaType.findByName(choice.getChoice());
return chosenType == null ? null : new Mana(chosenType);
}
}

View file

@ -9,18 +9,15 @@ import mage.abilities.mana.SimpleManaAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.choices.Choice;
import mage.choices.ChoiceColor;
import mage.constants.CardType;
import mage.constants.ColoredManaSymbol;
import mage.constants.ManaType;
import mage.constants.Zone;
import mage.filter.common.FilterControlledPermanent;
import mage.filter.StaticFilters;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.*;
/**
* @author anonymous
@ -47,11 +44,9 @@ public final class MeteorCrater extends CardImpl {
class MeteorCraterEffect extends ManaEffect {
/**
* *
* 04/10/2004 You can't choose "colorless". You have to choose one of the
* five colors.
*/
private static final FilterControlledPermanent filter = new FilterControlledPermanent();
public MeteorCraterEffect() {
super();
@ -64,110 +59,60 @@ class MeteorCraterEffect extends ManaEffect {
@Override
public List<Mana> getNetMana(Game game, Ability source) {
List<Mana> netManas = new ArrayList<>();
Mana types = getManaTypes(game, source);
if (types.getBlack() > 0) {
netManas.add(new Mana(ColoredManaSymbol.B));
}
if (types.getRed() > 0) {
netManas.add(new Mana(ColoredManaSymbol.R));
}
if (types.getBlue() > 0) {
netManas.add(new Mana(ColoredManaSymbol.U));
}
if (types.getGreen() > 0) {
netManas.add(new Mana(ColoredManaSymbol.G));
}
if (types.getWhite() > 0) {
netManas.add(new Mana(ColoredManaSymbol.W));
}
return netManas;
return game == null ? new ArrayList<>() : ManaType.getManaListFromManaTypes(getManaTypes(game, source), true);
}
@Override
public Mana produceMana(Game game, Ability source) {
Mana mana = new Mana();
if (game == null) {
return mana;
return null;
}
Mana types = getManaTypes(game, source);
Choice choice = new ChoiceColor(true);
choice.getChoices().clear();
choice.setMessage("Pick a mana color");
if (types.getAny() > 0) {
choice.getChoices().add("Black");
choice.getChoices().add("Red");
choice.getChoices().add("Blue");
choice.getChoices().add("Green");
choice.getChoices().add("White");
Set<ManaType> types = getManaTypes(game, source);
if (types.isEmpty()) {
return null;
}
Choice choice = ManaType.getChoiceOfManaTypes(types, true);
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
if (types.getBlack() > 0) {
choice.getChoices().add("Black");
}
if (types.getRed() > 0) {
choice.getChoices().add("Red");
}
if (types.getBlue() > 0) {
choice.getChoices().add("Blue");
}
if (types.getGreen() > 0) {
choice.getChoices().add("Green");
}
if (types.getWhite() > 0) {
choice.getChoices().add("White");
}
}
if (!choice.getChoices().isEmpty()) {
Player player = game.getPlayer(source.getControllerId());
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
player.choose(outcome, choice, game);
}
if (choice.getChoice() != null) {
switch (choice.getChoice()) {
case "Black":
mana.setBlack(1);
break;
case "Blue":
mana.setBlue(1);
break;
case "Red":
mana.setRed(1);
break;
case "Green":
mana.setGreen(1);
break;
case "White":
mana.setWhite(1);
break;
}
if (player == null || !player.choose(outcome, choice, game)) {
return null;
}
}
return mana;
ManaType chosenType = ManaType.findByName(choice.getChoice());
return chosenType == null ? null : new Mana(chosenType);
}
private Mana getManaTypes(Game game, Ability source) {
Mana types = new Mana();
if (game != null) {
List<Permanent> controlledPermanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game);
for (Permanent permanent : controlledPermanents) {
ObjectColor color = permanent.getColor(game);
if (color.isBlack()) {
types.add(Mana.BlackMana(1));
}
if (color.isBlue()) {
types.add(Mana.BlueMana(1));
}
if (color.isGreen()) {
types.add(Mana.GreenMana(1));
}
if (color.isRed()) {
types.add(Mana.RedMana(1));
}
if (color.isWhite()) {
types.add(Mana.WhiteMana(1));
}
private Set<ManaType> getManaTypes(Game game, Ability source) {
Set<ManaType> types = new HashSet<>(5);
if (game == null) {
return types;
}
List<Permanent> controlledPermanents = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_CONTROLLED_PERMANENT, source.getControllerId(), game);
for (Permanent permanent : controlledPermanents) {
ObjectColor color = permanent.getColor(game);
if (color.isBlack()) {
types.add(ManaType.BLACK);
}
if (color.isBlue()) {
types.add(ManaType.BLUE);
}
if (color.isGreen()) {
types.add(ManaType.GREEN);
}
if (color.isRed()) {
types.add(ManaType.RED);
}
if (color.isWhite()) {
types.add(ManaType.WHITE);
}
// If all types are already added, exit early
if (types.size() == 5) {
break;
}
}
return types;

View file

@ -6,8 +6,7 @@ import mage.abilities.Ability;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.effects.mana.ManaEffect;
import mage.choices.Choice;
import mage.choices.ChoiceColor;
import mage.constants.ColoredManaSymbol;
import mage.constants.ManaType;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.filter.FilterPermanent;
@ -16,7 +15,9 @@ import mage.game.permanent.Permanent;
import mage.players.Player;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* @author CountAndromalius
@ -24,11 +25,7 @@ import java.util.List;
public class AnyColorPermanentTypesManaAbility extends ActivatedManaAbilityImpl {
public AnyColorPermanentTypesManaAbility(TargetController targetController, FilterPermanent permanentTypes) {
this(targetController, true, permanentTypes);
}
public AnyColorPermanentTypesManaAbility(TargetController targetController, boolean onlyColors, FilterPermanent permanentTypes) {
super(Zone.BATTLEFIELD, new AnyColorPermanentTypesManaEffect(targetController, onlyColors, permanentTypes), new TapSourceCost());
super(Zone.BATTLEFIELD, new AnyColorPermanentTypesManaEffect(targetController, permanentTypes), new TapSourceCost());
}
public AnyColorPermanentTypesManaAbility(final AnyColorPermanentTypesManaAbility ability) {
@ -55,155 +52,88 @@ public class AnyColorPermanentTypesManaAbility extends ActivatedManaAbilityImpl
class AnyColorPermanentTypesManaEffect extends ManaEffect {
private final FilterPermanent filter;
private final boolean onlyColors; // false if mana types can be produced (also Colorless mana), if true only colors can be produced (no Colorless mana).
private boolean inManaTypeCalculation = false;
private transient boolean inManaTypeCalculation = false;
public AnyColorPermanentTypesManaEffect(TargetController targetController, boolean onlyColors, FilterPermanent permanentTypes) {
public AnyColorPermanentTypesManaEffect(TargetController targetController, FilterPermanent permanentTypes) {
super();
filter = permanentTypes;
this.onlyColors = onlyColors;
filter.add(targetController.getControllerPredicate());
String text = targetController == TargetController.OPPONENT ? "an opponent controls." : "you control.";
staticText = "Add one mana of any " + (this.onlyColors ? "color" : "type") + " among " + permanentTypes.getMessage() + " " + text;
staticText = "Add one mana of any color" +
" among " + permanentTypes.getMessage() + " " +
(targetController == TargetController.OPPONENT ? "an opponent controls." : "you control.");
}
public AnyColorPermanentTypesManaEffect(final AnyColorPermanentTypesManaEffect effect) {
super(effect);
this.filter = effect.filter.copy();
this.onlyColors = effect.onlyColors;
}
@Override
public List<Mana> getNetMana(Game game, Ability source) {
List<Mana> netManas = new ArrayList<>();
Mana types = getManaTypes(game, source);
if (types.getBlack() > 0) {
netManas.add(new Mana(ColoredManaSymbol.B));
}
if (types.getRed() > 0) {
netManas.add(new Mana(ColoredManaSymbol.R));
}
if (types.getBlue() > 0) {
netManas.add(new Mana(ColoredManaSymbol.U));
}
if (types.getGreen() > 0) {
netManas.add(new Mana(ColoredManaSymbol.G));
}
if (types.getWhite() > 0) {
netManas.add(new Mana(ColoredManaSymbol.W));
}
if (!onlyColors && types.getColorless() > 0) {
netManas.add(Mana.ColorlessMana(1));
}
if (types.getAny() > 0) {
netManas.add(Mana.AnyMana(1));
}
return netManas;
return game == null ? new ArrayList<>() : ManaType.getManaListFromManaTypes(getManaTypes(game, source), true);
}
@Override
public Mana produceMana(Game game, Ability source) {
Mana mana = new Mana();
if (game == null) {
return mana;
return null;
}
Mana types = getManaTypes(game, source);
Choice choice = new ChoiceColor(true);
choice.getChoices().clear();
choice.setMessage("Pick a mana color");
if (types.getBlack() > 0) {
choice.getChoices().add("Black");
}
if (types.getRed() > 0) {
choice.getChoices().add("Red");
}
if (types.getBlue() > 0) {
choice.getChoices().add("Blue");
}
if (types.getGreen() > 0) {
choice.getChoices().add("Green");
}
if (types.getWhite() > 0) {
choice.getChoices().add("White");
}
if (!onlyColors && types.getColorless() > 0) {
choice.getChoices().add("Colorless");
}
if (types.getAny() > 0) {
choice.getChoices().add("Black");
choice.getChoices().add("Red");
choice.getChoices().add("Blue");
choice.getChoices().add("Green");
choice.getChoices().add("White");
if (!onlyColors) {
choice.getChoices().add("Colorless");
}
Set<ManaType> types = getManaTypes(game, source);
if (types.isEmpty()) {
return null;
}
if (!choice.getChoices().isEmpty()) {
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 (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
if (!player.choose(outcome, choice, game)) {
return mana;
}
}
if (choice.getChoice() != null) {
switch (choice.getChoice()) {
case "Black":
mana.setBlack(1);
break;
case "Blue":
mana.setBlue(1);
break;
case "Red":
mana.setRed(1);
break;
case "Green":
mana.setGreen(1);
break;
case "White":
mana.setWhite(1);
break;
case "Colorless":
mana.setColorless(1);
break;
}
if (player == null || !player.choose(outcome, choice, game)) {
return null;
}
}
return mana;
ManaType chosenType = ManaType.findByName(choice.getChoice());
return chosenType == null ? null : new Mana(chosenType);
}
private Mana getManaTypes(Game game, Ability source) {
Mana types = new Mana();
if (game == null || game.getPhase() == null) {
return types;
}
if (inManaTypeCalculation) {
return types;
private Set<ManaType> getManaTypes(Game game, Ability source) {
Set<ManaType> manaTypes = new HashSet<>(6);
if (game == null || game.getPhase() == null || inManaTypeCalculation) {
return manaTypes;
}
inManaTypeCalculation = true;
ObjectColor permanentColor;
List<Permanent> permanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source, game);
for (Permanent permanent : permanents) {
permanentColor = permanent.getColor(game);
if (permanentColor.isColorless()) {
types.add(Mana.ColorlessMana(1));
} else {
List<ObjectColor> permanentColors = permanent.getColor(game).getColors();
for (ObjectColor color : permanentColors) {
types.add(new Mana(color.getOneColoredManaSymbol()));
}
if (permanentColor.isBlack()) {
manaTypes.add(ManaType.BLACK);
}
if (permanentColor.isBlue()) {
manaTypes.add(ManaType.BLUE);
}
if (permanentColor.isGreen()) {
manaTypes.add(ManaType.GREEN);
}
if (permanentColor.isRed()) {
manaTypes.add(ManaType.RED);
}
if (permanentColor.isWhite()) {
manaTypes.add(ManaType.WHITE);
}
// If all types are already added, exit early
if (manaTypes.size() == 5) {
break;
}
}
inManaTypeCalculation = false;
return types;
return manaTypes;
}
@Override