LimitBuy.lua 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 SceneHandler = require("scene.Handler")
  10. local LimitBuyExcel = require("excel.limitBuy").limitBuy
  11. local function checkDB(human)
  12. human.db.limitBuy = human.db.limitBuy or {startTime = 0, get = {}}
  13. local limitBuyDB = human.db.limitBuy
  14. local weekStartTime = Util.getWeekStartTime(os.time())
  15. if weekStartTime ~= limitBuyDB.startTime then
  16. limitBuyDB.startTime = weekStartTime
  17. limitBuyDB.get = {}
  18. end
  19. return human.db.limitBuy
  20. end
  21. function query(human)
  22. local limitBuyDB = checkDB(human)
  23. local msgRet = Msg.gc.GC_LIMITBUY_QUERY
  24. local len = 0
  25. local len1 = 0
  26. local net
  27. for k,v in ipairs(LimitBuyExcel) do
  28. len = len + 1
  29. net = msgRet.list[len]
  30. net.id = k
  31. net.nowCnt = limitBuyDB.get[k] or 0
  32. net.maxCnt = v.cnt
  33. net.desc = v.desc
  34. len1 = 0
  35. for k1,v1 in ipairs(v.items) do
  36. len1 = len1 + 1
  37. Grid.makeItem(net.reward[len1], v1[1], v1[2])
  38. end
  39. net.reward[0] = len1
  40. BuyLogic.fontBuyItem(human,net.buyItem,v.buyID)
  41. end
  42. msgRet.list[0] = len
  43. local now = os.time()
  44. msgRet.leftTime = Util.getWeekStartTime(now) - now + 604800
  45. Msg.send(msgRet, human.fd)
  46. end
  47. function buy(human, id)
  48. if true then
  49. return
  50. end
  51. local limitBuyDB = checkDB(human)
  52. local config = LimitBuyExcel[id]
  53. if limitBuyDB.get[id] and limitBuyDB.get[id] >= config.cnt then
  54. return
  55. end
  56. -- 改db
  57. limitBuyDB.get[id] = limitBuyDB.get[id] or 0
  58. limitBuyDB.get[id] = limitBuyDB.get[id] + 1
  59. --发放奖励
  60. BagLogic.addItemList(human, config.items, "limitBuy")
  61. query(human)
  62. end
  63. function isOpen(human)
  64. if true then
  65. return
  66. end
  67. if not SceneHandler.canCharge(human) then
  68. return
  69. end
  70. if not CommonDB.getServerOpenDay() then
  71. return
  72. end
  73. return true
  74. end