use of mage.choices.Choice in project mage by magefree.
the class TayamLuminousEnigmaReplacementEffect method pay.
@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
paid = false;
int countersRemoved = 0;
Player controller = game.getPlayer(controllerId);
for (int i = 0; i < countersToRemove; i++) {
if (target.choose(Outcome.UnboostCreature, controllerId, source.getSourceId(), game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
if (!permanent.getCounters(game).isEmpty()) {
String counterName = null;
if (permanent.getCounters(game).size() > 1) {
Choice choice = new ChoiceImpl(true);
Set<String> choices = new HashSet<>();
for (Counter counter : permanent.getCounters(game).values()) {
if (permanent.getCounters(game).getCount(counter.getName()) > 0) {
choices.add(counter.getName());
}
}
choice.setChoices(choices);
choice.setMessage("Choose a counter to remove from " + permanent.getLogName());
if (!controller.choose(Outcome.UnboostCreature, choice, game)) {
return false;
}
counterName = choice.getChoice();
} else {
for (Counter counter : permanent.getCounters(game).values()) {
if (counter.getCount() > 0) {
counterName = counter.getName();
}
}
}
if (counterName != null) {
permanent.removeCounters(counterName, 1, source, game);
target.clearChosen();
if (!game.isSimulation()) {
game.informPlayers(new StringBuilder(controller.getLogName()).append(" removes a ").append(counterName).append(" counter from ").append(permanent.getName()).toString());
}
countersRemoved++;
if (countersRemoved == countersToRemove) {
paid = true;
break;
}
}
}
}
} else {
break;
}
}
return paid;
}
use of mage.choices.Choice in project mage by magefree.
the class UrzaAcademyHeadmasterBrainstormEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
int x = game.getBattlefield().count(new FilterControlledCreaturePermanent(), source.getSourceId(), source.getControllerId(), game);
Choice manaChoice = new ChoiceImpl();
Set<String> choices = new LinkedHashSet<>();
choices.add("White");
choices.add("Blue");
choices.add("Black");
choices.add("Red");
choices.add("Green");
manaChoice.setChoices(choices);
manaChoice.setMessage("Select color of mana to add");
for (int i = 0; i < x; i++) {
Mana mana = new Mana();
if (!player.choose(Outcome.Benefit, manaChoice, game)) {
return false;
}
if (manaChoice.getChoice() == null) {
// can happen if player leaves game
return false;
}
switch(manaChoice.getChoice()) {
case "White":
mana.increaseWhite();
break;
case "Blue":
mana.increaseBlue();
break;
case "Black":
mana.increaseBlack();
break;
case "Red":
mana.increaseRed();
break;
case "Green":
mana.increaseGreen();
break;
}
player.getManaPool().addMana(mana, game, source);
}
return true;
}
return false;
}
use of mage.choices.Choice 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.choices.Choice in project mage by magefree.
the class BloodOathEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
MageObject sourceObject = game.getObject(source.getSourceId());
Player player = game.getPlayer(source.getControllerId());
Player opponent = game.getPlayer(source.getFirstTarget());
if (player != null && opponent != null && sourceObject != null) {
Choice choiceImpl = new ChoiceImpl();
choiceImpl.setChoices(choice);
if (player.choose(Outcome.Neutral, choiceImpl, game)) {
CardType type = null;
String choosenType = choiceImpl.getChoice();
if (choosenType.equals(CardType.ARTIFACT.toString())) {
type = CardType.ARTIFACT;
} else if (choosenType.equals(CardType.LAND.toString())) {
type = CardType.LAND;
} else if (choosenType.equals(CardType.CREATURE.toString())) {
type = CardType.CREATURE;
} else if (choosenType.equals(CardType.ENCHANTMENT.toString())) {
type = CardType.ENCHANTMENT;
} else if (choosenType.equals(CardType.INSTANT.toString())) {
type = CardType.INSTANT;
} else if (choosenType.equals(CardType.SORCERY.toString())) {
type = CardType.SORCERY;
} else if (choosenType.equals(CardType.PLANESWALKER.toString())) {
type = CardType.PLANESWALKER;
} else if (choosenType.equals(CardType.TRIBAL.toString())) {
type = CardType.TRIBAL;
}
if (type != null) {
Cards hand = opponent.getHand();
opponent.revealCards(sourceObject.getIdName(), hand, game);
Set<Card> cards = hand.getCards(game);
int damageToDeal = 0;
for (Card card : cards) {
if (card != null && card.getCardType(game).contains(type)) {
damageToDeal += 3;
}
}
game.informPlayers(sourceObject.getLogName() + " deals " + (damageToDeal == 0 ? "no" : "" + damageToDeal) + " damage to " + opponent.getLogName());
opponent.damage(damageToDeal, source.getSourceId(), source, game);
return true;
}
}
}
return false;
}
use of mage.choices.Choice in project mage by magefree.
the class ClockspinningAddOrRemoveCounterEffect method selectCounterType.
private Counter selectCounterType(Game game, Ability source, Card card) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && !card.getCounters(game).isEmpty()) {
String counterName = null;
if (card.getCounters(game).size() > 1) {
Choice choice = new ChoiceImpl(true);
Set<String> choices = new HashSet<>();
for (Counter counter : card.getCounters(game).values()) {
if (card.getCounters(game).getCount(counter.getName()) > 0) {
choices.add(counter.getName());
}
}
choice.setChoices(choices);
choice.setMessage("Choose a counter type to add to " + card.getName());
if (controller.choose(Outcome.Neutral, choice, game)) {
counterName = choice.getChoice();
} else {
return null;
}
} else {
for (Counter counter : card.getCounters(game).values()) {
if (counter.getCount() > 0) {
counterName = counter.getName();
}
}
}
return new Counter(counterName);
}
return null;
}
Aggregations