local WalletShopData = class("WalletShopData", require("DataBase")) local ProtocalDataNormal = require("ProtocalDataNormal") function WalletShopData:ctor() self.walletData = nil end function deepPrint(t, indentLevel) indentLevel = indentLevel or 0 local indent = "" for i = 1, indentLevel do indent = indent .. " " end local str = "" if type(t) == "table" then for k, v in pairs(t) do str = str .. indent .. "Key: " .. tostring(k) .. " - Value: " str= str .. deepPrint(v, indentLevel + 1) end else str= str .. indent .. tostring(t) end return str end function WalletShopData:RegisterNetEvents() ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_RUNE_BASE_DATA_NTF,self.RefreshWalletData,self) ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_BT_SHOP_INFO_ACK,self.RefreshWalletShopAllItemData,self) ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_CREDIT_RECHARGE_SHOP_ITEM_BUY_ACK, function(data) --购买商品信息返回 --LogError(deepPrint(data)) if data.error == 0 then --发消息刷新界面 --LogError("====================SC_CREDIT_RECHARGE_SHOP_ITEM_BUY_ACK========error = 0===============") if data.shop_item then ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.WALLETSHOP_SHOWREWARD,data.shop_item.goods_id) self:RefreshWalletShopItemData(data.shop_item) ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.WALLETSHOP_REFRESH,data) end end end) end function WalletShopData:UnRegisterNetEvents() ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_CREDIT_RECHARGE_SHOP_ITEM_BUY_ACK) ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_RUNE_BASE_DATA_NTF) ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_BT_SHOP_INFO_ACK) end function WalletShopData:GetWalletShopData() return self.walletShopData end function WalletShopData:GetWalletShopDataById(id) return self.walletShopData and self.walletShopData[id] end function WalletShopData:GetWalletData() return self.walletData end function WalletShopData:GetCurUseCredit() return self.walletData and self.walletData.use_credit or 0 end function WalletShopData:GetMaxUseCredit() return self.walletData and self.walletData.max_credit or 0 end function WalletShopData:GetCreditLimit() return self.walletData and self.walletData.creditLimit or false end function WalletShopData:GetEndTime() return self.endTime or 0 end function WalletShopData:RefreshWalletData(data) if not self.walletData then self.walletData = {} end if data.rune_base_data then self.walletData.use_credit = data.rune_base_data.used_credit_recharge --每日当前使用额度 self.walletData.max_credit = data.rune_base_data.max_credit_recharge --每日最大额度 self.walletData.creditLimit = data.rune_base_data.credit_recharge_limit --是否无额度无上限 ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.WALLETSHOPCREDIT_REFRESH) end end function WalletShopData:RefreshWalletShopItemData(data) --LogError("============================RefreshWalletShopItemData==================") if not data then return end if not self.walletShopData then self.walletShopData = {} end self.walletShopData[data.goods_id] = data end function WalletShopData:RefreshWalletShopAllItemData(data) --LogError("============================RefreshWalletShopItemData====== r sc============") if not data.goods_list then return end self.endTime = data.end_time ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.WALLETSHOP_ENDTIME_REFRESH) if not self.walletShopData then self.walletShopData = {} end for k, v in pairs(data.goods_list) do self.walletShopData[v.goods_id] = v end ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.WALLETSHOP_REFRESH) end function WalletShopData:SendWalletShopInfoReq() --LogError("============================SendWalletShopInfoReq==== send ==============") ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_BT_SHOP_INFO_REQ, {shop_type = 100}) --充钱钱包商店类型 end function WalletShopData:SendWalletShopItemBuyReq(id,num) ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_CREDIT_RECHARGE_SHOP_ITEM_BUY_REQ, {goods_id = id,count = 1}) end function WalletShopData:Clear() self.walletData = nil self.walletShopData = nil end function WalletShopData:Destroy() if self.Clear then self:Clear() end self:UnRegisterNetEvents() end return WalletShopData