示例#1
0
  /**
   * 消除cdType的cd
   *
   * @param cdType
   */
  public void removeCd(CdType cdType) {
    long now = GameServerAssist.getSystemTimeService().now();
    // 获取cd时间
    long cdInterval = getDiffTime(getCdInfo(cdType).getEndTime());
    if (cdInterval <= 0) {
      return;
    }
    // 计算需要消耗的货币数量
    CdTemplate cdTemplate =
        GameServerAssist.getCdTemplateManager().getCdTemplate(cdType.getIndex());
    if (!cdTemplate.isCanRemove()) {
      return;
    }
    CurrencyType currencyType = CurrencyType.indexOf(cdTemplate.getCurrencyType());
    int currencyNum = getRemoveCdCost(cdType, cdInterval);
    // 判断是否有足够的货币
    if (!human.getWallet().isEnough(currencyType, currencyNum)) {
      human.sendWarningMessage(LangConstants.COMMON_NOT_ENOUGH, currencyType.getDesc());
      return;
    }
    // 扣除货币
    boolean cost =
        human.getWallet().costMoney(currencyType, currencyNum, MoneyLogReason.REMOVE_CD, "");
    // 消除cd
    if (!cost) {
      logger.error(
          "消除cd时扣除对应货币失败。humanid"
              + human.getHumanGuid()
              + "; currencyType:"
              + currencyType.getDesc()
              + "; num:"
              + currencyNum);
      human.sendErrorMessage(LangConstants.SERVER_ERROR);
      return;
    }
    CdInfo cdInfo = getCdInfo(cdType);
    cdInfo.setEndTime(now);

    cdInfoMap.put(cdType, cdInfo);
    // 同步缓存
    cdInfoCaches.addUpdate(cdType, cdInfo);

    // 押运CD特殊处理
    if (cdType == CdType.ESCORT) {
      EscortInfo escortInfo =
          GameServerAssist.getGlobalEscortManager().getEscortInfo(human.getHumanGuid());
      GameServerAssist.getGlobalEscortManager().endEscort(escortInfo);
    }
  }
  @Override
  public void execute(CGBuyHonourShopItem message) {
    Player player = message.getPlayer();
    if (player == null) {
      return;
    }

    Human human = player.getHuman();
    if (human == null) {
      return;
    }

    // 判断功能是否开放
    if (!gameFuncService.gameFuncIsOpen(human, GameFuncType.HONOUR_SHOP, true)) {
      return;
    }

    // 客户端参数校验
    int itemId = message.getItemId();
    if (itemId < 1) {
      return;
    }
    int num = message.getNum();
    if (num < 1) {
      return;
    }

    // 判断是否是荣誉商店出售物品
    HonourShopItemInfo honourShopItemInfo = templateManager.getHonourShopItemInfo(itemId);
    if (honourShopItemInfo == null
        || !templateManager.canSee(honourShopItemInfo, human.getLevel())) {
      return;
    }

    // 判断荣誉是否足够
    int totalHonorNum = honourShopItemInfo.getNeedHonour() * num;
    if (human.getArenaHonor() < totalHonorNum) {
      String honorDesc = GameServerAssist.getSysLangService().read(LangConstants.HONOR);
      human.sendWarningMessage(LangConstants.COMMON_NOT_ENOUGH, honorDesc);
      return;
    }

    // 判断背包是否可以放得下
    if (!human.getBagManager().canContain(itemId, num)) {
      human.sendWarningMessage(LangConstants.BAG_IS_FULL);
      return;
    }

    // 扣除荣誉
    human.setArenaHonor(human.getArenaHonor() - totalHonorNum);
    // 记录荣誉变更日志
    GameServerAssist.getLogService()
        .sendHonourLog(
            human,
            HonourLogReason.HONOR_SHOP_BUY_ITEM,
            "",
            honourShopItemInfo.getNeedHonour(),
            human.getArenaHonor());
    // 给物品
    human.getBagManager().putItems(BagType.MAIN_BAG, itemId, num, ItemLogReason.HONOUR_SHOP, "");

    GCBuyHonourShopItem gcMsg = new GCBuyHonourShopItem();
    gcMsg.setSuccess(true);
    gcMsg.setLeftHonour(human.getArenaHonor());
    human.sendMessage(gcMsg);
  }