feat: complete playtest parity improvements
This commit is contained in:
+248
-59
@@ -2,8 +2,10 @@ class_name Game
|
||||
extends Node2D
|
||||
|
||||
signal game_started(settings: RunSettings, run_state: RunState)
|
||||
signal death_navigation_requested(action: StringName)
|
||||
signal save_requested
|
||||
|
||||
const REFERENCE_VIEWPORT := Vector2i(1280, 720)
|
||||
const REFERENCE_VIEWPORT := Vector2i(1920, 1080)
|
||||
const TILE_SIZE := Vector2i(32, 32)
|
||||
const GridMapStateType = preload("res://scripts/domain/grid_map_state.gd")
|
||||
const ActorStateType = preload("res://scripts/domain/actor_state.gd")
|
||||
@@ -22,6 +24,8 @@ const SpellStateType = preload("res://scripts/domain/magic/spell_state.gd")
|
||||
const TrapEngine = preload("res://scripts/domain/world/trap_engine.gd")
|
||||
const ItemDefinitionType = preload("res://scripts/domain/items/item_definition.gd")
|
||||
const ItemInstanceType = preload("res://scripts/domain/items/item_instance.gd")
|
||||
const LootResolverType = preload("res://scripts/domain/items/loot_resolver.gd")
|
||||
const TemporaryPlaytestKitType = preload("res://scripts/game/temporary_playtest_kit.gd")
|
||||
const InventoryPanelType = preload("res://scripts/presentation/inventory_panel.gd")
|
||||
const EconomyType = preload("res://scripts/domain/items/economy.gd")
|
||||
const CraftingEngineType = preload("res://scripts/domain/items/crafting_engine.gd")
|
||||
@@ -50,6 +54,7 @@ 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 HealthRegenerationType = preload("res://scripts/domain/combat/health_regeneration.gd")
|
||||
const TouristServiceType = preload("res://scripts/domain/world/tourist_service.gd")
|
||||
const DeathPanelType = preload("res://scripts/presentation/death_panel.gd")
|
||||
const VictoryPanelType = preload("res://scripts/presentation/victory_panel.gd")
|
||||
@@ -75,6 +80,7 @@ const QuestStateType = preload("res://scripts/domain/narrative/quest_state.gd")
|
||||
@onready var party_panel: PartyPanel = $HUD/PartyPanel
|
||||
@onready var character_panel: CharacterPanel = $HUD/CharacterPanel
|
||||
@onready var progression_choice_panel: ProgressionChoicePanel = $HUD/ProgressionChoicePanel
|
||||
@onready var race_class_choice_panel: RaceClassChoicePanel = $HUD/RaceClassChoicePanel
|
||||
@onready var achievement_panel: AchievementPanel = $HUD/AchievementPanel
|
||||
@onready var audience_panel: AudiencePanel = $HUD/AudiencePanel
|
||||
@onready var recap_panel: RecapPanel = $HUD/RecapPanel
|
||||
@@ -102,8 +108,8 @@ var last_turn_results: Array[TurnResult] = []
|
||||
var action_router: ActionRouter
|
||||
var pending_run_settings: RunSettings
|
||||
var pending_player_name := "Sans-Nom"
|
||||
var pending_base_archetype: StringName = &"vanguard"
|
||||
var pending_race: StringName = &"race_humain_standard"
|
||||
var pending_base_archetype: StringName = &""
|
||||
var pending_race: StringName = &""
|
||||
var pending_loaded_run: Dictionary = {}
|
||||
var floor_transition: FloorTransition
|
||||
var spell_catalog: ContentCatalog
|
||||
@@ -124,12 +130,14 @@ var moderation: Moderation
|
||||
var death_engine: DeathEngine
|
||||
var active_dialogue_npc: Dictionary = {}
|
||||
var active_event_index := -1
|
||||
var _turn_start_player_hit_points := -1
|
||||
var _turn_start_companion_hit_points := -1
|
||||
|
||||
func configure_new_run(settings: RunSettings, player_name: String, base_archetype: StringName, race: StringName = &"race_humain_standard") -> void:
|
||||
func configure_new_run(settings: RunSettings, player_name: String) -> void:
|
||||
pending_run_settings = settings
|
||||
pending_player_name = player_name
|
||||
pending_base_archetype = base_archetype
|
||||
pending_race = race
|
||||
pending_base_archetype = &""
|
||||
pending_race = &""
|
||||
|
||||
func configure_loaded_run(loaded: Dictionary) -> void:
|
||||
pending_loaded_run = loaded
|
||||
@@ -147,6 +155,9 @@ func _ready() -> void:
|
||||
spell_targeting_overlay.target_selected.connect(_on_spell_target_selected)
|
||||
spell_targeting_overlay.targeting_cancelled.connect(_cancel_spell_targeting)
|
||||
progression_choice_panel.choice_confirmed.connect(_choose_level_three_perk)
|
||||
race_class_choice_panel.race_confirmed.connect(_choose_floor_three_race)
|
||||
race_class_choice_panel.class_confirmed.connect(_choose_floor_three_class)
|
||||
death_panel.navigation_requested.connect(func(action: StringName) -> void: death_navigation_requested.emit(action))
|
||||
map_renderer.set_map(game_state.map)
|
||||
_sync_map_renderer_visibility()
|
||||
_sync_minimap()
|
||||
@@ -175,6 +186,8 @@ func _initialize_run_state() -> void:
|
||||
run_state.base_archetype = pending_base_archetype
|
||||
spell_catalog = ContentCatalogType.load_from_directory("res://data/ascii")
|
||||
run_state.content_catalog = spell_catalog
|
||||
if pending_run_settings != null:
|
||||
_initialize_tutorial_kit()
|
||||
crafting_engine = CraftingEngineType.new(spell_catalog)
|
||||
dialogue_engine = DialogueEngineType.new()
|
||||
event_engine = EventEngineType.new()
|
||||
@@ -191,20 +204,24 @@ func _initialize_run_state() -> void:
|
||||
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.
|
||||
# Preserve the no-class initial state used by dialogue gates in existing runs;
|
||||
# menu creation assigns its explicit base class immediately after launch.
|
||||
if pending_run_settings != null:
|
||||
class_engine.apply_creation(dialogue_player, pending_race, run_state.base_archetype)
|
||||
# New runs deliberately remain classless and raceless through dungeon floors
|
||||
# one and two. The floor-three milestone applies both choices later.
|
||||
game_state.content_catalog = spell_catalog
|
||||
spell_state = SpellStateType.new([&"spell_epines_empoisonnees"])
|
||||
floor_transition = FloorTransitionType.new(spell_catalog)
|
||||
var initial_floor := floor_transition.initial_floor(run_state)
|
||||
if pending_run_settings != null:
|
||||
TemporaryPlaytestKitType.apply_to_new_run(initial_floor)
|
||||
game_state.set_floor_state(initial_floor)
|
||||
game_state.player.cell = initial_floor.entrance
|
||||
# Direct Game-scene instantiation is the established automated-test seam.
|
||||
# Production runs are always configured by MainMenu and keep the reference
|
||||
# surface empty; the seam retains one deterministic actor for combat tests.
|
||||
if pending_loaded_run.is_empty() and _is_automated_test_run():
|
||||
game_state.enemies[&"goblin"] = ActorStateType.new(&"goblin", initial_floor.entrance + Vector2i(3, 0), 6, 2)
|
||||
game_state.update_exploration()
|
||||
if settings.pet_enabled:
|
||||
game_state.companion = CompanionStateType.from_choice(&"moth", initial_floor.entrance + Vector2i.RIGHT)
|
||||
game_state.companion = CompanionStateType.from_choice(&"moth", initial_floor.entrance + Vector2i.RIGHT, 8, settings.pet_name, settings.pet_species)
|
||||
if pending_run_settings != null:
|
||||
var game_started := GameEventType.new(
|
||||
run_state.next_turn(),
|
||||
@@ -215,8 +232,11 @@ func _initialize_run_state() -> void:
|
||||
"difficulty_id": settings.difficulty_id,
|
||||
"permadeath": settings.permadeath,
|
||||
"pet_enabled": settings.pet_enabled,
|
||||
"pet_name": settings.pet_name if settings.pet_enabled else "",
|
||||
"pet_species": settings.pet_species if settings.pet_enabled else "",
|
||||
"player_name": run_state.player_name,
|
||||
"base_archetype": run_state.base_archetype,
|
||||
"race": dialogue_player.race,
|
||||
},
|
||||
"%s begins a new run." % run_state.player_name,
|
||||
&"player",
|
||||
@@ -226,6 +246,17 @@ func _initialize_run_state() -> void:
|
||||
run_state.append_events([game_started])
|
||||
_observe_achievements([game_started])
|
||||
|
||||
func _initialize_tutorial_kit() -> void:
|
||||
# Floors one and two use DCWASCII's class-neutral kit so combat is explicit
|
||||
# and playable without pre-empting the floor-three class choice.
|
||||
run_state.gold = 15
|
||||
var knife := ItemInstanceType.new(ItemDefinitionType.from_catalog(spell_catalog, &"weapon_hunting_knife"), 1, &"tutorial-knife")
|
||||
var bandage := ItemInstanceType.new(ItemDefinitionType.from_catalog(spell_catalog, &"consumable_bandage"), 1, &"tutorial-bandage")
|
||||
run_state.inventory.add_item(knife)
|
||||
run_state.inventory.add_item(bandage)
|
||||
run_state.equipment.equip(run_state.inventory, knife.instance_id, game_state.player, run_state.identification)
|
||||
_sync_player_equipment()
|
||||
|
||||
func _apply_loaded_run(loaded: Dictionary) -> void:
|
||||
run_state = loaded.get("run_state")
|
||||
game_state = loaded.get("game_state")
|
||||
@@ -258,6 +289,15 @@ func _apply_loaded_run(loaded: Dictionary) -> void:
|
||||
game_state.update_exploration()
|
||||
_refresh_title()
|
||||
|
||||
func _is_automated_test_run() -> bool:
|
||||
var arguments := OS.get_cmdline_args() + OS.get_cmdline_user_args()
|
||||
if "--test-mode" in arguments:
|
||||
return true
|
||||
for argument in arguments:
|
||||
if argument.begins_with("-g"):
|
||||
return true
|
||||
return false
|
||||
|
||||
func _get_capture_mode() -> String:
|
||||
var arguments := OS.get_cmdline_user_args()
|
||||
if "--capture-exit" in arguments:
|
||||
@@ -280,16 +320,42 @@ func _capture_visual_check(capture_mode: String) -> void:
|
||||
get_tree().quit(0 if result == OK else 1)
|
||||
|
||||
func _prepare_exit_capture_state() -> void:
|
||||
game_state.map.set_cell(Vector2i(4, 10), GridMapStateType.CellKind.FLOOR)
|
||||
game_state.map.set_cell(Vector2i(4, 7), GridMapStateType.CellKind.FLOOR)
|
||||
game_state.player.cell = Vector2i(18, 4)
|
||||
# The exit capture represents a reached stair route; make the B6 gate
|
||||
# eligible so the visual fixture remains valid without weakening gameplay.
|
||||
run_state.current_floor_deadline().turns_remaining = FloorDeadline.STAIRS_OPEN_DAYS_BEFORE_COLLAPSE * FloorDeadline.TURNS_PER_DAY
|
||||
_process_interact()
|
||||
# Preserve the entrance exploration, then frame the authored surface exit.
|
||||
# This exercises visible, explored, and unknown rendering without depending
|
||||
# on the removed prototype-map coordinates.
|
||||
game_state.map.set_cell(Vector2i(36, 7), GridMapStateType.CellKind.FLOOR)
|
||||
game_state.player.cell = game_state.floor_state.exit
|
||||
game_state.update_exploration()
|
||||
_sync_map_renderer_visibility()
|
||||
_sync_minimap()
|
||||
player_view.refresh()
|
||||
_sync_camera_to_player()
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
# Movement and wait commands belong to gameplay even if a previously opened
|
||||
# Control retained keyboard focus. Handle them before focused UI consumes the
|
||||
# arrow event; modal panels still own navigation and are handled below.
|
||||
if event is InputEventKey and event.is_pressed() and not event.echo and not _has_modal_panel_open():
|
||||
var physical_direction := _physical_movement_direction(event as InputEventKey)
|
||||
if physical_direction != Vector2i.ZERO:
|
||||
action_router.submit(PlayerActionType.new(&"move", physical_direction))
|
||||
get_viewport().set_input_as_handled()
|
||||
|
||||
func _has_modal_panel_open() -> bool:
|
||||
return options_panel.visible or help_panel.visible or faction_panel.visible or moderation_panel.visible or audience_panel.visible or recap_panel.visible or achievement_panel.visible or race_class_choice_panel.visible or progression_choice_panel.visible or character_panel.visible or party_panel.visible or companion_panel.visible or quest_panel.visible or event_panel.visible or dialogue_panel.visible or crafting_panel.visible or shop_panel.visible or inventory_panel.visible or loot_panel.visible or targeting_overlay.visible or spell_targeting_overlay.visible
|
||||
|
||||
func _physical_movement_direction(event: InputEventKey) -> Vector2i:
|
||||
match event.physical_keycode:
|
||||
KEY_UP: return Vector2i.UP
|
||||
KEY_DOWN: return Vector2i.DOWN
|
||||
KEY_LEFT: return Vector2i.LEFT
|
||||
KEY_RIGHT: return Vector2i.RIGHT
|
||||
return Vector2i.ZERO
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event is InputEventKey and event.echo:
|
||||
get_viewport().set_input_as_handled()
|
||||
return
|
||||
if run_state != null and run_state.is_game_over:
|
||||
get_viewport().set_input_as_handled()
|
||||
return
|
||||
@@ -347,6 +413,15 @@ func _unhandled_input(event: InputEvent) -> void:
|
||||
return
|
||||
get_viewport().set_input_as_handled()
|
||||
return
|
||||
if race_class_choice_panel.visible and event is InputEventKey and event.is_pressed():
|
||||
if event.keycode == KEY_UP:
|
||||
race_class_choice_panel.select_next(-1)
|
||||
elif event.keycode == KEY_DOWN:
|
||||
race_class_choice_panel.select_next(1)
|
||||
elif event.keycode == KEY_ENTER or event.keycode == KEY_SPACE:
|
||||
race_class_choice_panel.confirm()
|
||||
get_viewport().set_input_as_handled()
|
||||
return
|
||||
if progression_choice_panel.visible and event is InputEventKey and event.is_pressed():
|
||||
if event.keycode == KEY_UP:
|
||||
progression_choice_panel.select_next(-1)
|
||||
@@ -535,9 +610,11 @@ 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:
|
||||
if run_state.is_game_over or race_class_choice_panel.visible:
|
||||
last_turn_results = []
|
||||
return []
|
||||
_turn_start_player_hit_points = game_state.player.hit_points
|
||||
_turn_start_companion_hit_points = game_state.companion.actor.hit_points if game_state.companion != null else -1
|
||||
match action.kind:
|
||||
&"move":
|
||||
last_turn_results = _process_action(action.direction)
|
||||
@@ -597,6 +674,10 @@ func submit_player_action(action: PlayerAction) -> Array[GameEvent]:
|
||||
last_turn_results = []
|
||||
hud.toggle_log()
|
||||
return []
|
||||
&"save":
|
||||
last_turn_results = []
|
||||
save_requested.emit()
|
||||
return []
|
||||
&"ranged":
|
||||
return _begin_targeting()
|
||||
&"ranged_target":
|
||||
@@ -609,24 +690,25 @@ func submit_player_action(action: PlayerAction) -> Array[GameEvent]:
|
||||
return _record_unavailable_action(action)
|
||||
|
||||
func _begin_targeting() -> Array[GameEvent]:
|
||||
if game_state.player.ranged_weapon.is_empty():
|
||||
return _record_non_turn_event(&"invalid_ranged_target", &"", {"reason": &"no_ranged_weapon", "damage": 0}, "Aucune arme à distance n’est équipée.")
|
||||
var targets: Dictionary[StringName, Vector2i] = {}
|
||||
var ranged_combat := RangedCombatType.new()
|
||||
for enemy_id: StringName in game_state.enemies:
|
||||
var enemy: ActorState = game_state.enemies[enemy_id]
|
||||
if enemy.is_alive():
|
||||
if enemy.is_alive() and ranged_combat.validation_reason(game_state.map, game_state.player, enemy).is_empty():
|
||||
targets[enemy_id] = enemy.cell
|
||||
if game_state.player.ranged_weapon.is_empty():
|
||||
return _record_ranged_event(&"invalid_ranged_target", &"", {"reason": &"no_ranged_weapon", "damage": 0}, "No ranged weapon is equipped.")
|
||||
if targets.is_empty():
|
||||
return _record_ranged_event(&"invalid_ranged_target", &"", {"reason": &"invalid_target", "damage": 0}, "No valid ranged target.")
|
||||
return _record_non_turn_event(&"invalid_ranged_target", &"", {"reason": &"invalid_target", "damage": 0}, "Aucune cible valide à portée et en ligne de vue.")
|
||||
targeting_overlay.begin(targets)
|
||||
return _record_ranged_event(&"targeting_started", &"", {"target_ids": targeting_overlay.get_target_ids()}, "Choose a ranged target.")
|
||||
return _record_non_turn_event(&"targeting_started", &"", {"target_ids": targeting_overlay.get_target_ids()}, "Choisissez une cible à distance.")
|
||||
|
||||
func _on_target_selected(target_id: StringName) -> void:
|
||||
action_router.submit(PlayerActionType.new(&"ranged_target", Vector2i.ZERO, target_id))
|
||||
|
||||
func _cancel_targeting() -> void:
|
||||
targeting_overlay.finish()
|
||||
_record_ranged_event(&"targeting_cancelled", &"", {}, "Ranged targeting cancelled.")
|
||||
_record_non_turn_event(&"targeting_cancelled", &"", {}, "Ciblage à distance annulé.")
|
||||
|
||||
func _begin_spell_targeting() -> Array[GameEvent]:
|
||||
var available: Array[StringName] = []
|
||||
@@ -707,6 +789,15 @@ func _process_ranged_target(target_id: StringName) -> Array[TurnResult]:
|
||||
TurnResolver.append_enemy_response(game_state, results)
|
||||
return _resolve_player_action(results, true)
|
||||
|
||||
func _record_non_turn_event(kind: StringName, target_id: StringName, payload: Dictionary, message: String) -> Array[GameEvent]:
|
||||
var event := GameEventType.new(run_state.current_turn, run_state.current_floor, kind, payload, message, &"player", target_id, game_state.player.cell)
|
||||
var events: Array[GameEvent] = [event]
|
||||
run_state.append_events(events)
|
||||
event_presenter.enqueue(events)
|
||||
event_presenter.present_next()
|
||||
hud.refresh(game_state, run_state.recent_events(run_state.log.size()), run_state)
|
||||
return events
|
||||
|
||||
func _record_ranged_event(kind: StringName, target_id: StringName, payload: Dictionary, message: String) -> Array[GameEvent]:
|
||||
var event := GameEventType.new(run_state.next_turn(), run_state.current_floor, kind, payload, message, &"player", target_id, game_state.player.cell)
|
||||
var events: Array[GameEvent] = [event]
|
||||
@@ -796,7 +887,7 @@ func _process_interact() -> Array[TurnResult]:
|
||||
# behavior and are deliberately not used as item sources in this slice.
|
||||
if game_state.floor_state.ground_items.has(game_state.player.cell):
|
||||
return _process_ground_pickup()
|
||||
if _is_down_stairs() and not run_state.current_floor_deadline().can_descend():
|
||||
if _is_down_stairs() and run_state.current_floor > 0 and not run_state.current_floor_deadline().can_descend():
|
||||
var deadline := run_state.current_floor_deadline()
|
||||
var blocked := _deadline_result(
|
||||
&"stairs_refused",
|
||||
@@ -1369,6 +1460,7 @@ func _use_selected_inventory_item(target = null) -> void:
|
||||
return
|
||||
var result := run_state.inventory.use_item(item.instance_id, game_state.player, run_state.identification, target)
|
||||
if bool(result.accepted):
|
||||
_apply_item_use_effects(result.effects)
|
||||
_record_ranged_event(&"item_used", &"", {"instance_id": item.instance_id, "effects": result.effects, "revealed": result.revealed}, "Used %s." % item.definition.name)
|
||||
elif result.reason == &"target_required":
|
||||
_record_ranged_event(&"item_targeting_started", &"", {"instance_id": item.instance_id, "target_kind": &"ally"}, "Choose an ally target for %s." % item.definition.name)
|
||||
@@ -1376,6 +1468,11 @@ func _use_selected_inventory_item(target = null) -> void:
|
||||
_record_ranged_event(&"item_use_refused", &"", {"instance_id": item.instance_id, "reason": result.reason}, "Cannot use that item.")
|
||||
inventory_panel.refresh()
|
||||
|
||||
func _apply_item_use_effects(effects: Array) -> void:
|
||||
for effect: Dictionary in effects:
|
||||
if StringName(effect.get("type", "")) == &"learn_spell":
|
||||
spell_state.learn(StringName(effect.get("spell", "")))
|
||||
|
||||
# Public hook for the future party selector: it applies the currently selected
|
||||
# ally-target consumable without coupling this D3 slice to a party UI.
|
||||
func submit_inventory_ally_target(target) -> Array[GameEvent]:
|
||||
@@ -1422,15 +1519,19 @@ func _take_all_loot() -> void:
|
||||
else:
|
||||
refused_items.append({"item_id": StringName(item_data.get("item_id", "")), "quantity": int(item_data.get("quantity", 1)), "reason": result.reason})
|
||||
var gold := int(pending_loot.get("gold", 0))
|
||||
var ammunition := maxi(0, int(pending_loot.get("ammunition", 0)))
|
||||
run_state.gold += gold
|
||||
game_state.player.ammunition += ammunition
|
||||
loot_panel.dismiss()
|
||||
var message := "Butin récupéré"
|
||||
if gold > 0:
|
||||
message += " : +%d or" % gold
|
||||
if ammunition > 0:
|
||||
message += " : +%d munitions" % ammunition
|
||||
if not refused_items.is_empty():
|
||||
message += " (inventaire plein pour certains objets)"
|
||||
message += "."
|
||||
_record_ranged_event(&"loot_taken", &"", {"items": accepted_items, "gold": gold, "refused_items": refused_items}, message)
|
||||
_record_ranged_event(&"loot_taken", &"", {"items": accepted_items, "gold": gold, "ammunition": ammunition, "refused_items": refused_items}, message)
|
||||
pending_loot.clear()
|
||||
|
||||
func _process_rest() -> Array[TurnResult]:
|
||||
@@ -1494,14 +1595,59 @@ func _transition_floor(stairs_cell: Vector2i) -> void:
|
||||
game_state.set_floor_state(destination)
|
||||
game_state.content_catalog = spell_catalog
|
||||
game_state.player.cell = transition["arrival"]
|
||||
_place_companion_near_player()
|
||||
game_state.update_exploration()
|
||||
map_renderer.set_map(game_state.map)
|
||||
_sync_map_renderer_visibility()
|
||||
_sync_minimap()
|
||||
player_view.set_actor(game_state.player)
|
||||
_sync_camera_to_player()
|
||||
# Camera bounds are map-specific. Recompute them before positioning the
|
||||
# camera whenever a floor transition swaps the active map dimensions.
|
||||
_configure_camera()
|
||||
_sync_enemy_views()
|
||||
hud.refresh(game_state, run_state.recent_events(run_state.log.size()), run_state)
|
||||
_check_floor_three_race_class_milestone()
|
||||
|
||||
func _place_companion_near_player() -> void:
|
||||
if game_state.companion == null or not game_state.companion.is_alive():
|
||||
return
|
||||
var occupied: Dictionary[Vector2i, bool] = {game_state.player.cell: true}
|
||||
for enemy: ActorState in game_state.enemies.values():
|
||||
if enemy.is_alive():
|
||||
occupied[enemy.cell] = true
|
||||
for member: ActorState in game_state.party.living_members():
|
||||
occupied[member.cell] = true
|
||||
for direction: Vector2i in [Vector2i.LEFT, Vector2i.DOWN, Vector2i.RIGHT, Vector2i.UP]:
|
||||
var candidate := game_state.player.cell + direction
|
||||
if game_state.map.is_walkable(candidate) and not occupied.has(candidate):
|
||||
game_state.companion.actor.cell = candidate
|
||||
return
|
||||
|
||||
func _check_floor_three_race_class_milestone() -> void:
|
||||
if run_state.current_floor != 3 or (not dialogue_player.race.is_empty() and not dialogue_player.archetype.is_empty()):
|
||||
return
|
||||
race_class_choice_panel.present_races(class_engine.race_definitions())
|
||||
_record_ranged_event(
|
||||
&"race_class_choice_required",
|
||||
&"",
|
||||
{"floor": run_state.current_floor},
|
||||
"Niveau 3 du Donjon : choisissez votre race, puis votre classe."
|
||||
)
|
||||
|
||||
func _choose_floor_three_race(race_id: StringName) -> void:
|
||||
var result := class_engine.choose_race(dialogue_player, race_id)
|
||||
if not bool(result.get("accepted", false)):
|
||||
return
|
||||
_record_ranged_event(&"race_chosen", race_id, {}, "Race choisie : %s." % race_id)
|
||||
race_class_choice_panel.present_classes(class_engine.class_definitions(dialogue_player.race))
|
||||
|
||||
func _choose_floor_three_class(class_id: StringName) -> void:
|
||||
var result := class_engine.choose_class(dialogue_player, class_id)
|
||||
if not bool(result.get("accepted", false)):
|
||||
return
|
||||
run_state.base_archetype = dialogue_player.archetype
|
||||
race_class_choice_panel.dismiss()
|
||||
_record_ranged_event(&"class_chosen", class_id, {}, "Classe choisie : %s." % class_id)
|
||||
|
||||
func _process_action(direction: Vector2i) -> Array[TurnResult]:
|
||||
var results := game_state.try_player_action(direction)
|
||||
@@ -1532,14 +1678,18 @@ func _append_collapse_damage(results: Array[TurnResult]) -> void:
|
||||
# journal: results from one resolved player action are converted and appended once,
|
||||
# and every resulting GameEvent shares that action's turn number.
|
||||
func _resolve_player_action(results: Array[TurnResult], sync_camera: bool) -> Array[TurnResult]:
|
||||
if _results_consume_turn(results):
|
||||
_apply_passive_health_regeneration(results)
|
||||
_sync_map_renderer_visibility()
|
||||
_sync_minimap()
|
||||
player_view.refresh()
|
||||
_sync_companion_view()
|
||||
_sync_party_views()
|
||||
_sync_enemy_views()
|
||||
if sync_camera:
|
||||
_sync_camera_to_player()
|
||||
_dispatch_audio(results)
|
||||
_resolve_enemy_loot(results)
|
||||
var events := _record_events(results)
|
||||
_resolve_player_death_if_needed()
|
||||
_append_level_up_events(events)
|
||||
@@ -1565,6 +1715,39 @@ 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 _results_consume_turn(results: Array[TurnResult]) -> bool:
|
||||
if results.is_empty():
|
||||
return false
|
||||
return not results.all(func(result: TurnResult) -> bool:
|
||||
return result.kind in [&"blocked", &"nothing_to_interact", &"rest_refused", &"stairs_refused"]
|
||||
)
|
||||
|
||||
func _apply_passive_health_regeneration(results: Array[TurnResult]) -> void:
|
||||
_sync_dialogue_player_progression()
|
||||
var player_took_damage := (_turn_start_player_hit_points >= 0 and game_state.player.hit_points < _turn_start_player_hit_points) or results.any(func(result: TurnResult) -> bool:
|
||||
return result.damage > 0 and (result.target_id == game_state.player.id or result.kind == &"collapse_damage")
|
||||
)
|
||||
var perk_bonus := int(perk_engine.modifiers().get("regen_bonus", 0)) if perk_engine != null else 0
|
||||
if not player_took_damage:
|
||||
HealthRegenerationType.apply(
|
||||
game_state.player,
|
||||
dialogue_player.effective_attribute(&"end"),
|
||||
dialogue_player.effective_skill(&"regeneration"),
|
||||
perk_bonus,
|
||||
run_state.settings.difficulty_id
|
||||
)
|
||||
var companion_took_damage := game_state.companion != null and ((_turn_start_companion_hit_points >= 0 and game_state.companion.actor.hit_points < _turn_start_companion_hit_points) or results.any(func(result: TurnResult) -> bool:
|
||||
return result.damage > 0 and result.target_id == game_state.companion.actor.id
|
||||
))
|
||||
if game_state.companion != null and game_state.companion.is_alive() and not companion_took_damage:
|
||||
HealthRegenerationType.apply(
|
||||
game_state.companion.actor,
|
||||
game_state.companion.endurance,
|
||||
game_state.companion.regeneration_skill,
|
||||
game_state.companion.regeneration_perk_bonus,
|
||||
run_state.settings.difficulty_id
|
||||
)
|
||||
|
||||
func _resolve_player_death_if_needed() -> void:
|
||||
if game_state.player.is_alive() or run_state.is_game_over:
|
||||
return
|
||||
@@ -1708,6 +1891,30 @@ func _append_level_up_events(events: Array[GameEvent]) -> void:
|
||||
run_state.append_events([level_event])
|
||||
_check_progression_choices_and_evolutions()
|
||||
|
||||
func _resolve_enemy_loot(results: Array[TurnResult]) -> void:
|
||||
var resolved_enemy_ids: Dictionary[StringName, bool] = {}
|
||||
for result: TurnResult in results:
|
||||
var descriptors: Array = result.payload.get("domain_events", [])
|
||||
for descriptor: Dictionary in descriptors:
|
||||
if descriptor.kind != &"loot_dropped" or descriptor.actor_id == &"player" or resolved_enemy_ids.has(StringName(descriptor.actor_id)):
|
||||
continue
|
||||
resolved_enemy_ids[StringName(descriptor.actor_id)] = true
|
||||
var table_id := StringName(descriptor.payload.get("loot_table", ""))
|
||||
var table := spell_catalog.get_loot_table(table_id) if spell_catalog != null else {}
|
||||
var reward := LootResolverType.resolve(table, run_state.seed, "enemy:%d:%s" % [run_state.current_floor, descriptor.actor_id])
|
||||
reward["loot_table"] = table_id
|
||||
descriptor.payload = reward
|
||||
var drop_cell: Vector2i = result.to_cell
|
||||
for item_data: Dictionary in reward.items:
|
||||
var definition := ItemDefinitionType.from_catalog(spell_catalog, StringName(item_data.get("item_id", "")))
|
||||
if not definition.is_valid():
|
||||
continue
|
||||
if not game_state.floor_state.ground_items.has(drop_cell):
|
||||
game_state.floor_state.ground_items[drop_cell] = []
|
||||
game_state.floor_state.ground_items[drop_cell].append(ItemInstanceType.new(definition, int(item_data.get("quantity", 1))))
|
||||
run_state.gold += int(reward.gold)
|
||||
_sync_map_renderer_visibility()
|
||||
|
||||
func _record_events(results: Array[TurnResult]) -> Array[GameEvent]:
|
||||
var events: Array[GameEvent] = []
|
||||
if results.is_empty():
|
||||
@@ -1764,34 +1971,12 @@ func _get_actor_view(actor_id: StringName) -> ActorView:
|
||||
return enemy_views.get(actor_id) as ActorView
|
||||
|
||||
func _create_initial_state() -> GameState:
|
||||
var map := GridMapStateType.new(Vector2i(30, 20), GridMapStateType.CellKind.WALL)
|
||||
_carve_room(map, Rect2i(2, 12, 6, 5))
|
||||
_carve_room(map, Rect2i(2, 4, 7, 7))
|
||||
_carve_room(map, Rect2i(10, 2, 10, 6))
|
||||
_carve_room(map, Rect2i(21, 5, 7, 8))
|
||||
_carve_vertical_corridor(map, 4, 10, 12)
|
||||
_carve_horizontal_corridor(map, 8, 10, 6)
|
||||
_carve_horizontal_corridor(map, 18, 21, 6)
|
||||
_carve_vertical_corridor(map, 18, 4, 6)
|
||||
map.set_cell(Vector2i(4, 11), GridMapStateType.CellKind.CLOSED_DOOR)
|
||||
map.set_cell(Vector2i(4, 7), GridMapStateType.CellKind.CHEST)
|
||||
map.set_cell(Vector2i(18, 4), GridMapStateType.CellKind.STAIRS)
|
||||
var player := ActorStateType.new(&"player", Vector2i(4, 12), 12, 3)
|
||||
var goblin := ActorStateType.new(&"goblin", Vector2i(24, 8), 6, 2)
|
||||
return GameStateType.new(map, player, {&"goblin": goblin})
|
||||
|
||||
func _carve_room(map: GridMapState, room: Rect2i) -> void:
|
||||
for y in range(room.position.y, room.end.y):
|
||||
for x in range(room.position.x, room.end.x):
|
||||
map.set_cell(Vector2i(x, y), GridMapStateType.CellKind.FLOOR)
|
||||
|
||||
func _carve_horizontal_corridor(map: GridMapState, from_x: int, to_x: int, y: int) -> void:
|
||||
for x in range(from_x, to_x + 1):
|
||||
map.set_cell(Vector2i(x, y), GridMapStateType.CellKind.FLOOR)
|
||||
|
||||
func _carve_vertical_corridor(map: GridMapState, x: int, from_y: int, to_y: int) -> void:
|
||||
for y in range(from_y, to_y + 1):
|
||||
map.set_cell(Vector2i(x, y), GridMapStateType.CellKind.FLOOR)
|
||||
# Run initialization immediately replaces this neutral shell with the authored
|
||||
# surface. Keeping the shell content-free prevents the removed prototype map
|
||||
# from becoming an accidental gameplay source again.
|
||||
var map := GridMapStateType.new(Vector2i.ONE, GridMapStateType.CellKind.FLOOR)
|
||||
var player := ActorStateType.new(&"player", Vector2i.ZERO, 12, 3)
|
||||
return GameStateType.new(map, player, {})
|
||||
|
||||
func _configure_camera() -> void:
|
||||
var map_size := game_state.map.size * TILE_SIZE
|
||||
@@ -1863,4 +2048,8 @@ func _sync_enemy_views() -> void:
|
||||
view.texture = preload("res://assets/dcss/goblin.png")
|
||||
enemies.add_child(view)
|
||||
enemy_views[enemy_id] = view
|
||||
enemy_views[enemy_id].set_actor(game_state.enemies[enemy_id])
|
||||
var enemy: ActorState = game_state.enemies[enemy_id]
|
||||
enemy_views[enemy_id].set_actor(enemy)
|
||||
# Actor sprites must obey the same current-FOV contract as special map
|
||||
# markers. Explored memory never reveals a live enemy.
|
||||
enemy_views[enemy_id].visible = enemy.is_alive() and game_state.visible_cells.has(enemy.cell)
|
||||
|
||||
Reference in New Issue
Block a user