boxAdapt.lua 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. --[[
  2. Descripttion:
  3. version:
  4. Author: Neo,Huang
  5. Date: 2023-11-17 22:23:09
  6. LastEditors: Neo,Huang
  7. LastEditTime: 2023-11-17 23:23:51
  8. --]]
  9. -- 箱子配置
  10. local baseAdapt = require "base.baseAdapt"
  11. local root = {}
  12. ----------------------------------------
  13. -- 盲盒
  14. ----------------------------------------
  15. -- 箱子物品列表
  16. function root:blind_get_box_item_list(boxId)
  17. local confList = {}
  18. local conf = baseAdapt:getConfig("BlindBoxAwardConfig")
  19. for _, v in ipairs(conf) do
  20. if v.boxId == boxId then
  21. table.insert(confList, table.copy(v))
  22. end
  23. end
  24. return confList
  25. end
  26. -- 获取箱子信息
  27. function root:blind_get_box_key_info(boxId, key)
  28. local conf = baseAdapt:getConfig("BlindBoxConfig")
  29. for _, v in ipairs(conf) do
  30. if v.boxId == boxId then
  31. if is_empty(key) then
  32. return v
  33. else
  34. return v[key]
  35. end
  36. end
  37. end
  38. end
  39. ----------------------------------------
  40. -- 战斗
  41. ----------------------------------------
  42. -- 获取箱子配置
  43. function root:battle_get_box_key_info(boxId, key)
  44. if is_empty(boxId) then
  45. return
  46. end
  47. local conf = baseAdapt:getConfig("BattleBoxConfig")
  48. for _, v in ipairs(conf) do
  49. if v.boxId == boxId then
  50. if is_empty(key) then
  51. return v
  52. else
  53. return v[key]
  54. end
  55. end
  56. end
  57. end
  58. -- 参加战斗消耗
  59. function root:battle_get_box_price(boxIdList)
  60. if is_empty(boxIdList) then
  61. return 0
  62. end
  63. local price = 0
  64. for _, v in ipairs(boxIdList) do
  65. local boxPrice = self:battle_get_box_key_info(v, "price")
  66. if not is_empty(boxPrice) then
  67. price = price + boxPrice
  68. end
  69. end
  70. return price
  71. end
  72. -- 检查战斗箱子
  73. function root:battle_is_box_list_valid(boxIdList)
  74. if is_empty(boxIdList) then
  75. return false
  76. end
  77. -- 数量
  78. local minCount = self:battle_const("battle_box_min")
  79. local maxCount = self:battle_const("battle_box_max")
  80. if #boxIdList < minCount or #boxIdList > maxCount then
  81. return false
  82. end
  83. for _, v in ipairs(boxIdList) do
  84. local conf = self:battle_get_box_key_info(v)
  85. if is_empty(conf) or is_empty(conf.price) then
  86. return false
  87. end
  88. end
  89. return true
  90. end
  91. -- 常量
  92. function root:battle_const(key)
  93. if is_empty(key) then
  94. return
  95. end
  96. local conf = baseAdapt:getConfig("BattleConstConfig")
  97. for _, v in ipairs(conf) do
  98. if v.main_key == key then
  99. return v.value
  100. end
  101. end
  102. end
  103. -- 箱子物品列表
  104. function root:battle_get_box_item_list(boxId)
  105. local confList = {}
  106. local conf = baseAdapt:getConfig("BattleBoxAwardConfig")
  107. for _, v in ipairs(conf) do
  108. if v.boxId == boxId then
  109. table.insert(confList, table.copy(v))
  110. end
  111. end
  112. return confList
  113. end
  114. return root