/** * 根据角色等级随机生成一个地图坐标位置 * * @param playerLevel * @return int[地图id, x坐标, y坐标] */ public int[] randomMapPoint(int playerLevel, int branch) { ScreenType[] types = {ScreenType.FIELD}; List<MapConfig> mapList = new ArrayList<MapConfig>(); for (ScreenType type : types) { List<MapConfig> list = resourceService.listByIndex(IndexName.MAP_SCREENTYPE, MapConfig.class, type.ordinal()); for (Iterator<MapConfig> iterator = list.iterator(); iterator.hasNext(); ) { MapConfig mapConfig = iterator.next(); int levelLimit = mapConfig.getLevelLimit(); if (playerLevel < levelLimit || levelLimit < TreasureRule.TREASURE_MAP_LEVEL_LIMIT) { iterator.remove(); } } mapList.addAll(list); } if (mapList.size() > 0) { MapConfig mapConfig = mapList.get(Tools.getRandomInteger(mapList.size())); int mapId = mapConfig.getId(); GameMap gameMap = gameMapManager.getGameMapById(mapId, branch); Point randomPoint = gameMapManager.randomPoint(gameMap); if (randomPoint != null) { return new int[] {mapId, randomPoint.x, randomPoint.y}; } } return null; }
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()); } }