Пример #1
0
 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;
 }
Пример #2
0
  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;
  }