DailyLeichong.lua 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. -- 今日累充金额
  44. ObjHuman.updateDaily(human)
  45. local nowDailyCharge = human.db.topupAcountDaily or 0
  46. for i = 1, #config.pay do
  47. msgRet.weekPay[i].id = i
  48. msgRet.weekPay[i].cur = nowDailyCharge
  49. msgRet.weekPay[i].max = config.pay[i]
  50. msgRet.weekPay[i].desc = Util.format(config.desc, config.pay[i])
  51. msgRet.weekPay[i].reward[0] = #(config.reward[i])
  52. for j = 1, msgRet.weekPay[i].reward[0] do
  53. local itemID = config.reward[i][j][1]
  54. local itemCnt = config.reward[i][j][2]
  55. Grid.makeItem(msgRet.weekPay[i].reward[j], itemID, itemCnt)
  56. end
  57. end
  58. msgRet.weekPay[0] = #config.pay
  59. Msg.send(msgRet, human.fd)
  60. end
  61. function charge(human, price)
  62. if isOpen(human) ~= true then
  63. return
  64. end
  65. active(human, price)
  66. end
  67. function active(human, price)
  68. local config = getConfig()
  69. if config == nil then return end
  70. local nowDailyCharge = human.db.topupAcountDaily
  71. local lastDailyCharge = nowDailyCharge - price
  72. local dailyLeiChong = human.db.dailyLeiChong
  73. for i = 1, #config.pay do
  74. if not dailyLeiChong or not dailyLeiChong[i] then
  75. local needPay = config.pay[i]
  76. if needPay <= nowDailyCharge and needPay > lastDailyCharge then
  77. human.db.dailyLeiChong = human.db.dailyLeiChong or {}
  78. human.db.dailyLeiChong[i] = i
  79. -- 发放奖励
  80. local items = { }
  81. for z, v in ipairs(config.reward[i]) do
  82. items[z] = { v[1], v[2] }
  83. end
  84. --[[local title = MailExcel.mail[62].title
  85. local content = Util.format(MailExcel.mail[62].content, config.pay[i])
  86. local senderName = MailExcel.mail[62].senderName
  87. MailManager.add(MailManager.SYSTEM, human.db._id, title, content, items, senderName)]]
  88. end
  89. end
  90. end
  91. end