ItemRecycling_1.lua 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. ItemRecycling = {}
  2. local this = {}
  3. local ItemRecyclingType = {
  4. PIN_JIE = 1,
  5. ZHUO_YUE = 2,
  6. ZHI_YE = 3
  7. }
  8. ITEM_RECYCLING_TYPE = "R$itemRecyclingTYPE"
  9. -- 合服时取消所有选择的回收类型
  10. function ItemRecycling.combineglobalvar(varName)
  11. local allWorldGoods = getsysvar(ITEM_RECYCLING_TYPE)
  12. if table.isEmpty(allWorldGoods) then
  13. return
  14. end
  15. setsysvar(ITEM_RECYCLING_TYPE, {})
  16. end
  17. -- 分解
  18. function ItemRecycling.decompositionlua(actor, msgID, msgData)
  19. -- local decompositionItemList = msgData[1]
  20. -- local allItemInfo = getallbagiteminfo(actor)
  21. -- if table.isEmpty(allItemInfo) then
  22. -- return
  23. -- end
  24. -- if table.isEmpty(decompositionItemList) then
  25. -- return
  26. -- end
  27. -- local allequip = getplaydef(actor, "T$luaitemextdata")
  28. -- local allNeedMaterial = {}
  29. -- local allObtainList = {}
  30. -- for bagIndex, count in pairs(decompositionItemList) do
  31. -- for _, itemInfo in pairs(allItemInfo) do
  32. -- if itemInfo.bagindex == tonumber(bagIndex) then
  33. -- local itemCfgId = itemInfo.cfgid
  34. -- local decomposeGroup = ConfigDataManager.getTableValue("cfg_item", "decomposeGroup", "id", itemCfgId)
  35. -- if string.isNullOrEmpty(decomposeGroup) then
  36. -- tipinfo(actor, "选择的道具中拥有不能分解的道具,请重新选择")
  37. -- return
  38. -- end
  39. -- local decomposeTable = ConfigDataManager.getTable("cfg_recovery_out", "id", decomposeGroup)
  40. -- if table.isEmpty(decomposeTable) then
  41. -- -- error(actor,"分解类型配置错误")
  42. -- return
  43. -- end
  44. -- if not table.isNullOrEmpty(allequip) then
  45. -- local equipext = allequip[tonumber(itemInfo.id)]
  46. -- if not table.isNullOrEmpty(equipext) then
  47. -- allequip[tonumber(itemInfo.id)] = nil
  48. -- end
  49. -- end
  50. -- local decomposeInfo = decomposeTable[1]
  51. -- -- 计算分解需要的东西
  52. -- local needMaterial = decomposeInfo.needmaterial
  53. -- if not string.isNullOrEmpty(needMaterial) then
  54. -- local needMaterialInfo = string.split(needMaterial, "#")
  55. -- local needMaterialCount = allNeedMaterial[needMaterialInfo[1]]
  56. -- if not needMaterialCount then
  57. -- needMaterialCount = 0
  58. -- end
  59. -- allNeedMaterial[needMaterialInfo[1]] = needMaterialCount + (tonumber(needMaterialInfo[2]) * count)
  60. -- end
  61. -- -- 计算分解获得的东西
  62. -- local material = decomposeInfo.material
  63. -- local group = decomposeInfo.group
  64. -- if tonumber(group) == 2 then
  65. -- if not string.isNullOrEmpty(material) then
  66. -- local allObtainTable = string.split(material, "|")
  67. -- if not table.isEmpty(allObtainTable) then
  68. -- if table.count(allObtainTable) == 1 then
  69. -- -- 分解只会获得一种物品
  70. -- local obtainInfo = string.split(allObtainTable[1], "#")
  71. -- local obtainCount = allObtainList[obtainInfo[1]]
  72. -- if obtainCount == nil then
  73. -- obtainCount = 0
  74. -- end
  75. -- local total = obtainCount + (tonumber(obtainInfo[2]) * count)
  76. -- allObtainList[obtainInfo[1]] = total
  77. -- else
  78. -- -- 分解获得物品配置权重
  79. -- local allWeight = 0
  80. -- local newAllObtainTable = {}
  81. -- for _, obtainInfo in pairs(allObtainTable) do
  82. -- local obtainWeight = string.split(obtainInfo, "#")
  83. -- allWeight = allWeight + tonumber(obtainWeight[3])
  84. -- obtainWeight[3] = allWeight
  85. -- table.insert(newAllObtainTable, obtainWeight)
  86. -- end
  87. -- for i = 1, count do
  88. -- local successIndex = math.random(1, allWeight)
  89. -- local lastWeight = 0
  90. -- for _, newObtainInfo in pairs(newAllObtainTable) do
  91. -- if lastWeight < successIndex and newObtainInfo[3] >= successIndex then
  92. -- local obtainCount = allObtainList[newObtainInfo[1]]
  93. -- if obtainCount == nil then
  94. -- obtainCount = 0
  95. -- end
  96. -- allObtainList[newObtainInfo[1]] = obtainCount + (tonumber(newObtainInfo[2]))
  97. -- end
  98. -- lastWeight = newObtainInfo[3]
  99. -- end
  100. -- end
  101. -- end
  102. -- end
  103. -- end
  104. -- else
  105. -- if not string.isNullOrEmpty(material) then
  106. -- local allObtainTable = string.split(material, "|")
  107. -- for _, obtainInfo in pairs(allObtainTable) do
  108. -- local obtainItemInfo = string.split(obtainInfo, "#")
  109. -- local obtainCount = allObtainList[obtainItemInfo[1]]
  110. -- if obtainCount == nil then
  111. -- obtainCount = 0
  112. -- end
  113. -- local total = obtainCount + (tonumber(obtainItemInfo[2]) * count)
  114. -- allObtainList[obtainItemInfo[1]] = total
  115. -- end
  116. -- end
  117. -- end
  118. -- end
  119. -- end
  120. -- end
  121. -- itemdecomposition(actor, decompositionItemList, allObtainList, allNeedMaterial)
  122. -- sendluamsg(actor, LuaMessageIdToClient.RES_ITEM_DECOMPOSITION, allObtainList)
  123. -- setplaydef(actor, "T$luaitemextdata", allequip)
  124. local decompositionItemList = msgData[1]
  125. local allItemInfo = getallbagiteminfo(actor)
  126. if table.isEmpty(allItemInfo) then
  127. return
  128. end
  129. if table.isEmpty(decompositionItemList) then
  130. return
  131. end
  132. local cfgs = ConfigDataManager.getTable("cfg_recovery_out")
  133. local allequip = getplaydef(actor, "T$luaitemextdata")
  134. local allNeedMaterial = {}
  135. local allObtainList = {}
  136. for bagIndex, count in pairs(decompositionItemList) do
  137. for _, itemInfo in pairs(allItemInfo) do
  138. if itemInfo.bagindex == tonumber(bagIndex) then
  139. -- local itemCfgId = itemInfo.cfgid
  140. local cfgItem = ConfigDataManager.getById("cfg_item", itemInfo.cfgid)
  141. local isMatchCfg, cfgRecovery = table.findByCondi(cfgs, function(a)
  142. if string.isNullOrEmpty(a.needmaterial) then
  143. return false
  144. end
  145. local ss = string.split(a.needmaterial, "#")
  146. if table.count(ss) <= 0 then
  147. return false
  148. end
  149. return tonumber(ss[1]) == itemInfo.cfgid;
  150. end)
  151. -- local decomposeGroup = ConfigDataManager.getTableValue("cfg_item", "decomposeGroup", "id", itemCfgId)
  152. if isMatchCfg == nil or cfgItem == nil then
  153. tipinfo(actor, "选择的道具中拥有不能分解的道具,请重新选择")
  154. return
  155. end
  156. local decomposeTable = cfgRecovery
  157. if table.isEmpty(decomposeTable) then
  158. -- error(actor,"分解类型配置错误")
  159. return
  160. end
  161. if not table.isNullOrEmpty(allequip) then
  162. local equipext = allequip[tonumber(itemInfo.id)]
  163. if not table.isNullOrEmpty(equipext) then
  164. allequip[tonumber(itemInfo.id)] = nil
  165. end
  166. end
  167. local decomposeInfo = decomposeTable
  168. -- 计算分解需要的东西
  169. local needMaterial = decomposeInfo.needmaterial
  170. if not string.isNullOrEmpty(needMaterial) then
  171. local needMaterialInfo = string.split(needMaterial, "#")
  172. local needMaterialCount = allNeedMaterial[needMaterialInfo[1]]
  173. if not needMaterialCount then
  174. needMaterialCount = 0
  175. end
  176. allNeedMaterial[needMaterialInfo[1]] = needMaterialCount + (tonumber(needMaterialInfo[2]) * count)
  177. end
  178. -- 计算分解获得的东西
  179. local material = decomposeInfo.material
  180. if not string.isNullOrEmpty(material) then
  181. local allObtainTable = string.split(material, "|")
  182. for _, obtainInfo in pairs(allObtainTable) do
  183. local obtainItemInfo = string.split(obtainInfo, "#")
  184. local obtainCount = allObtainList[obtainItemInfo[1]]
  185. if obtainCount == nil then
  186. obtainCount = 0
  187. end
  188. local total = obtainCount + (tonumber(obtainItemInfo[2]) * count)
  189. allObtainList[obtainItemInfo[1]] = total
  190. end
  191. end
  192. local entrymaterial = decomposeInfo.entrymaterial
  193. if not string.isNullOrEmpty(entrymaterial) and cfgItem.type == "2" then
  194. local enyrys = itemInfo.entries
  195. local rr = string.split(entrymaterial, "|")
  196. for i, v in ipairs(rr) do
  197. local materiald = string.split(v, "#")
  198. local entryId = tonumber(materiald[1])
  199. local entryCoe = tonumber(materiald[2])
  200. local rewardId = tonumber(materiald[3])
  201. local rewardNum = tonumber(materiald[4])
  202. local tk, tv = table.findByCondi(enyrys, function(a)
  203. return a.attrid == entryId
  204. end)
  205. if tk ~= nil then
  206. local getNum = math.floor(tv.value / entryCoe)
  207. if allObtainList[rewardId] ~= nil then
  208. allObtainList[rewardId] = allObtainList[rewardId] + rewardNum * getNum
  209. else
  210. allObtainList[rewardId] = rewardNum * getNum
  211. end
  212. end
  213. end
  214. end
  215. end
  216. end
  217. end
  218. removeitembyidxlist(actor, decompositionItemList, 9999, "分解消耗")
  219. additemmaptobag(actor, allObtainList, 0, 9999, "分解获得")
  220. -- itemdecomposition(actor, decompositionItemList, allObtainList, allNeedMaterial)
  221. sendluamsg(actor, LuaMessageIdToClient.RES_ITEM_DECOMPOSITION, allObtainList)
  222. setplaydef(actor, "T$luaitemextdata", allequip)
  223. end
  224. function ItemRecycling.recyclingRateReward(actor, reward)
  225. this.recyclingRateReward(actor, reward)
  226. end
  227. function this.recyclingRateReward(actor, reward)
  228. local rate = 0
  229. -- 月卡特权
  230. local is_open, count = PrivilegeMonth.hasPrivilege(actor, PrivilegeMonth.PrivilegeType.RECYCLING_INCOME_UP)
  231. if is_open then
  232. rate = rate + count;
  233. end
  234. -- VIP特权
  235. local vip_open, vip_rate = VipGiftPack.hasPrivilege(actor, VipPrivilege.Type.recycle)
  236. if vip_open and string.tonumber(vip_rate) > 0 then
  237. rate = rate + tonumber(vip_rate)
  238. end
  239. if rate < 1 then
  240. return
  241. end
  242. for key, value in pairs(reward) do
  243. local final_value = value * rate / 100
  244. if final_value >= 1 then
  245. reward[key] = final_value
  246. end
  247. end
  248. additemmaptobag(actor, reward, 0, 9999, '回收')
  249. GameTips.sendGetRewardMsg(actor, reward)
  250. this.debug("加成过的回收奖励", reward)
  251. end
  252. -- 回收
  253. function ItemRecycling.recovery(actor, msgData)
  254. local allItemInfo = getallbagiteminfo(actor)
  255. if table.isEmpty(allItemInfo) then
  256. return
  257. end
  258. if table.isEmpty(msgData) then
  259. return
  260. end
  261. local allObtainList = {}
  262. local itemIdGold = tostring(10010001)
  263. local allequip = getplaydef(actor, "T$luaitemextdata")
  264. for bagIndex, count in pairs(msgData) do
  265. for _, itemInfo in pairs(allItemInfo) do
  266. if itemInfo.bagindex == tonumber(bagIndex) then
  267. local itemCfgId = itemInfo.cfgid
  268. local recoveryGroup = ConfigDataManager.getTableValue("cfg_item", "recoveryGroup", "id", itemCfgId)
  269. local recoveryUp = ConfigDataManager.getTableValue("cfg_item", "recoveryUp", "id", itemCfgId)
  270. if string.isNullOrEmpty(recoveryGroup) then
  271. tipinfo(actor, "选择的道具中拥有不能分解的道具,请重新选择")
  272. return
  273. end
  274. local recoveryTable = ConfigDataManager.getTable("cfg_recovery", "id", recoveryGroup)
  275. if table.isEmpty(recoveryTable) then
  276. -- error(actor,"回收类型配置错误")
  277. return
  278. end
  279. if not table.isNullOrEmpty(allequip) then
  280. local equipext = allequip[tonumber(itemInfo.id)]
  281. if not table.isNullOrEmpty(equipext) then
  282. allequip[tonumber(itemInfo.id)] = nil
  283. end
  284. end
  285. local num = EquipFunc.getEquipRecoverCost(actor, itemInfo.id)
  286. if allObtainList[itemIdGold] ~= nil then
  287. allObtainList[itemIdGold] = allObtainList[itemIdGold] + num
  288. else
  289. allObtainList[itemIdGold] = num
  290. end
  291. -- local recoveryInfo = recoveryTable[1]
  292. -- local materialString = recoveryInfo.material
  293. -- local material = string.split(materialString,"#")
  294. -- local addCount = math.random(tonumber(material[2]), tonumber(material[3]))
  295. -- addCount = addCount * count
  296. -- if not string.isNullOrEmpty(recoveryUp) then
  297. -- addCount = addCount * ( 1 + math.floor(tonumber(recoveryUp) / 100))
  298. -- end
  299. -- local obtainCount = allObtainList[material[1]]
  300. -- if obtainCount == nil then
  301. -- obtainCount = 0
  302. -- end
  303. -- allObtainList[material[1]] = obtainCount + addCount
  304. end
  305. end
  306. end
  307. -- 做每天获取金币总量限制
  308. -- if allObtainList[itemIdGold] ~= nil then
  309. -- local enough, left_num = Player.GoldCountEnough(allObtainList[itemIdGold])
  310. -- if enough then
  311. -- allObtainList[itemIdGold] = left_num
  312. -- else
  313. -- allObtainList[itemIdGold] = 0
  314. -- end
  315. -- end
  316. itemrecovery(actor, msgData, allObtainList)
  317. sendluamsg(actor, LuaMessageIdToClient.RES_RECOVERY_REWARD, allObtainList)
  318. sendluamsg(actor, LuaMessageIdToClient.COMMON_REWARD_PANEL, allObtainList)
  319. setplaydef(actor, "T$luaitemextdata", allequip)
  320. -- sendluamsg(actor,LuaMessageIdToClient.RES_ITEM_RECOVERY,allObtainList)
  321. end
  322. -- 设置玩家回收类型
  323. function ItemRecycling.setItemRecyclingType(ownActor, msgData)
  324. this.setItemRecycling(ownActor, msgData)
  325. sendluamsg(ownActor, LuaMessageIdToClient.RES_GET_RECYCLING_TYPE, msgData)
  326. end
  327. function this.setItemRecycling(ownActor, msgData)
  328. callonserial(ownActor, "set_item_recycling", msgData)
  329. end
  330. function set_item_recycling(ownActor, msgData)
  331. local itemRecoveryType = getsysvar(ownActor, ITEM_RECYCLING_TYPE)
  332. if table.isNullOrEmpty(itemRecoveryType) then
  333. itemRecoveryType = {}
  334. end
  335. itemRecoveryType[ownActor:toString()] = msgData
  336. setsysvar(ownActor, ITEM_RECYCLING_TYPE, itemRecoveryType)
  337. end
  338. -- 获取当前玩家回收设置信息
  339. function ItemRecycling.getItemRecyclingType(ownActor)
  340. local itemRecoveryType = getsysvar(ownActor, ITEM_RECYCLING_TYPE)
  341. if table.isNullOrEmpty(itemRecoveryType) then
  342. sendluamsg(ownActor, LuaMessageIdToClient.RES_GET_RECYCLING_TYPE, nil)
  343. return
  344. end
  345. for actor, recyclingType in pairs(itemRecoveryType) do
  346. if actor == ownActor:toString() then
  347. sendluamsg(ownActor, LuaMessageIdToClient.RES_GET_RECYCLING_TYPE, recyclingType)
  348. return
  349. end
  350. end
  351. sendluamsg(ownActor, LuaMessageIdToClient.RES_GET_RECYCLING_TYPE, nil)
  352. end
  353. -- 自动回收道具
  354. function ItemRecycling.autoRecycling(actor)
  355. -- jprint("开启自动回收")
  356. local allItemRecoveryType = getsysvar(actor, ITEM_RECYCLING_TYPE)
  357. local bagIndex = {}
  358. if table.isNullOrEmpty(allItemRecoveryType) then
  359. table.insert(bagIndex, 0)
  360. return bagIndex
  361. end
  362. local itemRecoveryType = allItemRecoveryType[actor:toString()]
  363. if table.isNullOrEmpty(itemRecoveryType) then
  364. table.insert(bagIndex, 0)
  365. return bagIndex
  366. end
  367. local allItemInfo = getallbagiteminfo(actor)
  368. if table.isEmpty(allItemInfo) then
  369. table.insert(bagIndex, 0)
  370. return bagIndex
  371. end
  372. local alldata = EquipAndAppear.getLuaItemExtData(actor)
  373. for _, itemInfo in pairs(allItemInfo) do
  374. if this.getItemInfo(alldata, itemInfo.id) then
  375. local itemCfgId = itemInfo.cfgid
  376. if this.medicineCanRecycling(actor, itemCfgId) then
  377. local recoveryGroup = ConfigDataManager.getTableValue("cfg_item", "recoveryGroup", "id", itemCfgId)
  378. if not string.isNullOrEmpty(recoveryGroup) then
  379. local secondType = itemRecoveryType[recoveryGroup]
  380. if secondType ~= nil then
  381. if not secondType["1"] then
  382. table.insert(bagIndex, itemInfo.bagindex)
  383. else
  384. for _, type in pairs(secondType) do
  385. local recoveryScreen = ConfigDataManager.getTable("cfg_recovery_screen", "id", type)
  386. if not table.isNullOrEmpty(recoveryScreen) then
  387. local recoveryScreenInfo = recoveryScreen[1]
  388. local recoveryScreenType = tonumber(recoveryScreenInfo.type)
  389. if recoveryScreenType == ItemRecyclingType.PIN_JIE then
  390. local rank = recoveryScreenInfo.rank
  391. local cfgRank = ConfigDataManager.getTableValue("cfg_item", "rank", "id",
  392. itemCfgId)
  393. if not string.isNullOrEmpty(rank) and not string.isNullOrEmpty(cfgRank) and
  394. tonumber(rank) == tonumber(cfgRank) then
  395. table.insert(bagIndex, itemInfo.bagindex)
  396. break
  397. end
  398. elseif recoveryScreenType == ItemRecyclingType.ZHUO_YUE then
  399. local cfgCount = recoveryScreenInfo.count
  400. local entries = itemInfo.entries
  401. if not string.isNullOrEmpty(cfgCount) and not table.isNullOrEmpty(entries) and
  402. tonumber(cfgCount) == table.count(entries) then
  403. table.insert(bagIndex, itemInfo.bagindex)
  404. break
  405. end
  406. elseif recoveryScreenType == ItemRecyclingType.ZHI_YE then
  407. local cfgCareer = recoveryScreenInfo.career
  408. local job = ConfigDataManager.getTableValue("cfg_item", "job", "id", itemCfgId)
  409. if not string.isNullOrEmpty(cfgCareer) and not string.isNullOrEmpty(job) then
  410. local recoveryCareer = string.split(cfgCareer, "|")
  411. local itemCareer = string.split(job, "|")
  412. for _, career in pairs(itemCareer) do
  413. if table.contains(recoveryCareer, career) then
  414. table.insert(bagIndex, itemInfo.bagindex)
  415. break
  416. end
  417. end
  418. end
  419. end
  420. end
  421. end
  422. end
  423. end
  424. end
  425. end
  426. end
  427. end
  428. table.insert(bagIndex, 0)
  429. return bagIndex
  430. end
  431. --- 判断道具是否合乎药水回收要求
  432. function this.medicineCanRecycling(actor, itemCfgId)
  433. local type = ConfigDataManager.getTableValue("cfg_item", "type", "id", itemCfgId)
  434. local subType = ConfigDataManager.getTableValue("cfg_item", "subType", "id", itemCfgId)
  435. if tonumber(type) == 3 and tonumber(subType) == 1 then
  436. local conditions = ConfigDataManager.getTableValue("cfg_npcShop", "conditions", "itemId", itemCfgId)
  437. local result = checkcondition(actor, conditions)
  438. return result == "0"
  439. end
  440. return true
  441. end
  442. -- 判断当前道具有没有锻造
  443. function this.getItemInfo(alldata, itemId)
  444. local equipdata = alldata[tonumber(itemId)]
  445. if equipdata == nil then
  446. return true
  447. end
  448. if equipdata.strengthlv == nil and equipdata.appendlv == nil then
  449. return true
  450. end
  451. if equipdata.strengthlv ~= 0 or equipdata.appendlv ~= 0 then
  452. return false
  453. end
  454. return true
  455. end
  456. ---------------------------- 日志打印 -----------------------------
  457. this.log_open = false
  458. function this.debug(...)
  459. if not this.log_open then
  460. return
  461. end
  462. gameDebug.print(...)
  463. end
  464. function this.jprint(param)
  465. if not this.log_open then
  466. return
  467. end
  468. if param == nil then
  469. param = "error! 输出内容为空. nil"
  470. end
  471. jprint(param)
  472. end
  473. function this.loginfo(actor, param)
  474. if not this.log_open then
  475. return
  476. end
  477. if param == nil then
  478. param = "error! 日志输出内容为空. nil"
  479. end
  480. jprint(param)
  481. info(actor, param)
  482. end