VPet/VPet-Simulator.Windows.Interface/GameSave_v2.cs

215 lines
6.5 KiB
C#
Raw Normal View History

2023-09-17 12:57:28 +00:00
using LinePutScript;
using LinePutScript.Dictionary;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
2023-09-22 13:24:02 +00:00
using System.Security.Policy;
2023-09-17 12:57:28 +00:00
using System.Text;
using System.Threading.Tasks;
using VPet_Simulator.Core;
namespace VPet_Simulator.Windows.Interface
{
/// <summary>
2023-09-20 12:58:28 +00:00
/// 游戏存档 最新版
2023-09-17 12:57:28 +00:00
/// </summary>
2023-09-22 16:18:24 +00:00
public class GameSave_v2 : IGetOBJ<ILine>
2023-09-17 12:57:28 +00:00
{
2023-09-20 12:58:28 +00:00
/// <summary>
/// 新存档
/// </summary>
public GameSave_v2(string petname)
2023-09-20 12:58:28 +00:00
{
GameSave = new GameSave(petname);
2023-09-20 12:58:28 +00:00
Statistics = new Statistics();
}
protected void load(ILPS lps, Statistics oldStatistics = null, GameSave oldGameSave = null, ILPS olddata = null)
2023-09-17 12:57:28 +00:00
{
if (lps.FindLine("statistics") == null)
{//尝试从老存档加载
2023-09-20 12:58:28 +00:00
Statistics = oldStatistics;
2023-09-17 12:57:28 +00:00
}
else
{
Statistics = new Statistics(lps["statistics"].ToList());
}
2023-09-22 13:24:02 +00:00
ILine vpet = lps.FindLine("vpet");
bool nohashcheck = true;
long hash;
if (vpet != null)
2023-09-17 12:57:28 +00:00
{
2023-09-22 13:24:02 +00:00
GameSave = GameSave.Load(vpet);
hash = vpet.GetInt64("hash");
if (vpet.Remove("hash"))
{
HashCheck = vpet.GetLongHashCode() == hash;
nohashcheck = false;
}
2023-09-17 12:57:28 +00:00
}
2023-09-20 12:58:28 +00:00
else if (oldGameSave != null)
{
GameSave = oldGameSave;
}
2023-09-22 13:24:02 +00:00
if (nohashcheck)
{
2023-09-22 16:18:24 +00:00
hash = lps.GetInt64("hash");
2023-09-22 13:24:02 +00:00
if (lps.Remove("hash"))
{
2023-09-22 16:59:41 +00:00
HashCheck = Sub.GetHashCode(lps.ToString()) == hash;
2023-09-22 13:24:02 +00:00
}
}
2023-09-20 12:58:28 +00:00
if (olddata != null)
Data.AddRange(olddata);
Data.AddRange(lps);
}
/// <summary>
/// 读存档, 带入老数据
/// </summary>
/// <param name="lps">数据</param>
/// <param name="oldStatistics">老统计</param>
/// <param name="oldGameSave">老存档</param>
/// <param name="olddata">老数据</param>
public GameSave_v2(ILPS lps, Statistics oldStatistics = null, GameSave oldGameSave = null, ILPS olddata = null)
{
load(lps, oldStatistics, oldGameSave, olddata);
}
/// <summary>
/// 读存档, 带入老存档
/// </summary>
/// <param name="lps"></param>
/// <param name="oldSave"></param>
public GameSave_v2(ILPS lps, GameSave_v2 oldSave)
{
2023-09-22 16:18:24 +00:00
load(lps, oldSave.Statistics, oldSave.GameSave, oldSave.Data);
2023-09-17 12:57:28 +00:00
}
2023-09-20 12:58:28 +00:00
/// <summary>
/// 游戏相关数据
/// </summary>
public LPS_D Data = new LPS_D();
/// <summary>
/// 游戏存档
/// </summary>
public GameSave GameSave;
/// <summary>
/// 统计
/// </summary>
2023-09-17 12:57:28 +00:00
public Statistics Statistics = null;
2023-09-22 13:24:02 +00:00
public ILPS ToLPS()
2023-09-20 12:58:28 +00:00
{
var lps = new LPS_D();
lps.AddRange(Data);
lps.AddLine(GameSave.ToLine());
lps.Add(new Line("statistics", "", Statistics.ToSubs()));
2023-09-22 16:18:24 +00:00
lps.Remove("hash");
if (HashCheck)
{
2023-09-22 16:59:41 +00:00
lps[(gi64)"hash"] = Sub.GetHashCode(lps.ToString());
2023-09-22 16:18:24 +00:00
}
else
lps[(gint)"hash"] = -1;
2023-09-20 12:58:28 +00:00
return lps;
}
2023-09-22 13:24:02 +00:00
/// <summary>
/// Hash检查
/// </summary>
2023-09-22 16:18:24 +00:00
public bool HashCheck { get; private set; } = true;
2023-09-22 16:38:43 +00:00
2023-09-22 16:18:24 +00:00
2023-09-22 13:24:02 +00:00
/// <summary>
2023-09-22 16:18:24 +00:00
/// 关闭该玩家的HashCheck检查
/// 请使用imw中的HashCheckOff
2023-09-22 13:24:02 +00:00
/// </summary>
2023-09-22 16:18:24 +00:00
public void HashCheckOff()
2023-09-22 13:24:02 +00:00
{
HashCheck = false;
}
2023-09-22 16:18:24 +00:00
#region GETOBJ
public DateTime this[gdat subName] { get => Data[subName]; set => Data[subName] = value; }
public double this[gflt subName] { get => Data[subName]; set => Data[subName] = value; }
public double this[gdbe subName] { get => Data[subName]; set => Data[subName] = value; }
public long this[gi64 subName] { get => Data[subName]; set => Data[subName] = value; }
public int this[gint subName] { get => Data[subName]; set => Data[subName] = value; }
public bool this[gbol subName] { get => Data[subName]; set => Data[subName] = value; }
public string this[gstr subName] { get => Data[subName]; set => Data[subName] = value; }
public ILine this[string subName] { get => Data[subName]; set => Data[subName] = value; }
public bool GetBool(string subName)
{
return Data.GetBool(subName);
}
public void SetBool(string subName, bool value)
{
Data.SetBool(subName, value);
}
public int GetInt(string subName, int defaultvalue = 0)
{
return Data.GetInt(subName, defaultvalue);
}
public void SetInt(string subName, int value)
{
Data.SetInt(subName, value);
}
public long GetInt64(string subName, long defaultvalue = 0)
{
return Data.GetInt64(subName, defaultvalue);
}
public void SetInt64(string subName, long value)
{
Data.SetInt64(subName, value);
}
public double GetFloat(string subName, double defaultvalue = 0)
{
return Data.GetFloat(subName, defaultvalue);
}
public void SetFloat(string subName, double value)
{
Data.SetFloat(subName, value);
}
public DateTime GetDateTime(string subName, DateTime defaultvalue = default)
{
return Data.GetDateTime(subName, defaultvalue);
}
public void SetDateTime(string subName, DateTime value)
{
Data.SetDateTime(subName, value);
}
public string GetString(string subName, string defaultvalue = null)
{
return Data.GetString(subName, defaultvalue);
}
public void SetString(string subName, string value)
{
Data.SetString(subName, value);
}
public double GetDouble(string subName, double defaultvalue = 0)
{
return Data.GetDouble(subName, defaultvalue);
}
public void SetDouble(string subName, double value)
{
Data.SetDouble(subName, value);
}
#endregion
2023-09-17 12:57:28 +00:00
}
}