Hub character swapping, XP percentage, passive health regeneration
ci / verify (push) Successful in 47s

Character swapping is hub-only, and refused by the SERVER rather than merely
greyed out in the menu. Allowing it inside a dungeon would be an instant,
uninterruptible exit from danger -- strictly better than the one-second escape
channel, which would make that channel pointless. Creating a character in a
dungeon is refused for the same reason. Both are covered by diag_progression.

Health regenerates at 0.5% of MAXIMUM per second. A percentage rather than a
flat rate so it does not become irrelevant at level 15: a capped character
regains 1.2 hp/s against a level 1's 0.5, and both take about 200 seconds to
heal from nothing. No out-of-combat gate -- at this rate it cannot out-heal
anything actually shooting at you, and a trickle that never stops is easier to
reason about than a timer players have to learn. A fractional carry is needed
because a tick heals well under one hit point, so truncating each tick would
heal exactly nothing; there is a test for that specifically.

The XP bar now states the percentage and the level it leads to, since a bar
answers "how far" vaguely and a number answers it exactly.

Recorded the two Stage 3 answers: 4 inventory slots, and the boss's food item
is player-instanced now so the mechanism gets exercised rather than deferred.

Writing the swap guard's test caught my own mistake: the first version created
its spare character through the store, which has no opinion about where you
are, so it bypassed the guard it was meant to prove and left a stray character
behind that broke a later assertion.

200 tests. check.sh, test.sh, smoke.sh and both diagnostics pass.
This commit is contained in:
2026-09-04 00:56:29 +02:00
parent 4765bbce28
commit 7ef972e3b3
14 changed files with 243 additions and 15 deletions
+7
View File
@@ -51,6 +51,13 @@ const PLAYER_BULLET_DAMAGE := 6
## live bullet field is survivable. Both halves matter: invulnerability alone
## would make the spawn point a free firing position.
const SPAWN_GRACE_TICKS := 120 # 2 seconds
## Passive healing, as a percentage of MAXIMUM health per second -- so it
## scales with level rather than becoming irrelevant at level 15. There is
## deliberately no out-of-combat gate: a slow trickle that never stops is
## simpler to reason about than a timer players have to learn, and at this rate
## it cannot outpace anything that is actually shooting at you.
const HP_REGEN_PERCENT_PER_SEC := 0.5
## A downed player cannot leave for the hub until this has elapsed. Enforced
## here rather than only by grey-ing out the button, because a disabled button
## is a suggestion -- the server is the only thing a modified client cannot
+13 -2
View File
@@ -11,7 +11,8 @@ extends RefCounted
## the wire value of every event after it -- a mismatched client would
## mis-decode every hit and death, so the handshake has to reject it.
## 5: handshake carries an auth ticket instead of a bare name; added character
## list/select/create messages and per-player max health in the snapshot.
## list/select/create messages, per-player max health and colour in the
## snapshot.
const VERSION := 5
const DEFAULT_PORT := 27015
const MAX_CLIENTS := 32
@@ -29,7 +30,17 @@ enum InstanceKind { LOBBY, DUNGEON }
## Why a character selection failed. Sent rather than a bare "no", so the UI can
## say something useful instead of appearing broken.
enum SelectResult { OK, NO_SUCH_CHARACTER, CHARACTER_IS_DEAD, LIMIT_REACHED, NOT_AUTHENTICATED }
enum SelectResult {
OK,
NO_SUCH_CHARACTER,
CHARACTER_IS_DEAD,
LIMIT_REACHED,
NOT_AUTHENTICATED,
## Swapping is hub-only. Allowing it inside a dungeon would be an instant,
## uninterruptible exit from danger -- strictly better than the one-second
## escape channel, and it would make that channel pointless.
NOT_IN_HUB,
}
## Player flags packed into the snapshot's per-player byte.
const F_ALIVE := 1
+14
View File
@@ -233,6 +233,15 @@ func on_select_character(peer_id: int, character_id: String) -> void:
return
# Looked up against THIS account's characters, so a client cannot select
# somebody else's by guessing an id.
# Hub only. A player inside a dungeon who could swap character would have an
# instant escape from anything dangerous -- strictly better than the escape
# channel, and it would hollow out the whole reason that channel exists.
# Checked here rather than hidden in the UI, which a modified client ignores.
var here := instance_of(peer_id)
if here != null and here.kind != Protocol.InstanceKind.LOBBY:
Net.send_select_result(peer_id, Protocol.SelectResult.NOT_IN_HUB,
"you can only change character in the hub")
return
var c := store.get_character(account, character_id)
if c == null:
Net.send_select_result(peer_id, Protocol.SelectResult.NO_SUCH_CHARACTER, "no such character")
@@ -251,6 +260,11 @@ func on_create_character(peer_id: int, character_name: String) -> void:
if account == AuthProvider.NO_ACCOUNT:
Net.send_select_result(peer_id, Protocol.SelectResult.NOT_AUTHENTICATED, "not signed in")
return
var where := instance_of(peer_id)
if where != null and where.kind != Protocol.InstanceKind.LOBBY:
Net.send_select_result(peer_id, Protocol.SelectResult.NOT_IN_HUB,
"you can only change character in the hub")
return
var c := store.create_character(account, character_name)
if c == null:
Net.send_select_result(peer_id, Protocol.SelectResult.LIMIT_REACHED,
+22
View File
@@ -21,6 +21,10 @@ var alive: bool = true
var fire_cooldown: int = 0
## Ticks of arrival protection left: invulnerable, and unable to shoot.
var spawn_grace: int = 0
## Fractional health carried between ticks. Regeneration is well under one hit
## point per tick, so without this it would round to zero every tick and heal
## nothing at all.
var regen_carry: float = 0.0
## Ticks before a downed player may ask to return to the hub.
var respawn_lockout: int = 0
@@ -68,6 +72,7 @@ func reset_for_instance(spawn: Vector2, grace: int = 0) -> void:
alive = true
spawn_grace = grace
respawn_lockout = 0
regen_carry = 0.0
fire_cooldown = 0
escape_ticks = 0
input_queue.clear()
@@ -86,3 +91,20 @@ func adopt(c: Character) -> void:
colour = c.colour
max_hp = c.max_hp()
hp = mini(hp, max_hp)
## One tick of passive healing. Returns true if the visible hit points changed,
## so the caller can decide whether anything needs announcing.
func regenerate() -> bool:
if not alive or hp >= max_hp:
regen_carry = 0.0
return false
regen_carry += float(max_hp) * (SimConfig.HP_REGEN_PERCENT_PER_SEC / 100.0) \
* SimConfig.TICK_DELTA
if regen_carry < 1.0:
return false
var whole := int(regen_carry)
regen_carry -= float(whole)
var before := hp
hp = mini(hp + whole, max_hp)
return hp != before
+1
View File
@@ -172,6 +172,7 @@ func step() -> void:
func _step_players() -> void:
for p in players.values():
p.regenerate()
if p.spawn_grace > 0:
p.spawn_grace -= 1
if p.fire_cooldown > 0:
+13
View File
@@ -8,12 +8,14 @@ extends CanvasLayer
signal select_requested(character_id: String)
signal create_requested(character_name: String)
signal closed
var _list: VBoxContainer
var _name_field: LineEdit
var _create_button: Button
var _status: Label
var _title: Label
var _close_button: Button
var _known: Array[Dictionary] = []
var _selected: String = ""
@@ -63,6 +65,11 @@ func _ready() -> void:
_create_button.pressed.connect(_on_create)
row.add_child(_create_button)
_close_button = Button.new()
_close_button.text = "Back to the hub"
_close_button.pressed.connect(func() -> void: closed.emit())
panel.add_child(_close_button)
_status = Label.new()
_status.add_theme_font_size_override("font_size", 12)
_status.add_theme_color_override("font_color", Color(1.0, 0.6, 0.5))
@@ -144,3 +151,9 @@ func _row_for(c: Dictionary) -> Control:
play.pressed.connect(func() -> void: select_requested.emit(String(c["id"])))
row.add_child(play)
return row
## Whether the player may dismiss this screen. False when they have nothing to
## play, in which case there is nowhere to dismiss it to.
func set_dismissible(can_close: bool) -> void:
_close_button.visible = can_close
+11
View File
@@ -9,9 +9,11 @@ extends CanvasLayer
signal resumed
signal return_to_hub_requested
signal disconnect_requested
signal characters_requested
var _panel: VBoxContainer
var _hub_button: Button
var _characters_button: Button
var _disconnect_button: Button
var _note: Label
var _in_dungeon: bool = false
@@ -55,6 +57,9 @@ func _ready() -> void:
_hub_button = _button("Return to hub", func() -> void:
return_to_hub_requested.emit()
close())
_characters_button = _button("Change character", func() -> void:
characters_requested.emit()
close())
_button("Resume", func() -> void: close())
_disconnect_button = _button("Disconnect to menu", func() -> void:
disconnect_requested.emit()
@@ -108,6 +113,12 @@ func set_in_dungeon(in_dungeon: bool) -> void:
return
_in_dungeon = in_dungeon
_hub_button.disabled = not in_dungeon
# Swapping is hub-only, and the server enforces that regardless of what
# this button does -- but a disabled button explains the rule, where a
# refusal after the fact just looks broken.
_characters_button.disabled = in_dungeon
_characters_button.text = "Change character (hub only)" if in_dungeon \
else "Change character"
if in_dungeon:
# Disconnecting is not an escape: the server keeps the body in the
# world, channelling out, for the same second the escape button costs.
+11 -4
View File
@@ -156,10 +156,17 @@ func _draw_xp_bar(at: Vector2) -> void:
if who.is_empty():
return
var level := int(who["level"])
var progress: float = who["progress"] if level < Progression.MAX_LEVEL else 1.0
_canvas.draw_rect(Rect2(at, Vector2(BAR_W, 4.0)), Color(0.1, 0.12, 0.18))
_canvas.draw_rect(Rect2(at, Vector2(BAR_W * progress, 4.0)),
Color(0.6, 0.55, 1.0) if level < Progression.MAX_LEVEL else Color(1.0, 0.85, 0.4))
var capped := level >= Progression.MAX_LEVEL
var progress: float = 1.0 if capped else who["progress"]
var tint := Color(1.0, 0.85, 0.4) if capped else Color(0.6, 0.55, 1.0)
_canvas.draw_rect(Rect2(at, Vector2(BAR_W, 5.0)), Color(0.1, 0.12, 0.18))
_canvas.draw_rect(Rect2(at, Vector2(BAR_W * progress, 5.0)), tint)
# The number as well as the bar: "how far to the next level" is a question
# a bar answers vaguely and a percentage answers exactly.
var text := "MAX" if capped else "%d%% to level %d" % [
int(floor(progress * 100.0)), level + 1]
_canvas.draw_string(ThemeDB.fallback_font, at + Vector2(BAR_W + 10.0, 6.0),
text, HORIZONTAL_ALIGNMENT_LEFT, -1, 12, tint)
## Shown after the boss dies, so the victory lap has a visible clock on it.
+13 -2
View File
@@ -20,9 +20,13 @@ func _ready() -> void:
get_viewport().size_changed.connect(_recentre)
menu.return_to_hub_requested.connect(_on_return_to_hub)
menu.disconnect_requested.connect(_on_disconnect)
menu.characters_requested.connect(func() -> void: _roster_open = true)
hud.respawn_pressed.connect(_on_respawn_pressed)
characters.select_requested.connect(func(id: String) -> void: Net.select_character(id))
characters.select_requested.connect(func(id: String) -> void:
_roster_open = false
Net.select_character(id))
characters.create_requested.connect(func(n: String) -> void: Net.create_character(n))
characters.closed.connect(func() -> void: _roster_open = false)
var _screen_centre := Vector2.ZERO
@@ -60,7 +64,14 @@ func _process(_delta: float) -> void:
# The roster screen is shown exactly when there is nothing to play: first
# login, or after the last living character died.
if _bound != null:
characters.visible = _bound.needs_character() or _roster_open
# Forced open when there is nothing to play; opened deliberately from
# the menu otherwise. Never while in a dungeon -- the server refuses
# swaps there, so offering the screen would only invite a refusal.
var forced := _bound.needs_character()
if _bound.instance_kind != Protocol.InstanceKind.LOBBY:
_roster_open = false
characters.visible = forced or _roster_open
characters.set_dismissible(not forced)
_follow_camera()
menu.set_in_dungeon(_bound != null
and _bound.instance_kind == Protocol.InstanceKind.DUNGEON)