/
MainWindow.xaml.cs
796 lines (698 loc) · 35.7 KB
/
MainWindow.xaml.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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Threading;
using NHotkey;
using NHotkey.Wpf;
namespace OverParse
{
// TODO: Code Optimization
public partial class MainWindow : Window
{
private Log encounterlog;
private List<Combatant> lastCombatants = new List<Combatant>();
public DispatcherTimer damageTimer = new DispatcherTimer();
public static Dictionary<string, string> skillDict = new Dictionary<string, string>();
public static string[] ignoreskill;
private List<string> sessionLogFilenames = new List<string>();
private string lastStatus = "";
private IntPtr hwndcontainer;
List<Combatant> workingList = new List<Combatant>();
Process thisProcess = Process.GetCurrentProcess();
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
// Get this window's handle
IntPtr hwnd = new WindowInteropHelper(this).Handle;
hwndcontainer = hwnd;
}
public MainWindow()
{
InitializeComponent();
Dispatcher.UnhandledException += Panic;
LowResources.IsChecked = Properties.Settings.Default.LowResources;
CPUdraw.IsChecked = Properties.Settings.Default.CPUdraw;
if (Properties.Settings.Default.LowResources) { thisProcess.PriorityClass = ProcessPriorityClass.Idle; }
if (Properties.Settings.Default.CPUdraw)
{
RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
}
else
{
RenderOptions.ProcessRenderMode = RenderMode.Default;
}
try { Directory.CreateDirectory("Logs"); }
catch
{
MessageBox.Show("Overparse cannot save logs at the moment. \n\nPlease check that you are running Overparse as an administrator or that your account has read/write access to this directory", "OverParse Setup", MessageBoxButton.OK, MessageBoxImage.Error);
Application.Current.Shutdown();
}
//Directory.CreateDirectory("Debug");
//FileStream filestream = new FileStream("Debug\\log_" + string.Format("{0:yyyy-MM-dd_hh-mm-ss-tt}", DateTime.Now) + ".txt", FileMode.Create);
//var streamwriter = new StreamWriter(filestream)
//{
// AutoFlush = true
//};
//Console.SetOut(streamwriter);
//Console.SetError(streamwriter);
//Console.WriteLine("OVERPARSE V." + Assembly.GetExecutingAssembly().GetName().Version);
if (Properties.Settings.Default.UpgradeRequired && !Properties.Settings.Default.ResetInvoked)
{
//Console.WriteLine("Upgrading settings");
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.UpgradeRequired = false;
}
Properties.Settings.Default.ResetInvoked = false;
Top = Properties.Settings.Default.Top;
Left = Properties.Settings.Default.Left;
Height = Properties.Settings.Default.Height;
Width = Properties.Settings.Default.Width;
//Console.WriteLine("Applying UI settings");
//Console.WriteLine(this.Top = Properties.Settings.Default.Top);
//Console.WriteLine(this.Left = Properties.Settings.Default.Left);
//Console.WriteLine(this.Height = Properties.Settings.Default.Height);
//Console.WriteLine(this.Width = Properties.Settings.Default.Width);
bool outOfBounds = (Left <= SystemParameters.VirtualScreenLeft - Width) ||
(Top <= SystemParameters.VirtualScreenTop - Height) ||
(SystemParameters.VirtualScreenLeft + SystemParameters.VirtualScreenWidth <= Left) ||
(SystemParameters.VirtualScreenTop + SystemParameters.VirtualScreenHeight <= Top);
if (outOfBounds)
{
//Console.WriteLine("Window's off-screen, resetting");
Top = 50;
Left = 50;
}
AutoEndEncounters.IsChecked = Properties.Settings.Default.AutoEndEncounters;
SetEncounterTimeout.IsEnabled = AutoEndEncounters.IsChecked;
SeparateZanverse.IsChecked = Properties.Settings.Default.SeparateZanverse;
SeparateFinish.IsChecked = Properties.Settings.Default.SeparateFinish;
SeparateAIS.IsChecked = Properties.Settings.Default.SeparateAIS;
SeparateDB.IsChecked = Properties.Settings.Default.SeparateDB;
SeparateRide.IsChecked = Properties.Settings.Default.SeparateRide;
SeparatePwp.IsChecked = Properties.Settings.Default.SeparatePwp;
SeparateLsw.IsChecked = Properties.Settings.Default.SeparateLsw;
HidePlayers.IsChecked = Properties.Settings.Default.HidePlayers;
HideAIS.IsChecked = Properties.Settings.Default.HideAIS;
HideDB.IsChecked = Properties.Settings.Default.HideDB;
HideRide.IsChecked = Properties.Settings.Default.HideRide;
HidePwp.IsChecked = Properties.Settings.Default.HidePwp;
HideLsw.IsChecked = Properties.Settings.Default.HideLsw;
//NoMyName.IsChecked = Properties.Settings.Default.NomyName;
Onlyme.IsChecked = Properties.Settings.Default.Onlyme;
DPSFormat.IsChecked = Properties.Settings.Default.DPSformat;
Nodecimal.IsChecked = Properties.Settings.Default.Nodecimal;
ClickthroughMode.IsChecked = Properties.Settings.Default.ClickthroughEnabled;
LogToClipboard.IsChecked = Properties.Settings.Default.LogToClipboard;
AlwaysOnTop.IsChecked = Properties.Settings.Default.AlwaysOnTop;
AutoHideWindow.IsChecked = Properties.Settings.Default.AutoHideWindow;
ShowDamageGraph.IsChecked = Properties.Settings.Default.ShowDamageGraph; ShowDamageGraph_Click(null, null);
AnonymizeNames.IsChecked = Properties.Settings.Default.AnonymizeNames; AnonymizeNames_Click(null, null);
HighlightYourDamage.IsChecked = Properties.Settings.Default.HighlightYourDamage; HighlightYourDamage_Click(null, null);
Clock.IsChecked = Properties.Settings.Default.Clock; Clock_Click(null, null);
SeparateAIS_Click(null, null);
SeparateDB_Click(null, null);
SeparateRide_Click(null, null);
SeparatePwp_Click(null, null);
SeparateLsw_Click(null, null);
HandleWindowOpacity(); HandleListOpacity();
LoadListColumn();
// Console.WriteLine($"Launch method: {Properties.Settings.Default.LaunchMethod}");
if (Properties.Settings.Default.Maximized)
{
WindowState = WindowState.Maximized;
}
try
{
HotkeyManager.Current.AddOrReplace("End Encounter", Key.E, ModifierKeys.Control | ModifierKeys.Shift, EndEncounter_Key);
HotkeyManager.Current.AddOrReplace("End Encounter (No log)", Key.R, ModifierKeys.Control | ModifierKeys.Shift, EndEncounterNoLog_Key);
HotkeyManager.Current.AddOrReplace("Default Window Size", Key.D, ModifierKeys.Control | ModifierKeys.Shift, DefaultWindowSize_Key);
HotkeyManager.Current.AddOrReplace("Always On Top", Key.A, ModifierKeys.Control | ModifierKeys.Shift, AlwaysOnTop_Key);
} catch {
MessageBox.Show("Hot keys are currently not working for this instance of Overparse. \n\nPlease check that you are not running multiple instances of Overparse", "OverParse Setup", MessageBoxButton.OK, MessageBoxImage.Information);
}
// skills.csv
Console.WriteLine("Updating skills.csv");
string[] tmp;
try
{
WebClient client = new WebClient();
Stream stream = client.OpenRead("https://raw.githubusercontent.com/VariantXYZ/PSO2ACT/master/PSO2ACT/skills.csv");
using (StreamReader webreader = new StreamReader(stream))
{
String content = webreader.ReadToEnd();
tmp = content.Split('\n');
File.WriteAllText("skills.csv", content);
}
client.Dispose();
stream.Dispose();
}
catch (Exception ex)
{
Console.WriteLine($"skills.csv update failed: {ex.ToString()}");
if (File.Exists("skills.csv"))
{
MessageBox.Show("OverParse failed to update its skill mappings. This usually means your connection hiccuped for a moment.\n\nA local copy will be used instead. If you'd like to try and update again, just relaunch OverParse.", "OverParse Setup", MessageBoxButton.OK, MessageBoxImage.Information);
tmp = File.ReadAllLines("skills.csv");
}
else
{
MessageBox.Show("OverParse failed to update its skill mappings. This usually means your connection hiccuped for a moment.\n\nSince you have no skill mappings downloaded, all attacks will be marked as \"Unknown\". If you'd like to try and update again, please relaunch OverParse.", "OverParse Setup", MessageBoxButton.OK, MessageBoxImage.Information);
tmp = new string[0];
}
}
// ignoreskills.csv
try
{
WebClient client = new WebClient();
client.DownloadFile("https://raw.githubusercontent.com/mysterious64/OverParse/master/OverParse/Updates/ignoreskills.csv", "ignoreskills.csv");
}
catch
{
MessageBox.Show("Cannot update your local ignoreskills.csv please be warned that JA data might be wrong.\n\nA local copy will be used instead. If you'd like to try and update again, please use the 'Force Update Skills' option within the 'Other' menu.", "OverParse Setup", MessageBoxButton.OK, MessageBoxImage.Information);
}
try
{
ignoreskill = File.ReadAllLines("ignoreskills.csv");
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
ignoreskill = new string[] { "12345678900" }; // Placeholder Value
}
Console.WriteLine("Parsing skills.csv");
foreach (string s in tmp)
{
string[] split = s.Split(',');
if (split.Length > 1)
{
skillDict.Add(split[1], split[0]);
}
}
//Initializing default log
//and installing...
encounterlog = new Log(Properties.Settings.Default.Path);
UpdateForm(null, null);
//Initializing damageTimer
damageTimer.Tick += new EventHandler(UpdateForm);
damageTimer.Interval = new TimeSpan(0, 0, 0, 0, Properties.Settings.Default.Updateinv);
damageTimer.Start();
//Initializing inactiveTimer
System.Windows.Threading.DispatcherTimer inactiveTimer = new System.Windows.Threading.DispatcherTimer();
inactiveTimer.Tick += new EventHandler(HideIfInactive);
inactiveTimer.Interval = TimeSpan.FromMilliseconds(200);
inactiveTimer.Start();
//Initializing logCheckTimer
System.Windows.Threading.DispatcherTimer logCheckTimer = new System.Windows.Threading.DispatcherTimer();
logCheckTimer.Tick += new EventHandler(CheckForNewLog);
logCheckTimer.Interval = new TimeSpan(0, 0, 1);
logCheckTimer.Start();
}
private void HideIfInactive(object sender, EventArgs e)
{
if (!Properties.Settings.Default.AutoHideWindow)
return;
string title = WindowsServices.GetActiveWindowTitle();
string[] relevant = { "OverParse", "OverParse Setup", "OverParse Error", "Encounter Timeout", "Phantasy Star Online 2" };
if (!relevant.Contains(title))
{
Opacity = 0;
} else {
HandleWindowOpacity();
}
}
private void CheckForNewLog(object sender, EventArgs e)
{
DirectoryInfo directory = encounterlog.logDirectory;
if (!directory.Exists)
{
return;
}
if (directory.GetFiles().Count() == 0)
{
return;
}
FileInfo log = directory.GetFiles().Where(f => Regex.IsMatch(f.Name, @"\d+\.csv")).OrderByDescending(f => f.Name).First();
if (log.Name != encounterlog.filename)
{
//Console.WriteLine($"Found a new log file ({log.Name}), switching...");
encounterlog = new Log(Properties.Settings.Default.Path);
}
}
private void LoadListColumn()
{
GridLength temp = new GridLength(0);
if (!Properties.Settings.Default.ListName) { CombatantView.Columns.Remove(NameColumn); NameHC.Width = temp; }
if (Properties.Settings.Default.Variable)
{
if (Properties.Settings.Default.ListPct) { PercentHC.Width = new GridLength(0.4, GridUnitType.Star); } else { CombatantView.Columns.Remove(PercentColumn); PercentHC.Width = temp; }
if (Properties.Settings.Default.ListDmg) { DmgHC.Width = new GridLength(0.8, GridUnitType.Star); } else { CombatantView.Columns.Remove(DamageColumn); DmgHC.Width = temp; }
if (Properties.Settings.Default.ListDmgd) { DmgDHC.Width = new GridLength(0.6, GridUnitType.Star); } else { CombatantView.Columns.Remove(DamagedColumn); DmgDHC.Width = temp; }
if (Properties.Settings.Default.ListDPS) { DPSHC.Width = new GridLength(0.6, GridUnitType.Star); } else { CombatantView.Columns.Remove(DPSColumn); DPSHC.Width = temp; }
if (Properties.Settings.Default.ListJA) { JAHC.Width = new GridLength(0.4, GridUnitType.Star); } else { CombatantView.Columns.Remove(JAColumn); JAHC.Width = temp; }
if (Properties.Settings.Default.ListCri) { CriHC.Width = new GridLength(0.4, GridUnitType.Star); } else { CombatantView.Columns.Remove(CriColumn); CriHC.Width = temp; }
if (Properties.Settings.Default.ListHit) { MdmgHC.Width = new GridLength(0.6, GridUnitType.Star); } else { CombatantView.Columns.Remove(HColumn); MdmgHC.Width = temp; }
}
else
{
if (Properties.Settings.Default.ListPct) { PercentHC.Width = new GridLength(39); } else { CombatantView.Columns.Remove(PercentColumn); PercentHC.Width = temp; }
if (Properties.Settings.Default.ListDmg) { DmgHC.Width = new GridLength(78); } else { CombatantView.Columns.Remove(DamageColumn); DmgHC.Width = temp; }
if (Properties.Settings.Default.ListDmgd) { DmgDHC.Width = new GridLength(52); } else { CombatantView.Columns.Remove(DamagedColumn); DmgDHC.Width = temp; }
if (Properties.Settings.Default.ListDPS) { DPSHC.Width = new GridLength(44); } else { CombatantView.Columns.Remove(DPSColumn); DPSHC.Width = temp; }
if (Properties.Settings.Default.ListJA) { JAHC.Width = new GridLength(44); } else { CombatantView.Columns.Remove(JAColumn); JAHC.Width = temp; }
if (Properties.Settings.Default.ListCri) { CriHC.Width = new GridLength(44); } else { CombatantView.Columns.Remove(CriColumn); CriHC.Width = temp; }
if (Properties.Settings.Default.ListHit) { MdmgHC.Width = new GridLength(62); } else { CombatantView.Columns.Remove(HColumn); MdmgHC.Width = temp; }
}
if (!Properties.Settings.Default.ListAtk) { CombatantView.Columns.Remove(MaxHitColumn); AtkHC.Width = temp; }
}
private void Panic(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
try { Directory.CreateDirectory("ErrorLogs"); }
catch { MessageBox.Show("OverParse has failed to create the directory: <ErrorLogs>"); }
string datetime = string.Format("{0:yyyy-MM-dd_HH-mm-ss}", DateTime.Now);
string filename = $"ErrorLogs/ErrorLogs - {datetime}.txt";
string errorMessage1 = string.Format("{0}", e.Exception.Source);
string errorMessage2 = string.Format("{0}", e.Exception.StackTrace);
string errorMessage3 = string.Format("{0}", e.Exception.TargetSite);
string errorMessage4 = string.Format("{0}", e.Exception.InnerException);
string errorMessage5 = string.Format("{0}", e.Exception.Message);
//=== UNHANDLED EXCEPTION ===
//e.Exception.ToString()
string elog = (errorMessage1 + "\n" + errorMessage2 + "\n" + errorMessage3 + "\n" + errorMessage4 + "\n" + errorMessage5);
File.WriteAllText(filename, elog);
}
public void HandleWindowOpacity()
{
TheWindow.Opacity = Properties.Settings.Default.WindowOpacity;
// ACHTUNG ACHTUNG ACHTUNG ACHTUNG ACHTUNG ACHTUNG ACHTUNG ACHTUNG
WinOpacity_0.IsChecked = false;
WinOpacity_25.IsChecked = false;
Winopacity_50.IsChecked = false;
WinOpacity_75.IsChecked = false;
WinOpacity_100.IsChecked = false;
if (Properties.Settings.Default.WindowOpacity == 0)
{
WinOpacity_0.IsChecked = true;
}
else if (Properties.Settings.Default.WindowOpacity == .25)
{
WinOpacity_25.IsChecked = true;
}
else if (Properties.Settings.Default.WindowOpacity == .50)
{
Winopacity_50.IsChecked = true;
}
else if (Properties.Settings.Default.WindowOpacity == .75)
{
WinOpacity_75.IsChecked = true;
}
else if (Properties.Settings.Default.WindowOpacity == 1)
{
WinOpacity_100.IsChecked = true;
}
}
public void HandleListOpacity()
{
MainBack.Opacity = Properties.Settings.Default.ListOpacity;
ListOpacity_0.IsChecked = false;
ListOpacity_25.IsChecked = false;
Listopacity_50.IsChecked = false;
ListOpacity_75.IsChecked = false;
ListOpacity_100.IsChecked = false;
if (Properties.Settings.Default.ListOpacity == 0)
{
ListOpacity_0.IsChecked = true;
}
else if (Properties.Settings.Default.ListOpacity == .25)
{
ListOpacity_25.IsChecked = true;
}
else if (Properties.Settings.Default.ListOpacity == .50)
{
Listopacity_50.IsChecked = true;
}
else if (Properties.Settings.Default.ListOpacity == .75)
{
ListOpacity_75.IsChecked = true;
}
else if (Properties.Settings.Default.ListOpacity == 1)
{
ListOpacity_100.IsChecked = true;
}
}
private void Window_Deactivated(object sender, EventArgs e)
{
Window window = (Window)sender;
window.Topmost = AlwaysOnTop.IsChecked;
if (Properties.Settings.Default.ClickthroughEnabled)
{
int extendedStyle = WindowsServices.GetWindowLong(hwndcontainer, WindowsServices.GWL_EXSTYLE);
WindowsServices.SetWindowLong(hwndcontainer, WindowsServices.GWL_EXSTYLE, extendedStyle | WindowsServices.WS_EX_TRANSPARENT);
}
}
private void Window_Activated(object sender, EventArgs e)
{
HandleWindowOpacity();
Window window = (Window)sender;
window.Topmost = AlwaysOnTop.IsChecked;
if (Properties.Settings.Default.ClickthroughEnabled)
{
int extendedStyle = WindowsServices.GetWindowLong(hwndcontainer, WindowsServices.GWL_EXSTYLE);
WindowsServices.SetWindowLong(hwndcontainer, WindowsServices.GWL_EXSTYLE, extendedStyle & ~WindowsServices.WS_EX_TRANSPARENT);
}
}
private void Window_StateChanged(object sender, EventArgs e)
{
if (WindowState == WindowState.Maximized)
{
WindowState = WindowState.Normal;
}
}
public void UpdateForm(object sender, EventArgs e)
{
if (encounterlog == null) { return; }
if (Properties.Settings.Default.Clock) { Datetime.Content = DateTime.Now.ToString("HH:mm:ss.ff"); }
encounterlog.UpdateLog(this, null);
EncounterStatus.Content = encounterlog.LogStatus();
// get a copy of the right combatants
List<Combatant> targetList = (encounterlog.running ? encounterlog.combatants : lastCombatants);
workingList.Clear();
foreach (Combatant c in targetList)
{
Combatant temp = new Combatant(c.ID, c.Name, c.isTemporary);
foreach (Attack a in c.Attacks)
{
temp.Attacks.Add(new Attack(a.ID, a.Damage, a.JA, a.Cri));
}
temp.Damaged = c.Damaged;
temp.PercentReadDPS = c.PercentReadDPS;
workingList.Add(temp);
}
// clear out the list
CombatantData.Items.Clear();
// for zanverse dummy and status bar because WHAT IS GOOD STRUCTURE
int elapsed = Log.ActiveTime;
// create and sort dummy AIS combatants
if (Properties.Settings.Default.SeparateAIS)
{
List<Combatant> pendingCombatants = new List<Combatant>();
foreach (Combatant c in workingList)
{
if (!c.IsAlly)
continue;
if (c.AisDamage > 0)
{
Combatant AISHolder = new Combatant(c.ID, "AIS|" + c.Name, "AIS");
List<Attack> targetAttacks = c.Attacks.Where(a => Combatant.AISAttackIDs.Contains(a.ID)).ToList();
c.Attacks = c.Attacks.Except(targetAttacks).ToList();
AISHolder.Attacks.AddRange(targetAttacks);
pendingCombatants.Add(AISHolder);
}
}
workingList.AddRange(pendingCombatants);
}
if (Properties.Settings.Default.SeparateDB)
{
List<Combatant> pendingDBCombatants = new List<Combatant>();
foreach (Combatant c in workingList)
{
if (!c.IsAlly)
continue;
if (c.DBDamage > 0)
{
Combatant DBHolder = new Combatant(c.ID, "DB|" + c.Name, "DB");
List<Attack> targetAttacks = c.Attacks.Where(a => Combatant.DBAttackIDs.Contains(a.ID)).ToList();
c.Attacks = c.Attacks.Except(targetAttacks).ToList();
DBHolder.Attacks.AddRange(targetAttacks);
pendingDBCombatants.Add(DBHolder);
}
}
workingList.AddRange(pendingDBCombatants);
}
if (Properties.Settings.Default.SeparateRide)
{
List<Combatant> pendingRideCombatants = new List<Combatant>();
foreach (Combatant c in workingList)
{
if (!c.IsAlly)
continue;
if (c.RideDamage > 0)
{
Combatant RideHolder = new Combatant(c.ID, "Ride|" + c.Name, "Ride");
List<Attack> targetAttacks = c.Attacks.Where(a => Combatant.RideAttackIDs.Contains(a.ID)).ToList();
c.Attacks = c.Attacks.Except(targetAttacks).ToList();
RideHolder.Attacks.AddRange(targetAttacks);
pendingRideCombatants.Add(RideHolder);
}
}
workingList.AddRange(pendingRideCombatants);
}
if (Properties.Settings.Default.SeparatePwp)
{
List<Combatant> pendingPwpCombatants = new List<Combatant>();
foreach (Combatant c in workingList)
{
if (!c.IsAlly)
continue;
if (c.PwpDamage > 0)
{
Combatant PhotonHolder = new Combatant(c.ID, "Pwp|" + c.Name, "Pwp");
List<Attack> targetAttacks = c.Attacks.Where(a => Combatant.PhotonAttackIDs.Contains(a.ID)).ToList();
c.Attacks = c.Attacks.Except(targetAttacks).ToList();
PhotonHolder.Attacks.AddRange(targetAttacks);
pendingPwpCombatants.Add(PhotonHolder);
}
}
workingList.AddRange(pendingPwpCombatants);
}
if (Properties.Settings.Default.SeparateLsw)
{
List<Combatant> pendingLswCombatants = new List<Combatant>();
foreach (Combatant c in workingList)
{
if (!c.IsAlly)
continue;
if (c.LswDamage > 0)
{
Combatant LswHolder = new Combatant(c.ID, "Lsw|" + c.Name, "Lsw");
List<Attack> targetAttacks = c.Attacks.Where(a => Combatant.LaconiumAttackIDs.Contains(a.ID)).ToList();
c.Attacks = c.Attacks.Except(targetAttacks).ToList();
LswHolder.Attacks.AddRange(targetAttacks);
pendingLswCombatants.Add(LswHolder);
}
}
workingList.AddRange(pendingLswCombatants);
}
// force resort here to neatly shuffle AIS parses back into place
workingList.Sort((x, y) => y.ReadDamage.CompareTo(x.ReadDamage));
// make dummy zanverse combatant if necessary
int totalZanverse = workingList.Where(c => c.IsAlly == true).Sum(x => x.ZvsDamage);
int totalFinish = workingList.Where(c => c.IsAlly == true).Sum(x => x.HTFDamage);
if (Properties.Settings.Default.SeparateFinish)
{
if (totalFinish > 0)
{
Combatant finishHolder = new Combatant("99999998", "HTF Attacks", "HTF Attacks");
foreach (Combatant c in workingList)
{
if (c.IsAlly)
{
List<Attack> targetAttacks = c.Attacks.Where(a => Combatant.FinishAttackIDs.Contains(a.ID)).ToList();
finishHolder.Attacks.AddRange(targetAttacks);
c.Attacks = c.Attacks.Except(targetAttacks).ToList();
}
}
workingList.Add(finishHolder);
}
}
if (Properties.Settings.Default.SeparateZanverse)
{
if (totalZanverse > 0)
{
Combatant zanverseHolder = new Combatant("99999999", "Zanverse", "Zanverse");
foreach (Combatant c in workingList)
{
if (c.IsAlly)
{
List<Attack> targetAttacks = c.Attacks.Where(a => a.ID == "2106601422").ToList();
zanverseHolder.Attacks.AddRange(targetAttacks);
c.Attacks = c.Attacks.Except(targetAttacks).ToList();
}
}
workingList.Add(zanverseHolder);
}
}
// get group damage totals
int totalDamage = workingList.Sum(x => x.Damage);
int totalReadDamage = workingList.Sum(x => x.ReadDamage);
// dps calcs!
foreach (Combatant c in workingList)
{
c.PercentReadDPS = c.ReadDamage / (float)totalReadDamage * 100;
}
// damage graph stuff
Combatant.maxShare = 0;
foreach (Combatant c in workingList)
{
if ((c.IsAlly) && c.ReadDamage > Combatant.maxShare)
Combatant.maxShare = c.ReadDamage;
bool filtered = true;
if (Properties.Settings.Default.SeparateAIS || Properties.Settings.Default.SeparateDB || Properties.Settings.Default.SeparateRide || Properties.Settings.Default.SeparatePwp || Properties.Settings.Default.SeparateLsw)
{
if (c.IsAlly && c.isTemporary == "no" && !HidePlayers.IsChecked)
filtered = false;
if (c.IsAlly && c.isTemporary == "AIS" && !HideAIS.IsChecked)
filtered = false;
if (c.IsAlly && c.isTemporary == "DB" && !HideDB.IsChecked)
filtered = false;
if (c.IsAlly && c.isTemporary == "Ride" && !HideRide.IsChecked)
filtered = false;
if (c.IsAlly && c.isTemporary == "Pwp" && !HidePwp.IsChecked)
filtered = false;
if (c.IsAlly && c.isTemporary == "Lsw" && !HideLsw.IsChecked)
filtered = false;
if (c.IsZanverse)
filtered = false;
if (c.IsFinish)
filtered = false;
}
else
{
if ((c.IsAlly || c.IsZanverse || c.IsFinish || !FilterPlayers.IsChecked) && (c.Damage > 0))
filtered = false;
}
if (!filtered && c.Damage > 0)
{
CombatantData.Items.Add(c);
}
}
// status pane updates
EncounterIndicator.Fill = new SolidColorBrush(Color.FromArgb(192, 255, 128, 128));
EncounterStatus.Content = encounterlog.LogStatus();
if (encounterlog.valid && encounterlog.notEmpty)
{
EncounterIndicator.Fill = new SolidColorBrush(Color.FromArgb(192, 64, 192, 64));
EncounterStatus.Content = $"Waiting - {lastStatus}";
if (lastStatus == "")
EncounterStatus.Content = "Waiting for combat data...";
CombatantData.Items.Refresh();
}
if (encounterlog.running)
{
EncounterIndicator.Fill = new SolidColorBrush(Color.FromArgb(192, 0, 192, 255));
TimeSpan timespan = TimeSpan.FromSeconds(elapsed);
string timer = timespan.ToString(@"h\:mm\:ss");
EncounterStatus.Content = $"{timer}";
float totalDPS = totalDamage / (float)elapsed;
if (totalDPS > 0)
EncounterStatus.Content += $" - Total : {totalDamage.ToString("N0")}" + $" - {totalDPS.ToString("N0")} DPS";
if (!Properties.Settings.Default.SeparateZanverse)
EncounterStatus.Content += $" - Zanverse : {totalZanverse.ToString("N0")}";
lastStatus = EncounterStatus.Content.ToString();
}
// autoend
if (encounterlog.running)
{
if (Properties.Settings.Default.AutoEndEncounters)
{
int unixTimestamp = (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
if ((unixTimestamp - Log.newTimestamp) >= Properties.Settings.Default.EncounterTimeout)
{
//Automatically ending an encounter
EndEncounter_Click(null, null);
}
}
}
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
//Closing...
if (!Properties.Settings.Default.ResetInvoked)
{
if (WindowState == WindowState.Maximized)
{
Properties.Settings.Default.Top = RestoreBounds.Top;
Properties.Settings.Default.Left = RestoreBounds.Left;
Properties.Settings.Default.Height = RestoreBounds.Height;
Properties.Settings.Default.Width = RestoreBounds.Width;
Properties.Settings.Default.Maximized = true;
}
else
{
Properties.Settings.Default.Top = Top;
Properties.Settings.Default.Left = Left;
Properties.Settings.Default.Height = Height;
Properties.Settings.Default.Width = Width;
Properties.Settings.Default.Maximized = false;
}
}
encounterlog.WriteLog();
Properties.Settings.Default.Save();
}
private void OpenRecentLog_Click(object sender, RoutedEventArgs e)
{
string filename = sessionLogFilenames[SessionLogs.Items.IndexOf((e.OriginalSource as MenuItem))];
//attempting to open
Process.Start(Directory.GetCurrentDirectory() + "\\" + filename);
}
private void Minimize_Click(object sender, RoutedEventArgs e) => WindowState = WindowState.Minimized;
private void Exit_Click(object sender, RoutedEventArgs e)
{
Properties.Settings.Default.Save();
Application.Current.Shutdown();
}
public void EndEncounter_Key(object sender, HotkeyEventArgs e)
{
//Encounter hotkey pressed
EndEncounter_Click(null, null);
e.Handled = true;
}
public void EndEncounterNoLog_Key(object sender, HotkeyEventArgs e)
{
//Encounter hotkey (no log) pressed
EndEncounterNoLog_Click(null, null);
e.Handled = true;
}
public void DefaultWindowSize_Key(object sender, HotkeyEventArgs e)
{
DefaultWindowSize_Click(null, null);
e.Handled = true;
}
private void AlwaysOnTop_Key(object sender, HotkeyEventArgs e)
{
// Console.WriteLine("Always-on-top hotkey pressed");
AlwaysOnTop.IsChecked = !AlwaysOnTop.IsChecked;
IntPtr wasActive = WindowsServices.GetForegroundWindow();
// hack for activating overparse window
this.WindowState = WindowState.Minimized;
this.Show();
this.WindowState = WindowState.Normal;
this.Topmost = AlwaysOnTop.IsChecked;
AlwaysOnTop_Click(null, null);
WindowsServices.SetForegroundWindow(wasActive);
e.Handled = true;
}
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
DragMove();
}
}
private void ListViewItem_MouseRightClick(object sender, MouseButtonEventArgs e)
{
ListViewItem data = sender as ListViewItem;
Combatant data2 = (Combatant)data.DataContext;
Detalis f = new Detalis(data2) { Owner = this };
f.Show();
}
}
}