迁移游戏数据到新存档系统

This commit is contained in:
ZouJin 2023-09-23 00:18:24 +08:00
parent f92a09d9f1
commit d808b5cb17
6 changed files with 151 additions and 37 deletions

View File

@ -14,7 +14,7 @@ namespace VPet_Simulator.Windows.Interface
/// <summary>
/// 游戏存档 最新版
/// </summary>
public class GameSave_v2
public class GameSave_v2 : IGetOBJ<ILine>
{
/// <summary>
/// 新存档
@ -54,10 +54,10 @@ namespace VPet_Simulator.Windows.Interface
if (nohashcheck)
{
hash = vpet.GetInt64("hash");
hash = lps.GetInt64("hash");
if (lps.Remove("hash"))
{
HashCheck = vpet.GetLongHashCode() == hash;
HashCheck = lps.GetLongHashCode() == hash;
}
}
@ -83,7 +83,7 @@ namespace VPet_Simulator.Windows.Interface
/// <param name="oldSave"></param>
public GameSave_v2(ILPS lps, GameSave_v2 oldSave)
{
load(lps, oldSave.Statistics,oldSave.GameSave,oldSave.Data);
load(lps, oldSave.Statistics, oldSave.GameSave, oldSave.Data);
}
/// <summary>
@ -105,18 +105,110 @@ namespace VPet_Simulator.Windows.Interface
lps.AddRange(Data);
lps.AddLine(GameSave.ToLine());
lps.Add(new Line("statistics", "", Statistics.ToSubs()));
lps.Remove("hash");
if (HashCheck)
{
lps[(gi64)"hash"] = lps.GetLongHashCode();
}
else
lps[(gint)"hash"] = -1;
return lps;
}
/// <summary>
/// Hash检查
/// </summary>
public bool HashCheck { get; private set; }
public bool HashCheck { get; private set; } = true;
/// <summary>
///
/// 关闭该玩家的HashCheck检查
/// 请使用imw中的HashCheckOff
/// </summary>
public void HashCheckOff ()
public void HashCheckOff()
{
HashCheck = false;
}
#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
}
}

View File

@ -182,7 +182,7 @@ namespace VPet_Simulator.Windows.Interface
public void LoadEatTimeSource(IMainWindow imw)
{
DateTime now = DateTime.Now;
DateTime eattime = imw.Set.PetData.GetDateTime("buytime_" + Name, now);
DateTime eattime = imw.GameSavesData["buytime"].GetDateTime(Name, now);
if (eattime <= now)
{
if (Type == FoodType.Meal || Type == FoodType.Snack || Type == FoodType.Drink || Type == FoodType.Gift)

View File

@ -213,7 +213,19 @@ namespace VPet_Simulator.Windows.Interface
/// <summary>
/// 当前宠物的储存数据
/// </summary>
public ILine PetData => this["petdata"];
public ILine PetData_OLD => this["petdata"];
/// <summary>
/// 储存顺序次数
/// </summary>
public int SaveTimes
{
get
{
int list = GetInt("savetimes", 100000) + 1 ;
SetInt("savetimes", list);
return list;
}
}
private int presslength;
private int intercycle;

View File

@ -1,5 +1,6 @@
using CSCore.CoreAudioAPI;
using LinePutScript;
using LinePutScript.Dictionary;
using LinePutScript.Localization.WPF;
using Panuon.WPF.UI;
using Steamworks;
@ -103,6 +104,11 @@ namespace VPet_Simulator.Windows
return list[Function.Rnd.Next(list.Count)];
}
private Image hashcheckimg;
/// <summary>
/// 关闭该玩家的HashCheck检查
/// 如果你的mod属于作弊mod/有作弊内容,请在作弊前调用这个方法
/// </summary>
public void HashCheckOff()
{
HashCheck = false;
@ -115,7 +121,7 @@ namespace VPet_Simulator.Windows
get => GameSavesData.HashCheck;
set
{
if(!value)
if (!value)
{
GameSavesData.HashCheckOff();
}
@ -169,7 +175,7 @@ namespace VPet_Simulator.Windows
//游戏存档
if (Set != null)
{
var st = GameSavesData.Statistics[(gint)"savetimes"]++;
var st = Set.SaveTimes;
if (Main != null)
{
Set.VoiceVolume = Main.PlayVoiceVolume;
@ -203,14 +209,8 @@ namespace VPet_Simulator.Windows
if (File.Exists(ExtensionValue.BaseDirectory + @"\Save.lps"))
File.Move(ExtensionValue.BaseDirectory + @"\Save.lps", ExtensionValue.BaseDirectory + $"\\BackUP\\Save_{st}.lps");
var l = GameSavesData.ToLPS();
if (HashCheck)
{
l[(gi64)"hash"] = new Line(l.ToString()).GetLongHashCode();
}
else
l[(gint)"hash"] = -1;
File.WriteAllText(ExtensionValue.BaseDirectory + @"\Save.lps", l.ToString());
File.WriteAllText(ExtensionValue.BaseDirectory + @"\Save.lps", GameSavesData.ToLPS().ToString());
}
}
}
@ -442,7 +442,7 @@ namespace VPet_Simulator.Windows
{
//获取吃腻时间
DateTime now = DateTime.Now;
DateTime eattime = Set.PetData.GetDateTime("buytime_" + item.Name, now);
DateTime eattime = GameSavesData["buytime"].GetDateTime(item.Name, now);
double eattimes = 0;
if (eattime > now)
{
@ -452,7 +452,7 @@ namespace VPet_Simulator.Windows
Core.Save.EatFood(item, Math.Max(0.5, 1 - Math.Pow(eattimes, 2) * 0.01));
//吃腻了
eattimes += 2;
Set.PetData.SetDateTime("buytime_" + item.Name, now.AddHours(eattimes));
GameSavesData["buytime"].SetDateTime(item.Name, now.AddHours(eattimes));
//通知
item.LoadEatTimeSource(this);
item.NotifyOfPropertyChange("Description");
@ -601,8 +601,21 @@ namespace VPet_Simulator.Windows
if (GameSavesData != null)
tmp = new GameSave_v2(lps, GameSavesData);
else
tmp = new GameSave_v2(lps, Set.Statistics_OLD);
if(tmp.GameSave == null)
{
var data = new LPS_D();
foreach (var item in Set.PetData_OLD)
{
if (item.Name.Contains("_"))
{
var strs = Sub.Split(item.Name, "_", 1);
data[strs[0]][(gstr)strs[1]] = item.Info;
}
else
data.Add(new Line(item.Name, item.Info));
}
tmp = new GameSave_v2(lps, Set.Statistics_OLD, olddata: data);
}
if (tmp.GameSave == null)
return false;
if (tmp.GameSave.Money == 0 && tmp.GameSave.Likability == 0 && tmp.GameSave.Exp == 0
&& tmp.GameSave.StrengthDrink == 0 && tmp.GameSave.StrengthFood == 0)//数据全是0,可能是bug

View File

@ -62,32 +62,29 @@ namespace VPet_Simulator.Windows
rMoney.Text = mw.Core.Save.Money.ToString("f2");
//喜好度刷新
foreach (var sub in mw.Set.PetData)
foreach (var sub in mw.GameSavesData["buytime"])
{
if (sub.Name.StartsWith("buytime_"))
var name = sub.Name;
var food = mw.Foods.FirstOrDefault(x => x.Name == name);
if (food != null)
{
var name = sub.Name.Substring(8);
var food = mw.Foods.FirstOrDefault(x => x.Name == name);
if (food != null)
{
food.LoadEatTimeSource(mw);
food.NotifyOfPropertyChange("Description");
}
food.LoadEatTimeSource(mw);
food.NotifyOfPropertyChange("Description");
}
}
//没钱了,宠物给你私房钱 (开罗传统)
if (mw.Core.Save.Money <= 1)
{
if (mw.Set.PetData[(gbol)"self"])
if (mw.GameSavesData[(gbol)"self"])
{
MessageBoxX.Show("更好买老顾客大优惠!桌宠的食物钱我来出!\n更好买提示您:$10以下的食物/药品等随便赊账".Translate());
}
else
{
MessageBoxX.Show("看到您囊中羞涩,桌宠拿出了1000块私房钱出来给你".Translate());
mw.Set.PetData[(gbol)"self"] = true;
mw.GameSavesData[(gbol)"self"] = true;
mw.Core.Save.Money += 1000;
}
}
}
Show();

View File

@ -1130,8 +1130,8 @@ namespace VPet_Simulator.Windows
{
var l = new LPS(File.ReadAllText(path));
GameSave_v2 gs = new GameSave_v2(l);
if (MessageBoxX.Show("存档名称:{0}\n存档等级:{1}\n存档金钱:{2}\n是否加载该备份存档? 当前游戏数据会丢失"
.Translate(gs.GameSave.Name, gs.GameSave.Level, gs.GameSave.Money), "是否加载该备份存档? 当前游戏数据会丢失".Translate(), MessageBoxButton.YesNo, MessageBoxIcon.Info) == MessageBoxResult.Yes)
if (MessageBoxX.Show("存档名称:{0}\n存档等级:{1}\n存档金钱:{2}\nHashCheck:{3}\n是否加载该备份存档? 当前游戏数据会丢失"
.Translate(gs.GameSave.Name, gs.GameSave.Level, gs.GameSave.Money, gs.HashCheck), "是否加载该备份存档? 当前游戏数据会丢失".Translate(), MessageBoxButton.YesNo, MessageBoxIcon.Info) == MessageBoxResult.Yes)
{
try
{