源战役客户端
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

156 řádky
5.7 KiB

před 4 týdny
  1. -- <*
  2. -- @Author: Saber
  3. -- @Description: 招财猫活动controller
  4. -- *>
  5. require("game.fortuneCat.FortuneCatModel")
  6. require("game.fortuneCat.FortuneCatMainView") -- 招财猫活动主界面
  7. require("game.fortuneCat.FortuneCatRecordItem") -- 招财猫活动招财记录节点
  8. require("game.fortuneCat.FortuneCatRollItem") -- 招财猫活动抽奖节点
  9. require("game.fortuneCat.FortuneCatAdTipsView") -- 招财猫活动广告界面
  10. FortuneCatController = FortuneCatController or BaseClass(BaseController, true)
  11. local FortuneCatController = FortuneCatController
  12. function FortuneCatController:__init()
  13. FortuneCatController.Instance = self
  14. self.model = FortuneCatModel:getInstance()
  15. self:AddEvents()
  16. self:RegisterAllProtocal()
  17. end
  18. function FortuneCatController:RegisterAllProtocal( )
  19. self:RegisterProtocal(33219, "handle33219") -- 查询招财猫活动配置数据
  20. self:RegisterProtocal(33220, "handle33220") -- 查询单个招财猫活动信息
  21. self:RegisterProtocal(33221, "handle33221") -- 招财猫招财
  22. self:RegisterProtocal(33222, "handle33222") -- 招财猫招财记录
  23. end
  24. function FortuneCatController:AddEvents()
  25. local function onRequestHandler(...)
  26. local args = {...}
  27. if args[1] == 33220 or args[1] == 33221 or args[1] == 33222 then
  28. self:SendFmtToGame(args[1], "hh", args[2], args[3])
  29. else
  30. self:SendFmtToGame(args[1])
  31. end
  32. end
  33. self.model:Bind(FortuneCatModel.REQUEST_CCMD_EVENT, onRequestHandler)
  34. local function game_start()
  35. self.model:Fire(FortuneCatModel.REQUEST_CCMD_EVENT, 33219)
  36. end
  37. GlobalEventSystem:Bind(EventName.GAME_START, game_start)
  38. local function on_lv_up(lv)
  39. local open_lv = GetModuleOpenLevel(331, 64, true)
  40. if lv == open_lv then -- 活动按钮
  41. self.model:CheckEventOpen()
  42. end
  43. end
  44. RoleManager.Instance.mainRoleInfo:Bind(EventName.CHANGE_LEVEL, on_lv_up)
  45. local function onTaskFinishHandler(taskId)
  46. if taskId == CustomActivityModel.CAT_FOTANA_TASK_ID then
  47. self.model:CheckAdViewOpen()
  48. end
  49. end
  50. GlobalEventSystem:Bind(TaskEvent.ANS_FINISHED_TASK_LIST, onTaskFinishHandler)
  51. local function open_fortune_cat_view(show, sub_type)
  52. if show then
  53. if not sub_type then return end
  54. if not self.fc_cat_view then
  55. self.fc_cat_view = FortuneCatMainView.New()
  56. end
  57. if not self.fc_cat_view:HasOpen() then
  58. self.fc_cat_view:Open(sub_type)
  59. end
  60. else
  61. if self.fc_cat_view then
  62. self.fc_cat_view:Close()
  63. end
  64. end
  65. end
  66. self.model:Bind(FortuneCatModel.OPEN_FORTUNE_CAT_VIEW, open_fortune_cat_view)
  67. local function open_fortune_cat_ad_view(show, sub_type)
  68. if show then
  69. if not sub_type then return end
  70. if self.model.fc_login_ad_view_flag then return end
  71. if not self.fc_cat_ad_view then
  72. self.fc_cat_ad_view = FortuneCatAdTipsView.New()
  73. end
  74. if not self.fc_cat_ad_view:HasOpen() then
  75. self.fc_cat_ad_view:Open(sub_type)
  76. end
  77. else
  78. if self.fc_cat_ad_view then
  79. self.fc_cat_ad_view:Close()
  80. end
  81. end
  82. end
  83. self.model:Bind(FortuneCatModel.OPEN_FORTUNE_CAT_AD_VIEW, open_fortune_cat_ad_view)
  84. -- 监听玩家彩钻是否满足转盘需要
  85. local function check_role_jin()
  86. local function check_role_jin_delay()
  87. self.model:CheckFCAllSubTypeRed()
  88. end
  89. TimeManager.GetInstance():StartTime("FortuneCatController_CheckRoleJin", 1, check_role_jin_delay)
  90. end
  91. RoleManager.Instance.mainRoleInfo:BindOne("jin", check_role_jin)
  92. end
  93. function FortuneCatController:handle33219( )
  94. local vo = SCMD33219.New(true)
  95. self.model:SetFortuneCatConfig(vo)
  96. -- 存在活动配置和活动信息协议的时序问题,所以拿到配置的时候也更新一下按钮打开情况
  97. self.model:CheckEventOpen()
  98. self.model:Fire(FortuneCatModel.UPDATE_FORTUNE_CAT_CONFIG)
  99. end
  100. function FortuneCatController:handle33220( )
  101. local vo = SCMD33220.New(true)
  102. self.model:SetFortuneCatRollTimes(vo)
  103. self.model:CheckFortuneCatRed(vo.sub_type)
  104. self.model:Fire(FortuneCatModel.UPDATE_FORTUNE_CAT_ROLL_TIME, vo.sub_type)
  105. end
  106. function FortuneCatController:handle33221( )
  107. local vo = SCMD33221.New(true)
  108. if vo.res == 1 then
  109. self.model:SetFortuneCatRollResult(vo)
  110. self.model:CheckFortuneCatRed(vo.sub_type)
  111. self.model:Fire(FortuneCatModel.UPDATE_FORTUNE_CAT_RESULT, vo)
  112. local function delay_method( )
  113. if self.fc_cat_view and self.fc_cat_view:HasOpen() then
  114. -- 构造玩家抽奖信息数据
  115. local role_vo = RoleManager.Instance.mainRoleInfo
  116. local info_data = {
  117. role_id = role_vo.role_id,
  118. role_name = role_vo.name,
  119. time = TimeUtil:getServerTime(),
  120. times = vo.times,
  121. sort = vo.sort,
  122. mult = vo.mult,
  123. }
  124. self.model:UpdateFortuneCatRollRecord(vo, info_data)
  125. self.model:Fire(FortuneCatModel.UPDATE_FORTUNE_CAT_ROLL_RECORD, vo.sub_type)
  126. end
  127. end
  128. -- 延时3秒弹出数据
  129. setTimeout(delay_method, FortuneCatModel.AnimTime)
  130. else
  131. ErrorCodeShow(vo.res)
  132. end
  133. end
  134. function FortuneCatController:handle33222( )
  135. local vo = SCMD33222.New(true)
  136. self.model:SetFortuneCatRollRecord(vo)
  137. self.model:Fire(FortuneCatModel.UPDATE_FORTUNE_CAT_ROLL_RECORD, vo.sub_type)
  138. end