--月卡相关 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)