Connect printed Diplomat defenses and Ecaz Tanked Duke Cunning
This commit is contained in:
1 parent
039fe4e87f
commit
be8703dc51
17 files changed
+811
-182
No files matched your search
@@ -1,28 +1,20 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { registerHooks } from 'node:module';
|
||||
import { createElement } from 'react';
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import { DiplomatDefense } from '../components/diplomat-defense';
|
||||
import { botActions } from '../game/bots';
|
||||
import { DIFFICULTIES } from '../game/bot-profiles';
|
||||
import { applyAction, viewGame, type Game } from '../game/engine';
|
||||
import { applyAction, viewGame, type Game, type GameView } from '../game/engine';
|
||||
import { baseDeck, ixBattleCards, type Card } from '../game/cards';
|
||||
import { richeseCards } from '../game/richese-cards';
|
||||
import type { DiplomatDefenseQuote } from '../game/diplomat-defense';
|
||||
import {
|
||||
diplomatDefenseGame,
|
||||
revealDiplomatPlans,
|
||||
takeBattleCard,
|
||||
} from './diplomat-defense-fixture';
|
||||
|
||||
const aliases = registerHooks({
|
||||
resolve(specifier, context, next) {
|
||||
return next(
|
||||
specifier === 'next/image' ? 'vinext/shims/image' : specifier === 'next/link' ? 'vinext/shims/link' : specifier,
|
||||
context,
|
||||
);
|
||||
},
|
||||
});
|
||||
const { RevealedBattle } = await import('../components/revealed-battle');
|
||||
aliases.deregister();
|
||||
|
||||
function markup(game: Game, viewer = 'a', busy = false) {
|
||||
return renderToStaticMarkup(
|
||||
@@ -34,6 +26,37 @@ function markup(game: Game, viewer = 'a', busy = false) {
|
||||
);
|
||||
}
|
||||
|
||||
/** Project the public revealed receipt with a chosen copied role. Native
|
||||
* integration is proven separately once the server passes the widened kind. */
|
||||
function markupCopy(source: Card, kind: DiplomatDefenseQuote['kind']): string {
|
||||
const base = viewGame(revealDiplomatPlans(diplomatDefenseGame()), 'a');
|
||||
const battle = base.battle!;
|
||||
const view: GameView = {
|
||||
...base,
|
||||
battle: {
|
||||
...battle,
|
||||
cards: [source],
|
||||
diplomatDefense: { ...battle.diplomatDefense!, source: source.id, kind },
|
||||
},
|
||||
decision: {
|
||||
kind: 'diplomatDefense',
|
||||
player: 'a',
|
||||
event: 'projected',
|
||||
cards: ['worthless-projected'],
|
||||
source: source.id,
|
||||
},
|
||||
};
|
||||
return renderToStaticMarkup(
|
||||
createElement(DiplomatDefense, { game: view, act() {}, busy: false }),
|
||||
);
|
||||
}
|
||||
|
||||
function describedProtection(html: string) {
|
||||
const match = /provides <strong>(.*?)<\/strong> protection/.exec(html);
|
||||
assert.ok(match, html);
|
||||
return match[1];
|
||||
}
|
||||
|
||||
function revealAgainstProjectile(game: Game) {
|
||||
const own = game.players.find((player) => player.id === 'a')!;
|
||||
const other = game.players.find((player) => player.id === 'd')!;
|
||||
@@ -54,26 +77,16 @@ function revealAgainstProjectile(game: Game) {
|
||||
return next;
|
||||
}
|
||||
|
||||
void test('the deciding owner sees the copied protection, named Worthless choice, mandatory discard and decline', () => {
|
||||
void test('only the deciding owner can access eligible committed cards, with busy controls disabled', () => {
|
||||
const game = diplomatDefenseGame();
|
||||
const uncommitted = takeBattleCard(game, 'd', 'worthless');
|
||||
const revealed = revealDiplomatPlans(game);
|
||||
const html = markup(revealed);
|
||||
assert.match(html, /aria-label="Diplomat defense choice"/);
|
||||
assert.match(html, /opposing committed defense, <strong>Snooper/);
|
||||
assert.match(html, /<strong>Poison defense<\/strong> protection/);
|
||||
assert.match(html, /Copy Snooper with Baliset · mandatory discard/);
|
||||
assert.match(html, /must be discarded after this battle/);
|
||||
assert.match(html, /Decline Diplomat defense/);
|
||||
assert.equal(html.includes(uncommitted.name), false);
|
||||
assert.equal(markup(revealed, 'd'), '');
|
||||
assert.ok(
|
||||
(markup(revealed, 'a', true).match(/disabled=""/g) ?? []).length >= 2,
|
||||
);
|
||||
assert.match(
|
||||
markup(revealDiplomatPlans(diplomatDefenseGame(false, true))),
|
||||
/Diplomat defense choice/,
|
||||
);
|
||||
});
|
||||
|
||||
void test('all profiles copy useful revealed protection and decline a mismatched defense', () => {
|
||||
@@ -113,45 +126,6 @@ void test('all profiles copy useful revealed protection and decline a mismatched
|
||||
}
|
||||
});
|
||||
|
||||
void test('the revealed plan preserves the public copied or declined Diplomat status across views', () => {
|
||||
const unsealed = diplomatDefenseGame();
|
||||
assert.equal(
|
||||
renderToStaticMarkup(
|
||||
createElement(RevealedBattle, { game: viewGame(unsealed, 'a') }),
|
||||
),
|
||||
'',
|
||||
);
|
||||
|
||||
let copied = revealDiplomatPlans(unsealed);
|
||||
assert.equal(copied.decision?.kind, 'diplomatDefense');
|
||||
copied = applyAction(copied, 'a', {
|
||||
type: 'decision',
|
||||
event: copied.decision.event,
|
||||
card: copied.decision.cards[0],
|
||||
});
|
||||
for (const viewer of ['a', 'd']) {
|
||||
const html = renderToStaticMarkup(
|
||||
createElement(RevealedBattle, { game: viewGame(copied, viewer) }),
|
||||
);
|
||||
assert.match(
|
||||
html,
|
||||
/Diplomat: Baliset copies Snooper · discard after battle/,
|
||||
);
|
||||
}
|
||||
|
||||
let declined = revealDiplomatPlans(diplomatDefenseGame());
|
||||
assert.equal(declined.decision?.kind, 'diplomatDefense');
|
||||
declined = applyAction(declined, 'a', {
|
||||
type: 'decision',
|
||||
event: declined.decision.event,
|
||||
card: null,
|
||||
});
|
||||
const declinedHtml = renderToStaticMarkup(
|
||||
createElement(RevealedBattle, { game: viewGame(declined, 'd') }),
|
||||
);
|
||||
assert.match(declinedHtml, /Diplomat: defense copy declined/);
|
||||
assert.doesNotMatch(declinedHtml, /discard after battle/);
|
||||
});
|
||||
|
||||
void test('all profiles retain legal Worthless plans for the native trainer and the selected hidden trained disc', () => {
|
||||
for (const difficulty of DIFFICULTIES) {
|
||||
@@ -177,7 +151,70 @@ void test('all profiles retain legal Worthless plans for the native trainer and
|
||||
candidates.length,
|
||||
`${difficulty} omitted ${hidden ? 'trained-disc' : 'native'} Diplomat planning`,
|
||||
);
|
||||
assert.doesNotThrow(() => applyAction(game, 'a', candidates[0]));
|
||||
let sealed = applyAction(game, 'a', candidates[0]);
|
||||
const opponent = sealed.players.find(player => player.id === 'd')!;
|
||||
sealed = applyAction(sealed, 'd', {
|
||||
type: 'battlePlan', dial: 0, leader: 'guild-1',
|
||||
weapon: opponent.hand.find(card => card.kind === 'poison')!.id,
|
||||
defense: opponent.hand.find(card => card.kind === 'snooper')!.id,
|
||||
});
|
||||
assert.ok(sealed.decision?.kind === 'diplomatDefense');
|
||||
const selected = sealed.decision!;
|
||||
sealed = applyAction(sealed, 'a', { type: 'decision', event: selected.event, card: selected.cards[0] });
|
||||
sealed = applyAction(sealed, 'a', { type: 'traitorCall', call: false });
|
||||
sealed = applyAction(sealed, 'd', { type: 'traitorCall', call: false });
|
||||
assert.equal(sealed.players[0].leaders.find(disc => disc.id === leader)!.dead, false);
|
||||
assert.equal(sealed.discard.filter(card => card.id === selected.cards[0]).length, 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
void test('the choice describes the actual copied role instead of a binary Shield or Snooper', () => {
|
||||
const ix = ixBattleCards(),
|
||||
deck = baseDeck();
|
||||
const snooper = deck.find((c) => c.kind === 'snooper')!;
|
||||
const cases = [
|
||||
{ source: snooper, kind: 'snooper' as const },
|
||||
{ source: deck.find((c) => c.kind === 'shield')!, kind: 'shield' as const },
|
||||
{
|
||||
source: ix.find((c) => c.kind === 'shieldSnooper')!,
|
||||
kind: 'shieldSnooper' as const,
|
||||
},
|
||||
{
|
||||
source: ix.find((c) => c.kind === 'weirdingWay')!,
|
||||
kind: 'weirdingWay' as const,
|
||||
},
|
||||
{
|
||||
source: ix.find((c) => c.kind === 'chemistry')!,
|
||||
kind: 'chemistry' as const,
|
||||
},
|
||||
{
|
||||
source: richeseCards().find((c) => c.effect === 'portableSnooper')!,
|
||||
kind: 'snooper' as const,
|
||||
},
|
||||
];
|
||||
const described = cases.map(({ source, kind }) => {
|
||||
const html = markupCopy(source, kind);
|
||||
assert.ok(html.includes(source.name), source.name);
|
||||
assert.ok(
|
||||
html.includes(`Copy ${source.name} with worthless-projected`),
|
||||
source.name,
|
||||
);
|
||||
return describedProtection(html);
|
||||
});
|
||||
assert.equal(new Set(described.slice(0, 2)).size, 2);
|
||||
assert.equal(described[0], described[5]);
|
||||
for (const index of [2, 3, 4])
|
||||
assert.ok(
|
||||
!described.slice(0, 2).includes(described[index]),
|
||||
cases[index].source.name,
|
||||
);
|
||||
for (const [index, { source, kind }] of cases.entries()) {
|
||||
const html = markupCopy(source, kind);
|
||||
assert.equal(
|
||||
html.includes('data-copied-role-interpretation="true"'),
|
||||
index >= 2,
|
||||
source.name,
|
||||
);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user