/** * 消除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); } }
/** 领取黄钻每日礼包 */ 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); }
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); }
@Override public void execute(CGSellShopItem message) { Player player = message.getPlayer(); if (player == null) { return; } Human human = player.getHuman(); if (human == null) { return; } // 判断功能是否开放 if (!gameFuncService.gameFuncIsOpen(human, GameFuncType.SHOP, true)) { return; } BagType bagType = BagType.indexOf(message.getBagType()); int bagIndex = message.getBagIndex(); Item item = human.getBagManager().getItem(bagType, bagIndex); if (item == null) { return; } // 判断物品是否可以出售 ItemTemplate itemTemplate = templateManager.getItemTemplate(item.getItemId()); if (itemTemplate == null || !itemTemplate.canSell()) { human.sendErrorMessage(LangConstants.CAN_NOT_SELL_ITEM); return; } int num = message.getNum(); if (num < 1) { return; } if (item.getOverlapNum() < num) { return; } int sellPrice = item.getSellCurrencyNum(); if (item.isEquip()) { EquipItemFeature feature = (EquipItemFeature) item.getFeature(); if (feature.isEquiped()) { human.sendErrorMessage(LangConstants.CAN_NOT_SELL); return; } EquipUpgradeTemplate upgradeTemplate = GameServerAssist.getEquipUpgradeTemplateManager() .getEquipUpgradeTemplate(item.getItemId(), feature.getLevel()); if (upgradeTemplate != null) { sellPrice = upgradeTemplate.getSellPrice(); } } human .getWallet() .addMoney( CurrencyType.indexOf(item.getSellCurrencyType()), sellPrice * num, true, MoneyLogReason.SHOP_SELL, ""); human .getBagManager() .removeItem(item.getBagType(), item.getBagIndex(), num, ItemLogReason.SHOP_SELL, ""); }