Skip to content

Commit

Permalink
implement attachChannelToCastEvent fn for channeling normalizer
Browse files Browse the repository at this point in the history
  • Loading branch information
Krealle committed Mar 21, 2024
1 parent aa341b8 commit b1607d7
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/parser/shared/normalizers/Channeling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b1607d7

Please sign in to comment.