2021-07-09 11:03:30 +02:00
|
|
|
|
using System.Collections.Generic;
|
2021-07-09 11:30:11 +02:00
|
|
|
|
using System;
|
2021-07-09 11:03:30 +02:00
|
|
|
|
using System.Text;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
2021-11-10 21:24:39 +01:00
|
|
|
|
namespace EliteBGS.BGS {
|
2021-07-09 11:30:11 +02:00
|
|
|
|
public class Objective : IComparable<Objective> {
|
2022-01-09 11:13:01 +01:00
|
|
|
|
[JsonIgnore]
|
|
|
|
|
public bool IsEnabled { get; set; }
|
|
|
|
|
|
|
|
|
|
[JsonIgnore]
|
2022-11-06 15:41:12 +01:00
|
|
|
|
public List<LogEntry> Children { get; } = new List<LogEntry>();
|
2022-01-09 11:13:01 +01:00
|
|
|
|
|
|
|
|
|
[JsonIgnore]
|
2022-11-06 15:41:12 +01:00
|
|
|
|
public string Name {
|
|
|
|
|
get { return this.ToString(); }
|
|
|
|
|
}
|
2022-01-09 11:13:01 +01:00
|
|
|
|
|
|
|
|
|
[JsonIgnore]
|
|
|
|
|
public bool IsExpanded { get; set; }
|
|
|
|
|
|
2021-07-09 11:03:30 +02:00
|
|
|
|
[JsonIgnore]
|
|
|
|
|
public List<LogEntry> LogEntries {
|
2022-11-06 15:41:12 +01:00
|
|
|
|
get => Children;
|
2021-07-09 11:03:30 +02:00
|
|
|
|
}
|
2022-01-09 11:13:01 +01:00
|
|
|
|
|
2021-09-30 13:28:52 +02:00
|
|
|
|
public void Clear() {
|
2022-11-06 15:41:12 +01:00
|
|
|
|
if (LogEntries == null) {
|
2021-09-30 13:28:52 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2022-11-06 15:41:12 +01:00
|
|
|
|
LogEntries.RemoveAll(x => !x.ManuallyAdded);
|
2021-09-30 13:28:52 +02:00
|
|
|
|
}
|
2021-07-09 11:03:30 +02:00
|
|
|
|
|
2022-01-09 11:13:01 +01:00
|
|
|
|
public bool ManuallyAdded { get; set; }
|
|
|
|
|
|
2021-07-09 11:03:30 +02:00
|
|
|
|
public int Matches(LogEntry e) {
|
|
|
|
|
int match_count = 0;
|
|
|
|
|
|
|
|
|
|
if (e.OnlyControllingFaction) {
|
|
|
|
|
if (Faction == null || (e.Faction != Faction)) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-06 15:41:12 +01:00
|
|
|
|
if (e.Faction != null && Faction != null) {
|
|
|
|
|
if (string.Compare(e.Faction, Faction, true) != 0) {
|
2021-11-20 11:27:56 +01:00
|
|
|
|
/* if we have a faction, and it doesn't match we don't care.
|
|
|
|
|
* faction is the most important comparision, so if it doesn't match
|
|
|
|
|
* it is not the right objective
|
|
|
|
|
*/
|
|
|
|
|
return 0;
|
|
|
|
|
} else {
|
2021-08-19 17:14:20 +02:00
|
|
|
|
++match_count;
|
|
|
|
|
}
|
2021-07-09 11:03:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-20 11:27:56 +01:00
|
|
|
|
/* system and station only add to the match strength though */
|
2022-11-06 15:41:12 +01:00
|
|
|
|
if (e.System != null && System != null) {
|
|
|
|
|
if (string.Compare(e.System, System, true) == 0) {
|
2021-08-19 17:14:20 +02:00
|
|
|
|
++match_count;
|
|
|
|
|
}
|
2021-07-09 11:03:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-06 15:41:12 +01:00
|
|
|
|
/* station does not matter */
|
2021-07-09 11:03:30 +02:00
|
|
|
|
|
|
|
|
|
return match_count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int CompareTo(Objective other) {
|
|
|
|
|
return (other.System == System &&
|
|
|
|
|
other.Station == Station &&
|
|
|
|
|
other.Faction == Faction) ? 0 : -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsValid => System != null && Faction != null;
|
|
|
|
|
|
2022-11-06 15:41:12 +01:00
|
|
|
|
public string System { get; set; }
|
2021-07-09 11:03:30 +02:00
|
|
|
|
|
2022-11-06 15:41:12 +01:00
|
|
|
|
public string Station { get; set; }
|
2021-07-09 11:03:30 +02:00
|
|
|
|
|
2022-11-06 15:41:12 +01:00
|
|
|
|
public string Faction { get; set; }
|
2021-07-09 11:03:30 +02:00
|
|
|
|
|
|
|
|
|
public override string ToString() {
|
|
|
|
|
StringBuilder str = new StringBuilder();
|
2022-11-06 15:41:12 +01:00
|
|
|
|
if (!string.IsNullOrEmpty(System)) {
|
|
|
|
|
str.AppendFormat("System: {0}", System);
|
2021-07-09 11:03:30 +02:00
|
|
|
|
}
|
2022-11-06 15:41:12 +01:00
|
|
|
|
if (!string.IsNullOrEmpty(Faction)) {
|
2021-07-09 11:03:30 +02:00
|
|
|
|
if (str.Length > 0) {
|
|
|
|
|
str.Append(", ");
|
|
|
|
|
}
|
2022-11-06 15:41:12 +01:00
|
|
|
|
str.AppendFormat("Faction: {0}", Faction);
|
2021-07-09 11:03:30 +02:00
|
|
|
|
}
|
|
|
|
|
return str.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-06 15:41:12 +01:00
|
|
|
|
public string ToLocationString() {
|
2021-07-09 11:03:30 +02:00
|
|
|
|
StringBuilder str = new StringBuilder();
|
2022-11-06 15:41:12 +01:00
|
|
|
|
if (!string.IsNullOrEmpty(System)) {
|
|
|
|
|
str.AppendFormat("{0}", System);
|
2021-07-09 11:03:30 +02:00
|
|
|
|
}
|
2022-11-06 15:41:12 +01:00
|
|
|
|
if (!string.IsNullOrEmpty(Station)) {
|
2021-07-09 11:03:30 +02:00
|
|
|
|
if (str.Length > 0) {
|
|
|
|
|
str.Append(", ");
|
|
|
|
|
}
|
2022-11-06 15:41:12 +01:00
|
|
|
|
str.AppendFormat("{0}", Station);
|
2021-07-09 11:03:30 +02:00
|
|
|
|
}
|
|
|
|
|
return str.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|