Exemplo n.º 1
0
  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());
    }
  }