Fix hit boolean for torpedos

This commit is contained in:
aronmal 2023-09-10 19:46:21 +02:00
parent 2991dc19f2
commit 8b179b5e65
Signed by: aronmal
GPG key ID: 816B7707426FC612

View file

@ -225,20 +225,20 @@ export function intersectingShip(
export function compiledHits(i: 0 | 1) { export function compiledHits(i: 0 | 1) {
return ( return (
users[i]?.moves.reduce((hits, move) => { users[i]?.moves.reduce((hits, { orientation, type, ...move }) => {
const list = targetList(move, move.type) const list = targetList(move, type)
return move.type === MoveType.Enum.radar return type === MoveType.Enum.radar
? hits ? hits
: [ : [
...hits, ...hits,
...list.map(({ x, y }) => ({ ...list.map((pos) => ({
hit: !!intersectingShip(users[i === 0 ? 1 : 0]?.ships ?? [], { hit: !!intersectingShip(users[i === 0 ? 1 : 0]?.ships ?? [], {
...move, ...pos,
orientation,
size: 1, size: 1,
variant: 0, variant: 0,
}).fields.length, }).fields.length,
x, ...pos,
y,
})), })),
] ]
}, [] as Hit[]) ?? [] }, [] as Hit[]) ?? []