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

732 lines
25 KiB

пре 4 недеља
  1. SwallowView = SwallowView or BaseClass(BaseItem)
  2. local SwallowView = SwallowView
  3. function SwallowView:__init()
  4. self.base_file = "bag"
  5. self.layout_file = "SwallowView"
  6. self.column_num = 4 --一行几个图标
  7. self.defult_slot = 24 --默认最少生成空格数
  8. self.equips_list = {} --装备列表
  9. self.equips_count = 0 --装备数量
  10. self.progressing_fun_queue = {} --吞噬进度条的执行方法队列
  11. self.progressing_time = 0.4 --吞噬进度条跑完一次需要的时间
  12. self.full_screen = true
  13. self.ani_right = 400
  14. self.ani_left = -200
  15. self.adjust_mid = {left = 160, right = 780}
  16. self.bag_item_list = {} --背包物品列表
  17. self.core_attr_item_list = {} --特殊属性条
  18. self.timer_id_list = {}
  19. self.model = BagModel:getInstance()
  20. self.model.need_sort_bag = false --是否需要在关闭界面后重整背包(只在吞噬操作后才进行重整)
  21. self.loop_mgr = LoopScrowViewMgr.New()
  22. --吞噬红点当次登录只给一次,打开界面后就取消掉
  23. if self.model:GetSwallowRedDot() then
  24. self.model.is_check_swallow_red = false--一次性红点先取消了
  25. self.model:CheckEquipSwallowRed()
  26. GlobalEventSystem:Fire(EventName.UPDATE_BAG_RED)
  27. -- self.model:Fire(BagModel.ANS_UPDATE_EQUIP_RED)
  28. end
  29. self.fly_shoes_id = BagModel.FlyGoodsID
  30. self:Load()
  31. end
  32. function SwallowView:Open( )
  33. BaseView.Open(self)
  34. end
  35. function SwallowView:Load_callback()
  36. local nodes = {
  37. "right/swallowBtn:obj", --吞噬按钮
  38. "right/tipsBtn:obj", --帮助按钮
  39. "progressBg/progressBar:img",--进度条
  40. "right/equipScroll/Viewport/Content_equip", "right/equipScroll", --装备滚动列表
  41. "right/equipScroll/Viewport/Content_equip/con_equip",
  42. "attrCon",
  43. "attrCon/attr2:tmp","attrCon/attr1:tmp",--属性
  44. "progressExpNum:tmp",--经验进度
  45. "coreAttrCon:obj",
  46. "swallowLv:tmp",--等级
  47. "right/swallowCheck:obj", "right/swallowCheck/checkmark:obj", --勾选普通装备
  48. "right/swallowAuto:obj", "right/swallowAuto/automark:obj", --勾选自动吞噬
  49. "coreBigIcon:raw",
  50. "attrCon/attrArrow2:obj","attrCon/attrArrow1:obj",
  51. "right/bag_bg:img",
  52. "progressBg/progressHandle",
  53. "effectCon:obj",
  54. "flyCon",
  55. "swallowEffect",
  56. }
  57. self:GetChildren(nodes)
  58. lua_resM:setImageSprite(self, self.bag_bg_img, "bagSwallow_asset","bag_swallow_bag_bg")
  59. lua_resM:setOutsideRawImage(self,self.coreBigIcon_raw,GameResPath.GetViewBigBg("bag_swallow_bg"))
  60. self.swallowCheck_toggle = self.swallowCheck:GetComponent("Toggle")
  61. self.swallowAuto_toggle = self.swallowAuto:GetComponent("Toggle")
  62. self.swallowAuto_toggle.isOn = self.model.is_auto_swallow
  63. SetAnchoredPositionX(self.attrCon,-195)
  64. self:AddEvent()
  65. if self.need_refreshData then
  66. self:UpdateView()
  67. self:AddUIEffect("ui_heidong", self.effectCon, "Scene", nil, 4.5, true, nil, false)
  68. end
  69. end
  70. function SwallowView:AddEvent()
  71. local on_click = function ( click_obj )
  72. if self.swallowBtn_obj == click_obj then -- 开始吞噬
  73. self:BeginSwallow()
  74. elseif self.tipsBtn_obj == click_obj then -- 帮助按钮
  75. EventSystem.Fire(GlobalEventSystem,EventName.OPEN_INSTRUCTION_VIEW, 15001)
  76. elseif self.swallowCheck_obj == click_obj then -- 勾选普通
  77. self:SelectEquip()
  78. elseif self.swallowAuto_obj == click_obj then -- 自动吞噬
  79. self.model.set_auto_swallow = true
  80. self.model:Fire(BagModel.REQUEST_PROTOCOL,15025,self.swallowAuto_toggle.isOn and 1 or 0)
  81. end
  82. end
  83. AddClickEvent(self.swallowBtn_obj, on_click)
  84. AddClickEvent(self.tipsBtn_obj, on_click)
  85. AddClickEvent(self.swallowCheck_obj, on_click)
  86. AddClickEvent(self.swallowAuto_obj, on_click)
  87. local function clickBagIcon(type, type_id, index, bool)
  88. if type == GoodsModel.TYPE.EQUIP or type_id == self.fly_shoes_id then
  89. self.equips_list[index].isSelect = bool
  90. self:ShowSwallowExp()
  91. end
  92. end
  93. self:BindEvent(self.model,BagModel.CLICK_EQUIP_ITEM,clickBagIcon)
  94. local function Refresh_Init()
  95. -- self:UpdateView(true,true)
  96. self:UpdateShow(true,true)
  97. end
  98. self:BindEvent(self.model,BagModel.REFRESH_SWALLOW_INIT,Refresh_Init)
  99. -- --点击切换法核时候,需要高亮展示相应的特殊属性已经切换到法核模型
  100. -- local function switch_core_show_handler(index)
  101. -- for i,v in ipairs(self.core_attr_item_list) do
  102. -- v:SetSelected(i == index)
  103. -- end
  104. -- self:UpdateCoreShow(index)
  105. -- end
  106. -- self:BindEvent(self.model,BagModel.CLICK_SWALLOW_CORE_ITEM,switch_core_show_handler)
  107. local function update_suto_swallow_state(bool)
  108. self.swallowAuto_toggle.isOn = bool
  109. end
  110. self:BindEvent(self.model,BagModel.UPDATE_AUTO_SWALLOW_STATE,update_suto_swallow_state)
  111. end
  112. function SwallowView:UpdateView(need_anim,bool)
  113. if self.is_loaded then
  114. self.need_refreshData = false
  115. self:AddUIEffect("ui_heidong", self.effectCon, "Scene", nil, 4.5, true, nil, false,nil,nil,nil)
  116. self:UpdateShow(need_anim,bool)
  117. else
  118. self.need_refreshData = true
  119. end
  120. end
  121. function SwallowView:UpdateShow(need_anim,bool)
  122. --刷新法核解锁属性
  123. if not need_anim then
  124. self:UpdateCoreAttr()
  125. end
  126. --刷新吞噬进度
  127. self:UpdateSwallowProgress(need_anim)
  128. --刷新装备列表
  129. self:UpdateEquipScroll()
  130. end
  131. -- --刷新法核滚动列表(这玩意不要了,但是不晓得后面会不会加回来)
  132. -- function SwallowView:UpdateCoreScroll(bool )
  133. -- local cfg = self.model:GetSwallowCoreCfg()
  134. -- if not self.item_list_com then
  135. -- self.item_list_com = self:AddUIComponent(UI.ItemListCreator)
  136. -- end
  137. -- local info = {
  138. -- data_list = cfg,
  139. -- item_con = self.Content_core,
  140. -- item_class = SwallowCoreItem,
  141. -- item_width = 100,
  142. -- space_x = 2,
  143. -- start_x = 5,
  144. -- start_y = -14,
  145. -- scroll_view = self.coreScroll,
  146. -- create_frequency = 0.01,
  147. -- reuse_item_num = 6,
  148. -- on_update_item = function(item, i, v)
  149. -- item:SetData(v,i,#cfg)
  150. -- end,
  151. -- final_callback = function()
  152. -- local now_item_id = self.model:GetNowSwallowCoreItemId()
  153. -- self.item_list_com:IterateItems(function( item, i )
  154. -- self.model.now_select_core_item_id = now_item_id
  155. -- self.model:Fire(BagModel.CLICK_SWALLOW_CORE_ITEM,now_item_id)
  156. -- end)
  157. -- if now_item_id >5 then
  158. -- self.item_list_com:ScrollToItem(now_item_id)
  159. -- end
  160. -- end,
  161. -- }
  162. -- self.item_list_com:UpdateItems(info)
  163. -- if bool then
  164. -- local now_item_id = self.model:GetNowSwallowCoreItemId()
  165. -- self.item_list_com:IterateItems(function( item, i )
  166. -- self.model.now_select_core_item_id = now_item_id
  167. -- self.model:Fire(BagModel.CLICK_SWALLOW_CORE_ITEM,now_item_id)
  168. -- end)
  169. -- if now_item_id >5 then
  170. -- self.item_list_com:ScrollToItem(now_item_id)
  171. -- end
  172. -- end
  173. -- end
  174. -- --刷新法核展示
  175. -- function SwallowView:UpdateCoreShow(index)
  176. -- local core_cfg, cur
  177. -- if index then
  178. -- core_cfg = self.model:GetSwallCoreCfgByLv(index)
  179. -- cur = index
  180. -- else
  181. -- core_cfg, cur = self.model:GetNowSwallowCoreCfg()
  182. -- end
  183. -- end
  184. --刷新法核解锁属性
  185. function SwallowView:UpdateCoreAttr( )
  186. local cfg = self.model:GetSwallowCoreCfg()
  187. if cfg then
  188. for k,v in pairs(self.core_attr_item_list) do
  189. v:SetVisible(false)
  190. end
  191. for i,v in ipairs(cfg) do
  192. local item = self.core_attr_item_list[i]
  193. if not item then
  194. item = SwallowCoreAttrItem.New(self.coreAttrCon)
  195. self.core_attr_item_list[i] = item
  196. end
  197. item:SetVisible(true)
  198. item:SetData(v,i)
  199. end
  200. end
  201. end
  202. --刷新吞噬进度
  203. function SwallowView:UpdateSwallowProgress(need_anim)
  204. local is_up = self.model.swallow_lv > self.model.pre_swallow_lv
  205. local up_lv_num = self.model.swallow_lv - self.model.pre_swallow_lv
  206. --经验进度条
  207. local endValue = 0
  208. local lv_cfg = Config.Goodsdevour[self.model.swallow_lv]
  209. local next_lv_cfg = Config.Goodsdevour[self.model.swallow_lv+1]
  210. if lv_cfg then
  211. if not next_lv_cfg then
  212. self.swallowLv_tmp.text = string.format("Lv.%s",self.model.swallow_lv)
  213. -- self.progressExpNum_tmp.text = "满级了"
  214. self.progressExpNum_tmp.text = string.format("(<color=%s>%s</color>/%s)",ColorUtil.WHITE,self.model.swallow_exp,lv_cfg.exp)
  215. -- SetSizeDeltaX(self.progressBar,590)
  216. -- SetAnchoredPositionX(self.progressHandle,590)
  217. endValue = self.model.swallow_exp/lv_cfg.exp
  218. SetSizeDeltaX(self.progressBar,590*endValue)
  219. SetAnchoredPositionX(self.progressHandle,590*endValue)
  220. else
  221. endValue = self.model.swallow_exp/lv_cfg.exp
  222. if endValue < 0 then
  223. endValue = 0
  224. elseif endValue > 1 then
  225. endValue = 1
  226. end
  227. if need_anim then
  228. if is_up then
  229. local function fun()
  230. self.in_progressing = true --进度条正在跑
  231. self.progressing_fun_queue = {}
  232. self.progressing_time = 0.5
  233. if self.progressing_time * up_lv_num > 2 then
  234. self.progressing_time = 2 / up_lv_num
  235. end
  236. for i=1,up_lv_num-1 do --前几次跑完整的0到1
  237. local pre_fun = function()
  238. self.swallowLv_tmp.text = string.format("Lv.%s",self.model.pre_swallow_lv+i)
  239. SetSizeDeltaX(self.progressBar,0)
  240. SetAnchoredPositionX(self.progressHandle,0)
  241. table.remove(self.progressing_fun_queue,1)
  242. TweenLite.to(self, self.progressBar, TweenLite.UiAnimationType.WIDTH, 590, self.progressing_time,self.progressing_fun_queue[1])
  243. TweenLite.to(self, self.progressHandle, TweenLite.UiAnimationType.ANCHORED_POSX, 590, self.progressing_time)
  244. self:SetExpAnimation(0,Config.Goodsdevour[self.model.pre_swallow_lv+i].exp,self.model.pre_swallow_lv+i,self.progressing_time)
  245. end
  246. table.insert(self.progressing_fun_queue,pre_fun)
  247. end
  248. --最后一段的进度条
  249. local final_fun = function()
  250. local end_flag_change = function()
  251. self.in_progressing = false --跑完了
  252. self.progressing_fun_queue = {}
  253. end
  254. self.swallowLv_tmp.text = string.format("Lv.%s",self.model.swallow_lv)
  255. SetSizeDeltaX(self.progressBar,0)
  256. SetAnchoredPositionX(self.progressHandle,0)
  257. table.remove(self.progressing_fun_queue,1)
  258. TweenLite.to(self, self.progressBar, TweenLite.UiAnimationType.WIDTH, 590*endValue, endValue*self.progressing_time,end_flag_change)
  259. TweenLite.to(self, self.progressHandle, TweenLite.UiAnimationType.ANCHORED_POSX, 590*endValue, endValue*self.progressing_time)
  260. self:SetExpAnimation(0,Config.Goodsdevour[self.model.swallow_lv].exp,self.model.swallow_lv,endValue*self.progressing_time)
  261. end
  262. table.insert(self.progressing_fun_queue,final_fun)
  263. --开始执行队列中的方法来跑进度条
  264. self.progressing_fun_queue[1]()
  265. end
  266. TweenLite.to(self, self.progressBar, TweenLite.UiAnimationType.WIDTH, 590, (1-self.progressBar_img.fillAmount)*self.progressing_time,fun)
  267. TweenLite.to(self, self.progressHandle, TweenLite.UiAnimationType.ANCHORED_POSX, 590, (1-self.progressBar_img.fillAmount)*self.progressing_time)
  268. self:SetExpAnimation(self.model.swallow_exp,Config.Goodsdevour[self.model.pre_swallow_lv].exp,self.model.pre_swallow_lv,(1-self.progressBar_img.fillAmount)*self.progressing_time)
  269. else
  270. self.swallowLv_tmp.text = string.format("Lv.%s",self.model.swallow_lv)
  271. TweenLite.to(self, self.progressBar, TweenLite.UiAnimationType.WIDTH, 590*endValue, endValue*self.progressing_time)
  272. TweenLite.to(self, self.progressHandle, TweenLite.UiAnimationType.ANCHORED_POSX, 590*endValue, endValue*self.progressing_time)
  273. self:SetExpAnimation(self.model.pre_swallow_exp,self.model.swallow_exp,self.model.swallow_lv,endValue*self.progressing_time)
  274. end
  275. else
  276. self.progressExpNum_tmp.text = string.format("(<color=%s>%s</color>/%s)",ColorUtil.WHITE,self.model.swallow_exp,lv_cfg.exp)
  277. self.swallowLv_tmp.text = string.format("Lv.%s",self.model.swallow_lv)
  278. SetSizeDeltaX(self.progressBar,590*endValue)
  279. SetAnchoredPositionX(self.progressHandle,590*endValue)
  280. end
  281. end
  282. else
  283. self.swallowLv_tmp.text = string.format("Lv.%s",self.model.swallow_lv)
  284. -- self.progressExpNum_tmp.text = "满级了"
  285. self.progressExpNum_tmp.text = string.format("(<color=%s>%s</color>/%s)",ColorUtil.WHITE,self.model.swallow_exp,lv_cfg.exp)
  286. -- SetSizeDeltaX(self.progressBar,590)
  287. -- SetAnchoredPositionX(self.progressHandle,590)
  288. endValue = self.model.swallow_exp/lv_cfg.exp
  289. SetSizeDeltaX(self.progressBar,590*endValue)
  290. SetAnchoredPositionX(self.progressHandle,590*endValue)
  291. end
  292. --属性
  293. local next_lv_cfg = Config.Goodsdevour[self.model.swallow_lv+1]
  294. local next_attr_data = next_lv_cfg and stringtotable(next_lv_cfg.attr) or nil
  295. local attr_data = stringtotable(lv_cfg.attr)
  296. local txt_1 = ""
  297. local txt_2 = ""
  298. local pre_txt_1 = ""
  299. local pre_txt_2 = ""
  300. if attr_data then
  301. pre_txt_1 = string.format("%s <color=%s>+%s</color>",WordManager:GetProperties(attr_data[1][1]),ColorUtil.WHITE,WordManager:GetPropertyValue(attr_data[1][1],attr_data[1][2]))
  302. pre_txt_2 = string.format("%s <color=%s>+%s</color>",WordManager:GetProperties(attr_data[2][1]),ColorUtil.WHITE,WordManager:GetPropertyValue(attr_data[2][1],attr_data[2][2]))
  303. end
  304. txt_1 = pre_txt_1 .. " "
  305. txt_2 = pre_txt_2 .. " "
  306. if next_lv_cfg and next_attr_data and attr_data then
  307. txt_1 = txt_1..HtmlColorTxt(WordManager:GetPropertyValue(next_attr_data[1][1],next_attr_data[1][2]-attr_data[1][2]), ColorUtil.GREEN_DARK)
  308. txt_2 = txt_2..HtmlColorTxt(WordManager:GetPropertyValue(next_attr_data[2][1],next_attr_data[2][2]-attr_data[2][2]), ColorUtil.GREEN_DARK)
  309. self.attrArrow1_obj:SetActive(true)
  310. self.attrArrow2_obj:SetActive(true)
  311. else
  312. self.attrArrow1_obj:SetActive(false)
  313. self.attrArrow2_obj:SetActive(false)
  314. end
  315. self.attr1_tmp.text = pre_txt_1
  316. self.attr2_tmp.text = pre_txt_2
  317. SetLocalPositionX(self.attrArrow1, GetLocalPositionX(self.attr1) + self.attr1_tmp.preferredWidth+20)
  318. SetLocalPositionX(self.attrArrow2, GetLocalPositionX(self.attr2) + self.attr2_tmp.preferredWidth+20)
  319. self.attr1_tmp.text = txt_1
  320. self.attr2_tmp.text = txt_2
  321. end
  322. --经验增长动画
  323. function SwallowView:SetExpAnimation(start_exp,end_exp,lv,duration)
  324. if #self.timer_id_list ~= 0 then
  325. self:DeleteTimer()
  326. end
  327. local lv_max_exp = Config.Goodsdevour[lv].exp
  328. for i=1,20 do
  329. local function delay_func()
  330. self.progressExpNum_tmp.text = string.format("(<color=%s>%s</color>/%s)",ColorUtil.WHITE,math.floor(start_exp+((end_exp - start_exp)/20)*i),lv_max_exp)
  331. end
  332. local id = GlobalTimerQuest:AddDelayQuest(delay_func,i*(duration/20))
  333. table.insert(self.timer_id_list,id)
  334. end
  335. local function end_show()
  336. self.progressExpNum_tmp.text = string.format("(<color=%s>%s</color>/%s)",ColorUtil.WHITE,self.model.swallow_exp,Config.Goodsdevour[self.model.swallow_lv].exp)
  337. end
  338. local end_id = GlobalTimerQuest:AddDelayQuest(end_show,20*(duration/20)+0.05)
  339. table.insert(self.timer_id_list,end_id)
  340. end
  341. function SwallowView:DeleteTimer()
  342. for i=1,#self.timer_id_list do
  343. GlobalTimerQuest:CancelQuest(self.timer_id_list[i])
  344. self.timer_id_list[i] = nil
  345. end
  346. self.timer_id_list = {}
  347. end
  348. --刷新装备列表
  349. function SwallowView:UpdateEquipScroll( )
  350. self.equips_list = {}
  351. self.equips_count = 0
  352. --先拿到背包中的装备数据
  353. local goods_list = GoodsModel:getInstance().bag_goods_list -- 获取到背包列表
  354. for k,v in pairs(goods_list) do
  355. -- 项链8 戒指9 耳饰10 守护11 不可吞噬
  356. if v.type == GoodsModel.TYPE.EQUIP and v.subtype ~= 8 and v.subtype ~= 9
  357. and v.subtype ~= 10 and v.subtype ~= 11 and v.goods_num >0 then
  358. table.insert(self.equips_list,v)
  359. end
  360. end
  361. table.sort(self.equips_list,function(a,b)
  362. if a.color~=b.color then
  363. return a.color<b.color
  364. else
  365. return a.type_id<b.type_id
  366. end
  367. end)
  368. -- 如果是永久Vip,则额外加入小飞鞋的吞噬
  369. if VipModel:getInstance():IsForeverVip() then
  370. local fly_shoes = GoodsModel:getInstance():GetTypeGoods(self.fly_shoes_id)
  371. if not IsTableEmpty(fly_shoes) then
  372. for k, v in ipairs(fly_shoes) do -- 防止有多种小飞鞋
  373. table.insert(self.equips_list, 1, v)
  374. end
  375. end
  376. end
  377. self.equips_count = #self.equips_list
  378. --默认勾选住普通装备
  379. self.swallowCheck_toggle.isOn = true
  380. self:SelectEquip()
  381. --开始创建装备背包列表
  382. local total_num = 0
  383. if self.equips_count > self.defult_slot then
  384. total_num = self.equips_count
  385. else
  386. total_num = self.defult_slot
  387. end
  388. for k = 1,self.defult_slot do
  389. local item = self.bag_item_list[k]
  390. if item == nil then
  391. item = SwallowBagItem.New(self.con_equip,nil,self.layer_name)
  392. item:SetVisible(false)
  393. self.bag_item_list[k] = item
  394. end
  395. end
  396. self.loop_mgr:Init(self.equipScroll,self.Content_equip,self.column_num,89.5,89.5,function(item,index,realIndex )
  397. self:OnInitializeItem(item,index,realIndex )
  398. end)
  399. self.loop_mgr:InitChildren(self.bag_item_list, total_num)
  400. self.loop_mgr:RestToBeginning()
  401. self.loop_mgr:ForceUpdateCurrentItems()
  402. self.loop_mgr:SetContentSizeData()
  403. end
  404. function SwallowView:OnInitializeItem(item,index,realIndex)
  405. if item and realIndex > 0 and realIndex <= self.equips_count then
  406. item:SetData(self.equips_list[realIndex],realIndex)
  407. else
  408. item:SetData(nil)
  409. end
  410. self:UpdateItemState()
  411. end
  412. function SwallowView:UpdateItemState()
  413. for k,item in pairs(self.bag_item_list) do
  414. item:UpdateSelect()
  415. end
  416. end
  417. -- 批量选择装备
  418. function SwallowView:SelectEquip()
  419. local color = ColorType.BLUE_DARK
  420. local main_level = RoleManager.Instance.mainRoleInfo.level
  421. local main_career = RoleManager.Instance.mainRoleInfo.career
  422. local my_max_turn = EquipModel.getInstance():GetCurrentOpenSuitSeries()--我当前的最大装备套数
  423. local repetitive_flag_list = {}--未解锁的蓝装只筛选一个去吞噬
  424. for k,v in pairs(self.equips_list) do
  425. v.isSelect = false
  426. end
  427. if self.swallowCheck_toggle.isOn then
  428. for k,v in pairs(self.equips_list) do
  429. if v.type_id == self.fly_shoes_id then
  430. v.isSelect = true
  431. else
  432. if v.color <= color then
  433. if v.color == ColorType.BLUE_DARK then--蓝装需要判定筛选
  434. local can_not_use = false--是否为不可操作的装备(不可穿戴)
  435. local can_tip, flag = EquipModel:getInstance():EquipCanShowGoodsTip(v)
  436. local equip_cfg = EquipModel:getInstance():GetEquipmentCfg(v.type_id)--拿到装备配置
  437. local equip_series = equip_cfg and equip_cfg.series or 0--装备对应套数
  438. local career_list = equip_cfg and equip_cfg.career or {}--装备对应职业
  439. local is_my_career = false--是否为我能用的职业
  440. for k,v in pairs(career_list) do
  441. if v == main_career then
  442. is_my_career = true
  443. break
  444. end
  445. end
  446. local not_my_career_equip = false
  447. local high_series_can_join = false
  448. if is_my_career then
  449. --如果是我的职业,判定一下是否为未解锁的套数
  450. if equip_series > my_max_turn then --还没解锁的套数蓝装只保留一个
  451. if repetitive_flag_list[v.type_id] then--已经有了一个了,剩下的都拿去吞噬
  452. high_series_can_join = true
  453. else
  454. repetitive_flag_list[v.type_id] = true
  455. end
  456. else--已经解锁的套数判断下是否不可操作穿戴的装备
  457. if flag ~= 1 then
  458. can_not_use = true
  459. end
  460. end
  461. else--如果都不是自己的职业,那直接吞掉就完事了
  462. not_my_career_equip = true
  463. end
  464. if can_not_use or not_my_career_equip or high_series_can_join then
  465. v.isSelect = true
  466. end
  467. else
  468. v.isSelect = true
  469. end
  470. else
  471. v.isSelect = false
  472. end
  473. end
  474. end
  475. else
  476. for k,v in pairs(self.equips_list) do
  477. v.isSelect = false
  478. end
  479. end
  480. self:UpdateItemState()
  481. self:ShowSwallowExp()
  482. end
  483. --预览吞噬经验
  484. function SwallowView:ShowSwallowExp()
  485. -- local next_lv_cfg = Config.Goodsdevour[self.model.swallow_lv+1]
  486. -- if not next_lv_cfg then
  487. -- self.progressExpNum_tmp.text = "满级了"
  488. -- return
  489. -- end
  490. -- 构建装备表
  491. local equips_list = {}
  492. for k,v in pairs(self.equips_list) do
  493. if v.isSelect == true then
  494. table.insert(equips_list,v)
  495. end
  496. end
  497. local exp = 0
  498. for i,v in ipairs(equips_list) do
  499. if v.type_id == self.fly_shoes_id then -- 1件小飞鞋写死1点经验值
  500. exp = exp + v.goods_num
  501. else
  502. local cfg = Config.Equipment[v.type_id]
  503. if cfg then
  504. exp = exp + tonumber(cfg.devour_exp)
  505. end
  506. end
  507. end
  508. --展示预览吞噬经验
  509. if exp ~= 0 then
  510. local lv_cfg = Config.Goodsdevour[self.model.swallow_lv]
  511. if lv_cfg then
  512. self.progressExpNum_tmp.text = string.format("(<color=%s>%s <color=%s>+%s</color></color>/%s)",ColorUtil.WHITE,self.model.swallow_exp,ColorUtil.GREEN_TIPS,exp,lv_cfg.exp)
  513. end
  514. else
  515. local lv_cfg = Config.Goodsdevour[self.model.swallow_lv]
  516. if lv_cfg then
  517. self.progressExpNum_tmp.text = string.format("(<color=%s>%s</color>/%s)",ColorUtil.WHITE,self.model.swallow_exp,lv_cfg.exp)
  518. end
  519. end
  520. end
  521. --开始吞噬
  522. function SwallowView:BeginSwallow()
  523. if self.in_progressing then
  524. Message.show("吞噬中,请稍后再试","fault")
  525. return
  526. end
  527. --先记录一下吞噬前的吞噬等级
  528. self.model.pre_swallow_lv = self.model.swallow_lv
  529. self.model.pre_swallow_exp = self.model.swallow_exp
  530. -- 构建要发的装备表
  531. local equips_list = {}
  532. local is_rare_color = 0
  533. for k,v in pairs(self.equips_list) do
  534. if v.isSelect == true then
  535. local equip = {}
  536. equip.id = v.goods_id
  537. equip.type_id = v.type_id
  538. -- equip.num = v.goods_num
  539. table.insert(equips_list,equip)
  540. if v.type_id ~= self.fly_shoes_id then
  541. is_rare_color = is_rare_color > v.color and is_rare_color or v.color
  542. end
  543. end
  544. end
  545. if #equips_list == 0 then
  546. Message.show("尚未选择吞噬物品","fault")
  547. else
  548. local function ok_callback()
  549. self.model.need_sort_bag = true
  550. self.model:Fire(BagModel.REQUEST_PROTOCOL,15024,equips_list)
  551. for i,v in ipairs(equips_list) do
  552. self:FlyAwardToBag(v.type_id,i)
  553. end
  554. lua_soundM:PlayEffect(self, "success",false,LuaSoundManager.SOUND_TYPE.UI)
  555. end
  556. if is_rare_color >= 3 then
  557. Alert.show("您选中的装备中包含稀有装备,确定要吞噬吗?", Alert.Type.Two, ok_callback, nil, "确定", "取消")
  558. else
  559. ok_callback()
  560. end
  561. end
  562. end
  563. function SwallowView:FlyAwardToBag(goods_type_id,index)
  564. local goods_type_id = goods_type_id
  565. local start_pos = self.flyCon:InverseTransformPoint(self.flyCon.transform.position)
  566. self.image_pool = self.image_pool or {}
  567. local image_item
  568. if #self.image_pool > 0 then
  569. image_item = table.remove(self.image_pool, #self.image_pool)
  570. else
  571. image_item = {}
  572. image_item.gameObject = UiFactory.createChild(self.flyCon, UIType.Image)
  573. image_item.transform = image_item.gameObject.transform
  574. image_item.img = image_item.gameObject:GetComponent("Image")
  575. end
  576. SetLocalScale(image_item.transform,0.6,0.6,0.6)
  577. image_item.gameObject:SetActive(true)
  578. local goods_vo = GoodsModel:getInstance():GetGoodsBasicByTypeId(goods_type_id)
  579. local goods_icon = goods_vo and goods_vo.goods_icon or 0
  580. lua_resM:setOutsideImageSprite(self, image_item.img, GameResPath.GetGoodsIcon(goods_icon), true)
  581. SetLocalPosition(image_item.transform, start_pos.x, start_pos.y, start_pos.z)
  582. local optional = {
  583. min_duration = 0.6,
  584. rand_duration = 0.9,
  585. stop_duration = 0,
  586. }
  587. local flyAction = cc.FlyToRandom.New(start_pos, Vector3.New(-444, -222, 0),optional)
  588. local action = cc.Sequence.New(flyAction, cc.CallFunc.New(function()
  589. image_item.gameObject:SetActive(false)
  590. table.insert(self.image_pool, image_item)
  591. end))
  592. cc.ActionManager:getInstance():addAction(action, image_item.transform)
  593. if self.delay_show_effect then
  594. TimerQuest.CancelQuest(GlobalTimerQuest, self.delay_show_effect)
  595. self.delay_show_effect = nil
  596. end
  597. if self.delay_hide_effect_id then
  598. TimerQuest.CancelQuest(GlobalTimerQuest, self.delay_hide_effect_id)
  599. self.delay_hide_effect_id = nil
  600. end
  601. if self.delay_show_effect_id then
  602. TimerQuest.CancelQuest(GlobalTimerQuest, self.delay_show_effect_id)
  603. self.delay_show_effect_id = nil
  604. end
  605. local function delay_method( )
  606. self:AddUIEffect("ui_heidongtunshi", self.swallowEffect, "Scene", nil, 4.5, false, nil, false,nil,nil,0.4)
  607. end
  608. self.delay_show_effect = setTimeout(delay_method, 0)
  609. lua_soundM:StopEffect(self, LuaSoundManager.SOUND_TYPE.UI, self.sound_id)
  610. if lua_soundM then
  611. self.sound_id = lua_soundM:PlayEffect(self, "swallow",false,LuaSoundManager.SOUND_TYPE.UI)
  612. end
  613. local function delay_hide_effect( )
  614. self.effectCon_obj:SetActive(false)
  615. end
  616. self.delay_hide_effect_id = setTimeout(delay_hide_effect, 0.2)
  617. local function delay_show_effect_con( )
  618. self.effectCon_obj:SetActive(true)
  619. end
  620. self.delay_show_effect_id = setTimeout(delay_show_effect_con, 1.5)
  621. end
  622. function SwallowView:__delete( )
  623. if self.delay_show_effect then
  624. TimerQuest.CancelQuest(GlobalTimerQuest, self.delay_show_effect)
  625. self.delay_show_effect = nil
  626. end
  627. if self.delay_hide_effect_id then
  628. TimerQuest.CancelQuest(GlobalTimerQuest, self.delay_hide_effect_id)
  629. self.delay_hide_effect_id = nil
  630. end
  631. if self.delay_show_effect_id then
  632. TimerQuest.CancelQuest(GlobalTimerQuest, self.delay_show_effect_id)
  633. self.delay_show_effect_id = nil
  634. end
  635. for k,v in pairs(self.bag_item_list) do
  636. v:DeleteMe()
  637. v = nil
  638. end
  639. self.bag_item_list = {}
  640. for k,v in pairs(self.core_attr_item_list) do
  641. v:DeleteMe()
  642. v = nil
  643. end
  644. self.core_attr_item_list = {}
  645. self.equips_list = {}
  646. if self.loop_mgr then
  647. self.loop_mgr:DeleteMe()
  648. self.loop_mgr = nil
  649. end
  650. self:DeleteTimer()
  651. self:ClearUIEffect(self.effectCon)
  652. self:ClearUIEffect(self.flyCon)
  653. end