コード例 #1
0
ファイル: NpcFacadeImpl.java プロジェクト: fuyunkong/Warriors
  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
ファイル: NpcFacadeImpl.java プロジェクト: fuyunkong/Warriors
  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());
  }
コード例 #3
0
ファイル: NpcFacadeImpl.java プロジェクト: fuyunkong/Warriors
  public void initNPC() {
    List<NpcConfig> list = (List<NpcConfig>) baseService.listAll(NpcConfig.class);
    if (list == null || list.isEmpty()) {
      LOGGER.error("NPC数据为空");
      return;
    }

    if (npcs == null) {
      npcs = new HashMap<Integer, Npc>(list.size());
      handleNpcSet = Collections.synchronizedSet(new HashSet<Npc>(5));
    }

    CopyOnWriteArrayList<Integer> branchs = channelFacade.getCurrentBranching();
    for (NpcConfig config : list) {
      if (config.getMapId() == null) {
        LOGGER.error("构建NPC数据,基础NPC:{},地图ID为空,请检查配置", config.getId());
        continue;
      }
      Npc npc = Npc.valueOf(config);
      Npc exist = this.npcs.put(npc.getId(), npc);
      if (exist != null) {
        LOGGER.error(
            "重复npc1[id:{}, mapId:{}],npc2[id:{}, mapId:{}],请检查配置",
            new Object[] {config.getId(), config.getMapId(), exist.getId(), exist.getMapId()});
      }

      for (int branching : branchs) {
        GameMap gameMap = gameMapManager.getGameMapById(npc.getMapId(), branching);
        if (gameMap == null) {
          continue;
        }
        UnitId unitId = UnitId.valueOf(config.getId(), ElementType.NPC);
        gameMap.enterMap(unitId, config.getBornX(), config.getBornY());
      }
    }
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("NPC数据构建完毕,一共存在[{}]个NPC", this.npcs.size());
    }
  }