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

@ -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