implement failed missions which give negative INF

This commit is contained in:
Florian Stinglmayr 2021-11-12 22:23:40 +01:00
parent ee9f7ea4cd
commit 6dda7cfde4
5 changed files with 74 additions and 6 deletions

View File

@ -103,6 +103,24 @@ namespace EliteBGS.BGS {
return builder.ToString();
}
private string BuildFailedMissions(Objective objective) {
MissionFailed[] missions = objective.LogEntries.OfType<MissionFailed>().ToArray();
StringBuilder builder = new StringBuilder();
if (missions.Length <= 0) {
return "";
}
foreach (MissionFailed failed in missions) {
MissionFailedEntry f = failed.Failed;
builder.AppendFormat("Failed mission \"{0}\"\n",
f.HumanReadableName == null ? f.Name : f.HumanReadableName
);
}
return builder.ToString();
}
private string BuildMissionList(Objective objective) {
Dictionary<string, Dictionary<string, int>> collated = new Dictionary<string, Dictionary<string, int>>();
StringBuilder output = new StringBuilder();
@ -190,6 +208,9 @@ namespace EliteBGS.BGS {
var missions = BuildMissionList(objective);
entries.Append(missions);
var failed = BuildFailedMissions(objective);
entries.Append(failed);
var vouchers = BuildVouchers(objective);
entries.Append(vouchers);

View File

@ -3,11 +3,9 @@ using EDJournal;
namespace EliteBGS.BGS {
public class MissionCompleted : LogEntry {
public MissionCompleted(MissionCompletedEntry e, string system, string station) {
this.Entries.Add(e);
this.Faction = e.JSON.GetValue("Faction").ToString();
this.System = system;
this.Station = station;
public MissionCompleted(MissionCompletedEntry e) {
Entries.Add(e);
Faction = e.JSON.GetValue("Faction").ToString();
}
public string MissionName {

28
BGS/MissionFailed.cs Normal file
View File

@ -0,0 +1,28 @@
using System.Text;
using EDJournal;
namespace EliteBGS.BGS {
public class MissionFailed : LogEntry {
public MissionFailedEntry Failed { get; set; }
public MissionAcceptedEntry Accepted { get; set; }
public MissionFailed(MissionAcceptedEntry accepted) {
Accepted = accepted;
Faction = accepted.Faction;
}
public override string ToString() {
StringBuilder builder = new StringBuilder();
if (Failed == null || Accepted == null) {
return "";
}
builder.AppendFormat("Mission failed: \"{0}\"",
Failed.HumanReadableName != null ? Failed.HumanReadableName : Failed.Name
);
return builder.ToString();
}
}
}

View File

@ -30,6 +30,8 @@ namespace EliteBGS.BGS {
private bool IsRelevant(Entry e) {
return e.Is(Events.MissionCompleted) ||
e.Is(Events.MissionFailed) ||
e.Is(Events.MissionAccepted) ||
e.Is(Events.Docked) ||
e.Is(Events.FSDJump) ||
e.Is(Events.MultiSellExplorationData) ||
@ -50,6 +52,8 @@ namespace EliteBGS.BGS {
select log
;
Dictionary<int, MissionAcceptedEntry> acceptedMissions = new Dictionary<int, MissionAcceptedEntry>();
string current_system = null;
string current_station = null;
string controlling_faction = null;
@ -71,7 +75,7 @@ namespace EliteBGS.BGS {
controlling_faction = (e as FSDJumpEntry).SystemFaction;
} else if (e.Is(Events.MissionCompleted)) {
var completed = e as MissionCompletedEntry;
entry = new MissionCompleted(completed, current_system, current_station);
entry = new MissionCompleted(completed) { System = current_system, Station = current_station };
if (completed.HumanReadableNameWasGenerated) {
/* If the human readable name was generated, we send a log message. Because the
* generated names all sort of suck, we should have more human readable names in
@ -81,6 +85,22 @@ namespace EliteBGS.BGS {
completed.Name +
"\" was generated, please report this.");
}
} else if (e.Is(Events.MissionAccepted)) {
MissionAcceptedEntry accepted = e as MissionAcceptedEntry;
acceptedMissions[accepted.MissionID] = accepted;
} else if (e.Is(Events.MissionFailed)) {
var failed = e as MissionFailedEntry;
var accepted = acceptedMissions[failed.MissionID];
if (accepted == null) {
OnLog?.Invoke("Mission failed that wasn't accepted, please adjust time frame.");
continue;
}
entry = new MissionFailed(accepted) { Failed = failed, System = current_system };
if (failed.HumanReadableName == null) {
OnLog?.Invoke("Human readable name for mission \"" +
failed.Name +
"\" was not recognised");
}
} else if (e.Is(Events.MultiSellExplorationData)) {
/* For multi-sell-exploraton-data only the controlling faction of the station sold to matters.
*/

View File

@ -79,6 +79,7 @@
</ApplicationDefinition>
<Compile Include="BGS\DiscordLogGenerator.cs" />
<Compile Include="BGS\GenericDiscordLog.cs" />
<Compile Include="BGS\MissionFailed.cs" />
<Compile Include="BGS\NonaDiscordLog.cs" />
<Compile Include="BGS\SellCargo.cs" />
<Compile Include="BGS\SellMicroResources.cs" />