2097 lines
76 KiB
Lua
2097 lines
76 KiB
Lua
local skynet = require "skynet"
|
||
local oo = require "Class"
|
||
local log = require "Log"
|
||
local pb = require "pb"
|
||
local errorInfo = require "ErrorInfo"
|
||
local json =require "json"
|
||
local dataType = require "DataType"
|
||
local Raffle = oo.class()
|
||
|
||
Raffle.ActivityType = dataType.ActivityType_Raffle
|
||
Raffle.BoxType_Normal = 1 --签到奖励类型 普通
|
||
Raffle.BoxType_Blind = 2 --签到奖励类型 盲盒
|
||
Raffle.BoxType_Optional = 3 --签到奖励类型 自选
|
||
|
||
Raffle.LotteryType_1= 1 --初级家具卡池
|
||
Raffle.LotteryType_2= 2 --高级家具卡池
|
||
Raffle.LotteryType_3= 3 --限时家具卡池
|
||
Raffle.LotteryType_4= 4 --不凡家具卡池
|
||
|
||
Raffle.TicketType_1= 1 --高级设计稿
|
||
Raffle.TicketType_2= 2 --初级设计稿
|
||
Raffle.TicketType_3= 3 --限时设计稿
|
||
Raffle.TicketType_4= 4 --限时不凡设计稿
|
||
|
||
--构造函数
|
||
function Raffle:Init()
|
||
|
||
end
|
||
|
||
-- 每次登录需要进行修改的数据
|
||
function Raffle:LoginInitData(player)
|
||
|
||
--功能未开启
|
||
if not player:IsUnlockSystem( dataType.UnlockSystem_DesignHouse ) then
|
||
log.debug("设计空间未开启-等级不足")
|
||
return
|
||
end
|
||
|
||
--获取开启的设计卡池
|
||
local activitys = self:CheckDataAndGetActivity(player)
|
||
|
||
for lotteryType, activity in pairs(activitys) do
|
||
|
||
--活动未开启
|
||
if activity.activityId == 0 then
|
||
goto continue
|
||
end
|
||
|
||
local raffle=player.gameData.RaffleMap[activity.activityId]
|
||
|
||
--兼容有问题的号
|
||
if raffle.totalDesignCount == nil then
|
||
raffle.totalDesignCount=0
|
||
end
|
||
if raffle.damnedGoodsIds== nil then
|
||
raffle.damnedGoodsIds={}
|
||
end
|
||
|
||
--是否有免费次数
|
||
if raffle.freeTime <= skynet.GetTime() then
|
||
if lotteryType == self.LotteryType_2 then
|
||
skynet.server.msgTips:Reset(player , 31)
|
||
elseif lotteryType == self.LotteryType_1 then
|
||
skynet.server.msgTips:Reset(player , 34)
|
||
end
|
||
end
|
||
|
||
--是否包含签到奖励
|
||
if raffle.timeSignIn == nil or not next(raffle.timeSignIn) then
|
||
goto continue
|
||
end
|
||
|
||
--登录天数是否今日
|
||
if os.date("%Y-%m-%d",raffle.loginTime) ~= os.date("%Y-%m-%d",skynet.GetTime()) then
|
||
|
||
raffle.loginTime=skynet.GetTime()
|
||
|
||
--检查签到奖励
|
||
local cfgRaffle = self:GetCfgRaffleByRaffleType( player , {self.LotteryType_3,self.LotteryType_4} )
|
||
if cfgRaffle== nil or cfgRaffle.signReward == nil or not next(cfgRaffle.signReward) then
|
||
goto continue
|
||
end
|
||
|
||
--初始化下一天的签到奖励
|
||
for day, _ in ipairs(cfgRaffle.signReward) do
|
||
if day == #raffle.timeSignIn+1 then
|
||
table.insert(raffle.timeSignIn , {day = day,status = 1})
|
||
break
|
||
end
|
||
end
|
||
end
|
||
|
||
::continue::
|
||
end
|
||
|
||
--初始化积分
|
||
if player.gameData.design==nil then
|
||
player.gameData.design={}
|
||
end
|
||
|
||
if player.gameData.design.highStorePoints == nil then
|
||
--积分
|
||
player.gameData.design.highStorePoints = 0
|
||
end
|
||
|
||
--初始化灵感碎片
|
||
if player.gameData.design.fragmentNum == nil then
|
||
player.gameData.design.fragmentNum = 0
|
||
end
|
||
|
||
--红点处理
|
||
skynet.server.msgTips:Reset(player , 68)
|
||
skynet.server.msgTips:Reset(player , 69)
|
||
|
||
math.randomseed(skynet.GetTime())
|
||
|
||
--测试d代码
|
||
--self:TimeFragmentShow(player,{},{})
|
||
end
|
||
|
||
--初始玩家数据,返回设计id信息index1:初级设计id,index2:高级设计id,index3:限时设计id
|
||
function Raffle:CheckDataAndGetActivity(player)
|
||
|
||
--查询类型
|
||
local LotteryTypes={self.LotteryType_1,self.LotteryType_2,self.LotteryType_3,self.LotteryType_4}
|
||
|
||
--返回开启的活动id
|
||
local activitys= {}
|
||
|
||
for _, LotteryType in ipairs(LotteryTypes) do
|
||
local activityId,startTime,endTime,id = skynet.server.activity:GetActivityInfo( player , dataType.ActivityType_Raffle , LotteryType )
|
||
|
||
--活动开启,不存在玩家数据
|
||
if activityId~=0 and (player.gameData.RaffleMap == nil or player.gameData.RaffleMap[activityId] == nil) then
|
||
|
||
if player.gameData.RaffleMap== nil then
|
||
player.gameData.RaffleMap= {}
|
||
end
|
||
|
||
--初始化玩家数据
|
||
player.gameData.RaffleMap[activityId]= {}
|
||
player.gameData.RaffleMap[activityId].id=id
|
||
player.gameData.RaffleMap[activityId].freeTime=skynet.GetTime() --初始存在免费
|
||
|
||
--单抽设计次数
|
||
player.gameData.RaffleMap[activityId].designCount=0
|
||
|
||
--单抽累计设计次数
|
||
player.gameData.RaffleMap[activityId].totalDesignCount=0
|
||
|
||
player.gameData.RaffleMap[activityId].isBuyStorePack8 = false
|
||
|
||
--初始化时间(用于计算登录天数)
|
||
player.gameData.RaffleMap[activityId].loginTime=skynet.GetTime()
|
||
|
||
--获取对应卡池信息
|
||
local cfgRaffle = skynet.server.gameConfig:GetPlayerCurCfg( player , "Raffle" , activityId )
|
||
|
||
--限时签到
|
||
if cfgRaffle ~= nil and next(cfgRaffle.signReward) then
|
||
player.gameData.RaffleMap[activityId].timeSignIn={}
|
||
table.insert( player.gameData.RaffleMap[activityId].timeSignIn , {day = 1,status = 1})
|
||
|
||
--十连抽次数
|
||
player.gameData.RaffleMap[activityId].totalTimeTenNum=0
|
||
end
|
||
|
||
--累计抽卡
|
||
if cfgRaffle ~= nil and next(cfgRaffle.raffleNum) then
|
||
player.gameData.RaffleMap[activityId].totalTimeReward={}
|
||
end
|
||
|
||
--保底套间已经得到的信息
|
||
player.gameData.RaffleMap[activityId].damnedGoodsIds={}
|
||
end
|
||
|
||
if activityId ~= 0 then
|
||
activitys[LotteryType]={activityId=activityId,startTime=startTime,endTime=endTime}
|
||
end
|
||
end
|
||
return activitys
|
||
|
||
end
|
||
|
||
--获取免费的设计稿
|
||
function Raffle:GetFreeDesign( player )
|
||
|
||
--可免费抽卡类型
|
||
local freeTypes ={}
|
||
|
||
--开启的活动
|
||
local activitys=self:CheckDataAndGetActivity(player)
|
||
|
||
--循环检查
|
||
for lotteryType, activity in pairs(activitys) do
|
||
|
||
--活动未开启
|
||
if activity.activityId == 0 then
|
||
goto continue
|
||
end
|
||
|
||
if player.gameData.RaffleMap[activity.activityId].freeTime < skynet.GetTime() then
|
||
table.insert(freeTypes,lotteryType)
|
||
end
|
||
|
||
::continue::
|
||
end
|
||
|
||
return freeTypes
|
||
end
|
||
|
||
--根据类型获取设计信息
|
||
function Raffle:GetCfgRaffleByRaffleType( player , raffleTypes )
|
||
|
||
local cfgRaffle=nil
|
||
|
||
--获取活动信息
|
||
local activitys=self:CheckDataAndGetActivity(player)
|
||
for _, raffleType in pairs(raffleTypes) do
|
||
|
||
--活动未开启
|
||
if activitys[raffleType] ~= nil and activitys[raffleType].activityId ~= 0 then
|
||
|
||
--获取对应卡池信息
|
||
cfgRaffle= skynet.server.gameConfig:GetPlayerCurCfg( player , "Raffle" , activitys[raffleType].activityId )
|
||
return cfgRaffle
|
||
end
|
||
end
|
||
return cfgRaffle
|
||
end
|
||
|
||
--获取随机家具配置
|
||
function Raffle:GetFurniture( player , lotteryId , quality )
|
||
|
||
--家具和装修
|
||
local goodIds = {}
|
||
local cfgRaffle = skynet.server.gameConfig:GetPlayerCurCfg( player , "Raffle" , lotteryId )
|
||
|
||
--添加散件家具
|
||
if dataType.FurnitureQuality_Common == quality then
|
||
goodIds = skynet.server.common:DeepCopy(cfgRaffle.ordinaryFurId)
|
||
elseif dataType.FurnitureQuality_Special == quality then
|
||
goodIds = skynet.server.common:DeepCopy(cfgRaffle.rarityFurId)
|
||
if cfgRaffle.raffleType ==self.LotteryType_1 then
|
||
--添加套装家具(这里套间认为是稀有)
|
||
local cfgAllFurniture = skynet.server.gameConfig:GetPlayerAllCfg( player , "Furniture")
|
||
|
||
for _, v2 in pairs(cfgAllFurniture) do
|
||
if cfgRaffle.suitId == v2.suitType then
|
||
table.insert(goodIds,v2.id)
|
||
end
|
||
end
|
||
end
|
||
elseif dataType.FurnitureQuality_Rare == quality then
|
||
goodIds = skynet.server.common:DeepCopy(cfgRaffle.rareFurId)
|
||
|
||
if cfgRaffle.raffleType ~=self.LotteryType_4 then
|
||
--添加套装家具
|
||
local cfgAllFurniture = skynet.server.gameConfig:GetPlayerAllCfg( player , "Furniture")
|
||
|
||
for _, v2 in pairs(cfgAllFurniture) do
|
||
if cfgRaffle.suitId == v2.suitType then
|
||
table.insert(goodIds,v2.id)
|
||
end
|
||
end
|
||
end
|
||
|
||
elseif dataType.FurnitureQuality_Splendid == quality then
|
||
|
||
--添加套装家具
|
||
local cfgAllFurniture = skynet.server.gameConfig:GetPlayerAllCfg( player , "Furniture")
|
||
|
||
for _, v2 in pairs(cfgAllFurniture) do
|
||
if cfgRaffle.suitId == v2.suitType then
|
||
table.insert(goodIds,v2.id)
|
||
end
|
||
end
|
||
end
|
||
|
||
return goodIds
|
||
end
|
||
|
||
--获取券信息
|
||
function Raffle:GetTicket( player )
|
||
local data = {}
|
||
data.basicBluePrint = skynet.server.bag:GetGoodsCount( player , dataType.GoodsType_Prop , 1)
|
||
data.advancedBluePrint = skynet.server.bag:GetGoodsCount( player , dataType.GoodsType_Prop , 2)
|
||
|
||
--检查并且获取活动信息
|
||
local activitys=self:CheckDataAndGetActivity(player)
|
||
if activitys ~= nil and activitys[self.TicketType_3] ~= nil then
|
||
local cfgTimeRaffle = skynet.server.gameConfig:GetPlayerCurCfg( player , "Raffle" , activitys[self.TicketType_3].activityId )
|
||
data.limitedBluePrint = skynet.server.bag:GetGoodsCount( player , dataType.GoodsType_Prop , cfgTimeRaffle.ticket)
|
||
elseif activitys ~= nil and activitys[self.TicketType_4] ~= nil then
|
||
local cfgTimeRaffle = skynet.server.gameConfig:GetPlayerCurCfg( player , "Raffle" , activitys[self.TicketType_4].activityId )
|
||
data.limitedBluePrint = skynet.server.bag:GetGoodsCount( player , dataType.GoodsType_Prop , cfgTimeRaffle.ticket)
|
||
else
|
||
data.limitedBluePrint = 0
|
||
end
|
||
|
||
--玩家高级卡池的积分
|
||
data.highStorePoints = player.gameData.design.highStorePoints
|
||
return data
|
||
end
|
||
|
||
--商城充值
|
||
function Raffle:Pay( player , storeId )
|
||
|
||
local activitys =self:CheckDataAndGetActivity(player)
|
||
|
||
for _, activity in pairs(activitys) do
|
||
|
||
--活动是否开启
|
||
if activity.activityId == 0 then
|
||
goto continue
|
||
end
|
||
|
||
local cfgRaffle = skynet.server.gameConfig:GetPlayerCurCfg( player , "Raffle" , activity.activityId )
|
||
--一元礼包显示控制
|
||
if cfgRaffle.limitPack == storeId then
|
||
player.gameData.RaffleMap[activity.activityId].isBuyStorePack8 = true
|
||
end
|
||
|
||
::continue::
|
||
end
|
||
end
|
||
|
||
--是否有签到奖励可领取
|
||
function Raffle:CheckSignIn( player )
|
||
|
||
--获取对应卡池信息
|
||
local cfgRaffle = self:GetCfgRaffleByRaffleType( player , {self.LotteryType_3,self.LotteryType_4} )
|
||
if cfgRaffle== nil or cfgRaffle.signReward == nil or not next(cfgRaffle.signReward) then
|
||
return false
|
||
end
|
||
|
||
local raffle=player.gameData.RaffleMap[cfgRaffle.id]
|
||
|
||
for _, value in ipairs(raffle.timeSignIn) do
|
||
if value.status == 1 then
|
||
return true
|
||
end
|
||
end
|
||
|
||
return false
|
||
end
|
||
|
||
--限时卡池是否有奖励可以领取
|
||
function Raffle:CheckTimeAward( player )
|
||
|
||
--获取对应卡池信息
|
||
local cfgRaffle = self:GetCfgRaffleByRaffleType( player , {self.LotteryType_3,self.LotteryType_4} )
|
||
if cfgRaffle== nil or cfgRaffle.signReward == nil or not next(cfgRaffle.signReward) or cfgRaffle.raffleNum== nil or not next(cfgRaffle.raffleNum) then
|
||
return false
|
||
end
|
||
|
||
local raffle=player.gameData.RaffleMap[cfgRaffle.id]
|
||
local totalCount =raffle.totalDesignCount+ raffle.totalTimeTenNum*10
|
||
|
||
for _ ,num in ipairs(cfgRaffle.raffleNum) do
|
||
|
||
--是否解锁
|
||
local function ifGreaterNum ()
|
||
return totalCount >= num
|
||
end
|
||
|
||
--是否购买
|
||
local function ifBuy ()
|
||
for _, numTemp in ipairs(raffle.totalTimeReward) do
|
||
if numTemp == num then
|
||
return true
|
||
end
|
||
end
|
||
return false
|
||
end
|
||
|
||
--已解锁 未购买
|
||
if ifGreaterNum() and not ifBuy() then
|
||
return true
|
||
end
|
||
end
|
||
|
||
return false
|
||
end
|
||
|
||
--是否有免费抽卡
|
||
function Raffle:CheckFreeDesign( player , lotteryTypeParam)
|
||
|
||
--获取开启的设计卡池
|
||
local activitys = self:CheckDataAndGetActivity(player)
|
||
|
||
for lotteryType, activity in pairs(activitys) do
|
||
|
||
--活动未开启
|
||
if activity.activityId == 0 or lotteryType ~= lotteryTypeParam then
|
||
goto continue
|
||
end
|
||
|
||
local raffle=player.gameData.RaffleMap[activity.activityId]
|
||
|
||
--是否有免费次数
|
||
if raffle.freeTime <= skynet.GetTime() then
|
||
return true
|
||
end
|
||
|
||
::continue::
|
||
end
|
||
|
||
return false
|
||
end
|
||
|
||
--获取进阶礼包信息
|
||
function Raffle:Show( player , c2sData , s2cData )
|
||
c2sData.data = assert(pb.decode("C2SDesignShow", c2sData.data ))
|
||
s2cData.cmd = pb.enum("MsgType","CMD_S2C_DesignShow")
|
||
local data = {}
|
||
data.cardPoolInfos={}
|
||
data.isShowUI={}
|
||
data.isBuyStorePack8 =false
|
||
|
||
--检查并且获取活动信息
|
||
local activitys=self:CheckDataAndGetActivity(player)
|
||
|
||
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
|
||
|
||
--循环开启的活动
|
||
for raffleType, activity in pairs(activitys) do
|
||
local isShowUI = false
|
||
|
||
--活动未开启
|
||
if activity.activityId ~= 0 then
|
||
|
||
--获取对应卡池配置信息
|
||
local cfgRaffle= skynet.server.gameConfig:GetPlayerCurCfg( player , "Raffle" , activity.activityId )
|
||
|
||
--卡池信息
|
||
table.insert(data.cardPoolInfos,{raffleId=activity.activityId,raffleType=raffleType,startTime=activity.startTime,endTime=activity.endTime})
|
||
|
||
--免费设计时间
|
||
local freeTime = player.gameData.RaffleMap[activity.activityId].freeTime
|
||
|
||
--设计次数
|
||
local designCount = player.gameData.RaffleMap[activity.activityId].designCount
|
||
|
||
--初级免费抽奖时间戳(秒)
|
||
if cfgRaffle.raffleType ==self.LotteryType_1 then
|
||
data.basicFreeTime=freeTime
|
||
|
||
--高级免费抽奖时间戳(秒)
|
||
elseif cfgRaffle.raffleType == self.LotteryType_2 then
|
||
data.advancedFreeTime = freeTime
|
||
|
||
--距离高级卡池保底次数
|
||
data.highCount=tonumber(cfgSValue.limitRaffleRareNewGua)- designCount
|
||
|
||
--显示设计
|
||
elseif cfgRaffle.raffleType == self.LotteryType_3 then
|
||
data.timeCount = tonumber(cfgSValue.voluteRaffleRareNewGua) - designCount
|
||
elseif cfgRaffle.raffleType == self.LotteryType_4 then
|
||
data.timeCount = tonumber(cfgSValue.splendidRaffleSingle) - designCount
|
||
end
|
||
|
||
--是否购买过礼包
|
||
if player.gameData.RaffleMap[activity.activityId].isBuyStorePack8 then
|
||
data.isBuyStorePack8 = true
|
||
end
|
||
|
||
isShowUI=true
|
||
|
||
end
|
||
table.insert(data.isShowUI , isShowUI)
|
||
end
|
||
|
||
data.designCurrency=self:GetTicket(player)
|
||
|
||
--返回信息
|
||
s2cData.data = assert(pb.encode("S2CDesignShow", data))
|
||
end
|
||
|
||
--根据参数随机几个道具,randomGoodsMap 随机资源,key:权重,val:道具列表。lotteryTimes 抽奖次数
|
||
function Raffle:LotteryGoods(player, randomGoodsMap , lotteryTimes )
|
||
|
||
--已经产出的道具
|
||
local outPutGoods = {}
|
||
|
||
--不存在随机配置
|
||
if not randomGoodsMap or not next(randomGoodsMap) then
|
||
return outPutGoods
|
||
end
|
||
|
||
--svalu配置
|
||
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
|
||
|
||
--总概率
|
||
local totalRandom = 0
|
||
|
||
--统计总概率
|
||
for weight, _ in pairs(randomGoodsMap) do
|
||
totalRandom=totalRandom+weight
|
||
end
|
||
|
||
--循环产出
|
||
for i = 1, lotteryTimes, 1 do
|
||
|
||
::continue::--已经重复了,需要重新随机
|
||
local random = math.random(1,totalRandom)
|
||
|
||
--随机道具列表
|
||
local goods = {}
|
||
|
||
--以及比较过的权重
|
||
local alreadyWeight = 0
|
||
for weight, goodsTemp in pairs(randomGoodsMap) do
|
||
if random<= alreadyWeight+weight then
|
||
goods =goodsTemp
|
||
break
|
||
end
|
||
alreadyWeight=alreadyWeight+weight
|
||
end
|
||
|
||
if not next(goods) then
|
||
goto continue
|
||
end
|
||
|
||
--随机一个家具
|
||
local goodsId = goods[math.random(1,#goods)]
|
||
|
||
--重复个数
|
||
local repetitionNum=0
|
||
|
||
--判断是否重复
|
||
for _, valueGoodsId in ipairs(outPutGoods) do
|
||
if valueGoodsId == goodsId then
|
||
repetitionNum=repetitionNum+1
|
||
|
||
if repetitionNum >= cfgSValue.raffleTenDropRepeatLimit then
|
||
goto continue
|
||
end
|
||
end
|
||
end
|
||
|
||
table.insert(outPutGoods,goodsId)
|
||
end
|
||
|
||
--返回信息
|
||
return outPutGoods
|
||
end
|
||
|
||
--领取进阶礼包信息
|
||
function Raffle:Lottery( player , c2sData , s2cData )
|
||
c2sData.data = assert(pb.decode("C2SDesignLottery", c2sData.data ))
|
||
s2cData.cmd = pb.enum("MsgType","CMD_S2C_DesignLottery")
|
||
local data = {}
|
||
data.rewards={}
|
||
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
|
||
local goodsType=dataType.GoodsType_Furniture
|
||
|
||
--//抽奖类型 1-初级家具卡池 2-高级家具卡池 3-限时家具卡池
|
||
local lotteryType = c2sData.data.lotteryType
|
||
data.lotteryType=lotteryType
|
||
|
||
--//抽奖次数 1-抽一次 2-抽十次
|
||
local lotteryTimes = c2sData.data.lotteryTimes==2 and 10 or 1
|
||
|
||
--获取对应卡池配置信息
|
||
local cfgRaffle = self:GetCfgRaffleByRaffleType( player , {lotteryType} )
|
||
if cfgRaffle== nil then
|
||
cfgRaffle=self:GetCfgRaffleByRaffleType( player , {self.LotteryType_4} )
|
||
if cfgRaffle== nil then
|
||
s2cData.code = errorInfo.ErrorCode.OpFailed
|
||
return
|
||
end
|
||
end
|
||
|
||
--玩家设计空间信息
|
||
local raffle=player.gameData.RaffleMap[cfgRaffle.id]
|
||
|
||
local isFree = false; --是不是免费抽奖
|
||
|
||
--获取需要随机的随机家具
|
||
local commonGoods = self:GetFurniture( player , cfgRaffle.id , dataType.FurnitureQuality_Common ) --普通家具
|
||
local specialGoods = self:GetFurniture( player , cfgRaffle.id , dataType.FurnitureQuality_Special ) --稀有家具
|
||
local rareGoods = self:GetFurniture( player , cfgRaffle.id , dataType.FurnitureQuality_Rare ) --罕见家具
|
||
local splendidGoods = self:GetFurniture( player , cfgRaffle.id , dataType.FurnitureQuality_Splendid ) --不凡家具
|
||
|
||
--产出道具
|
||
local outPutGoods={}
|
||
|
||
--初级设计空间
|
||
if cfgRaffle.raffleType == self.LotteryType_1 then --初级设计空间
|
||
|
||
--是否免费
|
||
local isFree = false
|
||
|
||
--单抽,是否免费
|
||
if lotteryTimes ==1 and raffle.freeTime <= skynet.GetTime() then
|
||
isFree = true
|
||
raffle.freeTime = skynet.GetTime() + (cfgSValue.goldRaffleTypeFreeTime * 60 )
|
||
end
|
||
|
||
--判断资源是否足够(移除资源 需要注意 如果失败了怎么办)
|
||
if not isFree and not skynet.server.bag:RemoveGoods( player , dataType.GoodsType_Prop , 1 , lotteryTimes) then
|
||
s2cData.code = errorInfo.ErrorCode.NoEnoughGoods
|
||
return
|
||
end
|
||
|
||
--组装随机资源参数
|
||
local randomGoodsMap = {
|
||
[math.floor(tonumber(cfgSValue.goldRaffleFurnitureRatio[1])*100)] = specialGoods,
|
||
[math.floor(tonumber(cfgSValue.goldRaffleFurnitureRatio[2])*100)] = commonGoods,
|
||
}
|
||
|
||
--随机产出
|
||
outPutGoods = self:LotteryGoods(player, randomGoodsMap , lotteryTimes )
|
||
|
||
--任务
|
||
--skynet.server.taskListEvent:Modify( player , 9 , 1 )--这个任务看起来有问题,先注释掉
|
||
skynet.server.levelTask:Modify( player , 69 , lotteryTimes )
|
||
skynet.server.taskListEvent:Modify( player , 69 , lotteryTimes )
|
||
|
||
--高级设计空间
|
||
elseif cfgRaffle.raffleType == self.LotteryType_2 then --高级设计空间
|
||
|
||
--是否免费
|
||
local isFree = false
|
||
|
||
--单抽,是否免费
|
||
if lotteryTimes ==1 and raffle.freeTime <= skynet.GetTime() then
|
||
isFree=true
|
||
raffle.freeTime = skynet.GetTime() + (cfgSValue.voluteRaffleTypeFreeTime * 60 )
|
||
end
|
||
|
||
--判断资源是否足够(移除资源 需要注意 如果失败了怎么办)
|
||
if not isFree and not skynet.server.bag:RemoveGoods( player , dataType.GoodsType_Prop , 2 , lotteryTimes) then
|
||
s2cData.code = errorInfo.ErrorCode.NoEnoughGoods
|
||
return
|
||
end
|
||
|
||
--未获取的套间道具
|
||
local notExistSuitGoods ={}
|
||
|
||
for _, goodsId in ipairs(rareGoods) do
|
||
if not skynet.server.illustration:IsExistGoods( player , goodsType , goodsId ) then
|
||
table.insert( notExistSuitGoods , goodsId )
|
||
end
|
||
end
|
||
|
||
--所有都得到,直接全部随机
|
||
if not next(notExistSuitGoods) then
|
||
|
||
--过滤当前已经获得的套间道具
|
||
for _, goodsId in ipairs(rareGoods) do
|
||
for _, value in ipairs(raffle.damnedGoodsIds) do
|
||
if goodsId == value then
|
||
goto continue
|
||
end
|
||
end
|
||
table.insert( notExistSuitGoods , goodsId )
|
||
::continue::
|
||
end
|
||
end
|
||
|
||
--到这里如果还没套间,则全部随机
|
||
if not next(notExistSuitGoods) then
|
||
|
||
for _, goodsId in ipairs(rareGoods) do
|
||
table.insert( notExistSuitGoods , goodsId )
|
||
end
|
||
end
|
||
|
||
--组装随机资源参数
|
||
local randomGoodsMap = {}
|
||
|
||
--是否是单抽
|
||
if lotteryTimes ==1 then
|
||
|
||
--是否出保底
|
||
if raffle.designCount +1 >= tonumber(cfgSValue.limitRaffleRareNewGua) then
|
||
|
||
--随机一个套间道具
|
||
table.insert(outPutGoods,notExistSuitGoods[math.random(1,#notExistSuitGoods)])
|
||
else
|
||
|
||
randomGoodsMap = {
|
||
[math.floor(tonumber(cfgSValue.seniorRaffleFurnitureRatio[1])*100)] = notExistSuitGoods,
|
||
[math.floor(tonumber(cfgSValue.seniorRaffleFurnitureRatio[2])*100)] = specialGoods,
|
||
[math.floor(tonumber(cfgSValue.seniorRaffleFurnitureRatio[3])*100)] = commonGoods,
|
||
}
|
||
|
||
--随机一个套间道具
|
||
outPutGoods = self:LotteryGoods(player, randomGoodsMap , lotteryTimes )
|
||
raffle.designCount = raffle.designCount +1
|
||
end
|
||
|
||
--判断是否出套间id
|
||
for _, goodsId1 in ipairs(outPutGoods) do
|
||
for _, goodsId2 in ipairs(notExistSuitGoods) do
|
||
if goodsId1 == goodsId2 then
|
||
raffle.designCount = 0
|
||
table.insert( raffle.damnedGoodsIds , goodsId1 )
|
||
break
|
||
end
|
||
end
|
||
end
|
||
--十连抽
|
||
else
|
||
|
||
randomGoodsMap = {
|
||
[math.floor(tonumber(cfgSValue.seniorRaffleFurnitureRatio[2])*100)] = specialGoods,
|
||
[math.floor(tonumber(cfgSValue.seniorRaffleFurnitureRatio[3])*100)] = commonGoods,
|
||
}
|
||
|
||
--先随机
|
||
outPutGoods = self:LotteryGoods(player, randomGoodsMap , lotteryTimes )
|
||
|
||
--随机套间id
|
||
local suitGoods = notExistSuitGoods[math.random(1,#notExistSuitGoods)]
|
||
outPutGoods[math.random(1,#outPutGoods)]=suitGoods
|
||
|
||
--添加到已获得
|
||
table.insert( raffle.damnedGoodsIds , suitGoods )
|
||
end
|
||
|
||
--添加积分
|
||
player.gameData.design.highStorePoints = player.gameData.design.highStorePoints + cfgSValue.raffleIntegral*lotteryTimes
|
||
|
||
--任务
|
||
skynet.server.levelTask:Modify( player , 48 , lotteryTimes )
|
||
--skynet.server.taskListEvent:Modify( player , 10 , 1 )--看起来这个任务有问题,先注释掉
|
||
skynet.server.taskListEvent:Modify( player , 48 , lotteryTimes )
|
||
|
||
--套间是否已经全部获得
|
||
if #raffle.damnedGoodsIds == #rareGoods then
|
||
raffle.damnedGoodsIds={}
|
||
end
|
||
|
||
--限时设计空间
|
||
elseif cfgRaffle.raffleType == self.LotteryType_3 then --限时设计空间
|
||
|
||
--判断资源是否足够(移除资源 需要注意 如果失败了怎么办)
|
||
if not skynet.server.bag:RemoveGoods( player , dataType.GoodsType_Prop , cfgRaffle.ticket , lotteryTimes) then
|
||
s2cData.code = errorInfo.ErrorCode.NoEnoughGoods
|
||
return
|
||
end
|
||
|
||
--未获取的套间道具
|
||
local notExistSuitGoods ={}
|
||
|
||
for _, goodsId in ipairs(rareGoods) do
|
||
if not skynet.server.illustration:IsExistGoods( player , goodsType , goodsId ) then
|
||
table.insert( notExistSuitGoods , goodsId )
|
||
end
|
||
end
|
||
|
||
--所有都得到,直接全部随机
|
||
if not next(notExistSuitGoods) then
|
||
|
||
--过滤已经获得的套间道具
|
||
for _, goodsId in ipairs(rareGoods) do
|
||
for _, value in ipairs(raffle.damnedGoodsIds) do
|
||
if goodsId == value then
|
||
goto continue
|
||
end
|
||
end
|
||
table.insert( notExistSuitGoods , goodsId )
|
||
::continue::
|
||
end
|
||
end
|
||
|
||
--到这里如果还没套间,则全部随机
|
||
if not next(notExistSuitGoods) then
|
||
|
||
for _, goodsId in ipairs(rareGoods) do
|
||
table.insert( notExistSuitGoods , goodsId )
|
||
end
|
||
end
|
||
|
||
--组装随机资源参数
|
||
local randomGoodsMap = {}
|
||
|
||
--是否是单抽
|
||
if lotteryTimes ==1 then
|
||
|
||
--是否出保底
|
||
if raffle.designCount+1 >= tonumber(cfgSValue.voluteRaffleRareNewGua) then
|
||
|
||
--随机一个套间道具
|
||
table.insert(outPutGoods,notExistSuitGoods[math.random(1,#notExistSuitGoods)])
|
||
else
|
||
|
||
randomGoodsMap = {
|
||
[math.floor(tonumber(cfgSValue.seniorRaffleFurnitureRatio[1])*100)] = notExistSuitGoods,
|
||
[math.floor(tonumber(cfgSValue.seniorRaffleFurnitureRatio[2])*100)] = specialGoods,
|
||
[math.floor(tonumber(cfgSValue.seniorRaffleFurnitureRatio[3])*100)] = commonGoods,
|
||
}
|
||
|
||
--随机一个套间道具
|
||
outPutGoods = self:LotteryGoods(player, randomGoodsMap , lotteryTimes )
|
||
raffle.designCount = raffle.designCount +1
|
||
end
|
||
|
||
--判断是否出套间id
|
||
for _, goodsId1 in ipairs(outPutGoods) do
|
||
for _, goodsId2 in ipairs(notExistSuitGoods) do
|
||
if goodsId1 == goodsId2 then
|
||
raffle.designCount = 0
|
||
table.insert( raffle.damnedGoodsIds , goodsId1 )
|
||
break
|
||
end
|
||
end
|
||
end
|
||
|
||
--添加累计单抽
|
||
raffle.totalDesignCount=raffle.totalDesignCount +1
|
||
|
||
--十连抽
|
||
else
|
||
|
||
randomGoodsMap = {
|
||
[math.floor(tonumber(cfgSValue.seniorRaffleFurnitureRatio[2])*100)] = specialGoods,
|
||
[math.floor(tonumber(cfgSValue.seniorRaffleFurnitureRatio[3])*100)] = commonGoods,
|
||
}
|
||
|
||
--先随机
|
||
outPutGoods = self:LotteryGoods(player, randomGoodsMap , lotteryTimes )
|
||
|
||
--罕见家具个数
|
||
local rareNum =1
|
||
|
||
if (raffle.totalTimeTenNum+1)%cfgSValue.hiddenRafflePositive[1]==0 then
|
||
rareNum=cfgSValue.hiddenRafflePositive[2]
|
||
end
|
||
|
||
--已经随机过的位置
|
||
local posList ={}
|
||
for i = 1, rareNum, 1 do
|
||
|
||
::continue::--重新随机位置
|
||
local pos = math.random(1,#outPutGoods)
|
||
|
||
--判断是否随机过
|
||
for _, value in ipairs(posList) do
|
||
if pos == value then
|
||
goto continue
|
||
end
|
||
end
|
||
|
||
--添加随机位置
|
||
table.insert( posList , pos )
|
||
|
||
--随机罕见道具
|
||
local goodsId = notExistSuitGoods[math.random(1,#notExistSuitGoods)]
|
||
|
||
--随机套间id
|
||
outPutGoods[pos]=goodsId
|
||
|
||
--删除已经得到过的罕见道具
|
||
for i = 1, #notExistSuitGoods, 1 do
|
||
if notExistSuitGoods[i] == goodsId then
|
||
table.remove( notExistSuitGoods , i )
|
||
break
|
||
end
|
||
end
|
||
|
||
--添加到已产出的套间
|
||
table.insert( raffle.damnedGoodsIds , goodsId )
|
||
|
||
--套间是否已经全部获得
|
||
if #raffle.damnedGoodsIds == #rareGoods or not next(notExistSuitGoods) then
|
||
raffle.damnedGoodsIds={}
|
||
notExistSuitGoods=rareGoods
|
||
end
|
||
end
|
||
|
||
--第一次触发礼包
|
||
if raffle.totalTimeTenNum == 0 then
|
||
skynet.server.store:TriggerPackMultiDraw(player,cfgRaffle)
|
||
end
|
||
|
||
--添加次数
|
||
raffle.totalTimeTenNum=raffle.totalTimeTenNum+1
|
||
end
|
||
|
||
--套间是否已经全部获得
|
||
if #raffle.damnedGoodsIds == #rareGoods then
|
||
raffle.damnedGoodsIds={}
|
||
end
|
||
elseif cfgRaffle.raffleType == self.LotteryType_4 then --限时设计空间-不凡
|
||
|
||
--判断资源是否足够(移除资源 需要注意 如果失败了怎么办)
|
||
if not skynet.server.bag:RemoveGoods( player , dataType.GoodsType_Prop , cfgRaffle.ticket , lotteryTimes) then
|
||
s2cData.code = errorInfo.ErrorCode.NoEnoughGoods
|
||
return
|
||
end
|
||
|
||
--未获取的套间道具
|
||
local notExistSuitGoods ={}
|
||
|
||
for _, goodsId in ipairs(splendidGoods) do
|
||
if not skynet.server.illustration:IsExistGoods( player , goodsType , goodsId ) then
|
||
table.insert( notExistSuitGoods , goodsId )
|
||
end
|
||
end
|
||
|
||
--所有都得到,直接全部随机
|
||
if not next(notExistSuitGoods) then
|
||
for _, goodsId in ipairs(splendidGoods) do
|
||
for _, value in ipairs(raffle.damnedGoodsIds) do
|
||
if goodsId == value then
|
||
goto continue
|
||
end
|
||
end
|
||
table.insert( notExistSuitGoods , goodsId )
|
||
::continue::
|
||
end
|
||
end
|
||
|
||
--到这里如果还没套间,则全部随机
|
||
if not next(notExistSuitGoods) then
|
||
for _, goodsId in ipairs(splendidGoods) do
|
||
table.insert( notExistSuitGoods , goodsId )
|
||
end
|
||
end
|
||
|
||
--组装随机资源参数
|
||
local randomGoodsMap = {}
|
||
|
||
--是否是单抽
|
||
if lotteryTimes ==1 then
|
||
|
||
--是否出保底
|
||
if raffle.designCount+1 >= tonumber(cfgSValue.splendidRaffleSingle) then
|
||
|
||
--随机一个套间道具
|
||
table.insert(outPutGoods,notExistSuitGoods[math.random(1,#notExistSuitGoods)])
|
||
else
|
||
|
||
randomGoodsMap = {
|
||
[math.floor(tonumber(cfgSValue.splendidRaffleRatio[1])*100)] = notExistSuitGoods,
|
||
[math.floor(tonumber(cfgSValue.splendidRaffleRatio[2])*100)] = rareGoods,
|
||
[math.floor(tonumber(cfgSValue.splendidRaffleRatio[3])*100)] = specialGoods,
|
||
[math.floor(tonumber(cfgSValue.splendidRaffleRatio[4])*100)] = commonGoods,
|
||
}
|
||
|
||
--随机一个套间道具
|
||
outPutGoods = self:LotteryGoods(player, randomGoodsMap , lotteryTimes )
|
||
raffle.designCount = raffle.designCount +1
|
||
end
|
||
|
||
--判断是否出套间id
|
||
for _, goodsId1 in ipairs(outPutGoods) do
|
||
for _, goodsId2 in ipairs(notExistSuitGoods) do
|
||
if goodsId1 == goodsId2 then
|
||
raffle.designCount = 0
|
||
table.insert( raffle.damnedGoodsIds , goodsId1 )
|
||
break
|
||
end
|
||
end
|
||
end
|
||
|
||
--添加累计单抽
|
||
raffle.totalDesignCount=raffle.totalDesignCount +1
|
||
--十连抽
|
||
else
|
||
|
||
randomGoodsMap = {
|
||
[math.floor(tonumber(cfgSValue.splendidRaffleRatio[2])*100)] = rareGoods,
|
||
[math.floor(tonumber(cfgSValue.splendidRaffleRatio[3])*100)] = specialGoods,
|
||
[math.floor(tonumber(cfgSValue.splendidRaffleRatio[4])*100)] = commonGoods,
|
||
}
|
||
|
||
--先随机
|
||
outPutGoods = self:LotteryGoods(player, randomGoodsMap , lotteryTimes )
|
||
|
||
--不凡家具个数
|
||
local rareNum =1
|
||
|
||
-- if (raffle.totalTimeTenNum+1)%cfgSValue.hiddenRafflePositive[1]==0 then
|
||
-- rareNum=cfgSValue.hiddenRafflePositive[2]
|
||
-- end
|
||
|
||
--已经随机过的位置
|
||
local posList ={}
|
||
for i = 1, rareNum, 1 do
|
||
|
||
::continue::--重新随机位置
|
||
local pos = math.random(1,#outPutGoods)
|
||
|
||
--判断是否随机过
|
||
for _, value in ipairs(posList) do
|
||
if pos == value then
|
||
goto continue
|
||
end
|
||
end
|
||
|
||
--添加随机位置
|
||
table.insert( posList , pos )
|
||
|
||
--随机罕见道具
|
||
local goodsId = notExistSuitGoods[math.random(1,#notExistSuitGoods)]
|
||
|
||
--随机套间id
|
||
outPutGoods[pos]=goodsId
|
||
|
||
--删除已经得到过的罕见道具
|
||
for i = 1, #notExistSuitGoods, 1 do
|
||
if notExistSuitGoods[i] == goodsId then
|
||
table.remove( notExistSuitGoods , i )
|
||
break
|
||
end
|
||
end
|
||
|
||
--添加到已产出的套间
|
||
table.insert( raffle.damnedGoodsIds , goodsId )
|
||
|
||
--套间是否已经全部获得
|
||
if #raffle.damnedGoodsIds == #splendidGoods or not next(notExistSuitGoods) then
|
||
raffle.damnedGoodsIds={}
|
||
notExistSuitGoods=splendidGoods
|
||
end
|
||
end
|
||
|
||
--第一次触发礼包
|
||
if raffle.totalTimeTenNum == 0 then
|
||
skynet.server.store:TriggerPackMultiDraw(player,cfgRaffle)
|
||
end
|
||
|
||
--添加次数
|
||
raffle.totalTimeTenNum=raffle.totalTimeTenNum+1
|
||
end
|
||
|
||
--套间是否已经全部获得
|
||
if #raffle.damnedGoodsIds == #splendidGoods then
|
||
raffle.damnedGoodsIds={}
|
||
end
|
||
end
|
||
|
||
--发放奖励
|
||
for _, goodsId in pairs( outPutGoods ) do
|
||
local isNewGoods = not skynet.server.illustration:IsExistGoods( player , goodsType , goodsId ) --不存在就是新的
|
||
log.debug(string.format("玩家 %d 设计间 发放奖励 商品类型 %d 商品ID %d 商品数量 %d", player.userId , goodsType , goodsId , 1 ))
|
||
skynet.server.bag:AddGoods( player , dataType.GoodsType_Furniture , goodsId , 1 )
|
||
table.insert( data.rewards ,{ item = {goodsType=goodsType,goodsId=goodsId,goodsCount=1} , isNew = isNewGoods } )
|
||
|
||
--成就任务处理
|
||
local cfgFurniture = skynet.server.gameConfig:GetPlayerCurCfg( player , "Furniture" , goodsId )
|
||
if cfgFurniture.quality ~= 3 then
|
||
skynet.server.achieveTask:Modify( player , 60 , 1) --未获取到罕见家具
|
||
skynet.server.taskListEvent:Modify( player , 60 , 1) --未获取到罕见家具
|
||
end
|
||
end
|
||
|
||
--红点
|
||
if cfgRaffle.raffleType == self.LotteryType_1 and not self:CheckFreeDesign(player,self.LotteryType_1) then
|
||
skynet.server.msgTips:ReduceAll(player , 34)
|
||
end
|
||
if cfgRaffle.raffleType == self.LotteryType_2 and not self:CheckFreeDesign(player,self.LotteryType_2) then
|
||
skynet.server.msgTips:ReduceAll(player , 31)
|
||
end
|
||
|
||
--红点处理
|
||
if self:CheckTimeAward(player) then
|
||
skynet.server.msgTips:Add(player , 68)
|
||
end
|
||
|
||
--任务
|
||
skynet.server.levelTask:Modify( player , 37 , lotteryTimes )
|
||
skynet.server.achieveTask:Modify( player , 37 , lotteryTimes)
|
||
skynet.server.taskListEvent:Modify( player , 37 , lotteryTimes)
|
||
|
||
data.designCurrency=self:GetTicket(player)
|
||
data.highCount=self:GetTicketNum(player,self.TicketType_2)
|
||
data.timeCount=self:GetTicketNum(player,self.TicketType_3)
|
||
|
||
--是否可以分享
|
||
if 0 == player.gameData.todayGain.designShare then
|
||
data.canShare = true
|
||
else
|
||
data.canShare = false
|
||
end
|
||
data.isFree=isFree
|
||
|
||
local cData={}
|
||
local sData={}
|
||
local rData={}
|
||
local spDta={}
|
||
for _, value in ipairs(outPutGoods) do
|
||
for _, value1 in ipairs(commonGoods) do
|
||
if value==value1 then
|
||
table.insert(cData,value)
|
||
goto continue
|
||
end
|
||
end
|
||
for _, value1 in ipairs(specialGoods) do
|
||
if value==value1 then
|
||
table.insert(sData,value)
|
||
goto continue
|
||
end
|
||
end
|
||
|
||
for _, value1 in ipairs(rareGoods) do
|
||
if value==value1 then
|
||
table.insert(rData,value)
|
||
goto continue
|
||
end
|
||
end
|
||
|
||
for _, value1 in ipairs(splendidGoods) do
|
||
if value==value1 then
|
||
table.insert(spDta,value)
|
||
goto continue
|
||
end
|
||
end
|
||
::continue::
|
||
end
|
||
s2cData.data = assert(pb.encode("S2CDesignLottery", data))
|
||
end
|
||
|
||
--获取保底次数
|
||
function Raffle:GetTicketNum(player,lotteryType)
|
||
|
||
--获取对应卡池配置信息
|
||
local cfgRaffle = self:GetCfgRaffleByRaffleType( player , {lotteryType} )
|
||
if cfgRaffle== nil then
|
||
cfgRaffle = self:GetCfgRaffleByRaffleType( player , {self.LotteryType_4} )
|
||
if cfgRaffle == nil then
|
||
return 0
|
||
end
|
||
end
|
||
|
||
--设计次数
|
||
local designCount = player.gameData.RaffleMap[cfgRaffle.id].designCount
|
||
|
||
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
|
||
|
||
if cfgRaffle.raffleType == self.LotteryType_2 then
|
||
|
||
--距离高级卡池保底次数
|
||
return tonumber(cfgSValue.limitRaffleRareNewGua)- designCount
|
||
|
||
elseif cfgRaffle.raffleType == self.LotteryType_3 then
|
||
return tonumber(cfgSValue.voluteRaffleRareNewGua) - designCount
|
||
elseif cfgRaffle.raffleType == self.LotteryType_4 then
|
||
return tonumber(cfgSValue.splendidRaffleSingle) - designCount
|
||
end
|
||
|
||
return 0
|
||
end
|
||
|
||
--设计分享
|
||
function Raffle:Share( player , c2sData , s2cData )
|
||
c2sData.data = assert(pb.decode("C2SDesignShare", c2sData.data ))
|
||
local data = {}
|
||
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
|
||
local haveReward = false
|
||
if 0 == player.gameData.todayGain.designShare then
|
||
|
||
--本日未分享 发放对应奖励并修改相关数据
|
||
player.gameData.todayGain.designShare = 1
|
||
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_24")
|
||
player:MoneyChange( cfgSValue.shareReward[1] , cfgSValue.shareReward[2] , eventId)
|
||
haveReward = true
|
||
end
|
||
data.designShare = player.gameData.todayGain.designShare
|
||
data.haveReward = haveReward
|
||
s2cData.cmd = pb.enum("MsgType","CMD_S2C_DesignShare")
|
||
s2cData.data = assert(pb.encode("S2CDesignShare", data))
|
||
end
|
||
|
||
--限时累计卡池奖励界面显示
|
||
function Raffle:TimeAwardShow( player , c2sData , s2cData )
|
||
c2sData.data = assert(pb.decode("C2SDesignTimeAwardShow", c2sData.data ))
|
||
local data = {}
|
||
data.timeAwardInfos = {}
|
||
|
||
--获取对应卡池信息
|
||
local cfgRaffle = self:GetCfgRaffleByRaffleType( player , {self.LotteryType_3,self.LotteryType_4} )
|
||
if cfgRaffle== nil or cfgRaffle.signReward == nil or not next(cfgRaffle.signReward) or cfgRaffle.raffleNum== nil or not next(cfgRaffle.raffleNum) then
|
||
s2cData.code = errorInfo.ErrorCode.OpFailed
|
||
return
|
||
end
|
||
|
||
--获取活动信息
|
||
local activitys=self:CheckDataAndGetActivity(player)
|
||
|
||
local raffle=player.gameData.RaffleMap[cfgRaffle.id]
|
||
local totalCount =raffle.totalDesignCount+ raffle.totalTimeTenNum*10
|
||
data.designCount = totalCount
|
||
|
||
for index ,num in ipairs(cfgRaffle.raffleNum) do
|
||
|
||
--获取奖励配置
|
||
local rewardInfo = cfgRaffle.numReward[index]
|
||
if rewardInfo == nil then
|
||
s2cData.code=errorInfo.ErrorCode.OpFailed
|
||
return
|
||
end
|
||
|
||
local rewardInfo = skynet.server.common:Split(rewardInfo,"_" )
|
||
rewardInfo[1],rewardInfo[2] = tonumber(rewardInfo[1]),tonumber(rewardInfo[2])
|
||
|
||
local rewardItem = {id = num,status = 0,needDesignCount = num,rewardType = rewardInfo[1],rewardId = 0,optionalRewardIds={}}
|
||
if rewardInfo[1] == self.BoxType_Normal then
|
||
rewardItem.rewardId = rewardInfo[2]
|
||
elseif rewardInfo[1] == self.BoxType_Optional then--自选奖励
|
||
|
||
for _, goodsId in ipairs(cfgRaffle.frameId) do
|
||
if skynet.server.bag:GetGoodsCount(player, dataType.GoodsType_Furniture ,goodsId) > 0 then
|
||
table.insert(rewardItem.optionalRewardIds,goodsId)
|
||
end
|
||
end
|
||
end
|
||
|
||
--是否解锁
|
||
if totalCount >= num then
|
||
rewardItem.status = 1
|
||
end
|
||
|
||
--检查是否已经购买
|
||
for _, numTemp in ipairs(raffle.totalTimeReward) do
|
||
if numTemp == num then
|
||
rewardItem.status = 2
|
||
end
|
||
end
|
||
|
||
table.insert(data.timeAwardInfos,rewardItem)
|
||
end
|
||
|
||
if activitys[self.LotteryType_3] ~=nil then
|
||
data.endTime =activitys[self.LotteryType_3].endTime
|
||
data.startTime = activitys[self.LotteryType_3].startTime
|
||
else
|
||
data.endTime =activitys[self.LotteryType_4].endTime
|
||
data.startTime = activitys[self.LotteryType_4].startTime
|
||
end
|
||
s2cData.cmd = pb.enum("MsgType","CMD_S2C_DesignTimeAwardShow")
|
||
s2cData.data = assert(pb.encode("S2CDesignTimeAwardShow", data))
|
||
end
|
||
|
||
--限时累计卡池奖励获取
|
||
function Raffle:TimeAwardGet( player , c2sData , s2cData )
|
||
c2sData.data = assert(pb.decode("C2SDesignTimeAwardGet", c2sData.data ))
|
||
local data = {}
|
||
local timeAwardId = c2sData.data.timeAwardId --奖励id
|
||
local optionptionalRewardId = c2sData.data.optionptionalRewardId --自选id
|
||
data.timeAwardInfos = {}
|
||
data.conversionInfo = {}
|
||
data.timeAwardId=timeAwardId
|
||
|
||
--获取对应卡池信息
|
||
local cfgRaffle = self:GetCfgRaffleByRaffleType( player , {self.LotteryType_3,self.LotteryType_4} )
|
||
if cfgRaffle== nil or cfgRaffle.signReward == nil or not next(cfgRaffle.signReward) or cfgRaffle.raffleNum== nil or not next(cfgRaffle.raffleNum) then
|
||
s2cData.code = errorInfo.ErrorCode.OpFailed
|
||
return
|
||
end
|
||
|
||
--获取活动信息
|
||
local activitys=self:CheckDataAndGetActivity(player)
|
||
|
||
local raffle=player.gameData.RaffleMap[cfgRaffle.id]
|
||
local totalCount = raffle.totalDesignCount+ raffle.totalTimeTenNum*10
|
||
data.designCount = totalCount
|
||
|
||
for index ,num in ipairs(cfgRaffle.raffleNum) do
|
||
|
||
--获取奖励配置
|
||
local rewardInfo = cfgRaffle.numReward[index]
|
||
if rewardInfo == nil then
|
||
s2cData.code=errorInfo.ErrorCode.OpFailed
|
||
return
|
||
end
|
||
|
||
local rewardInfo = skynet.server.common:Split(rewardInfo,"_" )
|
||
rewardInfo[1],rewardInfo[2] = tonumber(rewardInfo[1]),tonumber(rewardInfo[2])
|
||
|
||
if num == timeAwardId and totalCount >= num then
|
||
|
||
local isBuy =false
|
||
--检查是否已经购买
|
||
for _, numTemp in ipairs(raffle.totalTimeReward) do
|
||
if numTemp == num then
|
||
isBuy = true
|
||
break
|
||
end
|
||
end
|
||
|
||
if not isBuy then
|
||
|
||
--普通奖励
|
||
if rewardInfo[1] == self.BoxType_Normal then --普通
|
||
|
||
--发放对应奖励 并修改相关数据
|
||
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_61")
|
||
|
||
--被转化的奖励
|
||
local conversionInfo = player:GiveReward(rewardInfo[2] , eventId ,1)
|
||
local rewards = skynet.server.playerLand:GetRewardInfo(player , rewardInfo[2])
|
||
data.rewardInfos = rewards
|
||
data.conversionInfo = conversionInfo
|
||
|
||
--判断奖励是否包含头像或头像框
|
||
local haveHead = false
|
||
for k1 , v1 in pairs(rewards) do
|
||
if v1.type == dataType.GoodsType_HeadAndHeadFrame then
|
||
haveHead = true
|
||
break
|
||
end
|
||
end
|
||
if haveHead then
|
||
--主动推送一下玩家个人信息
|
||
local data1 = {}
|
||
data1.newOwn = {}
|
||
for k1 , v1 in pairs(rewards) do
|
||
local cfgHead = skynet.server.gameConfig:GetPlayerCurCfg( player , "Head" , v1.id )
|
||
table.insert(data1.newOwn , {ownType = cfgHead.type , ownId = v1.id})
|
||
end
|
||
skynet.server.gameServer:SendMsgToUser( player.userId , "CMD_S2C_PersonalUpdateOwnInfo" , data1 )
|
||
end
|
||
elseif rewardInfo[1] == self.BoxType_Blind then--盲盒
|
||
--盲盒奖励
|
||
local reward = self:BoxReward(player,cfgRaffle.id)
|
||
for k1 , v1 in pairs(reward) do
|
||
skynet.server.bag:AddGoods( player , dataType.GoodsType_Furniture , v1.id , v1.count )
|
||
end
|
||
data.rewardInfos = reward
|
||
elseif rewardInfo[1] == self.BoxType_Optional then--自选
|
||
|
||
local isExist= false
|
||
--验证配置自选是否存在
|
||
for index, value in ipairs(cfgRaffle.frameId) do
|
||
if value == optionptionalRewardId then
|
||
isExist=true
|
||
end
|
||
end
|
||
if not isExist then
|
||
s2cData.code=errorInfo.ErrorCode.OpFailed
|
||
return
|
||
end
|
||
|
||
--发放对应奖励 并修改相关数据
|
||
skynet.server.bag:AddGoods(player, dataType.GoodsType_Furniture, optionptionalRewardId, 1)
|
||
|
||
--返回奖励信息
|
||
data.rewardInfos = {{ type = dataType.GoodsType_Furniture , id = optionptionalRewardId , count = 1}}
|
||
end
|
||
|
||
table.insert(raffle.totalTimeReward,num)
|
||
skynet.server.msgTips:Reduce(player , 68)
|
||
end
|
||
end
|
||
|
||
--添加返回值
|
||
local rewardItem = {id = num,status = 0,needDesignCount = num,rewardType = rewardInfo[1],rewardId = 0,optionalRewardIds={}}
|
||
if rewardInfo[1] == self.BoxType_Normal then
|
||
rewardItem.rewardId = rewardInfo[2]
|
||
elseif rewardInfo[1] == self.BoxType_Optional then--自选奖励
|
||
|
||
for _, goodsId in ipairs(cfgRaffle.frameId) do
|
||
if skynet.server.bag:GetGoodsCount(player, dataType.GoodsType_Furniture ,goodsId) > 0 then
|
||
table.insert(rewardItem.optionalRewardIds,goodsId)
|
||
end
|
||
end
|
||
end
|
||
|
||
--是否解锁
|
||
if totalCount >= num then
|
||
rewardItem.status = 1
|
||
end
|
||
|
||
--检查是否已经购买
|
||
for _, numTemp in ipairs(raffle.totalTimeReward) do
|
||
if numTemp == num then
|
||
rewardItem.status = 2
|
||
end
|
||
end
|
||
|
||
table.insert(data.timeAwardInfos,rewardItem)
|
||
end
|
||
|
||
--红点处理
|
||
if not self:CheckTimeAward(player) then
|
||
skynet.server.msgTips:ReduceAll(player , 68)
|
||
end
|
||
|
||
if activitys[self.LotteryType_3] ~=nil then
|
||
|
||
data.endTime =activitys[self.LotteryType_3].endTime
|
||
else
|
||
data.endTime =activitys[self.LotteryType_4].endTime
|
||
end
|
||
s2cData.cmd = pb.enum("MsgType","CMD_S2C_DesignTimeAwardGet")
|
||
s2cData.data = assert(pb.encode("S2CDesignTimeAwardGet", data))
|
||
end
|
||
|
||
--高级卡池兑换商店显示
|
||
function Raffle:HighStoreShow( player , c2sData , s2cData )
|
||
c2sData.data = assert(pb.decode("C2SDesignHighStoreShow", c2sData.data ))
|
||
local data = {}
|
||
|
||
--获取对应卡池信息
|
||
local cfgRaffle = self:GetCfgRaffleByRaffleType( player , {self.LotteryType_2} )
|
||
if cfgRaffle== nil then
|
||
s2cData.code = errorInfo.ErrorCode.OpFailed
|
||
return
|
||
end
|
||
|
||
local raffle=player.gameData.RaffleMap[cfgRaffle.id]
|
||
|
||
data.highStorePoints = player.gameData.design.highStorePoints
|
||
data.highStoreInfos = self:GetHighStoreInfo( player , cfgRaffle)
|
||
|
||
s2cData.cmd = pb.enum("MsgType","CMD_S2C_DesignHighStoreShow")
|
||
s2cData.data = assert(pb.encode("S2CDesignHighStoreShow", data))
|
||
end
|
||
|
||
--高级卡池兑换商店兑换
|
||
function Raffle:HighStoreRedeem( player , c2sData , s2cData )
|
||
c2sData.data = assert(pb.decode("C2SDesignHighStoreRedeem", c2sData.data ))
|
||
local data = {}
|
||
local goodsType = c2sData.data.goodsType
|
||
local goodsId = c2sData.data.goodsId
|
||
local redeemCount = c2sData.data.redeemCount
|
||
|
||
--获取对应卡池信息
|
||
local cfgRaffle = self:GetCfgRaffleByRaffleType( player , {self.LotteryType_2} )
|
||
if cfgRaffle== nil then
|
||
s2cData.code = errorInfo.ErrorCode.OpFailed
|
||
return
|
||
end
|
||
|
||
--判断是否拥有
|
||
if dataType.GoodsType_Decorate == goodsType and player:IsBuyGoods(goodsType,goodsId) then
|
||
s2cData.code = errorInfo.ErrorCode.AlreadyExchange
|
||
return
|
||
end
|
||
|
||
local cfgDecoration = skynet.server.gameConfig:GetPlayerAllCfg( player , "Decoration")
|
||
|
||
if dataType.GoodsType_Furniture == goodsType then
|
||
local cfgFurniture = skynet.server.gameConfig:GetPlayerCurCfg( player , "Furniture" , goodsId )
|
||
local needPoints = cfgFurniture.integral * redeemCount --需要的积分
|
||
if player.gameData.design.highStorePoints >= needPoints then
|
||
--积分足够 扣除相应积分 增加对应物品
|
||
player.gameData.design.highStorePoints = player.gameData.design.highStorePoints - needPoints
|
||
skynet.server.bag:AddGoods(player,goodsType,goodsId,redeemCount)
|
||
data.highRedeemPoints = player.gameData.design.highStorePoints
|
||
data.highRedeemInfos = self:GetHighStoreInfo( player ,cfgRaffle)
|
||
data.awards = {type = goodsType,id = goodsId,count = redeemCount}
|
||
else
|
||
s2cData.code = errorInfo.ErrorCode.NoEnoughPoint
|
||
end
|
||
elseif dataType.GoodsType_Decorate == goodsType then
|
||
local needPoints = cfgDecoration[goodsId].integral * redeemCount --需要的积分
|
||
if player.gameData.design.highStorePoints >= needPoints then
|
||
--积分足够 扣除相应积分 增加对应物品
|
||
player.gameData.design.highStorePoints = player.gameData.design.highStorePoints - needPoints
|
||
skynet.server.bag:AddGoods(player,goodsType,goodsId,redeemCount)
|
||
data.highRedeemPoints = player.gameData.design.highStorePoints
|
||
data.highRedeemInfos = self:GetHighStoreInfo( player ,cfgRaffle)
|
||
data.awards = {type = goodsType,id = goodsId,count = redeemCount}
|
||
else
|
||
s2cData.code = errorInfo.ErrorCode.NoEnoughPoint
|
||
end
|
||
end
|
||
s2cData.cmd = pb.enum("MsgType","CMD_S2C_DesignHighStoreRedeem")
|
||
s2cData.data = assert(pb.encode("S2CDesignHighStoreRedeem", data))
|
||
end
|
||
|
||
--限时卡池签到显示
|
||
function Raffle:TimeSignInShow( player , c2sData , s2cData )
|
||
c2sData.data = assert(pb.decode("C2SDesignTimeSignInShow", c2sData.data ))
|
||
local data = {}
|
||
data.timeSignIns = {}
|
||
|
||
--获取对应卡池信息
|
||
local cfgRaffle = self:GetCfgRaffleByRaffleType( player , {self.LotteryType_3,self.LotteryType_4} )
|
||
if cfgRaffle== nil or cfgRaffle.signReward == nil or not next(cfgRaffle.signReward) then
|
||
s2cData.code = errorInfo.ErrorCode.OpFailed
|
||
return
|
||
end
|
||
|
||
local raffle=player.gameData.RaffleMap[cfgRaffle.id]
|
||
|
||
--循环配置
|
||
for index, cfgSignReward in ipairs(cfgRaffle.signReward) do
|
||
|
||
local showData={id=index,status=0,day=index,rewardId=cfgSignReward}
|
||
|
||
--检查是否已经购买
|
||
for _, timeSignIn in ipairs(raffle.timeSignIn) do
|
||
if index == timeSignIn.day then
|
||
showData={id=index,status=timeSignIn.status,day=timeSignIn.day,rewardId=cfgSignReward}
|
||
break
|
||
end
|
||
end
|
||
|
||
table.insert(data.timeSignIns,showData)
|
||
|
||
end
|
||
|
||
s2cData.cmd = pb.enum("MsgType","CMD_S2C_DesignTimeSignInShow")
|
||
s2cData.data = assert(pb.encode("S2CDesignTimeSignInShow", data))
|
||
end
|
||
|
||
--限时卡池签到获取
|
||
function Raffle:TimeSignInGet( player , c2sData , s2cData )
|
||
c2sData.data = assert(pb.decode("C2SDesignTimeSignInGet", c2sData.data ))
|
||
local data = {}
|
||
local day = c2sData.data.day
|
||
data.timeSignIns = {}
|
||
local isShowUI = true
|
||
|
||
--获取对应卡池信息
|
||
local cfgRaffle = self:GetCfgRaffleByRaffleType( player , {self.LotteryType_3,self.LotteryType_4} )
|
||
if cfgRaffle== nil or cfgRaffle.signReward == nil or not next(cfgRaffle.signReward) then
|
||
s2cData.code = errorInfo.ErrorCode.OpFailed
|
||
return
|
||
end
|
||
|
||
local raffle=player.gameData.RaffleMap[cfgRaffle.id]
|
||
|
||
--循环配置
|
||
for index, cfgSignReward in ipairs(cfgRaffle.signReward) do
|
||
|
||
--是否是购买礼包天数
|
||
if index == day then
|
||
|
||
--检查是否已经购买
|
||
for _, timeSignIn in ipairs(raffle.timeSignIn) do
|
||
|
||
--不是改礼包
|
||
if index ~= timeSignIn.day then
|
||
goto continue1
|
||
end
|
||
|
||
--是否可领取
|
||
if timeSignIn.status ~= 1 then
|
||
goto continue1
|
||
end
|
||
|
||
--发奖
|
||
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_62")
|
||
player:GiveReward(cfgSignReward , eventId , 1)
|
||
data.rewardId = cfgSignReward
|
||
timeSignIn.status = 2
|
||
break
|
||
::continue1::
|
||
end
|
||
end
|
||
|
||
local showData={id=index,status=0,day=index,rewardId=cfgSignReward}
|
||
|
||
--检查是否已经购买
|
||
for _, timeSignIn in ipairs(raffle.timeSignIn) do
|
||
if index == timeSignIn.day then
|
||
showData={id=index,status=timeSignIn.status,day=timeSignIn.day,rewardId=cfgSignReward}
|
||
break
|
||
end
|
||
end
|
||
|
||
-- if not isShowUI and showData.status ~= 2 then
|
||
-- isShowUI =true
|
||
-- end
|
||
table.insert(data.timeSignIns,showData)
|
||
end
|
||
|
||
if not self:CheckSignIn(player) then
|
||
skynet.server.msgTips:ReduceAll(player , 69)
|
||
end
|
||
|
||
--领取做一个标记,特殊处理
|
||
raffle.isGetSign = true
|
||
|
||
data.isShowUI = isShowUI
|
||
s2cData.cmd = pb.enum("MsgType","CMD_S2C_DesignTimeSignInGet")
|
||
s2cData.data = assert(pb.encode("S2CDesignTimeSignInGet", data))
|
||
end
|
||
|
||
--设计概览
|
||
function Raffle:OverviewShow( player , c2sData ,s2cData )
|
||
c2sData.data = assert(pb.decode("C2SDesignOverviewShow", c2sData.data ))
|
||
local data = {}
|
||
data.overviewInfos = {}
|
||
local designType = c2sData.data.designType
|
||
|
||
--获取对应卡池信息
|
||
local cfgRaffle = self:GetCfgRaffleByRaffleType( player , {designType} )
|
||
if cfgRaffle== nil then
|
||
cfgRaffle = self:GetCfgRaffleByRaffleType( player , {self.LotteryType_4} )
|
||
if cfgRaffle==nil then
|
||
log.debug("设计空间预览 未找到开启的活动,designType:",designType)
|
||
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
|
||
return
|
||
end
|
||
end
|
||
|
||
data.overviewInfos = self:GetGoodsInfo( player , cfgRaffle)
|
||
s2cData.cmd = pb.enum("MsgType","CMD_S2C_DesignOverviewShow")
|
||
s2cData.data = assert(pb.encode("S2CDesignOverviewShow", data))
|
||
end
|
||
|
||
--盲盒随机奖励
|
||
function Raffle:BoxReward( player , raffleId )
|
||
local cfgRaffle = skynet.server.gameConfig:GetPlayerCurCfg( player , "Raffle" , raffleId )
|
||
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue" )
|
||
local rewards = {}
|
||
local frameId = cfgRaffle.frameId --所有可以进行随机的家具id
|
||
local raffleBlindBoxReward = cfgSValue.raffleBlindBoxReward --设计奖励盲盒开启的已拥有套间家具与未拥有套间家具的占比
|
||
local haveFur = {} --拥有的家具id集合
|
||
local notFur = {} --未拥有的家具id集合
|
||
for k , v in pairs(frameId) do
|
||
local have = skynet.server.illustration:IsExistGoods( player , dataType.GoodsType_Furniture , v ) --是否拥有
|
||
if have then
|
||
table.insert(haveFur , v)
|
||
else
|
||
table.insert(notFur , v)
|
||
end
|
||
end
|
||
--没有未拥有的家具 则不用看中间值了
|
||
if #notFur == 0 then
|
||
local count = math.random(1 , #haveFur)
|
||
table.insert(rewards ,{ type = dataType.GoodsType_Furniture , id = haveFur[count] , count = 1})
|
||
else
|
||
--依照比例确定本次盲盒奖励是拥有还是未拥有
|
||
local count = math.random(1 , 10)
|
||
if count <= 10 * raffleBlindBoxReward and next(haveFur) then
|
||
local count1 = math.random(1 , #haveFur)
|
||
table.insert(rewards ,{ type = dataType.GoodsType_Furniture , id = haveFur[count1] , count = 1})
|
||
else
|
||
local count1 = math.random(1 , #notFur)
|
||
table.insert(rewards ,{ type = dataType.GoodsType_Furniture , id = notFur[count1] , count = 1})
|
||
end
|
||
end
|
||
return rewards
|
||
end
|
||
|
||
--获取该玩家高级卡池兑换商店物品的信息
|
||
function Raffle:GetHighStoreInfo( player,cfgRaffle )
|
||
local cfgFurniture = skynet.server.gameConfig:GetPlayerAllCfg( player , "Furniture")
|
||
--存储兑换物品相关信息
|
||
local highStoreInfos = {}
|
||
--普通家具
|
||
for k ,v in pairs(cfgRaffle.ordinaryFurId) do
|
||
local have = player:IsBuyGoods(dataType.GoodsType_Furniture,v) --是否拥有
|
||
local needPoints = skynet.server.gameConfig:GetPlayerCurCfg( player , "Furniture" , v).integral --需要的积分
|
||
table.insert(highStoreInfos , {goodsId=v , goodsType=dataType.GoodsType_Furniture,needPoints = needPoints,status = have,suitId = 0})
|
||
end
|
||
-- --普通装修
|
||
-- for k ,v in pairs(cfgRaffle.ordinaryDecId) do
|
||
-- local have = player:IsBuyGoods(dataType.GoodsType_Decorate,v) --是否拥有
|
||
-- local needPoints = skynet.server.gameConfig:GetPlayerCurCfg( player , "Decoration" , v).integral --需要的积分
|
||
-- table.insert(highStoreInfos , {goodsId=v , goodsType=dataType.GoodsType_Decorate,needPoints=needPoints,status=have,suitId = 0})
|
||
-- end
|
||
--稀有家具
|
||
for k ,v in pairs(cfgRaffle.rarityFurId) do
|
||
local have = player:IsBuyGoods(dataType.GoodsType_Furniture,v) --是否拥有
|
||
local needPoints = skynet.server.gameConfig:GetPlayerCurCfg( player , "Furniture" , v).integral --需要的积分
|
||
table.insert(highStoreInfos , {goodsId=v , goodsType=dataType.GoodsType_Furniture,needPoints=needPoints,status=have,suitId = 0})
|
||
end
|
||
-- --稀有装修
|
||
-- for k ,v in pairs(cfgRaffle.rarityDecId) do
|
||
-- local have = player:IsBuyGoods(dataType.GoodsType_Decorate,v) --是否拥有
|
||
-- local needPoints = skynet.server.gameConfig:GetPlayerCurCfg( player , "Decoration" , v).integral --需要的积分
|
||
-- table.insert(highStoreInfos , {goodsId=v , goodsType=dataType.GoodsType_Decorate,needPoints=needPoints,status=have,suitId = 0})
|
||
-- end
|
||
--罕见家具
|
||
for k ,v in pairs(cfgRaffle.rareFurId) do
|
||
local have = player:IsBuyGoods(dataType.GoodsType_Furniture,v) --是否拥有
|
||
local needPoints = skynet.server.gameConfig:GetPlayerCurCfg( player , "Furniture" , v).integral --需要的积分
|
||
table.insert(highStoreInfos , {goodsId=v , goodsType=dataType.GoodsType_Furniture,needPoints=needPoints,status=have,suitId = 0})
|
||
end
|
||
-- --罕见装修
|
||
-- for k ,v in pairs(cfgRaffle.rareDecId) do
|
||
-- local have = player:IsBuyGoods(dataType.GoodsType_Decorate,v) --是否拥有
|
||
-- local needPoints = skynet.server.gameConfig:GetPlayerCurCfg( player , "Decoration" , v).integral --需要的积分
|
||
-- table.insert(highStoreInfos , {goodsId=v , goodsType=dataType.GoodsType_Decorate,needPoints=needPoints,status=have,suitId = 0})
|
||
-- end
|
||
|
||
--新增装修
|
||
for k ,v in pairs(cfgRaffle.decoRedeem) do
|
||
local have = player:IsBuyGoods(dataType.GoodsType_Decorate,v) --是否拥有
|
||
local needPoints = skynet.server.gameConfig:GetPlayerCurCfg( player , "Decoration" , v).integral --需要的积分
|
||
table.insert(highStoreInfos , {goodsId=v , goodsType=dataType.GoodsType_Decorate,needPoints=needPoints,status=have,suitId = 0})
|
||
end
|
||
|
||
--套装物品
|
||
for k1, v1 in pairs( cfgFurniture ) do
|
||
if cfgRaffle.suitId == v1.suitType then
|
||
local have = player:IsBuyGoods(dataType.GoodsType_Furniture,v1.id) --是否拥有
|
||
local needPoints = v1.integral --需要的积分
|
||
table.insert(highStoreInfos , {goodsId=v1.id , goodsType=dataType.GoodsType_Furniture,needPoints=needPoints,status=have,suitId = cfgRaffle.suitId})
|
||
end
|
||
end
|
||
return highStoreInfos
|
||
end
|
||
|
||
--获取该玩家对应卡池的物品相关信息
|
||
function Raffle:GetGoodsInfo( player , cfgRaffle)
|
||
local cfgFurniture = skynet.server.gameConfig:GetPlayerAllCfg( player , "Furniture")
|
||
local cfgDecoration = skynet.server.gameConfig:GetPlayerAllCfg( player , "Decoration")
|
||
|
||
--存储兑换物品相关信息
|
||
local overviewInfos = {}
|
||
for k ,v in pairs(cfgRaffle.ordinaryFurId) do
|
||
local have = player:IsBuyGoods(dataType.GoodsType_Furniture,v) --是否拥有
|
||
if have then
|
||
table.insert(overviewInfos , {goodsId = v , goodsType = dataType.GoodsType_Furniture})
|
||
end
|
||
end
|
||
-- --普通装修
|
||
-- for k ,v in pairs(cfgRaffle.ordinaryDecId) do
|
||
-- local have = player:IsBuyGoods(dataType.GoodsType_Decorate,v) --是否拥有
|
||
-- if have then
|
||
-- table.insert(overviewInfos , {goodsId = v , goodsType = dataType.GoodsType_Decorate})
|
||
-- end
|
||
-- end
|
||
--稀有家具
|
||
for k ,v in pairs(cfgRaffle.rarityFurId) do
|
||
local have = player:IsBuyGoods(dataType.GoodsType_Furniture,v) --是否拥有
|
||
if have then
|
||
table.insert(overviewInfos , {goodsId = v , goodsType = dataType.GoodsType_Furniture})
|
||
end
|
||
end
|
||
-- --稀有装修
|
||
-- for k ,v in pairs(cfgRaffle.rarityDecId) do
|
||
-- local have = player:IsBuyGoods(dataType.GoodsType_Decorate,v) --是否拥有
|
||
-- if have then
|
||
-- table.insert(overviewInfos , {goodsId = v , goodsType = dataType.GoodsType_Decorate})
|
||
-- end
|
||
-- end
|
||
--罕见家具
|
||
for k ,v in pairs(cfgRaffle.rareFurId) do
|
||
local have = player:IsBuyGoods(dataType.GoodsType_Furniture,v) --是否拥有
|
||
if have then
|
||
table.insert(overviewInfos , {goodsId = v , goodsType = dataType.GoodsType_Furniture})
|
||
end
|
||
end
|
||
-- --罕见装修
|
||
-- for k ,v in pairs(cfgRaffle.rareDecId) do
|
||
-- local have = player:IsBuyGoods(dataType.GoodsType_Decorate,v) --是否拥有
|
||
-- if have then
|
||
-- table.insert(overviewInfos , {goodsId = v , goodsType = dataType.GoodsType_Decorate})
|
||
-- end
|
||
-- end
|
||
--新增装修字段
|
||
for k ,v in pairs(cfgRaffle.decoRedeem) do
|
||
local have = player:IsBuyGoods(dataType.GoodsType_Decorate,v) --是否拥有
|
||
if have then
|
||
table.insert(overviewInfos , {goodsId = v , goodsType = dataType.GoodsType_Decorate})
|
||
end
|
||
end
|
||
|
||
--套装物品
|
||
for k1, v1 in pairs( cfgFurniture ) do
|
||
if cfgRaffle.suitId == v1.suitType then
|
||
local have = player:IsBuyGoods(dataType.GoodsType_Furniture,v1.id) --是否拥有
|
||
if have then
|
||
table.insert(overviewInfos , {goodsId = v1.id , goodsType = dataType.GoodsType_Furniture})
|
||
end
|
||
end
|
||
end
|
||
for k1, v1 in pairs( cfgDecoration ) do
|
||
if cfgRaffle.suitId == v1.suitType then
|
||
local have = player:IsBuyGoods(dataType.GoodsType_Decorate,v1.id) --是否拥有
|
||
if have then
|
||
table.insert(overviewInfos , {goodsId = v1.id , goodsType = dataType.GoodsType_Decorate})
|
||
end
|
||
end
|
||
end
|
||
return overviewInfos
|
||
end
|
||
|
||
--获取灵感碎片信息
|
||
function Raffle:TimeFragmentShow( player, c2sData ,s2cData )
|
||
c2sData.data = assert(pb.decode("C2SDesignTimeFragmentShow", c2sData.data ))
|
||
s2cData.cmd = pb.enum("MsgType","CMD_S2C_DesignTimeFragmentShow")
|
||
local data = {}
|
||
|
||
--获取对应卡池信息
|
||
local cfgRaffle = self:GetCfgRaffleByRaffleType( player , {self.LotteryType_3,self.LotteryType_4} )
|
||
if cfgRaffle== nil or cfgRaffle.signReward == nil or not next(cfgRaffle.signReward) then
|
||
s2cData.code = errorInfo.ErrorCode.OpFailed
|
||
return
|
||
end
|
||
|
||
--获取碎片配置信息
|
||
local cfgRaffleFragment = skynet.server.gameConfig:GetPlayerCurCfg( player , "RaffleFragment",cfgRaffle.fragmentId)
|
||
|
||
--灵感碎片
|
||
data.fragmentNum=player.gameData.design.fragmentNum
|
||
|
||
if cfgRaffleFragment==nil then
|
||
s2cData.code = errorInfo.ErrorCode.OpFailed
|
||
return
|
||
end
|
||
|
||
--兑换家具
|
||
data.goodsIds={}
|
||
for _, furniture in ipairs(cfgRaffleFragment.redeemFurniture) do
|
||
|
||
--判断道具是存在
|
||
if skynet.server.bag:GetGoodsCount( player , dataType.GoodsType_Furniture , furniture) > 0 then
|
||
table.insert(data.goodsIds,furniture)
|
||
end
|
||
end
|
||
|
||
--转换家具
|
||
data.transitions={}
|
||
|
||
--判断家具是否在使用
|
||
local notUseGoodss=skynet.server.bag:GetUnusedGoodsInfo( player , dataType.GoodsType_Furniture )
|
||
for _, furniture in ipairs(self:SortTransition(player,cfgRaffleFragment.transferFurniture)) do
|
||
|
||
--判断道具是存在
|
||
local goodsNum=skynet.server.bag:GetGoodsCount( player , dataType.GoodsType_Furniture , furniture)
|
||
if goodsNum> 0 then
|
||
|
||
--是否可以转换
|
||
local isUse=false
|
||
for _, goodsItem in ipairs(notUseGoodss) do
|
||
if goodsItem.id == furniture then
|
||
goodsNum=goodsItem.count--设置可用家具数量
|
||
isUse =true
|
||
break
|
||
end
|
||
end
|
||
|
||
--是否正在使用
|
||
if isUse then
|
||
table.insert(data.transitions,{goodsId=furniture,goodsNum=goodsNum})
|
||
end
|
||
end
|
||
end
|
||
|
||
s2cData.data = assert(pb.encode("S2CDesignTimeFragmentShow", data))
|
||
end
|
||
|
||
--灵感碎片兑换信息
|
||
function Raffle:TimeFragmentExchange( player, c2sData ,s2cData )
|
||
c2sData.data = assert(pb.decode("C2SDesignTimeFragmentExchange", c2sData.data ))
|
||
s2cData.cmd = pb.enum("MsgType","CMD_S2C_DesignTimeFragmentExchange")
|
||
local goodsId=c2sData.data.goodsId
|
||
local goodsNum=c2sData.data.goodsNum
|
||
local data = {}
|
||
data.goodsId=goodsId
|
||
data.goodsNum=goodsNum
|
||
|
||
--获取对应卡池信息
|
||
local cfgRaffle = self:GetCfgRaffleByRaffleType( player , {self.LotteryType_3,self.LotteryType_4} )
|
||
if cfgRaffle== nil or cfgRaffle.signReward == nil or not next(cfgRaffle.signReward) then
|
||
s2cData.code = errorInfo.ErrorCode.OpFailed
|
||
return
|
||
end
|
||
|
||
--获取碎片配置信息
|
||
local cfgRaffleFragment = skynet.server.gameConfig:GetPlayerCurCfg( player , "RaffleFragment",cfgRaffle.fragmentId)
|
||
|
||
local isExist=false
|
||
--兑换道具是否存在
|
||
for _, value in ipairs(cfgRaffleFragment.redeemFurniture) do
|
||
if value==goodsId then
|
||
isExist=true
|
||
break
|
||
end
|
||
end
|
||
|
||
if not isExist then
|
||
s2cData.code = errorInfo.ErrorCode.OpFailed
|
||
log.debug("灵感碎片兑换道具不存在",goodsId)
|
||
return
|
||
end
|
||
|
||
--获取道具配置
|
||
local cfgFurniture = skynet.server.gameConfig:GetPlayerCurCfg( player , "Furniture",goodsId)
|
||
|
||
--检查配置是否有误
|
||
if cfgFurniture.fragmentNum==0 then
|
||
s2cData.code = errorInfo.ErrorCode.OpFailed
|
||
log.debug("道具配置有误,灵感积分配置为0",goodsId)
|
||
return
|
||
end
|
||
|
||
--灵感碎片是足够
|
||
if player.gameData.design.fragmentNum == nil then
|
||
player.gameData.design.fragmentNum = 0
|
||
end
|
||
|
||
if player.gameData.design.fragmentNum<cfgFurniture.fragmentNum*goodsNum then
|
||
s2cData.code = errorInfo.ErrorCode.OpFailed
|
||
log.debug("灵感碎片不足",goodsId)
|
||
return
|
||
end
|
||
|
||
--扣除灵感碎片
|
||
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_135")
|
||
player:MoneyChange( dataType.GoodsType_Fragment , -(cfgFurniture.fragmentNum*goodsNum) , eventId)
|
||
|
||
--添加家具
|
||
skynet.server.bag:AddGoods(player, dataType.GoodsType_Furniture, goodsId, goodsNum)
|
||
|
||
--灵感碎片
|
||
data.fragmentNum=player.gameData.design.fragmentNum
|
||
|
||
--兑换家具
|
||
data.goodsIds={}
|
||
for _, furniture in ipairs(cfgRaffleFragment.redeemFurniture) do
|
||
|
||
--判断道具是存在
|
||
if skynet.server.bag:GetGoodsCount( player , dataType.GoodsType_Furniture , furniture) > 0 then
|
||
table.insert(data.goodsIds,furniture)
|
||
end
|
||
end
|
||
|
||
--转换家具
|
||
data.transitions={}
|
||
|
||
--判断家具是否在使用
|
||
local notUseGoodss=skynet.server.bag:GetUnusedGoodsInfo( player , dataType.GoodsType_Furniture )
|
||
for _, furniture in ipairs(self:SortTransition(player,cfgRaffleFragment.transferFurniture)) do
|
||
|
||
--判断道具是存在
|
||
local goodsNum=skynet.server.bag:GetGoodsCount( player , dataType.GoodsType_Furniture , furniture)
|
||
if goodsNum> 0 then
|
||
|
||
--是否可以转换
|
||
local isUse=false
|
||
for _, goodsItem in ipairs(notUseGoodss) do
|
||
if goodsItem.id == furniture then
|
||
goodsNum=goodsItem.count--设置可用家具数量
|
||
isUse =true
|
||
break
|
||
end
|
||
end
|
||
|
||
--是否正在使用
|
||
if isUse then
|
||
table.insert(data.transitions,{goodsId=furniture,goodsNum=goodsNum})
|
||
end
|
||
end
|
||
end
|
||
|
||
s2cData.data = assert(pb.encode("S2CDesignTimeFragmentExchange", data))
|
||
end
|
||
|
||
--灵感碎片转换信息
|
||
function Raffle:TimeFragmentTransition( player, c2sData ,s2cData )
|
||
c2sData.data = assert(pb.decode("C2SDesignTimeFragmentTransition", c2sData.data ))
|
||
s2cData.cmd = pb.enum("MsgType","CMD_S2C_DesignTimeFragmentTransition")
|
||
local goodsId=c2sData.data.goodsId
|
||
local goodsNum=c2sData.data.goodsNum
|
||
local data = {}
|
||
|
||
--获取对应卡池信息
|
||
local cfgRaffle = self:GetCfgRaffleByRaffleType( player , {self.LotteryType_3,self.LotteryType_4} )
|
||
if cfgRaffle== nil or cfgRaffle.signReward == nil or not next(cfgRaffle.signReward) then
|
||
s2cData.code = errorInfo.ErrorCode.OpFailed
|
||
return
|
||
end
|
||
|
||
--获取碎片配置信息
|
||
local cfgRaffleFragment = skynet.server.gameConfig:GetPlayerCurCfg( player , "RaffleFragment",cfgRaffle.fragmentId)
|
||
|
||
local isExist=false
|
||
--兑换道具是否存在
|
||
for _, value in ipairs(self:SortTransition(player,cfgRaffleFragment.transferFurniture)) do
|
||
if value==goodsId then
|
||
isExist=true
|
||
break
|
||
end
|
||
end
|
||
|
||
if not isExist then
|
||
s2cData.code = errorInfo.ErrorCode.OpFailed
|
||
log.debug("灵感碎片兑换道具不存在",goodsId)
|
||
return
|
||
end
|
||
|
||
--获取道具配置
|
||
local cfgFurniture = skynet.server.gameConfig:GetPlayerCurCfg( player , "Furniture",goodsId)
|
||
|
||
--检查配置是否有误
|
||
if cfgFurniture.fragmentNum==0 then
|
||
s2cData.code = errorInfo.ErrorCode.OpFailed
|
||
log.debug("道具配置有误,灵感积分配置为0",goodsId)
|
||
return
|
||
end
|
||
|
||
--判断道具是否足够
|
||
if skynet.server.bag:GetGoodsCount( player , dataType.GoodsType_Furniture , goodsId) < goodsNum then
|
||
s2cData.code = errorInfo.ErrorCode.OpFailed
|
||
log.debug("转换家具不足",goodsId)
|
||
return
|
||
end
|
||
|
||
--判断家具是否在使用
|
||
local notUseGoodss=skynet.server.bag:GetUnusedGoodsInfo( player , dataType.GoodsType_Furniture )
|
||
|
||
--是否可以转换
|
||
local isUse=false
|
||
for _, goodsItem in ipairs(notUseGoodss) do
|
||
if goodsItem.id == goodsId and goodsItem.count >= goodsNum then
|
||
isUse =true
|
||
break
|
||
end
|
||
end
|
||
|
||
--是否正在使用
|
||
if not isUse then
|
||
s2cData.code = errorInfo.ErrorCode.PropUsing
|
||
return
|
||
end
|
||
|
||
--扣除家具
|
||
skynet.server.bag:RemoveGoods(player, dataType.GoodsType_Furniture, goodsId, goodsNum)
|
||
|
||
--添加积分
|
||
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_136")
|
||
player:MoneyChange( dataType.GoodsType_Fragment , cfgFurniture.fragmentNum*goodsNum , eventId)
|
||
|
||
--灵感碎片
|
||
data.fragmentNum=player.gameData.design.fragmentNum
|
||
|
||
--兑换家具
|
||
data.goodsIds={}
|
||
for _, furniture in ipairs(cfgRaffleFragment.redeemFurniture) do
|
||
|
||
--判断道具是存在
|
||
if skynet.server.bag:GetGoodsCount( player , dataType.GoodsType_Furniture , furniture) > 0 then
|
||
table.insert(data.goodsIds,furniture)
|
||
end
|
||
end
|
||
|
||
--转换家具
|
||
data.transitions={}
|
||
|
||
for _, furniture in ipairs(self:SortTransition(player,cfgRaffleFragment.transferFurniture)) do
|
||
|
||
--判断道具是存在
|
||
local goodsNum=skynet.server.bag:GetGoodsCount( player , dataType.GoodsType_Furniture , furniture)
|
||
if goodsNum> 0 then
|
||
|
||
--是否可以转换
|
||
local isUse=false
|
||
for _, goodsItem in ipairs(notUseGoodss) do
|
||
if goodsItem.id == furniture then
|
||
goodsNum=goodsItem.count--设置可用家具数量
|
||
-- if goodsItem.id == goodsId then
|
||
-- goodsNum=goodsNum-c2sData.data.goodsNum
|
||
-- end
|
||
|
||
--大于0才能设置成可用
|
||
if goodsNum>0 then
|
||
isUse =true
|
||
end
|
||
break
|
||
end
|
||
end
|
||
|
||
--是否正在使用
|
||
if isUse then
|
||
table.insert(data.transitions,{goodsId=furniture,goodsNum=goodsNum})
|
||
end
|
||
end
|
||
end
|
||
|
||
s2cData.data = assert(pb.encode("S2CDesignTimeFragmentTransition", data))
|
||
end
|
||
|
||
--排序转换道具
|
||
function Raffle:SortTransition(player, transferFurniture )
|
||
|
||
if transferFurniture == nil then
|
||
return transferFurniture
|
||
end
|
||
|
||
local sortData={}
|
||
for _, value in ipairs(transferFurniture) do
|
||
local cfgFurniture = skynet.server.gameConfig:GetPlayerCurCfg( player , "Furniture",value)
|
||
table.insert(sortData,{id=value,sort=cfgFurniture.fragmentNum})
|
||
end
|
||
|
||
--倒序排序
|
||
table.sort(sortData,function(a,b)
|
||
return a.sort > b.sort
|
||
end)
|
||
|
||
local result={}
|
||
for _, value in ipairs(sortData) do
|
||
table.insert(result,value.id)
|
||
end
|
||
|
||
return result
|
||
end
|
||
|
||
|
||
skynet.server.raffle = Raffle
|
||
return Raffle |