ItemExchange.lua 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. --涉及到的相关属性在属性表配置
  2. ItemExchange = {}
  3. local this = ItemExchange;
  4. local filename = "ItemExchange";
  5. local exchangeType = {
  6. [5] = {
  7. type = 5,
  8. items = {
  9. [50030001] = 20,
  10. [50030002] = 80,
  11. [50030003] = 50,
  12. [50030005] = 100,
  13. }
  14. },
  15. [2] = {
  16. type = 2,
  17. pos = {
  18. [1] = 1,
  19. [2] = 1,
  20. [3] = 1,
  21. [4] = 1,
  22. [5] = 1,
  23. [6] = 1,
  24. [7] = 1,
  25. [8] = 1,
  26. [9] = 1,
  27. },
  28. },
  29. }
  30. function ItemExchange.onLoginEnd(actor)
  31. end
  32. -- 回收
  33. function ItemExchange.exchange(actor, msgData)
  34. local allItemInfo = getallbagiteminfo(actor)
  35. if table.isEmpty(allItemInfo) then
  36. return
  37. end
  38. if table.isEmpty(msgData) then
  39. return
  40. end
  41. local allObtainList = {}
  42. local allequip = getplaydef(actor, "T$luaitemextdata")
  43. for bagIndex, count in pairs(msgData) do
  44. for _, itemInfo in pairs(allItemInfo) do
  45. if itemInfo.bagindex == tonumber(bagIndex) then
  46. local itemCfgId = itemInfo.cfgid
  47. local itemType = tonumber(ConfigDataManager.getTableValue("cfg_item", "type", "id", itemCfgId))
  48. local itemExchange = tonumber(ConfigDataManager.getTableValue("cfg_item", "itemExchange", "id", itemCfgId))
  49. local itemSubtype = tonumber(ConfigDataManager.getTableValue("cfg_item", "subType", "id", itemCfgId))
  50. local qutstanding = tonumber(ConfigDataManager.getTableValue("cfg_item", "Outstanding", "id", itemCfgId))
  51. local canExchange = true
  52. if itemExchange == nil or itemExchange == "" or tonumber(itemExchange) == 0 then
  53. canExchange = false
  54. end
  55. -- if itemType == 1 and exchangeType[itemType].items[itemCfgId] == nil then
  56. -- canExchange = false
  57. -- end
  58. -- if itemType == 2 and (exchangeType[itemType].pos[itemSubtype] == nil or qutstanding < 1) then
  59. -- canExchange = false
  60. -- end
  61. if canExchange == false then
  62. tipinfo(actor, "选择的道具中拥有不能兑换的道具,请重新选择")
  63. return
  64. end
  65. if not table.isNullOrEmpty(allequip) then
  66. local equipext = allequip[tonumber(itemInfo.id)]
  67. if not table.isNullOrEmpty(equipext) then
  68. allequip[tonumber(itemInfo.id)] = nil
  69. end
  70. end
  71. local cfgId = tostring(10020001)
  72. local num = itemExchange
  73. if itemType == 2 then
  74. num = num + EquipFunc.getEquipExchangeCost(itemInfo)
  75. if not string.isNullOrEmpty(qutstanding) and tonumber(qutstanding) >= 1 then
  76. local level = API.GetItemData(actor, itemInfo.id, "strengthlv") or 0
  77. if level > 3 then
  78. num = num + (level - 3) * 100
  79. end
  80. end
  81. end
  82. -- 乘以兑换数量
  83. num = num * count
  84. if allObtainList[cfgId] ~= nil then
  85. allObtainList[cfgId] = allObtainList[cfgId] + num
  86. else
  87. allObtainList[cfgId] = num
  88. end
  89. end
  90. end
  91. end
  92. itemrecovery(actor, msgData, allObtainList)
  93. sendluamsg(actor, LuaMessageIdToClient.RES_EXCHANGE_REWARD, allObtainList)
  94. sendluamsg(actor, LuaMessageIdToClient.COMMON_REWARD_PANEL, allObtainList)
  95. setplaydef(actor, "T$luaitemextdata", allequip)
  96. -- sendluamsg(actor,LuaMessageIdToClient.RES_ITEM_RECOVERY,allObtainList)
  97. end