/// <summary> /// 请求购买商品的消息处理 /// </summary> /// <param name="token"></param> /// <param name="model"></param> private void OnReqBuyGoods(UserToken token, SocketModel model) { ReqBuyGoods req = SerializeUtil.Deserialize <ReqBuyGoods>(model.message); MallCfg cfg = ConfigManager.instance.mallCfgs[(int)req.goodid]; CharacterData ch = CacheManager.instance.GetCharData(token.characterid); RspBuyGoods rsp = new RspBuyGoods(); // 金币不足 if (req.buyType == BuyType.Gold) { if (ch.gold < cfg.Gold) { rsp.msgtips = (uint)MsgTips.GoldNotEnough; } else { // 更新缓存 ch.gold -= cfg.Gold; rsp.msgtips = (uint)MsgTips.BuyGoodsSuccess; } } // 钻石不足 else if (req.buyType == BuyType.Diamon) { if (ch.diamond < cfg.Diamond) { rsp.msgtips = (uint)MsgTips.DiamondNotEnough; } else { ch.diamond -= cfg.Diamond; rsp.msgtips = (uint)MsgTips.BuyGoodsSuccess; } } // 同步角色金币数据 rsp.gold = (uint)ch.gold; rsp.diamond = (uint)ch.diamond; // 更新背包缓存 int firstEmptySlot = CacheManager.instance.GetFirstEmptySlot(token.characterid); InventoryData invData = CacheManager.instance.GetInvData(token.characterid, firstEmptySlot); invData.itemid = cfg.ItemID; invData.num = 1; rsp.inv = InventoryData.GetInvDTO(invData); NetworkManager.Send(token, (int)MsgID.BuyGoods_SRES, rsp); }
private void OnBuyGoodsRsp(SocketModel model) { RspBuyGoods rsp = SerializeUtil.Deserialize <RspBuyGoods>(model.message); if (rsp.msgtips == (uint)MsgTips.BuyGoodsSuccess) { WindowManager.instance.Close <BuyTypeWnd>(); DataCache.instance.currentCharacter.gold = (int)rsp.gold; DataCache.instance.currentCharacter.diamond = (int)rsp.diamond; WindowManager.instance.Get <MallWnd>().UpdateGoldDiamond((int)rsp.gold, (int)rsp.diamond); } else if (rsp.msgtips == (uint)MsgTips.DiamondNotEnough) { MessageBox.Show("钻石不足"); } else if (rsp.msgtips == (uint)MsgTips.GoldNotEnough) { MessageBox.Show("金币不足"); } }