This commit is contained in:
Forrest 2026-10-01 23:01:56 -04:00
parent 0cba7f5ee0
commit 32ed347b58
172 changed files with 5464 additions and 582 deletions

View file

@ -159,7 +159,9 @@ static func _beta_resolve(s: Dictionary, item: Dictionary, src: Dictionary) -> v
static func _code_zero_resolve(s: Dictionary, _item: Dictionary, src: Dictionary) -> void:
var foes := State.opponents_in_combat(s, src.ref)
for r in foes:
var counters := State.counters_of(State.anomaly(s, r))
State.anomaly(s, r).infection += 1
State.emit_counters(s, r, counters)
State.fired(s, "Code Zero", src.controller)
var names := ", ".join(foes.map(func(r): return "%s (%d)" % [State.anomaly_name(s, r), State.infection_of(State.anomaly(s, r))]))
State.say(s, "Patient Zero infects %s." % names)
@ -184,7 +186,7 @@ static func _leaker_resolve(s: Dictionary, _item: Dictionary, src: Dictionary) -
static func _leaker_discard(s: Dictionary, data: Dictionary, card: Variant) -> void:
var p: int = data.ref.player
if State.remove_from(s.players[State.other(p)].hand, card):
State.to_discard(s, card)
State.to_discard(s, card, "hand", "discarded")
State.say(s, "Exfiltrate: %s discards %s." % [State.player_name(State.other(p)), State.name_of(s, card)])
if State.anomaly(s, data.ref).breachedTurn == s.turn:
Flow.draw_cards(s, p, 1)
@ -209,14 +211,16 @@ static func _backup_resolve(s: Dictionary, item: Dictionary, src: Dictionary) ->
if av.at == null or av.damage == 0:
return
var healed := mini(3, av.damage)
var counters := State.counters_of(av)
av.damage -= healed
State.emit_counters(s, src.ref, counters)
State.fired(s, "Backup Machine", p)
State.say(s, "Restore Point heals %d damage on %s." % [healed, State.anomaly_name(s, src.ref)])
return
var card: int = item.args.card
if not State.remove_from(s.players[p].discard, card):
return
State.to_hand(s, card)
State.to_hand(s, card, "discard")
State.fired(s, "Backup Machine", p)
State.say(s, "Restore Point returns %s to %s's hand." % [State.name_of(s, card), State.player_name(p)])
if State.def_of(s, card).kind != "hardware" or Query.slots_free(s, src.ref) <= 0:
@ -237,7 +241,7 @@ static func _backup_resolve(s: Dictionary, item: Dictionary, src: Dictionary) ->
static func _backup_install(s: Dictionary, data: Dictionary, yes: Variant) -> void:
if not yes or State.anomaly(s, data.ref).at == null or not s.players[data.ref.player].hand.has(data.card):
return
s.players[data.ref.player].bandwidth -= data.cost
State.add_bandwidth(s, data.ref.player, -data.cost)
s.stats.bandwidthOnCards[data.ref.player] += data.cost
HardwareCards.attach_hardware(s, data.card, data.ref)
State.say(s, "%s is installed on %s." % [State.name_of(s, data.card), State.anomaly_name(s, data.ref)])
@ -266,6 +270,8 @@ static func _bits_resolve(s: Dictionary, item: Dictionary, src: Dictionary) -> v
for v in before:
after.append(State.roll_die(s) if v <= k else v)
c.dice[key] = after
if State.has_events(s):
State.emit(s, {"k": "rerolled", "ref": src.ref.duplicate(), "dice": after.duplicate()})
State.fired(s, "Broken Bits", src.controller)
var rerolled := before.filter(func(v): return v <= k).size()
State.say(s, "Bit Flip rerolls %d dice: [%s] → [%s]." % [rerolled, ",".join(before.map(func(v): return str(v))), ",".join(after.map(func(v): return str(v)))])

View file

@ -247,7 +247,7 @@ static func _sabotage_resolve(s: Dictionary, item: Dictionary) -> void:
State.fired(s, item.name, item.player)
if item.args.mode == "destroy":
State.uninstall_hardware(s, hw)
State.to_discard(s, hw)
State.to_discard(s, hw, "worn", "destroyed")
State.stat(s, "hardwareLost", owner.player)
State.say(s, "Sabotage destroys %s." % State.name_of(s, hw))
HardwareCards.shed_hardware(s, owner)
@ -400,7 +400,7 @@ static func _dump_discard(s: Dictionary, data: Dictionary, _value: Variant) -> v
static func _dump_drop(s: Dictionary, data: Dictionary, card: Variant) -> void:
if State.remove_from(s.players[data.player].hand, card):
State.to_discard(s, card)
State.to_discard(s, card, "hand", "discarded")
# Rollback
@ -421,7 +421,7 @@ static func _rollback_resolve(s: Dictionary, item: Dictionary) -> void:
var wearer = State.wearer_of(s, card)
if State.uninstall_program(s, card) == null and State.uninstall_hardware(s, card) == null:
return
State.to_hand(s, card)
State.to_hand(s, card, "worn" if wearer != null else "play")
State.fired(s, item.name, item.player)
State.say(s, "Rollback returns %s to %s's hand." % [State.name_of(s, card), State.player_name(State.owner_of(s, card))])
if wearer != null:
@ -565,8 +565,10 @@ static func _purge_resolve(s: Dictionary, item: Dictionary) -> void:
var here := CardUtil.mine(s, item.player, loc)
for r in here:
var av := State.anomaly(s, r)
var counters := State.counters_of(av)
av.infection = 0
av.permanentInfection = 0
State.emit_counters(s, r, counters)
av.mods = av.mods.filter(func(m): return m.cores >= 0 or m.by == item.player)
av.rootedUntil = 0
av.disabledUntil = 0
@ -591,7 +593,7 @@ static func _reset_resolve(s: Dictionary, item: Dictionary) -> void:
var back: Array = item.args.cards.filter(func(id): return State.program_location(s, id) == item.target)
for id in back:
State.uninstall_program(s, id)
State.to_hand(s, id)
State.to_hand(s, id, "play")
var gain: int = back.size() * (1 + item.power)
State.gain_bandwidth(s, item.player, gain)
State.fired(s, item.name, item.player)

View file

@ -35,7 +35,7 @@ static func shed_hardware(s: Dictionary, r: Dictionary) -> void:
hw = list[i]
break
State.uninstall_hardware(s, hw)
State.to_discard(s, hw)
State.to_discard(s, hw, "worn", "shed")
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)])
@ -57,6 +57,7 @@ static func _wearing(wearer: Variant, r: Dictionary) -> bool:
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)
State.emit_install(s, card, "anomaly:%d:%d" % [r.player, r.slot])
s.cards[card].installedTurn = s.turn
State.stat(s, "hardwareInstalled", r.player)
State.played(s, State.name_of(s, card), r.player)
@ -264,7 +265,7 @@ static func _raid_defeated(s: Dictionary, _hw: int, ev: Dictionary) -> bool:
static func _raid_keep(s: Dictionary, data: Dictionary, keep: Variant) -> void:
if keep:
s.players[data.ref.player].bandwidth -= data.cost
State.add_bandwidth(s, data.ref.player, -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)
@ -366,7 +367,7 @@ static func _hot_swap_resolve(s: Dictionary, item: Dictionary, src: Dictionary)
if not Query.slots_fit(s, r, out_card, into):
return
State.uninstall_hardware(s, out_card)
State.to_hand(s, out_card)
State.to_hand(s, out_card, "worn")
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)])

View file

@ -38,10 +38,10 @@ static func destroy_program(s: Dictionary, id: int) -> void:
for x in here:
if x.name == "Version Control":
State.fired(s, "Version Control", owner)
State.to_hand(s, id)
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)
State.to_discard(s, id, "play", "destroyed")
State.say(s, "%s is destroyed." % State.name_of(s, id))
@ -50,6 +50,7 @@ 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)
@ -91,6 +92,7 @@ static func _latest_penalty(s: Dictionary, av: Dictionary) -> Variant:
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":
@ -106,6 +108,7 @@ static func _remove_negative(s: Dictionary, r: Dictionary, what: String) -> void
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:
@ -575,7 +578,7 @@ static func _packet_loss_breach(s: Dictionary, src: Dictionary, ev: Dictionary)
return
var card: int = hand[Rng.rand_int(s.rng, hand.size())]
State.remove_from(hand, card)
State.to_discard(s, 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)])
@ -678,7 +681,7 @@ static func _garbage_resolve(s: Dictionary, item: Dictionary, src: Dictionary) -
if State.program_location(s, card) != src.at:
return
State.uninstall_program(s, card)
State.to_discard(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)
@ -705,7 +708,7 @@ static func _version_captured(s: Dictionary, src: Dictionary, ev: Dictionary) ->
static func _version_save(s: Dictionary, _data: Variant, card: Variant) -> void:
if State.uninstall_program(s, card) == null:
return
State.to_hand(s, card)
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))])

View file

@ -189,6 +189,7 @@ static func _callable_redraw(s: Dictionary, data: Dictionary, again: Variant) ->
if not State.remove_from(pl.hand, data.card):
return
pl.deck.append(data.card)
State.emit_pile(s, data.card, "deck", "hand")
State.fired(s, "Callable Server", data.player)
Flow.draw_now(s, data.player)
s.stats.cardsDrawn[data.player] -= 1

View file

@ -39,7 +39,9 @@ static func add_bugs(s: Dictionary, r: Dictionary, n: int, source: String, by: i
State.say(s, "ECC Memory blocks %s's Bug counters on %s." % [source, State.anomaly_name(s, r)])
State.fired(s, "ECC Memory", r.player)
return false
var counters := State.counters_of(State.anomaly(s, r))
State.anomaly(s, r).bugs += n
State.emit_counters(s, r, counters)
State.fired(s, source, by)
State.say(s, "%s: %s gets %d Bug counter%s (%d total)." % [source, State.anomaly_name(s, r), n, "" if n == 1 else "s", State.anomaly(s, r).bugs])
return true
@ -47,10 +49,12 @@ static func add_bugs(s: Dictionary, r: Dictionary, n: int, source: String, by: i
static func infect(s: Dictionary, r: Dictionary, n: int, source: String, by: int, permanent := false) -> void:
var av := State.anomaly(s, r)
var counters := State.counters_of(av)
if permanent:
av.permanentInfection += n
else:
av.infection += n
State.emit_counters(s, r, counters)
State.fired(s, source, by)
State.say(s, "%s: %s gets %s %sInfection counter%s (%d total)." % [source, State.anomaly_name(s, r), "an" if n == 1 else str(n), "permanent " if permanent else "", "" if n == 1 else "s", av.infection + av.permanentInfection])

View file

@ -104,8 +104,9 @@ static func _new_anomaly(card: int, face_up: bool, copy_of: Variant) -> Dictiona
}
## Starts a game from {pool, decks: [deck, deck], seed, rules?, log?}. A deck is {anomalies, servers,
## main}, lists of card names. Returns null (and records an error) if a deck is illegal.
## Starts a game from {pool, decks: [deck, deck], seed, rules?, log?, events?}. A deck is {anomalies,
## servers, main}, lists of card names. Returns null (and records an error) if a deck is illegal.
## With `events`, the game also keeps s.events for the table to act out (State.emit).
static func create_game(o: Dictionary) -> Variant:
var pool: Dictionary = o.pool
var decks: Array = o.decks
@ -146,6 +147,7 @@ static func create_game(o: Dictionary) -> Variant:
"stats": _new_stats(),
"cardUse": {},
"log": [] if o.get("log", false) else null,
"events": [] if o.get("events", false) else null,
}
var add := func(card_name: String, owner: int) -> int:
s.defs[card_name] = _with_price(pool.by_name[card_name], rules)
@ -175,13 +177,17 @@ static func create_game(o: Dictionary) -> Variant:
"anomalies": avs,
"unlockedLevel": 1,
})
for i in 4:
if avs[i].faceUp:
State.emit(s, {"k": "flipped", "ref": State.ref(p, i + 1)})
for p in 2:
var me: Dictionary = s.players[p]
var start: Dictionary = s.locations[GameMap.START_LOC[p]]
var server: int = me.serverPile.pop_front()
start.owner = p
start.server = server
me.bandwidth = rules.startingBandwidth + CardScripts.of(s.cards[server].name).get("bandwidthOnPlace", 0)
State.emit_install(s, server, "loc:" + GameMap.START_LOC[p])
State.add_bandwidth(s, p, rules.startingBandwidth + CardScripts.of(s.cards[server].name).get("bandwidthOnPlace", 0))
State.played(s, s.cards[server].name, p)
for i in rules.openingHand:
Flow.draw_now(s, p)
@ -190,9 +196,14 @@ static func create_game(o: Dictionary) -> Variant:
s.active = s.firstPlayer
var p2 := State.other(s.firstPlayer)
var second: Dictionary = s.players[p2]
second.bandwidth += rules.secondPlayer.bandwidth
for av in second.anomalies.slice(0, rules.startingAnomalies + rules.secondPlayer.anomalies):
State.add_bandwidth(s, p2, rules.secondPlayer.bandwidth)
var opening: Array = second.anomalies.slice(0, rules.startingAnomalies + rules.secondPlayer.anomalies)
for i in opening.size():
var av: Dictionary = opening[i]
var was: bool = av.faceUp
av.faceUp = av.card >= 0
if av.faceUp and not was:
State.emit(s, {"k": "flipped", "ref": State.ref(p2, i + 1)})
for i in rules.secondPlayer.cards:
Flow.draw_now(s, p2)
if rules.secondPlayer.locations > 0:
@ -201,11 +212,13 @@ static func create_game(o: Dictionary) -> Variant:
var L: Dictionary = s.locations[GameMap.other_end(line, GameMap.START_LOC[p2])]
L.owner = p2
L.server = second.serverPile.pop_front()
State.emit_install(s, L.server, "loc:" + GameMap.other_end(line, GameMap.START_LOC[p2]))
State.played(s, s.cards[L.server].name, p2)
s.stats.cardsDrawn = [0, 0]
State.say(s, "%s goes first." % State.player_name(s.firstPlayer), {"tag": "game", "player": s.firstPlayer})
_begin_turn(s, not rules.firstTurn.draw)
run(s)
State.reconcile_bandwidth(s, [0, 0], 0)
return s
@ -218,6 +231,7 @@ static func _begin_turn(s: Dictionary, skip_draw: bool) -> void:
return
s.turn += 1
s.clock = State.start_of(s.turn)
State.emit(s, {"k": "turn", "turn": s.turn, "p": s.active})
# Command rule: a player's turn is their commands in a round, so its refreshes come at the first.
var fresh: bool = not cmd or State.first_command(s, s.turn)
if not cmd or State.round_of(s, s.turn) != State.round_of(s, s.turn - 1):
@ -260,7 +274,7 @@ static func _end_turn(s: Dictionary) -> void:
var until = s.cards[hw].get("pushedUntil")
if until != null and not State.running(s, until):
State.remove_from(av.hardware, hw)
State.to_discard(s, hw)
State.to_discard(s, hw, "worn", "expired")
State.say(s, "%s (Push Update) is discarded." % State.name_of(s, hw))
_tidy(s)
s.active = State.commander_of(s, s.turn + 1) if s.rules.commands.on else State.other(s.active)
@ -727,6 +741,11 @@ static func apply_action(s: Dictionary, a: Dictionary, legal: Variant = null) ->
var p: int = decider(s)
var me: Dictionary = s.players[p]
var who := State.player_name(p)
var events_from := -1
var bandwidth_before := []
if State.has_events(s):
events_from = s.events.size()
bandwidth_before = [s.players[0].bandwidth, s.players[1].bandwidth]
match a.type:
"end":
@ -752,9 +771,11 @@ static func apply_action(s: Dictionary, a: Dictionary, legal: Variant = null) ->
"buyAnomaly":
var price: int = anomaly_for_sale(s, p).price
var av: Dictionary = me.anomalies[a.slot - 1]
me.bandwidth -= price
State.add_bandwidth(s, p, -price)
State.stat(s, "bandwidthOnAnomalies", p, price)
State.stat(s, "anomaliesBought", p)
if not av.faceUp:
State.emit(s, {"k": "flipped", "ref": State.ref(p, a.slot)})
av.faceUp = true
State.say(s, "%s buys Anomaly %d: %s (-%d Gb, now %d)." % [who, a.slot, State.name_of(s, av.card), price, me.bandwidth], {"tag": "card", "player": p})
"recruit":
@ -763,18 +784,19 @@ static func apply_action(s: Dictionary, a: Dictionary, legal: Variant = null) ->
if av.card >= 0:
Flow.retire_anomaly(s, State.ref(p, a.slot))
State.remove_from(me.hand, a.card)
me.bandwidth -= cost
State.add_bandwidth(s, p, -cost)
State.stat(s, "bandwidthOnCards", p, cost)
State.stat(s, "anomaliesRecruited", p)
State.played(s, State.name_of(s, a.card), p)
av.merge(_new_anomaly(a.card, true, null), true)
me.anomalies[a.slot + 3].card = a.card
State.emit(s, {"k": "flipped", "ref": State.ref(p, a.slot)})
State.say(s, "%s recruits %s as Anomaly %d (-%d Gb, now %d)." % [who, State.name_of(s, a.card), a.slot, cost, me.bandwidth], {"tag": "card", "player": p})
"salvage":
var gain: int = State.def_of(s, a.card).bandwidth
State.remove_from(me.hand, a.card)
State.to_discard(s, a.card)
me.bandwidth += gain
State.to_discard(s, a.card, "hand", "salvage")
State.add_bandwidth(s, p, gain)
State.stat(s, "bandwidthFromSalvage", p, gain)
State.stat(s, "cardsSalvaged", p)
State.say(s, "%s salvages %s (+%d Gb, now %d)." % [who, State.name_of(s, a.card), gain, me.bandwidth], {"tag": "card", "player": p})
@ -784,6 +806,7 @@ static func apply_action(s: Dictionary, a: Dictionary, legal: Variant = null) ->
var text := "%s places %s on %s." % [who, State.anomaly_name(s, r), a.to] if av.at == null \
else "%s moves %s %s → %s." % [who, State.anomaly_name(s, r), av.at, a.to]
State.say(s, text, {"tag": "move", "player": p, "loc": a.to, "ref": r})
State.emit_moved(s, r, av.at, a.to)
av.at = a.to
av.placed = true
"recall":
@ -806,15 +829,17 @@ static func apply_action(s: Dictionary, a: Dictionary, legal: Variant = null) ->
"clearFirewall":
var level: int = s.firewalls[a.line]
var cost := State.firewall_cost(s, level)
me.bandwidth -= cost
State.add_bandwidth(s, p, -cost)
State.stat(s, "bandwidthOnFirewalls", p, cost)
s.firewalls.erase(a.line)
State.emit(s, {"k": "firewall", "line": a.line, "from": level, "to": 0, "p": p})
State.stat(s, "firewallsCleared", p)
State.say(s, "%s clears the Lv %d Firewall on %s (-%d Gb)." % [who, level, a.line, cost], {"tag": "firewall", "player": p})
"firewall":
var before: int = s.firewalls.get(a.line, 0)
var cost := Query.pay(s, {"kind": "firewall", "player": p, "line": a.line, "level": a.level}, "bandwidthOnFirewalls")
s.firewalls[a.line] = a.level
State.emit(s, {"k": "firewall", "line": a.line, "from": before, "to": a.level, "p": p})
State.stat(s, "firewallsUpgraded" if before else "firewallsPlaced", p)
var text := "%s upgrades the Firewall on %s to Lv %d (-%d Gb)." % [who, a.line, a.level, cost] if before \
else "%s places a Lv %d Firewall on %s (-%d Gb)." % [who, a.level, a.line, cost]
@ -824,6 +849,7 @@ static func apply_action(s: Dictionary, a: Dictionary, legal: Variant = null) ->
var cost := Query.pay(s, {"kind": "hardware", "player": p, "card": a.card, "ref": r, "at": State.anomaly(s, r).at}, "bandwidthOnCards")
State.remove_from(me.hand, a.card)
State.anomaly(s, r).hardware.append(a.card)
State.emit_install(s, a.card, "anomaly:%d:%d" % [r.player, r.slot])
s.cards[a.card].installedTurn = s.turn
State.stat(s, "hardwareInstalled", p)
State.played(s, State.name_of(s, a.card), p)
@ -834,6 +860,7 @@ static func apply_action(s: Dictionary, a: Dictionary, legal: Variant = null) ->
var cost := Query.pay(s, {"kind": "program", "player": p, "card": a.card, "at": a.at}, "bandwidthOnCards")
State.remove_from(me.hand, a.card)
s.locations[a.at].programs.append(a.card)
State.emit_install(s, a.card, "loc:" + a.at)
s.cards[a.card].installedTurn = s.turn
State.stat(s, "programsInstalled", p)
State.played(s, State.name_of(s, a.card), p)
@ -850,6 +877,7 @@ static func apply_action(s: Dictionary, a: Dictionary, legal: Variant = null) ->
"from": a.from, "power": execution_power(s, p, a.from),
}
s.stack.append(item)
State.emit(s, {"k": "stack", "p": p, "card": a.card, "name": card_name, "kind": "execution"})
if item.power > 0:
State.fired(s, "Dedicated GPU", p)
State.stat(s, "executionsPlayed", p)
@ -863,7 +891,7 @@ static func apply_action(s: Dictionary, a: Dictionary, legal: Variant = null) ->
"activate":
var src: Dictionary = ability_source(s, a.card, a.name)
var cost := ability_cost(s, src) + _extra_cost(s, src, a.args)
me.bandwidth -= cost
State.add_bandwidth(s, p, -cost)
State.stat(s, "bandwidthOnAbilities", p, cost)
if src.kind == "hardware":
HardwareCards.use_hardware(s, src.id)
@ -871,6 +899,7 @@ static func apply_action(s: Dictionary, a: Dictionary, legal: Variant = null) ->
State.mark_used(s, ability_key(src))
var label: String = "%s (%s)" % [State.def_of(s, src.id).ability.name, src.name] if src.kind == "anomaly" else src.name
s.stack.append({"kind": "ability", "player": p, "card": src.id, "name": src.name, "target": null, "args": a.args, "from": null, "power": 0})
State.emit(s, {"k": "stack", "p": p, "card": src.id, "name": src.name, "kind": "ability"})
State.stat(s, "abilitiesUsed", p)
if src.kind == "anomaly":
State.played(s, src.name, p)
@ -878,6 +907,8 @@ static func apply_action(s: Dictionary, a: Dictionary, legal: Variant = null) ->
State.say(s, "%s uses %s%s." % [who, label, paid], {"tag": "card", "player": p, "loc": src.at, "ref": src.get("ref")})
_respond_to(s, p, s.stack.size() - 1)
run(s)
if events_from >= 0:
State.reconcile_bandwidth(s, bandwidth_before, events_from)
return true
@ -954,7 +985,7 @@ static func _resolve_top(s: Dictionary) -> void:
var item: Dictionary = s.stack.pop_back()
var script := CardScripts.of(item.name)
if item.kind == "execution":
State.to_discard(s, item.card)
State.to_discard(s, item.card, "stack", "played")
for src in Query.sources(s):
var sc := CardScripts.of(src.name)
if sc.has("negates") and sc.negates.call(s, src, item):
@ -1043,6 +1074,7 @@ static func view_for(s: Dictionary, p: int) -> Dictionary:
var view := s.duplicate()
view.rng = {"s": 0}
view.log = null
view.events = null
view.players = players
view.choice = choice
view.combat = combat

View file

@ -28,6 +28,7 @@ static func draw_now(s: Dictionary, p: int) -> Variant:
var card: int = pl.deck.pop_front()
pl.hand.append(card)
State.stat(s, "cardsDrawn", p)
State.emit(s, {"k": "drew", "p": p, "card": card})
return card
@ -49,16 +50,21 @@ static func _clear_status(av: Dictionary) -> void:
av.damage = 0
## A copy leaves play. It has no Hardware of its own.
static func remove_copy(s: Dictionary, r: Dictionary) -> void:
## A copy leaves play. It has no Hardware of its own. `recalled` is false when a defeat already
## told the events.
static func remove_copy(s: Dictionary, r: Dictionary, recalled := true) -> void:
var cp := State.anomaly(s, r)
if cp.at == null:
return
State.say(s, "%s is removed." % State.anomaly_name(s, r), {"tag": "move", "player": r.player, "ref": r})
var counters := State.counters_of(cp)
if recalled:
State.emit_moved(s, r, cp.at, null)
_clear_status(cp)
cp.permanentInfection = 0
cp.at = null
cp.faceUp = false
State.emit_counters(s, r, counters)
drop_from_combat(s, r)
@ -70,11 +76,11 @@ static func retire_anomaly(s: Dictionary, r: Dictionary) -> void:
if not av.hardware.is_empty():
State.stat(s, "hardwareLost", r.player, av.hardware.size())
for hw in av.hardware:
State.to_discard(s, hw)
State.to_discard(s, hw, "worn", "retired")
var from := " from %s" % av.at if av.at else ""
State.say(s, "%s retires %s%s." % [State.player_name(r.player), State.anomaly_name(s, r), from], {"tag": "card", "player": r.player, "ref": r})
drop_from_combat(s, r)
State.to_discard(s, av.card)
State.to_discard(s, av.card, "slot", "retired")
State.stat(s, "anomaliesRetired", r.player)
@ -84,18 +90,22 @@ static func knock_out(s: Dictionary, r: Dictionary, loc: String, role: String, k
var av := State.anomaly(s, r)
if av.at == null:
return
if State.has_events(s):
State.emit(s, {"k": "destroyed", "ref": r.duplicate(), "loc": av.at})
if State.is_copy(r):
remove_copy(s, r)
remove_copy(s, r, false)
else:
if not keep_hardware and not av.hardware.is_empty():
var names := ", ".join(av.hardware.map(func(h): return State.name_of(s, h)))
State.say(s, "%s loses %s." % [State.player_name(r.player), names], {"tag": "combat", "player": r.player, "ref": r, "loc": loc})
State.stat(s, "hardwareLost", r.player, av.hardware.size())
for hw in av.hardware:
State.to_discard(s, hw)
State.to_discard(s, hw, "worn", "destroyed")
av.hardware = []
var counters := State.counters_of(av)
_clear_status(av)
av.at = null
State.emit_counters(s, r, counters)
State.say(s, "%s returns to its slot." % State.anomaly_name(s, r), {"tag": "combat", "player": r.player, "ref": r, "loc": loc})
remove_copy(s, State.copy_of(r))
State.stat(s, "anomaliesDestroyed", r.player)
@ -112,9 +122,12 @@ static func recall_anomaly(s: Dictionary, r: Dictionary) -> void:
var healed: int = av.damage
var healing := ", healing %d damage" % healed if healed else ""
State.say(s, "%s recalls %s from %s to its slot%s." % [State.player_name(r.player), State.anomaly_name(s, r), av.at, healing], {"tag": "move", "player": r.player, "ref": r, "loc": av.at})
var counters := State.counters_of(av)
State.emit_moved(s, r, av.at, null)
_clear_status(av)
av.at = null
av.placed = true
State.emit_counters(s, r, counters)
remove_copy(s, State.copy_of(r))
State.stat(s, "recalls", r.player)
@ -123,6 +136,8 @@ static func recall_anomaly(s: Dictionary, r: Dictionary) -> void:
static func create_copy(s: Dictionary, original: Dictionary, to: String) -> void:
var r := State.copy_of(original)
var cp := State.anomaly(s, r)
var was = cp.at
var counters := State.counters_of(cp)
cp.merge({
"card": State.anomaly(s, original).card,
"faceUp": true,
@ -141,6 +156,8 @@ static func create_copy(s: Dictionary, original: Dictionary, to: String) -> void
"breachedTurn": 0,
"createdTurn": s.turn,
}, true)
State.emit_moved(s, r, was, to)
State.emit_counters(s, r, counters)
State.say(s, "%s creates %s on %s." % [State.player_name(r.player), State.anomaly_name(s, r), to], {"tag": "card", "player": r.player, "ref": r, "loc": to})
@ -148,6 +165,7 @@ static func create_copy(s: Dictionary, original: Dictionary, to: String) -> void
static func move_anomaly(s: Dictionary, r: Dictionary, to: String) -> void:
var av := State.anomaly(s, r)
State.say(s, "%s moves %s → %s." % [State.anomaly_name(s, r), av.at, to], {"tag": "move", "player": r.player, "ref": r, "loc": to})
State.emit_moved(s, r, av.at, to)
av.at = to
@ -225,6 +243,8 @@ static func _roll_all(s: Dictionary, c: Dictionary) -> void:
break
c.ties += 1
c.rolled = true
if State.has_events(s):
State.emit(s, {"k": "rolled", "loc": c.loc, "dice": c.dice.duplicate(true)})
# ---------------------------------------------------------------------------------------------
@ -241,6 +261,8 @@ static func damage_anomaly(s: Dictionary, r: Dictionary, n: int) -> bool:
if av.at == null or n <= 0:
return false
av.damage += n
if State.has_events(s):
State.emit(s, {"k": "damaged", "ref": r.duplicate(), "amount": n, "loc": av.at})
var dead: bool = av.damage >= Query.health_of(s, r)
var how := " and is destroyed" if dead else " (%s)" % health_text(s, r)
State.say(s, "%s takes %d damage%s." % [State.anomaly_name(s, r), n, how], {"tag": "combat", "player": r.player, "ref": r, "amount": n, "loc": av.at})
@ -327,6 +349,7 @@ static func sync_dice(s: Dictionary, c: Dictionary) -> void:
for r in State.fighters_of(c):
var key := State.ref_key(r)
var dice: Array = c.dice.get(key, [])
var before := dice.duplicate() if State.has_events(s) else []
var want := Query.cores_of(s, Query.fighter_of(s, r))
while dice.size() < want:
dice.append(State.roll_die(s))
@ -334,6 +357,8 @@ static func sync_dice(s: Dictionary, c: Dictionary) -> void:
dice.sort()
dice.resize(want)
c.dice[key] = dice
if State.has_events(s) and dice != before:
State.emit(s, {"k": "rerolled", "ref": r.duplicate(), "dice": dice.duplicate()})
## Current dice totals {atk, def}, after syncing to Core changes.
@ -407,6 +432,9 @@ static func _run_stage(s: Dictionary, c: Dictionary, stage: String) -> void:
var hp := func(r): return ", %s" % health_text(s, r) if s.rules.health.on else ""
var defs := " and ".join(c.defenders.map(func(d): return "%s%s" % [State.anomaly_name(s, d), hp.call(d)]))
State.say(s, "Combat at %s: %s (%d Cores, from %s%s) vs %s (%d Cores)." % [c.loc, State.anomaly_name(s, c.attacker), sides.atk, c.origin, hp.call(c.attacker), defs, sides.def], {"tag": "combat", "player": c.attacker.player, "loc": c.loc, "ref": c.attacker})
if State.has_events(s):
State.emit(s, {"k": "combat", "id": c.id, "loc": c.loc, "attacker": c.attacker.duplicate(),
"defenders": c.defenders.map(func(d): return d.duplicate()), "kind": c.kind})
Query.emit(s, "onCombatStart", null)
return
if stage == "roll":
@ -497,16 +525,22 @@ static func capture_main(s: Dictionary, r: Dictionary, loc: String, how: String)
if State.anomaly(s, r).at == null or State.controls(s, p, loc):
return
var previous = L.owner
State.emit_moved(s, r, State.anomaly(s, r).at, loc)
if State.has_events(s):
State.emit(s, {"k": "captured", "loc": loc, "p": p, "from": previous})
if L.server != null:
State.reset_card(s, L.server)
s.players[s.cards[L.server].owner].serverPile.append(L.server)
State.emit_pile(s, L.server, "serverPile", "play")
if previous != null and not L.programs.is_empty():
State.stat(s, "programsLost", previous, L.programs.size())
for prog in L.programs:
State.to_discard(s, prog)
State.to_discard(s, prog, "play", "captured")
L.programs = []
L.owner = p
L.server = me.serverPile.pop_front() if not me.serverPile.is_empty() else null
if L.server != null:
State.emit_install(s, L.server, "loc:" + loc)
State.anomaly(s, r).at = loc
var level := GameMap.level_for(p, loc)
@ -528,6 +562,7 @@ static func capture_main(s: Dictionary, r: Dictionary, loc: String, how: String)
if i < level and not av.faceUp:
av.faceUp = true
av.unlockedTurn = s.turn
State.emit(s, {"k": "flipped", "ref": State.ref(p, i + 1)})
State.say(s, "%s unlocks Anomaly %d: %s." % [State.player_name(p), i + 1, State.name_of(s, av.card)], {"tag": "capture", "player": p, "loc": loc})
if State.grid_count(s, p) >= s.rules.winLocations:
s.over = true

View file

@ -356,7 +356,7 @@ static func pay(s: Dictionary, payment: Dictionary, stat_key: String) -> int:
var cost := maxi(0, n)
if cost > s.players[payment.player].bandwidth:
Util.fail("Can't afford %d Gb" % cost)
s.players[payment.player].bandwidth -= cost
State.add_bandwidth(s, payment.player, -cost)
State.stat(s, stat_key, payment.player, cost)
for src in touched:
var sc := CardScripts.of(src.name)

View file

@ -65,6 +65,58 @@ static func say(s: Dictionary, msg: String, meta := {}) -> void:
s.log.append(line)
## Records what just happened for the table to act out (godot-plan.md §3): `ev` is {k: kind, ...}.
## Only a game made with `events` keeps them; TS has no events, so they stay out of conformance.
static func emit(s: Dictionary, ev: Dictionary) -> void:
var events = s.get("events")
if events != null:
events.append(ev)
## Whether this game records events, to skip building ones nobody keeps.
static func has_events(s: Dictionary) -> bool:
return s.get("events") != null
## Events from index `from` as `viewer` may see them: copies, with cards they can't see as -1 (the
## other player's draws, and cards the other player takes into hand from a hidden pile).
static func events_for(s: Dictionary, viewer: int, from := 0) -> Array:
var out := []
var events = s.get("events")
if events == null:
return out
for i in range(maxi(0, from), events.size()):
var ev: Dictionary = events[i].duplicate(true)
var theirs: bool = ev.get("p", viewer) != viewer
if theirs and (ev.k == "drew" or (ev.k == "hand" and ev.get("from") in ["deck", "serverPile", ""])):
ev.card = -1
elif theirs and ev.k == "pile" and ev.get("from") == "hand":
ev.card = -1
out.append(ev)
return out
## Folded Bandwidth events must equal the Bandwidth: when a change slipped past the helpers, one more
## event makes up the difference. `before` is each player's Bandwidth at event `from`. Counted in
## event_fixes, which tests expect to stay 0.
static var event_fixes := 0
static func reconcile_bandwidth(s: Dictionary, before: Array, from: int) -> void:
var events = s.get("events")
if events == null:
return
var have := before.duplicate()
for i in range(from, events.size()):
var ev: Dictionary = events[i]
if ev.k == "bandwidth":
have[ev.p] = ev.to
for p in 2:
if have[p] != s.players[p].bandwidth:
event_fixes += 1
emit(s, {"k": "bandwidth", "p": p, "from": have[p], "to": s.players[p].bandwidth})
## The play-by-play as `viewer` may read it, or every line in full for null.
static func log_for(s: Dictionary, viewer: Variant) -> Array:
var out := []
@ -374,14 +426,60 @@ static func reset_card(s: Dictionary, id: int) -> void:
c.erase("pushedUntil")
static func to_discard(s: Dictionary, id: int) -> void:
## `from` and `why` only describe the move for events: from "hand", "play" (a location's Server or
## Program), "worn" (Hardware), "stack", "slot" or "deck"; why "salvage", "played", "destroyed",
## "captured", "discarded", ….
static func to_discard(s: Dictionary, id: int, from := "", why := "") -> void:
reset_card(s, id)
s.players[owner_of(s, id)].discard.append(id)
if has_events(s):
emit(s, {"k": "discard", "p": owner_of(s, id), "card": id, "from": from, "why": why})
static func to_hand(s: Dictionary, id: int) -> void:
static func to_hand(s: Dictionary, id: int, from := "") -> void:
reset_card(s, id)
s.players[owner_of(s, id)].hand.append(id)
if has_events(s):
emit(s, {"k": "hand", "p": owner_of(s, id), "card": id, "from": from})
## A Server, Program or Hardware card arriving on a location ("loc:C2") or an Anomaly
## ("anomaly:0:1"), for events.
static func emit_install(s: Dictionary, id: int, at: String) -> void:
if has_events(s):
emit(s, {"k": "install", "p": owner_of(s, id), "card": id, "at": at})
## A card going into its owner's deck or Server pile ("deck", "serverPile"), for events.
static func emit_pile(s: Dictionary, id: int, zone: String, from: String) -> void:
if has_events(s):
emit(s, {"k": "pile", "p": owner_of(s, id), "card": id, "zone": zone, "from": from})
static func emit_moved(s: Dictionary, r: Dictionary, from: Variant, to: Variant) -> void:
if not has_events(s) or from == to:
return
if from == null:
emit(s, {"k": "placed", "ref": r.duplicate(), "loc": to})
elif to == null:
emit(s, {"k": "recalled", "ref": r.duplicate(), "from": from})
else:
emit(s, {"k": "moved", "ref": r.duplicate(), "from": from, "to": to})
## The counters an Anomaly shows, for "counter" events: take them before a change and pass them to
## emit_counters after it.
static func counters_of(av: Dictionary) -> Dictionary:
return {"infection": infection_of(av), "bugs": av.bugs, "damage": av.damage}
static func emit_counters(s: Dictionary, r: Dictionary, before: Dictionary) -> void:
if not has_events(s):
return
var now := counters_of(anomaly(s, r))
for what in now:
if now[what] != before[what]:
emit(s, {"k": "counter", "ref": r.duplicate(), "what": what, "from": before[what], "to": now[what]})
static func remove_from(list: Array, id: int) -> bool:
@ -417,10 +515,18 @@ static func program_location(s: Dictionary, id: int) -> Variant:
static func gain_bandwidth(s: Dictionary, p: int, n: int, key := "bandwidthFromEffects") -> void:
if n <= 0:
return
s.players[p].bandwidth += n
add_bandwidth(s, p, n)
stat(s, key, p, n)
## Changes a player's Bandwidth by `n` (negative to spend), with its event. No stats.
static func add_bandwidth(s: Dictionary, p: int, n: int) -> void:
var before: int = s.players[p].bandwidth
s.players[p].bandwidth = before + n
if n != 0 and has_events(s):
emit(s, {"k": "bandwidth", "p": p, "from": before, "to": before + n})
# ---------------------------------------------------------------------------------------------
# Tasks and choices