forked from LorisYounger/VPet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.cs
2231 lines (2096 loc) · 96 KB
/
MainWindow.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using NAudio.CoreAudioApi;
using LinePutScript;
using LinePutScript.Dictionary;
using LinePutScript.Localization.WPF;
using Panuon.WPF.UI;
using Steamworks;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using System.Web;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Interop;
using VPet_Simulator.Core;
using VPet_Simulator.Windows.Interface;
using static VPet_Simulator.Core.GraphHelper;
using static VPet_Simulator.Core.GraphInfo;
using Timer = System.Timers.Timer;
using ToolBar = VPet_Simulator.Core.ToolBar;
using ContextMenu = System.Windows.Forms.ContextMenuStrip;
using MenuItem = System.Windows.Forms.ToolStripMenuItem;
using Application = System.Windows.Application;
using Line = LinePutScript.Line;
using static VPet_Simulator.Windows.Interface.ExtensionFunction;
using Image = System.Windows.Controls.Image;
using System.Data;
using System.Windows.Media;
using System.Windows.Threading;
using MessageBox = System.Windows.MessageBox;
namespace VPet_Simulator.Windows
{
public partial class MainWindow : IMainWindow
{
public readonly string ModPath = ExtensionValue.BaseDirectory + @"\mod";
public bool IsSteamUser { get; }
public LPS_D Args { get; }
public string PrefixSave { get; } = "";
private string prefixsavetrans = null;
public string PrefixSaveTrans
{
get
{
if (prefixsavetrans == null)
{
if (PrefixSave == "")
prefixsavetrans = "";
else
prefixsavetrans = '-' + PrefixSave.TrimStart('-').Translate();
}
return prefixsavetrans;
}
}
public Setting Set { get; set; }
ISetting IMainWindow.Set => Set;
public List<PetLoader> Pets { get; set; } = new List<PetLoader>();
public List<CoreMOD> CoreMODs = new List<CoreMOD>();
public GameCore Core { get; set; } = new GameCore();
public List<Window> Windows { get; set; } = new List<Window>();
public Main Main { get; set; }
public UIElement TalkBox;
public winGameSetting winSetting { get; set; }
public winBetterBuy winBetterBuy { get; set; }
public winWorkMenu winWorkMenu { get; set; }
//public ChatGPTClient CGPTClient;
public ImageResources ImageSources { get; set; } = new ImageResources();
/// <summary>
/// 所有三方插件
/// </summary>
public List<MainPlugin> Plugins { get; } = new List<MainPlugin>();
/// <summary>
/// 所有字体(位置)
/// </summary>
public List<IFont> Fonts { get; } = new List<IFont>();
/// <summary>
/// 所有主题
/// </summary>
public List<Theme> Themes = new List<Theme>();
/// <summary>
/// 当前启用主题
/// </summary>
public Theme Theme = null;
/// <summary>
/// 加载主题
/// </summary>
/// <param name="themename">主题名称</param>
public void LoadTheme(string themename)
{
Theme ctheme = Themes.Find(x => x.Name == themename || x.xName == themename);
if (ctheme == null)
{
return;
}
Theme = ctheme;
//加载图片包
ImageSources.AddSources(ctheme.Images);
//阴影颜色
Application.Current.Resources["ShadowColor"] = Function.HEXToColor('#' + ctheme.ThemeColor[(gstr)"ShadowColor"]);
foreach (ILine lin in ctheme.ThemeColor.Assemblage.FindAll(x => !x.Name.Contains("Color")))
Application.Current.Resources[lin.Name] = new SolidColorBrush(Function.HEXToColor('#' + lin.info));
//系统生成部分颜色
Color c = Function.HEXToColor('#' + ctheme.ThemeColor["Primary"].info);
c.A = 204;
Application.Current.Resources["PrimaryTrans"] = new SolidColorBrush(c);
c.A = 44;
Application.Current.Resources["PrimaryTrans4"] = new SolidColorBrush(c);
c.A = 170;
Application.Current.Resources["PrimaryTransA"] = new SolidColorBrush(c);
c.A = 238;
Application.Current.Resources["PrimaryTransE"] = new SolidColorBrush(c);
c = Function.HEXToColor('#' + ctheme.ThemeColor["Secondary"].info);
c.A = 204;
Application.Current.Resources["SecondaryTrans"] = new SolidColorBrush(c);
c.A = 44;
Application.Current.Resources["SecondaryTrans4"] = new SolidColorBrush(c);
c.A = 170;
Application.Current.Resources["SecondaryTransA"] = new SolidColorBrush(c);
c.A = 238;
Application.Current.Resources["SecondaryTransE"] = new SolidColorBrush(c);
c = Function.HEXToColor('#' + ctheme.ThemeColor["DARKPrimary"].info);
c.A = 204;
Application.Current.Resources["DARKPrimaryTrans"] = new SolidColorBrush(c);
c.A = 44;
Application.Current.Resources["DARKPrimaryTrans4"] = new SolidColorBrush(c);
c.A = 170;
Application.Current.Resources["DARKPrimaryTransA"] = new SolidColorBrush(c);
c.A = 238;
Application.Current.Resources["DARKPrimaryTransE"] = new SolidColorBrush(c);
}
public void LoadFont(string fontname)
{
IFont cfont = Fonts.Find(x => x.Name == fontname);
if (cfont == null)
{
return;
}
Application.Current.Resources["MainFont"] = cfont.Font;
Panuon.WPF.UI.GlobalSettings.Setting.FontFamily = cfont.Font;
}
public List<Food> Foods { get; } = new List<Food>();
/// <summary>
/// 版本号
/// </summary>
public int version { get; } = 11000;
/// <summary>
/// 版本号
/// </summary>
public string Version => $"{version / 10000}.{version % 10000 / 100}.{version % 100:00}";
public List<LowText> LowFoodText { get; set; } = new List<LowText>();
public List<LowText> LowDrinkText { get; set; } = new List<LowText>();
public List<SelectText> SelectTexts { get; set; } = new List<SelectText>();
public List<ClickText> ClickTexts { get; set; } = new List<ClickText>();
public GameSave_v2 GameSavesData { get; set; }
/// <summary>
/// 获得自动点击的文本
/// </summary>
/// <returns>说话内容</returns>
public ClickText GetClickText()
{
ClickText.DayTime dt;
var now = DateTime.Now.Hour;
if (now < 6)
dt = ClickText.DayTime.Midnight;
else if (now < 12)
dt = ClickText.DayTime.Morning;
else if (now < 18)
dt = ClickText.DayTime.Afternoon;
else
dt = ClickText.DayTime.Night;
ClickText.ModeType mt;
switch (Core.Save.Mode)
{
case IGameSave.ModeType.PoorCondition:
mt = ClickText.ModeType.PoorCondition;
break;
default:
case IGameSave.ModeType.Nomal:
mt = ClickText.ModeType.Nomal;
break;
case IGameSave.ModeType.Happy:
mt = ClickText.ModeType.Happy;
break;
case IGameSave.ModeType.Ill:
mt = ClickText.ModeType.Ill;
break;
}
var list = ClickTexts.FindAll(x => x.DaiTime.HasFlag(dt) && x.Mode.HasFlag(mt) && x.CheckState(Main));
if (list.Count == 0)
return null;
return list[Function.Rnd.Next(list.Count)];
}
private Image hashcheckimg;
/// <summary>
/// 关闭该玩家的HashCheck检查
/// 如果你的mod属于作弊mod/有作弊内容,请在作弊前调用这个方法
/// </summary>
public void HashCheckOff()
{
HashCheck = false;
}
/// <summary>
/// 存档 Hash检查 是否通过
/// </summary>
public bool HashCheck
{
get => GameSavesData.HashCheck;
set
{
if (!value)
{
GameSavesData.HashCheckOff();
}
Main?.Dispatcher.Invoke(() =>
{
if (GameSavesData.HashCheck)
{
if (hashcheckimg == null)
{
hashcheckimg = new Image();
hashcheckimg.Source = ImageResources.NewSafeBitmapImage("pack://application:,,,/Res/hash.png");
hashcheckimg.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
hashcheckimg.ToolTip = "是没有修改过存档/使用超模MOD的玩家专属标志".Translate();
Grid.SetColumn(hashcheckimg, 4);
Grid.SetRowSpan(hashcheckimg, 2);
Main.ToolBar.gdPanel.Children.Add(hashcheckimg);
}
}
else
{
if (hashcheckimg != null)
{
Main.ToolBar.gdPanel.Children.Remove(hashcheckimg);
hashcheckimg = null;
}
}
});
}
}
public void SetZoomLevel(double zl)
{
Set.ZoomLevel = zl;
//this.Height = 500 * zl;
MGrid.Width = 500 * zl;
if (petHelper != null)
{
petHelper.Width = 50 * zl;
petHelper.Height = 50 * zl;
petHelper.ReloadLocation();
}
}
//private DateTime timecount = DateTime.Now;
/// <summary>
/// 保存设置
/// </summary>
public void Save()
{
foreach (MainPlugin mp in Plugins)
mp.Save();
//游戏存档
if (Set != null)
{
var st = Set.SaveTimesPP;
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);
//GameSavesData.Statistics[(gint)"stat_time"] = (int)(DateTime.Now - timecount).TotalMinutes;
//timecount = DateTime.Now;
}
Set.StartRecordLastPoint = new Point(Dispatcher.Invoke(() => Left), Dispatcher.Invoke(() => Top));
File.WriteAllText(ExtensionValue.BaseDirectory + @$"\Setting{PrefixSave}.lps", Set.ToString());
if (!Directory.Exists(ExtensionValue.BaseDirectory + @"\Saves"))
Directory.CreateDirectory(ExtensionValue.BaseDirectory + @"\Saves");
if (Core != null && Core.Save != null)
{
var ds = new List<string>(Directory.GetFiles(ExtensionValue.BaseDirectory + @"\Saves", $"Save{PrefixSave}_*.lps")).OrderBy(x =>
{
if (int.TryParse(x.Split('_').Last().Split('.')[0], out int i))
return i;
return 0;
}).ToList();
while (ds.Count > Set.BackupSaveMaxNum)
{
File.Delete(ds[0]);
ds.RemoveAt(0);
}
if (File.Exists(ExtensionValue.BaseDirectory + $"\\Saves\\Save{PrefixSave}_{st}.lps"))
File.Delete(ExtensionValue.BaseDirectory + $"\\Saves\\Save{PrefixSave}_{st}.lps");
File.WriteAllText(ExtensionValue.BaseDirectory + $"\\Saves\\Save{PrefixSave}_{st}.lps", GameSavesData.ToLPS().ToString());
if (File.Exists(ExtensionValue.BaseDirectory + @"\Save.lps"))
{
if (File.Exists(ExtensionValue.BaseDirectory + @"\Save.bkp"))
File.Delete(ExtensionValue.BaseDirectory + @"\Save.bkp");
File.Move(ExtensionValue.BaseDirectory + @"\Save.lps", ExtensionValue.BaseDirectory + @"\Save.bkp");
}
}
}
}
/// <summary>
/// 重载DIY按钮区域
/// </summary>
public void LoadDIY()
{
Main.ToolBar.MenuDIY.Items.Clear();
if (App.MutiSaves.Count > 1)
{
var list = App.MutiSaves.ToList();
foreach (var win in App.MainWindows)
{
list.Remove(win.PrefixSave);
}
list.Remove(PrefixSave);
if (list.Count > 0)
{
var menuItem = new System.Windows.Controls.MenuItem()
{
Header = "桌宠多开".Translate(),
HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center,
};
foreach (var win in list)
{
var mo = new System.Windows.Controls.MenuItem()
{
Header = win.Translate(),
HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center,
};
mo.Click += (s, e) =>
{
if (App.MainWindows.FirstOrDefault(x => x.PrefixSave.Trim('-') == win) == null)
{
new MainWindow(win).Show();
}
menuItem.Items.Remove(s);
};
menuItem.Items.Add(mo);
}
Main.ToolBar.MenuDIY.Items.Add(menuItem);
}
}
foreach (ISub sub in Set["diy"])
Main.ToolBar.AddMenuButton(ToolBar.MenuType.DIY, sub.Name, () =>
{
Main.ToolBar.Visibility = Visibility.Collapsed;
RunDIY(sub.Info);
});
try
{
//加载游戏创意工坊插件
foreach (MainPlugin mp in Plugins)
mp.LoadDIY();
}
catch (Exception e)
{
MessageBoxX.Show(e.ToString(), "由于插件引起的自定按钮加载错误".Translate());
}
}
/// <summary>
/// 加载帮助器
/// </summary>
public void LoadPetHelper()
{
petHelper = new PetHelper(this);
petHelper.Show();
}
public void RunDIY(string content)
{
if (content.Contains(@":\"))
{
try
{
if (!Set["v"][(gbol)"rundiy"])
{
MessageBoxX.Show("由于操作系统的设计,通过我们软件启动的程序可能会在任务管理器中归类为我们软件的子进程,这可能导致CPU/内存占用显示较高".Translate(),
"关于CPU/内存占用显示较高的一次性提示".Translate());
Set["v"][(gbol)"rundiy"] = true;
}
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = content;
startInfo.UseShellExecute = false;
Process.Start(startInfo);
}
catch
{
try
{
try
{
Process.Start(content);
}
catch
{
var psi = new ProcessStartInfo
{
FileName = content,
UseShellExecute = true
};
Process.Start(psi);
}
}
catch (Exception e)
{
MessageBoxX.Show("快捷键运行失败:无法运行指定内容".Translate() + '\n' + e.Message);
}
}
}
else if (content.Contains("://"))
{
try
{
ExtensionSetting.StartURL(content);
}
catch (Exception e)
{
MessageBoxX.Show("快捷键运行失败:无法运行指定内容".Translate() + '\n' + e.Message);
}
}
else
{
try
{
SendKeys.SendWait(content);
}
catch (Exception e)
{
MessageBoxX.Show("快捷键运行失败:无法运行指定内容".Translate() + '\n' + e.Message);
}
}
}
public void ShowSetting(int page = -1)
{
if (page >= 0 && page <= 6)
winSetting.MainTab.SelectedIndex = page;
winSetting.Show();
}
public void ShowWorkMenu(Work.WorkType type)
{
if (winWorkMenu == null)
{
winWorkMenu = new winWorkMenu(this, type);
winWorkMenu.Show();
}
else
{
winWorkMenu.LsbCategory.SelectedIndex = (int)type;
winWorkMenu.Focus();
winWorkMenu.Topmost = true;
}
}
public void ShowBetterBuy(Food.FoodType type)
{
winBetterBuy.Show(type);
}
int lowstrengthAskCountFood = 20;
int lowstrengthAskCountDrink = 20;
private void lowStrength()
{
var sm = Core.Save.StrengthMax;
var sm75 = sm * 0.75;
if (Set.AutoBuy && Core.Save.Money >= 100)
{
var havemoney = Core.Save.Money * 0.8;
List<Food> food = Foods.FindAll(x => x.Price >= 2 && x.Health >= 0 && x.Exp >= 0 && x.Likability >= 0 && x.Price < havemoney //桌宠不吃负面的食物
&& !x.IsOverLoad() // 不吃超模食物
);
if (Core.Save.StrengthFood < sm75)
{
if (Core.Save.StrengthFood < sm * 0.50)
{//太饿了,找正餐
food = food.FindAll(x => x.Type == Food.FoodType.Meal && x.StrengthFood > Math.Min(sm * 0.20, 100));
}
else
{//找零食
food = food.FindAll(x => x.Type == Food.FoodType.Snack && x.StrengthFood > Math.Min(sm * 0.10, 50));
}
if (food.Count == 0)
return;
var item = food[Function.Rnd.Next(food.Count)];
Core.Save.Money -= item.Price * 0.2;
TakeItem(item);
GameSavesData.Statistics[(gint)"stat_autobuy"]++;
Main.Display(item.GetGraph(), item.ImageSource, Main.DisplayToNomal);
}
else if (Core.Save.StrengthDrink < sm75)
{
food = food.FindAll(x => x.Type == Food.FoodType.Drink && x.StrengthDrink > Math.Min(sm * 0.10, 50));
if (food.Count == 0)
return;
var item = food[Function.Rnd.Next(food.Count)];
Core.Save.Money -= item.Price * 0.2;
TakeItem(item);
GameSavesData.Statistics[(gint)"stat_autobuy"]++;
Main.Display(item.GetGraph(), item.ImageSource, Main.DisplayToNomal);
}
else if (Set.AutoGift && Core.Save.Feeling < Core.Save.FeelingMax * 0.50)
{
food = food.FindAll(x => x.Type == Food.FoodType.Gift && x.Feeling > Math.Min(Core.Save.FeelingMax * 0.10, 50));
if (food.Count == 0)
return;
var item = food[Function.Rnd.Next(food.Count)];
Core.Save.Money -= item.Price * 0.2;
TakeItem(item);
GameSavesData.Statistics[(gint)"stat_autogift"]++;
Main.Display(item.GetGraph(), item.ImageSource, Main.DisplayToNomal);
}
}
else if (Core.Save.Mode == IGameSave.ModeType.Happy || Core.Save.Mode == IGameSave.ModeType.Nomal)
{
if (Core.Save.StrengthFood < sm75 && Function.Rnd.Next(lowstrengthAskCountFood--) == 0)
{
lowstrengthAskCountFood = Set.InteractionCycle;
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 (txt.Count != 0)
if (Core.Save.StrengthFood > sm * 0.60)
{
txt = txt.FindAll(x => x.Strength == LowText.StrengthType.L);
if (txt.Count != 0)
Main.Say(txt[Function.Rnd.Next(txt.Count)].TranslateText);
}
else if (Core.Save.StrengthFood > sm * 0.40)
{
txt = txt.FindAll(x => x.Strength == LowText.StrengthType.M);
if (txt.Count != 0)
Main.Say(txt[Function.Rnd.Next(txt.Count)].TranslateText);
}
else
{
txt = txt.FindAll(x => x.Strength == LowText.StrengthType.S);
if (txt.Count != 0)
Main.Say(txt[Function.Rnd.Next(txt.Count)].TranslateText);
}
Main.DisplayStopForce(() => Main.Display(GraphType.Switch_Hunger, AnimatType.Single, Main.DisplayToNomal));
return;
}
if (Core.Save.StrengthDrink < sm75 && Function.Rnd.Next(lowstrengthAskCountDrink--) == 0)
{
lowstrengthAskCountDrink = Set.InteractionCycle;
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 (txt.Count != 0)
if (Core.Save.StrengthDrink > sm * 0.60)
{
txt = txt.FindAll(x => x.Strength == LowText.StrengthType.L);
if (txt.Count != 0)
Main.Say(txt[Function.Rnd.Next(txt.Count)].TranslateText);
}
else if (Core.Save.StrengthDrink > sm * 0.40)
{
txt = txt.FindAll(x => x.Strength == LowText.StrengthType.M);
if (txt.Count != 0)
Main.Say(txt[Function.Rnd.Next(txt.Count)].TranslateText);
}
else
{
txt = txt.FindAll(x => x.Strength == LowText.StrengthType.S);
if (txt.Count != 0)
Main.Say(txt[Function.Rnd.Next(txt.Count)].TranslateText);
}
Main.DisplayStopForce(() => Main.Display(GraphType.Switch_Thirsty, AnimatType.Single, Main.DisplayToNomal));
return;
}
}
else
{
var sm20 = sm * 0.20;
if (Core.Save.StrengthFood < sm * 0.60 && Function.Rnd.Next(lowstrengthAskCountFood--) == 0)
{
lowstrengthAskCountFood = Set.InteractionCycle;
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 > sm * 0.40)
{
txt = txt.FindAll(x => x.Strength == LowText.StrengthType.L);
if (txt.Count != 0)
Main.Say(txt[Function.Rnd.Next(txt.Count)].TranslateText);
}
else if (Core.Save.StrengthFood > sm20)
{
txt = txt.FindAll(x => x.Strength == LowText.StrengthType.M);
if (txt.Count != 0)
Main.Say(txt[Function.Rnd.Next(txt.Count)].TranslateText);
}
else
{
txt = txt.FindAll(x => x.Strength == LowText.StrengthType.S);
if (txt.Count != 0)
Main.Say(txt[Function.Rnd.Next(txt.Count)].TranslateText);
}
Main.DisplayStopForce(() => Main.Display(GraphType.Switch_Hunger, AnimatType.Single, Main.DisplayToNomal));
return;
}
if (Core.Save.StrengthDrink < sm * 0.60 && Function.Rnd.Next(lowstrengthAskCountDrink--) == 0)
{
lowstrengthAskCountDrink = Set.InteractionCycle;
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 > sm * 0.40)
{
txt = txt.FindAll(x => x.Strength == LowText.StrengthType.L);
if (txt.Count != 0)
Main.Say(txt[Function.Rnd.Next(txt.Count)].TranslateText);
}
else if (Core.Save.StrengthDrink > sm20)
{
txt = txt.FindAll(x => x.Strength == LowText.StrengthType.M);
if (txt.Count != 0)
Main.Say(txt[Function.Rnd.Next(txt.Count)].TranslateText);
}
else
{
txt = txt.FindAll(x => x.Strength == LowText.StrengthType.S);
if (txt.Count != 0)
Main.Say(txt[Function.Rnd.Next(txt.Count)].TranslateText);
}
Main.DisplayStopForce(() => Main.Display(GraphType.Switch_Thirsty, AnimatType.Single, Main.DisplayToNomal));
return;
}
}
}
/// <summary>
/// 使用/食用物品 (不包括显示动画)
/// </summary>
/// <param name="item">物品</param>
public void TakeItem(Food item)
{
//获取吃腻时间
Main.LastInteractionTime = DateTime.Now;
DateTime now = DateTime.Now;
DateTime eattime = GameSavesData["buytime"].GetDateTime(item.Name, now);
double eattimes = 0;
if (eattime > now)
{
eattimes = (eattime - now).TotalHours;
}
//开始加点
Core.Save.EatFood(item, Math.Max(0.5, 1 - Math.Pow(eattimes, 2) * 0.01));
//吃腻了
eattimes += 2;
GameSavesData["buytime"].SetDateTime(item.Name, now.AddHours(eattimes));
//通知
item.LoadEatTimeSource(this);
item.NotifyOfPropertyChange("Description");
Core.Save.Money -= item.Price;
//统计
GameSavesData.Statistics[(gint)"stat_buytimes"]++;
GameSavesData.Statistics[(gint)("buy_" + item.Name)]++;
GameSavesData.Statistics[(gdbe)"stat_betterbuy"] += item.Price;
switch (item.Type)
{
case Food.FoodType.Food:
GameSavesData.Statistics[(gdbe)"stat_bb_food"] += item.Price;
break;
case Food.FoodType.Drink:
GameSavesData.Statistics[(gdbe)"stat_bb_drink"] += item.Price;
break;
case Food.FoodType.Drug:
GameSavesData.Statistics[(gdbe)"stat_bb_drug"] += item.Price;
GameSavesData.Statistics[(gdbe)"stat_bb_drug_exp"] += item.Exp;
break;
case Food.FoodType.Snack:
GameSavesData.Statistics[(gdbe)"stat_bb_snack"] += item.Price;
break;
case Food.FoodType.Functional:
GameSavesData.Statistics[(gdbe)"stat_bb_functional"] += item.Price;
break;
case Food.FoodType.Meal:
GameSavesData.Statistics[(gdbe)"stat_bb_meal"] += item.Price;
break;
case Food.FoodType.Gift:
GameSavesData.Statistics[(gdbe)"stat_bb_gift"] += item.Price;
GameSavesData.Statistics[(gdbe)"stat_bb_gift_like"] += item.Likability;
break;
}
}
public void RunAction(string action)
{
switch (action)
{
case "DisplayNomal":
Main.DisplayNomal();
break;
case "DisplayToNomal":
Main.DisplayToNomal();
break;
case "DisplayTouchHead":
Main.DisplayTouchHead();
break;
case "DisplayTouchBody":
Main.DisplayTouchBody();
break;
case "DisplayIdel":
Main.DisplayIdel();
break;
case "DisplayIdel_StateONE":
Main.DisplayIdel_StateONE();
break;
case "DisplaySleep":
Main.DisplaySleep();
break;
case "DisplayRaised":
Main.DisplayRaised();
break;
case "DisplayMove":
Main.DisplayMove();
break;
}
}
/// <summary>
/// Steam统计相关变化
/// </summary>
private void Statistics_StatisticChanged(Statistics sender, string name, SetObject value)
{
if (name.StartsWith("stat_"))
{
SteamUserStats.SetStat(name, (int)value);
}
}
/// <summary>
/// 计算统计数据
/// </summary>
private void StatisticsCalHandle()
{
var stat = GameSavesData.Statistics;
var save = Core.Save;
stat["stat_money"] = (SetObject)save.Money;
stat["stat_level"] = save.Level;
stat["stat_likability"] = save.Likability;
stat[(gi64)"stat_total_time"] += (int)Set.LogicInterval;
switch (Main.State)
{
case Main.WorkingState.Work:
if (Main.NowWork.Type == Work.WorkType.Work)
stat[(gi64)"stat_work_time"] += (int)Set.LogicInterval;
else
stat[(gi64)"stat_study_time"] += (int)Set.LogicInterval;
break;
case Main.WorkingState.Sleep:
stat[(gi64)"stat_sleep_time"] += (int)Set.LogicInterval;
break;
}
if (save.Mode == IGameSave.ModeType.Ill)
{
if (save.Money < 100)
stat["stat_ill_nomoney"] = 1;
}
if (save.Money < save.Level)
{
stat["stat_level_g_money"] = 1;
}
if (save.Feeling < 1)
{
stat["stat_0_feel"] = 1;
if (save.StrengthDrink < 1)
stat["stat_0_f_sd"] = 1;
}
if (save.Strength < 1 && save.Feeling < 1 && save.StrengthFood < 1 && save.StrengthDrink < 1)
stat["stat_0_all"] = 1;
if (save.StrengthFood < 1)
stat["stat_0_strengthfood"] = 1;
if (save.StrengthDrink < 1)
{
stat["stat_0_strengthdrink"] = 1;
if (save.StrengthFood < 1)
stat["stat_0_sd_sf"] = 1;
}
if (save.Strength > 99 && save.Feeling > 99 && save.StrengthFood > 99 && save.StrengthDrink > 99)
stat[(gint)"stat_100_all"]++;
if (IsSteamUser)
{
Task.Run(SteamUserStats.StoreStats);
}
}
/// <summary>
/// 加载游戏存档
/// </summary>
public bool SavesLoad(ILPS lps)
{
if (lps == null)
return false;
if (string.IsNullOrWhiteSpace(lps.ToString()))
return false;
GameSave_v2 tmp;
if (GameSavesData != null)
tmp = new GameSave_v2(lps, GameSavesData);
else
{
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, null, 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
return false;
if (tmp.GameSave.Exp < -1000000000)
{
tmp.GameSave.Exp = 1000000;
tmp.Data[(gbol)"round"] = true;
Dispatcher.Invoke(() => MessageBoxX.Show("检测到经验值超过 9,223,372,036 导致算数溢出\n已经自动回正".Translate(), "数据溢出警告".Translate()));
}
if (tmp.GameSave.Money < -1000000000)
{
tmp.GameSave.Money = 100000;
Dispatcher.Invoke(() => MessageBoxX.Show("检测到金钱超过 9,223,372,036 导致算数溢出\n已经自动回正".Translate(), "数据溢出警告".Translate()));
}
if (tmp.Data[(gbol)"round"])
{//根据游玩时间补偿数据溢出
Dispatcher.Invoke(() => MessageBoxX.Show("您以前遭遇过数据溢出, 已根据游戏时长自动添加进当前数值".Translate(), "数据溢出恢复".Translate()));
var totalhour = (int)(tmp.Statistics[(gint)"stat_total_time"] / 3600);//总计游玩时间/小时
if (totalhour < 500)
{
tmp.GameSave.Exp += totalhour * 200;
}
else
{
double lm = Math.Sqrt(totalhour / 500);
tmp.GameSave.LevelMax += (int)lm;
tmp.GameSave.Exp += (totalhour % 500 + (lm - (int)lm) * 500) * 200;
}
tmp.GameSave.LikabilityMax += totalhour / 10;
tmp.Data[(gbol)"round"] = false;
}
GameSavesData = tmp;
Core.Save = tmp.GameSave;
HashCheck = HashCheck;
return true;
}
private void Handle_Steam(Main obj)
{
string jointab = " ";
if (winMutiPlayer != null)
{
if (winMutiPlayer.Joinable)
jointab += "可加入".Translate();
SteamFriends.SetRichPresence("steam_player_group", winMutiPlayer.LobbyID.ToString("x"));
SteamFriends.SetRichPresence("steam_player_group_size", winMutiPlayer.lb.MemberCount.ToString());
}
else
{
SteamFriends.SetRichPresence("steam_player_group_size", "0");
}
if (App.MainWindows.Count > 1)
{
if (App.MainWindows.FirstOrDefault() != this)
{
return;
}
string str = "";
int lv = 0;
int workcount = 0;
int sleepcount = 0;
int musiccount = 0;
int allcount = App.MainWindows.Count * 2 / 3;
foreach (var item in App.MainWindows)
{
str += item.GameSavesData.GameSave.Name + ",";
if (item.HashCheck)
{
lv += item.GameSavesData.GameSave.Level;
}
else
lv = int.MinValue;
switch (item.Main.State)
{
case Main.WorkingState.Work:
workcount++;
break;
case Main.WorkingState.Sleep:
sleepcount++;
break;
case Main.WorkingState.Nomal:
if (item.Main.DisplayType.Name == "music")
musiccount++;
break;
}
}
SteamFriends.SetRichPresence("usernames", str.Trim(','));
if (lv > 0)
{
SteamFriends.SetRichPresence("lv", $" (lv{lv}/{App.MainWindows.Count})" + jointab);
}
else
{
SteamFriends.SetRichPresence("lv", " " + jointab);
}
if (workcount > allcount)
{
SteamFriends.SetRichPresence("steam_display", "#Status_MUTI_Work");
}
else if (sleepcount > allcount)
{
SteamFriends.SetRichPresence("steam_display", "#Status_MUTI_Sleep");
}
else if (musiccount > allcount)
{
SteamFriends.SetRichPresence("steam_display", "#Status_MUTI_Music");
}
else
{
SteamFriends.SetRichPresence("steam_display", "#Status_MUTI_Play");
}
}
else
{
if (HashCheck)
{
SteamFriends.SetRichPresence("lv", $" (lv{GameSavesData.GameSave.Level})" + jointab);
}
else
{
SteamFriends.SetRichPresence("lv", " " + jointab);
}
if (Core.Save.Mode == IGameSave.ModeType.Ill)
{
SteamFriends.SetRichPresence("steam_display", "#Status_Ill");
}
else
{
SteamFriends.SetRichPresence("mode", (Core.Save.Mode.ToString() + "ly").Translate());
switch (obj.State)
{
case Main.WorkingState.Work:
SteamFriends.SetRichPresence("work", obj.NowWork.Name.Translate());
SteamFriends.SetRichPresence("steam_display", "#Status_Work");
break;
case Main.WorkingState.Sleep:
SteamFriends.SetRichPresence("steam_display", "#Status_Sleep");
break;
default:
if (obj.DisplayType.Name == "music")
SteamFriends.SetRichPresence("steam_display", "#Status_Music");
else
{
switch (obj.DisplayType.Type)
{
case GraphType.Move:
SteamFriends.SetRichPresence("idel", "乱爬".Translate());