Beispiel #1
0
  public Npc getRandomNpcByScreenType(int screenType) {
    List<NpcConfig> npcList = npcService.listNpcConfig(screenType, ElementType.NPC.ordinal());
    if (npcList == null || npcList.isEmpty()) {
      return null;
    }

    NpcConfig npcConfig = npcList.get(Tools.getRandomInteger(npcList.size()));
    return this.getNpc(npcConfig.getId());
  }
Beispiel #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());
  }