use of mage.choices.ChoiceImpl 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;
}
use of mage.choices.ChoiceImpl 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.ChoiceImpl 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;
}
use of mage.choices.ChoiceImpl in project mage by magefree.
the class WalkingSpongeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (controller != null && permanent != null) {
ChoiceImpl chooseAbility = new ChoiceImpl();
chooseAbility.setMessage("Choose an ability to remove (default is flying)");
Set<String> choice = new LinkedHashSet<>();
choice.add("Flying");
choice.add("First strike");
choice.add("Trample");
chooseAbility.setChoices(choice);
// since the player can't pick "no ability", let's default to the first option
Ability ability = FlyingAbility.getInstance();
if (controller.choose(Outcome.UnboostCreature, chooseAbility, game)) {
String chosenAbility = chooseAbility.getChoice();
if (chosenAbility.equals("First strike")) {
ability = FirstStrikeAbility.getInstance();
} else if (chosenAbility.equals("Trample")) {
ability = TrampleAbility.getInstance();
}
} else {
return false;
}
game.informPlayers(controller.getLogName() + " has chosen " + ability.getRule());
ContinuousEffect effect = new LoseAbilityTargetEffect(ability, Duration.EndOfTurn);
game.addEffect(effect, source);
return true;
}
return false;
}
use of mage.choices.ChoiceImpl in project mage by magefree.
the class FatespinnerSkipEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
if (player != null) {
Choice choice = new ChoiceImpl(true);
choice.setMessage("Choose phase or step to skip");
choice.setChoices(choices);
if (!player.choose(outcome, choice, game)) {
return false;
}
String chosenPhase = choice.getChoice();
game.informPlayers(player.getLogName() + " has chosen to skip " + chosenPhase.toLowerCase(Locale.ENGLISH) + '.');
game.addEffect(new FatespinnerSkipEffect(chosenPhase), source);
return true;
}
return false;
}
Aggregations