PvZ Online: AI Dave
Adventure requires a Yumina login. The existing separate-tab login flow preserves the original game tab's relay identity and saves. Versus remains available to guests and makes no Dave requests.
Dave now has five authored chapter scenes: The neighbor next door, Keep a light on, Around the back, Stay within earshot, and One house to keep. They follow the original day/night/pool/fog/roof campaign. The recurring story is two neighbors trying to keep the player's home, with increasing familiarity grounded in witnessed progress. Scenes and conversation topics are localized into English, Simplified Chinese and Spanish. Each chapter introduction is remembered per account/campaign cycle and uses no model request or API key. The ×4/API explanation lives outside Dave's dialogue. His original animation and mumbling accompany the browser panel; there is no generated voice.
Conversation uses the player's private Yumina API connection. Choose model opens Yumina's actual shared ModelBrowser in a separate tab, with its private catalog, search, favorites and recent choices. The Adventure remains paused. This entry suppresses official billing-source and unsupported mix controls; it does not change platform billing preferences. /app/settings#ai-config contains connection settings. An absent/private-disabled connection cannot fall back to Yumina credits or an official key. API keys remain encrypted on the server and never enter game URLs. A random, account-bound same-origin BroadcastChannel returns the selected model, saved for this account in the game tab's session. The picker hydrates this account's saved favorites before enabling edits. Dave receives current chapter boundaries, a compact Adventure snapshot, scoped notebook facts and up to twelve saved dialogue messages. Logged-in players can play Adventure and see authored scenes without an AI connection.
Occasional encounters: the suspicious tin
This is one complete optional item loop, with authored English, Simplified Chinese and Spanish scenes and AI follow-up:
flowchart LR
A[Quiet moment on the lawn] --> B[Dave offers a tin]
B --> C[Ignore or decline: keep playing]
B --> D[Pay 25 sun]
D --> E[Keep sealed until later this level]
E --> F[Open once]
F --> G[75 sun]
F --> H[Empty tin]
G --> I[Talk about what happened]
H --> I
H --> J[Short callback if this attempt ends in defeat]- Roughly two-thirds of eligible levels have one invitation, at a varied point after 60–120 seconds of active play. Levels 1–4, conveyor stages, vase puzzles and the final boss are excluded. Immediate house danger, a mower used in the last 20 seconds, pauses, original Dave scenes and the final spawned wave defer or suppress it. Declining or ignoring costs nothing; the invitation fades after eight seconds and its offer expires after 30 seconds of active play.
- Buying costs 25 sun and requires at least 100 sun, leaving 75 for defense. The card explicitly says the contents may be useful or empty. One sealed tin lasts only this level; it neither unlocks a plant nor enters a permanent inventory.
- Three of four outcome hashes produce 75 sun, the rest an empty tin. Salted hashes use level/campaign cycle independently of the simulation RNG. Contents are fixed before purchase, preserved in optional save chunk 23 and not rerolled by reloading. Replaying the same level/cycle repeats the outcome; timing can differ as the defense becomes calm. This is deliberate replay stability, not fresh per-player randomness.
- Opening consumes the tin once. A dud has no effect beyond the already-disclosed 25-sun purchase. It cannot damage plants, add enemies, take extra sun, secretly repair itself or become a new quest. Both action and result survive save/continue.
- Native receipts, authored dialogue and item UI work without an AI call. Ask Dave about this puts a suggested complaint/thanks in the composer; the player chooses whether to send it. The model receives only revealed outcomes and remembers the purchase/dud/reward and lost attempts. It can improvise excuses and react to a bonk or apology, but cannot grant an invented refund or change the result. Older attempts are memories, not current inventory.
- After a dud or garden gift, defeat may produce one brief, nonblocking aside. It runs for six seconds, has a two-minute session cooldown, and costs no AI request. Native loss disables all Dave actions and never saves a defeated board over the playable save. The notebook records the lost attempt separately. No claim is made that Dave's tin caused the loss.
- Dave's occasional visits can be switched off. This preference is separate from the existing unchecked-by-default paid proactive AI comments. Invitations do not pause combat; opening a conversation does. No additional item families, plant conversations or side-quest log were added.
Sample authored dud: “Ah. That was the sound-effects model.” / “哦。这是音效款。” The lid makes a satisfying pop; nothing comes out. Dave laughs, notices the player's reaction and offers the empty tin as a weak consolation. The next player message determines how that conversation continues.
Notebook and story continuity
game_npc_dave_memory stores one bounded JSON notebook per authenticated account with a foreign key that cascades on account deletion. The notebook retains up to 24 turns, 80 observed milestones, eight pinned player notes, eight selected verbatim player statements and 30 chapter markers. UTF-8 budgeting trims old turns before the 64 KiB database constraint; this is deliberately bounded memory, not an unlimited transcript or a second full save system.
The model may select a short exact quote from the current player message to remember, as part of the same response. The server checks the quote against that message and rejects common credential text. This creates a remembered player statement, never a confirmed game event. Player notes and previous assistant dialogue cannot grant rewards or establish victories. No extra AI summarization requests run.
Dialogue, automatic recollections and observed milestones from later levels or a different campaign cycle are excluded from the current prompt. Explicit player-pinned notes remain account-wide. An imported late save gets an introduction rather than an invented shared childhood/history. Completed previous Adventures permit a different replay greeting; the native ending remains unchanged.
The notebook is readable in Dave's panel and can be cleared independently of game progress. Writes use revision comparisons, so another tab or a reset cannot be overwritten by an old in-flight reply. There is no database transaction held open while waiting for the model.
Gameplay rules
- Adventure remains 4× the original weighted zombie budget, not 5× and not necessarily four times the bodies. The entry screen explains this and the separate PvP Versus mode. The first authored Dave scene warns about the heavier invasion and invites direct conversation.
- Player actions have immediate authored reactions without a model request: give Dave 50 sun for his garden, a cartoon punch against his pot, and an apology after the punch. Each is once per level; gifts require 50 sun and are unavailable on conveyor stages. Punches do no damage and have no resource penalty; apologies repair the social incident. These observations affect Dave's conversational attitude, not shop prices or an invisible affection meter.
- Native interaction flags persist separately in optional save chunk 22; old saves default to zero and the existing chunk 21 payload is unchanged. Retrying a failed notebook response never charges a second gift. The notebook records each action/reaction once, with the same account and revision checks as other mutations.
- The dialogue panel keeps its header, social actions and text composer visible while conversation scrolls. Chapter introductions have a direct Talk to Dave button; conversation ideas, notebook and API settings are expandable. English, Simplified Chinese and Spanish share the layout.
- Web startup skips the publisher splash/title drawing and first-Adventure publisher cinematic; normal lawn transitions, tutorials and later original cutscenes remain. Known signed-in players enter without flashing the login explanation. Chinese Versus has a smaller heading and the requested Chinese-only design credit.
- Talking plants are explicitly deferred to the next update at the owner's request.
- Opening Dave pauses solo play; closing him resumes his owned pause. He is unavailable during other modal screens, scripted Dave sequences, vase puzzles, the final boss and transitions.
- The first eligible sun gift is 50 sun, only below 100 current sun.
- An unlocked Cherry Bomb can be offered for 100–150 sun as a temporary usable seed packet.
- A no-shovel challenge awards 75 sun after the next scheduled wave is cleared without digging. Digging after acceptance fails it.
- Each offer kind is usable once per level. Acceptance rechecks native state, price, unlock and wave expiry. Rewards never execute generated code.
- Conveyor levels allow conversation but disable these sun-based offers. Visible zombie names and selected plant names improve advice; fog conservatively omits the concealed part of the lawn, including local lighting edge cases.
- Offer limits, challenge progress and proactive call counts persist in optional save chunk 21. Old saves have empty Dave state. Conversation UI and request IDs are transient.
- Proactive comments are unchecked by default, capped at two calls per level and separated by at least 90 seconds of simulation time. They do not pause the game. Dismiss silences further comments for the current board.
HTTP and operations
GET /api/game/npc/dave/config, POST /api/game/npc/dave and POST /api/game/npc/dave/notebook are behind the existing game auth middleware. Generation requires the same account ID displayed by config, strict Adventure-only Zod context, a 24 KiB body, at most eight requests/minute, and one active request/account. Notebook visits/intro markers/notes/reset use a 12 KiB body and 60 requests/minute. Existing Redis concurrency/rate limiting is reused, with its existing memory fallback.
Generation has a 20-second deadline, 500 output tokens, no automatic retry, bounded output parsing and a private-provider check before generation. Browser navigation/level changes cancel requests and reject stale request/run/board IDs. A provider may still bill work already started before cancellation.
Set PVZ_DAVE_DISABLED=1 on the API service to disable Dave while retaining logged-in Adventure access. The new table is added by db/game-npc-ddl.ts, also represented in Drizzle schema.ts. Provisioning runs after the server binds its port, with one-second lock and three-second statement deadlines. It retries on a notebook request if startup provisioning was deferred; no existing tables are altered or player rows rewritten. Deploy the API via main before publishing the updated game HTML to S3; publish hashed JS/WASM before the HTML entrypoint. Existing game builds remain wire-compatible.
Validation
pnpm buildandpnpm typecheckin the platform repository.pnpm exec tsx --test src/lib/game-npc/*.test.ts src/routes/game-npc.test.tsin packages/server, including full HTTP/database tests using PGlite and a fake provider.node --test wasm/tests/*.test.mjsand standalone C++wasm/tests/dave-rules.test.cppin the game repository.- Rebuild WASM; inspect guest gate, zero-call scripted welcome, mocked-provider chat and gift, duplicate acceptance, save/continue, account changes and landscape phone layout.
- Run the existing pool Versus self-test to 8000 ticks; baseline hash is
846fe342.
The fake provider exercises the integration without spending an owner's key. Real-provider answer quality and physical iOS/Android keyboards still need a player trial. The notebook is account-persistent; the underlying Adventure save/profile behavior is unchanged. This release adds no new game-save migration or multiplayer NPC authority.
Design references
The public popular hub and editable public world structures were inspected on 2026-09-07 UTC: 桜色の季節 uses explicit story phases/relationship flags; 壺中の毒 · 大逃杀 separates knowledge, character rules and event state; 咒术回战 constrains its timeline and progression. These informed structure only. Their prose, character material and model instructions were not copied. Download counts are a popularity signal, not evidence that a particular writing technique causes retention. No private player conversations were read.
