Beispiel #1
0
 /** 重置cd的疲劳度 */
 public void resetCdTired() {
   for (CdInfo cdInfo : cdInfoMap.values()) {
     cdInfo.setTimes(0);
     cdInfoMap.put(CdType.indexOf(cdInfo.getCdType()), cdInfo);
     // 同步缓存
     cdInfoCaches.addUpdate(CdType.indexOf(cdInfo.getCdType()), cdInfo);
   }
 }
Beispiel #2
0
 /**
  * 获取cdType对应的cd信息
  *
  * @param cdType
  * @return
  */
 public CdInfo getCdInfo(CdType cdType) {
   CdInfo cdInfo = cdInfoMap.get(cdType);
   if (cdInfo == null) {
     cdInfo = new CdInfo();
     cdInfo.setCdType(cdType.getIndex());
     cdInfo.setEndTime(GameServerAssist.getSystemTimeService().now());
   }
   return cdInfo;
 }
Beispiel #3
0
  /**
   * 减少CD时间
   *
   * @param time 减少时间
   */
  public void reduceCdTime(CdType cdType, long time) {
    if (!cdInfoMap.containsKey(cdType)) {
      return;
    }
    CdInfo cdInfo = getCdInfo(cdType);
    cdInfo.setEndTime(cdInfo.getEndTime() - time);

    cdInfoMap.put(cdType, cdInfo);
    // 同步缓存
    cdInfoCaches.addUpdate(cdType, cdInfo);
  }
Beispiel #4
0
  /**
   * 免费消除cd
   *
   * @param cdType
   */
  public void removeCdFree(CdType cdType) {
    if (!cdInfoMap.containsKey(cdType)) {
      return;
    }
    long now = GameServerAssist.getSystemTimeService().now();
    CdInfo cdInfo = getCdInfo(cdType);
    cdInfo.setEndTime(now);

    cdInfoMap.put(cdType, cdInfo);
    // 同步缓存
    cdInfoCaches.addUpdate(cdType, cdInfo);
  }
Beispiel #5
0
  @Override
  public void onLoad(HumanEntity humanEntity) {
    for (HumanCd.Builder builder : humanEntity.getBuilder().getCdBuilderList()) {
      CdData cdData = builder.getCdData();
      CdType cdType = CdType.indexOf(cdData.getCdType());
      CdInfo cdInfo = new CdInfo();
      cdInfo.setCdType(cdType.getIndex());
      cdInfo.setTimes(cdData.getTimes());
      cdInfo.setEndTime(cdData.getEndTime());

      cdInfoMap.put(cdType, cdInfo);
    }
  }
Beispiel #6
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);
    }
  }
Beispiel #7
0
  /**
   * 增加CD时间
   *
   * @param time 增加时间
   */
  public void addCdTime(CdType cdType, long time) {
    if (!cdInfoMap.containsKey(cdType)) {
      return;
    }
    CdInfo cdInfo = getCdInfo(cdType);
    long endTime = cdInfo.getEndTime();
    long now = GameServerAssist.getSystemTimeService().now();
    if (endTime < now) {
      endTime = now;
    }
    cdInfo.setEndTime(endTime + time);

    cdInfoMap.put(cdType, cdInfo);
    // 同步缓存
    cdInfoCaches.addUpdate(cdType, cdInfo);
  }
Beispiel #8
0
  /**
   * 添加ms长的时间
   *
   * @param cdType
   * @param ms
   */
  public void addCd(CdType cdType, long ms) {
    // 出现ms小于零的情况肯定是非法情况
    if (ms < 0) {
      return;
    }
    // 调用添加cd之前应该已经判断过,所以如果再次判断不能添加直接返回
    if (!canAddCd(cdType, ms)) {
      return;
    }

    CdInfo cdInfo = getCdInfo(cdType);
    long now = GameServerAssist.getSystemTimeService().now();
    if (cdInfo.getEndTime() < now) {
      cdInfo.setEndTime(now + ms);
    } else {
      cdInfo.setEndTime(cdInfo.getEndTime() + ms);
    }
    cdInfo.setTimes(cdInfo.getTimes() + 1);
    cdInfoMap.put(cdType, cdInfo);
    // 同步缓存
    cdInfoCaches.addUpdate(cdType, cdInfo);
  }