DailyLeichong.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. -- 每日累充
  2. local Util = require("common.Util")
  3. local CommonDB = require("common.CommonDB")
  4. local Log = require("common.Log")
  5. local PresentExcel = require("excel.present")
  6. local MailExcel = require("excel.mail")
  7. local MailManager = require("mail.MailManager")
  8. local Msg = require("core.Msg")
  9. local ObjHuman = require("core.ObjHuman")
  10. local BagLogic = require("bag.BagLogic")
  11. local Grid = require("bag.Grid")
  12. local SceneHandler = require("scene.Handler")
  13. local function getConfig()
  14. local subDay = CommonDB.getServerOpenDay()
  15. if subDay == nil then
  16. return
  17. end
  18. if subDay <= 7 then
  19. -- 开服首周
  20. return PresentExcel.dailyLeichong[1]
  21. else
  22. -- 开服第二周和以后
  23. return PresentExcel.dailyLeichong[2]
  24. end
  25. end
  26. function isOpen(human)
  27. if true then
  28. return
  29. end
  30. if not SceneHandler.canCharge(human) then
  31. return
  32. end
  33. local config = getConfig()
  34. if config == nil then return end
  35. return true
  36. end
  37. function query(human)
  38. local config = getConfig()
  39. if config == nil then return end
  40. local now = os.time()
  41. local msgRet = Msg.gc.GC_DAILY_LEICHONG_QUERY
  42. msgRet.sec = Util.getDayStartTime(now) + 24 * 3600 - now
  43. msgRet.titledesc = config.desc2
  44. -- 今日累充金额
  45. ObjHuman.updateDaily(human)
  46. local nowDailyCharge = human.db.topupAcountDaily or 0
  47. local dailyLeiChong = human.db.dailyLeiChong
  48. for i = 1, #config.pay do
  49. msgRet.weekPay[i].id = i
  50. msgRet.weekPay[i].cur = nowDailyCharge
  51. msgRet.weekPay[i].max = config.pay[i]
  52. msgRet.weekPay[i].desc = Util.format(config.desc, config.pay[i])
  53. msgRet.weekPay[i].state = 0
  54. if dailyLeiChong and dailyLeiChong[i] then
  55. msgRet.weekPay[i].state = 1
  56. end
  57. msgRet.weekPay[i].reward[0] = #(config.reward[i])
  58. for j = 1, msgRet.weekPay[i].reward[0] do
  59. local itemID = config.reward[i][j][1]
  60. local itemCnt = config.reward[i][j][2]
  61. Grid.makeItem(msgRet.weekPay[i].reward[j], itemID, itemCnt)
  62. end
  63. end
  64. msgRet.weekPay[0] = #config.pay
  65. Msg.send(msgRet, human.fd)
  66. end
  67. function charge(human, price)
  68. -- if isOpen(human) ~= true then --暂时不判断开启条件
  69. -- return
  70. -- end
  71. active(human, price)
  72. end
  73. function active(human, price)
  74. local config = getConfig()
  75. if config == nil then return end
  76. local nowDailyCharge = human.db.topupAcountDaily
  77. local lastDailyCharge = nowDailyCharge - price
  78. local dailyLeiChong = human.db.dailyLeiChong
  79. for i = 1, #config.pay do
  80. if not dailyLeiChong or not dailyLeiChong[i] then
  81. local needPay = config.pay[i]
  82. if needPay <= nowDailyCharge and needPay > lastDailyCharge then
  83. human.db.dailyLeiChong = human.db.dailyLeiChong or {}
  84. human.db.dailyLeiChong[i] = i
  85. -- 发放奖励
  86. local items = { }
  87. for z, v in ipairs(config.reward[i]) do
  88. items[z] = { v[1], v[2] }
  89. end
  90. local title = MailExcel.mail[2016].title
  91. local content = Util.format(MailExcel.mail[2016].content, config.pay[i])
  92. local senderName = MailExcel.mail[2016].senderName
  93. MailManager.add(MailManager.SYSTEM, human.db._id, title, content, items, senderName)
  94. end
  95. end
  96. end
  97. end