use of mage.choices.ChoiceImpl in project mage by magefree.
the class GrimdancerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanentEntering(source.getSourceId());
if (player == null || permanent == null) {
return false;
}
Choice choice = new ChoiceImpl(true);
choice.setMessage("Choose two abilities");
choice.setChoices(choices);
if (!player.choose(outcome, choice, game)) {
return false;
}
Counter counter1 = null;
Counter counter2 = null;
switch(choice.getChoice()) {
case "Menace and deathtouch":
counter1 = CounterType.MENACE.createInstance();
counter2 = CounterType.DEATHTOUCH.createInstance();
break;
case "Menace and lifelink":
counter1 = CounterType.MENACE.createInstance();
counter2 = CounterType.LIFELINK.createInstance();
break;
case "Deathtouch and lifelink":
counter1 = CounterType.DEATHTOUCH.createInstance();
counter2 = CounterType.LIFELINK.createInstance();
break;
}
permanent.addCounters(counter1, source.getControllerId(), source, game);
permanent.addCounters(counter2, source.getControllerId(), source, game);
return true;
}
use of mage.choices.ChoiceImpl in project mage by magefree.
the class MindblazeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(targetPointer.getFirst(game, source));
Player playerControls = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
if (player == null || playerControls == null || sourceObject == null) {
return false;
}
Choice numberChoice = new ChoiceImpl();
numberChoice.setMessage("Choose a number greater than 0");
Set<String> numbers = new HashSet<>();
for (int i = 1; i <= 4; i++) {
numbers.add(Integer.toString(i));
}
numberChoice.setChoices(numbers);
String cardName = ChooseACardNameEffect.TypeOfName.NON_LAND_NAME.getChoice(playerControls, game, source, false);
playerControls.choose(Outcome.Neutral, numberChoice, game);
game.informPlayers(sourceObject.getIdName() + " - Chosen number: [" + numberChoice.getChoice() + ']');
Cards cards = new CardsImpl();
cards.addAll(player.getLibrary().getCards(game));
playerControls.revealCards("Library", cards, game);
FilterCard filter = new FilterCard();
filter.add(new NamePredicate(cardName));
int count = Integer.parseInt(numberChoice.getChoice());
if (player.getLibrary().count(filter, game) == count) {
player.damage(8, source.getSourceId(), source, game);
}
player.shuffleLibrary(source, game);
return true;
}
use of mage.choices.ChoiceImpl in project mage by magefree.
the class StaffOfTheLetterMagusEffect 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());
}
ChoiceImpl choice = new ChoiceImpl(true);
choice.setMessage("Choose letter");
Set<String> choices = new HashSet<>();
// Can I choose Y?
// Yes. We play by popular game show rules here. Y is a consonant.
// https://magic.wizards.com/en/articles/archive/news/unstable-faqawaslfaqpaftidawabiajtbt-2017-12-06
Character[] forbiddenChars = { 'A', 'E', 'I', 'N', 'O', 'R', 'S', 'T', 'U' };
for (Character letter = 'A'; letter <= 'Z'; letter++) {
if (Arrays.binarySearch(forbiddenChars, letter) < 0) {
choices.add(letter.toString());
}
}
choice.setChoices(choices);
if (controller != null && mageObject != null && controller.choose(outcome, choice, game)) {
if (!game.isSimulation()) {
game.informPlayers(mageObject.getLogName() + ": " + controller.getLogName() + " has chosen " + choice.getChoice());
}
game.getState().setValue(mageObject.getId() + "_letter", choice.getChoice());
if (mageObject instanceof Permanent) {
((Permanent) mageObject).addInfo("chosen letter", CardUtil.addToolTipMarkTags("Chosen letter: " + choice.getChoice()), game);
}
return true;
}
return false;
}
use of mage.choices.ChoiceImpl in project mage by magefree.
the class TergridsLaternEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetedPlayer = game.getPlayer(source.getTargets().getFirstTarget());
if (targetedPlayer == null) {
return false;
}
// AI hint to discard/sacrifice before die
Outcome aiOutcome = (targetedPlayer.getLife() <= 3 * 2) ? Outcome.Benefit : Outcome.Detriment;
Set<String> choiceSet = new HashSet<>();
if (game.getBattlefield().count(StaticFilters.FILTER_CONTROLLED_PERMANENT_NON_LAND, source.getSourceId(), targetedPlayer.getId(), game) > 0) {
choiceSet.add(SACRIFICE_CHOICE);
}
if (targetedPlayer.getHand().size() > 0) {
choiceSet.add(DISCARD_CHOICE);
}
choiceSet.add(LIFE_LOSS_CHOICE);
String chosen;
if (choiceSet.size() > 1) {
Choice choice = new ChoiceImpl(true);
choice.setChoices(choiceSet);
targetedPlayer.choose(aiOutcome, choice, game);
chosen = choice.getChoice();
if (chosen == null) {
// on disconnect
chosen = LIFE_LOSS_CHOICE;
}
} else {
chosen = LIFE_LOSS_CHOICE;
}
switch(chosen) {
case SACRIFICE_CHOICE:
TargetPermanent target = new TargetPermanent(StaticFilters.FILTER_CONTROLLED_PERMANENT_NON_LAND);
target.setNotTarget(true);
targetedPlayer.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
Permanent chosenLand = game.getPermanent(target.getFirstTarget());
return chosenLand != null && chosenLand.sacrifice(source, game);
case DISCARD_CHOICE:
return targetedPlayer.discard(1, false, false, source, game).size() > 0;
case LIFE_LOSS_CHOICE:
return targetedPlayer.loseLife(3, game, source, false) > 0;
}
return false;
}
use of mage.choices.ChoiceImpl in project mage by magefree.
the class UrzasAvengerEffect method init.
@Override
public void init(Ability source, Game game) {
super.init(source, game);
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Choice choice = new ChoiceImpl(true);
choice.setMessage("Choose one");
choice.setChoices(choices);
if (controller.choose(outcome, choice, game)) {
switch(choice.getChoice()) {
case "Banding":
gainedAbility = BandingAbility.getInstance();
break;
case "Flying":
gainedAbility = FlyingAbility.getInstance();
break;
case "First strike":
gainedAbility = FirstStrikeAbility.getInstance();
break;
default:
gainedAbility = TrampleAbility.getInstance();
break;
}
}
}
}
Aggregations