files-game/engine/cards/programs.gd
2026-10-01 23:01:56 -04:00

737 lines
29 KiB
GDScript3

class_name ProgramCards
## Programs (cards/programs.ts). 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 Anomalies
## are only ever "at" your location while attacking or capturing it.
static func _enemy_of(src: Dictionary, r: Dictionary) -> bool:
return r.player != src.controller
## The first active source with this name at the location, so duplicates don't double up.
static func _first_here(s: Dictionary, src: Dictionary, loc: String) -> bool:
var named := Query.sources_named(s, src.name, loc)
return not named.is_empty() and Query.same_source(named[0], src)
## Destroys an installed Program. Hotfix (first each turn) disables it instead; otherwise Version
## Control returns it to its owner's hand.
static func destroy_program(s: Dictionary, id: int) -> void:
var loc = State.program_location(s, id)
if loc == null:
return
var owner := State.owner_of(s, id)
var here: Array = Query.sources(s).filter(func(x): return x.at == loc and x.controller == owner and x.get("virtual") == null)
var hotfix = null
for x in here:
if x.name == "Hotfix" and State.used_this_turn(s, "hotfix:%d" % x.id) == 0:
hotfix = x
break
if hotfix != null:
State.mark_used(s, "hotfix:%d" % hotfix.id)
s.cards[id].disabledUntil = maxi(s.cards[id].disabledUntil, State.start_of(State.next_turn_of(s, owner)))
State.fired(s, "Hotfix", owner)
State.say(s, "Hotfix: %s is disabled instead of destroyed." % State.name_of(s, id))
return
State.uninstall_program(s, id)
State.stat(s, "programsLost", owner)
for x in here:
if x.name == "Version Control":
State.fired(s, "Version Control", owner)
State.to_hand(s, id, "play")
State.say(s, "Version Control: %s returns to %s's hand." % [State.name_of(s, id), State.player_name(owner)])
return
State.to_discard(s, id, "play", "destroyed")
State.say(s, "%s is destroyed." % State.name_of(s, id))
## Installs a Program for free (Replication Routine).
static func _install_free(s: Dictionary, card: int, at: String) -> void:
var p := State.owner_of(s, card)
State.remove_from(s.players[p].hand, card)
s.locations[at].programs.append(card)
State.emit_install(s, card, "loc:" + at)
s.cards[card].installedTurn = s.turn
State.stat(s, "programsInstalled", p)
State.played(s, State.name_of(s, card), p)
State.say(s, "%s installs %s on %s for free." % [State.player_name(p), State.name_of(s, card), at])
Query.emit(s, "onInstall", {"card": card, "at": at, "ref": null})
## Negative things on an Anomaly that Error Correction can remove, one at a time, as options.
static func _negatives(s: Dictionary, r: Dictionary) -> Array:
var av := State.anomaly(s, r)
var out := []
if av.infection > 0:
out.append({"label": "an Infection counter", "value": "infection"})
if av.bugs > 0:
out.append({"label": "a Bug counter", "value": "bug"})
if av.permanentInfection > 0:
out.append({"label": "a permanent Infection counter", "value": "permanent"})
for hw in State.hardware_of(s, r):
if not Query.hardware_active(s, hw):
out.append({"label": "disabled %s" % State.name_of(s, hw), "value": "hw:%d" % hw})
var worst = _latest_penalty(s, av)
if worst != null:
out.append({"label": "%d Cores from %s" % [worst.cores, worst.source], "value": "mod:%d" % worst.seq})
if State.running(s, av.rootedUntil):
out.append({"label": "Packet Flood", "value": "rooted"})
if State.running(s, av.disabledUntil):
out.append({"label": "Disabled", "value": "disabled"})
return out
## The most recent active modifier that lowers an Anomaly's Cores, or null.
static func _latest_penalty(s: Dictionary, av: Dictionary) -> Variant:
var worst = null
for m in State.active_mods(s, av):
if m.cores < 0 and (worst == null or m.seq > worst.seq):
worst = m
return worst
static func _remove_negative(s: Dictionary, r: Dictionary, what: String) -> void:
var av := State.anomaly(s, r)
var counters := State.counters_of(av)
if what == "infection":
av.infection -= 1
elif what == "bug":
av.bugs -= 1
elif what == "permanent":
av.permanentInfection -= 1
elif what == "rooted":
av.rootedUntil = 0
elif what == "disabled":
av.disabledUntil = 0
elif what.begins_with("hw:"):
s.cards[what.substr(3).to_int()].disabledUntil = 0
elif what.begins_with("mod:"):
var seq := what.substr(4).to_int()
av.mods = av.mods.filter(func(m): return m.seq != seq)
State.emit_counters(s, r, counters)
static func scripts() -> Dictionary:
return {
# 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 Anomaly attacks or breaches this Server, place an Infection counter on it. An Anomaly with 3+ Infection counters has -2 Core.",
"onAttackDeclared": _recursive_attack,
"onBreach": _recursive_breach,
"globalCores": func(s, f): return -2 if State.infection_of(State.anomaly(s, f.ref)) >= 3 else 0,
},
# Reading: "owner" is the attacking Anomaly's owner, who picks which of its Hardware is disabled
# for that combat.
"Memory Parasite": {
"text": "Enemy Anomalies attacking this Server have 1 hardware component disabled of the owners choosing.",
"onCombatStart": _parasite_combat_start,
"resume": {"disable": _parasite_disable},
},
# 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 Bandwidth cost.",
"onInstall": _replication_install,
"resume": {"install": _replication_resume},
},
# Fires on every roll the attacker loses here (with the health rule off, that's every defeat).
"Resource Leech": {
"text": "Whenever an enemy Anomaly takes damage while attacking this Server, gain 3 Gb.",
"onDamage": _leech_damage,
},
"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": _worm_install,
"resume": {"spread": _worm_spread},
},
"Payload Injector": {
"text": "The first Execution you play targeting this Server each round costs 2 less Gb.",
"costMod": _payload_cost,
"onPaid": _payload_paid,
},
# Enemy Anomalies are only ever at this location while attacking it. The counter survives defeat.
"Persistent Infection": {
"text": "Whenever an enemy Anomaly takes damage at this Server, place an Infection counter on it permanently.",
"onDamage": _persistent_damage,
},
# Reading: your Anomaly 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 Anomaly is controlled by the owner of this Program, it may attack a second adjacent Server in the same command.",
"extraAttacks": 1,
},
"Stack Overflow": {
"text": "Anomalies you control defending this Server gain +1 Core for each Program installed on this Server (including this one).",
"cores": _stack_overflow_cores,
},
# 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": _race_combat_start,
"resume": {"pick": _race_pick},
},
"Bloatware": {
"text": "At the start of any combat at this Server, the attacking Anomaly loses 1 Core for each Hardware installed on it.",
"onCombatStart": _bloatware_combat_start,
},
"Null Pointer": {
"text": "Once per round, when an enemy Execution would resolve at this Server, it's effect does not occur.",
"negates": _null_pointer_negates,
},
# Reading: "Hardware bonuses" are the Cores Hardware adds.
"Stock Rice": {
"text": "Neither Anomaly in a combat that takes place at this Server may use any Hardware bonuses.",
"blocksHardwareInCombat": true,
"onCombatStart": _stock_rice_combat_start,
},
# Every lost roll disables a Program until its controller's next command; a destroyed attacker
# lets the owner destroy it instead.
"Overflow Error": {
"text": "When an enemy Anomaly takes damage while attacking this Server, disable one Program its controller has in play until their next command. If the Anomaly was destroyed, you may destroy that Program instead.",
"onDamage": _overflow_damage,
"resume": {"hit": _overflow_hit},
},
# Reading: the copy lasts until your next turn, while this Program is disabled.
"Undefined Behavior": {
"text": "Once per round, copy the localized effect of another Program on another Server. Then disable this Program until your next command.",
"ability": {"uses": _undefined_uses, "resolve": _undefined_resolve},
},
"Packet Loss": {
"text": "When an enemy successfully breaches this Server, its controller discards a card at random.",
"onBreach": _packet_loss_breach,
},
# The once-per-turn Hardware abilities are Hot-Swap Bay's and Quantum Coprocessor's.
"Desynchronization": {
"text": "Enemy Anomalies attacking this Server cannot use their Hardware's \"once per round\" 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 Anomaly you control at this Server suffers -1 Core.",
"onCombatStart": _artifact_combat_start,
},
# Executions check for this through CardUtil.scope_of().
"Ghost Process": {
"text": "Your Executions played targeting this Server may also affect Anomalies, Programs, and Hardware at one adjacent Server.",
},
# Runs from the engine right after an enemy Execution that targets an Anomaly is played.
"False Positive": {
"text": "When an enemy Execution targets an Anomaly you control at this Server, you may redirect it to another legal Anomaly at another Server.",
"resume": {"offer": _false_positive_offer, "redirect": _false_positive_redirect},
},
"Fragmentation": {
"text": "Executions your opponents play targeting this Server cost +2 Gb.",
"costMod": func(_s, src, pay): return 2 if pay.kind == "execution" and pay.player != src.controller and pay.get("at") == src.at else 0,
"onPaid": func(s, src, _pay): State.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 round is instead disabled until your next command.",
},
"Error Correction": {
"text": "At the beginning of your first command each round, remove one negative counter or status from each Anomaly you control at this Server.",
"onTurnStart": _error_correction_turn_start,
"resume": {"fix": _error_correction_fix, "remove": func(s, data, what): _remove_negative(s, data.ref, what)},
},
# Reading: it can sacrifice itself.
"Garbage Collection": {
"text": "Once per round, sacrifice one Program installed on this Server to recover its printed Bandwidth value.",
"ability": {"uses": _garbage_uses, "resolve": _garbage_resolve},
},
"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": _version_captured,
"resume": {"save": _version_save},
},
"Rollback Routine": {
"text": "Once per round, undo the most recent temporary stat reduction applied to an Anomaly you control at this Server.",
"ability": {"uses": _rollback_uses, "resolve": _rollback_resolve},
},
"Compatibility Layer": {
"text": "This Server may hold one additional Program beyond the normal limit, and Patch Programs installed here cost 2 less Gb.",
"programSlots": 1,
"costMod": func(s, src, pay): return -2 if pay.kind == "program" and pay.player == src.controller and pay.get("at") == src.at and CardUtil.is_patch(s, pay.card) else 0,
"onPaid": func(s, src, _pay): State.fired(s, "Compatibility Layer", src.controller),
},
}
# Recursive Infection
static func _recursive_attack(s: Dictionary, src: Dictionary, ev: Dictionary) -> void:
if ev.to == src.at and _enemy_of(src, ev.ref):
CardUtil.infect(s, ev.ref, 1, "Recursive Infection", src.controller)
static func _recursive_breach(s: Dictionary, src: Dictionary, ev: Dictionary) -> void:
if ev.loc != src.at or not _enemy_of(src, ev.ref):
return
for d in s.declarations:
if d.kind == "attack" and State.same_ref(d.ref, ev.ref) and d.to == ev.loc:
return
CardUtil.infect(s, ev.ref, 1, "Recursive Infection", src.controller)
# Memory Parasite
static func _parasite_combat_start(s: Dictionary, src: Dictionary, _ev: Variant) -> void:
var c: Dictionary = s.combat
if c.loc != src.at or not _enemy_of(src, c.attacker):
return
var hw: Array = State.hardware_of(s, c.attacker).filter(func(h): return Query.hardware_active(s, h) and not c.suppressed.has(h))
if hw.is_empty():
return
State.fired(s, "Memory Parasite", src.controller)
if hw.size() == 1:
c.suppressed.append(hw[0])
State.say(s, "Memory Parasite disables %s for this combat." % State.name_of(s, hw[0]))
return
State.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(func(h): return {"label": State.name_of(s, h), "value": h}),
"resume": {"name": "Memory Parasite", "fn": "disable", "data": null},
})
static func _parasite_disable(s: Dictionary, _data: Variant, hw: Variant) -> void:
if s.combat != null:
s.combat.suppressed.append(hw)
# Replication Routine
static func _replication_install(s: Dictionary, src: Dictionary, ev: Dictionary) -> void:
if not src.at or ev.at != src.at or src.get("virtual") != null or not CardUtil.is_virus(s, ev.card):
return
if s.locations[src.at].programs.size() >= Query.program_slots(s, src.at):
return
var hand: Array = s.players[src.controller].hand.filter(func(id): return CardUtil.is_virus(s, id))
if hand.is_empty():
return
State.ask(s, {
"player": src.controller,
"kind": "Replication Routine:install",
"prompt": "Replication Routine: install a second Virus Program on %s for free?" % src.at,
"options": [{"label": "No", "value": null}] + CardUtil.card_options(s, hand),
"resume": {"name": "Replication Routine", "fn": "install", "data": {"at": src.at}},
})
static func _replication_resume(s: Dictionary, data: Dictionary, card: Variant) -> void:
if card == null or not State.controls(s, State.owner_of(s, card), data.at):
return
if s.locations[data.at].programs.size() >= Query.program_slots(s, data.at):
return
State.fired(s, "Replication Routine", State.owner_of(s, card))
_install_free(s, card, data.at)
# Resource Leech, Persistent Infection
static func _leech_damage(s: Dictionary, src: Dictionary, ev: Dictionary) -> void:
if ev.loc != src.at or ev.role != "attack" or not _enemy_of(src, ev.ref):
return
State.gain_bandwidth(s, src.controller, 3)
State.fired(s, "Resource Leech", src.controller)
State.say(s, "Resource Leech: %s gains 3 Gb." % State.player_name(src.controller))
static func _persistent_damage(s: Dictionary, src: Dictionary, ev: Dictionary) -> void:
if ev.loc != src.at or not _enemy_of(src, ev.ref) or State.is_copy(ev.ref):
return
CardUtil.infect(s, ev.ref, 1, "Persistent Infection", src.controller, true)
# Worm Protocol
static func _worm_install(s: Dictionary, src: Dictionary, ev: Dictionary) -> void:
if ev.card != src.id or src.get("virtual") != null:
return
var near := State.neighbors(s, src.at)
if near.is_empty():
return
State.ask(s, {
"player": src.controller,
"kind": "Worm Protocol:spread",
"prompt": "Worm Protocol on %s: spread your other Programs' effects to which adjacent location?" % src.at,
"options": near.map(func(l): return {"label": l, "value": l}),
"resume": {"name": "Worm Protocol", "fn": "spread", "data": {"card": src.id}},
})
static func _worm_spread(s: Dictionary, data: Dictionary, to: Variant) -> void:
s.cards[data.card].wormTo = to
State.fired(s, "Worm Protocol", State.owner_of(s, data.card))
# Payload Injector
static func _payload_cost(s: Dictionary, src: Dictionary, pay: Dictionary) -> int:
return -2 if pay.kind == "execution" and pay.player == src.controller and pay.get("at") == src.at \
and State.used_this_turn(s, "payload:%d" % src.id) == 0 else 0
static func _payload_paid(s: Dictionary, src: Dictionary, _pay: Dictionary) -> void:
State.mark_used(s, "payload:%d" % src.id)
State.fired(s, "Payload Injector", src.controller)
# Stack Overflow
static func _stack_overflow_cores(s: Dictionary, src: Dictionary, f: Dictionary) -> int:
if f.role == "defend" and f.at == src.at and f.ref.player == src.controller:
return Query.installed_count(s, src.at)
return 0
# Race Condition
static func _race_combat_start(s: Dictionary, src: Dictionary, _ev: Variant) -> void:
var c: Dictionary = s.combat
if c.loc != src.at or not _first_here(s, src, c.loc):
return
State.fired(s, "Race Condition", src.controller)
_ask_race(s, c.attacker.player)
static func _race_pick(s: Dictionary, data: Dictionary, pick: Variant) -> void:
var c = s.combat
if c == null or c.ended:
return
c.race[data.player] = pick
var defender: int = c.defenders[0].player if not c.defenders.is_empty() else State.other(c.attacker.player)
if data.player == c.attacker.player:
_ask_race(s, defender)
return
var a = c.race[c.attacker.player]
var d = c.race[defender]
State.say(s, "Race Condition: attacker chose %s, defender chose %s." % [Util.js(a), Util.js(d)])
if a != d and not c.defenders.is_empty():
State.add_mod(s, c.defenders[0], 2, "Race Condition", defender, {"combat": c.id})
State.say(s, "The choices differ: the defender gets +2 Cores.")
static func _ask_race(s: Dictionary, player: int) -> void:
State.ask(s, {
"player": player,
"kind": "Race Condition:pick",
"secret": true,
"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": player}},
})
# Bloatware, Stock Rice, Visual Artifact
static func _bloatware_combat_start(s: Dictionary, src: Dictionary, _ev: Variant) -> void:
var c: Dictionary = s.combat
if c.loc != src.at or not _enemy_of(src, c.attacker) or Query.bug_immune(s, c.attacker, src.controller):
return
var n: int = State.hardware_of(s, c.attacker).size()
if n == 0:
return
State.add_mod(s, c.attacker, -n, "Bloatware", src.controller, {"combat": c.id})
State.fired(s, "Bloatware", src.controller)
State.say(s, "Bloatware: %s loses %d Core%s." % [State.anomaly_name(s, c.attacker), n, "" if n == 1 else "s"])
static func _stock_rice_combat_start(s: Dictionary, src: Dictionary, _ev: Variant) -> void:
if s.combat.loc == src.at:
State.fired(s, "Stock Rice", src.controller)
static func _artifact_combat_start(s: Dictionary, src: Dictionary, _ev: Variant) -> void:
var c: Dictionary = s.combat
if c.loc != src.at or s.cards[src.id].get("spent", false):
return
var guarding := false
for d in c.defenders:
if d.player == src.controller:
guarding = true
if not guarding:
return
s.cards[src.id].spent = true
State.add_mod(s, c.attacker, -1, "Visual Artifact", src.controller, {"combat": c.id})
State.fired(s, "Visual Artifact", src.controller)
State.say(s, "Visual Artifact: %s gets -1 Core." % State.anomaly_name(s, c.attacker))
# Null Pointer
static func _null_pointer_negates(s: Dictionary, src: Dictionary, item: Dictionary) -> bool:
if item.player == src.controller or item.target != src.at or State.used_this_turn(s, "null:%d" % src.id) > 0:
return false
State.mark_used(s, "null:%d" % src.id)
State.fired(s, "Null Pointer", src.controller)
State.say(s, "Null Pointer: %s has no effect." % item.name)
return true
# Overflow Error
static func _overflow_damage(s: Dictionary, src: Dictionary, ev: Dictionary) -> void:
if ev.loc != src.at or ev.role != "attack" or not _enemy_of(src, ev.ref):
return
var theirs := []
for l in GameMap.LOCATIONS:
if State.controls(s, ev.ref.player, l):
for id in CardUtil.programs_on(s, l):
if Query.can_target_program(s, id, src.controller):
theirs.append(id)
if theirs.is_empty():
return
State.fired(s, "Overflow Error", src.controller)
var options := []
for id in theirs:
var where := "%s on %s" % [State.name_of(s, id), State.program_location(s, id)]
if ev.destroyed:
options.append({"label": "Destroy %s" % where, "value": {"card": id, "mode": "destroy"}})
options.append({"label": "Disable %s" % where, "value": {"card": id, "mode": "disable"}})
State.ask(s, {
"player": src.controller,
"kind": "Overflow Error:hit",
"prompt": "Overflow Error: destroy or disable one of their Programs." if ev.destroyed else "Overflow Error: disable one of their Programs.",
"options": options,
"resume": {"name": "Overflow Error", "fn": "hit", "data": null},
})
static func _overflow_hit(s: Dictionary, _data: Variant, v: Variant) -> void:
if State.program_location(s, v.card) == null:
return
if v.mode == "destroy":
destroy_program(s, v.card)
else:
var until := State.start_of(State.next_turn_of(s, State.owner_of(s, v.card)))
s.cards[v.card].disabledUntil = maxi(s.cards[v.card].disabledUntil, until)
# Undefined Behavior
static func _undefined_uses(s: Dictionary, src: Dictionary) -> Array:
if src.kind != "program" or src.get("virtual") != null:
return []
var out := []
for l in GameMap.LOCATIONS:
if l == src.at:
continue
for id in CardUtil.programs_on(s, l):
if State.name_of(s, id) != "Undefined Behavior" and Query.can_target_program(s, id, src.controller):
out.append({"card": id})
return out
static func _undefined_resolve(s: Dictionary, item: Dictionary, src: Dictionary) -> void:
var card: int = item.args.card
if State.program_location(s, card) == null:
return
var until := State.start_of(State.next_turn_of(s, src.controller))
s.seq += 1
s.virtuals.append({"id": s.seq, "name": State.name_of(s, card), "controller": src.controller, "at": src.at, "until": until, "installed": false, "from": card})
s.cards[src.id].disabledUntil = maxi(s.cards[src.id].disabledUntil, until)
State.fired(s, "Undefined Behavior", src.controller)
State.say(s, "Undefined Behavior on %s copies %s and shuts itself off until %s's next turn." % [src.at, State.name_of(s, card), State.player_name(src.controller)])
# Packet Loss
static func _packet_loss_breach(s: Dictionary, src: Dictionary, ev: Dictionary) -> void:
if ev.loc != src.at or not _enemy_of(src, ev.ref):
return
var hand: Array = s.players[ev.ref.player].hand
if hand.is_empty():
return
var card: int = hand[Rng.rand_int(s.rng, hand.size())]
State.remove_from(hand, card)
State.to_discard(s, card, "hand", "discarded")
State.fired(s, "Packet Loss", src.controller)
State.say(s, "Packet Loss: %s discards %s at random." % [State.player_name(ev.ref.player), State.name_of(s, card)])
# False Positive
static func _false_positive_offer(s: Dictionary, data: Dictionary, _value: Variant) -> void:
if data.index >= s.stack.size():
return
var item: Dictionary = s.stack[data.index]
var ex: Dictionary = CardScripts.of(item.name).get("execution", {})
var hit: Array = ex.targetsAnomalies.call(s, item) if ex.has("targetsAnomalies") else []
var guarded = null
for r in hit:
if r.player == item.player:
continue
var at = State.anomaly(s, r).at
for x in Query.sources(s):
if x.name == "False Positive" and x.at == at and x.controller == r.player:
guarded = r
break
if guarded != null:
break
if ex.is_empty() or guarded == null:
return
var from = State.anomaly(s, guarded).at
var options := [{"label": "Leave it", "value": null}]
for play in ex.plays.call(s, item.player):
var refs: Array = ex.targetsAnomalies.call(s, {"player": item.player, "target": play.target, "args": play.args}) if ex.has("targetsAnomalies") else []
if refs.is_empty():
continue
var away := true
for r in refs:
if State.anomaly(s, r).at == from or State.same_ref(r, guarded):
away = false
if not away:
continue
var whom := State.anomaly_name(s, play.args.ref) if play.args.get("ref") != null else State.name_of(s, play.args.get("card", -1))
options.append({"label": "Redirect to %s on %s" % [whom, Util.js(play.target)], "value": {"index": data.index, "target": play.target, "args": play.args}})
if options.size() == 1:
return
State.ask(s, {
"player": guarded.player,
"kind": "False Positive:redirect",
"prompt": "False Positive: redirect %s away from %s?" % [item.name, State.anomaly_name(s, guarded)],
"options": options,
"resume": {"name": "False Positive", "fn": "redirect", "data": null},
})
static func _false_positive_redirect(s: Dictionary, _data: Variant, v: Variant) -> void:
if v == null or v.index >= s.stack.size():
return
var item: Dictionary = s.stack[v.index]
item.target = v.target
item.args = v.args
State.fired(s, "False Positive", State.other(item.player))
# Error Correction
static func _error_correction_turn_start(s: Dictionary, src: Dictionary, _ev: Variant) -> void:
if s.active != src.controller:
return
var tasks := []
for r in State.refs_in_play(s, src.controller):
if State.anomaly(s, r).at == src.at:
tasks.append(State.later("Error Correction", "fix", {"ref": r}))
State.push_tasks(s, tasks)
static func _error_correction_fix(s: Dictionary, data: Dictionary, _value: Variant) -> void:
var list := _negatives(s, data.ref)
if list.is_empty():
return
State.fired(s, "Error Correction", data.ref.player)
if list.size() == 1:
_remove_negative(s, data.ref, list[0].value)
State.say(s, "Error Correction removes %s from %s." % [list[0].label, State.anomaly_name(s, data.ref)])
return
State.ask(s, {
"player": data.ref.player,
"kind": "Error Correction:remove",
"prompt": "Error Correction: remove what from %s?" % State.anomaly_name(s, data.ref),
"options": list,
"resume": {"name": "Error Correction", "fn": "remove", "data": {"ref": data.ref}},
})
# Garbage Collection
static func _garbage_uses(s: Dictionary, src: Dictionary) -> Array:
if src.kind != "program":
return []
return s.locations[src.at].programs.map(func(card): return {"card": card})
static func _garbage_resolve(s: Dictionary, item: Dictionary, src: Dictionary) -> void:
var card: int = item.args.card
if State.program_location(s, card) != src.at:
return
State.uninstall_program(s, card)
State.to_discard(s, card, "play", "sacrificed")
State.stat(s, "programsLost", src.controller)
State.gain_bandwidth(s, src.controller, State.def_of(s, card).bandwidth)
State.fired(s, "Garbage Collection", src.controller)
State.say(s, "Garbage Collection sacrifices %s for %d Gb." % [State.name_of(s, card), State.def_of(s, card).bandwidth])
# Version Control
static func _version_captured(s: Dictionary, src: Dictionary, ev: Dictionary) -> void:
if ev.loc != src.at or src.get("virtual") != null:
return
var here: Array = s.locations[ev.loc].programs
if here.is_empty():
return
State.ask(s, {
"player": src.controller,
"kind": "Version Control:save",
"prompt": "Version Control: %s is being captured. Return which Program to your hand?" % ev.loc,
"options": here.map(func(id): return {"label": State.name_of(s, id), "value": id}),
"resume": {"name": "Version Control", "fn": "save", "data": null},
})
static func _version_save(s: Dictionary, _data: Variant, card: Variant) -> void:
if State.uninstall_program(s, card) == null:
return
State.to_hand(s, card, "play")
State.fired(s, "Version Control", State.owner_of(s, card))
State.say(s, "Version Control returns %s to %s's hand." % [State.name_of(s, card), State.player_name(State.owner_of(s, card))])
# Rollback Routine
static func _rollback_uses(s: Dictionary, src: Dictionary) -> Array:
if src.kind != "program":
return []
var out := []
for r in State.refs_in_play(s, src.controller):
if State.anomaly(s, r).at == src.at and _latest_penalty(s, State.anomaly(s, r)) != null:
out.append({"ref": r})
return out
static func _rollback_resolve(s: Dictionary, item: Dictionary, src: Dictionary) -> void:
var av := State.anomaly(s, item.args.ref)
if av.at != src.at:
return
var last = _latest_penalty(s, av)
if last == null:
return
av.mods = av.mods.filter(func(m): return m.seq != last.seq)
State.fired(s, "Rollback Routine", src.controller)
State.say(s, "Rollback Routine undoes %d Cores from %s on %s." % [last.cores, last.source, State.anomaly_name(s, item.args.ref)])