コード例 #1
0
  @Override
  public void resolve(final SpellAbility sa) {
    final Card host = sa.getHostCard();
    final Map<String, String> svars = host.getSVars();

    // AF specific sa
    int power = -1;
    if (sa.hasParam("Power")) {
      power = AbilityUtils.calculateAmount(host, sa.getParam("Power"), sa);
    }
    int toughness = -1;
    if (sa.hasParam("Toughness")) {
      toughness = AbilityUtils.calculateAmount(host, sa.getParam("Toughness"), sa);
    }
    final Game game = sa.getActivatingPlayer().getGame();

    // Every Animate event needs a unique time stamp
    final long timestamp = game.getNextTimestamp();

    final boolean permanent = sa.hasParam("Permanent");

    final CardType types = new CardType();
    if (sa.hasParam("Types")) {
      types.addAll(Arrays.asList(sa.getParam("Types").split(",")));
    }

    final CardType removeTypes = new CardType();
    if (sa.hasParam("RemoveTypes")) {
      removeTypes.addAll(Arrays.asList(sa.getParam("RemoveTypes").split(",")));
    }

    // allow ChosenType - overrides anything else specified
    if (types.hasSubtype("ChosenType")) {
      types.clear();
      types.add(host.getChosenType());
    }

    final List<String> keywords = new ArrayList<String>();
    if (sa.hasParam("Keywords")) {
      keywords.addAll(Arrays.asList(sa.getParam("Keywords").split(" & ")));
    }

    final List<String> removeKeywords = new ArrayList<String>();
    if (sa.hasParam("RemoveKeywords")) {
      removeKeywords.addAll(Arrays.asList(sa.getParam("RemoveKeywords").split(" & ")));
    }

    final List<String> hiddenKeywords = new ArrayList<String>();
    if (sa.hasParam("HiddenKeywords")) {
      hiddenKeywords.addAll(Arrays.asList(sa.getParam("HiddenKeywords").split(" & ")));
    }
    // allow SVar substitution for keywords
    for (int i = 0; i < keywords.size(); i++) {
      final String k = keywords.get(i);
      if (svars.containsKey(k)) {
        keywords.add(svars.get(k));
        keywords.remove(k);
      }
    }

    // colors to be added or changed to
    String tmpDesc = "";
    if (sa.hasParam("Colors")) {
      final String colors = sa.getParam("Colors");
      if (colors.equals("ChosenColor")) {
        tmpDesc = CardUtil.getShortColorsString(host.getChosenColors());
      } else {
        tmpDesc =
            CardUtil.getShortColorsString(new ArrayList<String>(Arrays.asList(colors.split(","))));
      }
    }
    final String finalDesc = tmpDesc;

    // abilities to add to the animated being
    final List<String> abilities = new ArrayList<String>();
    if (sa.hasParam("Abilities")) {
      abilities.addAll(Arrays.asList(sa.getParam("Abilities").split(",")));
    }
    // replacement effects to add to the animated being
    final List<String> replacements = new ArrayList<String>();
    if (sa.hasParam("Replacements")) {
      replacements.addAll(Arrays.asList(sa.getParam("Replacements").split(",")));
    }
    // triggers to add to the animated being
    final List<String> triggers = new ArrayList<String>();
    if (sa.hasParam("Triggers")) {
      triggers.addAll(Arrays.asList(sa.getParam("Triggers").split(",")));
    }

    // sVars to add to the animated being
    final List<String> sVars = new ArrayList<String>();
    if (sa.hasParam("sVars")) {
      sVars.addAll(Arrays.asList(sa.getParam("sVars").split(",")));
    }

    String valid = "";

    if (sa.hasParam("ValidCards")) {
      valid = sa.getParam("ValidCards");
    }

    CardCollectionView list;
    List<Player> tgtPlayers = getTargetPlayers(sa);

    if (!sa.usesTargeting() && !sa.hasParam("Defined")) {
      list = game.getCardsIn(ZoneType.Battlefield);
    } else {
      list = tgtPlayers.get(0).getCardsIn(ZoneType.Battlefield);
    }

    list = CardLists.getValidCards(list, valid.split(","), host.getController(), host);

    for (final Card c : list) {
      doAnimate(
          c,
          sa,
          power,
          toughness,
          types,
          removeTypes,
          finalDesc,
          keywords,
          removeKeywords,
          hiddenKeywords,
          timestamp);

      // give abilities
      final List<SpellAbility> addedAbilities = new ArrayList<SpellAbility>();
      if (abilities.size() > 0) {
        for (final String s : abilities) {
          final String actualAbility = host.getSVar(s);
          final SpellAbility grantedAbility = AbilityFactory.getAbility(actualAbility, c);
          addedAbilities.add(grantedAbility);
          c.addSpellAbility(grantedAbility);
        }
      }

      // remove abilities
      final List<SpellAbility> removedAbilities = new ArrayList<SpellAbility>();
      if (sa.hasParam("OverwriteAbilities") || sa.hasParam("RemoveAllAbilities")) {
        for (final SpellAbility ab : c.getSpellAbilities()) {
          if (ab.isAbility()) {
            c.removeSpellAbility(ab);
            removedAbilities.add(ab);
          }
        }
      }
      // give replacement effects
      final List<ReplacementEffect> addedReplacements = new ArrayList<ReplacementEffect>();
      if (replacements.size() > 0) {
        for (final String s : replacements) {
          final String actualReplacement = host.getSVar(s);
          final ReplacementEffect parsedReplacement =
              ReplacementHandler.parseReplacement(actualReplacement, c, false);
          addedReplacements.add(c.addReplacementEffect(parsedReplacement));
        }
      }
      // Grant triggers
      final List<Trigger> addedTriggers = new ArrayList<Trigger>();
      if (triggers.size() > 0) {
        for (final String s : triggers) {
          final String actualTrigger = host.getSVar(s);
          final Trigger parsedTrigger = TriggerHandler.parseTrigger(actualTrigger, c, false);
          addedTriggers.add(c.addTrigger(parsedTrigger));
        }
      }

      // suppress triggers from the animated card
      final List<Trigger> removedTriggers = new ArrayList<Trigger>();
      if (sa.hasParam("OverwriteTriggers") || sa.hasParam("RemoveAllAbilities")) {
        final FCollectionView<Trigger> triggersToRemove = c.getTriggers();
        for (final Trigger trigger : triggersToRemove) {
          trigger.setSuppressed(true);
          removedTriggers.add(trigger);
        }
      }

      // suppress static abilities from the animated card
      final List<StaticAbility> removedStatics = new ArrayList<StaticAbility>();
      if (sa.hasParam("OverwriteStatics") || sa.hasParam("RemoveAllAbilities")) {
        final FCollectionView<StaticAbility> staticsToRemove = c.getStaticAbilities();
        for (final StaticAbility stAb : staticsToRemove) {
          stAb.setTemporarilySuppressed(true);
          removedStatics.add(stAb);
        }
      }

      // suppress static abilities from the animated card
      final List<ReplacementEffect> removedReplacements = new ArrayList<ReplacementEffect>();
      if (sa.hasParam("OverwriteReplacements") || sa.hasParam("RemoveAllAbilities")) {
        final FCollectionView<ReplacementEffect> replacementsToRemove = c.getReplacementEffects();
        for (final ReplacementEffect re : replacementsToRemove) {
          re.setTemporarilySuppressed(true);
          removedReplacements.add(re);
        }
      }

      // give sVars
      if (sVars.size() > 0) {
        for (final String s : sVars) {
          final String actualsVar = host.getSVar(s);
          c.setSVar(s, actualsVar);
        }
      }
      game.fireEvent(new GameEventCardStatsChanged(c));

      final GameCommand unanimate =
          new GameCommand() {
            private static final long serialVersionUID = -5861759814760561373L;

            @Override
            public void run() {
              doUnanimate(
                  c,
                  sa,
                  finalDesc,
                  hiddenKeywords,
                  addedAbilities,
                  addedTriggers,
                  addedReplacements,
                  false,
                  removedAbilities,
                  timestamp);

              // give back suppressed triggers
              for (final Trigger t : removedTriggers) {
                t.setSuppressed(false);
              }

              // give back suppressed static abilities
              for (final StaticAbility s : removedStatics) {
                s.setTemporarilySuppressed(false);
              }

              // give back suppressed replacement effects
              for (final ReplacementEffect re : removedReplacements) {
                re.setTemporarilySuppressed(false);
              }
              game.fireEvent(new GameEventCardStatsChanged(c));
            }
          };

      if (!permanent) {
        if (sa.hasParam("UntilEndOfCombat")) {
          game.getEndOfCombat().addUntil(unanimate);
        } else {
          game.getEndOfTurn().addUntil(unanimate);
        }
      }
    }
  } // animateAllResolve
コード例 #2
0
  @Override
  public void resolve(SpellAbility sa) {
    final Card host = sa.getHostCard();
    final Player player = sa.getActivatingPlayer();
    final Game game = player.getGame();
    Player chooser = player;
    int numToDig = AbilityUtils.calculateAmount(host, sa.getParam("DigNum"), sa);

    final ZoneType srcZone =
        sa.hasParam("SourceZone")
            ? ZoneType.smartValueOf(sa.getParam("SourceZone"))
            : ZoneType.Library;

    final ZoneType destZone1 =
        sa.hasParam("DestinationZone")
            ? ZoneType.smartValueOf(sa.getParam("DestinationZone"))
            : ZoneType.Hand;
    final ZoneType destZone2 =
        sa.hasParam("DestinationZone2")
            ? ZoneType.smartValueOf(sa.getParam("DestinationZone2"))
            : ZoneType.Library;

    int libraryPosition =
        sa.hasParam("LibraryPosition") ? Integer.parseInt(sa.getParam("LibraryPosition")) : -1;
    int destZone1ChangeNum = 1;
    final boolean mitosis = sa.hasParam("Mitosis");
    String changeValid = sa.hasParam("ChangeValid") ? sa.getParam("ChangeValid") : "";
    // andOrValid is for cards with "creature card and/or a land card"
    String andOrValid = sa.hasParam("AndOrValid") ? sa.getParam("AndOrValid") : "";
    final boolean anyNumber = sa.hasParam("AnyNumber");

    final int libraryPosition2 =
        sa.hasParam("LibraryPosition2") ? Integer.parseInt(sa.getParam("LibraryPosition2")) : -1;
    final boolean optional = sa.hasParam("Optional");
    final boolean noMove = sa.hasParam("NoMove");
    final boolean skipReorder = sa.hasParam("SkipReorder");

    // A hack for cards like Explorer's Scope that need to ensure that a card is revealed to the
    // player activating the ability
    final boolean forceRevealToController = sa.hasParam("ForceRevealToController");

    // These parameters are used to indicate that a dialog box must be show to the player asking if
    // the player wants to proceed
    // with an optional ability, otherwise the optional ability is skipped.
    final boolean mayBeSkipped = sa.hasParam("PromptToSkipOptionalAbility");
    final String optionalAbilityPrompt =
        sa.hasParam("OptionalAbilityPrompt") ? sa.getParam("OptionalAbilityPrompt") : "";

    boolean changeAll = false;
    boolean allButOne = false;
    final List<String> keywords = new ArrayList<String>();
    if (sa.hasParam("Keywords")) {
      keywords.addAll(Arrays.asList(sa.getParam("Keywords").split(" & ")));
    }

    if (sa.hasParam("ChangeNum")) {
      if (sa.getParam("ChangeNum").equalsIgnoreCase("All")) {
        changeAll = true;
      } else if (sa.getParam("ChangeNum").equalsIgnoreCase("AllButOne")) {
        allButOne = true;
      } else {
        destZone1ChangeNum = AbilityUtils.calculateAmount(host, sa.getParam("ChangeNum"), sa);
      }
    }

    final TargetRestrictions tgt = sa.getTargetRestrictions();
    final List<Player> tgtPlayers = getTargetPlayers(sa);

    if (sa.hasParam("Choser")) {
      final List<Player> choosers =
          AbilityUtils.getDefinedPlayers(sa.getHostCard(), sa.getParam("Choser"), sa);
      if (!choosers.isEmpty()) {
        chooser = choosers.get(0);
      }
    }

    for (final Player p : tgtPlayers) {
      if (tgt != null && !p.canBeTargetedBy(sa)) {
        continue;
      }
      final CardCollection top = new CardCollection();
      final CardCollection rest = new CardCollection();
      final PlayerZone sourceZone = p.getZone(srcZone);

      numToDig = Math.min(numToDig, sourceZone.size());
      for (int i = 0; i < numToDig; i++) {
        top.add(sourceZone.get(i));
      }

      if (!top.isEmpty()) {
        DelayedReveal delayedReveal = null;
        boolean hasRevealed = true;
        if (sa.hasParam("Reveal")) {
          game.getAction().reveal(top, p, false);
        } else if (sa.hasParam("RevealOptional")) {
          String question = "Reveal: " + Lang.joinHomogenous(top) + "?";

          hasRevealed = p.getController().confirmAction(sa, null, question);
          if (hasRevealed) {
            game.getAction().reveal(top, p);
          }
        } else if (sa.hasParam("RevealValid")) {
          final String revealValid = sa.getParam("RevealValid");
          final CardCollection toReveal =
              CardLists.getValidCards(top, revealValid, host.getController(), host);
          if (!toReveal.isEmpty()) {
            game.getAction().reveal(toReveal, host.getController());
            if (sa.hasParam("RememberRevealed")) {
              for (final Card one : toReveal) {
                host.addRemembered(one);
              }
            }
          }
          // Singletons.getModel().getGameAction().revealToCopmuter(top.toArray());
          // - for when it exists
        } else if (!sa.hasParam("NoLooking")) {
          // show the user the revealed cards
          delayedReveal = new DelayedReveal(top, srcZone, PlayerView.get(p));

          if (noMove) {
            // Let the activating player see the cards even if they're not moved
            game.getAction().revealTo(top, player);
          }
        }

        if (sa.hasParam("RememberRevealed") && !sa.hasParam("RevealValid") && hasRevealed) {
          for (final Card one : top) {
            host.addRemembered(one);
          }
        }

        if (!noMove) {
          CardCollection movedCards;
          CardCollection andOrCards;
          for (final Card c : top) {
            rest.add(c);
          }
          CardCollection valid;
          if (mitosis) {
            valid = sharesNameWithCardOnBattlefield(game, top);
            andOrCards = new CardCollection();
          } else if (!changeValid.isEmpty()) {
            if (changeValid.contains("ChosenType")) {
              changeValid = changeValid.replace("ChosenType", host.getChosenType());
            }
            valid =
                CardLists.getValidCards(top, changeValid.split(","), host.getController(), host);
            if (!andOrValid.equals("")) {
              andOrCards =
                  CardLists.getValidCards(top, andOrValid.split(","), host.getController(), host);
              andOrCards.removeAll((Collection<?>) valid);
              valid.addAll(andOrCards);
            } else {
              andOrCards = new CardCollection();
            }
          } else {
            valid = top;
            andOrCards = new CardCollection();
          }

          if (forceRevealToController) {
            // Force revealing the card to the player activating the ability (e.g. Explorer's Scope)
            game.getAction().revealTo(top, player);
          }

          // Optional abilities that use a dialog box to prompt the user to skip the ability (e.g.
          // Explorer's Scope, Quest for Ula's Temple)
          if (optional && mayBeSkipped && !valid.isEmpty()) {
            String prompt =
                !optionalAbilityPrompt.isEmpty()
                    ? optionalAbilityPrompt
                    : "Would you like to proceed with the optional ability for "
                        + sa.getHostCard()
                        + "?\n\n("
                        + sa.getDescription()
                        + ")";
            if (!p.getController()
                .confirmAction(sa, null, prompt.replace("CARDNAME", sa.getHostCard().getName()))) {
              return;
            }
          }

          if (changeAll) {
            movedCards = new CardCollection(valid);
          } else if (sa.hasParam("RandomChange")) {
            int numChanging = Math.min(destZone1ChangeNum, valid.size());
            movedCards = CardLists.getRandomSubList(valid, numChanging);
          } else if (allButOne) {
            movedCards = new CardCollection(valid);
            String prompt;
            if (destZone2.equals(ZoneType.Library) && libraryPosition2 == 0) {
              prompt = "Choose a card to leave on top of {player's} library";
            } else {
              prompt = "Choose a card to leave in {player's} " + destZone2.name();
            }

            Card chosen =
                chooser
                    .getController()
                    .chooseSingleEntityForEffect(valid, delayedReveal, sa, prompt, false, p);
            movedCards.remove(chosen);
            if (sa.hasParam("RandomOrder")) {
              CardLists.shuffle(movedCards);
            }
          } else {
            int j = 0;
            String prompt;

            if (sa.hasParam("PrimaryPrompt")) {
              prompt = sa.getParam("PrimaryPrompt");
            } else {
              prompt = "Choose a card to put into " + destZone1.name();
              if (destZone1.equals(ZoneType.Library)) {
                if (libraryPosition == -1) {
                  prompt = "Choose a card to put on the bottom of {player's} library";
                } else if (libraryPosition == 0) {
                  prompt = "Choose a card to put on top of {player's} library";
                }
              }
            }

            movedCards = new CardCollection();
            while (j < destZone1ChangeNum || (anyNumber && j < numToDig)) {
              // let user get choice
              Card chosen = null;
              if (!valid.isEmpty()) {
                chosen =
                    chooser
                        .getController()
                        .chooseSingleEntityForEffect(
                            valid, delayedReveal, sa, prompt, anyNumber || optional, p);
              } else {
                chooser.getController().notifyOfValue(sa, null, "No valid cards");
              }

              if (chosen == null) {
                break;
              }

              movedCards.add(chosen);
              valid.remove(chosen);
              if (!andOrValid.equals("")) {
                andOrCards.remove(chosen);
                if (!chosen.isValid(andOrValid.split(","), host.getController(), host)) {
                  valid = new CardCollection(andOrCards);
                } else if (!chosen.isValid(changeValid.split(","), host.getController(), host)) {
                  valid.removeAll((Collection<?>) andOrCards);
                }
              }
              j++;
            }

            if (!changeValid.isEmpty()) {
              game.getAction()
                  .reveal(
                      movedCards,
                      chooser,
                      true,
                      chooser
                          + " picked "
                          + (movedCards.size() == 1 ? "this card" : "these cards")
                          + " from ");
            }
          }
          if (sa.hasParam("ForgetOtherRemembered")) {
            host.clearRemembered();
          }
          Collections.reverse(movedCards);
          for (Card c : movedCards) {
            final PlayerZone zone = c.getOwner().getZone(destZone1);

            if (zone.is(ZoneType.Library)
                || zone.is(ZoneType.PlanarDeck)
                || zone.is(ZoneType.SchemeDeck)) {
              if (libraryPosition == -1 || libraryPosition > zone.size()) {
                libraryPosition = zone.size();
              }
              c = game.getAction().moveTo(zone, c, libraryPosition);
            } else {
              c = game.getAction().moveTo(zone, c);
              if (destZone1.equals(ZoneType.Battlefield)) {
                for (final String kw : keywords) {
                  c.addExtrinsicKeyword(kw);
                }
                if (sa.hasParam("Tapped")) {
                  c.setTapped(true);
                }
              }
            }

            if (sa.hasParam("ExileFaceDown")) {
              c.setState(CardStateName.FaceDown, true);
            }
            if (sa.hasParam("Imprint")) {
              host.addImprintedCard(c);
            }
            if (sa.hasParam("ForgetOtherRemembered")) {
              host.clearRemembered();
            }
            if (sa.hasParam("RememberChanged")) {
              host.addRemembered(c);
            }
            rest.remove(c);
          }

          // now, move the rest to destZone2
          if (destZone2 == ZoneType.Library
              || destZone2 == ZoneType.PlanarDeck
              || destZone2 == ZoneType.SchemeDeck) {
            CardCollection afterOrder = rest;
            if (sa.hasParam("RestRandomOrder")) {
              CardLists.shuffle(afterOrder);
            } else if (!skipReorder && rest.size() > 1) {
              afterOrder =
                  (CardCollection) chooser.getController().orderMoveToZoneList(rest, destZone2);
            }
            if (libraryPosition2 != -1) {
              // Closest to top
              Collections.reverse(afterOrder);
            }
            for (final Card c : afterOrder) {
              if (destZone2 == ZoneType.Library) {
                game.getAction().moveToLibrary(c, libraryPosition2);
              } else {
                game.getAction().moveToVariantDeck(c, destZone2, libraryPosition2);
              }
            }
          } else {
            // just move them randomly
            for (int i = 0; i < rest.size(); i++) {
              Card c = rest.get(i);
              final PlayerZone toZone = c.getOwner().getZone(destZone2);
              c = game.getAction().moveTo(toZone, c);
              if (destZone2.equals(ZoneType.Battlefield) && !keywords.isEmpty()) {
                for (final String kw : keywords) {
                  c.addExtrinsicKeyword(kw);
                }
              }
            }
          }
        }
      }
    }
  }