791 lines
26 KiB
Lua
791 lines
26 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 ActivityNewPlayerRaffle = oo.class()
|
|||
|
|
|
|||
|
|
ActivityNewPlayerRaffle.ActivityType = dataType.ActivityType_NewPlayerRaffle
|
|||
|
|
|
|||
|
|
--当前抽卡类型 都是家具
|
|||
|
|
local goodsType = dataType.GoodsType_Furniture
|
|||
|
|
|
|||
|
|
--构造函数
|
|||
|
|
function ActivityNewPlayerRaffle:Init()
|
|||
|
|
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
-- 每次登录需要进行修改的数据
|
|||
|
|
function ActivityNewPlayerRaffle:LoginInitData(player)
|
|||
|
|
|
|||
|
|
--判断模块是否开启
|
|||
|
|
if not player:IsUnlockSystem( dataType.UnlockSystem_ActivityNewPlayerRaffle ) or self:CheckData(player) == nil then
|
|||
|
|
return
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
-- 处理红点
|
|||
|
|
skynet.server.msgTips:Reset(player, 106)
|
|||
|
|
skynet.server.msgTips:Reset(player, 107)
|
|||
|
|
skynet.server.msgTips:Reset(player, 108)
|
|||
|
|
|
|||
|
|
--新手限定设计卡池 1次
|
|||
|
|
if self:IsLottery(player,1) then
|
|||
|
|
skynet.server.msgTips:Add(player,106)
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--新手限定设计卡池 10次
|
|||
|
|
if self:IsLottery(player,10) then
|
|||
|
|
skynet.server.msgTips:Add(player,108)
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
math.randomseed(skynet.GetTime())
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
|
|||
|
|
--是否可以设计卡池
|
|||
|
|
function ActivityNewPlayerRaffle:IsLottery(player,lotteryTimes)
|
|||
|
|
|
|||
|
|
--不存在开启的活动
|
|||
|
|
local cfgNewPlayerRaffle = self:CheckData(player)
|
|||
|
|
|
|||
|
|
--活动未开启
|
|||
|
|
if cfgNewPlayerRaffle == nil then
|
|||
|
|
return false
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--获取数值基础配置
|
|||
|
|
local cfgSValue = skynet.server.gameConfig:GetAllCfg( "SValue")
|
|||
|
|
|
|||
|
|
--当前蜗壳币
|
|||
|
|
local volute = player.gameData.volute
|
|||
|
|
|
|||
|
|
--需要蜗壳币
|
|||
|
|
local needVolute = lotteryTimes==1 and cfgSValue.newPlayerRafflePrice[1] or cfgSValue.newPlayerRafflePrice[2]
|
|||
|
|
|
|||
|
|
--检查消耗资源
|
|||
|
|
if volute < needVolute then
|
|||
|
|
--log.debug(string.format("新手设计抽卡 资源不足,needVolute:%d,volute:%d",needVolute,volute))
|
|||
|
|
return false
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
return true
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--初始玩家数据
|
|||
|
|
function ActivityNewPlayerRaffle:CheckData(player)
|
|||
|
|
|
|||
|
|
--默认空活动
|
|||
|
|
local cfgNewPlayerRaffle = nil
|
|||
|
|
|
|||
|
|
if player==nil then
|
|||
|
|
log.debug("新手限定设计卡池checkdata, player is nil")
|
|||
|
|
return cfgNewPlayerRaffle
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--判断等级是否开启
|
|||
|
|
local cfgSValue = skynet.server.gameConfig:GetAllCfg( "SValue")
|
|||
|
|
if cfgSValue == nil or cfgSValue.newPlayerRaffleTrigger[1] > player.gameData.level then
|
|||
|
|
return cfgNewPlayerRaffle
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
local cfgActivitys = skynet.server.gameConfig:GetPlayerAllCfg(player, "Activity")
|
|||
|
|
if cfgActivitys == nil then
|
|||
|
|
log.debug("新手限定设计卡池未开启-未获取到有效的活动2")
|
|||
|
|
return cfgNewPlayerRaffle
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
local ifContain = false
|
|||
|
|
local activityId = 0
|
|||
|
|
|
|||
|
|
for index, v in pairs(cfgActivitys) do
|
|||
|
|
if v.activityType == ActivityNewPlayerRaffle.ActivityType and v.level<=player.gameData.level then
|
|||
|
|
ifContain=true
|
|||
|
|
activityId = v.activityId
|
|||
|
|
break
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
if not ifContain then
|
|||
|
|
|
|||
|
|
log.debug("新手限定设计卡池未开启-玩家未满足条件")
|
|||
|
|
return cfgNewPlayerRaffle
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--初始化
|
|||
|
|
if player.gameData.NewPlayerRaffleMap==nil then
|
|||
|
|
player.gameData.NewPlayerRaffleMap={}
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--获取活动配置
|
|||
|
|
cfgNewPlayerRaffle=self:GetNewPlayerRaffleConfig(player,activityId)
|
|||
|
|
|
|||
|
|
--未获取到有效的活动
|
|||
|
|
if cfgNewPlayerRaffle == nil then
|
|||
|
|
return cfgNewPlayerRaffle
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--如果玩家已经存在活动不需要检查
|
|||
|
|
if player.gameData.NewPlayerRaffleMap[activityId] then
|
|||
|
|
|
|||
|
|
--是否过期
|
|||
|
|
if self:GetActivityEndTime(player.gameData.NewPlayerRaffleMap[activityId].activityOpenTime) < skynet.GetTime() then
|
|||
|
|
|
|||
|
|
log.debug("新手限定设计卡池已过期")
|
|||
|
|
return nil
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
return cfgNewPlayerRaffle
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--存在活动初始化玩家数据
|
|||
|
|
local playerActivityMatchSuff = {}
|
|||
|
|
playerActivityMatchSuff.id = cfgNewPlayerRaffle.id
|
|||
|
|
playerActivityMatchSuff.oneLotteryCount = 0 --单抽次数
|
|||
|
|
playerActivityMatchSuff.oneLotterySuitCount = 0 --单抽套间产出次数
|
|||
|
|
playerActivityMatchSuff.tenLotteryCount = 0 --十连抽次数
|
|||
|
|
playerActivityMatchSuff.totalLotteryCount=0--累计抽卡次数 领取设计奖励使用
|
|||
|
|
playerActivityMatchSuff.rewardList={}--已领取设计奖励
|
|||
|
|
playerActivityMatchSuff.activityOpenTime = skynet.GetTime() --活动开启的时间戳
|
|||
|
|
|
|||
|
|
--更新缓存
|
|||
|
|
player.gameData.NewPlayerRaffleMap[activityId] = playerActivityMatchSuff
|
|||
|
|
|
|||
|
|
return cfgNewPlayerRaffle
|
|||
|
|
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--是否可以领取设计奖励
|
|||
|
|
function ActivityNewPlayerRaffle:IsDrawReward(player)
|
|||
|
|
|
|||
|
|
local isCanBuy=false
|
|||
|
|
|
|||
|
|
--不存在开启的活动
|
|||
|
|
local cfgNewPlayerRaffle=ActivityNewPlayerRaffle:CheckData(player)
|
|||
|
|
|
|||
|
|
--活动未开启
|
|||
|
|
if cfgNewPlayerRaffle == nil then
|
|||
|
|
return isCanBuy
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
local accumDesignRewardStrs=cfgNewPlayerRaffle.accumDesignReward
|
|||
|
|
|
|||
|
|
--循环配置
|
|||
|
|
for key, str in pairs(accumDesignRewardStrs) do
|
|||
|
|
|
|||
|
|
--解析配置
|
|||
|
|
local arr = skynet.server.common:Split(str, "_")
|
|||
|
|
local lotteryCount=tonumber(arr[1])
|
|||
|
|
|
|||
|
|
|
|||
|
|
if #arr ~= 2 then
|
|||
|
|
log.debug(string.format("新手限定设计卡池活动 配置异常,accumDesignReward:%d",str))
|
|||
|
|
break
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--判断是否可以领取
|
|||
|
|
if player.gameData.NewPlayerRaffleMap[cfgNewPlayerRaffle.id].totalLotteryCount >= lotteryCount then
|
|||
|
|
|
|||
|
|
--没有领取数据直接返回
|
|||
|
|
if #player.gameData.NewPlayerRaffleMap[cfgNewPlayerRaffle.id].rewardList <=0 then
|
|||
|
|
isCanBuy=true
|
|||
|
|
break
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
for _, count in ipairs(player.gameData.NewPlayerRaffleMap[cfgNewPlayerRaffle.id].rewardList) do
|
|||
|
|
|
|||
|
|
--已经领取直接跳出
|
|||
|
|
if count == lotteryCount then
|
|||
|
|
isCanBuy=false
|
|||
|
|
break
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--没有领取
|
|||
|
|
isCanBuy=true
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--已经有结果 直接跳出
|
|||
|
|
if isCanBuy then
|
|||
|
|
break
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
return isCanBuy
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
|
|||
|
|
--获取配置信息
|
|||
|
|
function ActivityNewPlayerRaffle:GetNewPlayerRaffleConfig(player,activityId)
|
|||
|
|
|
|||
|
|
local cfNewPlayerRaffle=nil
|
|||
|
|
|
|||
|
|
--获取该活动的默认初始关卡
|
|||
|
|
local cfNewPlayerRaffles=skynet.server.gameConfig:GetPlayerAllCfg(player, "NewPlayerRaffle")
|
|||
|
|
if cfNewPlayerRaffles==nil then
|
|||
|
|
|
|||
|
|
log.debug("cfNewPlayerRaffle is nil")
|
|||
|
|
return cfNewPlayerRaffle
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
for index, value in pairs(cfNewPlayerRaffles) do
|
|||
|
|
if value.id==activityId then
|
|||
|
|
cfNewPlayerRaffle=value
|
|||
|
|
break
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
return cfNewPlayerRaffle
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--获取显示信息
|
|||
|
|
function ActivityNewPlayerRaffle:Show( player , c2sData , s2cData )
|
|||
|
|
|
|||
|
|
c2sData.data = assert(pb.decode("C2SActivityNewPlayerRaffleShow", c2sData.data ))
|
|||
|
|
s2cData.cmd = pb.enum("MsgType","CMD_S2C_ActivityNewPlayerRaffleShow")
|
|||
|
|
local data = {}
|
|||
|
|
data.isBuyExperienceStorePack = false
|
|||
|
|
data.newPlayerCount = 0
|
|||
|
|
data.activityEndTime = 0
|
|||
|
|
|
|||
|
|
--不存在开启的活动
|
|||
|
|
local cfgNewPlayerRaffle=self:CheckData(player)
|
|||
|
|
|
|||
|
|
--活动未开启
|
|||
|
|
if cfgNewPlayerRaffle == nil then
|
|||
|
|
log.debug("cfgNewPlayerRaffle is nil")
|
|||
|
|
s2cData.code = errorInfo.ErrorCode.ActivityClosed
|
|||
|
|
return
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
if player.gameData.NewPlayerRaffleMap[cfgNewPlayerRaffle.id]~=nil then
|
|||
|
|
|
|||
|
|
data.newPlayerCount =10 - player.gameData.NewPlayerRaffleMap[cfgNewPlayerRaffle.id].oneLotteryCount
|
|||
|
|
data.activityEndTime = self:GetActivityEndTime(player.gameData.NewPlayerRaffleMap[cfgNewPlayerRaffle.id].activityOpenTime)
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--是否买过体验礼包
|
|||
|
|
data.isBuyExperienceStorePack=(player.gameData.storePack.storePackInfo[cfgNewPlayerRaffle.storepackId] ~= nil and not player.gameData.storePack.storePackInfo[cfgNewPlayerRaffle.storepackId].IsShow)and true or false
|
|||
|
|
|
|||
|
|
s2cData.data = assert(pb.encode("S2CActivityNewPlayerRaffleShow", data))
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--新手限定设计卡池 设计奖励展示
|
|||
|
|
function ActivityNewPlayerRaffle:AwardShow( player , c2sData , s2cData )
|
|||
|
|
c2sData.data = assert(pb.decode("C2SActivityNewPlayerRaffleAwardShow", c2sData.data ))
|
|||
|
|
s2cData.cmd = pb.enum("MsgType","CMD_S2C_ActivityNewPlayerRaffleAwardShow")
|
|||
|
|
local data = {}
|
|||
|
|
data.designCount = 0
|
|||
|
|
data.timeAwardInfos = {}
|
|||
|
|
|
|||
|
|
--不存在开启的活动
|
|||
|
|
local cfgNewPlayerRaffle=self:CheckData(player)
|
|||
|
|
|
|||
|
|
--活动未开启
|
|||
|
|
if cfgNewPlayerRaffle == nil then
|
|||
|
|
log.debug("cfgNewPlayerRaffle is nil")
|
|||
|
|
s2cData.code = errorInfo.ErrorCode.ActivityClosed
|
|||
|
|
return
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--循环组装奖励信息
|
|||
|
|
for index, value in ipairs(cfgNewPlayerRaffle.accumDesignReward) do
|
|||
|
|
local reward={status=0}
|
|||
|
|
local arr=skynet.server.common:Split(value, "_")
|
|||
|
|
local lotteryCount=tonumber(arr[1])
|
|||
|
|
|
|||
|
|
reward.needDesignCount=lotteryCount
|
|||
|
|
if player.gameData.NewPlayerRaffleMap[cfgNewPlayerRaffle.id].totalLotteryCount >= lotteryCount then
|
|||
|
|
reward.status=1
|
|||
|
|
end
|
|||
|
|
for _, value in ipairs(player.gameData.NewPlayerRaffleMap[cfgNewPlayerRaffle.id].rewardList) do
|
|||
|
|
if value==lotteryCount then
|
|||
|
|
reward.status=2
|
|||
|
|
break
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
data.timeAwardInfos[index] = reward
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--玩家数据
|
|||
|
|
local newPlayerRaffleMap = player.gameData.NewPlayerRaffleMap[cfgNewPlayerRaffle.id]
|
|||
|
|
data.designCount = newPlayerRaffleMap.totalLotteryCount
|
|||
|
|
|
|||
|
|
s2cData.data = assert(pb.encode("S2CActivityNewPlayerRaffleAwardShow", data))
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--新手限定设计卡池 设计奖励获取
|
|||
|
|
function ActivityNewPlayerRaffle:AwardGet( player , c2sData , s2cData )
|
|||
|
|
c2sData.data = assert(pb.decode("C2SActivityNewPlayerRaffleAwardGet", c2sData.data ))
|
|||
|
|
s2cData.cmd = pb.enum("MsgType","CMD_S2C_ActivityNewPlayerRaffleAwardGet")
|
|||
|
|
|
|||
|
|
--参数
|
|||
|
|
local timeAwardId = c2sData.data.timeAwardId
|
|||
|
|
|
|||
|
|
--返回信息
|
|||
|
|
local data = {}
|
|||
|
|
data.timeAwardInfos={}
|
|||
|
|
|
|||
|
|
--不存在开启的活动
|
|||
|
|
local cfgNewPlayerRaffle=self:CheckData(player)
|
|||
|
|
|
|||
|
|
--活动未开启
|
|||
|
|
if cfgNewPlayerRaffle == nil then
|
|||
|
|
log.debug("cfgNewPlayerRaffle is nil")
|
|||
|
|
s2cData.code = errorInfo.ErrorCode.ActivityClosed
|
|||
|
|
return
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--判断配置是否存在
|
|||
|
|
for index, value in ipairs(cfgNewPlayerRaffle.accumDesignReward) do
|
|||
|
|
local reward={status=0}
|
|||
|
|
local arr=skynet.server.common:Split(value, "_")
|
|||
|
|
local lotteryCount=tonumber(arr[1])
|
|||
|
|
local rewardId=tonumber(arr[2])
|
|||
|
|
reward.needDesignCount=lotteryCount
|
|||
|
|
if player.gameData.NewPlayerRaffleMap[cfgNewPlayerRaffle.id].totalLotteryCount >= lotteryCount then
|
|||
|
|
reward.status=1
|
|||
|
|
end
|
|||
|
|
for _, value in ipairs(player.gameData.NewPlayerRaffleMap[cfgNewPlayerRaffle.id].rewardList) do
|
|||
|
|
if value==lotteryCount then
|
|||
|
|
reward.status=2
|
|||
|
|
break
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--当前领取的奖励
|
|||
|
|
if lotteryCount == timeAwardId then
|
|||
|
|
if reward.status ~= 1 then
|
|||
|
|
s2cData.code = errorInfo.ErrorCode.NotGet
|
|||
|
|
return
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--领取奖励
|
|||
|
|
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_118")
|
|||
|
|
player:GiveReward(rewardId ,eventId,1)
|
|||
|
|
reward.status = 2
|
|||
|
|
|
|||
|
|
data.rewardId = rewardId
|
|||
|
|
|
|||
|
|
--添加更新记录
|
|||
|
|
table.insert(player.gameData.NewPlayerRaffleMap[cfgNewPlayerRaffle.id].rewardList,timeAwardId)
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
data.timeAwardInfos[index] = reward
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--玩家数据
|
|||
|
|
local newPlayerRaffleMap = player.gameData.NewPlayerRaffleMap[cfgNewPlayerRaffle.id]
|
|||
|
|
data.designCount = newPlayerRaffleMap.totalLotteryCount
|
|||
|
|
|
|||
|
|
--处理红点
|
|||
|
|
if not self:IsDrawReward(player) then
|
|||
|
|
skynet.server.msgTips:ReduceAll(player, 107)
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
s2cData.data = assert(pb.encode("S2CActivityNewPlayerRaffleAwardGet", data))
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--新手限定设计卡池 抽奖
|
|||
|
|
function ActivityNewPlayerRaffle:Lottery(player,c2sData,s2cData)
|
|||
|
|
c2sData.data = assert(pb.decode("C2SActivityNewPlayerRaffleLottery", c2sData.data ))
|
|||
|
|
s2cData.cmd = pb.enum("MsgType","CMD_S2C_ActivityNewPlayerRaffleLottery")
|
|||
|
|
|
|||
|
|
--参数 抽奖次数 1-抽一次 2-抽十次
|
|||
|
|
local lotteryTimes = c2sData.data.lotteryTimes
|
|||
|
|
|
|||
|
|
--log.debug(string.format("新手限定设计卡池 抽卡开始,lotteryTimes:%d",c2sData.data.lotteryTimes))
|
|||
|
|
|
|||
|
|
--返回信息
|
|||
|
|
local data = {}
|
|||
|
|
data.rewards={}
|
|||
|
|
|
|||
|
|
--不存在开启的活动
|
|||
|
|
local cfgNewPlayerRaffle=self:CheckData(player)
|
|||
|
|
|
|||
|
|
--活动未开启
|
|||
|
|
if cfgNewPlayerRaffle == nil then
|
|||
|
|
s2cData.code = errorInfo.ErrorCode.ActivityClosed
|
|||
|
|
--log.debug("新手设计抽卡 活动已关闭")
|
|||
|
|
return
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--玩家数据
|
|||
|
|
local newPlayerRaffleMap = player.gameData.NewPlayerRaffleMap[cfgNewPlayerRaffle.id]
|
|||
|
|
|
|||
|
|
--获取数值基础配置
|
|||
|
|
local cfgSValue = skynet.server.gameConfig:GetAllCfg( "SValue")
|
|||
|
|
|
|||
|
|
--当前蜗壳币
|
|||
|
|
local volute = player.gameData.volute
|
|||
|
|
|
|||
|
|
--需要蜗壳币
|
|||
|
|
local needVolute = lotteryTimes==1 and cfgSValue.newPlayerRafflePrice[1] or cfgSValue.newPlayerRafflePrice[2]
|
|||
|
|
|
|||
|
|
--检查消耗资源
|
|||
|
|
if volute < needVolute then
|
|||
|
|
s2cData.code = errorInfo.ErrorCode.VoluteNotEnough
|
|||
|
|
--log.debug(string.format("新手设计抽卡 资源不足,needVolute:%d,volute:%d",needVolute,volute))
|
|||
|
|
return
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--查找道具配置
|
|||
|
|
local cfgFurnitures = skynet.server.gameConfig:GetPlayerAllCfg(player, "Furniture")
|
|||
|
|
|
|||
|
|
-- 单抽
|
|||
|
|
if lotteryTimes == 1 then
|
|||
|
|
|
|||
|
|
--随机资源id
|
|||
|
|
local randomGoodsId = 0
|
|||
|
|
|
|||
|
|
--判断是否需要出套间id-前多少次 出多少个
|
|||
|
|
if newPlayerRaffleMap.oneLotteryCount >= (tonumber(cfgSValue.newPlayerRaffleSingle[1])- (tonumber(cfgSValue.newPlayerRaffleSingle[2])-newPlayerRaffleMap.oneLotterySuitCount)) then
|
|||
|
|
|
|||
|
|
--随机产出套间id
|
|||
|
|
randomGoodsId = RandomSuit(player,cfgNewPlayerRaffle.suitId)
|
|||
|
|
|
|||
|
|
--已经全部产出套间,重置抽卡次数
|
|||
|
|
if newPlayerRaffleMap.oneLotteryCount+1 >= tonumber(cfgSValue.newPlayerRaffleSingle[1]) then
|
|||
|
|
newPlayerRaffleMap.oneLotteryCount = 0
|
|||
|
|
newPlayerRaffleMap.oneLotterySuitCount=0
|
|||
|
|
else
|
|||
|
|
newPlayerRaffleMap.oneLotteryCount = newPlayerRaffleMap.oneLotteryCount + 1
|
|||
|
|
newPlayerRaffleMap.oneLotterySuitCount = newPlayerRaffleMap.oneLotterySuitCount + 1
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--log.debug( string.format("新手限定设计卡池 单抽产出套间,套间id:%d",randomGoodsId))
|
|||
|
|
|
|||
|
|
else--正常单抽
|
|||
|
|
|
|||
|
|
--随机权重
|
|||
|
|
local randWeightArr =cfgSValue.newPlayerRafflePossibility
|
|||
|
|
local totalWeight = 0
|
|||
|
|
|
|||
|
|
for _, value in ipairs(randWeightArr) do
|
|||
|
|
totalWeight=totalWeight+(value*100)
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
local randomNum =math.random(1,totalWeight)
|
|||
|
|
|
|||
|
|
--套间
|
|||
|
|
if randomNum<=randWeightArr[1]*100 then
|
|||
|
|
--随机产出套间id
|
|||
|
|
randomGoodsId= RandomSuit(player,cfgNewPlayerRaffle.suitId)
|
|||
|
|
|
|||
|
|
--已经全部产出套间,重置抽卡次数
|
|||
|
|
if newPlayerRaffleMap.oneLotterySuitCount+1 >= tonumber(cfgSValue.newPlayerRaffleSingle[2]) then
|
|||
|
|
newPlayerRaffleMap.oneLotteryCount = 0
|
|||
|
|
newPlayerRaffleMap.oneLotterySuitCount=0
|
|||
|
|
else
|
|||
|
|
newPlayerRaffleMap.oneLotteryCount = newPlayerRaffleMap.oneLotteryCount + 1
|
|||
|
|
newPlayerRaffleMap.oneLotterySuitCount = newPlayerRaffleMap.oneLotterySuitCount + 1
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--log.debug( string.format("新手限定设计卡池 单抽产出套间,套间id:%d",randomGoodsId))
|
|||
|
|
|
|||
|
|
--散件稀有
|
|||
|
|
elseif randomNum<=randWeightArr[1]*100+randWeightArr[2]*100 then
|
|||
|
|
|
|||
|
|
--随机稀有物品
|
|||
|
|
randomGoodsId=RandomStuff(player,cfgNewPlayerRaffle.rareStuffId)
|
|||
|
|
newPlayerRaffleMap.oneLotteryCount = newPlayerRaffleMap.oneLotteryCount + 1
|
|||
|
|
|
|||
|
|
--散件普通
|
|||
|
|
elseif randomNum<=randWeightArr[1]*100+randWeightArr[2]*100+randWeightArr[3]*100 then
|
|||
|
|
--随机普通物品
|
|||
|
|
randomGoodsId=RandomStuff(player,cfgNewPlayerRaffle.normalStuffId)
|
|||
|
|
newPlayerRaffleMap.oneLotteryCount = newPlayerRaffleMap.oneLotteryCount + 1
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--组装返回数据
|
|||
|
|
local item={}
|
|||
|
|
item.goodsType = goodsType
|
|||
|
|
item.goodsId = randomGoodsId
|
|||
|
|
item.goodsCount = 1
|
|||
|
|
|
|||
|
|
--添加到返回数据
|
|||
|
|
data.rewards[1]={}
|
|||
|
|
data.rewards[1].item=item
|
|||
|
|
data.rewards[1].isNew = not skynet.server.illustration:IsExistGoods( player , goodsType , randomGoodsId )
|
|||
|
|
|
|||
|
|
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_119" )
|
|||
|
|
|
|||
|
|
--扣除消耗
|
|||
|
|
player:MoneyChange(dataType.GoodsType_Volute , -needVolute ,eventId)
|
|||
|
|
|
|||
|
|
--发奖
|
|||
|
|
skynet.server.bag:AddGoods(player, goodsType, randomGoodsId, 1)
|
|||
|
|
|
|||
|
|
--循环套间
|
|||
|
|
for _, cfgFurniture in pairs(cfgFurnitures) do
|
|||
|
|
if cfgFurniture.id == randomGoodsId then
|
|||
|
|
|
|||
|
|
local quality = cfgFurniture.quality
|
|||
|
|
|
|||
|
|
--不凡品种特殊处理(之前的规则无法兼容)
|
|||
|
|
if quality==4 then
|
|||
|
|
quality=18
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--添加经验
|
|||
|
|
player:AddExpForType( 1 , quality , 1 )
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--10连抽
|
|||
|
|
else
|
|||
|
|
--本次产出道具列表
|
|||
|
|
local outGoodsList = {}
|
|||
|
|
|
|||
|
|
--本次抽卡出套间数量
|
|||
|
|
local suitCount=0
|
|||
|
|
|
|||
|
|
--前6次十抽必得套间物品数量--第7次后每次10抽必得套间数量
|
|||
|
|
suitCount=player.gameData.NewPlayerRaffleMap[cfgNewPlayerRaffle.id].tenLotteryCount<=6 and cfgSValue.newPlayerRaffleDisposable[1] or cfgSValue.newPlayerRaffleDisposable[2]
|
|||
|
|
|
|||
|
|
--先产出套间物品
|
|||
|
|
for i = 1, suitCount do
|
|||
|
|
|
|||
|
|
local outGoodsIdList={}
|
|||
|
|
for _, value in ipairs(outGoodsList) do
|
|||
|
|
outGoodsIdList[value.goodsId]=true
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
local randomGoodsId= RandomSuit(player,cfgNewPlayerRaffle.suitId,outGoodsIdList)
|
|||
|
|
table.insert(outGoodsList,{goodsId=randomGoodsId,goodsType=goodsType})
|
|||
|
|
--log.debug( string.format("新手限定设计卡池 十连抽产出套间,套间id:%d",randomGoodsId))
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--普通产出
|
|||
|
|
for i = 1, 10-suitCount do
|
|||
|
|
|
|||
|
|
local randomNum =math.random(1,2)
|
|||
|
|
|
|||
|
|
local stuffIdList = randomNum == 1 and cfgNewPlayerRaffle.rareStuffId or cfgNewPlayerRaffle.normalStuffId
|
|||
|
|
|
|||
|
|
local randomGoodsId = RandomStuff(player,stuffIdList)
|
|||
|
|
|
|||
|
|
--随机物品
|
|||
|
|
table.insert(outGoodsList,{goodsId=randomGoodsId,goodsType= goodsType})
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_119" )
|
|||
|
|
|
|||
|
|
--随机打乱物品
|
|||
|
|
Shuffle(outGoodsList)
|
|||
|
|
|
|||
|
|
--扣除消耗
|
|||
|
|
player:MoneyChange(dataType.GoodsType_Volute , -needVolute ,eventId)
|
|||
|
|
|
|||
|
|
for index, temp in ipairs(outGoodsList) do
|
|||
|
|
|
|||
|
|
--组装返回数据
|
|||
|
|
local item={}
|
|||
|
|
item.goodsType = temp.goodsType
|
|||
|
|
item.goodsId = temp.goodsId
|
|||
|
|
item.goodsCount = 1
|
|||
|
|
|
|||
|
|
--添加到返回数据
|
|||
|
|
data.rewards[index]={}
|
|||
|
|
data.rewards[index].item=item
|
|||
|
|
data.rewards[index].isNew = not skynet.server.illustration:IsExistGoods( player , temp.goodsType , temp.goodsId )
|
|||
|
|
|
|||
|
|
--发奖
|
|||
|
|
if not skynet.server.bag:AddGoods(player, temp.goodsType, temp.goodsId, 1) then
|
|||
|
|
--log.debug(string.format("家具添加失败:goodsType:%d,goodsId:%d",temp.goodsType,temp.goodsId))
|
|||
|
|
s2cData.code = errorInfo.ErrorCode.OPFailed
|
|||
|
|
return
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--循环套间
|
|||
|
|
for _, cfgFurniture in pairs(cfgFurnitures) do
|
|||
|
|
if cfgFurniture.id == temp.goodsId then
|
|||
|
|
|
|||
|
|
local quality = cfgFurniture.quality
|
|||
|
|
|
|||
|
|
--不凡品种特殊处理(之前的规则无法兼容)
|
|||
|
|
if quality==4 then
|
|||
|
|
quality=18
|
|||
|
|
end
|
|||
|
|
--添加经验
|
|||
|
|
player:AddExpForType( 1 , quality , 1 )
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--添加次数
|
|||
|
|
player.gameData.NewPlayerRaffleMap[cfgNewPlayerRaffle.id].tenLotteryCount=player.gameData.NewPlayerRaffleMap[cfgNewPlayerRaffle.id].tenLotteryCount+1
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--更新抽奖次数
|
|||
|
|
player.gameData.NewPlayerRaffleMap[cfgNewPlayerRaffle.id].totalLotteryCount = player.gameData.NewPlayerRaffleMap[cfgNewPlayerRaffle.id].totalLotteryCount + (lotteryTimes == 1 and 1 or 10)
|
|||
|
|
|
|||
|
|
--是否可以分享
|
|||
|
|
if 0 == player.gameData.todayGain.designShare then
|
|||
|
|
data.canShare = true
|
|||
|
|
else
|
|||
|
|
data.canShare = false
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
data.newPlayerCount =10 - player.gameData.NewPlayerRaffleMap[cfgNewPlayerRaffle.id].oneLotteryCount
|
|||
|
|
|
|||
|
|
--处理红点
|
|||
|
|
if lotteryTimes == 1 then
|
|||
|
|
skynet.server.msgTips:ReduceAll(player, 106)
|
|||
|
|
if not self:IsLottery(player,10) then
|
|||
|
|
skynet.server.msgTips:ReduceAll(player, 108)
|
|||
|
|
end
|
|||
|
|
else
|
|||
|
|
skynet.server.msgTips:ReduceAll(player, 108)
|
|||
|
|
if not self:IsLottery(player,1) then
|
|||
|
|
skynet.server.msgTips:ReduceAll(player, 106)
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--可领取奖励
|
|||
|
|
if self:IsDrawReward(player) then
|
|||
|
|
skynet.server.msgTips:Add(player,107)
|
|||
|
|
end
|
|||
|
|
s2cData.data = assert(pb.encode("S2CActivityNewPlayerRaffleLottery", data))
|
|||
|
|
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--获取预览信息
|
|||
|
|
function ActivityNewPlayerRaffle:AwardPreview( player , c2sData , s2cData )
|
|||
|
|
c2sData.data = assert(pb.decode("C2SActivityNewPlayerRaffleAwardPreview", c2sData.data ))
|
|||
|
|
s2cData.cmd = pb.enum("MsgType","CMD_S2C_ActivityNewPlayerRaffleAwardPreview")
|
|||
|
|
local data = {}
|
|||
|
|
data.overviewInfos ={}
|
|||
|
|
|
|||
|
|
--不存在开启的活动
|
|||
|
|
local cfgNewPlayerRaffle=self:CheckData(player)
|
|||
|
|
|
|||
|
|
--活动未开启
|
|||
|
|
if cfgNewPlayerRaffle == nil then
|
|||
|
|
log.debug("cfgNewPlayerRaffle is nil")
|
|||
|
|
s2cData.code = errorInfo.ErrorCode.ActivityClosed
|
|||
|
|
return
|
|||
|
|
end
|
|||
|
|
--套间列表
|
|||
|
|
local cfgFurnitures = skynet.server.gameConfig:GetPlayerAllCfg(player, "Furniture")
|
|||
|
|
if cfgFurnitures ~= nil then
|
|||
|
|
for _, cfgFurniture in pairs(cfgFurnitures) do
|
|||
|
|
if cfgFurniture.suitType== cfgNewPlayerRaffle.suitId and skynet.server.illustration:IsExistGoods(player,goodsType,cfgFurniture.id)then
|
|||
|
|
table.insert(data.overviewInfos,{goodsId=cfgFurniture.id,goodsType=goodsType })
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--稀有物品
|
|||
|
|
for _, goodsId in ipairs(cfgNewPlayerRaffle.rareStuffId) do
|
|||
|
|
if skynet.server.illustration:IsExistGoods(player,goodsType,goodsId)then
|
|||
|
|
table.insert(data.overviewInfos,{goodsId=goodsId,goodsType=goodsType })
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--普通物品
|
|||
|
|
for _, goodsId in ipairs(cfgNewPlayerRaffle.normalStuffId) do
|
|||
|
|
if skynet.server.illustration:IsExistGoods(player,goodsType,goodsId)then
|
|||
|
|
table.insert(data.overviewInfos,{goodsId=goodsId,goodsType=goodsType })
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
s2cData.data = assert(pb.encode("S2CActivityNewPlayerRaffleAwardPreview", data))
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--随机套间
|
|||
|
|
function RandomSuit(player,suitId,outGoodsList)
|
|||
|
|
|
|||
|
|
if outGoodsList == nil then
|
|||
|
|
outGoodsList={}
|
|||
|
|
end
|
|||
|
|
local retSuitId=0
|
|||
|
|
--查找道具配置
|
|||
|
|
local cfgFurnitures = skynet.server.gameConfig:GetPlayerAllCfg(player, "Furniture")
|
|||
|
|
|
|||
|
|
if cfgFurnitures == nil then
|
|||
|
|
log.error("ActivityNewPlayerRaffle:randomSuit cfgFurnitures is nil")
|
|||
|
|
return retSuitId
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
local suitList = {}
|
|||
|
|
|
|||
|
|
--循环查找套间配置
|
|||
|
|
for _, value in pairs(cfgFurnitures) do
|
|||
|
|
if value.suitType == suitId and suitId ~= 0 then
|
|||
|
|
table.insert(suitList, value)
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
if #suitList == 0 then
|
|||
|
|
log.error("ActivityNewPlayerRaffle:randomSuit suitList is nil")
|
|||
|
|
return retSuitId
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
local prioritySuitList = {}
|
|||
|
|
|
|||
|
|
--查找未得到的套间
|
|||
|
|
for _, value in ipairs(suitList) do
|
|||
|
|
if skynet.server.bag:GetGoodsCount(player,goodsType, value.id)<=0 and outGoodsList[value.id] == nil then
|
|||
|
|
table.insert(prioritySuitList,value)
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
if #prioritySuitList == 0 then
|
|||
|
|
local index = math.random(1,#suitList)
|
|||
|
|
local suit =suitList[index]
|
|||
|
|
|
|||
|
|
--返回资源
|
|||
|
|
return suit.id
|
|||
|
|
|
|||
|
|
else
|
|||
|
|
local index = math.random(1,#prioritySuitList)
|
|||
|
|
local suit =prioritySuitList[index]
|
|||
|
|
|
|||
|
|
--返回资源
|
|||
|
|
return suit.id
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--稀有物品,普通物品
|
|||
|
|
function RandomStuff(player,rareStuffIds)
|
|||
|
|
|
|||
|
|
if rareStuffIds==nil or #rareStuffIds == 0 then
|
|||
|
|
log.error("ActivityNewPlayerRaffle:randomStuff rareStuffIds is nil")
|
|||
|
|
return 0
|
|||
|
|
end
|
|||
|
|
local index = math.random(1,#rareStuffIds)
|
|||
|
|
return rareStuffIds[index]
|
|||
|
|
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--获取活动结束时间
|
|||
|
|
function ActivityNewPlayerRaffle:GetActivityEndTime(starTime)
|
|||
|
|
if starTime <=0 then
|
|||
|
|
return 0
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--获取数值基础配置
|
|||
|
|
local cfgSValue = skynet.server.gameConfig:GetAllCfg( "SValue")
|
|||
|
|
|
|||
|
|
local continuousDays = cfgSValue.newPlayerRaffleTrigger[3] or 10 -- 默认值为10天
|
|||
|
|
|
|||
|
|
--返回10天后的时间戳
|
|||
|
|
return starTime + 86400 * continuousDays
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--随机打乱物品
|
|||
|
|
function Shuffle(table)
|
|||
|
|
if type(table) ~= "table" then return end
|
|||
|
|
|
|||
|
|
for i = #table, 2, -1 do
|
|||
|
|
local j = math.random(i) -- 生成[1, i]范围内的随机索引
|
|||
|
|
table[i], table[j] = table[j], table[i] -- 交换元素
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
skynet.server.activityNewPlayerRaffle = ActivityNewPlayerRaffle
|
|||
|
|
return ActivityNewPlayerRaffle
|