DailyLibaoLogic.lua 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. ---------------------------------------------------
  2. -- 充值-每日礼包
  3. -- 每日0点刷新购买次数
  4. -- db.dailyLibao[id] = cnt
  5. -- 新修改: 不同渠道的礼包配置不同
  6. ---------------------------------------------------
  7. local DailyLibaoExcel = require("excel.present").dailyLibao
  8. local Lang = require("common.Lang")
  9. local Msg = require("core.Msg")
  10. local ObjHuman = require("core.ObjHuman")
  11. local Broadcast = require("broadcast.Broadcast")
  12. local PanelDefine = require("broadcast.PanelDefine")
  13. local Grid = require("bag.Grid")
  14. local BagLogic = require("bag.BagLogic")
  15. local BuyLogic = require("topup.BuyLogic")
  16. local VipLogic = require("vip.VipLogic")
  17. local YunYingLogic = require("yunying.YunYingLogic")
  18. local CommonDefine = require("common.CommonDefine")
  19. local FREE_LIBAO_ID = 0 -- 免费
  20. local QUICK_LIBAO_ID = 1 -- 一键购买
  21. local QUICK_STATUS_CANT = 0 -- 不能购买
  22. local QUICK_STATUS_CAN = 1 -- 可购买
  23. -- 通过渠道标识获取礼包配置ID
  24. local function getCfgIdxByChannel(human)
  25. local quick_gift_id = 1
  26. local gift_start_id, gift_end_id = 2, 4
  27. --if human.phpChanelID == CommonDefine.CHANNEL_TAG_MUZI or human.phpChanelID == CommonDefine.CHANNEL_TAG_SANLI_QQ then
  28. quick_gift_id = 11
  29. gift_start_id = 12
  30. gift_end_id = 14
  31. --end
  32. return quick_gift_id, gift_start_id, gift_end_id
  33. end
  34. -- 已购买数量
  35. function getCnt(human, id)
  36. if not human.db.dailyLibao then
  37. return 0
  38. end
  39. return human.db.dailyLibao[id] or 0
  40. end
  41. function addCnt(human, id)
  42. if not human.db.dailyLibao then
  43. human.db.dailyLibao = {}
  44. end
  45. human.db.dailyLibao[id] = getCnt(human, id) + 1
  46. end
  47. -- 剩余次数
  48. function getLeftCnt(human, id)
  49. local config = DailyLibaoExcel[id]
  50. if not config then return 0 end
  51. return math.max(config.cnt - getCnt(human, id), 0)
  52. end
  53. -- 封装礼包结构体
  54. function fontLibaoNet(net, id, config, human)
  55. net.id = id
  56. net.items[0] = #config.items
  57. net.doubleFlags[0] = net.items[0]
  58. for i = 1, net.items[0] do
  59. local itemID = config.items[i][1]
  60. local itemCnt = config.items[i][2]
  61. Grid.makeItem(net.items[i], itemID, itemCnt)
  62. net.doubleFlags[i] = config.items[i][3] or 0 -- 是否显示双倍标签
  63. end
  64. net.cnt = getCnt(human, id)
  65. net.maxCnt = config.cnt
  66. net.vipLv = 0
  67. BuyLogic.fontBuyItem(human, net.buyItem, config.buyID)
  68. net.name = config.name
  69. end
  70. -- 可否一键购买
  71. local function canQuickBuy(human)
  72. -- for id, config in ipairs(DailyLibaoExcel) do
  73. -- if id ~= QUICK_LIBAO_ID then
  74. -- -- 剩余购买次数
  75. -- if getCnt(human, id) >= config.cnt then
  76. -- return
  77. -- end
  78. -- end
  79. -- end
  80. local _, gift_start_id, gift_end_id = getCfgIdxByChannel(human)
  81. for i=gift_start_id, gift_end_id do
  82. local config = DailyLibaoExcel[i]
  83. -- 剩余购买次数
  84. if getCnt(human, i) >= config.cnt then
  85. return false
  86. end
  87. end
  88. return true
  89. end
  90. -- 获取原价
  91. local function getQuickOldPrice(human)
  92. local sum = 0
  93. -- for id, config in ipairs(DailyLibaoExcel) do
  94. -- if id ~= QUICK_LIBAO_ID then
  95. -- sum = sum + BuyLogic.getRealPrice(human, config.buyID)
  96. -- end
  97. -- end
  98. local _, gift_start_id, gift_end_id = getCfgIdxByChannel(human)
  99. for i=gift_start_id, gift_end_id do
  100. local config = DailyLibaoExcel[i]
  101. sum = sum + BuyLogic.getRealPrice(human, config.buyID)
  102. end
  103. return sum
  104. end
  105. -- 封装一键购买信息
  106. function fontQuickNet(net, human, quick_gift_id)
  107. local config = DailyLibaoExcel[quick_gift_id]
  108. net.status = canQuickBuy(human) and QUICK_STATUS_CAN or QUICK_STATUS_CANT
  109. net.oldPrice = getQuickOldPrice(human)
  110. net.vipLv = 0
  111. BuyLogic.fontBuyItem(human, net.buyItem, config.buyID)
  112. end
  113. -- 面板查询
  114. function sendQuery(human)
  115. -- ObjHuman.updateDaily(human)
  116. -- local msgRet = Msg.gc.GC_PRE_DAILY_LIBAO_QUERY
  117. -- msgRet.list[0] = 0
  118. -- for id, config in ipairs(DailyLibaoExcel) do
  119. -- if id ~= QUICK_LIBAO_ID then
  120. -- msgRet.list[0] = msgRet.list[0] + 1
  121. -- fontLibaoNet(msgRet.list[msgRet.list[0]], id, config, human)
  122. -- end
  123. -- end
  124. -- fontQuickNet(msgRet.quickData, human)
  125. -- msgRet.freeRed = (getLeftCnt(human, FREE_LIBAO_ID) > 0) and 1 or 0
  126. -- --Msg.trace(msgRet)
  127. -- Msg.send(msgRet, human.fd)
  128. local quick_gift_id, gift_start_id, gift_end_id = getCfgIdxByChannel(human)
  129. local msgRet = Msg.gc.GC_PRE_DAILY_LIBAO_QUERY
  130. msgRet.list[0] = 0
  131. local len = 0
  132. for i=gift_start_id, gift_end_id do
  133. len = len + 1
  134. msgRet.list[0] = len
  135. local config = DailyLibaoExcel[i]
  136. fontLibaoNet(msgRet.list[len], i, config, human)
  137. end
  138. fontQuickNet(msgRet.quickData, human, quick_gift_id)
  139. msgRet.freeRed = (getLeftCnt(human, FREE_LIBAO_ID) > 0) and 1 or 0
  140. Msg.send(msgRet, human.fd)
  141. end
  142. -- 给予东西
  143. local function giveLibaoItems(human, id)
  144. local config = DailyLibaoExcel[id]
  145. if not config then return end
  146. if getLeftCnt(human, id) < 1 then
  147. return Broadcast.sendErr(human, Lang.YUNYING_BUY_ERR_CNT)
  148. end
  149. addCnt(human, id)
  150. return config.items
  151. end
  152. -- 领取免费礼包
  153. function getPreFreeLibao(human)
  154. ObjHuman.updateDaily(human)
  155. local items = giveLibaoItems(human, FREE_LIBAO_ID)
  156. if not items then return end
  157. sendQuery(human)
  158. -- 通用获得道具弹窗
  159. if items then
  160. for _, item in pairs(items) do
  161. BagLogic.addItem(human, item[1], item[2], "daily_libao")
  162. end
  163. end
  164. BagLogic.sendItemGetList(human, items, "daily_libao")
  165. for k, v in pairs(funcID) do
  166. YunYingLogic.updateIcon(YYInfo[k], human)
  167. YunYingLogic.sendGroupUpdate(YYInfo[k], human, PanelDefine.PANEL_ID_3107)
  168. break
  169. end
  170. end
  171. -- 购买礼包
  172. function buyLibao(human, id)
  173. -- ObjHuman.updateDaily(human)
  174. local itemsAll = nil
  175. -- if id == QUICK_LIBAO_ID then
  176. -- for tid, config in ipairs(DailyLibaoExcel) do
  177. -- if tid ~= QUICK_LIBAO_ID then
  178. -- local items = giveLibaoItems(human, tid)
  179. -- if items then
  180. -- itemsAll = itemsAll or {}
  181. -- for _, item in ipairs(items) do
  182. -- itemsAll[#itemsAll + 1] = item
  183. -- end
  184. -- end
  185. -- end
  186. -- end
  187. -- itemsAll = BagLogic.sameItemTogether(itemsAll)
  188. -- else
  189. -- itemsAll = giveLibaoItems(human, id)
  190. -- end
  191. local quick_gift_id, gift_start_id, gift_end_id = getCfgIdxByChannel(human)
  192. if id == quick_gift_id then
  193. for i=gift_start_id, gift_end_id do
  194. local items = giveLibaoItems(human, i)
  195. if items then
  196. itemsAll = itemsAll or {}
  197. for _, item in ipairs(items) do
  198. itemsAll[#itemsAll + 1] = item
  199. end
  200. end
  201. end
  202. itemsAll = BagLogic.sameItemTogether(itemsAll)
  203. else
  204. itemsAll = giveLibaoItems(human, id)
  205. end
  206. if not itemsAll then return end
  207. if itemsAll then
  208. for _, item in pairs(itemsAll) do
  209. BagLogic.addItem(human, item[1], item[2], "mail")
  210. end
  211. end
  212. -- 通用获得道具弹窗
  213. BagLogic.sendItemGetList(human, itemsAll, "daily_libao")
  214. sendQuery(human)
  215. end
  216. -- 红点
  217. function isRed(human)
  218. -- 有免费礼包可以领取
  219. if getLeftCnt(human, FREE_LIBAO_ID) > 0 then
  220. return true
  221. end
  222. end