Exemple #1
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null) {
     // Find the two permanents to meld.
     UUID sourceId = source.getSourceId();
     FilterControlledCreaturePermanent filter =
         new FilterControlledCreaturePermanent("creature named " + meldWithName);
     filter.add(new NamePredicate(meldWithName));
     TargetPermanent target = new TargetControlledCreaturePermanent(filter);
     Set<UUID> meldWithList = target.possibleTargets(sourceId, source.getControllerId(), game);
     if (meldWithList.isEmpty()) {
       return false; // possible permanent has left the battlefield meanwhile
     }
     UUID meldWithId;
     if (meldWithList.size() == 1) {
       meldWithId = meldWithList.iterator().next();
     } else {
       controller.choose(Outcome.BoostCreature, target, sourceId, game);
       meldWithId = target.getFirstTarget();
     }
     // Exile the two permanents to meld.
     Permanent sourcePermanent = game.getPermanent(sourceId);
     Permanent meldWithPermanent = game.getPermanent(meldWithId);
     if (sourcePermanent != null && meldWithPermanent != null) {
       sourcePermanent.moveToExile(null, "", sourceId, game);
       meldWithPermanent.moveToExile(null, "", sourceId, game);
       // Create the meld card and move it to the battlefield.
       Card sourceCard = game.getExile().getCard(sourceId, game);
       Card meldWithCard = game.getExile().getCard(meldWithId, game);
       if (!sourceCard.isCopy() && !meldWithCard.isCopy()) {
         meldCard.setOwnerId(controller.getId());
         meldCard.setTopHalfCard(meldWithCard, game);
         meldCard.setBottomHalfCard(sourceCard, game);
         meldCard.setMelded(true);
         game.addMeldCard(meldCard.getId(), meldCard);
         game.getState().addCard(meldCard);
         meldCard.setZone(Zone.EXILED, game);
         meldCard.moveToZone(Zone.BATTLEFIELD, sourceId, game, false);
       }
       return true;
     }
   }
   return false;
 }
Exemple #2
0
 @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;
   }
 }