422 lines
16 KiB
GDScript
422 lines
16 KiB
GDScript
class_name HardwareCards
|
|
## Hardware (cards/hardware.ts). It works while its wearer is in play. "The occupied Server" is the
|
|
## location the wearer stands on.
|
|
|
|
|
|
## 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 Anomaly picks it (Cooling helps one Hardware a turn).
|
|
static func hardware_uses_left(s: Dictionary, hw: int) -> int:
|
|
var used := State.used_this_turn(s, "hw:%d" % hw)
|
|
var cooler = _cooler_for(s, hw)
|
|
return (1 if cooler == null else 2) - used
|
|
|
|
|
|
static func _cooler_for(s: Dictionary, hw: int) -> Variant:
|
|
var r = State.wearer_of(s, hw)
|
|
if r == null:
|
|
return null
|
|
for id in State.anomaly(s, r).hardware:
|
|
if id == hw or s.cards[id].name != "Cooling System" or not Query.hardware_active(s, id):
|
|
continue
|
|
var picked_for = s.used.get("cool:%d" % id)
|
|
if picked_for == null or picked_for == hw:
|
|
return id
|
|
return null
|
|
|
|
|
|
## Reading: an Anomaly that loses an Expansion Slot (Network Interface Upgrade removed) discards
|
|
## Hardware until it fits, the most recently installed first.
|
|
static func shed_hardware(s: Dictionary, r: Dictionary) -> void:
|
|
while not Query.slots_fit(s, r):
|
|
var hw = null
|
|
var list: Array = State.anomaly(s, r).hardware
|
|
for i in range(list.size() - 1, -1, -1):
|
|
if Query.takes_slot(s, list[i]):
|
|
hw = list[i]
|
|
break
|
|
State.uninstall_hardware(s, hw)
|
|
State.to_discard(s, hw)
|
|
State.stat(s, "hardwareLost", r.player)
|
|
State.say(s, "%s is out of Expansion Slots and discards %s." % [State.anomaly_name(s, r), State.name_of(s, hw)])
|
|
|
|
|
|
static func use_hardware(s: Dictionary, hw: int) -> void:
|
|
var cooler = _cooler_for(s, hw)
|
|
State.mark_used(s, "hw:%d" % hw)
|
|
if State.used_this_turn(s, "hw:%d" % hw) >= 2 and cooler != null:
|
|
s.used["cool:%d" % cooler] = hw
|
|
State.fired(s, "Cooling System", State.owner_of(s, hw))
|
|
|
|
|
|
## Whether `r` is the Anomaly (or a copy of the Anomaly) wearing Hardware at `wearer`.
|
|
static func _wearing(wearer: Variant, r: Dictionary) -> bool:
|
|
return wearer != null and wearer.player == r.player and (wearer.slot == r.slot or wearer.slot + 4 == r.slot)
|
|
|
|
|
|
## Installs a Hardware card from its owner's hand onto an Anomaly, without paying.
|
|
static func attach_hardware(s: Dictionary, card: int, r: Dictionary) -> void:
|
|
State.remove_from(s.players[r.player].hand, card)
|
|
State.anomaly(s, r).hardware.append(card)
|
|
s.cards[card].installedTurn = s.turn
|
|
State.stat(s, "hardwareInstalled", r.player)
|
|
State.played(s, State.name_of(s, card), r.player)
|
|
|
|
|
|
static func scripts() -> Dictionary:
|
|
return {
|
|
# Health rule: the wearer's Health goes up by 2 (Query.health_of). Without the rule it does nothing.
|
|
"RAM Expansion": {"text": "Anomaly gains +2 Health.", "health": 2},
|
|
"Additional Core": {"text": "Anomaly gains +1 Core.", "cores": func(_s, _src, _f): return 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": "Anomaly gains +2 Cores during combat, but one installed Program at the current server becomes disabled afterward for 2 commands.",
|
|
"cores": func(_s, _src, f): return 2 if f.role != null else 0,
|
|
"onCombatEnd": _overclocked_combat_end,
|
|
"resume": {"disable": func(s, _data, id): _disable_for_two_turns(s, id)},
|
|
},
|
|
|
|
"Solid-State Cache": {
|
|
"text": "The first Program installed on the occupied Server each round costs 3 less Gb.",
|
|
"costMod": _cache_cost,
|
|
"onPaid": _use_and_fire.bind("Solid-State Cache"),
|
|
},
|
|
|
|
# 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 Anomaly would be destroyed, do not destroy the Hardware.",
|
|
"savePriority": 0,
|
|
"onWearerDefeated": _rps_defeated,
|
|
},
|
|
|
|
# Ruling: it takes no Expansion Slot and adds one, so the wearer nets +1 Expansion Slot.
|
|
"Network Interface Upgrade": {
|
|
"text": "This Hardware can be played without taking an Expansion Slot on the Anomaly.",
|
|
"noSlot": 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, Bandwidth recovered).
|
|
"Dedicated GPU": {
|
|
"text": "Executions performed by this Anomaly receive +1 effectiveness or combat strength.",
|
|
"executionPower": 1,
|
|
},
|
|
|
|
# Blocks opponents' Bug counters (see CardUtil.add_bugs; no card places them yet) and their
|
|
# Bug Program effects on the wearer (Bloatware, Stock Rice).
|
|
"ECC Memory": {
|
|
"text": "Opponents cannot place Bug counters or Bug status effects on this Anomaly.",
|
|
"bugImmunity": true,
|
|
},
|
|
|
|
# Works through hardware_uses_left() above.
|
|
"Cooling System": {"text": "Allow one Hardware to activate twice per round."},
|
|
|
|
# Reading: half the combined printed Bandwidth of its Hardware, rounded up.
|
|
"RAID Array": {
|
|
"text": "When this Anomaly is destroyed, all hardware can be kept by paying half the Bandwidth cost.",
|
|
"savePriority": 1,
|
|
"onWearerDefeated": _raid_defeated,
|
|
"resume": {"keep": _raid_keep},
|
|
},
|
|
|
|
"Packet Accelerator": {
|
|
"text": "This Anomaly gains +1 Core hen attacking.",
|
|
"cores": func(_s, _src, f): return 1 if f.role == "attack" else 0,
|
|
},
|
|
|
|
# Programs never target Anomalies, so this taxes Executions (and Hardware they hit).
|
|
"Firewall Appliance": {
|
|
"text": "The first hostile Program or Execution targeting this Anomaly each round costs the opponent +3 Gb.",
|
|
"costMod": _appliance_cost,
|
|
"onPaid": _use_and_fire.bind("Firewall Appliance"),
|
|
},
|
|
|
|
# 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": _sandbox_install,
|
|
"onTurnStart": _sandbox_turn_start,
|
|
"resume": {"protect": _sandbox_protect},
|
|
},
|
|
|
|
# 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 first command each round.",
|
|
"onTurnStart": _diagnostic_turn_start,
|
|
"resume": {"bottom": _diagnostic_bottom},
|
|
},
|
|
|
|
# Reading: swap Hardware on this Anomaly, paying the difference in printed Bandwidth (no refund).
|
|
"Hot-Swap Bay": {
|
|
"text": "Once per round, return one Hardware to your hand and install another Hardware from your hand, paying the difference in cost.",
|
|
"ability": {
|
|
"hardwareOncePerTurn": true,
|
|
"uses": _hot_swap_uses,
|
|
"extraCost": _hot_swap_extra,
|
|
"resolve": _hot_swap_resolve,
|
|
},
|
|
},
|
|
|
|
# Ruling: Servers perform Executions, so "this Anomaly 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 round when this Anomaly uses an Execution, you may copy that Execution's effect with a different legal target, then disable this Hardware.",
|
|
"copiesExecutions": true,
|
|
"resume": {"offer": _quantum_offer, "copy": _quantum_copy},
|
|
},
|
|
}
|
|
|
|
|
|
static func _use_and_fire(s: Dictionary, src: Dictionary, _pay: Dictionary, card_name: String) -> void:
|
|
use_hardware(s, src.id)
|
|
State.fired(s, card_name, src.controller)
|
|
|
|
|
|
# Overclocked CPU
|
|
|
|
static func _overclocked_combat_end(s: Dictionary, src: Dictionary, _ev: Variant) -> void:
|
|
var c: Dictionary = s.combat
|
|
var role := ""
|
|
if _wearing(src.get("ref"), c.attacker):
|
|
role = "attack"
|
|
else:
|
|
for d in c.defenders:
|
|
if _wearing(src.get("ref"), d):
|
|
role = "defend"
|
|
break
|
|
if role == "":
|
|
return
|
|
var loc: String = c.origin if role == "attack" else c.loc
|
|
if s.locations[loc].owner != src.controller:
|
|
return
|
|
var progs := CardUtil.programs_on(s, loc)
|
|
if progs.is_empty():
|
|
return
|
|
State.fired(s, "Overclocked CPU", src.controller)
|
|
if progs.size() == 1:
|
|
_disable_for_two_turns(s, progs[0])
|
|
return
|
|
State.ask(s, {
|
|
"player": src.controller,
|
|
"kind": "Overclocked CPU:disable",
|
|
"prompt": "Overclocked CPU: which Program on %s is disabled for 2 turns?" % loc,
|
|
"options": progs.map(func(id): return {"label": State.name_of(s, id), "value": id}),
|
|
"resume": {"name": "Overclocked CPU", "fn": "disable", "data": null},
|
|
})
|
|
|
|
|
|
static func _disable_for_two_turns(s: Dictionary, id: int) -> void:
|
|
s.cards[id].disabledUntil = maxi(s.cards[id].disabledUntil, State.end_of(s.turn + 1))
|
|
State.say(s, "Overclocked CPU: %s is disabled for 2 turns." % State.name_of(s, id))
|
|
|
|
|
|
# Solid-State Cache, Firewall Appliance
|
|
|
|
static func _cache_cost(s: Dictionary, src: Dictionary, pay: Dictionary) -> int:
|
|
return -3 if pay.kind == "program" and pay.player == src.controller and pay.get("at") == src.at \
|
|
and hardware_uses_left(s, src.id) > 0 else 0
|
|
|
|
|
|
static func _appliance_cost(s: Dictionary, src: Dictionary, pay: Dictionary) -> int:
|
|
if pay.kind != "execution" or pay.player == src.controller or hardware_uses_left(s, src.id) <= 0:
|
|
return 0
|
|
for r in pay.get("hostile", []):
|
|
if _wearing(src.get("ref"), r):
|
|
return 3
|
|
return 0
|
|
|
|
|
|
# Redundant Power Supply, RAID Array
|
|
|
|
static func _rps_defeated(s: Dictionary, hw: int, ev: Dictionary) -> bool:
|
|
if s.cards[hw].get("spent", false):
|
|
return false
|
|
s.cards[hw].spent = true
|
|
State.fired(s, "Redundant Power Supply", ev.ref.player)
|
|
State.say(s, "Redundant Power Supply: %s keeps its Hardware." % State.anomaly_name(s, ev.ref))
|
|
Flow.knock_out(s, ev.ref, ev.loc, ev.role, true)
|
|
return true
|
|
|
|
|
|
static func _raid_defeated(s: Dictionary, _hw: int, ev: Dictionary) -> bool:
|
|
var av := State.anomaly(s, ev.ref)
|
|
var total := 0
|
|
for h in av.hardware:
|
|
total += State.def_of(s, h).bandwidth
|
|
var cost := ceili(total / 2.0)
|
|
State.ask(s, {
|
|
"player": ev.ref.player,
|
|
"kind": "RAID Array:keep",
|
|
"prompt": "RAID Array: pay %d Gb to keep %s?" % [cost, ", ".join(av.hardware.map(func(h): return State.name_of(s, h)))],
|
|
"options": [
|
|
{"label": "Keep all Hardware for %d Gb" % cost, "value": true, "cost": cost},
|
|
{"label": "Lose the Hardware", "value": false},
|
|
],
|
|
"resume": {"name": "RAID Array", "fn": "keep", "data": {"ref": ev.ref, "loc": ev.loc, "role": ev.role, "cost": cost}},
|
|
})
|
|
return true
|
|
|
|
|
|
static func _raid_keep(s: Dictionary, data: Dictionary, keep: Variant) -> void:
|
|
if keep:
|
|
s.players[data.ref.player].bandwidth -= data.cost
|
|
State.stat(s, "bandwidthOnCards", data.ref.player, data.cost)
|
|
State.fired(s, "RAID Array", data.ref.player)
|
|
Flow.knock_out(s, data.ref, data.loc, data.role, keep)
|
|
|
|
|
|
# Hardware Sandbox
|
|
|
|
static func _sandbox_install(s: Dictionary, src: Dictionary, ev: Dictionary) -> void:
|
|
if ev.card == src.id:
|
|
_ask_sandbox(s, src.id)
|
|
|
|
|
|
static func _sandbox_turn_start(s: Dictionary, src: Dictionary, _ev: Variant) -> void:
|
|
if s.active != src.controller:
|
|
return
|
|
var p = s.cards[src.id].get("protects")
|
|
if p == null or State.program_location(s, p) != src.at:
|
|
_ask_sandbox(s, src.id)
|
|
|
|
|
|
static func _sandbox_protect(s: Dictionary, data: Dictionary, program: Variant) -> void:
|
|
s.cards[data.card].protects = program
|
|
State.fired(s, "Hardware Sandbox", State.owner_of(s, data.card))
|
|
|
|
|
|
static func _ask_sandbox(s: Dictionary, card: int) -> void:
|
|
var r = State.wearer_of(s, card)
|
|
var at = State.anomaly(s, r).at if r != null else null
|
|
if r == null or not at:
|
|
return
|
|
var progs: Array = s.locations[at].programs.filter(func(id): return State.owner_of(s, id) == r.player)
|
|
if progs.is_empty():
|
|
return
|
|
if progs.size() == 1:
|
|
s.cards[card].protects = progs[0]
|
|
return
|
|
State.ask(s, {
|
|
"player": r.player,
|
|
"kind": "Hardware Sandbox:protect",
|
|
"prompt": "Hardware Sandbox: protect which Program on %s?" % at,
|
|
"options": progs.map(func(id): return {"label": State.name_of(s, id), "value": id}),
|
|
"resume": {"name": "Hardware Sandbox", "fn": "protect", "data": {"card": card}},
|
|
})
|
|
|
|
|
|
# Diagnostic Module
|
|
|
|
static func _diagnostic_turn_start(s: Dictionary, src: Dictionary, _ev: Variant) -> void:
|
|
if s.active != src.controller or hardware_uses_left(s, src.id) <= 0:
|
|
return
|
|
var deck: Array = s.players[src.controller].deck
|
|
if deck.size() < 2:
|
|
return
|
|
use_hardware(s, src.id)
|
|
State.fired(s, "Diagnostic Module", src.controller)
|
|
var top := State.name_of(s, deck[0])
|
|
State.ask(s, {
|
|
"player": src.controller,
|
|
"kind": "Diagnostic Module:bottom",
|
|
"secret": true,
|
|
"prompt": "Diagnostic Module: the top card of your deck is %s. Put it on the bottom?" % top,
|
|
"options": [
|
|
{"label": "Keep %s on top" % top, "value": false},
|
|
{"label": "Put %s on the bottom" % top, "value": true},
|
|
],
|
|
"resume": {"name": "Diagnostic Module", "fn": "bottom", "data": {"player": src.controller}},
|
|
})
|
|
|
|
|
|
static func _diagnostic_bottom(s: Dictionary, data: Dictionary, bottom: Variant) -> void:
|
|
var deck: Array = s.players[data.player].deck
|
|
if bottom and not deck.is_empty():
|
|
deck.append(deck.pop_front())
|
|
|
|
|
|
# Hot-Swap Bay
|
|
|
|
static func _hot_swap_uses(s: Dictionary, src: Dictionary) -> Array:
|
|
var av := State.anomaly(s, src.ref)
|
|
var hand: Array = s.players[src.controller].hand.filter(func(id): return State.def_of(s, id).kind == "hardware")
|
|
var out := []
|
|
for out_card in av.hardware:
|
|
for o in CardUtil.card_options(s, hand):
|
|
if Query.slots_fit(s, src.ref, out_card, o.value):
|
|
out.append({"card": out_card, "cards": [o.value]})
|
|
return out
|
|
|
|
|
|
static func _hot_swap_extra(s: Dictionary, _src: Dictionary, args: Dictionary) -> int:
|
|
return maxi(0, State.def_of(s, args.cards[0]).bandwidth - State.def_of(s, args.card).bandwidth)
|
|
|
|
|
|
static func _hot_swap_resolve(s: Dictionary, item: Dictionary, src: Dictionary) -> void:
|
|
var out_card: int = item.args.card
|
|
var into: int = item.args.cards[0]
|
|
var r: Dictionary = src.ref
|
|
if not State.anomaly(s, r).hardware.has(out_card) or not s.players[src.controller].hand.has(into):
|
|
return
|
|
if not Query.slots_fit(s, r, out_card, into):
|
|
return
|
|
State.uninstall_hardware(s, out_card)
|
|
State.to_hand(s, out_card)
|
|
attach_hardware(s, into, r)
|
|
State.fired(s, "Hot-Swap Bay", src.controller)
|
|
State.say(s, "Hot-Swap Bay swaps %s for %s on %s." % [State.name_of(s, out_card), State.name_of(s, into), State.anomaly_name(s, r)])
|
|
|
|
|
|
# Quantum Coprocessor
|
|
|
|
static func _quantum_offer(s: Dictionary, data: Dictionary, _value: Variant) -> void:
|
|
var item: Dictionary = data.item
|
|
var qc = null
|
|
for r in State.refs_in_play(s, item.player):
|
|
if State.is_copy(r) or State.anomaly(s, r).at != item.from or Query.desynced(s, r):
|
|
continue
|
|
for hw in State.anomaly(s, r).hardware:
|
|
if s.cards[hw].name == "Quantum Coprocessor" and Query.hardware_active(s, hw) and hardware_uses_left(s, hw) > 0:
|
|
qc = hw
|
|
break
|
|
if qc != null:
|
|
break
|
|
if qc == null:
|
|
return
|
|
var ex: Dictionary = CardScripts.of(item.name).get("execution", {})
|
|
if ex.is_empty():
|
|
return
|
|
var same := {"t": item.target, "a": item.args}
|
|
var plays: Array = ex.plays.call(s, item.player).filter(func(p): return {"t": p.target, "a": p.args} != same)
|
|
if plays.is_empty():
|
|
return
|
|
var options := [{"label": "Don't copy", "value": null}]
|
|
for p in plays:
|
|
var label := "%s %s" % [p.target if p.target != null else "no target", Describe.describe_args(s, p.args, item.player)]
|
|
options.append({"label": label, "value": {"target": p.target, "args": p.args}})
|
|
State.ask(s, {
|
|
"player": item.player,
|
|
"kind": "Quantum Coprocessor:copy",
|
|
"prompt": "Quantum Coprocessor: copy %s with a different target?" % item.name,
|
|
"options": options,
|
|
"resume": {"name": "Quantum Coprocessor", "fn": "copy", "data": {"item": item, "qc": qc}},
|
|
})
|
|
|
|
|
|
static func _quantum_copy(s: Dictionary, data: Dictionary, v: Variant) -> void:
|
|
if not v:
|
|
return
|
|
use_hardware(s, data.qc)
|
|
s.cards[data.qc].disabledUntil = State.start_of(State.next_turn_of(s, data.item.player))
|
|
State.fired(s, "Quantum Coprocessor", data.item.player)
|
|
State.say(s, "Quantum Coprocessor copies %s onto %s." % [data.item.name, v.target if v.target != null else "a new target"])
|
|
var copy: Dictionary = data.item.duplicate()
|
|
copy.target = v.target
|
|
copy.args = v.args
|
|
copy.from = null
|
|
CardScripts.of(data.item.name).execution.resolve.call(s, copy)
|