use of mage.choices.ChoiceImpl in project mage by magefree.
the class StorageMatrixRestrictionEffect method applies.
@Override
public boolean applies(Permanent permanent, Ability source, Game game) {
if (game.getStep().getType() == PhaseStep.UNTAP) {
if (game.getTurnNum() != turn) {
turn = game.getTurnNum();
applies = false;
Permanent storageMatrix = game.getPermanent(source.getSourceId());
if (storageMatrix != null && !storageMatrix.isTapped()) {
Choice choiceImpl = new ChoiceImpl(true);
choiceImpl.setMessage("Untap which kind of permanent?");
choiceImpl.setChoices(choice);
Player player = game.getPlayer(game.getActivePlayerId());
if (player != null && player.choose(outcome, choiceImpl, game)) {
String choosenType = choiceImpl.getChoice();
if (choosenType != null) {
game.informPlayers(storageMatrix.getLogName() + ": " + player.getLogName() + " chose to untap " + choosenType);
if (choosenType.equals(CardType.ARTIFACT.toString())) {
type = CardType.ARTIFACT;
} else if (choosenType.equals(CardType.LAND.toString())) {
type = CardType.LAND;
} else {
type = CardType.CREATURE;
}
applies = true;
}
}
}
}
if (applies) {
return !permanent.getCardType(game).contains(type);
}
}
return false;
}
use of mage.choices.ChoiceImpl in project mage by magefree.
the class StingingStudyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Set<Integer> manaValues = new HashSet<>();
for (Card commander : game.getCommanderCardsFromAnyZones(player, CommanderCardType.ANY, Zone.BATTLEFIELD, Zone.COMMAND)) {
manaValues.add(commander.getManaValue());
}
int chosenValue;
if (manaValues.size() > 1) {
Choice choice = new ChoiceImpl(true);
choice.setChoices(manaValues.stream().map(x -> "" + x).collect(Collectors.toSet()));
player.choose(outcome, choice, game);
chosenValue = Integer.parseInt(choice.getChoice());
} else {
chosenValue = manaValues.stream().findFirst().orElse(0);
}
if (chosenValue == 0) {
return false;
}
player.drawCards(chosenValue, source, game);
player.loseLife(chosenValue, game, source, false);
return true;
}
use of mage.choices.ChoiceImpl in project mage by magefree.
the class TeferisRealmEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
Player controller = game.getPlayer(source.getControllerId());
if (player != null && controller != null) {
Choice choiceImpl = new ChoiceImpl(true);
choiceImpl.setMessage("Phase out which kind of permanents?");
choiceImpl.setChoices(choices);
if (!player.choose(outcome, choiceImpl, game)) {
return false;
}
String choosenType = choiceImpl.getChoice();
FilterPermanent filter = new FilterPermanent();
filter.add(TokenPredicate.FALSE);
switch(choosenType) {
case ARTIFACT:
filter.add(CardType.ARTIFACT.getPredicate());
break;
case CREATURE:
filter.add(CardType.CREATURE.getPredicate());
break;
case LAND:
filter.add(CardType.LAND.getPredicate());
break;
case NON_AURA_ENCHANTMENT:
filter.add(CardType.ENCHANTMENT.getPredicate());
filter.add(Predicates.not(SubType.AURA.getPredicate()));
break;
default:
return false;
}
game.informPlayers(player.getLogName() + " chooses " + choosenType + "s to phase out");
List<UUID> permIds = new ArrayList<>();
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, controller.getId(), game)) {
permIds.add(permanent.getId());
}
return new PhaseOutAllEffect(permIds).apply(game, source);
}
return false;
}
use of mage.choices.ChoiceImpl in project mage by magefree.
the class WhenFluffyBunniesAttackEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getFirstTarget());
ChoiceImpl choice = new ChoiceImpl(true);
choice.setMessage("Choose letter");
Set<String> choices = new HashSet<>();
for (Character letter = 'A'; letter <= 'Z'; letter++) {
choices.add(letter.toString());
}
choice.setChoices(choices);
if (controller != null && permanent != null && controller.choose(outcome, choice, game)) {
if (!game.isSimulation()) {
MageObject mageObject = game.getObject(source.getSourceId());
if (mageObject != null) {
game.informPlayers(mageObject.getLogName() + ": " + controller.getLogName() + " has chosen " + choice.getChoice());
}
}
Character chosenLetter = choice.getChoice().charAt(0);
int unboostValue = 0;
String permName = permanent.getName();
for (int i = 0; i < permName.length(); i++) {
Character letter = permName.charAt(i);
if (Character.isLetter(letter) && Character.toUpperCase(letter) == chosenLetter) {
unboostValue--;
}
}
BoostTargetEffect effect = new BoostTargetEffect(unboostValue, unboostValue, Duration.EndOfTurn);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
return true;
}
return false;
}
use of mage.choices.ChoiceImpl in project mage by magefree.
the class ChooseExpansionSetEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject mageObject = game.getPermanentEntering(source.getSourceId());
if (mageObject == null) {
mageObject = game.getObject(source.getSourceId());
}
if (controller != null) {
Choice setChoice = new ChoiceImpl(true);
setChoice.setMessage("Choose expansion set");
List<String> setCodes = ExpansionRepository.instance.getSetCodes();
Set<String> sets = new HashSet<String>(setCodes);
setChoice.setChoices(sets);
if (controller.choose(outcome, setChoice, game)) {
if (!game.isSimulation()) {
game.informPlayers(controller.getLogName() + " has chosen set " + setChoice.getChoice());
}
game.getState().setValue(mageObject.getId() + "_set", setChoice.getChoice());
this.setValue("setchosen", setChoice.getChoice());
if (mageObject instanceof Permanent) {
((Permanent) mageObject).addInfo("chosen set", CardUtil.addToolTipMarkTags("Chosen set: " + setChoice.getChoice()), game);
}
return true;
}
}
return false;
}
Aggregations