use of mage.ConditionalMana in project mage by magefree.
the class ManaOptions method addMana.
/**
* Adds the given mana value to all existing options
*
* @param addMana Mana to add to the existing options
*/
public void addMana(Mana addMana) {
if (isEmpty()) {
this.add(new Mana());
}
if (addMana instanceof ConditionalMana) {
ManaOptions copy = this.copy();
this.clear();
for (Mana mana : copy) {
ConditionalMana condMana = ((ConditionalMana) addMana).copy();
condMana.add(mana);
// Add mana as option with condition
add(condMana);
// Add old mana without the condition
add(mana);
}
} else {
for (Mana mana : this) {
mana.add(addMana);
}
}
forceManaDeduplication();
}
use of mage.ConditionalMana in project mage by magefree.
the class ManaOptions method removeDuplicated.
public void removeDuplicated() {
Set<String> list = new HashSet<>();
for (int i = this.size() - 1; i >= 0; i--) {
String s;
if (this.get(i) instanceof ConditionalMana) {
s = this.get(i).toString() + ((ConditionalMana) this.get(i)).getConditionString();
} else {
s = this.get(i).toString();
}
if (s.isEmpty()) {
this.remove(i);
} else if (list.contains(s)) {
// remove duplicated
this.remove(i);
} else {
list.add(s);
}
}
// battlefield:Human:Cascading Cataracts:1
for (int i = this.size() - 1; i >= 0; i--) {
for (int ii = 0; ii < i; ii++) {
Mana moreValuable = Mana.getMoreValuableMana(this.get(i), this.get(ii));
if (moreValuable != null) {
this.get(ii).setToMana(moreValuable);
this.remove(i);
break;
}
}
}
}
use of mage.ConditionalMana in project mage by magefree.
the class DoublingCubeEffect method produceMana.
@Override
public Mana produceMana(Game game, Ability source) {
if (game != null) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
ManaPool pool = controller.getManaPool();
int blackMana = pool.getBlack();
int whiteMana = pool.getWhite();
int blueMana = pool.getBlue();
int greenMana = pool.getGreen();
int redMana = pool.getRed();
int colorlessMana = pool.getColorless();
for (ConditionalMana conditionalMana : pool.getConditionalMana()) {
blackMana += conditionalMana.getBlack();
whiteMana += conditionalMana.getWhite();
blueMana += conditionalMana.getBlue();
greenMana += conditionalMana.getGreen();
redMana += conditionalMana.getRed();
colorlessMana += conditionalMana.getColorless();
}
return new Mana(whiteMana, blueMana, blackMana, redMana, greenMana, 0, 0, colorlessMana);
}
}
return new Mana();
}
use of mage.ConditionalMana in project mage by magefree.
the class AddConditionalManaOfAnyColorEffect method produceMana.
@Override
public Mana produceMana(Game game, Ability source) {
if (game != null) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int value = amount.calculate(game, source, this);
if (value > 0) {
if (oneChoice || value == 1) {
ChoiceColor choice = new ChoiceColor(true);
controller.choose(outcome, choice, game);
if (choice.getChoice() == null) {
return null;
}
return new ConditionalMana(manaBuilder.setMana(choice.getMana(value), source, game).build());
}
List<String> manaStrings = new ArrayList<>(5);
manaStrings.add("W");
manaStrings.add("U");
manaStrings.add("B");
manaStrings.add("R");
manaStrings.add("G");
List<Integer> choices = controller.getMultiAmount(this.outcome, manaStrings, 0, value, MultiAmountType.MANA, game);
Mana mana = new Mana(choices.get(0), choices.get(1), choices.get(2), choices.get(3), choices.get(4), 0, 0, 0);
return new ConditionalMana(manaBuilder.setMana(mana, source, game).build());
}
}
}
return new Mana();
}
use of mage.ConditionalMana in project mage by magefree.
the class AddConditionalManaOfTwoDifferentColorsEffect method produceMana.
@Override
public Mana produceMana(Game game, Ability source) {
if (game != null) {
Player player = getPlayer(game, source);
Mana mana = new ConditionalMana(manaBuilder.setMana(ManaChoice.chooseTwoDifferentColors(player, game), source, game).build());
return mana;
}
return new Mana();
}
Aggregations