Skip to content

Commit 20bc552

Browse files
authored
feat(webchat): pass-through visitors - strangers and the crab (#103352)
Roughly one load in ten, someone else walks across the footer ledge once and leaves: usually a stranger lobster wearing a palette the resident pet does not (hover: 'a stranger'), and on rare loads a crab (hover: 'definitely a lobster') - wide shell, eye stalks, walks strictly sideways, smug about it. Passers never perch, never react, and never count for the Lobsterdex. Planned by a pure per-seed function, gated by the visits setting, skipped under reduced motion, and their timers reset with the seed and clean up on disconnect.
1 parent 514829f commit 20bc552

3 files changed

Lines changed: 263 additions & 2 deletions

File tree

‎ui/src/components/lobster-pet.test.ts‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {
1111
isLobsterTwinLoad,
1212
lobsterPetName,
1313
lobsterPetSeed,
14+
planLobsterPasser,
15+
strangerLookFor,
1416
resolveLobsterPetMode,
1517
resolveLobsterRunOutcome,
1618
type LobsterPet,
@@ -639,6 +641,69 @@ describe("lobster pet element", () => {
639641
expect(element.querySelector(".lobster-pet")?.getAttribute("style")).toContain("--lob-face:-1");
640642
});
641643

644+
it("a stranger crosses once and is never recorded", async () => {
645+
vi.useFakeTimers();
646+
vi.setSystemTime(new Date("2026-07-09T12:00:00"));
647+
vi.stubGlobal("localStorage", window.localStorage);
648+
// Seed 9 plans a stranger crossing at ~98s (probed via the pure planner).
649+
const plan = planLobsterPasser(9);
650+
expect(plan?.kind).toBe("stranger");
651+
const element = createPet(9);
652+
await element.updateComplete;
653+
654+
await vi.advanceTimersByTimeAsync((plan?.atMs ?? 0) + 500);
655+
await element.updateComplete;
656+
const passer = element.querySelector(".lobster-pet--passer");
657+
expect(passer).not.toBeNull();
658+
expect(passer?.getAttribute("title")).toBe("a stranger");
659+
expect(passer?.className).not.toContain("lobster-pet--crab");
660+
661+
// Strangers wear someone else's palette and never enter the dex; the
662+
// resident pet may have logged itself during the advance, so assert the
663+
// stranger's palette specifically stays out.
664+
const own = createLobsterPetLook(9, new Date("2026-07-09T12:00:00"));
665+
const strangerPalette = strangerLookFor(9, own.palette.id).palette.id;
666+
expect(strangerPalette).not.toBe(own.palette.id);
667+
expect(getLobsterdex().has(strangerPalette)).toBe(false);
668+
669+
await vi.advanceTimersByTimeAsync(12_000);
670+
await element.updateComplete;
671+
expect(element.querySelector(".lobster-pet--passer")).toBeNull();
672+
});
673+
674+
it("the crab is definitely a lobster and also not recorded", async () => {
675+
vi.useFakeTimers();
676+
vi.setSystemTime(new Date("2026-07-09T12:00:00"));
677+
vi.stubGlobal("localStorage", window.localStorage);
678+
const plan = planLobsterPasser(119);
679+
expect(plan?.kind).toBe("crab");
680+
const element = createPet(119);
681+
await element.updateComplete;
682+
683+
await vi.advanceTimersByTimeAsync((plan?.atMs ?? 0) + 500);
684+
await element.updateComplete;
685+
const crab = element.querySelector(".lobster-pet--crab");
686+
expect(crab).not.toBeNull();
687+
expect(crab?.getAttribute("title")).toBe("definitely a lobster");
688+
// The resident pet may have visited during the advance; whatever is in
689+
// the dex must be its own palette. Crabs are not acknowledged.
690+
const own = createLobsterPetLook(119, new Date("2026-07-09T12:00:00")).palette.id;
691+
expect([...getLobsterdex()].every((id) => id === own)).toBe(true);
692+
});
693+
694+
it("most loads see no passer at all", async () => {
695+
expect(planLobsterPasser(0)).toBeNull();
696+
let passers = 0;
697+
for (let seed = 0; seed < 2000; seed++) {
698+
if (planLobsterPasser(seed)) {
699+
passers++;
700+
}
701+
}
702+
// ~9.5% of loads get one visitor; crabs are a rare slice of that.
703+
expect(passers).toBeGreaterThan(60);
704+
expect(passers).toBeLessThan(2000 * 0.2);
705+
});
706+
642707
it("stays static when reduced motion is preferred, including visibility resumes", async () => {
643708
vi.useFakeTimers();
644709
vi.stubGlobal(

‎ui/src/components/lobster-pet.ts‎

Lines changed: 142 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ export const LOBSTER_PET_CLAW_MULS: Record<LobsterPetClawSize, number> = {
288288
const SPOT_ZONES = { left: [12, 38], right: [60, 84] } as const;
289289
const ENTER_MS = 450;
290290
const LEAVE_MS = 350;
291+
// One full ledge crossing for pass-through visitors.
292+
const PASSER_CROSS_MS = 11_000;
291293

292294
export type LobsterPetAnchor = "ledge" | "bar";
293295

@@ -360,6 +362,40 @@ export function isLobsterTwinLoad(seed: number): boolean {
360362
return mulberry32((seed ^ 0x7715) >>> 0)() < 0.04;
361363
}
362364

365+
export type LobsterPasserKind = "stranger" | "crab";
366+
367+
export type LobsterPasserPlan = {
368+
kind: LobsterPasserKind;
369+
atMs: number;
370+
direction: 1 | -1;
371+
};
372+
373+
// Once per load, someone else might just... walk through. Strangers are
374+
// other lobsters that never stop; the crab is not a lobster and refuses to
375+
// discuss it. Neither counts for the Lobsterdex.
376+
export function planLobsterPasser(seed: number): LobsterPasserPlan | null {
377+
const rng = mulberry32((seed ^ 0xcab) >>> 0);
378+
const roll = rng();
379+
if (roll >= 0.095) {
380+
return null;
381+
}
382+
const kind: LobsterPasserKind = roll < 0.015 ? "crab" : "stranger";
383+
const atMs = Math.round(60_000 + rng() * 840_000);
384+
const direction: 1 | -1 = rng() < 0.5 ? 1 : -1;
385+
return { kind, atMs, direction };
386+
}
387+
388+
// A stranger wears a different palette than the resident pet.
389+
export function strangerLookFor(seed: number, own: LobsterPetPaletteId): LobsterPetLook {
390+
for (let offset = 1; offset <= 24; offset++) {
391+
const look = createLobsterPetLook((seed + offset * 7919) >>> 0);
392+
if (look.palette.id !== own) {
393+
return look;
394+
}
395+
}
396+
return createLobsterPetLook((seed + 1) >>> 0);
397+
}
398+
363399
// Late-night visitors are always sleepy, whatever their daytime personality.
364400
export function isLobsterNightTime(now: Date = new Date()): boolean {
365401
const hour = now.getHours();
@@ -644,6 +680,45 @@ const ANTENNAE_SPRITES: Record<LobsterPetAntennae, TemplateResult> = {
644680
`,
645681
};
646682

683+
// Not a lobster. Wide shell, eye stalks, walks sideways across the ledge,
684+
// and the Lobsterdex refuses to acknowledge it.
685+
export function renderCrabSvg() {
686+
return svg`
687+
<svg
688+
class="lobster-pet__svg"
689+
viewBox="0 0 120 105"
690+
preserveAspectRatio="none"
691+
aria-hidden="true"
692+
>
693+
<g stroke="#a63a2e" stroke-width="4" stroke-linecap="round" fill="none">
694+
<path d="M22 78 L8 88" />
695+
<path d="M28 88 L16 99" />
696+
<path d="M98 78 L112 88" />
697+
<path d="M92 88 L104 99" />
698+
</g>
699+
<g stroke="#c44536" stroke-width="3.5" stroke-linecap="round" fill="none">
700+
<path d="M44 38 L40 24" />
701+
<path d="M76 38 L80 24" />
702+
</g>
703+
<circle cx="40" cy="22" r="4.5" fill="#0a1014" />
704+
<circle cx="80" cy="22" r="4.5" fill="#0a1014" />
705+
<circle cx="41.5" cy="20.5" r="1.8" fill="#ffd166" />
706+
<circle cx="81.5" cy="20.5" r="1.8" fill="#ffd166" />
707+
<ellipse cx="60" cy="70" rx="46" ry="30" fill="#c44536" />
708+
<ellipse cx="48" cy="60" rx="16" ry="9" fill="#ffffff" opacity="0.1" />
709+
<path
710+
d="M16 58 C2 52 -2 62 4 72 C10 82 20 76 24 66 C26 60 22 58 16 58 Z"
711+
fill="#d95f4b"
712+
/>
713+
<path
714+
d="M104 58 C118 52 122 62 116 72 C110 82 100 76 96 66 C94 60 98 58 104 58 Z"
715+
fill="#d95f4b"
716+
/>
717+
<path d="M48 82 Q60 90 72 82" stroke="#7e2a20" stroke-width="3" stroke-linecap="round" fill="none" />
718+
</svg>
719+
`;
720+
}
721+
647722
// Same species as icons.lobster / the dreams-scene sleeper: smooth dome body
648723
// with stubby legs, side claws, antennae, and teal-glint eyes.
649724
export function renderLobsterSvg(
@@ -738,13 +813,16 @@ export class LobsterPet extends LitElement {
738813
@state() private dismissed = false;
739814
@state() private grumpy = false;
740815
@state() private vigil = false;
816+
@state() private passer: LobsterPasserPlan | null = null;
741817
@state() private shellVisible = false;
742818
private shellSpotPct = 50;
743819
private shellScale = 2;
744820
private molted = false;
745821
private moltPlanned = false;
746822
private twinPlanned = false;
747823
private shellTimer: number | null = null;
824+
private passerTimer: number | null = null;
825+
private passerEndTimer: number | null = null;
748826

749827
private look: LobsterPetLook | null = null;
750828
private rng: () => number = mulberry32(0);
@@ -780,13 +858,15 @@ export class LobsterPet extends LitElement {
780858
window.clearTimeout(this.shellTimer);
781859
this.shellTimer = null;
782860
}
783-
for (const timer of [this.vigilTimer, this.holdTimer]) {
861+
for (const timer of [this.vigilTimer, this.holdTimer, this.passerTimer, this.passerEndTimer]) {
784862
if (timer !== null) {
785863
window.clearTimeout(timer);
786864
}
787865
}
788866
this.vigilTimer = null;
789867
this.holdTimer = null;
868+
this.passerTimer = null;
869+
this.passerEndTimer = null;
790870
document.removeEventListener("pointermove", this.handleGaze);
791871
super.disconnectedCallback();
792872
}
@@ -823,6 +903,7 @@ export class LobsterPet extends LitElement {
823903
this.moltPlanned = isLobsterMoltLoad(this.seed);
824904
this.twinPlanned = isLobsterTwinLoad(this.seed);
825905
this.scheduleVisits();
906+
this.schedulePasser();
826907
// The first update takes this branch, so the mode-change branch below
827908
// never sees the initial mode: arm the vigil tracker here as well.
828909
this.vigil = false;
@@ -1076,6 +1157,34 @@ export class LobsterPet extends LitElement {
10761157
}, stayMs);
10771158
}
10781159

1160+
// ---- Pass-through visitors (strangers and the crab) ----
1161+
1162+
private schedulePasser() {
1163+
for (const timer of [this.passerTimer, this.passerEndTimer]) {
1164+
if (timer !== null) {
1165+
window.clearTimeout(timer);
1166+
}
1167+
}
1168+
this.passerTimer = null;
1169+
this.passerEndTimer = null;
1170+
this.passer = null;
1171+
const plan = planLobsterPasser(this.seed);
1172+
if (!plan || prefersReducedMotion()) {
1173+
return;
1174+
}
1175+
this.passerTimer = window.setTimeout(() => {
1176+
this.passerTimer = null;
1177+
if (!this.visitsEnabled || document.hidden) {
1178+
return;
1179+
}
1180+
this.passer = plan;
1181+
this.passerEndTimer = window.setTimeout(() => {
1182+
this.passerEndTimer = null;
1183+
this.passer = null;
1184+
}, PASSER_CROSS_MS);
1185+
}, plan.atMs);
1186+
}
1187+
10791188
// Each arrival re-rolls where the pet shows up: the ledge above the footer
10801189
// divider or the free stretch inside the footer bar.
10811190
private rollPerch() {
@@ -1292,13 +1401,44 @@ export class LobsterPet extends LitElement {
12921401
// The shell may outlive the visit while it fades, but dismissal and the
12931402
// visits setting silence it like everything else.
12941403
const showShell = this.shellVisible && this.visitsEnabled && !this.dismissed;
1295-
if (!showSprites && !showShell) {
1404+
const showPasser = this.passer !== null && this.visitsEnabled;
1405+
if (!showSprites && !showShell && !showPasser) {
12961406
return nothing;
12971407
}
12981408
return html`
12991409
${showShell ? this.renderShell(look) : nothing}
13001410
${showSprites ? this.renderSprite(look, false) : nothing}
13011411
${showSprites && this.twinPlanned ? this.renderSprite(look, true) : nothing}
1412+
${showPasser && this.passer ? this.renderPasser(this.passer, look) : nothing}
1413+
`;
1414+
}
1415+
1416+
// A pass-through visitor: crosses the ledge once and is gone. Strangers
1417+
// are other lobsters (never your palette); the crab is, allegedly, also a
1418+
// lobster. Neither perches, neither counts for the Lobsterdex.
1419+
private renderPasser(passer: LobsterPasserPlan, own: LobsterPetLook) {
1420+
const crab = passer.kind === "crab";
1421+
const look = crab ? own : strangerLookFor(this.seed, own.palette.id);
1422+
const classes = [
1423+
"lobster-pet",
1424+
"lobster-pet--passer",
1425+
crab ? "lobster-pet--crab" : `lobster-pet--palette-${look.palette.id}`,
1426+
passer.direction === 1 ? "lobster-pet--passer-ltr" : "lobster-pet--passer-rtl",
1427+
].join(" ");
1428+
const style = crab
1429+
? `--lob-scale:2;--lob-w:1;--lob-h:0.82;--lob-face:1`
1430+
: this.spriteStyle(look, Math.min(look.scale, 2), 0, passer.direction);
1431+
return html`
1432+
<div
1433+
class=${classes}
1434+
style=${style}
1435+
aria-hidden="true"
1436+
title=${crab ? "definitely a lobster" : "a stranger"}
1437+
>
1438+
<div class="lobster-pet__body">
1439+
${crab ? renderCrabSvg() : renderLobsterSvg(look, { standalone: true })}
1440+
</div>
1441+
</div>
13021442
`;
13031443
}
13041444
}

‎ui/src/styles/lobster-pet.css‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,62 @@ openclaw-lobster-pet[data-spot="bar"] .lobster-pet {
659659
}
660660
}
661661

662+
/* ---- Pass-through visitors ---- */
663+
664+
/* Passers cross the whole ledge once; left/right position comes from the
665+
crossing keyframes, not the perch variable. */
666+
.lobster-pet--passer {
667+
pointer-events: none;
668+
cursor: default;
669+
bottom: 0;
670+
}
671+
672+
.lobster-pet--passer .lobster-pet__body {
673+
animation: lobster-pet-waddle 0.32s ease-in-out infinite;
674+
}
675+
676+
.lobster-pet--passer-ltr {
677+
animation: lobster-pet-cross-ltr 11s linear forwards;
678+
}
679+
680+
.lobster-pet--passer-rtl {
681+
animation: lobster-pet-cross-rtl 11s linear forwards;
682+
}
683+
684+
/* The crab walks sideways by definition: it crosses while facing you and
685+
feels no need to explain itself. */
686+
.lobster-pet--crab .lobster-pet__body {
687+
animation: lobster-pet-crab-scuttle 0.24s ease-in-out infinite;
688+
}
689+
690+
@keyframes lobster-pet-cross-ltr {
691+
from {
692+
left: -6%;
693+
}
694+
to {
695+
left: 106%;
696+
}
697+
}
698+
699+
@keyframes lobster-pet-cross-rtl {
700+
from {
701+
left: 106%;
702+
}
703+
to {
704+
left: -6%;
705+
}
706+
}
707+
708+
@keyframes lobster-pet-crab-scuttle {
709+
0%,
710+
100% {
711+
transform: translateY(0);
712+
}
713+
50% {
714+
transform: translateY(-8%);
715+
}
716+
}
717+
662718
/* ---- Lobsterdex (appearance settings gallery) ---- */
663719

664720
.lobsterdex {

0 commit comments

Comments
 (0)