Merge pull request #2538 from nigelzor/mana-cleanup

Mana ability cleanup
This commit is contained in:
Neil Gentleman 2016-10-31 01:36:18 -07:00 committed by GitHub
commit 6f96ec5be5
94 changed files with 154 additions and 353 deletions

View file

@ -90,17 +90,7 @@ public class ConditionalManaEffect extends ManaEffect {
return false; // it happens, don't know how
}
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);
}
createdMana = choice.getMana(amount);
}
mana = createdMana;
}
@ -117,8 +107,7 @@ public class ConditionalManaEffect extends ManaEffect {
}
@Override
public Mana getMana(Game game, Ability source
) {
public Mana getMana(Game game, Ability source) {
Mana mana = null;
if (condition.apply(game, source)) {
mana = effect.getMana();

View file

@ -56,6 +56,6 @@ public class AddConditionalColorlessManaEffect extends ManaEffect {
}
public Mana getMana() {
return new Mana(0, 0, 0, 0, 0, 0, 0, amount);
return Mana.ColorlessMana(amount);
}
}

View file

@ -94,19 +94,10 @@ public class AddConditionalManaOfAnyColorEffect extends ManaEffect {
return false;
}
}
Mana mana = null;
if (choice.getColor().isBlack()) {
mana = manaBuilder.setMana(Mana.BlackMana(1), 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();
Mana mana = choice.getMana(1);
if (mana != null) {
mana = manaBuilder.setMana(mana, source, game).build();
}
if (mana != null) {
checkToFirePossibleEvents(mana, game, source);
controller.getManaPool().addMana(mana, game, source);

View file

@ -64,22 +64,10 @@ public class AddManaAnyColorAttachedControllerEffect extends ManaEffect {
return false;
}
}
int amount = 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);
}
Mana mana = choice.getMana(1);
if (mana != null) {
checkToFirePossibleEvents(mana, game, source);
player.getManaPool().addMana(mana, game, source);
player.getManaPool().addMana(mana, game, source);
return true;
}
}

View file

@ -46,7 +46,7 @@ public class AddManaOfAnyColorEffect extends BasicManaEffect {
}
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.staticText = new StringBuilder("add ")
.append(CardUtil.numberToText(amount))
@ -75,18 +75,7 @@ public class AddManaOfAnyColorEffect extends BasicManaEffect {
if (choice.getColor() == null) {
return false; // it happens, don't know how
}
Mana createdMana = null;
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);
}
Mana createdMana = choice.getMana(amount);
if (createdMana != null) {
checkToFirePossibleEvents(createdMana, game, source);
controller.getManaPool().addMana(createdMana, game, source);
@ -103,7 +92,7 @@ public class AddManaOfAnyColorEffect extends BasicManaEffect {
@Override
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 {
private final Mana computedMana;
private final DynamicValue amount;
private final DynamicValue netAmount;
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) {
super(mana);
this.amount = amount;
computedMana = new Mana();
this.text = text;
this.oneChoice = oneChoice;
this.netAmount = netAmount;
@ -81,7 +79,6 @@ public class DynamicManaEffect extends BasicManaEffect {
public DynamicManaEffect(final DynamicManaEffect effect) {
super(effect);
this.computedMana = effect.computedMana.copy();
this.amount = effect.amount.copy();
this.text = effect.text;
this.oneChoice = effect.oneChoice;
@ -99,7 +96,7 @@ public class DynamicManaEffect extends BasicManaEffect {
@Override
public boolean apply(Game game, Ability source) {
computeMana(false, game, source);
Mana computedMana = computeMana(false, game, source);
checkToFirePossibleEvents(computedMana, game, source);
game.getPlayer(source.getControllerId()).getManaPool().addMana(computedMana, game, source);
return true;
@ -119,7 +116,7 @@ public class DynamicManaEffect extends BasicManaEffect {
}
public Mana computeMana(boolean netMana, Game game, Ability source) {
this.computedMana.clear();
Mana computedMana = new Mana();
int count;
if (netMana && netAmount != null) {
// calculate the maximum available mana
@ -155,17 +152,7 @@ public class DynamicManaEffect extends BasicManaEffect {
}
}
}
if (choiceColor.getColor().isBlack()) {
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();
}
choiceColor.increaseMana(computedMana);
if (!oneChoice) {
choiceColor.clearChoice();
}

View file

@ -188,7 +188,7 @@ class AnyColorLandsProduceManaEffect extends ManaEffect {
netManas.add(new Mana(ColoredManaSymbol.W));
}
if (types.getColorless() > 0) {
netManas.add(new Mana(0, 0, 0, 0, 0, 0, 0, 1));
netManas.add(Mana.ColorlessMana(1));
}
return netManas;
}

View file

@ -38,7 +38,7 @@ public class ColorlessManaAbility extends BasicManaAbility {
public ColorlessManaAbility() {
super(new BasicManaEffect(Mana.ColorlessMana(1)));
this.netMana.add(new Mana(0, 0, 0, 0, 0, 0, 0, 1));
this.netMana.add(Mana.ColorlessMana(1));
}
public ColorlessManaAbility(ColorlessManaAbility ability) {

View file

@ -24,7 +24,7 @@ public class ConditionalColorlessManaAbility extends ManaAbility {
public ConditionalColorlessManaAbility(Cost cost, int amount, ConditionalManaBuilder manaBuilder) {
super(Zone.BATTLEFIELD, new AddConditionalColorlessManaEffect(amount, manaBuilder), cost);
this.netMana.add(new Mana(0, 0, 0, 0, 0, 0, 0, amount));
this.netMana.add(Mana.ColorlessMana(amount));
}
public ConditionalColorlessManaAbility(final ConditionalColorlessManaAbility ability) {

View file

@ -317,7 +317,7 @@ public class ManaOptions extends ArrayList<Mana> {
}
}
} else {
payCombinations.add(new Mana(0, 0, 0, 0, 0, 0, 0, number));
payCombinations.add(Mana.ColorlessMana(number));
}
return payCombinations;
}

View file

@ -29,6 +29,8 @@
package mage.choices;
import java.util.ArrayList;
import mage.Mana;
import mage.ObjectColor;
/**
@ -90,4 +92,33 @@ public class ChoiceColor extends ChoiceImpl {
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();
}
}
}