mirror of
https://github.com/LorisYounger/VPet.git
synced 2024-08-30 18:42:36 +00:00
迁移统计到新存档
This commit is contained in:
parent
a858810d0c
commit
7315c3948f
@ -4,6 +4,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Policy;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VPet_Simulator.Core;
|
||||
@ -33,14 +34,33 @@ namespace VPet_Simulator.Windows.Interface
|
||||
{
|
||||
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)
|
||||
{
|
||||
GameSave = oldGameSave;
|
||||
}
|
||||
|
||||
if (nohashcheck)
|
||||
{
|
||||
hash = vpet.GetInt64("hash");
|
||||
if (lps.Remove("hash"))
|
||||
{
|
||||
HashCheck = vpet.GetLongHashCode() == hash;
|
||||
}
|
||||
}
|
||||
|
||||
if (olddata != null)
|
||||
Data.AddRange(olddata);
|
||||
Data.AddRange(lps);
|
||||
@ -79,7 +99,7 @@ namespace VPet_Simulator.Windows.Interface
|
||||
/// </summary>
|
||||
public Statistics Statistics = null;
|
||||
|
||||
public ILPS Save()
|
||||
public ILPS ToLPS()
|
||||
{
|
||||
var lps = new LPS_D();
|
||||
lps.AddRange(Data);
|
||||
@ -87,5 +107,16 @@ namespace VPet_Simulator.Windows.Interface
|
||||
lps.Add(new Line("statistics", "", Statistics.ToSubs()));
|
||||
return lps;
|
||||
}
|
||||
/// <summary>
|
||||
/// Hash检查
|
||||
/// </summary>
|
||||
public bool HashCheck { get; private set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void HashCheckOff ()
|
||||
{
|
||||
HashCheck = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ namespace VPet_Simulator.Windows.Interface
|
||||
/// </summary>
|
||||
void HashCheckOff();
|
||||
|
||||
GameSave_v2 GameSave_v2 { get; }
|
||||
GameSave_v2 GameSavesData { get; }
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,19 +33,19 @@ namespace VPet_Simulator.Windows.Interface
|
||||
allowmove = !this["gameconfig"].GetBool("allowmove");
|
||||
smartmove = this["gameconfig"].GetBool("smartmove");
|
||||
enablefunction = !this["gameconfig"].GetBool("nofunction");
|
||||
Statistics = new Statistics(this["statistics"].ToList());
|
||||
Statistics_OLD = new Statistics(this["statistics"].ToList());
|
||||
autobuy = this["gameconfig"].GetBool("autobuy");
|
||||
autogift = this["gameconfig"].GetBool("autogift");
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
this["statistics"] = new Line("statistics", "", "", Statistics.ToSubs().ToArray());
|
||||
{//留作备份,未来版本删了
|
||||
this["statistics"] = new Line("statistics", "", "", Statistics_OLD.ToSubs().ToArray());
|
||||
return base.ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// 统计数据信息
|
||||
/// 统计数据信息(旧)
|
||||
/// </summary>
|
||||
public Statistics Statistics;
|
||||
public Statistics Statistics_OLD;
|
||||
|
||||
//public Size WindowsSize
|
||||
//{
|
||||
|
@ -62,7 +62,7 @@ namespace VPet_Simulator.Windows
|
||||
|
||||
public List<ClickText> ClickTexts { get; set; } = new List<ClickText>();
|
||||
|
||||
public GameSave_v2 GameSave_v2 { get; set; }
|
||||
public GameSave_v2 GameSavesData { get; set; }
|
||||
/// <summary>
|
||||
/// 获得自动点击的文本
|
||||
/// </summary>
|
||||
@ -112,13 +112,16 @@ namespace VPet_Simulator.Windows
|
||||
/// </summary>
|
||||
public bool HashCheck
|
||||
{
|
||||
get => hashCheck;
|
||||
get => GameSavesData.HashCheck;
|
||||
set
|
||||
{
|
||||
hashCheck = value;
|
||||
if(!value)
|
||||
{
|
||||
GameSavesData.HashCheckOff();
|
||||
}
|
||||
Main?.Dispatcher.Invoke(() =>
|
||||
{
|
||||
if (hashCheck)
|
||||
if (GameSavesData.HashCheck)
|
||||
{
|
||||
if (hashcheckimg == null)
|
||||
{
|
||||
@ -166,14 +169,14 @@ namespace VPet_Simulator.Windows
|
||||
//游戏存档
|
||||
if (Set != null)
|
||||
{
|
||||
var st = Set.Statistics[(gint)"savetimes"]++;
|
||||
var st = GameSavesData.Statistics[(gint)"savetimes"]++;
|
||||
if (Main != null)
|
||||
{
|
||||
Set.VoiceVolume = Main.PlayVoiceVolume;
|
||||
List<string> list = new List<string>();
|
||||
Foods.FindAll(x => x.Star).ForEach(x => list.Add(x.Name));
|
||||
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;
|
||||
}
|
||||
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"))
|
||||
File.Move(ExtensionValue.BaseDirectory + @"\Save.lps", ExtensionValue.BaseDirectory + $"\\BackUP\\Save_{st}.lps");
|
||||
var l = Core.Save.ToLine();
|
||||
var l = GameSavesData.ToLPS();
|
||||
if (HashCheck)
|
||||
{
|
||||
l[(gi64)"hash"] = new Line(l.ToString()).GetLongHashCode();
|
||||
@ -456,30 +459,30 @@ namespace VPet_Simulator.Windows
|
||||
|
||||
Core.Save.Money -= item.Price;
|
||||
//统计
|
||||
Set.Statistics[(gint)("buy_" + item.Name)]++;
|
||||
Set.Statistics[(gdbe)"stat_betterbuy"] += item.Price;
|
||||
GameSavesData.Statistics[(gint)("buy_" + item.Name)]++;
|
||||
GameSavesData.Statistics[(gdbe)"stat_betterbuy"] += item.Price;
|
||||
switch (item.Type)
|
||||
{
|
||||
case Food.FoodType.Food:
|
||||
Set.Statistics[(gdbe)"stat_bb_food"] += item.Price;
|
||||
GameSavesData.Statistics[(gdbe)"stat_bb_food"] += item.Price;
|
||||
break;
|
||||
case Food.FoodType.Drink:
|
||||
Set.Statistics[(gdbe)"stat_bb_drink"] += item.Price;
|
||||
GameSavesData.Statistics[(gdbe)"stat_bb_drink"] += item.Price;
|
||||
break;
|
||||
case Food.FoodType.Drug:
|
||||
Set.Statistics[(gdbe)"stat_bb_drug"] += item.Price;
|
||||
GameSavesData.Statistics[(gdbe)"stat_bb_drug"] += item.Price;
|
||||
break;
|
||||
case Food.FoodType.Snack:
|
||||
Set.Statistics[(gdbe)"stat_bb_snack"] += item.Price;
|
||||
GameSavesData.Statistics[(gdbe)"stat_bb_snack"] += item.Price;
|
||||
break;
|
||||
case Food.FoodType.Functional:
|
||||
Set.Statistics[(gdbe)"stat_bb_functional"] += item.Price;
|
||||
GameSavesData.Statistics[(gdbe)"stat_bb_functional"] += item.Price;
|
||||
break;
|
||||
case Food.FoodType.Meal:
|
||||
Set.Statistics[(gdbe)"stat_bb_meal"] += item.Price;
|
||||
GameSavesData.Statistics[(gdbe)"stat_bb_meal"] += item.Price;
|
||||
break;
|
||||
case Food.FoodType.Gift:
|
||||
Set.Statistics[(gdbe)"stat_bb_gift"] += item.Price;
|
||||
GameSavesData.Statistics[(gdbe)"stat_bb_gift"] += item.Price;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -533,7 +536,7 @@ namespace VPet_Simulator.Windows
|
||||
/// </summary>
|
||||
private void StatisticsCalHandle()
|
||||
{
|
||||
var stat = Set.Statistics;
|
||||
var stat = GameSavesData.Statistics;
|
||||
var save = Core.Save;
|
||||
stat["stat_money"] = save.Money;
|
||||
stat["stat_level"] = save.Level;
|
||||
@ -588,23 +591,24 @@ namespace VPet_Simulator.Windows
|
||||
/// <summary>
|
||||
/// 加载游戏
|
||||
/// </summary>
|
||||
public bool GameLoad(ILine line)
|
||||
public bool GameLoad(ILPS lps)
|
||||
{
|
||||
if (line == null)
|
||||
if (lps == null)
|
||||
return false;
|
||||
if (string.IsNullOrWhiteSpace(line.ToString()))
|
||||
if (string.IsNullOrWhiteSpace(lps.ToString()))
|
||||
return false;
|
||||
|
||||
Core.Save = GameSave.Load(line);
|
||||
|
||||
if (Core.Save.Money == 0 && Core.Save.Likability == 0 && Core.Save.Exp == 0
|
||||
&& Core.Save.StrengthDrink == 0 && Core.Save.StrengthFood == 0)//数据全是0,可能是bug
|
||||
GameSave_v2 tmp;
|
||||
if (GameSavesData != null)
|
||||
tmp = new GameSave_v2(lps, GameSavesData);
|
||||
else
|
||||
tmp = new GameSave_v2(lps, Set.Statistics_OLD);
|
||||
if(tmp.GameSave == null)
|
||||
return false;
|
||||
long hash = line.GetInt64("hash");
|
||||
if (line.Remove("hash"))
|
||||
{
|
||||
HashCheck = line.GetLongHashCode() == hash;
|
||||
}
|
||||
if (tmp.GameSave.Money == 0 && tmp.GameSave.Likability == 0 && tmp.GameSave.Exp == 0
|
||||
&& tmp.GameSave.StrengthDrink == 0 && tmp.GameSave.StrengthFood == 0)//数据全是0,可能是bug
|
||||
return false;
|
||||
GameSavesData = tmp;
|
||||
Core.Save = tmp.GameSave;
|
||||
return true;
|
||||
}
|
||||
private void Handle_Steam(Main obj)
|
||||
@ -766,7 +770,6 @@ namespace VPet_Simulator.Windows
|
||||
public bool? CurrMusicType { get; private set; }
|
||||
|
||||
int LastDiagnosisTime = 0;
|
||||
private bool hashCheck = true;
|
||||
|
||||
/// <summary>
|
||||
/// 上传遥测文件
|
||||
|
@ -271,7 +271,7 @@ namespace VPet_Simulator.Windows
|
||||
{
|
||||
try
|
||||
{
|
||||
if (GameLoad(new Line(File.ReadAllText(latestsave))))
|
||||
if (GameLoad(new LPS(File.ReadAllText(latestsave))))
|
||||
return;
|
||||
MessageBoxX.Show("存档损毁,无法加载该存档\n可能是上次储存出错或Steam云同步导致的\n请在设置中加载备份还原存档", "存档损毁".Translate());
|
||||
}
|
||||
@ -412,7 +412,7 @@ namespace VPet_Simulator.Windows
|
||||
if (File.Exists(ExtensionValue.BaseDirectory + @"\Save.lps"))
|
||||
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);
|
||||
@ -432,11 +432,11 @@ namespace VPet_Simulator.Windows
|
||||
|
||||
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
|
||||
|| Set.Statistics[(gdbe)"stat_bb_snack"] < 0 || Set.Statistics[(gdbe)"stat_bb_functional"] < 0 || Set.Statistics[(gdbe)"stat_bb_meal"] < 0
|
||||
|| Set.Statistics[(gdbe)"stat_bb_gift"] < 0)
|
||||
if (GameSavesData.Statistics[(gdbe)"stat_bb_food"] < 0 || GameSavesData.Statistics[(gdbe)"stat_bb_drink"] < 0 || GameSavesData.Statistics[(gdbe)"stat_bb_drug"] < 0
|
||||
|| GameSavesData.Statistics[(gdbe)"stat_bb_snack"] < 0 || GameSavesData.Statistics[(gdbe)"stat_bb_functional"] < 0 || GameSavesData.Statistics[(gdbe)"stat_bb_meal"] < 0
|
||||
|| GameSavesData.Statistics[(gdbe)"stat_bb_gift"] < 0)
|
||||
{
|
||||
hashCheck = false;
|
||||
HashCheck = false;
|
||||
}
|
||||
|
||||
if (Set.AutoSaveInterval > 0)
|
||||
@ -465,7 +465,7 @@ namespace VPet_Simulator.Windows
|
||||
TranslateText = "关注 {0} 谢谢喵".Translate(SteamClient.Name)
|
||||
});
|
||||
//Steam成就
|
||||
Set.Statistics.StatisticChanged += Statistics_StatisticChanged;
|
||||
GameSavesData.Statistics.StatisticChanged += Statistics_StatisticChanged;
|
||||
//Steam通知
|
||||
SteamFriends.SetRichPresence("username", Core.Save.Name);
|
||||
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.OnSay += Main_OnSay;
|
||||
Main.Event_TouchHead += Main_Event_TouchHead;
|
||||
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))
|
||||
{
|
||||
@ -798,22 +798,22 @@ namespace VPet_Simulator.Windows
|
||||
|
||||
private void Main_Event_TouchBody()
|
||||
{
|
||||
Set.Statistics[(gint)"stat_touch_body"]++;
|
||||
GameSavesData.Statistics[(gint)"stat_touch_body"]++;
|
||||
}
|
||||
|
||||
private void Main_Event_TouchHead()
|
||||
{
|
||||
Set.Statistics[(gint)"stat_touch_head"]++;
|
||||
GameSavesData.Statistics[(gint)"stat_touch_head"]++;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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)
|
||||
|
@ -1098,9 +1098,9 @@ namespace VPet_Simulator.Windows
|
||||
int reloadid = 0;
|
||||
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.Items.Clear();
|
||||
if (Directory.Exists(ExtensionValue.BaseDirectory + @"\BackUP"))
|
||||
@ -1128,10 +1128,10 @@ namespace VPet_Simulator.Windows
|
||||
{
|
||||
try
|
||||
{
|
||||
var l = new Line(File.ReadAllText(path));
|
||||
GameSave gs = GameSave.Load(l);
|
||||
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.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
|
||||
{
|
||||
@ -1288,7 +1288,7 @@ namespace VPet_Simulator.Windows
|
||||
{
|
||||
mw.Core.Save = new GameSave(mw.Core.Save.Name);
|
||||
if (!mw.HashCheck)
|
||||
mw.Set.Statistics = new Statistics();
|
||||
mw.GameSavesData.Statistics = new Statistics();
|
||||
mw.HashCheck = true;
|
||||
CBSaveReLoad.IsEnabled = false;
|
||||
BtnSaveReload.IsEnabled = false;
|
||||
|
Loading…
Reference in New Issue
Block a user