@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); MageObject sourceObject = source.getSourceObject(game); if (controller != null && sourceObject != null) { Choice choice = new ChoiceImpl(true); choice.setMessage("Choose a creature type:"); choice.setChoices(CardRepository.instance.getCreatureTypes()); while (!controller.choose(Outcome.BoostCreature, choice, game)) { if (!controller.canRespond()) { return false; } } Cards revealedCards = new CardsImpl(); while (controller.getLibrary().size() > 0) { Card card = controller.getLibrary().removeFromTop(game); if (card.getCardType().contains(CardType.CREATURE) && card.getSubtype().contains(choice.getChoice())) { controller.moveCards(card, Zone.BATTLEFIELD, source, game); break; } revealedCards.add(card); } controller.revealCards(sourceObject.getIdName(), revealedCards, game); controller.moveCards(revealedCards, Zone.LIBRARY, source, game); controller.shuffleLibrary(source, game); return true; } return false; }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); MageObject mageObject = game.getObject(source.getSourceId()); if (controller != null && mageObject != null) { Choice typeChoice = new ChoiceImpl(true); typeChoice.setMessage("Choose creature type"); typeChoice.setChoices(CardRepository.instance.getCreatureTypes()); while (!controller.choose(outcome, typeChoice, game)) { if (!controller.canRespond()) { return false; } } if (!game.isSimulation()) { game.informPlayers( mageObject.getName() + ": " + controller.getLogName() + " has chosen " + typeChoice.getChoice()); } Cards cardsToLibrary = new CardsImpl(); FilterCreatureCard filter = new FilterCreatureCard(); filter.add(new SubtypePredicate(typeChoice.getChoice())); cardsToLibrary.addAll( controller .getGraveyard() .getCards(filter, source.getSourceId(), source.getControllerId(), game)); controller.putCardsOnTopOfLibrary(cardsToLibrary, game, source, false); controller.shuffleLibrary(game); return true; } return false; }
@Override public boolean choose(Outcome outcome, Choice choice, Game game) { Iterator<String> it = choice.getChoices().iterator(); String sChoice = it.next(); int choiceNum = rnd.nextInt(choice.getChoices().size()); for (int i = 0; i < choiceNum; i++) { sChoice = it.next(); } choice.setChoice(sChoice); return true; }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { Choice cardChoice = new ChoiceImpl(); cardChoice.setChoices(CardRepository.instance.getNonLandAndNonCreatureNames()); cardChoice.clearChoice(); while (!controller.choose(Outcome.Detriment, cardChoice, game)) { game.debugMessage("player canceled choosing name. retrying."); } String cardName = cardChoice.getChoice(); game.informPlayers("Council of the Absolute, named card: [" + cardName + "]"); game.getState().setValue(source.getSourceId().toString(), cardName); } return false; }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { Choice choice = new ChoiceImpl(true); choice.setMessage("Choose creature type"); choice.setChoices(CardRepository.instance.getCreatureTypes()); while (!controller.choose(Outcome.GainControl, choice, game)) { if (!controller.isInGame()) { return false; } } String chosenType = choice.getChoice(); if (!game.isSimulation()) { game.informPlayers(controller.getLogName() + " has chosen " + chosenType); } UUID playerWithMost = null; int maxControlled = 0; for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { FilterPermanent filter = new FilterCreaturePermanent(chosenType, chosenType); filter.add(new ControllerIdPredicate(playerId)); int controlled = new PermanentsOnBattlefieldCount(filter).calculate(game, source, this); if (controlled > maxControlled) { maxControlled = controlled; playerWithMost = playerId; } else if (controlled == maxControlled) { playerWithMost = null; // Do nothing in case of tie } } if (playerWithMost != null && playerWithMost.equals(controller.getId())) { for (Permanent permanent : game.getBattlefield() .getActivePermanents( new FilterCreaturePermanent(chosenType, chosenType), controller.getId(), source.getSourceId(), game)) { ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame); effect.setTargetPointer(new FixedTarget(permanent.getId())); game.addEffect(effect, source); } } return true; } return false; }
@Override public boolean apply(Game game, Ability source) { Player player = game.getPlayer(source.getControllerId()); if (player != null) { Choice typeChoice = new ChoiceImpl(true); typeChoice.setMessage("Choose a creature type:"); typeChoice.setChoices(CardRepository.instance.getCreatureTypes()); while (!player.choose(Outcome.BoostCreature, typeChoice, game)) { if (!player.canRespond()) { return false; } } FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent(); filter.add(new SubtypePredicate(typeChoice.getChoice())); return new DrawCardSourceControllerEffect(new PermanentsOnBattlefieldCount(filter)) .apply(game, source); } return false; }
protected void addAbilityNode(SimulationNode parent, Ability ability, Game game) { Game sim = game.copy(); sim.getStack().push(new StackAbility(ability, playerId)); ability.activate(sim, false); sim.applyEffects(); SimulationNode newNode = new SimulationNode(parent, sim, playerId); logger.debug( indent(newNode.getDepth()) + "simulating -- node #:" + SimulationNode.getCount() + " triggered ability option"); for (Target target : ability.getTargets()) { for (UUID targetId : target.getTargets()) { newNode.getTargets().add(targetId); } } for (Choice choice : ability.getChoices()) { newNode.getChoices().add(choice.getChoice()); } parent.children.add(newNode); }
@Override public boolean apply(Game game, Ability source) { Player player = game.getPlayer(source.getControllerId()); MageObject sourceObject = game.getObject(source.getSourceId()); if (player != null) { Choice typeChoice = new ChoiceImpl(true); typeChoice.setMessage("Choose a creature type:"); typeChoice.setChoices(CardRepository.instance.getCreatureTypes()); while (!player.choose(outcome, typeChoice, game)) { if (!player.canRespond()) { return false; } } if (typeChoice.getChoice() != null) { game.informPlayers(sourceObject.getLogName() + " chosen type: " + typeChoice.getChoice()); } FilterCreaturePermanent filterCreaturePermanent = new FilterCreaturePermanent(); filterCreaturePermanent.add(new SubtypePredicate(typeChoice.getChoice())); for (Permanent creature : game.getBattlefield() .getActivePermanents(filterCreaturePermanent, source.getSourceId(), game)) { creature.untap(game); } return true; } return false; }
@Override public boolean apply(Game game, Ability source) { Player player = game.getPlayer(targetPointer.getFirst(game, source)); Player controller = game.getPlayer(source.getControllerId()); if (player != null && controller != null) { Choice cardChoice = new ChoiceImpl(); cardChoice.setChoices(CardRepository.instance.getNonLandNames()); cardChoice.clearChoice(); while (!controller.choose(Outcome.Exile, cardChoice, game)) { game.debugMessage("player canceled choosing name. retrying."); } String cardName = cardChoice.getChoice(); game.informPlayers("CranialExtraction, named card: [" + cardName + "]"); for (Card card : player.getGraveyard().getCards(game)) { if (card.getName().equals(cardName)) { card.moveToExile(null, "", source.getId(), game); } } for (Card card : player.getHand().getCards(game)) { if (card.getName().equals(cardName)) { card.moveToExile(null, "", source.getId(), game); } } for (Card card : player.getLibrary().getCards(game)) { if (card.getName().equals(cardName)) { card.moveToExile(null, "", source.getId(), game); } } controller.lookAtCards("CranialExtraction Hand", player.getHand(), game); controller.lookAtCards( "CranialExtraction Library", new CardsImpl(Zone.PICK, player.getLibrary().getCards(game)), game); player.shuffleLibrary(game); } return true; }
@Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { Permanent permanent = ((EntersTheBattlefieldEvent) event).getTarget(); if (permanent != null) { Choice choice = new ChoiceImpl(true); choice.setMessage("Choose what " + permanent.getIdName() + " becomes to"); choice.getChoices().add(choice33); choice.getChoices().add(choice22); choice.getChoices().add(choice16); Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { while (!choice.isChosen()) { controller.choose(Outcome.Neutral, choice, game); if (!controller.canRespond()) { return false; } } } int power = 0; int toughness = 0; switch (choice.getChoice()) { case choice33: power = 3; toughness = 3; break; case choice22: power = 2; toughness = 2; game.addEffect( new GainAbilitySourceEffect(FlyingAbility.getInstance(), Duration.Custom), source); break; case choice16: power = 1; toughness = 6; game.addEffect( new GainAbilitySourceEffect(DefenderAbility.getInstance(), Duration.Custom), source); break; } permanent.getPower().modifyBaseValue(power); permanent.getToughness().modifyBaseValue(toughness); // game.addEffect(new SetPowerToughnessSourceEffect(power, toughness, Duration.Custom, // SubLayer.SetPT_7b), source); } return false; }
private Choice buildChoice(ManaCosts manaCosts, ManaCosts manaCostsSpell) { Choice choice = new ChoiceImpl(); String creatureCosts = manaCosts.getText(); String spellCosts = manaCostsSpell.getText(); if (creatureCosts.contains("B") && spellCosts.contains("B")) { choice.getChoices().add("Black"); } if (creatureCosts.contains("U") && spellCosts.contains("U")) { choice.getChoices().add("Blue"); } if (creatureCosts.contains("G") && spellCosts.contains("G")) { choice.getChoices().add("Green"); } if (creatureCosts.contains("R") && spellCosts.contains("R")) { choice.getChoices().add("Red"); } if (creatureCosts.contains("W") && spellCosts.contains("W")) { choice.getChoices().add("White"); } return choice; }
@Override public void adjustCosts(Ability ability, Game game) { Player player = game.getPlayer(controllerId); if (player == null || !(ability instanceof SpellAbility)) { return; } Target target = new TargetControlledCreaturePermanent(1, Integer.MAX_VALUE, filter, true); target.setTargetName("creatures to convoke"); if (!target.canChoose(sourceId, controllerId, game)) { return; } if (player.chooseUse(Outcome.Detriment, "Convoke creatures?", game)) { player.chooseTarget(Outcome.Tap, target, ability, game); if (target.getTargets().size() > 0) { int adjCost = 0; for (UUID creatureId : target.getTargets()) { Permanent perm = game.getPermanent(creatureId); if (perm == null) { continue; } ManaCosts manaCostsCreature = perm.getSpellAbility().getManaCosts(); if (manaCostsCreature != null && manaCostsCreature.convertedManaCost() > 0 && perm.tap(game)) { Choice chooseManaType = buildChoice(manaCostsCreature, ability.getManaCostsToPay()); if (chooseManaType.getChoices().size() > 0) { if (chooseManaType.getChoices().size() > 1) { chooseManaType.getChoices().add("Colorless"); chooseManaType.setMessage("Choose mana color to reduce from " + perm.getName()); while (!chooseManaType.isChosen()) { player.choose(Outcome.Benefit, chooseManaType, game); } } else { chooseManaType.setChoice(chooseManaType.getChoices().iterator().next()); } ManaCosts manaCostsToReduce = new ManaCostsImpl(); if (chooseManaType.getChoice().equals("Black")) { manaCostsToReduce.load("{B}"); } if (chooseManaType.getChoice().equals("Blue")) { manaCostsToReduce.load("{U}"); } if (chooseManaType.getChoice().equals("Green")) { manaCostsToReduce.load("{G}"); } if (chooseManaType.getChoice().equals("White")) { manaCostsToReduce.load("{W}"); } if (chooseManaType.getChoice().equals("Red")) { manaCostsToReduce.load("{R}"); } if (chooseManaType.getChoice().equals("Colorless")) { ++adjCost; } CardUtil.adjustCost((SpellAbility) ability, manaCostsToReduce); } else { ++adjCost; } } } this.getTargets().add(target); CardUtil.adjustCost((SpellAbility) ability, adjCost); } } }
@Override public boolean apply(Game game, Ability source) { Player player = game.getPlayer(source.getControllerId()); if (player == null) { return false; } Cards cards = new CardsImpl(Zone.PICK); int count = Math.min(player.getLibrary().size(), 5); for (int i = 0; i < count; i++) { Card card = player.getLibrary().removeFromTop(game); if (card != null) { cards.add(card); game.setZone(card.getId(), Zone.PICK); } } player.revealCards("Fact or Fiction", cards, game); Set<UUID> opponents = game.getOpponents(source.getControllerId()); if (!opponents.isEmpty()) { Player opponent = game.getPlayer(opponents.iterator().next()); TargetCard target = new TargetCard( 0, cards.size(), Zone.PICK, new FilterCard("cards to put in the first pile")); Cards pile1 = new CardsImpl(); if (opponent.choose(Outcome.Neutral, cards, target, game)) { List<UUID> targets = target.getTargets(); for (UUID targetId : targets) { Card card = cards.get(targetId, game); if (card != null) { pile1.add(card); cards.remove(card); } } } player.revealCards("Pile 1 (Fact or Fiction)", pile1, game); player.revealCards("Pile 2 (Fact or Fiction)", cards, game); Choice choice = new ChoiceImpl(true); choice.setMessage("Select a pile of cards to put into your hand:"); StringBuilder sb = new StringBuilder("Pile 1: "); for (UUID cardId : pile1) { Card card = pile1.get(cardId, game); if (card != null) { sb.append(card.getName()).append("; "); } } sb.delete(sb.length() - 2, sb.length()); choice.getChoices().add(sb.toString()); sb = new StringBuilder("Pile 2: "); for (UUID cardId : cards) { Card card = cards.get(cardId, game); if (card != null) { sb.append(card.getName()).append("; "); } } sb.delete(sb.length() - 2, sb.length()); choice.getChoices().add(sb.toString()); Zone pile1Zone = Zone.GRAVEYARD; Zone pile2Zone = Zone.HAND; if (player.choose(Outcome.Neutral, choice, game)) { if (choice.getChoice().startsWith("Pile 1")) { pile1Zone = Zone.HAND; pile2Zone = Zone.GRAVEYARD; } } for (UUID cardUuid : pile1) { Card card = pile1.get(cardUuid, game); if (card != null) { card.moveToZone(pile1Zone, source.getId(), game, false); } } for (UUID cardUuid : cards) { Card card = cards.get(cardUuid, game); if (card != null) { card.moveToZone(pile2Zone, source.getId(), game, false); } } } return true; }
@Override public boolean apply(Game game, Ability source) { Mana types = getManaTypes(game, source); Choice choice = new ChoiceImpl(true); choice.setMessage("Pick a mana color"); 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 (types.getAny() > 0) { choice.getChoices().add("Black"); choice.getChoices().add("Red"); choice.getChoices().add("Blue"); choice.getChoices().add("Green"); choice.getChoices().add("White"); } if (choice.getChoices().size() > 0) { 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) { Mana mana = new Mana(); 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; } checkToFirePossibleEvents(mana, game, source); player.getManaPool().addMana(mana, game, source); } } return true; }
@java.lang.Override public boolean apply(Game game, Ability source) { Permanent permanent = game.getPermanent(source.getSourceId()); Player player = game.getPlayer(source.getControllerId()); if (permanent != null && player != null) { List<UUID> imprinted = permanent.getImprinted(); if (imprinted.size() > 0) { Card imprintedCard = game.getCard(imprinted.get(0)); if (imprintedCard != null) { Choice choice = new ChoiceImpl(true); choice.setMessage("Pick a mana color"); ObjectColor color = imprintedCard.getColor(game); if (color.isBlack()) { choice.getChoices().add("Black"); } if (color.isRed()) { choice.getChoices().add("Red"); } if (color.isBlue()) { choice.getChoices().add("Blue"); } if (color.isGreen()) { choice.getChoices().add("Green"); } if (color.isWhite()) { choice.getChoices().add("White"); } if (choice.getChoices().size() > 0) { Mana mana = new Mana(); if (choice.getChoices().size() == 1) { choice.setChoice(choice.getChoices().iterator().next()); } else { player.choose(outcome, choice, game); } if (choice.getChoice().equals("Black")) { player.getManaPool().addMana(Mana.BlackMana, game, source); } else if (choice.getChoice().equals("Blue")) { player.getManaPool().addMana(Mana.BlueMana, game, source); } else if (choice.getChoice().equals("Red")) { player.getManaPool().addMana(Mana.RedMana, game, source); } else if (choice.getChoice().equals("Green")) { player.getManaPool().addMana(Mana.GreenMana, game, source); } else if (choice.getChoice().equals("White")) { player.getManaPool().addMana(Mana.WhiteMana, game, source); } else if (choice.getChoice().equals("Colorless")) { player.getManaPool().addMana(Mana.ColorlessMana, game, source); } checkToFirePossibleEvents(mana, game, source); player.getManaPool().addMana(mana, game, source); } } } } return true; }
public String getValue(boolean useHidden, Game game) { StringBuilder sb = new StringBuilder(1024); sb.append(turnNum) .append(turn.getPhaseType()) .append(turn.getStepType()) .append(activePlayerId) .append(priorityPlayerId); for (Player player : players.values()) { sb.append("player").append(player.isPassed()).append(player.getLife()).append("hand"); if (useHidden) { sb.append(player.getHand()); } else { sb.append(player.getHand().size()); } sb.append("library").append(player.getLibrary().size()); sb.append("graveyard"); for (Card card : player.getGraveyard().getCards(game)) { sb.append(card.getName()); } } sb.append("permanents"); List<String> perms = new ArrayList<String>(); for (Permanent permanent : battlefield.getAllPermanents()) { perms.add(permanent.getValue()); } Collections.sort(perms); sb.append(perms); sb.append("spells"); for (StackObject spell : stack) { sb.append(spell.getControllerId()).append(spell.getName()); sb.append(spell.getStackAbility().toString()); for (Mode mode : spell.getStackAbility().getModes().values()) { if (!mode.getTargets().isEmpty()) { sb.append("targets"); for (Target target : mode.getTargets()) { sb.append(target.getTargets()); } } if (!mode.getChoices().isEmpty()) { sb.append("choices"); for (Choice choice : mode.getChoices()) { sb.append(choice.getChoice()); } } } } for (ExileZone zone : exile.getExileZones()) { sb.append("exile").append(zone.getName()).append(zone); } sb.append("combat"); for (CombatGroup group : combat.getGroups()) { sb.append(group.getDefenderId()).append(group.getAttackers()).append(group.getBlockers()); } return sb.toString(); }