Class NPCQuery

All Implemented Interfaces:
Predicate<INPC>

public class NPCQuery extends ActorQuery<INPC,NPCQuery>
Query class for finding and filtering NPCs (Non-Player Characters) in the game world.

This class extends ActorQuery with NPC-specific filtering capabilities, primarily the ability to filter by NPC index. NPCs can be filtered by all criteria available in the parent classes including:

  • NPC indices
  • Combat levels, animations, targets (from ActorQuery)
  • IDs, names, actions, locations, distances (from SceneEntityQuery)

Example usage:


 // Find all goblins within 10 tiles
 NPCQuery query = new NPCQuery(npcSupplier)
     .names("Goblin")
     .distance(player, 10);
 SceneEntityQueryResults<INPC> results = query.results();
 
  • Constructor Details

    • NPCQuery

      public NPCQuery(Supplier<List<INPC>> supplier)
      Constructs a new NPC query with the specified NPC supplier.
      Parameters:
      supplier - a supplier that provides the list of NPCs to query
  • Method Details

    • indices

      public NPCQuery indices(int... indices)
      Filters NPCs by their indices.

      Only NPCs with an index matching one of the specified values will be included. The NPC index is a unique identifier for an NPC within the current game scene.

      Parameters:
      indices - the NPC indices to filter by
      Returns:
      this query instance for method chaining
    • results

      protected SceneEntityQueryResults<INPC> results(List<INPC> list)
      Wraps the filtered list of NPCs in a SceneEntityQueryResults container.
      Specified by:
      results in class Query<INPC,NPCQuery,SceneEntityQueryResults<INPC>>
      Parameters:
      list - the list of NPCs that passed all filters
      Returns:
      the results wrapped in a SceneEntityQueryResults container
    • test

      public boolean test(INPC npc)
      Tests whether an NPC passes all accumulated filter criteria.

      This method checks the NPC against the index filter and all parent class filters.

      Specified by:
      test in interface Predicate<INPC>
      Overrides:
      test in class ActorQuery<INPC,NPCQuery>
      Parameters:
      npc - the NPC to test
      Returns:
      true if the NPC passes all filters, false otherwise