Пример #1
0
  /**
   * 声望招募英雄
   *
   * @param userId
   * @param systemHeroId
   * @return
   */
  public Map<String, Object> inviteHero(String userId, int systemHeroId, String heroName) {
    User user = userService.getByUserId(userId);
    SystemInviteHero systemInviteHero =
        this.systemInviteHeroDaoCache.getSystemInviteHero(systemHeroId);

    if (systemInviteHero == null)
      throw new ServiceException(
          SystemConstant.FAIL_CODE,
          "没有配置该英雄??userId[" + userId + "],systemHeroId[" + systemHeroId + "]");

    if (systemInviteHero.getCamp() != 0 && user.getCamp() != systemInviteHero.getCamp())
      throw new ServiceException(CAMP_NOT_MATE, "阵营不匹配");

    // 背包检查
    List<GoodsBeanBO> list = new ArrayList<GoodsBeanBO>();
    GoodsBeanBO goodsBeanBO = new GoodsBeanBO();
    goodsBeanBO.setGoodsId(systemInviteHero.getSystemHeroId());
    goodsBeanBO.setGoodsType(GoodsType.Hero.intValue);
    goodsBeanBO.setGoodsNum(1);
    list.add(goodsBeanBO);
    this.userService.checkBag(userId, list);

    Map<String, Object> map = new HashMap<String, Object>();
    // 各种XX条件判断
    if (user.getGold() < systemInviteHero.getNeedGold())
      throw new ServiceException(SystemErrorCode.GOLD_NOT_ENOUGH, "金币不足");

    if (user.getLevel() < systemInviteHero.getLevel())
      throw new ServiceException(SystemErrorCode.LEVEL_NOT_ENOUGH, "等级不足");

    // 扣金币
    if (!this.userService.reduceGold(
        userId, systemInviteHero.getNeedGold(), GoodsUseType.REDUCE_PRESTIGE_INVITE))
      throw new ServiceException(SystemErrorCode.GOLD_NOT_ENOUGH, "金币不足");

    CommonGoodsBeanBO drop = new CommonGoodsBeanBO();
    this.heroService.addHero(
        userId, systemHeroId, false, heroName, GoodsUseType.ADD_PRESTIGE_INVITE, drop);

    user = this.userService.getByUserId(userId);
    map.put("dr", drop);
    map.put("gd", user.getGold());
    map.put("mon", user.getMoney());
    return map;
  }
Пример #2
0
  /**
   * 查看用户的酒馆信息
   *
   * @param userId
   * @return
   */
  public List<InviteHeroBO> getInviteHeroInfo(String userId) {
    List<InviteHeroBO> list = Lists.newArrayList();
    User user = this.userService.getByUserId(userId);

    List<SystemInviteHero> inviteList =
        this.systemInviteHeroDaoCache.getSystemInviteHeroList(user.getCamp());
    Map<String, String> tempMap = Maps.newConcurrentMap();

    Map<String, String> nameMap = this.heroService.getUserHeroNameMap(userId);
    for (SystemInviteHero hero : inviteList) {
      InviteHeroBO heroBO = new InviteHeroBO();
      heroBO.setSystemHeroId(hero.getSystemHeroId());
      String heroName =
          this.heroService.getNewHeroName(userId, hero.getSystemHeroId(), nameMap, tempMap);
      heroBO.setHeroName(heroName);
      tempMap.put(heroName, heroName);

      list.add(heroBO);
    }

    return list;
  }