@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++; }
sim.undo(playerId);
sim.undo(playerId);
@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(); } } } }
protected static int playerPaysXGenericMana(Player player, Ability source, Game game) { int xValue = 0; boolean payed = false; while (player.canRespond() && !payed) { 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); if (!payed) { game.undo(player.getId()); } } else { payed = true; } } game.informPlayers(player.getLogName() + " pays {" + xValue + "}."); return xValue; } }
public void sendPlayerAction(PlayerAction playerAction, UUID userId, Object data) { switch (playerAction) { case UNDO: game.undo(getPlayerId(userId)); break; case ROLLBACK_TURNS: // basic request of a player to rollback