forked from WikiDeck/wikideck
Night 2 (2026-11-17), from the `claude/wikideck` fork's `night/2026-11-17` branch. It follows Night 1 (#22).
## What's in it
- **Duel engine** (fork #72, #80): 40-card decks of cards you own, Notability/Citations, keywords, effects T1–T12, Connected, a hidden-information-safe `viewFor`/`logFor`, and replay. Balance v1 tuning (#84) gives the first player about 51%.
- **Card profiles** (#70, #82): Figure, Location, Event, Institution or Doctrine, plus stats, keywords and rules text, all derived from real article data. Templates only.
- **Design and story** (#66, #69, #83): DUEL_DESIGN.md, plus the match log and the encyclopedic "Battle of X (2026)" recap.
- **PvP** (#74, #77, #81, #76, #85):
- The server checks ownership, and 40-card eligibility is enforced.
- Modes: Classic (ranked), Draft and Trending.
- Invites, quick match, Elo, a ladder and recap pages. Online matches render on the duel board.
- **Duel board UI** (#79): MTG-style card faces and combat declaration, built for 360 px first.
- **Polite Wikimedia client** (#73, #75): throttled, cached and identified requests, the mint-path fix, and a prefetch pool.
- **Android mining** (#78): native RandomX, as a sideload build. The emulator mined a testnet block.
- **Testnet ops** (#67, #68).
PR numbers refer to `claude/wikideck`.
## Status
- **Tests:** 423, of which 422 pass, 0 fail and 1 is skipped. The build is OK (`node:24-alpine`, `--network none`).
- **Testnet:** running this commit (036489c) on r350.
- **Untouched:** no changes to `server/testnet/consensus.ts`, `randomx.ts`, `native/` or the mainnet compose.
- **Review:** night-review reviewed fork #66–#79. #80–#85 came from the agents' unfinished branches and were not reviewed.
- **Known gaps:**
- The PvP end-to-end test hasn't been run (it needs two eom.dev accounts).
- Bot matches aren't reachable from Play.
- Card identity pre-bake hasn't been done.
- The RandomX verifier latch (`server/testnet/randomx.ts:140`) is still open.
This PR is for Eric to merge.
🤖 Generated with [Claude Code](https://claude.com/claude-code)Reviewed-on: WikiDeck/wikideck#23
Co-authored-by: Claude <claude@eom.dev>
118 lines
5.0 KiB
TypeScript
118 lines
5.0 KiB
TypeScript
/**
|
|
* Adapter: duel-core's LogEvent[] (shared/duel/types.ts) → story MatchRecord (DUEL_DESIGN §8).
|
|
* Pure. Pass the omniscient `state.log` for recaps, or `logFor(state, seat)` output for a seat's log
|
|
* (hidden draws there have no `card`, and stay hidden).
|
|
*/
|
|
import type { CardInstance, CardRef, LogEvent } from '../types.ts';
|
|
import type { MatchRecord, Seat, StoryCard, StoryEvent, StoryPlayer } from './types.ts';
|
|
|
|
export interface FromDuelInput {
|
|
matchId: string;
|
|
/** Story seed, opaque: the host derives it (sha256(engineSeed + ':story')). Never the engine seed. */
|
|
storySeed: string;
|
|
/** ISO YYYY-MM-DD. */
|
|
date: string;
|
|
players: [StoryPlayer, StoryPlayer];
|
|
/** Every card instance of both decks (tokens are picked up from the log). */
|
|
instances: CardInstance[];
|
|
log: LogEvent[];
|
|
startingLife?: number;
|
|
hostName?: string;
|
|
ratingChange?: [number, number];
|
|
}
|
|
|
|
function storyCard(inst: CardInstance): StoryCard {
|
|
const c = inst.card;
|
|
return {
|
|
id: inst.uid, title: c.title, description: c.description, type: c.type, cost: c.cost, portal: c.portal,
|
|
revisionId: c.token ? undefined : c.revisionId, tokenId: c.token ? undefined : c.cardId, owner: inst.owner,
|
|
token: c.token || undefined,
|
|
};
|
|
}
|
|
|
|
export function fromDuel(input: FromDuelInput): MatchRecord {
|
|
const cards: Record<string, StoryCard> = {};
|
|
for (const inst of input.instances) cards[inst.uid] = storyCard(inst);
|
|
/** Tokens (and anything not in the decks) come from their log CardRef: never cited. */
|
|
const ref = (r: CardRef, owner: Seat): string => {
|
|
if (!cards[r.uid]) cards[r.uid] = { id: r.uid, title: r.title, type: r.type, cost: 0, owner, token: true };
|
|
return r.uid;
|
|
};
|
|
const events: StoryEvent[] = [];
|
|
let lastTurn = 0;
|
|
for (const e of input.log) {
|
|
switch (e.kind) {
|
|
case 'turnStart':
|
|
lastTurn = e.turn;
|
|
events.push({ kind: 'turnStart', turn: e.turn, seat: e.seat });
|
|
break;
|
|
case 'draw':
|
|
events.push(e.card ? { kind: 'draw', seat: e.seat, card: ref(e.card, e.seat) } : { kind: 'draw', seat: e.seat });
|
|
break;
|
|
case 'deploy':
|
|
events.push({ kind: 'deploy', seat: e.seat, card: ref(e.card, e.seat) });
|
|
break;
|
|
case 'cast':
|
|
events.push({ kind: 'cast', seat: e.seat, card: ref(e.card, e.seat) });
|
|
break;
|
|
case 'adopt':
|
|
events.push({
|
|
kind: 'adopt', seat: e.seat, doctrine: ref(e.card, e.seat), figure: ref(e.to, e.seat),
|
|
power: e.to.power ?? 0, toughness: e.to.toughness ?? 0,
|
|
});
|
|
break;
|
|
case 'tokenCreated': {
|
|
const prev = events[events.length - 1];
|
|
const src = ref(e.source, e.seat);
|
|
ref(e.card, e.seat);
|
|
if (prev && prev.kind === 'tokenCreated' && prev.source === src && prev.token === e.card.title) prev.count += 1;
|
|
else events.push({ kind: 'tokenCreated', seat: e.seat, source: src, token: e.card.title, count: 1 });
|
|
break;
|
|
}
|
|
case 'connected':
|
|
events.push({ kind: 'connected', seat: e.seat, a: ref(e.card, e.seat), b: ref(e.with, e.seat), reason: e.via });
|
|
break;
|
|
case 'rivalry':
|
|
events.push({ kind: 'rivalry', a: ref(e.card, 0), b: ref(e.with, 1), reason: e.via });
|
|
break;
|
|
case 'attack':
|
|
for (const a of e.attackers) events.push({ kind: 'attack', seat: e.seat, card: ref(a, e.seat), power: a.power ?? 0, toughness: a.toughness ?? 0 });
|
|
break;
|
|
case 'block':
|
|
for (const b of e.blocks) {
|
|
events.push({
|
|
kind: 'block', seat: e.seat, blocker: ref(b.blocker, e.seat), attacker: ref(b.attacker, e.seat === 0 ? 1 : 0),
|
|
power: b.blocker.power ?? 0, toughness: b.blocker.toughness ?? 0,
|
|
});
|
|
}
|
|
break;
|
|
case 'lifeGain':
|
|
events.push({ kind: 'lifeGain', seat: e.seat, source: ref(e.source, e.seat), amount: e.amount, life: e.life });
|
|
break;
|
|
case 'effectDamage':
|
|
events.push({ kind: 'effectDamage', source: ref(e.source, 0), target: ref(e.target, 0), amount: e.amount });
|
|
break;
|
|
case 'playerDamage':
|
|
events.push({ kind: 'playerDamage', seat: e.seat, source: e.source ? ref(e.source, e.seat === 0 ? 1 : 0) : undefined, amount: e.amount, life: e.life });
|
|
break;
|
|
case 'destroyed':
|
|
events.push({ kind: 'destroyed', card: ref(e.card, e.owner) });
|
|
break;
|
|
case 'discard':
|
|
events.push({ kind: 'discard', seat: e.seat, card: ref(e.card, e.seat) });
|
|
break;
|
|
case 'gameOver':
|
|
events.push({ kind: 'gameOver', winner: e.winner, reason: e.reason, turn: e.turn || lastTurn, life: e.life });
|
|
break;
|
|
// start, mulligan, keep, effect, combatDamage, bounced, fatigue, concede, timeout:
|
|
// not narrated in v1 (combat outcomes are told by destroyed/playerDamage; gameOver covers concede/timeout).
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
return {
|
|
matchId: input.matchId, seed: input.storySeed, date: input.date, players: input.players, cards, events,
|
|
startingLife: input.startingLife, hostName: input.hostName, ratingChange: input.ratingChange,
|
|
};
|
|
}
|