VPet/VPet-Simulator.Windows/MainWindow.cs

351 lines
15 KiB
C#
Raw Normal View History

2023-03-13 15:40:04 +00:00
using ChatGPT.API.Framework;
using LinePutScript;
2023-07-01 07:46:08 +00:00
using LinePutScript.Localization.WPF;
2023-02-27 12:29:40 +00:00
using System;
2023-01-10 10:43:32 +00:00
using System.Collections.Generic;
2023-02-27 12:29:40 +00:00
using System.Diagnostics;
2023-01-24 06:56:16 +00:00
using System.IO;
2023-06-18 22:20:06 +00:00
using System.Threading.Tasks;
2023-04-01 19:31:28 +00:00
using System.Windows;
2023-01-10 10:43:32 +00:00
using VPet_Simulator.Core;
2023-04-01 15:15:50 +00:00
using VPet_Simulator.Windows.Interface;
using ToolBar = VPet_Simulator.Core.ToolBar;
2023-01-10 10:43:32 +00:00
namespace VPet_Simulator.Windows
{
2023-04-01 15:15:50 +00:00
public partial class MainWindow : IMainWindow
2023-01-10 10:43:32 +00:00
{
public readonly string ModPath = Environment.CurrentDirectory + @"\mod";
2023-04-01 19:31:28 +00:00
public bool IsSteamUser { get; }
public Setting Set { get; set; }
public List<PetLoader> Pets { get; set; } = new List<PetLoader>();
2023-01-10 10:43:32 +00:00
public List<CoreMOD> CoreMODs = new List<CoreMOD>();
2023-04-01 19:31:28 +00:00
public GameCore Core { get; set; } = new GameCore();
public Main Main { get; set; }
public UIElement TalkBox;
public winGameSetting winSetting { get; set; }
2023-06-08 08:46:53 +00:00
public winBetterBuy winBetterBuy { get; set; }
2023-03-13 15:40:04 +00:00
public ChatGPTClient CGPTClient;
2023-06-08 08:46:53 +00:00
public ImageResources ImageSources { get; set; } = new ImageResources();
2023-01-10 10:43:32 +00:00
/// <summary>
2023-04-01 19:31:28 +00:00
/// 所有三方插件
/// </summary>
public List<MainPlugin> Plugins { get; } = new List<MainPlugin>();
2023-06-08 08:46:53 +00:00
public List<Food> Foods { get; } = new List<Food>();
2023-04-01 19:31:28 +00:00
/// <summary>
2023-01-10 10:43:32 +00:00
/// 版本号
/// </summary>
2023-07-03 22:48:13 +00:00
public int verison { get; } = 30;
2023-01-10 10:43:32 +00:00
/// <summary>
/// 版本号
/// </summary>
public string Verison => $"{verison / 100}.{verison % 100}";
2023-06-18 22:20:06 +00:00
public List<LowText> LowFoodText { get; set; } = new List<LowText>();
public List<LowText> LowDrinkText { get; set; } = new List<LowText>();
2023-01-10 10:43:32 +00:00
public void SetZoomLevel(double zl)
{
Set.ZoomLevel = zl;
2023-05-27 10:37:15 +00:00
//this.Height = 500 * zl;
2023-01-10 10:43:32 +00:00
this.Width = 500 * zl;
2023-07-03 11:41:02 +00:00
if (petHelper != null)
{
petHelper.Width = 50 * zl;
petHelper.Height = 50 * zl;
petHelper.ReloadLocation();
}
2023-01-10 10:43:32 +00:00
}
2023-01-24 06:56:16 +00:00
/// <summary>
/// 保存设置
/// </summary>
public void Save()
{
2023-04-01 19:31:28 +00:00
foreach (MainPlugin mp in Plugins)
mp.Save();
2023-01-24 06:56:16 +00:00
//游戏存档
if (Set != null)
2023-05-25 17:50:38 +00:00
{
2023-06-14 11:14:04 +00:00
var st = Set.Statistics[(gint)"savetimes"]++;
2023-05-27 10:37:15 +00:00
if (Main != null)
2023-06-08 11:44:41 +00:00
{
2023-05-27 10:37:15 +00:00
Set.VoiceVolume = Main.PlayVoiceVolume;
2023-06-08 11:44:41 +00:00
List<string> list = new List<string>();
Foods.FindAll(x => x.Star).ForEach(x => list.Add(x.Name));
Set["betterbuy"]["star"].info = string.Join(",", list);
}
2023-06-22 22:09:26 +00:00
File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + @"\Setting.lps", Set.ToString());
2023-06-23 13:15:57 +00:00
if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + @"\UserData"))
Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + @"\UserData");
2023-06-23 13:15:57 +00:00
2023-06-22 22:09:26 +00:00
if (Core != null && Core.Save != null)
2023-06-23 13:15:57 +00:00
{
var ds = new List<string>(Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + @"\UserData"));
while (ds.Count > Set.BackupSaveMaxNum)
{
2023-06-23 13:15:57 +00:00
File.Delete(ds[0]);
ds.RemoveAt(0);
}
2023-06-23 13:15:57 +00:00
if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + $"\\UserData\\Save_{st}.lps"))
File.Delete(AppDomain.CurrentDomain.BaseDirectory + $"\\UserData\\Save_{st}.lps");
if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + @"\Save.lps"))
File.Move(AppDomain.CurrentDomain.BaseDirectory + @"\Save.lps", AppDomain.CurrentDomain.BaseDirectory + $"\\UserData\\Save_{st}.lps");
2023-06-22 22:09:26 +00:00
File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + @"\Save.lps", Core.Save.ToLine().ToString());
2023-06-23 13:15:57 +00:00
}
2023-06-22 22:09:26 +00:00
if (CGPTClient != null)
File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + @"\ChatGPTSetting.json", CGPTClient.Save());
2023-06-18 22:20:06 +00:00
}
2023-01-24 06:56:16 +00:00
}
2023-04-01 19:31:28 +00:00
/// <summary>
/// 重载DIY按钮区域
/// </summary>
2023-02-27 12:29:40 +00:00
public void LoadDIY()
{
Main.ToolBar.MenuDIY.Items.Clear();
foreach (Sub sub in Set["diy"])
2023-05-19 08:17:51 +00:00
Main.ToolBar.AddMenuButton(ToolBar.MenuType.DIY, sub.Name, () =>
{
Main.ToolBar.Visibility = Visibility.Collapsed;
RunDIY(sub.Info);
});
2023-04-01 19:31:28 +00:00
try
{
//加载游戏创意工坊插件
foreach (MainPlugin mp in Plugins)
2023-04-04 16:21:46 +00:00
mp.LoadDIY();
2023-04-01 19:31:28 +00:00
}
catch (Exception e)
{
2023-07-01 07:46:08 +00:00
new winReport(this, "由于插件引起的自定按钮加载错误".Translate() + '\n' + e.ToString()).Show();
2023-04-01 19:31:28 +00:00
}
2023-02-27 12:29:40 +00:00
}
2023-07-03 11:41:02 +00:00
/// <summary>
/// 加载帮助器
/// </summary>
public void LoadPetHelper()
2023-07-03 22:48:13 +00:00
{
2023-07-03 11:41:02 +00:00
petHelper = new PetHelper(this);
petHelper.Show();
}
2023-07-03 22:48:13 +00:00
2023-02-27 12:29:40 +00:00
public static void RunDIY(string content)
{
2023-04-01 15:15:50 +00:00
if (content.Contains("://") || content.Contains(@":\"))
2023-02-27 12:29:40 +00:00
{
2023-07-03 22:48:13 +00:00
try
{
Process.Start(content);
}
catch(Exception e)
{
MessageBox.Show("快捷键运行失败:无法运行指定内容".Translate() + '\n' + e.Message);
}
2023-02-27 12:29:40 +00:00
}
else
{
System.Windows.Forms.SendKeys.SendWait(content);
}
}
2023-04-01 15:15:50 +00:00
public void RunAction(string action)
{
switch (action)
{
case "DisplayNomal":
Main.DisplayNomal();
break;
case "DisplayTouchHead":
Main.DisplayTouchHead();
break;
case "DisplayTouchBody":
Main.DisplayTouchBody();
break;
case "DisplayBoring":
Main.DisplayBoring();
break;
case "DisplaySquat":
Main.DisplaySquat();
break;
case "DisplaySleep":
Main.DisplaySleep();
break;
case "DisplayRaised":
Main.DisplayRaised();
break;
case "DisplayFalled_Left":
Main.DisplayFalled_Left();
break;
case "DisplayFalled_Right":
Main.DisplayFalled_Right();
break;
case "DisplayWalk":
if (Function.Rnd.Next(2) == 0)
Main.DisplayWalk_Left();
else
Main.DisplayWalk_Right();
break;
case "DisplayWalk_Left":
Main.DisplayWalk_Left();
break;
case "DisplayWalk_Right":
Main.DisplayWalk_Right();
break;
case "DisplayCrawl":
if (Function.Rnd.Next(2) == 0)
Main.DisplayCrawl_Left();
else
Main.DisplayCrawl_Right();
break;
case "DisplayCrawl_Left":
Main.DisplayCrawl_Left();
break;
case "DisplayCrawl_Right":
Main.DisplayCrawl_Right();
break;
case "DisplayClimb_Left_UP":
Main.DisplayClimb_Left_UP();
break;
case "DisplayClimb_Left_DOWN":
Main.DisplayClimb_Left_DOWN();
break;
case "DisplayClimb_Right_UP":
Main.DisplayClimb_Right_UP();
break;
case "DisplayClimb_Right_DOWN":
Main.DisplayClimb_Right_DOWN();
break;
case "DisplayClimb_Top_Right":
Main.DisplayClimb_Top_Right();
break;
case "DisplayClimb_Top_Left":
Main.DisplayClimb_Top_Left();
break;
case "DisplayFall":
if (Function.Rnd.Next(2) == 0)
Main.DisplayFall_Left();
else
Main.DisplayFall_Right();
break;
case "DisplayFall_Left":
Main.DisplayFall_Left();
break;
case "DisplayFall_Right":
Main.DisplayFall_Right();
break;
case "DisplayIdel_StateONE":
Main.DisplayIdel_StateONE();
break;
case "DisplayIdel_StateTWO":
Main.DisplayIdel_StateTWO();
break;
}
}
2023-06-18 22:20:06 +00:00
int lowstrengthAskCountFood = 1;
int lowstrengthAskCountDrink = 1;
private void lowStrength()
{
if (Core.Save.Mode == GameSave.ModeType.Happy || Core.Save.Mode == GameSave.ModeType.Nomal)
{
if (Core.Save.StrengthFood < 75 && Function.Rnd.Next(lowstrengthAskCountFood--) == 0)
{
lowstrengthAskCountFood = 20;
var like = Core.Save.Likability < 40 ? 0 : (Core.Save.Likability < 70 ? 1 : (Core.Save.Likability < 100 ? 2 : 3));
var txt = LowFoodText.FindAll(x => x.Mode == LowText.ModeType.H && (int)x.Like < like);
if (Core.Save.StrengthFood > 60)
{
txt = txt.FindAll(x => x.Strength == LowText.StrengthType.L);
2023-07-03 11:41:02 +00:00
Main.Say(txt[Function.Rnd.Next(txt.Count)].TranslateText, GraphCore.Helper.SayType.None);
2023-06-18 22:20:06 +00:00
}
else if (Core.Save.StrengthFood > 40)
{
txt = txt.FindAll(x => x.Strength == LowText.StrengthType.M);
2023-07-03 11:41:02 +00:00
Main.Say(txt[Function.Rnd.Next(txt.Count)].TranslateText, GraphCore.Helper.SayType.None);
2023-06-18 22:20:06 +00:00
}
else
{
txt = txt.FindAll(x => x.Strength == LowText.StrengthType.S);
2023-07-03 11:41:02 +00:00
Main.Say(txt[Function.Rnd.Next(txt.Count)].TranslateText, GraphCore.Helper.SayType.None);
2023-06-18 22:20:06 +00:00
}
2023-06-20 18:39:54 +00:00
Task.Run(() => Main.Display(GraphCore.GraphType.Switch_Hunger, Main.DisplayToNomal));
2023-06-18 22:20:06 +00:00
return;
}
if (Core.Save.StrengthDrink < 75 && Function.Rnd.Next(lowstrengthAskCountDrink--) == 0)
{
lowstrengthAskCountDrink = 20;
var like = Core.Save.Likability < 40 ? 0 : (Core.Save.Likability < 70 ? 1 : (Core.Save.Likability < 100 ? 2 : 3));
var txt = LowDrinkText.FindAll(x => x.Mode == LowText.ModeType.H && (int)x.Like < like);
if (Core.Save.StrengthDrink > 60)
{
txt = txt.FindAll(x => x.Strength == LowText.StrengthType.L);
2023-07-03 11:41:02 +00:00
Main.Say(txt[Function.Rnd.Next(txt.Count)].TranslateText, GraphCore.Helper.SayType.None);
2023-06-18 22:20:06 +00:00
}
else if (Core.Save.StrengthDrink > 40)
{
txt = txt.FindAll(x => x.Strength == LowText.StrengthType.M);
2023-07-03 11:41:02 +00:00
Main.Say(txt[Function.Rnd.Next(txt.Count)].TranslateText, GraphCore.Helper.SayType.None);
2023-06-18 22:20:06 +00:00
}
else
{
txt = txt.FindAll(x => x.Strength == LowText.StrengthType.S);
2023-07-03 11:41:02 +00:00
Main.Say(txt[Function.Rnd.Next(txt.Count)].TranslateText, GraphCore.Helper.SayType.None);
2023-06-18 22:20:06 +00:00
}
Task.Run(() => Main.Display(GraphCore.GraphType.Switch_Thirsty, Main.DisplayToNomal));
return;
}
}
else
{
if (Core.Save.StrengthFood < 60 && Function.Rnd.Next(lowstrengthAskCountFood--) == 0)
{
var like = Core.Save.Likability < 40 ? 0 : (Core.Save.Likability < 70 ? 1 : (Core.Save.Likability < 100 ? 2 : 3));
var txt = LowFoodText.FindAll(x => x.Mode == LowText.ModeType.L && (int)x.Like < like);
if (Core.Save.StrengthFood > 40)
{
txt = txt.FindAll(x => x.Strength == LowText.StrengthType.L);
2023-07-03 11:41:02 +00:00
Main.Say(txt[Function.Rnd.Next(txt.Count)].TranslateText, GraphCore.Helper.SayType.None);
2023-06-18 22:20:06 +00:00
}
else if (Core.Save.StrengthFood > 20)
{
txt = txt.FindAll(x => x.Strength == LowText.StrengthType.M);
2023-07-03 11:41:02 +00:00
Main.Say(txt[Function.Rnd.Next(txt.Count)].TranslateText, GraphCore.Helper.SayType.None);
2023-06-18 22:20:06 +00:00
}
else
{
txt = txt.FindAll(x => x.Strength == LowText.StrengthType.S);
2023-07-03 11:41:02 +00:00
Main.Say(txt[Function.Rnd.Next(txt.Count)].TranslateText, GraphCore.Helper.SayType.None);
2023-06-18 22:20:06 +00:00
}
2023-06-20 18:39:54 +00:00
Task.Run(() => Main.Display(GraphCore.GraphType.Switch_Hunger, Main.DisplayToNomal));
2023-06-18 22:20:06 +00:00
return;
}
if (Core.Save.StrengthDrink < 60 && Function.Rnd.Next(lowstrengthAskCountDrink--) == 0)
{
var like = Core.Save.Likability < 40 ? 0 : (Core.Save.Likability < 70 ? 1 : (Core.Save.Likability < 100 ? 2 : 3));
var txt = LowDrinkText.FindAll(x => x.Mode == LowText.ModeType.L && (int)x.Like < like);
if (Core.Save.StrengthDrink > 40)
{
txt = txt.FindAll(x => x.Strength == LowText.StrengthType.L);
2023-07-03 11:41:02 +00:00
Main.Say(txt[Function.Rnd.Next(txt.Count)].TranslateText, GraphCore.Helper.SayType.None);
2023-06-18 22:20:06 +00:00
}
else if (Core.Save.StrengthDrink > 20)
{
txt = txt.FindAll(x => x.Strength == LowText.StrengthType.M);
2023-07-03 11:41:02 +00:00
Main.Say(txt[Function.Rnd.Next(txt.Count)].TranslateText, GraphCore.Helper.SayType.None);
2023-06-18 22:20:06 +00:00
}
else
{
txt = txt.FindAll(x => x.Strength == LowText.StrengthType.S);
2023-07-03 11:41:02 +00:00
Main.Say(txt[Function.Rnd.Next(txt.Count)].TranslateText, GraphCore.Helper.SayType.None);
2023-06-18 22:20:06 +00:00
}
Task.Run(() => Main.Display(GraphCore.GraphType.Switch_Thirsty, Main.DisplayToNomal));
return;
}
}
2023-06-20 19:30:26 +00:00
}
2023-01-10 10:43:32 +00:00
}
}