7ef972e3b3
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.
97 lines
2.7 KiB
GDScript
97 lines
2.7 KiB
GDScript
extends GutTest
|
|
## Passive health regeneration.
|
|
|
|
var world: SimWorld
|
|
const PEER := 4
|
|
|
|
|
|
func before_each() -> void:
|
|
world = SimWorld.new(1)
|
|
world.add_player(PEER, "tester")
|
|
|
|
|
|
func _player() -> SimPlayer:
|
|
return world.players[PEER]
|
|
|
|
|
|
func test_it_heals_the_configured_share_of_maximum_per_second() -> void:
|
|
var p := _player()
|
|
p.hp = 1
|
|
for _i in SimConfig.TICK_RATE:
|
|
world.step()
|
|
var expected := float(p.max_hp) * SimConfig.HP_REGEN_PERCENT_PER_SEC / 100.0
|
|
assert_almost_eq(float(p.hp - 1), expected, 1.0,
|
|
"one second should restore %.1f%% of maximum" % SimConfig.HP_REGEN_PERCENT_PER_SEC)
|
|
|
|
|
|
## The reason for the fractional carry: at this rate a tick heals far less than
|
|
## one hit point, so truncating every tick would heal exactly nothing forever.
|
|
func test_fractions_accumulate_rather_than_being_lost() -> void:
|
|
var p := _player()
|
|
p.hp = 1
|
|
var per_tick := float(p.max_hp) * (SimConfig.HP_REGEN_PERCENT_PER_SEC / 100.0) \
|
|
* SimConfig.TICK_DELTA
|
|
assert_lt(per_tick, 1.0, "setup: a single tick must heal less than one hp")
|
|
for _i in SimConfig.TICK_RATE * 10:
|
|
world.step()
|
|
assert_gt(p.hp, 1, "ten seconds of sub-integer healing must still add up")
|
|
|
|
|
|
func test_it_scales_with_maximum_health_so_levels_do_not_dilute_it() -> void:
|
|
var low := _player()
|
|
low.max_hp = 100
|
|
low.hp = 1
|
|
for _i in SimConfig.TICK_RATE:
|
|
world.step()
|
|
var low_gain := low.hp - 1
|
|
|
|
var world2 := SimWorld.new(1)
|
|
var high := world2.add_player(PEER, "tester")
|
|
high.max_hp = 240
|
|
high.hp = 1
|
|
for _i in SimConfig.TICK_RATE:
|
|
world2.step()
|
|
assert_gt(high.hp - 1, low_gain,
|
|
"a levelled character should regain more per second, not the same")
|
|
|
|
|
|
func test_it_never_exceeds_maximum() -> void:
|
|
var p := _player()
|
|
p.hp = p.max_hp - 1
|
|
for _i in SimConfig.TICK_RATE * 30:
|
|
world.step()
|
|
assert_eq(p.hp, p.max_hp)
|
|
|
|
|
|
func test_the_dead_do_not_heal() -> void:
|
|
var p := _player()
|
|
p.alive = false
|
|
p.hp = 0
|
|
for _i in SimConfig.TICK_RATE * 10:
|
|
world.step()
|
|
assert_eq(p.hp, 0, "regeneration must not quietly revive a downed player")
|
|
|
|
|
|
## A replica never heals anyone: health, like damage, is the server's to decide.
|
|
func test_a_replica_world_does_not_regenerate() -> void:
|
|
world.authoritative = false
|
|
var p := _player()
|
|
p.hp = 1
|
|
for _i in SimConfig.TICK_RATE * 5:
|
|
world.step()
|
|
assert_eq(p.hp, 1)
|
|
|
|
|
|
## Slow enough that it cannot out-heal being shot, which is what makes an
|
|
## out-of-combat gate unnecessary.
|
|
func test_it_cannot_outpace_incoming_fire() -> void:
|
|
var p := _player()
|
|
p.pos = Vector2.ZERO
|
|
p.spawn_grace = 0
|
|
var start := p.hp
|
|
for _i in 60:
|
|
world.pool.spawn(Vector2.ZERO, Vector2.ZERO, 6.0, 60, 5,
|
|
SimConfig.TEAM_ENEMY, SimConfig.KIND_ORB)
|
|
world.step()
|
|
assert_lt(p.hp, start, "standing in fire must still lose health")
|