feat(client): Luck (deterministic gen/drift/descriptor) + GameState store
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
31
client/scripts/state/game_state.gd
Normal file
31
client/scripts/state/game_state.gd
Normal file
@@ -0,0 +1,31 @@
|
||||
class_name GameState
|
||||
extends RefCounted
|
||||
## Luck-centric game state (spec decision 5). The SOLE home of numeric Luck,
|
||||
## stats, world-NPC dispositions, and inventory — none of which enter the canon
|
||||
## log (charter §7/§2). The log reads only luck_descriptor() from here.
|
||||
|
||||
var luck: int = 0
|
||||
var luck_base: int = 0
|
||||
var stats: Dictionary = {} # {str, dex, con, fth, mag}
|
||||
var npc_dispositions: Dictionary = {} # world-npc id -> int (−100..100)
|
||||
var inventory: Dictionary = {} # item_id -> qty
|
||||
|
||||
|
||||
func set_luck(v: int) -> void:
|
||||
luck = clampi(v, Luck.MIN, Luck.MAX)
|
||||
|
||||
|
||||
func drift_luck(delta: int) -> void:
|
||||
luck = Luck.drift(luck, luck_base, delta)
|
||||
|
||||
|
||||
func luck_descriptor() -> String:
|
||||
return Luck.descriptor(luck)
|
||||
|
||||
|
||||
func set_npc_disposition(id: String, v: int) -> void:
|
||||
npc_dispositions[id] = clampi(v, -100, 100)
|
||||
|
||||
|
||||
func add_item(item_id: String, qty: int) -> void:
|
||||
inventory[item_id] = int(inventory.get(item_id, 0)) + qty
|
||||
1
client/scripts/state/game_state.gd.uid
Normal file
1
client/scripts/state/game_state.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://c0ffensw2ym6w
|
||||
35
client/scripts/state/luck.gd
Normal file
35
client/scripts/state/luck.gd
Normal file
@@ -0,0 +1,35 @@
|
||||
class_name Luck
|
||||
extends RefCounted
|
||||
## Numeric Luck (charter §7). Lives in GameState; only descriptor() reaches the
|
||||
## log. Deterministic given a seeded RNG (charter §10). Die/range/bands are
|
||||
## TUNABLE constants — not final values.
|
||||
|
||||
const MIN := 1
|
||||
const MAX := 20
|
||||
const DRIFT := 3
|
||||
|
||||
const BANDS := [
|
||||
{"max": 4, "text": "Fortune spits on you"},
|
||||
{"max": 8, "text": "The world is not on your side"},
|
||||
{"max": 12, "text": "The dice are indifferent"},
|
||||
{"max": 16, "text": "Luck rides with you"},
|
||||
{"max": 20, "text": "The dice are kind today"},
|
||||
]
|
||||
|
||||
|
||||
static func roll_base(rng: RandomNumberGenerator, modifier: int) -> int:
|
||||
var total := 0
|
||||
for i in 5:
|
||||
total += rng.randi_range(1, 20)
|
||||
return clampi(roundi(total / 5.0) + modifier, MIN, MAX)
|
||||
|
||||
|
||||
static func drift(current: int, base: int, delta: int) -> int:
|
||||
return clampi(clampi(current + delta, base - DRIFT, base + DRIFT), MIN, MAX)
|
||||
|
||||
|
||||
static func descriptor(luck: int) -> String:
|
||||
for band in BANDS:
|
||||
if luck <= band["max"]:
|
||||
return band["text"]
|
||||
return BANDS[-1]["text"]
|
||||
1
client/scripts/state/luck.gd.uid
Normal file
1
client/scripts/state/luck.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dah05dv3uoym
|
||||
Reference in New Issue
Block a user