HomeServer/Server/AllServer/GameServer/Group/GroupBMExchange.lua

221 lines
11 KiB
Lua
Raw Normal View History

2024-11-20 15:41:09 +08:00
local skynet = require "skynet"
local oo = require "Class"
local pb = require "pb"
local log = require "Log"
local json =require "json"
local errorInfo = require "ErrorInfo"
local dataType = require "DataType"
local redisKeyUrl = require "RedisKeyUrl"
local group = require "Group"
local GroupBMExchange = oo.class(group)
GroupBMExchange.Timber = 1
GroupBMExchange.Cement = 2
GroupBMExchange.Rebar = 3
--建材兑换 界面显示 Building materials 建材
function GroupBMExchange:Show( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SGroupBMShow", c2sData.data ))
local data = {}
data.bmInfos = {}
data.goodsInfos = {}
local activityId, startTime, endTime , id = skynet.server.activity:GetActivityInfo( player , dataType.ActivityType_GroupDoubleMaterial )
data.activityId = id
local pageId = c2sData.data.pageId
data.bmInfos,data.goodsInfos = self:OwnBMData(player,pageId)
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GroupBMShow")
s2cData.data = assert(pb.encode("S2CGroupBMShow", data))
end
--建材兑换 兑换
function GroupBMExchange:Exchange( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SGroupBMExchange", c2sData.data ))
local data = {}
local cfgFishType = skynet.server.gameConfig:GetPlayerAllCfg( player , "FishType")
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
local cfgCuisineMenu = skynet.server.gameConfig:GetPlayerAllCfg( player , "CuisineMenu")
local cfgCoffeeType = skynet.server.gameConfig:GetPlayerAllCfg( player , "CoffeeType")
data.bmInfos = {}
data.goodsInfos = {}
local pageId = c2sData.data.pageId
local goodsType = c2sData.data.goodsType
local goodsId = c2sData.data.goodsId
local isExchangeSuc = false --是否兑换成功
local activityId = skynet.server.activity:GetActivityInfo( player , dataType.ActivityType_GroupDoubleMaterial ) --双倍兑换活动是否开启
--根据pageId和goodsType goodsId 确定应增加的建材和减少的物品
if self.Timber == pageId and goodsType == dataType.GoodsType_Fish then
--获取玩家该鱼的数量和等级
local ownCount = skynet.server.bag:GetGoodsCount(player , dataType.GoodsType_Fish, goodsId)
local level = cfgFishType[goodsId].fishType
--需要的物品数量
local needCount = cfgSValue.communityMaterialFish[ level ]
if ownCount >= needCount then
--扣除对应的物品
skynet.server.bag:RemoveGoods(player , dataType.GoodsType_Fish, goodsId , needCount)
--发放对应物品
local exchangeCount = cfgSValue.communityMaterialExchange
--双倍活动开启则乘一个奖励系数
if activityId > 0 then
exchangeCount = exchangeCount * cfgSValue.communityMaterialDouble
end
skynet.server.bag:AddGoods(player , dataType.GoodsType_Prop , 8 , exchangeCount)
data.award = {type = dataType.GoodsType_Prop, id = 8, count = exchangeCount}
isExchangeSuc = true
end
elseif self.Cement == pageId and goodsType == dataType.GoodsType_CuisineMenu then
--获取玩家该菜品的数量和等级
local ownCount = skynet.server.bag:GetGoodsCount(player , dataType.GoodsType_CuisineMenu, goodsId)
local level = cfgCuisineMenu[goodsId].menuLevel
if 0 == level and 2 == cfgCuisineMenu[goodsId].foodType then
level = 5
end
--需要的物品数量
local needCount = 0
if level > 0 then
needCount = needCount + cfgSValue.communityMaterialFood[ level ]
else
return
end
if ownCount >= needCount then
--扣除对应的物品
skynet.server.bag:RemoveGoods(player , dataType.GoodsType_CuisineMenu, goodsId , needCount)
--发放对应物品
local exchangeCount = cfgSValue.communityMaterialExchange
--双倍活动开启则乘一个奖励系数
if activityId > 0 then
exchangeCount = exchangeCount * cfgSValue.communityMaterialDouble
end
skynet.server.bag:AddGoods(player , dataType.GoodsType_Prop , 9 , exchangeCount)
data.award = {type = dataType.GoodsType_Prop, id = 9, count = exchangeCount}
isExchangeSuc = true
end
elseif self.Rebar == pageId and goodsType == dataType.GoodsType_Coffee then
--获取玩家该咖啡的数量和等级
local ownCount = skynet.server.bag:GetGoodsCount(player , dataType.GoodsType_Coffee, goodsId)
local level = cfgCoffeeType[goodsId].rarity
--需要的物品数量
local needCount = cfgSValue.communityMaterialCoffee[ level ]
if ownCount >= needCount then
--扣除对应的物品
skynet.server.bag:RemoveGoods(player , dataType.GoodsType_Coffee, goodsId , needCount)
--发放对应物品
local exchangeCount = cfgSValue.communityMaterialExchange
--双倍活动开启则乘一个奖励系数
if activityId > 0 then
exchangeCount = exchangeCount * cfgSValue.communityMaterialDouble
end
skynet.server.bag:AddGoods(player , dataType.GoodsType_Prop , 10 , exchangeCount)
data.award = {type = dataType.GoodsType_Prop, id = 10, count = exchangeCount}
isExchangeSuc = true
end
end
if isExchangeSuc then
--通行证任务
--在家园完成%次建材兑换
skynet.server.taskListEvent:Modify( player , 119 , 1 )
end
data.bmInfos,data.goodsInfos = self:OwnBMData(player,pageId)
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GroupBMExchange")
s2cData.data = assert(pb.encode("S2CGroupBMExchange", data))
end
--家园建设具体界面展示
function GroupBMExchange:ConstructShow( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SGroupBMConstructShow", c2sData.data ))
local data = {}
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GroupBMConstructShow")
s2cData.data = assert(pb.encode("S2CGroupBMConstructShow", data))
end
--家园建设 建材贡献
function GroupBMExchange:ConstructContribute( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SGroupBMConstructContribute", c2sData.data ))
local data = {}
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GroupBMConstructContribute")
s2cData.data = assert(pb.encode("S2CGroupBMConstructContribute", data))
end
--玩家拥有的建材 鱼 咖啡 料理
function GroupBMExchange:OwnBMData( player , pageId )
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
local cfgFishType = skynet.server.gameConfig:GetPlayerAllCfg( player , "FishType")
local cfgCuisineMenu = skynet.server.gameConfig:GetPlayerAllCfg( player , "CuisineMenu")
local cfgCoffeeType = skynet.server.gameConfig:GetPlayerAllCfg( player , "CoffeeType")
--存储玩家相关数据
local bmInfos = {}
local goodsInfos = {} --存储满足兑换数量的物品
--木材
local timberContent = skynet.server.bag:GetGoodsCount(player , dataType.GoodsType_Prop, 8)
table.insert(bmInfos,{type = dataType.GoodsType_Prop , id = 8 , count = timberContent})
--水泥
local cementContent = skynet.server.bag:GetGoodsCount(player , dataType.GoodsType_Prop, 9)
table.insert(bmInfos,{type = dataType.GoodsType_Prop , id = 9 , count = cementContent})
--钢筋
local rebarContent = skynet.server.bag:GetGoodsCount(player , dataType.GoodsType_Prop, 10)
table.insert(bmInfos,{type = dataType.GoodsType_Prop , id = 10 , count = rebarContent})
--如果没有页签id 直接返回玩家拥有的建材信息
if not pageId then
return bmInfos
end
--根据pageId获取对应的物品
if self.Timber == pageId then
--鱼
local needCount = cfgSValue.communityMaterialFish
for k ,v in pairs( cfgFishType ) do
local level = v.fishType
local count = skynet.server.bag:GetGoodsCount(player , dataType.GoodsType_Fish, v.id)
--如果物品的数量大于交易所需要的数量 则添加进返回数据中
if level > 0 then
if count > 0 then
table.insert(goodsInfos , {type = dataType.GoodsType_Fish,id = v.id,count = count,useCount = needCount[level]})
else
table.insert(goodsInfos , {type = dataType.GoodsType_Fish,id = v.id,count = 0,useCount = needCount[level]})
end
end
end
elseif self.Cement == pageId then
--菜
local needCount = cfgSValue.communityMaterialFood
for k ,v in pairs( cfgCuisineMenu ) do
local level = v.menuLevel
--隐藏料理消耗的数量索引为5
if 0 == level and 2 == v.foodType then
level = 5
end
local count = skynet.server.bag:GetGoodsCount(player , dataType.GoodsType_CuisineMenu, v.id)
--如果物品的数量大于交易所需要的数量 则添加进返回数据中
if level > 0 then
--table.insert(goodsInfos , {type = dataType.GoodsType_CuisineMenu,id = v.id,count = count,useCount = needCount[level]})
if count > 0 then
table.insert(goodsInfos , {type = dataType.GoodsType_CuisineMenu,id = v.id,count = count,useCount = needCount[level]})
else
table.insert(goodsInfos , {type = dataType.GoodsType_CuisineMenu,id = v.id,count = 0,useCount = needCount[level]})
end
end
end
elseif self.Rebar == pageId then
--咖啡
local needCount = cfgSValue.communityMaterialCoffee
for k ,v in pairs( cfgCoffeeType ) do
local level = v.rarity
local count = skynet.server.bag:GetGoodsCount(player , dataType.GoodsType_Coffee, v.id)
--如果物品的数量大于交易所需要的数量 则添加进返回数据中
if level > 0 then
--table.insert(goodsInfos , {type = dataType.GoodsType_Coffee,id = v.id,count = count,useCount = needCount[level]})
if count > 0 then
table.insert(goodsInfos , {type = dataType.GoodsType_Coffee,id = v.id,count = count,useCount = needCount[level]})
else
table.insert(goodsInfos , {type = dataType.GoodsType_Coffee,id = v.id,count = 0,useCount = needCount[level]})
end
end
end
end
return bmInfos,goodsInfos
end
skynet.server.groupBMExchange = GroupBMExchange
return GroupBMExchange