@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { int xSum = 0; xSum += playerPaysXGenericMana(controller, source, game); for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { if (!Objects.equals(playerId, controller.getId())) { Player player = game.getPlayer(playerId); if (player != null) { xSum += playerPaysXGenericMana(player, source, game); } } } ContinuousEffect effect = new BoostSourceEffect(xSum, 0, Duration.EndOfTurn); game.addEffect(effect, source); // prevent undo controller.resetStoredBookmark(game); return true; } return false; } }
@Override public synchronized void rollbackTurns(int turnsToRollback) { if (gameOptions.rollbackTurnsAllowed) { int turnToGoTo = getTurnNum() - turnsToRollback; if (turnToGoTo < 1 || !gameStatesRollBack.containsKey(turnToGoTo)) { informPlayers(GameLog.getPlayerRequestColoredText("Player request: It's not possible to rollback " + turnsToRollback + " turn(s)")); } else { GameState restore = gameStatesRollBack.get(turnToGoTo); if (restore != null) { informPlayers(GameLog.getPlayerRequestColoredText("Player request: Rolling back to start of turn " + restore.getTurnNum())); state.restoreForRollBack(restore); playerList.setCurrent(state.getPlayerByOrderId()); // Reset temporary created bookmarks because no longer valid after rollback savedStates.clear(); gameStates.clear(); // because restore uses the objects without copy each copy the state again gameStatesRollBack.put(getTurnNum(), state.copy()); executingRollback = true; for (Player playerObject : getPlayers().values()) { if (playerObject.isHuman() && playerObject.isInGame()) { playerObject.resetStoredBookmark(this); playerObject.abort(); playerObject.resetPlayerPassedActions(); } } fireUpdatePlayersEvent(); } } } }
player.resetStoredBookmark(game); // otherwise you can e.g. undo card drawn with Mentor of the Meek } else {
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { int xSum = 0; xSum += playerPaysXGenericMana(controller, source, game); for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { if (!Objects.equals(playerId, controller.getId())) { Player player = game.getPlayer(playerId); if (player != null) { xSum += playerPaysXGenericMana(player, source, game); } } } if (xSum > 0) { for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { Player player = game.getPlayer(playerId); if (player != null) { player.drawCards(xSum, game); } } } // prevent undo controller.resetStoredBookmark(game); return true; } return false; }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { Player player = game.getPlayer(playerId); if (player != null) { TargetCardInLibrary target = new TargetCardInLibrary(0, Integer.MAX_VALUE, filter); if (player.searchLibrary(target, game)) { player.moveCards(new CardsImpl(target.getTargets()), Zone.BATTLEFIELD, source, game); player.shuffleLibrary(source, game); } } } // prevent undo controller.resetStoredBookmark(game); return true; } return false; } }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { ManaCosts cost = new ManaCostsImpl("{X}{W}{U}{U}"); if (controller.chooseUse(Outcome.Damage, "Pay " + cost.getText() + "? If you do, you gain X life and draw X cards.", source, game)) { int costX = controller.announceXMana(0, Integer.MAX_VALUE, "Announce the value for {X}", game, source); cost.add(new GenericManaCost(costX)); if (cost.pay(source, game, source.getSourceId(), source.getControllerId(), false, null)) { controller.resetStoredBookmark(game); // otherwise you can undo the payment controller.gainLife(costX, game, source); controller.drawCards(costX, game); return true; } } } return false; }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { int xSum = 0; xSum += playerPaysXGenericMana(controller, source, game); for(UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { if (!Objects.equals(playerId, controller.getId())) { Player player = game.getPlayer(playerId); if (player != null) { xSum += playerPaysXGenericMana(player, source, game); } } } if (xSum > 0) { for(UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { Effect effect = new PutTopCardOfLibraryIntoGraveTargetEffect(xSum); effect.setTargetPointer(new FixedTarget(playerId)); effect.apply(game, source); } } // prevent undo controller.resetStoredBookmark(game); return true; } return false; }
protected static int playerPaysXGenericMana(Player player, Ability source, Game game) { int xValue = 0; boolean payed = false; while (player.canRespond() && !payed) { int bookmark = game.bookmarkState(); player.resetStoredBookmark(game); xValue = player.announceXMana(0, Integer.MAX_VALUE, "How much mana will you pay?", game, source); if (xValue > 0) { Cost cost = new GenericManaCost(xValue); payed = cost.pay(source, game, source.getSourceId(), player.getId(), false, null); } else { payed = true; } if (!payed) { game.restoreState(bookmark, "Collective Voyage"); game.fireUpdatePlayersEvent(); } else { game.removeBookmark(bookmark); } } game.informPlayers(player.getLogName() + " pays {" + xValue + "}."); return xValue; } }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { int xSum = 0; xSum += playerPaysXGenericMana(controller, source, game); for(UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { if (!Objects.equals(playerId, controller.getId())) { Player player = game.getPlayer(playerId); if (player != null) { xSum += playerPaysXGenericMana(player, source, game); } } } if (xSum > 0) { for(UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { Effect effect = new CreateTokenTargetEffect(new SoldierToken(), xSum); effect.setTargetPointer(new FixedTarget(playerId)); effect.apply(game, source); } } // prevent undo controller.resetStoredBookmark(game); return true; } return false; }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { int amount = source.getManaCostsToPay().getX(); for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { Player player = game.getPlayer(playerId); if (player != null && player.chooseUse(outcome, "Search your library for up to " + amount + " basic lands?", source, game)) { TargetCardInLibrary target = new TargetCardInLibrary(0, amount, StaticFilters.FILTER_CARD_BASIC_LAND); if (player.searchLibrary(target, game)) { player.moveCards(new CardsImpl(target.getTargets()).getCards(game), Zone.BATTLEFIELD, source, game, true, false, false, null); player.shuffleLibrary(source, game); } } } // prevent undo controller.resetStoredBookmark(game); return true; } return false; } }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { Player player = game.getPlayer(playerId); if (player != null) { TargetCardInLibrary target = new TargetCardInLibrary(); if (player.chooseUse(Outcome.Benefit, "Search your library for a card to put into your hand?", source, game)) { player.searchLibrary(target, game); for (UUID cardId : target.getTargets()) { Card card = player.getLibrary().getCard(cardId, game); if (card != null) { player.moveCards(card, Zone.HAND, source, game); } } player.shuffleLibrary(source, game); } } } // prevent undo controller.resetStoredBookmark(game); return true; } return false; } }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { int xSum = 0; xSum += playerPaysXGenericMana(controller, source, game); for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { if (!Objects.equals(playerId, controller.getId())) { Player player = game.getPlayer(playerId); if (player != null) { xSum += playerPaysXGenericMana(player, source, game); } } } for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { Player player = game.getPlayer(playerId); if (player != null) { TargetCardInLibrary target = new TargetCardInLibrary(0, xSum, StaticFilters.FILTER_CARD_BASIC_LAND); if (player.searchLibrary(target, game)) { player.moveCards(new CardsImpl(target.getTargets()).getCards(game), Zone.BATTLEFIELD, source, game, true, false, true, null); player.shuffleLibrary(source, game); } } } // prevent undo controller.resetStoredBookmark(game); return true; } return false; }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { Player player = game.getPlayer(playerId); if (player != null) { TargetCardInLibrary target = new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD_BASIC_LAND); if (player.chooseUse(Outcome.Benefit, "Search your library for a card to put into your hand?", source, game)) { player.searchLibrary(target, game); for (UUID cardId : target.getTargets()) { Card card = player.getLibrary().getCard(cardId, game); if (card != null) { player.revealCards(source, new CardsImpl(card), game); player.moveCards(card, Zone.HAND, source, game); } } player.shuffleLibrary(source, game); } } } // prevent undo controller.resetStoredBookmark(game); return true; } return false; } }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { Player player = game.getPlayer(source.getFirstTarget()); if (player != null) { FilterCard filter = new FilterCard("card named " + partnerName); filter.add(new NamePredicate(partnerName)); TargetCardInLibrary target = new TargetCardInLibrary(filter); if (player.chooseUse(Outcome.Benefit, "Search your library for a card named " + partnerName + " and put it into your hand?", source, game)) { player.searchLibrary(target, game); for (UUID cardId : target.getTargets()) { Card card = player.getLibrary().getCard(cardId, game); if (card != null) { player.revealCards(source, new CardsImpl(card), game); player.moveCards(card, Zone.HAND, source, game); } } player.shuffleLibrary(source, game); } } // prevent undo controller.resetStoredBookmark(game); return true; } return false; } }
@Override public boolean apply(Game game, Ability source) { Player player = game.getPlayer(game.getActivePlayerId()); MageObject sourceObject = source.getSourceObject(game); if (player == null || sourceObject == null) { return false; } Cost cost = new OrCost(new ManaCostsImpl("{R}{R}"), new PayLifeCost(2), "{R}{R} or 2 life"); if (player.chooseUse(Outcome.GainControl, "Gain control of " + sourceObject.getLogName() + "?", source, game)) { if (cost.pay(source, game, source.getSourceId(), player.getId(), false)) { ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, false, player.getId()); effect.setTargetPointer(new FixedTarget(source.getSourceId(), source.getSourceObjectZoneChangeCounter())); game.addEffect(effect, source); player.resetStoredBookmark(game); } } return true; } }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { ManaCosts cost = new ManaCostsImpl("{X}{R}"); if (controller.chooseUse(outcome, "Pay " + cost.getText() + "? If you do, you create X 1/1 red Elemental creature tokens that are tapped and attacking.", source, game)) { int costX = controller.announceXMana(0, Integer.MAX_VALUE, "Announce the value for {X}", game, source); cost.add(new GenericManaCost(costX)); if (cost.pay(source, game, source.getSourceId(), source.getControllerId(), false, null)) { controller.resetStoredBookmark(game); // otherwise you can undo the payment CreateTokenEffect effect = new CreateTokenEffect(new TilonallisSummonerElementalToken(), costX, true, true); effect.apply(game, source); Effect exileEffect = new ExileTargetEffect(null, "", Zone.BATTLEFIELD) .setText("exile those tokens unless you have the city's blessing"); exileEffect.setTargetPointer(new FixedTargets(new CardsImpl(effect.getLastAddedTokenIds()), game)); game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility( Zone.ALL, exileEffect, TargetController.ANY, new InvertCondition(CitysBlessingCondition.instance)), source); } } return true; } return false; } }
targetPlayer.resetStoredBookmark(game); for (RestrictionEffect eff : game.getContinuousEffects().getRestrictionEffects()) { if (eff instanceof WordOfCommandCantActivateEffect) {