public GameState(final GameState state) { this.players = state.players.copy(); this.playerList = state.playerList.copy(); this.activePlayerId = state.activePlayerId; this.priorityPlayerId = state.priorityPlayerId; this.turn = state.turn.copy(); this.stack = state.stack.copy(); this.command = state.command.copy(); this.exile = state.exile.copy(); this.revealed = state.revealed.copy(); this.lookedAt.putAll(state.lookedAt); this.battlefield = state.battlefield.copy(); this.turnNum = state.turnNum; this.extraTurn = state.extraTurn; this.legendaryRuleActive = state.legendaryRuleActive; this.gameOver = state.gameOver; this.effects = state.effects.copy(); for (TriggeredAbility trigger : state.triggered) { this.triggered.add(trigger.copy()); } this.triggers = state.triggers.copy(); this.delayed = state.delayed.copy(); this.specialActions = state.specialActions.copy(); this.combat = state.combat.copy(); this.turnMods = state.turnMods.copy(); this.watchers = state.watchers.copy(); for (Map.Entry<String, Object> entry : state.values.entrySet()) { if (entry.getValue() instanceof Boolean) { // AI changed values of Boolean for cards like Wall of Roots TODO: copy other // types than Boolean this.values.put(entry.getKey(), Boolean.valueOf(((Boolean) entry.getValue()).toString())); } else { this.values.put(entry.getKey(), entry.getValue()); } } this.zones.putAll(state.zones); for (Map.Entry<UUID, Abilities<ActivatedAbility>> entry : state.otherAbilities.entrySet()) { otherAbilities.put(entry.getKey(), entry.getValue().copy()); } this.paused = state.paused; }
@Override public boolean triggerAbility(TriggeredAbility source, Game game) { Ability ability = source.copy(); List<Ability> options = getPlayableOptions(ability, game); if (options.isEmpty()) { if (logger.isDebugEnabled()) logger.debug("simulating -- triggered ability:" + ability); game.getStack().push(new StackAbility(ability, playerId)); ability.activate(game, false); game.applyEffects(); game.getPlayers().resetPassed(); } else { SimulationNode parent = (SimulationNode) game.getCustomData(); if (parent.getDepth() == maxDepth) return true; logger.debug( indent(parent.getDepth()) + "simulating -- triggered ability - adding children:" + options.size()); for (Ability option : options) { addAbilityNode(parent, option, game); } } return true; }