LeichongHaoli.lua 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. -- 累充豪礼
  2. local Util = require("common.Util")
  3. local CommonDB = require("common.CommonDB")
  4. local Msg = require("core.Msg")
  5. local ObjHuman = require("core.ObjHuman")
  6. local BagLogic = require("bag.BagLogic")
  7. local Grid = require("bag.Grid")
  8. local YunYingLogic = require("yunying.YunYingLogic")
  9. local PanelDefine = require("broadcast.PanelDefine")
  10. local SceneHandler = require("scene.Handler")
  11. local HaoliExcel = require("excel.present").leichongHaoli
  12. local function checkDB(human)
  13. human.db.leichongHaoli = human.db.leichongHaoli or {updateTime = 0, day = 0, get = {}}
  14. local haoliDB = human.db.leichongHaoli
  15. if haoliDB.day >= #HaoliExcel and not Util.isSameDay(haoliDB.upTime) then
  16. human.db.leichongHaoli = {updateTime = 0, day = 0, get = {}}
  17. end
  18. return human.db.leichongHaoli
  19. end
  20. GET_STATE0 = 0 --不可领取
  21. GET_STATE1 = 1 --未领取
  22. GET_STATE2 = 2 --已经领取
  23. local function getState(haoliDB,id,need)
  24. if haoliDB.day < need then
  25. return GET_STATE0
  26. end
  27. if haoliDB.get[id] then
  28. return GET_STATE2
  29. else
  30. return GET_STATE1
  31. end
  32. end
  33. function query(human)
  34. local haoliDB = checkDB(human)
  35. local msgRet = Msg.gc.GC_LEICHONG_HAOLI_QUERY
  36. local len = 0
  37. local len1 = 0
  38. local net
  39. for k,v in ipairs(HaoliExcel) do
  40. len = len + 1
  41. net = msgRet.list[len]
  42. net.id = k
  43. net.need = v.day
  44. net.state = getState(haoliDB,k,v.day)
  45. len1 = 0
  46. for k1,v1 in ipairs(v.reward) do
  47. len1 = len1 + 1
  48. Grid.makeItem(net.reward[len1], v1[1], v1[2])
  49. end
  50. net.reward[0] = len1
  51. end
  52. msgRet.list[0] = len
  53. Msg.send(msgRet, human.fd)
  54. end
  55. function get(human, id)
  56. local haoliDB = checkDB(human)
  57. local config = HaoliExcel[id]
  58. if getState(haoliDB,id,config.day) ~= GET_STATE1 then
  59. return
  60. end
  61. -- 改db
  62. haoliDB.get[id] = 1
  63. --发放奖励
  64. BagLogic.sendItemGetList(human, config.reward, "leichongHaoli")
  65. local msgRet = Msg.gc.GC_LEICHONG_HAOLI_GET
  66. Msg.send(msgRet,human.fd)
  67. for k, v in pairs(funcID) do
  68. YunYingLogic.updateIcon(YYInfo[k], human)
  69. YunYingLogic.sendGroupUpdate(YYInfo[k], human, PanelDefine.PANEL_ID_3305)
  70. break
  71. end
  72. end
  73. function isOpen(human)
  74. if true then
  75. return
  76. end
  77. if not SceneHandler.canCharge(human) then
  78. return
  79. end
  80. if not CommonDB.getServerOpenDay() then
  81. return
  82. end
  83. return true
  84. end
  85. function isRed(human)
  86. local haoliDB = checkDB(human)
  87. for k,v in ipairs(HaoliExcel) do
  88. if getState(haoliDB,k,v.day) == GET_STATE1 then
  89. return true
  90. end
  91. end
  92. end
  93. MONEY_LIMIT = 6
  94. function onAddMoney(human,money)
  95. if isOpen(human) ~= true then
  96. return
  97. end
  98. if money < MONEY_LIMIT then
  99. return
  100. end
  101. local haoliDB = checkDB(human)
  102. if not Util.isSameDay(haoliDB.upTime) then
  103. haoliDB.upTime = os.time()
  104. haoliDB.day = haoliDB.day + 1
  105. for k, v in pairs(funcID) do
  106. YunYingLogic.updateIcon(YYInfo[k], human)
  107. YunYingLogic.sendGroupUpdate(YYInfo[k], human, PanelDefine.PANEL_ID_3305)
  108. break
  109. end
  110. end
  111. end