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.

202 lines
5.8 KiB

1 month ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Sog;
using ProtoCSStruct;
namespace World
{
public static class WorldServerUtils
{
public static WorldServerData GetWorldServerData()
{
return ServerDataObjMgr.GetDataObj<WorldServerData>(WorldDataObjType.WorldServerData);
}
public static WorldBattleRecordDataCache GetWorldMainlandRecordData()
{
return ServerDataObjMgr.GetDataObj<WorldBattleRecordDataCache>(WorldDataObjType.MainlandRecord);
}
public static LogicWorldRecordInfo GetLogicWorldRecordInfo(int logicWorldId)
{
var data = GetWorldMainlandRecordData();
if(data.m_logicWorldMap.TryGetValue(logicWorldId, out var oneInfo))
{
return oneInfo;
}
return null;
}
//public static WorldBattleReplayAllInfoCache GetWorldReplayCahceData()
//{
// return ServerDataObjMgr.GetDataObj<WorldBattleReplayAllInfoCache>(WorldDataObjType.BattleReplayData);
//}
public static ProtoCSStructPacker GetProtoPacker()
{
return ProtoPackerFactory.Instance.GetProtoCSStructPacker();
}
public static StructPacketSender GetPacketSender()
{
return GetWorldServerData().m_packetSender;
}
public static PlayerTable GetPlayerTable()
{
return ServerDataObjMgr.GetDataObj<PlayerTable>(WorldDataObjType.PlayerTable);
}
public static WorldRankData GetWorldRankData()
{
return ServerDataObjMgr.GetDataObj<WorldRankData>(WorldDataObjType.WorldRankData);
}
public static WorldGlobalData GetWorldGlobalData()
{
return ServerDataObjMgr.GetDataObj<WorldGlobalData>(WorldDataObjType.WorldGlobalData);
}
public static WaitInLinePlayerTableData GetWaitInLinePlayerTableData()
{
return ServerDataObjMgr.GetDataObj<WaitInLinePlayerTableData>(WorldDataObjType.WaitInLinePlayerTableData);
}
public static RoleCacheInfoSvc GetRoleCacheInfoSvc()
{
return ServerDataObjMgr.GetDataObj<RoleCacheInfoSvc>(WorldDataObjType.RoleCacheInfo);
}
public static WorldHomeData GetWorldHomeData()
{
return ServerDataObjMgr.GetDataObj<WorldHomeData>(WorldDataObjType.WorldHomeData);
}
public static WorldLoginLoadingData GetWorldLoginLoadingData()
{
return ServerDataObjMgr.GetDataObj<WorldLoginLoadingData>(WorldDataObjType.WorldLoginLoadingData);
}
public static WorldUnionChangeCacheData GetUnionChangeCacheData()
{
return ServerDataObjMgr.GetDataObj<WorldUnionChangeCacheData>(WorldDataObjType.WorldUnionChangeCacheData);
}
///service
public static PlayerTableOp GetPlayerTableOp()
{
return ServiceMgr.GetService<PlayerTableOp>(WorldServiceType.PlayerTableOp);
}
public static WaitInLinePlayerTableDataOp GetWaitInLinePlayerTableDataOp()
{
return ServiceMgr.GetService<WaitInLinePlayerTableDataOp>(WorldServiceType.WaitInLinePlayerTableOp);
}
public static WorldMsgHandler GetWorldMsgHandler()
{
return ServiceMgr.GetService<WorldMsgHandler>(WorldServiceType.WorldMsgHandler);
}
public static EventHandlerMgr GetEventHandlerMgr()
{
return ServiceMgr.GetService<EventHandlerMgr>(WorldServiceType.EventHandlerMgr);
}
public static long GetTimeMs()
{
return GetWorldServerData().m_app.Time.GetTime();
}
public static long GetTimeSecond()
{
return GetWorldServerData().m_app.Time.GetTimeSecond();
}
public static DateTime GetDateTime()
{
return GetWorldServerData().m_app.Time.GetDateTime();
}
public static ServerApp GetApp()
{
return GetWorldServerData().m_app;
}
public static uint GetAppID()
{
return GetWorldServerData().m_app.ServerID;
}
public static int SetBit(ref int value, int bit)
{
value |= (1 << bit);
return value;
}
public static bool IsBitSet(int value, int bit)
{
return (value & (1 << bit)) > 0;
}
public static int ClearBit(ref int value, int bit)
{
value &= (~(1 << bit));
return value;
}
/// <summary>
/// 获取服务器配置方法
/// </summary>
public static WorldServerConfig GetServerConfig()
{
return (WorldServerConfig)ServerConfigMgr.Instance.m_serverConfig;
}
public static int GetLogicWorldId(int realmId)
{
var serverData = GetWorldServerData();
if (serverData.m_configRealmMap.TryGetValue(realmId, out var briefInfo))
{
return briefInfo.logicWorldId;
}
TraceLog.Error("WorldServerUtils.GetLogicWorldId fail {0}", realmId);
return 0;
}
public static bool CheckIsSameLogicWorld(int realm1, int realm2)
{
if (realm1 == realm2)
{
return true;
}
int logicWorld1 = GetLogicWorldId(realm1);
int logicWorld2 = GetLogicWorldId(realm2);
return logicWorld1 == logicWorld2;
}
public static string GetRealmName(int realmId)
{
var configRealm = GetWorldServerData().m_configRealm;
var realmBrief = configRealm.FirstOrDefault(r => r.realmId == realmId);
if (realmBrief != null)
{
return realmBrief.realmName;
}
return realmId.ToString();
}
}
}