Godot 4 (GDScript)
boss_phase_controller.gdclass_name BossPhaseController
extends Node
signal phase_triggered(new_phase: int)
@export var max_hp: int = 100
@export var phase_thresholds: Array[int] = [45] # Hard lock HP values
var hp: int = 100
var current_phase: int = 1
func apply_damage(raw_damage: int) -> Dictionary:
var next_hp := maxi(0, hp - raw_damage)
var clamped := false
if current_phase <= phase_thresholds.size():
var gate := phase_thresholds[current_phase - 1]
if hp > gate and next_hp <= gate:
next_hp = gate
clamped = true
current_phase += 1
phase_triggered.emit(current_phase)
hp = next_hp
return { "hp": hp, "clamped": clamped, "phase": current_phase }