DailyLibaoLogic.lua 8.1 KB

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