use of mage.Mana in project mage by magefree.
the class DeckBuilder method addLandsToDeck.
/**
* Adds lands from non basic land (if provided), adds basic lands getting
* them from provided {@link RateCallback}}.
*
* @param allowedColors
* @param landCardPool
* @param callback
*/
private static void addLandsToDeck(List<ColoredManaSymbol> allowedColors, List<String> setsToUse, List<Card> landCardPool, RateCallback callback) {
// Calculate statistics per color.
final Map<String, Integer> colorCount = new HashMap<>();
for (final Card card : deck.getCards()) {
for (String symbol : card.getManaCostSymbols()) {
int count = 0;
symbol = symbol.replace("{", "").replace("}", "");
if (isColoredMana(symbol)) {
for (ColoredManaSymbol allowed : allowedColors) {
if (symbol.contains(allowed.toString())) {
count++;
}
}
if (count > 0) {
Integer typeCount = colorCount.getOrDefault(symbol, 0);
typeCount += 1;
colorCount.put(symbol, typeCount);
}
}
}
}
// Add suitable non basic lands to deck in order of pack.
final Map<String, Integer> colorSource = new HashMap<>();
for (final ColoredManaSymbol color : ColoredManaSymbol.values()) {
colorSource.put(color.toString(), 0);
}
if (landCardPool != null) {
for (final Card landCard : landCardPool) {
deck.getCards().add(landCard);
for (Mana mana : landCard.getMana()) {
for (ColoredManaSymbol color : allowedColors) {
int amount = mana.getColor(color);
if (amount > 0) {
Integer count = colorSource.get(color.toString());
count += amount;
colorSource.put(color.toString(), count);
}
}
}
}
}
// Add optimal basic lands to deck.
while (deck.getCards().size() < deckSize) {
ColoredManaSymbol bestColor = null;
// Default to a color in the allowed colors
if (allowedColors != null && !allowedColors.isEmpty()) {
bestColor = allowedColors.get(RandomUtil.nextInt(allowedColors.size()));
}
int lowestRatio = Integer.MAX_VALUE;
for (final ColoredManaSymbol color : ColoredManaSymbol.values()) {
final Integer count = colorCount.get(color.toString());
if (count != null && count > 0) {
final int source = colorSource.get(color.toString());
final int ratio;
if (source < MIN_SOURCE) {
ratio = source - count;
} else {
ratio = source * 100 / count;
}
if (ratio < lowestRatio) {
lowestRatio = ratio;
bestColor = color;
}
}
}
final Card landCard = callback.getBestBasicLand(bestColor, setsToUse);
Integer count = colorSource.get(bestColor.toString());
count++;
colorSource.put(bestColor.toString(), count);
deck.getCards().add(landCard);
}
}
use of mage.Mana in project mage by magefree.
the class JackInTheMoxManaEffect method produceMana.
@Override
public Mana produceMana(Game game, Ability source) {
Mana mana = new Mana();
if (game == null) {
return mana;
}
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (controller != null && permanent != null) {
int amount = controller.rollDice(outcome, source, game, 6);
switch(amount) {
case 1:
permanent.sacrifice(source, game);
controller.loseLife(5, game, source, false);
break;
case 2:
mana.add(Mana.WhiteMana(1));
break;
case 3:
mana.add(Mana.BlueMana(1));
break;
case 4:
mana.add(Mana.BlackMana(1));
break;
case 5:
mana.add(Mana.RedMana(1));
break;
case 6:
mana.add(Mana.GreenMana(1));
break;
default:
break;
}
}
return mana;
}
use of mage.Mana in project mage by magefree.
the class KlothysGodOfDestinyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Card card = game.getCard(source.getFirstTarget());
if (player == null || card == null) {
return false;
}
boolean isLand = card.isLand(game);
player.moveCards(card, Zone.EXILED, source, game);
if (isLand) {
Mana mana = new Mana();
if (player.chooseUse(Outcome.PutManaInPool, "Choose a color of mana to add", null, "Red", "Green", source, game)) {
mana.increaseRed();
} else {
mana.increaseGreen();
}
player.getManaPool().addMana(mana, game, source);
return true;
}
player.gainLife(2, game, source);
game.getOpponents(player.getId()).stream().map(game::getPlayer).filter(Objects::nonNull).forEach(opponent -> opponent.damage(2, source.getSourceId(), source, game));
return true;
}
use of mage.Mana in project mage by magefree.
the class NehebDreadhordeChampionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
int counter = player.discard(0, Integer.MAX_VALUE, false, source, game).size();
if (counter < 1) {
return true;
}
player.drawCards(counter, source, game);
player.getManaPool().addMana(new Mana(ManaType.RED, counter), game, source, true);
return true;
}
use of mage.Mana in project mage by magefree.
the class OpenTheOmenpathsCondition method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Mana mana = ManaChoice.chooseTwoDifferentColors(player, game);
mana.add(mana);
ConditionalMana conditionalMana = new ConditionalMana(mana);
conditionalMana.addCondition(new OpenTheOmenpathsCondition());
player.getManaPool().addMana(conditionalMana, game, source);
return true;
}
Aggregations