use of mage.choices.Choice in project mage by magefree.
the class MeteorCraterEffect method produceMana.
@Override
public Mana produceMana(Game game, Ability source) {
Mana mana = new Mana();
if (game == null) {
return mana;
}
Mana types = getManaTypes(game, source);
Choice choice = new ChoiceColor(true);
choice.getChoices().clear();
choice.setMessage("Pick a mana color");
if (types.getAny() > 0) {
choice.getChoices().add("Black");
choice.getChoices().add("Red");
choice.getChoices().add("Blue");
choice.getChoices().add("Green");
choice.getChoices().add("White");
} else {
if (types.getBlack() > 0) {
choice.getChoices().add("Black");
}
if (types.getRed() > 0) {
choice.getChoices().add("Red");
}
if (types.getBlue() > 0) {
choice.getChoices().add("Blue");
}
if (types.getGreen() > 0) {
choice.getChoices().add("Green");
}
if (types.getWhite() > 0) {
choice.getChoices().add("White");
}
}
if (!choice.getChoices().isEmpty()) {
Player player = game.getPlayer(source.getControllerId());
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
player.choose(outcome, choice, game);
}
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;
}
}
}
return mana;
}
use of mage.choices.Choice in project mage by magefree.
the class MuldrothaTheGravetideWatcher method addPermanentTypes.
private void addPermanentTypes(GameEvent event, Card mageObject, Game game) {
if (mageObject != null && event.getAdditionalReference() != null && MageIdentifier.MuldrothaTheGravetideWatcher.equals(event.getAdditionalReference().getApprovingAbility().getIdentifier())) {
UUID playerId = null;
if (mageObject instanceof Spell) {
playerId = ((Spell) mageObject).getControllerId();
} else if (mageObject instanceof Permanent) {
playerId = ((Permanent) mageObject).getControllerId();
}
if (playerId != null) {
Set<CardType> permanentTypes = sourcePlayedPermanentTypes.get(event.getAdditionalReference().getApprovingMageObjectReference());
if (permanentTypes == null) {
permanentTypes = EnumSet.noneOf(CardType.class);
sourcePlayedPermanentTypes.put(event.getAdditionalReference().getApprovingMageObjectReference(), permanentTypes);
}
Set<CardType> typesNotCast = EnumSet.noneOf(CardType.class);
for (CardType cardType : mageObject.getCardType(game)) {
if (cardType.isPermanentType()) {
if (!permanentTypes.contains(cardType)) {
typesNotCast.add(cardType);
}
}
}
if (typesNotCast.size() <= 1) {
permanentTypes.addAll(typesNotCast);
} else {
Player player = game.getPlayer(playerId);
if (player != null) {
Choice typeChoice = new ChoiceImpl(true);
typeChoice.setMessage("Choose permanent type you consume for casting from graveyard.");
for (CardType cardType : typesNotCast) {
typeChoice.getChoices().add(cardType.toString());
}
if (player.choose(Outcome.Detriment, typeChoice, game)) {
String typeName = typeChoice.getChoice();
CardType chosenType = null;
for (CardType cardType : CardType.values()) {
if (cardType.toString().equals(typeName)) {
chosenType = cardType;
break;
}
}
if (chosenType != null) {
permanentTypes.add(chosenType);
}
}
}
}
}
}
}
use of mage.choices.Choice in project mage by magefree.
the class PatriarchsBiddingEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (controller != null && sourceObject != null) {
Set<String> chosenTypes = new HashSet<>();
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
Choice typeChoice = new ChoiceCreatureType(sourceObject);
if (!player.choose(Outcome.PutCreatureInPlay, typeChoice, game)) {
continue;
}
String chosenType = typeChoice.getChoice();
game.informPlayers(sourceObject.getLogName() + ": " + player.getLogName() + " has chosen " + chosenType);
chosenTypes.add(chosenType);
}
List<SubType.SubTypePredicate> predicates = new ArrayList<>();
for (String type : chosenTypes) {
predicates.add(SubType.byDescription(type).getPredicate());
}
FilterCard filter = new FilterCreatureCard();
filter.add(Predicates.or(predicates));
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
player.moveCards(player.getGraveyard().getCards(filter, game), Zone.BATTLEFIELD, source, game);
}
}
return true;
}
return false;
}
use of mage.choices.Choice in project mage by magefree.
the class ReverseTheSandsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Choice lifeChoice = new ChoiceImpl(true);
Set<String> choices = new HashSet<>();
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
choices.add(Integer.toString(player.getLife()) + " life of " + player.getLogName());
}
}
lifeChoice.setChoices(choices);
for (UUID playersId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playersId);
if (player != null) {
String selectedChoice;
if (choices.size() > 1) {
lifeChoice.setMessage("Which players life should get player " + player.getLogName());
if (!controller.choose(Outcome.Detriment, lifeChoice, game)) {
return false;
}
selectedChoice = lifeChoice.getChoice();
} else {
selectedChoice = choices.iterator().next();
}
int index = selectedChoice.indexOf(' ');
if (index > 0) {
String lifeString = selectedChoice.substring(0, index);
int life = Integer.parseInt(lifeString);
player.setLife(life, game, source);
choices.remove(selectedChoice);
game.informPlayers(new StringBuilder("Player ").append(player.getLogName()).append(" life set to ").append(life).toString());
}
}
}
}
return false;
}
use of mage.choices.Choice in project mage by magefree.
the class WorldQuellerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
List<Card> chosen = new ArrayList<>();
Player player = game.getPlayer(source.getControllerId());
Permanent sourceCreature = game.getPermanent(source.getSourceId());
if (player != null && sourceCreature != null) {
Choice choiceImpl = new ChoiceImpl();
choiceImpl.setChoices(choice);
if (!player.choose(Outcome.Neutral, choiceImpl, game)) {
return false;
}
CardType type = null;
String choosenType = choiceImpl.getChoice();
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) {
FilterControlledPermanent filter = new FilterControlledPermanent("permanent you control of type " + type.toString());
filter.add(type.getPredicate());
TargetPermanent target = new TargetControlledPermanent(1, 1, filter, false);
target.setNotTarget(true);
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player2 = game.getPlayer(playerId);
if (player2 != null && target.canChoose(source.getSourceId(), playerId, game)) {
while (player2.canRespond() && !target.isChosen() && target.canChoose(source.getSourceId(), playerId, game)) {
player2.chooseTarget(Outcome.Sacrifice, target, source, game);
}
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
chosen.add(permanent);
}
target.clearChosen();
}
}
// all chosen permanents are sacrificed together
for (Permanent permanent : game.getBattlefield().getAllActivePermanents()) {
if (chosen.contains(permanent)) {
permanent.sacrifice(source, game);
}
}
return true;
}
}
return false;
}
Aggregations