diff --git a/src/game-logic.js b/src/game-logic.js index 58accda..b642840 100644 --- a/src/game-logic.js +++ b/src/game-logic.js @@ -49,3 +49,25 @@ export const reducePlayerHitQueue = ({ gameOver: nextHull <= 0, }; }; + +export const processQueuedPlayerHits = ({ + hull, + lastHitAt, + now, + hits, + cooldownMs = PLAYER_HIT_COOLDOWN_MS, + maxHull = PLAYER_MAX_HULL, +}) => { + for (const { shot } of hits) { + if (shot?.active && typeof shot.destroy === 'function') shot.destroy(); + } + + return reducePlayerHitQueue({ + hull, + lastHitAt, + now, + damages: hits.map(({ damage }) => damage), + cooldownMs, + maxHull, + }); +};