ItemCompoundProxy.lua 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  1. local RemoteProxy = requireProxy("remote/RemoteProxy")
  2. local ItemCompoundProxy = class("ItemCompoundProxy", RemoteProxy)
  3. ItemCompoundProxy.NAME = global.ProxyTable.ItemCompoundProxy
  4. --[[
  5. README:
  6. self.compoundNeedList = {
  7. [10000] = {
  8. 12,123
  9. }
  10. }
  11. Index 为10000的材料能合成 12 123号合成ID
  12. self.compoundState = {
  13. [12] = true,
  14. [123] = false
  15. }
  16. 当前是否满足合成条件 用于红点等
  17. self.compoundList = {
  18. }
  19. ]]
  20. function ItemCompoundProxy:ctor()
  21. ItemCompoundProxy.super.ctor(self)
  22. self.config = {}
  23. self.configByIndex = {}
  24. self.redPoint = false
  25. self.onCompoundIndex = 0
  26. self.lastCheckMoneyTime = 0
  27. self.changeMoneyList = {}
  28. self.lastCheckMoneyCount = {}
  29. self.compoundNeedList = {} -- 原材料
  30. self.moneyNeedList = {}
  31. self.equipPosList = {}
  32. self.compoundState = {} --
  33. self.compoundList = {}
  34. self.pageRedPoint = {}
  35. self.showItemList = {}
  36. self.pageName = {}
  37. self.effectList = {}
  38. self:LoadConfig()
  39. end
  40. function ItemCompoundProxy:onRegister()
  41. ItemCompoundProxy.super.onRegister(self)
  42. end
  43. function ItemCompoundProxy:LoadConfig()
  44. local ItemConfigProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemConfigProxy)
  45. self.config = {}
  46. local fileName = "cfg_makeitems.lua"
  47. if global.FileUtilCtl:isFileExist("scripts/game_config/" .. fileName) then
  48. self.config = requireGameConfig("cfg_makeitems")
  49. end
  50. for k, item in pairs(self.config) do
  51. self.configByIndex[item.id] = item
  52. local pageIndex = item.page1 * 1000 + item.page2
  53. if not self.showItemList[pageIndex] then
  54. self.showItemList[pageIndex] = {}
  55. end
  56. self.pageName[item.page1] = item.page1name
  57. self.pageName[pageIndex] = item.page2name
  58. local moneyCost = {}
  59. local materialCost = {}
  60. local material = item.material
  61. local itemList = string.split(material or "", "&")
  62. for _, cost in pairs(itemList) do
  63. if cost and cost ~= "" then
  64. local costData = string.split(cost, "#")
  65. local costID = tonumber(costData[1])
  66. local costCount = tonumber(costData[2])
  67. table.insert(materialCost, {
  68. id = costID,
  69. count = costCount
  70. })
  71. if not self.compoundNeedList[costID] then
  72. self.compoundNeedList[costID] = {}
  73. end
  74. self.compoundNeedList[costID][item.id] = costCount
  75. local isBind, bindIndex = ItemConfigProxy:CheckItemBind(costID)
  76. if isBind and bindIndex and bindIndex ~= costID then
  77. if not self.compoundNeedList[bindIndex] then
  78. self.compoundNeedList[bindIndex] = {}
  79. end
  80. self.compoundNeedList[bindIndex][item.id] = costCount
  81. end
  82. end
  83. end
  84. local moneyList = string.split(item.CYquantity or "", "&")
  85. for _, cost in pairs(moneyList) do
  86. if cost and cost ~= "" then
  87. local costData = string.split(cost, "#")
  88. local costID = tonumber(costData[1])
  89. local costCount = tonumber(costData[2])
  90. if not self.moneyNeedList[costID] then
  91. self.moneyNeedList[costID] = {}
  92. end
  93. table.insert(moneyCost, {
  94. id = costID,
  95. count = costCount
  96. })
  97. self.moneyNeedList[costID][item.id] = costCount
  98. local isBind, bindIndex = ItemConfigProxy:CheckItemBind(costID)
  99. if isBind and bindIndex and bindIndex ~= costID then
  100. if not self.moneyNeedList[bindIndex] then
  101. self.moneyNeedList[bindIndex] = {}
  102. end
  103. self.moneyNeedList[bindIndex][item.id] = costCount
  104. end
  105. end
  106. end
  107. local equipPosCheck = item.isstamode
  108. if equipPosCheck and equipPosCheck ~= "" then
  109. local posListStr = string.split(equipPosCheck, "#")
  110. local posList = {}
  111. for i, v in ipairs(posListStr) do
  112. local pos = tonumber(v)
  113. if not self.equipPosList[pos] then
  114. self.equipPosList[pos] = {}
  115. end
  116. self.equipPosList[pos][item.id] = item.id
  117. table.insert(posList, pos)
  118. end
  119. item.posList = posList
  120. end
  121. local itemGet = item.product
  122. if itemGet then
  123. local itemGetData = string.split(itemGet, "#")
  124. local itemID = tonumber(itemGetData[1])
  125. local itemCount = tonumber(itemGetData[2])
  126. item.production = {
  127. id = itemID,
  128. count = itemCount
  129. }
  130. end
  131. item.moneycost = moneyCost
  132. item.materialcost = materialCost
  133. table.insert(self.showItemList[pageIndex], item)
  134. end
  135. local showConfig = SL:GetMetaValue("GAME_DATA","itemiconeffect")
  136. if showConfig and showConfig ~= "" then
  137. local effectType = string.split(showConfig, "|")
  138. for k, v in ipairs(effectType) do
  139. local effctAndList = string.split(v, "&")
  140. local listStr = effctAndList[1]
  141. local effectId = tonumber(effctAndList[2])
  142. local indexList = string.split(listStr, "#")
  143. for _, index in ipairs(indexList) do
  144. local comIndex = tonumber(index)
  145. self.effectList[comIndex] = effectId
  146. end
  147. end
  148. end
  149. end
  150. function ItemCompoundProxy:CheckStrConditions(condition)
  151. if not condition or condition == "" then
  152. return true
  153. end
  154. local RedPointProxy = global.Facade:retrieveProxy(global.ProxyTable.RedPointProxy)
  155. return RedPointProxy:CheckStrConditions(condition)
  156. end
  157. function ItemCompoundProxy:IsStrengIgnore(Index)
  158. if not Index then
  159. return false
  160. end
  161. local ItemConfigProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemConfigProxy)
  162. local cfg = ItemConfigProxy:GetItemDataByIndex(Index)
  163. local StdMode = cfg.StdMode
  164. if not StdMode then
  165. return false
  166. end
  167. local ItemManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemManagerProxy)
  168. local Item_Type = ItemManagerProxy:GetItemSettingType()
  169. local itemType = ItemManagerProxy:GetItemType(cfg)
  170. if itemType == Item_Type.Equip then -- 装备类型的强化都要忽略合成材料
  171. return true
  172. end
  173. return false
  174. end
  175. function ItemCompoundProxy:CheckListIsShow(page1, page2)
  176. for pageIndex, itemList in pairs(self.showItemList) do
  177. if math.floor(pageIndex / 1000) == page1 and ((not page2) or page2 == pageIndex) then
  178. for k, v in pairs(itemList) do
  179. local isShow = self:CheckStrConditions(v.showcondition)
  180. if isShow then
  181. return isShow
  182. end
  183. end
  184. end
  185. end
  186. return false
  187. end
  188. function ItemCompoundProxy:CheckCompoudListState(page1, page2)
  189. for pageIndex, itemList in pairs(self.showItemList) do
  190. if math.floor(pageIndex / 1000) == page1 and ((not page2) or page2 == pageIndex) then
  191. for k, v in pairs(itemList) do
  192. local isShow = self:GetCompoundStateByIndex(v.id)
  193. if isShow then
  194. return isShow
  195. end
  196. end
  197. end
  198. end
  199. return false
  200. end
  201. function ItemCompoundProxy:GetPageIndexByID(id)
  202. if not id then
  203. return
  204. end
  205. for pageIndex, itemList in pairs(self.showItemList) do
  206. for k, v in pairs(itemList) do
  207. if v.id == id then
  208. return pageIndex
  209. end
  210. end
  211. end
  212. return nil
  213. end
  214. function ItemCompoundProxy:GetPageName(pageIndex)
  215. return self.pageName[pageIndex]
  216. end
  217. function ItemCompoundProxy:OnItemChange(Index, isAdd)
  218. local PayProxy = global.Facade:retrieveProxy(global.ProxyTable.PayProxy)
  219. local needThisMaterialList = self.compoundNeedList[Index]
  220. if needThisMaterialList and next(needThisMaterialList) then -- 材料对应的列表
  221. for id, count in pairs(needThisMaterialList) do
  222. local state = clone(self.compoundState[id]) -- 根据增删,对应检测 增 检测原来不满足 删 检测原来满足
  223. if (not state and isAdd) or (state and not isAdd) then
  224. local compoundData = self:GetCompoundConfigByIndex(id)
  225. local materialCost = compoundData.materialcost or {}
  226. local isCanCompound = true
  227. local hongdian = compoundData.hongdian
  228. if isCanCompound and hongdian then
  229. if hongdian == -1 then
  230. isCanCompound = false
  231. else
  232. isCanCompound = self:CheckStrConditions(hongdian)
  233. end
  234. end
  235. local showcondition = compoundData.showcondition
  236. if isCanCompound and showcondition then
  237. isCanCompound = self:CheckStrConditions(showcondition)
  238. end
  239. local posList = compoundData.posList
  240. if isCanCompound and next(materialCost) then
  241. for _, costItem in pairs(materialCost) do
  242. isCanCompound = PayProxy:CheckItemCount(costItem.id, costItem.count, true, true)
  243. if not isCanCompound then
  244. break
  245. end
  246. end
  247. end
  248. local moneyCost = compoundData.moneycost or {}
  249. if isCanCompound and next(moneyCost) then
  250. for _, costItem in pairs(moneyCost) do
  251. local moneyID = costItem.id
  252. isCanCompound = PayProxy:CheckItemCount(moneyID, costItem.count, true, true)
  253. if not isCanCompound then
  254. break
  255. end
  256. end
  257. end
  258. local compCondition = compoundData.condition
  259. if isCanCompound and compCondition then
  260. isCanCompound = self:CheckStrConditions(compCondition)
  261. end
  262. if isCanCompound then
  263. self.redPoint = true
  264. end
  265. self.compoundState[id] = isCanCompound
  266. end
  267. local nowState = clone(self.compoundState[id])
  268. local upData = {
  269. stateChange = nowState,
  270. id = id,
  271. isAdd = isAdd
  272. }
  273. global.Facade:sendNotification(global.NoticeTable.Layer_CompoundItemLayer_Update, upData)
  274. end
  275. end
  276. end
  277. function ItemCompoundProxy:OnEquipChange(pos)
  278. local PayProxy = global.Facade:retrieveProxy(global.ProxyTable.PayProxy)
  279. local equipPosList = self.equipPosList[pos]
  280. if equipPosList and next(equipPosList) then -- 位置对应
  281. for id, count in pairs(equipPosList) do
  282. local state = clone(self.compoundState[id])
  283. local compoundData = self:GetCompoundConfigByIndex(id)
  284. local materialCost = compoundData.materialcost or {}
  285. local isCanCompound = true
  286. local showcondition = compoundData.showcondition
  287. if isCanCompound and showcondition then
  288. isCanCompound = self:CheckStrConditions(showcondition)
  289. end
  290. local hongdian = compoundData.hongdian
  291. if isCanCompound and hongdian then
  292. if hongdian == -1 then
  293. isCanCompound = false
  294. else
  295. isCanCompound = self:CheckStrConditions(hongdian)
  296. end
  297. end
  298. if isCanCompound and next(materialCost) then
  299. for _, costItem in pairs(materialCost) do
  300. local checkEquipCount = (compoundData.posList and next(compoundData.posList))
  301. isCanCompound = PayProxy:CheckItemCount(costItem.id, costItem.count, true, true)
  302. if not isCanCompound then
  303. break
  304. end
  305. end
  306. end
  307. local moneyCost = compoundData.moneycost or {}
  308. if isCanCompound and next(moneyCost) then
  309. for _, costItem in pairs(moneyCost) do
  310. local moneyID = costItem.id
  311. isCanCompound = PayProxy:CheckItemCount(moneyID, costItem.count, true, true, false)
  312. if not isCanCompound then
  313. break
  314. end
  315. end
  316. end
  317. local compCondition = compoundData.condition
  318. if isCanCompound and compCondition then
  319. isCanCompound = self:CheckStrConditions(compCondition)
  320. end
  321. if isCanCompound then
  322. self.redPoint = true
  323. end
  324. self.compoundState[id] = isCanCompound
  325. local nowState = clone(self.compoundState[id])
  326. local upData = {
  327. stateChange = state ~= nowState,
  328. id = id
  329. }
  330. global.Facade:sendNotification(global.NoticeTable.Layer_CompoundItemLayer_Update, upData)
  331. end
  332. end
  333. end
  334. function ItemCompoundProxy:OnMoneyChange(Index, isAdd)
  335. local BagProxy = global.Facade:retrieveProxy(global.ProxyTable.Bag)
  336. local PayProxy = global.Facade:retrieveProxy(global.ProxyTable.PayProxy)
  337. local needThisMoneyList = self.moneyNeedList[Index]
  338. if needThisMoneyList and next(needThisMoneyList) then -- 材料对应的列表
  339. for id, count in pairs(needThisMoneyList) do
  340. local state = clone(self.compoundState[id]) -- 根据增删,对应检测 增 检测原来不满足 删 检测原来满足
  341. if (not state and isAdd) or (state and not isAdd) then
  342. local compoundData = self:GetCompoundConfigByIndex(id)
  343. local materialCost = compoundData.materialcost or {}
  344. local isCanCompound = true
  345. local showcondition = compoundData.showcondition
  346. if isCanCompound and showcondition then
  347. isCanCompound = self:CheckStrConditions(showcondition)
  348. end
  349. local hongdian = compoundData.hongdian
  350. if isCanCompound and hongdian then
  351. if hongdian == -1 then
  352. isCanCompound = false
  353. else
  354. isCanCompound = self:CheckStrConditions(hongdian)
  355. end
  356. end
  357. if isCanCompound and next(materialCost) then
  358. for _, costItem in pairs(materialCost) do
  359. local checkEquipCount = (compoundData.posList and next(compoundData.posList))
  360. isCanCompound = PayProxy:CheckItemCount(costItem.id, costItem.count, true, true)
  361. if not isCanCompound then
  362. break
  363. end
  364. end
  365. end
  366. local moneyCost = compoundData.moneycost or {}
  367. if isCanCompound and next(moneyCost) then
  368. for _, costItem in pairs(moneyCost) do
  369. local moneyID = costItem.id
  370. isCanCompound = PayProxy:CheckItemCount(moneyID, costItem.count, true, true, true)
  371. if not isCanCompound then
  372. break
  373. end
  374. end
  375. end
  376. local compCondition = compoundData.condition
  377. if isCanCompound and compCondition then
  378. isCanCompound = self:CheckStrConditions(compCondition)
  379. end
  380. if isCanCompound then
  381. self.redPoint = true
  382. end
  383. self.compoundState[id] = isCanCompound
  384. end
  385. local nowState = clone(self.compoundState[id])
  386. local upData = {
  387. stateChange = state ~= nowState,
  388. id = id
  389. }
  390. global.Facade:sendNotification(global.NoticeTable.Layer_CompoundItemLayer_Update, upData)
  391. end
  392. end
  393. end
  394. --[[
  395. 避免货币频繁变动导致检测过于频繁
  396. 10秒内不重复检测
  397. CD内的变动在delay中检测
  398. ]]
  399. function ItemCompoundProxy:OnMoneyChangeCount(Index, count)
  400. local serverTime = GetServerTime()
  401. if Index == 2 then -- 元宝类型改成绑定元宝类型检测(消耗货币只检测绑定元宝, 但是元宝又可以和绑定元宝一起消耗)
  402. Index = 4
  403. end
  404. self.changeMoneyList[Index] = count
  405. if not self.onMoneyChangeUpdate then
  406. PerformWithDelayGlobal(function()
  407. local nowServerTime = GetServerTime()
  408. for k, v in pairs(self.changeMoneyList) do
  409. local oldCount = self.lastCheckMoneyCount[k] or 0
  410. local newCount = v
  411. if v ~= oldCount then
  412. self:OnMoneyChange(k, v > oldCount)
  413. end
  414. self.lastCheckMoneyCount[k] = newCount
  415. end
  416. self.changeMoneyList = {}
  417. self.lastCheckMoneyTime = nowServerTime
  418. self.onMoneyChangeUpdate = nil
  419. end, 5)
  420. self.onMoneyChangeUpdate = true
  421. end
  422. if serverTime > (self.lastCheckMoneyTime + 5) or serverTime < self.lastCheckMoneyTime then
  423. for k, v in pairs(self.changeMoneyList) do
  424. local oldCount = self.lastCheckMoneyCount[k] or 0
  425. local newCount = v
  426. if v ~= oldCount then
  427. self:OnMoneyChange(k, v > oldCount)
  428. end
  429. self.lastCheckMoneyCount[k] = newCount
  430. end
  431. self.changeMoneyList = {}
  432. self.lastCheckMoneyTime = serverTime
  433. end
  434. end
  435. function ItemCompoundProxy:SetOnCompoundIndex(Index)
  436. self.onCompoundIndex = Index
  437. end
  438. function ItemCompoundProxy:GetOnCompoundIndex()
  439. return self.onCompoundIndex
  440. end
  441. function ItemCompoundProxy:GetOnCompoundData()
  442. local onCompoundIndex = self:GetOnCompoundIndex()
  443. local data = self:GetCompoundConfigByIndex(onCompoundIndex)
  444. return data
  445. end
  446. function ItemCompoundProxy:CheckCompoudState()
  447. return self.redPoint
  448. end
  449. function ItemCompoundProxy:GetCompoundStateByIndex(Index)
  450. return self.compoundState[Index]
  451. end
  452. function ItemCompoundProxy:GetCompoundConfig()
  453. return self.config
  454. end
  455. function ItemCompoundProxy:GetShowItemList(menulayertype)
  456. local typeList = {}
  457. menulayertype = menulayertype or 0
  458. for k, list in pairs(self.showItemList) do
  459. for i, item in ipairs(list) do
  460. local itemMenulayertype = item.menulayertype or 0
  461. if itemMenulayertype == menulayertype then
  462. if not typeList[k] then
  463. typeList[k] = {}
  464. end
  465. table.insert(typeList[k], item)
  466. end
  467. end
  468. end
  469. local sortTypeList = {}
  470. if typeList and next(typeList) then
  471. for k, v in pairs(typeList) do
  472. if #v > 1 then
  473. table.sort(v, function(item1, item2)
  474. return item1.page3 < item2.page3
  475. end)
  476. end
  477. sortTypeList[k] = v
  478. end
  479. else
  480. sortTypeList = typeList
  481. end
  482. return sortTypeList
  483. end
  484. function ItemCompoundProxy:GetShowItemListByIndex(PageIndex, menulayertype)
  485. local pageData = self:GetShowItemList(menulayertype)
  486. return pageData[PageIndex]
  487. end
  488. function ItemCompoundProxy:GetCompoundConfigByIndex(Index)
  489. return self.configByIndex[Index]
  490. end
  491. function ItemCompoundProxy:GetCompoundEffect(Index)
  492. return self.effectList[Index]
  493. end
  494. function ItemCompoundProxy:CheckIsCanCompoud(item, isTips, isSystemTips)
  495. if not item then
  496. return
  497. end
  498. local PayProxy = global.Facade:retrieveProxy(global.ProxyTable.PayProxy)
  499. local EquipProxy = global.Facade:retrieveProxy(global.ProxyTable.Equip)
  500. local materialCost = item.materialcost or {}
  501. local compoundCount = nil
  502. local takeoffPlayerEquip = {}
  503. if isTips ~= true then
  504. isTips = false
  505. end
  506. local checkEquipCount = (item.posList and next(item.posList))
  507. if next(materialCost) then
  508. for _, costItem in pairs(materialCost) do
  509. local costDataNotips = {
  510. itemID = costItem.id,
  511. itemNum = costItem.count,
  512. noTips = true
  513. }
  514. local isCanCompound = CheckItemCountEnoughEX(costDataNotips)
  515. local costDataWithEquip = {
  516. itemID = costItem.id,
  517. itemNum = costItem.count,
  518. equipCount = checkEquipCount,
  519. noTips = true
  520. }
  521. local itemWithEquip = CheckItemCountEnoughEX(costDataWithEquip)
  522. if not itemWithEquip and not isCanCompound then
  523. local costData = {
  524. itemID = costItem.id,
  525. itemNum = costItem.count,
  526. equipCount = checkEquipCount,
  527. noTips = not isTips,
  528. errorTitle = isSystemTips and GET_STRING(90090011) or nil
  529. }
  530. CheckItemCountEnoughEX(costData)
  531. return false
  532. end
  533. local itemHaveNum = PayProxy:GetItemCount(costItem.id, true)
  534. local canCompoundCount = math.floor(itemHaveNum / costItem.count)
  535. compoundCount = compoundCount and math.min(compoundCount, canCompoundCount) or canCompoundCount
  536. end
  537. end
  538. local moneyCost = item.moneycost or {}
  539. if next(moneyCost) then
  540. for _, costItem in pairs(moneyCost) do
  541. local costData = {
  542. itemID = costItem.id,
  543. itemNum = costItem.count,
  544. noTips = not isTips,
  545. bOneID = true,
  546. errorTitle = isSystemTips and GET_STRING(90090011) or nil
  547. }
  548. local isCanCompound = CheckItemCountEnoughEX(costData)
  549. if not isCanCompound then
  550. return false
  551. end
  552. local itemHaveNum = PayProxy:GetItemCount(costData.itemID, true)
  553. local canCompoundCount = math.floor(itemHaveNum / costItem.count)
  554. compoundCount = compoundCount and math.min(compoundCount, canCompoundCount) or canCompoundCount
  555. end
  556. end
  557. local condition = item.condition
  558. if condition then
  559. if not self:CheckStrConditions(condition) then
  560. return false
  561. end
  562. end
  563. local itemProduct = item.product
  564. if not itemProduct or itemProduct == "" then
  565. return false
  566. end
  567. local needPos = 0
  568. local itemArray = string.split(itemProduct, "&")
  569. for i, itemGet in ipairs(itemArray) do
  570. if itemGet and itemGet ~= "" then
  571. local itemGetData = string.split(itemGet, "#")
  572. local itemID = tonumber(itemGetData[1])
  573. local itemCount = tonumber(itemGetData[2])
  574. local ItemConfigProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemConfigProxy)
  575. local itemData = ItemConfigProxy:GetItemDataByIndex(itemID)
  576. local isLap = ItemConfigProxy:CheckItemOverLap(itemData)
  577. if itemID > 100 then -- 货币占格子
  578. if isLap then
  579. needPos = needPos + 1 -- math.ceil(itemCount/itemData.OverLap)
  580. else
  581. needPos = needPos + itemCount
  582. end
  583. end
  584. end
  585. end
  586. local BagProxy = global.Facade:retrieveProxy(global.ProxyTable.Bag)
  587. local bagItemNum = BagProxy:GetTotalItemCount()
  588. local maxBag = BagProxy:GetMaxBag()
  589. if bagItemNum + needPos > maxBag then
  590. if isSystemTips then
  591. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(800050))
  592. end
  593. return false
  594. end
  595. return true, compoundCount, takeoffPlayerEquip
  596. end
  597. function ItemCompoundProxy:RequestCompound()
  598. local item = self:GetOnCompoundData()
  599. if not item then
  600. return
  601. end
  602. local compoundID = item.id
  603. local isCanCompound, compoudNum, equipList = self:CheckIsCanCompoud(item, true, true)
  604. if not isCanCompound then
  605. return
  606. end
  607. local itemGet = item.product
  608. local itemGetData = string.split(itemGet, "#")
  609. local itemID = tonumber(itemGetData[1])
  610. local itemCount = tonumber(itemGetData[2])
  611. local ItemConfigProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemConfigProxy)
  612. local ItemManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemManagerProxy)
  613. local itemData = ItemConfigProxy:GetItemDataByIndex(itemID)
  614. local isEquip = ItemManagerProxy:GetItemTypeByStdMode(itemData.StdMode) == ItemManagerProxy.ItemType.Equip
  615. if item.hecheng and item.hecheng > 0 and compoudNum > 1 then
  616. local function callback(num)
  617. num = tonumber(num)
  618. if not num or num <= 0 then
  619. return
  620. end
  621. if num > compoudNum then
  622. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(90020007))
  623. else
  624. self:SureCompound(item, num, equipList)
  625. end
  626. end
  627. local itemShwoArray = string.split(item.shwo or "", "#")
  628. local produceItemID = tonumber(itemShwoArray[1])
  629. local count = tonumber(itemShwoArray[2])
  630. local data = {}
  631. data.title = GET_STRING(90090012)
  632. data.maxNum = compoudNum
  633. data.callback = callback
  634. data.Index = produceItemID
  635. data.count = count
  636. data.notValidTitle = GET_STRING(90020007)
  637. global.Facade:sendNotification(global.NoticeTable.Layer_CommonNumber_Open, data)
  638. else
  639. compoudNum = 1
  640. self:SureCompound(item, compoudNum, equipList)
  641. end
  642. end
  643. function ItemCompoundProxy:SureCompound(item, num, equipList)
  644. if item.confirmtype and item.confirmtype > 0 then
  645. local function callback(btnType)
  646. if btnType == 1 then
  647. self:ChooseItemToCompound(item, num, equipList)
  648. end
  649. end
  650. local ItemConfigProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemConfigProxy)
  651. local produceItem = item.shwo
  652. local produceItemName = item.page3name
  653. if not produceItemName or produceItemName == "" then
  654. local produceItemID = tonumber(string.split(produceItem, "#")[1])
  655. produceItemName = ItemConfigProxy:GetItemName(produceItemID)
  656. end
  657. local data = {}
  658. data.str = string.format(GET_STRING(90090002), SL:GetMetaValue("GAME_DATA", "DEFAULT_FONT_SIZE"), produceItemName)
  659. data.callback = callback
  660. data.btnType = 2
  661. global.Facade:sendNotification(global.NoticeTable.Layer_CommonTips_Open, data)
  662. else
  663. self:ChooseItemToCompound(item, num, equipList)
  664. end
  665. end
  666. function ItemCompoundProxy:ChooseItemToCompound(item, num, equipList)
  667. local isShowChooseLayer = item.choice
  668. local compoundID = item.id
  669. --[[
  670. 需要玩家选择的道具
  671. 规则逻辑
  672. 所需的装备材料如果多 不能合 必须材料数刚好满足
  673. 选择了
  674. - > 合成
  675. ]]
  676. if isShowChooseLayer and isShowChooseLayer == 1 then
  677. local needItems = item.materialcost
  678. local BagProxy = global.Facade:retrieveProxy(global.ProxyTable.Bag)
  679. local EquipProxy = global.Facade:retrieveProxy(global.ProxyTable.Equip)
  680. local ItemConfigProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemConfigProxy)
  681. local ItemManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemManagerProxy)
  682. for k, v in pairs(needItems) do
  683. local itemID = v.id
  684. local itemData = ItemConfigProxy:GetItemDataByIndex(itemID)
  685. local isEquip = ItemManagerProxy:GetItemTypeByStdMode(itemData.StdMode) == ItemManagerProxy.ItemType.Equip
  686. if isEquip then
  687. local hasCount = GetItemDataNumber(itemID, {
  688. equip = true,
  689. specialMoney = true
  690. })
  691. local needCount = v.count
  692. if hasCount ~= needCount then
  693. ShowSystemTips(GET_STRING(90090004))
  694. return
  695. end
  696. end
  697. end
  698. end
  699. if equipList and next(equipList) then
  700. for k, v in pairs(equipList) do
  701. global.Facade:sendNotification(global.NoticeTable.TakeOffRequest, v)
  702. end
  703. end
  704. self:requestCompoundJson(compoundID)
  705. end
  706. -- 检测红点
  707. function ItemCompoundProxy:BadgeCheckFunc(type)
  708. local checkType = type or 0
  709. for i, v in pairs(self.compoundState) do
  710. local config = self:GetCompoundConfigByIndex(i) or {}
  711. local itemType = config.menulayertype or 0
  712. if v and itemType == checkType then
  713. return true
  714. end
  715. end
  716. return false
  717. end
  718. -- 打开不同的合成通知一下脚本
  719. function ItemCompoundProxy:requestCompoundChangeJson(data)
  720. print("=========打开不同的合成Json: id, methods, data: ", global.JsonMsgType.CompoundChange,
  721. global.ActMessageTable.CompoundItem, data)
  722. global.JsonProtoHelper:SendMsg(global.JsonMsgType.CompoundChange, 1, global.ActMessageTable.CompoundItem, nil, data)
  723. end
  724. function ItemCompoundProxy:requestCompoundJson(data)
  725. print("=========请求合成Json: id, methods, data: ", global.JsonMsgType.CompoundItem,
  726. global.ActMessageTable.CompoundItem, data)
  727. global.JsonProtoHelper:SendMsg(global.JsonMsgType.CompoundItem, 1, global.ActMessageTable.CompoundItem, nil, data)
  728. end
  729. function ItemCompoundProxy:event(data)
  730. print("=========接收合成Json: id, methods, data: ", data)
  731. if not data then
  732. return
  733. end
  734. dump(data, "__SS")
  735. local recog = data.recog
  736. local id = data.param1
  737. if recog == 0 then
  738. -- success
  739. local cfg = id and self:GetCompoundConfigByIndex(id) or {}
  740. global.Facade:sendNotification(global.NoticeTable.SystemTips, cfg.CGmessage or "")
  741. elseif recog == -1 or recog == -2 then
  742. -- failed
  743. local cfg = id and self:GetCompoundConfigByIndex(id) or {}
  744. global.Facade:sendNotification(global.NoticeTable.SystemTips, cfg.SBmessage or "")
  745. end
  746. end
  747. function ItemCompoundProxy:RegisterMsgHandler()
  748. ItemCompoundProxy.super.RegisterMsgHandler(self)
  749. local msgType = global.MsgType
  750. global.JsonProtoHelper:RegisterJsonHandler(global.JsonMsgType.CompoundItem, self)
  751. end
  752. return ItemCompoundProxy