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

1254 lines
62 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 CuisineShop = oo.class()
CuisineShop.ShopType = dataType.ShopType_Cuisine
CuisineShop.NPCId = 6 --茂星
function CuisineShop:Init()
end
--玩家料理店数据初始化
function CuisineShop:InitData(player , shopType)
--料理相关数据
local cfgCuisineMenu = skynet.server.gameConfig:GetPlayerAllCfg( player , "CuisineMenu") --菜品数据
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue") --套餐数据
--玩家料理店相关数据
player.gameData.shop[ shopType ] = {}
player.gameData.shop[ shopType ].cuisineInfos = {} --玩家菜品的相关信息
player.gameData.shop[ shopType ].menuInfos = {} --玩家菜单的相关信息
player.gameData.shop[ shopType ].mealInfos = {} --玩家套餐制作的相关信息
player.gameData.shop[ shopType ].plotInfos = {} --玩家菜地的相关信息
player.gameData.shop[ shopType ].restockInfos = {} --玩家进货的相关信息
player.gameData.shop[ shopType ].failMenuInfos = {} --玩家失败料理的相关信息
--玩家菜品相关数据赋值
for k ,v in pairs(cfgCuisineMenu) do
local count = v.id
player.gameData.shop[ shopType ].cuisineInfos[ count ] = {}
player.gameData.shop[ shopType ].cuisineInfos[ count ].id = v.id --菜品id
player.gameData.shop[ shopType ].cuisineInfos[ count ].status = 0 --菜品状态 0 未完成 1 已完成 默认未完成
player.gameData.shop[ shopType ].cuisineInfos[ count ].setChoiceCount = 0 --套餐选择该菜品的次数
end
--玩家菜单相关数据赋值
for k ,v in pairs(cfgCuisineMenu) do
--如果玩家没有该等级菜单则进行赋值
if not player.gameData.shop[ shopType ].menuInfos [ v.menuLevel ] and v.menuLevel > 0 then
local count = v.menuLevel
player.gameData.shop[ shopType ].menuInfos [ count ] = {}
player.gameData.shop[ shopType ].menuInfos [ count ].level = count --菜单等级level
player.gameData.shop[ shopType ].menuInfos [ count ].status = 0 --菜单状态 0 未解锁 1 未完成 2 已完成 默认未解锁
player.gameData.shop[ shopType ].menuInfos [ count ].cuisineIds = {} --菜单包含的菜品id
for k1 , v1 in pairs(cfgCuisineMenu) do
if count == v1.menuLevel then
table.insert(player.gameData.shop[ shopType ].menuInfos [ count ].cuisineIds , v1.id)
end
end
end
end
--玩家套餐相关数据赋值 料理店套餐难度分布(简单,中等,困难) 2,1,1
local difficulty = 1
local count = 1
for k ,v in pairs(cfgSValue.foodShopSetDifficultyNum) do
for k1=1,v,1 do
player.gameData.shop[ shopType ].mealInfos[ count ] = {}
player.gameData.shop[ shopType ].mealInfos[ count ].id = count --套餐索引
player.gameData.shop[ shopType ].mealInfos[ count ].difficulty = difficulty --套餐难度
player.gameData.shop[ shopType ].mealInfos[ count ].status = 0 --套餐状态 0 未开启该套餐 1 未完成 2 可以完成 3 已完成 默认未开启该套餐
player.gameData.shop[ shopType ].mealInfos[ count ].cuisineInclude = {} --套餐完成包含的菜品
count = count + 1
end
difficulty = difficulty + 1
end
--玩家菜地相关数据赋值 默认5块地
for i=1,5,1 do
player.gameData.shop[ shopType ].plotInfos[ i ] = {}
player.gameData.shop[ shopType ].plotInfos[ i ].id = i --菜地id
player.gameData.shop[ shopType ].plotInfos[ i ].status = 0 --菜地状态 0未解锁 1未种植 2幼苗 3初枝 4成枝 5成熟 默认未种植
player.gameData.shop[ shopType ].plotInfos[ i ].matId = 0 --植物id 初始为0
player.gameData.shop[ shopType ].plotInfos[ i ].nextStatusTime = 0 --下个植物状态的时间戳
player.gameData.shop[ shopType ].plotInfos[ i ].startPlantTime = 0 --开始种植的时间戳
end
--玩家进货相关数据赋值
player.gameData.shop[ shopType ].restockInfos.status = 2 --进货状态 0 可进货 1 进货中 2 可领取进货
player.gameData.shop[ shopType ].restockInfos.restockLevel = 1 --上次进货的货源等级
player.gameData.shop[ shopType ].restockInfos.finishTime = 0 --进货完成时间戳 初始为0
player.gameData.shop[ shopType ].restockInfos.rewards = {} --进货的货品
--玩家当前的菜单等级 初始默认为1
player.gameData.shop[ shopType ].menuLevel = 1
player.gameData.shop[ shopType ].menuInfos [ 1 ].status = 1 --对应菜单等级的数据修改
--刷新食材
local cfgCuisineMaterial = skynet.server.gameConfig:GetPlayerAllCfg( player , "CuisineMaterial")
for k , v in pairs(cfgCuisineMaterial) do
if v.menuLevel == 1 and v.materialType == 2 then
table.insert(player.gameData.shop[ self.ShopType ].restockInfos.rewards,{type = dataType.GoodsType_CuisineMaterial , id = v.id , count = v.gainNum})
end
end
self:LoginInitData(player)
--将玩家的菜单等级存入redis中 提供给送礼进行使用
skynet.server.personal:SetDetail( player.gameData.partner.id ,"cuisineLevel", player.gameData.shop[ shopType ].menuLevel)
end
--每次登录需要进行修改的数据
function CuisineShop:LoginInitData(player)
--重置料理店红点
skynet.server.msgTips:Reset(player , 51) --种植成熟的红点
skynet.server.msgTips:Reset(player , 58) --可进货的红点
skynet.server.msgTips:Reset(player , 59) --菜单奖励可领取的红点
skynet.server.msgTips:Reset(player , 73) --套餐可以完成的红点
local cfgCuisineMenu = skynet.server.gameConfig:GetPlayerAllCfg( player , "CuisineMenu") --菜品数据
local curShop = player.gameData.shop[ self.ShopType ]
for k, v in pairs( cfgCuisineMenu ) do
if curShop and not curShop.cuisineInfos[ v.id ] then
curShop.cuisineInfos[ v.id ] = {}
curShop.cuisineInfos[ v.id ].id = v.id --菜品id
curShop.cuisineInfos[ v.id ].status = 0 --菜品状态 0 未完成 1 已完成 默认未完成
curShop.cuisineInfos[ v.id ].setChoiceCount = 0 --套餐选择该菜品的次数
end
end
local cfgCuisineMaterial = skynet.server.gameConfig:GetPlayerAllCfg( player , "CuisineMaterial")
local cfgCuisineSet = skynet.server.gameConfig:GetPlayerAllCfg( player , "CuisineSet")
if player.gameData.shop[ self.ShopType ] then
--判断玩家的菜地是否需要修改状态
local nowTime = skynet.GetTime()
for k, v in pairs(player.gameData.shop[ self.ShopType ].plotInfos) do
if v.matId > 0 and v.status < 4 and v.status > 0 and nowTime >= v.nextStatusTime then
local timeCoefficient = skynet.server.store:GetTimeCoefficient(player , 3)
--获取该植物所有状态的到达时间
local allStatusTime = self:GetAllStatusTime(player,cfgCuisineMaterial[v.matId].plantId, v.status, v.nextStatusTime, timeCoefficient)
for k1 ,v1 in pairs(allStatusTime) do
if nowTime >= v1.nextStatusTime then
if v1.status == 4 then
v.status = 5
v.nextStatusTime = 0
break
else
v.status = v1.status
v.nextStatusTime = v1.nextStatusTime
end
else
v.status = v1.status
v.nextStatusTime = v1.nextStatusTime
break
end
end
elseif v.matId > 0 and v.status == 4 and nowTime >= v.nextStatusTime then
v.status = 5
v.nextStatusTime = 0
end
end
--判断玩家的进货是否需要刷新
if nowTime >= player.gameData.shop[ self.ShopType ].restockInfos.finishTime and 1 == player.gameData.shop[ self.ShopType ].restockInfos.status then
player.gameData.shop[ self.ShopType ].restockInfos.status = 2
player.gameData.shop[ self.ShopType ].restockInfos.finishTime = 0
end
--判断玩家的套餐是否需要刷新
if player.gameData.shop[ self.ShopType ].menuLevel >= 2 then
for k ,v in pairs(player.gameData.shop[ self.ShopType ].mealInfos) do
if v.status == 0 then
self:RefreshSetMeal(player , v.difficulty , v.id) --刷新对应难度的套餐
end
end
end
--检查玩家菜地是否能够解锁
self:PlotUnlock(player)
--红点系统
if player.gameData.shop[ self.ShopType ].restockInfos.status == 2 then --进货红点
skynet.server.msgTips:AddNoNotice(player , 58)
end
for k ,v in pairs(player.gameData.shop[ self.ShopType ].plotInfos) do --种植红点
if v.status == 5 then
skynet.server.msgTips:AddNoNotice(player , 51)
end
end
for k ,v in pairs(player.gameData.shop[ self.ShopType ].menuInfos) do --菜单领取的红点
if v.status == 2 then
skynet.server.msgTips:AddNoNotice(player , 59)
end
end
if player.gameData.shop[ self.ShopType ].menuLevel >= 2 then --套餐可完成的红点
for k ,v in pairs(player.gameData.shop[ self.ShopType ].mealInfos) do
--判断刷新的套餐是否可以完成
if v.status == 1 then
local finish = true
for k1 ,v1 in pairs(v.cuisineInclude) do
local menuCount = skynet.server.bag:GetGoodsCount(player , dataType.GoodsType_CuisineMenu, v1) --获取玩家背包中该菜品的数量
if 0 == menuCount then
finish = false
end
end
if finish then
v.status = 2
--增加对应红点
skynet.server.msgTips:AddNoNotice(player , 73)
end
elseif v.status == 2 then
--增加对应红点
skynet.server.msgTips:AddNoNotice(player , 73)
end
end
end
end
end
--料理店信息展示
function CuisineShop:CuisineShow(player, c2sData , s2cData)
c2sData.data = assert(pb.decode("C2SCuisineShow", c2sData.data ))
local data = {}
data.plotInfos = {} --菜地信息
local nowTime = skynet.GetTime()
local plotInfos = player.gameData.shop[ self.ShopType ].plotInfos
local cfgCuisineMaterial = skynet.server.gameConfig:GetPlayerAllCfg( player , "CuisineMaterial")
--判断玩家的菜品数据是否需要进行修改
for k,v in pairs(player.gameData.shop[ self.ShopType ].cuisineInfos) do
if skynet.server.bag:GetGoodsCount(player , dataType.GoodsType_CuisineMenu, v.id) > 0 and 0 == v.status then
v.status = 1
self:FinishMenu(player)
end
end
for k ,v in pairs(plotInfos) do
--检查一下该玩家有没有到下个状态的植物
if nowTime >= v.nextStatusTime and v.status < 5 and v.nextStatusTime > 0 then
local timeCoefficient = skynet.server.store:GetTimeCoefficient(player , 3)
--修改对应的数据
local allStatusTime = self:GetAllStatusTime(player,cfgCuisineMaterial[v.matId].plantId, v.status, v.nextStatusTime, timeCoefficient )
for k1 ,v1 in pairs(allStatusTime) do
if nowTime >= v1.nextStatusTime then
if v1.status == 4 then
v.status = 5
v.nextStatusTime = 0
v.startPlantTime = 0
--添加对应红点
skynet.server.msgTips:Add(player , 51)
break
else
v.status = v1.status
v.nextStatusTime = v1.nextStatusTime
end
else
v.status = v1.status
v.nextStatusTime = v1.nextStatusTime
break
end
end
end
table.insert(data.plotInfos,v)
end
--将种植时间处理为完成时间
for k ,v in pairs(data.plotInfos) do
if v.matId > 0 then
v.totalTime = self:GetAllTime(player , v.startPlantTime , v.matId)
end
end
data.menuLevel = player.gameData.shop[ self.ShopType ].menuLevel
skynet.server.levelTask:Modify( player , 78 , 1 )
skynet.server.taskListEvent:Modify( player , 78 , 1 )
--判断玩家的进货是否需要刷新
if nowTime >= player.gameData.shop[ self.ShopType ].restockInfos.finishTime and 1 == player.gameData.shop[ self.ShopType ].restockInfos.status then
player.gameData.shop[ self.ShopType ].restockInfos.status = 2
player.gameData.shop[ self.ShopType ].restockInfos.finishTime = 0
skynet.server.msgTips:Add(player , 58) --进货红点
end
data.restockInfo = player.gameData.shop[ self.ShopType ].restockInfos
s2cData.cmd = pb.enum("MsgType","CMD_S2C_CuisineShow")
s2cData.data = assert(pb.encode("S2CCuisineShow", data))
end
--显示玩家可以种植的植物id Vegetables and fruits
function CuisineShop:CuisineShowVF(player, c2sData , s2cData)
c2sData.data = assert(pb.decode("C2SCuisineShowVF", c2sData.data ))
local data = {}
local cfgCuisineMaterial = skynet.server.gameConfig:GetPlayerAllCfg( player , "CuisineMaterial")
data.matIds = {}
local level = player.gameData.shop[ self.ShopType ].menuLevel
for k ,v in pairs(cfgCuisineMaterial) do
if v.menuLevel <= level and 1 == v.materialType then
table.insert( data.matIds , v.id)
end
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_CuisineShowVF")
s2cData.data = assert(pb.encode("S2CCuisineShowVF", data))
end
--蔬果种植 Vegetables and fruits
function CuisineShop:CuisinePlantVF(player, c2sData , s2cData)
c2sData.data = assert(pb.decode("C2SCuisinePlantVF", c2sData.data ))
local data = {}
local cfgCuisineMaterial = skynet.server.gameConfig:GetPlayerAllCfg( player , "CuisineMaterial")
data.plotInfos = {}
local matId = c2sData.data.matId --植物id
local plotId = c2sData.data.plotId --菜地id
local plotInfos = player.gameData.shop[ self.ShopType ].plotInfos
for k , v in pairs(plotInfos) do
if v.id == plotId and v.status == 1 then
local plantId = cfgCuisineMaterial[matId].plantId
--修改玩家菜地相关数据
v.matId = matId
v.startPlantTime = skynet.GetTime()
local timeCoefficient = skynet.server.store:GetTimeCoefficient(player , 3)
v.status,v.nextStatusTime = self:GetNextStatusTime( player , plantId , v.startPlantTime , timeCoefficient)
data.plotInfos = v
--将种植时间处理为完成时间
data.plotInfos.totalTime = self:GetAllTime(player , v.startPlantTime , v.matId)
break
end
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_CuisinePlantVF")
s2cData.data = assert(pb.encode("S2CCuisinePlantVF", data))
end
--改变蔬果生长 移除或者加速
function CuisineShop:CuisineChangeVF(player, c2sData , s2cData)
c2sData.data = assert(pb.decode("C2SCuisineChangeVF", c2sData.data ))
local data = {}
local cfgCuisineMaterial = skynet.server.gameConfig:GetPlayerAllCfg( player , "CuisineMaterial")
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
data.plotInfos = {}
local plotId = c2sData.data.plotId --菜地id
local type = c2sData.data.type --1 删除 2 加速
local methodType = c2sData.data.methodType --加速类型
local plotInfos = player.gameData.shop[ self.ShopType ].plotInfos
if 1 == type then
self:InitPlot(player,plotId)
data.plotInfos = plotInfos[ plotId ]
elseif 2 == type then
--进行加速
local isSuc = false --是否加速成功
if methodType == dataType.AccelerateType_Volute then
--消耗玩家蜗壳币
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_12")
isSuc = player:MoneyChange(dataType.GoodsType_Volute , -cfgSValue.plantGrowupCost , eventId)
if false == isSuc then
s2cData.code = errorInfo.ErrorCode.NoEnoughMoney
else
--使用蜗壳币进行施加营养 修改相关数据
player.gameData.todayGain.plantUseCount = player.gameData.todayGain.plantUseCount + 1
if player.gameData.todayGain.plantUseCount == cfgSValue.triggerPlantPack[ 1 ] then
skynet.server.store:TriggerPack(player , skynet.server.store.TriggerPack_Plant)
end
end
elseif methodType == dataType.AccelerateType_AccTicket and skynet.server.bag:GetGoodsCount(player , dataType.GoodsType_Prop, 5) > 0 then
--消耗玩家一个营养液
skynet.server.bag:RemoveGoods(player , dataType.GoodsType_Prop, 5 , 1)
isSuc = true
elseif methodType == dataType.AccelerateType_ADTicket
and skynet.server.ad:CanWatch( player , "AccelerateVegetable")
and skynet.server.ad:PayADTicket( player , "AccelerateVegetable") then
isSuc = true
elseif methodType == dataType.AccelerateType_WatchAD
and skynet.server.ad:CanWatch( player , "AccelerateVegetable")then
skynet.server.ad:Update(player, "AccelerateVegetable")
isSuc = true
end
if isSuc then
local plantId = cfgCuisineMaterial[plotInfos[ plotId ].matId].plantId
--获取植物成熟的所需时间
local timeCoefficient = skynet.server.store:GetTimeCoefficient(player , 3)
local growTime = cfgSValue.plantGrowTimeRatio
local curCfgPlant = skynet.server.gameConfig:GetPlayerCurCfg( player , "Plant", plantId )
local allTime = math.ceil(( curCfgPlant.coin * (growTime[1]+growTime[2]+growTime[3])) * 60 * timeCoefficient)
--跳转的时间为总生长时间的1/3
plotInfos[ plotId ].startPlantTime = plotInfos[ plotId ].startPlantTime - math.ceil(allTime / 3)
plotInfos[ plotId ].status,plotInfos[ plotId ].nextStatusTime = self:GetNextStatusTime( player , plantId , plotInfos[ plotId ].startPlantTime , timeCoefficient)
--如果植物成熟修改对应数据
if plotInfos[ plotId ].status == dataType.FlowerpotStatus_Ripe then
plotInfos[ plotId ].startPlantTime = 0
skynet.server.msgTips:Add(player , 51)
end
data.plotInfos = plotInfos[ plotId ]
data.plotInfos.totalTime = data.plotInfos.startPlantTime + allTime
end
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_CuisineChangeVF")
s2cData.data = assert(pb.encode("S2CCuisineChangeVF", data))
end
--蔬果获取
function CuisineShop:CuisineGetVF(player, c2sData , s2cData)
c2sData.data = assert(pb.decode("C2SCuisineGetVF", c2sData.data ))
local data = {}
local cfgCuisineMaterial = skynet.server.gameConfig:GetPlayerAllCfg( player , "CuisineMaterial")
data.plotInfo = {}
local plotId = c2sData.data.plotId --菜地id
if 5 == player.gameData.shop[ self.ShopType ].plotInfos[ plotId ].status then
--添加对应的植物
local plantId = player.gameData.shop[ self.ShopType ].plotInfos[ plotId ].matId
local count = cfgCuisineMaterial[ player.gameData.shop[ self.ShopType ].plotInfos[ plotId ].matId ].gainNum
skynet.server.bag:AddGoods(player, dataType.GoodsType_CuisineMaterial , plantId , count)
--修改玩家菜地相关数据
self:InitPlot(player,plotId)
--领取后消除红点
skynet.server.msgTips:Reduce(player , 51)
skynet.server.levelTask:Modify( player , 81 , 1 )
skynet.server.taskListEvent:Modify( player ,81, 1)
skynet.server.taskListEvent:Modify( player , 24 , 1 )
end
data.plotInfo = player.gameData.shop[ self.ShopType ].plotInfos[ plotId ]
s2cData.cmd = pb.enum("MsgType","CMD_S2C_CuisineGetVF")
s2cData.data = assert(pb.encode("S2CCuisineGetVF", data))
end
--进货展示
function CuisineShop:CuisineShowFI(player, c2sData , s2cData)
c2sData.data = assert(pb.decode("C2SCuisineShowFI", c2sData.data ))
local data = {}
--判断玩家的进货是否需要刷新
local nowTime = skynet.GetTime()
if nowTime >= player.gameData.shop[ self.ShopType ].restockInfos.finishTime and 1 == player.gameData.shop[ self.ShopType ].restockInfos.status then
player.gameData.shop[ self.ShopType ].restockInfos.status = 2
player.gameData.shop[ self.ShopType ].restockInfos.finishTime = 0
skynet.server.msgTips:Add(player , 58) --进货红点
end
data.restockInfo = player.gameData.shop[ self.ShopType ].restockInfos
s2cData.cmd = pb.enum("MsgType","CMD_S2C_CuisineShowFI")
s2cData.data = assert(pb.encode("S2CCuisineShowFI", data))
end
--食材开始进货
function CuisineShop:CuisineStartFI(player, c2sData , s2cData)
c2sData.data = assert(pb.decode("C2SCuisineStartFI", c2sData.data ))
local data = {}
local restockLevel = c2sData.data.restockLevel --玩家本次进货的等级
data.restockInfo = {}
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
--只能选择小于或等于当前菜单等级的货源
if player.gameData.shop[ self.ShopType ].menuLevel >= restockLevel and 0 == player.gameData.shop[ self.ShopType ].restockInfos.status then
local cfgCuisineMaterial = skynet.server.gameConfig:GetPlayerAllCfg( player , "CuisineMaterial")
player.gameData.shop[ self.ShopType ].restockInfos.status = 1
player.gameData.shop[ self.ShopType ].restockInfos.restockLevel = restockLevel
local needTime = 0 --本次进货需要的时间
local replenishCount = 0 --补充数量
for k , v in pairs(cfgCuisineMaterial) do
if v.menuLevel == restockLevel and v.materialType == 2 then
needTime = needTime + v.gainNum * v.restockTime
--激活了豪华月卡,数量增加
if skynet.server.luxuryCard:IsActivate( player ) then
replenishCount = cfgSValue.luxuryCardProteinGainTimes * v.gainNum
else
replenishCount = v.gainNum
end
table.insert(player.gameData.shop[ self.ShopType ].restockInfos.rewards,{type = dataType.GoodsType_CuisineMaterial , id = v.id , count = replenishCount })
end
end
--进货的完成时间
local timeCoefficient = skynet.server.store:GetTimeCoefficient(player , 6) --月卡权益 时间系数
player.gameData.shop[ self.ShopType ].restockInfos.finishTime = skynet.GetTime() + math.ceil(needTime * timeCoefficient)
data.restockInfo = player.gameData.shop[ self.ShopType ].restockInfos
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_CuisineStartFI")
s2cData.data = assert(pb.encode("S2CCuisineStartFI", data))
end
--食材进货获取 Food ingredient
function CuisineShop:CuisineGetFI(player, c2sData , s2cData)
c2sData.data = assert(pb.decode("C2SCuisineGetFI", c2sData.data ))
local data = {}
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
data.restockInfo = {}
if 2 == player.gameData.shop[ self.ShopType ].restockInfos.status then
--增加对应食材
for k ,v in pairs(player.gameData.shop[ self.ShopType ].restockInfos.rewards) do
skynet.server.bag:AddGoods(player, v.type , v.id , v.count)
end
--修改对应数据
player.gameData.shop[ self.ShopType ].restockInfos.status = 0
player.gameData.shop[ self.ShopType ].restockInfos.finishTime = 0
player.gameData.shop[ self.ShopType ].restockInfos.rewards = {}
data.restockInfo = player.gameData.shop[ self.ShopType ].restockInfos
--领取后消除红点
skynet.server.msgTips:Reduce(player , 58)
skynet.server.levelTask:Modify( player , 82 , 1 )
skynet.server.taskListEvent:Modify( player , 82 , 1 )
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_CuisineGetFI")
s2cData.data = assert(pb.encode("S2CCuisineGetFI", data))
end
--加速进货
function CuisineShop:CuisineAccelerateRestock(player, c2sData , s2cData)
c2sData.data = assert(pb.decode("C2SCuisineAccelerateRestock", c2sData.data ))
local data = {}
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
local nowTime = skynet.GetTime()
local restockInfos = player.gameData.shop[ self.ShopType ].restockInfos
local methodType = c2sData.data.methodType
if 1 ~= restockInfos.status then
return
else
--根据类型进行加速
if methodType == dataType.AccelerateType_Volute then
--消耗玩家蜗壳币
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_11")
--进行计算立刻完成需要多少蜗壳币
local needVolute = math.ceil((restockInfos.finishTime - nowTime) / 60 / cfgSValue.timeExchangeVoluteCoin[2] * cfgSValue.timeExchangeVoluteCoin[1])
local isSuc = player:MoneyChange(dataType.GoodsType_Volute , -needVolute , eventId)
if false == isSuc then
s2cData.code = errorInfo.ErrorCode.NoEnoughMoney
else
restockInfos.status = 2
restockInfos.finishTime = 0
skynet.server.msgTips:Add(player , 58)
--使用蜗壳币进行加速 修改相关数据
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
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)
restockInfos.finishTime = restockInfos.finishTime - cfgSValue.speedCouponTime * 60 --十分钟
--restockInfos.finishTime = restockInfos.finishTime - 600 --十分钟
--判断是否可以进货
if nowTime >= restockInfos.finishTime then
restockInfos.status = 2
restockInfos.finishTime = 0
skynet.server.msgTips:Add(player , 58)
end
elseif methodType == dataType.AccelerateType_ADTicket
and skynet.server.ad:CanWatch( player , "AccelerateRestock")
and skynet.server.ad:PayADTicket( player , "AccelerateRestock") then
--修改料理店数据
restockInfos.status = 2
restockInfos.finishTime = 0
skynet.server.msgTips:Add(player , 58)
elseif methodType == dataType.AccelerateType_WatchAD
and skynet.server.ad:CanWatch( player , "AccelerateRestock") then
skynet.server.ad:Update(player, "AccelerateRestock")
--修改料理店数据
restockInfos.status = 2
restockInfos.finishTime = 0
skynet.server.msgTips:Add(player , 58)
end
end
data.restockInfo = restockInfos
s2cData.cmd = pb.enum("MsgType","CMD_S2C_CuisineAccelerateRestock")
s2cData.data = assert(pb.encode("S2CCuisineAccelerateRestock", data))
end
--展示玩家拥有的蔬果和肉类
function CuisineShop:CuisineShowMaterials(player, c2sData , s2cData)
c2sData.data = assert(pb.decode("C2SCuisineShowMaterials", c2sData.data ))
local data = {}
local cfgCuisineMaterial = skynet.server.gameConfig:GetPlayerAllCfg( player , "CuisineMaterial")
data.materialInfos = {}
for k ,v in pairs(player.gameData.bag) do
if dataType.GoodsType_CuisineMaterial == v.type then
table.insert(data.materialInfos,{type = v.type , id = v.id , count = v.count , materialType = cfgCuisineMaterial[v.id].materialType})
end
end
data.menuIds = {}
for k ,v in pairs(player.gameData.shop[ self.ShopType ].cuisineInfos) do
if 1 == v.status then
table.insert(data.menuIds , v.id)
end
end
data.failMenuInfos = {}
for k ,v in pairs(player.gameData.shop[ self.ShopType ].failMenuInfos) do
table.insert(data.failMenuInfos, {ids = v})
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_CuisineShowMaterials")
s2cData.data = assert(pb.encode("S2CCuisineShowMaterials", data))
end
--菜品制作
function CuisineShop:CuisineMakeCuisine(player, c2sData , s2cData)
c2sData.data = assert(pb.decode("C2SCuisineMakeCuisine", c2sData.data ))
local data = {}
local cfgCuisineMenu = skynet.server.gameConfig:GetPlayerAllCfg( player , "CuisineMenu")
local cfgCuisineSet = skynet.server.gameConfig:GetPlayerAllCfg( player , "CuisineSet")
local materialIds = c2sData.data.materialIds --所有食材的id
if #materialIds > 4 then
return
end
table.sort(materialIds) --排序一下
local finishDish = false --是否完成
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_80")
for k ,v in pairs(cfgCuisineMenu) do
if player.gameData.shop[ self.ShopType ].menuLevel >= v.menuLevel then
local isEqual = self:IsEqual(materialIds,v.ingredient)
if isEqual and 0 == player.gameData.shop[ self.ShopType ].cuisineInfos[ v.id ].status then
player.gameData.shop[ self.ShopType ].cuisineInfos[ v.id ].status = 1 --完成对应菜品
player:GiveRewardNpc(v.finishedReward, self.NPCId , eventId) --发放对应的完成奖励 奖励id npcId
finishDish = true
data.isFinish = finishDish
data.cuisineId = v.id
--判断该菜品完成后当前等级菜单是否完成
data.isNewLevel = self:FinishMenu(player)
data.isReward = true
skynet.server.levelTask:Modify( player , 79 , 1 )
skynet.server.taskListEvent:Modify( player , 79 , 1 )
--如果是隐藏料理 完成对应npc任务
if v.foodType == 2 then
skynet.server.npcTask:Modify( player , 99 , 1 , 0 , v.id )
skynet.server.taskListEvent:Modify( player , 99 , 1 )
end
break
elseif isEqual and 1 == player.gameData.shop[ self.ShopType ].cuisineInfos[ v.id ].status then
--如果是隐藏料理 完成对应npc任务
if v.foodType == 2 then
skynet.server.npcTask:Modify( player , 99 , 1 , 0 , v.id )
skynet.server.taskListEvent:Modify( player , 99 , 1 )
end
finishDish = true
data.isFinish = finishDish
data.cuisineId = v.id
data.isReward = false
break
end
end
end
--如果制作菜品失败 发送未完成奖励
if not finishDish then
for k ,v in pairs(cfgCuisineMenu) do
if 3 == v.foodType then
player:GiveRewardNpc(v.finishedReward, self.NPCId , eventId)
data.isFinish = finishDish
data.cuisineId = 0
data.isReward = true
break
end
end
--将失败的材料id存储
table.insert(player.gameData.shop[ self.ShopType ].failMenuInfos,materialIds)
else
--完成了做菜 添加对应的数据
skynet.server.bag:AddGoods(player , dataType.GoodsType_CuisineMenu , data.cuisineId , 1)
end
--消耗掉对应的材料
for k ,v in pairs(materialIds) do
skynet.server.bag:RemoveGoods(player , dataType.GoodsType_CuisineMaterial, v , 1) --移除背包中对应材料的数据
end
data.menuLevel = player.gameData.shop[ self.ShopType ].menuLevel
--套餐红点
self:SetMealRedDot( player )
s2cData.cmd = pb.enum("MsgType","CMD_S2C_CuisineMakeCuisine")
s2cData.data = assert(pb.encode("S2CCuisineMakeCuisine", data))
end
--展示玩家当前套餐
function CuisineShop:CuisineShowSetMeal(player, c2sData , s2cData)
c2sData.data = assert(pb.decode("C2SCuisineShowSetMeal", c2sData.data ))
skynet.server.msgTips:ReduceAll(player , 73)
local data = {}
local cfgCuisineSet = skynet.server.gameConfig:GetPlayerAllCfg( player , "CuisineSet")
data.setMealInfos = {}
--如果有套餐难度还未开启 判断是否可以进行刷新
for k ,v in pairs(player.gameData.shop[ self.ShopType ].mealInfos) do
if v.status == 0 then
self:RefreshSetMeal(player , v.difficulty , v.id)
end
end
for k ,v in pairs(player.gameData.shop[ self.ShopType ].mealInfos) do
--判断刷新的套餐是否可以完成
if v.status ~= 0 then
local cuisineCounts = {} --菜品信息
local finish = true
for k1 ,v1 in pairs(v.cuisineInclude) do
local count = skynet.server.bag:GetGoodsCount(player , dataType.GoodsType_CuisineMenu, v1) --获取玩家背包中该菜品的数量
if 0 == count then
finish = false
end
table.insert(cuisineCounts , {id = v1 , count = count})
end
--获取对应难度菜单的奖励id
local cuisineSetReward = 0
for k1 ,v1 in pairs(cfgCuisineSet) do
if v1.difficulty == v.difficulty then
cuisineSetReward = v1.reward
break
end
end
if finish then
v.status = 2
--增加对应红点
skynet.server.msgTips:AddNoNotice(player , 73)
table.insert(data.setMealInfos , {status = 2 , rewardId = cuisineSetReward , cuisineCounts = cuisineCounts , setId = v.id})
else
v.status = 1
table.insert(data.setMealInfos , {status = 1 , rewardId = cuisineSetReward , cuisineCounts = cuisineCounts , setId = v.id})
end
end
end
skynet.server.msgTips:SendLastTips(player , 73)
s2cData.cmd = pb.enum("MsgType","CMD_S2C_CuisineShowSetMeal")
s2cData.data = assert(pb.encode("S2CCuisineShowSetMeal", data))
end
--套餐制作
function CuisineShop:CuisineMakeSetMeal(player, c2sData , s2cData)
c2sData.data = assert(pb.decode("C2SCuisineMakeSetMeal", c2sData.data ))
local data = {}
local cfgCuisineSet = skynet.server.gameConfig:GetPlayerAllCfg( player , "CuisineSet")
data.setMealInfos = {}
local setMealId = c2sData.data.setMealId --套餐id
--判断该套餐是否可以完成
if player.gameData.shop[ self.ShopType ].mealInfos[ setMealId ].status == 2 then
local rewardId = 0
for k , v in pairs(cfgCuisineSet) do
if v.difficulty == player.gameData.shop[ self.ShopType ].mealInfos[ setMealId ].difficulty then
rewardId = v.reward
end
end
--发放对应的奖励 同时修改玩家背包和套餐相关数据
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_80")
player:GiveRewardNpc(rewardId, self.NPCId , eventId)
data.rewardId = rewardId
for k , v in pairs(player.gameData.shop[ self.ShopType ].mealInfos[ setMealId ].cuisineInclude) do
skynet.server.bag:RemoveGoods(player , dataType.GoodsType_CuisineMenu, v , 1) --移除背包中对应菜品的数据
end
--再次刷新对应套餐难度的所需菜品
self:RefreshSetMeal(player , player.gameData.shop[ self.ShopType ].mealInfos[ setMealId ].difficulty , setMealId)
-- 完成元气套餐
if player.gameData.shop[ self.ShopType ].mealInfos[ setMealId ].difficulty == 2 then
skynet.server.taskListEvent:Modify( player , 114 , 1)
elseif player.gameData.shop[ self.ShopType ].mealInfos[ setMealId ].difficulty == 3 then
skynet.server.taskListEvent:Modify( player , 115 , 1)
end
--重置对应红点
skynet.server.msgTips:ReduceAll(player , 73)
--成就任务
skynet.server.achieveTask:Modify( player , 63 , 1)
--npc任务
skynet.server.npcTask:Modify( player , 63 , 1 )
skynet.server.taskListEvent:Modify( player , 26 , 1 )
--嘉年华任务
skynet.server.taskListEvent:Modify( player ,63, 1)
player:AddExpCount( 5 )
end
--返回玩家新的套餐信息
for k ,v in pairs(player.gameData.shop[ self.ShopType ].mealInfos) do
--判断刷新的套餐是否可以完成
if v.status ~= 0 then
local cuisineCounts = {}
local finish = true
for k1 ,v1 in pairs(v.cuisineInclude) do
local count = skynet.server.bag:GetGoodsCount(player , dataType.GoodsType_CuisineMenu, v1) --获取玩家背包中该菜品的数量
if count == 0 then
finish = false
end
table.insert(cuisineCounts , {id = v1 , count = count})
end
--获取对应难度菜单的奖励id
local cuisineSetReward = 0
for k1 ,v1 in pairs(cfgCuisineSet) do
if v1.difficulty == v.difficulty then
cuisineSetReward = v1.reward
break
end
end
if finish then
v.status = 2
--增加对应红点
skynet.server.msgTips:AddNoNotice(player , 73)
table.insert(data.setMealInfos , {status = 2 , rewardId = cuisineSetReward , cuisineCounts = cuisineCounts , setId = v.id})
else
v.status = 1
table.insert(data.setMealInfos , {status = 1 , rewardId = cuisineSetReward , cuisineCounts = cuisineCounts , setId = v.id})
end
end
end
skynet.server.msgTips:SendLastTips(player , 73)
s2cData.cmd = pb.enum("MsgType","CMD_S2C_CuisineMakeSetMeal")
s2cData.data = assert(pb.encode("S2CCuisineMakeSetMeal", data))
end
--展示菜单
function CuisineShop:CuisineShowMenu(player, c2sData , s2cData)
c2sData.data = assert(pb.decode("C2SCuisineShowMenu", c2sData.data ))
local data = {}
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
local cfgCuisineMenu = skynet.server.gameConfig:GetPlayerAllCfg( player , "CuisineMenu")
local type = c2sData.data.type --1 普通菜单 2 隐藏菜单
data.type = type
if 1 == type then
data.menuInfos = {}
for k ,v in pairs(player.gameData.shop[ self.ShopType ].menuInfos) do
local cuisineInfos = {} --玩家该菜单对应的菜品数据
--只需要判断当前菜单等级的菜品
if player.gameData.shop[ self.ShopType ].menuLevel == v.level then
local finish = true
for k1 , v1 in pairs(v.cuisineIds) do
local status = player.gameData.shop[ self.ShopType ].cuisineInfos[ v1 ].status
if status == 0 then
finish = false
end
table.insert(cuisineInfos , {id = v1 , status = status})
end
if finish and v.status == 1 then
v.status = 2
table.insert(data.menuInfos, {level = v.level , status = v.status , cuisineInfos = cuisineInfos , rewardId = cfgSValue.restaurantMenuLvlReward[ v.level ]})
else
table.insert(data.menuInfos, {level = v.level , status = v.status , cuisineInfos = cuisineInfos , rewardId = cfgSValue.restaurantMenuLvlReward[ v.level ]})
end
else
for k1 , v1 in pairs(v.cuisineIds) do
local status = player.gameData.shop[ self.ShopType ].cuisineInfos[ v1 ].status
table.insert(cuisineInfos , {id = v1 , status = status})
end
table.insert(data.menuInfos, {level = v.level , status = v.status , cuisineInfos = cuisineInfos , rewardId = cfgSValue.restaurantMenuLvlReward[ v.level ]})
end
end
elseif 2 == type then
data.spMenuInfos = {}
for k,v in pairs(player.gameData.shop[ self.ShopType ].cuisineInfos) do
if 2 == cfgCuisineMenu[ v.id ].foodType then
table.insert(data.spMenuInfos , {id = v.id,status = v.status})
end
end
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_CuisineShowMenu")
s2cData.data = assert(pb.encode("S2CCuisineShowMenu", data))
end
--领取菜单奖励
function CuisineShop:CuisineMenuAward(player, c2sData , s2cData)
c2sData.data = assert(pb.decode("C2SCuisineMenuAward", c2sData.data ))
local data = {}
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
local level = c2sData.data.level --获取的菜单Id
if player.gameData.shop[ self.ShopType ].menuInfos[ level ].status == 2 then
--发放对应的奖励
local rewardId = cfgSValue.restaurantMenuLvlReward[ level ]
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_75")
player:GiveReward(rewardId , eventId , 1)
data.rewardId = rewardId
--修改玩家相关数据
player.gameData.shop[ self.ShopType ].menuInfos[ level ].status = 3
--领取后消除红点
skynet.server.msgTips:Reduce(player , 59)
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_CuisineMenuAward")
s2cData.data = assert(pb.encode("S2CCuisineMenuAward", data))
end
--一键制作
function CuisineShop:CuisineMassProduce(player, c2sData , s2cData)
c2sData.data = assert(pb.decode("C2SCuisineMassProduce", c2sData.data ))
local data = {}
local cuisineId = c2sData.data.cuisineId --制作菜品id
local number = c2sData.data.number --制作菜品数量
local cfgCuisineMenu = skynet.server.gameConfig:GetPlayerCurCfg( player , "CuisineMenu" , cuisineId)
--菜单3级才开启一键制作
if player.gameData.shop[ self.ShopType ].menuLevel >= 3 then
--判断玩家对应材料是否足够
local canDoCuisine = true --是否可以完成做菜
for k , v in pairs(cfgCuisineMenu.ingredient) do
local count = skynet.server.bag:GetGoodsCount( player , dataType.GoodsType_CuisineMaterial, v ) --获取玩家背包中该材料的数量
if count < number then
canDoCuisine = false
break
end
end
--如果可以完成 扣除材料增加菜品
if canDoCuisine then
for k , v in pairs(cfgCuisineMenu.ingredient) do
skynet.server.bag:RemoveGoods( player , dataType.GoodsType_CuisineMaterial, v , number)
end
skynet.server.bag:AddGoods( player , dataType.GoodsType_CuisineMenu , cuisineId , number)
--套餐红点
self:SetMealRedDot( player )
--返回客户端需要的数据暂定
data.isFinish = true
data.cuisineId = cuisineId
--如果是隐藏料理 完成对应npc任务
if cfgCuisineMenu.foodType == 2 then
skynet.server.npcTask:Modify( player , 99 , 1 , 0 , cuisineId )
skynet.server.taskListEvent:Modify( player , 99 , 1)
end
else
s2cData.code = errorInfo.ErrorCode.NoEnoughMaterial
end
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_CuisineMassProduce")
s2cData.data = assert(pb.encode("S2CCuisineMassProduce", data))
end
--菜单是否完成
function CuisineShop:FinishMenu(player)
--玩家当前的菜单等级 和菜单所对应的菜品id
local level = player.gameData.shop[ self.ShopType ].menuLevel
local cuisineIds = player.gameData.shop[ self.ShopType ].menuInfos[ level ].cuisineIds
local finish = true
for k ,v in pairs(cuisineIds) do
if 0 == player.gameData.shop[ self.ShopType ].cuisineInfos[ v ].status then
finish = false
break
end
end
--如果该菜单已经完成了 修改玩家对应数据
if finish and 1 == player.gameData.shop[ self.ShopType ].menuInfos[ level ].status then
player.gameData.shop[ self.ShopType ].menuInfos[ level ].status = 2 --该菜单状态修改为已完成
if level < 4 then
player.gameData.shop[ self.ShopType ].menuLevel = level + 1 --菜单当前等级加1
player.gameData.shop[ self.ShopType ].menuInfos[ player.gameData.shop[ self.ShopType ].menuLevel ].status = 1 --菜单相关状态修改
end
--到达二级过后刷新套餐
if 2 == player.gameData.shop[ self.ShopType ].menuLevel then
for k ,v in pairs(player.gameData.shop[ self.ShopType ].mealInfos) do
if v.status == 0 then
self:RefreshSetMeal(player , v.difficulty , v.id) --刷新对应难度的套餐
end
end
skynet.server.npcTask:Modify( player , 96 , 2 )
skynet.server.taskListEvent:Modify( player , 96 , 2 )
else
skynet.server.npcTask:Modify( player , 96 , 1 )
skynet.server.taskListEvent:Modify( player , 96 , 1 )
end
--解锁菜单对应的菜地
self:PlotUnlock(player)
--将玩家的菜单等级存入redis中 提供给送礼进行使用
skynet.server.personal:SetDetail( player.gameData.partner.id ,"cuisineLevel", player.gameData.shop[ self.ShopType ].menuLevel)
--添加对应红点
skynet.server.msgTips:Add(player , 59)
--发送最新的料理店信息给客户端
local s2cData = {}
self:CuisineShow(player , {} ,s2cData)
local data = assert(pb.decode("S2CCuisineShow", s2cData.data))
skynet.server.gameServer:SendMsgToUser(player.userId, "CMD_S2C_CuisineShow", data)
end
return finish
end
--土块初始化
function CuisineShop:InitPlot(player, plotId)
player.gameData.shop[ self.ShopType ].plotInfos[ plotId ].status = 1
player.gameData.shop[ self.ShopType ].plotInfos[ plotId ].matId = 0
player.gameData.shop[ self.ShopType ].plotInfos[ plotId ].nextStatusTime = 0
player.gameData.shop[ self.ShopType ].plotInfos[ plotId ].startPlantTime = 0
end
--食材进货刷新 取消
function CuisineShop:RefreshFI(player)
local level = player.gameData.shop[ self.ShopType ].menuLevel
local cfgCuisineMaterial = skynet.server.gameConfig:GetPlayerAllCfg( player , "CuisineMaterial")
--获取该玩家所有可以进货的食材
local allFI = {}
for k ,v in pairs( cfgCuisineMaterial ) do
if v.menuLevel <= level and v.materialType == 2 then
table.insert(allFI , {type = dataType.GoodsType_CuisineMaterial , id = v.id , count = v.gainNum})
end
end
--每次进货物品
local getFI = {} --玩家得到的货物
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
local stockNum = cfgSValue.restaurantMeatType
for i=1,stockNum,1 do
local count = math.random(1,#allFI)
--添加到获取表中 同时防止进货物品重复
table.insert( getFI , allFI[count])
table.remove( allFI , count)
end
return getFI
end
--套餐刷新
function CuisineShop:RefreshSetMeal(player, type, setId)
local cfgCuisineSet = skynet.server.gameConfig:GetPlayerAllCfg( player , "CuisineSet")
--本次刷新套餐难度需要的菜品数量
local needCuisineNum = 0
--本次刷新套餐难度中包含的菜品
local setIncludeMenus = {}
for k , v in pairs(cfgCuisineSet) do
if v.difficulty == type then
needCuisineNum = v.cuisineNum
setIncludeMenus = v.cuisineInclude
break
end
end
local canDoMenus = {} --存储玩家该套餐难度可以做的菜
local priDoMenus = {} --存储玩家该套餐难度优先做的菜
for k , v in pairs(setIncludeMenus) do
local cuisineInfo = player.gameData.shop[ self.ShopType ].cuisineInfos[v]
if cuisineInfo.status == 1 and cuisineInfo.setChoiceCount == 0 then
table.insert(priDoMenus,cuisineInfo.id)
elseif cuisineInfo.status == 1 then
table.insert(canDoMenus,cuisineInfo.id)
end
end
--判断是否可以进行刷新
if #canDoMenus + #priDoMenus < needCuisineNum then
return
end
--开始刷新本次套餐的对应菜品
player.gameData.shop[ self.ShopType ].mealInfos[setId].status = 1
player.gameData.shop[ self.ShopType ].mealInfos[setId].cuisineInclude = {}
if #priDoMenus >= needCuisineNum then
--优先做菜的数量比需要的数量多时 直接在优先里面进行随机
for k=1,needCuisineNum,1 do
local key = math.random(1,#priDoMenus)
table.insert(player.gameData.shop[ self.ShopType ].mealInfos[setId].cuisineInclude,priDoMenus[key])
--修改对应的菜品被套餐选中的次数
player.gameData.shop[self.ShopType].cuisineInfos[priDoMenus[key]].setChoiceCount = 1
--移除对应的菜品 防止刷新到同一个
table.remove(priDoMenus , key)
end
elseif #priDoMenus < needCuisineNum and #priDoMenus > 0 then
--优先做菜的数量比需要的数量少但是比0大时 直接选择优先的菜,剩余的菜从可以做的菜里面随机
for k , v in pairs(priDoMenus) do
table.insert(player.gameData.shop[ self.ShopType ].mealInfos[setId].cuisineInclude,v)
player.gameData.shop[self.ShopType].cuisineInfos[v].setChoiceCount = 1
end
local residueCount = needCuisineNum - #priDoMenus --还需要刷新的菜品数量
for k=1,residueCount,1 do
local key = math.random(1,#canDoMenus)
table.insert(player.gameData.shop[ self.ShopType ].mealInfos[setId].cuisineInclude,canDoMenus[key])
--修改对应的菜品被套餐选中的次数
player.gameData.shop[self.ShopType].cuisineInfos[canDoMenus[key]].setChoiceCount = player.gameData.shop[self.ShopType].cuisineInfos[canDoMenus[key]].setChoiceCount + 1
--移除对应的菜品 防止刷新到同一个
table.remove(canDoMenus , key)
end
elseif #priDoMenus == 0 then
--没有优先做菜时 直接在可以做的菜里面进行随机
for k=1,needCuisineNum,1 do
local key = math.random(1,#canDoMenus)
table.insert(player.gameData.shop[ self.ShopType ].mealInfos[setId].cuisineInclude,canDoMenus[key])
--修改对应的菜品被套餐选中的次数
player.gameData.shop[self.ShopType].cuisineInfos[canDoMenus[key]].setChoiceCount = player.gameData.shop[self.ShopType].cuisineInfos[canDoMenus[key]].setChoiceCount + 1
--移除对应的菜品 防止刷新到同一个
table.remove(canDoMenus , key)
end
end
end
--套餐刷新(旧)
function CuisineShop:OldRefreshSetMeal(player,type)
local cfgCuisineSet = skynet.server.gameConfig:GetPlayerAllCfg( player , "CuisineSet")
local setMealInfos = {} --setMealInfos存储还可以进行刷新的套餐
local count = 2 --存储还需要刷新的套餐数量
local number = 9999 --存储套餐最小的完成次数
if 1 ~= type then
count = 1
end
local canDoMenu = {} --存储玩家已经做过的菜
for k ,v in pairs(player.gameData.shop[ self.ShopType ].cuisineInfos) do
if 1 == v.status then
canDoMenu[ v.id ] = v.id
end
end
--存储玩家可以完成的套餐
for k ,v in pairs(cfgCuisineSet) do
if v.difficulty == type then
local canFinish = true
for k1 ,v1 in pairs(v.cuisineInclude) do
if canDoMenu[v1] == nil then
canFinish = false
end
end
if canFinish then
--使用套餐id作为key
setMealInfos[ v.id ] = {}
setMealInfos[ v.id ].id = v.id
end
end
end
--判断是否还有可以进行刷新的套餐
if next(setMealInfos) == nil then
return
end
for k ,v in pairs(player.gameData.shop[ self.ShopType ].mealInfos) do
if 0 == v.status and type == cfgCuisineSet[ v.id ].difficulty then
if v.number < number and setMealInfos[v.id] ~= nil then
number = v.number
setMealInfos[ v.id ].number = v.number
end
elseif (1 == v.status or 2 == v.status) and type == cfgCuisineSet[ v.id ].difficulty then
count = count - 1
elseif 3 == v.status and type == cfgCuisineSet[ v.id ].difficulty then
--完成了的套餐将其status置为0 且完成次数加1
v.status = 0
v.number = v.number + 1
end
end
--根据规则进行刷新套餐
local nowSetMealInfos = {} --存储符合本次刷新条件的简单套餐
if count > 0 and 1 == type then
for k , v in pairs(setMealInfos) do
if v.number == number then
table.insert(nowSetMealInfos , v.id)
end
end
if #nowSetMealInfos == 0 then
return
end
--进行刷新套餐
if #nowSetMealInfos >= count then
--刷新套餐数量大于0 同时满足刷新的套餐数量大于需要的套餐数量
for i=1 ,count ,1 do
local key = math.random(1,#nowSetMealInfos)
local setMealId = nowSetMealInfos[ key ] --随机的套餐id
player.gameData.shop[ self.ShopType ].mealInfos[ setMealId ].status = 1 --修改对应套餐的状态
table.remove(nowSetMealInfos , key) --移除本次刷新套餐中的数据 防止刷新到同一个
end
elseif #nowSetMealInfos < count then
local needCount = count - #nowSetMealInfos --还需刷新的套餐数量
for i=1 ,count - needCount ,1 do
local key = math.random(1,#nowSetMealInfos)
local setMealId = nowSetMealInfos[ key ] --随机的套餐id
player.gameData.shop[ self.ShopType ].mealInfos[ setMealId ].status = 1 --修改对应套餐的状态
table.remove(nowSetMealInfos , key) --移除本次刷新套餐中的数据 防止刷新到同一个
end
--再访问一次本方法
self:OldRefreshSetMeal(player)
end
elseif count > 0 and 1 ~= type then
for k , v in pairs(setMealInfos) do
if v.number == number then
table.insert(nowSetMealInfos , v.id)
end
end
if #nowSetMealInfos == 0 then
return
end
--进行刷新套餐 因为只有一个不存在满足条件的套餐数量不够
for i=1 ,count ,1 do
local key = math.random(1,#nowSetMealInfos)
local setMealId = nowSetMealInfos[ key ] --随机的套餐id
player.gameData.shop[ self.ShopType ].mealInfos[ setMealId ].status = 1 --修改对应套餐的状态
table.remove(nowSetMealInfos , key) --移除本次刷新套餐中的数据 防止刷新到同一个
end
end
end
--判断食材是否符合菜品所需食材
function CuisineShop:IsEqual(a,b)
local _a,_b = 0, 0
for _ak, _av in pairs(a) do
_a = _a + 1
end
for _bk, _bv in pairs(b) do
_b = _b + 1
end
if _a ~= _b then
return false
end
for a_k, a_v in pairs(a) do
if a_v ~= b[a_k] then
return false
end
end
return true
end
--获取到成熟状态的所有时间 植物id 植物当前状态 下个状态的时间 月卡时间系数
function CuisineShop:GetAllStatusTime( player , plantId , status , nextStatusTime , timeCoefficient)
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
local growTime = cfgSValue.plantGrowTimeRatio
local curCfgPlant = skynet.server.gameConfig:GetPlayerCurCfg( player , "Plant", plantId )
local allStatusTime = {}
--往allStatusTime 插入对应数据
local count = status
allStatusTime[ count ] = {}
allStatusTime[ count ].status = status
allStatusTime[ count ].nextStatusTime = nextStatusTime
for i = status + 1 , 4 , 1 do
--((出售价格 * 系数) = 分钟数) * 60秒 = 所需要的秒数 购买了月卡的话缩短时间
if dataType.FlowerpotStatus_Sprout == i then --发芽
local nextTime = allStatusTime[i-1].nextStatusTime + math.ceil(( curCfgPlant.coin * growTime[2]) * 60 * timeCoefficient)
count = count + 1
allStatusTime[ count ] = {}
allStatusTime[ count ].status = i
allStatusTime[ count ].nextStatusTime = nextTime
elseif dataType.FlowerpotStatus_Bud == i then --花苞
local nextTime = allStatusTime[i-1].nextStatusTime + math.ceil(( curCfgPlant.coin * growTime[3]) * 60 * timeCoefficient)
count = count + 1
allStatusTime[ count ] = {}
allStatusTime[ count ].status = i
allStatusTime[ count ].nextStatusTime = nextTime
end
end
return allStatusTime
end
--获取当前状态和下一个状态的时间
function CuisineShop:GetNextStatusTime( player , plantId , startPlantTime , timeCoefficient)
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
local growTime = cfgSValue.plantGrowTimeRatio
local nextStatusTime = startPlantTime
local curCfgPlant = skynet.server.gameConfig:GetPlayerCurCfg( player , "Plant", plantId )
local status = dataType.FlowerpotStatus_Seed --植物的状态最起码是种子
for k , v in pairs(growTime) do
--开始种植的时间 + 下个状态的所需时间 ((出售价格 * 系数) = 分钟数) * 60秒 = 所需要的秒数
nextStatusTime = nextStatusTime + math.ceil(( curCfgPlant.coin * v ) * 60 * timeCoefficient)
if skynet.GetTime() < nextStatusTime then
return status,nextStatusTime
else
status = status + 1
end
end
--没有返回则代表植物已经成熟了
return status,0
end
--获取好友送礼 刷新相关数据
function CuisineShop:RefreshData( player, goodsId)
local cfgOneCuisineMenu = skynet.server.gameConfig:GetPlayerCurCfg( player , "CuisineMenu" , goodsId )
--如果是隐藏料理 完成对应npc任务
if cfgOneCuisineMenu.foodType == 2 then
skynet.server.npcTask:Modify( player , 99 , 1 , 0 , goodsId )
skynet.server.taskListEvent:Modify( player , 99 , 1)
end
end
--完成做菜后 判断套餐红点
function CuisineShop:SetMealRedDot( player )
if player.gameData.shop[ self.ShopType ].menuLevel >= 2 then --套餐可完成的红点
for k ,v in pairs(player.gameData.shop[ self.ShopType ].mealInfos) do
--判断刷新的套餐是否可以完成
if v.status ~= 0 then
local finish = true
for k1 ,v1 in pairs(v.cuisineInclude) do
local count = skynet.server.bag:GetGoodsCount(player , dataType.GoodsType_CuisineMenu, v1) --获取玩家背包中该菜品的数量
if 0 == count then
finish = false
end
end
if finish then
v.status = 2
--增加对应红点
skynet.server.msgTips:Add(player , 73)
end
end
end
end
end
--检查玩家菜地是否能够解锁
function CuisineShop:PlotUnlock( player )
local plotInfos = player.gameData.shop[ self.ShopType ].plotInfos
local menuLevel = player.gameData.shop[ self.ShopType ].menuLevel --玩家菜单等级
--菜地plot对应菜单解锁等级
local foodShopPlotUnlock = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue").foodShopPlotUnlock
for k , v in pairs(foodShopPlotUnlock) do
local arr = skynet.server.common:Split(v , "_")
arr[1],arr[2] = tonumber(arr[1]),tonumber(arr[2])
if plotInfos[ arr[1] ].status == 0 and menuLevel >= arr[2] then
plotInfos[ arr[1] ].status = 1
end
end
end
--根据种植时间获取植物所有生长时间
function CuisineShop:GetAllTime( player , startPlantTime , matId )
local timeCoefficient = skynet.server.store:GetTimeCoefficient(player , 3) --月卡权益
local growTime = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue").plantGrowTimeRatio
local cfgCuisineMaterial = skynet.server.gameConfig:GetPlayerAllCfg( player , "CuisineMaterial")
local plantId = cfgCuisineMaterial[matId].plantId
local curCfgPlant = skynet.server.gameConfig:GetPlayerCurCfg( player , "Plant", plantId )
return startPlantTime + math.ceil(( curCfgPlant.coin * (growTime[1]+growTime[2]+growTime[3])) * 60 * timeCoefficient)
end
skynet.server.cuisineShop = CuisineShop
return CuisineShop