From b1607d77eb07f303aa098aa47ef90a6a8622c435 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Thu, 21 Mar 2024 09:42:04 +0100 Subject: [PATCH] implement attachChannelToCastEvent fn for channeling normalizer --- src/parser/shared/normalizers/Channeling.ts | 62 +++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/src/parser/shared/normalizers/Channeling.ts b/src/parser/shared/normalizers/Channeling.ts index 9c47a06bf7d..20da5047a8b 100644 --- a/src/parser/shared/normalizers/Channeling.ts +++ b/src/parser/shared/normalizers/Channeling.ts @@ -252,9 +252,71 @@ export function endCurrentChannel(event: AnyEvent, channelState: ChannelState) { trigger: event, }; channelState.eventsInserter.addAfterEvent(endChannel, event); + + attachChannelToCastEvent(endChannel); + channelState.unresolvedChannel = null; } +/** + * Attempts to attach the endChannel event to the associated cast event + * If the endChannel trigger isn't a cast event, eg. the endChannel was triggered by a debuff event, + * we try to see if the beginChannel trigger was a cast event and attach it to that one + */ +export function attachChannelToCastEvent(endChannelEvent: EndChannelEvent) { + const triggerEvent = endChannelEvent.trigger; + + // Shouldn't be able to happen but just incase + if (!triggerEvent) { + console.log( + 'Channeling normalizer tried to attach endChannelEvent to cast event, but no trigger event for endChannel was found!', + endChannelEvent, + ); + return; + } + + if (triggerEvent.type === EventType.Cast) { + if (triggerEvent.ability.guid !== endChannelEvent.ability.guid) { + // Potential bail out here ? + console.log( + 'Channeling normalizer found mismatching abilities when trying to attach endChannelEvent to cast event', + endChannelEvent, + ); + } + + triggerEvent.channel = endChannelEvent; + return; + } + + const beginChannelTrigger = endChannelEvent.beginChannel.trigger; + + if (!beginChannelTrigger) { + console.log( + 'Channeling normalizer tried to attach endChannelEvent to cast event, but no trigger event for beginChannel was found!', + endChannelEvent, + ); + return; + } + + if (beginChannelTrigger.type === EventType.Cast) { + if (beginChannelTrigger.ability.guid !== endChannelEvent.ability.guid) { + // Potential bail out here ? + console.log( + 'Channeling normalizer found mismatching abilities when trying to attach endChannelEvent to cast event', + endChannelEvent, + ); + } + + beginChannelTrigger.channel = endChannelEvent; + return; + } + + console.log( + 'Channeling normalizer tried to attach endChannelEvent to cast event, but was unable to find it.', + endChannelEvent, + ); +} + /** * Cancels the current channel (if there is one), and updates the channel state appropriately * @param channelState the current channel state