use of mage.Mana in project mage by magefree.
the class AddManaInAnyCombinationEffect method produceMana.
@Override
public Mana produceMana(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
int size = manaSymbols.size();
Mana mana = new Mana();
List<String> manaStrings = new ArrayList<>(size);
for (ColoredManaSymbol coloredManaSymbol : manaSymbols) {
manaStrings.add(coloredManaSymbol.toString());
}
List<Integer> manaList = player.getMultiAmount(this.outcome, manaStrings, 0, amount.calculate(game, source, this), MultiAmountType.MANA, game);
for (int i = 0; i < size; i++) {
ColoredManaSymbol coloredManaSymbol = manaSymbols.get(i);
int amount = manaList.get(i);
for (int j = 0; j < amount; j++) {
mana.add(new Mana(coloredManaSymbol));
}
}
return mana;
}
return null;
}
use of mage.Mana in project mage by magefree.
the class AddManaOfAnyTypeProducedEffect method produceMana.
@Override
public Mana produceMana(Game game, Ability source) {
Mana newMana = new Mana();
if (game == null) {
return newMana;
}
Permanent permanent = (Permanent) this.getValue("tappedPermanent");
Mana types = (Mana) this.getValue("mana");
if (permanent == null || types == null) {
return newMana;
}
Player targetController = game.getPlayer(permanent.getControllerId());
if (targetController == null) {
return newMana;
}
Choice choice = new ChoiceColor(true);
choice.getChoices().clear();
choice.setMessage("Pick the type of mana to produce");
if (types.getWhite() > 0) {
choice.getChoices().add("White");
}
if (types.getBlue() > 0) {
choice.getChoices().add("Blue");
}
if (types.getBlack() > 0) {
choice.getChoices().add("Black");
}
if (types.getRed() > 0) {
choice.getChoices().add("Red");
}
if (types.getGreen() > 0) {
choice.getChoices().add("Green");
}
if (types.getColorless() > 0) {
choice.getChoices().add("Colorless");
}
if (choice.getChoices().isEmpty()) {
return newMana;
}
if (choice.getChoices().size() != 1 && !targetController.choose(outcome, choice, game)) {
return newMana;
}
choice.setChoice(choice.getChoices().iterator().next());
switch(choice.getChoice()) {
case "White":
newMana.setWhite(1);
break;
case "Blue":
newMana.setBlue(1);
break;
case "Black":
newMana.setBlack(1);
break;
case "Red":
newMana.setRed(1);
break;
case "Green":
newMana.setGreen(1);
break;
case "Colorless":
newMana.setColorless(1);
break;
}
return newMana;
}
use of mage.Mana in project mage by magefree.
the class AddManaOfAnyTypeProducedEffect method getNetMana.
@Override
public List<Mana> getNetMana(Game game, Ability source) {
List<Mana> netMana = new ArrayList<>();
Mana types = (Mana) this.getValue("mana");
if (types == null) {
return netMana;
}
if (types.getBlack() > 0) {
netMana.add(Mana.BlackMana(1));
}
if (types.getRed() > 0) {
netMana.add(Mana.RedMana(1));
}
if (types.getBlue() > 0) {
netMana.add(Mana.BlueMana(1));
}
if (types.getGreen() > 0) {
netMana.add(Mana.GreenMana(1));
}
if (types.getWhite() > 0) {
netMana.add(Mana.WhiteMana(1));
}
if (types.getColorless() > 0) {
netMana.add(Mana.ColorlessMana(1));
}
return netMana;
}
use of mage.Mana in project mage by magefree.
the class AddManaOfAnyColorEffect method produceMana.
@Override
public Mana produceMana(Game game, Ability source) {
if (game != null) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
String mes = String.format("Select a color of mana to add %d of it", this.amount);
if (mes != null) {
ChoiceColor choice = new ChoiceColor(true, mes, game.getObject(source.getSourceId()));
if (controller.choose(outcome, choice, game)) {
if (choice.getColor() != null) {
Mana mana = choice.getMana(amount);
mana.setFlag(setFlag);
return mana;
}
}
}
}
}
return new Mana();
}
use of mage.Mana in project mage by magefree.
the class ManaEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = getPlayer(game, source);
if (player == null) {
return false;
}
if (game.inCheckPlayableState()) {
// So it's important if ManaEffects overwrite the apply method to take care for this.
if (source instanceof TriggeredAbility) {
player.addAvailableTriggeredMana(getNetMana(game, source));
}
// No need to add mana to pool during checkPlayable
return true;
}
Mana manaToAdd = produceMana(game, source);
if (manaToAdd != null && manaToAdd.count() > 0) {
checkToFirePossibleEvents(manaToAdd, game, source);
addManaToPool(player, manaToAdd, game, source);
}
return true;
}
Aggregations