1
0
Fork 0
mirror of https://github.com/correl/mage.git synced 2025-04-06 01:04:10 -09:00

add mana-generation helpers to ChoiceColor

This commit is contained in:
Neil Gentleman 2016-07-17 23:27:09 -07:00
parent ec87dd4c94
commit 0125f88611
12 changed files with 55 additions and 144 deletions

View file

@ -107,17 +107,7 @@ class CoalitionRelicEffect extends OneShotEffect {
} }
player.choose(outcome, choice, game); player.choose(outcome, choice, game);
} }
if (choice.getColor().isBlack()) { choice.increaseMana(mana);
mana.increaseBlack();
} else if (choice.getColor().isBlue()) {
mana.increaseBlue();
} else if (choice.getColor().isRed()) {
mana.increaseRed();
} else if (choice.getColor().isGreen()) {
mana.increaseGreen();
} else if (choice.getColor().isWhite()) {
mana.increaseWhite();
}
choice.clearChoice(); choice.clearChoice();
} }
player.getManaPool().addMana(mana, game, source); player.getManaPool().addMana(mana, game, source);

View file

@ -140,17 +140,7 @@ class DawnsReflectionManaEffect extends ManaEffect {
while (controller.canRespond() && !controller.choose(Outcome.Benefit, choiceColor, game)) { while (controller.canRespond() && !controller.choose(Outcome.Benefit, choiceColor, game)) {
} }
if (choiceColor.getColor().isBlack()) { choiceColor.increaseMana(mana);
mana.increaseBlack();
} else if (choiceColor.getColor().isBlue()) {
mana.increaseBlue();
} else if (choiceColor.getColor().isRed()) {
mana.increaseRed();
} else if (choiceColor.getColor().isGreen()) {
mana.increaseGreen();
} else if (choiceColor.getColor().isWhite()) {
mana.increaseWhite();
}
} }
controller.getManaPool().addMana(mana, game, source); controller.getManaPool().addMana(mana, game, source);

View file

@ -30,7 +30,6 @@ package mage.cards.f;
import java.util.UUID; import java.util.UUID;
import mage.ConditionalMana; import mage.ConditionalMana;
import mage.Mana; import mage.Mana;
import mage.ObjectColor;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.costs.Cost; import mage.abilities.costs.Cost;
import mage.abilities.costs.common.ExileTargetCost; import mage.abilities.costs.common.ExileTargetCost;
@ -116,22 +115,11 @@ class FoodChainManaEffect extends ManaEffect {
} }
ChoiceColor choice = new ChoiceColor(); ChoiceColor choice = new ChoiceColor();
controller.choose(Outcome.PutManaInPool, choice, game); controller.choose(Outcome.PutManaInPool, choice, game);
ObjectColor chosenColor = choice.getColor(); if (choice.getColor() == null) {
if (chosenColor == null) {
return false; return false;
} }
Mana mana = null; Mana chosen = choice.getMana(manaCostExiled + 1);
if (chosenColor.isBlack()) { Mana mana = new FoodChainManaBuilder().setMana(chosen, source, game).build();
mana = new FoodChainManaBuilder().setMana(Mana.BlackMana(manaCostExiled + 1), source, game).build();
} else if (chosenColor.isBlue()) {
mana = new FoodChainManaBuilder().setMana(Mana.BlueMana(manaCostExiled + 1), source, game).build();
} else if (chosenColor.isRed()) {
mana = new FoodChainManaBuilder().setMana(Mana.RedMana(manaCostExiled + 1), source, game).build();
} else if (chosenColor.isGreen()) {
mana = new FoodChainManaBuilder().setMana(Mana.GreenMana(manaCostExiled + 1), source, game).build();
} else if (chosenColor.isWhite()) {
mana = new FoodChainManaBuilder().setMana(Mana.WhiteMana(manaCostExiled + 1), source, game).build();
}
if (mana != null) { if (mana != null) {
checkToFirePossibleEvents(mana, game, source); checkToFirePossibleEvents(mana, game, source);
controller.getManaPool().addMana(mana, game, source); controller.getManaPool().addMana(mana, game, source);

View file

@ -135,11 +135,11 @@ class MarketFestivalManaEffect extends ManaEffect {
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId()); MageObject sourceObject = game.getObject(source.getSourceId());
if(controller != null && sourceObject != null){ if (controller != null && sourceObject != null) {
int x = 2; int x = 2;
Mana mana = new Mana(); Mana mana = new Mana();
for(int i = 0; i < x; i++){ for (int i = 0; i < x; i++) {
ChoiceColor choiceColor = new ChoiceColor(); ChoiceColor choiceColor = new ChoiceColor();
if (i == 0) { if (i == 0) {
choiceColor.setMessage("First mana color for " + sourceObject.getLogName()); choiceColor.setMessage("First mana color for " + sourceObject.getLogName());
@ -152,22 +152,11 @@ class MarketFestivalManaEffect extends ManaEffect {
} }
} }
if (choiceColor.getColor().isBlack()) { choiceColor.increaseMana(mana);
mana.increaseBlack();
} else if (choiceColor.getColor().isBlue()) {
mana.increaseBlue();
} else if (choiceColor.getColor().isRed()) {
mana.increaseRed();
} else if (choiceColor.getColor().isGreen()) {
mana.increaseGreen();
} else if (choiceColor.getColor().isWhite()) {
mana.increaseWhite();
}
} }
checkToFirePossibleEvents(mana, game, source); checkToFirePossibleEvents(mana, game, source);
controller.getManaPool().addMana(mana, game, source); controller.getManaPool().addMana(mana, game, source);
return true; return true;
} }
return false; return false;
} }

View file

@ -134,17 +134,7 @@ class PlasmCaptureManaEffect extends ManaEffect {
} }
} }
if (choiceColor.getColor().isBlack()) { choiceColor.increaseMana(mana);
mana.increaseBlack();
} else if (choiceColor.getColor().isBlue()) {
mana.increaseBlue();
} else if (choiceColor.getColor().isRed()) {
mana.increaseRed();
} else if (choiceColor.getColor().isGreen()) {
mana.increaseGreen();
} else if (choiceColor.getColor().isWhite()) {
mana.increaseWhite();
}
} }
player.getManaPool().addMana(mana, game, source); player.getManaPool().addMana(mana, game, source);

View file

@ -156,24 +156,13 @@ class VedalkenEngineerEffect extends ManaEffect {
return false; return false;
} }
Mana mana = new Mana();
ChoiceColor choiceColor = new ChoiceColor(true); ChoiceColor choiceColor = new ChoiceColor(true);
while (!controller.choose(Outcome.Benefit, choiceColor, game)) { while (!controller.choose(Outcome.Benefit, choiceColor, game)) {
if (!controller.canRespond()) { if (!controller.canRespond()) {
return false; return false;
} }
} }
if (choiceColor.getColor().isBlack()) { Mana mana = choiceColor.getMana(amount);
mana.setBlack(amount);
} else if (choiceColor.getColor().isBlue()) {
mana.setBlue(amount);
} else if (choiceColor.getColor().isRed()) {
mana.setRed(amount);
} else if (choiceColor.getColor().isGreen()) {
mana.setGreen(amount);
} else if (choiceColor.getColor().isWhite()) {
mana.setWhite(amount);
}
Mana condMana = manaBuilder.setMana(mana, source, game).build(); Mana condMana = manaBuilder.setMana(mana, source, game).build();
checkToFirePossibleEvents(condMana, game, source); checkToFirePossibleEvents(condMana, game, source);
controller.getManaPool().addMana(condMana, game, source); controller.getManaPool().addMana(condMana, game, source);

View file

@ -90,17 +90,7 @@ public class ConditionalManaEffect extends ManaEffect {
return false; // it happens, don't know how return false; // it happens, don't know how
} }
if (choice.getColor().isBlack()) { createdMana = choice.getMana(amount);
createdMana = Mana.BlackMana(amount);
} else if (choice.getColor().isBlue()) {
createdMana = Mana.BlueMana(amount);
} else if (choice.getColor().isRed()) {
createdMana = Mana.RedMana(amount);
} else if (choice.getColor().isGreen()) {
createdMana = Mana.GreenMana(amount);
} else if (choice.getColor().isWhite()) {
createdMana = Mana.WhiteMana(amount);
}
} }
mana = createdMana; mana = createdMana;
} }
@ -117,8 +107,7 @@ public class ConditionalManaEffect extends ManaEffect {
} }
@Override @Override
public Mana getMana(Game game, Ability source public Mana getMana(Game game, Ability source) {
) {
Mana mana = null; Mana mana = null;
if (condition.apply(game, source)) { if (condition.apply(game, source)) {
mana = effect.getMana(); mana = effect.getMana();

View file

@ -94,19 +94,10 @@ public class AddConditionalManaOfAnyColorEffect extends ManaEffect {
return false; return false;
} }
} }
Mana mana = null; Mana mana = choice.getMana(1);
if (choice.getColor().isBlack()) { if (mana != null) {
mana = manaBuilder.setMana(Mana.BlackMana(1), source, game).build(); mana = manaBuilder.setMana(mana, source, game).build();
} else if (choice.getColor().isBlue()) {
mana = manaBuilder.setMana(Mana.BlueMana(1), source, game).build();
} else if (choice.getColor().isRed()) {
mana = manaBuilder.setMana(Mana.RedMana(1), source, game).build();
} else if (choice.getColor().isGreen()) {
mana = manaBuilder.setMana(Mana.GreenMana(1), source, game).build();
} else if (choice.getColor().isWhite()) {
mana = manaBuilder.setMana(Mana.WhiteMana(1), source, game).build();
} }
if (mana != null) { if (mana != null) {
checkToFirePossibleEvents(mana, game, source); checkToFirePossibleEvents(mana, game, source);
controller.getManaPool().addMana(mana, game, source); controller.getManaPool().addMana(mana, game, source);

View file

@ -64,22 +64,10 @@ public class AddManaAnyColorAttachedControllerEffect extends ManaEffect {
return false; return false;
} }
} }
int amount = 1; Mana mana = choice.getMana(1);
Mana mana = null;
if (choice.getColor().isBlack()) {
mana = Mana.BlackMana(amount);
} else if (choice.getColor().isBlue()) {
mana = Mana.BlueMana(amount);
} else if (choice.getColor().isRed()) {
mana = Mana.RedMana(amount);
} else if (choice.getColor().isGreen()) {
mana = Mana.GreenMana(amount);
} else if (choice.getColor().isWhite()) {
mana = Mana.WhiteMana(amount);
}
if (mana != null) { if (mana != null) {
checkToFirePossibleEvents(mana, game, source); checkToFirePossibleEvents(mana, game, source);
player.getManaPool().addMana(mana, game, source); player.getManaPool().addMana(mana, game, source);
return true; return true;
} }
} }

View file

@ -46,7 +46,7 @@ public class AddManaOfAnyColorEffect extends BasicManaEffect {
} }
public AddManaOfAnyColorEffect(final int amount) { public AddManaOfAnyColorEffect(final int amount) {
super(new Mana(0,0,0,0,0,0, amount, 0)); super(new Mana(0, 0, 0, 0, 0, 0, amount, 0));
this.amount = amount; this.amount = amount;
this.staticText = new StringBuilder("add ") this.staticText = new StringBuilder("add ")
.append(CardUtil.numberToText(amount)) .append(CardUtil.numberToText(amount))
@ -75,18 +75,7 @@ public class AddManaOfAnyColorEffect extends BasicManaEffect {
if (choice.getColor() == null) { if (choice.getColor() == null) {
return false; // it happens, don't know how return false; // it happens, don't know how
} }
Mana createdMana = null; Mana createdMana = choice.getMana(amount);
if (choice.getColor().isBlack()) {
createdMana = Mana.BlackMana(amount);
} else if (choice.getColor().isBlue()) {
createdMana = Mana.BlueMana(amount);
} else if (choice.getColor().isRed()) {
createdMana = Mana.RedMana(amount);
} else if (choice.getColor().isGreen()) {
createdMana = Mana.GreenMana(amount);
} else if (choice.getColor().isWhite()) {
createdMana = Mana.WhiteMana(amount);
}
if (createdMana != null) { if (createdMana != null) {
checkToFirePossibleEvents(createdMana, game, source); checkToFirePossibleEvents(createdMana, game, source);
controller.getManaPool().addMana(createdMana, game, source); controller.getManaPool().addMana(createdMana, game, source);
@ -103,7 +92,7 @@ public class AddManaOfAnyColorEffect extends BasicManaEffect {
@Override @Override
public Mana getMana() { public Mana getMana() {
return (new Mana(0,0,0,0,0,0,amount, 0)); return new Mana(0, 0, 0, 0, 0, 0, amount, 0);
} }
} }

View file

@ -42,7 +42,6 @@ import mage.players.Player;
*/ */
public class DynamicManaEffect extends BasicManaEffect { public class DynamicManaEffect extends BasicManaEffect {
private final Mana computedMana;
private final DynamicValue amount; private final DynamicValue amount;
private final DynamicValue netAmount; private final DynamicValue netAmount;
private String text = null; private String text = null;
@ -73,7 +72,6 @@ public class DynamicManaEffect extends BasicManaEffect {
public DynamicManaEffect(Mana mana, DynamicValue amount, String text, boolean oneChoice, DynamicValue netAmount) { public DynamicManaEffect(Mana mana, DynamicValue amount, String text, boolean oneChoice, DynamicValue netAmount) {
super(mana); super(mana);
this.amount = amount; this.amount = amount;
computedMana = new Mana();
this.text = text; this.text = text;
this.oneChoice = oneChoice; this.oneChoice = oneChoice;
this.netAmount = netAmount; this.netAmount = netAmount;
@ -81,7 +79,6 @@ public class DynamicManaEffect extends BasicManaEffect {
public DynamicManaEffect(final DynamicManaEffect effect) { public DynamicManaEffect(final DynamicManaEffect effect) {
super(effect); super(effect);
this.computedMana = effect.computedMana.copy();
this.amount = effect.amount.copy(); this.amount = effect.amount.copy();
this.text = effect.text; this.text = effect.text;
this.oneChoice = effect.oneChoice; this.oneChoice = effect.oneChoice;
@ -99,7 +96,7 @@ public class DynamicManaEffect extends BasicManaEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
computeMana(false, game, source); Mana computedMana = computeMana(false, game, source);
checkToFirePossibleEvents(computedMana, game, source); checkToFirePossibleEvents(computedMana, game, source);
game.getPlayer(source.getControllerId()).getManaPool().addMana(computedMana, game, source); game.getPlayer(source.getControllerId()).getManaPool().addMana(computedMana, game, source);
return true; return true;
@ -119,7 +116,7 @@ public class DynamicManaEffect extends BasicManaEffect {
} }
public Mana computeMana(boolean netMana, Game game, Ability source) { public Mana computeMana(boolean netMana, Game game, Ability source) {
this.computedMana.clear(); Mana computedMana = new Mana();
int count; int count;
if (netMana && netAmount != null) { if (netMana && netAmount != null) {
// calculate the maximum available mana // calculate the maximum available mana
@ -155,17 +152,7 @@ public class DynamicManaEffect extends BasicManaEffect {
} }
} }
} }
if (choiceColor.getColor().isBlack()) { choiceColor.increaseMana(computedMana);
computedMana.increaseBlack();
} else if (choiceColor.getColor().isBlue()) {
computedMana.increaseBlue();
} else if (choiceColor.getColor().isRed()) {
computedMana.increaseRed();
} else if (choiceColor.getColor().isGreen()) {
computedMana.increaseGreen();
} else if (choiceColor.getColor().isWhite()) {
computedMana.increaseWhite();
}
if (!oneChoice) { if (!oneChoice) {
choiceColor.clearChoice(); choiceColor.clearChoice();
} }

View file

@ -29,6 +29,8 @@
package mage.choices; package mage.choices;
import java.util.ArrayList; import java.util.ArrayList;
import mage.Mana;
import mage.ObjectColor; import mage.ObjectColor;
/** /**
@ -90,4 +92,33 @@ public class ChoiceColor extends ChoiceImpl {
return color; return color;
} }
public Mana getMana(int amount) {
Mana mana = null;
if (getColor().isBlack()) {
mana = Mana.BlackMana(amount);
} else if (getColor().isBlue()) {
mana = Mana.BlueMana(amount);
} else if (getColor().isRed()) {
mana = Mana.RedMana(amount);
} else if (getColor().isGreen()) {
mana = Mana.GreenMana(amount);
} else if (getColor().isWhite()) {
mana = Mana.WhiteMana(amount);
}
return mana;
}
public void increaseMana(Mana mana) {
if (getColor().isBlack()) {
mana.increaseBlack();
} else if (getColor().isBlue()) {
mana.increaseBlue();
} else if (getColor().isRed()) {
mana.increaseRed();
} else if (getColor().isGreen()) {
mana.increaseGreen();
} else if (getColor().isWhite()) {
mana.increaseWhite();
}
}
} }