PageStoreProxy.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. local RemoteProxy = requireProxy("remote/RemoteProxy")
  2. local PageStoreProxy = class("PageStoreProxy", RemoteProxy)
  3. PageStoreProxy.NAME = global.ProxyTable.PageStoreProxy
  4. PageStoreProxy.normalNpcStorePageId = 100
  5. function PageStoreProxy:ctor()
  6. PageStoreProxy.super.ctor(self)
  7. self.pageData = {}
  8. end
  9. function PageStoreProxy:onRegister()
  10. PageStoreProxy.super.onRegister(self)
  11. end
  12. function PageStoreProxy:ResetPageData(page, data)
  13. self.pageData[page] = data
  14. end
  15. function PageStoreProxy:InitPageStoreData()
  16. local initPage = 4
  17. for i = 1, initPage do
  18. self:RequestPageData(i)
  19. end
  20. end
  21. function PageStoreProxy:GetPageData(page)
  22. return self.pageData[page]
  23. end
  24. function PageStoreProxy:RequestPageData(page)
  25. LuaSendMsg(global.MsgType.MSG_CS_REQUEST_DATA_BY_PAGE, page)
  26. end
  27. function PageStoreProxy:RequestBuy(Index, num, reduceCardIndex)
  28. local buyNum = num or 1
  29. local useCardIndex = reduceCardIndex or 0
  30. LuaSendMsg(global.MsgType.MSG_CS_PAGE_STORE_REQUEST_BUY_ITEM, Index, buyNum, useCardIndex)
  31. end
  32. function PageStoreProxy:RequestItemIndexData(index)
  33. LuaSendMsg(global.MsgType.MSG_CS_REQUEST_DATA_BY_INDEX, index)
  34. end
  35. function PageStoreProxy:GetItemDataByStoreIndex(Index)
  36. if not Index then
  37. return nil
  38. end
  39. for _, v in pairs(self.pageData) do
  40. for _, itemData in pairs(v) do
  41. local storeIndex = itemData.Index
  42. if storeIndex == Index then
  43. return itemData
  44. end
  45. end
  46. end
  47. return nil
  48. end
  49. function PageStoreProxy:CheckStoreLimitStatus(Index)
  50. local data = self:GetItemDataByStoreIndex(Index)
  51. if not data then
  52. return false
  53. end
  54. if data.LimitCount and data.LimitCount > 0 and data.LimitType then
  55. local buyCount = data.BuyCount or 0
  56. local leftCount = data.LimitCount - buyCount
  57. return leftCount > 0
  58. else
  59. return true
  60. end
  61. end
  62. function PageStoreProxy:handle_MSG_SC_GOTDATA_BY_PAGE(msg)
  63. local header = msg:GetHeader()
  64. local page = header.recog
  65. local data = ParseRawMsgToJson(msg)
  66. if not page or not data then
  67. return
  68. end
  69. local pageData = {
  70. page = page
  71. }
  72. self:ResetPageData(page, data)
  73. if page == self.normalNpcStorePageId then
  74. -- 如果是100 则是通用NPC商店面板
  75. global.Facade:sendNotification(global.NoticeTable.Layer_NPC_Store_Open, data)
  76. elseif page >= 1000 then
  77. global.Facade:sendNotification(global.NoticeTable.Layer_OriginalSecret_Update, pageData)
  78. else
  79. global.Facade:sendNotification(global.NoticeTable.Layer_PageStore_Refresh, pageData)
  80. end
  81. ssr.ssrBridge:OnStoreDataRefreshByPage(data, page)
  82. end
  83. function PageStoreProxy:RegisterMsgHandler()
  84. PageStoreProxy.super.RegisterMsgHandler(self)
  85. local msgType = global.MsgType
  86. -- 根据页签返回页签数据
  87. LuaRegisterMsgHandler(msgType.MSG_SC_GOTDATA_BY_PAGE, handler(self, self.handle_MSG_SC_GOTDATA_BY_PAGE))
  88. end
  89. return PageStoreProxy