GoldBoxProxy.lua 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. local RemoteProxy = requireProxy("remote/RemoteProxy")
  2. local GoldBoxProxy = class("GoldBoxProxy", RemoteProxy)
  3. GoldBoxProxy.NAME = global.ProxyTable.GoldBoxProxy
  4. local cjson = require("cjson")
  5. function GoldBoxProxy:ctor()
  6. GoldBoxProxy.super.ctor(self)
  7. self._CostConfig = {} --消耗数据
  8. self._ItemIndexData = {} --服务器发送的宝箱物品数据
  9. self._ItemData = {} --宝箱物品数据
  10. self._Config = {} --宝箱数据
  11. self._boxStdMode = 1 --宝箱的stdmode
  12. self._TotalopenTime = 1 --总的开启次数
  13. self._rewardIndex = 1 --奖励的index
  14. self._openTime = 0 --开启次数
  15. self._itemShow = {}
  16. self._StdMode = 110
  17. self._SameBoxItem = {} --背包中相同宝箱的数据
  18. self._isHaveOpen = false
  19. self._boxClose = false
  20. self._boxMakeIndex = nil
  21. self._BoxData = {}
  22. end
  23. function GoldBoxProxy:RandomConfig(config )
  24. -- body
  25. local data = {}
  26. local index = 1
  27. while #config~=0 do
  28. local n=math.random(1,#config)
  29. if config[n]~=nil then
  30. if config[n].Index == 0 then
  31. data[0] = config[n]
  32. table.remove(config,n)
  33. else
  34. data[index]=config[n]
  35. table.remove(config,n)
  36. index=index+1
  37. end
  38. end
  39. end
  40. return data
  41. end
  42. --获取开启总次数
  43. function GoldBoxProxy:GetTotalOpenTime( )
  44. return self._TotalopenTime
  45. end
  46. --获取开启次数
  47. function GoldBoxProxy:GetOpenTime( ... )
  48. -- body
  49. return self._openTime
  50. end
  51. --设置开启次数
  52. function GoldBoxProxy:SetOpenTime( openTime )
  53. -- body
  54. self._openTime = openTime
  55. end
  56. --获取物品信息
  57. function GoldBoxProxy:GetItemShow( index )
  58. -- body
  59. -- dump(self._itemShow)
  60. return self._itemShow[index]
  61. end
  62. --获取宝箱中物品的数据
  63. function GoldBoxProxy:GetBoxItem( )
  64. -- body
  65. self._itemShow = {}
  66. local itemData = {}
  67. for i,v in ipairs(self._ItemData) do
  68. local data = string.split(v.reward,"#")
  69. table.insert(itemData,{id =tonumber(data[1]),number = tonumber(data[2]),isJipin = tonumber(data[3]) })
  70. end
  71. self._itemShow = itemData
  72. end
  73. --获取奖励
  74. function GoldBoxProxy:GetRewardIndex( ... )
  75. -- body
  76. return self._rewardIndex
  77. end
  78. function GoldBoxProxy:IsHaveOpen( ... )
  79. -- body
  80. return self._isHaveOpen
  81. end
  82. function GoldBoxProxy:CheckMuchTime( ... )
  83. -- body
  84. if self._TotalopenTime - self._openTime >1 then
  85. return true
  86. else
  87. return false
  88. end
  89. end
  90. function GoldBoxProxy:CheckHaveOpenTime( ... )
  91. -- body
  92. print("可重摇次数 === ",self._TotalopenTime)
  93. print("已重摇次数 === ",self._openTime)
  94. if self._TotalopenTime - self._openTime >=1 then
  95. return true
  96. else
  97. return false
  98. end
  99. end
  100. function GoldBoxProxy:getLeftOpenTime( ... )
  101. -- body
  102. return self._TotalopenTime - self._openTime
  103. end
  104. function GoldBoxProxy:setBoxItemData(data)
  105. self._BoxData = data
  106. end
  107. function GoldBoxProxy:setRefreshBoxItemData(data)
  108. self._newBoxData = data
  109. end
  110. function GoldBoxProxy:RequsetOpenBoxAgain( ... )
  111. LuaSendMsg( global.MsgType.MSG_SC_OPEN_TREASUREBOX_AGAIN)
  112. end
  113. function GoldBoxProxy:RequsetGetBoxReward( ... )
  114. LuaSendMsg( global.MsgType.MSG_SC_TREASUREBOX_REWARD)
  115. end
  116. function GoldBoxProxy:ResponsGetBoxItemInfo( msg )
  117. -- body
  118. print("===========MSG_CS_TREASUREBOX_INFO===============")
  119. local msgheader = msg:GetHeader()
  120. dump(msg:GetHeader())
  121. local data = ParseRawMsgToJson(msg)
  122. if msgheader.param1 == 1 then
  123. -- dump(data)
  124. if self._BoxData and next(self._BoxData)~=nil then
  125. -- dump(self._BoxData)
  126. local bagdata = {
  127. storage = {
  128. MakeIndex = self._BoxData.MakeIndex,
  129. state = 1
  130. }
  131. }
  132. global.Facade:sendNotification(global.NoticeTable.Bag_State_Change, bagdata)
  133. self._BoxData = {}
  134. end
  135. if msgheader.param2 == 0 then
  136. self._TotalopenTime = 1
  137. else
  138. self._TotalopenTime = msgheader.param2
  139. end
  140. self._Config = self:RandomConfig(data)
  141. -- global.Facade:sendNotification(global.NoticeTable.Layer_Treasure_Box_Close)
  142. global.Facade:sendNotification(global.NoticeTable.Layer_Treasure_Box_Refresh,self._Config)
  143. elseif msgheader.param1 == 2 then
  144. if msgheader.recog == 0 then
  145. self._openTime = self._openTime+1
  146. local rewardindex = 1
  147. for k,v in pairs(self._Config) do
  148. if msgheader.param2 == v.Index then
  149. rewardindex = k
  150. end
  151. end
  152. global.Facade:sendNotification(global.NoticeTable.Layer_Gold_Box_Open_Anim,rewardindex)
  153. end
  154. elseif msgheader.param1 == 3 then
  155. if msgheader.recog == 0 then
  156. self._BoxData = {}
  157. self._openTime = 0
  158. global.Facade:sendNotification(global.NoticeTable.Layer_Gold_Box_Close)
  159. if self._newBoxData and next(self._newBoxData) then
  160. self._BoxData = self._newBoxData
  161. self._newBoxData = nil
  162. end
  163. end
  164. end
  165. end
  166. function GoldBoxProxy:onRegister()
  167. GoldBoxProxy.super.RegisterMsgHandler(self)
  168. local msgType = global.MsgType
  169. LuaRegisterMsgHandler( msgType.MSG_CS_TREASUREBOX_INFO,handler( self, self.ResponsGetBoxItemInfo))
  170. end
  171. return GoldBoxProxy