424 lines
13 KiB
Lua
424 lines
13 KiB
Lua
local skynet = require "skynet"
|
||
local oo = require "Class"
|
||
local log = require "Log"
|
||
local protoc = require "protoc"
|
||
local pb = require "pb"
|
||
local json =require "json"
|
||
local dataType = require "DataType"
|
||
local GameConfig = oo.class()
|
||
|
||
skynet.cfgRoomCenter = {}
|
||
skynet.cfgRoomCenter.CheckRoomTime = 30 --多少时间检测一下所有房间
|
||
skynet.cfgRoomCenter.MaxTimeNoStart = 30 --最长多少秒不开始游戏(秒)
|
||
skynet.cfgRoomCenter.MaxTimeGame = 900 --一局游戏最长时间
|
||
|
||
function GameConfig:GetClusterServerConfig( name )
|
||
for k, v in pairs(skynet.server.gameConfig.ClusterServerConfig) do
|
||
if name == v.serverName then
|
||
return v
|
||
end
|
||
end
|
||
end
|
||
|
||
function GameConfig:LoadConfig()
|
||
log.info("开始加载配置")
|
||
local cmd = string.format("find %s -name *.config","Server")
|
||
local fp = io.popen(cmd)
|
||
for filename in fp:lines() do
|
||
self:LoadOneConfig(filename)
|
||
end
|
||
fp:close()
|
||
log.info("结束加载配置")
|
||
end
|
||
|
||
function GameConfig:LoadOneConfig(filename)
|
||
local newModule = {}
|
||
if filename then
|
||
local f = assert(io.open(filename))
|
||
local source = f:read "*a"
|
||
f:close()
|
||
assert(load(source, "@"..filename, "t", newModule))()
|
||
end
|
||
|
||
for name,config in pairs(newModule) do
|
||
GameConfig[name] = config
|
||
local str = string.format("加载配置文件 %s 变量名 %s",filename, name)
|
||
log.info(str)
|
||
end
|
||
end
|
||
|
||
|
||
function GameConfig:LoadJson()
|
||
log.info("开始加载JSON配置")
|
||
local cmd = string.format("find %s -name *.json","Server")
|
||
local fp = io.popen(cmd)
|
||
for filename in fp:lines() do
|
||
self:LoadOneJson(filename)
|
||
end
|
||
|
||
--转换染色家具
|
||
--[[
|
||
self.oldFruniture = {} -- 保存下需要改动的旧家具ID,方便后面转换老用户的数据
|
||
for k, v in pairs(self.Furniture) do
|
||
--家具配置对染色家具ID进行转换
|
||
if 2 == #v.dyeFurTrans and 0 == math.floor( v.id /1000000 ) then
|
||
local oldId = v.id
|
||
v.id = v.dyeFurTrans[2] * 100000 + v.dyeFurTrans[1];
|
||
self.oldFruniture [ oldId ] = v.id
|
||
end
|
||
end
|
||
|
||
for k1, v1 in pairs(self.FurnitureBook) do
|
||
for k2, v2 in pairs(v1.furnitrueId) do
|
||
local newId = skynet.server.gameConfig.oldFruniture[ v2 ]
|
||
if newId then
|
||
v1.furnitrueId[ k2 ] = newId
|
||
end
|
||
end
|
||
end
|
||
]]
|
||
|
||
fp:close()
|
||
log.info("结束加载JSON配置")
|
||
end
|
||
|
||
function GameConfig:LoadOneJson(filename)
|
||
if filename then
|
||
local f = assert(io.open(filename))
|
||
local source = f:read("*all")
|
||
f:close()
|
||
local startPos = string.find(filename ,"GameConfig/") + #"GameConfig/"
|
||
local endPos = string.find(filename ,"_" ) - 1
|
||
local newFileName = string.sub(filename,startPos ,endPos)
|
||
if "SValue" ==newFileName then
|
||
GameConfig[ newFileName ] = json:decode(source)
|
||
else
|
||
GameConfig[ newFileName ] = json:decode(source)["items"]
|
||
end
|
||
log.info(string.format("加载配置文件 %s 变量名 %s",filename, newFileName))
|
||
|
||
end
|
||
end
|
||
|
||
--载入PB协议
|
||
function GameConfig:LoadProto()
|
||
log.info("开始加载ProtoBuf")
|
||
local cmd = string.format("find %s -name *.proto","Server")
|
||
local fp = io.popen(cmd)
|
||
for filename in fp:lines() do
|
||
self:LoadOneProto(filename)
|
||
end
|
||
fp:close()
|
||
|
||
log.info("结束加载ProtoBuf")
|
||
end
|
||
|
||
function GameConfig:LoadOneProto(filename)
|
||
local newModule = {}
|
||
if filename then
|
||
local f = assert(io.open(filename))
|
||
log.info("加载ProtoBuf文件" , filename)
|
||
local source = f:read "*a"
|
||
f:close()
|
||
protoc:load(source)
|
||
end
|
||
end
|
||
|
||
--获取当前服的集群配置
|
||
function GameConfig:GetCurClusterServerCfg( id )
|
||
for k, v in pairs( self.ClusterServerConfig ) do
|
||
if id == v.serverId then
|
||
return v
|
||
end
|
||
end
|
||
return nil
|
||
end
|
||
|
||
--获取当前植物的配置
|
||
function GameConfig:GetCurPlantCfg( id )
|
||
for k, v in pairs( self.Plant ) do
|
||
if id == v.id then
|
||
return v
|
||
end
|
||
end
|
||
return nil
|
||
end
|
||
--获取当前家具配置
|
||
function GameConfig:GetCurFurnitureCfg( id )
|
||
--将染色的家具id转化为正常id
|
||
id = self:RestoreGeneralID( id )
|
||
|
||
for k, v in pairs( self.Furniture ) do
|
||
if id == v.id then
|
||
return v
|
||
end
|
||
end
|
||
return nil
|
||
end
|
||
|
||
--将染色的家具id转化为正常id
|
||
function GameConfig:RestoreGeneralID( id )
|
||
if id >= 100000 then
|
||
id = id % 100000
|
||
end
|
||
return id
|
||
end
|
||
|
||
--获取当前装修配置
|
||
function GameConfig:GetCurDecorationCfg( id )
|
||
for k, v in pairs( self.Decoration ) do
|
||
if id == v.id then
|
||
return v
|
||
end
|
||
end
|
||
return nil
|
||
end
|
||
|
||
|
||
--获取最大进度值
|
||
function GameConfig:GetTaskConfig( id )
|
||
local cfgTask = skynet.server.gameConfig.Task --任务配置
|
||
for k, v in pairs( cfgTask ) do
|
||
if id == v.id then
|
||
return v
|
||
end
|
||
end
|
||
return nil
|
||
end
|
||
|
||
--获取色彩配置
|
||
function GameConfig:GetColorCfg( id )
|
||
local cfg = skynet.server.gameConfig.Color
|
||
for k, v in pairs( cfg ) do
|
||
if id == v.id then
|
||
return v
|
||
end
|
||
end
|
||
return nil
|
||
end
|
||
|
||
--获取方案配置
|
||
function GameConfig:GetSchemeCfg( id )
|
||
local cfg = skynet.server.gameConfig.Scheme
|
||
for k, v in pairs( cfg ) do
|
||
if id == v.combineID then
|
||
return v
|
||
end
|
||
end
|
||
return nil
|
||
end
|
||
|
||
--获取植物商品的配置
|
||
function GameConfig:GetPlantCfg( goodsId )
|
||
local cfgPlant = skynet.server.gameConfig.Plant
|
||
for k, v in pairs( cfgPlant ) do
|
||
if goodsId == v.id then
|
||
return v
|
||
end
|
||
end
|
||
return nil
|
||
end
|
||
|
||
--获取装修的配置
|
||
function GameConfig:GetDecorationCfg( goodsId )
|
||
local cfgPlant = skynet.server.gameConfig.Decoration
|
||
for k, v in pairs( cfgPlant ) do
|
||
if goodsId == v.id then
|
||
return v
|
||
end
|
||
end
|
||
return nil
|
||
end
|
||
|
||
--获取手机消息
|
||
function GameConfig:GetPhoneMsgCfg( msgId )
|
||
local cfgPhone = skynet.server.gameConfig.PhoneMsg
|
||
for k, v in pairs( cfgPhone ) do
|
||
if msgId == v.id then
|
||
return v
|
||
end
|
||
end
|
||
return nil
|
||
end
|
||
|
||
--获取手机消息
|
||
function GameConfig:GetLevelCfg( level )
|
||
local cfgLevel = skynet.server.gameConfig.Level
|
||
for k, v in pairs( cfgLevel ) do
|
||
if level == v.level then
|
||
return v
|
||
end
|
||
end
|
||
return nil
|
||
end
|
||
|
||
--获取每日任务
|
||
function GameConfig:GetEventsDailyTaskCfg( id )
|
||
local cfg = skynet.server.gameConfig.DailyTask
|
||
for k, v in pairs( cfg ) do
|
||
if id == v.id then
|
||
return v
|
||
end
|
||
end
|
||
return nil
|
||
end
|
||
|
||
--获取商场价格
|
||
function GameConfig:GetStorePriceCfg( id )
|
||
local cfg = skynet.server.gameConfig.StorePrice
|
||
for k, v in pairs( cfg ) do
|
||
if id == v.storePackId then
|
||
return v
|
||
end
|
||
end
|
||
return nil
|
||
end
|
||
|
||
--获取当前配置
|
||
function GameConfig:GetCurCfg( cfgName , id )
|
||
local cfg = skynet.server.gameConfig[ cfgName ]
|
||
for k, v in pairs( cfg ) do
|
||
if id == v.id then
|
||
return v
|
||
end
|
||
end
|
||
return nil
|
||
end
|
||
|
||
function GameConfig:Is()
|
||
|
||
end
|
||
|
||
--获取所有配置
|
||
function GameConfig:GetAllCfg( cfgName )
|
||
local cfg = skynet.server.gameConfig[ cfgName ]
|
||
return cfg
|
||
end
|
||
|
||
--获取购买货币信息
|
||
function GameConfig:GetBuyMoney( cfgName , id )
|
||
local cfgCur = skynet.server.gameConfig:GetCurCfg( cfgName , id )
|
||
if dataType.MoneyType_No == cfgCur.currencyBuy then
|
||
return cfgCur.currencyBuy , 0
|
||
elseif dataType.MoneyType_Coin == cfgCur.currencyBuy then
|
||
return cfgCur.currencyBuy , cfgCur.coin
|
||
elseif dataType.MoneyType_Map == cfgCur.currencyBuy then
|
||
return cfgCur.currencyBuy , cfgCur.mapCoin
|
||
elseif dataType.MoneyType_Volute == cfgCur.currencyBuy then
|
||
return cfgCur.currencyBuy , cfgCur.voluteCoin
|
||
end
|
||
end
|
||
|
||
--通过awardId获取对应奖励的信息 货币奖励Player:GiveReward()处理
|
||
function GameConfig:AwardInfo( rewardId )
|
||
local Reward = self.Reward --获取配置文件Reward中的数据
|
||
local Furniture = self.Furniture --获取配置文件Furniture中的数据
|
||
local Clothes = self.Clothes --获取配置文件Clothes中的数据
|
||
local PetClothes = self.PetClothes --获取配置文件PetClothes中的数据
|
||
local ClothesSuit = self.ClothesSuit --获取配置文件ClothesSuit中的数据
|
||
local reward = {}
|
||
for k ,v in pairs(Reward) do
|
||
if rewardId==v.id then
|
||
--场景物品(恒定数量为1) 1=furniture 2=decoration 物品类型_物品id 1_123
|
||
if next(v.sceneObject) ~=nil then
|
||
for k1 ,v1 in pairs(v.sceneObject) do
|
||
local arr = skynet.server.common:Split(v1 , "_")
|
||
arr[1],arr[2] = tonumber(arr[1]),tonumber(arr[2])
|
||
if arr[1]==1 then
|
||
local type = pb.enum("EnumGoodsType" , "Furniture")
|
||
table.insert(reward , {type=type, id=arr[2] ,count=1})
|
||
elseif arr[1]==2 then
|
||
local type = pb.enum("EnumGoodsType" , "Decorate")
|
||
table.insert(reward , {type=type, id=arr[2] ,count=1})
|
||
end
|
||
end
|
||
end
|
||
--服饰物品(恒定数量为1)1=人物 2=宠物 类型_衣服id 1_123
|
||
if next(v.appearanceObject) ~=nil then
|
||
for k1 ,v1 in pairs(v.appearanceObject) do
|
||
local arr = skynet.server.common:Split(v1 , "_")
|
||
arr[1],arr[2] = tonumber(arr[1]),tonumber(arr[2])
|
||
if arr[1]==1 then
|
||
local type = pb.enum("EnumGoodsType" , "Clothes")
|
||
table.insert(reward , {type=type, id=arr[2] ,count=1})
|
||
elseif arr[1]==2 then
|
||
local type = pb.enum("EnumGoodsType" , "PetClothes")
|
||
table.insert(reward , {type=type, id=arr[2] ,count=1})
|
||
end
|
||
end
|
||
end
|
||
--套装物品(恒定数量为1) 1=家装 2=服装 类型_套装id 1_1
|
||
if next(v.suitObject)~=nil then
|
||
for k1 ,v1 in pairs(v.suitObject) do
|
||
local arr = skynet.server.common:Split(v1 , "_")
|
||
arr[1],arr[2] = tonumber(arr[1]),tonumber(arr[2])
|
||
if arr[1]==1 then
|
||
--获取家具对应的套装物品
|
||
for k2 ,v2 in pairs(Furniture) do
|
||
if v2.suitType == arr[2] then
|
||
local type = pb.enum("EnumGoodsType" , "Furniture")
|
||
table.insert(reward , {type=type, id=v2.id ,count=1})
|
||
end
|
||
end
|
||
elseif arr[1]==2 then
|
||
local type = nil
|
||
for k2 ,v2 in pairs(ClothesSuit) do
|
||
if v2.id==arr[2] then
|
||
--获取该套装类型
|
||
type = v2.type
|
||
end
|
||
end
|
||
if type == 1 then
|
||
--获取人物服装对应的套装物品
|
||
for k2 ,v2 in pairs(Clothes) do
|
||
if v2.suitId == arr[2] then
|
||
local type = pb.enum("EnumGoodsType" , "Clothes")
|
||
table.insert(reward , {type=type, id=v2.id ,count=1})
|
||
end
|
||
end
|
||
elseif type == 2 then
|
||
--获取动物服装对应的套装物品
|
||
for k2 ,v2 in pairs(PetClothes) do
|
||
if v2.suitId == arr[2] then
|
||
local type = pb.enum("EnumGoodsType" , "PetClothes")
|
||
table.insert(reward , {type=type, id=v2.id ,count=1})
|
||
end
|
||
end
|
||
end
|
||
end
|
||
end
|
||
end
|
||
--道具 类型_数量 id 3_10
|
||
if next(v.ticket)~=nil then
|
||
for k1 ,v1 in pairs(v.ticket) do
|
||
local arr = skynet.server.common:Split(v1 , "_")
|
||
arr[1],arr[2] = tonumber(arr[1]),tonumber(arr[2])
|
||
local type = pb.enum("EnumGoodsType" , "Prop")
|
||
table.insert(reward , {type=type, id=arr[1] ,count=arr[2]})
|
||
end
|
||
end
|
||
--种子 id_数量 id 3_10
|
||
if next(v.seed)~=nil then
|
||
for k1 ,v1 in pairs(v.seed) do
|
||
local arr = skynet.server.common:Split(v1 , "_")
|
||
arr[1],arr[2] = tonumber(arr[1]),tonumber(arr[2])
|
||
table.insert(reward , {type=dataType.GoodsType_Seed, id=arr[1] ,count=arr[2]})
|
||
end
|
||
end
|
||
end
|
||
end
|
||
return reward
|
||
end
|
||
|
||
--是否正式服
|
||
function GameConfig:IsOnline()
|
||
return self.BasicConfig.isOnline
|
||
end
|
||
|
||
--是否开启审核
|
||
function GameConfig:IsAudit()
|
||
return self.BasicConfig.isAudit
|
||
end
|
||
|
||
skynet.server.gameConfig = GameConfig
|
||
return GameConfig |