/** * @param game * @param playerId * @param forceChange - does only work for targets with maximal one targetId * @param onlyOneTarget - 114.6b one target must be changed to another target * @return */ public boolean chooseNewTargets( Game game, UUID playerId, boolean forceChange, boolean onlyOneTarget) { Player player = game.getPlayer(playerId); if (player != null) { for (SpellAbility spellAbility : spellAbilities) { for (Target target : spellAbility.getTargets()) { Target newTarget = target.copy(); newTarget.clearChosen(); for (UUID targetId : target.getTargets()) { MageObject object = game.getObject(targetId); String name = null; if (object == null) { Player targetPlayer = game.getPlayer(targetId); if (targetPlayer != null) { name = targetPlayer.getName(); } } else { name = object.getName(); } if (name != null && (forceChange || player.chooseUse( spellAbility.getEffects().get(0).getOutcome(), "Change target from " + name + "?", game))) { if (forceChange && target.possibleTargets(this.getSourceId(), playerId, game).size() > 1) { int iteration = 0; do { if (iteration > 0) { game.informPlayer( player, "You may only select exactly one target that must be different from the origin target!"); } iteration++; newTarget.clearChosen(); player.chooseTarget( spellAbility.getEffects().get(0).getOutcome(), newTarget, spellAbility, game); } while (targetId.equals(newTarget.getFirstTarget()) || newTarget.getTargets().size() != 1); } else { if (!player.chooseTarget( spellAbility.getEffects().get(0).getOutcome(), newTarget, spellAbility, game)) { newTarget.addTarget(targetId, spellAbility, game, false); } } } else { newTarget.addTarget(targetId, spellAbility, game, false); } } target.clearChosen(); for (UUID newTargetId : newTarget.getTargets()) { target.addTarget(newTargetId, spellAbility, game, false); } } } return true; } return false; }
@Override public boolean resolve(Game game) { boolean result; if (this.getCardType().contains(CardType.INSTANT) || this.getCardType().contains(CardType.SORCERY)) { int index = 0; result = false; boolean legalParts = false; for (SpellAbility spellAbility : this.spellAbilities) { for (UUID modeId : spellAbility.getModes().getSelectedModes()) { spellAbility.getModes().setMode(spellAbility.getModes().get(modeId)); if (spellAbility.getTargets().stillLegal(spellAbility, game)) { legalParts = true; if (!spellAbility.getSpellAbilityType().equals(SpellAbilityType.SPLICE)) { updateOptionalCosts(index); } result |= spellAbility.resolve(game); } } index++; } if (legalParts) { if (!copiedSpell) { for (Effect effect : ability.getEffects()) { if (effect instanceof PostResolveEffect) { ((PostResolveEffect) effect).postResolve(card, ability, controllerId, game); return result; } } if (!card.isCopy() && game.getState().getZone(card.getId()) == Zone.STACK) { card.moveToZone(Zone.GRAVEYARD, ability.getId(), game, false); } } return result; } // 20091005 - 608.2b game.informPlayers(getName() + " has been fizzled."); counter(null, game); return false; } else if (this.getCardType().contains(CardType.ENCHANTMENT) && this.getSubtype().contains("Aura")) { if (ability.getTargets().stillLegal(ability, game)) { updateOptionalCosts(0); if (card.putOntoBattlefield(game, fromZone, ability.getId(), controllerId)) { return ability.resolve(game); } return false; } if (this.getCardType() .contains( CardType.CREATURE)) { // e.g. Creature with Bestow (rule confirmation yet missing) updateOptionalCosts(0); result = card.putOntoBattlefield(game, fromZone, ability.getId(), controllerId); return result; } else { // 20091005 - 608.2b game.informPlayers(getName() + " has been fizzled."); counter(null, game); return false; } } else { updateOptionalCosts(0); result = card.putOntoBattlefield(game, fromZone, ability.getId(), controllerId); return result; } }