예제 #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);
    }
  }
예제 #2
0
 /** 领取黄钻每日礼包 */
 public void receiveDailyReward() {
   if (this.getYellowVipDailyRewardState() != YellowVipRewardState.CAN_GET.getIndex()) {
     return;
   }
   int yellowVipLevel = this.getYellowVipLevel();
   if (yellowVipLevel <= 0) {
     return;
   }
   YellowVipDailyRewardTemplate template =
       GameServerAssist.getYellowVipTemplateManager()
           .getYellowVipDailyRewardTemplate(human.getLevel());
   if (template == null) {
     return;
   }
   int maxRewardLevel = template.getVipCoin().size();
   int rewardIndex = yellowVipLevel >= maxRewardLevel ? maxRewardLevel - 1 : yellowVipLevel - 1;
   human
       .getWallet()
       .addMoney(
           CurrencyType.COIN,
           template.getVipCoin().get(rewardIndex),
           true,
           MoneyLogReason.YELLOW_VIP_DAILY_REWARD,
           "");
   dailyRewardState = YellowVipRewardState.HAS_GOT.getIndex();
   cache.addUpdate(human.getHumanGuid(), convertToEntity());
   GCUpdateYellowVipRewardState gcMsg = new GCUpdateYellowVipRewardState();
   gcMsg.setRewardType(YellowVipRewardType.DAILY_REWARD.getIndex());
   gcMsg.setRewardState(new int[] {dailyRewardState});
   human.sendMessage(gcMsg);
 }
예제 #3
0
 /** 领取年费黄钻每日礼包 */
 public void receiveYearVipDailyReward() {
   if (this.getYearYellowVipRewardState() != YellowVipRewardState.CAN_GET.getIndex()) {
     return;
   }
   YearYellowVipRewardTemplate template =
       GameServerAssist.getYellowVipTemplateManager().getYearYellowVipRewardTemplate();
   if (human.getBagManager().getFreeSize(BagType.MAIN_BAG) < 2) {
     human.sendErrorMessage(LangConstants.BAG_FREE_UNIT_NOT_ENOUGH);
     return;
   }
   human
       .getBagManager()
       .putItems(
           BagType.MAIN_BAG,
           template.getItemId1(),
           template.getItemCount1(),
           ItemLogReason.YEAR_YELLOW_VIP_DAILY_REWARD,
           "");
   human
       .getBagManager()
       .putItems(
           BagType.MAIN_BAG,
           template.getItemId2(),
           template.getItemCount2(),
           ItemLogReason.YEAR_YELLOW_VIP_DAILY_REWARD,
           "");
   yearVipDailyRewardState = YellowVipRewardState.HAS_GOT.getIndex();
   cache.addUpdate(human.getHumanGuid(), convertToEntity());
   GCUpdateYellowVipRewardState gcMsg = new GCUpdateYellowVipRewardState();
   gcMsg.setRewardType(YellowVipRewardType.YEAR_VIP_REWARD.getIndex());
   gcMsg.setRewardState(new int[] {yearVipDailyRewardState});
   human.sendMessage(gcMsg);
 }
예제 #4
0
 /** 领取黄钻新手礼包 */
 public void receiveOnceReward() {
   if (getYellowVipOnceRewardState() != YellowVipRewardState.CAN_GET.getIndex()) {
     return;
   }
   int itemId = GameServerAssist.getYellowVipTemplateManager().getOnceRewardItemId();
   Item rewardItem = ItemFactory.creatNewItem(human, itemId);
   if (rewardItem == null) {
     return;
   }
   int itemCount = 1;
   if (rewardItem.getType() == ItemDetailType.VIRTUAL_SPREE.getIndex()) {
     SpreeTemplate spreeTemplate =
         GameServerAssist.getSpreeTemplateManager().getSpreeTemplate(itemId);
     if (spreeTemplate == null) {
       return;
     }
     itemCount =
         spreeTemplate.getItems().size() < spreeTemplate.getItemCount()
             ? spreeTemplate.getItems().size()
             : spreeTemplate.getItemCount();
   }
   if (human.getBagManager().getFreeSize(BagType.MAIN_BAG) < itemCount) {
     human.sendErrorMessage(LangConstants.BAG_FREE_UNIT_NOT_ENOUGH);
     return;
   }
   human
       .getBagManager()
       .putItems(BagType.MAIN_BAG, itemId, 1, ItemLogReason.YELLOW_VIP_ONCE_REWARD, "");
   onceRewardState = YellowVipRewardState.HAS_GOT.getIndex();
   cache.addUpdate(human.getHumanGuid(), convertToEntity());
   GCUpdateYellowVipRewardState gcMsg = new GCUpdateYellowVipRewardState();
   gcMsg.setRewardType(YellowVipRewardType.ONCE_REWARD.getIndex());
   gcMsg.setRewardState(new int[] {onceRewardState});
   human.sendMessage(gcMsg);
 }
예제 #5
0
 private HumanYellowVipRewardStateEntity convertToEntity() {
   HumanYellowVipRewardStateInfo.Builder builder = HumanYellowVipRewardStateInfo.newBuilder();
   builder.setHumanGuid(human.getHumanGuid());
   builder.setDailyRewardState(dailyRewardState);
   builder.setYearVipDailyRewardState(yearVipDailyRewardState);
   builder.setOnceRewardState(onceRewardState);
   for (Integer state : levelUpRewardState) {
     builder.addLevelUpRewardState(state);
   }
   return new HumanYellowVipRewardStateEntity(builder);
 }
예제 #6
0
 @Override
 public void onLogin() {
   int yellowVipLevel = 0;
   int isYearYellowVip = 0;
   int isYellowHighVip = 0;
   String openId = "";
   IntPropertyCacheSet propertySet =
       human.getPropertyManager().getIntPropertySet(PropertyType.HUMAN_INT_PROPERTY);
   if (human.getPlayer().getLocalProperties() != null) {
     Object objYellowVipLevel =
         human.getPlayer().getLocalProperties().get(SharedConstants.YELLOW_VIP_LEVEL);
     yellowVipLevel =
         objYellowVipLevel != null && !StringUtils.isEmpty(objYellowVipLevel.toString())
             ? Integer.parseInt(objYellowVipLevel.toString())
             : 0;
     Object objIsYearVip =
         human.getPlayer().getLocalProperties().get(SharedConstants.IS_YELLOW_YEAR_VIP);
     isYearYellowVip =
         objIsYearVip != null && !StringUtils.isEmpty(objIsYearVip.toString())
             ? Integer.parseInt(objIsYearVip.toString())
             : 0;
     Object objIsYellowHighVip =
         human.getPlayer().getLocalProperties().get(SharedConstants.IS_YELLOW_HIGH_VIP);
     isYellowHighVip =
         objIsYellowHighVip != null && !StringUtils.isEmpty(objIsYellowHighVip.toString())
             ? Integer.parseInt(objIsYellowHighVip.toString())
             : 0;
     Object objOpenId = human.getPlayer().getLocalProperties().get(SharedConstants.OPEN_ID);
     openId = objOpenId != null ? objOpenId.toString() : "";
     if (yellowVipLevel <= 0) {
       isYearYellowVip = 0;
       isYellowHighVip = 0;
     }
   }
   propertySet.setPropertyValue(HumanIntProperty.YELLOW_VIP_LEVEL, yellowVipLevel);
   propertySet.setPropertyValue(HumanIntProperty.IS_YEAR_YELLOW_VIP, isYearYellowVip);
   propertySet.setPropertyValue(HumanIntProperty.IS_YELLOW_HIGH_VIP, isYellowHighVip);
   TencentUserInfo txUserInfo = new TencentUserInfo();
   txUserInfo.setId(human.getHumanGuid());
   txUserInfo.setPassportId(human.getPlayer().getPassportId());
   txUserInfo.setOpenId(openId);
   txUserInfo.setYellowVipLevel(yellowVipLevel);
   txUserInfo.setIsYearYellowVip(isYearYellowVip == 1);
   txUserInfo.setIsYellowHighVip(isYellowHighVip == 1);
   GameServerAssist.getTencentUserInfoManager().updateTencentUserInfo(txUserInfo);
   updateLevelUpRewardState();
 }
예제 #7
0
 public void receiveLevelUpReward(int rewardIndex) {
   if (rewardIndex < 0 || rewardIndex > levelUpRewardState.length - 1) {
     return;
   }
   if (levelUpRewardState[rewardIndex] != YellowVipRewardState.CAN_GET.getIndex()) {
     return;
   }
   int[] levels = GameServerAssist.getYellowVipTemplateManager().getLevelUpRewardKeys();
   if (human.getLevel() < levels[rewardIndex]) {
     return;
   }
   if (human.getBagManager().getFreeSize(BagType.MAIN_BAG) < 1) {
     human.sendErrorMessage(LangConstants.BAG_FREE_UNIT_NOT_ENOUGH);
     return;
   }
   YellowVipLevelUpRewardTemplate template =
       GameServerAssist.getYellowVipTemplateManager()
           .getYellowVipLevelUpRewardTemplate(levels[rewardIndex]);
   human
       .getWallet()
       .addMoney(
           CurrencyType.COIN,
           template.getCoin(),
           true,
           MoneyLogReason.YELLOW_VIP_LEVEL_UP_REWARD,
           "");
   human
       .getBagManager()
       .putItems(
           BagType.MAIN_BAG,
           template.getItemId(),
           template.getItemCount(),
           ItemLogReason.YELLOW_VIP_LEVEL_UP_REWARD,
           "");
   levelUpRewardState[rewardIndex] = YellowVipRewardState.HAS_GOT.getIndex();
   cache.addUpdate(human.getHumanGuid(), convertToEntity());
   GCUpdateYellowVipRewardState gcMsg = new GCUpdateYellowVipRewardState();
   gcMsg.setRewardType(YellowVipRewardType.LEVEL_UP_REWARD.getIndex());
   gcMsg.setRewardState(levelUpRewardState);
   human.sendMessage(gcMsg);
 }