예제 #1
0
 /**
  * Checks if there are enough {@link Permanent} or {@link Player} that can be chosen. Should only
  * be used for Ability targets since this checks for protection, shroud etc.
  *
  * @param sourceId - the target event source
  * @param sourceControllerId - controller of the target event source
  * @param game
  * @return - true if enough valid {@link Permanent} or {@link Player} exist
  */
 @Override
 public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
   int count = 0;
   MageObject targetSource = game.getObject(sourceId);
   for (UUID playerId : game.getPlayer(sourceControllerId).getInRange()) {
     Player player = game.getPlayer(playerId);
     if (player != null
         && player.canBeTargetedBy(targetSource, game)
         && filter.match(player, game)) {
       count++;
       if (count >= this.minNumberOfTargets) {
         return true;
       }
     }
   }
   for (Permanent permanent :
       game.getBattlefield()
           .getActivePermanents(new FilterCreaturePermanent(), sourceControllerId, game)) {
     if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game)
         && filter.match(permanent, sourceId, sourceControllerId, game)) {
       count++;
       if (count >= this.minNumberOfTargets) {
         return true;
       }
     }
   }
   return false;
 }
예제 #2
0
 @Override
 public boolean canTarget(UUID id, Ability source, Game game) {
   Player player = game.getPlayer(id);
   if (player != null) {
     if (source != null) {
       return player.canBeTargetedBy(game.getObject(source.getSourceId()), game)
           && filter.match(player, source.getSourceId(), source.getControllerId(), game);
     } else {
       return filter.match(player, game);
     }
   }
   return false;
 }
예제 #3
0
 @Override
 public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
   Set<UUID> possibleTargets = new HashSet<UUID>();
   MageObject targetSource = game.getObject(sourceId);
   for (UUID playerId : game.getPlayer(sourceControllerId).getInRange()) {
     Player player = game.getPlayer(playerId);
     if (player != null
         && !player.hasLeft()
         && filter.match(player, sourceId, sourceControllerId, game)) {
       if (player.canBeTargetedBy(targetSource, game)) possibleTargets.add(playerId);
     }
   }
   return possibleTargets;
 }
예제 #4
0
 /**
  * Checks if there are enough {@link Player} that can be chosen. Should only be used for Ability
  * targets since this checks for protection, shroud etc.
  *
  * @param sourceId - the target event source
  * @param sourceControllerId - controller of the target event source
  * @param game
  * @return - true if enough valid {@link Player} exist
  */
 @Override
 public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
   int count = 0;
   MageObject targetSource = game.getObject(sourceId);
   for (UUID playerId : game.getPlayer(sourceControllerId).getInRange()) {
     Player player = game.getPlayer(playerId);
     if (player != null
         && !player.hasLeft()
         && filter.match(player, sourceId, sourceControllerId, game)) {
       if (player.canBeTargetedBy(targetSource, game)) {
         count++;
         if (count >= this.minNumberOfTargets) return true;
       }
     }
   }
   return false;
 }
예제 #5
0
 @Override
 public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
   Set<UUID> possibleTargets = new HashSet<UUID>();
   MageObject targetSource = game.getObject(sourceId);
   for (UUID playerId : game.getPlayer(sourceControllerId).getInRange()) {
     Player player = game.getPlayer(playerId);
     if (player != null
         && player.canBeTargetedBy(targetSource, game)
         && filter.match(player, game)) {
       possibleTargets.add(playerId);
     }
   }
   for (Permanent permanent :
       game.getBattlefield()
           .getActivePermanents(new FilterCreaturePermanent(), sourceControllerId, game)) {
     if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game)
         && filter.match(permanent, sourceId, sourceControllerId, game)) {
       possibleTargets.add(permanent.getId());
     }
   }
   return possibleTargets;
 }
예제 #6
0
  public boolean canTarget(UUID controllerId, UUID id, Ability source, Game game) {
    Permanent permanent = game.getPermanent(id);
    Player player = game.getPlayer(id);

    if (source != null) {
      MageObject targetSource = game.getObject(source.getSourceId());
      if (permanent != null) {
        return permanent.canBeTargetedBy(targetSource, source.getControllerId(), game)
            && filter.match(permanent, source.getSourceId(), source.getControllerId(), game);
      }
      if (player != null) {
        return player.canBeTargetedBy(targetSource, game) && filter.match(player, game);
      }
    }

    if (permanent != null) {
      return filter.match(permanent, game);
    }
    if (player != null) {
      return filter.match(player, game);
    }
    return false;
  }