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(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(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(BattleDataObjType.PlayerTable); } public static BattleTable GetBattleTable() { return ServerDataObjMgr.GetDataObj(BattleDataObjType.BattleTable); } //server service public static PlayerTableOp GetPlayerTableOp() { return ServiceMgr.GetService(BattleServiceType.PlayerTableOp); } //public static BattleTableOp GetBattleTableOp() //{ // return ServiceMgr.GetService(BattleServiceType.BattleTableOp); //} /// /// 获取服务器配置方法 /// 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 m_allConfigMap = new Dictionary(); if (GameConfigMgr.Instance.m_isBin) { //GameLogic.GameConfigRegisterSvc.RegisterBinAll(m_allConfigMap); } else { //GameLogic.GameConfigRegisterSvc.RegisterAll(m_allConfigMap); } List 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; } } }