use of mage.choices.Choice in project mage by magefree.
the class SphinxAmbassadorEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source));
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (controller != null && targetPlayer != null && sourcePermanent != null) {
TargetCardInLibrary target = new TargetCardInLibrary();
controller.searchLibrary(target, source, game, targetPlayer.getId());
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
TreeSet<String> choices = new TreeSet<>();
Collection<Card> cards = game.getCards();
for (Card gameCard : cards) {
if (gameCard.isOwnedBy(targetPlayer.getId())) {
choices.add(gameCard.getName());
}
}
Choice cardChoice = new ChoiceImpl(false, ChoiceHintType.CARD);
cardChoice.setChoices(choices);
cardChoice.clearChoice();
if (!targetPlayer.choose(Outcome.Benefit, cardChoice, game)) {
return false;
}
String cardName = cardChoice.getChoice();
game.informPlayers(sourcePermanent.getName() + ", named card: [" + cardName + ']');
if (!card.getName().equals(cardName) && card.isCreature(game)) {
if (controller.chooseUse(outcome, "Put " + card.getName() + " onto the battlefield?", source, game)) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
}
}
targetPlayer.shuffleLibrary(source, game);
return true;
}
return false;
}
use of mage.choices.Choice in project mage by magefree.
the class VeteranWarleaderEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (sourceObject != null && controller != null) {
Choice abilityChoice = new ChoiceImpl();
abilityChoice.setMessage("Choose an ability to add");
Set<String> abilities = new HashSet<>();
abilities.add(FirstStrikeAbility.getInstance().getRule());
abilities.add(VigilanceAbility.getInstance().getRule());
abilities.add(TrampleAbility.getInstance().getRule());
abilityChoice.setChoices(abilities);
if (!controller.choose(Outcome.AddAbility, abilityChoice, game)) {
return false;
}
String chosen = abilityChoice.getChoice();
Ability ability = null;
if (FirstStrikeAbility.getInstance().getRule().equals(chosen)) {
ability = FirstStrikeAbility.getInstance();
} else if (VigilanceAbility.getInstance().getRule().equals(chosen)) {
ability = VigilanceAbility.getInstance();
} else if (TrampleAbility.getInstance().getRule().equals(chosen)) {
ability = TrampleAbility.getInstance();
}
if (ability != null) {
game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " has chosen: " + chosen);
ContinuousEffect effect = new GainAbilitySourceEffect(ability, Duration.EndOfTurn);
game.addEffect(effect, source);
return true;
}
}
return false;
}
use of mage.choices.Choice in project mage by magefree.
the class VigeanIntuitionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
MageObject sourceObject = game.getObject(source.getSourceId());
Player player = game.getPlayer(source.getControllerId());
if (sourceObject == null || player == null) {
return false;
}
Library library = player.getLibrary();
if (library == null) {
return false;
}
Choice choiceImpl = new ChoiceImpl();
choiceImpl.setChoices(choice);
if (player.choose(Outcome.Neutral, choiceImpl, game)) {
String choosenType = choiceImpl.getChoice();
if (choosenType == null || choosenType.isEmpty()) {
return false;
}
CardType type = null;
if (choosenType.equals(CardType.ARTIFACT.toString())) {
type = CardType.ARTIFACT;
} else if (choosenType.equals(CardType.LAND.toString())) {
type = CardType.LAND;
} else if (choosenType.equals(CardType.CREATURE.toString())) {
type = CardType.CREATURE;
} else if (choosenType.equals(CardType.ENCHANTMENT.toString())) {
type = CardType.ENCHANTMENT;
} else if (choosenType.equals(CardType.INSTANT.toString())) {
type = CardType.INSTANT;
} else if (choosenType.equals(CardType.SORCERY.toString())) {
type = CardType.SORCERY;
} else if (choosenType.equals(CardType.PLANESWALKER.toString())) {
type = CardType.PLANESWALKER;
} else if (choosenType.equals(CardType.TRIBAL.toString())) {
type = CardType.TRIBAL;
}
if (type != null) {
Set<Card> top = library.getTopCards(game, 4);
player.revealCards(source, new CardsImpl(top), game);
Cards putInHand = new CardsImpl();
Cards putInGraveyard = new CardsImpl();
for (Card card : top) {
if (card != null && card.getCardType(game).contains(type)) {
putInHand.add(card);
} else {
putInGraveyard.add(card);
}
}
player.moveCards(putInHand, Zone.HAND, source, game);
player.moveCards(putInGraveyard, Zone.GRAVEYARD, source, game);
return true;
}
}
return false;
}
use of mage.choices.Choice in project mage by magefree.
the class DraftFromSpellbookEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Set<String> toSelect = new HashSet<>();
while (toSelect.size() < 3) {
toSelect.add(RandomUtil.randomFromCollection(spellbook));
}
Choice choice = new ChoiceImpl(true, ChoiceHintType.CARD);
choice.setMessage("Choose a card to draft");
choice.setChoices(toSelect);
player.choose(outcome, choice, game);
String cardName = choice.getChoice();
if (cardName == null) {
return false;
}
CardInfo cardInfo = CardRepository.instance.findCards(new CardCriteria().nameExact(cardName)).stream().findFirst().orElse(null);
if (cardInfo == null) {
return false;
}
Set<Card> cards = new HashSet<>();
cards.add(cardInfo.getCard());
game.loadCards(cards, player.getId());
player.moveCards(cards, Zone.HAND, source, game);
return true;
}
use of mage.choices.Choice in project mage by magefree.
the class AnyColorLandsProduceManaEffect method produceMana.
@Override
public Mana produceMana(Game game, Ability source) {
Mana mana = new Mana();
if (game == null) {
return mana;
}
Choice choice = ManaType.getChoiceOfManaTypes(getManaTypes(game, source), onlyColors);
if (!choice.getChoices().isEmpty()) {
Player player = game.getPlayer(source.getControllerId());
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
if (player == null || !player.choose(outcome, choice, game)) {
return null;
}
}
if (choice.getChoice() != null) {
switch(choice.getChoice()) {
case "Black":
mana.setBlack(1);
break;
case "Blue":
mana.setBlue(1);
break;
case "Red":
mana.setRed(1);
break;
case "Green":
mana.setGreen(1);
break;
case "White":
mana.setWhite(1);
break;
case "Colorless":
mana.setColorless(1);
break;
}
}
}
return mana;
}
Aggregations