forked from Provissy/HoppoPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainViewViewModel.cs
737 lines (612 loc) · 22.5 KB
/
MainViewViewModel.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Threading.Tasks;
using Grabacr07.KanColleViewer.ViewModels.Catalogs;
using Grabacr07.KanColleWrapper;
using Grabacr07.KanColleWrapper.Models;
using Grabacr07.KanColleViewer.Models;
using Livet.EventListeners;
using System.Threading;
using System.Timers;
using System.Windows.Threading;
using System.IO;
using System.Windows;
using System.Net;
using System.Text.RegularExpressions;
using System.ComponentModel.Composition;
using Grabacr07.KanColleViewer.Composition;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Management;
using MetroRadiance;
using Grabacr07.KanColleViewer;
using System.Reflection;
namespace HoppoPlugin
{
public class MainViewViewModel : Grabacr07.KanColleViewer.ViewModels.TabItemViewModel
{
[DllImport("user32.dll", EntryPoint = "WindowFromPoint")]
public static extern int WindowFromPoint(
int xPoint,
int yPoint
);
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect);
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
#region Storie data.
/// <summary>
/// 全舰娘等级,一行20个。
/// </summary>
public static int[] ExpTable = new int[] { 0, 0, 100, 300, 600, 1000, 1500, 2100, 2800, 3600, 4500, 5500, 6600, 7800, 9100, 10500, 12000, 13600, 15300, 17100, 19000,
21000, 23100, 25300, 27600, 30000, 32500, 35100, 37800, 40600, 43500, 46500, 49600, 52800, 56100, 59500, 63000, 66600, 70300, 74100, 78000,
82000, 86100, 90300, 94600, 99000, 103500, 108100, 112800, 117600, 122500, 127500, 132700, 138100, 143700, 149500, 155500, 161700, 168100, 174700, 181500,
188500, 195800, 203400, 211300, 219500, 228000, 236800, 245900, 255300, 265000, 275000, 285400, 296200, 307400, 319000, 331000, 343400, 356200, 369400, 383000,
397000, 411500, 426500, 442000, 458000, 474500, 491500, 509000, 527000, 545500, 564500, 584500, 606500, 631500, 661500, 701500, 761500, 851500, 1000000, 1000000,
1010000, 1011000, 1013000, 1016000, 1020000, 1025000, 1031000, 1038000, 1046000, 1055000, 1065000, 1077000, 1091000, 1107000, 1125000, 1145000, 1168000, 1194000, 1223000, 1255000,
1290000, 1329000, 1372000, 1419000, 1470000, 1525000, 1584000, 1647000, 1714000, 1785000, 1860000, 1940000, 2025000, 2115000, 2210000, 2310000, 2415000, 2525000, 2640000, 2760000,
2887000, 3021000, 3162000, 3310000, 3465000, 3628000, 3799000, 3978000, 4165000, 4360000 };
/// <summary>
/// 海域EXP。
/// </summary>
public IEnumerable<string> SeaList { get; private set; }
public static Dictionary<string, int> SeaExpTable = new Dictionary<string, int>
{
{"1-1", 30}, {"1-2", 50}, {"1-3", 80}, {"1-4", 100}, {"1-5", 150},
{"2-1", 120}, {"2-2", 150}, {"2-3", 200},{"2-4", 300},
{"3-1", 310}, {"3-2", 320}, {"3-3", 330}, {"3-4", 350},
{"4-1", 310}, {"4-2", 320}, {"4-3", 330}, {"4-4", 340},
{"5-1", 360}, {"5-2", 380}, {"5-3", 400}, {"5-4", 420}, {"5-5", 450}
};
#endregion
public IEnumerable<string> ResultList { get; private set; }
public string[] Results = { "S", "A", "B", "C", "D", "E" };
private readonly Subject<Unit> updateSource = new Subject<Unit>();
private Homeport homeport = null;
public ShipCatalogSortWorker SortWorker { get; private set; }
private bool isInitialised = false;
#region Ships 変更通知プロパティ
private IReadOnlyCollection<ShipViewModel> _Ships;
public IReadOnlyCollection<ShipViewModel> Ships
{
get { return this._Ships; }
set
{
if (this._Ships != value)
{
this._Ships = value;
this.RaisePropertyChanged();
}
}
}
#endregion
#region CurrentShip 変更通知プロパティ
private Ship _CurrentShip;
public Ship CurrentShip
{
get { return this._CurrentShip; }
set
{
if (this._CurrentShip != value)
{
this._CurrentShip = value;
if (value != null)
{
this.CurrentLevel = this.CurrentShip.Level;
this.TargetLevel = Math.Min(this.CurrentShip.Level + 1, 150);
this.CurrentExp = this.CurrentShip.Exp;
this.UpdateExpCalculator();
this.RaisePropertyChanged();
}
}
}
}
#endregion
#region CurrentLevel 変更通知プロパティ
private int _CurrentLevel;
public int CurrentLevel
{
get { return this._CurrentLevel; }
set
{
if (this._CurrentLevel != value && value >= 1 && value <= 150)
{
this._CurrentLevel = value;
this.CurrentExp = ExpTable[value];
this.TargetLevel = Math.Max(this.TargetLevel, Math.Min(value + 1, 150));
this.RaisePropertyChanged();
this.UpdateExpCalculator();
}
}
}
#endregion
#region TargetLevel 変更通知プロパティ
private int _TargetLevel;
public int TargetLevel
{
get { return this._TargetLevel; }
set
{
if (this._TargetLevel != value && value >= 1 && value <= 150)
{
this._TargetLevel = value;
this.TargetExp = ExpTable[value];
this.CurrentLevel = Math.Min(this.CurrentLevel, Math.Max(value - 1, 1));
this.RaisePropertyChanged();
this.UpdateExpCalculator();
}
}
}
#endregion
#region SelectedSea 変更通知プロパティ
private string _SelectedSea;
public string SelectedSea
{
get { return this._SelectedSea; }
set
{
if (_SelectedSea != value)
{
this._SelectedSea = value;
this.RaisePropertyChanged();
this.UpdateExpCalculator();
}
}
}
#endregion
#region SelectedResult 変更通知プロパティ
private string _SelectedResult;
public string SelectedResult
{
get { return this._SelectedResult; }
set
{
if (this._SelectedResult != value)
{
this._SelectedResult = value;
this.RaisePropertyChanged();
this.UpdateExpCalculator();
}
}
}
#endregion
#region IsFlagship 変更通知プロパティ
private bool _IsFlagship;
public bool IsFlagship
{
get { return this._IsFlagship; }
set
{
if (this._IsFlagship != value)
{
this._IsFlagship = value;
this.RaisePropertyChanged();
this.UpdateExpCalculator();
}
}
}
#endregion
#region IsMVP 変更通知プロパティ
private bool _IsMVP;
public bool IsMVP
{
get { return this._IsMVP; }
set
{
if (this._IsMVP != value)
{
this._IsMVP = value;
this.RaisePropertyChanged();
this.UpdateExpCalculator();
}
}
}
#endregion
#region IsReloading 変更通知プロパティ
private bool _IsReloading;
public bool IsReloading
{
get { return this._IsReloading; }
set
{
if (this._IsReloading != value)
{
this._IsReloading = value;
this.RaisePropertyChanged();
this.UpdateExpCalculator();
}
}
}
#endregion
#region CurrentExp 変更通知プロパティ
private int _CurrentExp;
public int CurrentExp
{
get { return this._CurrentExp; }
private set
{
if (this._CurrentExp != value)
{
this._CurrentExp = value;
this.RaisePropertyChanged();
}
}
}
#endregion
#region TargetExp 変更通知プロパティ
private int _TargetExp;
public int TargetExp
{
get { return this._TargetExp; }
private set
{
if (this._TargetExp != value)
{
this._TargetExp = value;
this.RaisePropertyChanged();
}
}
}
#endregion
#region SortieExp 変更通知プロパティ
private int _SortieExp;
public int SortieExp
{
get { return this._SortieExp; }
private set
{
if (this._SortieExp != value)
{
this._SortieExp = value;
this.RaisePropertyChanged();
}
}
}
#endregion
#region RemainingExp 変更通知プロパティ
private int _RemainingExp;
public int RemainingExp
{
get { return this._RemainingExp; }
private set
{
if (this._RemainingExp != value)
{
this._RemainingExp = value;
this.RaisePropertyChanged();
}
}
}
#endregion
#region RunCount 変更通知プロパティ
private int _RunCount;
public int RunCount
{
get { return this._RunCount; }
private set
{
if (this._RunCount != value)
{
this._RunCount = value;
this.RaisePropertyChanged();
}
}
}
#endregion
#region Initialised 変更通知プロパティ
public bool Initialised
{
get { return this.isInitialised; }
set
{
this.isInitialised = value;
this.RaisePropertyChanged();
}
}
#endregion
#region CurrentEnableSoundNotify 変更通知プロパティ
public bool CurrentEnableSoundNotify
{
get { return HoppoPluginSettings.Current.EnableSoundNotify; }
set
{
if (HoppoPluginSettings.Current.EnableSoundNotify != value)
{
HoppoPluginSettings.Current.EnableSoundNotify = value;
HoppoPluginSettings.Current.Save();
this.RaisePropertyChanged();
}
}
}
#endregion
#region NekoDetector 変更通知プロパティ
public bool _CurrentNekoDetector;
public bool CurrentNekoDetector
{
get { return _CurrentNekoDetector; }
set
{
if (_CurrentNekoDetector != value)
{
nekoDetector(value);
_CurrentNekoDetector = value;
this.RaisePropertyChanged();
}
}
}
#endregion
#region CurrentIsDarkTheme 変更通知プロパティ
public bool CurrentIsDarkTheme
{
get { return HoppoPluginSettings.Current.IsDarkTheme; }
set
{
if (HoppoPluginSettings.Current.IsDarkTheme != value)
{
if (value) ThemeService.Current.ChangeTheme(Theme.Dark);
HoppoPluginSettings.Current.IsDarkTheme = value;
HoppoPluginSettings.Current.Save();
this.RaisePropertyChanged();
}
}
}
#endregion
#region CurrentIsLightTheme 変更通知プロパティ
public bool CurrentIsLightTheme
{
get { return HoppoPluginSettings.Current.IsLightTheme; }
set
{
if (HoppoPluginSettings.Current.IsLightTheme != value)
{
if (value) ThemeService.Current.ChangeTheme(Theme.Light);
HoppoPluginSettings.Current.IsLightTheme = value;
HoppoPluginSettings.Current.Save();
this.RaisePropertyChanged();
}
}
}
#endregion
#region CurrentVolume 変更通知プロパティ
public double CurrentVolume
{
get { return HoppoPluginSettings.Current.Volume; }
set
{
if (HoppoPluginSettings.Current.Volume != value)
{
HoppoPluginSettings.Current.Volume = value;
HoppoPluginSettings.Current.Save();
this.RaisePropertyChanged();
}
}
}
#endregion
#region CurrentEnableNotifyIcon 変更通知プロパティ
public bool CurrentEnableNotifyIcon
{
get { return HoppoPluginSettings.Current.EnableNotifyIcon; }
set
{
if (HoppoPluginSettings.Current.EnableNotifyIcon != value)
{
HoppoPluginSettings.Current.EnableNotifyIcon = value;
HoppoPluginSettings.Current.Save();
this.RaisePropertyChanged();
}
}
}
#endregion
#region CurrentEnableNAS 変更通知プロパティ
public bool CurrentEnableNAS
{
get { return HoppoPluginSettings.Current.EnableNAS; }
set
{
if (HoppoPluginSettings.Current.EnableNAS != value)
{
HoppoPluginSettings.Current.EnableNAS = value;
HoppoPluginSettings.Current.Save();
this.RaisePropertyChanged();
}
}
}
#endregion
public override string Name
{
get { return "HoppoPlugin"; }
protected set { throw new NotImplementedException(); }
}
public Logger Logger { get; private set; }
WebClient wClient = new WebClient();
GameWatcher gameWatcher = new GameWatcher();
DispatcherTimer timer = new DispatcherTimer();
public MainViewViewModel()
{
this.CompositeDisposable.Add(new PropertyChangedEventListener(KanColleClient.Current)
{
{ () => KanColleClient.Current.IsStarted, (sender, args) => this.UpdateMode() },
});
this.SeaList = SeaExpTable.Keys.ToList();
this.ResultList = Results.ToList();
this.SortWorker = new ShipCatalogSortWorker();
this.SortWorker.SetTarget(ShipCatalogSortTarget.Level, true);
this.updateSource
.Do(_ => this.IsReloading = true)
.Throttle(TimeSpan.FromMilliseconds(7.0))
.Do(_ => this.UpdateCore())
.Subscribe(_ => this.IsReloading = false);
this.CompositeDisposable.Add(this.updateSource);
SelectedSea = SeaExpTable.Keys.FirstOrDefault();
SelectedResult = Results.FirstOrDefault();
this.Update();
this.Logger = new Logger(KanColleClient.Current.Proxy);
timer.Tick += new EventHandler(timer_Tick);
timer.Interval = TimeSpan.FromSeconds(5);
timer.Start();
}
//public TabItemViewModel
void timer_Tick(object sender, EventArgs e)
{
timer.Stop();
Grabacr07.KanColleViewer.App.Current.MainWindow.Closing += new System.ComponentModel.CancelEventHandler(kcvCanceling);
}
private void kcvCanceling(object o ,System.ComponentModel.CancelEventArgs e)
{
MessageBoxResult mbr = MessageBox.Show("确定要退出KanColleViewer么?", "HoppoPlugin提示", MessageBoxButton.YesNo, MessageBoxImage.Warning);
if(mbr == MessageBoxResult.No)
{
e.Cancel = true;
return;
}
NekoAvoidanceSystem.Shutdown();
}
public void clearHoppoPlugin()
{
try
{
if (MessageBoxResult.No == MessageBox.Show("此操作会强制终止KCV,确定继续么?", "WARNING", MessageBoxButton.YesNo, MessageBoxImage.Warning))
return;
MessageBox.Show("清空设置后后将会关闭KanColleViewer!");
File.Delete(HoppoPluginSettings.HPSettingsPath);
(Process.GetProcessesByName("KanColleViewer")[0]).Kill();
}
catch(Exception ex)
{
MessageBox.Show("Error ! " + ex.ToString());
}
}
public void Update()
{
this.RaisePropertyChanged("AllShipTypes");
this.updateSource.OnNext(Unit.Default);
}
private void UpdateCore()
{
if (!this.Initialised)
{
return;
}
var list = this.homeport.Organization.Ships.Values
.Where(x => x.Level != 1);
this.Ships = this.SortWorker.Sort(list)
.Select((x, i) => new ShipViewModel(i + 1, x)).ToList();
}
private void UpdateMode()
{
if (!this.Initialised)
{
this.Initialised = true;
this.homeport = KanColleClient.Current.Homeport;
this.CompositeDisposable.Add(new PropertyChangedEventListener(this.homeport.Organization)
{
{ () => this.homeport.Organization.Ships, (sender, args) => this.Update() },
});
}
}
public void UpdateExpCalculator()
{
if (this.TargetLevel < this.CurrentLevel || this.TargetExp < this.CurrentExp)
return;
double Multiplier = (this.IsFlagship ? 1.5 : 1) * (this.IsMVP ? 2 : 1) * (this.SelectedResult == "S" ? 1.2 : (this.SelectedResult == "C" ? 0.8 : (this.SelectedResult == "D" ? 0.7 : (this.SelectedResult == "E" ? 0.5 : 1))));
this.SortieExp = (int)Math.Round(SeaExpTable[this.SelectedSea] * Multiplier);
this.RemainingExp = this.TargetExp - this.CurrentExp;
this.RunCount = (int)Math.Round(this.RemainingExp / (double)this.SortieExp);
}
private void nekoDetector(bool b)
{
MessageBox.Show("请注意,不能在分离模式下启用此功能。");
IntPtr hWnd = GetForegroundWindow();
RECT rect = new RECT();
GetWindowRect(hWnd, ref rect);
int width = rect.Right - rect.Left;
int height = rect.Bottom - rect.Top;
int x = rect.Left;
int y = rect.Top;
try
{
if (b)
{
int a = Convert.ToInt32(WindowFromPoint(x + 100, y + 100));
GameWatcher.Instance.Start((IntPtr)a);
}
else
{
GameWatcher.Instance.Stop();
}
}
catch (Exception ex)
{
MessageBox.Show("ERROR" + ex.ToString());
}
}
#region MapInfoProxy変更通知プロパティ
private MapInfoProxy _MapInfoProxy;
public MapInfoProxy MapInfoProxy
{
get
{ return _MapInfoProxy; }
set
{
if (_MapInfoProxy == value)
return;
_MapInfoProxy = value;
if (_MapInfoProxy != null)
{
_MapInfoProxy.PropertyChanged += (sender, e) =>
{
if (e.PropertyName == "Maps")
{
RaisePropertyChanged(() => NextEventMapHp);
RaisePropertyChanged(() => RemainingCount);
}
};
}
RaisePropertyChanged();
}
}
#endregion
public string NextEventMapHp
{
get
{
if (MapInfoProxy.Maps == null) return "No Data";
var map = MapInfoProxy.Maps.api_data.LastOrDefault(x => x.api_eventmap != null);
if (map == null) return "No Map";
return map.api_eventmap.api_now_maphp + "/" + map.api_eventmap.api_max_maphp;
}
}
public string RemainingCount
{
get
{
var shipMaster = KanColleClient.Current.Master.Ships;
if (MapInfoProxy == null || MapInfoProxy.Maps == null) return "No Data";
var map = MapInfoProxy.Maps.api_data.LastOrDefault(x => x.api_eventmap != null);
if (map == null) return "No Map";
if (!MapInfo.EventBossDictionary.ContainsKey(map.api_id)) return "Unknow";
var lastBossHp = shipMaster
.Single(x => x.Key == MapInfo.EventBossDictionary[map.api_id].Last())
.Value.HP;
var normalBossHp = shipMaster
.Single(x => x.Key == MapInfo.EventBossDictionary[map.api_id].First())
.Value.HP;
if (map.api_eventmap.api_now_maphp <= lastBossHp) return "1回";
return (Math.Ceiling((double)(map.api_eventmap.api_now_maphp - lastBossHp) / normalBossHp) + 1) + "回";
}
}
}
}