Stage 2: accounts, characters, permadeath, levels and experience
ci / verify (push) Successful in 47s
ci / verify (push) Successful in 47s
Identity is shaped like Steamworks so swapping to it is one subclass and no schema change: the client presents an opaque ticket, the server validates it into a stable 64-bit account id, and nothing downstream sees anything else. LocalAuthProvider takes any ticket at face value -- insecure on purpose, and labelled as such everywhere, because the point is the shape rather than the security. Do not ship it. Characters persist as JSON keyed by account. Account ids are written as decimal strings because they are 64-bit and JSON numbers are doubles, which would silently round them. A corrupt store aborts the server rather than starting empty: starting empty looks like it worked and then saves over every character on the first level-up. Levels 1-15, +10 max health each, level DERIVED from lifetime experience rather than stored beside it, so a hand-edited save cannot produce a level 12 character with a level 3's experience. Experience is shared undivided across everyone alive in the instance -- splitting it would make bringing a friend cost you progress. A level-up heals by what it added, so gaining one mid-fight is relief rather than a bar that moved further from full. Death is permanent and unbinds the character entirely: no "return to the hub as the character who just died", because the run is over. The record is retired, never deleted. The five-character cap counts LIVING characters only -- counting the dead would lock a player out of their own account after five deaths. Verified by tools/diag_progression.tscn, which drives the real server through kill -> xp -> level -> health and death -> retire -> roster. The bot smoke test cannot cover that: bots are poor shots and rarely kill anything. Writing it caught two real ordering bugs -- the death event was dispatched before the payload that tells the player they died, and the dead character stayed bound to the peer. Also added --account and --store so several clients and test runs can coexist on one machine. The smoke test now uses a scratch store; without it a rerun resumed the previous run's characters and "a character was created" quietly stopped being true. 193 tests. check.sh, test.sh, smoke.sh, diag_progression and diag_prediction all pass.
This commit is contained in:
@@ -161,3 +161,60 @@ func test_cleared_countdown_round_trips() -> void:
|
||||
func test_countdown_defaults_to_not_applicable() -> void:
|
||||
var snap := NetCodec.decode_snapshot(NetCodec.encode_snapshot(world))
|
||||
assert_eq(int(snap["cleared_countdown"]), Protocol.COUNTDOWN_NONE)
|
||||
|
||||
|
||||
# --- Characters -------------------------------------------------------------
|
||||
|
||||
func test_character_roster_round_trips() -> void:
|
||||
var rng := RandomNumberGenerator.new()
|
||||
rng.seed = 5
|
||||
var a := Character.create("Ada", rng)
|
||||
a.grant_xp(Progression.total_xp_for_level(4))
|
||||
var b := Character.create("Departed", rng)
|
||||
b.retire()
|
||||
var out := NetCodec.decode_characters(
|
||||
NetCodec.encode_characters([a, b] as Array[Character], a.id))
|
||||
assert_eq(String(out["selected"]), a.id)
|
||||
var chars: Array = out["characters"]
|
||||
assert_eq(chars.size(), 2)
|
||||
assert_eq(String(chars[0]["name"]), "Ada")
|
||||
assert_eq(int(chars[0]["level"]), a.level)
|
||||
assert_eq(int(chars[0]["max_hp"]), a.max_hp(),
|
||||
"the roster shows each character's own health ceiling")
|
||||
assert_true(chars[0]["active"])
|
||||
assert_false(chars[1]["active"], "a dead character is listed, not hidden")
|
||||
|
||||
|
||||
## Colour is a character's only identity until cosmetics exist, so it has to
|
||||
## survive the wire exactly rather than approximately.
|
||||
func test_character_colour_survives_the_wire() -> void:
|
||||
var rng := RandomNumberGenerator.new()
|
||||
rng.seed = 11
|
||||
var c := Character.create("Hue", rng)
|
||||
var out := NetCodec.decode_characters(
|
||||
NetCodec.encode_characters([c] as Array[Character], ""))
|
||||
var got: Color = out["characters"][0]["colour"]
|
||||
assert_eq(got.to_rgba32(), c.colour.to_rgba32())
|
||||
|
||||
|
||||
func test_an_empty_character_list_is_safe() -> void:
|
||||
var out := NetCodec.decode_characters(
|
||||
NetCodec.encode_characters([] as Array[Character], ""))
|
||||
assert_eq((out["characters"] as Array).size(), 0)
|
||||
assert_eq(NetCodec.decode_characters(PackedByteArray())["characters"].size(), 0)
|
||||
|
||||
|
||||
## Max health is per-character now, so a snapshot that assumed a constant would
|
||||
## draw every levelled player's bar wrong.
|
||||
func test_the_snapshot_carries_each_players_own_max_health() -> void:
|
||||
var p: SimPlayer = world.players[42]
|
||||
p.level = 5
|
||||
p.max_hp = Progression.max_hp_for_level(5)
|
||||
p.hp = 42
|
||||
p.colour = Color(0.2, 0.6, 0.9)
|
||||
var snap := NetCodec.decode_snapshot(NetCodec.encode_snapshot(world))
|
||||
var rec: Dictionary = snap["players"][0]
|
||||
assert_eq(int(rec["hp"]), 42)
|
||||
assert_eq(int(rec["max_hp"]), Progression.max_hp_for_level(5))
|
||||
assert_almost_eq((rec["colour"] as Color).b, 0.9, 0.02,
|
||||
"party members are told apart by colour, so it rides the snapshot")
|
||||
|
||||
Reference in New Issue
Block a user