源战役客户端
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.

212 lines
5.1 KiB

  1. TaskBountyRewardView = TaskBountyRewardView or BaseClass(BaseView)
  2. local TaskBountyRewardView = TaskBountyRewardView
  3. function TaskBountyRewardView:__init()
  4. self.base_file = "task"
  5. self.layout_file = "TaskBountyRewardView"
  6. self.layer_name = "Activity"
  7. self.destroy_imm = true
  8. self.use_background = true
  9. self.hide_maincancas = false
  10. self.model = TaskModel:getInstance()
  11. self.time_diff = 10
  12. self.is_set_zdepth = true
  13. -- self.use_local_view = true
  14. self.item_list = {}
  15. self.load_callback = function ()
  16. self:LoadSuccess()
  17. self:InitEvent()
  18. end
  19. self.open_callback = function ()
  20. self:InitView()
  21. end
  22. self.close_callback = function ()
  23. end
  24. self.destroy_callback = function ()
  25. self:Clear()
  26. end
  27. end
  28. function TaskBountyRewardView:Open(circle_num)
  29. self.circle_num = circle_num
  30. BaseView.Open(self)
  31. end
  32. function TaskBountyRewardView:Clear()
  33. if self.update_reward_id then
  34. GlobalEventSystem:UnBind(self.update_reward_id)
  35. self.update_reward_id = nil
  36. end
  37. for i, v in ipairs(self.item_list) do
  38. v:DeleteMe()
  39. v = nil
  40. end
  41. self.item_list = {}
  42. self:CancelTimer()
  43. end
  44. function TaskBountyRewardView:Close()
  45. BaseView.Close(self)
  46. end
  47. function TaskBountyRewardView:InitView()
  48. self:StartTimer()
  49. local info = self.model.circle_cache_reward
  50. if not info then
  51. return
  52. end
  53. local reward_list = {}
  54. for index, vo in ipairs(info.reward) do
  55. table.insert(reward_list, vo)
  56. end
  57. for index, vo in ipairs(info.extra_reward) do
  58. table.insert(reward_list, vo)
  59. end
  60. for i, v in ipairs(reward_list) do
  61. local item = self.item_list[i]
  62. if item == nil then
  63. item = AwardItem.New(self.item_parent)
  64. self.item_list[i] = item
  65. end
  66. item:SetVisible(true)
  67. item:SetItemSize(78, 78)
  68. local goods_id, lock = GoodsModel:getInstance():GetMappingTypeId(v[1], v[2])
  69. item:SetData(goods_id, v[3], nil, nil, lock)
  70. if v.is_vip then
  71. item:SetVipAdditionTip(true)
  72. end
  73. end
  74. for i=#reward_list + 1,#self.item_list do
  75. self.item_list[i]:SetVisible(false)
  76. end
  77. if self.circle_num == 10 then
  78. self.ok_btn_txt.text = "继续任务"
  79. elseif self.circle_num == 20 then
  80. self.ok_btn_txt.text = "确定"
  81. end
  82. end
  83. function TaskBountyRewardView:LoadSuccess()
  84. self.left_img,
  85. self.right_img
  86. = GetChildImages(self.transform, {
  87. "left",
  88. "right",
  89. })
  90. lua_resM:setOutsideImageSprite(self, self.left_img, GameResPath.GetCommonImage("jsui_bg"))
  91. lua_resM:setOutsideImageSprite(self, self.right_img,GameResPath.GetCommonImage("jsui_bg"))
  92. self.cancel_btn,
  93. self.ok_btn = self:GetChildGameObjects({
  94. "CancelBtn",
  95. "OkBtn",
  96. })
  97. self.item_parent = self:GetChildTransforms({
  98. "ItemParent"
  99. })
  100. self.tip_txt,
  101. self.ok_btn_txt = self:GetChildTexts({
  102. "Tip",
  103. "OkBtn/Text",
  104. })
  105. end
  106. function TaskBountyRewardView:InitEvent()
  107. local function onBtnClickHandler(target)
  108. if target == self.cancel_btn then
  109. self:Close()
  110. GlobalEventSystem:Fire(EventName.START_AUTO_DO_TASK,true)
  111. elseif target == self.ok_btn then
  112. if self.circle_num == 10 then
  113. self:Close()
  114. GlobalEventSystem:Fire(EventName.START_AUTO_DO_TASK,true)
  115. elseif self.circle_num == 20 then
  116. self:Close()
  117. self:GoToHook()
  118. end
  119. end
  120. end
  121. AddClickEvent(self.cancel_btn,onBtnClickHandler)
  122. AddClickEvent(self.ok_btn,onBtnClickHandler)
  123. end
  124. function TaskBountyRewardView:GoToHook()
  125. local onHookData = DailyModel:getInstance():GetOnhookConfig()
  126. if onHookData then
  127. local pointList = ErlangParser:GetInstance():Parse(onHookData.xy)
  128. local index = math.random(1, #pointList)
  129. local randomPoint = pointList[index]
  130. local x = tonumber(randomPoint[1])
  131. local y = tonumber(randomPoint[2])
  132. local call_back = function ()
  133. GlobalEventSystem:Fire(EventName.STARTAUTOFIGHT)
  134. end
  135. local findVo = FindVo.New()
  136. findVo.type = FindVo.POINT
  137. findVo.sceneId = tonumber(onHookData.scene_id)
  138. findVo.x = x / SceneObj.LogicRealRatio.x
  139. findVo.y = y / SceneObj.LogicRealRatio.y
  140. findVo.call_back = call_back
  141. findVo.force_change_scene = true
  142. GlobalEventSystem:Fire(EventName.STOPAUTOFIGHT)
  143. GlobalEventSystem:Fire(EventName.FORCE_STOP_DO_TASK)
  144. Scene.Instance:FindElement(findVo)
  145. end
  146. end
  147. function TaskBountyRewardView:CancelTimer()
  148. if self.timer_id then
  149. TimerQuest.CancelQuest(GlobalTimerQuest, self.timer_id)
  150. self.timer_id = nil
  151. end
  152. end
  153. function TaskBountyRewardView:StartTimer()
  154. self:CancelTimer()
  155. local end_time = TimeUtil:getServerTime( ) + self.time_diff
  156. local function onTimer()
  157. local time = end_time - TimeUtil:getServerTime( )
  158. if time > 0 then
  159. if self.circle_num == 10 then
  160. self.tip_txt.text = string.format("%d秒后自动任务",time)
  161. elseif self.circle_num == 20 then
  162. self.tip_txt.text = string.format("%d秒后自动野外挂机",time)
  163. end
  164. else
  165. self:CancelTimer()
  166. if self.circle_num == 10 then
  167. self:Close()
  168. GlobalEventSystem:Fire(EventName.START_AUTO_DO_TASK,true)
  169. elseif self.circle_num == 20 then
  170. self:Close()
  171. self:GoToHook()
  172. end
  173. end
  174. end
  175. onTimer()
  176. self.timer_id = TimerQuest.AddPeriodQuest(GlobalTimerQuest, onTimer,1,-1)
  177. end