SevenDayGiftLogic.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. --七日豪礼
  2. local Msg = require("core.Msg")
  3. local SevenDayGiftExcel = require("excel.present").sevenDayGift
  4. local BuyExcel = require("excel.buy")
  5. local BuyLogic = require("topup.BuyLogic")
  6. local Grid = require("bag.Grid")
  7. local BagLogic = require("bag.BagLogic")
  8. local Util = require("common.Util")
  9. local Lang = require("common.Lang")
  10. local Broadcast = require("broadcast.Broadcast")
  11. local CommonDB = require("common.CommonDB")
  12. local TopupLogic = require("topup.TopupLogic")
  13. local YunYingLogic = require("yunying.YunYingLogic")
  14. local PanelDefine = require("broadcast.PanelDefine")
  15. local SceneHandler = require("scene.Handler")
  16. SEVENDAYGIFT_BUY_NO = 0 --没买
  17. SEVENDAYGIFT_BUY_HAD = 1 --已买
  18. local function isBuy(human,id)
  19. local godDailyTopup = human.db.godDailyTopup
  20. local status = 0
  21. if godDailyTopup and godDailyTopup[id] and godDailyTopup[id].pay then
  22. status = 1
  23. end
  24. return status
  25. end
  26. -- 检查活动是否开启
  27. function check(human,noSend)
  28. if not SceneHandler.canCharge(human) then
  29. return
  30. end
  31. local openLv = YunYingLogic.getOpenLvByPanelID(PanelDefine.PANEL_ID_62)
  32. if human.db.lv < openLv then
  33. if not noSend then
  34. local str = Util.format(Lang.ROLE_LEV_ERROR,openLv)
  35. return Broadcast.sendErr(human,str)
  36. end
  37. end
  38. for i=1,#SevenDayGiftExcel do
  39. local isBuy = isBuy(human,i)
  40. if isBuy == SEVENDAYGIFT_BUY_NO then
  41. return true
  42. end
  43. end
  44. end
  45. function makeGiftMsg(human,net,config,id)
  46. net.id = config.realId
  47. local buyID = config.buyID
  48. net.giftVipExp = config.vipExp
  49. net.item[0] = #config.reward
  50. for j = 1,#config.reward do
  51. Grid.makeItem(net.item[j],config.reward[j][1],config.reward[j][2])
  52. end
  53. BuyLogic.fontBuyItem(human,net.buyMsg, buyID)
  54. local godDailyTopup = human.db.godDailyTopup
  55. local status = 0
  56. if godDailyTopup and godDailyTopup[id] and godDailyTopup[id].pay then
  57. status = 1
  58. end
  59. net.status = status
  60. end
  61. --七日豪礼查询
  62. function query(human)
  63. if not check(human) and not SevenLoginDayLogic.isBaseOpen(human) then return end
  64. local msgRet = Msg.gc.GC_SEVENDAYGIFT_QUERY
  65. local today = Util.diffDay(human.db.createTime) + 1
  66. if today > #SevenDayGiftExcel then
  67. today = #SevenDayGiftExcel + 1
  68. end
  69. msgRet.today = today
  70. msgRet.giftMsg[0] = #SevenDayGiftExcel
  71. for i=1,#SevenDayGiftExcel do
  72. makeGiftMsg(human,msgRet.giftMsg[i],SevenDayGiftExcel[i],i)
  73. end
  74. --Msg.trace(msgRet)
  75. Msg.send(msgRet,human.fd)
  76. end
  77. function dailyTopupBuy(human,id)
  78. if not check(human) and not SevenLoginDayLogic.isBaseOpen(human) then return end
  79. -- 礼包不存在
  80. local config = SevenDayGiftExcel[id]
  81. if not config then
  82. return Broadcast.sendErr(human,Lang.ACT_WAS_OVER)
  83. end
  84. local today = Util.diffDay(human.db.createTime) + 1
  85. if id > today then
  86. return Broadcast.sendErr(human,Lang.TOMORROW_OPEN)
  87. end
  88. -- 礼包已购买
  89. if human.db.godDailyTopup and human.db.godDailyTopup[id] and human.db.godDailyTopup[id].pay ~= nil then
  90. return Broadcast.sendErr(human,Lang.COMMON_LIBAO_HADBUY)
  91. end
  92. -- 写db
  93. human.db.godDailyTopup = human.db.godDailyTopup or {}
  94. human.db.godDailyTopup[id] = human.db.godDailyTopup[id] or {}
  95. human.db.godDailyTopup[id].pay = 1
  96. -- 发货
  97. BagLogic.addItemList(human, config.reward, "seven_DayGift")
  98. update(human,id)
  99. for k, v in pairs(funcID) do
  100. YunYingLogic.updateIcon(YYInfo[k], human)
  101. YunYingLogic.sendGroupUpdate(YYInfo[k], human, PanelDefine.PANEL_ID_102)
  102. break
  103. end
  104. end
  105. function update(human,id)
  106. local msgRet = Msg.gc.GC_SEVENDAYGIFT_UPDATE
  107. local config = SevenDayGiftExcel[id]
  108. if not config then return end
  109. makeGiftMsg(human,msgRet.giftMsg,config,id)
  110. --Msg.trace(msgRet)
  111. Msg.send(msgRet,human.fd)
  112. end
  113. function isBaseOpen(human,noSend)
  114. if not SceneHandler.canCharge(human) then
  115. return
  116. end
  117. if check(human,noSend) then
  118. return true
  119. end
  120. end
  121. function isOpen(human)
  122. if isBaseOpen(human,true) or SevenLoginDayLogic.isBaseOpen(human,true) then
  123. return true
  124. end
  125. end