示例#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, Game game) {
   Permanent permanent = game.getPermanent(id);
   if (permanent != null) {
     return filter.match(permanent, game);
   }
   Player player = game.getPlayer(id);
   if (player != null) {
     return filter.match(player, game);
   }
   return false;
 }
示例#3
0
 public TargetCreatureOrPlayer(int minNumTargets, int maxNumTargets) {
   this.minNumberOfTargets = minNumTargets;
   this.maxNumberOfTargets = maxNumTargets;
   this.zone = Zone.ALL;
   this.filter = new FilterCreatureOrPlayer();
   this.targetName = filter.getMessage();
 }
示例#4
0
 @Override
 public Set<UUID> possibleTargets(UUID sourceControllerId, Game game) {
   Set<UUID> possibleTargets = new HashSet<UUID>();
   for (UUID playerId : game.getPlayer(sourceControllerId).getInRange()) {
     Player player = game.getPlayer(playerId);
     if (player != null && filter.match(player, game)) {
       possibleTargets.add(playerId);
     }
   }
   for (Permanent permanent :
       game.getBattlefield()
           .getActivePermanents(new FilterCreaturePermanent(), sourceControllerId, game)) {
     if (filter.match(permanent, null, sourceControllerId, game)) {
       possibleTargets.add(permanent.getId());
     }
   }
   return possibleTargets;
 }
示例#5
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;
  }