/**
  * 获取操作应该花费的cd时间
  *
  * @param cdType
  * @param baseTime
  * @return
  */
 public long getSpendTime(CdType cdType, long baseTime) {
   CdTemplate cdTemplate =
       GameServerAssist.getCdTemplateManager().getCdTemplate(cdType.getIndex());
   if (cdTemplate == null) {
     return baseTime;
   }
   return (long) (baseTime + (cdTemplate.getBaseCd() + getCdTired(cdType)) * TimeUtils.MIN);
 }
 /**
  * 获取花费
  *
  * @param cdType
  * @param cdInterval
  * @return
  */
 public int getRemoveCdCost(CdType cdType, long cdInterval) {
   CdTemplate cdTemplate =
       GameServerAssist.getCdTemplateManager().getCdTemplate(cdType.getIndex());
   if (cdTemplate == null || cdInterval < 1) {
     return 0;
   }
   return (int)
       (cdTemplate.getCurrencyNum()
           * ((cdInterval - 1) / (TimeUtils.MIN * cdTemplate.getCostMins()) + 1));
 }
 /**
  * 下发加速消除cd的确认信息
  *
  * @param cdType
  */
 public void snapCdSpeedUpInfo(CdType cdType) {
   long timeDiff = getDiffTime(getCdInfo(cdType).getEndTime());
   if (timeDiff > 0) {
     CdTemplate cdTemplate =
         GameServerAssist.getCdTemplateManager().getCdTemplate(cdType.getIndex());
     int currencyNum = getRemoveCdCost(cdType, timeDiff);
     GCCdSpeedUp gcCdSpeedUpMsg = new GCCdSpeedUp();
     gcCdSpeedUpMsg.setCdType(cdType.getIndex());
     gcCdSpeedUpMsg.setCurrencyType(cdTemplate.getCurrencyType());
     gcCdSpeedUpMsg.setCurrencyNum(currencyNum);
     human.sendMessage(gcCdSpeedUpMsg);
   }
 }
 /**
  * 获取cdType对应的疲劳度
  *
  * @param cdType
  * @return
  */
 private float getCdTired(CdType cdType) {
   CdTemplate cdTemplate =
       GameServerAssist.getCdTemplateManager().getCdTemplate(cdType.getIndex());
   if (cdTemplate.getTiredRatio() <= 0) {
     return 0;
   }
   CdTiredTemplate cdTiredTemplate =
       GameServerAssist.getCdTemplateManager().getCdTiredTemplate(getCdInfo(cdType).getTimes());
   if (cdTiredTemplate == null) {
     return GameServerAssist.getCdTemplateManager().getMaxCdTired() * cdTemplate.getTiredRatio();
   }
   return cdTiredTemplate.getTired() * cdTemplate.getTiredRatio();
 }
  /**
   * 消除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);
    }
  }
  /**
   * cdType是否可以添加ms长的时间
   *
   * @param cdType
   * @param ms
   * @return
   */
  public boolean canAddCd(CdType cdType, long ms) {
    CdTemplate cdTemplate =
        GameServerAssist.getCdTemplateManager().getCdTemplate(cdType.getIndex());
    if (cdTemplate == null) {
      return false;
    }
    Long cdEndTime = getCdInfo(cdType).getEndTime();
    long now = GameServerAssist.getSystemTimeService().now();
    if (cdTemplate.getCdMode() == 2) {
      // cd不可累加,cd结束后才能添加
      return now >= cdEndTime;
    }
    long maxMs = cdTemplate.getCdMaxNum() * TimeUtils.MIN;

    return (cdEndTime - now + ms) <= maxMs;
  }