Beispiel #1
0
 @Override
 public boolean applies(GameEvent event, Ability source, Game game) {
   boolean isCombat = false;
   switch (event.getType()) {
     case DAMAGE_CREATURE:
     case DAMAGE_PLAYER:
     case DAMAGE_PLANESWALKER:
       if (event instanceof DamageCreatureEvent) {
         isCombat = ((DamageCreatureEvent) event).isCombatDamage();
       } else if (event instanceof DamageEvent) {
         isCombat = ((DamageEvent) event).isCombatDamage();
       }
       if (isCombat) {
         Permanent equipment = game.getPermanent(source.getSourceId());
         if (equipment != null && equipment.getAttachedTo() != null) {
           UUID attachedTo = equipment.getAttachedTo();
           if (event.getSourceId().equals(attachedTo)) {
             event.setAmount(event.getAmount() * 2);
           } else if (event.getTargetId().equals(attachedTo)) {
             event.setAmount(event.getAmount() * 2);
           }
         }
       }
   }
   return false;
 }
Beispiel #2
0
 @Override
 public boolean replaceEvent(GameEvent event, Ability source, Game game) {
   GameEvent preventEvent =
       new GameEvent(
           GameEvent.EventType.PREVENT_DAMAGE,
           source.getFirstTarget(),
           source.getId(),
           source.getControllerId(),
           event.getAmount(),
           false);
   if (!game.replaceEvent(preventEvent)) {
     int damage = event.getAmount();
     Permanent permanent = game.getPermanent(event.getSourceId());
     StringBuilder message = new StringBuilder();
     if (permanent != null) {
       message.append(" from ").append(permanent.getName());
     }
     message.insert(0, "Damage").append(" has been prevented: ").append(damage);
     event.setAmount(0);
     game.informPlayers(message.toString());
     game.fireEvent(
         GameEvent.getEvent(
             GameEvent.EventType.PREVENTED_DAMAGE,
             source.getFirstTarget(),
             source.getId(),
             source.getControllerId(),
             damage));
   }
   return false;
 }
Beispiel #3
0
 @Override
 public boolean replaceEvent(GameEvent event, Ability source, Game game) {
   boolean retValue = false;
   GameEvent preventEvent =
       new GameEvent(
           GameEvent.EventType.PREVENT_DAMAGE,
           source.getFirstTarget(),
           source.getId(),
           source.getControllerId(),
           event.getAmount(),
           false);
   int damage = event.getAmount();
   if (!game.replaceEvent(preventEvent)) {
     event.setAmount(0);
     game.fireEvent(
         GameEvent.getEvent(
             GameEvent.EventType.PREVENTED_DAMAGE,
             source.getFirstTarget(),
             source.getId(),
             source.getControllerId(),
             damage));
     retValue = true;
   }
   Permanent permanent = game.getPermanent(source.getSourceId());
   if (permanent != null) {
     permanent.removeCounters(CounterType.P1P1.createInstance(damage), game);
   }
   return retValue;
 }
Beispiel #4
0
 @Override
 public boolean replaceEvent(GameEvent event, Ability source, Game game) {
   GameEvent preventEvent =
       new GameEvent(
           GameEvent.EventType.PREVENT_DAMAGE,
           source.getControllerId(),
           source.getId(),
           source.getControllerId(),
           event.getAmount(),
           false);
   if (!game.replaceEvent(preventEvent)) {
     int damage = event.getAmount();
     if (damage > 0) {
       event.setAmount(damage - 1);
       this.used = true;
       game.fireEvent(
           GameEvent.getEvent(
               GameEvent.EventType.PREVENTED_DAMAGE,
               source.getControllerId(),
               source.getId(),
               source.getControllerId(),
               1));
     }
   }
   return false;
 }
Beispiel #5
0
  Cards ProteanHulkSearch(Game game, Ability source) {
    Cards cardsPicked = new CardsImpl(Zone.PICK);
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
      GameEvent event =
          GameEvent.getEvent(
              GameEvent.EventType.SEARCH_LIBRARY,
              source.getControllerId(),
              source.getControllerId(),
              source.getControllerId(),
              Integer.MAX_VALUE);
      if (!game.replaceEvent(event)) {
        int manaCostLeftToFetch = 6;
        int librarySearchLimit = event.getAmount();

        FilterCard filter =
            new FilterCreatureCard(
                "number of creature cards with total converted mana cost 6 or less (6 CMC left)");
        filter.add(
            new ConvertedManaCostPredicate(ComparisonType.LessThan, manaCostLeftToFetch + 1));
        TargetCardInLibrary target = new TargetCardInLibrary(0, 1, filter);
        target.setCardLimit(librarySearchLimit);

        while (target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
          target.choose(
              Outcome.PutCreatureInPlay, source.getControllerId(), source.getControllerId(), game);
          Card card = player.getLibrary().remove(target.getFirstTarget(), game);
          if (card == null) {
            break;
          }
          cardsPicked.add(card);
          game.setZone(card.getId(), Zone.PICK);
          game.getState().getLookedAt(source.getControllerId()).add("Protean Hulk", cardsPicked);

          librarySearchLimit--;
          if (librarySearchLimit == 0) {
            break;
          }
          manaCostLeftToFetch -= card.getManaCost().convertedManaCost();
          filter =
              new FilterCreatureCard(
                  "number of creature cards with total converted mana cost 6 or less ("
                      + manaCostLeftToFetch
                      + " CMC left)");
          filter.add(
              new ConvertedManaCostPredicate(ComparisonType.LessThan, manaCostLeftToFetch + 1));
          target = new TargetCardInLibrary(0, 1, filter);
          target.setCardLimit(librarySearchLimit);
        }
        game.fireEvent(
            GameEvent.getEvent(
                GameEvent.EventType.LIBRARY_SEARCHED,
                source.getControllerId(),
                source.getControllerId()));
      }
    }
    return cardsPicked;
  }
Beispiel #6
0
 @Override
 public boolean checkTrigger(GameEvent event, Game game) {
   if (event.getType() == GameEvent.EventType.DAMAGED_CREATURE
       && event.getTargetId().equals(this.sourceId)) {
     this.getEffects().get(0).setValue("damageAmount", event.getAmount());
     return true;
   }
   return false;
 }
Beispiel #7
0
 @Override
 public boolean checkTrigger(GameEvent event, Game game) {
   Permanent target = game.getPermanent(this.getFirstTarget());
   if (target != null && event.getSourceId().equals(target.getId())) {
     for (Effect effect : this.getEffects()) {
       effect.setValue("damage", event.getAmount());
     }
     return true;
   }
   return false;
 }
 @Override
 public boolean replaceEvent(GameEvent event, Ability source, Game game) {
   Permanent knightOfTheHolyNimbus = game.getPermanent(event.getTargetId());
   if (knightOfTheHolyNimbus != null && event.getAmount() == 0) { // 1=noRegen
     if (knightOfTheHolyNimbus.regenerate(source.getSourceId(), game)) {
       game.informPlayers(source.getSourceObject(game).getName() + " has been regenerated.");
       return true;
     }
   }
   return false;
 }
Beispiel #9
0
 @Override
 public boolean replaceEvent(GameEvent event, Ability source, Game game) {
   int damage = event.getAmount();
   preventDamageAction(event, source, game);
   Permanent permanent = game.getPermanent(source.getSourceId());
   if (permanent != null) {
     permanent.removeCounters(CounterType.P1P1.createInstance(damage), game);
   }
   new CreateTokenEffect(new SpiritToken(), damage).apply(game, source);
   return true;
 }
  @Override
  public void watch(GameEvent event, Game game) {
    switch (event.getType()) {
      case DAMAGED_CREATURE:
      case DAMAGED_PLANESWALKER:
      case DAMAGED_PLAYER:
        {
          MageObjectReference damageSourceRef = new MageObjectReference(event.getSourceId(), game);
          int damageDone =
              damagingObjects.containsKey(damageSourceRef)
                  ? damagingObjects.get(damageSourceRef)
                  : 0;
          damagingObjects.put(damageSourceRef, damageDone + event.getAmount());

          MageObjectReference damageTargetRef = new MageObjectReference(event.getTargetId(), game);
          int damageReceived =
              damagedObjects.containsKey(damageTargetRef) ? damagedObjects.get(damageTargetRef) : 0;
          damagedObjects.put(damageTargetRef, damageReceived + event.getAmount());
        }
    }
  }
 @Override
 public boolean checkTrigger(GameEvent event, Game game) {
   if (event.getSourceId().equals(this.sourceId)) {
     if (setTargetPointer) {
       for (Effect effect : this.getEffects()) {
         effect.setTargetPointer(new FixedTarget(event.getPlayerId()));
         effect.setValue("damage", event.getAmount());
       }
     }
     return true;
   }
   return false;
 }
Beispiel #12
0
 @Override
 public boolean checkTrigger(GameEvent event, Game game) {
   if (((DamagedEvent) event).isCombatDamage()) {
     if (event.getSourceId().equals(getSourceId())) {
       this.getEffects().clear();
       Effect effect =
           new AddManaToManaPoolTargetControllerEffect(
               Mana.GreenMana(event.getAmount()), "that player", true);
       effect.setTargetPointer(new FixedTarget(getControllerId()));
       effect.setText(
           "add that much {G} to your mana pool. Until end of turn, this mana doesn't empty from your mana pool as steps and phases end");
       this.addEffect(effect);
       return true;
     }
   }
   return false;
 }
Beispiel #13
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;
 }
 @Override
 public boolean checkTrigger(GameEvent event, Game game) {
   Permanent enchantment = game.getPermanent(sourceId);
   UUID targetId = event.getTargetId();
   if (enchantment != null
       && enchantment.getAttachedTo() != null
       && targetId.equals(enchantment.getAttachedTo())) {
     for (Effect effect : this.getEffects()) {
       effect.setValue("damage", event.getAmount());
       switch (setTargetPointer) {
         case PERMANENT:
           effect.setTargetPointer(new FixedTarget(targetId));
           break;
         case PLAYER:
           effect.setTargetPointer(
               new FixedTarget(game.getPermanentOrLKIBattlefield(targetId).getControllerId()));
           break;
       }
     }
     return true;
   }
   return false;
 }
 @Override
 public boolean checkTrigger(GameEvent event, Game game) {
   if (!onlyCombat || ((DamagedPlayerEvent) event).isCombatDamage()) {
     Permanent permanent = game.getPermanent(event.getSourceId());
     if (permanent != null && filter.match(permanent, sourceId, controllerId, game)) {
       if (!setTargetPointer.equals(SetTargetPointer.NONE)) {
         for (Effect effect : this.getEffects()) {
           effect.setValue("damage", event.getAmount());
           switch (setTargetPointer) {
             case PLAYER:
               effect.setTargetPointer(new FixedTarget(permanent.getControllerId()));
               break;
             case PERMANENT:
               effect.setTargetPointer(
                   new FixedTarget(permanent.getId(), permanent.getZoneChangeCounter(game)));
               break;
           }
         }
       }
       return true;
     }
   }
   return false;
 }
Beispiel #16
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;
  }
Beispiel #17
0
 @Override
 public boolean replaceEvent(GameEvent event, Ability source, Game game) {
   event.setAmount(event.getAmount() * 2);
   return false;
 }