예제 #1
0
  public static void transform(Permanent permanent, Card sourceCard, Game game) {

    if (sourceCard == null) {
      return;
    }

    permanent.setName(sourceCard.getName());
    permanent.getColor().setColor(sourceCard.getColor());
    permanent.getManaCost().clear();
    permanent.getManaCost().add(sourceCard.getManaCost());
    permanent.getCardType().clear();
    for (CardType type : sourceCard.getCardType()) {
      permanent.getCardType().add(type);
    }
    permanent.getSubtype().clear();
    for (String type : sourceCard.getSubtype()) {
      permanent.getSubtype().add(type);
    }
    permanent.getSupertype().clear();
    for (String type : sourceCard.getSupertype()) {
      permanent.getSupertype().add(type);
    }
    permanent.setExpansionSetCode(sourceCard.getExpansionSetCode());
    permanent.getAbilities().clear();
    for (Ability ability : sourceCard.getAbilities()) {
      permanent.addAbility(ability, game);
    }
    permanent.getPower().setValue(sourceCard.getPower().getValue());
    permanent.getToughness().setValue(sourceCard.getToughness().getValue());
  }
예제 #2
0
 public SimpleCardsView(Collection<Card> cards) {
   for (Card card : cards) {
     this.put(
         card.getId(),
         new SimpleCardView(
             card.getId(),
             card.getExpansionSetCode(),
             card.getCardNumber(),
             card.isFaceDown(),
             card.getUsesVariousArt()));
   }
 }
예제 #3
0
파일: Token.java 프로젝트: xdaft/mage
 public boolean putOntoBattlefield(int amount, Game game, UUID sourceId, UUID controllerId) {
   Card source = game.getCard(sourceId);
   String setCode = source != null ? source.getExpansionSetCode() : null;
   GameEvent event =
       GameEvent.getEvent(EventType.CREATE_TOKEN, null, sourceId, controllerId, amount);
   if (!game.replaceEvent(event)) {
     amount = event.getAmount();
     for (int i = 0; i < amount; i++) {
       PermanentToken permanent = new PermanentToken(this, controllerId, setCode, game);
       game.getState().addCard(permanent);
       game.addPermanent(permanent);
       this.lastAddedTokenId = permanent.getId();
       permanent.entersBattlefield(sourceId, game);
       game.applyEffects();
       game.fireEvent(
           new ZoneChangeEvent(permanent, controllerId, Zone.OUTSIDE, Zone.BATTLEFIELD));
     }
     return true;
   }
   return false;
 }
예제 #4
0
파일: Token.java 프로젝트: royk/mage
  public boolean putOntoBattlefield(
      int amount,
      Game game,
      UUID sourceId,
      UUID controllerId,
      boolean tapped,
      boolean attacking,
      UUID attackedPlayer) {
    Player controller = game.getPlayer(controllerId);
    if (controller == null) {
      return false;
    }
    lastAddedTokenIds.clear();

    // moved here from CreateTokenEffect because not all cards that create tokens use
    // CreateTokenEffect
    // they use putOntoBattlefield directly
    // TODO: Check this setCode handling because it makes no sense if token put into play with e.g.
    // "Feldon of the third Path"
    String setCode = null;
    if (this.getOriginalExpansionSetCode() != null
        && !this.getOriginalExpansionSetCode().isEmpty()) {
      setCode = this.getOriginalExpansionSetCode();
    } else {
      Card source = game.getCard(sourceId);
      if (source != null) {
        setCode = source.getExpansionSetCode();
      } else {
        MageObject object = game.getObject(sourceId);
        if (object instanceof PermanentToken) {
          setCode = ((PermanentToken) object).getExpansionSetCode();
        }
      }
    }
    if (!expansionSetCodeChecked) {
      expansionSetCodeChecked = this.updateExpansionSetCode(setCode);
    }

    GameEvent event =
        new GameEvent(
            EventType.CREATE_TOKEN,
            null,
            sourceId,
            controllerId,
            amount,
            this.getCardType().contains(CardType.CREATURE));
    if (!game.replaceEvent(event)) {
      amount = event.getAmount();

      List<Permanent> permanents = new ArrayList<>();
      List<Permanent> permanentsEntered = new ArrayList<>();

      for (int i = 0; i < amount; i++) {
        PermanentToken newToken =
            new PermanentToken(
                this,
                event.getPlayerId(),
                setCode,
                game); // use event.getPlayerId() because it can be replaced by replacement effect
        game.getState().addCard(newToken);
        permanents.add(newToken);
        game.getPermanentsEntering().put(newToken.getId(), newToken);
        newToken.setTapped(tapped);
      }
      game.setScopeRelevant(true);
      for (Permanent permanent : permanents) {
        if (permanent.entersBattlefield(sourceId, game, Zone.OUTSIDE, true)) {
          permanentsEntered.add(permanent);
        } else {
          game.getPermanentsEntering().remove(permanent.getId());
        }
      }
      game.setScopeRelevant(false);
      for (Permanent permanent : permanentsEntered) {
        game.addPermanent(permanent);
        permanent.setZone(Zone.BATTLEFIELD, game);
        game.getPermanentsEntering().remove(permanent.getId());

        this.lastAddedTokenIds.add(permanent.getId());
        this.lastAddedTokenId = permanent.getId();
        game.addSimultaneousEvent(
            new ZoneChangeEvent(
                permanent, permanent.getControllerId(), Zone.OUTSIDE, Zone.BATTLEFIELD));
        if (attacking && game.getCombat() != null) {
          game.getCombat().addAttackingCreature(permanent.getId(), game, attackedPlayer);
        }
        if (!game.isSimulation()) {
          game.informPlayers(
              controller.getLogName()
                  + " puts a "
                  + permanent.getLogName()
                  + " token onto the battlefield");
        }
      }
      return true;
    }
    return false;
  }
예제 #5
0
파일: GameView.java 프로젝트: bradens/mage
  public GameView(GameState state, Game game) {
    for (Player player : state.getPlayers().values()) {
      players.add(new PlayerView(player, state, game));
    }
    for (StackObject stackObject : state.getStack()) {
      if (stackObject instanceof StackAbility) {
        MageObject object = game.getObject(stackObject.getSourceId());
        Card card = game.getCard(stackObject.getSourceId());
        if (card != null) {
          if (object != null) {
            stack.put(
                stackObject.getId(),
                new StackAbilityView(
                    game, (StackAbility) stackObject, card.getName(), new CardView(card)));
          } else {
            stack.put(
                stackObject.getId(),
                new StackAbilityView(game, (StackAbility) stackObject, "", new CardView(card)));
          }
          if (card.canTransform()) {
            updateLatestCardView(game, card, stackObject.getId());
          }
          checkPaid(stackObject.getId(), (StackAbility) stackObject);
        } else if (object != null) {
          if (object instanceof PermanentToken) {
            PermanentToken token = (PermanentToken) object;
            stack.put(stackObject.getId(), new CardView(token));
            checkPaid(stackObject.getId(), (StackAbility) stackObject);
          } else {
            StackAbility stackAbility = ((StackAbility) object);
            stackAbility.newId();
            MageObject emblem = game.getEmblem(stackAbility.getSourceId());
            if (emblem != null) {
              Card sourceCard = game.getCard(((CommandObject) emblem).getSourceId());
              if (sourceCard != null) {
                stackAbility.setName("Emblem " + sourceCard.getName());
                stackAbility.setExpansionSetCode(sourceCard.getExpansionSetCode());
              }
            }

            stack.put(stackObject.getId(), new CardView(stackAbility));
            checkPaid(stackObject.getId(), stackAbility);
          }
        }
      } else {
        stack.put(stackObject.getId(), new CardView((Spell) stackObject));
        checkPaid(stackObject.getId(), (Spell) stackObject);
      }
      // stackOrder.add(stackObject.getId());
    }
    // Collections.reverse(stackOrder);
    for (ExileZone exileZone : state.getExile().getExileZones()) {
      exiles.add(new ExileView(exileZone, game));
    }
    for (String name : state.getRevealed().keySet()) {
      revealed.add(new RevealedView(name, state.getRevealed().get(name), game));
    }
    this.phase = state.getTurn().getPhaseType();
    this.step = state.getTurn().getStepType();
    this.turn = state.getTurnNum();
    if (state.getActivePlayerId() != null)
      this.activePlayerName = state.getPlayer(state.getActivePlayerId()).getName();
    else this.activePlayerName = "";
    if (state.getPriorityPlayerId() != null)
      this.priorityPlayerName = state.getPlayer(state.getPriorityPlayerId()).getName();
    else this.priorityPlayerName = "";
    for (CombatGroup combatGroup : state.getCombat().getGroups()) {
      combat.add(new CombatGroupView(combatGroup, game));
    }
    this.special =
        state.getSpecialActions().getControlledBy(state.getPriorityPlayerId()).size() > 0;
  }
예제 #6
0
  @Override
  public Token apply(Card source) {
    if (target == null) {
      throw new IllegalArgumentException("Target can't be null");
    }
    // A copy contains only the attributes of the basic card or basic Token that's the base of the
    // permanent
    // else gained abililies would be copied too.

    MageObject sourceObj = source;
    if (source instanceof PermanentToken) {
      sourceObj = ((PermanentToken) source).getToken();
      // to show the source image, the original values have to be used
      target.setOriginalExpansionSetCode(((Token) sourceObj).getOriginalExpansionSetCode());
      target.setOriginalCardNumber(((Token) sourceObj).getOriginalCardNumber());
      target.setCopySourceCard(((PermanentToken) source).getToken().getCopySourceCard());
    } else if (source instanceof PermanentCard) {
      if (((PermanentCard) source).isMorphed() || ((PermanentCard) source).isManifested()) {
        MorphAbility.setPermanentToFaceDownCreature(target);
        return target;
      } else {
        if (((PermanentCard) source).isTransformed() && source.getSecondCardFace() != null) {
          sourceObj = ((PermanentCard) source).getSecondCardFace();
        } else {
          sourceObj = ((PermanentCard) source).getCard();
        }

        target.setOriginalExpansionSetCode(source.getExpansionSetCode());
        target.setOriginalCardNumber(source.getCardNumber());
        target.setCopySourceCard((Card) sourceObj);
      }
    } else {
      target.setOriginalExpansionSetCode(source.getExpansionSetCode());
      target.setOriginalCardNumber(source.getCardNumber());
      if (source instanceof Card) {
        target.setCopySourceCard(source);
      }
    }

    target.setName(sourceObj.getName());
    target.getColor(null).setColor(sourceObj.getColor(null));
    target.getManaCost().clear();
    target.getManaCost().add(sourceObj.getManaCost());
    target.getCardType().clear();
    for (CardType type : sourceObj.getCardType()) {
      target.getCardType().add(type);
    }
    target.getSubtype().clear();
    for (String type : sourceObj.getSubtype()) {
      target.getSubtype().add(type);
    }
    target.getSupertype().clear();
    for (String type : sourceObj.getSupertype()) {
      target.getSupertype().add(type);
    }

    target.getAbilities().clear();

    for (Ability ability0 : sourceObj.getAbilities()) {
      Ability ability = ability0.copy();
      ability.newId();
      ability.setSourceId(target.getId());
      target.addAbility(ability);
    }

    target.getPower().modifyBaseValue(sourceObj.getPower().getBaseValueModified());
    target.getToughness().modifyBaseValue(sourceObj.getToughness().getBaseValueModified());

    return target;
  }
예제 #7
0
파일: Spell.java 프로젝트: quercitron/mage
 @Override
 public String getExpansionSetCode() {
   return card.getExpansionSetCode();
 }
예제 #8
0
  public PermanentView(Permanent permanent, Card card, UUID createdForPlayerId, Game game) {
    super(permanent, game, permanent.getControllerId().equals(createdForPlayerId));
    this.controlled = permanent.getControllerId().equals(createdForPlayerId);
    this.rules = permanent.getRules(game);
    this.tapped = permanent.isTapped();
    this.flipped = permanent.isFlipped();
    this.phasedIn = permanent.isPhasedIn();
    this.summoningSickness = permanent.hasSummoningSickness();
    this.morphed = permanent.isMorphed();
    this.manifested = permanent.isManifested();
    this.damage = permanent.getDamage();
    if (permanent.getAttachments().size() > 0) {
      attachments = new ArrayList<>();
      attachments.addAll(permanent.getAttachments());
    }
    this.attachedTo = permanent.getAttachedTo();
    if (isToken()) {
      original = new CardView(((PermanentToken) permanent).getToken());
      original.expansionSetCode = permanent.getExpansionSetCode();
      tokenSetCode = original.getTokenSetCode();
    } else {
      if (card != null) {
        // original may not be face down
        original = new CardView(card);
      } else {
        original = null;
      }
    }
    this.transformed = permanent.isTransformed();
    this.copy = permanent.isCopy();

    // for fipped, transformed or copied cards, switch the names
    if (original != null && !original.getName().equals(this.getName())) {
      if (permanent.isCopy() && permanent.isFlipCard()) {
        this.alternateName = permanent.getFlipCardName();
        this.originalName = this.getName();
      } else {
        if (controlled // controller may always know
            || (!morphed && !manifested)) { // others don't know for morph or transformed cards
          this.alternateName = original.getName();
          this.originalName = this.getName();
        }
      }
    }
    if (!permanent.getOwnerId().equals(permanent.getControllerId())) {
      Player owner = game.getPlayer(permanent.getOwnerId());
      if (owner != null) {
        this.nameOwner = owner.getName();
      } else {
        this.nameOwner = "";
      }
    } else {
      this.nameOwner = "";
    }

    if (permanent.isFaceDown(game) && card != null) {
      if (controlled) {
        // must be a morphed or manifested card
        for (Ability permanentAbility : permanent.getAbilities()) {
          if (permanentAbility instanceof TurnFaceUpAbility && !permanentAbility.getRuleVisible()) {
            this.rules.add(permanentAbility.getRule(true));
          }
          if (permanentAbility.getWorksFaceDown()) {
            this.rules.add(permanentAbility.getRule());
          }
        }
        this.name = card.getName();
        this.displayName = card.getName();
        this.expansionSetCode = card.getExpansionSetCode();
        this.cardNumber = card.getCardNumber();
      } else {
        if (permanent.isManifested()) {
          this.rules.add(
              "A manifested creature card can be turned face up any time for it's mana cost."
                  + " A face-down card can also be turned face up for its morph cost.");
        } else if (permanent.isMorphed()) {
          this.rules.add(
              "If the controller has priority, he or she may turn this permanent face up."
                  + " This is a special action; it doesn’t use the stack. To do this he or she pays the morph costs,"
                  + " then turns this permanent face up.");
        }
      }
    }
    // determines if shown in it's own column
    if (permanent.getAttachedTo() != null) {
      attachedToPermanent = game.getPermanent(permanent.getAttachedTo()) != null;
    } else {
      attachedToPermanent = false;
    }
  }