@Override
 public boolean checkTrigger(GameEvent event, Game game) {
   if (event.getType() == GameEvent.EventType.DAMAGED_PLAYER) {
     if (((DamagedEvent) event).isCombatDamage()) {
       Permanent creature = game.getPermanent(event.getSourceId());
       if (creature != null
           && creature.getControllerId().equals(controllerId)
           && !damagedPlayerIds.contains(event.getTargetId())) {
         damagedPlayerIds.add(event.getTargetId());
         return true;
       }
     }
   }
   if (event.getType().equals(GameEvent.EventType.END_COMBAT_STEP_POST)) {
     damagedPlayerIds.clear();
   }
   if (event.getType().equals(GameEvent.EventType.ZONE_CHANGE)
       && event.getTargetId().equals(getSourceId())) {
     ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
     if (zEvent.getFromZone().equals(Zone.GRAVEYARD)) {
       damagedPlayerIds.clear();
     }
   }
   return false;
 }
 @Override
 public boolean replaceEvent(GameEvent event, Ability source, Game game) {
   DamageEvent damageEvent = (DamageEvent) event;
   Permanent sourcePermanent = game.getPermanent(source.getSourceId());
   if (sourcePermanent != null) {
     // get name of old target
     Permanent targetPermanent = game.getPermanent(event.getTargetId());
     StringBuilder message = new StringBuilder();
     message.append(sourcePermanent.getName()).append(": gets ");
     message.append(damageEvent.getAmount()).append(" damage redirected from ");
     if (targetPermanent != null) {
       message.append(targetPermanent.getName());
     } else {
       Player targetPlayer = game.getPlayer(event.getTargetId());
       if (targetPlayer != null) {
         message.append(targetPlayer.getName());
       } else {
         message.append("unknown");
       }
     }
     game.informPlayers(message.toString());
     // redirect damage
     this.used = true;
     sourcePermanent.damage(
         damageEvent.getAmount(),
         damageEvent.getSourceId(),
         game,
         damageEvent.isPreventable(),
         damageEvent.isCombatDamage(),
         event.getAppliedEffects());
     return true;
   }
   return false;
 }
 @Override
 public boolean applies(GameEvent event, Ability source, Game game) {
   if (event.getType() == EventType.DAMAGE_PLAYER) {
     DamageEvent damageEvent = (DamageEvent) event;
     UUID playerId = getSourceControllerId(event.getSourceId(), game);
     if (!damageEvent.isCombatDamage()
         && game.getOpponents(event.getTargetId()).contains(playerId)) {
       Player target = game.getPlayer(event.getTargetId());
       Player player = game.getPlayer(playerId);
       if (target != null && player != null) {
         int numPlaneswalkers = game.getBattlefield().countAll(filter, target.getId(), game);
         if (numPlaneswalkers > 0
             && player.chooseUse(outcome, "Redirect damage to planeswalker?", game)) {
           redirectTarget = new TargetPermanent(filter);
           if (numPlaneswalkers == 1) {
             redirectTarget.add(
                 game.getBattlefield()
                     .getAllActivePermanents(filter, target.getId(), game)
                     .get(0)
                     .getId(),
                 game);
           } else {
             player.choose(Outcome.Damage, redirectTarget, null, game);
           }
           return true;
         }
       }
     }
   }
   return false;
 }
 @Override
 public boolean checkTrigger(GameEvent event, Game game) {
   if (!event.getTargetId().equals(getSourceId())) {
     MageObject sourceObj = this.getSourceObject(game);
     if (sourceObj != null) {
       if (sourceObj instanceof Card && ((Card) sourceObj).isFaceDown(game)) {
         // if face down and it's not itself that is turned face up, it does not trigger
         return false;
       }
     } else {
       // Permanent is and was not on the battlefield
       return false;
     }
   }
   Permanent permanent = game.getPermanent(event.getTargetId());
   if (filter.match(permanent, getSourceId(), getControllerId(), game)) {
     if (setTargetPointer) {
       for (Effect effect : getEffects()) {
         effect.setTargetPointer(new FixedTarget(event.getTargetId()));
       }
     }
     return true;
   }
   return false;
 }
Exemple #5
0
 @Override
 public boolean applies(GameEvent event, Ability source, Game game) {
   Permanent permanent = game.getPermanent(event.getTargetId());
   if (permanent == null) {
     permanent = game.getPermanentEntering(event.getTargetId());
   }
   if (permanent != null && permanent.getControllerId().equals(source.getControllerId())) {
     return true;
   }
   return false;
 }
Exemple #6
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;
 }
Exemple #7
0
 @Override
 public void watch(GameEvent event, Game game) {
   if (event.getType() == GameEvent.EventType.ZONE_CHANGE
       && ((ZoneChangeEvent) event).isDiesEvent()) {
     cards.add(event.getTargetId());
   }
 }
 @Override
 public boolean checkTrigger(GameEvent event, Game game) {
   return event.getPlayerId().equals(this.getControllerId())
       && game.getLastKnownInformation(event.getTargetId(), Zone.BATTLEFIELD)
           .getCardType()
           .contains(CardType.CREATURE);
 }
Exemple #9
0
 @Override
 public boolean checkTrigger(GameEvent event, Game game) {
   if (event.getZone() == Zone.HAND) {
     Spell spell = game.getStack().getSpell(event.getTargetId());
     if (spell != null
         && !spell.isCopy()
         && (spell.getCardType().contains(CardType.INSTANT)
             || spell.getCardType().contains(CardType.SORCERY))) {
       for (Effect effect : this.getEffects()) {
         effect.setTargetPointer(new FixedTarget(event.getTargetId()));
       }
       return true;
     }
   }
   return false;
 }
Exemple #10
0
 @Override
 public boolean checkTrigger(GameEvent event, Game game) {
   if ((event.getType() == EventType.DAMAGED_PLAYER
           && event.getTargetId().equals(this.getControllerId()))
       && ((DamagedEvent) event).isCombatDamage()) {
     return true;
   }
   if (event.getType() == EventType.DAMAGED_PLANESWALKER
       && ((DamagedEvent) event).isCombatDamage()) {
     Permanent permanent = game.getPermanent(event.getTargetId());
     if (permanent != null && permanent.getControllerId().equals(this.getControllerId())) {
       return true;
     }
   }
   return false;
 }
Exemple #11
0
 @Override
 public boolean checkTrigger(GameEvent event, Game game) {
   return GameEvent.EventType.DISCARDED_CARD.equals(event.getType())
       && game.getOpponents(this.getControllerId())
           .contains(game.getControllerId(event.getSourceId()))
       && getSourceId().equals(event.getTargetId());
 }
Exemple #12
0
 @Override
 public boolean applies(GameEvent event, Ability source, Game game) {
   if (event.getSourceId().equals(source.getSourceId())) {
     Player controller = game.getPlayer(source.getControllerId());
     return controller.hasOpponent(event.getTargetId(), game);
   }
   return false;
 }
 @Override
 public boolean replaceEvent(GameEvent event, Ability source, Game game) {
   Permanent target = game.getPermanent(event.getTargetId());
   if (target != null) {
     target.setTapped(true);
   }
   return false;
 }
Exemple #14
0
 @Override
 public boolean applies(GameEvent event, Ability source, Game game) {
   Spell spell = game.getStack().getSpell(event.getTargetId());
   if (spell != null && spell.getCardType().contains(CardType.CREATURE)) {
     return true;
   }
   return false;
 }
 @Override
 public boolean applies(GameEvent event, Ability source, Game game) {
   if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD
       && game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) {
     Card c = game.getCard(event.getTargetId());
     if (c != null && c.getCardType().contains(CardType.CREATURE)) return true;
   }
   return false;
 }
Exemple #16
0
 @Override
 public boolean checkTrigger(GameEvent event, Game game) {
   Spell spell = game.getStack().getSpell(event.getTargetId());
   if (spell != null && spell.getCardType().contains(CardType.ARTIFACT)) {
     this.getEffects().get(0).setTargetPointer(new FixedTarget(event.getPlayerId()));
     return true;
   }
   return false;
 }
Exemple #17
0
 @Override
 public boolean applies(GameEvent event, Ability source, Game game) {
   if (!this.used
       && super.applies(event, source, game)
       && event.getTargetId().equals(source.getControllerId())) {
     return true;
   }
   return false;
 }
Exemple #18
0
 @Override
 public boolean applies(GameEvent event, Ability source, Game game) {
   if (super.applies(event, source, game)) {
     if (event.getTargetId().equals(source.getSourceId())) {
       return true;
     }
   }
   return false;
 }
Exemple #19
0
 @Override
 public boolean checkTrigger(GameEvent event, Game game) {
   if (event.getType() == EventType.ATTACKER_DECLARED
       && event.getSourceId().equals(this.getSourceId())) {
     return true;
   }
   return event.getType() == EventType.ENTERS_THE_BATTLEFIELD
       && event.getTargetId().equals(this.getSourceId());
 }
Exemple #20
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;
 }
 @Override
 public boolean applies(GameEvent event, Ability source, Game game) {
   if (((ZoneChangeEvent) event).isDiesEvent()) {
     DamagedByWatcher watcher =
         (DamagedByWatcher)
             game.getState().getWatchers().get("DamagedByWatcher", source.getSourceId());
     return watcher != null && watcher.wasDamaged(event.getTargetId(), game);
   }
   return false;
 }
Exemple #22
0
 @Override
 public boolean checkTrigger(GameEvent event, Game game) {
   if (event.getTargetId().equals(target)) {
     ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
     if (zEvent.getFromZone() == Zone.BATTLEFIELD && zEvent.getToZone() == Zone.GRAVEYARD) {
       return true;
     }
   }
   return false;
 }
Exemple #23
0
 @Override
 public boolean applies(GameEvent event, Ability source, Game game) {
   if (event.getTargetId().equals(source.getSourceId())) {
     Permanent sourcePermanent = ((EntersTheBattlefieldEvent) event).getTarget();
     if (sourcePermanent != null && !sourcePermanent.isFaceDown(game)) {
       return true;
     }
   }
   return false;
 }
Exemple #24
0
 @Override
 public boolean applies(GameEvent event, Ability source, Game game) {
   if (event.getType() == GameEvent.EventType.ZONE_CHANGE
       && event.getTargetId().equals(source.getFirstTarget())
       && ((ZoneChangeEvent) event).getFromZone().equals(Zone.BATTLEFIELD)
       && !((ZoneChangeEvent) event).getToZone().equals(Zone.EXILED)) {
     return true;
   }
   return false;
 }
Exemple #25
0
 @Override
 public boolean checkTrigger(GameEvent event, Game game) {
   if (event.getType() == GameEvent.EventType.SPELL_CAST) {
     Spell spell = game.getStack().getSpell(event.getTargetId());
     if (spell != null && spell.getColor().contains(ObjectColor.GREEN)) {
       return true;
     }
   }
   return false;
 }
Exemple #26
0
 @Override
 public boolean applies(GameEvent event, Ability source, Game game) {
   if (event.getType() == EventType.ZONE_CHANGE && ((ZoneChangeEvent) event).isDiesEvent()) {
     DamagedByWatcher watcher =
         (DamagedByWatcher)
             game.getState().getWatchers().get("DamagedByWatcher", source.getSourceId());
     if (watcher != null) return watcher.damagedCreatures.contains(event.getTargetId());
   }
   return false;
 }
Exemple #27
0
 @Override
 public boolean checkTrigger(GameEvent event, Game game) {
   if (event.getType() == GameEvent.EventType.TAPPED) {
     Permanent p = game.getPermanent(event.getTargetId());
     if (p != null && p.getCardType().contains(CardType.CREATURE)) {
       if (game.getOpponents(this.controllerId).contains(p.getControllerId())) 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;
 }
 @Override
 public boolean checkTrigger(GameEvent event, Game game) {
   if (((ZoneChangeEvent) event).isDiesEvent()) {
     if (fixedTarget.getFirst(game, this).equals(event.getTargetId())) {
       if (this.getControllerId().equals(event.getPlayerId())) {
         return true;
       }
     }
   }
   return false;
 }
Exemple #30
0
  @Override
  public boolean checkTrigger(GameEvent event, Game game) {
    if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) {
      if (!event.getTargetId().equals(this.getSourceId())) {
        Permanent triggeringCreature = game.getPermanent(event.getTargetId());
        if (triggeringCreature != null
            && triggeringCreature.getCardType().contains(CardType.CREATURE)
            && triggeringCreature.getControllerId().equals(this.controllerId)) {
          Permanent sourceCreature = game.getPermanent(sourceId);
          if (sourceCreature != null
              && isPowerOrThoughnessGreater(sourceCreature, triggeringCreature)) {
            this.getEffects().get(0).setTargetPointer(new FixedTarget(event.getTargetId()));
            return true;
          }
        }
      }
    }

    return false;
  }