-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathCommander.cs
More file actions
582 lines (510 loc) · 18.3 KB
/
Commander.cs
File metadata and controls
582 lines (510 loc) · 18.3 KB
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
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using Utilities;
namespace EddiDataDefinitions
{
/// <summary>
/// Details about a commander
/// </summary>
public class FrontierApiCommander : INotifyPropertyChanged
{
// Parameters obtained from the Frontier API
/// <summary>The commander's name</summary>
[ PublicAPI ]
public string name
{
get => _name;
set
{
if ( value == _name )
{
return;
}
_name = value;
OnPropertyChanged();
}
}
/// <summary>The number of credits the commander holds</summary>
[PublicAPI]
public long credits
{
get => _credits;
set
{
if ( value == _credits )
{
return;
}
_credits = value;
OnPropertyChanged();
}
}
/// <summary>The amount of debt the commander owes</summary>
[PublicAPI]
public long debt
{
get => _debt;
set
{
if ( value == _debt )
{
return;
}
_debt = value;
OnPropertyChanged();
}
}
/// <summary>The commander's combat rating</summary>
[ PublicAPI ]
public CombatRating combatrating
{
get => _combatrating;
set
{
if ( value == _combatrating )
{
return;
}
_combatrating = value;
OnPropertyChanged();
}
}
/// <summary>The commander's trade rating</summary>
[ PublicAPI ]
public TradeRating traderating
{
get => _traderating;
set
{
if ( value == _traderating )
{
return;
}
_traderating = value;
OnPropertyChanged();
}
}
/// <summary>The commander's exploration rating</summary>
[ PublicAPI ]
public ExplorationRating explorationrating
{
get => _explorationrating;
set
{
if ( value == _explorationrating )
{
return;
}
_explorationrating = value;
OnPropertyChanged();
}
}
/// <summary>The commander's CQC rating</summary>
[ PublicAPI ]
public CQCRating cqcrating
{
get => _cqcrating;
set
{
if ( value == _cqcrating )
{
return;
}
_cqcrating = value;
OnPropertyChanged();
}
}
/// <summary>The commander's empire rating</summary>
[ PublicAPI ]
public EmpireRating empirerating
{
get => _empirerating;
set
{
if ( value == _empirerating )
{
return;
}
_empirerating = value;
OnPropertyChanged();
}
}
/// <summary>The commander's federation rating</summary>
[ PublicAPI ]
public FederationRating federationrating
{
get => _federationrating;
set
{
if ( value == _federationrating )
{
return;
}
_federationrating = value;
OnPropertyChanged();
}
}
/// <summary>The commander's mercenary rating</summary>
[ PublicAPI ]
public MercenaryRating mercenaryrating
{
get => _mercenaryrating;
set
{
if ( value == _mercenaryrating )
{
return;
}
_mercenaryrating = value;
OnPropertyChanged();
}
}
/// <summary>The commander's exobiologist rating</summary>
[ PublicAPI ]
public ExobiologistRating exobiologistrating
{
get => _exobiologistrating;
set
{
if ( value == _exobiologistrating )
{
return;
}
_exobiologistrating = value;
OnPropertyChanged();
}
}
/// <summary>The commander's crime rating</summary>
public int crimerating
{
get => _crimerating;
set
{
if ( value == _crimerating )
{
return;
}
_crimerating = value;
OnPropertyChanged();
}
}
/// <summary>The commander's service rating</summary>
public int servicerating
{
get => _servicerating;
set
{
if ( value == _servicerating )
{
return;
}
_servicerating = value;
OnPropertyChanged();
}
}
/// <summary>The commander's powerplay rating (if pledged)</summary>
public int powerrating
{
get => _powerrating;
set
{
if ( value == _powerrating )
{
return;
}
_powerrating = value;
OnPropertyChanged();
}
}
/// <summary>The commander's squadron name</summary>
[PublicAPI]
public string squadronname
{
get => _squadronname;
set { _squadronname = value; OnPropertyChanged(); }
}
/// <summary>The commander's squadron tag</summary>
[PublicAPI]
public string squadrontag
{
get => _squadrontag;
set { _squadrontag = value; OnPropertyChanged(); }
}
private string _name;
private string _squadronname;
private string _squadrontag;
private int _powerrating;
private int _servicerating;
private int _crimerating;
private ExobiologistRating _exobiologistrating;
private MercenaryRating _mercenaryrating;
private FederationRating _federationrating;
private EmpireRating _empirerating;
private CQCRating _cqcrating;
private ExplorationRating _explorationrating;
private TradeRating _traderating;
private CombatRating _combatrating;
private long _credits;
private long _debt;
#region INotifyPopertyChanged
public event PropertyChangedEventHandler PropertyChanged;
private protected void OnPropertyChanged ( [System.Runtime.CompilerServices.CallerMemberName] string propName = null )
{
PropertyChanged?.Invoke( this, new PropertyChangedEventArgs( propName ) );
}
#endregion
}
public class Commander : FrontierApiCommander
{
// Parameters not obtained from the Frontier API
// Note: Any information not updated from the Frontier API will need to be reset when the Frontier API refreshes the commander definition.
/// <summary>The commander's Frontier ID</summary>
public string EDID { get; set; }
[JsonIgnore]
private string _phoneticName;
/// <summary>The commander's phonetic name</summary>
public string phoneticName
{
get => _phoneticName;
set
{
if (string.IsNullOrEmpty(value))
{
_phoneticName = null;
}
else
{
_phoneticName = value;
OnPropertyChanged();
}
}
}
/// <summary>The commander's spoken name (rendered using ssml and IPA)</summary>
[PublicAPI]
public string phoneticname => SpokenName();
/// <summary> The commander's title. This is dependent on the current system</summary>
public string title
{
get => _title;
set { _title = value; OnPropertyChanged();}
}
private string _title;
/// <summary> The commander's gender. This is set in EDDI's configuration</summary>
[PublicAPI]
public string gender
{
get => _gender.ToString();
set
{
_gender = Enum.TryParse( value, out Gender parsedGender )
? parsedGender
: Gender.Neither; // Default value
OnPropertyChanged();
}
}
public Gender Gender
{
get => _gender;
set { _gender = value; OnPropertyChanged(); }
}
private Gender _gender;
/// <summary>The commander's powerplay power (if pledged)</summary>
public Power Power
{
get => _power ?? Power.None;
set { _power = value; OnPropertyChanged();}
}
private Power _power;
/// <summary>The commander's powerplay power (localized) (if pledged)</summary>
[PublicAPI]
public string power => (Power ?? Power.None)?.localizedName;
/// <summary>The commander's powerplay merits (if pledged)</summary>
public int? powermerits
{
get => _powermerits;
set { _powermerits = value; OnPropertyChanged();}
}
private int? _powermerits;
/// <summary>The name of the commander's home system (if selected)</summary>
public string homeSystemName
{
get => _homeSystemName;
set { _homeSystemName = value; OnPropertyChanged(); }
}
private string _homeSystemName;
/// <summary>The system address ID of the commander's home system (if selected)</summary>
public ulong? homeSystemAddress
{
get => _homeSystemAddress;
set { _homeSystemAddress = value; OnPropertyChanged(); }
}
private ulong? _homeSystemAddress;
/// <summary>The name of the commander's home station (if selected)</summary>
public string homeStationName
{
get => _homeStationName;
set { _homeStationName = value; OnPropertyChanged(); }
}
private string _homeStationName;
/// <summary>The market ID of the commander's home station (if selected)</summary>
public long? homeStationMarketID
{
get => _homeStationMarketID;
set { _homeStationMarketID = value; OnPropertyChanged(); }
}
private long? _homeStationMarketID;
public decimal? homeSystemX
{
get => _homeSystemX;
set { _homeSystemX = value; OnPropertyChanged(); }
}
private decimal? _homeSystemX;
public decimal? homeSystemY
{
get => _homeSystemY;
set { _homeSystemY = value; OnPropertyChanged(); }
}
private decimal? _homeSystemY;
public decimal? homeSystemZ
{
get => _homeSystemZ;
set { _homeSystemZ = value; OnPropertyChanged(); }
}
private decimal? _homeSystemZ;
/// <summary>The commander's squadron rank</summary>
[PublicAPI]
public SquadronRank squadronrank
{
get => _squadronrank;
set
{
void childPropertyChangedHandler ( object sender, PropertyChangedEventArgs e )
{
OnPropertyChanged();
}
if ( _squadronrank != null ) { _squadronrank.PropertyChanged -= childPropertyChangedHandler; }
if ( value != null ) { value.PropertyChanged += childPropertyChangedHandler; }
_squadronrank = value ?? new SquadronRank(null, string.Empty, string.Empty);
OnPropertyChanged();
}
}
private SquadronRank _squadronrank;
/// <summary>The commander's squadron system name</summary>
[PublicAPI]
public string squadronSystemName
{
get => _squadronSystemName;
set { _squadronSystemName = value; OnPropertyChanged(); }
}
private string _squadronSystemName;
/// <summary>The commander's squadron system numeric address</summary>
[PublicAPI]
public ulong? squadronSystemAddress
{
get => _squadronSystemAddress;
set { _squadronSystemAddress = value; OnPropertyChanged(); }
}
private ulong? _squadronSystemAddress;
/// <summary>The commander's squadron superpower</summary>
[PublicAPI]
public Superpower squadronallegiance
{
get => _squadronallegiance ?? Superpower.None;
set { _squadronallegiance = value; OnPropertyChanged();}
}
private Superpower _squadronallegiance;
/// <summary>The commander's squadron power</summary>
[PublicAPI]
public Power squadronpower
{
get => _squadronpower ?? Power.None;
set { _squadronpower = value; OnPropertyChanged();}
}
private Power _squadronpower;
/// <summary>The commander's squadron faction</summary>
[PublicAPI]
public string squadronfaction
{
get => _squadronfaction;
set { _squadronfaction = value; OnPropertyChanged();}
}
private string _squadronfaction;
/// <summary>The insurance excess percentage the commander has to pay</summary>
public decimal? insurance { get; set; } = 0.05M;
/// <summary>The Commander's friends</summary>
[PublicAPI]
public List<Friend> friends = [ ];
/// <summary>The Commander's status and progress with the various engineers</summary>
[PublicAPI]
public List<Engineer> engineers => Engineer.ENGINEERS;
public static Commander FromFrontierApiCmdr(Commander currentCmdr, FrontierApiCommander frontierApiCommander, DateTime apiTimeStamp, DateTime journalTimeStamp, out bool cmdrMatches)
{
if (frontierApiCommander is null) { cmdrMatches = true; return currentCmdr; }
// Copy our current commander to a new commander object
var Cmdr = currentCmdr.Copy();
// Set our commander name if it hadn't already been set
Cmdr.name = string.IsNullOrEmpty(Cmdr.name) ? frontierApiCommander.name : Cmdr.name;
// Verify that the profile information matches the current Cmdr name
if (frontierApiCommander.name != Cmdr.name)
{
Logging.Warn("Frontier API incorrectly configured: Returning information for Commander " +
frontierApiCommander.name + " rather than for " + Cmdr.name + ". Disregarding incorrect information.");
cmdrMatches = false;
return Cmdr;
}
cmdrMatches = true;
// Update our commander object with information exclusively available from the Frontier API
Cmdr.crimerating = frontierApiCommander.crimerating;
Cmdr.servicerating = frontierApiCommander.servicerating;
Cmdr.debt = frontierApiCommander.debt;
// Update our commander object with information obtainable from the journal
// Since the parameters below only increase, we will take any that are higher in rank than we had before
Cmdr.combatrating = (frontierApiCommander.combatrating?.rank ?? 0) >= (Cmdr.combatrating?.rank ?? 0)
? frontierApiCommander.combatrating : Cmdr.combatrating;
Cmdr.traderating = (frontierApiCommander.traderating?.rank ?? 0) >= (Cmdr.traderating?.rank ?? 0)
? frontierApiCommander.traderating : Cmdr.traderating;
Cmdr.explorationrating = (frontierApiCommander.explorationrating?.rank ?? 0) >= (Cmdr.explorationrating?.rank ?? 0)
? frontierApiCommander.explorationrating : Cmdr.explorationrating;
Cmdr.cqcrating = (frontierApiCommander.cqcrating?.rank ?? 0) >= (Cmdr.cqcrating?.rank ?? 0)
? frontierApiCommander.cqcrating : Cmdr.cqcrating;
Cmdr.empirerating = (frontierApiCommander.empirerating?.rank ?? 0) >= (Cmdr.empirerating?.rank ?? 0)
? frontierApiCommander.empirerating : Cmdr.empirerating;
Cmdr.federationrating = (frontierApiCommander.federationrating?.rank ?? 0) >= (Cmdr.federationrating?.rank ?? 0)
? frontierApiCommander.federationrating : Cmdr.federationrating;
Cmdr.mercenaryrating = (frontierApiCommander.mercenaryrating?.rank ?? 0) >= (Cmdr.mercenaryrating?.rank ?? 0)
? frontierApiCommander.mercenaryrating : Cmdr.mercenaryrating;
Cmdr.exobiologistrating = (frontierApiCommander.exobiologistrating?.rank ?? 0) >= (Cmdr.exobiologistrating?.rank ?? 0)
? frontierApiCommander.exobiologistrating : Cmdr.exobiologistrating;
// A few items are also updated from the journal but may change so we check the timestamp
if (apiTimeStamp > journalTimeStamp)
{
Cmdr.credits = frontierApiCommander.credits;
Cmdr.squadronname = frontierApiCommander.squadronname;
Cmdr.squadrontag = frontierApiCommander.squadrontag;
Cmdr.powerrating = frontierApiCommander.powerrating;
}
return Cmdr;
}
public string SpokenName()
{
var spokenName = string.Empty;
if (!string.IsNullOrWhiteSpace(phoneticName))
{
spokenName = "<phoneme alphabet=\"ipa\" ph=\"" + phoneticName + "\">" + name + "</phoneme>";
}
else if (!string.IsNullOrWhiteSpace(name))
{
spokenName = name;
}
return spokenName;
}
}
public enum Gender
{
Male,
Female,
Neither
}
}