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

944 line
32 KiB

  1. CapsuleEggView = CapsuleEggView or BaseClass(BaseView)
  2. local CapsuleEggView = CapsuleEggView
  3. function CapsuleEggView:__init()
  4. self.base_file = "capsuleEgg"
  5. self.layout_file = "CapsuleEggView"
  6. self.layer_name = "UI"
  7. self.destroy_imm = true
  8. self.use_background = true
  9. self.change_scene_close = true
  10. self.hide_maincancas = true --是否隐藏主界面
  11. self.append_to_ctl_queue = false --是否要添加进界面堆栈
  12. self.need_show_money = true --是否要显示顶部的金钱栏
  13. self.ten_buff_offer = 100--默认不打折
  14. self.close_fog = true
  15. self.is_set_zdepth = true
  16. self.need_culling_mask_ground = true --打开界面是否需要摄像机剔除ground层
  17. self.blur_activity_bg = true
  18. self.use_show_anim = true
  19. self.use_hide_anim = true
  20. self:AddPreLoadList("capsuleEgg", {"CapsuleEggRecordItem"})
  21. self.mainVo = RoleManager.Instance.mainRoleInfo
  22. self.model = CapsuleEggModel:getInstance()
  23. self.reward_item_list = {}
  24. self.cache_record_list = {} -- 当前页签的节点数据比上个页签少的时候,把多余的节点存进来
  25. self.show_item_list = {}
  26. self.label_list = {}
  27. self.current_pool_type = nil
  28. self.last_draw_time_1 = 0
  29. self.last_draw_time_10 = 0
  30. self.last_draw_time_50 = 0
  31. self.load_callback = function ()
  32. self:LoadSuccess()
  33. self:AddEvent()
  34. end
  35. self.open_callback = function ( )
  36. self:OpenSuccess()
  37. end
  38. self.close_win_callback = function ( )
  39. self:Close()
  40. end
  41. self.destroy_callback = function ( )
  42. self:DestroySuccess()
  43. end
  44. end
  45. function CapsuleEggView:Open(index)
  46. self.current_pool_type = index or CapsuleEggConst.PoolType.Dragon
  47. BaseView.Open(self)
  48. end
  49. function CapsuleEggView:LoadSuccess()
  50. local nodes = {
  51. "bg:raw","titleImg:img", "sloganImg:img",
  52. "costIcon3:img", "costIcon1:img", "costIcon2:img", --花费货币图标
  53. "costPrice1:tmp", "costPrice3:tmp", "costPrice2:tmp",
  54. "closeBtn:obj",
  55. --奖品栏
  56. "awardCon/award7", "awardCon/award3", "awardCon/award5", "awardCon/award2", "awardCon/award8",
  57. "awardCon/award1", "awardCon/award9", "awardCon/award4", "awardCon/award6", "awardCon/award10",
  58. "drawBtn_1:obj", "drawBtn_10:obj", "drawBtn_50:obj", --抽奖按钮
  59. "recordCon/recordScrollView/Viewport/Content", "recordCon/recordScrollView:obj",
  60. "recordCon/recordBg:img",
  61. "countDown:tmp",--免费倒计时
  62. "drawBtn_1/drawBtnText:tmp",
  63. "drawBtn_1/drawRed1:obj", "drawBtn_50/drawRed50:obj", "drawBtn_10/drawRed10:obj",
  64. "helpBtn:obj", "probBtn:obj",
  65. "rewardBtn:obj",
  66. "rewardBtn/rewardRed:obj",
  67. "recordCon",
  68. "recordCon/recordTips:tmp",
  69. "awardCon/award_scroll/Viewport/award_con",
  70. "awardCon/award_scroll",
  71. "rewardcountDown:tmp",
  72. "con_money:obj",
  73. --打折BUFF节点
  74. "tenBuffText:tmp", "fiftyBuffText:tmp", "costPriceOfferLine3:obj", "costPriceOffer3:tmp", "costPriceOfferLine2:obj", "costPriceOffer2:tmp",
  75. --龙神常驻BUFF节点
  76. "buffBtn:obj:img", "buffTimeText:tmp", "buffTipImg:obj",
  77. --不足十连提示气泡
  78. "tenTips:obj", "tenTips/tenTipsGetBtn:obj", "tenTips/tenTipsLeftNum:tmp",
  79. "rewardPreviewBtn:obj",
  80. --幸运值
  81. "luckyCon/luckyProgressLb:tmp", "luckyCon/luckyAdditionLb:tmp", "luckyCon/luckySlider:img",
  82. }
  83. self:GetChildren(nodes)
  84. self.reward_con_list = {}
  85. for i=1,10 do
  86. self.reward_con_list[i] = self["award"..i]
  87. end
  88. lua_resM:setOutsideRawImage(self,self.bg_raw,GameResPath.GetViewBigBg("capsule_egg_bg_1280_720"))
  89. -- lua_resM:setOutsideImageSprite(self, self.recordBg_img, GameResPath.GetCapsuleEggRes("capsule_egg_record_bg"))
  90. SetSizeDelta(self.transform, ScreenWidth, ScreenHeight)
  91. self:SetIpxMode()
  92. local function bg_back_func( ... )
  93. if self.background_wnd and self.background_wnd:GetComponent("RawImageExtend") then
  94. self:MoveUIToBack(self.background_wnd:GetComponent("RawImageExtend"))
  95. end
  96. self:MoveUIToBack(self.bg_raw)
  97. end
  98. if self.background_wnd then
  99. bg_back_func()
  100. else
  101. self.bg_back_func = bg_back_func
  102. end
  103. if not self.money_view then
  104. self.money_view = UIMoneyView.New(self.con_money)
  105. self.money_view:SetPosition(0,0)
  106. self.money_view:SetData()
  107. self.money_view:ChangeShowFlag("capsuleegg", 102305)
  108. end
  109. end
  110. function CapsuleEggView:AddEvent()
  111. local on_click = function ( click_obj )
  112. if self.closeBtn_obj == click_obj then--关闭界面
  113. self:Close()
  114. elseif self.rewardBtn_obj == click_obj then --奖励预览
  115. self.model:Fire(CapsuleEggConst.OPEN_CAPSULE_EGG_REWARD_VIEW, current_pool_type)
  116. elseif self.drawBtn_1_obj == click_obj then--单抽
  117. CustomActivityModel:getInstance():SetGoodsCanFly(false)
  118. if TimeUtil:getServerTimeMs()/1000 - self.last_draw_time_1 > 1 then
  119. self.last_draw_time_1 = TimeUtil:getServerTimeMs()/1000
  120. self:StartDraw(1)
  121. end
  122. elseif self.drawBtn_10_obj == click_obj then--十连
  123. CustomActivityModel:getInstance():SetGoodsCanFly(false)
  124. if TimeUtil:getServerTimeMs()/1000 - self.last_draw_time_10 > 1 then
  125. self.last_draw_time_10 = TimeUtil:getServerTimeMs()/1000
  126. self:StartDraw(10)
  127. end
  128. elseif self.drawBtn_50_obj == click_obj then--五十连
  129. if TimeUtil:getServerTimeMs()/1000 - self.last_draw_time_50 > 1 then
  130. self.last_draw_time_50 = TimeUtil:getServerTimeMs()/1000
  131. self:StartDraw(50)
  132. end
  133. elseif self.helpBtn_obj == click_obj then
  134. EventSystem.Fire(GlobalEventSystem,EventName.OPEN_INSTRUCTION_VIEW, 17000)
  135. elseif self.probBtn_obj == click_obj then
  136. Message.show("概率公式待完善")
  137. elseif self.tenTipsGetBtn_obj == click_obj then
  138. UIToolTipMgr:getInstance():AppendGoodsTips(102305, nil, nil,nil,nil,nil,nil,true,true)
  139. elseif self.rewardPreviewBtn_obj == click_obj then
  140. self.model:Fire(CapsuleEggConst.OPEN_CAPSULE_EGG_REWARD_PRE_VIEW,self.current_pool_type)
  141. elseif self.buffBtn_obj == click_obj then--龙神常驻BUFF按钮
  142. local buff_kind = OperateActivityModel.MaterialSubmitBuffKind.EGG_LUCKY_NUM --触发加成后,<color@1>龙神宝库</color>前2次10连抽享受八折优惠(十连券不计入)
  143. local buff_cfg,buff_info,dot = OperateActivityModel:getInstance():GetMaterialBuffInfoByKind(buff_kind)
  144. if buff_cfg and buff_info then
  145. local abs_pos = click_obj.transform:TransformPoint(Vector3.zero)
  146. local sub_type = CustomActivityModel:getInstance():getActMinSubType(CustomActivityModel.CustomActBaseType.MATERIAL_SUBMIT)
  147. local act_list = CustomActivityModel:getInstance():getActList(CustomActivityModel.CustomActBaseType.MATERIAL_SUBMIT, sub_type)
  148. if act_list then
  149. local buff_data = nil
  150. for k,v in pairs(act_list.condition_list) do--[{role_lv,80},{sub,1},{cost,30},{group,5}]
  151. if v[1] == "suit" then--全服进度套件ID
  152. buff_data = OperateActivityModel:getInstance():GetMaterialSubmitServerCfg(tonumber(v[2]),dot)
  153. break
  154. end
  155. end
  156. if buff_data then
  157. local data = {
  158. sub_type = sub_type,
  159. buff_data = buff_data,
  160. pos_x = abs_pos.x,
  161. pos_y = abs_pos.y,
  162. is_outside = true,
  163. }
  164. OperateActivityModel:getInstance():Fire(OperateActivityModel.OPEN_MATERIAL_SUBMIT_BUFF_VIEW,data)
  165. end
  166. end
  167. end
  168. end
  169. end
  170. AddClickEvent(self.closeBtn_obj, on_click)
  171. AddClickEvent(self.drawBtn_1_obj, on_click)
  172. AddClickEvent(self.drawBtn_10_obj, on_click)
  173. AddClickEvent(self.drawBtn_50_obj, on_click)
  174. AddClickEvent(self.helpBtn_obj, on_click)
  175. AddClickEvent(self.probBtn_obj, on_click)
  176. AddClickEvent(self.rewardBtn_obj, on_click)
  177. AddClickEvent(self.tenTipsGetBtn_obj, on_click)
  178. AddClickEvent(self.rewardPreviewBtn_obj, on_click)
  179. AddClickEvent(self.buffBtn_obj, on_click)
  180. --刷新倒计时
  181. local function on_update_count_down(pool_type)
  182. if pool_type == self.current_pool_type then
  183. self:UpdataFreeTimeInfo()
  184. end
  185. end
  186. self:BindEvent(self.model,CapsuleEggConst.UPDATE_CAPSULE_EGG_FREE_COUNT_DOWN,on_update_count_down)
  187. --刷新全服记录
  188. local function on_update_record(pool_type)
  189. if pool_type == self.current_pool_type then
  190. self:UpdateASRecord()
  191. end
  192. end
  193. self:BindEvent(self.model,CapsuleEggConst.UPDATE_SERVER_RECORD,on_update_record)
  194. local function on_ans_update_red_dot()
  195. self:UpdateRed()
  196. self:UpdateCost()
  197. end
  198. self:BindEvent(self.model, CapsuleEggConst.ANS_UPDATE_RED_DOT, on_ans_update_red_dot)
  199. local function on_goods_num_update()
  200. self:UpdateCost()
  201. self:UpdateTenTipsShow()
  202. end
  203. self:BindEvent(self.model, CapsuleEggConst.UPDATE_CPASULE_EGG_GOODS_NUM, on_goods_num_update)
  204. local function updata_buff_state(id)
  205. if id == KfActivityModel.TabID.MaterialSubmit and self.is_loaded then
  206. self:UpdateCost()
  207. end
  208. end
  209. self:BindEvent(KfActivityModel:getInstance(), KfActivityModel.ANS_UPDATE_VIEW, updata_buff_state)
  210. local function onOrientationChange()
  211. self:SetIpxMode()
  212. end
  213. self:BindEvent(GlobalEventSystem, EventName.ORIENTATION_DID_CHANGE, onOrientationChange)
  214. local function on_update_lucky_num()
  215. if not self.is_loaded then return end
  216. if self._use_delete_method then return end
  217. self:UpdateLuckyCon()
  218. end
  219. self:BindEvent(self.model, CapsuleEggConst.UPDATE_CAPSULE_SERVER_LUCKY, on_update_lucky_num)
  220. end
  221. function CapsuleEggView:SetIpxMode( )
  222. if ClientConfig.iphone_x_model then
  223. self.closeBtn.anchoredPosition = Vector2(-8-ClientConfig.iphone_x_offset_right, 335)
  224. self.titleImg.anchoredPosition = Vector2(-48+ClientConfig.iphone_x_offset_left, 306)
  225. -- self.recordCon.anchoredPosition = Vector2(0+ClientConfig.iphone_x_offset_left, -278)
  226. -- self.rewardBtn.anchoredPosition = Vector2(-101-ClientConfig.iphone_x_offset_right, -280)
  227. -- self.rewardcountDown.anchoredPosition = Vector2(-85-ClientConfig.iphone_x_offset_right, -326)
  228. end
  229. end
  230. function CapsuleEggView:SetJinValue()
  231. if self.is_loaded then
  232. self.num_1_tmp.text = WordManager:ConvertNum(self.mainVo.jin)
  233. end
  234. end
  235. function CapsuleEggView:OpenSuccess()
  236. self:UpdateRed()
  237. self:SwitchTab(self.current_pool_type)
  238. end
  239. function CapsuleEggView:SwitchTab( index )
  240. -- if index == self.current_pool_type then return end
  241. self.current_pool_type = index
  242. self.model:Fire(CapsuleEggConst.REQUEST_CCMD_EVENT,17000,self.current_pool_type)
  243. self.model:Fire(CapsuleEggConst.REQUEST_CCMD_EVENT,17001,self.current_pool_type)
  244. lua_resM:setOutsideImageSprite(self, self.titleImg_img, GameResPath.GetCapsuleEggRes("capsule_egg_draw_type_title_"..self.current_pool_type),true)
  245. lua_resM:setOutsideImageSprite(self, self.sloganImg_img, GameResPath.GetCapsuleEggRes("capsule_egg_slogan_"..self.current_pool_type),true)
  246. self:UpdateRewardCon()
  247. self:UpdateASRecord()
  248. self:UpdataFreeTimeInfo()
  249. self:UpdateCost()
  250. self:UpdateResetTime()
  251. self:UpdateLuckyCon()
  252. self:UpdateTenTipsShow()
  253. end
  254. --全服概率展示
  255. function CapsuleEggView:UpdateLuckyCon( )
  256. local server_lucky = self.model:GetServerlucky(self.current_pool_type)
  257. if self.have_act_buff_lucky_num then
  258. server_lucky = 999
  259. end
  260. local max_server = 999
  261. self.luckyProgressLb_tmp.text = server_lucky.."/"..max_server
  262. self.luckySlider_img.fillAmount = server_lucky/max_server
  263. local cfg = self.model.capsule_egg_kv_cfg["server_lucky_value"]
  264. if cfg then
  265. local lucky_addition_list = stringtotable(cfg.value)
  266. local lucky_addition = lucky_addition_list[1][2]
  267. for i,v in ipairs(lucky_addition_list) do
  268. if server_lucky >= v[1] then
  269. lucky_addition = v[2]
  270. end
  271. end
  272. self.luckyAdditionLb_tmp.text = "+"..lucky_addition.."%"
  273. end
  274. end
  275. --显示奖品
  276. function CapsuleEggView:UpdateRewardCon( )
  277. local reward_cfg = self.model:GetRewardCfg(self.current_pool_type)
  278. for k,v in pairs(self.reward_item_list) do
  279. v:SetVisible(false)
  280. end
  281. for i=1,10 do
  282. local item = self.reward_item_list[i]
  283. if not item then
  284. -- item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.reward_con_list[i])
  285. item = CapsuleEggShowAwardItem.New(self.reward_con_list[i])
  286. self.reward_item_list[i] = item
  287. end
  288. local award_item_size = CapsuleEggConst.AwardItemSize[i]
  289. -- item:SetItemSize(award_item_size, award_item_size)
  290. item:SetVisible(true)
  291. local goods_type_id = reward_cfg[i][2]
  292. item:SetData(goods_type_id,i)
  293. end
  294. local sub_reward_cfg = {}
  295. for i,v in ipairs(reward_cfg) do
  296. if i > 10 then
  297. table.insert(sub_reward_cfg, v)
  298. end
  299. end
  300. -- for i,v in ipairs(self.show_item_list) do
  301. -- v:SetVisible(false)
  302. -- end
  303. -- for i,v in ipairs(sub_reward_cfg) do
  304. -- local item = self.show_item_list[i]
  305. -- if not item then
  306. -- item = CapsuleEggShowAwardItemTwo.New(self.award_con, nil, self.layer_name)
  307. -- self.show_item_list[i] = item
  308. -- item:SetAnchoredPosition((70 + 18) * (i - 1), 0 )
  309. -- end
  310. -- item:SetVisible(true)
  311. -- item:SetData(v[2])
  312. -- end
  313. -- SetSizeDelta(self.award_con, #sub_reward_cfg * (70 + 18), 84)
  314. end
  315. --刷新全服记录
  316. function CapsuleEggView:UpdateASRecord( )
  317. local record_list = self.model:GetAllRecordList(self.current_pool_type)
  318. local x1 = self.model:GetStickRecordList(self.current_pool_type)
  319. local x2 = self.model:GetNormalRecordList(self.current_pool_type)
  320. -- 创建的时候要暂停动画
  321. self:StopTextAction()
  322. local del_num = 0
  323. for k = #self.cache_record_list, 1, -1 do
  324. self.label_list[#self.label_list+1] = table.remove(self.cache_record_list, k)
  325. end
  326. for k,v in pairs(self.label_list) do
  327. v:SetVisible(false)
  328. end
  329. if #record_list == 0 then
  330. self.recordTips_tmp.text = "暂无全服记录"
  331. self.recordScrollView_obj:SetActive(false)
  332. else
  333. self.recordTips_tmp.text = ""
  334. self.recordScrollView_obj:SetActive(true)
  335. end
  336. local node_height = self.recordScrollView.sizeDelta.y
  337. local height = 0
  338. local item
  339. self.record_count = 0
  340. for k, v in ipairs(record_list) do
  341. if k > self.model.max_record_count then
  342. break
  343. end
  344. item = self.label_list[k]
  345. if not item then
  346. item = CapsuleEggRecordItem.New(self.Content)
  347. self.label_list[k] = item
  348. end
  349. item:SetAnchoredPosition(5, -height)
  350. item:SetVisible(true)
  351. height = height + item:SetData(v)
  352. self.record_count = self.record_count + 1
  353. end
  354. if self.record_count < #self.label_list then
  355. for i = #self.label_list, self.record_count + 1, -1 do
  356. self.cache_record_list[#self.cache_record_list+1] = table.remove(self.label_list, i)
  357. end
  358. end
  359. SetSizeDeltaY(self.Content, height)
  360. if height > node_height then
  361. self:StartTextAction()
  362. end
  363. end
  364. function CapsuleEggView:StartTextAction()--开始轮播动画
  365. self:StopTextAction()
  366. local time = 1
  367. local function func()
  368. self:UpdateTextPos()
  369. self:Movetext()
  370. end
  371. self.time_id = GlobalTimerQuest:AddPeriodQuest(func,time,-1)
  372. end
  373. function CapsuleEggView:StopTextAction()
  374. if self.time_id then
  375. GlobalTimerQuest:CancelQuest(self.time_id)
  376. self.time_id = nil
  377. end
  378. self:StopMove()
  379. end
  380. function CapsuleEggView:Movetext()
  381. local text = self.label_list[1]
  382. local move_height = text:GetAnchoredPosition().y
  383. move_height = move_height > 0 and 0 or move_height
  384. for k,text in pairs(self.label_list) do
  385. text:StartAction(move_height)
  386. end
  387. end
  388. function CapsuleEggView:StopMove()
  389. for k,text in pairs(self.label_list) do
  390. text:StopAction()
  391. end
  392. end
  393. function CapsuleEggView:UpdateTextPos()
  394. local delete_index={}
  395. local height = 0
  396. for i=1,self.record_count do
  397. local text = self.label_list[i]
  398. if text then
  399. local vis = text:GetVisible()
  400. local h = text:GetRecordHeight()
  401. local y = text:GetAnchoredPosition().y
  402. height = height + (vis and h or 0)
  403. if y + h > 40 and vis then
  404. table.insert(delete_index,i)
  405. end
  406. end
  407. end
  408. local del_num=0
  409. local t = {}
  410. for i,v in ipairs(delete_index) do
  411. local index= v-del_num
  412. local text = table.remove(self.label_list,index)
  413. t[#t+1] = text
  414. del_num=del_num+1
  415. end
  416. for i=1,#t do
  417. local text = t[i]
  418. text:SetAnchoredPosition(5,-height)
  419. table.insert(self.label_list , text)
  420. end
  421. end
  422. --刷新免费抽奖时间展示
  423. function CapsuleEggView:UpdataFreeTimeInfo()
  424. local next_free_draw = self.model:GetNextFreeDrawTimeByPoolType(self.current_pool_type)
  425. if next_free_draw ~= 0 and self.model:GetFreeDrawTimesByPoolType(self.current_pool_type) == 0 then
  426. local time = next_free_draw - TimeUtil:getServerTime()
  427. self.drawRed1_obj:SetActive(time <= 0)
  428. self:UpdateFreeOneLuck()
  429. else
  430. GlobalTimerQuest:CancelQuest(self.count_down_timer_id)
  431. self.count_down_timer_id = nil
  432. self.drawRed1_obj:SetActive(true)
  433. self.drawBtnText_tmp.text = "本次免费"
  434. self.countDown_tmp.text = ""
  435. end
  436. end
  437. function CapsuleEggView:UpdateFreeOneLuck( )--更新免费次数剩余时间
  438. local have_time = self.model:GetNextFreeDrawTimeByPoolType(self.current_pool_type)-TimeUtil:getServerTime()
  439. self.countDown_tmp.text = ""
  440. GlobalTimerQuest:CancelQuest(self.count_down_timer_id)
  441. self.count_down_timer_id = nil
  442. if have_time > 0 then
  443. self.drawRed1_obj:SetActive(false)
  444. local function onTimer()
  445. have_time = have_time - 1
  446. if have_time > 0 then
  447. self.countDown_tmp.text = string.format("%s 后免费",TimeUtil:timeConvert13(have_time))
  448. self.drawBtnText_tmp.text = "寻宝 1 次"
  449. else
  450. GlobalTimerQuest:CancelQuest(self.count_down_timer_id)
  451. self.count_down_timer_id = nil
  452. self.countDown_tmp.text = ""
  453. self.drawRed1_obj:SetActive(true)
  454. self.drawBtnText_tmp.text = "本次免费"
  455. --请求协议刷新一次信息
  456. self.model:Fire(CapsuleEggConst.REQUEST_CCMD_EVENT,17000,self.current_pool_type)
  457. end
  458. end
  459. onTimer()
  460. if not self.count_down_timer_id then
  461. self.count_down_timer_id = GlobalTimerQuest:AddPeriodQuest(onTimer, 1, -1)
  462. end
  463. self.drawRed1_obj:SetActive(false)
  464. self.drawBtnText_tmp.text = "寻宝 1 次"
  465. else
  466. self.drawRed1_obj:SetActive(true)
  467. self.drawBtnText_tmp.text = "本次免费"
  468. end
  469. end
  470. --开始扭蛋
  471. function CapsuleEggView:StartDraw(times)
  472. local ticket_num_list = self.model:GetCostTicketNumList()
  473. local price_asset, price_icon = WordManager:GetCommonMoneyIcon(1)
  474. local cost_price = 0
  475. local tickets_goods_type_id = 102305
  476. if self.current_pool_type == 1 then
  477. tickets_goods_type_id = 102305
  478. elseif self.current_pool_type == 2 then
  479. tickets_goods_type_id = 102308
  480. elseif self.current_pool_type == 3 then
  481. tickets_goods_type_id = 102311
  482. end
  483. local tickets_price = Config.Goodsprice[tickets_goods_type_id].price
  484. if times == 1 then
  485. if self.model:CanFreeDraw(self.current_pool_type) then--免费抽
  486. self.model:Fire(CapsuleEggConst.REQUEST_CCMD_EVENT,17003,self.current_pool_type,times,1)
  487. return
  488. else
  489. if ticket_num_list[self.current_pool_type][1] >= 1 then--有单抽券直接抽
  490. self.model:Fire(CapsuleEggConst.REQUEST_CCMD_EVENT,17003,self.current_pool_type,times,0)
  491. return
  492. else--补齐
  493. cost_price = tickets_price
  494. end
  495. end
  496. elseif times == 10 then
  497. if ticket_num_list[self.current_pool_type][2] >= 1 then
  498. self.model:Fire(CapsuleEggConst.REQUEST_CCMD_EVENT,17003,self.current_pool_type,times,0)
  499. return
  500. else
  501. local ten_need_num = math.floor(self.ten_cost_num*self.ten_buff_offer/100 + 0.5)--折扣完后要四舍五入
  502. if ticket_num_list[self.current_pool_type][1] >= ten_need_num then
  503. self.model:Fire(CapsuleEggConst.REQUEST_CCMD_EVENT,17003,self.current_pool_type,times,0)
  504. return
  505. else
  506. cost_price = (ten_need_num -ticket_num_list[self.current_pool_type][1])*tickets_price
  507. end
  508. end
  509. elseif times == 50 then
  510. if ticket_num_list[self.current_pool_type][3] >= 1 then
  511. self.model:Fire(CapsuleEggConst.REQUEST_CCMD_EVENT,17003,self.current_pool_type,times,0)
  512. return
  513. else
  514. local fifty_need_num = math.floor(self.fifty_cost_num*self.fifty_buff_offer/100 + 0.5)--折扣完后要四舍五入
  515. if ticket_num_list[self.current_pool_type][1] >= fifty_need_num then
  516. self.model:Fire(CapsuleEggConst.REQUEST_CCMD_EVENT,17003,self.current_pool_type,times,0)
  517. return
  518. else
  519. cost_price = (fifty_need_num-ticket_num_list[self.current_pool_type][1])*tickets_price
  520. end
  521. end
  522. end
  523. local function ok_callback( ... )
  524. self.model:Fire(CapsuleEggConst.REQUEST_CCMD_EVENT,17003,self.current_pool_type,times,0)
  525. end
  526. local function toggle_function( flag )
  527. self.model._again_draw_no_double_check = flag
  528. end
  529. local function use_function( toggle_tip_data,call_fun_sum )
  530. if not self.model._again_draw_no_double_check and cost_price ~= 0 then
  531. GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data)
  532. else
  533. call_fun_sum()
  534. end
  535. end
  536. local buy_tip_data = {
  537. gold_type = 1,--货币类型
  538. cost_price = cost_price,--消耗金额
  539. ok_callback = ok_callback,--成功
  540. toggle_function = toggle_function,--多选
  541. togglePriceStr = string.format("<color=#fdffc2>%s</color> 补齐所需的单抽券",cost_price),--提示语
  542. use_function = use_function,--最终调用
  543. }
  544. CustomActivityModel:getInstance():BuyTips(buy_tip_data)
  545. end
  546. function CapsuleEggView:UpdateCost( )
  547. local cost_ticket_num_list = self.model:GetCostTicketNumList()
  548. lua_resM:setOutsideImageSprite(self, self.costIcon1_img, GameResPath.GetGoodsIcon(self.model:GetCostTicketGTypeId(self.current_pool_type,1)),true)
  549. if cost_ticket_num_list[self.current_pool_type][1] == 0 then
  550. self.costPrice1_tmp.text = string.format("<%s>%s</color>/1", ColorUtil.RED_DARK, cost_ticket_num_list[self.current_pool_type][1])
  551. else
  552. self.costPrice1_tmp.text = string.format("<%s>%s</color>/1", ColorUtil.GREEN_DARK, cost_ticket_num_list[self.current_pool_type][1])
  553. end
  554. local buff_kind = OperateActivityModel.MaterialSubmitBuffKind.LUCKY_OFFER --是否存在活动加成buff 挑战次数+1
  555. local buff_cfg,buff_info = OperateActivityModel:getInstance():GetMaterialBuffInfoByKind(buff_kind)
  556. -- buff_cfg = {discount = 80,data = 1}
  557. -- buff_info = {etime = TimeUtil:getServerTime( )+300,used = {{kdata = 10,vdata=0}}}
  558. self.ten_cost_num = 9
  559. local have_time = buff_cfg and buff_cfg.data or 0
  560. local show_offer_obj = false
  561. self.ten_buff_offer = 100
  562. local ten_buff_sum_time = 0
  563. if cost_ticket_num_list[self.current_pool_type][2] > 0 then--有十连券
  564. lua_resM:setOutsideImageSprite(self, self.costIcon2_img, GameResPath.GetGoodsIcon(self.model:GetCostTicketGTypeId(self.current_pool_type,10)),true)
  565. self.ten_cost_num = 1
  566. if cost_ticket_num_list[self.current_pool_type][2] < 1 then
  567. self.costPrice2_tmp.text = string.format("<%s>%s</color>/1", ColorUtil.RED_DARK, cost_ticket_num_list[self.current_pool_type][2])
  568. else
  569. self.costPrice2_tmp.text = string.format("<%s>%s</color>/1", ColorUtil.GREEN_DARK, cost_ticket_num_list[self.current_pool_type][2])
  570. end
  571. else
  572. if buff_cfg and buff_info then
  573. local sec = buff_info.etime - TimeUtil:getServerTime( )
  574. if sec > 0 then
  575. self:ActBuffTimeLate(sec)
  576. for k,v in pairs(buff_info.used) do
  577. if v.kdata == 10 then--十连还有次数
  578. have_time = have_time - v.vdata
  579. break
  580. end
  581. end
  582. if have_time > 0 then
  583. show_offer_obj = true
  584. self.ten_buff_offer = buff_cfg.discount
  585. end
  586. end
  587. end
  588. lua_resM:setOutsideImageSprite(self, self.costIcon2_img, GameResPath.GetGoodsIcon(self.model:GetCostTicketGTypeId(self.current_pool_type,1)),true)
  589. local lucky_num = show_offer_obj and math.floor(self.ten_cost_num*self.ten_buff_offer/100 + 0.5) or 9
  590. if cost_ticket_num_list[self.current_pool_type][1] < lucky_num then
  591. self.costPrice2_tmp.text = string.format("<%s>%s</color>/%s", ColorUtil.RED_DARK, cost_ticket_num_list[self.current_pool_type][1], lucky_num)
  592. else
  593. self.costPrice2_tmp.text = string.format("<%s>%s</color>/%s", ColorUtil.GREEN_DARK, cost_ticket_num_list[self.current_pool_type][1], lucky_num)
  594. end
  595. end
  596. self.costPriceOffer2_tmp.text = show_offer_obj and self.ten_cost_num or ""
  597. self.costPriceOfferLine2_obj:SetActive(show_offer_obj)
  598. self.tenBuffText_tmp.text = show_offer_obj and string.format("限时%s%%优惠:%s/%s",self.ten_buff_offer,have_time,buff_cfg.data) or ""
  599. local btn2_red_condition_1 = self.model:GetDrawBtnRed(self.current_pool_type,2)--有十连券
  600. local need_one_tickets_can_red = show_offer_obj and math.floor(self.ten_cost_num*self.ten_buff_offer/100 + 0.5) or 9
  601. local btn2_red_condition_2 = cost_ticket_num_list[self.current_pool_type][1] >= need_one_tickets_can_red
  602. local btn2_red = btn2_red_condition_1 or btn2_red_condition_2
  603. self.drawRed10_obj:SetActive(btn2_red)
  604. self.show_offer_obj = show_offer_obj
  605. self.fifty_cost_num = 45
  606. self.fifty_buff_offer = 100
  607. if cost_ticket_num_list[self.current_pool_type][3] > 0 then--有五十连券
  608. lua_resM:setOutsideImageSprite(self, self.costIcon3_img, GameResPath.GetGoodsIcon(self.model:GetCostTicketGTypeId(self.current_pool_type,50)),true)
  609. if cost_ticket_num_list[self.current_pool_type][3] < 1 then
  610. self.costPrice3_tmp.text = string.format("<%s>%s</color>/1", ColorUtil.RED_DARK, cost_ticket_num_list[self.current_pool_type][3])
  611. else
  612. self.costPrice3_tmp.text = string.format("<%s>%s</color>/1", ColorUtil.GREEN_DARK, cost_ticket_num_list[self.current_pool_type][3])
  613. end
  614. self.fifty_cost_num = 1
  615. else
  616. lua_resM:setOutsideImageSprite(self, self.costIcon3_img, GameResPath.GetGoodsIcon(self.model:GetCostTicketGTypeId(self.current_pool_type,1)),true)
  617. if cost_ticket_num_list[self.current_pool_type][1] < 45 then
  618. self.costPrice3_tmp.text = string.format("<%s>%s</color>/45", ColorUtil.RED_DARK, cost_ticket_num_list[self.current_pool_type][1])
  619. else
  620. self.costPrice3_tmp.text = string.format("<%s>%s</color>/45", ColorUtil.GREEN_DARK, cost_ticket_num_list[self.current_pool_type][1])
  621. end
  622. end
  623. local buff_kind = OperateActivityModel.MaterialSubmitBuffKind.EGG_LUCKY_NUM --触发加成后,<color@1>龙神宝库</color>幸运值持续维持999,抽中不清空
  624. local buff_cfg,buff_info = OperateActivityModel:getInstance():GetMaterialBuffInfoByKind(buff_kind)
  625. -- buff_cfg = {discount = 80,data = 1}
  626. -- buff_info = {etime = TimeUtil:getServerTime( )+300,used = {{kdata = 10,vdata=0}}}
  627. self.have_act_buff_lucky_num = false
  628. if buff_cfg and buff_info then
  629. local sec = buff_info.etime - TimeUtil:getServerTime( )
  630. if sec > 0 then
  631. self:ActEggLuckyBuffTimeLate(sec)
  632. self:UpdateLuckyCon()
  633. self.buffBtn_obj:SetActive(true)
  634. self.buffTipImg_obj:SetActive(true)
  635. self.have_act_buff_lucky_num = true
  636. lua_resM:setOutsideImageSprite(self, self.buffBtn_img, GameResPath.GetOperateActImage("ms_buff_btn_kind_6"), true)
  637. else
  638. self.buffBtn_obj:SetActive(false)
  639. self.buffTipImg_obj:SetActive(false)
  640. self.buffTimeText_tmp.text = ""
  641. end
  642. else
  643. self.buffBtn_obj:SetActive(false)
  644. self.buffTipImg_obj:SetActive(false)
  645. self.buffTimeText_tmp.text = ""
  646. end
  647. end
  648. --活动龙神常驻BUFF时间倒计时
  649. function CapsuleEggView:ActEggLuckyBuffTimeLate( sec )
  650. if self.is_loaded then
  651. if self.act_egg_sec == sec then
  652. return
  653. else
  654. self.act_egg_sec = sec
  655. end
  656. if self.act_egg_lucky_buff_timer_id then
  657. GlobalTimerQuest:CancelQuest(self.act_egg_lucky_buff_timer_id)
  658. self.act_egg_lucky_buff_timer_id = nil
  659. end
  660. local sec = sec or 0
  661. if sec > 0 then
  662. local function onTimer()
  663. sec = sec - 1
  664. if sec > 0 then
  665. self.buffTimeText_tmp.text = TimeUtil:timeConvert33(sec)
  666. else
  667. if self.act_egg_lucky_buff_timer_id then
  668. GlobalTimerQuest:CancelQuest(self.act_egg_lucky_buff_timer_id)
  669. self.act_egg_lucky_buff_timer_id = nil
  670. end
  671. self:UpdateCost()
  672. self:UpdateLuckyCon()
  673. end
  674. end
  675. if not self.act_egg_lucky_buff_timer_id then
  676. self.act_egg_lucky_buff_timer_id = GlobalTimerQuest:AddPeriodQuest(onTimer, 1, -1)
  677. end
  678. onTimer()
  679. else
  680. self:UpdateCost()
  681. end
  682. end
  683. end
  684. --活动BUFF时间倒计时
  685. function CapsuleEggView:ActBuffTimeLate( sec )
  686. if self.is_loaded then
  687. if self.act_sec == sec then
  688. return
  689. else
  690. self.act_sec = sec
  691. end
  692. if self.act_buff_timer_id then
  693. GlobalTimerQuest:CancelQuest(self.act_buff_timer_id)
  694. self.act_buff_timer_id = nil
  695. end
  696. local sec = sec or 0
  697. if sec > 0 then
  698. local function onTimer()
  699. sec = sec - 1
  700. if sec > 0 then
  701. else
  702. if self.act_buff_timer_id then
  703. GlobalTimerQuest:CancelQuest(self.act_buff_timer_id)
  704. self.act_buff_timer_id = nil
  705. end
  706. self:UpdateCost()
  707. end
  708. end
  709. if not self.act_buff_timer_id then
  710. self.act_buff_timer_id = GlobalTimerQuest:AddPeriodQuest(onTimer, 1, -1)
  711. end
  712. onTimer()
  713. else
  714. self:UpdateCost()
  715. end
  716. end
  717. end
  718. function CapsuleEggView:DestroySuccess( )
  719. if self.act_egg_lucky_buff_timer_id then
  720. GlobalTimerQuest:CancelQuest(self.act_egg_lucky_buff_timer_id)
  721. self.act_egg_lucky_buff_timer_id = nil
  722. end
  723. if self.act_buff_timer_id then
  724. GlobalTimerQuest:CancelQuest(self.act_buff_timer_id)
  725. self.act_buff_timer_id = nil
  726. end
  727. for k,v in pairs(self.reward_item_list) do
  728. v:DeleteMe()
  729. end
  730. self.reward_item_list = {}
  731. if self.count_down_timer_id then
  732. GlobalTimerQuest:CancelQuest(self.count_down_timer_id)
  733. self.count_down_timer_id = nil
  734. end
  735. self:StopTextAction()
  736. for k,v in pairs(self.label_list) do
  737. v:DeleteMe()
  738. end
  739. self.label_list = {}
  740. for k,v in pairs(self.cache_record_list) do
  741. v:DeleteMe()
  742. end
  743. self.cache_record_list = {}
  744. if self.timer then
  745. GlobalTimerQuest:CancelQuest(self.timer)
  746. self.timer = nil
  747. end
  748. for i,v in ipairs(self.show_item_list) do
  749. v:DeleteMe()
  750. end
  751. if self.money_view then
  752. self.money_view:DeleteMe()
  753. self.money_view = nil
  754. end
  755. self.model:CheckHaveSeeRedDot()
  756. self:StopTenTipsAnim()
  757. end
  758. function CapsuleEggView:UpdateRed( )
  759. local btn1_red = self.model:GetFreeDrawTimesByPoolType(self.current_pool_type) > 0
  760. -- local btn2_red = self.model:GetDrawBtnRed(self.current_pool_type,2)
  761. -- local btn3_red = self.model:GetDrawBtnRed(self.current_pool_type,3)
  762. self.drawRed1_obj:SetActive(btn1_red)
  763. -- self.drawRed10_obj:SetActive(btn2_red)
  764. -- self.drawRed50_obj:SetActive(btn3_red)
  765. self.rewardRed_obj:SetActive(self.model:GetTimeRewardRedDot())
  766. end
  767. function CapsuleEggView:UpdateResetTime( )
  768. self.reset_time = self.model:GetTimesRewarResetTime()
  769. self.rewardcountDown_tmp.text = ""
  770. local function timer_func()
  771. local left_time = self.reset_time - TimeUtil:getServerTime()
  772. if left_time and left_time > 0 then
  773. local str = ""
  774. if left_time > 3600 * 24 then
  775. str = TimeUtil:qianggouTimeLeft3(left_time, true)
  776. else
  777. str = TimeUtil:timeConvert11(left_time, false)
  778. end
  779. self.rewardcountDown_tmp.text = string.format("%s 后重置", str)
  780. else
  781. self.rewardcountDown_tmp.text = ""
  782. self.reset_time = self.model:GetTimesRewarResetTime()
  783. end
  784. end
  785. if not self.timer then
  786. self.timer = GlobalTimerQuest:AddPeriodQuest(timer_func, 1)
  787. end
  788. timer_func()
  789. end
  790. function CapsuleEggView:Close()
  791. --完成引导
  792. local helpVo = GuideModel:getInstance():GetHelpVo(HelpType.TYPE_CAPSULE_EGG,3)
  793. if helpVo then
  794. GlobalEventSystem:Fire(EventName.FINISH_CURRENT_HELP_STEP,helpVo)
  795. GlobalEventSystem:Fire(EventName.FORCE_TO_DO_TASK, true, true)
  796. end
  797. BaseView.Close(self)
  798. end
  799. function CapsuleEggView:UpdateTenTipsShow( )
  800. local cost_ticket_num_list = self.model:GetCostTicketNumList()[self.current_pool_type][1]
  801. local ten_cost_ticket_num_list = self.model:GetCostTicketNumList()[self.current_pool_type][2]
  802. local lucky_num = self.show_offer_obj and math.floor(self.ten_cost_num*self.ten_buff_offer/100 + 0.5) or 9
  803. local min_num = lucky_num - 3
  804. local max_num = lucky_num - 1
  805. if RoleManager.Instance.mainRoleInfo.level < 9999 and cost_ticket_num_list>=min_num and cost_ticket_num_list<=max_num and ten_cost_ticket_num_list == 0 then
  806. self.tenTips_obj:SetActive(true)
  807. self.tenTipsLeftNum_tmp.text = string.format("十连抽还差%s张",lucky_num-cost_ticket_num_list)
  808. self:TenTipsAnim(0)
  809. else
  810. self.tenTips_obj:SetActive(false)
  811. self:StopTenTipsAnim()
  812. SetAnchoredPosition(self.tenTips,342,-289)
  813. end
  814. end
  815. function CapsuleEggView:TenTipsAnim(time)
  816. self:StopTenTipsAnim()
  817. local call_fun = function ()
  818. local function onCompleted()
  819. self:TenTipsAnim(time)
  820. end
  821. self.ten_tip_tween_id1 =TweenLite.to(self, self.tenTips,TweenLite.UiAnimationType.POSX,342,1,onCompleted)
  822. end
  823. local onDelay = function( )
  824. self.ten_tip_tween_id2 =TweenLite.to(self, self.tenTips.transform,TweenLite.UiAnimationType.POSX,355,1,call_fun)
  825. end
  826. self.ten_tip_timer_id = setTimeout(onDelay, time)
  827. end
  828. function CapsuleEggView:StopTenTipsAnim( )
  829. if self.ten_tip_tween_id1 then
  830. TweenLite.Stop(self.ten_tip_tween_id1)
  831. self.ten_tip_tween_id1 = nil
  832. end
  833. if self.ten_tip_tween_id2 then
  834. TweenLite.Stop(self.ten_tip_tween_id2)
  835. self.ten_tip_tween_id2 = nil
  836. end
  837. if self.ten_tip_timer_id then
  838. GlobalTimerQuest:CancelQuest(self.ten_tip_timer_id)
  839. self.ten_tip_timer_id = nil
  840. end
  841. end