Пример #1
0
 /**
  * getTokenCreatures.
  *
  * @param cards a {@link java.util.ArrayList} object.
  * @return a {@link java.util.ArrayList} object.
  */
 public static ArrayList<Card> getTokenCreatures(ArrayList<Card> cards) {
   ArrayList<Card> ret = new ArrayList<Card>();
   for (Card c : cards) {
     if (c.isCreature() && c.isToken() && !c.isEquipped() && !c.isEnchanted()) ret.add(c);
   }
   return ret;
 }
Пример #2
0
 /**
  * getGlobalEnchantments.
  *
  * @param cards a {@link java.util.ArrayList} object.
  * @return a {@link java.util.ArrayList} object.
  */
 public static ArrayList<Card> getGlobalEnchantments(ArrayList<Card> cards) {
   ArrayList<Card> ret = new ArrayList<Card>();
   for (Card c : cards) {
     if (c.isGlobalEnchantment() && !c.isCreature()) ret.add(c);
   }
   return ret;
 }
Пример #3
0
 /**
  * getMoxen.
  *
  * @param cards a {@link java.util.ArrayList} object.
  * @param moxName a {@link java.lang.String} object.
  * @return a {@link java.util.ArrayList} object.
  */
 public static ArrayList<Card> getMoxen(ArrayList<Card> cards, String moxName) {
   ArrayList<Card> ret = new ArrayList<Card>();
   for (Card c : cards) {
     String name = c.getName();
     if (name.equals(moxName) && !c.isCreature()) ret.add(c);
   }
   return ret;
 }
Пример #4
0
 /**
  * getTokenCreatures.
  *
  * @param cards a {@link java.util.ArrayList} object.
  * @param tokenName a {@link java.lang.String} object.
  * @return a {@link java.util.ArrayList} object.
  */
 public static ArrayList<Card> getTokenCreatures(ArrayList<Card> cards, String tokenName) {
   ArrayList<Card> ret = new ArrayList<Card>();
   for (Card c : cards) {
     String name = c.getName();
     if (c.isCreature() && c.isToken() && name.equals(tokenName)) ret.add(c);
   }
   return ret;
 }
Пример #5
0
  /**
   * getEquippedEnchantedCreatures.
   *
   * @param cards a {@link java.util.ArrayList} object.
   * @return a {@link java.util.ArrayList} object.
   */
  public static ArrayList<Card> getEquippedEnchantedCreatures(ArrayList<Card> cards) {
    ArrayList<Card> ret = new ArrayList<Card>();
    for (Card c : cards) {
      if (c.isCreature() && (c.isEquipped() || c.isEnchanted())) {
        if (c.isEquipped()) ret.addAll(c.getEquippedBy());
        if (c.isEnchanted()) ret.addAll(c.getEnchantedBy());

        ret.add(c);
      }
    }
    return ret;
  }
Пример #6
0
 /**
  * getNonCreatureArtifacts.
  *
  * @param cards a {@link java.util.ArrayList} object.
  * @return a {@link java.util.ArrayList} object.
  */
 public static ArrayList<Card> getNonCreatureArtifacts(ArrayList<Card> cards) {
   ArrayList<Card> ret = new ArrayList<Card>();
   for (Card c : cards) {
     String name = c.getName();
     if (c.isArtifact()
         && !c.isCreature()
         && !c.isLand()
         && !c.isGlobalEnchantment()
         && !(c.isEquipment() && c.isEquipping())
         && !name.equals("Mox Emerald")
         && !name.equals("Mox Jet")
         && !name.equals("Mox Pearl")
         && !name.equals("Mox Ruby")
         && !name.equals("Mox Sapphire")) ret.add(c);
   }
   return ret;
 }
Пример #7
0
  /**
   * isStackable.
   *
   * @param c a {@link forge.Card} object.
   * @return a boolean.
   */
  public static boolean isStackable(Card c) {

    /*String name = c.getName();
    if( name.equals("Swamp") || name.equals("Bog") ||
        name.equals("Forest") || name.equals("Grass") ||
        name.equals("Plains") || name.equals("White Sand") ||
        name.equals("Mountain") || name.equals("Rock") ||
        name.equals("Island") || name.equals("Underwater")) {
      return true;
    }
    */
    if (c.isLand()
        || (c.getName().startsWith("Mox") && !c.getName().equals("Mox Diamond"))
        || (c.isLand() && c.isEnchanted())
        || (c.isAura() && c.isEnchanting())
        || (c.isToken() && CardFactoryUtil.multipleControlled(c))
        || (c.isCreature() && (c.isEquipped() || c.isEnchanted()))
        || (c.isEquipment() && c.isEquipping())
        || (c.isEnchantment())
        || (c instanceof ManaPool && c.isSnow())) return true;

    return false;
  }
Пример #8
0
  /**
   * setupNoLandPermPanel.
   *
   * @param p a {@link javax.swing.JPanel} object.
   * @param list a {@link java.util.ArrayList} object.
   * @param stack a boolean.
   */
  private static void setupNoLandPermPanel(JPanel p, ArrayList<Card> list, boolean stack) {

    int maxY = 0;
    int maxX = 0;

    Card c;

    if (stack) {
      // add all Cards in list to the GUI, add arrows to Local Enchantments

      ArrayList<Card> planeswalkers = getPlaneswalkers(list);
      ArrayList<Card> equippedEnchantedCreatures =
          getEquippedEnchantedCreatures(
              list); // this will also fetch the equipment and/or enchantment
      ArrayList<Card> nonTokenCreatures = getNonTokenCreatures(list);
      ArrayList<Card> tokenCreatures = getTokenCreatures(list);

      // sort tokenCreatures by name (TODO: fix the warning message somehow)
      Collections.sort(
          tokenCreatures,
          new Comparator<Card>() {
            public int compare(Card c1, Card c2) {
              return c1.getName().compareTo(c2.getName());
            }
          });

      ArrayList<Card> artifacts = getNonCreatureArtifacts(list);
      ArrayList<Card> enchantments = getGlobalEnchantments(list);
      // ArrayList<Card> nonBasics = getNonBasics(list);

      list = new ArrayList<Card>();
      list.addAll(planeswalkers);
      list.addAll(equippedEnchantedCreatures);
      list.addAll(nonTokenCreatures);
      list.addAll(tokenCreatures);
      list.addAll(artifacts);
      list.addAll(enchantments);

      int atInStack = 0;

      int marginX = 5;
      int marginY = 5;

      int x = marginX;

      int cardOffset = Constant.Runtime.stackOffset[0];

      String color = "";
      ArrayList<JPanel> cards = new ArrayList<JPanel>();

      ArrayList<CardPanel> connectedCards = new ArrayList<CardPanel>();

      boolean nextEquippedEnchanted = false;
      int nextXIfNotStacked = 0;
      Card prevCard = null;
      for (int i = 0; i < list.size(); i++) {
        JPanel addPanel;
        c = list.get(i);
        addPanel = new CardPanel(c);

        boolean startANewStack = false;

        if (!isStackable(c)) {
          startANewStack = true;
        } else {
          String newColor = c.getName(); // CardUtil.getColor(c);

          if (!newColor.equals(color)) {
            startANewStack = true;
            color = newColor;
          }
        }

        if (i == 0) {
          startANewStack = false;
        }

        if (!startANewStack && atInStack == Constant.Runtime.stackSize[0]) {
          startANewStack = true;
        }

        if ((c.isEquipment() || c.isAura())
            && (c.isEquipping() || c.isEnchanting())
            && !nextEquippedEnchanted) startANewStack = false;
        else if ((c.isEquipment() || c.isAura()) && (c.isEquipping() || c.isEnchanting())) {
          startANewStack = true;
          nextEquippedEnchanted = false;
        }

        if (c.isCreature() && (c.isEquipped() || c.isEnchanted())) {
          startANewStack = false;
          nextEquippedEnchanted = true;
        }
        // very hacky, but this is to ensure equipment stacking occurs correctly when a token is
        // equipped/enchanted, and there are more tokens of that same name
        else if ((prevCard != null
            && c.isCreature()
            && prevCard.isCreature()
            && (prevCard.isEquipped() || prevCard.isEnchanted())
            && prevCard.getName().equals(c.getName()))) startANewStack = true;
        else if (prevCard != null
            && c.isCreature()
            && prevCard.isCreature()
            && !prevCard.getName().equals(c.getName())) startANewStack = true;

        if (((c.isAura() && c.isEnchanting()) || (c.isEquipment() && c.isEquipping()))
            && prevCard != null
            && prevCard.isPlaneswalker()) startANewStack = true;

        if (startANewStack) {
          setupConnectedCards(connectedCards);
          connectedCards.clear();

          // Fixed distance if last was a stack, looks a bit nicer
          if (atInStack > 1) {
            x +=
                Math.max(addPanel.getPreferredSize().width, addPanel.getPreferredSize().height)
                    + marginX;
          } else {
            x = nextXIfNotStacked;
          }

          atInStack = 0;
        } else {
          if (i != 0) {
            x += cardOffset;
          }
        }

        nextXIfNotStacked = x + marginX + addPanel.getPreferredSize().width;

        int xLoc = x;

        int yLoc = marginY;
        yLoc += atInStack * cardOffset;

        addPanel.setLocation(new Point(xLoc, yLoc));
        addPanel.setSize(addPanel.getPreferredSize());

        cards.add(addPanel);

        connectedCards.add((CardPanel) addPanel);

        atInStack++;
        prevCard = c;
      }

      setupConnectedCards(connectedCards);
      connectedCards.clear();

      for (int i = cards.size() - 1; i >= 0; i--) {
        JPanel card = cards.get(i);
        // maxX = Math.max(maxX, card.getLocation().x + card.getSize().width + marginX);
        maxY = Math.max(maxY, card.getLocation().y + card.getSize().height + marginY);
        p.add(card);
      }

      maxX = nextXIfNotStacked;

      if (maxX > 0 && maxY > 0) { // p.getSize().width || maxY > p.getSize().height) {
        p.setPreferredSize(new Dimension(maxX, maxY));
      }

    } else {
      JPanel addPanel;
      for (int i = 0; i < list.size(); i++) {
        c = list.get(i);
        addPanel = new CardPanel(c);

        p.add(addPanel);
      }
    }
  } // setupPanel()