use of mage.choices.ChoiceImpl in project mage by magefree.
the class SpellsCostReductionControllerEffect method apply.
@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
if (manaCostsToReduce != null) {
CardUtil.adjustCost((SpellAbility) abilityToModify, manaCostsToReduce, false);
} else {
if (upTo) {
Mana mana = abilityToModify.getManaCostsToPay().getMana();
int reduceMax = mana.getGeneric();
if (reduceMax > this.amount) {
reduceMax = this.amount;
}
if (reduceMax > 0) {
Player controller = game.getPlayer(abilityToModify.getControllerId());
if (controller == null) {
return false;
}
int reduce = reduceMax;
if (!game.inCheckPlayableState()) {
ChoiceImpl choice = new ChoiceImpl(false);
Set<String> set = new LinkedHashSet<>();
for (int i = 0; i <= reduceMax; i++) {
set.add(String.valueOf(i));
}
choice.setChoices(set);
MageObject mageObject = game.getObject(abilityToModify.getSourceId());
choice.setMessage("Reduce cost of " + (mageObject != null ? mageObject.getIdName() : filter.getMessage()));
if (controller.choose(Outcome.Benefit, choice, game)) {
reduce = Integer.parseInt(choice.getChoice());
} else {
// cancel will be set to max possible reduce
reduce = reduceMax;
}
}
if (reduce > 0) {
CardUtil.reduceCost(abilityToModify, reduce);
}
}
} else {
CardUtil.reduceCost(abilityToModify, this.amount);
}
}
return true;
}
use of mage.choices.ChoiceImpl in project mage by magefree.
the class SpellsCostReductionAllEffect method apply.
@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
if (upTo) {
if (game.inCheckPlayableState()) {
CardUtil.reduceCost(abilityToModify, this.amount);
return true;
}
Mana mana = abilityToModify.getManaCostsToPay().getMana();
int reduceMax = mana.getGeneric();
if (reduceMax > this.amount) {
reduceMax = this.amount;
}
if (reduceMax > 0) {
Player controller = game.getPlayer(abilityToModify.getControllerId());
if (controller == null) {
return false;
}
ChoiceImpl choice = new ChoiceImpl(true);
Set<String> set = new LinkedHashSet<>();
for (int i = 0; i <= reduceMax; i++) {
set.add(String.valueOf(i));
}
choice.setChoices(set);
choice.setMessage("Reduce cost of " + filter);
if (controller.choose(Outcome.Benefit, choice, game)) {
int reduce = Integer.parseInt(choice.getChoice());
CardUtil.reduceCost(abilityToModify, reduce);
} else {
return false;
}
}
} else {
CardUtil.reduceCost(abilityToModify, this.amount);
}
return true;
}
use of mage.choices.ChoiceImpl in project mage by magefree.
the class CommanderIdentityManaEffect 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());
if (controller != null) {
Choice choice = new ChoiceImpl();
choice.setMessage("Pick a mana color");
for (UUID commanderId : game.getCommandersIds(controller, CommanderCardType.COMMANDER_OR_OATHBREAKER, false)) {
Card commander = game.getCard(commanderId);
if (commander != null) {
FilterMana commanderMana = commander.getColorIdentity();
if (commanderMana.isWhite()) {
choice.getChoices().add("White");
}
if (commanderMana.isBlue()) {
choice.getChoices().add("Blue");
}
if (commanderMana.isBlack()) {
choice.getChoices().add("Black");
}
if (commanderMana.isRed()) {
choice.getChoices().add("Red");
}
if (commanderMana.isGreen()) {
choice.getChoices().add("Green");
}
}
}
if (!choice.getChoices().isEmpty()) {
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
if (!controller.choose(outcome, choice, game)) {
return mana;
}
}
switch(choice.getChoice()) {
case "Black":
mana.setBlack(1);
break;
case "Blue":
mana.setBlue(1);
break;
case "Red":
mana.setRed(1);
break;
case "Green":
mana.setGreen(1);
break;
case "White":
mana.setWhite(1);
break;
}
}
}
return mana;
}
use of mage.choices.ChoiceImpl in project mage by magefree.
the class ElementalResonanceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent thisPerm = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (thisPerm == null) {
return false;
}
Permanent permanent = game.getPermanentOrLKIBattlefield(thisPerm.getAttachedTo());
if (permanent == null) {
return false;
}
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
List<String> manaOptions = new ArrayList<>();
// TODO: Phyrexian mana gives multiple choices when there should only be one (e.g. Slash Panther is {4} or {4}{R}).
for (Mana mana : permanent.getManaCost().getOptions()) {
String manaString = mana.toString();
if (!manaOptions.contains(manaString)) {
manaOptions.add(manaString);
}
}
String manaToAdd = "";
if (manaOptions.size() > 1) {
// TODO: Make the choices look nicer, right now the brace notation is hard to visually parse, especially with Reaper King
Choice choice = new ChoiceImpl();
choice.setMessage("Choose a mana combination");
choice.getChoices().addAll(manaOptions);
if (!controller.choose(Outcome.PutManaInPool, choice, game)) {
return false;
}
manaToAdd = choice.getChoice();
} else if (manaOptions.size() == 1) {
manaToAdd = manaOptions.get(0);
}
if (!manaToAdd.equals("")) {
controller.getManaPool().addMana(getManaFromString(manaToAdd), game, source);
}
return true;
}
use of mage.choices.ChoiceImpl in project mage by magefree.
the class GoblinClearCutterManaEffect method produceMana.
@Override
public Mana produceMana(Game game, Ability source) {
Mana mana = new Mana();
if (game == null) {
return mana;
}
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
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 < 3; i++) {
if (!player.choose(Outcome.Benefit, manaChoice, game)) {
return mana;
}
switch(manaChoice.getChoice()) {
case "Green":
mana.increaseGreen();
break;
case "Red":
mana.increaseRed();
break;
}
}
}
return mana;
}
Aggregations