123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041 |
- --月卡相关
- MonthCard = {}
- MonthCard.monthcardtype = {
- --永久限购
- NEVER = 1,
- --每月
- MONTH = 2,
- --每周
- WEEK = 3,
- --每日
- DAY = 4
- }
- local function _rechargeType()
- return "2"
- end
- local function _playerDbKey()
- return "T$monthcard"
- end
- -- 关闭月卡功能
- local card_is_close = true
- --function MonthCard.checkitemismonthcard(itemcfgid)
- -- local config = ConfigDataManager.getTable("cfg_monthlyPass", "id", itemcfgid)
- -- if config == nil or table.count(config) == 0 then
- -- return false
- -- end
- -- return true
- --end
- --月卡限购
- function MonthCard.limitCount(actor, type)
- local monthcard = getplaydef(actor, _playerDbKey())
- if monthcard == nil then
- return
- end
- local change_ids = {}
- for goodsId, hascard in pairs(monthcard) do
- if type(info) == "table" then
- local limit_type = ConfigDataManager.getTableValue("cfg_monthlypass", "limittype", "id", goodsId)
- if tonumber(type) == tonumber(limit_type) then
- hascard.buycount = 0
- table.insert(change_ids, goodsId)
- end
- end
- end
- setplaydef(actor, _playerDbKey(), monthcard)
- for _, id in pairs(change_ids) do
- local result = table.valueConvertToString(monthcard[id])
- --给客户端发月卡信息
- sendluamsg(actor, LuaMessageIdToClient.RES_MONTHCARD_CHANGE_INFO, result)
- end
- end
- --充值月卡
- function MonthCard.limitbuycount(actor, cfg, count, amount, ext, outRewards)
- if card_is_close then
- return
- end
- local goodsId = cfg.parameter
- local monthcard = getplaydef(actor, _playerDbKey())
- if monthcard == nil then
- monthcard = {}
- monthcard.todayreceivethreetime = false
- monthcard.receivetime = 0
- end
- local hascard = monthcard[tostring(goodsId)]
- if hascard == nil then
- hascard = {}
- hascard.cfgId = goodsId
- hascard.buycount = 0
- hascard.vaildTime = 0
- hascard.isopen = false
- hascard.isfirstbuy = true
- end
- hascard.buycount = hascard.buycount + tonumber(count)
- monthcard[tostring(goodsId)] = hascard
- hascard.isfirstbuy = false
- setplaydef(actor, _playerDbKey(), monthcard)
- local result = table.valueConvertToString(hascard)
- --给客户端发月卡信息
- sendluamsg(actor, LuaMessageIdToClient.RES_MONTHCARD_CHANGE_INFO, result)
- end
- -- 月卡时间增加
- function MonthCard.addTime(actor, day)
- if card_is_close then
- return
- end
- local monthcard = getplaydef(actor, _playerDbKey())
- local hascard = nil
- --更新玩家月卡信息
- local mcfgId = getmonthcardcfgid(actor)
- if mcfgId == 0 then
- mcfgId = getdaycardcfgid(actor)
- end
- if mcfgId ~= 0 then
- hascard = monthcard[tostring(mcfgId)]
- end
- if not hascard then
- for _, info in pairs(monthcard) do
- if type(info) == "table" then
- hascard = info
- local now = getbaseinfo("now")
- hascard.vaildTime = now
- hascard.isopen = true
- end
- end
- end
- hascard.vaildTime = hascard.vaildTime + tonumber(day) * 24 * 60 * 60 * 1000
- monthcard[tostring(hascard.cfgId)] = hascard
- setplaydef(actor, _playerDbKey(), monthcard)
- local result = table.valueConvertToString(hascard)
- --给客户端发月卡信息
- sendluamsg(actor, LuaMessageIdToClient.RES_MONTHCARD_CHANGE_INFO, result)
- end
- --使用月卡
- function MonthCard.usemonthcard(actor, cfgId, count)
- if card_is_close then
- return
- end
- local item = ConfigDataManager.getTable("cfg_item", "id", cfgId)
- if item == nil or next(item) == nil then
- return
- end
- if tonumber(item[1].type) ~= 7 then
- return
- end
- local subtype = item[1].subtype
- local config = ConfigDataManager.getTable("cfg_monthlyPass", "order", subtype)
- if config == nil or next(config) == nil then
- --不是月卡
- return
- end
- cfgId = config[1].id
- local now = getbaseinfo("now")
- local receThreeTime = tonumber(item[1].useparam) == 1 and true or false
- local monthcard = getplaydef(actor, _playerDbKey())
- if monthcard == nil then
- monthcard = {}
- monthcard.todayreceivethreetime = false
- monthcard.receivetime = 0
- end
- local hascard = monthcard[tostring(cfgId)]
- if hascard == nil then
- hascard = {}
- hascard.isfirstbuy = true
- hascard.isopen = false
- hascard.vaildTime = 0
- hascard.buycount = 0
- hascard.cfgId = cfgId
- end
- --先判断是月卡还是周卡
- local order = tonumber(subtype)
- local time = tonumber(item[1].useparam2) * 1000 * tonumber(count)
- --月卡,检查玩家当前是否有月卡、日卡
- local bool = checkactorhasmonthcard(actor)
- local bools = checkactorhasdaycard(actor)
- if order == 1 then
- if bool then
- --直接加时间就行,其他不变
- hascard.vaildTime = hascard.vaildTime + time
- --校验三倍时间是否发放
- if receThreeTime then
- if hascard.isfirstbuy then
- TripleIncome.AddRemainTime(actor, tonumber(config[1].firstincome) * 60 * 60)
- monthcard.receivetime = now
- else
- if not TimeUtil.isSameDay(math.floor(monthcard.receivetime / 1000), math.floor(now / 1000)) then
- TripleIncome.AddRemainTime(actor, tonumber(config[1].dayincome) * 60 * 60)
- monthcard.receivetime = now
- end
- end
- monthcard.todayreceivethreetime = true
- hascard.isfirstbuy = false
- end
- else
- if bools then
- --如果有日卡,算日卡的剩余时间,转化成月卡
- local daytime = getdaycardtime(actor)
- --先关闭日卡,再加到月卡上
- for _, info in pairs(monthcard) do
- if type(info) == "table" then
- if info.isopen then
- info.isopen = false
- end
- end
- end
- hascard.vaildTime = daytime + time
- hascard.isopen = true
- if receThreeTime then
- if hascard.isfirstbuy then
- --发放额外三倍时间
- TripleIncome.AddRemainTime(actor, tonumber(config[1].firstincome) * 60 * 60)
- monthcard.todayreceivethreetime = true
- monthcard.receivetime = now
- else
- --校验三倍时间是否发放
- if not TimeUtil.isSameDay(math.floor(monthcard.receivetime / 1000), math.floor(now / 1000)) then
- TripleIncome.AddRemainTime(actor, tonumber(config[1].dayincome) * 60 * 60)
- monthcard.todayreceivethreetime = true
- monthcard.receivetime = now
- end
- end
- hascard.isfirstbuy = false
- end
- else
- monthcard = setmonthcardinfo(actor, hascard, monthcard, now, time, config, cfgId, receThreeTime)
- end
- end
- end
- if order == 2 then
- --日卡
- if bool then
- --时间直接加到月卡上
- for _, info in pairs(monthcard) do
- if type(info) == "table" then
- if info.isopen then
- info.vaildTime = info.vaildTime + time
- end
- end
- end
- if receThreeTime then
- if hascard.isfirstbuy then
- --发放额外三倍时间
- TripleIncome.AddRemainTime(actor, tonumber(config[1].firstincome) * 60 * 60)
- monthcard.receivetime = now
- else
- --校验三倍时间是否发放
- if not TimeUtil.isSameDay(math.floor(monthcard.receivetime / 1000), math.floor(now / 1000)) then
- TripleIncome.AddRemainTime(actor, tonumber(config[1].dayincome) * 60 * 60)
- monthcard.receivetime = now
- end
- end
- monthcard.todayreceivethreetime = true
- hascard.isfirstbuy = false
- end
- else
- if bools then
- --直接加时间就行
- hascard.vaildTime = hascard.vaildTime + time
- if receThreeTime then
- if hascard.isfirstbuy then
- --发放额外三倍时间
- TripleIncome.AddRemainTime(actor, tonumber(config[1].firstincome) * 60 * 60)
- monthcard.receivetime = now
- else
- if not TimeUtil.isSameDay(math.floor(monthcard.receivetime / 1000), math.floor(now / 1000)) then
- TripleIncome.AddRemainTime(actor, tonumber(config[1].dayincome) * 60 * 60)
- monthcard.receivetime = now
- end
- end
- monthcard.todayreceivethreetime = true
- hascard.isfirstbuy = false
- end
- else
- monthcard = setmonthcardinfo(actor, hascard, monthcard, now, time, config, cfgId, receThreeTime)
- end
- end
- end
- -- monthcard.todayreceivethreetime = true --今日是否领取三倍时间
- --更新玩家月卡信息
- setplaydef(actor, _playerDbKey(), monthcard)
- local mcfgId = getmonthcardcfgid(actor)
- if mcfgId == 0 then
- mcfgId = getdaycardcfgid(actor)
- if mcfgId == 0 then
- hascard = {}
- end
- else
- hascard = monthcard[tostring(mcfgId)]
- end
- local result = table.valueConvertToString(hascard)
- --给客户端发月卡信息
- sendluamsg(actor, LuaMessageIdToClient.RES_MONTHCARD_CHANGE_INFO, result)
- end
- function setmonthcardinfo(actor, hascard, monthcard, now, time, config, cfgId, receThreeTime)
- if hascard == nil then
- hascard = {}
- end
- if hascard.vaildTime == 0 then
- hascard.cfgId = cfgId
- hascard.vaildTime = now + time
- --首次获得赠送三倍时间
- if receThreeTime then
- TripleIncome.AddRemainTime(actor, tonumber(config[1].firstincome) * 60 * 60)
- monthcard.receivetime = now
- monthcard.todayreceivethreetime = true
- hascard.isfirstbuy = false -- 是否是首次购买
- end
- hascard.isopen = true -- 是否开始生效,true 生效,false 不生效 --用于校验过期时间
- else
- if hascard.vaildTime < now then
- hascard.vaildTime = now + time
- if receThreeTime then
- if hascard.isfirstbuy then
- TripleIncome.AddRemainTime(actor, tonumber(config[1].firstincome) * 60 * 60)
- monthcard.receivetime = now
- else
- --过期了再获得,同时发放每日三倍时间
- TripleIncome.AddRemainTime(actor, tonumber(config[1].dayincome) * 60 * 60)
- monthcard.receivetime = now
- end
- monthcard.todayreceivethreetime = true
- hascard.isfirstbuy = false
- end
- hascard.isopen = true
- else
- --没过期,时间叠加
- hascard.vaildTime = hascard.vaildTime + time
- hascard.isopen = true
- if receThreeTime then
- --校验三倍时间是否发放
- if hascard.isfirstbuy then
- TripleIncome.AddRemainTime(actor, tonumber(config[1].firstincome) * 60 * 60)
- monthcard.receivetime = now
- else
- if not TimeUtil.isSameDay(math.floor(monthcard.receivetime / 1000), math.floor(now / 1000)) then
- TripleIncome.AddRemainTime(actor, tonumber(config[1].dayincome) * 60 * 60)
- monthcard.receivetime = now
- end
- end
- hascard.isfirstbuy = false
- monthcard.todayreceivethreetime = true
- end
- end
- end
- monthcard[tostring(cfgId)] = hascard
- return monthcard
- end
- --检查玩家是否有月卡
- function checkactorhasmonthcard(actor)
- if card_is_close then
- return false
- end
- local monthcard = getplaydef(actor, _playerDbKey())
- if monthcard == nil then
- return false
- end
- for _, info in pairs(monthcard) do
- if type(info) == "table" then
- if info.isopen then
- local config = ConfigDataManager.getTable("cfg_monthlyPass", "id", info.cfgId)
- if config == nil then
- return false
- end
- if tonumber(config[1].order) == 1 then
- return true
- end
- end
- end
- end
- return false
- end
- --检查玩家是否有日卡
- function checkactorhasdaycard(actor)
- if card_is_close then
- return false
- end
- local monthcard = getplaydef(actor, _playerDbKey())
- if monthcard == nil then
- return false
- end
- for _, info in pairs(monthcard) do
- if type(info) == "table" then
- if info.isopen then
- local config = ConfigDataManager.getTable("cfg_monthlyPass", "id", info.cfgId)
- if config == nil then
- return false
- end
- if tonumber(config[1].order) == 2 then
- return true
- end
- end
- end
- end
- return false
- end
- --算日卡的剩余时间
- function getdaycardtime(actor)
- if card_is_close then
- return 0
- end
- local monthcard = getplaydef(actor, _playerDbKey())
- if monthcard == nil then
- return 0
- end
- for _, info in pairs(monthcard) do
- if type(info) == "table" then
- if info.isopen then
- local config = ConfigDataManager.getTable("cfg_monthlyPass", "id", info.cfgId)
- if config == nil then
- return 0
- end
- if tonumber(config[1].order) == 2 then
- return info.vaildTime
- end
- end
- end
- end
- return 0
- end
- --获取日卡cfgId
- function getdaycardcfgid(actor)
- local monthcard = getplaydef(actor, _playerDbKey())
- if monthcard == nil then
- return 0
- end
- for _, info in pairs(monthcard) do
- if type(info) == "table" then
- if info.isopen then
- local config = ConfigDataManager.getTable("cfg_monthlyPass", "id", info.cfgId)
- if config == nil then
- return 0
- end
- if tonumber(config[1].order) == 2 then
- return info.cfgId
- end
- end
- end
- end
- return 0
- end
- --获取月卡cfgId
- function getmonthcardcfgid(actor)
- local monthcard = getplaydef(actor, _playerDbKey())
- if monthcard == nil then
- return 0
- end
- for _, info in pairs(monthcard) do
- if type(info) == "table" then
- if info.isopen then
- local config = ConfigDataManager.getTable("cfg_monthlyPass", "id", info.cfgId)
- if config == nil then
- return 0
- end
- if tonumber(config[1].order) == 1 then
- return info.cfgId
- end
- end
- end
- end
- return 0
- end
- --算月卡的剩余时间
- function getmonthcardtime(actor)
- if card_is_close then
- return 0
- end
- local monthcard = getplaydef(actor, _playerDbKey())
- if monthcard == nil then
- return 0
- end
- for _, info in pairs(monthcard) do
- if type(info) == "table" then
- if info.isopen then
- local config = ConfigDataManager.getTable("cfg_monthlyPass", "id", info.cfgId)
- if config == nil then
- return 0
- end
- if tonumber(config[1].order) == 1 then
- return info.vaildTime
- end
- end
- end
- end
- return 0
- end
- --获取月卡信息
- function MonthCard.getmonthcardinfo(actor)
- local monthcard = getplaydef(actor, _playerDbKey())
- if monthcard == nil then
- monthcard = {}
- end
- --给客户端发月卡信息
- local result = table.valueConvertToString(monthcard)
- sendluamsg(actor, LuaMessageIdToClient.RES_GET_MONTHCARD_INFO, result)
- -- Trade.sendRecharge(actor)
- end
- --检查月卡是否过期,过期时给客户端发送变化消息
- function MonthCard.checkmonthcardtime(actor)
- if card_is_close then
- return
- end
- local monthcard = getplaydef(actor, _playerDbKey())
- if monthcard == nil then
- return
- end
- local result = {}
- local now = getbaseinfo("now")
- for key, info in pairs(monthcard) do
- if type(info) == "table" then
- if info.isopen then
- if info.vaildTime < now then
- info.isopen = false
- result[tostring(table.count(result)) + 1] = key
- end
- end
- end
- end
- if table.count(result) == 0 then
- return
- end
- --更新月卡信息
- setplaydef(actor, _playerDbKey(), monthcard)
- --月卡过期,给客户端发送过期协议
- sendluamsg(actor, LuaMessageIdToClient.RES_MONTHCARD_OVERTIME, result)
- end
- function MonthCard.login(actor)
- if card_is_close then
- return
- end
- MonthCard.getmonthcardinfo(actor)
- jprint("--------- 登录发送月卡信息 -------")
- --获取上次离线的时间戳
- local offtime = getplaydef(actor, "T$offlinetime")
- if offtime == nil then
- return
- end
- local offlinetime = math.ceil(offtime / 1000)
- if offlinetime == 0 then
- return
- end
- local now = math.ceil(getbaseinfo("now") / 1000)
- --获取上次最长时间月卡距离离线时间有多久
- local result = summonthcardtoofflinetime(actor)
- if result.time < offlinetime then
- return
- end
- if TimeUtil.isSameDay(offlinetime, result.time) then
- return
- end
- --标志是否小于24小时,小于24小时要少发一天
- local daytime = 0
- if result.time > now then
- result.time = now
- --只有一种情况不用少发一天,就是当前月卡时间大于登录时间,而且超过24小时,其余情况都要少发一次
- if TimeUtil.within24hours(result.time, now) then
- daytime = timestamp_diff_days(offlinetime, result.time) - 1
- else
- daytime = timestamp_diff_days(offlinetime, result.time)
- end
- else
- daytime = timestamp_diff_days(offlinetime, result.time) - 1
- end
- --计算要发的时间,传递给三倍时间那边
- -- jprint("计算要发的时间",daytime)
- if daytime <= 0 then
- return
- end
- local config = ConfigDataManager.getTableValue("cfg_monthlyPass", "dayInCome", "id", result.cfgId)
- if config == nil then
- return
- end
- --传递
- TripleIncome.AddRemainTime(actor, tonumber(config) * daytime * 60 * 60)
- end
- function summonthcardtoofflinetime(actor)
- local monthcard = getplaydef(actor, _playerDbKey())
- local result = {}
- result.cfgId = 0
- result.time = 0
- if monthcard == nil then
- return result
- end
- for _, info in pairs(monthcard) do
- if type(info) == "table" then
- if info.vaildTime > result.time then
- result.time = math.ceil(info.vaildTime / 1000)
- result.cfgId = info.cfgId
- end
- end
- end
- return result
- end
- --计算两个时间戳相差了多少天
- function timestamp_diff_days(t1, t2)
- local date1 = TimeUtil.timeToDate(t1)
- local date2 = TimeUtil.timeToDate(t2)
- local function is_leap_year(year)
- return ((year % 4 == 0 and year % 100 ~= 0) or year % 400 == 0)
- end
- local function days_in_month(year, month)
- local days = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
- if month == 2 and is_leap_year(year) then
- return 29
- else
- return days[month]
- end
- end
- local function days_between(year1, month1, day1, year2, month2, day2)
- local years = year2 - year1
- local months = month2 - month1
- local days = day2 - day1
- for y = 1, math.abs(years) do
- local year = year1 + (y - 1) * (years > 0 and 1 or -1)
- days = days + (is_leap_year(year) and 366 or 365)
- end
- for m = 1, math.abs(months) do
- local month = month1 + (m - 1) * (months > 0 and 1 or -1)
- local year = year1 + (m - 1 + (years > 0 and 1 or 0)) * (years > 0 and 1 or -1)
- days = days + days_in_month(year, month)
- end
- return days
- end
- local days = days_between(date1.year, date1.month, date1.day, date2.year, date2.month, date2.day)
- return days
- end
- --发放三倍时间
- function MonthCard.receivemonthcardthreetime(actor)
- if card_is_close then
- return
- end
- local monthcard = getplaydef(actor, _playerDbKey())
- local result = {}
- result.success = false
- if monthcard == nil then
- -- result.reason = "请先开通月卡后领取!"
- -- sendluamsg(actor,LuaMessageIdToClient.RES_MONTHCARD_THREETIME,result)
- return
- end
- if monthcard.todayreceivethreetime == nil then
- -- result.reason = "请先开通月卡后领取!"
- -- sendluamsg(actor,LuaMessageIdToClient.RES_MONTHCARD_THREETIME,result)
- return
- end
- local now = getbaseinfo("now")
- for key, info in pairs(monthcard) do
- if type(info) == "table" then
- if info.isopen then
- --校验时间是否大于24小时
- local vaildTime = info.vaildTime
- local bool = TimeUtil.within24hours(now, vaildTime)
- if bool then
- -- result.reason = "月卡时间少于24小时,请续费后领取!"
- -- sendluamsg(actor,LuaMessageIdToClient.RES_MONTHCARD_THREETIME,result)
- return
- else
- --领取
- local dayincome = ConfigDataManager.getTableValue("cfg_monthlyPass", "dayInCome", "id", key)
- if dayincome == nil then
- -- result.reason = "领取失败!"
- -- sendluamsg(actor,LuaMessageIdToClient.RES_MONTHCARD_THREETIME,result)
- return
- end
- local time = tonumber(dayincome) * 60 * 60
- TripleIncome.AddRemainTime(actor, time)
- monthcard.todayreceivethreetime = true
- monthcard.receivetime = now
- --给客户端发消息
- -- result.success = true
- -- result.reason = "领取成功!"
- -- sendluamsg(actor,LuaMessageIdToClient.RES_MONTHCARD_THREETIME,result)
- return
- end
- end
- end
- end
- end
- --扣除指定的月卡时间,单位day
- function MonthCard.deletemonthcardtime(actor, day)
- if card_is_close then
- return false
- end
- local monthcard = getplaydef(actor, _playerDbKey())
- if monthcard == nil then
- return false
- end
- local bools = checkactorhasmonthcard(actor)
- local now = getbaseinfo("now")
- local kTime = tonumber(day) * 24 * 60 * 60 * 1000
- local hascard = {}
- if bools then
- local vaildTime = getmonthcardtime(actor)
- if vaildTime - now < kTime then
- return false
- end
- local cfgId = getmonthcardcfgid(actor)
- hascard = monthcard[tostring(cfgId)]
- hascard.vaildTime = hascard.vaildTime - kTime
- monthcard[tostring(cfgId)] = hascard
- end
- local bool = checkactorhasdaycard(actor)
- if bool then
- local vaildTime = getdaycardtime(actor)
- if vaildTime - now < kTime then
- return false
- end
- local cfgId = getdaycardcfgid(actor)
- hascard = monthcard[tostring(cfgId)]
- hascard.vaildTime = hascard.vaildTime - kTime
- monthcard[tostring(cfgId)] = hascard
- end
- if not bool and not bools then
- return false
- end
- setplaydef(actor, _playerDbKey(), monthcard)
- --发送月卡变化包
- local result = table.valueConvertToString(hascard)
- --给客户端发月卡信息
- sendluamsg(actor, LuaMessageIdToClient.RES_MONTHCARD_CHANGE_INFO, result)
- return true
- end
- --上架月卡
- function MonthCard.upshelfmonthcard(actor, msgData)
- local cfgId = msgData.itemcfgid
- if tonumber(cfgId) ~= 30030305 then
- sendluamsg(actor, LuaMessageIdToClient.TIPS, "该道具不能上架交易行!")
- return
- end
- --获取要上架的天数,要先从自己的月卡中扣掉
- local count = msgData.count
- local monthcard = getplaydef(actor, _playerDbKey())
- if monthcard == nil then
- sendluamsg(actor, LuaMessageIdToClient.TIPS, "背包内没有足够的道具!")
- return
- end
- local now = getbaseinfo("now")
- local bool = checkactorhasdaycard(actor)
- local cardid = 0
- if bool then
- --扣时间
- local daycardcfgId = getdaycardcfgid(actor)
- local hascard = monthcard[tostring(daycardcfgId)]
- local number = ConfigDataManager.getTableValue("cfg_stall", "number", "id", cfgId)
- if number == nil then
- return
- end
- local vaildTime = hascard.vaildTime - now
- local kTime = tonumber(number) * 24 * 60 * 60 * 1000 * tonumber(count)
- if vaildTime < kTime then
- sendluamsg(actor, LuaMessageIdToClient.TIPS, "月卡剩余时间不足!")
- return
- end
- hascard.vaildTime = hascard.vaildTime - kTime
- monthcard[tostring(daycardcfgId)] = hascard
- cardid = daycardcfgId
- end
- local bools = checkactorhasmonthcard(actor)
- if bools then
- --扣时间
- local monthcardcfgId = getmonthcardcfgid(actor)
- local hascard = monthcard[tostring(monthcardcfgId)]
- local number = ConfigDataManager.getTableValue("cfg_stall", "number", "id", cfgId)
- if number == nil then
- return
- end
- local vaildTime = hascard.vaildTime - now
- local kTime = tonumber(number) * 24 * 60 * 60 * 1000 * tonumber(count)
- if vaildTime < kTime then
- sendluamsg(actor, LuaMessageIdToClient.TIPS, "月卡剩余时间不足!")
- return
- end
- hascard.vaildTime = hascard.vaildTime - kTime
- monthcard[tostring(monthcardcfgId)] = hascard
- cardid = monthcardcfgId
- end
- setplaydef(actor, _playerDbKey(), monthcard)
- --发送月卡变化包
- local hascard = monthcard[tostring(cardid)]
- local result = table.valueConvertToString(hascard)
- --给客户端发月卡信息
- sendluamsg(actor, LuaMessageIdToClient.RES_MONTHCARD_CHANGE_INFO, result)
- msgData.bagindex = "-1"
- --走通用的上架方法
- Trade.worldTradeListing(actor, msgData)
- end
- -- 减少月卡时间
- function MonthCard.deleteTime(actor, day)
- local monthcard = getplaydef(actor, _playerDbKey())
- if monthcard == nil then
- sendluamsg(actor, LuaMessageIdToClient.TIPS, "背包内没有足够的道具!")
- return false
- end
- local now = getbaseinfo("now")
- local bool = checkactorhasdaycard(actor)
- local cardid = 0
- if bool then
- --扣时间
- local daycardcfgId = getdaycardcfgid(actor)
- local hascard = monthcard[tostring(daycardcfgId)]
- local vaildTime = hascard.vaildTime - now
- local kTime = 24 * 60 * 60 * 1000 * tonumber(day)
- if vaildTime < kTime then
- sendluamsg(actor, LuaMessageIdToClient.TIPS, "月卡剩余时间不足!")
- return false
- end
- hascard.vaildTime = hascard.vaildTime - kTime
- monthcard[tostring(daycardcfgId)] = hascard
- cardid = daycardcfgId
- end
- local bools = checkactorhasmonthcard(actor)
- if bools then
- --扣时间
- local monthcardcfgId = getmonthcardcfgid(actor)
- local hascard = monthcard[tostring(monthcardcfgId)]
- local vaildTime = hascard.vaildTime - now
- local kTime = 24 * 60 * 60 * 1000 * tonumber(day)
- if vaildTime < kTime then
- sendluamsg(actor, LuaMessageIdToClient.TIPS, "月卡剩余时间不足!")
- return false
- end
- hascard.vaildTime = hascard.vaildTime - kTime
- monthcard[tostring(monthcardcfgId)] = hascard
- cardid = monthcardcfgId
- end
- setplaydef(actor, _playerDbKey(), monthcard)
- --发送月卡变化包
- local hascard = monthcard[tostring(cardid)]
- local result = table.valueConvertToString(hascard)
- --给客户端发月卡信息
- sendluamsg(actor, LuaMessageIdToClient.RES_MONTHCARD_CHANGE_INFO, result)
- return true
- end
- function MonthCard.buymonthcardgoods(actor, itemcfgid, count)
- if card_is_close then
- return
- end
- local monthcard = getplaydef(actor, _playerDbKey())
- if monthcard == nil then
- monthcard = {}
- monthcard.todayreceivethreetime = false
- monthcard.receivetime = 0
- end
- --购买的月卡时间默认是月卡,不是日卡
- local order = 1
- local config = ConfigDataManager.getTable("cfg_monthlyPass", "order", order)
- if config == nil then
- return
- end
- local cardid = config[1].id
- local number = ConfigDataManager.getTableValue("cfg_stall", "number", "id", itemcfgid)
- if number == nil then
- return
- end
- local time = tonumber(number) * 24 * 60 * 60 * 1000 * tonumber(count)
- local now = getbaseinfo("now")
- local hascard = monthcard[tostring(cardid)]
- if hascard == nil then
- hascard = {}
- hascard.vaildTime = 0
- hascard.buycount = 0
- hascard.isfirstbuy = true
- hascard.isopen = false
- hascard.cfgId = cardid
- end
- --月卡,检查玩家当前是否有月卡、日卡
- local bool = checkactorhasmonthcard(actor)
- local bools = checkactorhasdaycard(actor)
- if order == 1 then
- if bool then
- --直接加时间就行,其他不变
- hascard.vaildTime = hascard.vaildTime + time
- if receThreeTime then
- if hascard.isfirstbuy then
- TripleIncome.AddRemainTime(actor, tonumber(config[1].dayincome) * 60 * 60)
- monthcard.receivetime = now
- else
- if TimeUtil.isSameDay(math.floor(monthcard.receivetime / 1000), math.floor(now / 1000)) then
- TripleIncome.AddRemainTime(actor, tonumber(config[1].dayincome) * 60 * 60)
- monthcard.receivetime = now
- end
- end
- hascard.isfirstbuy = false
- monthcard.todayreceivethreetime = true
- end
- else
- if bools then
- --如果有日卡,算日卡的剩余时间,转化成月卡
- local daytime = getdaycardtime(actor)
- --先关闭日卡,再加到月卡上
- for _, info in pairs(monthcard) do
- if type(info) == "table" then
- if info.isopen then
- info.isopen = false
- end
- end
- end
- hascard.vaildTime = daytime + time
- hascard.isopen = true
- if receThreeTime then
- if hascard.isfirstbuy then
- --发放额外三倍时间
- TripleIncome.AddRemainTime(actor, tonumber(config[1].firstincome) * 60 * 60)
- monthcard.receivetime = now
- else
- --校验三倍时间是否发放
- if TimeUtil.isSameDay(math.floor(monthcard.receivetime / 1000), math.floor(now / 1000)) then
- TripleIncome.AddRemainTime(actor, tonumber(config[1].dayincome) * 60 * 60)
- monthcard.receivetime = now
- end
- end
- monthcard.todayreceivethreetime = true
- hascard.isfirstbuy = false
- end
- else
- monthcard = setmonthcardinfo(actor, hascard, monthcard, now, time, config, cardid, true)
- end
- end
- end
- -- if order == 2 then
- -- --日卡
- -- if bool then
- -- --时间直接加到月卡上
- -- for _, info in pairs(monthcard) do
- -- if type(info) =="table" then
- -- if info.isopen then
- -- info.vaildTime = info.vaildTime + time
- -- end
- -- end
- -- end
- -- if flag then
- -- --发放额外三倍时间
- -- TripleIncome.AddRemainTime(actor,tonumber(config[1].firstincome) * 60 * 60)
- -- monthcard.todayreceivethreetime = true
- -- end
- -- else if bools then
- -- --直接加时间就行
- -- hascard.vaildTime = hascard.vaildTime + time
- -- hascard.isfirstbuy = false
- -- else monthcard = setmonthcardinfo(actor,hascard,monthcard,now,time,config,cardid)
- -- end
- -- end
- -- end
- monthcard[tostring(cardid)] = hascard
- -- monthcard.todayreceivethreetime = true --今日是否领取三倍时间
- --更新玩家月卡信息
- setplaydef(actor, _playerDbKey(), monthcard)
- local result = table.valueConvertToString(hascard)
- --给客户端发月卡信息
- sendluamsg(actor, LuaMessageIdToClient.RES_MONTHCARD_CHANGE_INFO, result)
- end
- --聊天功能是否开启 true | false
- function MonthCard.checkchatvx(actor)
- local monthcard = getplaydef(actor, _playerDbKey())
- if monthcard == nil then
- return false
- end
- for key, info in pairs(monthcard) do
- if type(info) == "table" then
- if info.isopen then
- local chat = ConfigDataManager.getTableValue("cfg_monthlyPass", "chat", "id", key)
- if tonumber(chat) == 1 then
- return true
- end
- end
- end
- end
- return false
- end
- --自动拾取功能是否开启
- function MonthCard.checkpickupopen(actor)
- local monthcard = getplaydef(actor, _playerDbKey())
- if monthcard == nil then
- return false
- end
- for key, info in pairs(monthcard) do
- if type(info) == "table" then
- if info.isopen then
- local pinkUp = ConfigDataManager.getTableValue("cfg_monthlyPass", "pickUp", "id", key)
- if tonumber(pinkUp) == 1 then
- return true
- end
- end
- end
- end
- return false
- end
- --自动回收功能是否开启
- function MonthCard.checkrecoveryopen(actor)
- local monthcard = getplaydef(actor, _playerDbKey())
- if monthcard == nil then
- return false
- end
- for key, info in pairs(monthcard) do
- if type(info) == "table" then
- if info.isopen then
- local recovery = ConfigDataManager.getTableValue("cfg_monthlyPass", "recovery", "id", key)
- if tonumber(recovery) == 1 then
- return true
- end
- end
- end
- end
- return false
- end
- function l_month_card_limit_count_gm(actor, type)
- MonthCard.limitCount(actor, type)
- end
- function l_month_card_send_msg_mg(actor)
- gameDebug.print(getplaydef(actor, _playerDbKey()))
- end
- --TODO 一定要放到文件最后
- EventListerTable.registerType("月卡", _rechargeType(), _playerDbKey())
- --注册充值事件
- RechargeEventListerTable:eventLister(_rechargeType(), "月卡充值", MonthCard.limitbuycount)
|