hp migration plan

Guide for hp migration plan

HP Formula Migration Plan

Context

The Hitpoints formula has been changed to match OSRS standards:
  • Old (Hypothetical): 10 + (Level - 1)
  • New (OSRS): Level (clamped 10-108)

Impact

Players with high Hitpoints levels will see a reduction in Max HP.
  • Level 99: 108 HP → 99 HP (-9)
  • Level 108: 117 HP → 108 HP (-9)

Issue

The players table persists hp (current hitpoints). max_hp is recalculated on login. If a player logs out with full health (e.g., 117 HP) and logs back in after the update, their hp (117) will exceed their new max_hp (108).

Solution

We need to clamp hp to the player's Hitpoints level.

SQL Migration

Execute the following SQL to correct all players:
UPDATE players p
SET hp = s.level
FROM skills s
WHERE p.id = s.player_id
  AND s.skill_name = 'hitpoints'
  AND p.hp > s.level;

Runtime Safeguard

In GameState::add_player or the login handler, ensure:
player.max_hp = combat_constants::calculate_hp(hitpoints_level);
if player.hp > player.max_hp {
    player.hp = player.max_hp;
}