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

962 lines
32 KiB

  1. --[[
  2. 1.id填大标签id
  3. 2.idid的上一级
  4. --]]
  5. ComposeModel = ComposeModel or BaseClass(EventDispatcher)
  6. local ComposeModel = ComposeModel
  7. ComposeModel.UPDATE_COMPOSE_VIEW_RED = "ComposeModel.UPDATE_COMPOSE_VIEW_RED"--更新红点
  8. local table_insert = table.insert
  9. local Trim = Trim
  10. local stringtotable = stringtotable
  11. -- 菜单ID
  12. ComposeModel.ComposePanelID = ComposeModel.ComposePanelID or {
  13. GOODS_JEWEL = 10000000, --宝石合成
  14. UPGRADE_ITEM = 20000000, --进阶合成
  15. EQUIP_CAREER = 30000000, --装备合成
  16. EQUIP_CAREER1 = 31000000, --职业1魔剑士装备
  17. EQUIP_CAREER2 = 32000000, --职业2龙骑士装备
  18. EQUIP_CAREER3 = 33000000, --职业3魔导士装备
  19. EQUIP_CAREER4 = 34000000, --职业4重炮手装备
  20. GOODS_SUIT = 40000000, --套装
  21. GOODS_ITEM = 50000000, --道具合成
  22. }
  23. --页签
  24. ComposeModel.MainTab = {
  25. Guard = 1,--守护
  26. Ornaments = 2,--饰品
  27. Draconic = 3,--刻印
  28. Gemstone = 4,--宝石
  29. Galaxy = 5,--星辰
  30. AwardBox = 6,--宝箱合成
  31. Other = 7,--其他合成
  32. Equip = 8,--装备合成
  33. }
  34. function ComposeModel:__init()
  35. ComposeModel.Instance = self
  36. self:Reset()
  37. end
  38. function ComposeModel:Reset()
  39. self.red_dot_info = {}--页签红点数据
  40. self.gemstone_login_red = true
  41. self.galaxy_login_red = true
  42. self.is_first_open_view = true--第一次打开合成界面不需要选择 默认帮他选择第一个页签
  43. self.goods_model = GoodsModel:getInstance()
  44. self.equip_model = EquipModel:getInstance()
  45. self.orange_jump_id = nil--橙装调整额外参数
  46. self:InitComposeCfg()
  47. end
  48. function ComposeModel:getInstance()
  49. if ComposeModel.Instance == nil then
  50. ComposeModel.New()
  51. end
  52. return ComposeModel.Instance
  53. end
  54. function ComposeModel:Clear()
  55. end
  56. --初始化合成配置
  57. function ComposeModel:InitComposeCfg( )
  58. -- Config.Goodscompose
  59. -- Config.Composemenu
  60. -- Config.Goodscomposeindex
  61. --合成类型控制配置
  62. self.compose_classify_cfg = {}
  63. local compose_classify_cfg = DeepCopy(Config.Goodscomposeorevolutionclassify)
  64. for k,v in pairs(compose_classify_cfg) do
  65. v.condition = stringtotable(v.condition)
  66. for i,vv in ipairs(v.condition) do
  67. if vv[1] == "open_lv" then
  68. v.open_lv = tonumber(vv[2])
  69. elseif vv[1] == "opday" then
  70. v.opday = tonumber(vv[2])
  71. end
  72. end
  73. if not self.compose_classify_cfg[v.id] then
  74. self.compose_classify_cfg[v.id] = {}
  75. end
  76. self.compose_classify_cfg[v.id][v.sub_id] = v
  77. end
  78. --物品合成升星物品typeid表
  79. self.goods_compose_info_cfg = {}
  80. --物品合成升星物品升星表
  81. self.up_quality_compose_list_cfg = {}
  82. self.equip_random_compose_list_cfg = {}----装备不指定合成配置表(服务端自己去购买获取装备随机属性的合成配置)
  83. local goods_compose_info_cfg = DeepCopy(Config.Goodscomposeorevolutioninfo)
  84. for k,v in pairs(goods_compose_info_cfg) do
  85. v.cost_goods = stringtotable(v.cost_goods)
  86. v.cost_money = stringtotable(v.cost_money)
  87. v.condition = stringtotable(v.condition)
  88. if v.condition then
  89. for i,vv in ipairs(v.condition) do
  90. if vv[1] == "open_lv" then
  91. v.open_lv = tonumber(vv[2])
  92. end
  93. end
  94. end
  95. if v.hidden ~= 1 then
  96. if not self.up_quality_compose_list_cfg[v.classify_id] then
  97. self.up_quality_compose_list_cfg[v.classify_id] = {}
  98. end
  99. if not self.up_quality_compose_list_cfg[v.classify_id][v.subclass] then
  100. self.up_quality_compose_list_cfg[v.classify_id][v.subclass] = {}
  101. end
  102. self.up_quality_compose_list_cfg[v.classify_id][v.subclass][#self.up_quality_compose_list_cfg[v.classify_id][v.subclass] + 1] = v
  103. end
  104. if v.classify_id == 1 or v.classify_id == 2 then
  105. if v.main_goods_id == 0 then
  106. self.equip_random_compose_list_cfg[v.target_goods_id] = v
  107. else
  108. self.goods_compose_info_cfg[v.main_goods_id] = v
  109. end
  110. end
  111. end
  112. end
  113. --刷新主界面装备图标红点
  114. function ComposeModel:CheckMainIconRedDot( )
  115. local show = false
  116. for k,v in pairs(self.red_dot_info) do
  117. if v == true then
  118. show = v
  119. break
  120. end
  121. end
  122. GlobalEventSystem:Fire(EventName.SHOW_FUNCTION_RED_POINT, 151, show)
  123. end
  124. --这样写红点 每次调全局的只要调两次
  125. function ComposeModel:IsNeedRedAll( )
  126. self.red_dot_info[ComposeModel.MainTab.Guard] = self:CheckGuardRedDot()
  127. self.red_dot_info[ComposeModel.MainTab.Ornaments] = self:CheckOrnamentsRedDot()
  128. self.red_dot_info[ComposeModel.MainTab.Gemstone] = self:CheckGemstoneRedDot()
  129. self.red_dot_info[ComposeModel.MainTab.Galaxy] = self:CheckGalaxyRedDot()
  130. self.red_dot_info[ComposeModel.MainTab.AwardBox] = self:CheckAwardBoxRedDot()
  131. self.red_dot_info[ComposeModel.MainTab.Other] = self:CheckOtherRedDot()
  132. self.red_dot_info[ComposeModel.MainTab.Equip] = self:CheckEquipRedDot()
  133. self:CheckMainIconRedDot()
  134. StrengthModel:getInstance():Fire(EventName.UPDATE_STRENGTH_MAIN_VIEW_SPECIAL)
  135. end
  136. --红点刷新
  137. function ComposeModel:IsNeedRed( tab_type,is_all,not_refresh_view )
  138. if not is_all then--全刷新就不判断等级了
  139. local can_refresh = self:CheckLevel(tab_type)
  140. if not can_refresh then return end
  141. end
  142. local bool = false
  143. if tab_type == ComposeModel.MainTab.Guard then--守护
  144. bool = self:CheckGuardRedDot()
  145. elseif tab_type == ComposeModel.MainTab.Ornaments then--饰品
  146. bool = self:CheckOrnamentsRedDot()
  147. elseif tab_type == ComposeModel.MainTab.Draconic then--刻印
  148. elseif tab_type == ComposeModel.MainTab.Gemstone then--宝石合成
  149. bool = self:CheckGemstoneRedDot()
  150. elseif tab_type == ComposeModel.MainTab.Galaxy then--星辰
  151. bool = self:CheckGalaxyRedDot()
  152. elseif tab_type == ComposeModel.MainTab.AwardBox then--宝箱合成
  153. bool = self:CheckAwardBoxRedDot()
  154. elseif tab_type == ComposeModel.MainTab.Other then--其他合成
  155. bool = self:CheckOtherRedDot()
  156. elseif tab_type == ComposeModel.MainTab.Equip then--装备合成
  157. bool = self:CheckEquipRedDot()
  158. end
  159. self.red_dot_info[tab_type] = bool
  160. -- print("huangcong:ComposeModel [start:159] :", self.red_dot_info)
  161. -- PrintTable(self.red_dot_info)
  162. -- print("huangcong:ComposeModel [end]")
  163. if not not_refresh_view then
  164. self:Fire(ComposeModel.UPDATE_COMPOSE_VIEW_RED,tab_type,bool)
  165. end
  166. if not is_all then
  167. self:CheckMainIconRedDot()
  168. end
  169. StrengthModel:getInstance():Fire(EventName.UPDATE_STRENGTH_MAIN_VIEW_SPECIAL)
  170. -- print("huangcong:ComposeModel [222]: ",bool,id)
  171. -- PrintTable(self.red_dot_info)
  172. end
  173. --检查等级
  174. function ComposeModel:CheckLevel( tab_type )
  175. local level = RoleManager:getInstance():GetMainRoleVo().level
  176. if tab_type == ComposeModel.MainTab.Guard and level >= Config.Modulesub["151@1"].open_lv then--守护
  177. return true
  178. elseif tab_type == ComposeModel.MainTab.Ornaments and level >= Config.Modulesub["151@2"].open_lv then--饰品
  179. return true
  180. elseif tab_type == ComposeModel.MainTab.Draconic and level >= Config.Modulesub["151@3"].open_lv then--刻印
  181. return true
  182. elseif tab_type == ComposeModel.MainTab.Gemstone and level >= Config.Modulesub["151@4"].open_lv then--宝石
  183. return true
  184. elseif tab_type == ComposeModel.MainTab.Galaxy and level >= Config.Modulesub["151@5"].open_lv then--星辰
  185. return true
  186. elseif tab_type == ComposeModel.MainTab.AwardBox and level >= Config.Modulesub["151@6"].open_lv then--宝箱合成
  187. return true
  188. elseif tab_type == ComposeModel.MainTab.Other and level >= Config.Modulesub["151@7"].open_lv then--其他合成
  189. return true
  190. elseif tab_type == ComposeModel.MainTab.Equip and level >= Config.Modulesub["151@8"].open_lv then--装备合成
  191. return true
  192. end
  193. return false
  194. end
  195. --检查守护的红点
  196. function ComposeModel:CheckGuardRedDot( )
  197. local have_red = self.equip_model:CheckGuardRedDot()--放在装备那边可以减少一部分红点刷新次数
  198. return have_red
  199. end
  200. --检查饰品红点
  201. function ComposeModel:CheckOrnamentsRedDot( )
  202. local have_red = self.equip_model:CheckOrnamentRedDot()--放在装备那边可以减少一部分红点刷新次数
  203. return have_red
  204. end
  205. --检查宝石红点
  206. function ComposeModel:CheckGemstoneRedDot( )
  207. do return false end
  208. local have_red = false--放在装备那边可以减少一部分红点刷新次数
  209. if not self.gemstone_login_red then
  210. return have_red
  211. end
  212. local cfg_list = self:GetEvolutionComposeListCfg(ComposeModel.MainTab.Gemstone) or {}
  213. local cost_list = nil
  214. local goods_num = 0
  215. for k,v in pairs(cfg_list) do
  216. if not have_red then
  217. for kk,vv in pairs(v) do
  218. cost_list = vv.cost_goods
  219. if cost_list and cost_list[1] then--宝石只需要判断下一级宝石是否满足合成数量接口
  220. goods_num = self.goods_model:GetTypeGoodsNum(cost_list[1][2])
  221. if goods_num >= cost_list[1][3] then
  222. have_red = true
  223. break
  224. end
  225. end
  226. end
  227. else
  228. break
  229. end
  230. end
  231. return have_red
  232. end
  233. --检查装备红点
  234. function ComposeModel:CheckEquipRedDot( )
  235. local cfg_list = self:GetEvolutionComposeListCfg(ComposeModel.MainTab.Equip) or {}
  236. local cost_list = nil
  237. local goods_num = 0
  238. local have_red = false
  239. for k,v in pairs(cfg_list) do
  240. if not have_red then
  241. for kk,vv in pairs(v) do
  242. if not self:CheckBagAndWearHaveOrangeEquip(vv.target_goods_id) then--如果身上和背包上没有就不用有红点了
  243. cost_list = vv.cost_goods
  244. if cost_list and cost_list[1] then--只要判断碎片是否足够就OK
  245. goods_num = self.goods_model:GetTypeGoodsNum(cost_list[1][2])
  246. if goods_num >= cost_list[1][3] then
  247. have_red = true
  248. break
  249. end
  250. end
  251. end
  252. end
  253. else
  254. break
  255. end
  256. end
  257. return have_red
  258. end
  259. --检查背包和身上穿戴是否有橙色装备
  260. function ComposeModel:CheckBagAndWearHaveOrangeEquip( type_id )
  261. local have_orange_equip = false--默认找不到
  262. local equip_cfg = self.equip_model:GetEquipmentCfg(type_id)
  263. if equip_cfg then
  264. local wear_goods_vo = self.goods_model:GetTargetSeriesTargetPosEquip(equip_cfg.series,equip_cfg.equip_type)
  265. if wear_goods_vo and wear_goods_vo.color >= 4 then
  266. return true
  267. end
  268. local bag_list = self.goods_model.bag_goods_list
  269. for i,v in pairs(bag_list) do
  270. local bag_equip_cfg = self.equip_model:GetEquipmentCfg(v.type_id)
  271. if bag_equip_cfg and self.equip_model:SelfCareerIsOk(v.type_id) and bag_equip_cfg.series == equip_cfg.series and bag_equip_cfg.equip_type == equip_cfg.equip_type and v.color >= 4 and v.goods_num > 0 then
  272. return true
  273. end
  274. end
  275. end
  276. return false
  277. end
  278. --检查星辰红点
  279. function ComposeModel:CheckGalaxyRedDot( )
  280. local have_red = false--放在装备那边可以减少一部分红点刷新次数
  281. if not self.galaxy_login_red then
  282. return have_red
  283. end
  284. local cfg_list = self:GetEvolutionComposeListCfg(ComposeModel.MainTab.Galaxy) or {}
  285. local cost_list = nil
  286. local goods_num = 0
  287. for k,v in pairs(cfg_list) do
  288. if not have_red then
  289. for kk,vv in pairs(v) do
  290. cost_list = vv.cost_goods
  291. if cost_list and cost_list[1] then--宝石只需要判断下一级宝石是否满足合成数量接口
  292. goods_num = self.goods_model:GetTypeGoodsNum(cost_list[1][2])
  293. if goods_num >= cost_list[1][3] then
  294. have_red = true
  295. break
  296. end
  297. end
  298. end
  299. else
  300. break
  301. end
  302. end
  303. return have_red
  304. end
  305. --检查宝箱合成红点
  306. function ComposeModel:CheckAwardBoxRedDot( )
  307. local have_red = false
  308. if self.awardBox_login_red then
  309. return have_red
  310. end
  311. local cfg_list = self:GetEvolutionComposeListCfg(ComposeModel.MainTab.AwardBox) or {}
  312. local cost_list = nil
  313. local goods_num = 0
  314. local is_all_have = false
  315. local openDay = ServerTimeModel:getInstance():GetOpenServerDay()
  316. local level = RoleManager.Instance.mainRoleInfo.level
  317. local open_lv = 0
  318. local open_day = 0
  319. for k,v in pairs(cfg_list) do
  320. if not have_red then
  321. for kk,vv in pairs(v) do
  322. open_lv = 0
  323. open_day = 0
  324. if #vv.condition > 0 then
  325. for kkk,vvv in ipairs(vv.condition) do
  326. if vvv[1] == "open_lv" then
  327. open_lv = tonumber(vvv[2])
  328. elseif vvv[1] == "opday" then
  329. open_day = tonumber(vvv[2])
  330. end
  331. end
  332. end
  333. if open_lv <= level and open_day <= openDay then
  334. cost_list = vv.cost_goods
  335. is_all_have = true
  336. for kkk,vvv in pairs(cost_list) do
  337. goods_num = self.goods_model:GetTypeGoodsNum(vvv[2])
  338. if goods_num < vvv[3] then
  339. is_all_have = false
  340. break
  341. end
  342. end
  343. if is_all_have then
  344. have_red = true
  345. end
  346. end
  347. end
  348. else
  349. break
  350. end
  351. end
  352. return have_red
  353. end
  354. --检查其他合成红点
  355. function ComposeModel:CheckOtherRedDot( )
  356. local have_red = false
  357. if self.other_login_red then
  358. return have_red
  359. end
  360. local cfg_list = self:GetEvolutionComposeListCfg(ComposeModel.MainTab.Other) or {}
  361. local cost_list = nil
  362. local goods_num = 0
  363. local is_all_have = false
  364. local openDay = ServerTimeModel:getInstance():GetOpenServerDay()
  365. local level = RoleManager.Instance.mainRoleInfo.level
  366. local open_lv = 0
  367. local open_day = 0
  368. for k,v in pairs(cfg_list) do
  369. if not have_red then
  370. for kk,vv in pairs(v) do
  371. open_lv = 0
  372. open_day = 0
  373. if #vv.condition > 0 then
  374. for kkk,vvv in ipairs(vv.condition) do
  375. if vvv[1] == "open_lv" then
  376. open_lv = tonumber(vvv[2])
  377. elseif vvv[1] == "opday" then
  378. open_day = tonumber(vvv[2])
  379. end
  380. end
  381. end
  382. if open_lv <= level and open_day <= openDay then
  383. cost_list = vv.cost_goods
  384. is_all_have = true
  385. for kkk,vvv in pairs(cost_list) do
  386. goods_num = self.goods_model:GetTypeGoodsNum(vvv[2])
  387. if goods_num < vvv[3] then
  388. is_all_have = false
  389. break
  390. end
  391. end
  392. if is_all_have then
  393. have_red = true
  394. end
  395. end
  396. end
  397. else
  398. break
  399. end
  400. end
  401. return have_red
  402. end
  403. --获得合成类型配置
  404. function ComposeModel:GetComposeTypeCfg( compose_type,compose_sub_type )
  405. if compose_type and compose_sub_type then
  406. if self.compose_classify_cfg[compose_type] then
  407. return self.compose_classify_cfg[compose_type][compose_sub_type]
  408. end
  409. elseif compose_type and not compose_sub_type then
  410. return self.compose_classify_cfg[compose_type]
  411. end
  412. end
  413. --获得道具(首饰)升品配置
  414. function ComposeModel:GetEvolutionComposeListCfg( classify_id )
  415. if self.up_quality_compose_list_cfg[classify_id] then
  416. local new_data = {}
  417. local up_quality_cfg = self.up_quality_compose_list_cfg[classify_id]
  418. local openDay = ServerTimeModel:getInstance():GetOpenServerDay()
  419. local level = RoleManager.Instance.mainRoleInfo.level
  420. local open_lv = 0
  421. local open_day = 0
  422. for i,v in pairs(up_quality_cfg) do
  423. for k,vv in pairs(v) do
  424. local type_id = vv.main_goods_id
  425. if classify_id == ComposeModel.MainTab.Equip then
  426. type_id = vv.target_goods_id
  427. end
  428. if self:IsCanCompose(vv.classify_id,vv.subclass,type_id) then
  429. if not new_data[vv.subclass] then
  430. new_data[vv.subclass] = {}
  431. end
  432. open_lv = 0
  433. open_day = 0
  434. if #vv.condition > 0 then
  435. for kkk,vvv in ipairs(vv.condition) do
  436. if vvv[1] == "open_lv" then
  437. open_lv = tonumber(vvv[2])
  438. elseif vvv[1] == "opday" then
  439. open_day = tonumber(vvv[2])
  440. end
  441. end
  442. end
  443. if open_lv <= level and open_day <= openDay then
  444. new_data[vv.subclass][#new_data[vv.subclass] + 1] = vv
  445. end
  446. end
  447. end
  448. end
  449. return new_data
  450. end
  451. end
  452. --获得道具ID合成配置
  453. function ComposeModel:GetEvolutionComposeCfg( type_id )
  454. if self.goods_compose_info_cfg[type_id] then
  455. local compose_type_cfg = self.compose_classify_cfg[self.goods_compose_info_cfg[type_id].classify_id][self.goods_compose_info_cfg[type_id].subclass]
  456. local openDay = ServerTimeModel:getInstance():GetOpenServerDay()
  457. local level = RoleManager.Instance.mainRoleInfo.level
  458. if compose_type_cfg and compose_type_cfg.open_lv <= level and compose_type_cfg.opday <= openDay then
  459. return self.goods_compose_info_cfg[type_id]
  460. end
  461. end
  462. end
  463. --装备不指定合成配置表
  464. function ComposeModel:GetEquipRandomComposeCfg( type_id )
  465. if self.equip_random_compose_list_cfg[type_id] then
  466. local compose_type_cfg = self.compose_classify_cfg[self.equip_random_compose_list_cfg[type_id].classify_id][self.equip_random_compose_list_cfg[type_id].subclass]
  467. local openDay = ServerTimeModel:getInstance():GetOpenServerDay()
  468. local level = RoleManager.Instance.mainRoleInfo.level
  469. if compose_type_cfg and compose_type_cfg.open_lv <= level and compose_type_cfg.opday <= openDay then
  470. return self.equip_random_compose_list_cfg[type_id]
  471. end
  472. end
  473. end
  474. --能否合成
  475. function ComposeModel:IsCanCompose( classify_id,subclass,type_id )
  476. if classify_id and subclass then
  477. local compose_type_cfg = self:GetComposeTypeCfg(classify_id,subclass)
  478. local openDay = ServerTimeModel:getInstance():GetOpenServerDay()
  479. local level = RoleManager.Instance.mainRoleInfo.level
  480. if classify_id == ComposeModel.MainTab.Equip and not self.equip_model:SelfCareerIsOk(type_id) then
  481. return false
  482. end
  483. if compose_type_cfg and compose_type_cfg.open_lv <= level and compose_type_cfg.opday <= openDay then--先满足主类型的
  484. if type_id and type_id ~= 0 then
  485. local goods_compose_cfg = self:GetEvolutionComposeCfg(type_id)
  486. if goods_compose_cfg and goods_compose_cfg.open_lv ~= nil then
  487. return level >= goods_compose_cfg.open_lv
  488. else
  489. return true
  490. end
  491. end
  492. return true
  493. end
  494. end
  495. return false
  496. end
  497. --获得刻印列表通过颜色和装备类型
  498. function ComposeModel:GetDraconicListByColorAndEquiptype( color,equip_type )
  499. local draconic_cfg_list = self.equip_model:GetDraconicCfg(equip_type)
  500. if draconic_cfg_list then
  501. draconic_cfg_list = DeepCopy(draconic_cfg_list)
  502. local new_list = {}
  503. for k,v in pairs(draconic_cfg_list) do
  504. if v.color == color then
  505. new_list[#new_list + 1] = v
  506. end
  507. end
  508. if #new_list > 1 then
  509. local sort_func = function ( a, b )
  510. return a.goods_id < b.goods_id
  511. end
  512. table.sort(new_list, sort_func)
  513. return new_list
  514. end
  515. end
  516. end
  517. --设置当前选中道具列表
  518. function ComposeModel:SetDraconicChooseList( list )
  519. self.draconic_choose_list = {}
  520. for i,v in pairs(list) do
  521. if v[4] then
  522. self.draconic_choose_list[#self.draconic_choose_list + 1] = v[4]
  523. end
  524. end
  525. -- print("huangcong:ComposeModel [start:263] :", self.draconic_choose_list)
  526. -- PrintTable(self.draconic_choose_list)
  527. -- print("huangcong:ComposeModel [end]")
  528. end
  529. function ComposeModel:GetDraconicChooseList( )
  530. return self.draconic_choose_list
  531. end
  532. --获得当前选择刻印的剩余数量 可能已经选了一个
  533. function ComposeModel:GetCurDraconicHaveNum( type_id )
  534. local goods_num = self.goods_model:GetTypeGoodsNum(type_id)
  535. local offer_num = 0
  536. for i,v in ipairs(self.draconic_choose_list) do
  537. if v.type_id == type_id then
  538. offer_num = offer_num + 1
  539. end
  540. end
  541. return goods_num - offer_num
  542. end
  543. --获取合成红点
  544. function ComposeModel:GetComposeRedDotByType( tab_type )
  545. if not tab_type then return false end
  546. return self.red_dot_info[tab_type]
  547. end
  548. --合成跳转
  549. function ComposeModel:TryComposeJump( tab_type )
  550. OpenFun.Open(151,1, type_id)
  551. end
  552. --请求装备合成
  553. function ComposeModel:ReqEquipCompose( choose_data,times,shop_item_info,cost_list,is_aotu_buy_cost)
  554. if not choose_data then return end
  555. local cur_cfg = choose_data
  556. if cur_cfg and cur_cfg.cost_goods[1] then
  557. local can_not_buy_list = {}
  558. local main_goods_id = cur_cfg.main_goods_id
  559. local goods_vo = nil
  560. local equip_cfg = self.equip_model:GetEquipmentCfg(main_goods_id)
  561. local secend_main_goods = tonumber(cur_cfg.cost_goods[1][2]) or nil
  562. if equip_cfg then
  563. secend_main_goods = equip_cfg.equip_type == EquipModel.EquipType.Guard and nil or secend_main_goods
  564. local series = equip_cfg.series
  565. local pos = equip_cfg.equip_type
  566. local wear_equip_suit_list = self.goods_model.wear_equip_suit_list
  567. if equip_cfg.equip_type == EquipModel.EquipType.Guard then
  568. for k,v in pairs(wear_equip_suit_list) do
  569. for kk,vv in pairs(v) do
  570. if vv.type_id == main_goods_id then
  571. goods_vo = vv
  572. elseif vv.type_id == secend_main_goods then
  573. goods_vo = vv
  574. cur_cfg = self:GetEvolutionComposeCfg(secend_main_goods)
  575. break
  576. end
  577. end
  578. end
  579. else
  580. if wear_equip_suit_list[series] and wear_equip_suit_list[series][pos] then
  581. if wear_equip_suit_list[series][pos].type_id == main_goods_id then
  582. goods_vo = wear_equip_suit_list[series][pos]
  583. elseif wear_equip_suit_list[series][pos].type_id == secend_main_goods then
  584. cur_cfg = self:GetEvolutionComposeCfg(secend_main_goods)
  585. goods_vo = wear_equip_suit_list[series][pos]
  586. end
  587. end
  588. end
  589. if not goods_vo then--如果是在背包中找到 主次合成物品ID调换
  590. local bag_list = self.goods_model.bag_goods_list
  591. for i,v in pairs(bag_list) do
  592. if (v.type_id == equip_cfg.goods_id or (v.type_id == secend_main_goods and equip_cfg.equip_type ~= EquipModel.EquipType.Guard)) and v.goods_num > 0 then
  593. goods_vo = v
  594. cur_cfg = self:GetEvolutionComposeCfg(v.type_id)
  595. break
  596. end
  597. end
  598. end
  599. end
  600. local cfg = cur_cfg
  601. if goods_vo then--主合成道具
  602. -- cfg = self:GetEvolutionComposeCfg(goods_vo.type_id)
  603. else
  604. cfg = self:GetEquipRandomComposeCfg(choose_data.target_goods_id)
  605. end
  606. if cfg then
  607. local data = {}
  608. data.rule_id = cfg.rule_id
  609. data.main_goods_id = goods_vo and goods_vo.goods_id or 0
  610. data.main_goods_location = goods_vo and goods_vo.pos or 2
  611. data.times = times or 1
  612. -- local list = self:GetUpQualityComposeList(cfg.cost_goods)--其实可以不拿 服务端可以自己拿的
  613. -- data.list = list or {}
  614. data.list = {}
  615. local auto_buy_list = {}
  616. local show_shop_item_num = 0
  617. if shop_item_info and TableSize(shop_item_info) > 0 then
  618. for i,v in ipairs(shop_item_info) do
  619. if v.shop_cfg then
  620. show_shop_item_num = show_shop_item_num + 1
  621. local shop_id,shop_num = v.shop_cfg.key_id,v.need_num
  622. if shop_id then
  623. auto_buy_list[#auto_buy_list + 1] = {shop_id,shop_num}
  624. end
  625. else
  626. can_not_buy_list[#can_not_buy_list + 1] = {0,v.type_id,v.need_num}
  627. end
  628. end
  629. end
  630. if #auto_buy_list > 0 and not is_aotu_buy_cost then
  631. Message.show("材料不足","fault")
  632. return
  633. end
  634. if #auto_buy_list == TableSize(shop_item_info) or TableSize(shop_item_info) == 0 then
  635. data.auto_buy_list = auto_buy_list
  636. print("huangcong:ComposeModel [start:131] :", data)
  637. PrintTable(data)
  638. print("huangcong:ComposeModel [end]")
  639. local ok = function ( )
  640. self:Fire(ComposeEvent.REQUEST_COMPOSE,data)
  641. end
  642. local goods_name = self.goods_model:getGoodsName(cfg.target_goods_id, true)
  643. local view_data = {}
  644. view_data.ok_callback = ok
  645. view_data.goods_name = goods_name
  646. view_data.times = times
  647. view_data.cost_list = cost_list or {}
  648. self:Fire(ComposeEvent.OPEN_COMPOSE_COST_AWARD_TIP_VIEW,view_data)
  649. else
  650. local view_data = {}
  651. view_data.cost_list = can_not_buy_list or {}
  652. local content_desc = string.format("当前缺失<color=%s>无法购买的材料</color>\n\n\n\n\n\n<color=%s>没有办法直接补齐材料合成哦</color>",ColorUtil.RED_DARK,ColorUtil.RED_DARK)
  653. view_data.content_desc = content_desc
  654. self:Fire(ComposeEvent.OPEN_COMPOSE_COST_AWARD_TIP_VIEW,view_data)
  655. end
  656. else
  657. Message.show("配置有误","fault")
  658. end
  659. end
  660. end
  661. --请求宝石合成
  662. function ComposeModel:ReqGemStoneCompose( choose_data,times,shop_item_info,cost_list,is_aotu_buy_cost )
  663. if not choose_data then return end
  664. local cfg = choose_data
  665. if cfg and cfg.cost_goods[1] then
  666. if cost_list then
  667. local can_not_buy_list = {}
  668. local data = {}
  669. data.rule_id = cfg.rule_id
  670. data.main_goods_id = 0
  671. data.main_goods_location = 0
  672. data.times = times or 1
  673. -- local list = self:GetUpQualityComposeList(cfg.cost_goods)--其实可以不拿 服务端可以自己拿的
  674. -- data.list = list or {}
  675. data.list = {}
  676. local auto_buy_list = {}
  677. local show_shop_item_num = 0
  678. if shop_item_info and TableSize(shop_item_info) > 0 then
  679. for i,v in ipairs(shop_item_info) do
  680. if v.shop_cfg then
  681. show_shop_item_num = show_shop_item_num + 1
  682. local shop_id,shop_num = v.shop_cfg.key_id,v.need_num
  683. if shop_id then
  684. auto_buy_list[#auto_buy_list + 1] = {shop_id,shop_num}
  685. end
  686. else
  687. can_not_buy_list[#can_not_buy_list + 1] = {0,v.type_id,v.need_num}
  688. end
  689. end
  690. end
  691. if #auto_buy_list > 0 and not is_aotu_buy_cost then
  692. Message.show("合成材料不足哦!")
  693. return
  694. end
  695. if #auto_buy_list == TableSize(shop_item_info) or TableSize(shop_item_info) == 0 then
  696. data.auto_buy_list = auto_buy_list
  697. print("huangcong:ComposeModel [start:715] :", data)
  698. PrintTable(data)
  699. print("huangcong:ComposeModel [end]")
  700. local ok = function ( )
  701. self:Fire(ComposeEvent.REQUEST_COMPOSE,data)
  702. end
  703. local goods_name = self.goods_model:getGoodsName(cfg.target_goods_id, true)
  704. local view_data = {}
  705. view_data.ok_callback = ok
  706. view_data.goods_name = goods_name
  707. view_data.times = times
  708. view_data.cost_list = cost_list or {}
  709. self:Fire(ComposeEvent.OPEN_COMPOSE_COST_AWARD_TIP_VIEW,view_data)
  710. else
  711. local view_data = {}
  712. view_data.cost_list = can_not_buy_list or {}
  713. local content_desc = string.format("当前缺失<color=%s>无法购买的材料</color>\n\n\n\n\n\n<color=%s>没有办法直接补齐材料合成哦</color>",ColorUtil.RED_DARK,ColorUtil.RED_DARK)
  714. view_data.content_desc = content_desc
  715. self:Fire(ComposeEvent.OPEN_COMPOSE_COST_AWARD_TIP_VIEW,view_data)
  716. end
  717. end
  718. end
  719. end
  720. --请求橙装合成
  721. function ComposeModel:ReqOrangeEquipCompose( choose_data,times,shop_item_info,cost_list,is_aotu_buy_cost )
  722. if not choose_data then return end
  723. local cfg = choose_data
  724. if cfg and cfg.cost_goods[1] then
  725. if cost_list then
  726. local can_not_buy_list = {}
  727. local data = {}
  728. data.rule_id = cfg.rule_id
  729. data.main_goods_id = 0
  730. data.main_goods_location = 0
  731. data.times = times or 1
  732. data.list = {}
  733. local auto_buy_list = {}
  734. local show_shop_item_num = 0
  735. if shop_item_info and TableSize(shop_item_info) > 0 then
  736. for i,v in ipairs(shop_item_info) do
  737. if v.shop_cfg then
  738. show_shop_item_num = show_shop_item_num + 1
  739. local shop_id,shop_num = v.shop_cfg.key_id,v.need_num
  740. if shop_id then
  741. auto_buy_list[#auto_buy_list + 1] = {shop_id,shop_num}
  742. end
  743. else
  744. can_not_buy_list[#can_not_buy_list + 1] = {0,v.type_id,v.need_num}
  745. end
  746. end
  747. end
  748. if #auto_buy_list > 0 and not is_aotu_buy_cost then
  749. Message.show("合成材料不足哦!")
  750. return
  751. end
  752. if #auto_buy_list == TableSize(shop_item_info) or TableSize(shop_item_info) == 0 then
  753. data.auto_buy_list = auto_buy_list
  754. self:Fire(ComposeEvent.REQUEST_COMPOSE,data)
  755. else
  756. local view_data = {}
  757. view_data.cost_list = can_not_buy_list or {}
  758. local content_desc = string.format("当前缺失<color=%s>无法购买的材料</color>\n\n\n\n\n\n<color=%s>没有办法直接补齐材料合成哦</color>",ColorUtil.RED_DARK,ColorUtil.RED_DARK)
  759. view_data.content_desc = content_desc
  760. self:Fire(ComposeEvent.OPEN_COMPOSE_COST_AWARD_TIP_VIEW,view_data)
  761. end
  762. end
  763. end
  764. end
  765. --请求宝箱或其他合成
  766. function ComposeModel:ReqAwardBoxOrOTherCompose( choose_data,times,shop_item_info,cost_list,is_aotu_buy_cost)
  767. if not choose_data then return end
  768. local cfg = choose_data
  769. if cfg and cfg.cost_goods[1] then
  770. if cost_list then
  771. local can_not_buy_list = {}
  772. local data = {}
  773. data.rule_id = cfg.rule_id
  774. data.main_goods_id = 0
  775. data.main_goods_location = 0
  776. data.times = times or 1
  777. -- local list = self:GetUpQualityComposeList(cfg.cost_goods)--其实可以不拿 服务端可以自己拿的
  778. -- data.list = list or {}
  779. data.list = {}
  780. local auto_buy_list = {}
  781. local show_shop_item_num = 0
  782. if shop_item_info and TableSize(shop_item_info) > 0 then
  783. for i,v in ipairs(shop_item_info) do
  784. if v.shop_cfg then
  785. show_shop_item_num = show_shop_item_num + 1
  786. local shop_id,shop_num = v.shop_cfg.key_id,v.need_num
  787. if shop_id then
  788. auto_buy_list[#auto_buy_list + 1] = {shop_id,shop_num}
  789. end
  790. else
  791. can_not_buy_list[#can_not_buy_list + 1] = {0,v.type_id,v.need_num}
  792. end
  793. end
  794. end
  795. if #auto_buy_list > 0 and not is_aotu_buy_cost then
  796. Message.show("合成材料不足哦!")
  797. return
  798. end
  799. if #auto_buy_list == TableSize(shop_item_info) or TableSize(shop_item_info) == 0 then
  800. data.auto_buy_list = auto_buy_list
  801. print("huangcong:ComposeModel [start:645] :", data)
  802. PrintTable(data)
  803. print("huangcong:ComposeModel [end]")
  804. local ok = function ( )
  805. self:Fire(ComposeEvent.REQUEST_COMPOSE,data)
  806. end
  807. local goods_name = self.goods_model:getGoodsName(cfg.target_goods_id, true)
  808. local view_data = {}
  809. view_data.ok_callback = ok
  810. view_data.goods_name = goods_name
  811. view_data.times = times
  812. view_data.cost_list = cost_list or {}
  813. self:Fire(ComposeEvent.OPEN_COMPOSE_COST_AWARD_TIP_VIEW,view_data)
  814. else
  815. local view_data = {}
  816. view_data.cost_list = can_not_buy_list or {}
  817. local content_desc = string.format("当前缺失<color=%s>无法购买的材料</color>\n\n\n\n\n\n<color=%s>没有办法直接补齐材料合成哦</color>",ColorUtil.RED_DARK,ColorUtil.RED_DARK)
  818. view_data.content_desc = content_desc
  819. self:Fire(ComposeEvent.OPEN_COMPOSE_COST_AWARD_TIP_VIEW,view_data)
  820. end
  821. end
  822. end
  823. end
  824. --获得守护或者饰品可以购买材料升品
  825. function ComposeModel:GetGuardOrOrnamentCanEvolution( equip_cfg )
  826. if not equip_cfg or not equip_cfg.goods_id then return end
  827. local compose_cfg = self:GetEvolutionComposeCfg(equip_cfg.goods_id)
  828. local limit_level = compose_cfg and compose_cfg.open_lv or 0
  829. local cost_list = RoleManager.Instance.mainRoleInfo.level >= limit_level and compose_cfg and compose_cfg.cost_goods or {}
  830. if cost_list and #cost_list > 0 then
  831. local shop_list = {}
  832. for kkk,vvv in ipairs(cost_list) do
  833. local goods_num = self.goods_model:GetTypeGoodsNum(vvv[2]) or 0
  834. if goods_num < vvv[3] then
  835. if self:GetShopCanBuyGoods(vvv) then--获得商城能否买道具
  836. else
  837. return false--如果有不能商城购买的消耗自己返回不能升品
  838. end
  839. end
  840. end
  841. return true
  842. end
  843. end
  844. --获得商城能否买道具
  845. function ComposeModel:GetShopCanBuyGoods( data )
  846. if not data or not data[2] then return end
  847. local goods_vo = self.goods_model:GetGoodsBasicByTypeId(data[2])
  848. if goods_vo then
  849. local cfg = ShopModel:getInstance():GetShopTypeIdBuyCFG(data[2])
  850. if cfg then
  851. cfg = DeepCopy(cfg)
  852. local new_data = {}
  853. for k,v in pairs(cfg) do
  854. new_data[#new_data + 1] = v
  855. end
  856. local sort_func = function ( a, b )
  857. return a.ctype > b.ctype
  858. end
  859. table.sort(new_data, sort_func)
  860. local quota_num = 0
  861. local jin = RoleManager.Instance.mainRoleInfo.jin--彩钻
  862. local jinLock = RoleManager.Instance.mainRoleInfo.jinLock--红钻
  863. local tong = RoleManager.Instance.mainRoleInfo.tong--交易券
  864. local honor = RoleManager.Instance.mainRoleInfo.honor--名望券
  865. local need_num = (data[3] or 1)--需要数量
  866. local have_num = self.goods_model:GetTypeGoodsNum(data[2]) or 0--拥有数量
  867. local need_price = 0
  868. local jin_enough = false
  869. for i,v in ipairs(new_data) do
  870. need_price = v.price * (need_num - have_num)
  871. --先判断钱够不够
  872. if v.ctype == 1 then--彩钻
  873. jin_enough = jin >= need_price
  874. elseif v.ctype == 2 then--红钻
  875. jin_enough = jinLock >= need_price
  876. elseif v.ctype == 3 then--交易券
  877. jin_enough = tong >= need_price
  878. elseif v.ctype == 4 then--名望券
  879. jin_enough = honor >= need_price
  880. end
  881. local shop_info = ShopModel:getInstance():GetGoodsShopInfoById(v.shop_type,v.sub_type,v.goods_id)
  882. if jin_enough then--如果钱够判断购买数量
  883. if v.quota_type > 0 and shop_info then--限购商品
  884. local left_num = v.quota_num - shop_info.sold_out
  885. if left_num >= need_num - have_num then
  886. return true
  887. end
  888. else--不限购
  889. return true
  890. end
  891. end
  892. end
  893. end
  894. end
  895. return false
  896. end
  897. --设置橙装合成跳转
  898. function ComposeModel:SetOrangeEquipComposeJumpInfo( type_id )
  899. if type_id == 108012 then--1代
  900. self.orange_jump_id = 801
  901. elseif type_id == 108022 then--2代
  902. self.orange_jump_id = 802
  903. elseif type_id == 108032 then--3代
  904. self.orange_jump_id = 803
  905. elseif type_id == 108042 then--4代
  906. self.orange_jump_id = 804
  907. elseif type_id == 108052 then--5代
  908. self.orange_jump_id = 805
  909. elseif type_id == 108062 then--6代
  910. self.orange_jump_id = 806
  911. end
  912. end