PrivilegeGift.lua 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. PrivilegeGift = {}
  2. local db_privilege_gift_buy_record = "T$_privilege_gift_buy_record" -- 角色特权礼包购买记录
  3. local function _rechargeType()
  4. return "21"
  5. end
  6. local function _playerDbKey()
  7. return "T$recharge_privilege_gift_data"
  8. end
  9. function PrivilegeGift.saveData(actor, giftId)
  10. end
  11. function PrivilegeGift.getData(actor)
  12. end
  13. function PrivilegeGift.CheckPrivilegeGift(actor)
  14. local configs = ConfigDataManager.getList("cfg_gift_preferential")
  15. local rechargeRecord = RechargeRecord.get(actor)
  16. local msg = {}
  17. for _, config in pairs(configs) do
  18. local giftId = config.id
  19. local result, endtime = PrivilegeGift.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 PrivilegeGift.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. else
  51. endtime = giftEndtimes[tonumber(giftId)]
  52. end
  53. return true, endtime
  54. end
  55. return false, nil
  56. end
  57. function checkgift(actor)
  58. PrivilegeGift.CheckPrivilegeGift(actor)
  59. end
  60. -- function PrivilegeGift.login(actor)
  61. -- local data = PrivilegeGift.getData(actor)
  62. -- end
  63. function PrivilegeGift.rechargeEvent(actor, cfg_recharge, count, amount, ext, outRewards)
  64. local giftId = cfg_recharge.parameter
  65. local cfg_PrivilegePack = ConfigDataManager.getById("cfg_PrivilegePack", giftId)
  66. gameDebug.assertTrue(table.notNullOrEmpty(cfg_PrivilegePack), "没有配置特权礼包", giftId)
  67. if not ConditionManager.Check(actor, cfg_PrivilegePack.conditionid) then
  68. tipinfo(actor, "购买条件不满足")
  69. return
  70. end
  71. -- 发放奖励,注意采用绑定的
  72. local tmp_rewardsArr = string.split(cfg_PrivilegePack.rewards, "|") string.toStringStringMap(cfg_PrivilegePack.rewards, "#", "|")
  73. local career = getbaseinfo(actor,"getbasecareer")
  74. local rewards = {}
  75. for _, item in pairs(tmp_rewardsArr) do
  76. local itemArr = string.split(item, "#")
  77. if #itemArr <= 2 or tonumber(itemArr[3]) == career then
  78. rewards[itemArr[1]] = itemArr[2]
  79. end
  80. end
  81. Bag.sendRewardsByBind(actor, rewards, "1", "特权礼包")
  82. -- 发放特权卡,发放并使用
  83. local privilegeItemArr = string.split(cfg_PrivilegePack.privilegecard, "#")
  84. PrivilegeMonth.usePrivilegeCard(actor, privilegeItemArr[1], privilegeItemArr[2]) -- 特权卡使用处理
  85. -- 记录使用状态
  86. -- PrivilegeGift.saveData(actor, giftId)
  87. end
  88. -- ------------------------------------------------------------- --
  89. --TODO 一定要放到文件最后
  90. EventListerTable.registerType("特权礼包", _rechargeType(), _playerDbKey())
  91. -- 注册登录事件
  92. -- LoginEventListerTable:eventLister("0", "特权礼包", PrivilegeGift.login)
  93. -- 礼包通用事件注册
  94. RechargeEventListerTable:eventLister(_rechargeType(), "特权礼包", PrivilegeGift.rechargeEvent)