PreferentialGift.lua 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. PreferentialGift = {}
  2. local oneHour = 3600
  3. local function _playerDbTimeKey()
  4. return "T$GiftEndtimes"
  5. end
  6. local function getTimeInfo(actor)
  7. return getplaydef(actor, _playerDbTimeKey()) or {}
  8. end
  9. local function setTimeInfo(actor, data)
  10. setplaydef(actor, _playerDbTimeKey(), data)
  11. end
  12. function PreferentialGift.CheckPreferentialGift(actor)
  13. local configs = ConfigDataManager.getList("cfg_gift_preferential")
  14. local rechargeRecord = RechargeRecord.get(actor)
  15. local giftEndtimes = getTimeInfo(actor)
  16. local msg = {}
  17. for _, config in pairs(configs) do
  18. local giftId = config.id
  19. local result, endtime = PreferentialGift.doCheck(actor, giftId, rechargeRecord, giftEndtimes)
  20. if result then
  21. table.insert(msg, { giftId = giftId, endtime = endtime })
  22. end
  23. end
  24. -- lg("特惠礼包检查:",msg)
  25. sendluamsg(actor, LuaMessageIdToClient.RES_PREFERENTIAL_BUTTON_PANEL_INFO, msg)
  26. end
  27. function PreferentialGift.doCheck(actor, giftId, rechargeRecord, giftEndtimes)
  28. local nowSec = getbaseinfo(actor, "nowsec")
  29. local giftRecoed = rechargeRecord[giftId]
  30. if giftRecoed then
  31. return false, nil
  32. end
  33. local updateTime = false
  34. if giftEndtimes[tonumber(giftId)] and nowSec > giftEndtimes[tonumber(giftId)] then
  35. return false, nil
  36. elseif not giftEndtimes[tonumber(giftId)] then
  37. updateTime = true
  38. end
  39. local condition = ConfigDataManager.getTableValue("cfg_gift_preferential", "conditions", "id", giftId)
  40. if condition == '' then
  41. return false
  42. end
  43. local result = ConditionManager.Check(actor, condition)
  44. if result then
  45. local endtime
  46. if updateTime then
  47. local time = ConfigDataManager.getTableValue("cfg_gift_preferential", "time", "id", giftId)
  48. endtime = nowSec + tonumber(time) * oneHour
  49. giftEndtimes[tonumber(giftId)] = endtime
  50. setTimeInfo(actor, giftEndtimes)
  51. else
  52. endtime = giftEndtimes[tonumber(giftId)]
  53. end
  54. return true, endtime
  55. end
  56. return false, nil
  57. end
  58. function checkgift(actor)
  59. PreferentialGift.CheckPreferentialGift(actor)
  60. end
  61. -- 注册充值回调事件,在所有充值礼包之后
  62. RechargeEventListerTable:eventLister("0", "特惠礼包", PreferentialGift.CheckPreferentialGift, 99999999)