Exemplo n.º 1
0
  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());
  }
Exemplo n.º 2
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;
  }
Exemplo n.º 3
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());
  }
Exemplo n.º 4
0
 /**
  * 随机一个箱子
  *
  * @param rewardId
  * @param digPropId
  * @param openedBoxs
  * @return
  */
 public int randomBox(int rewardId, int digPropId, Collection<Integer> openedBoxs) {
   List<Integer> allNpcIds = getAllNpcTypeIds(rewardId, digPropId);
   if (allNpcIds != null && openedBoxs != null) {
     int size = allNpcIds.size();
     if (size > 0 && allNpcIds.size() > openedBoxs.size()) {
       while (true) {
         int id = allNpcIds.get(Tools.getRandomInteger(size));
         TreasureEventConfig treasureEventConfig =
             this.resourceService.get(id, TreasureEventConfig.class);
         int npcId = treasureEventConfig.getType();
         if (!openedBoxs.contains(npcId)) {
           return npcId;
         }
       }
     }
   }
   return 0;
 }
Exemplo n.º 5
0
  /**
   * 随机一个藏宝图
   *
   * @param treasureId
   * @return
   */
  private TreasureConfig randomTreasure(int treasureId) {
    List<TreasureConfig> list =
        resourceService.listByIndex(IndexName.TREASURE_REWARDID, TreasureConfig.class, treasureId);
    if (list != null && list.size() > 0) {
      int rndRate = 0;
      int rate = 0;
      for (TreasureConfig config : list) {
        if (rndRate <= 0) {
          rndRate = Tools.getRandomInteger(config.getFullRate());
        }
        rate += config.getRate();
        if (rndRate < rate) {
          return config;
        }
      }

    } else {
      logger.error("藏宝图id[{}]没有对应的品质刷新数据", treasureId);
    }
    return null;
  }
Exemplo n.º 6
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());
  }
Exemplo n.º 7
0
  /**
   * 随机藏宝图怪物
   *
   * @param monsterDropNo
   * @return
   */
  public TreasureMonsterConfig getTreasureMonsterConfig(int monsterDropNo) {
    List<TreasureMonsterConfig> list =
        resourceService.listByIndex(
            IndexName.TREASURE_DROP_NO, TreasureMonsterConfig.class, monsterDropNo);
    if (list != null && list.size() > 0) {
      int rndRate = 0;
      int rate = 0;
      for (TreasureMonsterConfig config : list) {
        if (rndRate <= 0) {
          rndRate = Tools.getRandomInteger(config.getFullRate());
        }
        rate += config.getRate();
        if (rndRate < rate) {
          return config;
        }
      }

    } else {
      logger.error("藏宝图怪物掉落id[{}]没有对应的数据", monsterDropNo);
    }
    return null;
  }