修复等级更新错误

This commit is contained in:
ZouJin 2024-08-14 12:29:30 +08:00
parent 5920cf753d
commit 6a74e8e779
5 changed files with 55 additions and 20 deletions

View File

@ -14,11 +14,6 @@ namespace VPet_Simulator.Windows.Interface;
/// </summary> /// </summary>
public class GameSave_VPet : IGameSave public class GameSave_VPet : IGameSave
{ {
IMainWindow imw;
public GameSave_VPet(IMainWindow imw)
{
this.imw = imw;
}
/// <summary> /// <summary>
/// 宠物名字 /// 宠物名字
/// </summary> /// </summary>
@ -58,6 +53,8 @@ public class GameSave_VPet : IGameSave
int lun = LevelUpNeed(); int lun = LevelUpNeed();
bool islevelup = false; bool islevelup = false;
bool islevelmaxup = false; bool islevelmaxup = false;
int BeforeLevel = Level;
int BeforeLevelMax = LevelMax;
while (value >= lun) while (value >= lun)
{ {
islevelup = true; islevelup = true;
@ -71,26 +68,38 @@ public class GameSave_VPet : IGameSave
} }
lun = LevelUpNeed(); lun = LevelUpNeed();
} }
exp = value;
if (islevelup) if (islevelup)
{//播放等级升级动画 {
var gf = imw.Core.Graph.FindGraph("levelup", GraphInfo.AnimatType.Single, Mode); Event_LevelUp?.Invoke(new LevelUpEventArgs()
if (gf != null)
{ {
imw.Main.Display(gf, imw.Main.DisplayToNomal); IsLevelMaxUp = islevelmaxup,
} BeforeLevel = BeforeLevel,
} BeforeLevelMax = BeforeLevelMax
if (islevelmaxup)
{//告知用户上限等级上升
imw.Dispatcher.Invoke(() =>
{
imw.Main.Say("邦邦咔邦,{0}等级突破了!".Translate(Name));
MessageBoxX.Show("系统提示\n您的桌宠等级已经突破\nLv{0}→LV{1} x{2}\n已突破为尊贵的x{3}阶".Translate(
1000 + (LevelMax - 1) * 100, 100 * LevelMax, LevelMax), "桌宠等级突破".Translate());
}); });
} }
exp = value;
} }
} }
public class LevelUpEventArgs : EventArgs
{
/// <summary>
/// 是否升级
/// </summary>
public bool IsLevelUp => true;
/// <summary>
/// 是否升级指上限
/// </summary>
public bool IsLevelMaxUp { get; set; }
/// <summary>
/// 之前的等级
/// </summary>
public int BeforeLevel { get; set; }
/// <summary>
/// 之前的等级上限
/// </summary>
public int BeforeLevelMax { get; set; }
}
public event Action<LevelUpEventArgs> Event_LevelUp;
/// <summary> /// <summary>
/// 玩家总共获得的经验值数量 /// 玩家总共获得的经验值数量
/// </summary> /// </summary>

View File

@ -5,6 +5,8 @@ using Panuon.WPF.UI;
using System; using System;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
using static VPet_Simulator.Core.GraphHelper;
using VPet_Simulator.Core;
namespace VPet_Simulator.Windows.Interface namespace VPet_Simulator.Windows.Interface
{ {
@ -21,6 +23,7 @@ namespace VPet_Simulator.Windows.Interface
GameSave = new GameSave_VPet(petname); GameSave = new GameSave_VPet(petname);
Statistics = new Statistics(); Statistics = new Statistics();
} }
protected void load(ILPS lps, Statistics oldStatistics = null, GameSave_VPet oldGameSave = null, ILPS olddata = null) protected void load(ILPS lps, Statistics oldStatistics = null, GameSave_VPet oldGameSave = null, ILPS olddata = null)
{ {
if (lps.FindLine("statistics") == null) if (lps.FindLine("statistics") == null)

View File

@ -2360,5 +2360,24 @@ namespace VPet_Simulator.Windows
return works; return works;
} }
public System.Windows.Controls.MenuItem WorkStarMenu; public System.Windows.Controls.MenuItem WorkStarMenu;
public void LevelUP(GameSave_VPet.LevelUpEventArgs args)
{
var gf = Core.Graph.FindGraph("levelup", GraphInfo.AnimatType.Single, GameSavesData.GameSave.Mode);
if (gf != null)
{
Main.Display(gf, Main.DisplayToNomal);
}
if (args.IsLevelMaxUp)
{//告知用户上限等级上升
Dispatcher.Invoke(() =>
{
Main.Say("邦邦咔邦,{0}等级突破了!".Translate(Name));
MessageBoxX.Show("系统提示\n您的桌宠等级已经突破\nLv{0}→LV{1} x{2}\n已突破为尊贵的x{3}阶".Translate(
1000 + args.BeforeLevelMax * 100, 100 * GameSavesData.GameSave.LevelMax, GameSavesData.GameSave.LevelMax),
"桌宠等级突破".Translate());
});
}
}
} }
} }

View File

@ -66,7 +66,7 @@ namespace VPet_Simulator.Windows
{ {
return line.GetString(); return line.GetString();
} }
if(str.Contains('_') && double.TryParse(str.Split('_').Last(), out double d)) if (str.Contains('_') && double.TryParse(str.Split('_').Last(), out double d))
return d.ToString(); return d.ToString();
return null; return null;
}; };
@ -551,6 +551,7 @@ namespace VPet_Simulator.Windows
GameSavesData = new GameSave_v2(petname.Translate()); GameSavesData = new GameSave_v2(petname.Translate());
Core.Save = GameSavesData.GameSave; Core.Save = GameSavesData.GameSave;
HashCheck = HashCheck; HashCheck = HashCheck;
GameSavesData.GameSave.Event_LevelUp += LevelUP;
} }
private void WorkTimer_E_FinishWork(WorkTimer.FinishWorkInfo obj) private void WorkTimer_E_FinishWork(WorkTimer.FinishWorkInfo obj)

View File

@ -1483,6 +1483,8 @@ namespace VPet_Simulator.Windows
var oldsave = mw.GameSavesData; var oldsave = mw.GameSavesData;
mw.GameSavesData = new GameSave_v2(mw.Core.Save.Name); mw.GameSavesData = new GameSave_v2(mw.Core.Save.Name);
mw.Core.Save = mw.GameSavesData.GameSave; mw.Core.Save = mw.GameSavesData.GameSave;
mw.GameSavesData.GameSave.Event_LevelUp += mw.LevelUP;
if (oldsave.HashCheck) // 对于重开无作弊的玩家保留统计 if (oldsave.HashCheck) // 对于重开无作弊的玩家保留统计
{ {
mw.GameSavesData.Statistics = oldsave.Statistics; mw.GameSavesData.Statistics = oldsave.Statistics;
@ -1627,6 +1629,7 @@ namespace VPet_Simulator.Windows
GameSave_v2 ogs = mw.GameSavesData; GameSave_v2 ogs = mw.GameSavesData;
mw.GameSavesData = new GameSave_v2(ogs.GameSave.Name); mw.GameSavesData = new GameSave_v2(ogs.GameSave.Name);
mw.GameSavesData.Statistics[(gint)"stat_total_time"] = playtime * 60; mw.GameSavesData.Statistics[(gint)"stat_total_time"] = playtime * 60;
mw.GameSavesData.GameSave.Event_LevelUp += mw.LevelUP;
//同步等级 //同步等级
//按2小时=1级进行计算 //按2小时=1级进行计算