From df024bc3e6eeb2607f96e04eff89ba80e507c74e Mon Sep 17 00:00:00 2001 From: T'kael Date: Mon, 17 Jun 2024 00:54:27 -0700 Subject: [PATCH] `Destination arrived` event expanded to trigger when arriving at destination settlements / ground sites. Resolves #2623 --- ChangeLog.md | 4 ++++ Events/DestinationArrivedEvent.cs | 4 ++-- StatusMonitor/StatusMonitor.cs | 27 +++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 41f9b52c5d..a658b33b11 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -2,6 +2,10 @@ Full details of the variables available for each noted event, and VoiceAttack integrations, are available in the individual [event pages](https://github.com/EDCD/EDDI/wiki/Events). +## 4.0.4-b3 + * Events + * `Destination arrived` event expanded to trigger when arriving at destination settlements / ground sites (#2623) + ## 4.0.4-b2 * Speech Responder * Core diff --git a/Events/DestinationArrivedEvent.cs b/Events/DestinationArrivedEvent.cs index 458f0592f9..45d59d0a45 100644 --- a/Events/DestinationArrivedEvent.cs +++ b/Events/DestinationArrivedEvent.cs @@ -33,11 +33,11 @@ public class DestinationArrivedEvent : Event public long? marketID { get; private set; } - public DestinationArrivedEvent ( DateTime timestamp, string invariantName, string localizedName, int threat, long? marketID = null) : base(timestamp, NAME) + public DestinationArrivedEvent ( DateTime timestamp, string invariantName, string localizedName = null, int? threat = null, long? marketID = null) : base(timestamp, NAME) { this.invariantName = invariantName; this.name = string.IsNullOrEmpty( localizedName ) ? invariantName : localizedName; - this.threat = threat; + this.threat = threat ?? 0; this.marketID = marketID; } } diff --git a/StatusMonitor/StatusMonitor.cs b/StatusMonitor/StatusMonitor.cs index 98a221c661..1ddd60174e 100644 --- a/StatusMonitor/StatusMonitor.cs +++ b/StatusMonitor/StatusMonitor.cs @@ -300,6 +300,33 @@ public void PreHandle(Event @event) { handleMusicEvent( musicEvent ); } + else if ( @event is SettlementApproachedEvent settlementApproachedEvent ) + { + handleSettlementApproachedEvent( settlementApproachedEvent ); + } + } + + private void handleSettlementApproachedEvent ( SettlementApproachedEvent @event ) + { + // Synthesize a `Destination arrived` event when approaching a settlement / location we've been tracking, + // if the journal hasn't already generated a `SupercruiseDestinationDrop` event + if ( !@event.fromLoad && + currentStatus?.destinationSystemAddress != null && + currentStatus.destinationSystemAddress == @event.systemAddress && + currentStatus.destinationBodyId == @event.bodyId && + ( currentStatus.destination_name == @event.name || + currentStatus.destination_localized_name == @event.name ) ) + { + // Retrieve the last `SupercruiseDestinationDrop` event and verify that, if it exists, it does not match the settlement we may be approaching. + if ( !EDDI.Instance.lastEventOfType.TryGetValue( "SupercruiseDestinationDrop", + out var supercruiseDestinationDrop ) || + !( supercruiseDestinationDrop is DestinationArrivedEvent destinationArrivedEvent ) || + destinationArrivedEvent.name != @event.name ) + { + destinationArrivedEvent = new DestinationArrivedEvent( currentStatus.timestamp, @event.name ); + EDDI.Instance.enqueueEvent( destinationArrivedEvent ); + } + } } private void handleEnteredNormalSpaceEvent( EnteredNormalSpaceEvent @event )