| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- -------------------------------------------------
- -- 未成年人充值限额(依据玩家年龄)
- -------------------------------------------------
- local Util = require("common.Util")
- local Lang = require("common.Lang")
- local Msg = require("core.Msg")
- local ObjHuman = require("core.ObjHuman")
- local Broadcast = require("broadcast.Broadcast")
- local BUY_PRICE_ONE2 = 50 -- 八周岁以上未满十六周岁,单次上限
- local BUY_PRICE_MONTH2 = 200 -- 八周岁以上未满十六周岁,每月累计上限
- local BUY_PRICE_ONE3 = 100 -- 十六周岁以上未满十八周岁,单次上限
- local BUY_PRICE_MONTH3 = 400 -- 十六周岁以上未满十八周岁,每月累计上限
- -- 充值限额类型
- TOPUP_LIMIT_NONE = 0 -- 成年人或未设置年龄,无限制
- TOPUP_LIMIT_FORBID = 1 -- 不满八周岁,禁止充值
- TOPUP_LIMIT_MINOR = 2 -- 八周岁以上未满十八周岁,有单次/月累计限额
- -- maxMonthTopup 协议约定:-1 无限制,0 禁止充值,>0 为月累计上限
- TOPUP_MONTH_NO_LIMIT = -1
- local function getAge(human)
- return human.db.age
- end
- -- 返回:limitType, maxSingleTopup, maxMonthTopup
- local function getLimitByAge(age)
- if not age or age >= 18 then
- return TOPUP_LIMIT_NONE, 0, TOPUP_MONTH_NO_LIMIT
- end
- if age < 8 then
- return TOPUP_LIMIT_FORBID, 0, 0
- elseif age < 16 then
- return TOPUP_LIMIT_MINOR, BUY_PRICE_ONE2, BUY_PRICE_MONTH2
- elseif age < 18 then
- return TOPUP_LIMIT_MINOR, BUY_PRICE_ONE3, BUY_PRICE_MONTH3
- end
- return TOPUP_LIMIT_NONE, 0, TOPUP_MONTH_NO_LIMIT
- end
- function getLimitInfo(human)
- local age = getAge(human) or 0
- local monthTopup = human.db.topupAccountMonth or 0
- local limitType, maxSingleTopup, maxMonthTopup = getLimitByAge(getAge(human))
- return age, monthTopup, maxMonthTopup, maxSingleTopup, limitType
- end
- local function checkBuyPrice(human, price, oneLimit, monthLimit, ageTip)
- if price > oneLimit then
- Broadcast.sendErr(human, Util.format(Lang.BUY_CHECK_ERR_FCM_AGE, ageTip))
- Broadcast.sendErr(human, Util.format(Lang.BUY_CHECK_ERR_FCM_ONE, oneLimit))
- return false
- end
- local sum = human.db.topupAccountMonth or 0
- if (sum + price) > monthLimit then
- Broadcast.sendErr(human, Util.format(Lang.BUY_CHECK_ERR_FCM_AGE, ageTip))
- Broadcast.sendErr(human, Util.format(Lang.BUY_CHECK_ERR_FCM_MONTH, monthLimit))
- return false
- end
- return true
- end
- function checkCanBuy(human, price)
- if not human.db then
- return true
- end
- ObjHuman.updateDaily(human)
- local limitType, maxSingleTopup, maxMonthTopup = getLimitByAge(getAge(human))
- if limitType == TOPUP_LIMIT_NONE then
- return true
- end
- if limitType == TOPUP_LIMIT_FORBID then
- Broadcast.sendErr(human, Util.format(Lang.BUY_CHECK_ERR_FCM_AGE, 8))
- Broadcast.sendErr(human, Lang.BUY_CHECK_ERR_FCM_NOCHARGE)
- return false
- end
- local ageTip = maxMonthTopup == BUY_PRICE_MONTH2 and 16 or 18
- return checkBuyPrice(human, price, maxSingleTopup, maxMonthTopup, ageTip)
- end
- function query(human)
- ObjHuman.updateDaily(human)
- local age, monthTopup, maxMonthTopup = getLimitInfo(human)
- local msgRet = Msg.gc.GC_TOPUP_AGE_QUERY
- msgRet.age = age
- msgRet.monthTopup = monthTopup
- msgRet.maxMonthTopup = maxMonthTopup
- Msg.send(msgRet, human.fd)
- end
|