From c20c26dacbbac6fd64763a79a1bb31d5ff22befd Mon Sep 17 00:00:00 2001 From: Dominik Bornhaeusser Date: Fri, 27 Nov 2026 08:46:26 +0100 Subject: [PATCH] =?UTF-8?q?Felder=202:=20Geleitabteilung,=20Verst=C3=A4rku?= =?UTF-8?q?ng,=20Radar-Vorwarnung,=20Wochenziele=20Feldertr=C3=A4ge=20und?= =?UTF-8?q?=20Gr=C3=BCndung?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Geleitabteilung aus der Besatzung begleitet Ertragskonvois und kämpft bei Abfangversuchen (Kartell, Kriegsgegner); verteidigt das Feld nicht, Rest bleibt gültige Besatzung - Verstärkung: Besetzen gegen eigenes Feld fügt Schiffe der Besatzung hinzu (auch aus anderem Hafen, Veteranen gewichtet gemischt) - Radar-Vorwarnung (field_warning) bei Spielerangriffen auf Felder, Push und Meldung - Wochenziele feldertrag und gruendung - Balance fields: radarWarningFactor 0.5, escortMinRemainCommandPoints 6 - Migration 0016_felder2 (resource_field.escort), Simulation, Doku, Tests --- apps/api/src/routers/fields.ts | 9 +- apps/web/src/components/FieldEscort.tsx | 60 + apps/web/src/components/Fields.tsx | 27 +- apps/web/src/components/FieldsChapter.tsx | 7 +- apps/web/src/lib/names.ts | 4 + apps/web/src/screens/MissionPlan.tsx | 2 +- docs/REGELN-ERFOLGE.md | 2 + docs/REGELN-FELDER.md | 26 +- packages/balance/v1/balance.json | 4 +- packages/db/migrations/0016_felder2.sql | 1 + .../db/migrations/meta/0016_snapshot.json | 5782 +++++++++++++++++ packages/db/migrations/meta/_journal.json | 7 + packages/db/src/schema/fields.ts | 2 + packages/engine/src/achievement-defs.ts | 28 +- packages/engine/src/fields-core.ts | 16 +- packages/engine/src/fields-escort.ts | 58 + packages/engine/src/fields-missions.ts | 47 +- packages/engine/src/fields-radar.ts | 106 + packages/engine/src/fields-reinforce.ts | 78 + packages/engine/src/fields-run.ts | 22 +- packages/engine/src/index.ts | 1 + packages/engine/src/naval-convoy.ts | 12 +- packages/engine/src/weekly.ts | 48 +- packages/engine/test/fields2.test.ts | 249 + packages/game-core/ENTSCHEIDUNGEN.md | 38 +- packages/game-core/sim/fields.ts | 33 +- packages/game-core/sim/simulate.ts | 3 +- packages/game-core/src/fields.ts | 72 + packages/game-core/test/fields.test.ts | 31 +- 29 files changed, 6708 insertions(+), 67 deletions(-) create mode 100644 apps/web/src/components/FieldEscort.tsx create mode 100644 packages/db/migrations/0016_felder2.sql create mode 100644 packages/db/migrations/meta/0016_snapshot.json create mode 100644 packages/engine/src/fields-escort.ts create mode 100644 packages/engine/src/fields-radar.ts create mode 100644 packages/engine/src/fields-reinforce.ts create mode 100644 packages/engine/test/fields2.test.ts diff --git a/apps/api/src/routers/fields.ts b/apps/api/src/routers/fields.ts index dad8d4e..05249ad 100644 --- a/apps/api/src/routers/fields.ts +++ b/apps/api/src/routers/fields.ts @@ -1,7 +1,8 @@ -// Felder: Rohstofffelder – Lesemodell und Rückruf der Besatzung (Missionen laufen über mission.launch mit fieldId). +// Felder: Rohstofffelder – Lesemodell, Rückruf der Besatzung, Geleitabteilung (Missionen laufen über mission.launch +// mit fieldId; Besetzen gegen ein eigenes Feld ist eine Verstärkung). // Eingehängt in router.ts. import { z } from "zod"; -import { fieldRecall, fieldsView } from "@tidefront/engine"; +import { fieldRecall, fieldsView, setFieldEscort } from "@tidefront/engine"; import { authed, baseInput, baseRef, t } from "../trpc.ts"; const key = z.string().min(8).max(80); @@ -12,4 +13,8 @@ export const fieldsRouter = t.router({ recall: authed .input(z.object({ key, fieldId: z.number().int().min(1), ...baseRef })) .mutation(({ ctx, input }) => fieldRecall(ctx.engine, ctx.player.id, input.key, input.fieldId, input.baseId)), + /** Geleitabteilung aus der Besatzung festlegen (leer = aufheben); begleitet die Ertragskonvois. */ + escort: authed + .input(z.object({ key, fieldId: z.number().int().min(1), units: z.record(z.string().max(40), z.number().int().min(0).max(100000)), ...baseRef })) + .mutation(({ ctx, input }) => setFieldEscort(ctx.engine, ctx.player.id, input.key, input.fieldId, input.units)), }); diff --git a/apps/web/src/components/FieldEscort.tsx b/apps/web/src/components/FieldEscort.tsx new file mode 100644 index 0000000..3445bcc --- /dev/null +++ b/apps/web/src/components/FieldEscort.tsx @@ -0,0 +1,60 @@ +// Felder: Geleitabteilung einer Besatzung festlegen (begleitet die Ertragskonvois, verteidigt das Feld nicht), +// Hinweise zu Vorwarnung und Verstärkung. Teil von „Meine Felder“ (Fields.tsx). Regeln: docs/REGELN-FELDER.md. +import { useState } from "react"; +import { trpc, trpcClient } from "../lib/trpc.ts"; +import { useCommand } from "../lib/command.ts"; +import { label } from "../lib/names.ts"; +import { fmtDuration, fmtTime, useNow } from "../lib/time.ts"; +import { Button, ErrorLine, Stepper, UnitChips } from "../ui.tsx"; + +type Counts = Record; + +const invalidate = () => [trpc.fields.pathFilter().queryKey, trpc.base.pathFilter().queryKey]; + +/** Geleitzeile mit Bearbeiten: Schiffe der Besatzung auswählen, Rest muss eine gültige Besatzung bleiben. */ +export function FieldEscortEditor({ fieldId, garrison, escort }: { fieldId: number; garrison: Counts; escort: Counts }) { + const [open, setOpen] = useState(false); + const [pick, setPick] = useState(escort); + const save = useCommand((i: { key: string; fieldId: number; units: Counts }) => trpcClient.fields.escort.mutate(i), invalidate); + const has = Object.values(escort).some((n) => n > 0); + if (!open) { + return ( +
+ Geleit für Ertragskonvois: {has ? : keines} + +
+ ); + } + const ids = Object.keys(garrison).filter((id) => (garrison[id] ?? 0) > 0); + return ( +
+

Diese Schiffe begleiten jeden Ertragskonvoi und kämpfen gegen Kartell und Kriegsgegner. Sie verteidigen das Feld nicht – der Rest muss eine gültige Besatzung bleiben.

+ {ids.map((id) => ( +
+ {label(id)} (Besatzung {garrison[id]}) + setPick({ ...pick, [id]: v })} /> +
+ ))} +
+ + +
+ +
+ ); +} + +/** Erkannte Angriffe (Radar des Heimathafens) und eigene Verstärkungen unterwegs. */ +export function FieldIncomingLines({ incoming, reinforcements }: { incoming: { arriveAtMs: number }[]; reinforcements: { arriveAtMs: number; units: Counts }[] }) { + const now = useNow(); + return ( + <> + {incoming.map((a, i) => ( +
Angriff erkannt – Ankunft in {fmtDuration(Math.max(0, a.arriveAtMs - now))} ({fmtTime(a.arriveAtMs)})
+ ))} + {reinforcements.map((r, i) => ( +
Verstärkung unterwegs, Ankunft in {fmtDuration(Math.max(0, r.arriveAtMs - now))}:
+ ))} + + ); +} diff --git a/apps/web/src/components/Fields.tsx b/apps/web/src/components/Fields.tsx index 34e5d17..00753b9 100644 --- a/apps/web/src/components/Fields.tsx +++ b/apps/web/src/components/Fields.tsx @@ -8,11 +8,12 @@ import { fmtDuration, fmtTime, useNow } from "../lib/time.ts"; import { Button, Card, ErrorLine, UnitChips } from "../ui.tsx"; import { Icon } from "../icons.tsx"; import type { Target } from "../App.tsx"; +import { FieldEscortEditor, FieldIncomingLines } from "./FieldEscort.tsx"; // Felder 2: Geleit, Vorwarnung, Verstärkung export type FieldsData = NonNullable; type Field = FieldsData["fields"][number]; type Counts = Record; -type FieldsRules = { maxFields: number; maxFieldsPerHarborLevels: number; minGarrisonCommandPoints: number; deliveryHours: number; yieldFactors: number[]; zoneLinkKm: number; zoneMinFields: number; zoneBonus: number; guardRespawnHours: number; cartelRaidChance: number; alliancePointsPerFieldDay: number; minKmFromBase: number; upkeepProviantPerHour: number[]; kinds: Record }; +type FieldsRules = { maxFields: number; maxFieldsPerHarborLevels: number; minGarrisonCommandPoints: number; deliveryHours: number; yieldFactors: number[]; zoneLinkKm: number; zoneMinFields: number; zoneBonus: number; guardRespawnHours: number; cartelRaidChance: number; alliancePointsPerFieldDay: number; minKmFromBase: number; upkeepProviantPerHour: number[]; radarWarningFactor?: number; escortMinRemainCommandPoints?: number; kinds: Record }; export const KIND_TEXT: Record = { oelfeld: "Ölfeld", erzbucht: "Erzbucht", fischgrund: "Fischgrund", elektronikwrack: "Elektronik-Wrack" }; const KIND_HINT: Record = { @@ -67,6 +68,8 @@ export function FieldSheet({ data, sel, onPlan }: { data: FieldsData | null | un {f.relation !== "own" && } {canTake && } + {mine && } + {mine && } {mine && } ); @@ -113,8 +116,11 @@ export function MyFieldsCard({ base, onShowOnMap }: { base: BaseData; onShowOnMa
Ertrag {resLine(m.yieldPerHour)}/h ({Math.round(m.factor * 100)} %{m.zoneBonus ? ", Zonenbonus" : ""}) · Unterhalt {fmtNum(m.upkeepPerHour)} Proviant/h
-
Besatzung:
+ +
Besatzung: {Object.keys(m.escort).length > 0 && – verteidigt das Feld: }
+
Nächste Lieferung {d.nextDeliveryAtMs ? `in ${fmtDuration(d.nextDeliveryAtMs - now)}` : "bald"} per Konvoi nach {m.home ?? base.name}
+ @@ -130,11 +136,16 @@ export function FieldTargetLine({ fieldId }: { fieldId: number }) { const q = useFields(); const f = q.data?.fields.find((x) => x.id === fieldId); if (!f) return <>Rohstofffeld …
; - return <>Rohstofffeld {KIND_TEXT[f.kind]} Stufe {f.tier} – {RELATION_TEXT[f.relation]}{f.owner && f.relation !== "own" ? ` (${f.owner})` : ""}. Nur Schiffe; Seekampf gegen {f.owner ? "die Besatzung" : "die Kartell-Wache"}.
; + if (f.relation === "own") { + return <>Dein Rohstofffeld {KIND_TEXT[f.kind]} Stufe {f.tier} – Verstärkung: die Schiffe werden ohne Kampf der Besatzung hinzugefügt (aus einem anderen Hafen wechseln sie in den Hafen des Felds). Nur Schiffe; Admirale führen keine Feld-Verbände.
; + } + return <>Rohstofffeld {KIND_TEXT[f.kind]} Stufe {f.tier} – {RELATION_TEXT[f.relation]}{f.owner && f.relation !== "own" ? ` (${f.owner})` : ""}. Nur Schiffe; Seekampf gegen {f.owner ? "die Besatzung" : "die Kartell-Wache"}. Admirale führen keine Feld-Verbände.
; } -export function StayAllToggle({ value, onChange, balance }: { value: boolean; onChange: (v: boolean) => void; balance: Balance }) { +export function StayAllToggle({ value, onChange, balance, fieldId }: { value: boolean; onChange: (v: boolean) => void; balance: Balance; fieldId?: number }) { const r = fieldsRules(balance); + const q = useFields(); + if (fieldId !== undefined && q.data?.fields.find((x) => x.id === fieldId)?.relation === "own") return null; // Verstärkung: alles bleibt return ( {type === "blockade" && } - {type === "besetzen" && } + {type === "besetzen" && } {target && Object.keys(chosen).length > 0 && type !== "aufklaerung" && } {type !== "stationierung" && { setUnits(u); if (t) setType(t); setNote(n); }} />} diff --git a/docs/REGELN-ERFOLGE.md b/docs/REGELN-ERFOLGE.md index 5aee880..a4ffb1e 100644 --- a/docs/REGELN-ERFOLGE.md +++ b/docs/REGELN-ERFOLGE.md @@ -63,6 +63,8 @@ fortgeschrieben. | Wrackgut | 3.000 × (1 + KZ/5), auf 500 gerundet | Werft oder Flugfeld | | Anlagen | 5 + KZ/2 Verteidigungsanlagen | immer | | Tagesbefehle | 12 abgeholte Tagesbefehle der Woche | immer | +| Felderträge | Erträge von Rohstofffeldern im Wert von 5.000 × (1 + KZ/5), auf 1.000 gerundet (Richtpreis, Stahl = 1; eingelaufene Konvois) | Werft und mindestens ein erlaubtes Feld (Hafenkommandantur) | +| Gründung | 1 neuer Hafen in der Woche (aus den Häfen gelesen) | weiterer Hafen erlaubt (Kommandozentrale) und Hafenkommandantur für das Kolonieschiff | (KZ = Stufe der Kommandozentrale bei der Vergabe.) - Fortschritt zählt in der Woche, in der das Geschehen stattfand. Erfüllte Ziele der Vorwochen bleiben abholbar. diff --git a/docs/REGELN-FELDER.md b/docs/REGELN-FELDER.md index 4275b8e..492bcf1 100644 --- a/docs/REGELN-FELDER.md +++ b/docs/REGELN-FELDER.md @@ -27,7 +27,12 @@ Begründung und Simulation: `packages/game-core/ENTSCHEIDUNGEN.md`, Abschnitt J, („Ganzer Verband bleibt“) alle Schiffe als Besatzung; der Rest fährt heim. Reichen die Überlebenden nicht oder ist die Höchstzahl erreicht, ist das Feld danach neutral und unbewacht. 4. Die Besatzung ist eine Mission im Status „stationiert“: sie **belegt einen Missionsplatz**, ihr Unterhalt läuft - weiter, sie verteidigt das Feld. **Rückruf** (Truppen → Meine Felder oder Infoblatt): das Feld wird neutral, der + weiter, sie verteidigt das Feld (ohne die Geleitabteilung, siehe Ertrag). Admirale führen keine Feld-Verbände. + **Verstärkung:** „Besetzen“ gegen ein eigenes Feld mit Besatzung schickt Schiffe ohne Kampf hin (nur Schiffe, keine + Mindeststärke, keine Höchstzahl-Prüfung, Treibstoff für Hin- und Rückweg wie beim Besetzen). Bei Ankunft gehören + sie zur Besatzung und kehren mit ihr heim. Kommen sie aus einem anderen eigenen Hafen, wechseln sie in den Hafen + des Felds (Veteranen gewichtet gemischt wie bei der Verlegung). Ist das Feld bei Ankunft nicht mehr eigen, fährt + der Verband heim. Ein Besetzen-Verband, der ein inzwischen eigenes Feld erreicht, verstärkt ebenso. **Rückruf** (Truppen → Meine Felder oder Infoblatt): das Feld wird neutral, der angefangene Ertrag geht noch als Konvoi heim. Ohne Wache kehrt das Kartell nach `guardRespawnHours` (6 h) zurück. 5. Felder gehören einem Spieler **und** einem Heimathafen (dem Hafen, der sie genommen hat); dorthin gehen Ertrag und Unterhalt. @@ -35,8 +40,14 @@ Begründung und Simulation: `packages/game-core/ENTSCHEIDUNGEN.md`, Abschnitt J, ## Ertrag und Unterhalt - Alle `deliveryHours` (4 h) wird abgerechnet: Ertrag × Rangfaktor × Zonenbonus läuft als **Konvoi** (Art „Feld“, - ohne Geleit, `convoySpeedKmh` 40 km/h) zum Heimathafen. Das Kartell fängt wie bei anderen Konvois gelegentlich ab, + `convoySpeedKmh` 40 km/h) zum Heimathafen. Das Kartell fängt wie bei anderen Konvois gelegentlich ab, Kriegsgegner können ihn abfangen. Eine **Blockade** des Heimathafens hält ihn zurück. Minen wirken nicht. +- **Geleitabteilung** (Truppen → Meine Felder → Geleit einteilen): Schiffe der Besatzung, die jeden Ertragskonvoi + begleiten und bei Abfangversuchen (Kartell, Kriegsgegner) wie ein Geleitschutz kämpfen (mit den Modifikatoren des + Hafens des Felds). Sie verteidigen das Feld **nicht**; was bleibt, muss eine gültige Besatzung sein (bewaffnet, + ≥ `escortMinRemainCommandPoints` = 6 Kommandopunkte). Kein Treibstoff, keine eigene Mission. Gilt ab dem nächsten + Konvoi; jeder Konvoi kämpft mit dem aktuellen Bestand der Abteilung, Verluste fehlen der Besatzung. Fällt das Feld + (Spieler oder Kartell), kehrt die Abteilung heim – sie war unterwegs. - Unterhalt je Feld: 10/15/20 Proviant je Stunde (Stufe 1/2/3), vom Heimathafen (höchstens der Bestand). - Bei Verlust des Felds durch Angriff verfällt der angefangene Zyklus. @@ -49,9 +60,12 @@ Begründung und Simulation: `packages/game-core/ENTSCHEIDUNGEN.md`, Abschnitt J, - **Spieler**: „Angreifen“ auf der Karte (Missionsart Besetzen). Sieger übernimmt mit seiner Besatzung; die alte Besatzung ist vernichtet. Hält die Besatzung, bleiben ihre Verluste. +- **Radar-Vorwarnung**: Angriffe anderer Spieler auf ein besetztes Feld meldet das Radar des Hafens, dem das Feld + gehört, `radarWarningFactor` (50 %) seiner Vorwarnzeit vor Ankunft (Strom, Sabotage, Nebel und Tarnung wie bei + Häfen; einmal erkannt bleibt erkannt). Push und Systemnachricht; unter Meine Felder und im Infoblatt steht die + Ankunft. Ohne Radar keine Vorwarnung. - **Kartell**: je Lieferzyklus und besetztem Feld Chance `cartelRaidChance` (5 %); Ankunft nach - `cartelRaidLeadMinutes` (60 min, Push und Nachricht vorab), Verband 9/12/18 Schnellboote ± 30 %. Unterliegt die - Besatzung, wird das Feld neutral und das Kartell bewacht es wieder. + `cartelRaidLeadMinutes` (60 min, Push und Nachricht vorab), Verband 9/12/18 Schnellboote ± 30 %. Es kämpft die Besatzung ohne Geleitabteilung. Unterliegt sie, wird das Feld neutral und das Kartell bewacht es wieder. - Berichte für beide Seiten, Push und Systemnachricht an den Besitzer. ## Allianz-Einflusszone @@ -60,6 +74,8 @@ Begründung und Simulation: `packages/game-core/ENTSCHEIDUNGEN.md`, Abschnitt J, (auf der Karte durch Linien und Hof sichtbar). Ab `zoneMinFields` (3) Feldern: +10 % Ertrag je Feld der Zone. - Allianzwertung: +20 Punkte je besetztem Feld und Tag (am Saisonende zur Summe der Mitglieder addiert). -## Erfolge +## Erfolge und Wochenziele - Zähler `felder` (je Einnahme), Erfolg **Landnahme**: 1 / 5 / 20 Felder (Bronze/Silber/Gold). +- Zähler `feldertrag` (Wert eingelaufener Ertragskonvois zum Richtpreis): Wochenziel **Felderträge** + (`docs/REGELN-ERFOLGE.md`). diff --git a/packages/balance/v1/balance.json b/packages/balance/v1/balance.json index d259556..a768205 100644 --- a/packages/balance/v1/balance.json +++ b/packages/balance/v1/balance.json @@ -369,7 +369,9 @@ "zoneLinkKm": 450, "zoneMinFields": 3, "zoneBonus": 0.1, - "alliancePointsPerFieldDay": 20 + "alliancePointsPerFieldDay": 20, + "radarWarningFactor": 0.5, + "escortMinRemainCommandPoints": 6 }, "expansion": { "maxBases": 3, diff --git a/packages/db/migrations/0016_felder2.sql b/packages/db/migrations/0016_felder2.sql new file mode 100644 index 0000000..69dfdcb --- /dev/null +++ b/packages/db/migrations/0016_felder2.sql @@ -0,0 +1 @@ +ALTER TABLE "resource_field" ADD COLUMN "escort" jsonb DEFAULT '{}'::jsonb NOT NULL; \ No newline at end of file diff --git a/packages/db/migrations/meta/0016_snapshot.json b/packages/db/migrations/meta/0016_snapshot.json new file mode 100644 index 0000000..01084e6 --- /dev/null +++ b/packages/db/migrations/meta/0016_snapshot.json @@ -0,0 +1,5782 @@ +{ + "id": "f5b858be-5da5-4c7c-a97e-1a540a1e2100", + "prevId": "6b14eeb1-6d32-42b6-9c3d-ee5fb1e05957", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.audit_run": { + "name": "audit_run", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "ok": { + "name": "ok", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "details": { + "name": "details", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.base": { + "name": "base", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "player_id": { + "name": "player_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "col": { + "name": "col", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "row": { + "name": "row", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "state": { + "name": "state", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "is_home": { + "name": "is_home", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + } + }, + "indexes": { + "base_field": { + "name": "base_field", + "columns": [ + { + "expression": "col", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "row", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "base_home": { + "name": "base_home", + "columns": [ + { + "expression": "player_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"base\".\"is_home\"", + "concurrently": false, + "method": "btree", + "with": {} + }, + "base_player_idx": { + "name": "base_player_idx", + "columns": [ + { + "expression": "player_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "base_player_id_player_id_fk": { + "name": "base_player_id_player_id_fk", + "tableFrom": "base", + "tableTo": "player", + "columnsFrom": [ + "player_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.battle_report": { + "name": "battle_report", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "attacker_player_id": { + "name": "attacker_player_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "defender_player_id": { + "name": "defender_player_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "attacker_base_id": { + "name": "attacker_base_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "defender_base_id": { + "name": "defender_base_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "nest_id": { + "name": "nest_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "winner": { + "name": "winner", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "seed": { + "name": "seed", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "balance_version": { + "name": "balance_version", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "report": { + "name": "report", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "report_attacker": { + "name": "report_attacker", + "columns": [ + { + "expression": "attacker_player_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "report_defender": { + "name": "report_defender", + "columns": [ + { + "expression": "defender_player_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.command_log": { + "name": "command_log", + "schema": "", + "columns": { + "key": { + "name": "key", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "player_id": { + "name": "player_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "command": { + "name": "command", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "response": { + "name": "response", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.game_event": { + "name": "game_event", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "due_at": { + "name": "due_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "base_id": { + "name": "base_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "processed_at": { + "name": "processed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "game_event_due": { + "name": "game_event_due", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "due_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "game_event_base": { + "name": "game_event_base", + "columns": [ + { + "expression": "base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "due_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.invite_code": { + "name": "invite_code", + "schema": "", + "columns": { + "code": { + "name": "code", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "max_uses": { + "name": "max_uses", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "uses": { + "name": "uses", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "disabled_at": { + "name": "disabled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.mission": { + "name": "mission", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "player_id": { + "name": "player_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "base_id": { + "name": "base_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "target_kind": { + "name": "target_kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "target_id": { + "name": "target_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "target_col": { + "name": "target_col", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "target_row": { + "name": "target_row", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "plan": { + "name": "plan", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "arrive_at": { + "name": "arrive_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "return_at": { + "name": "return_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "returning": { + "name": "returning", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "cargo_home": { + "name": "cargo_home", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "report_id": { + "name": "report_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "mission_base_status": { + "name": "mission_base_status", + "columns": [ + { + "expression": "base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "mission_target": { + "name": "mission_target", + "columns": [ + { + "expression": "target_kind", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "target_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "mission_player_id_player_id_fk": { + "name": "mission_player_id_player_id_fk", + "tableFrom": "mission", + "tableTo": "player", + "columnsFrom": [ + "player_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "mission_base_id_base_id_fk": { + "name": "mission_base_id_base_id_fk", + "tableFrom": "mission", + "tableTo": "base", + "columnsFrom": [ + "base_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.nest": { + "name": "nest", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "col": { + "name": "col", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "row": { + "name": "row", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "level": { + "name": "level", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "defeated_at": { + "name": "defeated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "nest_field": { + "name": "nest_field", + "columns": [ + { + "expression": "col", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "row", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.player": { + "name": "player", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "pass_hash": { + "name": "pass_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "trader": { + "name": "trader", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "is_admin": { + "name": "is_admin", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "player_name_lower": { + "name": "player_name_lower", + "columns": [ + { + "expression": "lower(\"name\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.session": { + "name": "session", + "schema": "", + "columns": { + "token": { + "name": "token", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "player_id": { + "name": "player_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "session_player_id_player_id_fk": { + "name": "session_player_id_player_id_fk", + "tableFrom": "session", + "tableTo": "player", + "columnsFrom": [ + "player_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.wreck": { + "name": "wreck", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "col": { + "name": "col", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "row": { + "name": "row", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "stahl": { + "name": "stahl", + "type": "double precision", + "primaryKey": false, + "notNull": true + }, + "elektronik": { + "name": "elektronik", + "type": "double precision", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "wreck_field": { + "name": "wreck_field", + "columns": [ + { + "expression": "col", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "row", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.delivery": { + "name": "delivery", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "player_id": { + "name": "player_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "base_id": { + "name": "base_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "resource": { + "name": "resource", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "qty": { + "name": "qty", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "depart_at": { + "name": "depart_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "arrive_at": { + "name": "arrive_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'underway'" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.market": { + "name": "market", + "schema": "", + "columns": { + "resource": { + "name": "resource", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "state": { + "name": "state", + "type": "jsonb", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.market_news": { + "name": "market_news", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "key": { + "name": "key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "resource": { + "name": "resource", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "pct": { + "name": "pct", + "type": "double precision", + "primaryKey": false, + "notNull": true + }, + "reason": { + "name": "reason", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "starts_at": { + "name": "starts_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "ends_at": { + "name": "ends_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "fade_minutes": { + "name": "fade_minutes", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "pushed_at": { + "name": "pushed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "market_news_key": { + "name": "market_news_key", + "columns": [ + { + "expression": "key", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "resource", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "market_news_ends": { + "name": "market_news_ends", + "columns": [ + { + "expression": "ends_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.trade_ledger": { + "name": "trade_ledger", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "trade_id": { + "name": "trade_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "t_ms": { + "name": "t_ms", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "account": { + "name": "account", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "asset": { + "name": "asset", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "amount": { + "name": "amount", + "type": "numeric(24, 2)", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "ledger_account": { + "name": "ledger_account", + "columns": [ + { + "expression": "account", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "asset", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "ledger_trade": { + "name": "ledger_trade", + "columns": [ + { + "expression": "trade_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.alliance": { + "name": "alliance", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "tag": { + "name": "tag", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "alliance_name_lower": { + "name": "alliance_name_lower", + "columns": [ + { + "expression": "lower(\"name\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "alliance_tag_lower": { + "name": "alliance_tag_lower", + "columns": [ + { + "expression": "lower(\"tag\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.alliance_chat": { + "name": "alliance_chat", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "alliance_id": { + "name": "alliance_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "player_id": { + "name": "player_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "alliance_chat_alliance": { + "name": "alliance_chat_alliance", + "columns": [ + { + "expression": "alliance_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "alliance_chat_alliance_id_alliance_id_fk": { + "name": "alliance_chat_alliance_id_alliance_id_fk", + "tableFrom": "alliance_chat", + "tableTo": "alliance", + "columnsFrom": [ + "alliance_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "alliance_chat_player_id_player_id_fk": { + "name": "alliance_chat_player_id_player_id_fk", + "tableFrom": "alliance_chat", + "tableTo": "player", + "columnsFrom": [ + "player_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.alliance_member": { + "name": "alliance_member", + "schema": "", + "columns": { + "player_id": { + "name": "player_id", + "type": "integer", + "primaryKey": true, + "notNull": true + }, + "alliance_id": { + "name": "alliance_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "joined_at": { + "name": "joined_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "alliance_member_alliance": { + "name": "alliance_member_alliance", + "columns": [ + { + "expression": "alliance_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "alliance_member_player_id_player_id_fk": { + "name": "alliance_member_player_id_player_id_fk", + "tableFrom": "alliance_member", + "tableTo": "player", + "columnsFrom": [ + "player_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "alliance_member_alliance_id_alliance_id_fk": { + "name": "alliance_member_alliance_id_alliance_id_fk", + "tableFrom": "alliance_member", + "tableTo": "alliance", + "columnsFrom": [ + "alliance_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.alliance_request": { + "name": "alliance_request", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "alliance_id": { + "name": "alliance_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "player_id": { + "name": "player_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "alliance_request_pair": { + "name": "alliance_request_pair", + "columns": [ + { + "expression": "alliance_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "player_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "alliance_request_player": { + "name": "alliance_request_player", + "columns": [ + { + "expression": "player_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "alliance_request_alliance_id_alliance_id_fk": { + "name": "alliance_request_alliance_id_alliance_id_fk", + "tableFrom": "alliance_request", + "tableTo": "alliance", + "columnsFrom": [ + "alliance_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "alliance_request_player_id_player_id_fk": { + "name": "alliance_request_player_id_player_id_fk", + "tableFrom": "alliance_request", + "tableTo": "player", + "columnsFrom": [ + "player_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.diplomacy": { + "name": "diplomacy", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "party_a": { + "name": "party_a", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "party_b": { + "name": "party_b", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "proposed_by": { + "name": "proposed_by", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "active_from": { + "name": "active_from", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "ends_at": { + "name": "ends_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "peace_by": { + "name": "peace_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "diplomacy_pair": { + "name": "diplomacy_pair", + "columns": [ + { + "expression": "party_a", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "party_b", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "kind", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "diplomacy_b": { + "name": "diplomacy_b", + "columns": [ + { + "expression": "party_b", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.invite_block": { + "name": "invite_block", + "schema": "", + "columns": { + "email_hash": { + "name": "email_hash", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.message": { + "name": "message", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "from_player_id": { + "name": "from_player_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "to_player_id": { + "name": "to_player_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "subject": { + "name": "subject", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "read_at": { + "name": "read_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "message_to": { + "name": "message_to", + "columns": [ + { + "expression": "to_player_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "message_from": { + "name": "message_from", + "columns": [ + { + "expression": "from_player_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "message_from_player_id_player_id_fk": { + "name": "message_from_player_id_player_id_fk", + "tableFrom": "message", + "tableTo": "player", + "columnsFrom": [ + "from_player_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "message_to_player_id_player_id_fk": { + "name": "message_to_player_id_player_id_fk", + "tableFrom": "message", + "tableTo": "player", + "columnsFrom": [ + "to_player_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.player_invite": { + "name": "player_invite", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "code": { + "name": "code", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "inviter_id": { + "name": "inviter_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "channel": { + "name": "channel", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "friend_name": { + "name": "friend_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "block_token": { + "name": "block_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "sent_at": { + "name": "sent_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "send_count": { + "name": "send_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "revoked_at": { + "name": "revoked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "accepted_at": { + "name": "accepted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "accepted_player_id": { + "name": "accepted_player_id", + "type": "integer", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "player_invite_code": { + "name": "player_invite_code", + "columns": [ + { + "expression": "code", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "player_invite_block": { + "name": "player_invite_block", + "columns": [ + { + "expression": "block_token", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "player_invite_inviter": { + "name": "player_invite_inviter", + "columns": [ + { + "expression": "inviter_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "player_invite_email": { + "name": "player_invite_email", + "columns": [ + { + "expression": "lower(\"email\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "player_invite_accepted": { + "name": "player_invite_accepted", + "columns": [ + { + "expression": "accepted_player_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "player_invite_code_invite_code_code_fk": { + "name": "player_invite_code_invite_code_code_fk", + "tableFrom": "player_invite", + "tableTo": "invite_code", + "columnsFrom": [ + "code" + ], + "columnsTo": [ + "code" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "player_invite_inviter_id_player_id_fk": { + "name": "player_invite_inviter_id_player_id_fk", + "tableFrom": "player_invite", + "tableTo": "player", + "columnsFrom": [ + "inviter_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "player_invite_accepted_player_id_player_id_fk": { + "name": "player_invite_accepted_player_id_player_id_fk", + "tableFrom": "player_invite", + "tableTo": "player", + "columnsFrom": [ + "accepted_player_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.player_offer": { + "name": "player_offer", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "seller_id": { + "name": "seller_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "seller_base_id": { + "name": "seller_base_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "give": { + "name": "give", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "give_qty": { + "name": "give_qty", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "want": { + "name": "want", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "want_qty": { + "name": "want_qty", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "visibility": { + "name": "visibility", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "alliance_id": { + "name": "alliance_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'open'" + }, + "buyer_id": { + "name": "buyer_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "closed_at": { + "name": "closed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "player_offer_status": { + "name": "player_offer_status", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "player_offer_seller": { + "name": "player_offer_seller", + "columns": [ + { + "expression": "seller_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "player_offer_seller_id_player_id_fk": { + "name": "player_offer_seller_id_player_id_fk", + "tableFrom": "player_offer", + "tableTo": "player", + "columnsFrom": [ + "seller_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.season": { + "name": "season", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "number": { + "name": "number", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "starts_at": { + "name": "starts_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "ends_at": { + "name": "ends_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'running'" + }, + "finished_at": { + "name": "finished_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "season_number": { + "name": "season_number", + "columns": [ + { + "expression": "number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.season_alliance_result": { + "name": "season_alliance_result", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "season_id": { + "name": "season_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "alliance_id": { + "name": "alliance_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "tag": { + "name": "tag", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "rank": { + "name": "rank", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "members": { + "name": "members", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "total": { + "name": "total", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "player_ids": { + "name": "player_ids", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + } + }, + "indexes": { + "season_alliance_result_alliance": { + "name": "season_alliance_result_alliance", + "columns": [ + { + "expression": "season_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "alliance_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "season_alliance_result_rank": { + "name": "season_alliance_result_rank", + "columns": [ + { + "expression": "season_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "rank", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "season_alliance_result_season_id_season_id_fk": { + "name": "season_alliance_result_season_id_season_id_fk", + "tableFrom": "season_alliance_result", + "tableTo": "season", + "columnsFrom": [ + "season_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "season_alliance_result_alliance_id_alliance_id_fk": { + "name": "season_alliance_result_alliance_id_alliance_id_fk", + "tableFrom": "season_alliance_result", + "tableTo": "alliance", + "columnsFrom": [ + "alliance_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.season_result": { + "name": "season_result", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "season_id": { + "name": "season_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "player_id": { + "name": "player_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "player_name": { + "name": "player_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "rank": { + "name": "rank", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "ausbau": { + "name": "ausbau", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "militaer": { + "name": "militaer", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "kampf": { + "name": "kampf", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "beute": { + "name": "beute", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "befehle": { + "name": "befehle", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "total": { + "name": "total", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "awards": { + "name": "awards", + "type": "jsonb", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "season_result_player": { + "name": "season_result_player", + "columns": [ + { + "expression": "season_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "player_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "season_result_rank": { + "name": "season_result_rank", + "columns": [ + { + "expression": "season_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "rank", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "season_result_season_id_season_id_fk": { + "name": "season_result_season_id_season_id_fk", + "tableFrom": "season_result", + "tableTo": "season", + "columnsFrom": [ + "season_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "season_result_player_id_player_id_fk": { + "name": "season_result_player_id_player_id_fk", + "tableFrom": "season_result", + "tableTo": "player", + "columnsFrom": [ + "player_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.daily_challenge": { + "name": "daily_challenge", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "player_id": { + "name": "player_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "day": { + "name": "day", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "slot": { + "name": "slot", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "param": { + "name": "param", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "target": { + "name": "target", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "progress": { + "name": "progress", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "reward": { + "name": "reward", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "points": { + "name": "points", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "bonus_points": { + "name": "bonus_points", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "rerolled": { + "name": "rerolled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "claimed_at": { + "name": "claimed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "daily_challenge_slot": { + "name": "daily_challenge_slot", + "columns": [ + { + "expression": "player_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "day", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "slot", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "daily_challenge_open": { + "name": "daily_challenge_open", + "columns": [ + { + "expression": "player_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "claimed_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "daily_challenge_player_id_player_id_fk": { + "name": "daily_challenge_player_id_player_id_fk", + "tableFrom": "daily_challenge", + "tableTo": "player", + "columnsFrom": [ + "player_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.daily_streak": { + "name": "daily_streak", + "schema": "", + "columns": { + "player_id": { + "name": "player_id", + "type": "integer", + "primaryKey": true, + "notNull": true + }, + "last_day": { + "name": "last_day", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "length": { + "name": "length", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "best": { + "name": "best", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "daily_streak_player_id_player_id_fk": { + "name": "daily_streak_player_id_player_id_fk", + "tableFrom": "daily_streak", + "tableTo": "player", + "columnsFrom": [ + "player_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.formation_template": { + "name": "formation_template", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "player_id": { + "name": "player_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "units": { + "name": "units", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "mission_type": { + "name": "mission_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "formation_template_name": { + "name": "formation_template_name", + "columns": [ + { + "expression": "player_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lower(\"name\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "formation_template_player_id_player_id_fk": { + "name": "formation_template_player_id_player_id_fk", + "tableFrom": "formation_template", + "tableTo": "player", + "columnsFrom": [ + "player_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.guide_claim": { + "name": "guide_claim", + "schema": "", + "columns": { + "player_id": { + "name": "player_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "season_id": { + "name": "season_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "step": { + "name": "step", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "claimed_at": { + "name": "claimed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "boost_used_at": { + "name": "boost_used_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "guide_claim_pk": { + "name": "guide_claim_pk", + "columns": [ + { + "expression": "player_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "season_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "step", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "guide_claim_player_id_player_id_fk": { + "name": "guide_claim_player_id_player_id_fk", + "tableFrom": "guide_claim", + "tableTo": "player", + "columnsFrom": [ + "player_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "guide_claim_season_id_season_id_fk": { + "name": "guide_claim_season_id_season_id_fk", + "tableFrom": "guide_claim", + "tableTo": "season", + "columnsFrom": [ + "season_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.morning_summary": { + "name": "morning_summary", + "schema": "", + "columns": { + "player_id": { + "name": "player_id", + "type": "integer", + "primaryKey": true, + "notNull": true + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "minute_of_day": { + "name": "minute_of_day", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 420 + }, + "time_zone": { + "name": "time_zone", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'Europe/Berlin'" + }, + "push": { + "name": "push", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "last_sent_day": { + "name": "last_sent_day", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "last_sent_at": { + "name": "last_sent_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "morning_summary_player_id_player_id_fk": { + "name": "morning_summary_player_id_player_id_fk", + "tableFrom": "morning_summary", + "tableTo": "player", + "columnsFrom": [ + "player_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.summary_entry": { + "name": "summary_entry", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "player_id": { + "name": "player_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "summary_entry_player": { + "name": "summary_entry_player", + "columns": [ + { + "expression": "player_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "summary_entry_player_id_player_id_fk": { + "name": "summary_entry_player_id_player_id_fk", + "tableFrom": "summary_entry", + "tableTo": "player", + "columnsFrom": [ + "player_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.backup_download_token": { + "name": "backup_download_token", + "schema": "", + "columns": { + "token_hash": { + "name": "token_hash", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "player_id": { + "name": "player_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "file": { + "name": "file", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "used_at": { + "name": "used_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "backup_download_token_player_id_player_id_fk": { + "name": "backup_download_token_player_id_player_id_fk", + "tableFrom": "backup_download_token", + "tableTo": "player", + "columnsFrom": [ + "player_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.backup_request": { + "name": "backup_request", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "requested_by": { + "name": "requested_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "file": { + "name": "file", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "started_at": { + "name": "started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "finished_at": { + "name": "finished_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "backup_request_status": { + "name": "backup_request_status", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "backup_request_requested_by_player_id_fk": { + "name": "backup_request_requested_by_player_id_fk", + "tableFrom": "backup_request", + "tableTo": "player", + "columnsFrom": [ + "requested_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.backup_run": { + "name": "backup_run", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "file": { + "name": "file", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "bytes": { + "name": "bytes", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.bug_report": { + "name": "bug_report", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "player_id": { + "name": "player_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "subject": { + "name": "subject", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "text": { + "name": "text", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "meta": { + "name": "meta", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "log": { + "name": "log", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "screenshot": { + "name": "screenshot", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "screenshot_type": { + "name": "screenshot_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'offen'" + }, + "mailed_at": { + "name": "mailed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "bug_report_player": { + "name": "bug_report_player", + "columns": [ + { + "expression": "player_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "bug_report_status": { + "name": "bug_report_status", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "bug_report_player_id_player_id_fk": { + "name": "bug_report_player_id_player_id_fk", + "tableFrom": "bug_report", + "tableTo": "player", + "columnsFrom": [ + "player_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.mail_digest": { + "name": "mail_digest", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "player_id": { + "name": "player_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "sent_at": { + "name": "sent_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "mail_digest_open": { + "name": "mail_digest_open", + "columns": [ + { + "expression": "sent_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "player_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "mail_digest_player_id_player_id_fk": { + "name": "mail_digest_player_id_player_id_fk", + "tableFrom": "mail_digest", + "tableTo": "player", + "columnsFrom": [ + "player_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.password_reset": { + "name": "password_reset", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "player_id": { + "name": "player_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "code_hash": { + "name": "code_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "via": { + "name": "via", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "used_at": { + "name": "used_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "password_reset_hash": { + "name": "password_reset_hash", + "columns": [ + { + "expression": "code_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "password_reset_player": { + "name": "password_reset_player", + "columns": [ + { + "expression": "player_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "password_reset_player_id_player_id_fk": { + "name": "password_reset_player_id_player_id_fk", + "tableFrom": "password_reset", + "tableTo": "player", + "columnsFrom": [ + "player_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.player_email": { + "name": "player_email", + "schema": "", + "columns": { + "player_id": { + "name": "player_id", + "type": "integer", + "primaryKey": true, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "verified_at": { + "name": "verified_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "verify_hash": { + "name": "verify_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "verify_expires_at": { + "name": "verify_expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "prefs": { + "name": "prefs", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "unsubscribe_token": { + "name": "unsubscribe_token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "last_digest_at": { + "name": "last_digest_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "player_email_unsub": { + "name": "player_email_unsub", + "columns": [ + { + "expression": "unsubscribe_token", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "player_email_player_id_player_id_fk": { + "name": "player_email_player_id_player_id_fk", + "tableFrom": "player_email", + "tableTo": "player", + "columnsFrom": [ + "player_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.push_subscription": { + "name": "push_subscription", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "player_id": { + "name": "player_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "endpoint": { + "name": "endpoint", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "p256dh": { + "name": "p256dh", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "auth": { + "name": "auth", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "prefs": { + "name": "prefs", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "push_subscription_endpoint": { + "name": "push_subscription_endpoint", + "columns": [ + { + "expression": "endpoint", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "push_subscription_player": { + "name": "push_subscription_player", + "columns": [ + { + "expression": "player_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "push_subscription_player_id_player_id_fk": { + "name": "push_subscription_player_id_player_id_fk", + "tableFrom": "push_subscription", + "tableTo": "player", + "columnsFrom": [ + "player_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.server_setting": { + "name": "server_setting", + "schema": "", + "columns": { + "key": { + "name": "key", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.world_event": { + "name": "world_event", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "outcome": { + "name": "outcome", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "season_id": { + "name": "season_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "col": { + "name": "col", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "row": { + "name": "row", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "target_base_id": { + "name": "target_base_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "units": { + "name": "units", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "initial_units": { + "name": "initial_units", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "data": { + "name": "data", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "starts_at": { + "name": "starts_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "active_at": { + "name": "active_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "ends_at": { + "name": "ends_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "winner_player_id": { + "name": "winner_player_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "ended_at": { + "name": "ended_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "world_event_status": { + "name": "world_event_status", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "ends_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "world_event_target": { + "name": "world_event_target", + "columns": [ + { + "expression": "target_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "world_event_winner_player_id_player_id_fk": { + "name": "world_event_winner_player_id_player_id_fk", + "tableFrom": "world_event", + "tableTo": "player", + "columnsFrom": [ + "winner_player_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.world_event_damage": { + "name": "world_event_damage", + "schema": "", + "columns": { + "event_id": { + "name": "event_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "player_id": { + "name": "player_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "hp": { + "name": "hp", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "loot": { + "name": "loot", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "attacks": { + "name": "attacks", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + } + }, + "indexes": { + "world_event_damage_pk": { + "name": "world_event_damage_pk", + "columns": [ + { + "expression": "event_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "player_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "world_event_damage_event_id_world_event_id_fk": { + "name": "world_event_damage_event_id_world_event_id_fk", + "tableFrom": "world_event_damage", + "tableTo": "world_event", + "columnsFrom": [ + "event_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "world_event_damage_player_id_player_id_fk": { + "name": "world_event_damage_player_id_player_id_fk", + "tableFrom": "world_event_damage", + "tableTo": "player", + "columnsFrom": [ + "player_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.admiral": { + "name": "admiral", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "player_id": { + "name": "player_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "base_id": { + "name": "base_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "xp": { + "name": "xp", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "spec1": { + "name": "spec1", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "spec2": { + "name": "spec2", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "stationed": { + "name": "stationed", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "mission_id": { + "name": "mission_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "wounded_until": { + "name": "wounded_until", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "captive_until": { + "name": "captive_until", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "battles": { + "name": "battles", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "wins": { + "name": "wins", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "admiral_player": { + "name": "admiral_player", + "columns": [ + { + "expression": "player_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "admiral_player_id_player_id_fk": { + "name": "admiral_player_id_player_id_fk", + "tableFrom": "admiral", + "tableTo": "player", + "columnsFrom": [ + "player_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "admiral_base_id_base_id_fk": { + "name": "admiral_base_id_base_id_fk", + "tableFrom": "admiral", + "tableTo": "base", + "columnsFrom": [ + "base_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.achievement_counter": { + "name": "achievement_counter", + "schema": "", + "columns": { + "player_id": { + "name": "player_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "counter": { + "name": "counter", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "achievement_counter_player_id_player_id_fk": { + "name": "achievement_counter_player_id_player_id_fk", + "tableFrom": "achievement_counter", + "tableTo": "player", + "columnsFrom": [ + "player_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "achievement_counter_player_id_counter_pk": { + "name": "achievement_counter_player_id_counter_pk", + "columns": [ + "player_id", + "counter" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.achievement_tier": { + "name": "achievement_tier", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "player_id": { + "name": "player_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "achievement_id": { + "name": "achievement_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "tier": { + "name": "tier", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "reward": { + "name": "reward", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "unlocked_at": { + "name": "unlocked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "claimed_at": { + "name": "claimed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "notified_at": { + "name": "notified_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "achievement_tier_unique": { + "name": "achievement_tier_unique", + "columns": [ + { + "expression": "player_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "achievement_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "tier", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "achievement_tier_notify": { + "name": "achievement_tier_notify", + "columns": [ + { + "expression": "notified_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "achievement_tier_player_id_player_id_fk": { + "name": "achievement_tier_player_id_player_id_fk", + "tableFrom": "achievement_tier", + "tableTo": "player", + "columnsFrom": [ + "player_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.weekly_goal": { + "name": "weekly_goal", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "player_id": { + "name": "player_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "week": { + "name": "week", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "slot": { + "name": "slot", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "param": { + "name": "param", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "target": { + "name": "target", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "progress": { + "name": "progress", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "reward": { + "name": "reward", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "bonus": { + "name": "bonus", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "claimed_at": { + "name": "claimed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "weekly_goal_slot": { + "name": "weekly_goal_slot", + "columns": [ + { + "expression": "player_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "week", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "slot", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "weekly_goal_open": { + "name": "weekly_goal_open", + "columns": [ + { + "expression": "player_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "claimed_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "weekly_goal_player_id_player_id_fk": { + "name": "weekly_goal_player_id_player_id_fk", + "tableFrom": "weekly_goal", + "tableTo": "player", + "columnsFrom": [ + "player_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.alliance_raid": { + "name": "alliance_raid", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "alliance_id": { + "name": "alliance_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "creator_player_id": { + "name": "creator_player_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "target_kind": { + "name": "target_kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "target_id": { + "name": "target_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "target_col": { + "name": "target_col", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "target_row": { + "name": "target_row", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "target_name": { + "name": "target_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "desired_arrive_at": { + "name": "desired_arrive_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "join_deadline": { + "name": "join_deadline", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "arrive_at": { + "name": "arrive_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "report_id": { + "name": "report_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "alliance_raid_alliance": { + "name": "alliance_raid_alliance", + "columns": [ + { + "expression": "alliance_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "alliance_raid_creator_player_id_player_id_fk": { + "name": "alliance_raid_creator_player_id_player_id_fk", + "tableFrom": "alliance_raid", + "tableTo": "player", + "columnsFrom": [ + "creator_player_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.alliance_raid_member": { + "name": "alliance_raid_member", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "raid_id": { + "name": "raid_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "player_id": { + "name": "player_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "mission_id": { + "name": "mission_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "joined_at": { + "name": "joined_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "alliance_raid_member_once": { + "name": "alliance_raid_member_once", + "columns": [ + { + "expression": "raid_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "player_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "alliance_raid_member_player": { + "name": "alliance_raid_member_player", + "columns": [ + { + "expression": "player_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "alliance_raid_member_raid_id_alliance_raid_id_fk": { + "name": "alliance_raid_member_raid_id_alliance_raid_id_fk", + "tableFrom": "alliance_raid_member", + "tableTo": "alliance_raid", + "columnsFrom": [ + "raid_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "alliance_raid_member_player_id_player_id_fk": { + "name": "alliance_raid_member_player_id_player_id_fk", + "tableFrom": "alliance_raid_member", + "tableTo": "player", + "columnsFrom": [ + "player_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.blockade": { + "name": "blockade", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "mission_id": { + "name": "mission_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "attacker_id": { + "name": "attacker_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "attacker_base_id": { + "name": "attacker_base_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "target_base_id": { + "name": "target_base_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "target_player_id": { + "name": "target_player_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "col": { + "name": "col", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "row": { + "name": "row", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "units": { + "name": "units", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "outcome": { + "name": "outcome", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "starts_at": { + "name": "starts_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "ends_at": { + "name": "ends_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "ended_at": { + "name": "ended_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "blockade_target": { + "name": "blockade_target", + "columns": [ + { + "expression": "target_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "blockade_mission": { + "name": "blockade_mission", + "columns": [ + { + "expression": "mission_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "blockade_attacker_id_player_id_fk": { + "name": "blockade_attacker_id_player_id_fk", + "tableFrom": "blockade", + "tableTo": "player", + "columnsFrom": [ + "attacker_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "blockade_target_base_id_base_id_fk": { + "name": "blockade_target_base_id_base_id_fk", + "tableFrom": "blockade", + "tableTo": "base", + "columnsFrom": [ + "target_base_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.convoy": { + "name": "convoy", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "delivery_id": { + "name": "delivery_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "mission_id": { + "name": "mission_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "sender_id": { + "name": "sender_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "recipient_id": { + "name": "recipient_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "recipient_base_id": { + "name": "recipient_base_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "from_col": { + "name": "from_col", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "from_row": { + "name": "from_row", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "to_col": { + "name": "to_col", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "to_row": { + "name": "to_row", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "cargo": { + "name": "cargo", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "escort": { + "name": "escort", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "escort_mission_id": { + "name": "escort_mission_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "cartel_at": { + "name": "cartel_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "events": { + "name": "events", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'underway'" + }, + "depart_at": { + "name": "depart_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "arrive_at": { + "name": "arrive_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "convoy_status": { + "name": "convoy_status", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "arrive_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "convoy_delivery": { + "name": "convoy_delivery", + "columns": [ + { + "expression": "delivery_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "convoy_mission": { + "name": "convoy_mission", + "columns": [ + { + "expression": "mission_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.minefield": { + "name": "minefield", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "owner_id": { + "name": "owner_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "base_id": { + "name": "base_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "col": { + "name": "col", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "row": { + "name": "row", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "strength": { + "name": "strength", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "max_strength": { + "name": "max_strength", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "minefield_expires": { + "name": "minefield_expires", + "columns": [ + { + "expression": "expires_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "minefield_field": { + "name": "minefield_field", + "columns": [ + { + "expression": "col", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "row", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "minefield_owner_id_player_id_fk": { + "name": "minefield_owner_id_player_id_fk", + "tableFrom": "minefield", + "tableTo": "player", + "columnsFrom": [ + "owner_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "minefield_base_id_base_id_fk": { + "name": "minefield_base_id_base_id_fk", + "tableFrom": "minefield", + "tableTo": "base", + "columnsFrom": [ + "base_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.minefield_known": { + "name": "minefield_known", + "schema": "", + "columns": { + "minefield_id": { + "name": "minefield_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "player_id": { + "name": "player_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "known_at": { + "name": "known_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "minefield_known_pk": { + "name": "minefield_known_pk", + "columns": [ + { + "expression": "minefield_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "player_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "minefield_known_minefield_id_minefield_id_fk": { + "name": "minefield_known_minefield_id_minefield_id_fk", + "tableFrom": "minefield_known", + "tableTo": "minefield", + "columnsFrom": [ + "minefield_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "minefield_known_player_id_player_id_fk": { + "name": "minefield_known_player_id_player_id_fk", + "tableFrom": "minefield_known", + "tableTo": "player", + "columnsFrom": [ + "player_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.field_score": { + "name": "field_score", + "schema": "", + "columns": { + "alliance_id": { + "name": "alliance_id", + "type": "integer", + "primaryKey": true, + "notNull": true + }, + "points": { + "name": "points", + "type": "real", + "primaryKey": false, + "notNull": true, + "default": 0 + } + }, + "indexes": {}, + "foreignKeys": { + "field_score_alliance_id_alliance_id_fk": { + "name": "field_score_alliance_id_alliance_id_fk", + "tableFrom": "field_score", + "tableTo": "alliance", + "columnsFrom": [ + "alliance_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.resource_field": { + "name": "resource_field", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "site_index": { + "name": "site_index", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "col": { + "name": "col", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "row": { + "name": "row", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "tier": { + "name": "tier", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "player_id": { + "name": "player_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "base_id": { + "name": "base_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "mission_id": { + "name": "mission_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "guard": { + "name": "guard", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "guard_at": { + "name": "guard_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "captured_at": { + "name": "captured_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_tick_at": { + "name": "last_tick_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "escort": { + "name": "escort", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "resource_field_site": { + "name": "resource_field_site", + "columns": [ + { + "expression": "site_index", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "resource_field_hex": { + "name": "resource_field_hex", + "columns": [ + { + "expression": "col", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "row", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "resource_field_owner": { + "name": "resource_field_owner", + "columns": [ + { + "expression": "player_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "resource_field_player_id_player_id_fk": { + "name": "resource_field_player_id_player_id_fk", + "tableFrom": "resource_field", + "tableTo": "player", + "columnsFrom": [ + "player_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "resource_field_base_id_base_id_fk": { + "name": "resource_field_base_id_base_id_fk", + "tableFrom": "resource_field", + "tableTo": "base", + "columnsFrom": [ + "base_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/packages/db/migrations/meta/_journal.json b/packages/db/migrations/meta/_journal.json index 0e676df..4ede8b2 100644 --- a/packages/db/migrations/meta/_journal.json +++ b/packages/db/migrations/meta/_journal.json @@ -113,6 +113,13 @@ "when": 1795735139270, "tag": "0015_expansion", "breakpoints": true + }, + { + "idx": 16, + "version": "7", + "when": 1795764897932, + "tag": "0016_felder2", + "breakpoints": true } ] } \ No newline at end of file diff --git a/packages/db/src/schema/fields.ts b/packages/db/src/schema/fields.ts index fa39f18..d169e0c 100644 --- a/packages/db/src/schema/fields.ts +++ b/packages/db/src/schema/fields.ts @@ -26,6 +26,8 @@ export const resourceField = pgTable("resource_field", { capturedAt: ts("captured_at"), /** Bis hierhin ist der Ertrag abgerechnet (Lieferzyklus). */ lastTickAt: ts("last_tick_at"), + /** Geleitabteilung aus der Besatzung (Counts): begleitet die Ertragskonvois, verteidigt das Feld nicht. */ + escort: jsonb("escort").notNull().default({}), createdAt: ts("created_at").notNull().defaultNow(), }, (t) => [uniqueIndex("resource_field_site").on(t.siteIndex), uniqueIndex("resource_field_hex").on(t.col, t.row), index("resource_field_owner").on(t.ownerId)]); diff --git a/packages/engine/src/achievement-defs.ts b/packages/engine/src/achievement-defs.ts index 2ddf579..499b956 100644 --- a/packages/engine/src/achievement-defs.ts +++ b/packages/engine/src/achievement-defs.ts @@ -1,7 +1,7 @@ // Erfolge und Wochenziele: reine Funktionen (keine Datenbank). Definitionen der Erfolge in balance.json // (Block achievements), Spielwoche (Montag 0:00 Uhr in der Spielzeitzone), Pool und Auswahl der Wochenziele, // Belohnungen. Die Datenbankseite steht in achievements.ts und weekly.ts. -import { mulberry32, type AchievementDef, type AchievementReward, type ResourceMap } from "@tidefront/game-core"; +import { allowedBases, expansionOf, maxFieldsFor, mulberry32, type AchievementDef, type AchievementReward, type ResourceMap } from "@tidefront/game-core"; import { balance } from "./context.ts"; import { addDays, dayKey, dayStartMs, resourcePackage, type PoolContext } from "./challenge-pool.ts"; @@ -86,6 +86,8 @@ export function nextWeekStartMs(ms: number): number { export interface WeeklyContext extends PoolContext { /** Mitglied einer Allianz mit mindestens einem weiteren Mitglied. */ allied: boolean; + /** Mehrere Häfen: Zahl der eigenen Häfen (fehlt: keine Gründungsziele). */ + bases?: number; } interface WeeklyKind { @@ -100,6 +102,16 @@ const fmt = (n: number) => n.toLocaleString("de-DE"); const canLand = (c: PoolContext) => lvl(c, "werft") >= 1 && lvl(c, "kaserne") >= 1; const canSail = (c: PoolContext) => lvl(c, "werft") >= 1 || lvl(c, "flugfeld") >= 1; const nestCap = (c: PoolContext) => Math.max(1, Math.min(5, 1 + Math.floor(c.stage / 3))); +/** Felder: Werft und mindestens ein erlaubtes Feld (Hafenkommandantur). */ +const canHoldField = (c: PoolContext) => lvl(c, "werft") >= 1 && maxFieldsFor(lvl(c, "hafenkommandantur"), balance) > 0; + +/** Mehrere Häfen: ein weiterer Hafen ist erlaubt und das Kolonieschiff baubar (Hafenkommandantur). */ +function canFound(c: WeeklyContext): boolean { + const x = expansionOf(balance); + if (!x || c.bases === undefined) return false; + const allowed = allowedBases({ buildings: c.levels } as Parameters[0], balance); + return c.bases < allowed && lvl(c, "hafenkommandantur") >= x.harborLevelForShip; +} function canSpy(c: PoolContext): boolean { const e = balance.espionage; @@ -173,10 +185,22 @@ export const WEEKLY_KINDS: Record = { spec: () => ({ param: null, target: 12 }), text: (n) => `Hole ${n} Tagesbefehle ab`, }, + // Felder: Zähler „feldertrag“ (Wert der eingelaufenen Ertragskonvois zum Richtpreis, fields-run.ts). + feldertrag: { + icon: "besetzen", + spec: (c) => (canHoldField(c) ? { param: null, target: round(5000 * (1 + c.stage / 5), 1000) } : null), + text: (n) => `Fahre Erträge von Rohstofffeldern im Wert von ${fmt(n)} ein (Richtpreis, Stahl = 1)`, + }, + // Mehrere Häfen: neuer Hafen in der Woche gegründet (aus den Häfen gelesen, weekly.ts). + gruendung: { + icon: "kolonieschiff", + spec: (c) => (canFound(c) ? { param: null, target: 1 } : null), + text: () => "Gründe mit einem Kolonieschiff einen neuen Hafen", + }, }; /** Wochenziele, deren Stand aus dem Zustand gelesen wird (beim Abruf). */ -export const WEEKLY_DERIVED = new Set(["tagesbefehle"]); +export const WEEKLY_DERIVED = new Set(["tagesbefehle", "gruendung"]); export function weeklyText(kind: string, target: number, param: string | null): string { return WEEKLY_KINDS[kind]?.text(target, param) ?? kind; diff --git a/packages/engine/src/fields-core.ts b/packages/engine/src/fields-core.ts index bf3f52a..80e390e 100644 --- a/packages/engine/src/fields-core.ts +++ b/packages/engine/src/fields-core.ts @@ -4,7 +4,7 @@ // ist spielerweit (höchste Hafenkommandantur aller Häfen). import { and, desc, eq, inArray, isNotNull, sql } from "drizzle-orm"; import { - fieldBaseYield, fieldsOf, fieldYield, fieldZones, maxFieldsFor, yieldFactor, + clampEscort, fieldBaseYield, fieldDefenders, fieldsOf, fieldYield, fieldZones, maxFieldsFor, yieldFactor, type Counts, type FieldsBalance, type ResourceMap, } from "@tidefront/game-core"; import { fieldSites, hexCenter, hexDistanceKm, type FieldSite } from "@tidefront/world"; @@ -14,6 +14,7 @@ import { basesOfPlayer, readBase, type BaseRow } from "./store.ts"; import { modifiersFor, modsOf } from "./modifiers.ts"; import { maxHarborLevelOf } from "./player-wide.ts"; import { relationsOf } from "./alliance-core.ts"; +import { fieldIncoming } from "./fields-radar.ts"; export const FIELD_TYPE = "besetzen"; export const HOUR_MS = 3600000; @@ -32,6 +33,8 @@ export interface FieldRow { guardAt: Date | null; capturedAt: Date | null; lastTickAt: Date | null; + /** Geleitabteilung aus der Besatzung (fields-escort.ts). */ + escort: unknown; createdAt: Date; } @@ -193,6 +196,7 @@ export async function fieldsView(engine: Engine, playerId: number, _baseId?: num const mine = await ownedBy(db, playerId); const rank = new Map(mine.map((m, i) => [m.id, i])); const next = await nextTickMs(db); + const incoming = await fieldIncoming(db, playerId, mine, nowMs); const relationOf = (r: FieldRow) => r.ownerId === null ? (guarded(r) ? "kartell" : "frei") : r.ownerId === playerId ? "own" : relations.get(r.ownerId) ?? "neutral"; const fields = rows.map((r) => { @@ -214,9 +218,17 @@ export async function fieldsView(engine: Engine, playerId: number, _baseId?: num const minePart = mine.map((m) => { const z = zones.get(m.id); const i = rank.get(m.id)!; + const all = m.missionId !== null ? garrison.get(m.missionId) ?? {} : {}; + const escort = clampEscort(all, (m.escort as Counts) ?? {}); return { id: m.id, col: m.col, row: m.row, kind: m.kind, tier: m.tier, missionId: m.missionId, - garrison: m.missionId !== null ? garrison.get(m.missionId) ?? {} : {}, + garrison: all, + /** Geleitabteilung (fährt mit den Ertragskonvois) und wer das Feld verteidigt (Besatzung ohne Geleit). */ + escort, + defenders: fieldDefenders(all, escort), + /** Vom Radar erfasste Angriffe (Ankunft) und eigene Verstärkungen unterwegs. */ + incoming: incoming.attacks.get(m.id) ?? [], + reinforcements: incoming.reinforcements.get(m.id) ?? [], factor: yieldFactor(i, balance), zoneBonus: !!z?.bonus, yieldPerHour: fieldYield(m.kind, m.tier, 1, i, !!z?.bonus, balance) as ResourceMap, upkeepPerHour: f.upkeepProviantPerHour[m.tier - 1] ?? 0, diff --git a/packages/engine/src/fields-escort.ts b/packages/engine/src/fields-escort.ts new file mode 100644 index 0000000..a520e60 --- /dev/null +++ b/packages/engine/src/fields-escort.ts @@ -0,0 +1,58 @@ +// Felder: Geleitabteilung (docs/REGELN-FELDER.md, Abschnitt Geleitschutz). Ein Teil der Besatzung begleitet die +// Ertragskonvois des Felds und kämpft bei Abfangversuchen (Kartell, Kriegsgegner) mit; er verteidigt das Feld nicht. +// Gespeichert in resource_field.escort; die Schiffe bleiben Teil der Besatzungsmission (returning), Verluste im +// Konvoikampf werden dort abgezogen. Eingehängt in naval-convoy.ts (liveEscort, fightEscort) und fields-run.ts. +import { and, eq } from "drizzle-orm"; +import { activeUnits, clampEscort, escortCheck, subtractCounts, type Counts } from "@tidefront/game-core"; +import { tables, type DbOrTx, type Tx } from "@tidefront/db"; +import { balance, GameError, type Engine } from "./context.ts"; +import { runCommand } from "./commands.ts"; +import { fieldById } from "./fields-core.ts"; + +/** Aktuelle Geleitabteilung einer Besatzungsmission (leer, wenn das Feld nicht mehr gehalten wird). */ +export async function fieldEscortOf(db: DbOrTx, missionId: number | null): Promise { + if (missionId === null) return {}; + const [f] = await db.select({ escort: tables.resourceField.escort, ownerId: tables.resourceField.ownerId }) + .from(tables.resourceField).where(eq(tables.resourceField.missionId, missionId)); + if (!f || f.ownerId === null) return {}; + const [m] = await db.select({ status: tables.mission.status, returning: tables.mission.returning }).from(tables.mission).where(eq(tables.mission.id, missionId)); + if (!m || m.status !== "stationed") return {}; + return clampEscort(activeUnits((m.returning as Counts | null) ?? {}), (f.escort as Counts) ?? {}); +} + +/** Verluste der Geleitabteilung im Konvoikampf: aus Besatzung und Geleit streichen. */ +export async function fieldEscortLosses(tx: Tx, missionId: number | null, before: Counts, after: Counts): Promise { + if (missionId === null) return; + const lost = subtractCounts(before, after); + if (Object.keys(lost).length === 0) return; + const [m] = await tx.select().from(tables.mission).where(eq(tables.mission.id, missionId)).for("update"); + if (!m || m.status !== "stationed") return; + const garrison = subtractCounts(activeUnits((m.returning as Counts | null) ?? {}), lost); + await tx.update(tables.mission).set({ returning: garrison }).where(eq(tables.mission.id, m.id)); + const [f] = await tx.select({ id: tables.resourceField.id, escort: tables.resourceField.escort }).from(tables.resourceField) + .where(eq(tables.resourceField.missionId, missionId)); + if (f) { + const escort = clampEscort(garrison, subtractCounts((f.escort as Counts) ?? {}, lost)); + await tx.update(tables.resourceField).set({ escort }).where(eq(tables.resourceField.id, f.id)); + } +} + +/** + * Geleitabteilung eines eigenen Felds festlegen (leer = aufheben). Gilt ab dem nächsten Ertragskonvoi. + * Codes: no_field, field_no_garrison, field_escort_invalid, field_escort_too_large. + */ +export function setFieldEscort(engine: Engine, playerId: number, key: string, fieldId: number, units: Counts) { + return runCommand<{ ok: true; escort: Counts }>(engine, playerId, key, "fieldEscort", async (ctx) => { + const field = await fieldById(ctx.tx, fieldId, true); + if (!field || field.ownerId !== playerId) throw new GameError("no_field"); + const [m] = field.missionId !== null + ? await ctx.tx.select().from(tables.mission).where(and(eq(tables.mission.id, field.missionId), eq(tables.mission.status, "stationed"))) + : []; + if (!m) throw new GameError("field_no_garrison"); + const r = escortCheck(activeUnits((m.returning as Counts | null) ?? {}), units, balance); + if (!r.ok) throw new GameError(r.code); + await ctx.tx.update(tables.resourceField).set({ escort: r.escort }).where(eq(tables.resourceField.id, field.id)); + ctx.notify.push([[playerId], "missions"]); + return { ok: true as const, escort: r.escort }; + }); +} diff --git a/packages/engine/src/fields-missions.ts b/packages/engine/src/fields-missions.ts index a03ffec..43f314e 100644 --- a/packages/engine/src/fields-missions.ts +++ b/packages/engine/src/fields-missions.ts @@ -4,7 +4,7 @@ // (launchMission), views.ts (missionPreview) und handlers.ts (missionArrive). Regeln: docs/REGELN-FELDER.md. import { eq } from "drizzle-orm"; import { - activeUnits, garrisonCheck, guardDefender, resolveBattle, splitGarrison, strandTroops, + activeUnits, addCounts, clampEscort, fieldDefenders, garrisonCheck, guardDefender, resolveBattle, splitGarrison, strandTroops, type AttackerInput, type Counts, type DefenderInput, type Mission, } from "@tidefront/game-core"; import { hexDistanceKm } from "@tidefront/world"; @@ -22,6 +22,8 @@ import { } from "./naval-common.ts"; import { FIELD_TYPE, HOUR_MS, fieldById, fieldName, garrisonMods, guarded, maxFieldsOfPlayer, ownedBy, rules, type FieldRow } from "./fields-core.ts"; import { settleField } from "./fields-run.ts"; +import { checkReinforce, reinforceArrive } from "./fields-reinforce.ts"; +import { scheduleFieldWarning } from "./fields-radar.ts"; export interface FieldInput { type: string; @@ -31,15 +33,20 @@ export interface FieldInput { stayAll?: boolean; } -/** Prüfungen und Planung. Codes: no_field, bad_type, own_field, field_limit, field_ships_only, garrison_too_weak, ally, pact … */ +/** + * Prüfungen und Planung. Besetzen gegen ein eigenes Feld ist eine Verstärkung der Besatzung (fields-reinforce.ts). + * Codes: no_field, bad_type, field_limit, field_ships_only, field_no_garrison, garrison_too_weak, ally, pact … + */ async function planField(db: DbOrTx, playerId: number, own: BaseRow, input: FieldInput, nowMs: number) { const f = rules(); if (!f) throw new GameError("bad_type"); const field = await fieldById(db, input.fieldId); if (!field) throw new GameError("no_field"); let targetProtection; - if (input.type === FIELD_TYPE) { - if (field.ownerId === playerId) throw new GameError("own_field"); + const reinforce = input.type === FIELD_TYPE && field.ownerId === playerId; + if (reinforce) { + await checkReinforce(db, field, input.units); + } else if (input.type === FIELD_TYPE) { const g = garrisonCheck(activeCounts(input.units), balance); if (!g.ok) throw new GameError(g.code); if ((await ownedBy(db, playerId)).length >= (await maxFieldsOfPlayer(db, playerId, own))) throw new GameError("field_limit"); @@ -55,16 +62,20 @@ async function planField(db: DbOrTx, playerId: number, own: BaseRow, input: Fiel type: input.type as Mission["type"], baseType: input.type === FIELD_TYPE ? "ueberfall" : "aufklaerung", units: input.units, col: field.col, row: field.row, activeMissions: await activeMissionCount(db, own.id), mods: await modsOf(db, own, nowMs), targetProtection, }, nowMs); - return { r, field }; + return { r, field, reinforce }; } /** launchMission mit fieldId (Hafen aus dem Kommando-Kontext, bereits gesperrt). */ export async function launchField(tx: Tx, playerId: number, own: BaseRow, input: FieldInput, nowMs: number, notify: Notes) { - const { r, field } = await planField(tx, playerId, own, input, nowMs); + const { r, field, reinforce } = await planField(tx, playerId, own, input, nowMs); if (!r.ok) return r; await saveBase(tx, own.id, r.base); - const plan = input.type === FIELD_TYPE ? { ...r.mission, stayAll: !!input.stayAll } : r.mission; + const plan = reinforce ? { ...r.mission, reinforce: true } : input.type === FIELD_TYPE ? { ...r.mission, stayAll: !!input.stayAll } : r.mission; const missionId = await insertMission(tx, { playerId, baseId: own.id, targetKind: "field", targetId: field.id, col: field.col, row: field.row, plan }); + // Radar-Vorwarnung für den Besitzer eines angegriffenen Felds (fields-radar.ts). + if (!reinforce && input.type === FIELD_TYPE && field.ownerId !== null) { + await scheduleFieldWarning(tx, missionId, field, r.mission.arriveAtMs, nowMs, r.mission.warningFactor ?? 1); + } notify.push([[playerId], "base"], [[playerId], "missions"]); return { ok: true as const, missionId, arriveAtMs: r.mission.arriveAtMs }; } @@ -74,12 +85,12 @@ export async function previewField(db: DbOrTx, playerId: number, own: BaseRow, i const field = await fieldById(db, input.fieldId); const distanceKm = field ? hexDistanceKm(own, field) : 0; try { - const { r } = await planField(db, playerId, own, input, nowMs); + const { r, reinforce } = await planField(db, playerId, own, input, nowMs); if (!r.ok) return { ok: false as const, code: r.code, distanceKm }; const m = r.mission; return { ok: true as const, distanceKm: m.distanceKm, travelSeconds: m.travelSeconds, fuelCost: m.fuelCost, arriveAtMs: m.arriveAtMs, - returnAtMs: m.returnAtMs, target: { kind: "field", own: false }, intercept: null, + returnAtMs: m.returnAtMs, target: { kind: "field", own: reinforce }, intercept: null, weather: field ? missionWeather(own.col, own.row, field.col, field.row, nowMs) : null, weatherFactor: m.weather?.shipFactor ?? 1, }; } catch (err) { @@ -104,7 +115,7 @@ export async function endGarrison(tx: Tx, missionId: number | null, survivors: C export async function releaseField(tx: Tx, f: FieldRow, due: number, guard: Counts | null): Promise { const r = rules()!; await tx.update(tables.resourceField).set({ - ownerId: null, baseId: null, missionId: null, capturedAt: null, lastTickAt: null, + ownerId: null, baseId: null, missionId: null, capturedAt: null, lastTickAt: null, escort: {}, guard: guard ?? {}, guardAt: guard ? null : new Date(due + r.guardRespawnHours * HOUR_MS), }).where(eq(tables.resourceField.id, f.id)); } @@ -144,7 +155,10 @@ export async function fieldArrive(tx: Tx, m: MissionRowLike, plan: Mission, orig } const name = fieldName(field); const garrison = field.missionId !== null ? (await tx.select({ returning: tables.mission.returning }).from(tables.mission).where(eq(tables.mission.id, field.missionId)))[0] : undefined; - const garrisonUnits = activeUnits((garrison?.returning as Counts | null) ?? {}); + const garrisonAll = activeUnits((garrison?.returning as Counts | null) ?? {}); + // Die Geleitabteilung fährt mit den Ertragskonvois und verteidigt das Feld nicht (fields-escort.ts). + const escort = field.ownerId !== null ? clampEscort(garrisonAll, (field.escort as Counts) ?? {}) : {}; + const garrisonUnits = fieldDefenders(garrisonAll, escort); const ownerName = field.ownerId !== null ? await playerName(tx, field.ownerId) : null; if (m.type === "aufklaerung") { const reportId = await storeNavalReport(tx, { @@ -154,6 +168,11 @@ export async function fieldArrive(tx: Tx, m: MissionRowLike, plan: Mission, orig await sendHome(tx, m, plan, units, {}, reportId, due); return; } + // Verstärkung (oder Besetzen-Verband erreicht ein inzwischen eigenes Feld mit Besatzung). + if ((plan as { reinforce?: boolean }).reinforce || (field.ownerId === pid && garrison)) { + await reinforceArrive(tx, m, plan, field, due, notify, push); + return; + } // Besetzen: Ziel noch angreifbar? const refused = field.ownerId === pid ? "own_field" : field.ownerId !== null ? await diplomacyBlock(tx, pid, field.ownerId, due) : null; if (refused || !hasShips(units)) { @@ -186,12 +205,12 @@ export async function fieldArrive(tx: Tx, m: MissionRowLike, plan: Mission, orig const prevOwner = field.ownerId; let outcome: "captured" | "cleared" | "held" | "limit" = "held"; if (destroyed) { - if (prevOwner !== null) await endGarrison(tx, field.missionId, {}, due); + if (prevOwner !== null) await endGarrison(tx, field.missionId, escort, due); // Geleitabteilung war unterwegs und kehrt heim const split = splitGarrison(survivors, !!(plan as { stayAll?: boolean }).stayAll, balance); const limit = origin ? await maxFieldsOfPlayer(tx, pid, origin) : 0; if (split && origin && (await ownedBy(tx, pid)).length < limit) { await tx.update(tables.resourceField).set({ - ownerId: pid, baseId: origin.id, missionId: m.id, guard: {}, guardAt: null, capturedAt: new Date(due), lastTickAt: new Date(due), + ownerId: pid, baseId: origin.id, missionId: m.id, guard: {}, guardAt: null, capturedAt: new Date(due), lastTickAt: new Date(due), escort: {}, }).where(eq(tables.resourceField.id, field.id)); await stationGarrison(tx, m, plan, split.garrison, split.rest, due); await recordAchievement(tx, pid, "felder", 1, { atMs: due }); // Erfolg „Landnahme“ @@ -201,7 +220,7 @@ export async function fieldArrive(tx: Tx, m: MissionRowLike, plan: Mission, orig outcome = split ? "limit" : "cleared"; } } else if (prevOwner !== null) { - await tx.update(tables.mission).set({ returning: defenderLeft }).where(eq(tables.mission.id, field.missionId!)); + await tx.update(tables.mission).set({ returning: addCounts(defenderLeft, escort) }).where(eq(tables.mission.id, field.missionId!)); } else { await tx.update(tables.resourceField).set({ guard: defenderLeft }).where(eq(tables.resourceField.id, field.id)); } diff --git a/packages/engine/src/fields-radar.ts b/packages/engine/src/fields-radar.ts new file mode 100644 index 0000000..5b58db5 --- /dev/null +++ b/packages/engine/src/fields-radar.ts @@ -0,0 +1,106 @@ +// Felder: Radar-Vorwarnung bei Angriffen anderer Spieler auf ein besetztes Feld (docs/REGELN-FELDER.md, Angriffe). +// Wie bei Häfen (event-notices.ts attackWarning, radar.ts): fällig zu Ankunft − Vorwarnzeit; die Vorwarnzeit ist +// radarWarningFactor × Vorwarnzeit des Heimathafens des Felds (Radar mit Strom, Sabotage, Nebel, Tarnung des Angreifers). +// Einmal erkannt bleibt erkannt (plan.detectedAtMs). Push und Systemnachricht an den Besitzer. +import { and, eq, inArray } from "drizzle-orm"; +import { fieldWarningMinutes, radarWarningMinutes, settle } from "@tidefront/game-core"; +import { tables, type DbOrTx, type Tx } from "@tidefront/db"; +import { balance } from "./context.ts"; +import type { HandlerResult } from "./events.ts"; +import { readBase, scheduleEvent, type BaseRow } from "./store.ts"; +import { modsOf } from "./modifiers.ts"; +import { systemMessage } from "./alliance-core.ts"; +import { detectedAtOf, detectIncoming, isDetected, markDetected, warnFactor } from "./radar.ts"; +import { RADAR_RECHECK_MS } from "./event-notices.ts"; +import { fmtClock, playerName, type Notes } from "./naval-common.ts"; +import { FIELD_TYPE, fieldById, fieldName, type FieldRow } from "./fields-core.ts"; + +/** Vorwarnzeit (Minuten, ohne Tarnung) für Felder des Hafens `b` zum Zeitpunkt `atMs`. */ +export async function fieldWarnMinutes(db: DbOrTx, b: BaseRow, atMs: number): Promise { + const mods = await modsOf(db, b, atMs); + return fieldWarningMinutes(radarWarningMinutes(settle(b.state, atMs, balance, mods), balance, mods), balance); +} + +/** Beim Auslaufen eines Angriffs auf ein fremdes besetztes Feld: Vorwarnung planen. */ +export async function scheduleFieldWarning(tx: Tx, missionId: number, field: FieldRow, arriveAtMs: number, nowMs: number, warningFactor = 1): Promise { + if (field.ownerId === null || field.baseId === null) return; + const b = await readBase(tx, field.baseId); + if (!b) return; + const warnMs = (await fieldWarnMinutes(tx, b, nowMs)) * warningFactor * 60000; + await scheduleEvent(tx, "field_warning", Math.max(nowMs, arriveAtMs - warnMs), { missionId }, field.baseId); +} + +const minutesText = (ms: number) => { + const min = Math.max(1, Math.round(ms / 60000)); + return min >= 120 ? `${Math.floor(min / 60)} Std. ${min % 60} Min.` : `${min} Min.`; +}; + +/** game_event field_warning: Angriff auf ein Feld erkannt (sonst neu planen, solange der Verband unterwegs ist). */ +export async function fieldWarning(tx: Tx, payload: Record, due: number): Promise { + const none: HandlerResult = { notify: [] }; + const [m] = await tx.select().from(tables.mission).where(eq(tables.mission.id, Number(payload.missionId))); + if (!m || m.status !== "outbound" || m.targetKind !== "field" || m.targetId === null || m.type !== FIELD_TYPE) return none; + const f = await fieldById(tx, m.targetId); + if (!f || f.ownerId === null || f.ownerId === m.playerId || f.baseId === null) return none; + const b = await readBase(tx, f.baseId); + if (!b) return none; + if (detectedAtOf(m.plan) === null) { + const warn = await fieldWarnMinutes(tx, b, due); + if (!isDetected(m, due, warn)) { + const next = Math.min(m.arriveAt.getTime() - warn * warnFactor(m.plan) * 60000, due + RADAR_RECHECK_MS); + if (next < m.arriveAt.getTime()) await scheduleEvent(tx, "field_warning", Math.max(next, due + 1), { missionId: m.id }, b.id); + return none; + } + await markDetected(tx, [m.id], due); + } + const attacker = m.playerId !== null ? await playerName(tx, m.playerId) : "Unbekannt"; + const arrive = m.arriveAt.getTime(); + const left = minutesText(arrive - due); + const name = fieldName(f); + const notify: Notes = [[[f.ownerId], "missions"]]; + await systemMessage(tx, notify, [f.ownerId], `Angriff auf ${name} erkannt`, + `Das Radar von ${b.name} meldet einen Verband von ${attacker} auf dem Weg zu deinem Feld ${name}. Ankunft in ${left} ` + + `(${fmtClock(arrive)} Uhr). Deine Besatzung verteidigt; du kannst sie verstärken oder zurückrufen.`); + return { + notify, + push: [{ playerId: f.ownerId, notice: { + kind: "attack", url: "/?tab=truppen", tag: `field-attack-${m.id}`, title: `Angriff auf ${name} erkannt`, + body: `${attacker} greift dein Feld an. Ankunft in ${left} (${fmtClock(arrive)} Uhr).`, + facts: [["Angreifer", attacker], ["Ziel", name], ["Ankunft in", left], ["Ankunft", `${fmtClock(arrive)} Uhr`]], + } }], + }; +} + +/** + * Lesemodell „Meine Felder“: erkannte Angriffe auf eigene Felder (Feld-ID → Ankünfte) und eigene Verstärkungen + * unterwegs. Angreifer bleiben bis zum Kampf unbekannt (wie bei Häfen). + */ +export async function fieldIncoming(db: DbOrTx, playerId: number, mine: FieldRow[], nowMs: number) { + const attacks = new Map(); + const reinforcements = new Map }[]>(); + if (mine.length === 0) return { attacks, reinforcements }; + const rows = await db.select().from(tables.mission).where(and( + eq(tables.mission.targetKind, "field"), + inArray(tables.mission.targetId, mine.map((f) => f.id)), + eq(tables.mission.status, "outbound"), + eq(tables.mission.type, FIELD_TYPE), + )); + const warnByBase = new Map(); + for (const f of mine) { + if (f.baseId === null || warnByBase.has(f.baseId)) continue; + const b = await readBase(db, f.baseId); + warnByBase.set(f.baseId, b ? await fieldWarnMinutes(db, b, nowMs) : 0); + } + for (const f of mine) { + const here = rows.filter((m) => m.targetId === f.id); + for (const m of here.filter((x) => x.playerId === playerId)) { + const list = reinforcements.get(f.id) ?? []; + list.push({ arriveAtMs: m.arriveAt.getTime(), units: (m.plan as { units: Record }).units }); + reinforcements.set(f.id, list); + } + const hostile = here.filter((x) => x.playerId !== playerId); + const seen = await detectIncoming(db, hostile, nowMs, warnByBase.get(f.baseId ?? -1) ?? 0); + if (seen.length > 0) attacks.set(f.id, seen.map((m) => ({ arriveAtMs: m.arriveAt.getTime() })).sort((a, b) => a.arriveAtMs - b.arriveAtMs)); + } + return { attacks, reinforcements }; +} diff --git a/packages/engine/src/fields-reinforce.ts b/packages/engine/src/fields-reinforce.ts new file mode 100644 index 0000000..c4bd720 --- /dev/null +++ b/packages/engine/src/fields-reinforce.ts @@ -0,0 +1,78 @@ +// Felder: Verstärkung einer Besatzung (docs/REGELN-FELDER.md, Einnehmen). „Besetzen“ gegen ein eigenes Feld mit +// stehender Besatzung schickt Schiffe ohne Kampf zur Besatzung: bei Ankunft werden sie ihr hinzugefügt (kein Rückruf +// nötig). Aus einem anderen eigenen Hafen wechseln sie dabei in den Hafen des Felds (Veteranen gewichtet gemischt wie +// bei der Verlegung, unitsAway wandert mit). Ist das Feld bei Ankunft nicht mehr eigen, kehrt der Verband heim. +import { eq } from "drizzle-orm"; +import { activeUnits, addCounts, mergeVeterancy, returnMission, settle, type Counts, type Mission } from "@tidefront/game-core"; +import { tables, type DbOrTx, type Tx } from "@tidefront/db"; +import { balance, GameError, type NoticeJob } from "./context.ts"; +import { lockBases, saveBase } from "./store.ts"; +import { modsOf } from "./modifiers.ts"; +import { activeCounts, hasShips, pushNotice, sendHome, storeNavalReport, type MissionRowLike, type Notes } from "./naval-common.ts"; +import { fieldName, type FieldRow } from "./fields-core.ts"; + +/** Stehende Besatzungsmission eines Felds oder null. */ +export async function stationedGarrison(db: DbOrTx, f: FieldRow, lock = false) { + if (f.missionId === null) return null; + const q = db.select().from(tables.mission).where(eq(tables.mission.id, f.missionId)); + const [m] = lock ? await q.for("update") : await q; + return m && m.status === "stationed" ? m : null; +} + +/** Prüfung beim Auslaufen einer Verstärkung. Codes: empty_fleet, field_ships_only, field_no_garrison. */ +export async function checkReinforce(db: DbOrTx, f: FieldRow, units: Counts): Promise { + const ships = activeCounts(units); + if (Object.keys(ships).length === 0) throw new GameError("empty_fleet"); + if (Object.keys(ships).some((id) => balance.units[id]?.branch !== "see")) throw new GameError("field_ships_only"); + if (!(await stationedGarrison(db, f))) throw new GameError("field_no_garrison"); +} + +/** Ankunft einer Verstärkung (auch: Besetzen-Verband erreicht ein inzwischen eigenes Feld). */ +export async function reinforceArrive(tx: Tx, m: MissionRowLike, plan: Mission, field: FieldRow, due: number, notify: Notes, push: NoticeJob[]): Promise { + const pid = m.playerId!; + const units = activeCounts(plan.units); + const name = fieldName(field); + const g = field.ownerId === pid ? await stationedGarrison(tx, field, true) : null; + if (!g || g.baseId === null || m.baseId === null || !hasShips(units)) { + const reportId = await storeNavalReport(tx, { + kind: "feld", title: `Verstärkung für ${name} kehrt um`, attackerPlayerId: pid, defenderPlayerId: null, attackerBaseId: m.baseId, atMs: due, + report: { field: { id: field.id, kind: field.kind, tier: field.tier, refused: "field_lost" } }, + }); + await sendHome(tx, m, plan, units, {}, reportId, due); + push.push(pushNotice(pid, "report", `Verstärkung für ${name} kehrt um`, "Das Feld wird nicht mehr von dir gehalten.", "berichte")); + notify.push([[pid], "reports"], [[pid], "missions"]); + return; + } + const gPlan = g.plan as Mission; + // Ausgesandt laut gespeichertem Plan (Minenverluste unterwegs stecken nur in plan.units des Ablaufs). + const [orig] = await tx.select({ plan: tables.mission.plan }).from(tables.mission).where(eq(tables.mission.id, m.id)); + const sent = activeCounts(((orig?.plan as Mission | undefined) ?? plan).units); + let onBooks = sent; // was die Besatzungsmission künftig als ausgesandt führt + if (m.baseId !== g.baseId) { + onBooks = units; + // Wechsel in den Hafen des Felds: Ausgangshafen gibt die Einheiten ab, Zielhafen führt sie als unterwegs. + const bases = await lockBases(tx, [m.baseId, g.baseId]); + const from = bases.get(m.baseId); + const to = bases.get(g.baseId); + if (from && to) { + await saveBase(tx, from.id, returnMission(from.state, sent, {}, {}, due, balance, await modsOf(tx, from, due))); + const next = settle(to.state, due, balance, await modsOf(tx, to, due)); + const vet = mergeVeterancy(next, from.state.veterancy, units); + if (vet) next.veterancy = vet; + else delete next.veterancy; + next.unitsAway = addCounts(next.unitsAway, units); + await saveBase(tx, to.id, next); + } + } + // Gleicher Hafen: die Einheiten sind dort schon als unterwegs geführt; sie kehren mit der Besatzung heim. + const garrison = addCounts(activeUnits((g.returning as Counts | null) ?? {}), units); + await tx.update(tables.mission).set({ plan: { ...gPlan, units: addCounts(gPlan.units, onBooks) }, returning: garrison }).where(eq(tables.mission.id, g.id)); + const reportId = await storeNavalReport(tx, { + kind: "feld", title: `Verstärkung auf ${name} eingetroffen`, attackerPlayerId: pid, defenderPlayerId: null, attackerBaseId: m.baseId, + defenderBaseId: g.baseId, atMs: due, + report: { field: { id: field.id, kind: field.kind, tier: field.tier, outcome: "reinforced", units, garrison } }, + }); + await tx.update(tables.mission).set({ status: "done", returning: {}, cargoHome: {}, reportId, returnAt: new Date(due) }).where(eq(tables.mission.id, m.id)); + push.push(pushNotice(pid, "report", `Verstärkung auf ${name} eingetroffen`, "Die Schiffe gehören jetzt zur Besatzung.", "berichte")); + notify.push([[pid], "reports"], [[pid], "missions"], [[pid], "base"]); +} diff --git a/packages/engine/src/fields-run.ts b/packages/engine/src/fields-run.ts index 3a1122e..ebc2aa1 100644 --- a/packages/engine/src/fields-run.ts +++ b/packages/engine/src/fields-run.ts @@ -1,10 +1,11 @@ // Felder: Ablauf (docs/REGELN-FELDER.md). Globales field_tick alle deliveryHours: Ertrag je besetztem Feld (Rang, // Zonenbonus) als Konvoi zum Heimathafen (abfangbar, Blockade hält zurück), Unterhalt in Proviant, Allianzpunkte, // Würfel für Kartellangriffe, neue Wachen und Felder. field_delivery: Konvoi läuft ein. field_raid: Kartell greift an. +// field_warning: Radar-Vorwarnung bei Spielerangriffen (fields-radar.ts). import { and, eq, isNull, lte, sql } from "drizzle-orm"; import { - activeUnits, blockadeOf, cartelFieldRaid, deliverCargo, fieldUpkeep, fieldYield, resolveBattle, settle, strandTroops, - type Counts, + activeUnits, addCounts, blockadeOf, cargoValue, cartelFieldRaid, clampEscort, deliverCargo, fieldDefenders, fieldUpkeep, fieldYield, + resolveBattle, settle, strandTroops, type Counts, } from "@tidefront/game-core"; import { hexDistanceKm } from "@tidefront/world"; import { tables, type Db, type Tx } from "@tidefront/db"; @@ -19,6 +20,9 @@ import { activeBlockade, createConvoy } from "./naval.ts"; import { pushNotice, storeNavalReport, type Notes } from "./naval-common.ts"; import { HOUR_MS, allianceMap, garrisonMods, fieldById, fieldName, ownedBy, rules, spawnFields, zonesOf, type FieldRow } from "./fields-core.ts"; import { endGarrison, releaseField } from "./fields-missions.ts"; +import { fieldEscortOf } from "./fields-escort.ts"; +import { fieldWarning } from "./fields-radar.ts"; +import { recordAchievement } from "./achievements.ts"; const none = (): HandlerResult => ({ notify: [] }); @@ -49,8 +53,11 @@ export async function settleField(tx: Tx, f: FieldRow, due: number, notify: Note const cargo = fieldYield(f.kind, f.tier, hours, Math.max(0, rank), zone, balance); if (Object.keys(cargo).length > 0) { const arrive = due + Math.ceil((hexDistanceKm(f, b) / r.convoySpeedKmh) * HOUR_MS); + // Geleitabteilung der Besatzung fährt mit (missionId = Besatzung; liveEscort liest ihren aktuellen Bestand). + const escort = await fieldEscortOf(tx, f.missionId); const convoyId = await createConvoy(tx, { kind: "feld", senderId: null, recipientId: f.ownerId, recipientBaseId: b.id, from: f, to: b, cargo, departMs: due, arriveMs: arrive, + ...(f.missionId !== null ? { missionId: f.missionId } : {}), escort, }); await scheduleEvent(tx, "field_delivery", arrive, { convoyId }, b.id); } @@ -119,6 +126,8 @@ async function fieldDelivery(tx: Tx, payload: Record, due: numb await tx.update(tables.convoy).set({ status: "arrived" }).where(eq(tables.convoy.id, c.id)); const b = await lockBase(tx, c.recipientBaseId); if (b) await saveBase(tx, b.id, deliverCargo(b.state, c.cargo as Counts, due, balance, await modsOf(tx, b, due))); + // Wochenziel „Erträge von Feldern einfahren“ (Wert zum Richtpreis, Stahl-Äquivalent); kein Erfolg. + if (b) await recordAchievement(tx, c.recipientId, "feldertrag", cargoValue(c.cargo as Counts, balance), { atMs: due }); return { notify: [[[c.recipientId], "base"], [[c.recipientId], "market"]] }; } @@ -130,7 +139,9 @@ async function fieldRaid(tx: Tx, payload: Record, due: number): if (!m || m.status !== "stationed") return none(); const owner = f.ownerId; const units = activeUnits(payload.units as Counts); - const garrison = activeUnits((m.returning as Counts | null) ?? {}); + const all = activeUnits((m.returning as Counts | null) ?? {}); + const escort = clampEscort(all, (f.escort as Counts) ?? {}); // Geleitabteilung ist mit den Konvois unterwegs + const garrison = fieldDefenders(all, escort); const seed = randomSeed(); const res = resolveBattle({ units }, { units: garrison, defenses: {}, modifiers: await garrisonMods(tx, f, due) }, balance, seed, battleWeather(f.col, f.row, due)); if (!res.ok) throw new Error(`battle: ${res.code}`); @@ -138,10 +149,10 @@ async function fieldRaid(tx: Tx, payload: Record, due: number): const name = fieldName(f); const notify: Notes = [[null, "map"], [[owner], "reports"], [[owner], "missions"]]; if (destroyed) { - await endGarrison(tx, m.id, {}, due); + await endGarrison(tx, m.id, escort, due); // die Geleitabteilung war unterwegs und kehrt heim await releaseField(tx, f, due, { ...(rules()!.guard[f.tier - 1] ?? {}) }); } else { - await tx.update(tables.mission).set({ returning: activeUnits(report.defender.final) }).where(eq(tables.mission.id, m.id)); + await tx.update(tables.mission).set({ returning: addCounts(activeUnits(report.defender.final), escort) }).where(eq(tables.mission.id, m.id)); } if ((report.wreck.stahl ?? 0) + (report.wreck.elektronik ?? 0) > 0) { await tx.insert(tables.wreck).values({ col: f.col, row: f.row, stahl: report.wreck.stahl ?? 0, elektronik: report.wreck.elektronik ?? 0, createdAt: new Date(due) }); @@ -159,6 +170,7 @@ export const FIELD_HANDLERS: Record fieldTick(tx, due), field_delivery: (tx, ev, due) => fieldDelivery(tx, ev.payload, due), field_raid: (tx, ev, due) => fieldRaid(tx, ev.payload, due), + field_warning: (tx, ev, due) => fieldWarning(tx, ev.payload, due), }; /** Worker (alle 10 Minuten, auch nach Saisonwechsel): Felder anlegen und field_tick planen, falls keines ansteht. */ diff --git a/packages/engine/src/index.ts b/packages/engine/src/index.ts index 944a61c..f91dc68 100644 --- a/packages/engine/src/index.ts +++ b/packages/engine/src/index.ts @@ -70,4 +70,5 @@ export { navalView, navalRouteMines, liftBlockade, clearNaval, NAVAL_TYPES } fro // Felder: Rohstofffelder einnehmen export { fieldsView, spawnFields, FIELD_KIND_TEXT } from "./fields-core.ts"; export { fieldRecall } from "./fields-missions.ts"; +export { setFieldEscort } from "./fields-escort.ts"; export { ensureFieldPlanner, clearFields } from "./fields-run.ts"; diff --git a/packages/engine/src/naval-convoy.ts b/packages/engine/src/naval-convoy.ts index 4832d23..08e20bc 100644 --- a/packages/engine/src/naval-convoy.ts +++ b/packages/engine/src/naval-convoy.ts @@ -35,6 +35,7 @@ import { activeCounts, hasShips, insertMission, planNaval, playerName, pushNotice, sendHome, storeNavalReport, type MissionRowLike, type NavalInput, type Notes, } from "./naval-common.ts"; +import { fieldEscortLosses, fieldEscortOf } from "./fields-escort.ts"; // Felder: Geleitabteilung export interface ConvoyRow { id: number; @@ -111,9 +112,13 @@ async function lockConvoy(tx: Tx, where: { id?: number; missionId?: number; deli return (c as ConvoyRow) ?? null; } -/** Geleit, das wirklich mitfährt: beim Transport der Verband selbst, beim Handel nur, solange die Geleitmission läuft. */ +/** + * Geleit, das wirklich mitfährt: beim Transport der Verband selbst, beim Handel nur, solange die Geleitmission läuft, + * beim Feldertrag die aktuelle Geleitabteilung der Besatzung (missionId = Besatzungsmission), sofern bei der Abfahrt eingeteilt. + */ async function liveEscort(tx: Tx, c: ConvoyRow): Promise { if (c.kind === "transport") return activeCounts(c.escort as Counts); + if (c.kind === "feld") return hasShips(c.escort as Counts) ? fieldEscortOf(tx, c.missionId) : {}; if (c.escortMissionId === null) return {}; const [m] = await tx.select({ status: tables.mission.status }).from(tables.mission).where(eq(tables.mission.id, c.escortMissionId)); return m?.status === "outbound" ? activeCounts(c.escort as Counts) : {}; @@ -152,14 +157,15 @@ async function fightEscort(tx: Tx, c: ConvoyRow, attacker: AttackerInput, escort if (!res.ok) throw new Error(`battle: ${res.code}`); const { report, destroyed } = strandTroops(res.report, balance); const left = activeUnits(report.defender.final); + if (c.kind === "feld") await fieldEscortLosses(tx, c.missionId, escort, left); // Felder: Verluste der Besatzung c.escort = left; await tx.update(tables.convoy).set({ escort: left }).where(eq(tables.convoy.id, c.id)); return { held: !destroyed, report: { ...report, loot: {} }, seed, attackerLeft: activeUnits(report.attacker.final), hex }; } -/** Besitzer und Ausgangshafen des Geleits (Transport: der Verband selbst, Handel: die Geleitmission), null ohne. */ +/** Besitzer und Ausgangshafen des Geleits (Transport: der Verband selbst, Feld: die Besatzung, Handel: die Geleitmission), null ohne. */ async function escortSource(tx: Tx, c: ConvoyRow): Promise<{ playerId: number; baseId: number | null } | null> { - const missionId = c.kind === "transport" ? c.missionId : c.escortMissionId; + const missionId = c.kind === "transport" || c.kind === "feld" ? c.missionId : c.escortMissionId; if (missionId === null) return c.kind === "transport" && c.senderId !== null ? { playerId: c.senderId, baseId: null } : null; const [m] = await tx.select({ playerId: tables.mission.playerId, baseId: tables.mission.baseId }).from(tables.mission).where(eq(tables.mission.id, missionId)); if (!m || m.playerId === null) return c.kind === "transport" && c.senderId !== null ? { playerId: c.senderId, baseId: null } : null; diff --git a/packages/engine/src/weekly.ts b/packages/engine/src/weekly.ts index e61d592..4046130 100644 --- a/packages/engine/src/weekly.ts +++ b/packages/engine/src/weekly.ts @@ -26,7 +26,8 @@ export async function weeklyContextFor(tx: DbOrTx, playerId: number, atMs: numbe const [n] = await tx.select({ n: count() }).from(tables.allianceMember).where(eq(tables.allianceMember.allianceId, m.allianceId)); allied = (n?.n ?? 0) >= 2; } - return { ...poolContext(state, { others: (o?.n ?? 0) > 0, raidsPossible }, mods), allied }; + const [nb] = await tx.select({ n: count() }).from(tables.base).where(eq(tables.base.playerId, playerId)); + return { ...poolContext(state, { others: (o?.n ?? 0) > 0, raidsPossible }, mods), allied, bases: nb?.n ?? 1 }; } export async function weekRows(tx: DbOrTx, playerId: number, week: string): Promise { @@ -67,23 +68,14 @@ export async function advanceWeekly(tx: DbOrTx, playerId: number, kind: string, return done.length; } -/** Ziele, deren Stand aus dem Zustand gelesen wird (abgeholte Tagesbefehle der Woche): beim Abruf fortschreiben. */ +/** Ziele, deren Stand aus dem Zustand gelesen wird (abgeholte Tagesbefehle, gegründete Häfen der Woche): beim Abruf fortschreiben. */ export async function refreshWeeklyDerived(tx: DbOrTx, playerId: number, rows: WeeklyRow[], nowMs: number): Promise { const open = rows.filter((r) => !r.completedAt && WEEKLY_DERIVED.has(r.kind)); if (open.length === 0) return rows; const out = new Map(rows.map((r) => [r.id, r])); for (const r of open) { - const dc = tables.dailyChallenge; - const [n] = await tx - .select({ n: count() }) - .from(dc) - .where(and( - eq(dc.playerId, playerId), - isNotNull(dc.claimedAt), - gte(dc.claimedAt, new Date(weekStartMs(r.week))), - lt(dc.claimedAt, new Date(weekStartMs(addDays(r.week, 7)))), - )); - const progress = Math.min(r.target, Math.max(r.progress, n?.n ?? 0)); + const n = r.kind === "gruendung" ? await foundedInWeek(tx, playerId, r.week) : await dailiesInWeek(tx, playerId, r.week); + const progress = Math.min(r.target, Math.max(r.progress, n)); if (progress === r.progress) continue; const completedAt = progress >= r.target ? new Date(nowMs) : null; await tx.update(wg).set({ progress, completedAt }).where(and(eq(wg.id, r.id), isNull(wg.completedAt))); @@ -91,3 +83,33 @@ export async function refreshWeeklyDerived(tx: DbOrTx, playerId: number, rows: W } return rows.map((r) => out.get(r.id)!); } + +/** Abgeholte Tagesbefehle in der Woche. */ +async function dailiesInWeek(tx: DbOrTx, playerId: number, week: string): Promise { + const dc = tables.dailyChallenge; + const [n] = await tx + .select({ n: count() }) + .from(dc) + .where(and( + eq(dc.playerId, playerId), + isNotNull(dc.claimedAt), + gte(dc.claimedAt, new Date(weekStartMs(week))), + lt(dc.claimedAt, new Date(weekStartMs(addDays(week, 7)))), + )); + return n?.n ?? 0; +} + +/** Mehrere Häfen: in der Woche gegründete Häfen (Kolonien, nicht der Heimathafen). */ +async function foundedInWeek(tx: DbOrTx, playerId: number, week: string): Promise { + const b = tables.base; + const [n] = await tx + .select({ n: count() }) + .from(b) + .where(and( + eq(b.playerId, playerId), + eq(b.isHome, false), + gte(b.createdAt, new Date(weekStartMs(week))), + lt(b.createdAt, new Date(weekStartMs(addDays(week, 7)))), + )); + return n?.n ?? 0; +} diff --git a/packages/engine/test/fields2.test.ts b/packages/engine/test/fields2.test.ts new file mode 100644 index 0000000..549de52 --- /dev/null +++ b/packages/engine/test/fields2.test.ts @@ -0,0 +1,249 @@ +// Integrationstests Felder 2: Geleitabteilung für Ertragskonvois, Verstärkung einer Besatzung (auch aus einem anderen +// Hafen), Radar-Vorwarnung bei Angriffen auf Felder, Wochenziele „feldertrag“ und „gruendung“ +// (TEST_DATABASE_URL; die Datenbank wird geleert). +import { after, before, beforeEach, test } from "node:test"; +import assert from "node:assert/strict"; +import { and, eq, sql } from "drizzle-orm"; +import { createDb, migrateDb, tables } from "@tidefront/db"; +import { nestSites, isCoast, hexDistanceKm, COLS, ROWS } from "@tidefront/world"; +import type { BaseState } from "@tidefront/game-core"; +import { + chooseBase, ensureFieldPlanner, fieldRecall, fieldsView, launchMission, missionPreview, processDue, register, seed, setFieldEscort, + weeklyView, type Engine, +} from "../src/index.ts"; +import { addSecondHarbor } from "./multi-base.ts"; + +const url = process.env.TEST_DATABASE_URL; +const HOUR = 3600000; +const DAY = 24 * HOUR; +const { db, client } = createDb(url ?? "postgres://invalid", 20); +const engine: Engine = { db, notify: () => {}, log: () => {} }; +let keyN = 0; +const key = () => `fe${++keyN}-${Date.now()}`; +const used = new Set(); + +function coastNear(near: { col: number; row: number } | null, minKm = 300, maxKm = 700): { col: number; row: number } { + const nests = new Set(nestSites().map((n) => `${n.col},${n.row}`)); + for (let row = 20; row < ROWS; row++) for (let col = 10; col < COLS; col++) { + const k = `${col},${row}`; + if (!isCoast(col, row) || nests.has(k) || used.has(k)) continue; + if (near) { + const d = hexDistanceKm(near, { col, row }); + if (d < minKm || d > maxKm) continue; + } + used.add(k); + return { col, row }; + } + throw new Error("no coast"); +} + +async function patchBase(baseId: number, patch: (s: BaseState) => void) { + const [b] = await db.select().from(tables.base).where(eq(tables.base.id, baseId)); + const s = b.state as BaseState; + patch(s); + await db.update(tables.base).set({ state: s }).where(eq(tables.base.id, baseId)); +} + +async function stateOf(baseId: number): Promise { + const [b] = await db.select().from(tables.base).where(eq(tables.base.id, baseId)); + return b.state as BaseState; +} + +async function newPlayer(name: string, field: { col: number; row: number }) { + const p = await register(db, { inviteCode: "TEST", name, password: "geheim123" }); + const r = await chooseBase(engine, p.playerId, key(), { ...field, name: `Hafen ${name}`, nightShieldStartHour: null, tzOffsetMinutes: 0 }); + assert.equal(r.ok, true, JSON.stringify(r)); + const baseId = (r as { baseId: number }).baseId; + await patchBase(baseId, (s) => { + s.protection.createdAtMs = Date.now() - 30 * DAY; + s.resources = { stahl: 500_000, treibstoff: 500_000, elektronik: 500_000, proviant: 500_000 }; + s.buildings.kommandozentrale = 15; + s.buildings.hafenkommandantur = 10; + s.buildings.lagerkomplex = 15; + s.buildings.radarstation = 5; + s.buildings.kraftwerk = 15; + s.units = { ...s.units, zerstoerer: 30, korvette: 30 }; + }); + return { playerId: p.playerId, baseId, ...field }; +} + +async function runUntil(ms: number) { + while ((await processDue(engine, ms, 500)) > 0); +} + +async function fieldRow(id: number) { + const [f] = await db.select().from(tables.resourceField).where(eq(tables.resourceField.id, id)); + return f; +} + +async function missionRow(id: number) { + const [m] = await db.select().from(tables.mission).where(eq(tables.mission.id, id)); + return m; +} + +/** Freies, unbewachtes Feld nahe `near` (kampflos besetzbar). */ +async function freeField(near: { col: number; row: number }) { + const all = (await db.select().from(tables.resourceField)).filter((x) => x.ownerId === null); + const f = all.sort((x, y) => hexDistanceKm(x, near) - hexDistanceKm(y, near))[0]; + await db.update(tables.resourceField).set({ guard: {}, guardAt: new Date(Date.now() + 30 * DAY) }).where(eq(tables.resourceField.id, f.id)); + return f; +} + +async function capture(p: { playerId: number }, f: { id: number; col: number; row: number }, units: Record, baseId?: number) { + const go = await launchMission(engine, p.playerId, key(), { type: "besetzen", units, col: f.col, row: f.row, fieldId: f.id, stayAll: true, ...(baseId ? { baseId } : {}) }); + assert.equal(go.ok, true, JSON.stringify(go)); + await runUntil((go as { arriveAtMs: number }).arriveAtMs + 1000); + const row = await fieldRow(f.id); + assert.equal(row.ownerId, p.playerId); + return (go as { missionId: number }).missionId; +} + +before(async () => { + if (!url) throw new Error("TEST_DATABASE_URL fehlt"); + await db.execute(sql`drop schema if exists public cascade; drop schema if exists drizzle cascade; create schema public;`); + await migrateDb(db); + await seed(db, "TEST:100"); +}); + +beforeEach(async () => { + await db.delete(tables.gameEvent).where(sql`${tables.gameEvent.type} = 'raid_launch' or ${tables.gameEvent.type} like 'world_event%'`); +}); + +after(async () => { + await client.end(); +}); + +test("Felder 2: Geleitabteilung begleitet Ertragskonvois, verteidigt das Feld nicht; Radar-Vorwarnung bei Angriff", async () => { + const a = await newPlayer("Geleitherr", coastNear(null)); + const b = await newPlayer("Angreifer", coastNear(a)); + assert.ok(await ensureFieldPlanner(db, Date.now())); + const target = await freeField(a); + const gid = await capture(a, target, { zerstoerer: 2, korvette: 3 }); + + // Geleit festlegen: nur Schiffe der Besatzung, der Rest bleibt gültige Besatzung. + const tooMuch = await setFieldEscort(engine, a.playerId, key(), target.id, { zerstoerer: 2, korvette: 3 }); + assert.equal(tooMuch.ok ? "ok" : tooMuch.code, "field_escort_too_large"); + const bad = await setFieldEscort(engine, a.playerId, key(), target.id, { korvette: 4 }); + assert.equal(bad.ok ? "ok" : bad.code, "field_escort_invalid"); + const other = await setFieldEscort(engine, b.playerId, key(), target.id, { korvette: 1 }); + assert.equal(other.ok ? "ok" : other.code, "no_field"); + const ok = await setFieldEscort(engine, a.playerId, key(), target.id, { korvette: 2 }); + assert.equal(ok.ok, true, JSON.stringify(ok)); + let mine = (await fieldsView(engine, a.playerId))!.mine.find((m) => m.id === target.id)!; + assert.deepEqual(mine.escort, { korvette: 2 }); + assert.deepEqual(mine.defenders, { zerstoerer: 2, korvette: 1 }); + + // Lieferzyklus: Konvoi mit Geleit (missionId = Besatzung). + await db.update(tables.resourceField).set({ lastTickAt: new Date(Date.now() - 4 * HOUR) }).where(eq(tables.resourceField.id, target.id)); + await db.update(tables.gameEvent).set({ dueAt: new Date() }).where(sql`${tables.gameEvent.type} = 'field_tick' and ${tables.gameEvent.status} = 'pending'`); + await runUntil(Date.now() + 1000); + const [cv] = await db.select().from(tables.convoy).where(and(eq(tables.convoy.kind, "feld"), eq(tables.convoy.recipientId, a.playerId))); + assert.ok(cv, "Ertragskonvoi unterwegs"); + assert.equal(cv.missionId, gid); + assert.deepEqual(cv.escort, { korvette: 2 }); + + // Kartell fängt ab: das Geleit kämpft (2 Korvetten gegen Schnellboote) und hält. + await db.insert(tables.gameEvent).values({ type: "convoy_raid", dueAt: new Date(), payload: { convoyId: cv.id }, baseId: null }); + await runUntil(Date.now() + 1000); + const [rep] = await db.select().from(tables.battleReport).where(and(eq(tables.battleReport.kind, "konvoi"), eq(tables.battleReport.defenderPlayerId, a.playerId))); + assert.ok(rep, "Konvoibericht"); + assert.equal((rep.report as { convoy: { held: boolean } }).convoy.held, true, JSON.stringify(rep.report)); + const g1 = (await missionRow(gid)).returning as Record; + assert.equal(g1.zerstoerer, 2); + assert.ok((g1.korvette ?? 0) >= 1, "Verluste höchstens im Geleit"); + + // Ertrag läuft ein: Zähler für das Wochenziel „feldertrag“. + await runUntil(cv.arriveAt.getTime() + 1000); + const [cnt] = await db.select().from(tables.achievementCounter).where(and(eq(tables.achievementCounter.playerId, a.playerId), eq(tables.achievementCounter.counter, "feldertrag"))); + assert.ok(cnt && Number(cnt.value) > 0, "Zähler feldertrag"); + + // Kartellangriff aufs Feld: nur die Besatzung ohne Geleit kämpft; das Geleit bleibt Teil der Besatzung. + const before = (await missionRow(gid)).returning as Record; + await db.insert(tables.gameEvent).values({ type: "field_raid", dueAt: new Date(), payload: { fieldId: target.id, ownerId: a.playerId, units: { schnellboot: 1 } }, baseId: null }); + await runUntil(Date.now() + 1000); + const [raid] = await db.select().from(tables.battleReport).where(and(eq(tables.battleReport.kind, "feld"), eq(tables.battleReport.defenderPlayerId, a.playerId), sql`${tables.battleReport.attackerPlayerId} is null`)); + const defFleet = (raid.report as { battle: { defender: { before: Record } } }).battle.defender; + const fought = defFleet.before; + assert.equal(fought.korvette ?? 0, Math.max(0, (before.korvette ?? 0) - 2), `Geleit kämpft nicht mit: ${JSON.stringify(defFleet)}`); + const after1 = (await missionRow(gid)).returning as Record; + assert.ok((after1.korvette ?? 0) >= 2, `Geleit noch da: ${JSON.stringify(after1)}`); + + // Rivale greift an: Vorwarnung (Radar 5 am Heimathafen, Anteil radarWarningFactor), Push und Meldung. + const atk = await launchMission(engine, b.playerId, key(), { type: "besetzen", units: { zerstoerer: 12 }, col: target.col, row: target.row, fieldId: target.id, stayAll: true }); + assert.equal(atk.ok, true, JSON.stringify(atk)); + const arrive = (atk as { arriveAtMs: number }).arriveAtMs; + const [warn] = await db.select().from(tables.gameEvent).where(and(eq(tables.gameEvent.type, "field_warning"), eq(tables.gameEvent.status, "pending"))); + assert.ok(warn && warn.dueAt.getTime() < arrive, "Vorwarnung vor Ankunft geplant"); + await runUntil(warn.dueAt.getTime() + 1000); + const msgs = await db.select().from(tables.message).where(and(eq(tables.message.toPlayerId, a.playerId), sql`${tables.message.subject} like 'Angriff auf %erkannt'`)); + assert.equal(msgs.length, 1, "Meldung an den Besitzer"); + const atkId = (atk as { missionId: number }).missionId; + const detectedAt = ((await missionRow(atkId)).plan as { detectedAtMs?: number }).detectedAtMs; + assert.ok(detectedAt && detectedAt < arrive, "Erkennung im Plan gemerkt"); + // Die Ansicht läuft in Echtzeit: Erkennung auf „jetzt“ vorziehen. + await db.update(tables.mission).set({ plan: sql`jsonb_set(${tables.mission.plan}, '{detectedAtMs}', to_jsonb(${Date.now() - 1000}::bigint))` }).where(eq(tables.mission.id, atkId)); + mine = (await fieldsView(engine, a.playerId))!.mine.find((m) => m.id === target.id)!; + assert.equal(mine.incoming.length, 1, "Angriff in „Meine Felder“ sichtbar"); + await runUntil(arrive + 1000); + assert.equal((await fieldRow(target.id)).ownerId, b.playerId); + const old = await missionRow(gid); + assert.equal(old.status, "returning"); + assert.ok(((old.returning as Record).korvette ?? 0) >= 2, "Geleitabteilung war unterwegs und kehrt heim"); +}); + +test("Felder 2: Verstärkung aus demselben und aus einem anderen Hafen; Wochenziel Gründung", async () => { + const c = await newPlayer("Verstaerker", coastNear(null)); + const target = await freeField(c); + const gid = await capture(c, target, { korvette: 2 }); + + // Vorschau: Besetzen gegen das eigene Feld ist eine Verstärkung (ohne Mindestbesatzung). + const pv = await missionPreview(engine, c.playerId, { type: "besetzen", units: { zerstoerer: 1 }, col: target.col, row: target.row, fieldId: target.id }); + assert.equal(pv.ok, true, JSON.stringify(pv)); + const go = await launchMission(engine, c.playerId, key(), { type: "besetzen", units: { zerstoerer: 1 }, col: target.col, row: target.row, fieldId: target.id }); + assert.equal(go.ok, true, JSON.stringify(go)); + await runUntil((go as { arriveAtMs: number }).arriveAtMs + 1000); + const g = await missionRow(gid); + assert.equal(g.status, "stationed"); + assert.deepEqual(g.returning, { korvette: 2, zerstoerer: 1 }); + assert.equal(((g.plan as { units: Record }).units).zerstoerer, 1); + assert.equal((await missionRow((go as { missionId: number }).missionId)).status, "done"); + + // Aus einem anderen Hafen: Einheiten wechseln in den Hafen des Felds, Veteranen gewichtet gemischt. + const c2 = await addSecondHarbor(db, c.playerId, { + near: target, minKm: 60, maxKm: 500, + patch: (s) => { s.buildings.hafenkommandantur = 5; s.protection.createdAtMs = 0; s.units = { korvette: 4 }; s.veterancy = { korvette: 400 }; }, + }); + const homeBefore = await stateOf(c.baseId); + const go2 = await launchMission(engine, c.playerId, key(), { type: "besetzen", units: { korvette: 2 }, col: target.col, row: target.row, fieldId: target.id, baseId: c2.baseId }); + assert.equal(go2.ok, true, JSON.stringify(go2)); + await runUntil((go2 as { arriveAtMs: number }).arriveAtMs + 1000); + const colony = await stateOf(c2.baseId); + assert.equal(colony.unitsAway.korvette ?? 0, 0, "Kolonie führt die Schiffe nicht mehr"); + assert.equal(colony.units.korvette, 2); + const home = await stateOf(c.baseId); + assert.equal((home.unitsAway.korvette ?? 0) - (homeBefore.unitsAway.korvette ?? 0), 2, "Heimathafen führt sie als unterwegs"); + assert.ok((home.veterancy?.korvette ?? 0) > (homeBefore.veterancy?.korvette ?? 0), "Veteranen gemischt"); + assert.deepEqual((await missionRow(gid)).returning, { korvette: 4, zerstoerer: 1 }); + + // Rückruf: alles kehrt in den Hafen des Felds heim, unitsAway geht auf. + const rc = await fieldRecall(engine, c.playerId, key(), target.id); + assert.equal(rc.ok, true, JSON.stringify(rc)); + await runUntil((rc as { returnAtMs: number }).returnAtMs + 1000); + const back = await stateOf(c.baseId); + assert.equal(back.unitsAway.korvette ?? 0, 0); + assert.equal(back.unitsAway.zerstoerer ?? 0, 0); + assert.equal(back.units.korvette, (homeBefore.units.korvette ?? 0) + 4); + + // Verstärkung für ein nicht mehr eigenes Feld: Prüfung schlägt fehl (kein eigenes Feld mehr → Angriff verlangt Besatzung). + const weak = await missionPreview(engine, c.playerId, { type: "besetzen", units: { korvette: 1 }, col: target.col, row: target.row, fieldId: target.id }); + assert.equal(weak.ok ? "ok" : weak.code, "garrison_too_weak"); + + // Wochenziel „gruendung“: aus den Häfen der Woche gelesen (zweiter Hafen wurde eben angelegt). + const w = await weeklyView(engine, c.playerId); + assert.ok(w.goals.length > 0); + await db.update(tables.weeklyGoal).set({ kind: "gruendung", target: 1, progress: 0, completedAt: null }).where(eq(tables.weeklyGoal.id, w.goals[0].id)); + const w2 = await weeklyView(engine, c.playerId); + const goal = w2.goals.find((x) => x.id === w.goals[0].id)!; + assert.equal(goal.progress, 1, JSON.stringify(goal)); + assert.equal(goal.done, true); +}); diff --git a/packages/game-core/ENTSCHEIDUNGEN.md b/packages/game-core/ENTSCHEIDUNGEN.md index 6a4c3b0..30f789d 100644 --- a/packages/game-core/ENTSCHEIDUNGEN.md +++ b/packages/game-core/ENTSCHEIDUNGEN.md @@ -609,9 +609,37 @@ Ziel: Felder sind Entscheidungen und Konflikte, kein passiver Mehrertrag. vorbereitet für mehrere Häfen. Ertragskonvois nutzen das Konvoi-System (Art „feld“, ohne Geleit), Blockade hält sie zurück; Minen wirken auf Konvois nicht. Der angefangene Zyklus geht beim Rückruf noch als Konvoi heim, bei Verlust durch Angriff verfällt er. -7. **Offen:** kein Geleitschutz für Ertragskonvois; keine Verstärkung einer Besatzung (Rückruf und neu besetzen); - ein Admiral, der einen Besetzungsverband führt, bleibt bei der Besatzung; Wochenziel-Art für Felder nicht umgesetzt; - kein Radar-Vorwarnung für Angriffe auf Felder (nur Push nach dem Kampf, beim Kartell vorab). +7. **Geleitabteilung (Felder 2).** Ein Teil der Besatzung (`resource_field.escort`) begleitet jeden Ertragskonvoi und + kämpft bei Abfangversuchen mit; er verteidigt das Feld nicht, der Rest muss eine gültige Besatzung bleiben + (`escortMinRemainCommandPoints` 6). Bewusst ohne Treibstoff und ohne eigene Mission: Die Kosten sind gebundene + Schiffe (Unterhalt, Missionsplatz der Besatzung) und eine schwächere Feldverteidigung. Simulation (`sim/fields.ts`, + Konvoi Stufe 2 = 500 Stahl-Äq., 450 km, 400 Seeds): Kartell fängt 6,7 % der Konvois ab (2 Schnellboote), ohne + Geleit Ø 60 Stahl-Äq. Verlust je Tag (≈ 2 % des Ertrags); schon 1 Korvette hält zu 100 %. Gegen Kriegsgegner + (60 % Plünderung ohne Geleit): 1 Zerstörer hält gegen 2 Zerstörer zu 71 %, 2 Zerstörer gegen 2/4 Zerstörer zu + 100/71 %, gegen 3 U-Boote zu 28 %. Kosten: Besatzung 2 Zerstörer + 2 Korvetten fällt beim Kartellangriff auf + Stufe 1/2/3 nie; mit 1 Korvette Geleit ebenfalls nie, mit 2 Korvetten Geleit (verteidigen nur 2 Zerstörer) auf + Stufe 3 zu 47 %. Das Geleit lohnt also vor allem im Krieg; gegen das Kartell genügt eine Korvette, wenn die + Besatzung stark genug ist. Treibstoff je Konvoi (erster Gedanke: Hin- und Rückweg) hätte mit ≈ 65 Stahl-Äq. je Korvette + und Konvoi mehr gekostet als der Kartellverlust – verworfen. +8. **Verstärkung.** „Besetzen“ gegen das eigene Feld fügt die Schiffe bei Ankunft der Besatzung hinzu (keine + Mindeststärke, keine Höchstzahl, Treibstoff hin und zurück wie beim Besetzen, Missionsplatz nur während der Fahrt). + Aus einem anderen Hafen wechseln die Schiffe in den Hafen des Felds (unitsAway wandert, Veteranen gewichtet wie bei + der Verlegung) – so bleibt die Besatzung eine Mission eines Hafens. +9. **Radar-Vorwarnung.** Spielerangriffe auf Felder meldet das Radar des Hafens des Felds mit `radarWarningFactor` + = 50 % seiner Vorwarnzeit (Radar 5: 17,5 statt 35 Minuten), Ereignis `field_warning`, Push und Systemnachricht. + Halbiert, weil das Feld ≥ 220 km vor dem Hafen liegt; die Reaktion (Rückruf, sofort wirksam) braucht wenig Zeit. + Verstärkungen erreichen das Feld meist nicht mehr rechtzeitig (Fahrzeit mehrere Stunden) – gewollt. +10. **Wochenziele.** „Felderträge“ (Zähler `feldertrag` = Wert eingelaufener Konvois zum Richtpreis, Ziel + 5000 × (1 + KZ/5) auf 1000 gerundet: ein Feld Stufe 1 auf Rang 1 liefert ≈ 12 600 je Woche, KZ 5 braucht 10 000) + nur mit Werft und erlaubtem Feld; „Gründung“ (1 Hafen in der Woche, aus `base.created_at` gelesen) nur, wenn ein + weiterer Hafen erlaubt und die Hafenkommandantur für das Kolonieschiff erreicht ist. Kein Auftragsbuch-Schritt: + das Auftragsbuch ist die Einführung (elf Grundaufträge, Abschluss „Hafenmeister“); ein Gründungsauftrag (KZ 5) + hätte den Abschluss für Anfänger um Wochen verschoben. +11. **Admiral.** Feldmissionen nehmen keinen Admiral (launchField übergeht admiralId, die Planung bietet keinen an); + der frühere Punkt „Admiral bleibt bei der Besatzung“ tritt daher nicht auf. Die Planung sagt es jetzt ausdrücklich. +12. **Offen:** Geleitabteilung kämpft nicht bei Kartellangriffen auf das Feld mit (auch wenn gerade kein Konvoi + fährt); jeder Konvoi kämpft mit derselben Abteilung (keine Aufteilung auf gleichzeitig fahrende Konvois); + Admirale für Besetzungsverbände. ## K. Mehrere Häfen: Gründung und Verlegung (Welle 3 „Expansion“, Teil 2, Block `expansion`, v1.11) @@ -637,5 +665,5 @@ Ziel: Felder sind Entscheidungen und Konflikte, kein passiver Mehrertrag. mit Ladung heim. 6. **Verlegung.** Nur Hinfahrt (Treibstoff einfach), dauerhaft; Veteranen gewichtet gemischt, Admiral wechselt den Hafen. Transport in eigene Häfen ist erlaubt. -7. **Offen:** „Kolonie aufgeben“ (P5); Umbenennen eines Hafens; Ortsname aus der Karte statt „ II“; Auftragsbuch- - und Wochenziel-Schritt für Gründungen. +7. **Offen:** „Kolonie aufgeben“ (P5); Umbenennen eines Hafens; Ortsname aus der Karte statt „ II“. + Wochenziel „Gründung“ siehe J.10 (kein Auftragsbuch-Schritt). diff --git a/packages/game-core/sim/fields.ts b/packages/game-core/sim/fields.ts index 13cf182..5568795 100644 --- a/packages/game-core/sim/fields.ts +++ b/packages/game-core/sim/fields.ts @@ -2,7 +2,7 @@ // des Bot-Hafens; Fallquote der Besatzung bei Kartellangriffen. Seeds fest (1 … N), Ergebnis reproduzierbar. import type { Balance, Counts } from "../src/index.ts"; import { - cargoValue, cartelChance, convoysOf, fieldBaseYield, fieldsOf, fieldUpkeep, guardOf, maxFieldsFor, productionRates, resolveBattle, + cargoValue, cartelChance, cartelConvoyForce, convoysOf, fieldBaseYield, fieldDefenders, fieldWarningMinutes, fieldsOf, fieldUpkeep, guardOf, maxFieldsFor, productionRates, resolveBattle, strandTroops, trainingCost, yieldFactor, } from "../src/index.ts"; import type { BotSnapshot } from "./bot.ts"; @@ -83,3 +83,34 @@ export function runFieldsSim(balance: Balance, snaps: BotSnapshot[]): void { } console.log(` Zonenbonus +${pct(f.zoneBonus)} je Feld ab ${f.zoneMinFields} verbundenen Allianzfeldern; Allianzwertung ${f.alliancePointsPerFieldDay} Punkte je Feld und Tag.`); } + +/** Welle 3, Felder 2: Geleitabteilung für Ertragskonvois (Nutzen) gegen die schwächere Feldverteidigung (Kosten). */ +export function runFieldEscortSim(balance: Balance): void { + const f = fieldsOf(balance); + const c = convoysOf(balance); + if (!f || !c) return; + const cargo = cargoValue(fieldBaseYield("erzbucht", 2, balance), balance) * f.deliveryHours; // Stufe 2, ein Zyklus + const chance = cartelChance(DIST_KM, cargo, balance); + const force = cartelConvoyForce(cargo, balance); + console.log(`\nFelder: Geleitabteilung – Ertragskonvoi Stufe 2 (${Math.round(cargo)} Stahl-Äq.), ${DIST_KM} km, ${SEEDS} Seeds`); + console.log(` Kartell: Chance ${pct(chance)} je Konvoi, Verband ${force.schnellboot ?? 0} Schnellboote; ohne Geleit Verlust ${pct(c.lossShareUnescorted)} der Ladung`); + const escorts: [string, Counts][] = [["1 Korvette", { korvette: 1 }], ["2 Korvetten", { korvette: 2 }], ["1 Zerstörer", { zerstoerer: 1 }], ["2 Zerstörer", { zerstoerer: 2 }]]; + const raiders: [string, Counts][] = [["2 Zerstörer", { zerstoerer: 2 }], ["4 Zerstörer", { zerstoerer: 4 }], ["3 U-Boote", { uboot: 3 }]]; + console.log(` ${"Geleit".padEnd(14)}${"hält (Kartell)".padStart(16)}${"Ø Verlust/Tag".padStart(15)}${raiders.map(([n]) => `hält gg. ${n}`.padStart(22)).join("")}`); + const perDay = 24 / f.deliveryHours; + const noEscortLoss = chance * c.lossShareUnescorted * cargo * perDay; + console.log(` ${"ohne".padEnd(14)}${"–".padStart(16)}${noEscortLoss.toFixed(1).padStart(15)}${raiders.map(() => `0 % (−${pct(c.plunderShare)})`.padStart(22)).join("")}`); + for (const [name, e] of escorts) { + const holds = 1 - winRate(force, e, balance); + const loss = chance * (1 - holds) * c.lossShareEscortBeaten * cargo * perDay; + console.log(` ${name.padEnd(14)}${pct(holds).padStart(16)}${loss.toFixed(1).padStart(15)}${raiders.map(([, r]) => pct(1 - winRate(r, e, balance)).padStart(22)).join("")}`); + } + // Kosten: das Geleit verteidigt das Feld nicht. + const g: Counts = { zerstoerer: 2, korvette: 2 }; + console.log(` Kosten: Besatzung 2 Zerstörer + 2 Korvetten fällt beim Kartellangriff (Stufe 1/2/3):`); + for (const [name, e] of [["ohne Geleit", {}], ["Geleit 1 Korvette", { korvette: 1 }], ["Geleit 2 Korvetten", { korvette: 2 }]] as [string, Counts][]) { + const def = fieldDefenders(g, e); + console.log(` ${name.padEnd(20)}${[1, 2, 3].map((t) => pct(winRate(f.cartelRaid[t - 1], def, balance)).padStart(9)).join("")}`); + } + console.log(` Radar-Vorwarnung bei Spielerangriffen: ${pct(f.radarWarningFactor ?? 0)} der Hafen-Vorwarnzeit (z. B. Radar 5: ${fieldWarningMinutes(35, balance)} von 35 Minuten)`); +} diff --git a/packages/game-core/sim/simulate.ts b/packages/game-core/sim/simulate.ts index 123482f..c6c2d3b 100644 --- a/packages/game-core/sim/simulate.ts +++ b/packages/game-core/sim/simulate.ts @@ -26,7 +26,7 @@ import { runPowerSim } from "./power.ts"; import { runEspionageSim } from "./espionage.ts"; import { runAdmiralSim } from "./admirals.ts"; // Admirale import { runNavalSim } from "./naval.ts"; // See: Minen/Blockade/Konvoi -import { runFieldsSim } from "./fields.ts"; // Felder +import { runFieldEscortSim, runFieldsSim } from "./fields.ts"; // Felder import { runExpansionSim } from "./expansion.ts"; // Mehrere Häfen const balance = JSON.parse( @@ -269,6 +269,7 @@ runAdmiralSim(balance); runNavalSim(balance, snaps); // Felder: Ertrag gegen Kosten und Risiko, Fallquote der Besatzung. runFieldsSim(balance, snaps); +runFieldEscortSim(balance); // Felder 2: Geleitabteilung runExpansionSim(balance, snaps); // Mehrere Häfen /** Der Bot schickt alles, was daheim steht (die Doktrin hält ihn innerhalb der Kommandopunkte). */ diff --git a/packages/game-core/src/fields.ts b/packages/game-core/src/fields.ts index 7f16703..409ccd8 100644 --- a/packages/game-core/src/fields.ts +++ b/packages/game-core/src/fields.ts @@ -57,6 +57,10 @@ export interface FieldsBalance { zoneBonus: number; /** Allianzwertung: Punkte je Feld und Tag (Saisonbeitrag). */ alliancePointsPerFieldDay: number; + /** Radar-Vorwarnung bei Spielerangriffen auf ein besetztes Feld: Anteil der Vorwarnzeit des Heimathafens (fehlt: 0 = keine). */ + radarWarningFactor?: number; + /** Geleitabteilung: Mindest-Kommandopunkte, die nach Abzug des Geleits als Besatzung bleiben (fehlt: minGarrisonCommandPoints). */ + escortMinRemainCommandPoints?: number; } export function fieldsOf(b: Balance): FieldsBalance | null { @@ -215,3 +219,71 @@ export function fieldZones( } return out; } + +// ---------------------------------------------------------------- Geleitabteilung, Verstärkung, Vorwarnung + +/** Summe zweier Bestände (nur positive Zahlen). */ +export function addCounts(a: Counts, b: Counts): Counts { + const out: Counts = {}; + for (const src of [a, b]) for (const [id, n] of Object.entries(src)) if (n > 0) out[id] = (out[id] ?? 0) + n; + return out; +} + +/** a − b, nie negativ; leere Einträge fallen weg. */ +export function subtractCounts(a: Counts, b: Counts): Counts { + const out: Counts = {}; + for (const [id, n] of Object.entries(a)) { + const left = n - Math.max(0, b[id] ?? 0); + if (left > 0) out[id] = left; + } + return out; +} + +/** Geleitabteilung, gekappt auf den aktuellen Bestand der Besatzung (nach Verlusten). */ +export function clampEscort(garrison: Counts, escort: Counts): Counts { + const out: Counts = {}; + for (const [id, n] of Object.entries(escort)) { + const k = Math.min(Math.floor(n), garrison[id] ?? 0); + if (k > 0) out[id] = k; + } + return out; +} + +/** Wer das Feld verteidigt: Besatzung ohne die Geleitabteilung (die fährt mit den Ertragskonvois). */ +export function fieldDefenders(garrison: Counts, escort: Counts): Counts { + return subtractCounts(garrison, clampEscort(garrison, escort)); +} + +/** + * Geleitabteilung prüfen: nur Schiffe der Besatzung, ganze Zahlen; was bleibt, muss eine gültige Besatzung sein + * (bewaffnet, ≥ escortMinRemainCommandPoints bzw. minGarrisonCommandPoints). Leer = Geleit aufheben. + * Codes: no_fields, field_escort_invalid, field_escort_too_large. + */ +export function escortCheck(garrison: Counts, escort: Counts, balance: Balance): Result<{ escort: Counts; remain: Counts }> { + const f = fieldsOf(balance); + if (!f) return { ok: false, code: "no_fields" }; + const clean: Counts = {}; + for (const [id, n] of Object.entries(escort)) { + if (!Number.isInteger(n) || n < 0) return { ok: false, code: "field_escort_invalid" }; + if (n === 0) continue; + if (n > (garrison[id] ?? 0) || balance.units[id]?.branch !== "see") return { ok: false, code: "field_escort_invalid" }; + clean[id] = n; + } + const remain = subtractCounts(garrison, clean); + if (Object.keys(clean).length === 0) return { ok: true, escort: {}, remain }; + let cp = 0; + let armed = false; + for (const [id, n] of Object.entries(remain)) { + cp += (balance.units[id]?.commandPoints ?? 0) * n; + if ((balance.units[id]?.attack.see ?? 0) > 0) armed = true; + } + const min = f.escortMinRemainCommandPoints ?? f.minGarrisonCommandPoints; + if (!armed || cp + 1e-9 < min) return { ok: false, code: "field_escort_too_large" }; + return { ok: true, escort: clean, remain }; +} + +/** Vorwarnzeit (Minuten) für Spielerangriffe auf ein Feld aus der Vorwarnzeit seines Heimathafens. */ +export function fieldWarningMinutes(harborWarningMinutes: number, balance: Balance): number { + const k = fieldsOf(balance)?.radarWarningFactor ?? 0; + return Math.max(0, harborWarningMinutes * k); +} diff --git a/packages/game-core/test/fields.test.ts b/packages/game-core/test/fields.test.ts index b1d9cfc..3f38f04 100644 --- a/packages/game-core/test/fields.test.ts +++ b/packages/game-core/test/fields.test.ts @@ -1,8 +1,9 @@ -// Felder: Höchstzahl, abnehmender Ertrag, Besatzung, Zonen, Kartellwürfel, Kandidatenliste. +// Felder: Höchstzahl, abnehmender Ertrag, Besatzung, Zonen, Kartellwürfel, Kandidatenliste, Geleitabteilung, Vorwarnung. import { test } from "node:test"; import assert from "node:assert/strict"; import { - cartelFieldRaid, fieldUpkeep, fieldYield, fieldZones, fieldsOf, garrisonCheck, guardOf, maxFieldsFor, splitGarrison, yieldFactor, + addCounts, cartelFieldRaid, clampEscort, escortCheck, fieldDefenders, fieldUpkeep, fieldWarningMinutes, fieldYield, fieldZones, fieldsOf, + garrisonCheck, guardOf, maxFieldsFor, splitGarrison, subtractCounts, yieldFactor, } from "../src/index.ts"; import { fieldSites, hexDistanceKm, terrainAt } from "@tidefront/world"; import { loadBalance } from "./helpers.ts"; @@ -70,3 +71,29 @@ test("Kandidaten: nur See, Abstand gewahrt, gleiche Liste bei gleichem Seed", () assert.deepEqual(fieldSites(f.siteSeed, { ...kinds }, [...f.tierShares]).slice(0, 5), a.slice(0, 5)); assert.ok(new Set(a.map((s) => s.kind)).size === 4); }); + +test("Geleitabteilung: nur Schiffe der Besatzung, Rest bleibt gültige Besatzung", () => { + const g = { zerstoerer: 2, korvette: 2 }; + const ok = escortCheck(g, { korvette: 2 }, balance); + assert.ok(ok.ok); + if (ok.ok) assert.deepEqual(ok.remain, { zerstoerer: 2 }); + assert.equal((escortCheck(g, { korvette: 3 }, balance) as { code: string }).code, "field_escort_invalid"); + assert.equal((escortCheck(g, { korvette: 1.5 }, balance) as { code: string }).code, "field_escort_invalid"); + assert.equal((escortCheck(g, { schuetzen: 1 }, balance) as { code: string }).code, "field_escort_invalid"); + assert.ok(escortCheck(g, { zerstoerer: 2 }, balance).ok, "2 Korvetten (6 KP) bleiben als Besatzung"); + assert.equal((escortCheck(g, { zerstoerer: 2, korvette: 1 }, balance) as { code: string }).code, "field_escort_too_large"); + const none = escortCheck(g, {}, balance); + assert.ok(none.ok && Object.keys(none.escort).length === 0, "leer = aufheben"); +}); + +test("Geleitabteilung: Verteidiger ohne Geleit, Kappung nach Verlusten, Zählerhilfen", () => { + assert.deepEqual(fieldDefenders({ zerstoerer: 2, korvette: 2 }, { korvette: 1 }), { zerstoerer: 2, korvette: 1 }); + assert.deepEqual(clampEscort({ korvette: 1 }, { korvette: 2, zerstoerer: 1 }), { korvette: 1 }); + assert.deepEqual(addCounts({ korvette: 1 }, { korvette: 2, zerstoerer: 1 }), { korvette: 3, zerstoerer: 1 }); + assert.deepEqual(subtractCounts({ korvette: 3, zerstoerer: 1 }, { korvette: 5 }), { zerstoerer: 1 }); +}); + +test("Vorwarnung für Felder: Anteil der Vorwarnzeit des Heimathafens", () => { + assert.equal(fieldWarningMinutes(40, balance), 40 * (f.radarWarningFactor ?? 0)); + assert.equal(fieldWarningMinutes(0, balance), 0); +});