174 lines
6.8 KiB
Lua
174 lines
6.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 activity = require "Activity"
|
|
local json =require "json"
|
|
local ActivitySavingPot = oo.class()
|
|
|
|
ActivitySavingPot.ActivityType = dataType.ActivityType_SavingPot
|
|
|
|
--登陆逻辑
|
|
function ActivitySavingPot:LoginInitData( player )
|
|
--判断模块是否开启
|
|
if not player:IsUnlockSystem( dataType.UnlockSystem_ActivitySavingPot ) then
|
|
return
|
|
end
|
|
|
|
--获取开启的活动
|
|
local activityId, _, _, _ = activity:GetActivityInfo(player, self.ActivityType)
|
|
if (player.gameData.activity[self.ActivityType] == nil or next(player.gameData.activity[self.ActivityType]) == nil) and activityId ~= 0 then
|
|
self:InitData( player )
|
|
elseif player.gameData.activity[self.ActivityType] ~= nil and next(player.gameData.activity[self.ActivityType]) ~= nil and activityId ~= 0 and player.gameData.activity[self.ActivityType].curId ~= activityId then
|
|
self:InitData( player )
|
|
end
|
|
end
|
|
|
|
--初始化活动相关数据
|
|
function ActivitySavingPot:InitData( player )
|
|
player.gameData.activity[self.ActivityType] = {}
|
|
local activitySavingPot = player.gameData.activity[self.ActivityType]
|
|
activitySavingPot.curId = 0
|
|
--当前蜗壳币累计消费
|
|
activitySavingPot.voluteCost = 0
|
|
--已经推送过的礼包游标
|
|
activitySavingPot.sendPack = 0
|
|
--购买过的礼包游标
|
|
activitySavingPot.buyPack = 0
|
|
activitySavingPot.allPack = {}
|
|
activitySavingPot.allTier = {}
|
|
|
|
--初始化当期活动
|
|
local activityId, _, _, _ = activity:GetActivityInfo(player, self.ActivityType)
|
|
if activityId == 0 then
|
|
return
|
|
end
|
|
activitySavingPot.curId = activityId
|
|
local PiggyBank = skynet.server.gameConfig:GetPlayerCurCfg(player, "PiggyBank", activityId)
|
|
for i, v in pairs(PiggyBank.voluteLvlPack) do
|
|
activitySavingPot.allPack[i]=tonumber(v)
|
|
end
|
|
for i, v in pairs(PiggyBank.voluteCoinLvl) do
|
|
activitySavingPot.allTier[i]=tonumber(v)
|
|
end
|
|
skynet.server.msgTips:Add( player , 121 )
|
|
end
|
|
|
|
function ActivitySavingPot:CheckSavingPotPack( player, storeId )
|
|
|
|
local activityId, _, _, _ = activity:GetActivityInfo(player, self.ActivityType)
|
|
if activityId == 0 then
|
|
return
|
|
end
|
|
|
|
local activitySavingPot = player.gameData.activity[self.ActivityType]
|
|
if storeId == activitySavingPot.allPack[activitySavingPot.buyPack+1] then
|
|
activitySavingPot.buyPack = activitySavingPot.buyPack + 1
|
|
--skynet.server.msgTips:Reduce( player , 121)
|
|
--推送消息
|
|
local data = {}
|
|
data.packId = 0
|
|
data.currentCost = 0
|
|
|
|
if activitySavingPot == nil or next(activitySavingPot) == nil then
|
|
self:InitData( player )
|
|
activitySavingPot = player.gameData.activity[self.ActivityType]
|
|
data.packId = activitySavingPot.allPack[activitySavingPot.buyPack+1]
|
|
data.currentCost = activitySavingPot.voluteCost
|
|
else
|
|
if activitySavingPot.curId == activityId then
|
|
if activitySavingPot.buyPack >= #activitySavingPot.allPack then
|
|
data.packId = 0
|
|
data.currentCost = activitySavingPot.voluteCost
|
|
else
|
|
data.packId = activitySavingPot.allPack[activitySavingPot.buyPack+1]
|
|
data.currentCost = activitySavingPot.voluteCost
|
|
end
|
|
else
|
|
self:InitData( player )
|
|
activitySavingPot = player.gameData.activity[self.ActivityType]
|
|
data.packId = activitySavingPot.allPack[activitySavingPot.buyPack+1]
|
|
data.currentCost = activitySavingPot.voluteCost
|
|
end
|
|
end
|
|
skynet.server.gameServer:SendMsgToUser( player.userId , "CMD_S2C_ActivitySavingPotShow" , data )
|
|
end
|
|
end
|
|
|
|
--展示
|
|
function ActivitySavingPot:Show(player, c2sData, s2cData)
|
|
local activityId, _, _, _ = activity:GetActivityInfo(player, self.ActivityType)
|
|
if activityId == 0 then
|
|
return
|
|
end
|
|
local data = {}
|
|
local activitySavingPot = player.gameData.activity[self.ActivityType]
|
|
data.currentCost = 0
|
|
data.packId = 0
|
|
|
|
if activitySavingPot == nil or next(activitySavingPot) == nil then
|
|
self:InitData( player )
|
|
activitySavingPot = player.gameData.activity[self.ActivityType]
|
|
data.packId = activitySavingPot.allPack[activitySavingPot.buyPack+1]
|
|
data.currentCost = activitySavingPot.voluteCost
|
|
else
|
|
if activitySavingPot.curId == activityId then
|
|
if activitySavingPot.buyPack >= #activitySavingPot.allPack then
|
|
data.packId = 0
|
|
data.currentCost = activitySavingPot.voluteCost
|
|
else
|
|
data.packId = activitySavingPot.allPack[activitySavingPot.buyPack+1]
|
|
data.currentCost = activitySavingPot.voluteCost
|
|
end
|
|
else
|
|
self:InitData( player )
|
|
activitySavingPot = player.gameData.activity[self.ActivityType]
|
|
data.packId = activitySavingPot.allPack[activitySavingPot.buyPack+1]
|
|
data.currentCost = activitySavingPot.voluteCost
|
|
end
|
|
end
|
|
s2cData.cmd = pb.enum("MsgType", "CMD_S2C_ActivitySavingPotShow")
|
|
s2cData.data = assert(pb.encode("S2CActivitySavingPotShow", data))
|
|
end
|
|
|
|
|
|
--累计消费
|
|
function ActivitySavingPot:ChangeVoluteCost( player , num )
|
|
if not player:IsUnlockSystem( dataType.UnlockSystem_ActivitySavingPot ) or num >= 0 then
|
|
return
|
|
end
|
|
|
|
local activitySavingPot = player.gameData.activity[self.ActivityType]
|
|
activitySavingPot.voluteCost =activitySavingPot.voluteCost - num
|
|
if activitySavingPot.buyPack < #activitySavingPot.allTier and activitySavingPot.voluteCost > activitySavingPot.allTier[activitySavingPot.buyPack+1] and activitySavingPot.sendPack ~= activitySavingPot.buyPack + 1 then
|
|
activitySavingPot.sendPack = activitySavingPot.buyPack + 1
|
|
--推送红点
|
|
skynet.server.msgTips:Add( player , 121 )
|
|
end
|
|
end
|
|
|
|
--活动是否完结
|
|
function ActivitySavingPot:isActivityEnd( player )
|
|
|
|
--获取开启的活动
|
|
local activityId, _, _, _ = activity:GetActivityInfo(player, self.ActivityType)
|
|
|
|
--没有开启的活动
|
|
if activityId == 0 then
|
|
return true
|
|
end
|
|
|
|
--活动期间已经买完全部档位礼包
|
|
if player.gameData.activity[self.ActivityType] ~= nil and next(player.gameData.activity[self.ActivityType]) ~= nil then
|
|
local activitySavingPot = player.gameData.activity[self.ActivityType]
|
|
if activitySavingPot.buyPack >= #activitySavingPot.allPack and activityId == activitySavingPot.curId then
|
|
return true
|
|
end
|
|
end
|
|
return false
|
|
end
|
|
|
|
skynet.server.activitySavingPot = ActivitySavingPot
|
|
return ActivitySavingPot |