You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

148 lines
4.3 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using Sog;
namespace Battle
{
public static class BattleServerUtils
{
public static uint GenNextObjID()
{
var data = GetBattleServerData();
data.m_ObjID++;
if(data.m_ObjID > 1000000000)
{
data.m_ObjID = 1;
}
return data.m_ObjID;
}
public static BattleServerData GetBattleServerData()
{
return ServerDataObjMgr.GetDataObj<BattleServerData>(BattleDataObjType.BattleServerData);
}
public static ProtoCSStructPacker GetProtoPacker()
{
return ProtoPackerFactory.Instance.GetProtoCSStructPacker();
}
public static StructPacketSender GetPacketSender()
{
return GetBattleServerData().m_packetSender;
}
public static BattleMsgHandler GetBattleMsgHandler()
{
return ServiceMgr.GetService<BattleMsgHandler>(BattleServiceType.BattleMsgHandler);
}
public static long GetTimeSecond()
{
return GetBattleServerData().m_app.Time.GetTimeSecond();
}
public static long GetTimeMs()
{
return GetBattleServerData().m_app.Time.GetTime();
}
public static Random GetRandom()
{
return GetBattleServerData().m_app.Rand;
}
public static ServerApp GetApp()
{
return GetBattleServerData().m_app;
}
public static uint GetAppID()
{
return GetBattleServerData().m_app.ServerID;
}
//server data
public static PlayerTable GetPlayerTable()
{
return ServerDataObjMgr.GetDataObj<PlayerTable>(BattleDataObjType.PlayerTable);
}
public static BattleTable GetBattleTable()
{
return ServerDataObjMgr.GetDataObj<BattleTable>(BattleDataObjType.BattleTable);
}
//server service
public static PlayerTableOp GetPlayerTableOp()
{
return ServiceMgr.GetService<PlayerTableOp>(BattleServiceType.PlayerTableOp);
}
//public static BattleTableOp GetBattleTableOp()
//{
// return ServiceMgr.GetService<BattleTableOp>(BattleServiceType.BattleTableOp);
//}
/// <summary>
/// 获取服务器配置方法
/// </summary>
public static BattleServerConfig GetServerConfig()
{
return (BattleServerConfig)ServerConfigMgr.Instance.m_serverConfig;
}
//设置战斗版本号
public static void SetBattleVersion()
{
//int tableVersion = BattleParamDescMgr.Instance.ItemTable[0].version;
//var serverData = GetBattleServerData();
//if(serverData.m_battleVersion != tableVersion)
//{
// serverData.m_battleVersion = tableVersion;
// TraceLog.Debug("BattleServerUtils.SetBattleVersion success {0} ", tableVersion);
// //同步版本号
// SysSvc.SynSelfVersionToGame();
//}
}
//检查战斗所需的表格是否都加载
public static void CheckNeedRegisterFile()
{
Dictionary<string, IConfigManager> m_allConfigMap = new Dictionary<string, IConfigManager>();
if (GameConfigMgr.Instance.m_isBin)
{
//GameLogic.GameConfigRegisterSvc.RegisterBinAll(m_allConfigMap);
}
else
{
//GameLogic.GameConfigRegisterSvc.RegisterAll(m_allConfigMap);
}
List<String> fileList = m_allConfigMap.Keys.ToList();
int count = GameConfigMgr.Instance.CheckAllConfig(fileList);
if (count > 0)
{
TraceLog.Error("BattleServerUtils.CheckNeedRegisterFile error count", count);
throw new Exception("BattleServerUtils.CheckNeedRegisterFile error");
}
}
//获取战斗版本号
public static int GetBattleVersion()
{
return GetBattleServerData().m_battleVersion;
}
public static string GetConfigDataPath()
{
return GetBattleServerData().m_app.AppParam.ServerConfig.configDataPath;
}
}
}