Example #1
0
    @Override
    public Input handle(Action action, String actorID) {
      final Hunt act = (Hunt) action;
      final Food food = dmodel.getFoodById(act.getFoodTypeId());

      // This line gets the agents datamodel
      // Just trust me on that one :P
      final PublicAgentDataModel am = ((AbstractAgent) sim.getPlayer(actorID)).getDataModel();
      if (am.getHuntingTeam() == null) {
        Input result;
        if (food.getHuntersRequired() <= 1) {
          result =
              new HuntResult(actorID, food.getNutrition(), food.getNutrition(), dmodel.getTime());
        } else {
          result = new HuntResult(actorID, 0, 0, dmodel.getTime());
        }
        sim.getPlayer(actorID).enqueueInput(result);
      } else {
        if (!storedHuntResults.containsKey(am.getHuntingTeam())) {
          storedHuntResults.put(am.getHuntingTeam(), new LinkedList<TeamHuntEvent>());
        }
        storedHuntResults.get(am.getHuntingTeam()).add(new TeamHuntEvent(act, actorID));
      }
      logger.log(
          Level.FINE,
          "Agent {0} hunted {1}{2}",
          new Object[] {
            nameOf(actorID),
            food.getName(),
            am.getHuntingTeam() == null ? " alone." : " with team " + am.getHuntingTeam().hashCode()
          });
      return null;
    }
Example #2
0
 /**
  * Creates a new Team Hunt Event record based off the data passed to the {@link HuntHandler},
  * namely the Hunt and the ActorID
  *
  * @param hunt The hunt object
  * @param actorID The hunter's id
  */
 TeamHuntEvent(Hunt hunt, String actorID) {
   this.food = dmodel.getFoodById(hunt.getFoodTypeId());
   this.agent = actorID;
 }