源战役客户端
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

481 Zeilen
20 KiB

  1. -- <*
  2. -- @Author: Saber
  3. -- @Description: 经验快车快速挂机提取收益界面
  4. -- *>
  5. ExpQuickHangUpView = ExpQuickHangUpView or BaseClass(BaseView)
  6. local ExpQuickHangUpView = ExpQuickHangUpView
  7. local Status = Status
  8. local Config_Exp = Config.Exp
  9. function ExpQuickHangUpView:__init()
  10. self.base_file = "expDun"
  11. self.layout_file = "ExpQuickHangUpView"
  12. self.layer_name = "Activity"
  13. self.destroy_imm = true
  14. self.use_background = true
  15. self.is_set_zdepth = true
  16. self.blur_activity_bg = true
  17. self.use_show_anim = true
  18. self.use_hide_anim = true
  19. self.jump_close = true
  20. self.is_full = false -- 记录当前是否已经存够时间,防止出现升级后存在进度倒退的情况
  21. self.receive_type = nil -- 协议返回的快速挂机领取类型
  22. self.force_gray = false
  23. self.main_role = RoleManager.Instance.mainRoleInfo
  24. self.buff_have_time = 0--是否有免费的二倍数次数
  25. self.cur_lv = self.main_role.level
  26. self.cur_exp = self.main_role.exp
  27. self.last_update_time = 0
  28. self.model = ExpDunModel:getInstance()
  29. self.dun_model = BaseDungeonModel:getInstance()
  30. self.load_callback = function ()
  31. self:LoadSuccess()
  32. self:AddEvent()
  33. end
  34. self.open_callback = function ( )
  35. self:UpdateView()
  36. end
  37. self.destroy_callback = function ( )
  38. self:DestroySuccess()
  39. end
  40. end
  41. function ExpQuickHangUpView:Open( )
  42. --self.data = data
  43. BaseView.Open(self)
  44. end
  45. function ExpQuickHangUpView:LoadSuccess()
  46. local nodes = {
  47. "content", "content/sub_bg:raw",
  48. -- 次数及经验信息
  49. "content/use_num:tmp",
  50. -- 钻石购买栏
  51. "content/money_icon1:img:obj", "content/hangup_require1:tmp:obj", "content/receive_btn1:obj:imgex", "content/receive_btn1/receive_btn1_lb:tmp",
  52. -- vip栏
  53. "content/hangup_require2:obj:tmp", "content/receive_btn2:obj:imgex", "content/receive_btn2/receive_btn2_lb:tmp",
  54. --普通
  55. "content/hangup_require3:tmp", "content/receive_btn3:obj:imgex", "content/receive_btn3/receive_btn3_lb:tmp",
  56. -- 红点
  57. "content/receive_btn_red1:obj", "content/receive_btn_red2:obj", "content/receive_btn_red3:obj",
  58. -- 经验值进度相关
  59. "content/exp_tip:tmp", "content/level:tmp", "content/exp_progress:tmp", "content/exp_storge:tmp",
  60. "content/exp_fill:img",
  61. -- 奖励预览
  62. "content/award_con",
  63. --buff相关
  64. "content/buffText:tmp",
  65. }
  66. self:GetChildren(nodes)
  67. lua_resM:setOutsideRawImage(self, self.sub_bg_raw, GameResPath.GetViewBigBg("exp_hangup_bg"))
  68. self.exp_tip_tmp.text = "超级加速可获得<color=#fdffc2>大量经验值</color>和<color=#fdffc2>1个小时挂机收益</color>,等级、交易券、装备全都要"
  69. local function close_callback()
  70. self:Close()
  71. end
  72. self.tabWindowComponent = UITabWindow.New(self.transform, {}, nil, close_callback, self.background_wnd, self.content, UITabWindow.SizeSmallNoTab, nil, nil, true)
  73. self.tabWindowComponent:SetTitleText("超级加速")
  74. self.tabWindowComponent:SetBackgroundRes("WindowNew2_bg")
  75. end
  76. function ExpQuickHangUpView:AddEvent()
  77. local function click_event(target)
  78. if target == self.close_btn_obj then
  79. self:Close()
  80. elseif target == self.receive_btn1_obj then -- 备注:协议类型坑爹,配置是123排下去的,但是协议对应是321的顺序
  81. self:OnReceiveBtnClick(3)
  82. elseif target == self.receive_btn2_obj then
  83. self:OnReceiveBtnClick(2)
  84. elseif target == self.receive_btn3_obj then
  85. self:OnReceiveBtnClick(1)
  86. elseif target == self.hangup_require2_obj then -- 跳转贵族
  87. OpenFun.Open(451, 5)
  88. self:Close()
  89. end
  90. end
  91. AddClickEvent(self.close_btn_obj, click_event, LuaSoundManager.SOUND_UI.NONE)
  92. AddClickEvent(self.receive_btn1_obj, click_event)
  93. AddClickEvent(self.receive_btn2_obj, click_event)
  94. AddClickEvent(self.receive_btn3_obj, click_event)
  95. AddClickEvent(self.hangup_require2_obj, click_event)
  96. -- 升级检测
  97. local function update_view()
  98. self:UpdateHangupCountAndCost()
  99. self:UpdateExpStorge()
  100. end
  101. self.on_level_up_id = self.main_role:Bind(EventName.CHANGE_LEVEL, update_view)
  102. self:BindEvent(self.model, ExpDunModel.UPDATE_QUICKHANGUP_DATA, update_view)
  103. local function on_receive_reward(vo)
  104. self.is_full = false
  105. self.receive_type = vo.reward_arg
  106. self:UpdateBtnFlag(true)
  107. end
  108. self:BindEvent(self.model, ExpDunModel.UPDATE_HANGUP_VIEW, on_receive_reward)
  109. local function update_quick_hangup_red(type)
  110. if not type or type == ExpDunModel.Red_Type.QuickHangUp then
  111. self:UpdateQuickHangupRed()
  112. end
  113. end
  114. self:BindEvent(self.model, ExpDunModel.UPDATE_EXP_RED_BY_REDTYPE, update_quick_hangup_red)
  115. local function update_exp()
  116. -- 这个经验会分多段发过来,这边做一个延时
  117. local function delay_method( )
  118. self:UpdateRoleLvAndExp()
  119. end
  120. if self.update_exp_id then
  121. GlobalTimerQuest:CancelQuest(self.update_exp_id)
  122. self.update_exp_id = nil
  123. end
  124. self.update_exp_id = setTimeout(delay_method, 0.5)
  125. end
  126. self:BindEvent(self.model, ExpDunModel.SHOW_QUICK_HANGUP_ACTION, update_exp)
  127. local function updata_buff_state(id)
  128. if id == KfActivityModel.TabID.MaterialSubmit and self.is_loaded then
  129. self:UpdateQuickHangupRed()
  130. end
  131. end
  132. self:BindEvent(KfActivityModel:getInstance(), KfActivityModel.ANS_UPDATE_VIEW, updata_buff_state)
  133. end
  134. function ExpQuickHangUpView:UpdateView()
  135. self:UpdateBasicData()
  136. self:UpdateRoleLvAndExp(true)
  137. self:UpdateQuickHangupRed()
  138. self:UpdateHangupCountAndCost()
  139. self:UpdateExpStorge()
  140. end
  141. -- 加载基础数据
  142. function ExpQuickHangUpView:UpdateBasicData( )
  143. -- 加载期望获得道具
  144. local reward_list = self.model:GetExpDunExpectDropCfg()
  145. --如果有BOSS掉落活动 这里要添加展示奖励
  146. local act_award_list = OperateActivityModel:getInstance():GetBossActDropAward()
  147. local limit_time_item_len = #reward_list
  148. if #act_award_list>0 then
  149. for i,v in ipairs(act_award_list) do
  150. reward_list[#reward_list + 1] = v[2]
  151. end
  152. end
  153. self.reward_item_creator = self.reward_item_creator or self:AddUIComponent(UI.ItemListCreator)
  154. local info = {
  155. data_list = reward_list,
  156. item_con = self.award_con,
  157. scroll_view = self.award_con,
  158. obj_pool_type = UIObjPool.UIType.AwardItem,
  159. item_width = 62,
  160. space_x = 7,
  161. create_frequency = 0.01,
  162. alignment = UnityEngine.TextAnchor.UpperLeft,
  163. on_update_item = function(item, i, v)
  164. item:SetData(v, 1)
  165. item:SetItemSize(62, 62)
  166. if i > limit_time_item_len then--需要显示限时
  167. item:SetNumLimitVisible(true,6)
  168. else
  169. item:SetNumLimitVisible(false)
  170. end
  171. end,
  172. }
  173. self.reward_item_creator:UpdateItems(info)
  174. end
  175. function ExpQuickHangUpView:UpdateHangupCountAndCost()
  176. -- 加载快速挂机次数
  177. local max_count, use_count = self.model:GetHangUpTimeCount()
  178. local left_count = max_count - use_count + self.buff_have_time
  179. self.use_num_tmp.text = string.format("<size=%s%%><color=%s>%s</color>%s次</size>",self.buff_have_time>0 and 80 or 100 ,left_count > 0 and ColorUtil.GREEN_DARK or ColorUtil.RED_DARK, left_count, self.buff_have_time>0 and HtmlColorTxt("(+1)", ColorUtil.YELLOW_DARK) or "")
  180. -- 加载当前等级的配置
  181. local hangup_exp_cfg = self.model:GetBuyExpBasicExpCfg()
  182. local base_exp = 0
  183. if hangup_exp_cfg then
  184. base_exp = hangup_exp_cfg.base_exp
  185. end
  186. -- 加载描述文本
  187. -- local sup_vip_times_cfg = self.model:GetExpDunConfig("sup_vip_times")
  188. -- local sup_vip_times = sup_vip_times_cfg.value or 0
  189. -- self.vip_tips_tmp.text = string.format("激活贵族可多领取%s次", sup_vip_times)
  190. -- 加载按钮倍数
  191. self:UpdateBtnsTimes()
  192. -- 加载花费
  193. local mult_cost_cfg = self.model:GetExpDunConfig("multi_exp_cost")
  194. local jin = self.main_role.jin
  195. -- 缓存类型1的购买花费
  196. self.type1_cost = mult_cost_cfg and mult_cost_cfg.value or 0
  197. self.hangup_require1_tmp.text = string.format(" <color=%s>%s</color>",
  198. self.type1_cost <= jin and "#FDFFC2" or ColorUtil.RED_DARK, self.type1_cost)
  199. self.hangup_require2_tmp.text = "<u>贵族免费</u>"
  200. self.hangup_require3_tmp.text = "免费"
  201. self.receive_btn3_imgex.gray = self.main_role.sup_vip_type ~= 0 or self.force_gray
  202. SetTMPSharedMaterial(self.receive_btn3_lb_tmp,
  203. (self.main_role.sup_vip_type ~= 0 or self.force_gray)
  204. and ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn
  205. or ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkBlueBtn)
  206. end
  207. function ExpQuickHangUpView:UpdateBtnsTimes( )
  208. local exp_mult_cfg = self.model:GetExpDunConfig("exp_multiple_time")
  209. if exp_mult_cfg then
  210. local cfgs = stringtotable(exp_mult_cfg.value)
  211. for k = 1, 3 do
  212. self["receive_btn"..k.."_lb_tmp"].text = string.format("%s倍提取", cfgs[k][1])
  213. -- 缓存类型1的提升倍数
  214. if k == 1 then
  215. self.type1_times = cfgs[k][1]
  216. end
  217. end
  218. end
  219. end
  220. -- 更新快速挂机累计表现
  221. function ExpQuickHangUpView:UpdateExpStorge( )
  222. self:ClearExpStorgeTimer()
  223. local condition = Config.Modulesub["610@15"].open_lv
  224. local lv = RoleManager.Instance.mainRoleInfo.level
  225. if condition > lv then -- 未达到开放等级,默认0进度
  226. self.exp_storge_tmp.text = string.format("%s级开放超级加速", condition)
  227. else
  228. local last_time = self.model:GetQuickHangUpReceiveTime()
  229. local max_time, use_time = self.model:GetHangUpTimeCount()
  230. local left_time -- 距离下次刷新的时间
  231. if last_time ~= 0 and use_time < max_time then
  232. -- 加载当前等级的配置
  233. local hangup_exp_cfg = self.model:GetBuyExpBasicExpCfg()
  234. if not hangup_exp_cfg then
  235. self:ClearExpStorgeTimer()
  236. return
  237. end
  238. local end_time = last_time + hangup_exp_cfg.time -- 下次刷新的时间戳
  239. local function quick_hangup_timer()
  240. left_time = end_time - TimeUtil:getServerTime()
  241. if left_time < 0 then
  242. self.exp_storge_tmp.text = string.format("当前存储经验:<color=#ffffff>%s</color>/%s<color=%s>(已满)</color>",
  243. WordManager:ConvertNum(hangup_exp_cfg.base_exp),
  244. WordManager:ConvertNum(hangup_exp_cfg.base_exp),
  245. ColorUtil.GREEN_DARK)
  246. self:ClearExpStorgeTimer()
  247. self:UpdateBtnsTimes()
  248. self:UpdateBtnFlag()
  249. else
  250. self.exp_storge_tmp.text = string.format("当前存储经验:<color=#ffffff>%s</color>/%s",
  251. WordManager:ConvertNum(math.ceil(hangup_exp_cfg.base_exp * (hangup_exp_cfg.time - left_time) / hangup_exp_cfg.time)),
  252. WordManager:ConvertNum(hangup_exp_cfg.base_exp))
  253. for k = 1, 3 do
  254. local time_str = TimeUtil:timeConvert2(left_time, "mm:ss")
  255. self["receive_btn"..k.."_lb_tmp"].text = time_str
  256. end
  257. end
  258. end
  259. self.exp_storge_timer = GlobalTimerQuest:AddPeriodQuest(quick_hangup_timer, 0.5, -1)
  260. quick_hangup_timer()
  261. self:UpdateBtnFlag(left_time > 0)
  262. else
  263. self.exp_storge_tmp.text = string.format("当前存储经验:今日次数已用完")
  264. end
  265. end
  266. end
  267. function ExpQuickHangUpView:ClearExpStorgeTimer( )
  268. if self.exp_storge_timer then
  269. GlobalTimerQuest:CancelQuest(self.exp_storge_timer)
  270. self.exp_storge_timer = nil
  271. end
  272. end
  273. function ExpQuickHangUpView:OnReceiveBtnClick( btn_index )
  274. local function ok_callback()
  275. self.dun_model:Fire(BaseDungeonModel.REQUEST_CCMD_EVENT, 61050, 2, btn_index)
  276. end
  277. -- 按钮索引3对应配置第一条购买配置,也就是要花钱的那条
  278. if btn_index == 3 and self.model:GetQuickHangupTypeOneFlag() and self.buff_have_time == 0 then
  279. local priceText = string.format("<color=%s>%s</color> 彩钻获取%s倍收益?", ColorUtil.YELLOW_DARK, self.type1_cost, self.type1_times)
  280. local data = {
  281. insufficientText = "",
  282. price = self.type1_cost,
  283. priceText = priceText,
  284. titleText = "提示",
  285. ok_callback = ok_callback,
  286. no_need_toggle = false,
  287. toggle_function = function()
  288. self.model:UncheckQuickHangupTypeOne()
  289. end,
  290. }
  291. GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, data)
  292. else
  293. if btn_index == 1 and self.main_role.sup_vip_type ~= 0 then -- 免费档位贵族不给买
  294. Message.show("贵族玩家可领取1.5倍加速", "fault")
  295. return
  296. else
  297. ok_callback()
  298. end
  299. end
  300. end
  301. -- 修改所有领取按钮的状态 gray:灰化 btn_index:根据协议返回的类型控制按钮状态
  302. function ExpQuickHangUpView:UpdateBtnFlag( gray )
  303. local max_time, use_time = self.model:GetHangUpTimeCount()
  304. -- 这里还需要判断一下剩余次数够不够,不够了全部置灰
  305. self.force_gray = gray
  306. gray = gray or use_time >= max_time
  307. self.receive_btn1_imgex.gray = gray
  308. self.receive_btn2_imgex.gray = gray
  309. self.receive_btn3_imgex.gray = gray
  310. SetTMPSharedMaterial(self.receive_btn1_lb_tmp, gray and ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn
  311. or ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkOrangeBtn)
  312. SetTMPSharedMaterial(self.receive_btn2_lb_tmp, gray and ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn
  313. or ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkOrangeBtn)
  314. SetTMPSharedMaterial(self.receive_btn3_lb_tmp, gray and ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn
  315. or ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkBlueBtn)
  316. end
  317. -- 更新快速挂机红点
  318. function ExpQuickHangUpView:UpdateQuickHangupRed( )
  319. -- local bool = self.model:GetExpRedByRedType(ExpDunModel.Red_Type.QuickHangUp)
  320. local buff_kind = OperateActivityModel.MaterialSubmitBuffKind.ADVENTURE_EXP --玩家放置冒险获得1次免费2倍速BUFF
  321. local buff_cfg,buff_info = OperateActivityModel:getInstance():GetMaterialBuffInfoByKind(buff_kind)
  322. local buff_str = ""
  323. local have_time = 0
  324. -- buff_cfg = {discount = 80,data = 1}
  325. -- buff_info = {etime = TimeUtil:getServerTime( )+300,used = {{kdata = 1,vdata=0}}}
  326. if buff_cfg and buff_info then
  327. local sec = buff_info.etime - TimeUtil:getServerTime( )
  328. if sec > 0 then
  329. have_time = 1
  330. for k,v in pairs(buff_info.used) do
  331. if v.kdata == 1 and v.vdata == 1 then--buff有一次免费二倍
  332. have_time = 0
  333. break
  334. end
  335. end
  336. local buff_name = Config.Unitebuffkind[buff_kind] and Config.Unitebuffkind[buff_kind].name or ""
  337. if have_time >= 1 then
  338. buff_str = string.format("%s生效期间可免费获取%s次",buff_name,buff_cfg.data)
  339. end
  340. self:ActBuffTimeLate(sec)
  341. end
  342. end
  343. self.buffText_tmp.text = buff_str
  344. self.buff_have_time = have_time
  345. -- 2021年3月16日修改 不再在内层显示红点,全部false
  346. self.receive_btn_red1_obj:SetActive(have_time >= 1 and self.model:GetExpRedByRedType(ExpDunModel.Red_Type.QuickHangUp))
  347. -- self.receive_btn_red1_obj:SetActive((bool and self.main_role.jin >= self.type1_cost) or have_time >= 1)
  348. self.hangup_require1_obj:SetActive(have_time == 0)
  349. self.money_icon1_obj:SetActive(have_time == 0)
  350. -- -- vip关联的要检测以下是否是灰化了按钮,灰化情况下不出红点
  351. -- self.receive_btn_red2_obj:SetActive(bool and self.main_role.sup_vip_type ~= 0 )
  352. -- self.receive_btn_red3_obj:SetActive(bool and self.main_role.sup_vip_type == 0 )
  353. -- if bool then -- 红点都刷新了,那就顺便刷一下按钮
  354. -- self:UpdateBtnFlag()
  355. -- end
  356. end
  357. -- 更新玩家的经验和等级
  358. function ExpQuickHangUpView:UpdateRoleLvAndExp(force)
  359. if force or Status.NowTime - self.last_update_time > 1 then
  360. local add_lv = self.main_role.level - self.cur_lv
  361. local cur_exp = self.main_role.exp
  362. local cur_percentage = self.cur_exp / Config_Exp[self.cur_lv].exp
  363. local target_percentage = 0
  364. local function get_percentage(lv)
  365. if lv <= 0 then
  366. -- 不满一级,则补上最后的百分比
  367. local last_percentage = self.main_role.exp / Config_Exp[self.main_role.level].exp
  368. target_percentage = target_percentage + last_percentage
  369. else
  370. -- 获得经验的等级超过1级,则图片的填充百分比按整数增加
  371. target_percentage = target_percentage < 1 and 1 or (target_percentage + 1)
  372. lv = lv - 1
  373. get_percentage(lv)
  374. end
  375. end
  376. -- 递归获得提升n级增长的百分比
  377. get_percentage(add_lv)
  378. local add_percentage = target_percentage - cur_percentage
  379. if add_percentage > 0 then
  380. cc.ActionManager:getInstance():removeAllActionsFromTarget(self.exp_fill)
  381. local function action_percentage_func(percent)
  382. percent = percent - 1.0
  383. local real_pec = percent * percent * percent * percent * percent + 1
  384. local _, final_percentage = math.modf(cur_percentage + add_percentage * real_pec);
  385. self.exp_fill_img.fillAmount = final_percentage
  386. end
  387. local action_percentage = cc.CustomUpdate.New(1, action_percentage_func)
  388. cc.ActionManager:getInstance():addAction(action_percentage, self.exp_fill)
  389. end
  390. self.exp_fill_img.fillAmount = cur_percentage
  391. self.cur_lv = self.main_role.level
  392. self.cur_exp = self.main_role.exp
  393. self.level_tmp.text = string.format("Lv.%s", self.cur_lv)
  394. self.exp_progress_tmp.text = string.format("%s/%s", WordManager:ConvertNum(self.cur_exp), WordManager:ConvertNum(Config_Exp[self.cur_lv].exp))
  395. self.last_update_time = Status.NowTime
  396. end
  397. end
  398. function ExpQuickHangUpView:DestroySuccess( )
  399. if self.act_buff_timer_id then
  400. GlobalTimerQuest:CancelQuest(self.act_buff_timer_id)
  401. self.act_buff_timer_id = nil
  402. end
  403. if self.on_level_up_id then
  404. self.main_role:UnBind(self.on_level_up_id)
  405. self.on_level_up_id = nil
  406. end
  407. if self.update_exp_id then
  408. GlobalTimerQuest:CancelQuest(self.update_exp_id)
  409. self.update_exp_id = nil
  410. end
  411. if self.tabWindowComponent then
  412. self.tabWindowComponent:DeleteMe()
  413. self.tabWindowComponent = nil
  414. end
  415. self:ClearExpStorgeTimer()
  416. cc.ActionManager:getInstance():removeAllActionsFromTarget(self.exp_fill)
  417. end
  418. --活动BUFF时间倒计时
  419. function ExpQuickHangUpView:ActBuffTimeLate( sec )
  420. if self.is_loaded then
  421. if self.act_sec == sec then
  422. return
  423. else
  424. self.act_sec = sec
  425. end
  426. if self.act_buff_timer_id then
  427. GlobalTimerQuest:CancelQuest(self.act_buff_timer_id)
  428. self.act_buff_timer_id = nil
  429. end
  430. local sec = sec or 0
  431. if sec > 0 then
  432. local function onTimer()
  433. sec = sec - 1
  434. if sec > 0 then
  435. else
  436. if self.act_buff_timer_id then
  437. GlobalTimerQuest:CancelQuest(self.act_buff_timer_id)
  438. self.act_buff_timer_id = nil
  439. end
  440. self:UpdateQuickHangupRed()
  441. end
  442. end
  443. if not self.act_buff_timer_id then
  444. self.act_buff_timer_id = GlobalTimerQuest:AddPeriodQuest(onTimer, 1, -1)
  445. end
  446. onTimer()
  447. else
  448. self:UpdateQuickHangupRed()
  449. end
  450. end
  451. end