Exemplo n.º 1
0
 @Override
 public void setControllerId(UUID controllerId) {
   this.ability.setControllerId(controllerId);
   for (SpellAbility spellAbility : spellAbilities) {
     spellAbility.setControllerId(controllerId);
   }
   this.controllerId = controllerId;
 }
Exemplo n.º 2
0
 @Override
 public boolean apply(Game game, Ability source, Ability abilityToModify) {
   SpellAbility spellAbility = (SpellAbility) abilityToModify;
   Mana mana = spellAbility.getManaCostsToPay().getMana();
   if (mana.getColorless() > 0) {
     int count = new DevotionCount(ColoredManaSymbol.B).calculate(game, source);
     int newCount = mana.getColorless() - count;
     if (newCount < 0) {
       newCount = 0;
     }
     mana.setColorless(newCount);
     spellAbility.getManaCostsToPay().load(mana.toString());
     return true;
   }
   return false;
 }
Exemplo n.º 3
0
 public Spell(Card card, SpellAbility ability, UUID controllerId, Zone fromZone) {
   this.card = card;
   id = ability.getId();
   this.ability = ability;
   this.ability.setControllerId(controllerId);
   if (ability.getSpellAbilityType().equals(SpellAbilityType.SPLIT_FUSED)) {
     spellCards.add(((SplitCard) card).getLeftHalfCard());
     spellAbilities.add(((SplitCard) card).getLeftHalfCard().getSpellAbility().copy());
     spellCards.add(((SplitCard) card).getRightHalfCard());
     spellAbilities.add(((SplitCard) card).getRightHalfCard().getSpellAbility().copy());
   } else {
     spellCards.add(card);
     spellAbilities.add(ability);
   }
   this.controllerId = controllerId;
   this.fromZone = fromZone;
 }
Exemplo n.º 4
0
 @Override
 public boolean apply(Game game, Ability source) {
   Permanent permanent = game.getPermanent(source.getSourceId());
   if (permanent != null) {
     SpellAbility spellAbility =
         (SpellAbility) getValue(EntersBattlefieldEffect.SOURCE_CAST_SPELL_ABILITY);
     if (spellAbility != null
         && spellAbility.getSourceId().equals(source.getSourceId())
         && permanent.getZoneChangeCounter(game)
             == spellAbility.getSourceObjectZoneChangeCounter()) {
       // TODO: No perfect solution because there could be other effects that allow to cast the
       // card for this mana cost
       if (spellAbility.getManaCosts().getText().equals("{W}{U}{B}{R}{G}")) {
         permanent.addCounters(CounterType.P1P1.createInstance(2), game);
       }
     }
   }
   return true;
 }
Exemplo n.º 5
0
 public Spell(final Spell<T> spell) {
   this.id = spell.id;
   for (SpellAbility spellAbility : spell.spellAbilities) {
     this.spellAbilities.add(spellAbility.copy());
   }
   for (Card spellCard : spell.spellCards) {
     this.spellCards.add(spellCard.copy());
   }
   if (spell.spellAbilities.get(0).equals(spell.ability)) {
     this.ability = spellAbilities.get(0);
   } else {
     this.ability = spell.ability.copy();
   }
   if (spell.spellCards.get(0).equals(spell.card)) {
     this.card = spellCards.get(0);
   } else {
     this.card = spell.card.copy();
   }
   this.controllerId = spell.controllerId;
   this.fromZone = spell.fromZone;
   this.copiedSpell = spell.copiedSpell;
 }
Exemplo n.º 6
0
 public boolean activate(Game game, boolean noMana) {
   if (!spellAbilities.get(0).activate(game, noMana)) {
     return false;
   }
   // if there are more abilities (fused split spell) or first ability added new abilities
   // (splice), activate the additional abilities
   boolean ignoreAbility = true;
   boolean payNoMana = noMana;
   for (SpellAbility spellAbility : spellAbilities) {
     // costs for spliced abilities were added to main spellAbility, so pay no man for spliced
     // abilities
     payNoMana |= spellAbility.getSpellAbilityType().equals(SpellAbilityType.SPLICE);
     if (ignoreAbility) {
       ignoreAbility = false;
     } else {
       if (!spellAbility.activate(game, payNoMana)) {
         return false;
       }
     }
   }
   return true;
 }
Exemplo n.º 7
0
  /**
   * @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;
  }
Exemplo n.º 8
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;
   }
 }
Exemplo n.º 9
0
 public String getActivatedMessage(Game game) {
   return ability.getActivatedMessage(game);
 }