sim
This commit is contained in:
parent
746d218eda
commit
e590baf28d
44 changed files with 8308 additions and 0 deletions
599
sim/src/cards/programs.ts
Normal file
599
sim/src/cards/programs.ts
Normal file
|
|
@ -0,0 +1,599 @@
|
|||
/**
|
||||
* Programs. A Program sits on a location its owner controls and its effect is local: "this
|
||||
* Server" is the location it's on (or where Worm Protocol spreads it). Enemy Avatars are only
|
||||
* ever "at" your location while attacking or capturing it.
|
||||
*/
|
||||
import { LOCATIONS, type LocId } from '../map.ts';
|
||||
import {
|
||||
bugImmune,
|
||||
canTargetProgram,
|
||||
emit,
|
||||
hardwareActive,
|
||||
installedCount,
|
||||
programSlots,
|
||||
sameSource,
|
||||
sources,
|
||||
sourcesNamed,
|
||||
} from '../query.ts';
|
||||
import { scriptOf, type Script } from '../scripts.ts';
|
||||
import {
|
||||
activeMods,
|
||||
addMod,
|
||||
ask,
|
||||
avatar,
|
||||
avatarName,
|
||||
controls,
|
||||
defOf,
|
||||
fired,
|
||||
gainRam,
|
||||
hardwareOf,
|
||||
infectionOf,
|
||||
isCopy,
|
||||
later,
|
||||
markUsed,
|
||||
nameOf,
|
||||
neighbors,
|
||||
nextTurnOf,
|
||||
ownerOf,
|
||||
played,
|
||||
playerName,
|
||||
programLocation,
|
||||
pushTasks,
|
||||
refsInPlay,
|
||||
removeFrom,
|
||||
running,
|
||||
sameRef,
|
||||
say,
|
||||
startOf,
|
||||
stat,
|
||||
toDiscard,
|
||||
toHand,
|
||||
uninstallProgram,
|
||||
usedThisTurn,
|
||||
} from '../state.ts';
|
||||
import { randInt } from '../rng.ts';
|
||||
import { FOREVER, type AvatarRef, type GameState, type PlayerId, type Source, type Task } from '../types.ts';
|
||||
import { cardOptions, infect, isPatch, isVirus, programsOn } from './util.ts';
|
||||
|
||||
const enemyOf = (src: Source, ref: AvatarRef) => ref.player !== src.controller;
|
||||
/** The first active source with this name at the location, so duplicates don't double up. */
|
||||
const firstHere = (s: GameState, src: Source, loc: LocId) => {
|
||||
const first = sourcesNamed(s, src.name, loc)[0];
|
||||
return !!first && sameSource(first, src);
|
||||
};
|
||||
|
||||
/**
|
||||
* Destroys an installed Program. Hotfix (first each turn) disables it instead; otherwise Version
|
||||
* Control returns it to its owner's hand.
|
||||
*/
|
||||
export function destroyProgram(s: GameState, id: number): void {
|
||||
const loc = programLocation(s, id);
|
||||
if (!loc) return;
|
||||
const owner = ownerOf(s, id);
|
||||
const here = sources(s).filter((x) => x.at === loc && x.controller === owner && x.virtual === undefined);
|
||||
const hotfix = here.find((x) => x.name === 'Hotfix' && usedThisTurn(s, `hotfix:${x.id}`) === 0);
|
||||
if (hotfix) {
|
||||
markUsed(s, `hotfix:${hotfix.id}`);
|
||||
s.cards[id].disabledUntil = Math.max(s.cards[id].disabledUntil, startOf(nextTurnOf(s, owner)));
|
||||
fired(s, 'Hotfix', owner);
|
||||
say(s, `Hotfix: ${nameOf(s, id)} is disabled instead of destroyed.`);
|
||||
return;
|
||||
}
|
||||
uninstallProgram(s, id);
|
||||
stat(s, 'programsLost', owner);
|
||||
if (here.some((x) => x.name === 'Version Control')) {
|
||||
fired(s, 'Version Control', owner);
|
||||
toHand(s, id);
|
||||
say(s, `Version Control: ${nameOf(s, id)} returns to ${playerName(owner)}'s hand.`);
|
||||
return;
|
||||
}
|
||||
toDiscard(s, id);
|
||||
say(s, `${nameOf(s, id)} is destroyed.`);
|
||||
}
|
||||
|
||||
/** Installs a Program for free (Replication Routine). */
|
||||
function installFree(s: GameState, card: number, at: LocId): void {
|
||||
const p = ownerOf(s, card);
|
||||
removeFrom(s.players[p].hand, card);
|
||||
s.locations[at].programs.push(card);
|
||||
s.cards[card].installedTurn = s.turn;
|
||||
stat(s, 'programsInstalled', p);
|
||||
played(s, nameOf(s, card), p);
|
||||
say(s, `${playerName(p)} installs ${nameOf(s, card)} on ${at} for free.`);
|
||||
emit(s, 'onInstall', { card, at, ref: null });
|
||||
}
|
||||
|
||||
/** Negative things on an Avatar that Error Correction can remove, one at a time. */
|
||||
function negatives(s: GameState, ref: AvatarRef): { label: string; value: string }[] {
|
||||
const av = avatar(s, ref);
|
||||
const out: { label: string; value: string }[] = [];
|
||||
if (av.infection > 0) out.push({ label: 'an Infection counter', value: 'infection' });
|
||||
if (av.bugs > 0) out.push({ label: 'a Bug counter', value: 'bug' });
|
||||
if (av.permanentInfection > 0) out.push({ label: 'a permanent Infection counter', value: 'permanent' });
|
||||
for (const hw of hardwareOf(s, ref)) {
|
||||
if (!hardwareActive(s, hw)) out.push({ label: `disabled ${nameOf(s, hw)}`, value: `hw:${hw}` });
|
||||
}
|
||||
const worst = activeMods(s, av).filter((m) => m.cores < 0).sort((a, b) => b.seq - a.seq)[0];
|
||||
if (worst) out.push({ label: `${worst.cores} Cores from ${worst.source}`, value: `mod:${worst.seq}` });
|
||||
if (running(s, av.rootedUntil)) out.push({ label: 'Packet Flood', value: 'rooted' });
|
||||
if (running(s, av.disabledUntil)) out.push({ label: 'Disabled', value: 'disabled' });
|
||||
return out;
|
||||
}
|
||||
|
||||
function removeNegative(s: GameState, ref: AvatarRef, what: string): void {
|
||||
const av = avatar(s, ref);
|
||||
if (what === 'infection') av.infection--;
|
||||
else if (what === 'bug') av.bugs--;
|
||||
else if (what === 'permanent') av.permanentInfection--;
|
||||
else if (what === 'rooted') av.rootedUntil = 0;
|
||||
else if (what === 'disabled') av.disabledUntil = 0;
|
||||
else if (what.startsWith('hw:')) s.cards[Number(what.slice(3))].disabledUntil = 0;
|
||||
else if (what.startsWith('mod:')) av.mods = av.mods.filter((m) => m.seq !== Number(what.slice(4)));
|
||||
}
|
||||
|
||||
export const PROGRAMS: Record<string, Script> = {
|
||||
// Reading: one counter per attack declared on this Server, or per capture of it that wasn't an
|
||||
// attack. The -2 applies anywhere while this Program is in play, and doesn't stack with copies.
|
||||
'Recursive Infection': {
|
||||
text: 'Whenever an enemy Avatar attacks or breaches this Server, place an Infection counter on it. An Avatar with 3+ Infection counters has -2 Core.',
|
||||
onAttackDeclared(s, src, ev: { ref: AvatarRef; to: LocId }) {
|
||||
if (ev.to === src.at && enemyOf(src, ev.ref)) infect(s, ev.ref, 1, 'Recursive Infection', src.controller);
|
||||
},
|
||||
onBreach(s, src, ev: { ref: AvatarRef; loc: LocId }) {
|
||||
if (ev.loc !== src.at || !enemyOf(src, ev.ref)) return;
|
||||
const attacked = s.declarations.some((d) => d.kind === 'attack' && sameRef(d.ref, ev.ref) && d.to === ev.loc);
|
||||
if (!attacked) infect(s, ev.ref, 1, 'Recursive Infection', src.controller);
|
||||
},
|
||||
globalCores: (s, f) => (infectionOf(avatar(s, f.ref)) >= 3 ? -2 : 0),
|
||||
},
|
||||
|
||||
// Reading: "owner" is the attacking Avatar's owner, who picks which of its Hardware is disabled
|
||||
// for that combat.
|
||||
'Memory Parasite': {
|
||||
text: "Enemy Avatars attacking this Server have 1 hardware component disabled of the owners choosing.",
|
||||
onCombatStart(s, src) {
|
||||
const c = s.combat!;
|
||||
if (c.loc !== src.at || !enemyOf(src, c.attacker)) return;
|
||||
const hw = hardwareOf(s, c.attacker).filter((h) => hardwareActive(s, h) && !c.suppressed.includes(h));
|
||||
if (hw.length === 0) return;
|
||||
fired(s, 'Memory Parasite', src.controller);
|
||||
if (hw.length === 1) {
|
||||
c.suppressed.push(hw[0]);
|
||||
say(s, `Memory Parasite disables ${nameOf(s, hw[0])} for this combat.`);
|
||||
return;
|
||||
}
|
||||
ask(s, {
|
||||
player: c.attacker.player,
|
||||
kind: 'Memory Parasite:disable',
|
||||
prompt: 'Memory Parasite: which of your Hardware is disabled for this combat?',
|
||||
options: hw.map((h) => ({ label: nameOf(s, h), value: h })),
|
||||
resume: { name: 'Memory Parasite', fn: 'disable', data: null },
|
||||
});
|
||||
},
|
||||
resume: {
|
||||
disable(s, _data, hw: number) {
|
||||
s.combat?.suppressed.push(hw);
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// Reading: installing this card counts, so it can bring a second Virus with it.
|
||||
'Replication Routine': {
|
||||
text: 'When you install a Virus Program on this Server, you may install a second Virus Program from your hand here for no RAM cost.',
|
||||
onInstall(s, src, ev: { card: number; at: LocId | null }) {
|
||||
if (!src.at || ev.at !== src.at || src.virtual !== undefined || !isVirus(s, ev.card)) return;
|
||||
if (s.locations[src.at].programs.length >= programSlots(s, src.at)) return;
|
||||
const hand = s.players[src.controller].hand.filter((id) => isVirus(s, id));
|
||||
if (hand.length === 0) return;
|
||||
ask(s, {
|
||||
player: src.controller,
|
||||
kind: 'Replication Routine:install',
|
||||
prompt: `Replication Routine: install a second Virus Program on ${src.at} for free?`,
|
||||
options: [{ label: 'No', value: null }, ...cardOptions(s, hand)],
|
||||
resume: { name: 'Replication Routine', fn: 'install', data: { at: src.at } },
|
||||
});
|
||||
},
|
||||
resume: {
|
||||
install(s, data: { at: LocId }, card: number | null) {
|
||||
if (card === null || !controls(s, ownerOf(s, card), data.at)) return;
|
||||
if (s.locations[data.at].programs.length >= programSlots(s, data.at)) return;
|
||||
fired(s, 'Replication Routine', ownerOf(s, card));
|
||||
installFree(s, card, data.at);
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
'Resource Leech': {
|
||||
text: 'Whenever an enemy Avatar is destroyed while attacking this Server, gain 5 RAM.',
|
||||
onDefeat(s, src, ev: { ref: AvatarRef; loc: LocId; role: string }) {
|
||||
if (ev.loc !== src.at || ev.role !== 'attack' || !enemyOf(src, ev.ref)) return;
|
||||
gainRam(s, src.controller, 5);
|
||||
fired(s, 'Resource Leech', src.controller);
|
||||
say(s, `Resource Leech: ${playerName(src.controller)} gains 5 RAM.`);
|
||||
},
|
||||
},
|
||||
|
||||
'Worm Protocol': {
|
||||
text: 'The localized effects of your other Programs on this Server also apply at one adjacent Server you choose when this is installed.',
|
||||
onInstall(s, src, ev: { card: number }) {
|
||||
if (ev.card !== src.id || src.virtual !== undefined) return;
|
||||
const near = neighbors(s, src.at!);
|
||||
if (near.length === 0) return;
|
||||
ask(s, {
|
||||
player: src.controller,
|
||||
kind: 'Worm Protocol:spread',
|
||||
prompt: `Worm Protocol on ${src.at}: spread your other Programs' effects to which adjacent location?`,
|
||||
options: near.map((l) => ({ label: l, value: l })),
|
||||
resume: { name: 'Worm Protocol', fn: 'spread', data: { card: src.id } },
|
||||
});
|
||||
},
|
||||
resume: {
|
||||
spread(s, data: { card: number }, to: LocId) {
|
||||
s.cards[data.card].wormTo = to;
|
||||
fired(s, 'Worm Protocol', ownerOf(s, data.card));
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
'Payload Injector': {
|
||||
text: 'The first Execution you play targeting this Server each turn costs 2 less RAM.',
|
||||
costMod: (s, src, pay) =>
|
||||
pay.kind === 'execution' && pay.player === src.controller && pay.at === src.at &&
|
||||
usedThisTurn(s, `payload:${src.id}`) === 0 ? -2 : 0,
|
||||
onPaid(s, src) {
|
||||
markUsed(s, `payload:${src.id}`);
|
||||
fired(s, 'Payload Injector', src.controller);
|
||||
},
|
||||
},
|
||||
|
||||
// Reading: enemy Avatars only (Virus Programs hit attackers). The counter survives defeat.
|
||||
'Persistent Infection': {
|
||||
text: 'If an Avatar is defeated at this Server, place an Infection Counter on it permanently.',
|
||||
onDefeat(s, src, ev: { ref: AvatarRef; loc: LocId }) {
|
||||
if (ev.loc !== src.at || !enemyOf(src, ev.ref) || isCopy(ev.ref)) return;
|
||||
infect(s, ev.ref, 1, 'Persistent Infection', src.controller, true);
|
||||
},
|
||||
},
|
||||
|
||||
// Reading: your Avatar attacking from this Server may declare a second attack on another
|
||||
// adjacent location. Both come from this Server, even if the first one moved it.
|
||||
'Infinite Loop': {
|
||||
text: 'If the attacking Avatar is controlled by the owner of this Program, it may attack a second adjacent Server in the same turn.',
|
||||
extraAttacks: 1,
|
||||
},
|
||||
|
||||
'Stack Overflow': {
|
||||
text: 'Avatars you control defending this Server gain +1 Core for each Program installed on this Server (including this one).',
|
||||
cores: (s, src, f) =>
|
||||
f.role === 'defend' && f.at === src.at && f.ref.player === src.controller ? installedCount(s, src.at!) : 0,
|
||||
},
|
||||
|
||||
// Both players pick at the same time; the attacker's pick stays hidden from the defender.
|
||||
'Race Condition': {
|
||||
text: 'During any combat at this Server, both players secretly choose Attack or Defend. If the choices differ, the defender gains a combat bonus of +2 Cores.',
|
||||
onCombatStart(s, src) {
|
||||
const c = s.combat!;
|
||||
if (c.loc !== src.at || !firstHere(s, src, c.loc)) return;
|
||||
fired(s, 'Race Condition', src.controller);
|
||||
askRace(s, c.attacker.player);
|
||||
},
|
||||
resume: {
|
||||
pick(s, data: { player: PlayerId }, pick: 'attack' | 'defend') {
|
||||
const c = s.combat;
|
||||
if (!c || c.ended) return;
|
||||
c.race[data.player] = pick;
|
||||
const defender = c.defenders[0]?.player ?? (c.attacker.player === 0 ? 1 : 0);
|
||||
if (data.player === c.attacker.player) {
|
||||
askRace(s, defender);
|
||||
return;
|
||||
}
|
||||
const [a, d] = [c.race[c.attacker.player], c.race[defender]];
|
||||
say(s, `Race Condition: attacker chose ${a}, defender chose ${d}.`);
|
||||
if (a !== d && c.defenders.length) {
|
||||
addMod(s, c.defenders[0], 2, 'Race Condition', defender, { combat: c.id });
|
||||
say(s, 'The choices differ: the defender gets +2 Cores.');
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
'Memory Leak': {
|
||||
text: 'At the start of any combat at this Server, the attacking Avatar loses 1 Core for each Hardware installed on it.',
|
||||
onCombatStart(s, src) {
|
||||
const c = s.combat!;
|
||||
if (c.loc !== src.at || !enemyOf(src, c.attacker) || bugImmune(s, c.attacker, src.controller)) return;
|
||||
const n = hardwareOf(s, c.attacker).length;
|
||||
if (n === 0) return;
|
||||
addMod(s, c.attacker, -n, 'Memory Leak', src.controller, { combat: c.id });
|
||||
fired(s, 'Memory Leak', src.controller);
|
||||
say(s, `Memory Leak: ${avatarName(s, c.attacker)} loses ${n} Core${n === 1 ? '' : 's'}.`);
|
||||
},
|
||||
},
|
||||
|
||||
'Null Pointer': {
|
||||
text: "Once per turn, when an enemy Execution would resolve at this Server, it's effect does not occur.",
|
||||
negates(s, src, item) {
|
||||
if (item.player === src.controller || item.target !== src.at || usedThisTurn(s, `null:${src.id}`) > 0) return false;
|
||||
markUsed(s, `null:${src.id}`);
|
||||
fired(s, 'Null Pointer', src.controller);
|
||||
say(s, `Null Pointer: ${item.name} has no effect.`);
|
||||
return true;
|
||||
},
|
||||
},
|
||||
|
||||
// Reading: "Hardware bonuses" are the Cores Hardware adds.
|
||||
'Stock Rice': {
|
||||
text: 'Neither Avatar in a combat that takes place at this Server may use any Hardware bonuses.',
|
||||
blocksHardwareInCombat: true,
|
||||
onCombatStart(s, src) {
|
||||
if (s.combat!.loc === src.at) fired(s, 'Stock Rice', src.controller);
|
||||
},
|
||||
},
|
||||
|
||||
// Reading: an unspecified disable lasts until something re-enables it (Execute: Defragment).
|
||||
'Overflow Error': {
|
||||
text: "When an enemy Avatar is destroyed while attacking this Server, destroy or disable one Program that Avatar's controller has in play.",
|
||||
onDefeat(s, src, ev: { ref: AvatarRef; loc: LocId; role: string }) {
|
||||
if (ev.loc !== src.at || ev.role !== 'attack' || !enemyOf(src, ev.ref)) return;
|
||||
const theirs = LOCATIONS.flatMap((l) => (controls(s, ev.ref.player, l) ? programsOn(s, l) : []))
|
||||
.filter((id) => canTargetProgram(s, id, src.controller));
|
||||
if (theirs.length === 0) return;
|
||||
fired(s, 'Overflow Error', src.controller);
|
||||
ask(s, {
|
||||
player: src.controller,
|
||||
kind: 'Overflow Error:hit',
|
||||
prompt: 'Overflow Error: destroy or disable one of their Programs.',
|
||||
options: theirs.flatMap((id) => [
|
||||
{ label: `Destroy ${nameOf(s, id)} on ${programLocation(s, id)}`, value: { card: id, mode: 'destroy' } },
|
||||
{ label: `Disable ${nameOf(s, id)} on ${programLocation(s, id)}`, value: { card: id, mode: 'disable' } },
|
||||
]),
|
||||
resume: { name: 'Overflow Error', fn: 'hit', data: null },
|
||||
});
|
||||
},
|
||||
resume: {
|
||||
hit(s, _data, v: { card: number; mode: string }) {
|
||||
if (!programLocation(s, v.card)) return;
|
||||
if (v.mode === 'destroy') destroyProgram(s, v.card);
|
||||
else s.cards[v.card].disabledUntil = FOREVER;
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// Reading: the copy lasts until your next turn, while this Program is disabled.
|
||||
'Undefined Behavior': {
|
||||
text: 'Once per turn, copy the localized effect of another Program on another Server. Then disable this Program until your next turn.',
|
||||
ability: {
|
||||
uses(s, src) {
|
||||
if (src.kind !== 'program' || src.virtual !== undefined) return [];
|
||||
return LOCATIONS.filter((l) => l !== src.at)
|
||||
.flatMap((l) => programsOn(s, l))
|
||||
.filter((id) => nameOf(s, id) !== 'Undefined Behavior' && canTargetProgram(s, id, src.controller))
|
||||
.map((card) => ({ card }));
|
||||
},
|
||||
resolve(s, item, src) {
|
||||
const card = item.args.card!;
|
||||
if (!programLocation(s, card)) return;
|
||||
const until = startOf(nextTurnOf(s, src.controller));
|
||||
s.virtuals.push({ id: ++s.seq, name: nameOf(s, card), controller: src.controller, at: src.at!, until, installed: false, from: card });
|
||||
s.cards[src.id].disabledUntil = Math.max(s.cards[src.id].disabledUntil, until);
|
||||
fired(s, 'Undefined Behavior', src.controller);
|
||||
say(s, `Undefined Behavior on ${src.at} copies ${nameOf(s, card)} and shuts itself off until ${playerName(src.controller)}'s next turn.`);
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
'Packet Loss': {
|
||||
text: 'When an enemy successfully breaches this Server, its controller discards a card at random.',
|
||||
onBreach(s, src, ev: { ref: AvatarRef; loc: LocId }) {
|
||||
if (ev.loc !== src.at || !enemyOf(src, ev.ref)) return;
|
||||
const hand = s.players[ev.ref.player].hand;
|
||||
if (hand.length === 0) return;
|
||||
const card = hand[randInt(s.rng, hand.length)];
|
||||
removeFrom(hand, card);
|
||||
toDiscard(s, card);
|
||||
fired(s, 'Packet Loss', src.controller);
|
||||
say(s, `Packet Loss: ${playerName(ev.ref.player)} discards ${nameOf(s, card)} at random.`);
|
||||
},
|
||||
},
|
||||
|
||||
// The once-per-turn Hardware abilities are Hot-Swap Bay's and Quantum Coprocessor's.
|
||||
Desynchronization: {
|
||||
text: 'Enemy Avatars attacking this Server cannot use their Hardware\'s "once per turn" abilities during that combat.',
|
||||
blocksHardwareAbilities: true,
|
||||
},
|
||||
|
||||
// Reading: "each turn" was removed from the card, so this works once per installation.
|
||||
'Visual Artifact': {
|
||||
text: 'The first attack made against an Avatar you control at this Server suffers -1 Core.',
|
||||
onCombatStart(s, src) {
|
||||
const c = s.combat!;
|
||||
if (c.loc !== src.at || s.cards[src.id].spent || c.defenders.every((d) => d.player !== src.controller)) return;
|
||||
s.cards[src.id].spent = true;
|
||||
addMod(s, c.attacker, -1, 'Visual Artifact', src.controller, { combat: c.id });
|
||||
fired(s, 'Visual Artifact', src.controller);
|
||||
say(s, `Visual Artifact: ${avatarName(s, c.attacker)} gets -1 Core.`);
|
||||
},
|
||||
},
|
||||
|
||||
// Executions check for this through scopeOf() in util.ts.
|
||||
'Ghost Process': {
|
||||
text: 'Your Executions played targeting this Server may also affect Avatars, Programs, and Hardware at one adjacent Server.',
|
||||
},
|
||||
|
||||
// Runs from the engine right after an enemy Execution that targets an Avatar is played.
|
||||
'False Positive': {
|
||||
text: 'When an enemy Execution targets an Avatar you control at this Server, you may redirect it to another legal Avatar at another Server.',
|
||||
resume: {
|
||||
offer(s, data: { index: number }) {
|
||||
const item = s.stack[data.index];
|
||||
if (!item) return;
|
||||
const ex = scriptOf(item.name)?.execution;
|
||||
const hit = ex?.targetsAvatars?.(s, item) ?? [];
|
||||
const guarded = hit.find((r) => {
|
||||
if (r.player === item.player) return false;
|
||||
const at = avatar(s, r).at;
|
||||
return sources(s).some((x) => x.name === 'False Positive' && x.at === at && x.controller === r.player);
|
||||
});
|
||||
if (!ex || !guarded) return;
|
||||
const from = avatar(s, guarded).at;
|
||||
const options = ex.plays(s, item.player).filter((play) => {
|
||||
const refs = ex.targetsAvatars?.(s, { player: item.player, target: play.target, args: play.args }) ?? [];
|
||||
return refs.length > 0 && refs.every((r) => avatar(s, r).at !== from && !sameRef(r, guarded));
|
||||
});
|
||||
if (options.length === 0) return;
|
||||
ask(s, {
|
||||
player: guarded.player,
|
||||
kind: 'False Positive:redirect',
|
||||
prompt: `False Positive: redirect ${item.name} away from ${avatarName(s, guarded)}?`,
|
||||
options: [
|
||||
{ label: 'Leave it', value: null },
|
||||
...options.map((play) => ({
|
||||
label: `Redirect to ${play.args.ref ? avatarName(s, play.args.ref) : nameOf(s, play.args.card ?? -1)} on ${play.target}`,
|
||||
value: { index: data.index, target: play.target, args: play.args as never },
|
||||
})),
|
||||
],
|
||||
resume: { name: 'False Positive', fn: 'redirect', data: null },
|
||||
});
|
||||
},
|
||||
redirect(s, _data, v: { index: number; target: LocId; args: never } | null) {
|
||||
if (!v) return;
|
||||
const item = s.stack[v.index];
|
||||
if (!item) return;
|
||||
item.target = v.target;
|
||||
item.args = v.args;
|
||||
fired(s, 'False Positive', item.player === 0 ? 1 : 0);
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Fragmentation: {
|
||||
text: 'Executions your opponents play targeting this Server cost +2 RAM.',
|
||||
costMod: (s, src, pay) => (pay.kind === 'execution' && pay.player !== src.controller && pay.at === src.at ? 2 : 0),
|
||||
onPaid: (s, src) => fired(s, 'Fragmentation', src.controller),
|
||||
},
|
||||
|
||||
'Latency Spike': {
|
||||
text: 'The attacking player cannot play Executions during the first step of any combat at this Server.',
|
||||
blocksAttackerExecutions: true,
|
||||
},
|
||||
|
||||
// Destroyed means destroyed by an effect (Overflow Error). A captured location's Programs aren't
|
||||
// destroyed; they're discarded (see Version Control).
|
||||
Hotfix: {
|
||||
text: 'The first Program on this Server that would be destroyed each turn is instead disabled until your next turn.',
|
||||
},
|
||||
|
||||
'Error Correction': {
|
||||
text: 'At the beginning of your turn, remove one negative counter or status from each Avatar you control at this Server.',
|
||||
onTurnStart(s, src) {
|
||||
if (s.active !== src.controller) return;
|
||||
const tasks: Task[] = refsInPlay(s, src.controller)
|
||||
.filter((r) => avatar(s, r).at === src.at)
|
||||
.map((r) => later('Error Correction', 'fix', { ref: r as never }));
|
||||
pushTasks(s, ...tasks);
|
||||
},
|
||||
resume: {
|
||||
fix(s, data: { ref: AvatarRef }) {
|
||||
const list = negatives(s, data.ref);
|
||||
if (list.length === 0) return;
|
||||
fired(s, 'Error Correction', data.ref.player);
|
||||
if (list.length === 1) {
|
||||
removeNegative(s, data.ref, list[0].value);
|
||||
say(s, `Error Correction removes ${list[0].label} from ${avatarName(s, data.ref)}.`);
|
||||
return;
|
||||
}
|
||||
ask(s, {
|
||||
player: data.ref.player,
|
||||
kind: 'Error Correction:remove',
|
||||
prompt: `Error Correction: remove what from ${avatarName(s, data.ref)}?`,
|
||||
options: list,
|
||||
resume: { name: 'Error Correction', fn: 'remove', data: { ref: data.ref as never } },
|
||||
});
|
||||
},
|
||||
remove(s, data: { ref: AvatarRef }, what: string) {
|
||||
removeNegative(s, data.ref, what);
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// Reading: it can sacrifice itself.
|
||||
'Garbage Collection': {
|
||||
text: 'Once per turn, sacrifice one Program installed on this Server to recover its printed RAM value.',
|
||||
ability: {
|
||||
uses: (s, src) => (src.kind === 'program' ? s.locations[src.at!].programs.map((card) => ({ card })) : []),
|
||||
resolve(s, item, src) {
|
||||
const card = item.args.card!;
|
||||
if (programLocation(s, card) !== src.at) return;
|
||||
uninstallProgram(s, card);
|
||||
toDiscard(s, card);
|
||||
stat(s, 'programsLost', src.controller);
|
||||
gainRam(s, src.controller, defOf(s, card).ram);
|
||||
fired(s, 'Garbage Collection', src.controller);
|
||||
say(s, `Garbage Collection sacrifices ${nameOf(s, card)} for ${defOf(s, card).ram} RAM.`);
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
'Version Control': {
|
||||
text: 'When a Program on this Server would be destroyed, or when this Server is captured, return one Program from this Server to your hand instead of discarding it.',
|
||||
onCaptured(s, src, ev: { loc: LocId }) {
|
||||
if (ev.loc !== src.at || src.virtual !== undefined) return;
|
||||
const here = s.locations[ev.loc].programs;
|
||||
if (here.length === 0) return;
|
||||
ask(s, {
|
||||
player: src.controller,
|
||||
kind: 'Version Control:save',
|
||||
prompt: `Version Control: ${ev.loc} is being captured. Return which Program to your hand?`,
|
||||
options: here.map((id) => ({ label: nameOf(s, id), value: id })),
|
||||
resume: { name: 'Version Control', fn: 'save', data: null },
|
||||
});
|
||||
},
|
||||
resume: {
|
||||
save(s, _data, card: number) {
|
||||
if (!uninstallProgram(s, card)) return;
|
||||
toHand(s, card);
|
||||
fired(s, 'Version Control', ownerOf(s, card));
|
||||
say(s, `Version Control returns ${nameOf(s, card)} to ${playerName(ownerOf(s, card))}'s hand.`);
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
'Rollback Routine': {
|
||||
text: 'Once per turn, undo the most recent temporary stat reduction applied to an Avatar you control at this Server.',
|
||||
ability: {
|
||||
uses(s, src) {
|
||||
if (src.kind !== 'program') return [];
|
||||
return refsInPlay(s, src.controller)
|
||||
.filter((r) => avatar(s, r).at === src.at && activeMods(s, avatar(s, r)).some((m) => m.cores < 0))
|
||||
.map((ref) => ({ ref }));
|
||||
},
|
||||
resolve(s, item, src) {
|
||||
const av = avatar(s, item.args.ref!);
|
||||
if (av.at !== src.at) return;
|
||||
const last = activeMods(s, av).filter((m) => m.cores < 0).sort((a, b) => b.seq - a.seq)[0];
|
||||
if (!last) return;
|
||||
av.mods = av.mods.filter((m) => m !== last);
|
||||
fired(s, 'Rollback Routine', src.controller);
|
||||
say(s, `Rollback Routine undoes ${last.cores} Cores from ${last.source} on ${avatarName(s, item.args.ref!)}.`);
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
'Compatibility Layer': {
|
||||
text: 'This Server may hold one additional Program beyond the normal limit, and Patch Programs installed here cost 2 less RAM.',
|
||||
programSlots: 1,
|
||||
costMod: (s, src, pay) =>
|
||||
pay.kind === 'program' && pay.player === src.controller && pay.at === src.at && isPatch(s, pay.card!) ? -2 : 0,
|
||||
onPaid: (s, src) => fired(s, 'Compatibility Layer', src.controller),
|
||||
},
|
||||
};
|
||||
|
||||
function askRace(s: GameState, player: PlayerId): void {
|
||||
ask(s, {
|
||||
player,
|
||||
kind: 'Race Condition:pick',
|
||||
prompt: 'Race Condition: secretly choose Attack or Defend.',
|
||||
options: [{ label: 'Attack', value: 'attack' }, { label: 'Defend', value: 'defend' }],
|
||||
resume: { name: 'Race Condition', fn: 'pick', data: { player } },
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue