feat(call-for-fire-versus): resize fleet, add second FOB, charred destroyed cells with burn effect
Command Post becomes a 3x2 rect that flips wide/tall, the Ammo Depot L grows to four cells, the FOB becomes two cells, and a second FOB (Forward Operating Base II) joins the fleet for 16 cells across five structures. Fully destroyed structures now render charred black instead of red, and their cells burn with flame and ember particles for 45 seconds after destruction, driven by a new impact timestamp on each shot.
This commit is contained in:
parent
1d8402236b
commit
a72f1bbe03
8 changed files with 385 additions and 71 deletions
|
|
@ -2101,6 +2101,115 @@
|
|||
}
|
||||
}
|
||||
|
||||
/* Burning wreckage on destroyed Call-for-Fire-versus cells (~45s per cell). */
|
||||
.versus-burn {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
z-index: 1;
|
||||
overflow: hidden;
|
||||
border-radius: inherit;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.versus-burn::before,
|
||||
.versus-burn::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
bottom: -8%;
|
||||
width: 72%;
|
||||
height: 88%;
|
||||
transform-origin: 50% 100%;
|
||||
background: radial-gradient(
|
||||
ellipse at 50% 100%,
|
||||
rgba(251, 146, 60, 0.9) 0%,
|
||||
rgba(239, 68, 68, 0.5) 45%,
|
||||
rgba(127, 29, 29, 0) 75%
|
||||
);
|
||||
animation: versus-flame 900ms ease-in-out infinite alternate;
|
||||
}
|
||||
|
||||
.versus-burn::after {
|
||||
width: 42%;
|
||||
height: 62%;
|
||||
background: radial-gradient(
|
||||
ellipse at 50% 100%,
|
||||
rgba(254, 240, 138, 0.95) 0%,
|
||||
rgba(251, 146, 60, 0.6) 55%,
|
||||
rgba(251, 146, 60, 0) 85%
|
||||
);
|
||||
animation-duration: 620ms;
|
||||
animation-delay: -280ms;
|
||||
}
|
||||
|
||||
.versus-ember {
|
||||
position: absolute;
|
||||
bottom: 14%;
|
||||
left: 50%;
|
||||
width: 3px;
|
||||
height: 3px;
|
||||
border-radius: 9999px;
|
||||
background: rgba(253, 186, 116, 0.95);
|
||||
animation: versus-ember-rise 1.5s linear infinite;
|
||||
}
|
||||
|
||||
.versus-ember:nth-child(2) {
|
||||
left: 30%;
|
||||
animation-delay: 0.5s;
|
||||
}
|
||||
|
||||
.versus-ember:nth-child(3) {
|
||||
left: 68%;
|
||||
animation-delay: 1s;
|
||||
background: rgba(252, 165, 165, 0.9);
|
||||
}
|
||||
|
||||
@keyframes versus-flame {
|
||||
0% {
|
||||
transform: translateX(-50%) scale(0.85, 0.7);
|
||||
opacity: 0.7;
|
||||
}
|
||||
50% {
|
||||
transform: translateX(-50%) scale(1.05, 1);
|
||||
opacity: 1;
|
||||
}
|
||||
100% {
|
||||
transform: translateX(-50%) scale(0.9, 0.8);
|
||||
opacity: 0.75;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes versus-ember-rise {
|
||||
0% {
|
||||
transform: translateY(0) scale(1);
|
||||
opacity: 0;
|
||||
}
|
||||
12% {
|
||||
opacity: 1;
|
||||
}
|
||||
100% {
|
||||
transform: translateY(-14px) scale(0.3);
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.versus-burn::before,
|
||||
.versus-burn::after,
|
||||
.versus-ember {
|
||||
animation: none;
|
||||
}
|
||||
.versus-burn::before {
|
||||
opacity: 0.55;
|
||||
}
|
||||
.versus-burn::after {
|
||||
display: none;
|
||||
}
|
||||
.versus-ember {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.poker-action-console:not(.poker-action-console-complete) {
|
||||
grid-template-columns: minmax(0, 1.5fr) minmax(10rem, 0.8fr);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import {
|
|||
import { gridDesignation, METERS_PER_CELL, type GridPoint } from "@/lib/minigames/call-for-fire";
|
||||
import {
|
||||
FOB_FLEET,
|
||||
VERSUS_BURN_MS,
|
||||
VERSUS_WAITING_USER_ID,
|
||||
type FobPlacement,
|
||||
type FobRotation,
|
||||
|
|
@ -50,8 +51,16 @@ const FOB_STYLES: Record<string, { cell: string; swatch: string; ring: string }>
|
|||
swatch: "bg-violet-400",
|
||||
ring: "border-violet-500/60",
|
||||
},
|
||||
"fob-2": {
|
||||
cell: "border-emerald-500/70 bg-emerald-500/30 text-emerald-50",
|
||||
swatch: "bg-emerald-400",
|
||||
ring: "border-emerald-500/60",
|
||||
},
|
||||
};
|
||||
|
||||
/** Charred look for a fully destroyed structure's cells. */
|
||||
const DESTROYED_CELL = "border-zinc-500/40 bg-zinc-950 text-zinc-600";
|
||||
|
||||
function fobStyle(id: string) {
|
||||
return (
|
||||
FOB_STYLES[id] ?? {
|
||||
|
|
@ -66,13 +75,14 @@ function fobStyle(id: string) {
|
|||
function turnsForShape(shape: FobShape): number {
|
||||
if (shape === "square") return 1;
|
||||
if (shape === "l") return 4;
|
||||
return 2;
|
||||
return 2; // line and rect flip between two orientations
|
||||
}
|
||||
|
||||
/** Toggle-button label for the selected emplacement's current orientation. */
|
||||
function rotationLabel(shape: FobShape, orientation: FobRotation): string {
|
||||
if (shape === "square") return "Fixed";
|
||||
if (shape === "l") return "Rotate 90°";
|
||||
if (shape === "rect") return orientation % 2 === 0 ? "Wide" : "Tall";
|
||||
return orientation % 2 === 0 ? "Horizontal" : "Vertical";
|
||||
}
|
||||
|
||||
|
|
@ -388,7 +398,7 @@ function PlacementPhase({
|
|||
size="sm"
|
||||
className="h-auto"
|
||||
disabled={selectedIsSquare}
|
||||
title={selectedIsSquare ? "The Command Post is a fixed 2x2 block." : undefined}
|
||||
title={selectedIsSquare ? "This structure has a fixed orientation." : undefined}
|
||||
onClick={toggleOrientation}
|
||||
>
|
||||
<RotateCcw /> {rotationLabel(selectedDefinition.shape, effectiveOrientation)}
|
||||
|
|
@ -432,8 +442,8 @@ function PlacementPhase({
|
|||
<li>Click a placed structure to pick it up, then click a new cell to move it.</li>
|
||||
<li>
|
||||
Double-click a placed structure, or press the rotate toggle, to rotate it in place.
|
||||
The Command Post is a fixed 2x2 block and does not rotate; the Ammo Depot is an L and
|
||||
turns through four orientations.
|
||||
The Command Post is a 3x2 block that flips between wide and tall; the Ammo Depot is
|
||||
a four-cell L and turns through four orientations.
|
||||
</li>
|
||||
<li>The toggle also sets the orientation used for your next placement.</li>
|
||||
<li>Structures cannot overlap, and your opponent never sees your layout.</li>
|
||||
|
|
@ -513,6 +523,59 @@ function buildBoards(you: VersusMatchView["you"]) {
|
|||
return { myCells, incoming, myShots };
|
||||
}
|
||||
|
||||
/**
|
||||
* Cells still burning on each board. A structure burns for VERSUS_BURN_MS from
|
||||
* the instant its destroying round landed; after that its cells stay charred.
|
||||
*/
|
||||
function burnSets(
|
||||
you: VersusMatchView["you"],
|
||||
now: number,
|
||||
): { mine: Set<string>; enemy: Set<string> } {
|
||||
const mine = new Set<string>();
|
||||
const enemy = new Set<string>();
|
||||
const freshKill = (shot: VersusShotView) => {
|
||||
if (shot.outcome !== "destroyed" || !shot.assetId) return false;
|
||||
const at = Date.parse(shot.at);
|
||||
return Number.isFinite(at) && now - at < VERSUS_BURN_MS;
|
||||
};
|
||||
// Own board: the defender knows their full layout, so every cell of a
|
||||
// reduced structure burns.
|
||||
for (const shot of you.incoming) {
|
||||
if (!freshKill(shot)) continue;
|
||||
const fob = you.fleet.find((candidate) => candidate.id === shot.assetId);
|
||||
for (const cell of fob?.cells ?? []) mine.add(key(cell));
|
||||
}
|
||||
// Enemy sector: the shooter only knows the cells they struck, which is
|
||||
// exactly every cell of a structure they just destroyed.
|
||||
for (const shot of you.shots) {
|
||||
if (!freshKill(shot)) continue;
|
||||
for (const other of you.shots) {
|
||||
if (other.assetId === shot.assetId) enemy.add(key(other.grid));
|
||||
}
|
||||
}
|
||||
return { mine, enemy };
|
||||
}
|
||||
|
||||
/** Asset ids whose structure has been fully destroyed (from my fire). */
|
||||
function destroyedAssetIds(shots: VersusMatchView["you"]["shots"]): Set<string> {
|
||||
const ids = new Set<string>();
|
||||
for (const shot of shots) {
|
||||
if (shot.outcome === "destroyed" && shot.assetId) ids.add(shot.assetId);
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
/** Flickering flame and ember particles over a freshly destroyed cell. */
|
||||
function BurnFlames() {
|
||||
return (
|
||||
<span className="versus-burn" aria-hidden="true">
|
||||
<span className="versus-ember" />
|
||||
<span className="versus-ember" />
|
||||
<span className="versus-ember" />
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
function BattlePhase({
|
||||
match,
|
||||
currentUserId,
|
||||
|
|
@ -534,6 +597,8 @@ function BattlePhase({
|
|||
|
||||
const yourTurn = match.turnUserId !== null && String(match.turnUserId) === String(currentUserId);
|
||||
const boards = buildBoards(you);
|
||||
const burn = useMemo(() => burnSets(you, now), [you, now]);
|
||||
const enemyDown = useMemo(() => destroyedAssetIds(you.shots), [you.shots]);
|
||||
const firstShot = you.lastImpact === null;
|
||||
// Only animate explosions for shots that arrive while watching (not those
|
||||
// already on the board when the page loaded).
|
||||
|
|
@ -614,7 +679,7 @@ function BattlePhase({
|
|||
<div className="grid gap-4 lg:grid-cols-2">
|
||||
<BoardPanel
|
||||
title="Your fire bases"
|
||||
subtitle="Incoming rounds are marked. Structures turn red when reduced."
|
||||
subtitle="Incoming rounds are marked. Reduced structures burn out and go dark."
|
||||
>
|
||||
{Array.from({ length: BOARD }, (_, y) => (
|
||||
<ReadOnlyRow key={y} y={y}>
|
||||
|
|
@ -628,9 +693,10 @@ function BattlePhase({
|
|||
label={`grid ${cellLabel(x, y)}`}
|
||||
className={cn(
|
||||
fob && !destroyed && fobStyle(fob.id).cell,
|
||||
fob && destroyed && "border-red-500/70 bg-red-600/50 text-red-50",
|
||||
fob && destroyed && DESTROYED_CELL,
|
||||
)}
|
||||
>
|
||||
{burn.mine.has(`${x},${y}`) && <BurnFlames />}
|
||||
{fob ? "▣" : ""}
|
||||
{hit && (
|
||||
<span
|
||||
|
|
@ -674,17 +740,20 @@ function BattlePhase({
|
|||
{Array.from({ length: BOARD }, (_, x) => {
|
||||
const shot = boards.myShots.get(`${x},${y}`);
|
||||
const pending = pendingGrid && pendingGrid.x === x && pendingGrid.y === y;
|
||||
// Every cell of an enemy structure you fully destroyed goes dark.
|
||||
const structureDown = Boolean(
|
||||
shot?.shot.assetId && enemyDown.has(shot.shot.assetId),
|
||||
);
|
||||
return (
|
||||
<ReadOnlyCell
|
||||
key={`${x}-${y}`}
|
||||
label={`grid ${cellLabel(x, y)}`}
|
||||
className={cn(
|
||||
shot && shot.shot.outcome === "hit" && shot.shot.assetId
|
||||
? fobStyle(shot.shot.assetId).cell
|
||||
: undefined,
|
||||
shot &&
|
||||
shot.shot.outcome === "destroyed" &&
|
||||
"border-red-500/70 bg-red-600/40 text-red-50",
|
||||
shot && structureDown
|
||||
? DESTROYED_CELL
|
||||
: shot && shot.shot.outcome === "hit" && shot.shot.assetId
|
||||
? fobStyle(shot.shot.assetId).cell
|
||||
: undefined,
|
||||
shot &&
|
||||
shot.shot.outcome === "hit" &&
|
||||
!shot.shot.assetId &&
|
||||
|
|
@ -694,6 +763,7 @@ function BattlePhase({
|
|||
interactive={Boolean(yourTurn && firstShot)}
|
||||
onClick={() => setPendingGrid({ x, y })}
|
||||
>
|
||||
{burn.enemy.has(`${x},${y}`) && <BurnFlames />}
|
||||
{pending ? "◉" : shot ? (shot.shot.outcome === "miss" ? "•" : "✕") : ""}
|
||||
{shot &&
|
||||
shot.shot.outcome !== "miss" &&
|
||||
|
|
|
|||
|
|
@ -26,31 +26,40 @@ export const VERSUS_MAX_NAME_LENGTH = 40;
|
|||
/** Sentinel userId for the empty seat in a waiting match (never a real user). */
|
||||
export const VERSUS_WAITING_USER_ID = 0;
|
||||
|
||||
export type FobShape = "line" | "square" | "l";
|
||||
export type FobShape = "line" | "square" | "rect" | "l";
|
||||
|
||||
export interface FobDefinition {
|
||||
readonly id: string;
|
||||
readonly label: string;
|
||||
/** Occupied cells when placed. */
|
||||
readonly size: number;
|
||||
/** "line" is straight, "square" is an NxN block, "l" is a 3-cell corner. */
|
||||
/**
|
||||
* "line" is straight, "square" is an NxN block, "rect" is a width x height
|
||||
* block (rotates between wide and tall), "l" is a corner with one long arm
|
||||
* (`size - 2` cells) and one short arm (1 cell) around a fixed elbow.
|
||||
*/
|
||||
readonly shape: FobShape;
|
||||
/** Width in cells; only meaningful for the "rect" shape. */
|
||||
readonly width?: number;
|
||||
/** Height in cells; only meaningful for the "rect" shape. */
|
||||
readonly height?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* The emplacement fleet each player hides. Total occupied cells are 10 of 100,
|
||||
* The emplacement fleet each player hides. Total occupied cells are 16 of 100,
|
||||
* so rounds matter without dragging.
|
||||
*/
|
||||
export const FOB_FLEET: readonly FobDefinition[] = [
|
||||
{ id: "command-post", label: "Command Post", size: 4, shape: "square" },
|
||||
{ id: "ammo-depot", label: "Ammo Depot", size: 3, shape: "l" },
|
||||
{ id: "command-post", label: "Command Post", size: 6, shape: "rect", width: 3, height: 2 },
|
||||
{ id: "ammo-depot", label: "Ammo Depot", size: 4, shape: "l" },
|
||||
{ id: "radar-site", label: "Radar Site", size: 2, shape: "line" },
|
||||
{ id: "fob", label: "Forward Operating Base", size: 1, shape: "line" },
|
||||
{ id: "fob", label: "Forward Operating Base", size: 2, shape: "line" },
|
||||
{ id: "fob-2", label: "Forward Operating Base II", size: 2, shape: "line" },
|
||||
];
|
||||
|
||||
/**
|
||||
* Quarter-turns clockwise. Lines use 0 (horizontal) and 1 (vertical); the
|
||||
* square ignores it; the L uses all four.
|
||||
* rect uses 0 (wide) and 1 (tall); the square ignores it; the L uses all four.
|
||||
*/
|
||||
export type FobRotation = 0 | 1 | 2 | 3;
|
||||
|
||||
|
|
@ -64,6 +73,13 @@ export interface FobPlacement {
|
|||
export const VERSUS_SCORE_PER_FOB = 100;
|
||||
export const VERSUS_SCORE_PER_CELL = 1;
|
||||
|
||||
/**
|
||||
* How long a destroyed structure's cells keep burning on the client before
|
||||
* they settle to charred black. Purely cosmetic; the engine only stamps when
|
||||
* each structure died.
|
||||
*/
|
||||
export const VERSUS_BURN_MS = 45_000;
|
||||
|
||||
/** XP payout on match completion. */
|
||||
export const VERSUS_XP_WIN = 40;
|
||||
export const VERSUS_XP_LOSS = 10;
|
||||
|
|
|
|||
|
|
@ -81,6 +81,7 @@ function relativeCells(
|
|||
shape: FobShape,
|
||||
orientation: FobRotation,
|
||||
size: number,
|
||||
dims?: { width: number; height: number },
|
||||
): GridPoint[] | null {
|
||||
if (shape === "square") {
|
||||
const side = Math.round(Math.sqrt(size));
|
||||
|
|
@ -91,15 +92,29 @@ function relativeCells(
|
|||
}
|
||||
return cells;
|
||||
}
|
||||
if (shape === "rect") {
|
||||
const width = dims?.width ?? 0;
|
||||
const height = dims?.height ?? 0;
|
||||
if (width <= 0 || height <= 0 || width * height !== size) return null;
|
||||
// Orientation 0 is wide (width x height), orientation 1 tall (swapped);
|
||||
// the anchor stays the top-left cell of the block either way.
|
||||
const [w, h] = orientation % 2 === 0 ? [width, height] : [height, width];
|
||||
const cells: GridPoint[] = [];
|
||||
for (let dy = 0; dy < h; dy += 1) {
|
||||
for (let dx = 0; dx < w; dx += 1) cells.push({ x: dx, y: dy });
|
||||
}
|
||||
return cells;
|
||||
}
|
||||
if (shape === "l") {
|
||||
// Anchored on the elbow (the corner cell), so rotating keeps that cell
|
||||
// fixed on the board and the two arms swing around it. Orientation 0 looks
|
||||
// like an L with the elbow at its bottom-left, arms up and to the right.
|
||||
return [
|
||||
{ x: 0, y: 0 },
|
||||
rotateVector({ x: 0, y: -1 }, orientation),
|
||||
rotateVector({ x: 1, y: 0 }, orientation),
|
||||
];
|
||||
// fixed on the board and the two arms swing around it. The long arm runs
|
||||
// `size - 2` cells, the short arm one. Orientation 0 looks like an L with
|
||||
// the elbow at its bottom-left, the long arm up and the short arm right.
|
||||
const longArm = Math.max(1, size - 2);
|
||||
const cells: GridPoint[] = [{ x: 0, y: 0 }];
|
||||
for (let i = 1; i <= longArm; i += 1) cells.push(rotateVector({ x: 0, y: -i }, orientation));
|
||||
cells.push(rotateVector({ x: 1, y: 0 }, orientation));
|
||||
return cells;
|
||||
}
|
||||
const horizontal = orientation % 2 === 0;
|
||||
const cells: GridPoint[] = [];
|
||||
|
|
@ -113,7 +128,8 @@ function relativeCells(
|
|||
* Cells a placed emplacement covers, or null when it runs off the board. The
|
||||
* shape drives the footprint and orientation is quarter-turns clockwise.
|
||||
* `origin` is the anchor kept fixed while rotating: a line's first cell, the
|
||||
* square's top-left, or the L's elbow. For the L, `origin` is the elbow cell.
|
||||
* square's or rect's top-left, or the L's elbow. `dims` (width x height) is
|
||||
* required by the rect shape and ignored by the others.
|
||||
*/
|
||||
export function cellsForPlacement(
|
||||
origin: GridPoint,
|
||||
|
|
@ -121,8 +137,9 @@ export function cellsForPlacement(
|
|||
size: number,
|
||||
boardSize: number,
|
||||
shape: FobShape = "line",
|
||||
dims?: { width: number; height: number },
|
||||
): GridPoint[] | null {
|
||||
const relative = relativeCells(shape, orientation, size);
|
||||
const relative = relativeCells(shape, orientation, size, dims);
|
||||
if (!relative) return null;
|
||||
const cells: GridPoint[] = [];
|
||||
for (const cell of relative) {
|
||||
|
|
@ -141,7 +158,18 @@ export function cellsForFob(
|
|||
orientation: FobRotation,
|
||||
boardSize: number,
|
||||
): GridPoint[] | null {
|
||||
return cellsForPlacement(origin, orientation, definition.size, boardSize, definition.shape);
|
||||
const dims =
|
||||
definition.width && definition.height
|
||||
? { width: definition.width, height: definition.height }
|
||||
: undefined;
|
||||
return cellsForPlacement(
|
||||
origin,
|
||||
orientation,
|
||||
definition.size,
|
||||
boardSize,
|
||||
definition.shape,
|
||||
dims,
|
||||
);
|
||||
}
|
||||
|
||||
function cellKey(point: GridPoint): string {
|
||||
|
|
@ -319,7 +347,7 @@ export function fireShot(
|
|||
}
|
||||
}
|
||||
|
||||
const shot: VersusShot = { grid: impact, outcome, assetId };
|
||||
const shot: VersusShot = { grid: impact, outcome, assetId, at: now.toISOString() };
|
||||
const updatedPlayer: VersusPlayerState = {
|
||||
...player,
|
||||
lastImpact: impact,
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ export interface VersusShot {
|
|||
readonly outcome: ShotOutcome;
|
||||
/** Emplacement struck, or null on a miss. */
|
||||
readonly assetId: string | null;
|
||||
/** ISO instant the round impacted (drives the client burn effect). */
|
||||
readonly at: string;
|
||||
}
|
||||
|
||||
export interface VersusPlayerState {
|
||||
|
|
@ -79,6 +81,8 @@ export interface VersusShotView {
|
|||
readonly outcome: ShotOutcome;
|
||||
/** Emplacement type struck (known to the shooter), or null on a miss. */
|
||||
readonly assetId: string | null;
|
||||
/** ISO instant the round impacted (drives the client burn effect). */
|
||||
readonly at: string;
|
||||
}
|
||||
|
||||
export interface VersusYouView {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,12 @@ export function projectFob(fob: VersusFob): VersusFobView {
|
|||
}
|
||||
|
||||
function projectShots(shots: readonly VersusShot[]): VersusShotView[] {
|
||||
return shots.map((shot) => ({ grid: shot.grid, outcome: shot.outcome, assetId: shot.assetId }));
|
||||
return shots.map((shot) => ({
|
||||
grid: shot.grid,
|
||||
outcome: shot.outcome,
|
||||
assetId: shot.assetId,
|
||||
at: shot.at,
|
||||
}));
|
||||
}
|
||||
|
||||
/** Build the safe, per-viewer view of a match. */
|
||||
|
|
|
|||
|
|
@ -13,12 +13,14 @@ import {
|
|||
} from "@/lib/minigames/call-for-fire-versus/registry";
|
||||
import { computeVersusStatsDelta, readVersusStats, xpForVersus } from "@/lib/minigames/call-for-fire-versus/stats";
|
||||
|
||||
/** Mirrors the engine spec layout: 3x2 CP, 4-cell L depot, three 2-cell lines. */
|
||||
function fleetAt(x: number, y: number): FobPlacement[] {
|
||||
return [
|
||||
{ assetId: "command-post", origin: { x, y }, orientation: 0 },
|
||||
{ assetId: "ammo-depot", origin: { x, y: y + 3 }, orientation: 0 },
|
||||
{ assetId: "radar-site", origin: { x, y: y + 4 }, orientation: 0 },
|
||||
{ assetId: "fob", origin: { x, y: y + 5 }, orientation: 0 },
|
||||
{ assetId: "ammo-depot", origin: { x, y: y + 4 }, orientation: 0 },
|
||||
{ assetId: "radar-site", origin: { x, y: y + 5 }, orientation: 0 },
|
||||
{ assetId: "fob", origin: { x, y: y + 6 }, orientation: 0 },
|
||||
{ assetId: "fob-2", origin: { x, y: y + 7 }, orientation: 0 },
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -73,7 +75,7 @@ describe("call for fire versus registry: battle", () => {
|
|||
it("starts the battle after both fleets, host firing first", () => {
|
||||
const matchId = createMatch(9501, "Host");
|
||||
joinMatch(matchId, 9502, "Guest");
|
||||
placeFleetFor(matchId, 9501, fleetAt(4, 4));
|
||||
placeFleetFor(matchId, 9501, fleetAt(6, 0));
|
||||
const view = placeFleetFor(matchId, 9502, fleetAt(0, 0));
|
||||
expect(view.phase).toBe("battle");
|
||||
expect(view.turnUserId).toBe(9501);
|
||||
|
|
@ -83,7 +85,7 @@ describe("call for fire versus registry: battle", () => {
|
|||
it("resolves a shot and passes the turn", () => {
|
||||
const matchId = createMatch(9601, "Host");
|
||||
joinMatch(matchId, 9602, "Guest");
|
||||
placeFleetFor(matchId, 9601, fleetAt(4, 4));
|
||||
placeFleetFor(matchId, 9601, fleetAt(6, 0));
|
||||
placeFleetFor(matchId, 9602, fleetAt(0, 0));
|
||||
|
||||
const afterShot = fireShotFor(matchId, 9601, { kind: "grid", grid: { x: 0, y: 0 } });
|
||||
|
|
@ -99,7 +101,7 @@ describe("call for fire versus registry: battle", () => {
|
|||
it("awards the win to the opponent when a player leaves mid-battle", () => {
|
||||
const matchId = createMatch(9701, "Host");
|
||||
joinMatch(matchId, 9702, "Guest");
|
||||
placeFleetFor(matchId, 9701, fleetAt(4, 4));
|
||||
placeFleetFor(matchId, 9701, fleetAt(6, 0));
|
||||
placeFleetFor(matchId, 9702, fleetAt(0, 0));
|
||||
|
||||
leaveMatch(matchId, 9701);
|
||||
|
|
|
|||
|
|
@ -16,22 +16,24 @@ import {
|
|||
|
||||
/**
|
||||
* A deterministic, non-overlapping fleet layout anchored at (x, y):
|
||||
* a 2x2 Command Post (rows y..y+1), an L Ammo Depot with its elbow at
|
||||
* (x, y+3) (rows y+2..y+3), a Radar Site line (row y+4) and a 1-cell FOB
|
||||
* (row y+5).
|
||||
* a 3x2 Command Post (rows y..y+1), a 4-cell L Ammo Depot with its elbow at
|
||||
* (x, y+4) (long arm up through row y+2, short arm at (x+1, y+4)), then three
|
||||
* 2-cell horizontal lines: Radar Site (row y+5), FOB (row y+6), and FOB II
|
||||
* (row y+7).
|
||||
*/
|
||||
function fleetAt(x: number, y: number): FobPlacement[] {
|
||||
return [
|
||||
{ assetId: "command-post", origin: { x, y }, orientation: 0 },
|
||||
{ assetId: "ammo-depot", origin: { x, y: y + 3 }, orientation: 0 },
|
||||
{ assetId: "radar-site", origin: { x, y: y + 4 }, orientation: 0 },
|
||||
{ assetId: "fob", origin: { x, y: y + 5 }, orientation: 0 },
|
||||
{ assetId: "ammo-depot", origin: { x, y: y + 4 }, orientation: 0 },
|
||||
{ assetId: "radar-site", origin: { x, y: y + 5 }, orientation: 0 },
|
||||
{ assetId: "fob", origin: { x, y: y + 6 }, orientation: 0 },
|
||||
{ assetId: "fob-2", origin: { x, y: y + 7 }, orientation: 0 },
|
||||
];
|
||||
}
|
||||
|
||||
function startedState(): VersusState {
|
||||
let state = createVersusState({ userId: 1, name: "A" }, { userId: 2, name: "B" });
|
||||
state = expectState(placeFleet(state, 0, fleetAt(4, 4)));
|
||||
state = expectState(placeFleet(state, 0, fleetAt(6, 0)));
|
||||
state = expectState(placeFleet(state, 1, fleetAt(0, 0)));
|
||||
return state;
|
||||
}
|
||||
|
|
@ -63,6 +65,55 @@ describe("call for fire versus: fleet placement", () => {
|
|||
expect(cellsForPlacement({ x: 9, y: 0 }, 0, 4, 10, "square")).toBeNull();
|
||||
});
|
||||
|
||||
it("lays out a 3x2 rect that flips between wide and tall", () => {
|
||||
const wide = [
|
||||
{ x: 0, y: 0 },
|
||||
{ x: 1, y: 0 },
|
||||
{ x: 2, y: 0 },
|
||||
{ x: 0, y: 1 },
|
||||
{ x: 1, y: 1 },
|
||||
{ x: 2, y: 1 },
|
||||
];
|
||||
expect(cellsForPlacement({ x: 0, y: 0 }, 0, 6, 10, "rect", { width: 3, height: 2 })).toEqual(
|
||||
wide,
|
||||
);
|
||||
const tall = [
|
||||
{ x: 0, y: 0 },
|
||||
{ x: 1, y: 0 },
|
||||
{ x: 0, y: 1 },
|
||||
{ x: 1, y: 1 },
|
||||
{ x: 0, y: 2 },
|
||||
{ x: 1, y: 2 },
|
||||
];
|
||||
expect(cellsForPlacement({ x: 0, y: 0 }, 1, 6, 10, "rect", { width: 3, height: 2 })).toEqual(
|
||||
tall,
|
||||
);
|
||||
expect(cellsForPlacement({ x: 8, y: 0 }, 0, 6, 10, "rect", { width: 3, height: 2 })).toBeNull();
|
||||
// A rect without usable dimensions is rejected.
|
||||
expect(cellsForPlacement({ x: 0, y: 0 }, 0, 6, 10, "rect")).toBeNull();
|
||||
});
|
||||
|
||||
it("grows the L with its size while keeping the elbow anchor", () => {
|
||||
const anchor = { x: 2, y: 4 };
|
||||
// Orientation 0: long arm (size - 2 cells) up, short arm right.
|
||||
expect(cellsForPlacement(anchor, 0, 4, 10, "l")).toEqual([
|
||||
{ x: 2, y: 4 },
|
||||
{ x: 2, y: 3 },
|
||||
{ x: 2, y: 2 },
|
||||
{ x: 3, y: 4 },
|
||||
]);
|
||||
// Half-turn swings the long arm down and the short arm left; the elbow holds.
|
||||
expect(cellsForPlacement(anchor, 2, 4, 10, "l")).toEqual([
|
||||
{ x: 2, y: 4 },
|
||||
{ x: 2, y: 5 },
|
||||
{ x: 2, y: 6 },
|
||||
{ x: 1, y: 4 },
|
||||
]);
|
||||
for (const turn of [0, 1, 2, 3] as const) {
|
||||
expect(cellsForPlacement(anchor, turn, 4, 10, "l")).toContainEqual(anchor);
|
||||
}
|
||||
});
|
||||
|
||||
it("rotates the 3-cell L around its fixed elbow anchor", () => {
|
||||
const anchor = { x: 2, y: 2 };
|
||||
expect(cellsForPlacement(anchor, 0, 3, 10, "l")).toEqual([
|
||||
|
|
@ -96,11 +147,14 @@ describe("call for fire versus: fleet placement", () => {
|
|||
it("rejects missing, overlapping, and unknown emplacements", () => {
|
||||
expect(buildFleet([fleetAt(0, 0)[0]], 10)).toEqual({ error: "Missing structure: Ammo Depot." });
|
||||
|
||||
// The L's elbow at (2,2) runs its long arm up through (2,1), inside the
|
||||
// Command Post's 3x2 block.
|
||||
const overlapping: FobPlacement[] = [
|
||||
{ assetId: "command-post", origin: { x: 0, y: 0 }, orientation: 0 },
|
||||
{ assetId: "ammo-depot", origin: { x: 1, y: 1 }, orientation: 0 },
|
||||
{ assetId: "ammo-depot", origin: { x: 2, y: 2 }, orientation: 0 },
|
||||
{ assetId: "radar-site", origin: { x: 0, y: 4 }, orientation: 0 },
|
||||
{ assetId: "fob", origin: { x: 0, y: 5 }, orientation: 0 },
|
||||
{ assetId: "fob-2", origin: { x: 0, y: 6 }, orientation: 0 },
|
||||
];
|
||||
expect(buildFleet(overlapping, 10)).toEqual({ error: "Structures cannot overlap." });
|
||||
|
||||
|
|
@ -115,7 +169,7 @@ describe("call for fire versus: fleet placement", () => {
|
|||
let state = createVersusState({ userId: 1, name: "A" }, { userId: 2, name: "B" });
|
||||
state = expectState(placeFleet(state, 0, fleetAt(0, 0)));
|
||||
expect(state.phase).toBe("placing");
|
||||
state = expectState(placeFleet(state, 1, fleetAt(0, 4)));
|
||||
state = expectState(placeFleet(state, 1, fleetAt(0, 1)));
|
||||
expect(state.phase).toBe("battle");
|
||||
expect(state.turn).toBe(0);
|
||||
expect(state.startedAt).not.toBeNull();
|
||||
|
|
@ -159,39 +213,65 @@ describe("call for fire versus: firing", () => {
|
|||
});
|
||||
|
||||
it("ends the match when every emplacement is reduced", () => {
|
||||
// Player 0 walks fire across player 1's whole fleet; player 1 always misses.
|
||||
// Player 0 walks fire across all sixteen cells of player 1's fleetAt(0,0)
|
||||
// (Command Post, Ammo Depot L, Radar Site, FOB, FOB II); player 1 misses.
|
||||
let state = startedState();
|
||||
const moves: Array<{ i: 0 | 1; input: Parameters<typeof fireShot>[2] }> = [
|
||||
{ i: 0, input: { kind: "grid", grid: { x: 0, y: 0 } } },
|
||||
{ i: 1, input: { kind: "grid", grid: { x: 9, y: 9 } } },
|
||||
{ i: 0, input: { kind: "correction", rangeM: 0, deflectionM: 50 } },
|
||||
{ i: 1, input: { kind: "correction", rangeM: 0, deflectionM: 0 } },
|
||||
{ i: 0, input: { kind: "correction", rangeM: -50, deflectionM: -50 } },
|
||||
{ i: 1, input: { kind: "correction", rangeM: 0, deflectionM: 0 } },
|
||||
{ i: 0, input: { kind: "correction", rangeM: 0, deflectionM: 50 } },
|
||||
{ i: 1, input: { kind: "correction", rangeM: 0, deflectionM: 0 } },
|
||||
{ i: 0, input: { kind: "correction", rangeM: -50, deflectionM: -50 } },
|
||||
{ i: 1, input: { kind: "correction", rangeM: 0, deflectionM: 0 } },
|
||||
{ i: 0, input: { kind: "correction", rangeM: -50, deflectionM: 0 } },
|
||||
{ i: 1, input: { kind: "correction", rangeM: 0, deflectionM: 0 } },
|
||||
{ i: 0, input: { kind: "correction", rangeM: 0, deflectionM: 50 } },
|
||||
{ i: 1, input: { kind: "correction", rangeM: 0, deflectionM: 0 } },
|
||||
{ i: 0, input: { kind: "correction", rangeM: -50, deflectionM: -50 } },
|
||||
{ i: 1, input: { kind: "correction", rangeM: 0, deflectionM: 0 } },
|
||||
{ i: 0, input: { kind: "correction", rangeM: 0, deflectionM: 50 } },
|
||||
{ i: 1, input: { kind: "correction", rangeM: 0, deflectionM: 0 } },
|
||||
{ i: 0, input: { kind: "correction", rangeM: -50, deflectionM: -50 } },
|
||||
const targets = [
|
||||
{ x: 0, y: 0 },
|
||||
{ x: 1, y: 0 },
|
||||
{ x: 2, y: 0 },
|
||||
{ x: 2, y: 1 },
|
||||
{ x: 1, y: 1 },
|
||||
{ x: 0, y: 1 },
|
||||
{ x: 0, y: 2 },
|
||||
{ x: 0, y: 3 },
|
||||
{ x: 0, y: 4 },
|
||||
{ x: 1, y: 4 },
|
||||
{ x: 1, y: 5 },
|
||||
{ x: 0, y: 5 },
|
||||
{ x: 0, y: 6 },
|
||||
{ x: 1, y: 6 },
|
||||
{ x: 1, y: 7 },
|
||||
{ x: 0, y: 7 },
|
||||
];
|
||||
for (const move of moves) {
|
||||
state = expectState(fireShot(state, move.i, move.input));
|
||||
state = expectState(fireShot(state, 0, { kind: "grid", grid: targets[0] }));
|
||||
for (let i = 1; i < targets.length; i += 1) {
|
||||
// Player 1 keeps re-hitting the same empty corner between player 0's shots.
|
||||
state = expectState(
|
||||
fireShot(
|
||||
state,
|
||||
1,
|
||||
i === 1
|
||||
? { kind: "grid", grid: { x: 9, y: 9 } }
|
||||
: { kind: "correction", rangeM: 0, deflectionM: 0 },
|
||||
),
|
||||
);
|
||||
const previous = targets[i - 1];
|
||||
const next = targets[i];
|
||||
state = expectState(
|
||||
fireShot(state, 0, {
|
||||
kind: "correction",
|
||||
// One cell per 50m step; range is north-positive, deflection east-positive.
|
||||
rangeM: (previous.y - next.y) * 50,
|
||||
deflectionM: (next.x - previous.x) * 50,
|
||||
}),
|
||||
);
|
||||
}
|
||||
expect(state.phase).toBe("complete");
|
||||
expect(state.winner).toBe(0);
|
||||
expect(state.reason).toBe("eliminated");
|
||||
expect(state.players[0].fobsDestroyed).toBe(4);
|
||||
expect(state.players[0].fobsDestroyed).toBe(5);
|
||||
expect(isFleetDestroyed(state.players[1].fleet ?? [])).toBe(true);
|
||||
});
|
||||
|
||||
it("stamps every shot with its impact instant", () => {
|
||||
const state = startedState();
|
||||
const at = new Date("2026-10-19T12:00:00Z");
|
||||
const first = fireShot(state, 0, { kind: "grid", grid: { x: 0, y: 0 } }, at);
|
||||
if (!("shot" in first)) throw new Error("expected the shot to resolve");
|
||||
expect(first.shot.at).toBe(at.toISOString());
|
||||
});
|
||||
|
||||
it("passes the turn on a timeout", () => {
|
||||
const state = startedState();
|
||||
const skipped = skipTurn(state);
|
||||
|
|
@ -211,7 +291,7 @@ describe("call for fire versus: views", () => {
|
|||
expect(serialized).not.toContain('{"x":1,"y":0}');
|
||||
expect(serialized).not.toContain('"fobsDestroyed":4');
|
||||
// The viewer's own fleet is present.
|
||||
expect(view.you.fleet).toHaveLength(4);
|
||||
expect(view.you.fleet).toHaveLength(5);
|
||||
});
|
||||
|
||||
it("reports the outcome to the shooter only after a shot", async () => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue