231 lines
9.8 KiB
Lua
231 lines
9.8 KiB
Lua
|
|
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()
|
||
|
|
|
||
|
|
end
|
||
|
|
|
||
|
|
--新玩家第一次登录的时候调用
|
||
|
|
function PlayerLand:InitData( player )
|
||
|
|
--玩家对应的配置
|
||
|
|
local cfgPlayerLand = skynet.server.gameConfig:GetPlayerAllCfg( player , "PlayerLand")
|
||
|
|
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
|
||
|
|
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(cfgSValue.playerLandRewardClose*24) --签到结束时间
|
||
|
|
for k ,v in pairs(cfgPlayerLand) 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
|
||
|
|
self:LoginChangeData(player)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
--每天玩家第一次登录的时候进行修改对应数据
|
||
|
|
function PlayerLand:LoginChangeData( player )
|
||
|
|
local cfgPlayerLand = skynet.server.gameConfig:GetPlayerAllCfg( player , "PlayerLand")
|
||
|
|
if player.gameData.playerLand.isShow then
|
||
|
|
--是否签到完毕
|
||
|
|
if player.gameData.playerLand.signCount < #cfgPlayerLand then
|
||
|
|
--玩家新人签到的天数加1
|
||
|
|
player.gameData.playerLand.signCount = player.gameData.playerLand.signCount+1
|
||
|
|
--对应新人签到的当天领取状态修改为可以领取
|
||
|
|
player.gameData.playerLand.signInInfo[ player.gameData.playerLand.signCount ].status = 2
|
||
|
|
skynet.server.msgTips:AddNoNotice(player , 40) --有可领取奖励 增加对应红点
|
||
|
|
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
|
||
|
|
local reward = self:GetRewardInfo(player , cfgPlayerLand[ k ].rewardId) --对应的奖励信息
|
||
|
|
for k1 ,v1 in pairs( reward ) do
|
||
|
|
table.insert(award , v1 )
|
||
|
|
end
|
||
|
|
v.status = 3
|
||
|
|
end
|
||
|
|
end
|
||
|
|
skynet.server.msgTips:Reset(player , 40) --删除对应红点
|
||
|
|
local mailInfo = {mailType = "奖励" , mailTitle = "请领取奖励", mailText = "未领取的新人签到奖励" , mailEffectiveTime = 7}
|
||
|
|
local mailId = "XRQD" .. tostring(skynet.GetTime())
|
||
|
|
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 = skynet.GetTime()
|
||
|
|
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 = {}
|
||
|
|
local cfgPlayerLand = skynet.server.gameConfig:GetPlayerAllCfg( player , "PlayerLand")
|
||
|
|
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
|
||
|
|
--发放奖励
|
||
|
|
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_65")
|
||
|
|
player:GiveReward( cfgPlayerLand[ id ].rewardId, eventId)
|
||
|
|
skynet.server.msgTips:Reduce(player , 40) --发放奖励之后 消除对应红点
|
||
|
|
end
|
||
|
|
if v.id==id then
|
||
|
|
data.signInfo = v
|
||
|
|
end
|
||
|
|
end
|
||
|
|
--查看改玩家的所有奖励是否领取完毕
|
||
|
|
if player.gameData.playerLand.signCount == #cfgPlayerLand then
|
||
|
|
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
|
||
|
|
data.canShow = player.gameData.playerLand.isShow
|
||
|
|
s2cData.cmd = pb.enum("MsgType","CMD_S2C_PlayerLandGet")
|
||
|
|
s2cData.data = assert(pb.encode("S2CPlayerLandGet", data))
|
||
|
|
end
|
||
|
|
|
||
|
|
--新人签到显示 服务器主动推送(取消)
|
||
|
|
function PlayerLand:CanShow( player )
|
||
|
|
local data = {}
|
||
|
|
data.isShow = player.gameData.playerLand.isShow
|
||
|
|
skynet.server.gameServer:SendMsgToUser( player.userId , "CMD_S2C_PlayerLandCanShow" , data )
|
||
|
|
end
|
||
|
|
|
||
|
|
--通过奖励id获取所有奖励 然后提供给邮件使用
|
||
|
|
function PlayerLand:GetRewardInfo( player , rewardId )
|
||
|
|
local cfgReward = skynet.server.gameConfig:GetPlayerCurCfg( player , "Reward" , rewardId )
|
||
|
|
local award = {}
|
||
|
|
--如果没有找到对应的奖励信息 直接返回
|
||
|
|
if not cfgReward then
|
||
|
|
return award
|
||
|
|
end
|
||
|
|
--对应的货币奖励信息
|
||
|
|
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
|
||
|
|
|
||
|
|
--通过奖励id获取所有奖励 然后提供给邮件使用
|
||
|
|
function PlayerLand:GetRewardInfoNoPlayer( 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
|