ItemRecycling.lua 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  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(actor, allObtainList[itemIdGold])
  310. if enough then
  311. allObtainList[itemIdGold] = left_num
  312. Player.GoldCountAdd(actor, left_num)
  313. else
  314. allObtainList[itemIdGold] = 0
  315. end
  316. end
  317. itemrecovery(actor, msgData, allObtainList)
  318. sendluamsg(actor, LuaMessageIdToClient.RES_RECOVERY_REWARD, allObtainList)
  319. sendluamsg(actor, LuaMessageIdToClient.COMMON_REWARD_PANEL, allObtainList)
  320. setplaydef(actor, "T$luaitemextdata", allequip)
  321. -- sendluamsg(actor,LuaMessageIdToClient.RES_ITEM_RECOVERY,allObtainList)
  322. end
  323. -- 设置玩家回收类型
  324. function ItemRecycling.setItemRecyclingType(ownActor, msgData)
  325. this.setItemRecycling(ownActor, msgData)
  326. sendluamsg(ownActor, LuaMessageIdToClient.RES_GET_RECYCLING_TYPE, msgData)
  327. end
  328. function this.setItemRecycling(ownActor, msgData)
  329. callonserial(ownActor, "set_item_recycling", msgData)
  330. end
  331. function set_item_recycling(ownActor, msgData)
  332. local itemRecoveryType = getsysvar(ownActor, ITEM_RECYCLING_TYPE)
  333. if table.isNullOrEmpty(itemRecoveryType) then
  334. itemRecoveryType = {}
  335. end
  336. itemRecoveryType[ownActor:toString()] = msgData
  337. setsysvar(ownActor, ITEM_RECYCLING_TYPE, itemRecoveryType)
  338. end
  339. -- 获取当前玩家回收设置信息
  340. function ItemRecycling.getItemRecyclingType(ownActor)
  341. local itemRecoveryType = getsysvar(ownActor, ITEM_RECYCLING_TYPE)
  342. if table.isNullOrEmpty(itemRecoveryType) then
  343. sendluamsg(ownActor, LuaMessageIdToClient.RES_GET_RECYCLING_TYPE, nil)
  344. return
  345. end
  346. for actor, recyclingType in pairs(itemRecoveryType) do
  347. if actor == ownActor:toString() then
  348. sendluamsg(ownActor, LuaMessageIdToClient.RES_GET_RECYCLING_TYPE, recyclingType)
  349. return
  350. end
  351. end
  352. sendluamsg(ownActor, LuaMessageIdToClient.RES_GET_RECYCLING_TYPE, nil)
  353. end
  354. -- 自动回收道具
  355. function ItemRecycling.autoRecycling(actor)
  356. -- jprint("开启自动回收")
  357. local allItemRecoveryType = getsysvar(actor, ITEM_RECYCLING_TYPE)
  358. local bagIndex = {}
  359. if table.isNullOrEmpty(allItemRecoveryType) then
  360. table.insert(bagIndex, 0)
  361. return bagIndex
  362. end
  363. local itemRecoveryType = allItemRecoveryType[actor:toString()]
  364. if table.isNullOrEmpty(itemRecoveryType) then
  365. table.insert(bagIndex, 0)
  366. return bagIndex
  367. end
  368. local allItemInfo = getallbagiteminfo(actor)
  369. if table.isEmpty(allItemInfo) then
  370. table.insert(bagIndex, 0)
  371. return bagIndex
  372. end
  373. local alldata = EquipAndAppear.getLuaItemExtData(actor)
  374. for _, itemInfo in pairs(allItemInfo) do
  375. if this.getItemInfo(alldata, itemInfo.id) then
  376. local itemCfgId = itemInfo.cfgid
  377. if this.medicineCanRecycling(actor, itemCfgId) then
  378. local recoveryGroup = ConfigDataManager.getTableValue("cfg_item", "recoveryGroup", "id", itemCfgId)
  379. if not string.isNullOrEmpty(recoveryGroup) then
  380. local secondType = itemRecoveryType[recoveryGroup]
  381. if secondType ~= nil then
  382. if not secondType["1"] then
  383. table.insert(bagIndex, itemInfo.bagindex)
  384. else
  385. for _, type in pairs(secondType) do
  386. local recoveryScreen = ConfigDataManager.getTable("cfg_recovery_screen", "id", type)
  387. if not table.isNullOrEmpty(recoveryScreen) then
  388. local recoveryScreenInfo = recoveryScreen[1]
  389. local recoveryScreenType = tonumber(recoveryScreenInfo.type)
  390. if recoveryScreenType == ItemRecyclingType.PIN_JIE then
  391. local rank = recoveryScreenInfo.rank
  392. local cfgRank = ConfigDataManager.getTableValue("cfg_item", "rank", "id",
  393. itemCfgId)
  394. if not string.isNullOrEmpty(rank) and not string.isNullOrEmpty(cfgRank) and
  395. tonumber(rank) == tonumber(cfgRank) then
  396. table.insert(bagIndex, itemInfo.bagindex)
  397. break
  398. end
  399. elseif recoveryScreenType == ItemRecyclingType.ZHUO_YUE then
  400. local cfgCount = recoveryScreenInfo.count
  401. local entries = itemInfo.entries
  402. if not string.isNullOrEmpty(cfgCount) and not table.isNullOrEmpty(entries) and
  403. tonumber(cfgCount) == table.count(entries) then
  404. table.insert(bagIndex, itemInfo.bagindex)
  405. break
  406. end
  407. elseif recoveryScreenType == ItemRecyclingType.ZHI_YE then
  408. local cfgCareer = recoveryScreenInfo.career
  409. local job = ConfigDataManager.getTableValue("cfg_item", "job", "id", itemCfgId)
  410. if not string.isNullOrEmpty(cfgCareer) and not string.isNullOrEmpty(job) then
  411. local recoveryCareer = string.split(cfgCareer, "|")
  412. local itemCareer = string.split(job, "|")
  413. for _, career in pairs(itemCareer) do
  414. if table.contains(recoveryCareer, career) then
  415. table.insert(bagIndex, itemInfo.bagindex)
  416. break
  417. end
  418. end
  419. end
  420. end
  421. end
  422. end
  423. end
  424. end
  425. end
  426. end
  427. end
  428. end
  429. table.insert(bagIndex, 0)
  430. return bagIndex
  431. end
  432. --- 判断道具是否合乎药水回收要求
  433. function this.medicineCanRecycling(actor, itemCfgId)
  434. local type = ConfigDataManager.getTableValue("cfg_item", "type", "id", itemCfgId)
  435. local subType = ConfigDataManager.getTableValue("cfg_item", "subType", "id", itemCfgId)
  436. if tonumber(type) == 3 and tonumber(subType) == 1 then
  437. local conditions = ConfigDataManager.getTableValue("cfg_npcShop", "conditions", "itemId", itemCfgId)
  438. local result = checkcondition(actor, conditions)
  439. return result == "0"
  440. end
  441. return true
  442. end
  443. -- 判断当前道具有没有锻造
  444. function this.getItemInfo(alldata, itemId)
  445. local equipdata = alldata[tonumber(itemId)]
  446. if equipdata == nil then
  447. return true
  448. end
  449. if equipdata.strengthlv == nil and equipdata.appendlv == nil then
  450. return true
  451. end
  452. if equipdata.strengthlv ~= 0 or equipdata.appendlv ~= 0 then
  453. return false
  454. end
  455. return true
  456. end
  457. ---------------------------- 日志打印 -----------------------------
  458. this.log_open = false
  459. function this.debug(...)
  460. if not this.log_open then
  461. return
  462. end
  463. gameDebug.print(...)
  464. end
  465. function this.jprint(param)
  466. if not this.log_open then
  467. return
  468. end
  469. if param == nil then
  470. param = "error! 输出内容为空. nil"
  471. end
  472. jprint(param)
  473. end
  474. function this.loginfo(actor, param)
  475. if not this.log_open then
  476. return
  477. end
  478. if param == nil then
  479. param = "error! 日志输出内容为空. nil"
  480. end
  481. jprint(param)
  482. info(actor, param)
  483. end