DailyLibaoLogic.lua 7.9 KB

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