completely rework mission code
This commit is contained in:
parent
a11d3d10aa
commit
9d81a9ad7d
@ -5,7 +5,6 @@ namespace EliteBGS.BGS {
|
|||||||
public class MissionCompleted : LogEntry {
|
public class MissionCompleted : LogEntry {
|
||||||
public MissionCompleted(MissionCompletedEntry e) {
|
public MissionCompleted(MissionCompletedEntry e) {
|
||||||
Entries.Add(e);
|
Entries.Add(e);
|
||||||
Faction = e.JSON.GetValue("Faction").ToString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string MissionName {
|
public string MissionName {
|
||||||
|
@ -28,7 +28,7 @@ namespace EliteBGS.BGS {
|
|||||||
return added;
|
return added;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsRelevant(Entry e) {
|
public static bool IsRelevant(Entry e) {
|
||||||
return e.Is(Events.CommitCrime) ||
|
return e.Is(Events.CommitCrime) ||
|
||||||
e.Is(Events.Docked) ||
|
e.Is(Events.Docked) ||
|
||||||
e.Is(Events.FactionKillBond) ||
|
e.Is(Events.FactionKillBond) ||
|
||||||
@ -67,12 +67,17 @@ namespace EliteBGS.BGS {
|
|||||||
.ToList()
|
.ToList()
|
||||||
;
|
;
|
||||||
|
|
||||||
Dictionary<int, MissionAcceptedEntry> acceptedMissions = new Dictionary<int, MissionAcceptedEntry>();
|
Dictionary<ulong, MissionAcceptedEntry> acceptedMissions = new Dictionary<ulong, MissionAcceptedEntry>();
|
||||||
Dictionary<string, long> buyCost = new Dictionary<string, long>();
|
Dictionary<string, long> buyCost = new Dictionary<string, long>();
|
||||||
Dictionary<ulong, string> systems = new Dictionary<ulong, string>();
|
Dictionary<ulong, string> systems = new Dictionary<ulong, string>();
|
||||||
Dictionary<string, string> npcfactions = new Dictionary<string, string>();
|
Dictionary<string, string> npcfactions = new Dictionary<string, string>();
|
||||||
Dictionary<string, List<Faction>> system_factions = new Dictionary<string, List<Faction>>();
|
Dictionary<string, List<Faction>> system_factions = new Dictionary<string, List<Faction>>();
|
||||||
|
|
||||||
|
// A dictionary resolving to a station at which each mission was accepted
|
||||||
|
Dictionary<ulong, string> acceptedStations = new Dictionary<ulong, string>();
|
||||||
|
// A dictionary resolving to a system at which each mission was accepted
|
||||||
|
Dictionary<ulong, ulong> acceptedSystems = new Dictionary<ulong, ulong>();
|
||||||
|
|
||||||
string current_system = null;
|
string current_system = null;
|
||||||
ulong current_system_address = 0;
|
ulong current_system_address = 0;
|
||||||
string current_station = null;
|
string current_station = null;
|
||||||
@ -177,12 +182,18 @@ namespace EliteBGS.BGS {
|
|||||||
});
|
});
|
||||||
collate = true;
|
collate = true;
|
||||||
} else if (e.Is(Events.MissionCompleted)) {
|
} else if (e.Is(Events.MissionCompleted)) {
|
||||||
var completed = e as MissionCompletedEntry;
|
MissionCompletedEntry completed = e as MissionCompletedEntry;
|
||||||
results.Add(new MissionCompleted(completed) {
|
MissionAcceptedEntry accepted;
|
||||||
System = current_system,
|
|
||||||
Station = current_station,
|
if (!acceptedMissions.TryGetValue(completed.MissionID, out accepted)) {
|
||||||
SystemAddress = current_system_address,
|
OnLog?.Invoke(string.Format(
|
||||||
});
|
"Unable to find mission acceptance for mission \"{0}\". " +
|
||||||
|
"Please extend range to include the mission acceptance.", completed.HumanReadableName
|
||||||
|
));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
string mission_giver = completed.Faction;
|
||||||
if (completed.HumanReadableNameWasGenerated) {
|
if (completed.HumanReadableNameWasGenerated) {
|
||||||
/* If the human readable name was generated, we send a log message. Because the
|
/* 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
|
* generated names all sort of suck, we should have more human readable names in
|
||||||
@ -200,9 +211,51 @@ namespace EliteBGS.BGS {
|
|||||||
}
|
}
|
||||||
foreach (var influences in other.Value) {
|
foreach (var influences in other.Value) {
|
||||||
ulong system_address = influences.Key;
|
ulong system_address = influences.Key;
|
||||||
if (!faction.Equals(results[0].Faction) ||
|
ulong accepted_address = 0;
|
||||||
(faction.Equals(results[0].Faction) && system_address != current_system_address)) {
|
string system, accepted_station, accepted_system;
|
||||||
string system = systems.TryGetValue(system_address, out string sys) ? sys : "";
|
|
||||||
|
if (!systems.TryGetValue(system_address, out system)) {
|
||||||
|
OnLog?.Invoke(string.Format(
|
||||||
|
"Unknown system system \"{0}\" unable to assign that mission a target.", system_address
|
||||||
|
));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!acceptedSystems.TryGetValue(completed.MissionID, out accepted_address)) {
|
||||||
|
OnLog?.Invoke(string.Format(
|
||||||
|
"Unable to figure out in which system mission \"{0}\" was accepted.", system_address
|
||||||
|
));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!systems.TryGetValue(accepted_address, out accepted_system)) {
|
||||||
|
OnLog?.Invoke(string.Format(
|
||||||
|
"Unable to figure out in which system mission \"{0}\" was accepted.", system_address
|
||||||
|
));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!acceptedStations.TryGetValue(completed.MissionID, out accepted_station)) {
|
||||||
|
OnLog?.Invoke(string.Format(
|
||||||
|
"Unable to figure out in which station mission \"{0}\" was accepted.", system_address
|
||||||
|
));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (faction.Equals(mission_giver) && system_address == accepted_address) {
|
||||||
|
/* This is the influence block for the origin of the mission.
|
||||||
|
*/
|
||||||
|
results.Add(new MissionCompleted(completed) {
|
||||||
|
System = accepted_system,
|
||||||
|
Faction = mission_giver,
|
||||||
|
SystemAddress = accepted_address,
|
||||||
|
Station = accepted_station,
|
||||||
|
});
|
||||||
|
} else if (!faction.Equals(results[0].Faction) ||
|
||||||
|
(faction.Equals(results[0].Faction) && system_address != accepted_address)) {
|
||||||
|
/* This block is for secondary factions (first if), or if the secondary faction
|
||||||
|
* is the same as the mission giver, but in another system (second if).
|
||||||
|
*/
|
||||||
results.Add(new InfluenceSupport() {
|
results.Add(new InfluenceSupport() {
|
||||||
Faction = faction,
|
Faction = faction,
|
||||||
Influence = influences.Value,
|
Influence = influences.Value,
|
||||||
@ -215,7 +268,16 @@ namespace EliteBGS.BGS {
|
|||||||
}
|
}
|
||||||
} else if (e.Is(Events.MissionAccepted)) {
|
} else if (e.Is(Events.MissionAccepted)) {
|
||||||
MissionAcceptedEntry accepted = e as MissionAcceptedEntry;
|
MissionAcceptedEntry accepted = e as MissionAcceptedEntry;
|
||||||
acceptedMissions[accepted.MissionID] = accepted;
|
ulong id = accepted.MissionID;
|
||||||
|
if (!acceptedMissions.ContainsKey(id)) {
|
||||||
|
acceptedMissions[id] = accepted;
|
||||||
|
}
|
||||||
|
if (!acceptedStations.ContainsKey(id)) {
|
||||||
|
acceptedStations[id] = current_station;
|
||||||
|
}
|
||||||
|
if (!acceptedSystems.ContainsKey(id)) {
|
||||||
|
acceptedSystems[id] = current_system_address;
|
||||||
|
}
|
||||||
} else if (e.Is(Events.MissionFailed)) {
|
} else if (e.Is(Events.MissionFailed)) {
|
||||||
var failed = e as MissionFailedEntry;
|
var failed = e as MissionFailedEntry;
|
||||||
MissionAcceptedEntry accepted = null;
|
MissionAcceptedEntry accepted = null;
|
||||||
|
@ -202,6 +202,7 @@
|
|||||||
<Content Include="main-objectives.png">
|
<Content Include="main-objectives.png">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
|
<None Include="TestData\DoubleSupport.txt" />
|
||||||
<None Include="TestData\MurderOtherThanControllingFaction.txt" />
|
<None Include="TestData\MurderOtherThanControllingFaction.txt" />
|
||||||
<None Include="TestData\TestMurder.txt" />
|
<None Include="TestData\TestMurder.txt" />
|
||||||
<None Include="TestData\SellOrganicData.txt" />
|
<None Include="TestData\SellOrganicData.txt" />
|
||||||
|
859
TestData/DoubleSupport.txt
Normal file
859
TestData/DoubleSupport.txt
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user