use of mage.choices.Choice in project mage by magefree.
the class TsabosDecreeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source));
MageObject sourceObject = game.getObject(source.getSourceId());
if (player == null) {
return false;
}
if (sourceObject == null) {
return false;
}
Choice typeChoice = new ChoiceCreatureType(sourceObject);
if (!player.choose(outcome, typeChoice, game)) {
return false;
}
game.informPlayers(sourceObject.getLogName() + " chosen type: " + typeChoice.getChoice());
targetPlayer.revealCards("hand of " + targetPlayer.getName(), targetPlayer.getHand(), game);
FilterCard filterCard = new FilterCard();
filterCard.add(SubType.byDescription(typeChoice.getChoice()).getPredicate());
targetPlayer.discard(new CardsImpl(targetPlayer.getHand().getCards(filterCard, game)), false, source, game);
FilterCreaturePermanent filterCreaturePermanent = new FilterCreaturePermanent();
filterCreaturePermanent.add(SubType.byDescription(typeChoice.getChoice()).getPredicate());
for (Permanent creature : game.getBattlefield().getActivePermanents(filterCreaturePermanent, source.getSourceId(), game)) {
if (creature.isControlledBy(targetPlayer.getId())) {
creature.destroy(source, game, true);
}
}
return true;
}
use of mage.choices.Choice in project mage by magefree.
the class RemoveCounterCost 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);
if (controller != null) {
if (countersToRemove == 0) {
// Can happen when used for X costs where X = 0;
return paid = true;
}
target.clearChosen();
if (target.choose(Outcome.UnboostCreature, controllerId, source.getSourceId(), game)) {
for (UUID targetId : target.getTargets()) {
Permanent permanent = game.getPermanent(targetId);
if (permanent != null) {
if (!permanent.getCounters(game).isEmpty() && (counterTypeToRemove == null || permanent.getCounters(game).containsKey(counterTypeToRemove))) {
String counterName = null;
if (counterTypeToRemove != null) {
counterName = counterTypeToRemove.getName();
} else if (permanent.getCounters(game).size() > 1 && counterTypeToRemove == null) {
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 && !counterName.isEmpty()) {
int countersLeft = countersToRemove - countersRemoved;
int countersOnPermanent = permanent.getCounters(game).getCount(counterName);
int numberOfCountersSelected = 1;
if (countersLeft > 1 && countersOnPermanent > 1) {
numberOfCountersSelected = controller.getAmount(1, Math.min(countersLeft, countersOnPermanent), new StringBuilder("Remove how many counters from ").append(permanent.getIdName()).toString(), game);
}
permanent.removeCounters(counterName, numberOfCountersSelected, source, game);
countersRemoved += numberOfCountersSelected;
if (!game.isSimulation()) {
game.informPlayers(new StringBuilder(controller.getLogName()).append(" removes ").append(numberOfCountersSelected == 1 ? "a" : numberOfCountersSelected).append(' ').append(counterName).append(numberOfCountersSelected == 1 ? " counter from " : " counters from ").append(permanent.getName()).toString());
}
if (countersRemoved == countersToRemove) {
this.paid = true;
break;
}
}
}
}
}
}
}
return paid;
}
use of mage.choices.Choice in project mage by magefree.
the class ConvokeEffect method buildChoice.
private Choice buildChoice(ObjectColor creatureColor, Mana mana) {
Choice choice = new ChoiceColor();
choice.getChoices().clear();
if (creatureColor.isBlack() && mana.getBlack() > 0) {
choice.getChoices().add("Black");
}
if (creatureColor.isBlue() && mana.getBlue() > 0) {
choice.getChoices().add("Blue");
}
if (creatureColor.isGreen() && mana.getGreen() > 0) {
choice.getChoices().add("Green");
}
if (creatureColor.isRed() && mana.getRed() > 0) {
choice.getChoices().add("Red");
}
if (creatureColor.isWhite() && mana.getWhite() > 0) {
choice.getChoices().add("White");
}
return choice;
}
use of mage.choices.Choice in project mage by magefree.
the class FlowstoneSculptureEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Choice choice = new ChoiceImpl(true);
choice.setMessage("Choose ability to add");
choice.setChoices(choices);
if (!controller.choose(outcome, choice, game)) {
return false;
}
String chosen = choice.getChoice();
if (chosen.equals("+1/+1 counter")) {
return new AddCountersSourceEffect(CounterType.P1P1.createInstance()).apply(game, source);
} else {
Ability gainedAbility;
switch(chosen) {
case "Flying":
gainedAbility = FlyingAbility.getInstance();
break;
case "First strike":
gainedAbility = FirstStrikeAbility.getInstance();
break;
default:
gainedAbility = TrampleAbility.getInstance();
break;
}
game.addEffect(new GainAbilitySourceEffect(gainedAbility, Duration.WhileOnBattlefield), source);
return true;
}
}
return false;
}
use of mage.choices.Choice in project mage by magefree.
the class InvokeTheAncientsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
token.putOntoBattlefield(2, game, source, source.getControllerId());
for (UUID tokenId : token.getLastAddedTokenIds()) {
Permanent permanent = game.getPermanent(tokenId);
if (permanent == null) {
continue;
}
Choice choice = new ChoiceImpl(true);
choice.setMessage("Choose vigilance, reach, or trample counter");
choice.setChoices(choices);
player.choose(outcome, choice, game);
String chosen = choice.getChoice();
if (chosen != null) {
permanent.addCounters(CounterType.findByName(chosen.toLowerCase(Locale.ENGLISH)).createInstance(), source.getControllerId(), source, game);
}
}
return true;
}
Aggregations