feat: add C5 magic spellcasting

This commit is contained in:
goose
2026-10-03 11:01:47 -04:00
parent a7c2e2d034
commit 27f5d5b575
18 changed files with 550 additions and 10 deletions
+2 -2
View File
@@ -48,9 +48,9 @@ func begin(event: GameEvent, actor_lookup: Callable) -> void:
match event.kind:
&"moved", &"enemy_moved":
await _show_movement(event, actor_lookup)
&"projectile_fired":
&"projectile_fired", &"spell_cast_started":
await _show_projectile(event, actor_lookup)
&"melee", &"enemy_melee", &"damage_dealt":
&"melee", &"enemy_melee", &"damage_dealt", &"spell_damage_dealt":
await _show_impact(event, actor_lookup)
&"enemy_defeated", &"actor_died":
await _show_death(event, actor_lookup)
+3
View File
@@ -9,6 +9,8 @@ const BED_PROMPT := "H — Se reposer (coûte 1 jour)"
const EXIT_REACHED_PROMPT := "Sortie atteinte — prochain étage bientôt disponible"
@onready var player_health_label: Label = $PlayerHealthLabel
@onready var player_focus_label: Label = $PlayerFocusLabel
@onready var spell_label: Label = $SpellLabel
@onready var deadline_label: Label = $DeadlineLabel
@onready var enemy_health_label: Label = $EnemyHealthLabel
@onready var combat_summary_label: Label = $CombatSummaryLabel
@@ -23,6 +25,7 @@ func refresh(state: GameState, events: Array[GameEvent] = [], run_state: RunStat
if run_state != null:
_run_state = run_state
player_health_label.text = "Player HP: %d/%d" % [state.player.hit_points, state.player.max_hit_points]
player_focus_label.text = "Focus: %d/%d" % [state.player.focus, state.player.max_focus]
if state.enemies.has(&"goblin"):
var goblin: ActorState = state.enemies[&"goblin"]
enemy_health_label.text = "Goblin HP: %d/%d" % [goblin.hit_points, goblin.max_hit_points]
@@ -0,0 +1,52 @@
class_name SpellTargetingOverlay
extends TargetingOverlay
var _spell_ids: Array[StringName] = []
var _selected_spell_index := 0
func begin_spells(spell_ids: Array[StringName], targets: Dictionary[StringName, Vector2i]) -> void:
_spell_ids = spell_ids.duplicate()
_spell_ids.sort()
_selected_spell_index = 0
begin(targets)
_refresh_label()
func finish() -> void:
_spell_ids.clear()
super.finish()
func get_spell_ids() -> Array[StringName]:
return _spell_ids.duplicate()
func _unhandled_input(event: InputEvent) -> void:
if not visible or not event.is_pressed():
return
if event.is_action_pressed(&"ui_page_up"):
_cycle_spell(-1)
get_viewport().set_input_as_handled()
elif event.is_action_pressed(&"ui_page_down"):
_cycle_spell(1)
get_viewport().set_input_as_handled()
else:
super._unhandled_input(event)
func _cycle_spell(amount: int) -> void:
if _spell_ids.is_empty():
return
_selected_spell_index = posmod(_selected_spell_index + amount, _spell_ids.size())
_refresh_label()
func _refresh_label() -> void:
var target_ids := get_target_ids()
if _spell_ids.is_empty() or target_ids.is_empty():
target_label.text = "Aucun sort ou cible valide"
return
var target_id := target_ids[_selected_index]
target_label.text = "Sort : %s — Cible : %s — Entrée pour lancer, Échap pour annuler" % [String(_spell_ids[_selected_spell_index]).trim_prefix("spell_").capitalize(), String(target_id).capitalize()]
func choose(target_id: StringName) -> void:
if _targets.has(target_id) and not _spell_ids.is_empty():
target_selected.emit(target_id)
func selected_spell_id() -> StringName:
return _spell_ids[_selected_spell_index] if not _spell_ids.is_empty() else &""
@@ -0,0 +1 @@
uid://dkaw3lxw40reb