Ejemplo n.º 1
0
  /**
   * 根据角色等级随机生成一个地图坐标位置
   *
   * @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;
  }