AgeLimitLogic.lua 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. -------------------------------------------------
  2. -- 未成年人充值限额(依据玩家年龄)
  3. -------------------------------------------------
  4. local Util = require("common.Util")
  5. local Lang = require("common.Lang")
  6. local Msg = require("core.Msg")
  7. local ObjHuman = require("core.ObjHuman")
  8. local Broadcast = require("broadcast.Broadcast")
  9. local BUY_PRICE_ONE2 = 50 -- 八周岁以上未满十六周岁,单次上限
  10. local BUY_PRICE_MONTH2 = 200 -- 八周岁以上未满十六周岁,每月累计上限
  11. local BUY_PRICE_ONE3 = 100 -- 十六周岁以上未满十八周岁,单次上限
  12. local BUY_PRICE_MONTH3 = 400 -- 十六周岁以上未满十八周岁,每月累计上限
  13. -- 充值限额类型
  14. TOPUP_LIMIT_NONE = 0 -- 成年人或未设置年龄,无限制
  15. TOPUP_LIMIT_FORBID = 1 -- 不满八周岁,禁止充值
  16. TOPUP_LIMIT_MINOR = 2 -- 八周岁以上未满十八周岁,有单次/月累计限额
  17. -- maxMonthTopup 协议约定:-1 无限制,0 禁止充值,>0 为月累计上限
  18. TOPUP_MONTH_NO_LIMIT = -1
  19. local function getAge(human)
  20. return human.db.age
  21. end
  22. -- 返回:limitType, maxSingleTopup, maxMonthTopup
  23. local function getLimitByAge(age)
  24. if not age or age >= 18 then
  25. return TOPUP_LIMIT_NONE, 0, TOPUP_MONTH_NO_LIMIT
  26. end
  27. if age < 8 then
  28. return TOPUP_LIMIT_FORBID, 0, 0
  29. elseif age < 16 then
  30. return TOPUP_LIMIT_MINOR, BUY_PRICE_ONE2, BUY_PRICE_MONTH2
  31. elseif age < 18 then
  32. return TOPUP_LIMIT_MINOR, BUY_PRICE_ONE3, BUY_PRICE_MONTH3
  33. end
  34. return TOPUP_LIMIT_NONE, 0, TOPUP_MONTH_NO_LIMIT
  35. end
  36. function getLimitInfo(human)
  37. local age = getAge(human) or 0
  38. local monthTopup = human.db.topupAccountMonth or 0
  39. local limitType, maxSingleTopup, maxMonthTopup = getLimitByAge(getAge(human))
  40. return age, monthTopup, maxMonthTopup, maxSingleTopup, limitType
  41. end
  42. local function checkBuyPrice(human, price, oneLimit, monthLimit, ageTip)
  43. if price > oneLimit then
  44. Broadcast.sendErr(human, Util.format(Lang.BUY_CHECK_ERR_FCM_AGE, ageTip))
  45. Broadcast.sendErr(human, Util.format(Lang.BUY_CHECK_ERR_FCM_ONE, oneLimit))
  46. return false
  47. end
  48. local sum = human.db.topupAccountMonth or 0
  49. if (sum + price) > monthLimit then
  50. Broadcast.sendErr(human, Util.format(Lang.BUY_CHECK_ERR_FCM_AGE, ageTip))
  51. Broadcast.sendErr(human, Util.format(Lang.BUY_CHECK_ERR_FCM_MONTH, monthLimit))
  52. return false
  53. end
  54. return true
  55. end
  56. function checkCanBuy(human, price)
  57. if not human.db then
  58. return true
  59. end
  60. ObjHuman.updateDaily(human)
  61. local limitType, maxSingleTopup, maxMonthTopup = getLimitByAge(getAge(human))
  62. if limitType == TOPUP_LIMIT_NONE then
  63. return true
  64. end
  65. if limitType == TOPUP_LIMIT_FORBID then
  66. Broadcast.sendErr(human, Util.format(Lang.BUY_CHECK_ERR_FCM_AGE, 8))
  67. Broadcast.sendErr(human, Lang.BUY_CHECK_ERR_FCM_NOCHARGE)
  68. return false
  69. end
  70. local ageTip = maxMonthTopup == BUY_PRICE_MONTH2 and 16 or 18
  71. return checkBuyPrice(human, price, maxSingleTopup, maxMonthTopup, ageTip)
  72. end
  73. function query(human)
  74. ObjHuman.updateDaily(human)
  75. local age, monthTopup, maxMonthTopup = getLimitInfo(human)
  76. local msgRet = Msg.gc.GC_TOPUP_AGE_QUERY
  77. msgRet.age = age
  78. msgRet.monthTopup = monthTopup
  79. msgRet.maxMonthTopup = maxMonthTopup
  80. Msg.send(msgRet, human.fd)
  81. end