feat: port death and resurrection

This commit is contained in:
goose
2026-10-03 21:52:08 -04:00
parent 462bb97a5b
commit 8b479eaf08
13 changed files with 335 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
class_name DeathEngine
extends RefCounted
# Resurrection is deliberately data-gated: this quest-only item is authored by
# the dedicated narrative event and is excluded from generic loot/shop flows.
const NARRATIVE_PHYLACTERY_ID: StringName = &"misc_phylactere_narratif"
const RESURRECTION_HP_FRACTION := 0.25
const SLOT_POLICY_ACTIVE: StringName = &"active"
const SLOT_POLICY_PRESERVE: StringName = &"preserve"
const SLOT_POLICY_RETIRE: StringName = &"retire"
func resolve(combat_player: ActorState, narrative_player: PlayerState, inventory: InventoryState, permadeath: bool) -> Dictionary:
if combat_player == null or combat_player.is_alive():
return {"outcome": &"alive", "game_over": false, "slot_policy": SLOT_POLICY_ACTIVE}
var phylactery := _phylactery(inventory)
if phylactery != null:
inventory.remove_item(phylactery.instance_id)
combat_player.hit_points = maxi(1, int(float(combat_player.max_hit_points) * RESURRECTION_HP_FRACTION))
if narrative_player != null:
narrative_player.modify_attribute(&"end", -1)
narrative_player.flags[&"marked_by_death"] = true
return {
"outcome": &"resurrected",
"game_over": false,
"slot_policy": SLOT_POLICY_ACTIVE,
"item_id": NARRATIVE_PHYLACTERY_ID,
"hit_points": combat_player.hit_points,
"message": "Le phylactère se brise en poussière. Vous respirez de nouveau, marqué par la mort (-1 Endurance permanent).",
}
var outcome: StringName = &"permadeath" if permadeath else &"classic_death"
return {
"outcome": outcome,
"game_over": true,
"slot_policy": SLOT_POLICY_RETIRE if permadeath else SLOT_POLICY_PRESERVE,
"message": "Vous vous effondrez. Le donjon continue sans vous.",
}
func _phylactery(inventory: InventoryState) -> ItemInstance:
if inventory == null:
return null
for item: ItemInstance in inventory.items:
if item.definition.id == NARRATIVE_PHYLACTERY_ID:
return item
return null
+1
View File
@@ -0,0 +1 @@
uid://op1djmwb15ua
+5
View File
@@ -34,6 +34,11 @@ var recap_state: Dictionary = {}
# independently from panels and current FloorDeadline instances.
var faction_war_state: Dictionary = {}
var moderation_state: Dictionary = {}
# F6 owns final run lifecycle state. G1's save repository can later consume the
# explicit slot policy rather than inferring it from a transient death panel.
var is_game_over := false
var death_outcome: StringName = &""
var slot_policy: StringName = &"active"
func _init(new_seed: String, new_settings: RunSettings = null) -> void:
settings = new_settings if new_settings != null else RunSettings.new(new_seed)
+37
View File
@@ -49,6 +49,8 @@ const ModerationType = preload("res://scripts/domain/meta/moderation.gd")
const SyndicateType = preload("res://scripts/domain/meta/syndicate.gd")
const FactionPanelType = preload("res://scripts/presentation/faction_panel.gd")
const ModerationPanelType = preload("res://scripts/presentation/moderation_panel.gd")
const DeathEngineType = preload("res://scripts/domain/run/death_engine.gd")
const DeathPanelType = preload("res://scripts/presentation/death_panel.gd")
@onready var event_presenter: EventPresenter = $EventPresenter
@onready var map_renderer: MapRenderer = $World/MapRenderer
@onready var player_view: ActorView = $World/Player
@@ -73,6 +75,7 @@ const ModerationPanelType = preload("res://scripts/presentation/moderation_panel
@onready var recap_panel: RecapPanel = $HUD/RecapPanel
@onready var faction_panel: FactionPanel = $HUD/FactionPanel
@onready var moderation_panel: ModerationPanel = $HUD/ModerationPanel
@onready var death_panel: DeathPanel = $HUD/DeathPanel
@onready var achievement_toast: Label = $HUD/AchievementToast
@onready var title_label: Label = $HUD/TitleLabel
@onready var companion_view: ActorView = $World/Companion
@@ -108,6 +111,7 @@ var audience_state: AudienceState
var recap_log: RecapLog
var faction_war: FactionWar
var moderation: Moderation
var death_engine: DeathEngine
var active_dialogue_npc: Dictionary = {}
var active_event_index := -1
@@ -168,6 +172,7 @@ func _initialize_run_state() -> void:
recap_log = RecapLogType.new(run_state.recap_state)
faction_war = FactionWarType.new(spell_catalog, run_state.faction_war_state)
moderation = ModerationType.new(run_state.moderation_state)
death_engine = DeathEngineType.new()
_refresh_title()
# The existing base-archetype menu is now the mandatory class choice. Race
# defaults to the neutral human until the creation UI submits its selection.
@@ -236,6 +241,9 @@ func _prepare_exit_capture_state() -> void:
_sync_camera_to_player()
func _unhandled_input(event: InputEvent) -> void:
if run_state != null and run_state.is_game_over:
get_viewport().set_input_as_handled()
return
if faction_panel.visible and event is InputEventKey and event.is_pressed():
if event.keycode == KEY_ESCAPE or event.is_action_pressed(&"factions"):
_close_faction_panel()
@@ -454,6 +462,9 @@ func equip_test_ranged_weapon(definition: Dictionary, ammunition: int) -> void:
game_state.player.equip_ranged_weapon(definition, ammunition)
func submit_player_action(action: PlayerAction) -> Array[GameEvent]:
if run_state.is_game_over:
last_turn_results = []
return []
match action.kind:
&"move":
last_turn_results = _process_action(action.direction)
@@ -1413,6 +1424,7 @@ func _resolve_player_action(results: Array[TurnResult], sync_camera: bool) -> Ar
_sync_camera_to_player()
_dispatch_audio(results)
var events := _record_events(results)
_resolve_player_death_if_needed()
_append_level_up_events(events)
_observe_achievements(events)
_observe_audience(events)
@@ -1436,6 +1448,31 @@ func _resolve_player_action(results: Array[TurnResult], sync_camera: bool) -> Ar
hud.refresh(game_state, run_state.recent_events(run_state.log.size()), run_state)
return results
func _resolve_player_death_if_needed() -> void:
if game_state.player.is_alive() or run_state.is_game_over:
return
var outcome := death_engine.resolve(game_state.player, dialogue_player, run_state.inventory, run_state.settings.permadeath)
var kind: StringName = &"narrative_resurrection" if outcome.outcome == &"resurrected" else (&"permadeath_run_retired" if outcome.outcome == &"permadeath" else &"run_ended")
run_state.is_game_over = bool(outcome.game_over)
run_state.death_outcome = outcome.outcome
run_state.slot_policy = outcome.slot_policy
run_state.append_events([GameEventType.new(
run_state.current_turn,
run_state.current_floor,
kind,
{"outcome": outcome.outcome, "slot_policy": outcome.slot_policy, "item_id": outcome.get("item_id", &"")},
String(outcome.message),
game_state.player.id,
&"",
game_state.player.cell
)])
if run_state.is_game_over:
death_panel.present(run_state.death_outcome, run_state.player_name, run_state.current_floor, game_state.player.progression.level)
else:
# The narrative model owns permanent attributes. The prototype combat actor
# has no primary-attribute model, so preserve its combat max HP and resume.
player_view.refresh()
func _observe_achievements(events: Array[GameEvent]) -> void:
if achievement_manager == null:
return
+12
View File
@@ -0,0 +1,12 @@
class_name DeathPanel
extends PanelContainer
@onready var body: RichTextLabel = $Body
func present(outcome: StringName, player_name: String, floor: int, level: int) -> void:
visible = true
var mode := "Mort permanente : la sauvegarde de cette run est retirée." if outcome == &"permadeath" else "Classique : la sauvegarde de cette run reste disponible."
body.text = "%s n'aura pas survécu au donjon.\n\nNiveau atteint : %d Étage : %d\n\n%s\n\nLe donjon, lui, continuera sans vous." % [player_name, level, floor, mode]
func dismiss() -> void:
visible = false
+1
View File
@@ -0,0 +1 @@
uid://d2v3qwtooihs5