예제 #1
0
  public List<ContinuousEffect> getLayeredEffects(Game game) {
    List<ContinuousEffect> layerEffects = new ArrayList<>();
    for (ContinuousEffect effect : layeredEffects) {
      switch (effect.getDuration()) {
        case WhileOnBattlefield:
        case WhileOnStack:
        case WhileInGraveyard:
          HashSet<Ability> abilities = layeredEffects.getAbility(effect.getId());
          for (Ability ability : abilities) {
            // If e.g. triggerd abilities (non static) created the effect, the ability must not be
            // in usable zone (e.g. Unearth giving Haste effect)
            if (!(ability instanceof StaticAbility) || ability.isInUseableZone(game, null, null)) {
              layerEffects.add(effect);
              break;
            }
          }
          break;
        default:
          layerEffects.add(effect);
      }
    }

    updateTimestamps(layerEffects);

    Collections.sort(layerEffects, sorter);
    return layerEffects;
  }
예제 #2
0
 private boolean checkAbilityStillExists(
     Ability ability, ContinuousEffect effect, GameEvent event, Game game) {
   switch (effect
       .getDuration()) { // effects with fixed duration don't need an object with the source
                         // ability (e.g. a silence cast with isochronic Scepter has no more a card
                         // object
     case EndOfCombat:
     case EndOfGame:
     case EndOfStep:
     case EndOfTurn:
     case OneUse:
     case Custom: // custom duration means the effect ends itself if needed
       return true;
   }
   if (ability.getSourceId() == null) { // commander replacement effect
     return true;
   }
   MageObject object;
   if (event.getType().equals(EventType.ZONE_CHANGE)
       && ((ZoneChangeEvent) event).getFromZone().equals(Zone.BATTLEFIELD)
       && event.getTargetId().equals(ability.getSourceId())) {
     object = ((ZoneChangeEvent) event).getTarget();
   } else {
     object = game.getObject(ability.getSourceId());
   }
   if (object == null) {
     return false;
   }
   boolean exists = true;
   if (!object.getAbilities().contains(ability)) {
     exists = false;
     if (object instanceof PermanentCard) {
       PermanentCard permanent = (PermanentCard) object;
       if (permanent.canTransform() && event.getType() == GameEvent.EventType.TRANSFORMED) {
         exists = permanent.getCard().getAbilities().contains(ability);
       }
     }
   } else {
     if (object instanceof PermanentCard) {
       PermanentCard permanent = (PermanentCard) object;
       if (permanent.isFaceDown(game) && !ability.getWorksFaceDown()) {
         return false;
       }
     } else if (object instanceof Spell) {
       Spell spell = (Spell) object;
       if (spell.isFaceDown(game) && !ability.getWorksFaceDown()) {
         return false;
       }
     }
   }
   return exists;
 }