HomeServer/Server/AllServer/GameServer/Shop/CoffeeShop.lua

745 lines
29 KiB
Lua
Raw Permalink Normal View History

2024-11-20 15:41:09 +08:00
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 shop = require "Shop"
local CoffeeShop = oo.class(shop)
CoffeeShop.shopType = dataType.ShopType_Coffee
CoffeeShop.maxCDTime = 300 --60秒
CoffeeShop.MethodType_AD = 1 --广告
CoffeeShop.MethodType_Volute = 2 --蜗壳
--咖啡店展示
function CoffeeShop:Show( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SCoffeeMergeShow", c2sData.data ))
local curShop = player.gameData.shop[ self.shopType ]
local data = {}
data.supplierBoxes = curShop.supplierBoxes
data.grids = curShop.grids
data.currency = self:GetCurrency( player )
data.supplierMaxLevel = curShop.mergeMaxLevel
s2cData.cmd = pb.enum("MsgType","CMD_S2C_CoffeeMergeShow")
s2cData.data = assert(pb.encode("S2CCoffeeMergeShow", data))
--self:PringGrid( player )
end
--供应信息点击
function CoffeeShop:SupplyClick( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SCoffeeMergeSupplyClick", c2sData.data ))
local shopType = dataType.ShopType_Coffee
local data = {}
local type = c2sData.data.type
local isVaild = self:IsVaildSupplierBoxes( type )
if not type or not isVaild then
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
else
local gridIndex = self:GetFreeGrid( player )
if not gridIndex then
s2cData.code = errorInfo.ErrorCode.CoffeeShopGridFull
else
local curSupplier = self:GetSupplierBoxes( player , type )
--log.info(string.format("玩家 %d 咖啡店 类型 %d 最新数量 %d", player.userId , type , curSupplier.count))
if curSupplier and curSupplier.count >= 1 then
--数量减1重新CD时间
curSupplier.count = curSupplier.count - 1
local timeCoefficient = skynet.server.store:GetTimeCoefficient(player , 4) --月卡权益 时间系数
curSupplier.nextRefreshTime = skynet.GetTime() + math.ceil(self.maxCDTime * timeCoefficient)
--放到格子里去
self:AddToFreeGrids( player , gridIndex , type , 1 )
--skynet.server.taskListEvent:Modify( player , 13 , 1 )
--在咖啡店生成咖啡制作材料
skynet.server.taskListEvent:Modify( player , 125 , 1 )
data.supplierBox = curSupplier
data.gridTo = self:GetGrid( player , gridIndex ) --player.gameData.shop[ self.shopType ].grids[ gridIndex ]
else
s2cData.code = errorInfo.ErrorCode.NoEnoughGoods
end
end
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_CoffeeMergeSupplyClick")
s2cData.data = assert(pb.encode("S2CCoffeeMergeSupplyClick", data))
end
--获取最新供货信息
function CoffeeShop:SupplyShow( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SCoffeeMergeSupplyShow", c2sData.data ))
local data = {}
local type = c2sData.data.type
local isVaild = self:IsVaildSupplierBoxes( type )
if not type or not isVaild then
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
else
local curSupplier = self:GetSupplierBoxes( player , type )
if curSupplier then
data.supplierBox = curSupplier
else
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
end
skynet.server.msgTips:Reduce( player , 72 )
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_CoffeeMergeSupplyShow")
s2cData.data = assert(pb.encode("S2CCoffeeMergeSupplyShow", data))
end
--获取最新供货信息
function CoffeeShop:Sort( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SCoffeeMergeSort", c2sData.data ))
local data = {}
--排序得第一优先级为type得升序(1-3,0), 第二优先级为level的降序(5-1)
local grids = player.gameData.shop[ self.shopType ].grids
table.sort( grids , function(a,b)
if a.type == b.type then
return a.level > b.level
else
return a.type < b.type
end
end)
--将有数据的格子先整理出来
local tmpGrids = {}
local count = 1
for k, v in pairs( grids ) do
if 0 ~= v.type then
table.insert( tmpGrids , { type = v.type , index = count , level = v.level })
count = count + 1
end
end
--填充剩余格子
for i = count, 30, 1 do
table.insert( tmpGrids , { type = 0 , index = i, level = 0 })
end
player.gameData.shop[ self.shopType ].grids = tmpGrids
data.grids = tmpGrids
s2cData.cmd = pb.enum("MsgType","CMD_S2C_CoffeeMergeSort")
s2cData.data = assert(pb.encode("S2CCoffeeMergeSort", data))
end
--合并
function CoffeeShop:Merge( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SCoffeeMergeAttempt", c2sData.data ))
local data = {}
data.addCurrencyType = dataType.CoffeeShopGoodsType_Empty
local gridFrom = c2sData.data.gridFrom
local gridTo = c2sData.data.gridTo
if not gridFrom or not gridTo or not self:IsVaildGridID( gridFrom ) or not self:IsVaildGridID( gridTo ) then
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
else
gridFrom = gridFrom
gridTo = gridTo
local grid1 = self:GetGrid( player , gridFrom ) --player.gameData.shop[ self.shopType ].grids[ gridFrom ]
local grid2 = self:GetGrid( player , gridTo ) --player.gameData.shop[ self.shopType ].grids[ gridTo ]
if not grid1 or not grid2 then
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
else
if not self:IsFreeGrid( player , gridFrom ) and self:IsFreeGrid( player , gridTo ) then
--始非空格 终为空格 就移动过去
self:MoveGrid( player , gridFrom , gridTo )
else
---始非空格 终非空格 就合成过去
if self:IsSame( player , gridFrom , gridTo ) then
--开始合成
data.addCurrencyType = self:StartMerge( player ,gridFrom , gridTo )
if dataType.CoffeeShopGoodsType_Empty ~= data.addCurrencyType then
--有货币变化,向客户端同步下最新的货币数据
local currencyData = {}
currencyData.currency = {}
currencyData.currency.coffeeBean = player.gameData.shop[ self.shopType ].currency[1]
currencyData.currency.sugar = player.gameData.shop[ self.shopType ].currency[2]
currencyData.currency.milk = player.gameData.shop[ self.shopType ].currency[3]
skynet.server.gameServer:SendMsgToUser( player.userId , "CMD_S2C_CoffeeMergeCurrency" , currencyData )
end
skynet.server.levelTask:Modify( player , 49 , 1 )
skynet.server.taskListEvent:Modify( player , 49 , 1 )
else
--交换格子
self:ExchangeGrid( player , gridFrom , gridTo )
end
end
data.gridFrom = self:GetGrid( player , gridFrom ) --player.gameData.shop[ self.shopType ].grids[ gridFrom ]
data.gridTo = self:GetGrid( player , gridTo ) --player.gameData.shop[ self.shopType ].grids[ gridTo ]
--self:PringGrid( player )
end
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_CoffeeMergeAttempt")
s2cData.data = assert(pb.encode("S2CCoffeeMergeAttempt", data))
end
--补充
function CoffeeShop:Replenish( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SCoffeeSupplierReplenish", c2sData.data ))
local data = {}
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
data.addCurrencyType = dataType.CoffeeShopGoodsType_Empty
local supplierType = c2sData.data.supplierType
local methodType = c2sData.data.methodType
local isVaild = self:IsVaildSupplierBoxes( supplierType )
--玩家信息
local curSupplier = self:GetSupplierBoxes( player , supplierType )
local time = curSupplier.nextRefreshTime
local nowTime = skynet.GetTime()
if not supplierType or not methodType or not isVaild then
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
elseif time<=nowTime then--已经回复完毕
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
else
local isSuc = false
local cfgCoffeeMakingPara = cfgSValue.coffeeMakingPara
if methodType == dataType.AccelerateType_Volute then
-- 消耗玩家蜗壳币
local needVolute = 10
needVolute = math.ceil((time - nowTime) / 60 / cfgSValue.timeExchangeVoluteCoin[2] * cfgSValue.timeExchangeVoluteCoin[1])
if needVolute < 0 then--已经恢复完毕
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
s2cData.cmd = pb.enum("MsgType","CMD_S2C_CoffeeSupplierReplenish")
return
end
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_8")
if player:MoneyChange( dataType.MoneyType_Volute , - needVolute , eventId) then
--使用蜗壳币进行加速 修改相关数据
player.gameData.todayGain.speedUpUseCount = player.gameData.todayGain.speedUpUseCount + 1
if player.gameData.todayGain.speedUpUseCount == cfgSValue.triggerPlantPack[ 1 ] then
skynet.server.store:TriggerPack(player , skynet.server.store.TriggerPack_SpeedUp)
end
isSuc = true
end
elseif methodType == dataType.AccelerateType_AccTicket and skynet.server.bag:GetGoodsCount(player, dataType.GoodsType_Prop, 6) > 0 then
--消耗玩家一个刷新券
skynet.server.bag:RemoveGoods(player , dataType.GoodsType_Prop, 6 , 1)
isSuc = true
elseif methodType == dataType.AccelerateType_ADTicket then
if supplierType == 1 then
if skynet.server.ad:CanWatch(player, "CoffeeSupplyReplensh") and
skynet.server.ad:PayADTicket(player, "CoffeeSupplyReplensh") then
isSuc = true
end
elseif supplierType == 2 then
if skynet.server.ad:CanWatch(player, "SugarSupplyReplensh") and
skynet.server.ad:PayADTicket(player, "SugarSupplyReplensh") then
isSuc = true
end
elseif supplierType == 3 then
if skynet.server.ad:CanWatch(player, "MilkSupplyReplensh") and
skynet.server.ad:PayADTicket(player, "MilkSupplyReplensh") then
isSuc = true
end
end
elseif methodType == dataType.AccelerateType_WatchAD then
if supplierType == 1 then
if skynet.server.ad:CanWatch(player, "CoffeeSupplyReplensh") then
skynet.server.ad:Update(player, "CoffeeSupplyReplensh")
isSuc = true
end
elseif supplierType == 2 then
if skynet.server.ad:CanWatch(player, "SugarSupplyReplensh") then
skynet.server.ad:Update(player, "SugarSupplyReplensh")
isSuc = true
end
elseif supplierType == 3 then
if skynet.server.ad:CanWatch(player, "MilkSupplyReplensh") then
skynet.server.ad:Update(player, "MilkSupplyReplensh")
isSuc = true
end
end
end
if isSuc then
local replenishCount = cfgCoffeeMakingPara[1]
--激活了豪华月卡,数量增加
if skynet.server.luxuryCard:IsActivate( player ) then
replenishCount = replenishCount * cfgSValue.luxuryCardCoffeeClickModulus
end
curSupplier.count = replenishCount
data.supplierBox = curSupplier
log.debug(string.format("玩家 %d 咖啡店 补充商品 补充类型 %d 补充商品类型 %d ", player.userId , methodType , supplierType))
else
s2cData.code = errorInfo.ErrorCode.TodayMaxLimit
end
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_CoffeeSupplierReplenish")
s2cData.data = assert(pb.encode("S2CCoffeeSupplierReplenish", data))
end
--研发
function CoffeeShop:Research( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SCoffeeResearch", c2sData.data ))
local data = {}
data.addCurrencyType = dataType.CoffeeShopGoodsType_Empty
local curShop = player.gameData.shop[ self.shopType ]
if not curShop.guarantee then
curShop.guarantee = {0,0}
end
--检查是否有效
local isVaild = true
for i = dataType.CoffeeShopGoodsType_CoffeeBean, dataType.CoffeeShopGoodsType_Milk , 1 do
if 0 == curShop.currency[i] then
isVaild = false
break
end
end
if not isVaild then
s2cData.code = errorInfo.ErrorCode.NoEnoughGoods
else
--供应品足够,可以研发
--开始研发
--扣除货币
for i = dataType.CoffeeShopGoodsType_CoffeeBean, dataType.CoffeeShopGoodsType_Milk , 1 do
curShop.currency[i] = curShop.currency[i] - 1
end
--制作咖啡id
local coffeeId =0
--保底配置
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg(player, "SValue")
local cfgcoffeeMakingGuarantee = cfgSValue.coffeeMakingGuarantee
local cfgAllCoffeeType = skynet.server.gameConfig:GetPlayerAllCfg( player , "CoffeeType")
--是否触发新咖啡保底
local isGuarantee = false
coffeeId,isGuarantee = self:GetRandCoffee( player , self.CoffeeType_Coffee )
--是否新咖啡保底
if not isGuarantee then
--添加甄选/特调保底次数
curShop.guarantee[1],curShop.guarantee[2]=curShop.guarantee[1]+1,curShop.guarantee[2]+1
--臻选保底
if cfgcoffeeMakingGuarantee[1]- curShop.guarantee[1]<=1 then
--臻选咖啡列表
local reserveCoffeeIds = {}
for _, value in ipairs(cfgAllCoffeeType) do
if value.rarity == 2 then
table.insert(reserveCoffeeIds, value.id)
end
end
--随机甄选咖啡
coffeeId = reserveCoffeeIds[math.random(1, #reserveCoffeeIds)]
elseif cfgcoffeeMakingGuarantee[2]- curShop.guarantee[2]<=1 then --特调保底
--特调咖啡列表
local specialCoffeeIds = {}
for _, value in ipairs(cfgAllCoffeeType) do
if value.rarity == 3 then
table.insert(specialCoffeeIds, value.id)
end
end
--随机甄选咖啡
coffeeId = specialCoffeeIds[math.random(1, #specialCoffeeIds)]
else--普通制作
goto loop
end
-- 完成甄选咖啡的制作
if cfgAllCoffeeType[coffeeId].rarity == 2 then
--重置甄选保底次数
curShop.guarantee[1]=0
elseif cfgAllCoffeeType[coffeeId].rarity == 3 then
--重置特调保底次数
curShop.guarantee[2]=0
end
end
--已经获得普通咖啡就跳出
::loop::
-- 完成甄选咖啡的制作
if cfgAllCoffeeType[coffeeId].rarity == 2 then
skynet.server.taskListEvent:Modify( player , 118 , 1)
end
--研发成功
skynet.server.levelTask:Modify( player , 29 , 1 )
skynet.server.npcTask:Modify( player , 61 , 1 )
skynet.server.taskListEvent:Modify( player , 29 , 1)
skynet.server.taskListEvent:Modify( player , 11 , 1 )
skynet.server.taskListEvent:Modify( player , 61 , 1 )
--将研发的咖啡添加进背包
skynet.server.bag:AddGoods(player , dataType.GoodsType_Coffee , coffeeId , 1)
local isNew = self:GainCoffee( player , coffeeId )
local curCoffees = player.gameData.shop[ self.shopType ].coffees
--检查下能不能领取新的奖励了
local coffeeCount = #curCoffees
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
local cfgIllustationsReward = cfgSValue.coffeeIllustationReward
for k1, v1 in pairs( curShop.rewards ) do
for k2, v2 in pairs( cfgIllustationsReward ) do
local reward = skynet.server.common:Split( v2 ,"_" )
--满足条件就设置可领状态
if k2 == v1.id and dataType.Status_NoGain == v1.status and coffeeCount >= tonumber(reward[ 1 ]) then
v1.status = dataType.Status_CanGain
skynet.server.msgTips:Add(player , 62)
end
end
end
self:CheckMsgTips( player )
skynet.server.achieveTask:Modify( player , 61 , 1)
skynet.server.taskListEvent:Modify( player , 61 , 1)
data.currency = self:GetCurrency( player )
data.inventedCoffee = coffeeId
data.isNew = isNew
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_CoffeeResearch")
s2cData.data = assert(pb.encode("S2CCoffeeResearch", data))
end
--图鉴显示
function CoffeeShop:IllustrationShow( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SCoffeeIllustrationShow", c2sData.data ))
local curShop = player.gameData.shop[ self.shopType ]
local data = {}
local cfg = {}
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
local cfgIllustationsReward = cfgSValue.coffeeIllustationReward
local cfgReward = skynet.server.gameConfig:GetPlayerAllCfg( player , "Reward")
data.rewards = {}
data.currentCoffees = curShop.coffees
local coffeeCount = #curShop.coffees
for k1, v1 in pairs( curShop.rewards ) do
--能领和领取的发给客户端
if dataType.Status_CanGain == v1.status or dataType.Status_AlreadyGain == v1.status then
table.insert( data.rewards , v1 )
end
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_CoffeeIllustrationShow")
s2cData.data = assert(pb.encode("S2CCoffeeIllustrationShow", data))
end
--图鉴奖励
function CoffeeShop:IllustrationPrize( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SCoffeeIllustrationPrize", c2sData.data ))
local data = {}
local id = c2sData.data.id
if not id then
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
else
local curShop = player.gameData.shop[ self.shopType ]
data.id = id
data.awardMoney = {} --奖励的货币
data.awardGoods = {} --奖励的物品
data.rewards = {}
local rewardId = 0
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
for k, v in pairs( cfgSValue.coffeeIllustationReward ) do
local reward = skynet.server.common:Split( v ,"_" )
if id == k then
rewardId = tonumber(reward[2])
break
end
end
for k, v in pairs( curShop.rewards ) do
if id == v.id and dataType.Status_CanGain == v.status then
v.status = dataType.Status_AlreadyGain
--发奖
local cfgReward = skynet.server.gameConfig:GetPlayerCurCfg( player , "Reward" , rewardId )
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_74")
player:GiveReward( rewardId , eventId)
table.insert( data.awardMoney , { type = dataType.GoodsType_Clovers , count = cfgReward.mapCoin })
local cfgSceneObject = cfgReward.sceneObject
for k, v in pairs(cfgSceneObject) do
local tmp = skynet.server.common:Split( v ,"_" )
local goodsType = 0
if 1 == tonumber(tmp[ 1 ]) then
goodsType = dataType.GoodsType_Furniture
elseif 2 == tonumber(tmp[ 1 ]) then
goodsType = dataType.GoodsType_Decorate
end
table.insert( data.awardGoods , { goodsType = goodsType , goodsId = tonumber(tmp[ 2 ]) , goodsCount = 1})
skynet.server.msgTips:Reduce(player , 62)
end
end
--能领和领取的发给客户端
if dataType.Status_CanGain == v.status or dataType.Status_AlreadyGain == v.status then
table.insert( data.rewards , v )
end
end
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_CoffeeIllustrationPrize")
s2cData.data = assert(pb.encode("S2CCoffeeIllustrationPrize", data))
end
--添加格子商品
function CoffeeShop:AddToFreeGrids( player , index , type , level )
local curGrid = self:GetGrid( player , index ) --player.gameData.shop[ self.shopType ].grids[ index ]
curGrid.type = type
curGrid.level = level
log.debug(string.format("玩家 %d 咖啡店 添加格子商品 格子索引 %d 商品类型 %d 等级 %d", player.userId , index , type , level ))
end
--获取空闲格子
function CoffeeShop:GetFreeGrid( player )
local grids = player.gameData.shop[ self.shopType ].grids
for i = 1, 30, 1 do
local curGrid = self:GetGrid( player , i )
if dataType.CoffeeShopGoodsType_Empty == curGrid.type then
return i
end
end
return nil
end
--设置为空闲格子
function CoffeeShop:SetFreeGrid( player , index )
local grid = self:GetGrid( player , index )
--local grid = player.gameData.shop[ self.shopType ].grids[ index ]
if grid then
grid.type = dataType.CoffeeShopGoodsType_Empty
grid.level = 0
end
end
--是否为空闲格子
function CoffeeShop:IsFreeGrid( player , index )
--local grid = player.gameData.shop[ self.shopType ].grids[ index ]
local grid = self:GetGrid( player , index )
if grid and dataType.CoffeeShopGoodsType_Empty == grid.type then
return true
else
return false
end
end
--是否相同
function CoffeeShop:IsSame( player , gridFrom , gridTo )
--local grid = self:GetGrid( player , index )
local curGridFrom = self:GetGrid( player , gridFrom )
local curGridTo = self:GetGrid( player , gridTo )
if curGridFrom.type == curGridTo.type and curGridFrom.level == curGridTo.level then
return true
else
return false
end
end
--开始合成
function CoffeeShop:StartMerge( player , gridFrom , gridTo )
local curGridFrom = self:GetGrid( player , gridFrom )
local curGridTo = self:GetGrid( player , gridTo )
local currencyType = dataType.CoffeeShopGoodsType_Empty
curGridTo.level = curGridTo.level + 1
local curShop = player.gameData.shop[ self.shopType ]
--我已经合成过最高的等级
if dataType.CoffeeShopGoodsType_CoffeeBean == curGridTo.type and curGridTo.level > curShop.mergeMaxLevel[ 1 ] then
curShop.mergeMaxLevel[ 1 ] = curGridTo.level
elseif dataType.CoffeeShopGoodsType_Sugar == curGridTo.type and curGridTo.level > curShop.mergeMaxLevel[ 2 ] then
curShop.mergeMaxLevel[ 2 ] = curGridTo.level
elseif dataType.CoffeeShopGoodsType_Milk == curGridTo.type and curGridTo.level > curShop.mergeMaxLevel[ 3 ] then
curShop.mergeMaxLevel[ 3 ] = curGridTo.level
end
if 6 == curGridTo.level then
--合成了最高等级
for k, v in pairs( curShop.currency ) do
if curGridTo.type == k then
curShop.currency[ k ] = curShop.currency[ k ] + 1
curShop.mergeCount = curShop.mergeCount + 1
currencyType = k
break
end
end
self:SetFreeGrid( player , gridFrom )
self:SetFreeGrid( player , gridTo )
self:CheckMsgTips( player )
else
self:SetFreeGrid( player , gridFrom )
end
return currencyType
end
--移动格子
function CoffeeShop:MoveGrid( player , gridFrom , gridTo )
local curGridFrom = self:GetGrid( player , gridFrom )
local curGridTo = self:GetGrid( player , gridTo )
curGridTo.type = curGridFrom.type
curGridTo.level = curGridFrom.level
--清空原格子
self:SetFreeGrid( player , gridFrom )
end
--交换格子
function CoffeeShop:ExchangeGrid( player , gridFrom , gridTo )
local curGridFrom = self:GetGrid( player , gridFrom )
local curGridTo = self:GetGrid( player , gridTo )
curGridTo.type , curGridFrom.type = curGridFrom.type , curGridTo.type
curGridTo.level , curGridFrom.level = curGridFrom.level , curGridTo.level
end
--获取供应端信息
function CoffeeShop:GetSupplierBoxes( player , type )
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
local replenishCount = cfgSValue.coffeeMakingPara[1]
--激活了豪华月卡,数量增加
if skynet.server.luxuryCard:IsActivate( player ) then
replenishCount = replenishCount * cfgSValue.luxuryCardCoffeeClickModulus
end
for k, v in pairs( player.gameData.shop[ self.shopType ].supplierBoxes ) do
if type == v.type then
--如果CD时间到了就给他充满
if skynet.GetTime() > v.nextRefreshTime then
v.count = replenishCount
end
return v
end
end
return nil
end
--获取当前货币
function CoffeeShop:GetCurrency( player )
local curShop = player.gameData.shop[ self.shopType ]
local currency = {}
currency.coffeeBean = curShop.currency[1]
currency.sugar = curShop.currency[2]
currency.milk = curShop.currency[3]
return currency
end
function CoffeeShop:GetGrid( player , gridIndex )
for k, v in pairs( player.gameData.shop[ self.shopType ].grids ) do
if gridIndex == v.index then
return v
end
end
end
--是否有效的补充盒
function CoffeeShop:IsVaildSupplierBoxes( type )
if nil == type or type < dataType.CoffeeShopGoodsType_CoffeeBean or type > dataType.CoffeeShopGoodsType_Milk then
return false
end
return true
end
--是否有效的格子ID
function CoffeeShop:IsVaildGridID( id )
if nil == id or id < 1 and id >= 30 then
return false
end
return true
end
--检查是否有红点
function CoffeeShop:CheckMsgTips( player )
local curShop = player.gameData.shop[ self.shopType ]
--检查是否有足购的货币
local isEnough = true
for k, v in pairs( curShop.currency ) do
if curShop.currency[ k ] <= 0 then
isEnough = false
break
end
end
if isEnough then
skynet.server.msgTips:Reset( player , 67 )
skynet.server.msgTips:Add( player , 67 )
else
skynet.server.msgTips:Reduce( player , 67 )
end
end
--获得咖啡
function CoffeeShop:GainCoffee( player , coffeeId )
--如果背包中有 而对应的图鉴未解锁 则修改对应数据
local curShop = player.gameData.shop[ self.shopType ]
if coffeeId and curShop then
--看下是不是新咖啡
local isNew = true
for k, v in pairs( curShop.coffees ) do
if coffeeId == v then
isNew = false
break
end
end
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_79")
local curCfgCoffeeType = skynet.server.gameConfig:GetPlayerCurCfg( player , "CoffeeType" , coffeeId )
skynet.server.npcTask:Modify( player , 98 , 1 , nil , coffeeId )
skynet.server.taskListEvent:Modify( player , 98 , 1)
if isNew then
curShop.noNewCoffeeCount = 0
--解锁该咖啡图鉴
table.insert(curShop.coffees , coffeeId )
--发放首次制作奖励
player:GiveRewardNpc( curCfgCoffeeType.inventReward , 4 , eventId )
else
curShop.noNewCoffeeCount = curShop.noNewCoffeeCount + 1
--发放重复制作奖励
player:GiveRewardNpc( curCfgCoffeeType.rewardId , 4 , eventId )
end
player:AddExpForType( 8 )
return isNew
else
return false
end
end
--打印格式数据
function CoffeeShop:PringGrid( player )
local grids = player.gameData.shop[ self.shopType ].grids
local text = ""
for i = 1,30 do
text = text .. string.format( "%d %d %d | ", grids[i].index , grids[i].type , grids[i].level )
end
text = string.format("玩家 %d 进入咖啡店数据 " , player.userId ) .. text
log.info(text)
end
skynet.server.coffeeShop = CoffeeShop
return CoffeeShop