迁移统计到新存档

This commit is contained in:
ZouJin 2023-09-22 21:24:02 +08:00
parent a858810d0c
commit 7315c3948f
6 changed files with 99 additions and 65 deletions

View File

@ -4,6 +4,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Security.Policy;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using VPet_Simulator.Core; using VPet_Simulator.Core;
@ -33,14 +34,33 @@ namespace VPet_Simulator.Windows.Interface
{ {
Statistics = new Statistics(lps["statistics"].ToList()); Statistics = new Statistics(lps["statistics"].ToList());
} }
if (lps.FindLine("vpet") != null) ILine vpet = lps.FindLine("vpet");
bool nohashcheck = true;
long hash;
if (vpet != null)
{ {
GameSave = GameSave.Load(lps.FindLine("vpet")); GameSave = GameSave.Load(vpet);
hash = vpet.GetInt64("hash");
if (vpet.Remove("hash"))
{
HashCheck = vpet.GetLongHashCode() == hash;
nohashcheck = false;
}
} }
else if (oldGameSave != null) else if (oldGameSave != null)
{ {
GameSave = oldGameSave; GameSave = oldGameSave;
} }
if (nohashcheck)
{
hash = vpet.GetInt64("hash");
if (lps.Remove("hash"))
{
HashCheck = vpet.GetLongHashCode() == hash;
}
}
if (olddata != null) if (olddata != null)
Data.AddRange(olddata); Data.AddRange(olddata);
Data.AddRange(lps); Data.AddRange(lps);
@ -79,7 +99,7 @@ namespace VPet_Simulator.Windows.Interface
/// </summary> /// </summary>
public Statistics Statistics = null; public Statistics Statistics = null;
public ILPS Save() public ILPS ToLPS()
{ {
var lps = new LPS_D(); var lps = new LPS_D();
lps.AddRange(Data); lps.AddRange(Data);
@ -87,5 +107,16 @@ namespace VPet_Simulator.Windows.Interface
lps.Add(new Line("statistics", "", Statistics.ToSubs())); lps.Add(new Line("statistics", "", Statistics.ToSubs()));
return lps; return lps;
} }
/// <summary>
/// Hash检查
/// </summary>
public bool HashCheck { get; private set; }
/// <summary>
///
/// </summary>
public void HashCheckOff ()
{
HashCheck = false;
}
} }
} }

View File

@ -139,7 +139,7 @@ namespace VPet_Simulator.Windows.Interface
/// </summary> /// </summary>
void HashCheckOff(); void HashCheckOff();
GameSave_v2 GameSave_v2 { get; } GameSave_v2 GameSavesData { get; }
} }
} }

View File

@ -33,19 +33,19 @@ namespace VPet_Simulator.Windows.Interface
allowmove = !this["gameconfig"].GetBool("allowmove"); allowmove = !this["gameconfig"].GetBool("allowmove");
smartmove = this["gameconfig"].GetBool("smartmove"); smartmove = this["gameconfig"].GetBool("smartmove");
enablefunction = !this["gameconfig"].GetBool("nofunction"); enablefunction = !this["gameconfig"].GetBool("nofunction");
Statistics = new Statistics(this["statistics"].ToList()); Statistics_OLD = new Statistics(this["statistics"].ToList());
autobuy = this["gameconfig"].GetBool("autobuy"); autobuy = this["gameconfig"].GetBool("autobuy");
autogift = this["gameconfig"].GetBool("autogift"); autogift = this["gameconfig"].GetBool("autogift");
} }
public override string ToString() public override string ToString()
{ {//留作备份,未来版本删了
this["statistics"] = new Line("statistics", "", "", Statistics.ToSubs().ToArray()); this["statistics"] = new Line("statistics", "", "", Statistics_OLD.ToSubs().ToArray());
return base.ToString(); return base.ToString();
} }
/// <summary> /// <summary>
/// 统计数据信息 /// 统计数据信息(旧)
/// </summary> /// </summary>
public Statistics Statistics; public Statistics Statistics_OLD;
//public Size WindowsSize //public Size WindowsSize
//{ //{

View File

@ -62,7 +62,7 @@ namespace VPet_Simulator.Windows
public List<ClickText> ClickTexts { get; set; } = new List<ClickText>(); public List<ClickText> ClickTexts { get; set; } = new List<ClickText>();
public GameSave_v2 GameSave_v2 { get; set; } public GameSave_v2 GameSavesData { get; set; }
/// <summary> /// <summary>
/// 获得自动点击的文本 /// 获得自动点击的文本
/// </summary> /// </summary>
@ -112,13 +112,16 @@ namespace VPet_Simulator.Windows
/// </summary> /// </summary>
public bool HashCheck public bool HashCheck
{ {
get => hashCheck; get => GameSavesData.HashCheck;
set set
{ {
hashCheck = value; if(!value)
{
GameSavesData.HashCheckOff();
}
Main?.Dispatcher.Invoke(() => Main?.Dispatcher.Invoke(() =>
{ {
if (hashCheck) if (GameSavesData.HashCheck)
{ {
if (hashcheckimg == null) if (hashcheckimg == null)
{ {
@ -166,14 +169,14 @@ namespace VPet_Simulator.Windows
//游戏存档 //游戏存档
if (Set != null) if (Set != null)
{ {
var st = Set.Statistics[(gint)"savetimes"]++; var st = GameSavesData.Statistics[(gint)"savetimes"]++;
if (Main != null) if (Main != null)
{ {
Set.VoiceVolume = Main.PlayVoiceVolume; Set.VoiceVolume = Main.PlayVoiceVolume;
List<string> list = new List<string>(); List<string> list = new List<string>();
Foods.FindAll(x => x.Star).ForEach(x => list.Add(x.Name)); Foods.FindAll(x => x.Star).ForEach(x => list.Add(x.Name));
Set["betterbuy"]["star"].info = string.Join(",", list); Set["betterbuy"]["star"].info = string.Join(",", list);
//Set.Statistics[(gint)"stat_time"] = (int)(DateTime.Now - timecount).TotalMinutes; //GameSavesData.Statistics[(gint)"stat_time"] = (int)(DateTime.Now - timecount).TotalMinutes;
//timecount = DateTime.Now; //timecount = DateTime.Now;
} }
Set.StartRecordLastPoint = new Point(Dispatcher.Invoke(() => Left), Dispatcher.Invoke(() => Top)); Set.StartRecordLastPoint = new Point(Dispatcher.Invoke(() => Left), Dispatcher.Invoke(() => Top));
@ -200,7 +203,7 @@ namespace VPet_Simulator.Windows
if (File.Exists(ExtensionValue.BaseDirectory + @"\Save.lps")) if (File.Exists(ExtensionValue.BaseDirectory + @"\Save.lps"))
File.Move(ExtensionValue.BaseDirectory + @"\Save.lps", ExtensionValue.BaseDirectory + $"\\BackUP\\Save_{st}.lps"); File.Move(ExtensionValue.BaseDirectory + @"\Save.lps", ExtensionValue.BaseDirectory + $"\\BackUP\\Save_{st}.lps");
var l = Core.Save.ToLine(); var l = GameSavesData.ToLPS();
if (HashCheck) if (HashCheck)
{ {
l[(gi64)"hash"] = new Line(l.ToString()).GetLongHashCode(); l[(gi64)"hash"] = new Line(l.ToString()).GetLongHashCode();
@ -456,30 +459,30 @@ namespace VPet_Simulator.Windows
Core.Save.Money -= item.Price; Core.Save.Money -= item.Price;
//统计 //统计
Set.Statistics[(gint)("buy_" + item.Name)]++; GameSavesData.Statistics[(gint)("buy_" + item.Name)]++;
Set.Statistics[(gdbe)"stat_betterbuy"] += item.Price; GameSavesData.Statistics[(gdbe)"stat_betterbuy"] += item.Price;
switch (item.Type) switch (item.Type)
{ {
case Food.FoodType.Food: case Food.FoodType.Food:
Set.Statistics[(gdbe)"stat_bb_food"] += item.Price; GameSavesData.Statistics[(gdbe)"stat_bb_food"] += item.Price;
break; break;
case Food.FoodType.Drink: case Food.FoodType.Drink:
Set.Statistics[(gdbe)"stat_bb_drink"] += item.Price; GameSavesData.Statistics[(gdbe)"stat_bb_drink"] += item.Price;
break; break;
case Food.FoodType.Drug: case Food.FoodType.Drug:
Set.Statistics[(gdbe)"stat_bb_drug"] += item.Price; GameSavesData.Statistics[(gdbe)"stat_bb_drug"] += item.Price;
break; break;
case Food.FoodType.Snack: case Food.FoodType.Snack:
Set.Statistics[(gdbe)"stat_bb_snack"] += item.Price; GameSavesData.Statistics[(gdbe)"stat_bb_snack"] += item.Price;
break; break;
case Food.FoodType.Functional: case Food.FoodType.Functional:
Set.Statistics[(gdbe)"stat_bb_functional"] += item.Price; GameSavesData.Statistics[(gdbe)"stat_bb_functional"] += item.Price;
break; break;
case Food.FoodType.Meal: case Food.FoodType.Meal:
Set.Statistics[(gdbe)"stat_bb_meal"] += item.Price; GameSavesData.Statistics[(gdbe)"stat_bb_meal"] += item.Price;
break; break;
case Food.FoodType.Gift: case Food.FoodType.Gift:
Set.Statistics[(gdbe)"stat_bb_gift"] += item.Price; GameSavesData.Statistics[(gdbe)"stat_bb_gift"] += item.Price;
break; break;
} }
} }
@ -533,7 +536,7 @@ namespace VPet_Simulator.Windows
/// </summary> /// </summary>
private void StatisticsCalHandle() private void StatisticsCalHandle()
{ {
var stat = Set.Statistics; var stat = GameSavesData.Statistics;
var save = Core.Save; var save = Core.Save;
stat["stat_money"] = save.Money; stat["stat_money"] = save.Money;
stat["stat_level"] = save.Level; stat["stat_level"] = save.Level;
@ -588,23 +591,24 @@ namespace VPet_Simulator.Windows
/// <summary> /// <summary>
/// 加载游戏 /// 加载游戏
/// </summary> /// </summary>
public bool GameLoad(ILine line) public bool GameLoad(ILPS lps)
{ {
if (line == null) if (lps == null)
return false; return false;
if (string.IsNullOrWhiteSpace(line.ToString())) if (string.IsNullOrWhiteSpace(lps.ToString()))
return false; return false;
GameSave_v2 tmp;
Core.Save = GameSave.Load(line); if (GameSavesData != null)
tmp = new GameSave_v2(lps, GameSavesData);
if (Core.Save.Money == 0 && Core.Save.Likability == 0 && Core.Save.Exp == 0 else
&& Core.Save.StrengthDrink == 0 && Core.Save.StrengthFood == 0)//数据全是0,可能是bug tmp = new GameSave_v2(lps, Set.Statistics_OLD);
if(tmp.GameSave == null)
return false; return false;
long hash = line.GetInt64("hash"); if (tmp.GameSave.Money == 0 && tmp.GameSave.Likability == 0 && tmp.GameSave.Exp == 0
if (line.Remove("hash")) && tmp.GameSave.StrengthDrink == 0 && tmp.GameSave.StrengthFood == 0)//数据全是0,可能是bug
{ return false;
HashCheck = line.GetLongHashCode() == hash; GameSavesData = tmp;
} Core.Save = tmp.GameSave;
return true; return true;
} }
private void Handle_Steam(Main obj) private void Handle_Steam(Main obj)
@ -766,7 +770,6 @@ namespace VPet_Simulator.Windows
public bool? CurrMusicType { get; private set; } public bool? CurrMusicType { get; private set; }
int LastDiagnosisTime = 0; int LastDiagnosisTime = 0;
private bool hashCheck = true;
/// <summary> /// <summary>
/// 上传遥测文件 /// 上传遥测文件

View File

@ -271,7 +271,7 @@ namespace VPet_Simulator.Windows
{ {
try try
{ {
if (GameLoad(new Line(File.ReadAllText(latestsave)))) if (GameLoad(new LPS(File.ReadAllText(latestsave))))
return; return;
MessageBoxX.Show("存档损毁,无法加载该存档\n可能是上次储存出错或Steam云同步导致的\n请在设置中加载备份还原存档", "存档损毁".Translate()); MessageBoxX.Show("存档损毁,无法加载该存档\n可能是上次储存出错或Steam云同步导致的\n请在设置中加载备份还原存档", "存档损毁".Translate());
} }
@ -412,7 +412,7 @@ namespace VPet_Simulator.Windows
if (File.Exists(ExtensionValue.BaseDirectory + @"\Save.lps")) if (File.Exists(ExtensionValue.BaseDirectory + @"\Save.lps"))
try try
{ {
if (!GameLoad(new LpsDocument(File.ReadAllText(ExtensionValue.BaseDirectory + @"\Save.lps")).First())) if (!GameLoad(new LpsDocument(File.ReadAllText(ExtensionValue.BaseDirectory + @"\Save.lps"))))
{ {
//如果加载存档失败了,试试加载备份,如果没备份,就新建一个 //如果加载存档失败了,试试加载备份,如果没备份,就新建一个
LoadLatestSave(petloader.PetName); LoadLatestSave(petloader.PetName);
@ -432,11 +432,11 @@ namespace VPet_Simulator.Windows
AutoSaveTimer.Elapsed += AutoSaveTimer_Elapsed; AutoSaveTimer.Elapsed += AutoSaveTimer_Elapsed;
if (Set.Statistics[(gdbe)"stat_bb_food"] < 0 || Set.Statistics[(gdbe)"stat_bb_drink"] < 0 || Set.Statistics[(gdbe)"stat_bb_drug"] < 0 if (GameSavesData.Statistics[(gdbe)"stat_bb_food"] < 0 || GameSavesData.Statistics[(gdbe)"stat_bb_drink"] < 0 || GameSavesData.Statistics[(gdbe)"stat_bb_drug"] < 0
|| Set.Statistics[(gdbe)"stat_bb_snack"] < 0 || Set.Statistics[(gdbe)"stat_bb_functional"] < 0 || Set.Statistics[(gdbe)"stat_bb_meal"] < 0 || GameSavesData.Statistics[(gdbe)"stat_bb_snack"] < 0 || GameSavesData.Statistics[(gdbe)"stat_bb_functional"] < 0 || GameSavesData.Statistics[(gdbe)"stat_bb_meal"] < 0
|| Set.Statistics[(gdbe)"stat_bb_gift"] < 0) || GameSavesData.Statistics[(gdbe)"stat_bb_gift"] < 0)
{ {
hashCheck = false; HashCheck = false;
} }
if (Set.AutoSaveInterval > 0) if (Set.AutoSaveInterval > 0)
@ -465,7 +465,7 @@ namespace VPet_Simulator.Windows
TranslateText = "关注 {0} 谢谢喵".Translate(SteamClient.Name) TranslateText = "关注 {0} 谢谢喵".Translate(SteamClient.Name)
}); });
//Steam成就 //Steam成就
Set.Statistics.StatisticChanged += Statistics_StatisticChanged; GameSavesData.Statistics.StatisticChanged += Statistics_StatisticChanged;
//Steam通知 //Steam通知
SteamFriends.SetRichPresence("username", Core.Save.Name); SteamFriends.SetRichPresence("username", Core.Save.Name);
SteamFriends.SetRichPresence("mode", (Core.Save.Mode.ToString() + "ly").Translate()); SteamFriends.SetRichPresence("mode", (Core.Save.Mode.ToString() + "ly").Translate());
@ -720,13 +720,13 @@ namespace VPet_Simulator.Windows
//成就和统计 //成就和统计
Set.Statistics[(gint)"stat_open_times"]++; GameSavesData.Statistics[(gint)"stat_open_times"]++;
Main.MoveTimer.Elapsed += MoveTimer_Elapsed; Main.MoveTimer.Elapsed += MoveTimer_Elapsed;
Main.OnSay += Main_OnSay; Main.OnSay += Main_OnSay;
Main.Event_TouchHead += Main_Event_TouchHead; Main.Event_TouchHead += Main_Event_TouchHead;
Main.Event_TouchBody += Main_Event_TouchBody; Main.Event_TouchBody += Main_Event_TouchBody;
HashCheck = hashCheck; HashCheck = HashCheck;
if (File.Exists(ExtensionValue.BaseDirectory + @"\Tutorial.html") && Set["SingleTips"].GetDateTime("tutorial") <= new DateTime(2023, 6, 20)) if (File.Exists(ExtensionValue.BaseDirectory + @"\Tutorial.html") && Set["SingleTips"].GetDateTime("tutorial") <= new DateTime(2023, 6, 20))
{ {
@ -798,22 +798,22 @@ namespace VPet_Simulator.Windows
private void Main_Event_TouchBody() private void Main_Event_TouchBody()
{ {
Set.Statistics[(gint)"stat_touch_body"]++; GameSavesData.Statistics[(gint)"stat_touch_body"]++;
} }
private void Main_Event_TouchHead() private void Main_Event_TouchHead()
{ {
Set.Statistics[(gint)"stat_touch_head"]++; GameSavesData.Statistics[(gint)"stat_touch_head"]++;
} }
private void Main_OnSay(string obj) private void Main_OnSay(string obj)
{ {
Set.Statistics[(gint)"stat_say_times"]++; GameSavesData.Statistics[(gint)"stat_say_times"]++;
} }
private void MoveTimer_Elapsed(object sender, ElapsedEventArgs e) private void MoveTimer_Elapsed(object sender, ElapsedEventArgs e)
{ {
Set.Statistics[(gint)"stat_move_length"] += (int)(Math.Abs(Main.MoveTimerPoint.X) + Math.Abs(Main.MoveTimerPoint.Y)); GameSavesData.Statistics[(gint)"stat_move_length"] += (int)(Math.Abs(Main.MoveTimerPoint.X) + Math.Abs(Main.MoveTimerPoint.Y));
} }
private void AutoSaveTimer_Elapsed(object sender, ElapsedEventArgs e) private void AutoSaveTimer_Elapsed(object sender, ElapsedEventArgs e)

View File

@ -1098,9 +1098,9 @@ namespace VPet_Simulator.Windows
int reloadid = 0; int reloadid = 0;
private void CBSaveReLoad_MouseEnter(object sender, MouseEventArgs e) private void CBSaveReLoad_MouseEnter(object sender, MouseEventArgs e)
{ {
if (reloadid != mw.Set.Statistics[(gint)"savetimes"]) if (reloadid != mw.GameSavesData.Statistics[(gint)"savetimes"])
{ {
reloadid = mw.Set.Statistics[(gint)"savetimes"]; reloadid = mw.GameSavesData.Statistics[(gint)"savetimes"];
CBSaveReLoad.SelectedItem = null; CBSaveReLoad.SelectedItem = null;
CBSaveReLoad.Items.Clear(); CBSaveReLoad.Items.Clear();
if (Directory.Exists(ExtensionValue.BaseDirectory + @"\BackUP")) if (Directory.Exists(ExtensionValue.BaseDirectory + @"\BackUP"))
@ -1128,10 +1128,10 @@ namespace VPet_Simulator.Windows
{ {
try try
{ {
var l = new Line(File.ReadAllText(path)); var l = new LPS(File.ReadAllText(path));
GameSave gs = GameSave.Load(l); GameSave_v2 gs = new GameSave_v2(l);
if (MessageBoxX.Show("存档名称:{0}\n存档等级:{1}\n存档金钱:{2}\n是否加载该备份存档? 当前游戏数据会丢失" if (MessageBoxX.Show("存档名称:{0}\n存档等级:{1}\n存档金钱:{2}\n是否加载该备份存档? 当前游戏数据会丢失"
.Translate(gs.Name, gs.Level, gs.Money), "是否加载该备份存档? 当前游戏数据会丢失".Translate(), MessageBoxButton.YesNo, MessageBoxIcon.Info) == MessageBoxResult.Yes) .Translate(gs.GameSave.Name, gs.GameSave.Level, gs.GameSave.Money), "是否加载该备份存档? 当前游戏数据会丢失".Translate(), MessageBoxButton.YesNo, MessageBoxIcon.Info) == MessageBoxResult.Yes)
{ {
try try
{ {
@ -1288,7 +1288,7 @@ namespace VPet_Simulator.Windows
{ {
mw.Core.Save = new GameSave(mw.Core.Save.Name); mw.Core.Save = new GameSave(mw.Core.Save.Name);
if (!mw.HashCheck) if (!mw.HashCheck)
mw.Set.Statistics = new Statistics(); mw.GameSavesData.Statistics = new Statistics();
mw.HashCheck = true; mw.HashCheck = true;
CBSaveReLoad.IsEnabled = false; CBSaveReLoad.IsEnabled = false;
BtnSaveReload.IsEnabled = false; BtnSaveReload.IsEnabled = false;