@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;
 }
Esempio n. 2
0
 @Override
 public boolean replaceEvent(GameEvent event, Ability source, Game game) {
   PreventionEffectData preventionResult = preventDamageAction(event, source, game);
   if (preventionResult.getPreventedDamage() > 0) {
     Permanent redirectTo = game.getPermanent(getTargetPointer().getFirst(game, source));
     if (redirectTo != null) {
       game.informPlayers(
           "Dealing "
               + preventionResult.getPreventedDamage()
               + " to "
               + redirectTo.getLogName()
               + " instead.");
       DamageEvent damageEvent = (DamageEvent) event;
       redirectTo.damage(
           preventionResult.getPreventedDamage(),
           event.getSourceId(),
           game,
           damageEvent.isCombatDamage(),
           damageEvent.isPreventable(),
           event.getAppliedEffects());
     }
     discard(); // (only once)
   }
   return false;
 }
Esempio n. 3
0
 @Override
 public boolean applies(GameEvent event, Ability source, Game game) {
   if (super.applies(event, source, game) && event instanceof DamageEvent) {
     DamageEvent damageEvent = (DamageEvent) event;
     if (damageEvent.isCombatDamage()
         && !damageEvent.getSourceId().equals(source.getFirstTarget())) {
       return true;
     }
   }
   return false;
 }
Esempio n. 4
0
 @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;
 }