Add per-broadside player damage reducer
This commit is contained in:
parent
f5b35fd87f
commit
2dc9bba7f9
@ -67,3 +67,47 @@ export const processQueuedPlayerHits = ({
|
||||
maxHull,
|
||||
});
|
||||
};
|
||||
|
||||
export const reducePlayerVolleyHits = ({
|
||||
hull,
|
||||
hits,
|
||||
seenVolleyIds = [],
|
||||
maxHull = PLAYER_MAX_HULL,
|
||||
fallbackDamage = DEFAULT_PIRATE_SHOT_DAMAGE,
|
||||
maxSeenVolleys = 128,
|
||||
}) => {
|
||||
const seen = new Set(seenVolleyIds);
|
||||
const acceptedHits = [];
|
||||
const ignoredHits = [];
|
||||
let totalDamage = 0;
|
||||
|
||||
for (const hit of hits) {
|
||||
const volleyId = hit?.volleyId ?? null;
|
||||
|
||||
if (volleyId !== null && seen.has(volleyId)) {
|
||||
ignoredHits.push(hit);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (volleyId !== null) seen.add(volleyId);
|
||||
acceptedHits.push(hit);
|
||||
totalDamage += normalizePlayerDamage(hit?.damage, fallbackDamage);
|
||||
}
|
||||
|
||||
while (seen.size > maxSeenVolleys) {
|
||||
const oldest = seen.values().next().value;
|
||||
seen.delete(oldest);
|
||||
}
|
||||
|
||||
const currentHull = Number.isFinite(hull) ? hull : maxHull;
|
||||
const nextHull = Math.max(0, currentHull - totalDamage);
|
||||
|
||||
return {
|
||||
hull: nextHull,
|
||||
totalDamage,
|
||||
acceptedHits,
|
||||
ignoredHits,
|
||||
seenVolleyIds: seen,
|
||||
gameOver: nextHull <= 0,
|
||||
};
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user