Ejemplo n.º 1
0
 public NearbyComponentsSensor(
     PlannerAgent agent, Class<? extends VanillaEntityComponent>... classes) {
   this.agent = agent;
   this.state = WorldState.createEmptyState();
   this.classes = new ArrayList<Class<? extends VanillaEntityComponent>>();
   for (Class<? extends VanillaEntityComponent> clazz : classes) {
     this.classes.add(clazz);
   }
 }
Ejemplo n.º 2
0
 @Override
 public WorldState generateState() {
   ArrayList<Entity> entities = new ArrayList<Entity>();
   for (Entity entity :
       agent.getEntity().getWorld().getNearbyEntities(agent.getEntity(), radius)) {
     boolean hasClass = false;
     for (Class clazz : classes) {
       if (entity.get(clazz) != null) {
         hasClass = true;
         break;
       }
     }
     if (!hasClass) {
       continue;
     }
     entities.add(entity);
   }
   boolean found = entities.size() > 0;
   state.put("hasNearbyEntities", found);
   state.put("entities", found ? entities : Collections.emptyList());
   return state;
 }
Ejemplo n.º 3
0
 /**
  * Returns if the sensor sensed a player nearby.
  *
  * @return True if player detected, false if not.
  */
 public boolean hasFoundEntity() {
   return (Boolean) state.get("hasNearbyEntities");
 }
Ejemplo n.º 4
0
 /**
  * Returns all the entities this sensor found.
  *
  * @return Entities found
  */
 public List<Entity> getEntities() {
   final List<Entity> targets = state.get("entities");
   return targets == null ? new ArrayList<Entity>() : targets;
 }