源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

239 lines
7.1 KiB

преди 4 седмици
  1. require("game.proto.422.Require422")
  2. require("game.wardrobe.WardrobeModel")
  3. require("game.wardrobe.WardrobeConst")
  4. require("game.wardrobe.WardrobeMainView")
  5. require("game.wardrobe.WardrobeTotalItem")--总览item
  6. require("game.wardrobe.WardrobeVerTabItem")--左边tab
  7. require("game.wardrobe.WardrobeShopItem")--商店item
  8. require("game.wardrobe.WardrobeShopView")--风采商店
  9. require("game.wardrobe.WardrobeTipsView")--tip界面
  10. WardrobeController = WardrobeController or BaseClass(BaseController, true)
  11. local WardrobeController = WardrobeController
  12. WardrobeController.IsDebug = true
  13. function WardrobeController:__init()
  14. WardrobeController.Instance = self
  15. self.model = WardrobeModel:GetInstance()
  16. self:AddEvents()
  17. self:RegisterAllProtocal()
  18. end
  19. function WardrobeController:__delete()
  20. end
  21. function WardrobeController:RegisterAllProtocal( )
  22. self:RegisterProtocal(42200, "Handle42200")--风采总览
  23. self:RegisterProtocal(42201, "Handle42201")--风采值更新(推送单个类型)
  24. self:RegisterProtocal(42202, "Handle42202")--商城信息
  25. self:RegisterProtocal(42203, "Handle42203")--商城购买
  26. end
  27. function WardrobeController:AddEvents()
  28. local function on_game_start()
  29. self.model:Reset()
  30. end
  31. GlobalEventSystem:Bind(EventName.GAME_START, on_game_start)
  32. local function onRequestHandler(...)
  33. local args = {...}
  34. if args[1] == 42202 then
  35. self:SendFmtToGame(args[1], "c", args[2])
  36. elseif args[1] == 42203 then
  37. self:SendFmtToGame(args[1], "cii", args[2], args[3], args[4])
  38. else
  39. self:SendFmtToGame(args[1])
  40. end
  41. end
  42. self.model:Bind(WardrobeConst.REQ_WARDROBE_SCMD, onRequestHandler)
  43. local function update_red_dot_by_tab_id_func( tab_id )--主要的更新红点方法
  44. if not tab_id then
  45. self.model:IsNeedRedAll()
  46. else
  47. self.model:IsNeedRed(tab_id)
  48. end
  49. local red_dot = self.model:GetWardrobeAllRedDot()
  50. local bool = false
  51. for i,v in pairs(red_dot) do
  52. if v then
  53. bool = true
  54. break
  55. end
  56. end
  57. GlobalEventSystem:Fire(EventName.SHOW_FUNCTION_RED_POINT, 422, bool)
  58. end
  59. self.model:Bind(WardrobeConst.UPDATE_RED_DOT,update_red_dot_by_tab_id_func)
  60. local on_open_main_view = function (index, sub_index, param_list)
  61. if self.wardrobe_main_view == nil then
  62. self.wardrobe_main_view = WardrobeMainView.New()
  63. end
  64. if self.wardrobe_main_view:HasOpen() then
  65. self.wardrobe_main_view:ReOpen(index, sub_index, param_list)
  66. else
  67. self.wardrobe_main_view:Open(index, sub_index, param_list)
  68. end
  69. end
  70. GlobalEventSystem:Bind(WardrobeConst.OPEN_WARDROBE_MAIN_VIEW, on_open_main_view)
  71. local function open_wardrobe_tips_view(show)
  72. if RoleManager.Instance.mainRoleInfo.level < Config.Moduleid[422].open_lv then return end
  73. -- 如果界面还没加载完或者已经存在且在动画中则跳出
  74. if self.tips_view and (not self.tips_view:HasOpen() or self.tips_view.is_animating) then return end
  75. local function close_tips_view()
  76. if self.tips_view:HasOpen() then
  77. self.tips_view:Close()
  78. end
  79. end
  80. if show then
  81. local tip_data = self.model:GetWardrobeTipData()
  82. if tip_data then
  83. if self.tips_view == nil then
  84. self.tips_view = WardrobeTipsView.New()
  85. end
  86. if not self.tips_view:HasOpen() then
  87. self.tips_view:Open(tip_data)
  88. else
  89. self.tips_view:ResetViewInfo(tip_data)
  90. end
  91. else
  92. close_tips_view()
  93. end
  94. else
  95. close_tips_view()
  96. end
  97. end
  98. self.model:Bind(WardrobeConst.OPEN_WARDROBE_TIP_VIEW, open_wardrobe_tips_view)
  99. end
  100. function WardrobeController:OnWardrobeGoodsUpdate( )
  101. self.model:Fire(WardrobeConst.UPDATE_RED_DOT, WardrobeConst.TabId.DRESS)
  102. end
  103. -- ############## 风采总览 ##############
  104. -- protocol=42200
  105. -- {
  106. -- c2s{
  107. -- }
  108. -- s2c{
  109. -- stage :int8 // 阶数
  110. -- sum_wardrobe_value :int32 // 总风采值
  111. -- wardrobe_list:array{
  112. -- type :int8 // 类型
  113. -- wardrobe_value :int32 // 风采值
  114. -- collect :int8 // 收集进度
  115. -- sum_collect :int8 // 总收集量(每类外观配置决定)
  116. -- }
  117. -- }
  118. -- }
  119. function WardrobeController:Handle42200( )
  120. local vo = SCMD42200.New(true)
  121. -- print("HWR:WardrobeController [start:86] vo:", vo)
  122. -- PrintTable(vo)
  123. -- print("HWR:WardrobeController [end]")
  124. self.model:SetWardrobeTotalInfo(vo)
  125. end
  126. -- ############## 风采值更新(推送单个类型) ##############
  127. -- protocol=42201
  128. -- {
  129. -- s2c{
  130. -- // 总风采
  131. -- stage :int8 // 阶数
  132. -- sum_wardrobe_value :int32 // 总风采值
  133. -- // 单个类型进度
  134. -- type :int8 // 类型
  135. -- wardrobe_value :int32 // 风采值
  136. -- collect :int8 // 收集进度
  137. -- sum_collect :int8 // 总收集量(每类外观配置决定)
  138. -- // 新激活外观信息
  139. -- id :int32 // 进阶和伙伴是系统类型,其他是物品Id
  140. -- color :int8 // 品质(进阶和伙伴是阶数,物品是颜色)
  141. -- }
  142. -- }
  143. function WardrobeController:Handle42201( )
  144. local vo = SCMD42201.New(true)
  145. -- print("HWR:WardrobeController [start:157] vo:", vo)
  146. -- PrintTable(vo)
  147. -- print("HWR:WardrobeController [end]")
  148. local need_add_extra = false--是否需要额外加一个商城出现的
  149. -- local last_stage = self.model:GetMyWardrobeStage() --上次阶数
  150. -- if vo.stage > last_stage then
  151. -- local last_shop = 0
  152. -- for i,v in ipairs(Config.Wardrobeopen) do--遍历第一次找上次商城id
  153. -- if last_stage >= v.condition then
  154. -- last_shop = v.store_id
  155. -- end
  156. -- end
  157. -- --遍历第二次找激活的商城
  158. -- local cur_shop = 0
  159. -- for i=last_shop,#Config.Wardrobeopen do
  160. -- if Config.Wardrobeopen[i] then
  161. -- if vo.stage >= Config.Wardrobeopen[i].condition then
  162. -- cur_shop = Config.Wardrobeopen[i].store_id
  163. -- end
  164. -- end
  165. -- end
  166. -- need_add_extra = cur_shop > last_shop
  167. -- end
  168. local up_value = vo.sum_wardrobe_value - self.model:GetMyWardrobeValue()
  169. vo.up_value = up_value
  170. self.model:SetWardrobeTotalOneInfo(vo)
  171. self.model:SetWardrobeTipData(vo)
  172. -- if need_add_extra then
  173. -- vo.is_unlock = true
  174. -- self.model:SetWardrobeTipData(vo)
  175. -- end
  176. end
  177. -- ############## 商城信息 ##############
  178. -- protocol=42202
  179. -- {
  180. -- c2s{
  181. -- store_id :int8 // 货柜层数
  182. -- }
  183. -- s2c{
  184. -- store_id :int8 // 货柜层数
  185. -- goods_list:array{
  186. -- pos :int16 // 商品位置
  187. -- gtype_id :int32 // 商品类型Id
  188. -- num :int32 // 已经购买的次数
  189. -- }
  190. -- }
  191. -- }
  192. function WardrobeController:Handle42202( )
  193. local vo = SCMD42202.New(true)
  194. self.model:SetWardrobeShopInfo(vo)
  195. end
  196. -- ############## 商城购买 ##############
  197. -- protocol=42203
  198. -- {
  199. -- c2s{
  200. -- store_id :int8 // 货柜层数
  201. -- gtype_id :int32 // 商品类型Id
  202. -- buy_times :int32 // 购买个数
  203. -- }
  204. -- s2c{
  205. -- res :int32 // 返回码
  206. -- store_id :int8 // 货柜层数
  207. -- pos :int16 // 商品位置
  208. -- gtype_id :int32 // 商品类型Id
  209. -- num :int32 // 已经购买的次数
  210. -- }
  211. -- }
  212. function WardrobeController:Handle42203( )
  213. local vo = SCMD42203.New(true)
  214. if vo.res == 1 then
  215. Message.show("购买成功")
  216. else
  217. ErrorCodeShow(vo.res)
  218. end
  219. self.model:Fire(WardrobeConst.REQ_WARDROBE_SCMD, 42202, vo.store_id)
  220. end