源战役客户端
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

319 wiersze
9.5 KiB

4 tygodni temu
  1. require("game.proto.334.Require334")
  2. require("game.sakuraGift.SakuraGiftModel")
  3. require("game.sakuraGift.SakuraGiftConst")
  4. require("game.sakuraGift.view.SakuraGiftView")
  5. require("game.sakuraGift.view.SakuraGiftShopView")
  6. require("game.sakuraGift.view.SakuraGiftShopItem")
  7. require("game.sakuraGift.view.SakuraGiftAwardItem")
  8. require("game.sakuraGift.view.SakuraGiftExchangeView")
  9. require("game.sakuraGift.view.SakuraGiftMessageView")
  10. require("game.sakuraGift.view.SakuraGiftChuanwenItem")
  11. require("game.sakuraGift.view.SakuraGiftRewardView")
  12. require("game.sakuraGift.view.SakuraGiftRewardItem")
  13. require("game.sakuraGift.view.SakuraGiftChuanwenLabel")
  14. SakuraGiftController = SakuraGiftController or BaseClass(BaseController, true)
  15. local SakuraGiftController = SakuraGiftController
  16. function SakuraGiftController:__init()
  17. SakuraGiftController.Instance = self
  18. self.model = SakuraGiftModel:getInstance()
  19. self:AddEvents()
  20. self:RegisterAllProtocal()
  21. end
  22. function SakuraGiftController:__delete()
  23. end
  24. function SakuraGiftController:RegisterAllProtocal( )
  25. local register_cfg = {
  26. [33400] = {
  27. handler = function(self,scmd)
  28. self:Handle33400( scmd )
  29. end,
  30. },
  31. [33401] = {
  32. handler = function(self,scmd)
  33. self:Handle33401( scmd )
  34. end,
  35. },
  36. [33402] = {
  37. handler = function(self,scmd)
  38. self:Handle33402( scmd )
  39. end,
  40. },
  41. [33403] = {
  42. handler = function(self,scmd)
  43. self:Handle33403( scmd )
  44. end,
  45. },
  46. [33404] = {
  47. handler = function(self,scmd)
  48. self:Handle33404( scmd )
  49. end,
  50. },
  51. }
  52. self:RegisterProtocalByCFG(register_cfg)
  53. end
  54. function SakuraGiftController:AddEvents()
  55. local function on_game_start()
  56. self.model:Reset()
  57. end
  58. GlobalEventSystem:Bind(EventName.GAME_START, on_game_start)
  59. local function onRequestProtocal(...)
  60. local args = {...}
  61. if args[1] == 33400 or args[1] == 33403 then
  62. self:SendFmtToGame(args[1], "h", args[2])
  63. elseif args[1] == 33402 then
  64. self:SendFmtToGame(args[1], "hc", args[2], args[3])
  65. elseif args[1] == 33401 then
  66. self:SendFmtToGame(args[1], "hcc", args[2], args[3], args[4])
  67. elseif args[1] == 33404 then
  68. self:SendFmtToGame(args[1], "hih", args[2], args[3], args[4])
  69. end
  70. end
  71. self.model:Bind(SakuraGiftModel.REQUEST_CCMD_EVENT, onRequestProtocal)
  72. local function OPEN_BASE_VIEW( sub_type, is_close )
  73. if is_close then
  74. if self.sakuragiftview then
  75. self.sakuragiftview:Close()
  76. end
  77. return
  78. end
  79. if self.sakuragiftview == nil then
  80. self.sakuragiftview = SakuraGiftView.New()
  81. end
  82. local base_type = CustomActivityModel.CustomActBaseType.SAKURA_GIFT
  83. local sub_type = sub_type or CustomActivityModel:getInstance():getActMinSubType(base_type)
  84. self.cur_sub_type = sub_type
  85. if not self.sakuragiftview:HasOpen() then
  86. self.sakuragiftview:Open(sub_type)
  87. end
  88. end
  89. self.model:Bind(SakuraGiftModel.OPEN_BASE_VIEW, OPEN_BASE_VIEW)
  90. local function OPEN_SHOP_VIEW( sub_type, is_close )
  91. if is_close then
  92. if self.sakuragiftshopview then
  93. self.sakuragiftshopview:Close()
  94. end
  95. return
  96. end
  97. if self.sakuragiftshopview == nil then
  98. self.sakuragiftshopview = SakuraGiftShopView.New()
  99. end
  100. if not self.sakuragiftshopview:HasOpen() then
  101. self.sakuragiftshopview:Open(sub_type)
  102. end
  103. end
  104. self.model:Bind(SakuraGiftModel.OPEN_SHOP_VIEW, OPEN_SHOP_VIEW)
  105. local onSakuraGiftExchangeView = function (data, is_close)--兑换请求界面
  106. if self.SakuraGiftExchangeView == nil then
  107. self.SakuraGiftExchangeView = SakuraGiftExchangeView.New()
  108. end
  109. if self.SakuraGiftExchangeView:HasOpen() and not is_close then
  110. elseif not is_close then
  111. self.SakuraGiftExchangeView:Open(data)
  112. else
  113. self.SakuraGiftExchangeView:Close()
  114. end
  115. end
  116. self.model:Bind(SakuraGiftModel.OPEN_EXCHANGE_REQ_VIEW, onSakuraGiftExchangeView)
  117. local onSakuraGiftRewardView = function (data, is_close)
  118. if self.SakuraGiftRewardView == nil then
  119. self.SakuraGiftRewardView = SakuraGiftRewardView.New()
  120. end
  121. if self.SakuraGiftRewardView:HasOpen() and not is_close then
  122. elseif not is_close then
  123. self.SakuraGiftRewardView:Open(data)
  124. else
  125. self.SakuraGiftRewardView:Close()
  126. end
  127. end
  128. self.model:Bind(SakuraGiftModel.OPEN_REWARD_VIEW, onSakuraGiftRewardView)
  129. -- 上方滚屏
  130. -- local onSakuraGiftMessageView = function (show)
  131. -- if show then
  132. -- if self.SakuraGiftMessageView == nil then
  133. -- self.SakuraGiftMessageView = SakuraGiftMessageView.New()
  134. -- end
  135. -- else
  136. -- if self.SakuraGiftMessageView then
  137. -- self:HideNoticeView(false)
  138. -- self.SakuraGiftMessageView:DeleteMe()
  139. -- self.SakuraGiftMessageView = nil
  140. -- end
  141. -- end
  142. -- end
  143. -- self.model:Bind(SakuraGiftModel.OPEN_MESSAGE_VIEW, onSakuraGiftMessageView)
  144. end
  145. ----------滚屏跑马逻辑-start---------
  146. -- function SakuraGiftController:AppendNoticeMsg( content )
  147. -- if not self.SakuraGiftMessageView then
  148. -- return
  149. -- end
  150. -- self.SakuraGiftMessageView:AppendMessage(content)
  151. -- end
  152. -- function SakuraGiftController:HideNoticeView(bool)
  153. -- if self.SakuraGiftMessageView then
  154. -- self.SakuraGiftMessageView:SetHide(bool)
  155. -- end
  156. -- end
  157. -- function SakuraGiftController:InitMessage( )
  158. -- if self.SakuraGiftMessageView then
  159. -- self.SakuraGiftMessageView:InitMsg()
  160. -- end
  161. -- end
  162. ----------滚屏跑马逻辑-end-----------
  163. --[[############## 基础信息 ##############
  164. protocol=33400
  165. {
  166. c2s{
  167. sub_type :int16 //
  168. }
  169. s2c{
  170. sub_type :int16 //
  171. lucky_value :int32 // ()
  172. use_free_times :int8 // 使
  173. }
  174. }--]]
  175. function SakuraGiftController:Handle33400( scmd )
  176. self.model:SetActInfo(scmd)
  177. self.model:CheckAllRed( scmd.sub_type )
  178. self.model:Fire(SakuraGiftModel.REFRESH_ACT_INFO)
  179. end
  180. --[[############## 抽奖 ##############
  181. protocol=33401
  182. {
  183. c2s{
  184. sub_type :int16 //
  185. type :int8 // 1- 2-
  186. is_auto :int8 //
  187. }
  188. s2c{
  189. errcode :int32 //
  190. sub_type :int16 //
  191. lucky_value :int32 // ()
  192. use_free_times :int8 // 使
  193. reward_list:array{
  194. reward_id :int32 // Id
  195. num :int16 //
  196. }
  197. score :int32 //
  198. }
  199. }
  200. --]]
  201. function SakuraGiftController:Handle33401( scmd )
  202. if scmd.errcode == 1 then
  203. Message.show("操作成功~")
  204. self.model:SetActInfo(scmd)
  205. self.model:CheckAllRed( scmd.sub_type )
  206. self.model:Fire(SakuraGiftModel.REFRESH_ACT_INFO)
  207. self.model:ShowGetRewardView(scmd.reward_list)
  208. self.model:Fire(SakuraGiftModel.REQUEST_CCMD_EVENT,33402, scmd.sub_type, 1)
  209. else
  210. ErrorCodeShow(scmd.errcode)
  211. end
  212. end
  213. --[[############## 记录信息 ##############
  214. protocol=33402
  215. {
  216. c2s{
  217. sub_type :int16 //
  218. log_type :int8 // 1- 2-
  219. }
  220. s2c{
  221. sub_type :int16 //
  222. log_type :int8 // 1- 2-
  223. log_list:array{
  224. name :string
  225. good_type_id :int32 // Id
  226. num :int16 //
  227. time :int32 //
  228. }
  229. }
  230. }--]]
  231. function SakuraGiftController:Handle33402( scmd )
  232. if scmd.sub_type == self.cur_sub_type then -- 全服传闻
  233. local sort_func = function ( a, b )
  234. return a.time < b.time
  235. end
  236. table.sort(scmd.log_list, sort_func)
  237. self.model:InitMessage()
  238. -- local function delay_method( )
  239. local sort_func = function ( a, b )
  240. return a.time > b.time
  241. end
  242. table.sort(scmd.log_list, sort_func)
  243. for k,v in ipairs(scmd.log_list) do
  244. local content = "%s 在%s中祈福得到了%s * %s,实在是福运绵长啊"
  245. local goods_name = GoodsModel:getInstance():getGoodsName(v.good_type_id, true)
  246. content = string.format(content,
  247. HtmlColorTxt( v.name, ColorUtil.YELLOW_DARK),
  248. HtmlColorTxt( "[源樱之礼]", ColorUtil.GREEN_DARK),
  249. goods_name, v.num )
  250. self.model:AppendNoticeMsg( content )
  251. end
  252. self.model:Fire(SakuraGiftModel.UPDATE_CHUANWEN)
  253. -- end
  254. -- setTimeout(delay_method, 3)
  255. end
  256. -- self.model:Fire(SakuraGiftModel.REFRESH_RECORD_INFO, scmd)
  257. end
  258. --积分商城信息
  259. function SakuraGiftController:Handle33403( scmd )
  260. self.model:SetShopInfo(scmd)
  261. self.model:CheckAllRed( scmd.sub_type )
  262. self.model:Fire(SakuraGiftModel.REFRESH_SHOP_INFO)
  263. end
  264. --[[############## 积分商城兑换 ##############
  265. protocol=33404
  266. {
  267. c2s{
  268. sub_type :int16 //
  269. reward_id :int32 // Id(Id)
  270. buy_num :int16 //
  271. }
  272. s2c{
  273. errcode :int32 //
  274. sub_type :int16 //
  275. score :int32 //
  276. //
  277. reward_id :int32 // Id(Id)
  278. times :int16 //
  279. }
  280. }--]]
  281. --积分商城兑换
  282. function SakuraGiftController:Handle33404( scmd )
  283. if scmd.errcode == 1 then
  284. --print('=======Msh:SakuraGiftController.lua[200] ===TABLE====')
  285. --PrintTable(scmd)
  286. Message.show("兑换成功~")
  287. local is_find = self.model:RefreshShopOneInfo(scmd)
  288. --print('=======Msh:SakuraGiftController.lua[204] =======', is_find)
  289. if is_find then
  290. self.model:CheckRedByType(SakuraGiftModelRedType.Exchange, scmd.sub_type)
  291. self.model:Fire(SakuraGiftModel.REFRESH_SHOP_INFO)
  292. else
  293. self.model:Fire(SakuraGiftModel.REQUEST_CCMD_EVENT, 33403, scmd.sub_type)
  294. end
  295. else
  296. ErrorCodeShow(scmd.errcode)
  297. end
  298. end