use of mage.choices.Choice in project mage by magefree.
the class CreepingRenaissanceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Choice typeChoice = new ChoiceCardType(true, Arrays.stream(CardType.values()).filter(CardType::isPermanentType).collect(Collectors.toList()));
typeChoice.setMessage("Choose a permanent type");
if (!controller.choose(Outcome.ReturnToHand, typeChoice, game)) {
return false;
}
String typeName = typeChoice.getChoice();
CardType chosenType = CardType.fromString(typeChoice.getChoice());
if (chosenType == null) {
return false;
}
FilterCard filter = new FilterCard(chosenType.toString().toLowerCase(Locale.ENGLISH) + " card");
filter.add(chosenType.getPredicate());
return controller.moveCards(controller.getGraveyard().getCards(filter, source.getSourceId(), controller.getId(), game), Zone.HAND, source, game);
}
use of mage.choices.Choice in project mage by magefree.
the class GarthOneEyeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
initMap();
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Set<String> alreadyChosen = getAlreadyChosen(game, source);
Set<String> choices = new HashSet<>(names);
choices.removeAll(alreadyChosen);
String chosen;
switch(choices.size()) {
case 0:
return false;
case 1:
chosen = choices.stream().findAny().orElse(null);
break;
default:
Choice choice = new ChoiceImpl(true, ChoiceHintType.CARD);
choice.setChoices(choices);
player.choose(outcome, choice, game);
chosen = choice.getChoice();
}
alreadyChosen.add(chosen);
Card card = cardMap.get(chosen);
if (card == null || !player.chooseUse(outcome, "Cast " + card.getName() + '?', source, game)) {
return false;
}
Card copiedCard = game.copyCard(card, source, source.getControllerId());
copiedCard.setZone(Zone.OUTSIDE, game);
game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), Boolean.TRUE);
player.cast(player.chooseAbilityForCast(copiedCard, game, false), game, false, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), null);
return true;
}
use of mage.choices.Choice in project mage by magefree.
the class KindredDominanceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Choice typeChoice = new ChoiceCreatureType(game.getObject(source.getSourceId()));
if (controller != null && controller.choose(outcome, typeChoice, game)) {
game.informPlayers(controller.getLogName() + " has chosen " + typeChoice.getChoice());
FilterCreaturePermanent filter = new FilterCreaturePermanent("All creatures not of the chosen type");
filter.add(Predicates.not(SubType.byDescription(typeChoice.getChoice()).getPredicate()));
return new DestroyAllEffect(filter).apply(game, source);
}
return false;
}
use of mage.choices.Choice in project mage by magefree.
the class ChangeCreatureTypeTargetEffect method init.
@Override
public void init(Ability source, Game game) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return;
}
if (fromSubType == null) {
Choice typeChoice = new ChoiceCreatureType(game.getObject(source.getSourceId()));
typeChoice.setMessage("Choose creature type to change to Vampire");
if (!controller.choose(outcome, typeChoice, game)) {
discard();
return;
}
fromSubType = SubType.byDescription(typeChoice.getChoice());
if (!game.isSimulation()) {
game.informPlayers(controller.getLogName() + " has chosen the creature type: " + fromSubType.toString());
}
}
// To change body of generated methods, choose Tools | Templates.
super.init(source, game);
}
use of mage.choices.Choice in project mage by magefree.
the class NestingGroundsEffect 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;
}
Aggregations