Package mage.cards

Examples of mage.cards.MagePermanent


      int insertIndex = -1;

      // Find lands with the same name.
      for (int i = 0, n = allLands.size(); i < n; i++) {
        Stack stack = allLands.get(i);
        MagePermanent firstPanel = stack.get(0);
        if (firstPanel.getOriginal().getName().equals(permanent.getOriginal().getName())) {
          if (!empty(firstPanel.getLinks())) {
            // Put this land to the left of lands with the same name and attachments.
            insertIndex = i;
            break;
          }
          if (!empty(permanent.getLinks()) || stack.size() == landStackMax) {
            // If this land has attachments or the stack is full, put it to the right.
            insertIndex = i + 1;
            continue;
          }
          // Add to stack.
          stack.add(0, permanent);
          continue outerLoop;
        }
        if (insertIndex != -1)
          break;
      }

      Stack stack = new Stack();
      stack.add(permanent);
      allLands.add(insertIndex == -1 ? allLands.size() : insertIndex, stack);
    }

    Row allCreatures = new Row(permanents, RowType.creature);
    Row allOthers = new Row(permanents, RowType.other);

    cardWidth = cardWidthMax;
    Rectangle rect = jScrollPane.getVisibleRect();
    playAreaWidth = rect.width;
    playAreaHeight = rect.height - MW_GUIDE_HEIGHT;
    while (true) {
      rows.clear();
      cardHeight = Math.round(cardWidth * CardPanel.ASPECT_RATIO);
      extraCardSpacingX = (int) Math.round(cardWidth * EXTRA_CARD_SPACING_X);
      cardSpacingX = cardHeight - cardWidth + extraCardSpacingX;
      cardSpacingY = (int) Math.round(cardHeight * CARD_SPACING_Y);
      stackSpacingX = stackVertical ? 0 : (int) Math.round(cardWidth * STACK_SPACING_X);
      stackSpacingY = (int) Math.round(cardHeight * STACK_SPACING_Y);
      Row creatures = (Row) allCreatures.clone();
      Row lands = (Row) allLands.clone();
      Row others = (Row) allOthers.clone();
      // Wrap all creatures and lands.
      wrap(creatures, rows, -1);
      int afterCreaturesIndex = rows.size();
      wrap(lands, rows, afterCreaturesIndex);
      // Store the current rows and others.
      List<Row> storedRows = new ArrayList<Row>(rows.size());
      for (Row row : rows)
        storedRows.add((Row) row.clone());
      Row storedOthers = (Row) others.clone();
      // Fill in all rows with others.
      for (Row row : rows)
        fillRow(others, rows, row);

      // Stop if everything fits, otherwise revert back to the stored values.
      if (creatures.isEmpty() && lands.isEmpty() && others.isEmpty())
        break;
      rows = storedRows;
      others = storedOthers;
      // Try to put others on their own row(s) and fill in the rest.
      wrap(others, rows, afterCreaturesIndex);
      for (Row row : rows)
        fillRow(others, rows, row);
      // If that still doesn't fit, scale down.
      if (creatures.isEmpty() && lands.isEmpty() && others.isEmpty())
        break;
      //cardWidth = (int)(cardWidth / 1.2);
      cardWidth--;
    }

    // Get size of all the rows.
    int x, y = GUTTER_Y;
    int maxRowWidth = 0;
    for (Row row : rows) {
      int rowBottom = 0;
      x = GUTTER_X;
      for (int stackIndex = 0, stackCount = row.size(); stackIndex < stackCount; stackIndex++) {
        Stack stack = row.get(stackIndex);
        rowBottom = Math.max(rowBottom, y + stack.getHeight());
        x += stack.getWidth();
      }
      y = rowBottom;
      maxRowWidth = Math.max(maxRowWidth, x);
    }
    //setPreferredSize(new Dimension(maxRowWidth - cardSpacingX, y - cardSpacingY));
    //revalidate();

    // Position all card panels.
    x = 0;
    y = GUTTER_Y;
    for (Row row : rows) {
      int rowBottom = 0;
      x = GUTTER_X;
      for (int stackIndex = 0, stackCount = row.size(); stackIndex < stackCount; stackIndex++) {
        Stack stack = row.get(stackIndex);
        // Align others to the right.
        if (RowType.other.isType(stack.get(0))) {
          x = playAreaWidth - GUTTER_X + extraCardSpacingX;
          for (int i = stackIndex, n = row.size(); i < n; i++)
            x -= row.get(i).getWidth();
        }
        for (int panelIndex = 0, panelCount = stack.size(); panelIndex < panelCount; panelIndex++) {
          MagePermanent panel = stack.get(panelIndex);
          int stackPosition = panelCount - panelIndex - 1;
          ///setComponentZOrder((Component)panel, panelIndex);
          int panelX = x + (stackPosition * stackSpacingX);
          int panelY = y + (stackPosition * stackSpacingY);
          //panel.setLocation(panelX, panelY);
          battlefieldPanel.moveToBack(panel);
          panel.setCardBounds(panelX, panelY, cardWidth, cardHeight);
        }
        rowBottom = Math.max(rowBottom, y + stack.getHeight());
        x += stack.getWidth();
      }
      y = rowBottom;
View Full Code Here


      if (!permanents.containsKey(permanent.getId())) {
        addPermanent(permanent);
        changed = true;
      }
      else {
        MagePermanent p = permanents.get(permanent.getId());
        if (!changed) {
          int s1 = permanent.getAttachments() == null ? 0 : permanent.getAttachments().size();
          int s2 = p.getLinks().size();
          if (s1 != s2) {
            changed = true;
          }
        }
        permanents.get(permanent.getId()).update(permanent);
View Full Code Here

    invalidate();
    repaint();
  }

  private void addPermanent(PermanentView permanent) {
    final MagePermanent perm = Plugins.getInstance().getMagePermanent(permanent, bigCard, Config.dimensions, gameId);
    if (!Plugins.getInstance().isCardPluginLoaded()) {
      perm.setBounds(findEmptySpace(new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight)));
    } else {
      perm.setAlpha(0);
    }
    permanents.put(permanent.getId(), perm);
   
    BattlefieldPanel.this.add(perm, 10);
    if (!Plugins.getInstance().isCardPluginLoaded()) {
      moveToFront(perm);
      perm.update(permanent);
    } else {
      Thread t = new Thread(new Runnable() {
        @Override
        public void run() {
              Plugins.getInstance().onAddCard(perm);
View Full Code Here

      }
    }
  }
 
  private void groupAttachments(PermanentView permanent) {
    MagePermanent perm = permanents.get(permanent.getId());
    if (perm == null) return;
    int position = getPosition(perm);
    perm.getLinks().clear();
    Rectangle r = perm.getBounds();
    if (!Plugins.getInstance().isCardPluginLoaded()) {
      for (UUID attachmentId: permanent.getAttachments()) {
        MagePermanent link = permanents.get(attachmentId);
        if (link != null) {
          perm.getLinks().add(link);
          r.translate(20, 20);
          link.setBounds(r);
          setPosition(link, ++position);
        }
      }
    } else {
      for (UUID attachmentId: permanent.getAttachments()) {
        MagePermanent link = permanents.get(attachmentId);
        if (link != null) {
          link.setBounds(r);
          perm.getLinks().add(link);
          r.translate(8, 10);
          perm.setBounds(r);
          moveToFront(link);
          moveToFront(perm);
View Full Code Here

          Point target = p.getLocationOnScreen();
          target.translate(-parent.x, -parent.y);
          ArrowBuilder.addArrow((int)me.getX() + 35, (int)me.getY(), (int)target.getX() + 40, (int)target.getY() - 40, Color.red);
        } else {
          for (PlayAreaPanel pa : session.getGame().getPlayers().values()) {
            MagePermanent permanent = pa.getBattlefieldPanel().getPermanents().get(uuid);
            if (permanent != null) {
              Point target = permanent.getLocationOnScreen();
              target.translate(-parent.x, -parent.y);
              ArrowBuilder.addArrow((int)me.getX() + 35, (int)me.getY(), (int)target.getX() + 40, (int)target.getY() + 10, Color.red);
            }
          }
        }
      }
    }
   
    // Draw Arrows for source
    if (data.card.isAbility()) {
      Point parent = SwingUtilities.getRoot(data.component).getLocationOnScreen();
      Point me = new Point(data.locationOnScreen);
      me.translate(-parent.x, -parent.y);
      UUID uuid = data.card.getParentId();
      for (PlayAreaPanel pa : session.getGame().getPlayers().values()) {
        MagePermanent permanent = pa.getBattlefieldPanel().getPermanents().get(uuid);
        if (permanent != null) {
          Point source = permanent.getLocationOnScreen();
          source.translate(-parent.x, -parent.y);
          ArrowBuilder.addArrow((int)source.getX() + 40, (int)source.getY() + 10, (int)me.getX() + 35, (int)me.getY() + 20, Color.blue);
        }
      }
    }
View Full Code Here

            Point target = p.getLocationOnScreen();
            Point me = this.getLocationOnScreen();
            ArrowBuilder.addArrow((int)me.getX() + 35, (int)me.getY(), (int)target.getX() + 40, (int)target.getY() - 40, Color.red);
          } else {
            for (PlayAreaPanel pa : session.getGame().getPlayers().values()) {
              MagePermanent permanent = pa.getBattlefieldPanel().getPermanents().get(uuid);
              if (permanent != null) {
                Point target = permanent.getLocationOnScreen();
                Point me = this.getLocationOnScreen();
                ArrowBuilder.addArrow((int)me.getX() + 35, (int)me.getY(), (int)target.getX() + 40, (int)target.getY() + 10, Color.red);
              }
            }
          }
View Full Code Here

    public void update(Map<UUID, PermanentView> battlefield) {
        boolean changed = false;

        List<PermanentView> permanentsToAdd = new ArrayList<>();
        for (PermanentView permanent: battlefield.values()) {
            MagePermanent oldMagePermanent = permanents.get(permanent.getId());
            if (oldMagePermanent == null) {
                permanentsToAdd.add(permanent);
                changed = true;
            } else {               
                if (!changed) {
                    changed = CardUtil.isCreature(oldMagePermanent.getOriginalPermanent()) != CardUtil.isCreature(permanent);
                    if (!changed) {
                        int s1 = permanent.getAttachments() == null ? 0 : permanent.getAttachments().size();
                        int s2 = oldMagePermanent.getLinks().size();
                        if (s1 != s2) {
                            changed = true;
                        } else if (s1 > 0) {
                            Set<UUID> attachmentIds = new HashSet<>();
                            attachmentIds.addAll(permanent.getAttachments());
                            for (MagePermanent magePermanent : oldMagePermanent.getLinks()) {
                                if (!attachmentIds.contains(magePermanent.getOriginalPermanent().getId())) {
                                    // that means that the amount of attachments is the same
                                    // but they are different:
                                    // we've just found an attachment on previous view
                                    // that doesn't exist anymore on current view
                                    changed = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (!changed) {
                        UUID u1 = oldMagePermanent.getOriginalPermanent().getAttachedTo();
                        UUID u2 = permanent.getAttachedTo();
                        if (u1 == null && u2 != null || u2 == null && u1 != null
                                || (u1 != null && !u1.equals(u2)) ) {
                            changed = true;
                        }
                    }
                    if (!changed) {
                        List<CounterView> counters1 = oldMagePermanent.getOriginalPermanent().getCounters();
                        List<CounterView> counters2 = permanent.getCounters();
                        if (counters1 == null && counters2 != null || counters1 != null && counters2 == null) {
                            changed = true;
                        } else if (counters1 != null && counters2 != null && counters1.size() != counters2.size()) {
                            changed = true;
                        }
                    }

                }
                oldMagePermanent.update(permanent);
            }
        }

        addedArtifact = addedCreature = addedPermanent = false;
View Full Code Here

    private void addPermanent(PermanentView permanent, final int count) {
        if (cardDimension == null) {
            cardDimension = new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight);
        }
        final MagePermanent perm = Plugins.getInstance().getMagePermanent(permanent, bigCard, cardDimension, gameId, true);
        if (!Plugins.getInstance().isCardPluginLoaded()) {
            //perm.setBounds(findEmptySpace(new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight)));
        } else {
            //perm.setAlpha(0);
        }
        permanents.put(permanent.getId(), perm);

        BattlefieldPanel.this.jPanel.add(perm, 10);
        //this.jPanel.add(perm);
        if (!Plugins.getInstance().isCardPluginLoaded()) {
            moveToFront(perm);
            perm.update(permanent);
        } else {
            moveToFront(jPanel);
            Plugins.getInstance().onAddCard(perm, 1);
            /*Thread t = new Thread(new Runnable() {
                @Override
View Full Code Here

        combatAttackers.put(gameId, count);
    }

    private void drawAttacker(CombatGroupView group, CardView attacker, UUID gameId) {
        for (PlayAreaPanel pa2 : MageFrame.getGame(gameId).getPlayers().values()) {
            MagePermanent attackerCard = pa2.getBattlefieldPanel().getPermanents().get(attacker.getId());
            if (attackerCard != null) {
                drawDefender(group, attackerCard, gameId);
                drawBlockers(group, attackerCard, gameId);
            }
        }
View Full Code Here

                Point attackerPoint = attackerCard.getLocationOnScreen();
                attackerPoint.translate(-parentPoint.x, -parentPoint.y);
                ArrowBuilder.getBuilder().addArrow(gameId, (int) attackerPoint.getX() + 45, (int) attackerPoint.getY() + 25, (int) target.getX() + 40, (int) target.getY() - 20, Color.red, ArrowBuilder.Type.COMBAT);
            } else {
                for (PlayAreaPanel pa : MageFrame.getGame(gameId).getPlayers().values()) {
                    MagePermanent permanent = pa.getBattlefieldPanel().getPermanents().get(defenderId);
                    if (permanent != null) {
                        Point target = permanent.getLocationOnScreen();
                        target.translate(-parentPoint.x, -parentPoint.y);
                        Point attackerPoint = attackerCard.getLocationOnScreen();
                        attackerPoint.translate(-parentPoint.x, -parentPoint.y);
                        ArrowBuilder.getBuilder().addArrow(gameId, (int) attackerPoint.getX() + 45, (int) attackerPoint.getY() + 25, (int) target.getX() + 40, (int) target.getY() + 10, Color.red, ArrowBuilder.Type.COMBAT);
                    }
View Full Code Here

TOP

Related Classes of mage.cards.MagePermanent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.