sim
This commit is contained in:
parent
746d218eda
commit
e590baf28d
44 changed files with 8308 additions and 0 deletions
362
sim/src/cards/hardware.ts
Normal file
362
sim/src/cards/hardware.ts
Normal file
|
|
@ -0,0 +1,362 @@
|
|||
/**
|
||||
* Hardware. It works while its wearer is in play. "The occupied Server" is the location the
|
||||
* wearer stands on.
|
||||
*/
|
||||
import { knockOut } from '../flow.ts';
|
||||
import { desynced, hardwareActive } from '../query.ts';
|
||||
import { scriptOf, type Script } from '../scripts.ts';
|
||||
import {
|
||||
ask,
|
||||
avatar,
|
||||
avatarName,
|
||||
defOf,
|
||||
fired,
|
||||
isCopy,
|
||||
markUsed,
|
||||
nameOf,
|
||||
nextTurnOf,
|
||||
ownerOf,
|
||||
played,
|
||||
programLocation,
|
||||
refsInPlay,
|
||||
removeFrom,
|
||||
say,
|
||||
startOf,
|
||||
endOf,
|
||||
stat,
|
||||
toHand,
|
||||
uninstallHardware,
|
||||
usedThisTurn,
|
||||
wearerOf,
|
||||
} from '../state.ts';
|
||||
import type { AvatarRef, GameState, LocationState, PlayerId, StackItem } from '../types.ts';
|
||||
import { cardOptions, programsOn } from './util.ts';
|
||||
|
||||
/**
|
||||
* Uses a Hardware card has left this turn. Its "once per turn" or "first ... each turn" effect gets
|
||||
* one use, or two when Cooling System on the same Avatar picks it (Cooling helps one Hardware a turn).
|
||||
*/
|
||||
export function hardwareUsesLeft(s: GameState, hw: number): number {
|
||||
const used = usedThisTurn(s, `hw:${hw}`);
|
||||
const cooler = coolerFor(s, hw);
|
||||
return (cooler === null ? 1 : 2) - used;
|
||||
}
|
||||
|
||||
function coolerFor(s: GameState, hw: number): number | null {
|
||||
const ref = wearerOf(s, hw);
|
||||
if (!ref) return null;
|
||||
for (const id of avatar(s, ref).hardware) {
|
||||
if (id === hw || s.cards[id].name !== 'Cooling System' || !hardwareActive(s, id)) continue;
|
||||
const pickedFor = s.used[`cool:${id}`];
|
||||
if (pickedFor === undefined || pickedFor === hw) return id;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function useHardware(s: GameState, hw: number): void {
|
||||
const cooler = coolerFor(s, hw);
|
||||
markUsed(s, `hw:${hw}`);
|
||||
if (usedThisTurn(s, `hw:${hw}`) >= 2 && cooler !== null) {
|
||||
s.used[`cool:${cooler}`] = hw;
|
||||
fired(s, 'Cooling System', ownerOf(s, hw));
|
||||
}
|
||||
}
|
||||
|
||||
const wearing = (ref: AvatarRef | undefined, f: { ref: AvatarRef }) =>
|
||||
!!ref && ref.player === f.ref.player && (ref.slot === f.ref.slot || ref.slot + 4 === f.ref.slot);
|
||||
|
||||
/** Installs a Hardware card from its owner's hand onto an Avatar, without paying. */
|
||||
export function attachHardware(s: GameState, card: number, ref: AvatarRef): void {
|
||||
removeFrom(s.players[ref.player].hand, card);
|
||||
avatar(s, ref).hardware.push(card);
|
||||
s.cards[card].installedTurn = s.turn;
|
||||
stat(s, 'hardwareInstalled', ref.player);
|
||||
played(s, nameOf(s, card), ref.player);
|
||||
}
|
||||
|
||||
export const HARDWARE: Record<string, Script> = {
|
||||
// Reading: "+2 Core capacity" means +2 Cores.
|
||||
'RAM Expansion': {
|
||||
text: 'Avatar gains +2 Core capacity.',
|
||||
cores: () => 2,
|
||||
},
|
||||
'Additional Core': {
|
||||
text: 'Avatar gains +1 Core.',
|
||||
cores: () => 1,
|
||||
},
|
||||
|
||||
// Reading: the Program is one on the location the wearer fought from, the owner picks it, and it
|
||||
// stays disabled through the end of the next turn.
|
||||
'Overclocked CPU': {
|
||||
text: 'Avatar gains +2 Cores during combat, but one installed Program at the current server becomes disabled afterward for 2 turns.',
|
||||
cores: (_s, _src, f) => (f.role !== null ? 2 : 0),
|
||||
onCombatEnd(s, src) {
|
||||
const c = s.combat!;
|
||||
const role = wearing(src.ref, { ref: c.attacker }) ? 'attack' : c.defenders.some((d) => wearing(src.ref, { ref: d })) ? 'defend' : null;
|
||||
if (!role) return;
|
||||
const loc = role === 'attack' ? c.origin : c.loc;
|
||||
if (s.locations[loc].owner !== src.controller) return;
|
||||
const progs = programsOn(s, loc);
|
||||
if (progs.length === 0) return;
|
||||
fired(s, 'Overclocked CPU', src.controller);
|
||||
if (progs.length === 1) {
|
||||
disableForTwoTurns(s, progs[0]);
|
||||
return;
|
||||
}
|
||||
ask(s, {
|
||||
player: src.controller,
|
||||
kind: 'Overclocked CPU:disable',
|
||||
prompt: `Overclocked CPU: which Program on ${loc} is disabled for 2 turns?`,
|
||||
options: progs.map((id) => ({ label: nameOf(s, id), value: id })),
|
||||
resume: { name: 'Overclocked CPU', fn: 'disable', data: null },
|
||||
});
|
||||
},
|
||||
resume: {
|
||||
disable: (s, _data, id: number) => disableForTwoTurns(s, id),
|
||||
},
|
||||
},
|
||||
|
||||
'Solid-State Cache': {
|
||||
text: 'The first Program installed on the occupied Server each turn costs 3 less RAM.',
|
||||
costMod: (s, src, pay) =>
|
||||
pay.kind === 'program' && pay.player === src.controller && pay.at === src.at && hardwareUsesLeft(s, src.id) > 0 ? -3 : 0,
|
||||
onPaid(s, src) {
|
||||
useHardware(s, src.id);
|
||||
fired(s, 'Solid-State Cache', src.controller);
|
||||
},
|
||||
},
|
||||
|
||||
// Reading: the first time the wearer is defeated with this installed, all its Hardware stays on
|
||||
// it (in its slot) instead of being discarded.
|
||||
'Redundant Power Supply': {
|
||||
text: 'The first time this Avatar would be destroyed, do not destroy the Hardware.',
|
||||
savePriority: 0,
|
||||
onWearerDefeated(s, hw, ev) {
|
||||
if (s.cards[hw].spent) return false;
|
||||
s.cards[hw].spent = true;
|
||||
fired(s, 'Redundant Power Supply', ev.ref.player);
|
||||
say(s, `Redundant Power Supply: ${avatarName(s, ev.ref)} keeps its Hardware.`);
|
||||
knockOut(s, ev.ref, ev.loc, ev.role, true);
|
||||
return true;
|
||||
},
|
||||
},
|
||||
|
||||
// Ruling: it takes no port and adds one, so the wearer nets +1 Expansion Slot.
|
||||
'Network Interface Upgrade': {
|
||||
text: 'This Hardware can be played without taking an upgrade port on the Avatar.',
|
||||
noPort: true,
|
||||
extraSlots: 1,
|
||||
},
|
||||
|
||||
// Ruling: Servers perform Executions, so this works for Executions performed by the Server the
|
||||
// wearer stands on. +1 to the number the Execution uses (cards drawn, Cores, RAM recovered).
|
||||
'Dedicated GPU': {
|
||||
text: 'Executions performed by this Avatar receive +1 effectiveness or combat strength.',
|
||||
executionPower: 1,
|
||||
},
|
||||
|
||||
// Blocks opponents' Bug counters (see addBugs in util.ts; no card places them yet) and their
|
||||
// Bug Program effects on the wearer (Memory Leak, Stock Rice).
|
||||
'ECC Memory': {
|
||||
text: 'Opponents cannot place Bug counters or Bug status effects on this Avatar.',
|
||||
bugImmunity: true,
|
||||
},
|
||||
|
||||
// Works through hardwareUsesLeft() above.
|
||||
'Cooling System': {
|
||||
text: 'Allow one Hardware to activate twice per turn.',
|
||||
},
|
||||
|
||||
// Reading: half the combined printed RAM of its Hardware, rounded up.
|
||||
'RAID Array': {
|
||||
text: 'When this Avatar is destroyed, all hardware can be kept by paying half the RAM cost.',
|
||||
savePriority: 1,
|
||||
onWearerDefeated(s, hw, ev) {
|
||||
const av = avatar(s, ev.ref);
|
||||
const cost = Math.ceil(av.hardware.reduce((t, h) => t + defOf(s, h).ram, 0) / 2);
|
||||
ask(s, {
|
||||
player: ev.ref.player,
|
||||
kind: 'RAID Array:keep',
|
||||
prompt: `RAID Array: pay ${cost} RAM to keep ${av.hardware.map((h) => nameOf(s, h)).join(', ')}?`,
|
||||
options: [
|
||||
{ label: `Keep all Hardware for ${cost} RAM`, value: true, cost },
|
||||
{ label: 'Lose the Hardware', value: false },
|
||||
],
|
||||
resume: { name: 'RAID Array', fn: 'keep', data: { ref: ev.ref as never, loc: ev.loc, role: ev.role, cost } },
|
||||
});
|
||||
return true;
|
||||
},
|
||||
resume: {
|
||||
keep(s, data: { ref: AvatarRef; loc: string; role: 'attack' | 'defend'; cost: number }, keep: boolean) {
|
||||
if (keep) {
|
||||
s.players[data.ref.player].ram -= data.cost;
|
||||
stat(s, 'ramOnCards', data.ref.player, data.cost);
|
||||
fired(s, 'RAID Array', data.ref.player);
|
||||
}
|
||||
knockOut(s, data.ref, data.loc, data.role, keep);
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
'Packet Accelerator': {
|
||||
text: 'This Avatar gains +1 Core hen attacking.',
|
||||
cores: (_s, _src, f) => (f.role === 'attack' ? 1 : 0),
|
||||
},
|
||||
|
||||
// Programs never target Avatars, so this taxes Executions (and Hardware they hit).
|
||||
'Firewall Appliance': {
|
||||
text: 'The first hostile Program or Execution targeting this Avatar each turn costs the opponent +3 RAM.',
|
||||
costMod: (s, src, pay) =>
|
||||
pay.kind === 'execution' && pay.player !== src.controller && hardwareUsesLeft(s, src.id) > 0 &&
|
||||
(pay.hostile ?? []).some((r) => wearing(src.ref, { ref: r })) ? 3 : 0,
|
||||
onPaid(s, src) {
|
||||
useHardware(s, src.id);
|
||||
fired(s, 'Firewall Appliance', src.controller);
|
||||
},
|
||||
},
|
||||
|
||||
// Reading: pick the Program on install, and again at the start of your turn if the wearer has
|
||||
// moved. Protection only holds while the wearer stands on that Program's location.
|
||||
'Hardware Sandbox': {
|
||||
text: 'Choose one Program installed on the occupied Server. It cannot be targeted by opponents.',
|
||||
onInstall(s, src, ev: { card: number }) {
|
||||
if (ev.card === src.id) askSandbox(s, src.id);
|
||||
},
|
||||
onTurnStart(s, src) {
|
||||
if (s.active !== src.controller) return;
|
||||
const p = s.cards[src.id].protects;
|
||||
if (p === undefined || programLocation(s, p) !== src.at) askSandbox(s, src.id);
|
||||
},
|
||||
resume: {
|
||||
protect(s, data: { card: number }, program: number) {
|
||||
s.cards[data.card].protects = program;
|
||||
fired(s, 'Hardware Sandbox', ownerOf(s, data.card));
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// Reading: at the start of your turn, look at the top card and you may put it on the bottom.
|
||||
'Diagnostic Module': {
|
||||
text: 'Look at one face down card in your draw pile. You may place it at the bottom and draw another to start your turn.',
|
||||
onTurnStart(s, src) {
|
||||
if (s.active !== src.controller || hardwareUsesLeft(s, src.id) <= 0) return;
|
||||
const deck = s.players[src.controller].deck;
|
||||
if (deck.length < 2) return;
|
||||
useHardware(s, src.id);
|
||||
fired(s, 'Diagnostic Module', src.controller);
|
||||
ask(s, {
|
||||
player: src.controller,
|
||||
kind: 'Diagnostic Module:bottom',
|
||||
prompt: `Diagnostic Module: the top card of your deck is ${nameOf(s, deck[0])}. Put it on the bottom?`,
|
||||
options: [
|
||||
{ label: `Keep ${nameOf(s, deck[0])} on top`, value: false },
|
||||
{ label: `Put ${nameOf(s, deck[0])} on the bottom`, value: true },
|
||||
],
|
||||
resume: { name: 'Diagnostic Module', fn: 'bottom', data: { player: src.controller } },
|
||||
});
|
||||
},
|
||||
resume: {
|
||||
bottom(s, data: { player: PlayerId }, bottom: boolean) {
|
||||
const deck = s.players[data.player].deck;
|
||||
if (bottom && deck.length) deck.push(deck.shift()!);
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// Reading: swap Hardware on this Avatar, paying the difference in printed RAM (no refund).
|
||||
'Hot-Swap Bay': {
|
||||
text: 'Once per turn, return one Hardware to your hand and install another Hardware from your hand, paying the difference in cost.',
|
||||
ability: {
|
||||
hardwareOncePerTurn: true,
|
||||
uses(s, src) {
|
||||
const av = avatar(s, src.ref!);
|
||||
const hand = s.players[src.controller].hand.filter((id) => defOf(s, id).kind === 'hardware');
|
||||
return av.hardware.flatMap((out) => cardOptions(s, hand).map((o) => ({ card: out, cards: [o.value as number] })));
|
||||
},
|
||||
extraCost: (s, _src, args) => Math.max(0, defOf(s, args.cards![0]).ram - defOf(s, args.card!).ram),
|
||||
resolve(s, item, src) {
|
||||
const out = item.args.card!;
|
||||
const into = item.args.cards![0];
|
||||
const ref = src.ref!;
|
||||
if (!avatar(s, ref).hardware.includes(out) || !s.players[src.controller].hand.includes(into)) return;
|
||||
uninstallHardware(s, out);
|
||||
toHand(s, out);
|
||||
attachHardware(s, into, ref);
|
||||
fired(s, 'Hot-Swap Bay', src.controller);
|
||||
say(s, `Hot-Swap Bay swaps ${nameOf(s, out)} for ${nameOf(s, into)} on ${avatarName(s, ref)}.`);
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// Ruling: Servers perform Executions, so "this Avatar uses an Execution" means one performed by
|
||||
// the Server the wearer stands on. "Disable this Hardware" lasts until your next turn.
|
||||
'Quantum Coprocessor': {
|
||||
text: "Once per turn when this Avatar uses an Execution, you may copy that Execution's effect with a different legal target, then disable this Hardware.",
|
||||
copiesExecutions: true,
|
||||
resume: {
|
||||
offer(s, data: { item: StackItem }) {
|
||||
const item = data.item;
|
||||
const wearers = refsInPlay(s, item.player).filter((r) => !isCopy(r) && avatar(s, r).at === item.from && !desynced(s, r));
|
||||
const qc = wearers.flatMap((r) => avatar(s, r).hardware)
|
||||
.find((hw) => s.cards[hw].name === 'Quantum Coprocessor' && hardwareActive(s, hw) && hardwareUsesLeft(s, hw) > 0);
|
||||
if (qc === undefined) return;
|
||||
const ex = scriptOf(item.name)?.execution;
|
||||
if (!ex) return;
|
||||
const same = JSON.stringify({ t: item.target, a: item.args });
|
||||
const plays = ex.plays(s, item.player).filter((p) => JSON.stringify({ t: p.target, a: p.args }) !== same);
|
||||
if (plays.length === 0) return;
|
||||
ask(s, {
|
||||
player: item.player,
|
||||
kind: 'Quantum Coprocessor:copy',
|
||||
prompt: `Quantum Coprocessor: copy ${item.name} with a different target?`,
|
||||
options: [
|
||||
{ label: "Don't copy", value: null },
|
||||
...plays.map((p) => ({ label: `${p.target ?? 'no target'} ${describeArgs(s, p.args)}`, value: { target: p.target, args: p.args as never } })),
|
||||
],
|
||||
resume: { name: 'Quantum Coprocessor', fn: 'copy', data: { item: item as never, qc } },
|
||||
});
|
||||
},
|
||||
copy(s, data: { item: StackItem; qc: number }, v: { target: string | null; args: never } | null) {
|
||||
if (!v) return;
|
||||
useHardware(s, data.qc);
|
||||
s.cards[data.qc].disabledUntil = startOf(nextTurnOf(s, data.item.player));
|
||||
fired(s, 'Quantum Coprocessor', data.item.player);
|
||||
say(s, `Quantum Coprocessor copies ${data.item.name} onto ${v.target ?? 'a new target'}.`);
|
||||
scriptOf(data.item.name)!.execution!.resolve(s, { ...data.item, target: v.target, args: v.args, from: null });
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
function describeArgs(s: GameState, a: StackItem['args']): string {
|
||||
const parts: string[] = [];
|
||||
if (a.ref) parts.push(avatarName(s, a.ref));
|
||||
if (a.card !== undefined) parts.push(nameOf(s, a.card));
|
||||
if (a.to) parts.push(`→ ${a.to}`);
|
||||
if (a.mode) parts.push(a.mode);
|
||||
return parts.join(' ');
|
||||
}
|
||||
|
||||
function disableForTwoTurns(s: GameState, id: number): void {
|
||||
s.cards[id].disabledUntil = Math.max(s.cards[id].disabledUntil, endOf(s.turn + 1));
|
||||
say(s, `Overclocked CPU: ${nameOf(s, id)} is disabled for 2 turns.`);
|
||||
}
|
||||
|
||||
function askSandbox(s: GameState, card: number): void {
|
||||
const ref = wearerOf(s, card);
|
||||
const at = ref ? avatar(s, ref).at : null;
|
||||
if (!ref || !at) return;
|
||||
const progs = (s.locations[at] as LocationState).programs.filter((id) => ownerOf(s, id) === ref.player);
|
||||
if (progs.length === 0) return;
|
||||
if (progs.length === 1) {
|
||||
s.cards[card].protects = progs[0];
|
||||
return;
|
||||
}
|
||||
ask(s, {
|
||||
player: ref.player,
|
||||
kind: 'Hardware Sandbox:protect',
|
||||
prompt: `Hardware Sandbox: protect which Program on ${at}?`,
|
||||
options: progs.map((id) => ({ label: nameOf(s, id), value: id })),
|
||||
resume: { name: 'Hardware Sandbox', fn: 'protect', data: { card } },
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue