local skynet = require "skynet" local oo = require "Class" local log = require "Log" local pb = require "pb" local dataType = require "DataType" local errorInfo = require "ErrorInfo" local mail = require "Mail" local PlayerLand = oo.class() function PlayerLand:Init() --PlayerLand_data.json local PlayerLand = skynet.server.gameConfig.PlayerLand --获取配置文件PlayerLand中的数据 self.PlayerLandInfo = {} for k ,v in pairs(PlayerLand) do local count = v.id self.PlayerLandInfo[ count ] = {} self.PlayerLandInfo[ count ].id = v.id self.PlayerLandInfo[ count ].rewardId = v.rewardId self.PlayerLandInfo[ count ].reward = {} if v.rewardId>0 then self.PlayerLandInfo[ count ].reward = self:GetRewardInfo(v.rewardId) --对应的奖励信息 end end end --新玩家第一次登录的时候调用 function PlayerLand:InitData( player ) if next(player.gameData.playerLand.signInInfo) == nil then --初始化新人签到相关信息 player.gameData.playerLand.isShow = true --新人签到是否显示设置为true player.gameData.playerLand.signCount = 0 --签到天数默认为1 player.gameData.playerLand.endTime = skynet.server.common:GetAfterSomeHour(skynet.server.gameConfig.SValue.playerLandRewardClose*24) --签到结束时间 for k ,v in pairs(self.PlayerLandInfo) do local count = v.id player.gameData.playerLand.signInInfo[ count ] = {} player.gameData.playerLand.signInInfo[ count ].id = v.id --签到id player.gameData.playerLand.signInInfo[ count ].status = 1 --领取状态 1-无法领取 2-可以领取 3-已经领取 默认无法领取 end end self:LoginChangeData(player) --log.info("cccc" .. skynet.server.common:TableToString(self.PlayerLandInfo)) --log.info("cccc" .. skynet.server.common:TableToString(player.gameData.playerLand)) end --每天玩家第一次登录的时候进行修改对应数据 function PlayerLand:LoginChangeData( player ) if player.gameData.playerLand.isShow then --是否签到完毕 if player.gameData.playerLand.signCount < #self.PlayerLandInfo then --玩家新人签到的天数加1 player.gameData.playerLand.signCount = player.gameData.playerLand.signCount+1 --对应新人签到的当天领取状态修改为可以领取 player.gameData.playerLand.signInInfo[ player.gameData.playerLand.signCount ].status = 2 else --查看改玩家的所有奖励是否领取完毕 local getAll = true for k ,v in pairs(player.gameData.playerLand.signInInfo) do if v.status ~= 3 then getAll = false break end end --获取完毕则关闭新人签到 if getAll then player.gameData.playerLand.isShow = false end end --判断当前时间是否超过结束时间 local nowTime = skynet.GetTime() if nowTime >= player.gameData.playerLand.endTime then --已经结束 如果有可以领取的奖励没有领取则通过邮件进行补发 local award = {} for k , v in pairs( player.gameData.playerLand.signInInfo) do if 2 == v.status then table.insert(award , self.PlayerLandInfo[ k ].reward ) end end local mailInfo = {mailType = "奖励" , mailTitle = "请领取奖励", mailText = "未领取的新人签到奖励" , mailEffectiveTime = 7} local mailId = "XRQD" .. tostring(os.time()) mail:AddMail( player , mailId , mailInfo , award , false) --超过时间则关闭新人签到 player.gameData.playerLand.isShow = false end end end --新人签到检查(取消) function PlayerLand:Check( player , c2sData , s2cData ) c2sData.data = assert(pb.decode("C2SPlayerLandCheck", c2sData.data )) local data = {} if player.gameData.playerLand.isShow then --判断当前时间是否超过结束时间 local now = os.time() if now>=player.gameData.playerLand.endTime then data.canShow = false --已经结束 如果有可以领取的奖励没有领取则通过邮件进行补发 local award = {} for k , v in pairs( player.gameData.playerLand.signInInfo) do if v.status==2 then table.insert(award , self.PlayerLandInfo[ k ].reward ) end end if next(award)~=nil then -- 调用 邮件增加功能 进行发放奖励 local time = skynet.server.common:GetAfterSomeDay(7) --邮件存在7天 local strTime = skynet.server.common:GetStrTime(time) local mailInfo = {mailType = "奖励" , mailTitle = "未领取的新人签到奖励" , mailText = "请领取奖励" , playerFailureTime = strTime} local mailId = "XRQD" .. tostring(time) mail:AddMail( player , mailId , mailInfo , award , false) end else --判断奖励是否领取完毕 local canShow = false for k , v in pairs( player.gameData.playerLand.signInInfo) do if v.status~=3 then canShow =true break end end data.canShow = canShow end else data.canShow = false end s2cData.cmd = pb.enum("MsgType","CMD_S2C_PlayerLandCheck") s2cData.data = assert(pb.encode("S2CPlayerLandCheck", data)) end --新人签到显示 function PlayerLand:Show( player , c2sData , s2cData ) c2sData.data = assert(pb.decode("C2SPlayerLandShow", c2sData.data )) local data = {} data.signInfos = {} --新人签到信息列表 for k ,v in pairs(player.gameData.playerLand.signInInfo) do table.insert(data.signInfos , v) end s2cData.cmd = pb.enum("MsgType","CMD_S2C_PlayerLandShow") s2cData.data = assert(pb.encode("S2CPlayerLandShow", data)) end --新人签到获取 function PlayerLand:Get( player , c2sData , s2cData ) c2sData.data = assert(pb.decode("C2SPlayerLandGet", c2sData.data )) local id = c2sData.data.id local data = {} data.signInfo = {} for k ,v in pairs(player.gameData.playerLand.signInInfo) do if id == v.id and id <= player.gameData.playerLand.signCount and v.status == 2 then v.status = 3 --发放奖励 player:GiveReward( self.PlayerLandInfo[ id ].rewardId) skynet.server.msgTips:Reduce(player , 40) --发放奖励之后 消除对应红点 end if v.id==id then data.signInfo = v end end s2cData.cmd = pb.enum("MsgType","CMD_S2C_PlayerLandGet") s2cData.data = assert(pb.encode("S2CPlayerLandGet", data)) end --通过奖励id获取所有奖励 然后提供给邮件使用 function PlayerLand:GetRewardInfo( rewardId ) local cfgReward = skynet.server.gameConfig:GetCurCfg("Reward" , rewardId ) local award = {} --对应的货币奖励信息 if cfgReward.coin > 0 then table.insert(award , { type = dataType.GoodsType_Init , id = dataType.MoneyType_Coin, count = cfgReward.coin}) end if cfgReward.mapCoin > 0 then table.insert(award , { type = dataType.GoodsType_Init , id = dataType.MoneyType_Map, count = cfgReward.mapCoin}) end if cfgReward.voluteCoin > 0 then table.insert(award , { type = dataType.GoodsType_Init , id = dataType.MoneyType_Volute, count = cfgReward.voluteCoin}) end --对应的道具奖励信息 local reward = skynet.server.gameConfig:AwardInfo(rewardId) for k ,v in pairs(reward) do table.insert(award , v) end return award end skynet.server.playerLand = PlayerLand return PlayerLand