-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathMission.cs
More file actions
509 lines (411 loc) · 17 KB
/
Mission.cs
File metadata and controls
509 lines (411 loc) · 17 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
using JetBrains.Annotations;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
namespace EddiDataDefinitions
{
public class Mission : INotifyPropertyChanged
{
// The mission ID
[Utilities.PublicAPI]
public ulong missionid { get; private set; }
// The name of the mission
[Utilities.PublicAPI]
public string name
{
get => _name;
set
{
_name = value?
.Replace( "$", "" )
.Replace( ";", "" );
OnPropertyChanged();
}
}
[JsonIgnore]
private string _name;
// The localised name of the mission
[Utilities.PublicAPI]
public string localisedname
{
get => _localisedname;
set
{
_localisedname = value;
destinationstation = !string.IsNullOrEmpty( destinationstation )
? destinationstation
: FallbackGetDestinationStation( value );
targetfaction = !string.IsNullOrEmpty(targetfaction)
? targetfaction
: FallbackGetTargetFaction( value );
OnPropertyChanged();
}
}
[JsonIgnore]
private string _localisedname;
#region Expiration Data
[Utilities.PublicAPI]
public DateTime? expiry { get; set; }
[Utilities.PublicAPI, JsonIgnore]
public long? expiryseconds => expiry != null ? (long?)Utilities.Dates.fromDateTimeToSeconds( (DateTime)expiry ) : null;
[JsonIgnore]
public bool expiring { get; set; }
// The mission time remaining
[JsonIgnore]
public TimeSpan? timeRemaining => expiry != null ? TimeSpanNearestSecond( expiry - DateTime.UtcNow ) : null;
private static TimeSpan? TimeSpanNearestSecond ( TimeSpan? utcNow )
{
if ( utcNow is null ) { return null; }
return new TimeSpan( utcNow.Value.Days, utcNow.Value.Hours, utcNow.Value.Minutes, utcNow.Value.Seconds );
}
// While we track the time remaining constantly, we loop through each mission
// and update the displayed time remaining at intervals defined by the Mission Monitor.
public void UpdateTimeRemaining ()
{
OnPropertyChanged( nameof( timeRemaining ) );
}
#endregion
#region Mission Status
// Status of the mission
public string statusEDName
{
get => statusDef?.edname;
set
{
var sDef = MissionStatus.FromEDName(value);
this.statusDef = sDef;
}
}
[JsonIgnore]
public MissionStatus statusDef
{
get => _statusDef;
set
{
_statusDef = value;
if ( value != null && value != MissionStatus.Active && !onfoot )
{
// Missions are time constrained when active, and on-foot missions
// continue to be time constrained even after they are claimable.
expiry = null;
}
OnPropertyChanged( nameof( localizedStatus ) );
}
}
[JsonIgnore]
private MissionStatus _statusDef;
[JsonIgnore]
public string localizedStatus => statusDef?.localizedName ?? "Unknown";
[Utilities.PublicAPI, JsonIgnore, Obsolete( "Please use localizedName or invariantName" )]
public string status => localizedStatus;
[Utilities.PublicAPI]
public bool shared { get; set; }
[Utilities.PublicAPI ("Notes you have recorded about the mission.")]
public string notes
{
get => _notes;
set
{
if ( _notes == value ) { return; }
_notes = value;
OnPropertyChanged( nameof( notes ) );
}
}
[JsonIgnore]
private string _notes;
#endregion
#region Mission Tags / MetaData
[ JsonIgnore ]
public List<MissionType> tagsList => MissionTypes.FromMissionName( name );
[Utilities.PublicAPI, JsonIgnore]
public List<string> invariantTags => tagsList.Select(t => t.invariantName ?? "Unknown").ToList();
[JsonIgnore, UsedImplicitly]
public string localizedTagsString => string.Join(", ", tags );
[JsonIgnore]
public List<string> edTags => tagsList.Select(t => t.edname ?? "Unknown").ToList();
[Utilities.PublicAPI, JsonIgnore]
public List<string> tags => tagsList.Select( t => t.localizedName ?? "Unknown" ).ToList();
[Utilities.PublicAPI("Obsolete: `type` has been deprecated in favor of tags"), JsonIgnore, Obsolete("`type` has been deprecated in favor of tags")]
public string type => tags[0];
[JsonIgnore]
public bool chained => tagsList.Contains( MissionType.Chained );
[JsonIgnore]
public bool onfoot => tagsList.Contains( MissionType.OnFoot );
[Utilities.PublicAPI]
public bool communal { get; set; }
[Utilities.PublicAPI, JsonIgnore]
public bool legal => !tagsList.Any( t =>
t == MissionType.Hack ||
t == MissionType.Illegal ||
t == MissionType.Piracy ||
t == MissionType.Smuggle );
[Utilities.PublicAPI, JsonIgnore] // On-foot missions are always shareable.
public bool wing => tagsList.Contains( MissionType.Wing ) || onfoot;
#endregion
#region Mission Rewards
[Utilities.PublicAPI]
public string influence { get; set; }
[Utilities.PublicAPI]
public string reputation { get; set; }
[Utilities.PublicAPI("Credits awarded upon successful completion")]
public long? reward { get; set; }
#endregion
#region Mission Origin and Origin Faction
// The system in which the mission was accepted
[Utilities.PublicAPI]
public string originsystem { get; set; }
// The station in which the mission was accepted
[Utilities.PublicAPI]
public string originstation { get; set; }
// Mission returns to origin
[Utilities.PublicAPI, JsonIgnore]
public bool originreturn => tagsList.Any(t => t.ClaimAtOrigin);
// Mission delivers to a cargo depot
[Utilities.PublicAPI, JsonIgnore]
public bool cargodepot => tagsList.Any(t => t.ClaimAtCargoDepot);
[Utilities.PublicAPI]
public string faction { get; set; }
// The state of the minor faction
[ JsonIgnore ]
public FactionState FactionState => GetFactionState( name );
private static FactionState GetFactionState ( string missionName )
{
if ( string.IsNullOrEmpty( missionName ) ) { return null; }
// Get the faction state (Boom, Bust, Civil War, etc), if available
var elements = missionName.Split( '_' );
for ( var i = 2; i < elements.Length; i++ )
{
var element = elements
.ElementAtOrDefault(i);
// Return faction state when present
var factionState = FactionState
.AllOfThem
.FirstOrDefault(s =>
string.Equals( s.edname, element, StringComparison.OrdinalIgnoreCase ) );
if ( factionState != null ) { return factionState; }
}
return null;
}
#endregion
#region Mission Destination
// The destination system of the mission
[ Utilities.PublicAPI ]
public string destinationsystem
{
get => _destinationsystem;
set
{
if (_destinationsystem != value)
{
_destinationsystem = value;
OnPropertyChanged();
}
}
}
[JsonIgnore]
private string _destinationsystem;
// The destination station of the mission
[Utilities.PublicAPI]
public string destinationstation
{
get => _destinationstation;
set
{
if (_destinationstation != value)
{
_destinationstation = value;
OnPropertyChanged();
}
}
}
[JsonIgnore]
private string _destinationstation;
// Destination systems for chained missions
[Utilities.PublicAPI]
public List<NavWaypoint> destinationsystems { get; set; }
private static string FallbackGetDestinationStation ( string localisedName )
{
if ( string.IsNullOrEmpty( localisedName ) )
{ return string.Empty; }
var tidiedName = localisedName
.Replace("Covert ", "")
.Replace("Nonviolent ", "")
.Replace("Digital Infiltration: ", "")
.Replace("Heist: ", "")
.Replace("Reactivation: ", "")
.Replace("Restore: ", "")
.Replace("Sabotage: ", "")
.Replace("Settlement Raid: ", "")
.Replace("Shutdown: ", "")
;
var prefixesSuffixes = new List<Tuple<string, string>>
{
Tuple.Create("Acquire a sample from ", ""),
Tuple.Create("Breach the ", " network"),
Tuple.Create("Disable power at ", ""),
Tuple.Create("Disrupt production at ", ""),
Tuple.Create("Exterminate scavengers at ", ""),
Tuple.Create("Find a regulator for ", ""),
Tuple.Create("Find a regulator and prepare ", ""),
Tuple.Create("Halt production at ", ""),
Tuple.Create("Prepare ", " for operation"),
Tuple.Create("Switch off power at ", ""),
Tuple.Create("Take a sample from ", ""),
Tuple.Create("Turn on power at ", "")
};
foreach ( var prefixSuffix in prefixesSuffixes )
{
if ( tidiedName.StartsWith( prefixSuffix.Item1, StringComparison.InvariantCultureIgnoreCase )
&& tidiedName.EndsWith( prefixSuffix.Item2, StringComparison.InvariantCultureIgnoreCase ) )
{
if ( prefixSuffix.Item1.Length > 0 )
{
tidiedName = tidiedName
.Replace( prefixSuffix.Item1, "" );
}
if ( prefixSuffix.Item2.Length > 0 )
{
tidiedName = tidiedName
.Replace( prefixSuffix.Item2, "" );
}
return tidiedName;
}
}
return null;
}
#endregion
#region Community Goal Info
// Community goal details, if applicable
public int communalPercentileBand { get; set; }
public int communalTier { get; set; }
public long communalContribution { get; set; }
#endregion
#region Passenger Data
public string passengertypeEDName { get; set; }
[Utilities.PublicAPI, JsonIgnore]
public string passengertype => PassengerType.FromEDName( passengertypeEDName )?.localizedName;
[Utilities.PublicAPI]
public bool? passengerwanted { get; set; }
[Utilities.PublicAPI]
public bool? passengervips { get; set; }
#endregion
#region Mission Target
[Utilities.PublicAPI]
public string target { get; set; }
[Utilities.PublicAPI]
public string targetfaction
{
get => _targetfaction;
set
{
if ( _targetfaction != value )
{
_targetfaction = value;
OnPropertyChanged();
}
}
}
private string _targetfaction;
public string targetTypeEDName;
[Utilities.PublicAPI, JsonIgnore]
public string targettype => TargetType.FromEDName( targetTypeEDName )?.localizedName;
private static string FallbackGetTargetFaction ( string localisedName )
{
if ( string.IsNullOrEmpty( localisedName ) )
{ return string.Empty; }
var tidiedName = localisedName
.Replace("Settlement ", "")
.Replace("Massacre: ", "")
.Replace("Raid: ", "")
;
var prefixesSuffixes = new List<Tuple<string, string>>
{
Tuple.Create("Exterminate ", " members"),
Tuple.Create("Take out ", " personnel"),
};
foreach ( var prefixSuffix in prefixesSuffixes )
{
if ( tidiedName.StartsWith( prefixSuffix.Item1, StringComparison.InvariantCultureIgnoreCase )
&& tidiedName.EndsWith( prefixSuffix.Item2, StringComparison.InvariantCultureIgnoreCase ) )
{
if ( prefixSuffix.Item1.Length > 0 )
{
tidiedName = tidiedName
.Replace( prefixSuffix.Item1, "" );
}
if ( prefixSuffix.Item2.Length > 0 )
{
tidiedName = tidiedName
.Replace( prefixSuffix.Item2, "" );
}
return tidiedName;
}
}
return null;
}
#endregion
#region Mission Haulage Data
[Utilities.PublicAPI( "The localized name of the commodity required to complete the mission, as applicable" ), JsonProperty( "commodity" )]
public string commodity
{
get => CommodityDefinition?.localizedName;
set
{
var comDef = CommodityDefinition.FromName(value);
this.CommodityDefinition = comDef;
}
}
[Utilities.PublicAPI( "The commodity object for the commodity required to complete the mission, as applicable" ), JsonIgnore]
public CommodityDefinition CommodityDefinition { get; set; }
[Utilities.PublicAPI( "The localized name of the micro-resource required to complete the mission, as applicable" ), JsonProperty( "microresource" )]
public string microresource
{
get => MicroResourceDefinition?.localizedName;
set
{
var resDef = MicroResource.FromName(value);
this.MicroResourceDefinition = resDef;
}
}
[Utilities.PublicAPI( "The micro-resource object for the micro-resource required to complete the mission, as applicable" ), JsonIgnore]
public MicroResource MicroResourceDefinition { get; set; }
[Utilities.PublicAPI( "The amount of the commodity or micro-resource required to complete the mission." )]
public int? amount { get; set; }
[Utilities.PublicAPI( "The system where the mission cargo has been found, as applicable" )]
public string sourcesystem { get; set; }
[Utilities.PublicAPI ( "The body or station where the mission cargo has been found, as applicable" )]
public string sourcebody { get; set; }
[Utilities.PublicAPI( "The quantity of mission cargo which has been collected at a cargo depot" )]
public int collected { get; set; }
[Utilities.PublicAPI( "The quantity of mission cargo which has been delivered to a cargo depot" )]
public int delivered { get; set; }
public int wingCollected { get; set; } // The quantity of mission cargo which has been collected and not delivered by wing members
public long startmarketid { get; set; } // The cargo depot where mission cargo is collected
public long endmarketid { get; set; } // The cargo depot where mission cargo is delivered
#endregion
// Default Constructor
public Mission () { }
[JsonConstructor]
// Main Constructor
public Mission(ulong MissionId, string Name, DateTime? expiry, MissionStatus Status, string notes = null, bool Shared = false)
{
this.missionid = MissionId;
this.name = Name;
this.expiry = expiry?.ToUniversalTime();
this.statusDef = Status;
this.shared = Shared;
this.notes = notes;
this.expiring = false;
destinationsystems = [ ];
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}