mirror of
https://github.com/db9979/tidefront.git
synced 2026-12-06 12:54:09 +01:00
Merge branch 'main' into worktree-agent-a1cb2b41805f4a8ea
This commit is contained in:
commit
d8233c8dcd
51 files changed
+835
-239
No files matched your search
@@ -5,7 +5,7 @@ import { useQuery } from "@tanstack/react-query";
|
||||
import { trpc, trpcClient, type Balance, type BaseData } from "../lib/trpc.ts";
|
||||
import { useCommand } from "../lib/command.ts";
|
||||
import { fmtNum } from "../lib/names.ts";
|
||||
import { fmtDuration, fmtTime } from "../lib/time.ts";
|
||||
import { fmtDuration, fmtTime, useNow } from "../lib/time.ts";
|
||||
import { Button, Card, ErrorLine, ResChips, UnitChips } from "../ui.tsx";
|
||||
import { Icon } from "../icons.tsx";
|
||||
import { invalidateOps } from "./AllianceRaids.tsx";
|
||||
@@ -19,7 +19,7 @@ export function opsLimits(b: Balance | undefined): Limits {
|
||||
}
|
||||
|
||||
function minutesText(m: number): string {
|
||||
return m < 60 ? `${m} min` : m % 60 === 0 ? `${m / 60} h` : `${Math.floor(m / 60)} h ${m % 60} min`;
|
||||
return fmtDuration(m * 60_000); // einheitlich: „30 min“, „2 h“, „1 T“
|
||||
}
|
||||
|
||||
/** Missionsplanung (Überfall): denselben Verband als Sammelangriff der Allianz eröffnen. */
|
||||
@@ -31,13 +31,14 @@ export function RaidOpenCard({ balance, target, units, travelSeconds, ok, onDone
|
||||
const joinChoices = [15, 30, 60, 120, 240, 480, 720, 1440].filter((m) => m >= lim.minJoinMinutes && m <= lim.maxJoinHours * 60);
|
||||
const [join, setJoin] = useState(joinChoices[1] ?? joinChoices[0] ?? lim.minJoinMinutes);
|
||||
const [extra, setExtra] = useState(0);
|
||||
const now = useNow(60_000); // „Ankunft frühestens“ läuft mit der Uhr mit
|
||||
const open = useCommand(
|
||||
(i: { key: string; col: number; row: number; eventId?: number; units: Counts; joinMinutes: number; arriveMinutes: number }) => trpcClient.allianceOps.open.mutate(i),
|
||||
invalidateOps,
|
||||
);
|
||||
if (!al.data?.alliance) return null;
|
||||
const arriveMinutes = Math.min(lim.maxArriveHours * 60, join + extra);
|
||||
const earliest = Date.now() + join * 60000 + (travelSeconds ?? 0) * 1000;
|
||||
const earliest = now + join * 60000 + (travelSeconds ?? 0) * 1000;
|
||||
return (
|
||||
<Card title={<><Icon id="sammelangriff" size={18} /> Als Sammelangriff eröffnen</>}>
|
||||
<p className="text-xs text-ink2 mb-2">Deine Allianz kann bis zur Frist mit eigenen Verbänden beitreten. Alle laufen so aus, dass sie gleichzeitig ankommen; die Beute wird nach Kampfbeitrag geteilt.</p>
|
||||
@@ -51,7 +52,7 @@ export function RaidOpenCard({ balance, target, units, travelSeconds, ok, onDone
|
||||
{[0, 15, 30, 60, 120, 240].map((m) => <option key={m} value={m}>{m === 0 ? "so früh wie möglich" : `+ ${minutesText(m)}`}</option>)}
|
||||
</select>
|
||||
</label>
|
||||
<p className="text-xs text-ink2 mt-1">Ankunft frühestens {fmtTime(Math.max(earliest, Date.now() + arriveMinutes * 60000))} – ein langsamerer Verband verschiebt sie.</p>
|
||||
<p className="text-xs text-ink2 mt-1">Ankunft frühestens {fmtTime(Math.max(earliest, now + arriveMinutes * 60000))} – ein langsamerer Verband verschiebt sie.</p>
|
||||
<Button
|
||||
className="w-full mt-2"
|
||||
disabled={!ok || open.busy || Object.keys(units).length === 0}
|
||||
|
||||
@@ -6,7 +6,8 @@ import { useQuery } from "@tanstack/react-query";
|
||||
import { trpc, trpcClient, type BaseData } from "../lib/trpc.ts";
|
||||
import { useCommand } from "../lib/command.ts";
|
||||
import { fmtNum, label } from "../lib/names.ts";
|
||||
import { fmtDuration, fmtTime, useNow } from "../lib/time.ts";
|
||||
import { fmtDuration, fmtRange, fmtTime, useNow } from "../lib/time.ts";
|
||||
import { useLiveBase } from "../lib/live-base.ts";
|
||||
import { researchNote } from "../lib/research.ts";
|
||||
import { Icon } from "../icons.tsx";
|
||||
import { Button, Card, ErrorLine } from "../ui.tsx";
|
||||
@@ -34,7 +35,7 @@ export function Supply({ base }: { base: BaseData }) {
|
||||
<span>Radar-Vorwarnzeit</span><span className="text-right">{fmtNum(base.radarWarningMinutes, 1)} min<Note text={researchNote(base.modifierSources.find((m) => m.id === "forschung")?.mods, "radarWarning")} /><Note text={researchNote(base.modifierSources.find((m) => m.id === "wetter")?.mods, "radarWarning")?.replace("Forschung", "Nebel") ?? null} /></span>
|
||||
</div>
|
||||
<p className="text-xs text-ink2">Jede Einheit isst Proviant, auch unterwegs. Der Saldo steht oben in der Leiste bei Proviant. Ist er negativ, schrumpft der Vorrat; bei 0 droht Versorgungsmangel.</p>
|
||||
{(base.rates.proviant ?? 0) < 0 && !base.versorgungsmangel && <p className="text-siegel text-xs">Deine Truppen essen mehr, als du erzeugst: Vorrat reicht noch {fmtNum(Math.floor((base.resources.proviant ?? 0) / -(base.rates.proviant ?? -1)))} h. Versorgungshof ausbauen oder Proviant kaufen.</p>}
|
||||
{(base.rates.proviant ?? 0) < 0 && !base.versorgungsmangel && <p className="text-siegel text-xs">Deine Truppen essen mehr, als du erzeugst: Vorrat reicht noch <ProvisionLeft base={base} />. Versorgungshof ausbauen oder Proviant kaufen.</p>}
|
||||
{base.versorgungsmangel && <p className="text-red-300">Versorgungsmangel: keine Ausbildung, Angriff −20 %. Versorgungshof ausbauen oder Proviant kaufen.</p>}
|
||||
{base.deliveries.length > 0 && <DeliveryList base={base} />}
|
||||
</div>
|
||||
@@ -42,6 +43,13 @@ export function Supply({ base }: { base: BaseData }) {
|
||||
);
|
||||
}
|
||||
|
||||
/** Restdauer des Proviants bei negativem Saldo, aus dem hochgerechneten Bestand (live). */
|
||||
function ProvisionLeft({ base }: { base: BaseData }) {
|
||||
const live = useLiveBase(base);
|
||||
const rate = base.rates.proviant ?? 0;
|
||||
return <span className="mono">{rate < 0 ? fmtDuration(((live.resources.proviant ?? 0) / -rate) * 3_600_000) : "–"}</span>;
|
||||
}
|
||||
|
||||
/** Kleiner Forschungshinweis hinter einem Wert („+20 % durch Forschung“). */
|
||||
function Note({ text }: { text: string | null }) {
|
||||
return text ? <span className="block text-[11px] text-emerald-300 font-sans">{text}</span> : null;
|
||||
@@ -90,7 +98,7 @@ export function Protection({ base, now }: { base: BaseData; now: number }) {
|
||||
const win = p.nightWindow;
|
||||
const beginnerEnd = p.createdAtMs + (prot?.beginnerDays ?? 7) * 86400000;
|
||||
return (
|
||||
<Card title="Schutz" collapsible storageKey="basis-schutz" defaultOpen={false} summary={<span className={p.status ? "" : "text-siegel"}>{p.status ? `${label(p.status)} aktiv` : "kein Schutz aktiv"}{win ? ` · Nachtschild ${fmtTime(win.startMs)}–${fmtTime(win.endMs)}` : ""}</span>}>
|
||||
<Card title="Schutz" collapsible storageKey="basis-schutz" defaultOpen={false} summary={<span className={p.status ? "" : "text-siegel"}>{p.status ? `${label(p.status)} aktiv` : "kein Schutz aktiv"}{win ? ` · Nachtschild ${fmtRange(win.startMs, win.endMs)}` : ""}</span>}>
|
||||
<div className="flex items-start gap-3">
|
||||
<Icon id="schild" size={40} />
|
||||
<div className="text-sm min-w-0">
|
||||
@@ -99,7 +107,10 @@ export function Protection({ base, now }: { base: BaseData; now: number }) {
|
||||
{p.defeatShieldUntilMs > now && <div className="text-xs text-slate-400">Schutz nach Niederlage bis {fmtTime(p.defeatShieldUntilMs)}</div>}
|
||||
{win && (
|
||||
<div className="text-xs text-slate-400">
|
||||
{now >= win.startMs && now < win.endMs ? `Nachtschild bis ${fmtTime(win.endMs)}` : `Nächster Nachtschild ${fmtTime(win.startMs)}–${fmtTime(win.endMs)}`}
|
||||
{now >= win.startMs && now < win.endMs
|
||||
? `Nachtschild bis ${fmtTime(win.endMs)} (noch ${fmtDuration(win.endMs - now)})`
|
||||
: now >= win.endMs ? "Nachtschild vorbei – nächster Zeitraum wird geladen …"
|
||||
: `Nächster Nachtschild ${fmtRange(win.startMs, win.endMs)} (beginnt in ${fmtDuration(win.startMs - now)})`}
|
||||
{p.nightShieldSuspendedUntilMs > now ? " (durch eigenen Angriff aufgehoben)" : ""}
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -58,9 +58,9 @@ export function ProbeKampf({ balance, base, units, versorgungsmangel, modifiers,
|
||||
return (
|
||||
<div>
|
||||
{target.kind === "base" && scout.data && (
|
||||
<p className="text-xs text-ink2 mb-2">Lagebild vom {fmtTime(scout.data.atMs)}. Der Hafen kann sich seither verändert haben.</p>
|
||||
<p className="text-xs text-ink2 mb-2">Lagebild mit Stand {fmtTime(scout.data.atMs)}. Der Hafen kann sich seither verändert haben.</p>
|
||||
)}
|
||||
{target.kind === "nest" && target.lagebild && <p className="text-xs text-ink2 mb-2">Genau gegen das Lagebild vom {fmtTime(target.lagebild.atMs)} (Erholung und Beute hochgerechnet).</p>}
|
||||
{target.kind === "nest" && target.lagebild && <p className="text-xs text-ink2 mb-2">Genau gegen das Lagebild mit Stand {fmtTime(target.lagebild.atMs)} (Erholung und Beute hochgerechnet).</p>}
|
||||
{target.kind === "nest" && !target.lagebild && <NestRangeLine level={target.level} attacker={attacker} balance={balance} weather={weather} onScout={onScout} />}
|
||||
{weather && <p className="text-xs text-ink2 mb-2" data-testid="probe-wetter">Wetter am Ziel zur Ankunft (Vorhersage, Mitte der Spanne): {weatherText(weather)}.</p>}
|
||||
<Outcome attacker={attacker} defender={defender} balance={balance} weather={weather} />
|
||||
|
||||
@@ -63,7 +63,7 @@ export function FieldSheet({ data, sel, onPlan }: { data: FieldsData | null | un
|
||||
{f.garrison && <div className="text-xs">Besatzung: <UnitChips counts={f.garrison} /></div>}
|
||||
{f.guard && Object.keys(f.guard).length > 0 && <div className="text-xs">Kartell-Wache: <UnitChips counts={f.guard} /></div>}
|
||||
{f.guardAtMs && <div className="text-xs text-ink2">Unbewacht – das Kartell kehrt in {fmtDuration(f.guardAtMs - now)} zurück</div>}
|
||||
{f.intel && <div className="text-xs">Lagebild vom {fmtTime(f.intel.atMs)}: <UnitChips counts={f.intel.units} /></div>}
|
||||
{f.intel && <div className="text-xs">Lagebild (Stand {fmtTime(f.intel.atMs)}): <UnitChips counts={f.intel.units} /></div>}
|
||||
{!f.garrison && !f.guard && !f.intel && f.relation !== "frei" && <div className="text-xs text-ink2">Besatzung unbekannt – erst aufklären.</div>}
|
||||
<IntelStand tag={f.seen} now={now} />
|
||||
{f.zone && f.zone.size >= 2 && <div className="text-xs text-moos">Einflusszone: {f.zone.size} Felder{f.zone.bonus ? " – Ertragsbonus aktiv" : ""}</div>}
|
||||
|
||||
@@ -6,6 +6,7 @@ import { useEffect, useState } from "react";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { queryClient, trpc, trpcClient, type BaseData, type Balance, type Outputs } from "../lib/trpc.ts";
|
||||
import { serverNow } from "../lib/time.ts";
|
||||
import { useLiveBase } from "../lib/live-base.ts";
|
||||
import { useCommand } from "../lib/command.ts";
|
||||
import { countLabel, fmtNum } from "../lib/names.ts";
|
||||
import { Icon } from "../icons.tsx";
|
||||
@@ -108,7 +109,8 @@ export function overflowOf(base: BaseData, reward: Record<string, number> | unde
|
||||
|
||||
const invalidate = () => [trpc.guide.pathFilter().queryKey, trpc.base.pathFilter().queryKey, trpc.social.ranking.pathFilter().queryKey];
|
||||
|
||||
export function Guide({ base, onAction }: { base: BaseData; onAction: (a: GuideAction) => void }) {
|
||||
export function Guide({ base: snap, onAction }: { base: BaseData; onAction: (a: GuideAction) => void }) {
|
||||
const base = useLiveBase(snap); // Lagerwarnung mit hochgerechnetem Bestand
|
||||
const meta = useQuery({ ...trpc.meta.queryOptions(), staleTime: Infinity });
|
||||
const q = useGuide();
|
||||
const [showAll, setShowAll] = useState(false);
|
||||
|
||||
@@ -49,7 +49,7 @@ export function IntelOpsPlan({ op, base, map, initial, onSent }: {
|
||||
: op === "postenangriff" ? { op, units: chosen, postId: initial?.postId ?? 0 }
|
||||
: { op, units: chosen, col: points[0]?.col, row: points[0]?.row };
|
||||
const ready = Object.keys(chosen).length > 0 && (op === "postenangriff" ? !!initial?.postId : points.length > 0);
|
||||
const preview = useQuery({ ...trpc.intel.preview.queryOptions(input), enabled: ready, placeholderData: keepPreviousData });
|
||||
const preview = useQuery({ ...trpc.intel.preview.queryOptions(input), enabled: ready, placeholderData: keepPreviousData, refetchInterval: 60_000 }); // Ankunftszeit aktuell
|
||||
const launch = useCommand((i: typeof input & { key: string }) => trpcClient.intel.launch.mutate(i), () => [trpc.base.pathFilter().queryKey, trpc.world.map.pathFilter().queryKey]);
|
||||
if (!meta.data) return null;
|
||||
const balance = meta.data.balance;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Lagebild: Stand einer Angabe im Feld-Blatt („Stand: vor 5 h, Radar Hafen X“) und fremde Verbände auf einem Feld.
|
||||
// Live-Angaben (jetzt im Sensorbereich) brauchen keinen Stand; veraltete stehen in Klammern (docs/REGELN-LAGEBILD.md).
|
||||
import type { MapData } from "../lib/trpc.ts";
|
||||
import { fmtDuration } from "../lib/time.ts";
|
||||
import { fmtAgo } from "../lib/time.ts";
|
||||
|
||||
export type IntelTag = { age: "live" | "bekannt" | "veraltet"; atMs: number; source: string; level: string } | null | undefined;
|
||||
export type MapFleet = MapData["fleets"][number];
|
||||
@@ -10,10 +10,9 @@ const LEVEL_TEXT: Record<string, string> = { sichtung: "Sichtung", erkennung: "E
|
||||
const SIZE_TEXT: Record<string, string> = { klein: "klein (bis 10 Einheiten)", mittel: "mittel (bis 40)", gross: "groß (über 40)" };
|
||||
const REL_TEXT: Record<string, string> = { allianz: "Allianz", pakt: "Paktpartner", krieg: "Kriegsgegner", neutral: "neutral", kartell: "Kartell" };
|
||||
|
||||
/** „vor 5 h“ (unter einer Stunde in Minuten). */
|
||||
/** „vor 5 h“ (unter einer Stunde in Minuten) – einheitlich über fmtAgo (lib/time.ts). */
|
||||
export function agoText(atMs: number, now: number): string {
|
||||
const ms = Math.max(0, now - atMs);
|
||||
return ms < 60000 ? "gerade eben" : `vor ${fmtDuration(ms)}`;
|
||||
return fmtAgo(atMs, now);
|
||||
}
|
||||
|
||||
/** Zeile „Stand: vor X (Quelle)“ für bekanntes oder veraltetes Wissen; live: kleine Quellenangabe. */
|
||||
|
||||
@@ -6,7 +6,7 @@ import { useQuery } from "@tanstack/react-query";
|
||||
import { queryClient, trpc, trpcClient } from "../lib/trpc.ts";
|
||||
import { useCommand } from "../lib/command.ts";
|
||||
import { fmtNum, label } from "../lib/names.ts";
|
||||
import { fmtTime } from "../lib/time.ts";
|
||||
import { fmtAgo, fmtTime, useNow } from "../lib/time.ts";
|
||||
import type { Target } from "../App.tsx";
|
||||
import { Icon } from "../icons.tsx";
|
||||
import { Badge, Card, ErrorLine, Loading, SmallButton, UnitChips } from "../ui.tsx";
|
||||
@@ -18,19 +18,16 @@ const SENSOR_TEXT: Record<string, string> = {
|
||||
};
|
||||
const LEVEL_TEXT: Record<string, string> = { sichtung: "Sichtung", erkennung: "Erkennung", lagebild: "Lagebild" };
|
||||
|
||||
function ago(ms: number, now: number): string {
|
||||
const min = Math.max(0, Math.round((now - ms) / 60000));
|
||||
return min < 60 ? `vor ${min} min` : `vor ${Math.round(min / 60)} h`;
|
||||
}
|
||||
const ago = fmtAgo; // „vor 12 min“, „vor 2 h“ – live mit der gemeinsamen Uhr
|
||||
|
||||
export function LagebildTab({ onShowOnMap }: { onShowOnMap: (t: Target) => void }) {
|
||||
const q = useQuery({ ...trpc.intel.overview.queryOptions(), refetchInterval: 60000 });
|
||||
const now = useNow(60000);
|
||||
const [confirm, setConfirm] = useState<number | null>(null);
|
||||
const dismantle = useCommand((i: { key: string; postId: number }) => trpcClient.intel.dismantlePost.mutate(i), () => [trpc.intel.pathFilter().queryKey, trpc.base.pathFilter().queryKey, trpc.world.map.pathFilter().queryKey]);
|
||||
if (!q.data) return <Loading cards={3} />;
|
||||
const d = q.data;
|
||||
if (!d.enabled) return <Card title="Lagebild"><p className="text-sm">In dieser Saison gibt es keinen Kartennebel: Du siehst die ganze Welt.</p></Card>;
|
||||
const now = d.serverNow;
|
||||
const here = (col: number | null, row: number | null) => col !== null && row !== null
|
||||
? <SmallButton onClick={() => onShowOnMap({ col, row })}>Karte</SmallButton> : null;
|
||||
const sensors = Object.entries(d.sensors.reduce<Record<string, { n: number; km: number }>>((acc, s) => {
|
||||
@@ -114,7 +111,7 @@ export function LagebildTab({ onShowOnMap }: { onShowOnMap: (t: Target) => void
|
||||
</ul>
|
||||
)}
|
||||
<ErrorLine text={dismantle.error} code={dismantle.code} />
|
||||
<p className="text-xs text-ink2 mt-2">Stand {fmtTime(now)}.</p>
|
||||
<p className="text-xs text-ink2 mt-2">Stand {fmtTime(d.serverNow, now)}.</p>
|
||||
</Card>
|
||||
<SatelliteCard sats={d.satellites} launch={d.launch} onShowOnMap={onShowOnMap} />
|
||||
</div>
|
||||
|
||||
@@ -113,7 +113,7 @@ export function MissionPanel({ mission, now, home, onClose, onShowTarget }: {
|
||||
<Bar value={ph.progress} tone={ph.outbound ? "red" : "sea"} />
|
||||
<div className="mt-1 font-semibold">
|
||||
{ph.outbound ? `Ankunft in ${fmtDuration(ph.end - now)}` : `Daheim in ${fmtDuration(ph.end - now)}`}
|
||||
<span className="text-ink2 font-normal"> · {fmtTime(ph.end)} Uhr</span>
|
||||
<span className="text-ink2 font-normal"> · {fmtTime(ph.end)}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-1"><UnitChips counts={units} /></div>
|
||||
@@ -123,9 +123,9 @@ export function MissionPanel({ mission, now, home, onClose, onShowTarget }: {
|
||||
<div className="grid grid-cols-[auto_1fr] gap-x-3 gap-y-0.5 items-center mt-2 text-xs">
|
||||
<span className="text-slate-400">Ziel</span><span className="text-right">{name}{m.target.kind !== "kartell" ? ` (Feld ${m.target.col}/${m.target.row})` : ""}</span>
|
||||
<span className="text-slate-400">Heimathafen</span><span className="text-right">Feld {home.col}/{home.row}</span>
|
||||
<span className="text-slate-400">Abfahrt</span><span className="text-right">{fmtTime(m.departAtMs)} Uhr</span>
|
||||
<span className="text-slate-400">Ankunft am Ziel</span><span className="text-right">{fmtTime(m.arriveAtMs)} Uhr{!ph.outbound ? " (erreicht)" : ""}</span>
|
||||
<span className="text-slate-400">Zurück daheim</span><span className="text-right">{m.recalled && ph.outbound ? "–" : `${fmtTime(m.returnAtMs)} Uhr`}</span>
|
||||
<span className="text-slate-400">Abfahrt</span><span className="text-right">{fmtTime(m.departAtMs)}</span>
|
||||
<span className="text-slate-400">Ankunft am Ziel</span><span className="text-right">{fmtTime(m.arriveAtMs)}{!ph.outbound ? " (erreicht)" : ""}</span>
|
||||
<span className="text-slate-400">Zurück daheim</span><span className="text-right">{m.recalled && ph.outbound ? "–" : `${fmtTime(m.returnAtMs)}`}</span>
|
||||
{m.reportId && <span className="col-span-2 text-slate-400">Der Bericht liegt unter Meldungen.</span>}
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -5,7 +5,7 @@ import { hexAtXY, hexDistanceKm } from "@tidefront/world";
|
||||
import { trpc, trpcClient, type BaseData, type Outputs } from "../lib/trpc.ts";
|
||||
import { useCommand } from "../lib/command.ts";
|
||||
import { errorText, fmtNum, label } from "../lib/names.ts";
|
||||
import { fmtDuration, fmtTime, useNow } from "../lib/time.ts";
|
||||
import { fmtDuration, fmtTime, useCountdownNow, useNow } from "../lib/time.ts";
|
||||
import { Button, Card, CountsLine, ErrorLine, Stepper, SmallButton } from "../ui.tsx";
|
||||
import { Icon } from "../icons.tsx";
|
||||
import type { Target } from "../App.tsx";
|
||||
@@ -29,12 +29,13 @@ const resLine = (m: Counts | null | undefined) => {
|
||||
export function BlockadeBanner() {
|
||||
const q = useNaval();
|
||||
const b = q.data?.ownBlockade;
|
||||
if (!b) return null;
|
||||
const now = useCountdownNow(b?.endsAtMs);
|
||||
if (!b || b.endsAtMs <= now) return null; // abgelaufen: ausblenden, bis die nächste Abfrage kommt
|
||||
return (
|
||||
<div className="rounded-[3px] bg-card border border-siegel border-l-4 p-3 mb-3 flex gap-3 items-start" role="status">
|
||||
<Icon id="blockade" size={40} />
|
||||
<div className="text-sm">
|
||||
<div className="font-display uppercase text-siegel text-[12px] tracking-wider">Hafen blockiert bis {fmtTime(b.endsAtMs)}</div>
|
||||
<div className="font-display uppercase text-siegel text-[12px] tracking-wider">Hafen blockiert bis {fmtTime(b.endsAtMs)} · noch {fmtDuration(b.endsAtMs - now)}</div>
|
||||
<p className="text-ink2">Produktion −{Math.round((1 - b.factor) * 100)} %, eingehende Lieferungen werden zurückgehalten, Börsenverkäufe gesperrt. Greife den Blockadeverband über die Karte an – Verbündete können helfen.</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -179,11 +180,12 @@ export function LiftBlockade({ missionId }: { missionId: number }) {
|
||||
const q = useNaval();
|
||||
const lift = useCommand((i: { key: string; blockadeId: number }) => trpcClient.naval.liftBlockade.mutate(i), () => [trpc.base.pathFilter().queryKey, trpc.naval.pathFilter().queryKey]);
|
||||
const b = q.data?.blockades.find((x) => x.role === "own");
|
||||
const now = useNow();
|
||||
void missionId;
|
||||
if (!b) return null;
|
||||
return (
|
||||
<div className="mt-1">
|
||||
<span className="text-xs text-ink2 block">Hält die Blockade vor {b.targetName} noch {fmtDuration(b.endsAtMs - Date.now())}.</span>
|
||||
<span className="text-xs text-ink2 block">Hält die Blockade vor {b.targetName} noch {fmtDuration(b.endsAtMs - now)}.</span>
|
||||
<Button kind="secondary" disabled={lift.busy} onClick={() => void lift.run({ blockadeId: b.id })}>Blockade aufheben</Button>
|
||||
<ErrorLine text={lift.error} code={lift.code} />
|
||||
</div>
|
||||
|
||||
@@ -5,6 +5,7 @@ import { trpc, trpcClient, type BaseData, type Outputs } from "../lib/trpc.ts";
|
||||
import { useCommand } from "../lib/command.ts";
|
||||
import { fmtNum, label } from "../lib/names.ts";
|
||||
import { fmtDuration } from "../lib/time.ts";
|
||||
import { useLiveBase } from "../lib/live-base.ts";
|
||||
import { ActionBar, Badge, Button, Card, ErrorLine, Loading, UnitChips } from "../ui.tsx";
|
||||
import { ActionRemedy, ReasonLine } from "./Remedy.tsx"; // „Was hilft?“
|
||||
import { Icon } from "../icons.tsx";
|
||||
@@ -23,6 +24,7 @@ function Asset({ id, qty }: { id: string; qty: number }) {
|
||||
|
||||
export function PlayerTrade({ base }: { base: BaseData }) {
|
||||
const list = useQuery({ ...trpc.playerTrade.list.queryOptions(), refetchInterval: 60000 });
|
||||
const res = useLiveBase(base).resources; // Bestand live hochgerechnet
|
||||
const me = useQuery(trpc.alliance.get.queryOptions());
|
||||
const prices = usePrices();
|
||||
const [give, setGive] = useState("stahl");
|
||||
@@ -42,7 +44,7 @@ export function PlayerTrade({ base }: { base: BaseData }) {
|
||||
const ownOpen = open.filter((o) => o.own).length;
|
||||
const g = Math.floor(Number(giveQty) || 0);
|
||||
const w = Math.floor(Number(wantQty) || 0);
|
||||
const have = give === "credits" ? base.market.credits : base.resources[give] ?? 0;
|
||||
const have = give === "credits" ? base.market.credits : res[give] ?? 0;
|
||||
const unlocked = base.market.unlocked;
|
||||
// Gesperrt mit bekanntem Grund: der graue Knopf klappt „Was hilft?“ über der Leiste auf.
|
||||
const blockCode = !unlocked ? "locked" : ownOpen >= maxOpen ? "too_many_offers" : g > have ? (give === "credits" ? "funds" : "insufficient_resources") : null;
|
||||
@@ -129,9 +131,10 @@ export function PlayerTrade({ base }: { base: BaseData }) {
|
||||
function OfferRow({ o, fee, base, prices, busy, onAccept, onWithdraw }: { o: Offer; fee: number; base: BaseData; prices: Prices | null; busy: boolean; onAccept: (escort?: Record<string, number>) => void; onWithdraw: () => void }) {
|
||||
const [confirm, setConfirm] = useState(false);
|
||||
const [escort, setEscort] = useState<Record<string, number>>({}); // See: Konvoi – Geleitschutz
|
||||
const res = useLiveBase(base).resources;
|
||||
// Aus Sicht des Lesers: beim eigenen Angebot gibt er give, sonst gibt er want und bekommt give.
|
||||
const v = o.own ? readerValue(prices, o.give, o.giveQty, o.want, o.wantQty) : readerValue(prices, o.want, o.wantQty, o.give, o.giveQty);
|
||||
const have = o.want === "credits" ? base.market.credits : base.resources[o.want] ?? 0;
|
||||
const have = o.want === "credits" ? base.market.credits : res[o.want] ?? 0;
|
||||
const net = o.give === "credits" ? Math.floor(o.giveQty * (1 - fee) * 100) / 100 : o.giveQty - Math.floor(o.giveQty * fee);
|
||||
return (
|
||||
<li className={`py-2.5 pl-2.5 dotted-row border-l-[3px] ${o.own ? "border-l-see" : v?.strong ? (v.pct < 0 ? "border-l-siegel" : "border-l-messing") : "border-l-rule"}`}>
|
||||
|
||||
@@ -6,7 +6,8 @@ import type React from "react";
|
||||
import { BEAUFORT_WORDS, beaufort } from "@tidefront/game-core";
|
||||
import type { BaseData } from "../lib/trpc.ts";
|
||||
import { fmtNum } from "../lib/names.ts";
|
||||
import { serverNow } from "../lib/time.ts";
|
||||
import { fmtAt, fmtDuration, serverNow, useNow } from "../lib/time.ts";
|
||||
import { liveStoredAt } from "../lib/live-base.ts";
|
||||
import { Icon } from "../icons.tsx";
|
||||
import { INK, MESSING, MOOS, SEE, SIEGEL } from "../icons-art.tsx";
|
||||
import { Bar } from "../ui.tsx";
|
||||
@@ -47,7 +48,7 @@ function hourOf(ms: number): number {
|
||||
|
||||
/** Uhrzeit hh:mm in Ortszeit des Geräts. */
|
||||
function clockOf(ms: number): string {
|
||||
return new Date(ms - (serverNow() - Date.now())).toLocaleTimeString("de-DE", { hour: "2-digit", minute: "2-digit" });
|
||||
return fmtAt(ms); // einheitlich, mit „morgen“
|
||||
}
|
||||
|
||||
const sum = (o: Record<string, number>) => Object.values(o).reduce((a, b) => a + b, 0);
|
||||
@@ -81,6 +82,7 @@ export function PowerGrid({ base }: { base: BaseData }) {
|
||||
const meta = useQuery({ ...trpc.meta.queryOptions(), staleTime: Infinity });
|
||||
const windCut = (meta.data?.balance as { buildings?: { windpark?: { stormCutoff?: number } } } | undefined)?.buildings?.windpark?.stormCutoff;
|
||||
const g = base.grid;
|
||||
const stored = liveStoredAt(base, useNow()); // Speicher live hochgerechnet
|
||||
const supply = sum(g.now.supply);
|
||||
const demand = sum(g.now.demand);
|
||||
const short = g.now.served.radar < 1 || g.now.served.production < 1;
|
||||
@@ -104,10 +106,10 @@ export function PowerGrid({ base }: { base: BaseData }) {
|
||||
{g.now.capacity > 0 && (
|
||||
<div>
|
||||
<div className="flex justify-between text-xs text-ink2">
|
||||
<span>Speicher {fmtNum(g.now.stored)} / {fmtNum(g.now.capacity)}</span>
|
||||
<span>Speicher {fmtNum(stored)} / {fmtNum(g.now.capacity)}</span>
|
||||
<span className="mono">{g.now.charge > 0.5 ? `lädt ${fmtNum(g.now.charge)}/h` : g.now.charge < -0.5 ? `liefert ${fmtNum(-g.now.charge)}/h` : "ruht"}</span>
|
||||
</div>
|
||||
<Bar value={g.now.stored / g.now.capacity} tone="green" />
|
||||
<Bar value={stored / g.now.capacity} tone="green" />
|
||||
</div>
|
||||
)}
|
||||
<SurplusNow g={g} />
|
||||
@@ -130,7 +132,7 @@ export function PowerGrid({ base }: { base: BaseData }) {
|
||||
</div>
|
||||
{g.warning ? (
|
||||
<p className="text-xs text-red-300 font-semibold" role="status">
|
||||
{g.warning.atMs - serverNow() < 60000 ? "Jetzt" : `Voraussichtlich ab ${hourOf(g.warning.atMs)} Uhr`} fehlen {fmtNum(g.warning.missing)} Strom – {g.warning.text}
|
||||
{g.warning.atMs - serverNow() < 60000 ? "Jetzt" : `Voraussichtlich ab ${fmtAt(g.warning.atMs)} Uhr (in ${fmtDuration(g.warning.atMs - serverNow())})`} fehlen {fmtNum(g.warning.missing)} Strom – {g.warning.text}
|
||||
</p>
|
||||
) : (
|
||||
<p className="text-xs text-moos">Die nächsten {g.curve.length} Stunden reicht der Strom voraussichtlich.</p>
|
||||
|
||||
@@ -9,19 +9,25 @@ import { Bar, SmallButton } from "../ui.tsx";
|
||||
import { Icon } from "../icons.tsx";
|
||||
import { errorText, fmtNum } from "../lib/names.ts";
|
||||
import type { NavTarget } from "../lib/remedies/types.ts";
|
||||
import { useNow } from "../lib/time.ts";
|
||||
import { liveBaseAt } from "../lib/live-base.ts";
|
||||
|
||||
/** Gibt es zu diesem Code überhaupt einen Hinweis? */
|
||||
export function hasRemedy(code: string | null | undefined): boolean {
|
||||
return !!code && Object.hasOwn(REMEDIES, code);
|
||||
}
|
||||
|
||||
/** Abhilfe zum Code mit aktivem Hafen und Balance (null: nichts zu tun). */
|
||||
/**
|
||||
* Abhilfe zum Code mit aktivem Hafen und Balance (null: nichts zu tun). Live: Bestände werden sekündlich
|
||||
* hochgerechnet, Fehlmengen und Wartezeiten passen sich ohne Neuöffnen an.
|
||||
*/
|
||||
export function useRemedy(code: string | null | undefined, detail?: RemedyDetail): Remedy | null {
|
||||
const { base } = useNav();
|
||||
const known = hasRemedy(code);
|
||||
const meta = useQuery({ ...trpc.meta.queryOptions(), staleTime: Infinity, enabled: known });
|
||||
const now = useNow();
|
||||
if (!known) return null;
|
||||
return remedy(code, { base, balance: (meta.data?.balance ?? null) as CoreBalance | null, detail: detail ?? {}, now: Date.now() });
|
||||
return remedy(code, { base: liveBaseAt(base, now), balance: (meta.data?.balance ?? null) as CoreBalance | null, detail: detail ?? {}, now });
|
||||
}
|
||||
|
||||
/** Klappzustand eines Hinweises, damit auch ein grauer Knopf ihn öffnen kann. */
|
||||
|
||||
@@ -2,6 +2,8 @@ import type { BaseData } from "../lib/trpc.ts";
|
||||
import { fmtNum, label } from "../lib/names.ts";
|
||||
import { RES_ORDER, liveAmount } from "../lib/live.res.ts";
|
||||
import { useState } from "react";
|
||||
import { useNow } from "../lib/time.ts";
|
||||
import { liveStoredAt } from "../lib/live-base.ts";
|
||||
import { Icon } from "../icons.tsx";
|
||||
import { ResourceSheet } from "./ResourceSheet.tsx";
|
||||
import { HarborSwitcher } from "./HarborSwitcher.tsx";
|
||||
@@ -23,10 +25,10 @@ const sum = (o: Record<string, number>) => Object.values(o).reduce((a, b) => a +
|
||||
* Ausgeglichen (Kraftwerk regelt nach, Bilanz 0) steht „gedeckt“; ohne Speicher zeigt die zweite Zeile die
|
||||
* Kraftwerk-Auslastung statt eines Strichs.
|
||||
*/
|
||||
function PowerField({ base, onOpen }: { base: BaseData; onOpen: () => void }) {
|
||||
function PowerField({ base, now, onOpen }: { base: BaseData; now: number; onOpen: () => void }) {
|
||||
const g = base.grid;
|
||||
const bal = Math.round(sum(g.now.supply) - sum(g.now.demand));
|
||||
const fill = g.now.capacity > 0 ? Math.min(1, g.now.stored / g.now.capacity) : 0;
|
||||
const fill = g.now.capacity > 0 ? Math.min(1, liveStoredAt(base, now) / g.now.capacity) : 0; // Speicher live
|
||||
const warn = g.warning;
|
||||
const sign = bal > 0 ? "+" : bal < 0 ? "−" : "±";
|
||||
const demand = Math.round(sum(g.now.demand));
|
||||
@@ -58,9 +60,10 @@ function PowerField({ base, onOpen }: { base: BaseData; onOpen: () => void }) {
|
||||
}
|
||||
|
||||
/** Kopfleiste: Hafenwahl (ab zwei Häfen), Papierstreifen mit vier Ressourcen (Stich, Bestand, Rate, Füllstand), Stromfeld und Menü. */
|
||||
export function ResourceBar({ base, asOf, now, onMenu, onSwitchBase, onPlanFounding, onPower }: { base: BaseData; asOf: number; now: number; onMenu: (item: MenuItem) => void; onSwitchBase: (id: number) => void; onPlanFounding: () => void; onPower: () => void }) {
|
||||
export function ResourceBar({ base, asOf, onMenu, onSwitchBase, onPlanFounding, onPower }: { base: BaseData; asOf: number; onMenu: (item: MenuItem) => void; onSwitchBase: (id: number) => void; onPlanFounding: () => void; onPower: () => void }) {
|
||||
const [open, setOpen] = useState<string | null>(null);
|
||||
const [menu, setMenu] = useState(false);
|
||||
const now = useNow(); // gemeinsame Uhr: Bestände sekündlich hochgerechnet
|
||||
return (
|
||||
<header className="sticky top-0 z-30 bg-paper border-b-[3px] border-double border-ink" style={{ paddingTop: "env(safe-area-inset-top)" }}>
|
||||
<HarborSwitcher base={base} now={now} onSwitch={onSwitchBase} onPlanFounding={onPlanFounding} />
|
||||
@@ -85,7 +88,7 @@ export function ResourceBar({ base, asOf, now, onMenu, onSwitchBase, onPlanFound
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
<PowerField base={base} onOpen={onPower} />
|
||||
<PowerField base={base} now={now} onOpen={onPower} />
|
||||
<button type="button" onClick={() => setMenu(true)} aria-haspopup="dialog" aria-expanded={menu}
|
||||
className="tap shrink-0 rounded-lg border border-ink text-ink flex flex-col items-center justify-center gap-[3px] px-1">
|
||||
<span aria-hidden className="flex flex-col gap-[3px] w-4">{[0, 1, 2].map((i) => <span key={i} className="block h-[2px] bg-ink rounded-full" />)}</span>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { trpc, type BaseData } from "../lib/trpc.ts";
|
||||
import { fmtNum, label } from "../lib/names.ts";
|
||||
import { fmtDuration, fmtTime } from "../lib/time.ts";
|
||||
import { fmtDuration, fmtTime, serverNow } from "../lib/time.ts";
|
||||
import { Bar, Sheet } from "../ui.tsx";
|
||||
import { Icon } from "../icons.tsx";
|
||||
|
||||
@@ -57,7 +57,7 @@ export function ResourceSheet({ base, res, amount, onClose }: { base: BaseData;
|
||||
const fill = Math.min(1, amount / Math.max(1, cap));
|
||||
const price = market.data?.resources.find((r) => r.id === res)?.price;
|
||||
const powerCut = base.power && base.power.factor < 0.999 && building > 0;
|
||||
const now = Date.now();
|
||||
const now = serverNow();
|
||||
const untilFull = net > 0 && amount < cap ? ((cap - amount) / net) * 3600000 : null;
|
||||
const untilEmpty = net < 0 && amount > 0 ? (amount / -net) * 3600000 : null;
|
||||
const prodMods = base.modifierSources
|
||||
@@ -79,9 +79,9 @@ export function ResourceSheet({ base, res, amount, onClose }: { base: BaseData;
|
||||
{fill >= 0.999
|
||||
? <span className="text-messing">Lager voll – Produktion geht verloren. Lagerkomplex ausbauen oder verkaufen.</span>
|
||||
: untilFull !== null
|
||||
? <>Voll in {fmtDuration(untilFull)} <span className="text-ink2">· {fmtTime(now + untilFull)} Uhr</span></>
|
||||
? <>Voll in {fmtDuration(untilFull)} <span className="text-ink2">· {fmtTime(now + untilFull)}</span></>
|
||||
: untilEmpty !== null
|
||||
? <span className="text-siegel">Leer in {fmtDuration(untilEmpty)} · {fmtTime(now + untilEmpty)} Uhr</span>
|
||||
? <span className="text-siegel">Leer in {fmtDuration(untilEmpty)} · {fmtTime(now + untilEmpty)}</span>
|
||||
: <span className="text-ink2">Bestand bleibt gleich.</span>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
// Lagergrenze des Heimathafens). Vor dem Abholen: was je Ressource verfiele, mit Bestand/Kapazität des
|
||||
// Heimathafens, Knopf „Lagerkomplex ausbauen“ und „Trotzdem abholen“. Nach dem Abholen: lostNote() für die Bestätigung.
|
||||
import { useNav } from "../lib/nav.ts";
|
||||
import { useNow } from "../lib/time.ts";
|
||||
import { liveBaseAt } from "../lib/live-base.ts";
|
||||
import type { BaseData } from "../lib/trpc.ts";
|
||||
import { setActiveBase } from "../lib/active-base.ts";
|
||||
import { fmtNum, label } from "../lib/names.ts";
|
||||
import { Icon } from "../icons.tsx";
|
||||
@@ -35,6 +38,18 @@ export function overflowOf(storage: RewardStorage, rewards: Reward[]): Overflow[
|
||||
return [...out.values()].filter((o) => Math.round(o.lost) > 0).map((o) => ({ ...o, lost: Math.round(o.lost) }));
|
||||
}
|
||||
|
||||
/**
|
||||
* Lager des Heimathafens live: Ist der Heimathafen gerade aktiv, gelten seine hochgerechneten Bestände (die Ansicht
|
||||
* der Belohnungen kennt nur den Stand ihrer Abfrage); sonst bleibt der gelieferte Stand.
|
||||
*/
|
||||
export function liveStorage(storage: RewardStorage, active: BaseData | null, now: number): RewardStorage {
|
||||
if (!storage || !active?.isHome) return storage;
|
||||
const live = liveBaseAt(active, now);
|
||||
const resources = { ...storage.resources };
|
||||
for (const id of Object.keys(resources)) if (typeof live.resources[id] === "number") resources[id] = live.resources[id];
|
||||
return { ...storage, capacity: live.capacity, resources };
|
||||
}
|
||||
|
||||
/** Satz für die Bestätigung nach dem Abholen, oder "" wenn nichts verfallen ist. */
|
||||
export function lostNote(lost: Record<string, number> | null | undefined): string {
|
||||
const parts = Object.entries(lost ?? {}).filter(([, n]) => Math.round(n) > 0).map(([id, n]) => `${fmtNum(Math.round(n))} ${label(id)}`);
|
||||
@@ -47,7 +62,8 @@ export function lostNote(lost: Record<string, number> | null | undefined): strin
|
||||
*/
|
||||
export function RewardClaim(props: { storage: RewardStorage; rewards: Reward[]; busy: boolean; onClaim: () => void; onExpand?: () => void; className?: string }) {
|
||||
const nav = useNav();
|
||||
const over = overflowOf(props.storage, props.rewards);
|
||||
const now = useNow();
|
||||
const over = overflowOf(liveStorage(props.storage, nav.base, now), props.rewards);
|
||||
const expand = () => {
|
||||
// Belohnungen gehen in den Heimathafen: dort ausbauen.
|
||||
if (nav.base && !nav.base.isHome) setActiveBase(null);
|
||||
|
||||
@@ -20,8 +20,7 @@ export function awardTone(a: string): string {
|
||||
function remaining(endsAtMs: number, now: number): string {
|
||||
const ms = endsAtMs - now;
|
||||
if (ms <= 0) return "endet gleich";
|
||||
const days = Math.floor(ms / DAY);
|
||||
return days >= 2 ? `noch ${days} Tage` : `noch ${fmtDuration(ms)}`;
|
||||
return `noch ${fmtDuration(ms)}`; // einheitlich: „noch 5 T 3 h“
|
||||
}
|
||||
|
||||
/** Saisonleiste für die Rangliste. */
|
||||
|
||||
@@ -55,7 +55,7 @@ export function SpyPlan({ base, map, target, setTarget, center, onClose }: { bas
|
||||
const input = kind === "kartell"
|
||||
? { kind }
|
||||
: target && !target.eventId ? { kind, col: target.col, row: target.row, ...(kind === "sabotage" ? { building } : {}) } : null;
|
||||
const preview = useQuery({ ...trpc.espionage.preview.queryOptions(input ?? { kind }), enabled: !!input, placeholderData: keepPreviousData });
|
||||
const preview = useQuery({ ...trpc.espionage.preview.queryOptions(input ?? { kind }), enabled: !!input, placeholderData: keepPreviousData, refetchInterval: 60_000 }); // Ankunftszeit aktuell
|
||||
const launch = useCommand(
|
||||
(i: { key: string; kind: Kind; col?: number; row?: number; building?: string }) => trpcClient.espionage.launch.mutate(i),
|
||||
() => [trpc.base.pathFilter().queryKey],
|
||||
|
||||
@@ -5,7 +5,7 @@ import { useQuery } from "@tanstack/react-query";
|
||||
import { trpc, type BaseData } from "../lib/trpc.ts";
|
||||
import { fmtNum, label } from "../lib/names.ts";
|
||||
import { isThreat, TRANSFER } from "../lib/expansion.ts"; // Mehrere Häfen
|
||||
import { fmtDuration, fmtTime, useNow } from "../lib/time.ts";
|
||||
import { fmtAt, fmtDuration, useNow } from "../lib/time.ts";
|
||||
import { Icon } from "../icons.tsx";
|
||||
import { Card, SmallButton } from "../ui.tsx";
|
||||
|
||||
@@ -78,7 +78,7 @@ export function Timeline({ base, limit = SHOWN }: { base: BaseData; limit?: numb
|
||||
<span className={`flex-1 min-w-0 text-sm truncate ${i.alert ? "text-siegel font-semibold" : ""}`}>{i.text}</span>
|
||||
<span className="text-right leading-tight">
|
||||
<span className={`block mono text-[13px] ${i.alert ? "text-siegel" : ""}`}>{i.atMs <= now ? "jetzt" : fmtDuration(i.atMs - now)}</span>
|
||||
<span className="block mono text-[11px] text-ink2">{fmtTime(i.atMs)}</span>
|
||||
<span className="block mono text-[11px] text-ink2">{fmtAt(i.atMs, now)}</span>
|
||||
</span>
|
||||
</li>
|
||||
))}
|
||||
|
||||
@@ -8,6 +8,7 @@ import { trpc, trpcClient, type BaseData, type Balance } from "../lib/trpc.ts";
|
||||
import { useCommand } from "../lib/command.ts";
|
||||
import { fmtNum, label } from "../lib/names.ts";
|
||||
import { fmtDuration, fmtSeconds } from "../lib/time.ts";
|
||||
import { useLiveBase } from "../lib/live-base.ts";
|
||||
import { Button, Card, Cost, ErrorLine, Sheet, StatTable, Stepper, UnitChips } from "../ui.tsx";
|
||||
import { ActionRemedy, ReasonLine, useWhatHelps } from "./Remedy.tsx"; // „Was hilft?“
|
||||
import { Icon, IconTile } from "../icons.tsx";
|
||||
@@ -98,9 +99,10 @@ function TrainRow(props: { id: string; have: number; away: number; base: BaseDat
|
||||
const cmd = useCommand((i: { key: string; id: string; count: number }) => trpcClient.base.train.mutate(i), invalidateBase);
|
||||
const [info, setInfo] = useState(false);
|
||||
const vet = props.base.veterans?.find((v) => v.id === props.id);
|
||||
const res = useLiveBase(props.base).resources; // hochgerechnet: Höchstmenge und Rotfärbung live
|
||||
// Bezahlbare Höchstmenge: begrenzt die Eingabe, damit Kosten und Bauzeit sinnvoll bleiben.
|
||||
const afford = Object.entries(props.cost ?? {}).reduce(
|
||||
(m, [r, v]) => (v > 0 ? Math.min(m, Math.floor((props.base.resources[r] ?? 0) / v)) : m),
|
||||
(m, [r, v]) => (v > 0 ? Math.min(m, Math.floor((res[r] ?? 0) / v)) : m),
|
||||
MAX_TRAIN,
|
||||
);
|
||||
const why = props.busy
|
||||
@@ -144,7 +146,7 @@ function TrainRow(props: { id: string; have: number; away: number; base: BaseDat
|
||||
</div>
|
||||
{n >= 1 && !props.needLevel && (
|
||||
<div className="flex justify-between gap-2 mt-1 pl-12">
|
||||
<Cost cost={scale(props.cost, n)} have={props.base.resources} />
|
||||
<Cost cost={scale(props.cost, n)} have={res} />
|
||||
{props.secondsEach !== null && <span className="text-xs text-slate-400 flex items-center gap-1 shrink-0"><Icon id="uhr" size={14} /> {fmtSeconds(props.secondsEach * n)}</span>}
|
||||
</div>
|
||||
)}
|
||||
@@ -160,7 +162,7 @@ function TrainRow(props: { id: string; have: number; away: number; base: BaseDat
|
||||
<div className="mt-2">
|
||||
<StatTable rows={unitStats(props.balance, props.id).filter(([k]) => !BROKEN_DOWN.test(k)).map(([k, v]) => [k.replace(/^Bonus gegen (.*)$/, (_m, t: string) => `Bonus gegen ${label(t)}`), v])} />
|
||||
</div>
|
||||
<div className="mt-3 text-sm flex flex-wrap items-center gap-x-2"><span className="text-slate-400">Kosten je Stück: </span><Cost cost={props.cost} have={props.base.resources} /></div>
|
||||
<div className="mt-3 text-sm flex flex-wrap items-center gap-x-2"><span className="text-slate-400">Kosten je Stück: </span><Cost cost={props.cost} have={res} /></div>
|
||||
{props.secondsEach !== null && <div className="mt-1 text-sm flex items-center gap-1"><Icon id="uhr" size={16} /> {fmtSeconds(props.secondsEach)} je Stück</div>}
|
||||
{!props.needLevel && <p className="text-xs text-ink2 mt-1">Bezahlbar: bis {fmtNum(Math.max(0, afford))} Stück.</p>}
|
||||
</Sheet>
|
||||
|
||||
@@ -6,6 +6,7 @@ import type { WinSearchResult } from "@tidefront/game-core";
|
||||
import type { Balance, BaseData } from "../lib/trpc.ts";
|
||||
import { countLabel, fmtNum } from "../lib/names.ts";
|
||||
import { fmtSeconds } from "../lib/time.ts";
|
||||
import { useLiveBase } from "../lib/live-base.ts";
|
||||
import { runWinSearch } from "../lib/sim-client.ts";
|
||||
import { winInput, type WinTarget } from "../lib/win-input.ts";
|
||||
import { setTrainPreset } from "../lib/train-request.ts";
|
||||
@@ -89,6 +90,7 @@ export function WinSearch({ target, base, balance, planAt, title = "Was fehlt zu
|
||||
|
||||
function WinResult({ r, goal, ms, base, planAt, onTrain, onPlan }: { r: WinSearchResult; goal: number; ms: number; base: BaseData; planAt?: Target | null; onTrain: () => void; onPlan?: () => void }) {
|
||||
const need = Object.keys(r.extra).length > 0;
|
||||
const res = useLiveBase(base).resources; // Rotfärbung der Kosten live
|
||||
return (
|
||||
<div className="space-y-2 text-sm" data-testid="win-search-result">
|
||||
{!r.reachable ? (
|
||||
@@ -100,7 +102,7 @@ function WinResult({ r, goal, ms, base, planAt, onTrain, onPlan }: { r: WinSearc
|
||||
<div>
|
||||
<p><span className="text-ink2">Es fehlen:</span> <strong data-testid="win-search-extra">{extraText(r.extra)}</strong></p>
|
||||
<div className="flex flex-wrap items-center gap-x-3 gap-y-1 mt-0.5">
|
||||
<Cost cost={r.extraCost} have={base.resources} />
|
||||
<Cost cost={r.extraCost} have={res} />
|
||||
<span className="text-xs text-ink2 inline-flex items-center gap-1"><Icon id="uhr" size={14} /> {fmtSeconds(r.trainSeconds)} Ausbildung</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -12,7 +12,7 @@ import { hexCenter, seaRoute } from "@tidefront/world";
|
||||
import type { Balance, BaseData, MapData } from "../../lib/trpc.ts";
|
||||
import type { Target } from "../../App.tsx";
|
||||
import { countLabel, fmtNum } from "../../lib/names.ts";
|
||||
import { fmtDuration } from "../../lib/time.ts";
|
||||
import { fmtDuration, serverNow } from "../../lib/time.ts";
|
||||
import { requestPlan } from "../../lib/plan-request.ts";
|
||||
import { nearestNests, suggestRaid, suggestScout, travelMs, type Counts, type NestInfo } from "../../lib/strike.ts";
|
||||
import type { NestPlan, PlanJob } from "../../lib/raid-plan.ts";
|
||||
@@ -49,7 +49,7 @@ function usePlans(rows: Row[], base: BaseData, balance: Balance): Record<string,
|
||||
const [out, setOut] = useState<Record<string, NestPlan | null>>({});
|
||||
const sig = JSON.stringify(rows.map((r) => [r.key, r.nest.level, r.full, r.nest.lagebild?.atMs ?? null])) + JSON.stringify(base.modifiers ?? {}) + String(base.versorgungsmangel);
|
||||
useEffect(() => {
|
||||
const now = Date.now();
|
||||
const now = serverNow();
|
||||
const jobs: PlanJob[] = rows.filter((r) => r.nest.level !== null && Object.keys(r.full).length > 0).map((r) => {
|
||||
const t = travelMs(r.full, r.nest.distanceKm, balance, base.modifiers);
|
||||
const at = hexCenter(r.nest.col, r.nest.row);
|
||||
@@ -153,7 +153,7 @@ function TargetRow({ row, plan, base, balance, onShowOnMap }: { row: Row; plan:
|
||||
{known && (
|
||||
<details className="mt-0.5 text-xs" data-testid="ziel-details">
|
||||
<summary className="cursor-pointer text-ink2">Details</summary>
|
||||
<NestIntel level={nest.level!} lagebild={nest.lagebild} now={Date.now()} balance={balance} compact />
|
||||
<NestIntel level={nest.level!} lagebild={nest.lagebild} now={serverNow()} balance={balance} compact />
|
||||
{plan?.worth && <p className="text-[11px] text-ink2 mt-0.5">Beute bei Sieg ≈ {fmtNum(Math.round(plan.worth.loot[0]))}{plan.worth.loot[1] > plan.worth.loot[0] + 1 ? `–${fmtNum(Math.round(plan.worth.loot[1]))}` : ""} · Verluste ≈ {fmtNum(Math.round(plan.worth.loss))} · Treibstoff ≈ {fmtNum(Math.round(plan.worth.fuel))} (Richtpreis)</p>}
|
||||
</details>
|
||||
)}
|
||||
@@ -178,7 +178,7 @@ function TargetRow({ row, plan, base, balance, onShowOnMap }: { row: Row; plan:
|
||||
/** Kurzzeile: Lagebild-Alter, Spanne der Siegchance, Netto. */
|
||||
function WorthLine({ nest, plan }: { nest: NestInfo; plan: NestPlan | null | undefined }) {
|
||||
const parts: string[] = [];
|
||||
if (nest.lagebild) parts.push(`Lagebild ${agoText(nest.lagebild.atMs, Date.now())}`);
|
||||
if (nest.lagebild) parts.push(`Lagebild ${agoText(nest.lagebild.atMs, serverNow())}`);
|
||||
else parts.push("nur Erkennung");
|
||||
if (plan?.range) parts.push(`Sieg ${pct(plan.range.min)}–${pct(plan.range.max)}, Ø ${pct(plan.range.mean)}`);
|
||||
const w = plan?.worth;
|
||||
|
||||
@@ -15,6 +15,8 @@ import { Loading } from "../../ui.tsx";
|
||||
import type { Target } from "../../App.tsx";
|
||||
import type { MeldungenTab } from "../../screens/Meldungen.tsx";
|
||||
import { LageGroup, LageLine, type LageJump, type LageRow } from "./LageList.tsx";
|
||||
import { useEffect, useState } from "react";
|
||||
import { readLageSeen, useLageSeen, writeLageSeen } from "../../lib/lage-seen.ts";
|
||||
|
||||
const RECENT = 5;
|
||||
const REPORT_ICON: Record<string, string> = { ueberfall: "ueberfall", kartell: "kartell", aufklaerung: "aufklaerung", transport: "transport", spionage: "spionage", sabotage: "sabotage", konvoi: "konvoi", blockade: "blockade", minen: "mine", patrouille: "patrouille", satellit: "satellit", sichtung: "sichtung" };
|
||||
@@ -35,6 +37,13 @@ export function LageTab({ onShowOnMap, onSub, unreadMsgs, seenReport }: {
|
||||
const reports = useQuery({ ...trpc.report.list.queryOptions(), refetchInterval: 60000 });
|
||||
const daily = useDaily();
|
||||
const guide = useGuide();
|
||||
// Stand beim letzten Öffnen: Einträge, die seitdem dazugekommen sind, tragen „neu“ (erster Besuch: keine Markierung).
|
||||
const [before] = useState(() => readLageSeen());
|
||||
const quests0 = (daily.data?.claimable ?? 0) + (guide.data?.claimable ?? 0);
|
||||
const allKeys = lage.data ? [...lage.data.soon, ...lage.data.underway, ...lage.data.waiting].map((r) => r.key).concat(lage.data.urgent.keys, quests0 > 0 ? [`belohnung:quests:${quests0}`] : []) : null;
|
||||
const sig = allKeys?.join("|") ?? "";
|
||||
useEffect(() => { if (allKeys) writeLageSeen(allKeys, Date.now()); }, [sig]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
const isNew = (key: string) => before !== null && !before.keys.includes(key);
|
||||
if (!lage.data) return <Loading cards={3} error={lage.error ?? undefined} onRetry={() => void lage.refetch()} />;
|
||||
|
||||
/** Mehrere Häfen: vor dem Sprung den betroffenen Hafen aktiv machen (Heimathafen = null). */
|
||||
@@ -82,17 +91,17 @@ export function LageTab({ onShowOnMap, onSub, unreadMsgs, seenReport }: {
|
||||
)}
|
||||
{soon.length > 0 && (
|
||||
<LageGroup title="Gleich / heute" count={soon.length} testId="lage-soon">
|
||||
{soon.map((r) => <LageLine key={r.key} row={r} nowMs={now} onJump={jump} />)}
|
||||
{soon.map((r) => <LageLine key={r.key} row={r} nowMs={now} onJump={jump} unread={isNew(r.key)} />)}
|
||||
</LageGroup>
|
||||
)}
|
||||
{underway.length > 0 && (
|
||||
<LageGroup title="Unterwegs" count={underway.length} testId="lage-underway">
|
||||
{underway.map((r) => <LageLine key={r.key} row={r} nowMs={now} onJump={jump} />)}
|
||||
{underway.map((r) => <LageLine key={r.key} row={r} nowMs={now} onJump={jump} unread={isNew(r.key)} />)}
|
||||
</LageGroup>
|
||||
)}
|
||||
{waiting.length > 0 && (
|
||||
<LageGroup title="Wartet auf dich" count={waiting.length} testId="lage-waiting">
|
||||
{waiting.map((r) => <LageLine key={r.key} row={r} nowMs={now} onJump={jump} onTap={r.kind === "nachrichten" ? () => onSub("nachrichten") : undefined} />)}
|
||||
{waiting.map((r) => <LageLine key={r.key} row={r} nowMs={now} onJump={jump} unread={isNew(r.key)} onTap={r.kind === "nachrichten" ? () => onSub("nachrichten") : undefined} />)}
|
||||
</LageGroup>
|
||||
)}
|
||||
{recent.length > 0 && (
|
||||
@@ -111,7 +120,10 @@ export function LageTab({ onShowOnMap, onSub, unreadMsgs, seenReport }: {
|
||||
/** Zahl am Navigationszeichen „Meldungen“: nur Dringendes (Angriff, abholbereit, Nachfrist, leere Bauschlange). */
|
||||
export function useLageBadge(enabled: boolean, quests: number): { count: number; attack: boolean } {
|
||||
const q = useQuery({ ...trpc.lage.badge.queryOptions(), enabled, refetchInterval: 60000 });
|
||||
const seen = useLageSeen();
|
||||
const u = q.data;
|
||||
const count = (u ? u.attacks + u.grace + u.idleQueues + u.rewards : 0) + quests;
|
||||
// Nur, was seit dem letzten Öffnen der Lage neu ist; laufende Angriffe zählen immer (Sicherheit).
|
||||
const keys = [...(u?.keys ?? []), ...(quests > 0 ? [`belohnung:quests:${quests}`] : [])];
|
||||
const count = keys.filter((k) => k.startsWith("angriff:") || !seen.has(k)).length;
|
||||
return { count, attack: (u?.attacks ?? 0) > 0 };
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
// Die Regeln selbst prüft der Server; hier wird nur vorab erklärt, was er ablehnen würde.
|
||||
import { market } from "@tidefront/game-core";
|
||||
import type { Outputs } from "../../lib/trpc.ts";
|
||||
import { fmtAt } from "../../lib/time.ts";
|
||||
|
||||
export type MarketRes = Outputs["market"]["get"]["resources"][number];
|
||||
export type MarketCfg = {
|
||||
@@ -147,13 +148,9 @@ export function clock(ms: number): string {
|
||||
return new Date(ms).toLocaleTimeString("de-DE", { hour: "2-digit", minute: "2-digit" });
|
||||
}
|
||||
|
||||
/** Uhrzeit mit „morgen“ bzw. Datum, wenn nicht heute. */
|
||||
/** Uhrzeit mit „morgen“ bzw. Datum, wenn nicht heute – das einheitliche Format aus lib/time.ts (fmtAt). */
|
||||
export function when(ms: number, nowMs: number): string {
|
||||
const d = new Date(ms);
|
||||
const n = new Date(nowMs);
|
||||
const days = Math.round((new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime() - new Date(n.getFullYear(), n.getMonth(), n.getDate()).getTime()) / DAY);
|
||||
const prefix = days === 0 ? "" : days === 1 ? "morgen " : `${d.toLocaleDateString("de-DE", { day: "numeric", month: "numeric" })} `;
|
||||
return `${prefix}${clock(ms)}`;
|
||||
return fmtAt(ms, nowMs);
|
||||
}
|
||||
|
||||
/** Pfeil und Wort für eine Veränderung (nicht nur Farbe). */
|
||||
|
||||
Reference in new issue
Block a user