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.
105 lines
3.7 KiB
105 lines
3.7 KiB
using Sog;
|
|
using Sog.Log;
|
|
using ProtoCSStruct;
|
|
|
|
namespace World
|
|
{
|
|
public static class WorldServerDataUtils
|
|
{
|
|
private const string saveFile = "./worldSvrSaveData.fdb";
|
|
|
|
public static void SaveDataToFile()
|
|
{
|
|
ref WorldSvrSaveFileData data = ref WorldServerUtils.GetWorldServerData().m_WorldServerGlobalData;
|
|
|
|
// 更新商品库存信息
|
|
UpdateRealmItemStockInfo(ref data);
|
|
|
|
TraceLog.Stat("WorldServerDataUtils.SaveDataToFile round id {0}", data.RoundId);
|
|
TraceLog.Debug("WorldServerDataUtils.SaveDataToFile round id {0}", data.RoundId);
|
|
|
|
int iRet = Sog.IO.FileDBSave.SaveToFile(ref data, saveFile);
|
|
if (iRet != 0)
|
|
{
|
|
TraceLog.Error("WorldServerDataUtils.SaveDataToFile save file {0} error, ret {1}", saveFile, iRet);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public static void LoadDataFromFile()
|
|
{
|
|
TraceLog.Trace("WorldServerDataUtils.LoadDataFromFile load file {0} begin", saveFile);
|
|
|
|
ref WorldSvrSaveFileData data = ref WorldServerUtils.GetWorldServerData().m_WorldServerGlobalData;
|
|
bool success = Sog.IO.FileDBSave.ReadFromFile(ref data, saveFile);
|
|
if (success)
|
|
{
|
|
TraceLog.Trace("WorldServerDataUtils.LoadDataFromFile load file {0} success, count {1}"
|
|
, saveFile, data.RoundId);
|
|
|
|
// 初始化商品库存信息
|
|
InitRealmItemStockInfo(ref data);
|
|
}
|
|
else
|
|
{
|
|
WorldServerUtils.GetWorldServerData().m_WorldServerGlobalData = new WorldSvrSaveFileData();
|
|
|
|
TraceLog.Trace("WorldServerDataUtils.LoadDataFromFile no Data, new empty object");
|
|
|
|
//立即保存一下
|
|
SaveDataToFile();
|
|
}
|
|
|
|
TraceLog.Trace("WorldServerDataUtils.LoadDataFromFile end");
|
|
}
|
|
|
|
public static void InitRealmItemStockInfo(ref WorldSvrSaveFileData data)
|
|
{
|
|
TraceLog.Trace("WorldServerDataUtils.InitRealmItemStockInfo realm count {0}", data.RealmItemStock.Count);
|
|
|
|
var nowSec = WorldServerUtils.GetTimeSecond();
|
|
var realmStock = WorldServerUtils.GetWorldServerData().m_realmItemStock;
|
|
|
|
for (int i = 0; i < data.RealmItemStock.Count; i++)
|
|
{
|
|
var realmInfo = new RealmItemStockInfo { realmId = data.RealmItemStock[i].RealmId };
|
|
|
|
for (int j = 0; j < data.RealmItemStock[i].ItemStock.Count; j++)
|
|
{
|
|
int itemId = data.RealmItemStock[i].ItemStock[j].ItemID;
|
|
|
|
|
|
|
|
}
|
|
|
|
realmStock.Add(realmInfo.realmId, realmInfo);
|
|
}
|
|
}
|
|
|
|
public static void UpdateRealmItemStockInfo(ref WorldSvrSaveFileData data)
|
|
{
|
|
data.RealmItemStock.Clear();
|
|
var nowSec = WorldServerUtils.GetTimeSecond();
|
|
|
|
var realmStock = WorldServerUtils.GetWorldServerData().m_realmItemStock;
|
|
foreach (RealmItemStockInfo realmInfo in realmStock.Values)
|
|
{
|
|
var ssrealmInfo = new SSRealmItemStockInfo { RealmId = realmInfo.realmId };
|
|
|
|
foreach (ItemStockInfoOne stockOne in realmInfo.stockDict.Values)
|
|
{
|
|
|
|
|
|
}
|
|
|
|
// 有效信息才写入fdb
|
|
if (ssrealmInfo.ItemStock.Count > 0)
|
|
{
|
|
TraceLog.Stat("WorldServerDataUtils.UpdateRealmItemStockInfo realm {0} add succ", realmInfo.realmId);
|
|
data.RealmItemStock.Add(ref ssrealmInfo);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|