223 lines
5.7 KiB
Lua
223 lines
5.7 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 activity = require "Activity"
|
|||
|
|
local json =require "json"
|
|||
|
|
local dataType = require "DataType"
|
|||
|
|
local ActivityLevelPack = oo.class()
|
|||
|
|
|
|||
|
|
ActivityLevelPack.ActivityType = dataType.ActivityType_ActivityLevelPack
|
|||
|
|
|
|||
|
|
--构造函数
|
|||
|
|
function ActivityLevelPack:Init()
|
|||
|
|
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
-- 每次登录需要进行修改的数据
|
|||
|
|
function ActivityLevelPack:LoginInitData(player)
|
|||
|
|
|
|||
|
|
if not self:isCanBuy(player) then
|
|||
|
|
return
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
-- 处理红点
|
|||
|
|
if not self:isFirstOpen(player) then
|
|||
|
|
skynet.server.msgTips:Add(player, 115)
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
log.debug("分层礼包活动进行中")
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--初始玩家数据,返回活动信息,
|
|||
|
|
function ActivityLevelPack:CheckDataAndGetActivity(player)
|
|||
|
|
|
|||
|
|
--默认空活动
|
|||
|
|
local cfgLevelPack = nil
|
|||
|
|
|
|||
|
|
if player==nil then
|
|||
|
|
log.debug("分层礼包CheckDataAndGetActivity, player is nil")
|
|||
|
|
return cfgLevelPack
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--判断等级是否开启
|
|||
|
|
if not player:IsUnlockSystem( dataType.UnlockSystem_ActivityLevelPack) then
|
|||
|
|
log.debug("分层礼包等级不足")
|
|||
|
|
return cfgLevelPack
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--获取开启的活动
|
|||
|
|
local activityId,startTime, endTime , _ = activity:GetActivityInfo(player, ActivityLevelPack.ActivityType)
|
|||
|
|
|
|||
|
|
--没有开启的活动
|
|||
|
|
if activityId == 0 then
|
|||
|
|
return cfgLevelPack
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--初始化
|
|||
|
|
if player.gameData.LevelPackMap==nil then
|
|||
|
|
player.gameData.LevelPackMap={}
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--获取活动配置
|
|||
|
|
cfgLevelPack=self:GetLevelPackConfig(player,activityId)
|
|||
|
|
|
|||
|
|
--未获取到有效的活动
|
|||
|
|
if cfgLevelPack == nil then
|
|||
|
|
log.debug("分层礼包未开启-未获取到有效的活动2")
|
|||
|
|
return cfgLevelPack
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--如果玩家已经存在活动不需要检查
|
|||
|
|
if player.gameData.LevelPackMap[activityId] then
|
|||
|
|
|
|||
|
|
--删除过期活动,减少数据产生
|
|||
|
|
local removeKeyList = {}
|
|||
|
|
for exceedActivityId, _ in pairs(player.gameData.LevelPackMap) do
|
|||
|
|
if exceedActivityId ~= activityId then
|
|||
|
|
table.insert(removeKeyList, exceedActivityId)
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
if next(removeKeyList) then
|
|||
|
|
for _, removeKey in ipairs(removeKeyList) do
|
|||
|
|
player.gameData.LevelPackMap[removeKey]=nil
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
return cfgLevelPack
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--存在活动初始化玩家数据
|
|||
|
|
local playerActivityLevelPack = {}
|
|||
|
|
playerActivityLevelPack.isFirstOpen = false
|
|||
|
|
|
|||
|
|
--更新缓存
|
|||
|
|
player.gameData.LevelPackMap[activityId] = playerActivityLevelPack
|
|||
|
|
|
|||
|
|
return cfgLevelPack
|
|||
|
|
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--获取配置信息
|
|||
|
|
function ActivityLevelPack:GetLevelPackConfig(player,activityId)
|
|||
|
|
|
|||
|
|
local cfgLevelPack=nil
|
|||
|
|
|
|||
|
|
--获取该活动的默认初始关卡
|
|||
|
|
local cfgLevelPacks=skynet.server.gameConfig:GetPlayerAllCfg(player, "LevelPack")
|
|||
|
|
if cfgLevelPacks==nil then
|
|||
|
|
|
|||
|
|
log.debug("cfgLevelPacks is nil")
|
|||
|
|
return cfgLevelPack
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
for _, value in pairs(cfgLevelPacks) do
|
|||
|
|
if value.id==activityId then
|
|||
|
|
cfgLevelPack=value
|
|||
|
|
break
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
return cfgLevelPack
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--是否可以购买
|
|||
|
|
function ActivityLevelPack:isCanBuy( player)
|
|||
|
|
|
|||
|
|
--活动是否开启
|
|||
|
|
local cfgLevelPack =self:CheckDataAndGetActivity(player)
|
|||
|
|
if cfgLevelPack ==nil then
|
|||
|
|
return false
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
for _, storeId in ipairs(cfgLevelPack.storePackId) do
|
|||
|
|
local storePackInfo = player.gameData.storePack.storePackInfo[storeId]
|
|||
|
|
if storePackInfo ~= nil
|
|||
|
|
and storePackInfo.buyTime >= storePackInfo.packLimit[2] then
|
|||
|
|
return false --已经购买过
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
return true
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--分层礼包是否被购买
|
|||
|
|
function ActivityLevelPack:buyCount( player,storeId)
|
|||
|
|
|
|||
|
|
--活动是否开启
|
|||
|
|
local cfgLevelPack =self:CheckDataAndGetActivity(player)
|
|||
|
|
if cfgLevelPack ==nil then
|
|||
|
|
return 0
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
local isCon=false
|
|||
|
|
for _, id in ipairs(cfgLevelPack.storePackId) do
|
|||
|
|
|
|||
|
|
if storeId == id then
|
|||
|
|
isCon=true
|
|||
|
|
break
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--没有找到
|
|||
|
|
if not isCon then
|
|||
|
|
return 0
|
|||
|
|
end
|
|||
|
|
--是否购买过了
|
|||
|
|
if not self:isCanBuy(player) then
|
|||
|
|
return 1
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--可以购买
|
|||
|
|
return 0
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--是否首次打开
|
|||
|
|
function ActivityLevelPack:isFirstOpen( player)
|
|||
|
|
|
|||
|
|
--活动是否开启
|
|||
|
|
local cfgLevelPack =self:CheckDataAndGetActivity(player)
|
|||
|
|
if cfgLevelPack ==nil then
|
|||
|
|
return false
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
return player.gameData.LevelPackMap[cfgLevelPack.id].isFirstOpen
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--获取分层礼包信息
|
|||
|
|
function ActivityLevelPack:Show( player , c2sData , s2cData )
|
|||
|
|
c2sData.data = assert(pb.decode("C2SignPackShow", c2sData.data ))
|
|||
|
|
s2cData.cmd = pb.enum("MsgType","CMD_S2S_ActivitySignPackShow")
|
|||
|
|
local data = {}
|
|||
|
|
|
|||
|
|
--检查并且获取活动信息
|
|||
|
|
local cfgLevelPack=self:CheckDataAndGetActivity(player)
|
|||
|
|
|
|||
|
|
if cfgLevelPack == nil then
|
|||
|
|
s2cData.code = errorInfo.ErrorCode.ActivityClosed
|
|||
|
|
return
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--是否已经购买
|
|||
|
|
if not self:isCanBuy(player) then
|
|||
|
|
|
|||
|
|
log.debug("分层礼包已经购买!")
|
|||
|
|
s2cData.code=errorInfo.ErrorCode.AlreadyBuy
|
|||
|
|
return
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--获取开启的活动
|
|||
|
|
local activityId, _, _, _ = activity:GetActivityInfo(player, ActivityLevelPack.ActivityType)
|
|||
|
|
player.gameData.LevelPackMap[activityId].isFirstOpen = true
|
|||
|
|
|
|||
|
|
-- 处理红点
|
|||
|
|
skynet.server.msgTips:ReduceAll(player, 115)
|
|||
|
|
|
|||
|
|
--返回信息
|
|||
|
|
s2cData.data = assert(pb.encode("S2SignPackShow", data))
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
skynet.server.activityLevelPack = ActivityLevelPack
|
|||
|
|
return ActivityLevelPack
|