private Deck getGeneratedDeck() {
   switch (lstDecks.getGameType()) {
     case Commander:
       return DeckgenUtil.generateCommanderDeck(isAi, GameType.Commander);
     case TinyLeaders:
       return DeckgenUtil.generateCommanderDeck(isAi, GameType.TinyLeaders);
     case Archenemy:
       return DeckgenUtil.generateSchemeDeck();
     case Planechase:
       return DeckgenUtil.generatePlanarDeck();
     default:
       while (true) {
         switch (Aggregates.random(DeckType.ConstructedOptions)) {
           case PRECONSTRUCTED_DECK:
             return Aggregates.random(
                     DeckProxy.getAllPreconstructedDecks(QuestController.getPrecons()))
                 .getDeck();
           case QUEST_OPPONENT_DECK:
             return Aggregates.random(DeckProxy.getAllQuestEventAndChallenges()).getDeck();
           case COLOR_DECK:
             final List<String> colors = new ArrayList<String>();
             final int count = Aggregates.randomInt(1, 3);
             for (int i = 1; i <= count; i++) {
               colors.add("Random " + i);
             }
             return DeckgenUtil.buildColorDeck(colors, isAi);
           case THEME_DECK:
             return Aggregates.random(DeckProxy.getAllThemeDecks()).getDeck();
           default:
             continue;
         }
       }
   }
 }
 private Deck getFavoriteDeck() {
   Iterable<DeckProxy> decks;
   switch (lstDecks.getGameType()) {
     case Commander:
       decks = DeckProxy.getAllCommanderDecks();
       break;
     case TinyLeaders:
       decks = DeckProxy.getAllTinyLeadersDecks();
       break;
     case Archenemy:
       decks = DeckProxy.getAllSchemeDecks();
       break;
     case Planechase:
       decks = DeckProxy.getAllPlanarDecks();
       break;
     default:
       decks = DeckProxy.getAllConstructedDecks();
       break;
   }
   decks =
       Iterables.filter(
           decks,
           new Predicate<DeckProxy>() {
             @Override
             public boolean apply(final DeckProxy deck) {
               return deck.isFavoriteDeck();
             }
           });
   if (Iterables.isEmpty(decks)) {
     return getGeneratedDeck(); // fall back to generated deck if no favorite decks
   }
   return Aggregates.random(decks).getDeck();
 }
 private Deck getUserDeck() {
   Iterable<DeckProxy> decks;
   final GameType gameType = lstDecks.getGameType();
   switch (gameType) {
     case Commander:
       decks = DeckProxy.getAllCommanderDecks(DeckFormat.Commander.isLegalDeckPredicate());
       break;
     case TinyLeaders:
       decks = DeckProxy.getAllTinyLeadersDecks(DeckFormat.TinyLeaders.isLegalDeckPredicate());
       break;
     case Archenemy:
       decks = DeckProxy.getAllSchemeDecks(DeckFormat.Archenemy.isLegalDeckPredicate());
       break;
     case Planechase:
       decks = DeckProxy.getAllPlanarDecks(DeckFormat.Planechase.isLegalDeckPredicate());
       break;
     default:
       decks = DeckProxy.getAllConstructedDecks(gameType.getDeckFormat().isLegalDeckPredicate());
       break;
   }
   if (Iterables.isEmpty(decks)) {
     return getGeneratedDeck(); // fall back to generated deck if no decks in filtered list
   }
   return Aggregates.random(decks).getDeck();
 }
Example #4
0
  /**
   * chooseBoonTarget.
   *
   * @param list a {@link forge.CardList} object.
   * @param type a {@link java.lang.String} object.
   * @return a {@link forge.game.card.Card} object.
   */
  public static Card chooseBoonTarget(final CardCollectionView list, final String type) {
    Card choice = null;
    if (type.equals("P1P1")) {
      choice = ComputerUtilCard.getBestCreatureAI(list);

      if (choice == null) {
        // We'd only get here if list isn't empty, maybe we're trying to animate a land?
        choice = ComputerUtilCard.getBestLandToAnimate(list);
      }
    } else if (type.equals("DIVINITY")) {
      final CardCollection boon =
          CardLists.filter(
              list,
              new Predicate<Card>() {
                @Override
                public boolean apply(final Card c) {
                  return c.getCounters(CounterType.DIVINITY) == 0;
                }
              });
      choice = ComputerUtilCard.getMostExpensivePermanentAI(boon, null, false);
    } else {
      // The AI really should put counters on cards that can use it.
      // Charge counters on things with Charge abilities, etc. Expand
      // these above
      choice = Aggregates.random(list);
    }
    return choice;
  }
Example #5
0
 /**
  * chooseCursedTarget.
  *
  * @param list a {@link forge.CardList} object.
  * @param type a {@link java.lang.String} object.
  * @param amount a int.
  * @return a {@link forge.game.card.Card} object.
  */
 public static Card chooseCursedTarget(
     final CardCollectionView list, final String type, final int amount) {
   Card choice;
   if (type.equals("M1M1")) {
     // try to kill the best killable creature, or reduce the best one
     final List<Card> killable =
         CardLists.filter(
             list,
             new Predicate<Card>() {
               @Override
               public boolean apply(final Card c) {
                 return c.getNetToughness() <= amount;
               }
             });
     if (killable.size() > 0) {
       choice = ComputerUtilCard.getBestCreatureAI(killable);
     } else {
       choice = ComputerUtilCard.getBestCreatureAI(list);
     }
   } else {
     // improve random choice here
     choice = Aggregates.random(list);
   }
   return choice;
 }
 @Override
 public SpellAbility chooseSingleSpellAbility(
     Player player, SpellAbility sa, List<SpellAbility> spells) {
   final String logic = sa.getParam("AILogic");
   if ("Random".equals(logic)) {
     return Aggregates.random(spells);
   } else if ("Phasing".equals(logic)) { // Teferi's Realm : keep aggressive
     List<SpellAbility> filtered =
         Lists.newArrayList(
             Iterables.filter(
                 spells,
                 new Predicate<SpellAbility>() {
                   @Override
                   public boolean apply(final SpellAbility sp) {
                     return !sp.getDescription().contains("Creature")
                         && !sp.getDescription().contains("Land");
                   }
                 }));
     return Aggregates.random(filtered);
   } else if ("PayUnlessCost".equals(logic)) {
     for (final SpellAbility sp : spells) {
       String unlessCost = sp.getParam("UnlessCost");
       sp.setActivatingPlayer(sa.getActivatingPlayer());
       Cost unless = new Cost(unlessCost, false);
       SpellAbility paycost = new SpellAbility.EmptySa(sa.getHostCard(), player);
       paycost.setPayCosts(unless);
       if (ComputerUtilCost.willPayUnlessCost(
               sp, player, unless, false, new FCollection<Player>(player))
           && ComputerUtilCost.canPayCost(paycost, player)) {
         return sp;
       }
     }
     return spells.get(0);
   } else if ("Khans".equals(logic) || "Dragons".equals(logic)) { // Fate Reforged sieges
     for (final SpellAbility sp : spells) {
       if (sp.getDescription().equals(logic)) {
         return sp;
       }
     }
   }
   return spells.get(0); // return first choice if no logic found
 }
  /* (non-Javadoc)
   * @see forge.card.ability.SpellAbilityEffect#resolve(forge.card.spellability.SpellAbility)
   */
  @Override
  public void resolve(final SpellAbility sa) {
    final Card hostCard = sa.getHostCard();
    final Game game = hostCard.getGame();
    final List<String> keywords = new ArrayList<String>();
    final List<String> types = new ArrayList<String>();
    final List<String> svars = new ArrayList<String>();
    final List<String> triggers = new ArrayList<String>();
    if (sa.hasParam("Optional")) {
      if (!sa.getActivatingPlayer()
          .getController()
          .confirmAction(sa, null, "Copy this permanent?")) {
        return;
      }
    }
    if (sa.hasParam("Keywords")) {
      keywords.addAll(Arrays.asList(sa.getParam("Keywords").split(" & ")));
    }
    if (sa.hasParam("AddTypes")) {
      types.addAll(Arrays.asList(sa.getParam("AddTypes").split(" & ")));
    }
    if (sa.hasParam("AddSVars")) {
      svars.addAll(Arrays.asList(sa.getParam("AddSVars").split(" & ")));
    }
    if (sa.hasParam("Triggers")) {
      triggers.addAll(Arrays.asList(sa.getParam("Triggers").split(" & ")));
    }
    final int numCopies =
        sa.hasParam("NumCopies")
            ? AbilityUtils.calculateAmount(hostCard, sa.getParam("NumCopies"), sa)
            : 1;

    Player controller = null;
    if (sa.hasParam("Controller")) {
      final FCollectionView<Player> defined =
          AbilityUtils.getDefinedPlayers(hostCard, sa.getParam("Controller"), sa);
      if (!defined.isEmpty()) {
        controller = defined.getFirst();
      }
    }
    if (controller == null) {
      controller = sa.getActivatingPlayer();
    }

    List<Card> tgtCards = getTargetCards(sa);
    final TargetRestrictions tgt = sa.getTargetRestrictions();

    if (sa.hasParam("ValidSupportedCopy")) {
      List<PaperCard> cards =
          Lists.newArrayList(StaticData.instance().getCommonCards().getUniqueCards());
      String valid = sa.getParam("ValidSupportedCopy");
      if (valid.contains("X")) {
        valid =
            valid.replace("X", Integer.toString(AbilityUtils.calculateAmount(hostCard, "X", sa)));
      }
      if (StringUtils.containsIgnoreCase(valid, "creature")) {
        Predicate<PaperCard> cpp =
            Predicates.compose(CardRulesPredicates.Presets.IS_CREATURE, PaperCard.FN_GET_RULES);
        cards = Lists.newArrayList(Iterables.filter(cards, cpp));
      }
      if (StringUtils.containsIgnoreCase(valid, "equipment")) {
        Predicate<PaperCard> cpp =
            Predicates.compose(CardRulesPredicates.Presets.IS_EQUIPMENT, PaperCard.FN_GET_RULES);
        cards = Lists.newArrayList(Iterables.filter(cards, cpp));
      }
      if (sa.hasParam("RandomCopied")) {
        List<PaperCard> copysource = new ArrayList<PaperCard>(cards);
        List<Card> choice = new ArrayList<Card>();
        final String num = sa.hasParam("RandomNum") ? sa.getParam("RandomNum") : "1";
        int ncopied = AbilityUtils.calculateAmount(hostCard, num, sa);
        while (ncopied > 0) {
          final PaperCard cp = Aggregates.random(copysource);
          Card possibleCard =
              Card.fromPaperCard(
                  cp,
                  sa.getActivatingPlayer()); // Need to temporarily set the Owner so the Game is set

          if (possibleCard.isValid(valid, hostCard.getController(), hostCard)) {
            choice.add(possibleCard);
            copysource.remove(cp);
            ncopied -= 1;
          }
        }
        tgtCards = choice;
      } else if (sa.hasParam("DefinedName")) {
        String name = sa.getParam("DefinedName");
        if (name.equals("NamedCard")) {
          if (!hostCard.getNamedCard().isEmpty()) {
            name = hostCard.getNamedCard();
          }
        }

        Predicate<PaperCard> cpp =
            Predicates.compose(
                CardRulesPredicates.name(StringOp.EQUALS, name), PaperCard.FN_GET_RULES);
        cards = Lists.newArrayList(Iterables.filter(cards, cpp));

        tgtCards.clear();
        if (!cards.isEmpty()) {
          tgtCards.add(Card.fromPaperCard(cards.get(0), controller));
        }
      }
    }
    hostCard.clearClones();

    for (final Card c : tgtCards) {
      if ((tgt == null) || c.canBeTargetedBy(sa)) {

        int multiplier = numCopies * hostCard.getController().getTokenDoublersMagnitude();
        final List<Card> crds = new ArrayList<Card>(multiplier);

        for (int i = 0; i < multiplier; i++) {
          final Card copy = CardFactory.copyCopiableCharacteristics(c, sa.getActivatingPlayer());
          copy.setToken(true);
          copy.setCopiedPermanent(c);
          CardFactory.copyCopiableAbilities(c, copy);
          // add keywords from sa
          for (final String kw : keywords) {
            copy.addIntrinsicKeyword(kw);
          }
          for (final String type : types) {
            copy.addType(type);
          }
          for (final String svar : svars) {
            String actualsVar = hostCard.getSVar(svar);
            String name = svar;
            if (actualsVar.startsWith("SVar:")) {
              actualsVar = actualsVar.split("SVar:")[1];
              name = actualsVar.split(":")[0];
              actualsVar = actualsVar.split(":")[1];
            }
            copy.setSVar(name, actualsVar);
          }
          for (final String s : triggers) {
            final String actualTrigger = hostCard.getSVar(s);
            final Trigger parsedTrigger = TriggerHandler.parseTrigger(actualTrigger, copy, true);
            copy.addTrigger(parsedTrigger);
          }

          // Temporarily register triggers of an object created with CopyPermanent
          // game.getTriggerHandler().registerActiveTrigger(copy, false);
          final Card copyInPlay = game.getAction().moveToPlay(copy);

          // when copying something stolen:
          copyInPlay.setController(controller, 0);
          copyInPlay.setSetCode(c.getSetCode());

          copyInPlay.setCloneOrigin(hostCard);
          sa.getHostCard().addClone(copyInPlay);
          crds.add(copyInPlay);
          if (sa.hasParam("RememberCopied")) {
            hostCard.addRemembered(copyInPlay);
          }
          if (sa.hasParam("Tapped")) {
            copyInPlay.setTapped(true);
          }
          if (sa.hasParam("CopyAttacking") && game.getPhaseHandler().inCombat()) {
            final String attacked = sa.getParam("CopyAttacking");
            GameEntity defender;
            if ("True".equals(attacked)) {
              FCollectionView<GameEntity> defs = game.getCombat().getDefenders();
              defender =
                  c.getController()
                      .getController()
                      .chooseSingleEntityForEffect(
                          defs, sa, "Choose which defender to attack with " + c, false);
            } else {
              defender =
                  AbilityUtils.getDefinedPlayers(hostCard, sa.getParam("CopyAttacking"), sa).get(0);
            }
            game.getCombat().addAttacker(copyInPlay, defender);
            game.fireEvent(new GameEventCombatChanged());
          }

          if (sa.hasParam("AttachedTo")) {
            CardCollectionView list =
                AbilityUtils.getDefinedCards(hostCard, sa.getParam("AttachedTo"), sa);
            if (list.isEmpty()) {
              list = copyInPlay.getController().getGame().getCardsIn(ZoneType.Battlefield);
              list =
                  CardLists.getValidCards(
                      list, sa.getParam("AttachedTo"), copyInPlay.getController(), copyInPlay);
            }
            if (!list.isEmpty()) {
              Card attachedTo =
                  sa.getActivatingPlayer()
                      .getController()
                      .chooseSingleEntityForEffect(
                          list, sa, copyInPlay + " - Select a card to attach to.");
              if (copyInPlay.isAura()) {
                if (attachedTo.canBeEnchantedBy(copyInPlay)) {
                  copyInPlay.enchantEntity(attachedTo);
                } else { // can't enchant
                  continue;
                }
              } else if (copyInPlay.isEquipment()) { // Equipment
                if (attachedTo.canBeEquippedBy(copyInPlay)) {
                  copyInPlay.equipCard(attachedTo);
                } else {
                  continue;
                }
              } else { // Fortification
                copyInPlay.fortifyCard(attachedTo);
              }
            } else {
              continue;
            }
          }
        }

        if (sa.hasParam("AtEOT")) {
          final String location = sa.getParam("AtEOT");
          registerDelayedTrigger(sa, location, crds);
        }
      } // end canBeTargetedBy
    } // end foreach Card
  } // end resolve