152 lines
6.6 KiB
Lua
152 lines
6.6 KiB
Lua
|
|
local skynet = require "skynet"
|
||
|
|
local oo = require "Class"
|
||
|
|
local log = require "Log"
|
||
|
|
local pb = require "pb"
|
||
|
|
local errorInfo = require "ErrorInfo"
|
||
|
|
local dataType = require "DataType"
|
||
|
|
local Gashapon = oo.class()
|
||
|
|
|
||
|
|
function Gashapon:Init()
|
||
|
|
|
||
|
|
end
|
||
|
|
|
||
|
|
--扭蛋红点 每日第一次登录进行判断
|
||
|
|
function Gashapon:ShowRedDot(player)
|
||
|
|
--玩家大于等于6级才进行添加
|
||
|
|
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
|
||
|
|
if player.gameData.level>= cfgSValue.signInUnlockLvl then
|
||
|
|
skynet.server.msgTips:ReduceAll(player , 50) --重置对应红点
|
||
|
|
skynet.server.msgTips:Add(player , 50) --扭蛋每日红点
|
||
|
|
end
|
||
|
|
|
||
|
|
end
|
||
|
|
|
||
|
|
--扭蛋展示
|
||
|
|
function Gashapon:Show( player , c2sData , s2cData )
|
||
|
|
c2sData.data = assert(pb.decode("C2SGashaponShow", c2sData.data ))
|
||
|
|
local data = {}
|
||
|
|
data.serialId = player.gameData.gashapon.serialId
|
||
|
|
--获取该玩家还有多少扭蛋券
|
||
|
|
data.gashaponTicket = skynet.server.bag:GetGoodsCount( player , dataType.GoodsType_Prop , 7)
|
||
|
|
--消除对应红点
|
||
|
|
if skynet.server.bag:GetGoodsCount( player , dataType.GoodsType_Prop , 7) <= 0 then
|
||
|
|
skynet.server.msgTips:ReduceAll(player , 50)
|
||
|
|
end
|
||
|
|
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GashaponShow")
|
||
|
|
s2cData.data = assert(pb.encode("S2CGashaponShow", data))
|
||
|
|
end
|
||
|
|
|
||
|
|
--扭蛋抽奖
|
||
|
|
function Gashapon:Lottery( player , c2sData , s2cData )
|
||
|
|
c2sData.data = assert(pb.decode("C2SGashaponLottery", c2sData.data ))
|
||
|
|
local data = {}
|
||
|
|
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
|
||
|
|
local gashapon = player.gameData.gashapon
|
||
|
|
--判断玩家扭蛋券还够不
|
||
|
|
if skynet.server.bag:GetGoodsCount( player , dataType.GoodsType_Prop , 7) > 0 then
|
||
|
|
skynet.server.bag:RemoveGoods( player , dataType.GoodsType_Prop , 7 ,1)
|
||
|
|
--获取当天所属月份
|
||
|
|
local now = skynet.GetTime()
|
||
|
|
local month = tonumber(os.date("%m", now))
|
||
|
|
local lotteryLevel = 1 --蛋的等级
|
||
|
|
local rand = math.random(1, 100)
|
||
|
|
if rand >= 1 and rand <= 100*cfgSValue.gashaponIntegralRatio[ 1 ] then
|
||
|
|
lotteryLevel = 3 --罕见扭蛋
|
||
|
|
elseif rand > 100*cfgSValue.gashaponIntegralRatio[ 1 ] and rand <= 100*cfgSValue.gashaponIntegralRatio[ 2 ] then
|
||
|
|
lotteryLevel = 1 --蜗壳币扭蛋
|
||
|
|
elseif rand > 100*cfgSValue.gashaponIntegralRatio[ 2 ] then
|
||
|
|
lotteryLevel = 2 --普通扭蛋
|
||
|
|
end
|
||
|
|
gashapon.level = lotteryLevel
|
||
|
|
log.debug(string.format("玩家 %d 获取成功扭蛋系列 %d 蛋的等级 %d", player.userId , gashapon.serialId , lotteryLevel ))
|
||
|
|
|
||
|
|
data.serialId = gashapon.serialId
|
||
|
|
data.gashaponTicket = skynet.server.bag:GetGoodsCount( player , dataType.GoodsType_Prop , 7)
|
||
|
|
data.level = lotteryLevel
|
||
|
|
|
||
|
|
--消除对应红点
|
||
|
|
if skynet.server.bag:GetGoodsCount( player , dataType.GoodsType_Prop , 7) <= 0 then
|
||
|
|
skynet.server.msgTips:ReduceAll(player , 50)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GashaponLottery")
|
||
|
|
s2cData.data = assert(pb.encode("S2CGashaponLottery", data))
|
||
|
|
end
|
||
|
|
|
||
|
|
--扭蛋获取奖品
|
||
|
|
function Gashapon:GainPrize( player , c2sData , s2cData )
|
||
|
|
c2sData.data = assert(pb.decode("C2SGashaponGainPrize", c2sData.data ))
|
||
|
|
local gashapon = player.gameData.gashapon
|
||
|
|
local data = {}
|
||
|
|
local cfgGashapon = skynet.server.gameConfig:GetPlayerAllCfg( player , "Gashapon")
|
||
|
|
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
|
||
|
|
--该系列下的奖品
|
||
|
|
local allItemIds = cfgGashapon[ gashapon.serialId ].allItemId
|
||
|
|
if 0 == gashapon.lotteryLevel then
|
||
|
|
s2cData.code = errorInfo.ErrorCode.GetGoodsFailed
|
||
|
|
else
|
||
|
|
local goodsType = 0
|
||
|
|
local goodsId = 0
|
||
|
|
local goodsCount = 0
|
||
|
|
if 1 == gashapon.level then --蜗壳币扭蛋
|
||
|
|
goodsType = dataType.GoodsType_Volute
|
||
|
|
goodsId = 0
|
||
|
|
--随机蜗壳币数量
|
||
|
|
local adDiamond = cfgSValue.gashaponVoluteCoin[ math.random(1,4) ]
|
||
|
|
goodsCount = adDiamond
|
||
|
|
elseif 2 == gashapon.level then --普通扭蛋
|
||
|
|
goodsType = dataType.GoodsType_Furniture
|
||
|
|
goodsId = allItemIds[ math.random(2,6) ]
|
||
|
|
goodsCount = 1
|
||
|
|
elseif 3 == gashapon.level then --罕见扭蛋
|
||
|
|
goodsType = dataType.GoodsType_Furniture
|
||
|
|
goodsId = allItemIds[ 1 ]
|
||
|
|
goodsCount = 1
|
||
|
|
end
|
||
|
|
--发放奖励
|
||
|
|
if dataType.GoodsType_Volute == goodsType then
|
||
|
|
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_25")
|
||
|
|
player:MoneyChange( dataType.GoodsType_Volute , goodsCount , eventId) --发放四叶草
|
||
|
|
elseif dataType.GoodsType_Furniture == goodsType then
|
||
|
|
skynet.server.bag:AddGoods( player , dataType.GoodsType_Furniture , goodsId , goodsCount ) --新增商品
|
||
|
|
end
|
||
|
|
|
||
|
|
log.debug(string.format("玩家 %d 获取成功扭蛋系列 %d 蛋的等级 %d 商品类型 %d 商品ID %d 商品数量 %d", player.userId , gashapon.serialId , gashapon.level ,goodsType , goodsId , goodsCount))
|
||
|
|
|
||
|
|
gashapon.level = 0
|
||
|
|
data.goodsType = goodsType
|
||
|
|
data.goodsId = goodsId
|
||
|
|
data.goodsCount = goodsCount
|
||
|
|
end
|
||
|
|
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GashaponGainPrize")
|
||
|
|
s2cData.data = assert(pb.encode("S2CGashaponGainPrize", data))
|
||
|
|
end
|
||
|
|
|
||
|
|
--刷新
|
||
|
|
function Gashapon:Refresh( player )
|
||
|
|
local gashapon = player.gameData.gashapon
|
||
|
|
--需要刷新扭蛋系列
|
||
|
|
if 0 == gashapon.refreshTime or not skynet.server.common:IsSameDay( skynet.GetTime() , gashapon.refreshTime ) then
|
||
|
|
local cfgGashapon = skynet.server.gameConfig:GetPlayerAllCfg( player , "Gashapon")
|
||
|
|
gashapon.serialId = math.random(1 , #cfgGashapon)
|
||
|
|
gashapon.refreshTime = skynet.GetTime()
|
||
|
|
gashapon.isFreeLottery = true
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
--是否为扭蛋
|
||
|
|
function Gashapon:IsGashapon( player , goodsId )
|
||
|
|
local cfgAllGashapon = skynet.server.gameConfig:GetPlayerAllCfg( player , "Gashapon")
|
||
|
|
for k1, v1 in pairs( cfgAllGashapon ) do
|
||
|
|
for k2, v2 in pairs( v1.allItemId ) do
|
||
|
|
if goodsId == v2 then
|
||
|
|
return true
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
return false
|
||
|
|
end
|
||
|
|
|
||
|
|
skynet.server.gashapon = Gashapon
|
||
|
|
return Gashapon
|