Example #1
0
 private String getKey(TriggeredAbility ability, MageObject target) {
   String key = ability.getId() + "_";
   if (target != null) {
     key += target.getId();
   }
   return key;
 }
Example #2
0
  /**
   * @param game
   * @param source
   * @return
   */
  @Override
  public boolean isInUseableZone(Game game, MageObject source, GameEvent event) {
    if (!this.hasSourceObjectAbility(game, source, event)) {
      return false;
    }
    if (zone.equals(Zone.COMMAND)) {
      if (this.getSourceId() == null) { // commander effects
        return true;
      }
      MageObject object = game.getObject(this.getSourceId());
      // emblem are always actual
      if (object != null && object instanceof Emblem) {
        return true;
      }
    }

    UUID parameterSourceId;
    // for singleton abilities like Flying we can't rely on abilities' source because it's only once
    // in continuous effects
    // so will use the sourceId of the object itself that came as a parameter if it is not null
    if (this instanceof MageSingleton && source != null) {
      parameterSourceId = source.getId();
    } else {
      parameterSourceId = getSourceId();
    }
    // check agains shortLKI for effects that move multiple object at the same time (e.g. destroy
    // all)
    if (game.getShortLivingLKI(getSourceId(), getZone())) {
      return true;
    }
    // check against current state
    Zone test = game.getState().getZone(parameterSourceId);
    return test != null && zone.match(test);
  }
Example #3
0
 /**
  * Adds a by sourceId gained triggered ability
  *
  * @param ability - the gained ability
  * @param sourceId - the source that assigned the ability
  * @param attachedTo - the object that gained the ability
  */
 public void add(TriggeredAbility ability, UUID sourceId, MageObject attachedTo) {
   this.add(ability, attachedTo);
   List<UUID> uuidList = new LinkedList<UUID>();
   uuidList.add(sourceId);
   // if the object that gained the ability moves zone, also then the triggered ability must be
   // removed
   uuidList.add(attachedTo.getId());
   sources.put(getKey(ability, attachedTo), uuidList);
 }
 @Override
 public boolean apply(MageObject input, Game game) {
   Spell spell = game.getStack().getSpell(input.getId());
   if (spell != null) {
     Targets spellTargets = spell.getSpellAbility().getTargets();
     int numberOfTargets = 0;
     for (Target target : spellTargets) {
       numberOfTargets += target.getTargets().size();
     }
     if (numberOfTargets == targets) {
       return true;
     }
   }
   return false;
 }