Add per-projectile player damage reducer
This commit is contained in:
parent
cb139b839e
commit
1a99e1c362
@ -111,3 +111,24 @@ export const reducePlayerVolleyHits = ({
|
||||
gameOver: nextHull <= 0,
|
||||
};
|
||||
};
|
||||
|
||||
export const reducePlayerProjectileHits = ({
|
||||
hull,
|
||||
hits,
|
||||
maxHull = PLAYER_MAX_HULL,
|
||||
fallbackDamage = DEFAULT_PIRATE_SHOT_DAMAGE,
|
||||
}) => {
|
||||
const currentHull = Number.isFinite(hull) ? hull : maxHull;
|
||||
const totalDamage = hits.reduce(
|
||||
(sum, hit) => sum + normalizePlayerDamage(hit?.damage, fallbackDamage),
|
||||
0,
|
||||
);
|
||||
const nextHull = Math.max(0, currentHull - totalDamage);
|
||||
|
||||
return {
|
||||
hull: nextHull,
|
||||
totalDamage,
|
||||
appliedHits: hits.length,
|
||||
gameOver: nextHull <= 0,
|
||||
};
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user