use of mage.choices.Choice in project mage by magefree.
the class GrandWarlordRadhaEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
CreaturesAttackedWatcher watcher = game.getState().getWatcher(CreaturesAttackedWatcher.class);
if (watcher != null) {
int attackingCreatures = 0;
for (MageObjectReference attacker : watcher.getAttackedThisTurnCreatures()) {
if (attacker.getPermanentOrLKIBattlefield(game).isControlledBy(controller.getId())) {
attackingCreatures++;
}
}
if (attackingCreatures > 0) {
Choice manaChoice = new ChoiceImpl();
Set<String> choices = new LinkedHashSet<>();
choices.add("Red");
choices.add("Green");
manaChoice.setChoices(choices);
manaChoice.setMessage("Select color of mana to add");
for (int i = 0; i < attackingCreatures; i++) {
Mana mana = new Mana();
if (!controller.choose(Outcome.Benefit, manaChoice, game)) {
return false;
}
if (manaChoice.getChoice() == null) {
// can happen if player leaves game
return false;
}
switch(manaChoice.getChoice()) {
case "Green":
mana.increaseGreen();
break;
case "Red":
mana.increaseRed();
break;
}
controller.getManaPool().addMana(mana, game, source, true);
}
return true;
}
return true;
}
}
return false;
}
use of mage.choices.Choice in project mage by magefree.
the class AnyColorLandsProduceManaEffect method produceMana.
@Override
public Mana produceMana(Game game, Ability source) {
Mana mana = new Mana();
if (game == null) {
return mana;
}
int manaAmount = getManaAmount(game, source);
Mana types = getManaTypes(game, source);
Choice choice = new ChoiceColor(true);
choice.getChoices().clear();
choice.setMessage("Pick a mana color");
if (types.getBlack() > 0) {
choice.getChoices().add("Black");
}
if (types.getRed() > 0) {
choice.getChoices().add("Red");
}
if (types.getBlue() > 0) {
choice.getChoices().add("Blue");
}
if (types.getGreen() > 0) {
choice.getChoices().add("Green");
}
if (types.getWhite() > 0) {
choice.getChoices().add("White");
}
if (types.getColorless() > 0) {
choice.getChoices().add("Colorless");
}
if (types.getAny() > 0) {
choice.getChoices().add("Black");
choice.getChoices().add("Red");
choice.getChoices().add("Blue");
choice.getChoices().add("Green");
choice.getChoices().add("White");
choice.getChoices().add("Colorless");
}
if (!choice.getChoices().isEmpty()) {
Player player = game.getPlayer(source.getControllerId());
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else if (player == null || !player.choose(outcome, choice, game)) {
return mana;
}
if (choice.getChoice() != null) {
switch(choice.getChoice()) {
case "Black":
mana.setBlack(manaAmount);
break;
case "Blue":
mana.setBlue(manaAmount);
break;
case "Red":
mana.setRed(manaAmount);
break;
case "Green":
mana.setGreen(manaAmount);
break;
case "White":
mana.setWhite(manaAmount);
break;
case "Colorless":
mana.setColorless(manaAmount);
break;
}
}
}
return mana;
}
use of mage.choices.Choice in project mage by magefree.
the class LeechBonderEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent fromPermanent = game.getPermanent(source.getFirstTarget());
Permanent toPermanent = game.getPermanent(source.getTargets().get(1).getFirstTarget());
if (fromPermanent == null || toPermanent == null || controller == null) {
return false;
}
Set<String> possibleChoices = new HashSet<>(fromPermanent.getCounters(game).keySet());
if (possibleChoices.size() == 0) {
return false;
}
Choice choice = new ChoiceImpl();
choice.setChoices(possibleChoices);
if (controller.choose(outcome, choice, game)) {
String chosen = choice.getChoice();
if (fromPermanent.getCounters(game).containsKey(chosen)) {
CounterType counterType = CounterType.findByName(chosen);
if (counterType != null) {
Counter counter = counterType.createInstance();
fromPermanent.removeCounters(counterType.getName(), 1, source, game);
toPermanent.addCounters(counter, source.getControllerId(), source, game);
return true;
}
}
}
return false;
}
use of mage.choices.Choice in project mage by magefree.
the class LavabrinkFloodgatesEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(game.getActivePlayerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (player == null || permanent == null) {
return false;
}
Choice choice = new ChoiceImpl();
choice.setChoices(new HashSet(Arrays.asList("Add a doom counter", "Remove a doom counter", "Do nothing")));
player.choose(outcome, choice, game);
switch(choice.getChoice()) {
case "Add a doom counter":
permanent.addCounters(CounterType.DOOM.createInstance(), player.getId(), source, game);
break;
case "Remove a doom counter":
permanent.removeCounters(CounterType.DOOM.createInstance(), source, game);
break;
case "Do nothing":
default:
break;
}
if (permanent.getCounters(game).getCount(CounterType.DOOM) < 3 || !permanent.sacrifice(source, game)) {
return true;
}
game.fireReflexiveTriggeredAbility(new ReflexiveTriggeredAbility(new DamageAllEffect(6, StaticFilters.FILTER_PERMANENT_CREATURE), false, "it deals 6 damage to each creature."), source);
return true;
}
use of mage.choices.Choice in project mage by magefree.
the class ManaforgeCinderManaEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Choice manaChoice = new ChoiceImpl();
Set<String> choices = new LinkedHashSet<>();
choices.add("Black");
choices.add("Red");
manaChoice.setChoices(choices);
manaChoice.setMessage("Select black or red mana to add");
Mana mana = new Mana();
if (!controller.choose(Outcome.Benefit, manaChoice, game)) {
return false;
}
if (manaChoice.getChoice() == null) {
return false;
}
switch(manaChoice.getChoice()) {
case "Black":
mana.increaseBlack();
break;
case "Red":
mana.increaseRed();
break;
}
controller.getManaPool().addMana(mana, game, source);
return true;
}
return false;
}
Aggregations