Пример #1
0
  public Npc getRandomCollect(int level) {
    List<NpcConfig> allGather = new ArrayList<NpcConfig>(); // 所有采集物
    List<MapConfig> mapList =
        resourceService.listByIndex(
            IndexName.MAP_SCREENTYPE, MapConfig.class, ScreenType.FIELD.ordinal());
    if (mapList != null && !mapList.isEmpty()) {
      HashSet<Integer> mapIdList = new HashSet<Integer>();
      for (MapConfig config : mapList) {
        if (config == null) {
          continue;
        }
        if (level >= config.getLevelLimit()) {
          mapIdList.add(config.getId());
        }
      }

      if (!mapIdList.isEmpty()) {
        for (int mapId : mapIdList) {
          List<NpcConfig> npcList =
              resourceService.listByIndex(IndexName.NPC_MAPID, NpcConfig.class, mapId);
          if (npcList != null && !npcList.isEmpty()) {
            for (NpcConfig config : npcList) {
              if (config.getElementType() == ElementType.NPC_GATHER.ordinal()) {
                allGather.add(config);
              }
            }
          }
        }
      }
    }

    NpcConfig npcConfig = allGather.get(Tools.getRandomInteger(allGather.size()));
    return this.getNpc(npcConfig.getId());
  }
Пример #2
0
  public Npc getRandomNpcByLevel(int level) {
    List<NpcConfig> allNpcList = new ArrayList<NpcConfig>(); // 所有NPC
    List<NpcConfig> castleList =
        npcService.listNpcConfig(ScreenType.CASTLE.ordinal(), ElementType.NPC.ordinal());
    if (castleList != null && !castleList.isEmpty()) {
      allNpcList.addAll(castleList);
    }
    List<MapConfig> mapList =
        resourceService.listByIndex(
            IndexName.MAP_SCREENTYPE, MapConfig.class, ScreenType.FIELD.ordinal());
    if (mapList != null && !mapList.isEmpty()) {
      HashSet<Integer> mapIdList = new HashSet<Integer>();
      for (MapConfig config : mapList) {
        if (config == null) {
          continue;
        }
        if (level >= config.getLevelLimit()) {
          mapIdList.add(config.getId());
        }
      }

      if (!mapIdList.isEmpty()) {
        for (int mapId : mapIdList) {
          List<NpcConfig> result =
              resourceService.listByIndex(IndexName.NPC_MAPID, NpcConfig.class, mapId);
          if (result != null && !result.isEmpty()) {
            for (NpcConfig config : result) {
              if (config.getElementType() == ElementType.NPC.ordinal()
                  && config.getScreenType() == ScreenType.FIELD.ordinal()) {
                allNpcList.add(config);
              }
            }
          }
        }
      }
    }

    NpcConfig npcConfig = allNpcList.get(Tools.getRandomInteger(allNpcList.size()));
    return this.getNpc(npcConfig.getId());
  }