@Override public void selectAttackers(Game game, UUID attackingPlayerId) { //useful only for two player games - will only attack first opponent // logger.info("select attackers"); UUID defenderId = game.getOpponents(playerId).iterator().next(); List<Permanent> attackersList = super.getAvailableAttackers(defenderId, game); //use binary digits to calculate powerset of attackers int powerElements = (int) Math.pow(2, attackersList.size()); int value = RandomUtil.nextInt(powerElements); StringBuilder binary = new StringBuilder(); binary.append(Integer.toBinaryString(value)); while (binary.length() < attackersList.size()) { binary.insert(0, '0'); //pad with zeros } for (int i = 0; i < attackersList.size(); i++) { if (binary.charAt(i) == '1') { setStoredBookmark(game.bookmarkState()); // makes it possible to UNDO a declared attacker with costs from e.g. Propaganda if (!game.getCombat().declareAttacker(attackersList.get(i).getId(), defenderId, playerId, game)) { game.undo(playerId); } } } actionCount++; }
setStoredBookmark(sim.bookmarkState()); // makes it possible to UNDO a declared attacker with costs from e.g. Propaganda if (!sim.getCombat().declareAttacker(attackersList.get(j).getId(), defenderId, playerId, sim)) { sim.undo(playerId);
setStoredBookmark(sim.bookmarkState()); // makes it possible to UNDO a declared attacker with costs from e.g. Propaganda if (!sim.getCombat().declareAttacker(attackersList.get(j).getId(), defenderId, playerId, sim)) { sim.undo(playerId);
/** * bookmarks the current state and restores it if player doesn't pay the * mana cost * * @param ability * @param game * @param sourceId * @param payingPlayerId * @return true if the cost was paid */ @Override public boolean payOrRollback(Ability ability, Game game, UUID sourceId, UUID payingPlayerId) { int bookmark = game.bookmarkState(); handlePhyrexianManaCosts(payingPlayerId, ability, game); if (pay(ability, game, sourceId, payingPlayerId, false, null)) { game.removeBookmark(bookmark); return true; } game.restoreState(bookmark, ability.getRule()); return false; }
@Override public void declareAttacker(UUID attackerId, UUID defenderId, Game game, boolean allowUndo) { if (allowUndo) { setStoredBookmark(game.bookmarkState()); // makes it possible to UNDO a declared attacker with costs from e.g. Propaganda } Permanent attacker = game.getPermanent(attackerId); if (attacker != null && attacker.canAttack(defenderId, game) && attacker.isControlledBy(playerId)) { if (!game.getCombat().declareAttacker(attackerId, defenderId, playerId, game)) { game.undo(playerId); } } }
private void handleForcedToPayOnlyForCurrentPayment(Game game, ManaPool pool, ManaCosts referenceCosts) { // for Word of Command if (pool.isForcedToPay()) { if (referenceCosts != null && this.getText().equals(referenceCosts.getText())) { UUID playerId = pool.getPlayerId(); Player player = game.getPlayer(playerId); if (player != null) { game.undo(playerId); this.clearPaid(); this.setX(referenceCosts.getX()); player.getManaPool().restoreMana(pool.getPoolBookmark()); game.bookmarkState(); } } } }
@Override public void declareBlocker(UUID defenderId, UUID blockerId, UUID attackerId, Game game, boolean allowUndo) { if (isHuman() && allowUndo) { setStoredBookmark(game.bookmarkState()); } Permanent blocker = game.getPermanent(blockerId); CombatGroup group = game.getCombat().findGroup(attackerId); if (blocker != null && group != null && group.canBlock(blocker, game)) { group.addBlocker(blockerId, playerId, game); game.getCombat().addBlockingGroup(blockerId, attackerId, playerId, game); } else if (this.isHuman() && !game.isSimulation()) { game.informPlayer(this, "You can't block this creature."); } }
protected boolean playManaAbility(ActivatedManaAbilityImpl ability, Game game) { if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.ACTIVATE_ABILITY, ability.getId(), ability.getSourceId(), playerId))) { int bookmark = game.bookmarkState(); if (ability.activate(game, false)) { if (ability.resolve(game)) { if (ability.isUndoPossible()) { if (storedBookmark == -1 || storedBookmark > bookmark) { // e.g. useful for undo Nykthos, Shrine to Nyx setStoredBookmark(bookmark); } } else { resetStoredBookmark(game); } return true; } } restoreState(bookmark, ability.getRule(), game); } return false; }
&& executingEffects.size() > 0 && (!optional || player.chooseUse(executingEffects.get(0).getOutcome(), message, source, game))) { cost.clearPaid(); int bookmark = game.bookmarkState(); if (cost.pay(source, game, source.getSourceId(), player.getId(), false)) { for (Effect effect : executingEffects) {
public boolean chooseTargets(Outcome outcome, UUID playerId, Ability source, boolean noMana, Game game) { if (this.size() > 0) { if (!canChoose(source.getSourceId(), playerId, game)) { return false; } int state = game.bookmarkState(); while (!isChosen()) { Target target = this.getUnchosen().get(0); UUID targetController = playerId; if (target.getTargetController() != null) { // some targets can have controller different than ability controller targetController = target.getTargetController(); } if (noMana) { // if cast without mana (e.g. by suspend you may not be able to cancel the casting if you are able to cast it target.setRequired(true); } if (!target.chooseTarget(outcome, targetController, source, game)) { return false; } // Check if there are some rules for targets are violated, if so reset the targets and start again if (this.getUnchosen().isEmpty() && game.replaceEvent(new GameEvent(GameEvent.EventType.TARGETS_VALID, source.getSourceId(), source.getSourceId(), source.getControllerId()), source)) { game.restoreState(state, "Targets"); clearChosen(); } } } return true; }
if (response.getString() != null && response.getString().equals("special")) { // All attack setStoredBookmark(game.bookmarkState()); UUID attackedDefender = null; if (game.getCombat().getDefenders().size() > 1) {
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; } }
int bookmark = game.bookmarkState(); TriggeredAbility ability = triggeredAbility.copy(); MageObject sourceObject = ability.getSourceObject(game);
int bookmark = game.bookmarkState(); ability.newId(); ability.setControllerId(playerId); int bookmark = game.bookmarkState(); if (ability.activate(game, false)) { ability.resolve(game);
protected boolean specialAction(SpecialAction action, Game game) { //20091005 - 114 if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.ACTIVATE_ABILITY, action.getSourceId(), action.getId(), playerId))) { int bookmark = game.bookmarkState(); if (action.activate(game, false)) { game.fireEvent(GameEvent.getEvent(GameEvent.EventType.ACTIVATED_ABILITY, action.getSourceId(), action.getId(), playerId)); if (!game.isSimulation()) { game.informPlayers(getLogName() + action.getGameLogMessage(game)); } if (action.resolve(game)) { game.removeBookmark(bookmark); resetStoredBookmark(game); return true; } } restoreState(bookmark, action.getRule(), game); } return false; }
if (card != null) { if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, ability.getId(), ability.getSourceId(), playerId, permittingObject), ability)) { int bookmark = game.bookmarkState(); Zone fromZone = game.getState().getZone(card.getMainCard().getId()); card.cast(game, fromZone, ability, playerId);
manaPool.setForcedToPay(true); manaPool.storeMana(); int bookmark = game.bookmarkState();
int bookmark = game.bookmarkState(); if (totalCost.pay(source, game, source.getSourceId(), source.getControllerId(), false, null)) { game.fireEvent(new GameEvent(EventType.PAID_CUMULATIVE_UPKEEP, permanent.getId(), permanent.getId(), player.getId(), ageCounter, false));