EliteBGS/BGS/Objective.cs

121 lines
3.6 KiB
C#
Raw Normal View History

2021-07-09 11:03:30 +02:00
using System.Collections.Generic;
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 {
public class Objective : IComparable<Objective> {
2021-07-09 11:03:30 +02:00
private string system;
private string station;
private string faction;
private List<LogEntry> entries = new List<LogEntry>();
[JsonIgnore]
public List<LogEntry> LogEntries {
get => entries;
set => entries = value;
}
2021-09-30 13:28:52 +02:00
public void Clear() {
if (entries == null) {
return;
}
entries.RemoveAll(x => !x.ManuallyAdded);
}
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;
}
}
if (e.Faction != null && faction != null) {
if (string.Compare(e.Faction, faction, true) != 0) {
/* 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 {
++match_count;
}
2021-07-09 11:03:30 +02:00
}
/* system and station only add to the match strength though */
if (e.System != null && system != null) {
if (string.Compare(e.System, system, true) == 0) {
++match_count;
}
2021-07-09 11:03:30 +02:00
}
if (e.Station != null && station != null) {
if (string.Compare(e.Station, station, true) == 0) {
++match_count;
}
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;
public string System {
get { return system; }
set { system = value; }
}
public string Station {
get { return station; }
set { station = value; }
}
public string Faction {
get { return faction; }
set { faction = value; }
}
public override string ToString() {
StringBuilder str = new StringBuilder();
if (system != null && system.Length > 0) {
str.AppendFormat("System: {0}", system);
}
if (station != null && station.Length > 0) {
if (str.Length > 0) {
str.Append(", ");
}
str.AppendFormat("Station: {0}", station);
}
if (faction != null && faction.Length > 0) {
if (str.Length > 0) {
str.Append(", ");
}
str.AppendFormat("Faction: {0}", faction);
}
return str.ToString();
}
public string ToShortString() {
StringBuilder str = new StringBuilder();
if (system != null && system.Length > 0) {
str.AppendFormat("{0}", system);
}
if (station != null && station.Length > 0) {
if (str.Length > 0) {
str.Append(", ");
}
str.AppendFormat("{0}", station);
}
return str.ToString();
}
}
}