Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af3cda9eeb | ||
|
|
f17b5dd7c0 | ||
|
|
4b6521d308 | ||
|
|
4b9776ce20 | ||
|
|
484c91f4a6 | ||
|
|
fe13555778 | ||
|
|
4a3d2fc3ff | ||
|
|
e0798384a9 | ||
|
|
e8be817284 |
@@ -166,6 +166,18 @@ grow_vertical = 0
|
||||
theme_override_colors/font_color = Color(1, 0.9, 0.5, 1)
|
||||
theme_override_font_sizes/font_size = 16
|
||||
|
||||
[node name="DeadlineLabel" type="Label" parent="HUD"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 0
|
||||
offset_left = 26.0
|
||||
offset_top = 94.0
|
||||
offset_right = 360.0
|
||||
offset_bottom = 114.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 0
|
||||
theme_override_colors/font_color = Color(1, 0.76, 0.4, 1)
|
||||
theme_override_font_sizes/font_size = 14
|
||||
|
||||
[node name="EventLog" type="RichTextLabel" parent="HUD"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 1
|
||||
|
||||
@@ -7,12 +7,15 @@ var hit_points: int
|
||||
var max_hit_points: int
|
||||
var attack_damage: int
|
||||
|
||||
func _init(new_id: StringName, new_cell: Vector2i, new_hit_points: int, new_attack_damage: int) -> void:
|
||||
var content_id: StringName
|
||||
|
||||
func _init(new_id: StringName, new_cell: Vector2i, new_hit_points: int, new_attack_damage: int, new_content_id: StringName = &"") -> void:
|
||||
id = new_id
|
||||
cell = new_cell
|
||||
hit_points = new_hit_points
|
||||
max_hit_points = new_hit_points
|
||||
attack_damage = new_attack_damage
|
||||
content_id = new_content_id if not new_content_id.is_empty() else new_id
|
||||
|
||||
func is_alive() -> bool:
|
||||
return hit_points > 0
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
class_name ConditionEngine
|
||||
extends RefCounted
|
||||
|
||||
const StatusEffectType = preload("res://scripts/domain/combat/status_effect.gd")
|
||||
|
||||
var diagnostics := PackedStringArray()
|
||||
|
||||
func evaluate(condition: Dictionary, context: Dictionary) -> bool:
|
||||
if condition.is_empty():
|
||||
return true
|
||||
var kind := StringName(condition.get("type", ""))
|
||||
var player: PlayerState = context.get("player")
|
||||
if player == null:
|
||||
_diagnose("Condition requires a player: %s" % kind)
|
||||
return false
|
||||
match kind:
|
||||
&"skill":
|
||||
return player.effective_skill(StringName(condition.get("skill", ""))) >= int(condition.get("min", 0))
|
||||
&"attr":
|
||||
return player.effective_attribute(StringName(condition.get("attr", ""))) >= int(condition.get("min", 0))
|
||||
&"level":
|
||||
return player.level >= int(condition.get("min", 1))
|
||||
&"flag":
|
||||
return player.flags.get(StringName(condition.get("flag", "")), false) == condition.get("equals", true)
|
||||
&"reputation":
|
||||
return player.reputation.get(StringName(condition.get("faction", "")), 0) >= int(condition.get("min", 0))
|
||||
&"archetype":
|
||||
if condition.has("is_set"):
|
||||
return (not player.archetype.is_empty()) == bool(condition["is_set"])
|
||||
return player.archetype == StringName(condition.get("value", ""))
|
||||
&"has_race":
|
||||
if condition.has("is_set"):
|
||||
return (not player.race.is_empty()) == bool(condition["is_set"])
|
||||
return player.race == StringName(condition.get("value", ""))
|
||||
&"payload_flag":
|
||||
return _payload(context).get(StringName(condition.get("key", "")), false) == condition.get("equals", true)
|
||||
&"payload_equals":
|
||||
return _payload(context).get(StringName(condition.get("key", ""))) == condition.get("value")
|
||||
&"payload_min":
|
||||
return float(_payload(context).get(StringName(condition.get("key", "")), 0)) >= float(condition.get("min", 0))
|
||||
&"payload_max":
|
||||
return float(_payload(context).get(StringName(condition.get("key", "")), 0)) <= float(condition.get("max", 0))
|
||||
&"payload_contains":
|
||||
var value: Variant = _payload(context).get(StringName(condition.get("key", "")))
|
||||
return value is Array and value.has(condition.get("value")) or value is String and String(value).contains(String(condition.get("value", "")))
|
||||
&"not":
|
||||
return not evaluate(condition.get("cond", {}), context)
|
||||
&"all":
|
||||
for nested: Dictionary in condition.get("conds", []):
|
||||
if not evaluate(nested, context):
|
||||
return false
|
||||
return true
|
||||
&"any":
|
||||
for nested: Dictionary in condition.get("conds", []):
|
||||
if evaluate(nested, context):
|
||||
return true
|
||||
return false
|
||||
_:
|
||||
_diagnose("Unknown condition type: %s" % kind)
|
||||
return false
|
||||
|
||||
func evaluate_all(conditions: Array, context: Dictionary) -> bool:
|
||||
for condition: Dictionary in conditions:
|
||||
if not evaluate(condition, context):
|
||||
return false
|
||||
return true
|
||||
|
||||
func apply_effects(effects: Array, context: Dictionary) -> Array[Dictionary]:
|
||||
var applications: Array[Dictionary] = []
|
||||
for effect: Dictionary in effects:
|
||||
applications.append(apply_effect(effect, context))
|
||||
return applications
|
||||
|
||||
func apply_effect(effect: Dictionary, context: Dictionary) -> Dictionary:
|
||||
var player: PlayerState = context.get("player")
|
||||
var kind := StringName(effect.get("type", ""))
|
||||
if player == null:
|
||||
_diagnose("Effect requires a player: %s" % kind)
|
||||
return {"applied": false, "type": kind}
|
||||
match kind:
|
||||
&"set_flag":
|
||||
player.flags[StringName(effect.get("flag", ""))] = effect.get("value", true)
|
||||
&"add_attr":
|
||||
player.modify_attribute(StringName(effect.get("attr", "")), int(effect.get("amount", 1)))
|
||||
&"add_skill":
|
||||
player.modify_skill(StringName(effect.get("skill", "")), int(effect.get("amount", 1)))
|
||||
&"apply_status", &"inflict_status":
|
||||
player.apply_status(StatusEffectType.new(StringName(effect.get("status", "")), int(effect.get("duration", -1)), int(effect.get("magnitude", 0))))
|
||||
&"cure_status":
|
||||
player.clear_status(StringName(effect.get("status", "")))
|
||||
&"heal":
|
||||
player.hit_points = mini(player.max_hp(), player.hit_points + int(effect.get("amount", 0)))
|
||||
&"heal_pct":
|
||||
player.hit_points = mini(player.max_hp(), player.hit_points + int(player.max_hp() * float(effect.get("pct", 0.0))))
|
||||
&"damage":
|
||||
player.hit_points = maxi(0, player.hit_points - int(effect.get("amount", 0)))
|
||||
&"add_rep":
|
||||
var faction := StringName(effect.get("faction", ""))
|
||||
player.reputation[faction] = player.reputation.get(faction, 0) + int(effect.get("amount", 0))
|
||||
&"message", &"give_item", &"remove_item", &"learn_spell", &"learn_random_spell", &"complete_objective", &"endanger_tourist", &"augment_companion", &"join_party", &"tourist_selfie":
|
||||
# Later content slices own the corresponding inventory, quest, NPC, and spell mutations.
|
||||
pass
|
||||
_:
|
||||
_diagnose("Unknown effect type: %s" % kind)
|
||||
return {"applied": false, "type": kind}
|
||||
return {"applied": true, "type": kind}
|
||||
|
||||
func _payload(context: Dictionary) -> Dictionary:
|
||||
var payload: Variant = context.get("payload", {})
|
||||
return payload if payload is Dictionary else {}
|
||||
|
||||
func _diagnose(message: String) -> void:
|
||||
# Keep unsupported content visible to callers without silently granting access.
|
||||
diagnostics.append(message)
|
||||
@@ -0,0 +1 @@
|
||||
uid://u44apfxu8ud4
|
||||
@@ -0,0 +1,55 @@
|
||||
class_name StatusEffect
|
||||
extends RefCounted
|
||||
|
||||
const DEFINITIONS := {
|
||||
&"poison": {"kind": &"dot", "damage_per_turn": 3, "default_duration": 4},
|
||||
&"bleeding": {"kind": &"dot", "damage_per_turn": 2, "default_duration": 3},
|
||||
&"burning": {"kind": &"dot", "damage_per_turn": 5, "default_duration": 2},
|
||||
&"sepsis": {"kind": &"dot", "damage_per_turn": 4, "default_duration": 10},
|
||||
&"stunned": {"kind": &"control", "skip_turn": true, "default_duration": 1},
|
||||
&"feared": {"kind": &"control", "forced_flee": true, "default_duration": 2},
|
||||
&"confused": {"kind": &"control", "random_action": true, "default_duration": 2},
|
||||
&"wounded": {"kind": &"debuff", "attribute": &"str_", "amount": -1, "default_duration": 6},
|
||||
&"fatigued": {"kind": &"debuff", "attribute": &"agi", "amount": -1, "default_duration": 5},
|
||||
&"strengthened": {"kind": &"buff", "attribute": &"str_", "amount": 2, "default_duration": 5},
|
||||
&"regenerating": {"kind": &"buff", "heal_per_turn": 4, "default_duration": 4},
|
||||
}
|
||||
|
||||
var key: StringName
|
||||
var duration: int
|
||||
var magnitude: int
|
||||
var source: StringName
|
||||
|
||||
func _init(new_key: StringName, new_duration: int = -1, new_magnitude: int = 0, new_source: StringName = &"") -> void:
|
||||
key = new_key
|
||||
var definition: Dictionary = DEFINITIONS.get(key, {})
|
||||
duration = new_duration if new_duration >= 0 else int(definition.get("default_duration", 3))
|
||||
magnitude = new_magnitude if new_magnitude != 0 else _default_magnitude(definition)
|
||||
source = new_source
|
||||
|
||||
func hit_point_delta() -> int:
|
||||
var definition: Dictionary = DEFINITIONS.get(key, {})
|
||||
if definition.get("kind") == &"dot":
|
||||
return -abs(magnitude)
|
||||
if definition.has("heal_per_turn"):
|
||||
return abs(magnitude)
|
||||
return 0
|
||||
|
||||
func attribute_modifier() -> Dictionary[StringName, int]:
|
||||
var definition: Dictionary = DEFINITIONS.get(key, {})
|
||||
if not definition.has("attribute"):
|
||||
return {}
|
||||
return {StringName(definition["attribute"]): magnitude}
|
||||
|
||||
func is_expired() -> bool:
|
||||
return duration <= 0
|
||||
|
||||
func to_dictionary() -> Dictionary:
|
||||
return {"key": key, "duration": duration, "magnitude": magnitude, "source": source}
|
||||
|
||||
static func _default_magnitude(definition: Dictionary) -> int:
|
||||
if definition.has("damage_per_turn"):
|
||||
return int(definition["damage_per_turn"])
|
||||
if definition.has("heal_per_turn"):
|
||||
return int(definition["heal_per_turn"])
|
||||
return int(definition.get("amount", 0))
|
||||
@@ -0,0 +1 @@
|
||||
uid://cm5yjrbld0hq6
|
||||
@@ -10,6 +10,8 @@ var _entries := {
|
||||
"loot_table": {},
|
||||
"npc": {},
|
||||
"quest": {},
|
||||
"trap": {},
|
||||
"event": {},
|
||||
}
|
||||
var _diagnostics := PackedStringArray()
|
||||
|
||||
@@ -44,6 +46,12 @@ func get_npc(id: StringName) -> Dictionary:
|
||||
func get_quest(id: StringName) -> Dictionary:
|
||||
return _definition_for("quest", id)
|
||||
|
||||
func get_trap(id: StringName) -> Dictionary:
|
||||
return _definition_for("trap", id)
|
||||
|
||||
func get_event(id: StringName) -> Dictionary:
|
||||
return _definition_for("event", id)
|
||||
|
||||
func get_diagnostics() -> PackedStringArray:
|
||||
return _diagnostics
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
class_name Attributes
|
||||
extends RefCounted
|
||||
|
||||
const ATTRIBUTE_KEYS: Array[StringName] = [&"str_", &"agi", &"end", &"per", &"int_", &"wil", &"cha", &"luc"]
|
||||
const SKILL_KEYS: Array[StringName] = [
|
||||
&"melee", &"ranged", &"heavy", &"dodge", &"block", &"medicine", &"lockpicking",
|
||||
&"traps", &"survival", &"engineering", &"persuasion", &"intimidation", &"bargaining",
|
||||
&"observation", &"stealth", &"occultism", &"regeneration",
|
||||
]
|
||||
const BASE_ATTRIBUTE := 4
|
||||
const BASE_SKILL := 1
|
||||
|
||||
var values: Dictionary[StringName, int] = {}
|
||||
|
||||
func _init(initial_values: Dictionary = {}) -> void:
|
||||
for key in ATTRIBUTE_KEYS:
|
||||
values[key] = int(initial_values.get(key, BASE_ATTRIBUTE))
|
||||
|
||||
func get_attribute(key: StringName) -> int:
|
||||
return values.get(key, BASE_ATTRIBUTE)
|
||||
|
||||
func set_attribute(key: StringName, value: int) -> void:
|
||||
if not ATTRIBUTE_KEYS.has(key):
|
||||
push_warning("Unknown attribute key: %s" % key)
|
||||
return
|
||||
values[key] = value
|
||||
|
||||
func modify_attribute(key: StringName, delta: int) -> void:
|
||||
set_attribute(key, get_attribute(key) + delta)
|
||||
|
||||
func to_dictionary() -> Dictionary[StringName, int]:
|
||||
return values.duplicate()
|
||||
|
||||
static func default_skills(initial_values: Dictionary = {}) -> Dictionary[StringName, int]:
|
||||
var skills: Dictionary[StringName, int] = {}
|
||||
for key in SKILL_KEYS:
|
||||
skills[key] = int(initial_values.get(key, BASE_SKILL))
|
||||
return skills
|
||||
|
||||
static func is_attribute(key: StringName) -> bool:
|
||||
return ATTRIBUTE_KEYS.has(key)
|
||||
|
||||
static func is_skill(key: StringName) -> bool:
|
||||
return SKILL_KEYS.has(key)
|
||||
@@ -0,0 +1 @@
|
||||
uid://dyh5ir5sikdxk
|
||||
@@ -0,0 +1,107 @@
|
||||
class_name PlayerState
|
||||
extends RefCounted
|
||||
|
||||
const AttributesType = preload("res://scripts/domain/entities/attributes.gd")
|
||||
const StatusEffectType = preload("res://scripts/domain/combat/status_effect.gd")
|
||||
const ActorStateType = preload("res://scripts/domain/actor_state.gd")
|
||||
|
||||
var id: StringName = &"player"
|
||||
var cell := Vector2i.ZERO
|
||||
var attributes: Attributes
|
||||
var skills: Dictionary[StringName, int]
|
||||
var level := 1
|
||||
var hit_points := 1
|
||||
var focus := 0
|
||||
var equipment_attribute_modifiers: Dictionary[StringName, int] = {}
|
||||
var equipment_skill_modifiers: Dictionary[StringName, int] = {}
|
||||
var flags: Dictionary[StringName, Variant] = {}
|
||||
var reputation: Dictionary[StringName, int] = {}
|
||||
var archetype: StringName = &""
|
||||
var race: StringName = &""
|
||||
var status_effects: Array[StatusEffect] = []
|
||||
|
||||
func _init(data: Dictionary = {}) -> void:
|
||||
id = StringName(data.get("id", id))
|
||||
cell = data.get("cell", cell)
|
||||
attributes = _attributes_from(data.get("attributes", {}))
|
||||
skills = AttributesType.default_skills(data.get("skills", {}))
|
||||
level = maxi(1, int(data.get("level", level)))
|
||||
for flag in data.get("flags", {}):
|
||||
flags[StringName(flag)] = data.flags[flag]
|
||||
for faction in data.get("reputation", {}):
|
||||
reputation[StringName(faction)] = int(data.reputation[faction])
|
||||
archetype = StringName(data.get("archetype", archetype))
|
||||
race = StringName(data.get("race", race))
|
||||
hit_points = clampi(int(data.get("hit_points", max_hp())), 0, max_hp())
|
||||
focus = clampi(int(data.get("focus", max_focus())), 0, max_focus())
|
||||
|
||||
func max_hp() -> int:
|
||||
return maxi(1, 50 + attributes.get_attribute(&"end") * 6 + (level - 1) * 8)
|
||||
|
||||
func max_focus() -> int:
|
||||
return maxi(0, 15 + attributes.get_attribute(&"wil") * 5 + (level - 1) * 3)
|
||||
|
||||
func effective_attribute(key: StringName) -> int:
|
||||
var value: int = attributes.get_attribute(key) + equipment_attribute_modifiers.get(key, 0)
|
||||
for effect in status_effects:
|
||||
value += effect.attribute_modifier().get(key, 0)
|
||||
return value
|
||||
|
||||
func effective_skill(key: StringName) -> int:
|
||||
return skills.get(key, 0) + equipment_skill_modifiers.get(key, 0)
|
||||
|
||||
func modify_attribute(key: StringName, amount: int) -> void:
|
||||
attributes.modify_attribute(key, amount)
|
||||
_normalize_resources()
|
||||
|
||||
func modify_skill(key: StringName, amount: int) -> void:
|
||||
if not AttributesType.is_skill(key):
|
||||
push_warning("Unknown skill key: %s" % key)
|
||||
return
|
||||
skills[key] = maxi(0, skills.get(key, 0) + amount)
|
||||
|
||||
func apply_status(effect: StatusEffect) -> void:
|
||||
var existing := _status_for(effect.key)
|
||||
if existing == null:
|
||||
status_effects.append(effect)
|
||||
return
|
||||
existing.duration = maxi(existing.duration, effect.duration)
|
||||
if abs(effect.magnitude) > abs(existing.magnitude):
|
||||
existing.magnitude = effect.magnitude
|
||||
|
||||
func has_status(key: StringName) -> bool:
|
||||
return _status_for(key) != null
|
||||
|
||||
func clear_status(key: StringName) -> void:
|
||||
status_effects = status_effects.filter(func(effect: StatusEffect) -> bool: return effect.key != key)
|
||||
|
||||
func tick_status_effects() -> Array[Dictionary]:
|
||||
var ticks: Array[Dictionary] = []
|
||||
for effect in status_effects:
|
||||
var delta := effect.hit_point_delta()
|
||||
if delta != 0:
|
||||
hit_points = clampi(hit_points + delta, 0, max_hp())
|
||||
ticks.append({"status": effect.key, "hit_point_delta": delta, "remaining_duration": effect.duration - 1})
|
||||
effect.duration -= 1
|
||||
status_effects = status_effects.filter(func(effect: StatusEffect) -> bool: return not effect.is_expired())
|
||||
return ticks
|
||||
|
||||
func as_actor_state(attack_damage: int) -> ActorState:
|
||||
var actor := ActorStateType.new(id, cell, max_hp(), attack_damage)
|
||||
actor.hit_points = hit_points
|
||||
return actor
|
||||
|
||||
func _normalize_resources() -> void:
|
||||
hit_points = clampi(hit_points, 0, max_hp())
|
||||
focus = clampi(focus, 0, max_focus())
|
||||
|
||||
func _status_for(key: StringName) -> StatusEffect:
|
||||
for effect in status_effects:
|
||||
if effect.key == key:
|
||||
return effect
|
||||
return null
|
||||
|
||||
static func _attributes_from(value: Variant) -> Attributes:
|
||||
if value is Attributes:
|
||||
return value
|
||||
return AttributesType.new(value if value is Dictionary else {})
|
||||
@@ -0,0 +1 @@
|
||||
uid://b8y518h1wldal
|
||||
@@ -25,16 +25,23 @@ func _init(new_map: GridMapState, new_player: ActorState, new_enemies: Dictionar
|
||||
|
||||
func bind_run_state(run_state: RunState) -> void:
|
||||
run_state.set_floor_state(floor_state)
|
||||
floor_state = run_state.current_floor_state()
|
||||
set_floor_state(run_state.current_floor_state())
|
||||
|
||||
func set_floor_state(new_floor_state: FloorState) -> void:
|
||||
floor_state = new_floor_state
|
||||
map = floor_state.map
|
||||
enemies = floor_state.enemies
|
||||
explored_cells = floor_state.explored_cells
|
||||
exit_reached = false
|
||||
update_exploration()
|
||||
|
||||
func get_context_target() -> StringName:
|
||||
if exit_reached:
|
||||
return &"exit_reached"
|
||||
if map.get_cell(player.cell) == GridMapState.CellKind.STAIRS:
|
||||
return &"stairs"
|
||||
if map.get_cell(player.cell) == GridMapState.CellKind.BED:
|
||||
return &"bed"
|
||||
for direction in InteractionResolverType.TARGET_OFFSETS:
|
||||
if map.get_cell(player.cell + direction) == GridMapState.CellKind.CHEST:
|
||||
return &"chest"
|
||||
|
||||
@@ -2,7 +2,7 @@ class_name GridMapState
|
||||
extends RefCounted
|
||||
|
||||
const TILE_SIZE := Vector2i(32, 32)
|
||||
enum CellKind { FLOOR, WALL, CLOSED_DOOR, CHEST, STAIRS }
|
||||
enum CellKind { FLOOR, WALL, CLOSED_DOOR, CHEST, STAIRS, BED }
|
||||
|
||||
var size: Vector2i
|
||||
var _cells: Dictionary[Vector2i, CellKind] = {}
|
||||
@@ -37,7 +37,7 @@ func is_inside(cell: Vector2i) -> bool:
|
||||
|
||||
func is_walkable(cell: Vector2i) -> bool:
|
||||
var kind := get_cell(cell)
|
||||
return kind == CellKind.FLOOR or kind == CellKind.STAIRS
|
||||
return kind == CellKind.FLOOR or kind == CellKind.STAIRS or kind == CellKind.BED
|
||||
|
||||
func is_opaque(cell: Vector2i) -> bool:
|
||||
var kind := get_cell(cell)
|
||||
|
||||
@@ -20,13 +20,16 @@ static func resolve(state: GameState) -> Array[TurnResult]:
|
||||
var results: Array[TurnResult] = []
|
||||
if state.map.get_cell(state.player.cell) == GridMapState.CellKind.STAIRS and not state.exit_reached:
|
||||
state.exit_reached = true
|
||||
results.append(TurnResultType.new(state.player.id, &"stairs_used", state.player.cell, state.player.cell, &"", 0, "You descend the stairs."))
|
||||
var stairs_message := "You ascend the stairs." if state.floor_state.floor_number > 0 and state.player.cell == state.floor_state.entrance else "You descend the stairs."
|
||||
results.append(TurnResultType.new(state.player.id, &"stairs_used", state.player.cell, state.player.cell, &"", 0, stairs_message))
|
||||
TurnResolverType.append_enemy_response(state, results)
|
||||
return results
|
||||
|
||||
var chest_cell := _find_cell_of_kind(state, GridMapState.CellKind.CHEST)
|
||||
if chest_cell.x >= 0:
|
||||
state.map.set_cell(chest_cell, GridMapState.CellKind.FLOOR)
|
||||
if state.floor_state.chests.has(chest_cell):
|
||||
state.floor_state.chests[chest_cell]["opened"] = true
|
||||
results.append(TurnResultType.new(state.player.id, &"chest_opened", state.player.cell, chest_cell, &"", 0, "You open the chest."))
|
||||
TurnResolverType.append_enemy_response(state, results)
|
||||
return results
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
class_name FloorDeadline
|
||||
extends RefCounted
|
||||
|
||||
# ASCII parity: floor one starts at fifteen days, each later floor adds five.
|
||||
# A Godot run also gives its authored surface the floor-one allowance, so its
|
||||
# deliberately gated tutorial exit is testable through the same domain seam.
|
||||
const TURNS_PER_DAY := 20
|
||||
const BASE_DAYS := 15
|
||||
const EXTRA_DAYS_PER_FLOOR := 5
|
||||
const REAL_SECONDS_PER_DAY := 3600.0
|
||||
const WARNING_DAYS := 1
|
||||
const STAIRS_OPEN_DAYS_BEFORE_COLLAPSE := 2
|
||||
const BED_REST_DAY_COST := 1
|
||||
const COLLAPSE_DAMAGE_PER_TURN := 3
|
||||
|
||||
var floor_number: int
|
||||
var turns_remaining: int
|
||||
var collapsing := false
|
||||
var warned := false
|
||||
var real_seconds := 0.0
|
||||
|
||||
func _init(new_floor_number: int) -> void:
|
||||
floor_number = new_floor_number
|
||||
turns_remaining = deadline_days_for(new_floor_number) * TURNS_PER_DAY
|
||||
|
||||
static func deadline_days_for(new_floor_number: int) -> int:
|
||||
return BASE_DAYS + EXTRA_DAYS_PER_FLOOR * (maxi(1, new_floor_number) - 1)
|
||||
|
||||
func remaining_days() -> int:
|
||||
return ceili(float(turns_remaining) / float(TURNS_PER_DAY))
|
||||
|
||||
func can_descend() -> bool:
|
||||
return collapsing or turns_remaining <= STAIRS_OPEN_DAYS_BEFORE_COLLAPSE * TURNS_PER_DAY
|
||||
|
||||
func days_until_stairs_open() -> int:
|
||||
return maxi(0, remaining_days() - STAIRS_OPEN_DAYS_BEFORE_COLLAPSE)
|
||||
|
||||
# A return value is a deterministic semantic event list; the presentation
|
||||
# layer owns localized wording and actor damage application.
|
||||
func rest() -> Array[StringName]:
|
||||
if turns_remaining > 0:
|
||||
turns_remaining = maxi(0, turns_remaining - BED_REST_DAY_COST * TURNS_PER_DAY)
|
||||
real_seconds = 0.0
|
||||
return _state_events()
|
||||
|
||||
# This intentionally receives elapsed time rather than reading a wall clock:
|
||||
# callers/tests can advance pressure deterministically.
|
||||
func advance_real_seconds(elapsed_seconds: float) -> Array[StringName]:
|
||||
if elapsed_seconds <= 0.0 or turns_remaining <= 0:
|
||||
return _state_events()
|
||||
real_seconds += elapsed_seconds
|
||||
var events: Array[StringName] = []
|
||||
while real_seconds >= REAL_SECONDS_PER_DAY and turns_remaining > 0:
|
||||
real_seconds -= REAL_SECONDS_PER_DAY
|
||||
turns_remaining = maxi(0, turns_remaining - TURNS_PER_DAY)
|
||||
events.append(&"deadline_day_elapsed")
|
||||
events.append_array(_state_events())
|
||||
return events
|
||||
|
||||
# The collapse starts once, then each later deterministic gameplay tick deals
|
||||
# the fixed ASCII collapse damage. This makes the dangerous state explicit.
|
||||
func tick() -> StringName:
|
||||
var events := _state_events()
|
||||
if events.has(&"floor_collapsed"):
|
||||
return &"floor_collapsed"
|
||||
if collapsing:
|
||||
return &"collapse_damage"
|
||||
return &""
|
||||
|
||||
func collapse_damage_for(hit_points: int) -> int:
|
||||
return mini(COLLAPSE_DAMAGE_PER_TURN, maxi(0, hit_points))
|
||||
|
||||
func _state_events() -> Array[StringName]:
|
||||
var events: Array[StringName] = []
|
||||
if not warned and turns_remaining <= WARNING_DAYS * TURNS_PER_DAY:
|
||||
warned = true
|
||||
events.append(&"deadline_warning")
|
||||
if turns_remaining <= 0 and not collapsing:
|
||||
collapsing = true
|
||||
events.append(&"floor_collapsed")
|
||||
return events
|
||||
@@ -0,0 +1 @@
|
||||
uid://d1e5kjdwbkgyp
|
||||
@@ -0,0 +1,55 @@
|
||||
class_name FloorTransition
|
||||
extends RefCounted
|
||||
|
||||
const GridMapStateType = preload("res://scripts/domain/grid_map_state.gd")
|
||||
const SurfaceGeneratorType = preload("res://scripts/domain/world/surface_generator.gd")
|
||||
const FloorGeneratorType = preload("res://scripts/domain/world/floor_generator.gd")
|
||||
|
||||
var catalog: ContentCatalog
|
||||
|
||||
func _init(new_catalog: ContentCatalog) -> void:
|
||||
catalog = new_catalog
|
||||
|
||||
func initial_floor(run: RunState) -> FloorState:
|
||||
if not run.floors.has(0):
|
||||
run.set_floor_state(SurfaceGeneratorType.generate(run.seed))
|
||||
run.current_floor = 0
|
||||
run.ensure_floor_deadline(0)
|
||||
return run.current_floor_state()
|
||||
|
||||
# Returns the cached/generated destination and the stairs cell on which the
|
||||
# player arrives. Floor 0's sole stairs descends, while every procedural floor
|
||||
# has an up stair at entrance and down stair at exit.
|
||||
func transition(run: RunState, source: FloorState, stairs_cell: Vector2i) -> Dictionary:
|
||||
var destination_number := _destination_floor_number(source, stairs_cell)
|
||||
var destination := _floor_for(run, destination_number)
|
||||
var arrival := destination.entrance if destination_number > source.floor_number else destination.exit
|
||||
run.current_floor = destination_number
|
||||
run.ensure_floor_deadline(destination_number)
|
||||
return {"floor": destination, "arrival": arrival}
|
||||
|
||||
func _destination_floor_number(source: FloorState, stairs_cell: Vector2i) -> int:
|
||||
if source.floor_number == 0:
|
||||
return 1
|
||||
if stairs_cell == source.entrance:
|
||||
return source.floor_number - 1
|
||||
return source.floor_number + 1
|
||||
|
||||
func _floor_for(run: RunState, floor_number: int) -> FloorState:
|
||||
if run.floors.has(floor_number):
|
||||
return run.floors[floor_number]
|
||||
if floor_number == 0:
|
||||
return initial_floor(run)
|
||||
var floor := FloorGeneratorType.generate(run.seed, floor_number, catalog)
|
||||
# B3 only marked the down stair. B5 makes the entry stair explicit so a
|
||||
# return route is visible and interaction direction is unambiguous.
|
||||
floor.map.set_cell(floor.entrance, GridMapStateType.CellKind.STAIRS)
|
||||
_materialize_unopened_chests(floor)
|
||||
floor.metadata["hand_authored"] = false
|
||||
run.set_floor_state(floor)
|
||||
return floor
|
||||
|
||||
func _materialize_unopened_chests(floor: FloorState) -> void:
|
||||
for cell in floor.chests:
|
||||
if not bool(floor.chests[cell].get("opened", false)):
|
||||
floor.map.set_cell(cell, GridMapStateType.CellKind.CHEST)
|
||||
@@ -0,0 +1 @@
|
||||
uid://dld2hudsse86m
|
||||
@@ -7,6 +7,9 @@ var player_name := "Sans-Nom"
|
||||
var base_archetype: StringName = &"vanguard"
|
||||
var current_floor := 0
|
||||
var floors: Dictionary[int, FloorState] = {}
|
||||
# Deadline records are intentionally independent from generated FloorState so
|
||||
# revisiting/cache operations can never reset a collapsing floor's countdown.
|
||||
var floor_deadlines: Dictionary[int, FloorDeadline] = {}
|
||||
var current_turn := 0
|
||||
var log: Array[GameEvent] = []
|
||||
|
||||
@@ -20,6 +23,17 @@ func set_floor_state(floor: FloorState) -> void:
|
||||
func current_floor_state() -> FloorState:
|
||||
return floors.get(current_floor)
|
||||
|
||||
func ensure_floor_deadline(floor_number: int) -> FloorDeadline:
|
||||
if not floor_deadlines.has(floor_number):
|
||||
floor_deadlines[floor_number] = FloorDeadline.new(floor_number)
|
||||
return floor_deadlines[floor_number]
|
||||
|
||||
func deadline_for(floor_number: int) -> FloorDeadline:
|
||||
return ensure_floor_deadline(floor_number)
|
||||
|
||||
func current_floor_deadline() -> FloorDeadline:
|
||||
return ensure_floor_deadline(current_floor)
|
||||
|
||||
func next_turn() -> int:
|
||||
current_turn += 1
|
||||
return current_turn
|
||||
|
||||
@@ -30,8 +30,9 @@ const GridMapStateType = preload("res://scripts/domain/grid_map_state.gd")
|
||||
const FloorStateType = preload("res://scripts/domain/world/floor_state.gd")
|
||||
const RoomStateType = preload("res://scripts/domain/world/room_state.gd")
|
||||
const RoomGraphType = preload("res://scripts/domain/world/room_graph.gd")
|
||||
const FloorPopulatorType = preload("res://scripts/domain/world/floor_populator.gd")
|
||||
|
||||
static func generate(seed: String, floor_number: int, _catalog: ContentCatalog) -> FloorState:
|
||||
static func generate(seed: String, floor_number: int, catalog: ContentCatalog) -> FloorState:
|
||||
var rng := DeterministicRngType.from_seed("%s-floor%d" % [seed, floor_number])
|
||||
var rooms := _place_rooms(rng)
|
||||
var map := GridMapStateType.new(MAP_SIZE, GridMapStateType.CellKind.WALL)
|
||||
@@ -63,8 +64,24 @@ static func generate(seed: String, floor_number: int, _catalog: ContentCatalog)
|
||||
floor.map.set_cell(floor.exit, GridMapStateType.CellKind.STAIRS)
|
||||
floor.metadata["room_graph"] = graph.to_dict()
|
||||
floor.metadata["tree_door_cells"] = tree_door_cells
|
||||
_materialize_safe_room_beds(floor)
|
||||
FloorPopulatorType.populate(floor, catalog, seed)
|
||||
return floor
|
||||
|
||||
# Beds must be installed before population so the occupancy-aware population
|
||||
# pass cannot place an NPC on a safe room's resting tile.
|
||||
static func _materialize_safe_room_beds(floor: FloorState) -> void:
|
||||
var bed_cells: Array[Vector2i] = []
|
||||
for room in floor.rooms:
|
||||
if room.kind not in [&"sanctuary", &"refuge"]:
|
||||
continue
|
||||
var bed_cell := _room_center(room.bounds)
|
||||
if bed_cell == floor.entrance or bed_cell == floor.exit:
|
||||
continue
|
||||
floor.map.set_cell(bed_cell, GridMapStateType.CellKind.BED)
|
||||
bed_cells.append(bed_cell)
|
||||
floor.metadata["bed_cells"] = bed_cells
|
||||
|
||||
static func _place_rooms(rng: DeterministicRng) -> Array[RoomState]:
|
||||
var rooms: Array[RoomState] = []
|
||||
for room_index in range(ROOM_COUNT):
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
class_name FloorPopulator
|
||||
extends RefCounted
|
||||
|
||||
const DeterministicRngType = preload("res://scripts/domain/run/deterministic_rng.gd")
|
||||
const ActorStateType = preload("res://scripts/domain/actor_state.gd")
|
||||
const GridMapStateType = preload("res://scripts/domain/grid_map_state.gd")
|
||||
const SpawnRulesType = preload("res://scripts/domain/world/spawn_rules.gd")
|
||||
|
||||
static func populate(floor: FloorState, catalog: ContentCatalog, population_seed: String) -> void:
|
||||
_clear_population(floor)
|
||||
var rng := DeterministicRngType.from_seed("%s-population-%d" % [population_seed, floor.floor_number])
|
||||
var occupied: Dictionary[Vector2i, bool] = {
|
||||
floor.entrance: true,
|
||||
floor.exit: true,
|
||||
}
|
||||
for bed_cell: Vector2i in floor.metadata.get("bed_cells", []):
|
||||
occupied[bed_cell] = true
|
||||
var serial := 0
|
||||
for room in floor.rooms:
|
||||
if room.kind == &"entrance":
|
||||
continue
|
||||
match room.kind:
|
||||
&"combat", &"boss", &"arena":
|
||||
serial = _spawn_enemy(floor, catalog, room, rng, occupied, serial)
|
||||
&"treasure":
|
||||
_spawn_chest(floor, catalog, room, rng, occupied)
|
||||
&"trap":
|
||||
_spawn_trap(floor, catalog, room, rng, occupied)
|
||||
&"shop", &"guild", &"sanctuary", &"refuge":
|
||||
serial = _spawn_npc(floor, catalog, room, rng, occupied, serial)
|
||||
&"narrative", &"mystery", &"puzzle":
|
||||
_spawn_event(floor, catalog, room, rng, occupied)
|
||||
|
||||
static func _clear_population(floor: FloorState) -> void:
|
||||
floor.enemies.clear()
|
||||
floor.npcs.clear()
|
||||
floor.chests.clear()
|
||||
floor.traps.clear()
|
||||
floor.events.clear()
|
||||
|
||||
static func _spawn_enemy(floor: FloorState, catalog: ContentCatalog, room: RoomState, rng: DeterministicRng, occupied: Dictionary[Vector2i, bool], serial: int) -> int:
|
||||
var definitions := SpawnRulesType.eligible_enemies(catalog, floor.floor_number)
|
||||
var cell := _available_cell(floor, room, rng, occupied)
|
||||
if definitions.is_empty() or cell == Vector2i(-1, -1):
|
||||
return serial
|
||||
var definition: Dictionary = definitions[rng.next_int() % definitions.size()]
|
||||
var content_id := StringName(definition["id"])
|
||||
var actor_id := StringName("%s_%02d" % [content_id, serial])
|
||||
floor.enemies[actor_id] = ActorStateType.new(actor_id, cell, int(definition.get("hp", 1)), int(definition.get("attack", 0)), content_id)
|
||||
occupied[cell] = true
|
||||
return serial + 1
|
||||
|
||||
static func _spawn_chest(floor: FloorState, catalog: ContentCatalog, room: RoomState, rng: DeterministicRng, occupied: Dictionary[Vector2i, bool]) -> void:
|
||||
var definitions := SpawnRulesType.loot_tables(catalog)
|
||||
var cell := _available_cell(floor, room, rng, occupied)
|
||||
if definitions.is_empty() or cell == Vector2i(-1, -1):
|
||||
return
|
||||
var definition: Dictionary = definitions[rng.next_int() % definitions.size()]
|
||||
floor.chests[cell] = {
|
||||
"loot_table_id": definition["id"],
|
||||
"opened": false,
|
||||
}
|
||||
occupied[cell] = true
|
||||
|
||||
static func _spawn_trap(floor: FloorState, catalog: ContentCatalog, room: RoomState, rng: DeterministicRng, occupied: Dictionary[Vector2i, bool]) -> void:
|
||||
var definitions := SpawnRulesType.traps(catalog)
|
||||
var cell := _available_cell(floor, room, rng, occupied)
|
||||
if definitions.is_empty() or cell == Vector2i(-1, -1):
|
||||
return
|
||||
var definition: Dictionary = definitions[rng.next_int() % definitions.size()]
|
||||
floor.traps[cell] = {"trap_id": definition["id"]}
|
||||
occupied[cell] = true
|
||||
|
||||
static func _spawn_npc(floor: FloorState, catalog: ContentCatalog, room: RoomState, rng: DeterministicRng, occupied: Dictionary[Vector2i, bool], serial: int) -> int:
|
||||
var definition := SpawnRulesType.npc_for_role(catalog, room.kind)
|
||||
var cell := _available_cell(floor, room, rng, occupied)
|
||||
if definition.is_empty() or cell == Vector2i(-1, -1):
|
||||
return serial
|
||||
var content_id := StringName(definition["id"])
|
||||
var actor_id := StringName("%s_%02d" % [content_id, serial])
|
||||
floor.npcs[actor_id] = ActorStateType.new(actor_id, cell, 1, 0, content_id)
|
||||
occupied[cell] = true
|
||||
return serial + 1
|
||||
|
||||
static func _spawn_event(floor: FloorState, catalog: ContentCatalog, room: RoomState, rng: DeterministicRng, occupied: Dictionary[Vector2i, bool]) -> void:
|
||||
var definition := SpawnRulesType.event_for_role(catalog, room.kind)
|
||||
var cell := _available_cell(floor, room, rng, occupied)
|
||||
if definition.is_empty() or cell == Vector2i(-1, -1):
|
||||
return
|
||||
floor.events.append({
|
||||
"event_id": definition["id"],
|
||||
"cell": [cell.x, cell.y],
|
||||
"room_id": String(room.id),
|
||||
"resolved": false,
|
||||
})
|
||||
occupied[cell] = true
|
||||
|
||||
static func _available_cell(floor: FloorState, room: RoomState, rng: DeterministicRng, occupied: Dictionary[Vector2i, bool]) -> Vector2i:
|
||||
var candidates: Array[Vector2i] = []
|
||||
for y in range(room.bounds.position.y, room.bounds.end.y):
|
||||
for x in range(room.bounds.position.x, room.bounds.end.x):
|
||||
var cell := Vector2i(x, y)
|
||||
if floor.map.get_cell(cell) == GridMapStateType.CellKind.FLOOR and not occupied.has(cell):
|
||||
candidates.append(cell)
|
||||
if candidates.is_empty():
|
||||
return Vector2i(-1, -1)
|
||||
return candidates[rng.next_int() % candidates.size()]
|
||||
@@ -0,0 +1 @@
|
||||
uid://dh111xs1bii08
|
||||
@@ -18,6 +18,7 @@ var entities: Dictionary[StringName, ActorState]:
|
||||
enemies = value
|
||||
npcs.clear()
|
||||
var chests: Dictionary[Vector2i, Dictionary] = {}
|
||||
var traps: Dictionary[Vector2i, Dictionary] = {}
|
||||
var ground_items: Dictionary[Vector2i, Array] = {}
|
||||
var events: Array[Dictionary] = []
|
||||
var explored_cells: Dictionary[Vector2i, bool] = {}
|
||||
@@ -42,6 +43,7 @@ func to_dict() -> Dictionary:
|
||||
"enemies": _actors_to_array(enemies),
|
||||
"npcs": _actors_to_array(npcs),
|
||||
"chests": _cell_dictionary_to_array(chests),
|
||||
"traps": _cell_dictionary_to_array(traps),
|
||||
"ground_items": _cell_dictionary_to_array(ground_items),
|
||||
"events": events.duplicate(true),
|
||||
"explored_cells": _explored_cells_to_array(),
|
||||
@@ -62,6 +64,8 @@ static func from_dict(data: Dictionary) -> FloorState:
|
||||
floor.npcs = _actors_from_array(data.get("npcs", []))
|
||||
for chest_data: Dictionary in data.get("chests", []):
|
||||
floor.chests[_array_to_cell(chest_data.get("cell", [0, 0]))] = chest_data.get("value", {}).duplicate(true)
|
||||
for trap_data: Dictionary in data.get("traps", []):
|
||||
floor.traps[_array_to_cell(trap_data.get("cell", [0, 0]))] = trap_data.get("value", {}).duplicate(true)
|
||||
for item_data: Dictionary in data.get("ground_items", []):
|
||||
floor.ground_items[_array_to_cell(item_data.get("cell", [0, 0]))] = item_data.get("value", []).duplicate(true)
|
||||
for event_data: Dictionary in data.get("events", []):
|
||||
@@ -113,6 +117,7 @@ static func _actor_to_dict(actor: ActorState) -> Dictionary:
|
||||
"hit_points": actor.hit_points,
|
||||
"max_hit_points": actor.max_hit_points,
|
||||
"attack_damage": actor.attack_damage,
|
||||
"content_id": String(actor.content_id),
|
||||
}
|
||||
|
||||
static func _actor_from_dict(data: Dictionary) -> ActorState:
|
||||
@@ -120,7 +125,8 @@ static func _actor_from_dict(data: Dictionary) -> ActorState:
|
||||
StringName(data.get("id", "")),
|
||||
_array_to_cell(data.get("cell", [0, 0])),
|
||||
int(data.get("max_hit_points", data.get("hit_points", 0))),
|
||||
int(data.get("attack_damage", 0))
|
||||
int(data.get("attack_damage", 0)),
|
||||
StringName(data.get("content_id", data.get("id", "")))
|
||||
)
|
||||
actor.hit_points = int(data.get("hit_points", actor.max_hit_points))
|
||||
return actor
|
||||
|
||||
@@ -49,7 +49,7 @@ func tree_distances(start_index: int) -> Dictionary[int, int]:
|
||||
var distances: Dictionary[int, int] = {start_index: 0}
|
||||
var frontier: Array[int] = [start_index]
|
||||
while not frontier.is_empty():
|
||||
var current := frontier.pop_front()
|
||||
var current: int = frontier.pop_front()
|
||||
for neighbor in adjacency.get(current, []):
|
||||
if not distances.has(neighbor):
|
||||
distances[neighbor] = distances[current] + 1
|
||||
@@ -61,7 +61,7 @@ func farthest_tree_room(start_index: int) -> int:
|
||||
var farthest_index := start_index
|
||||
var farthest_distance := -1
|
||||
for room_index in range(distances.size()):
|
||||
var distance := distances.get(room_index, -1)
|
||||
var distance: int = distances.get(room_index, -1)
|
||||
if distance > farthest_distance:
|
||||
farthest_index = room_index
|
||||
farthest_distance = distance
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
class_name SpawnRules
|
||||
extends RefCounted
|
||||
|
||||
# B4 intentionally keeps authored content as lightweight records. Interaction
|
||||
# semantics belong to later slices; these rules only decide which catalog data
|
||||
# can occupy a generated floor.
|
||||
static func eligible_enemies(catalog: ContentCatalog, floor_number: int) -> Array[Dictionary]:
|
||||
var eligible: Array[Dictionary] = []
|
||||
for id in catalog.get_ids(&"enemy"):
|
||||
var definition := catalog.get_enemy(id)
|
||||
if int(definition.get("min_floor", 1)) <= floor_number:
|
||||
eligible.append(definition)
|
||||
return eligible
|
||||
|
||||
static func loot_tables(catalog: ContentCatalog) -> Array[Dictionary]:
|
||||
return _definitions(catalog, &"loot_table")
|
||||
|
||||
static func npcs(catalog: ContentCatalog) -> Array[Dictionary]:
|
||||
return _definitions(catalog, &"npc")
|
||||
|
||||
static func traps(catalog: ContentCatalog) -> Array[Dictionary]:
|
||||
return _definitions(catalog, &"trap")
|
||||
|
||||
static func events(catalog: ContentCatalog) -> Array[Dictionary]:
|
||||
return _definitions(catalog, &"event")
|
||||
|
||||
static func npc_for_role(catalog: ContentCatalog, role: StringName) -> Dictionary:
|
||||
var preferred_id: StringName = {
|
||||
&"shop": &"npc_wandering_merchant",
|
||||
&"guild": &"npc_guild_keeper",
|
||||
&"sanctuary": &"npc_shelter_survivor",
|
||||
&"refuge": &"npc_bobka",
|
||||
}.get(role, &"")
|
||||
if not preferred_id.is_empty():
|
||||
var preferred := catalog.get_npc(preferred_id)
|
||||
if not preferred.is_empty():
|
||||
return preferred
|
||||
var available := npcs(catalog)
|
||||
return available[0] if not available.is_empty() else {}
|
||||
|
||||
static func event_for_role(catalog: ContentCatalog, role: StringName) -> Dictionary:
|
||||
var preferred_id: StringName = {
|
||||
&"narrative": &"event_narrative_note",
|
||||
&"mystery": &"event_vending_machine",
|
||||
&"puzzle": &"event_puzzle_pressure_plates",
|
||||
}.get(role, &"")
|
||||
if not preferred_id.is_empty():
|
||||
var preferred := catalog.get_event(preferred_id)
|
||||
if not preferred.is_empty():
|
||||
return preferred
|
||||
var available := events(catalog)
|
||||
return available[0] if not available.is_empty() else {}
|
||||
|
||||
static func _definitions(catalog: ContentCatalog, kind: StringName) -> Array[Dictionary]:
|
||||
var definitions: Array[Dictionary] = []
|
||||
for id in catalog.get_ids(kind):
|
||||
match kind:
|
||||
&"loot_table": definitions.append(catalog.get_loot_table(id))
|
||||
&"npc": definitions.append(catalog.get_npc(id))
|
||||
&"trap": definitions.append(catalog.get_trap(id))
|
||||
&"event": definitions.append(catalog.get_event(id))
|
||||
return definitions
|
||||
@@ -0,0 +1 @@
|
||||
uid://can7v1ir5w5un
|
||||
@@ -0,0 +1,43 @@
|
||||
class_name SurfaceGenerator
|
||||
extends RefCounted
|
||||
|
||||
const GridMapStateType = preload("res://scripts/domain/grid_map_state.gd")
|
||||
const FloorStateType = preload("res://scripts/domain/world/floor_state.gd")
|
||||
const ActorStateType = preload("res://scripts/domain/actor_state.gd")
|
||||
|
||||
# Floor zero deliberately remains an authored tutorial surface. Its geometry is
|
||||
# not derived from the run seed; RunState supplies persistence by caching it.
|
||||
static func generate(_seed: String = "") -> FloorState:
|
||||
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 floor := FloorStateType.new(map, 0, 0)
|
||||
floor.entrance = Vector2i(4, 12)
|
||||
floor.exit = Vector2i(18, 4)
|
||||
floor.enemies[&"goblin"] = ActorStateType.new(&"goblin", Vector2i(24, 8), 6, 2)
|
||||
floor.chests[Vector2i(4, 7)] = {"opened": false}
|
||||
floor.metadata = {"hand_authored": true, "theme": "surface"}
|
||||
return floor
|
||||
|
||||
static 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)
|
||||
|
||||
static 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)
|
||||
|
||||
static 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)
|
||||
@@ -0,0 +1 @@
|
||||
uid://cieqsjogiiein
|
||||
+93
-11
@@ -14,6 +14,8 @@ const GameEventType = preload("res://scripts/domain/run/game_event.gd")
|
||||
const PlayerActionType = preload("res://scripts/domain/run/player_action.gd")
|
||||
const ActionRouterType = preload("res://scripts/game/action_router.gd")
|
||||
const ActorViewType = preload("res://scripts/presentation/actor_view.gd")
|
||||
const ContentCatalogType = preload("res://scripts/domain/content/content_catalog.gd")
|
||||
const FloorTransitionType = preload("res://scripts/domain/run/floor_transition.gd")
|
||||
@onready var event_presenter: EventPresenter = $EventPresenter
|
||||
@onready var map_renderer: MapRenderer = $World/MapRenderer
|
||||
@onready var player_view: ActorView = $World/Player
|
||||
@@ -29,6 +31,7 @@ var action_router: ActionRouter
|
||||
var pending_run_settings: RunSettings
|
||||
var pending_player_name := "Sans-Nom"
|
||||
var pending_base_archetype: StringName = &"vanguard"
|
||||
var floor_transition: FloorTransition
|
||||
|
||||
func configure_new_run(settings: RunSettings, player_name: String, base_archetype: StringName) -> void:
|
||||
pending_run_settings = settings
|
||||
@@ -46,7 +49,7 @@ func _ready() -> void:
|
||||
player_view.set_actor(game_state.player)
|
||||
_configure_camera()
|
||||
_sync_enemy_views()
|
||||
hud.refresh(game_state)
|
||||
hud.refresh(game_state, [], run_state)
|
||||
audio_library.set_ambience_context("exploration")
|
||||
var capture_mode := _get_capture_mode()
|
||||
if not capture_mode.is_empty():
|
||||
@@ -64,7 +67,10 @@ func _initialize_run_state() -> void:
|
||||
run_state = RunStateType.new(settings.seed, settings)
|
||||
run_state.player_name = pending_player_name
|
||||
run_state.base_archetype = pending_base_archetype
|
||||
game_state.bind_run_state(run_state)
|
||||
floor_transition = FloorTransitionType.new(ContentCatalogType.load_from_directory("res://data/ascii"))
|
||||
var initial_floor := floor_transition.initial_floor(run_state)
|
||||
game_state.set_floor_state(initial_floor)
|
||||
game_state.player.cell = initial_floor.entrance
|
||||
if pending_run_settings != null:
|
||||
var game_started := GameEventType.new(
|
||||
run_state.next_turn(),
|
||||
@@ -110,6 +116,9 @@ 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()
|
||||
_sync_camera_to_player()
|
||||
|
||||
@@ -134,6 +143,9 @@ func submit_player_action(action: PlayerAction) -> Array[GameEvent]:
|
||||
&"interact":
|
||||
last_turn_results = _process_interact()
|
||||
return run_state.recent_events(last_turn_results.size())
|
||||
&"rest":
|
||||
last_turn_results = _process_rest()
|
||||
return run_state.recent_events(last_turn_results.size())
|
||||
_:
|
||||
last_turn_results = []
|
||||
return _record_unavailable_action(action)
|
||||
@@ -153,7 +165,7 @@ func _record_unavailable_action(action: PlayerAction) -> Array[GameEvent]:
|
||||
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()))
|
||||
hud.refresh(game_state, run_state.recent_events(run_state.log.size()), run_state)
|
||||
return events
|
||||
|
||||
func get_game_state() -> GameState:
|
||||
@@ -170,16 +182,86 @@ func get_actor_cell_rect(actor_id: StringName) -> Rect2:
|
||||
return Rect2()
|
||||
|
||||
func _process_interact() -> Array[TurnResult]:
|
||||
if game_state.get_context_target() == &"exit_reached":
|
||||
return _refresh_hud_for_context()
|
||||
return _resolve_player_action(game_state.try_interact(), false)
|
||||
if _is_down_stairs() and not run_state.current_floor_deadline().can_descend():
|
||||
var deadline := run_state.current_floor_deadline()
|
||||
var blocked := _deadline_result(
|
||||
&"stairs_refused",
|
||||
"Les escaliers refusent de s’activer : encore %d jour(s) avant leur ouverture." % deadline.days_until_stairs_open()
|
||||
)
|
||||
_resolve_player_action([blocked], false)
|
||||
return [blocked]
|
||||
if _is_bed():
|
||||
return _process_rest()
|
||||
var results := game_state.try_interact()
|
||||
_resolve_player_action(results, false)
|
||||
if not results.is_empty() and results[0].kind == &"stairs_used":
|
||||
_transition_floor(results[0].from_cell)
|
||||
return results
|
||||
|
||||
func _refresh_hud_for_context() -> Array[TurnResult]:
|
||||
hud.refresh(game_state, run_state.recent_events(run_state.log.size()))
|
||||
return []
|
||||
func _process_rest() -> Array[TurnResult]:
|
||||
if not _is_bed():
|
||||
var refused := _deadline_result(&"rest_refused", "Il faut un lit pour se reposer. Cherchez-en un dans une salle sécurisée.")
|
||||
_resolve_player_action([refused], false)
|
||||
return [refused]
|
||||
var deadline := run_state.current_floor_deadline()
|
||||
var deadline_events := deadline.rest()
|
||||
var message := "Vous vous reposez. -1 jour avant l’effondrement de l’étage."
|
||||
if deadline_events.has(&"floor_collapsed"):
|
||||
message += " L’étage commence à s’effondrer !"
|
||||
elif deadline_events.has(&"deadline_warning"):
|
||||
message += " Compte à rebours critique."
|
||||
var result := _deadline_result(&"rested", message)
|
||||
_resolve_player_action([result], false)
|
||||
return [result]
|
||||
|
||||
func advance_floor_deadline(seconds: float) -> Array[TurnResult]:
|
||||
var deadline := run_state.current_floor_deadline()
|
||||
var deadline_events := deadline.advance_real_seconds(seconds)
|
||||
var results: Array[TurnResult] = []
|
||||
if deadline_events.has(&"deadline_day_elapsed"):
|
||||
results.append(_deadline_result(&"deadline_day_elapsed", "Une heure de jeu s’est écoulée : un jour de moins avant l’effondrement."))
|
||||
if deadline_events.has(&"deadline_warning"):
|
||||
results.append(_deadline_result(&"deadline_warning", "Compte à rebours critique : cet étage va bientôt s’effondrer."))
|
||||
if deadline_events.has(&"floor_collapsed"):
|
||||
results.append(_deadline_result(&"floor_collapsed", "Le compte à rebours est écoulé. L’étage commence à s’effondrer !"))
|
||||
if not results.is_empty():
|
||||
_resolve_player_action(results, false)
|
||||
return results
|
||||
|
||||
func _is_down_stairs() -> bool:
|
||||
return game_state.map.get_cell(game_state.player.cell) == GridMapStateType.CellKind.STAIRS and not (game_state.floor_state.floor_number > 0 and game_state.player.cell == game_state.floor_state.entrance)
|
||||
|
||||
func _is_bed() -> bool:
|
||||
return game_state.map.get_cell(game_state.player.cell) == GridMapStateType.CellKind.BED
|
||||
|
||||
func _deadline_result(kind: StringName, message: String) -> TurnResult:
|
||||
return TurnResult.new(game_state.player.id, kind, game_state.player.cell, game_state.player.cell, &"", 0, message)
|
||||
|
||||
func _transition_floor(stairs_cell: Vector2i) -> void:
|
||||
var transition := floor_transition.transition(run_state, game_state.floor_state, stairs_cell)
|
||||
var destination: FloorState = transition["floor"]
|
||||
game_state.set_floor_state(destination)
|
||||
game_state.player.cell = transition["arrival"]
|
||||
game_state.update_exploration()
|
||||
map_renderer.set_map(game_state.map)
|
||||
_sync_map_renderer_visibility()
|
||||
player_view.set_actor(game_state.player)
|
||||
_sync_camera_to_player()
|
||||
_sync_enemy_views()
|
||||
hud.refresh(game_state, run_state.recent_events(run_state.log.size()), run_state)
|
||||
|
||||
func _process_action(direction: Vector2i) -> Array[TurnResult]:
|
||||
return _resolve_player_action(game_state.try_player_action(direction), true)
|
||||
var results := game_state.try_player_action(direction)
|
||||
_append_collapse_damage(results)
|
||||
return _resolve_player_action(results, true)
|
||||
|
||||
func _append_collapse_damage(results: Array[TurnResult]) -> void:
|
||||
var deadline := run_state.current_floor_deadline()
|
||||
if deadline.tick() != &"collapse_damage":
|
||||
return
|
||||
var damage := mini(FloorDeadline.COLLAPSE_DAMAGE_PER_TURN, game_state.player.hit_points)
|
||||
game_state.player.hit_points = maxi(0, game_state.player.hit_points - damage)
|
||||
results.append(TurnResult.new(game_state.player.id, &"collapse_damage", game_state.player.cell, game_state.player.cell, &"", damage, "L’étage s’effondre autour de vous ! -%d PV." % damage))
|
||||
|
||||
# TurnResult remains the public prototype seam. RunState is the authoritative
|
||||
# journal: results from one resolved player action are converted and appended once,
|
||||
@@ -193,7 +275,7 @@ func _resolve_player_action(results: Array[TurnResult], sync_camera: bool) -> Ar
|
||||
var events := _record_events(results)
|
||||
event_presenter.enqueue(events)
|
||||
event_presenter.present_next()
|
||||
hud.refresh(game_state, run_state.recent_events(run_state.log.size()))
|
||||
hud.refresh(game_state, run_state.recent_events(run_state.log.size()), run_state)
|
||||
return results
|
||||
|
||||
func _record_events(results: Array[TurnResult]) -> Array[GameEvent]:
|
||||
|
||||
@@ -7,9 +7,11 @@ const SUPPORTED_CATALOGS := {
|
||||
"spells.json": "spell",
|
||||
"loot_tables.json": "loot_table",
|
||||
"npcs.json": "npc",
|
||||
"traps.json": "trap",
|
||||
}
|
||||
const SUPPORTED_DIRECTORY_CATALOGS := {
|
||||
"quests": "quest",
|
||||
"events": "event",
|
||||
}
|
||||
|
||||
static func load_directory(path: String) -> Dictionary:
|
||||
@@ -51,7 +53,7 @@ static func _load_file(path: String, relative_path: String, result: Dictionary)
|
||||
if file == null:
|
||||
result.diagnostics.append("Unable to read content file: %s" % relative_path)
|
||||
return
|
||||
var parsed := JSON.parse_string(file.get_as_text())
|
||||
var parsed: Variant = JSON.parse_string(file.get_as_text())
|
||||
if parsed == null:
|
||||
result.diagnostics.append("Invalid JSON content file: %s" % relative_path)
|
||||
return
|
||||
|
||||
@@ -4,18 +4,24 @@ extends CanvasLayer
|
||||
const DOOR_PROMPT := "Espace — Ouvrir la porte"
|
||||
const CHEST_PROMPT := "Espace — Ouvrir le coffre"
|
||||
const STAIRS_PROMPT := "Espace — Descendre l’escalier"
|
||||
const STAIRS_UP_PROMPT := "Espace — Monter l’escalier"
|
||||
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 deadline_label: Label = $DeadlineLabel
|
||||
@onready var enemy_health_label: Label = $EnemyHealthLabel
|
||||
@onready var combat_summary_label: Label = $CombatSummaryLabel
|
||||
@onready var event_log: RichTextLabel = $EventLog
|
||||
@onready var context_prompt_label: Label = $ContextPromptLabel
|
||||
var combat_summary := ""
|
||||
var _state: GameState
|
||||
var _run_state: RunState
|
||||
|
||||
func refresh(state: GameState, events: Array[GameEvent] = []) -> void:
|
||||
func refresh(state: GameState, events: Array[GameEvent] = [], run_state: RunState = null) -> void:
|
||||
_state = state
|
||||
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]
|
||||
if state.enemies.has(&"goblin"):
|
||||
var goblin: ActorState = state.enemies[&"goblin"]
|
||||
@@ -25,6 +31,7 @@ func refresh(state: GameState, events: Array[GameEvent] = []) -> void:
|
||||
enemy_health_label.text = "No active target"
|
||||
combat_summary = "No active target"
|
||||
combat_summary_label.text = combat_summary
|
||||
deadline_label.text = _deadline_status()
|
||||
context_prompt_label.text = get_context_prompt()
|
||||
# The supplied RunState journal events are the only source for journal text.
|
||||
event_log.clear()
|
||||
@@ -40,8 +47,27 @@ func get_context_prompt() -> String:
|
||||
&"closed_door":
|
||||
return DOOR_PROMPT
|
||||
&"stairs":
|
||||
if _state.floor_state.floor_number > 0 and _state.player.cell == _state.floor_state.entrance:
|
||||
return STAIRS_UP_PROMPT
|
||||
if _run_state != null:
|
||||
var deadline := _run_state.current_floor_deadline()
|
||||
if not deadline.can_descend():
|
||||
return "Escaliers verrouillés — encore %d jour(s) avant l’ouverture" % deadline.days_until_stairs_open()
|
||||
return STAIRS_PROMPT
|
||||
&"bed":
|
||||
return BED_PROMPT
|
||||
&"exit_reached":
|
||||
return EXIT_REACHED_PROMPT
|
||||
_:
|
||||
return ""
|
||||
|
||||
func _deadline_status() -> String:
|
||||
if _run_state == null:
|
||||
return ""
|
||||
var deadline := _run_state.current_floor_deadline()
|
||||
var status := "Étage %d — %d jour(s) avant l’effondrement" % [_run_state.current_floor, deadline.remaining_days()]
|
||||
if deadline.collapsing:
|
||||
return status + " — EFFONDREMENT"
|
||||
if deadline.can_descend():
|
||||
return status + " — escaliers ouverts"
|
||||
return status + " — escaliers dans %d jour(s)" % deadline.days_until_stairs_open()
|
||||
|
||||
@@ -14,6 +14,8 @@ const TEXTURES := {
|
||||
GridMapStateType.CellKind.CLOSED_DOOR: preload("res://assets/dcss/closed_door.png"),
|
||||
GridMapStateType.CellKind.CHEST: preload("res://assets/dcss/chest.png"),
|
||||
GridMapStateType.CellKind.STAIRS: preload("res://assets/dcss/stairs.png"),
|
||||
# B6 has no distinct bed sprite yet; a bed remains visibly traversable.
|
||||
GridMapStateType.CellKind.BED: preload("res://assets/dcss/floor.png"),
|
||||
}
|
||||
|
||||
var map: GridMapState
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
extends GutTest
|
||||
|
||||
const GameScene = preload("res://scenes/Game.tscn")
|
||||
|
||||
func test_current_game_event_and_hud_remain_available_with_attributes_domain_loaded() -> void:
|
||||
var game := GameScene.instantiate() as Game
|
||||
add_child_autofree(game)
|
||||
await get_tree().process_frame
|
||||
|
||||
var state := game.get_game_state()
|
||||
state.enemies[&"goblin"].cell = state.player.cell + Vector2i.RIGHT
|
||||
game.submit_test_action(Vector2i.RIGHT)
|
||||
await get_tree().process_frame
|
||||
|
||||
var hud := game.get_node("HUD") as GameHud
|
||||
assert_eq(state.enemies[&"goblin"].hit_points, 3)
|
||||
assert_true(game.get_run_state().recent_events(2).any(func(event: GameEvent) -> bool: return event.kind == &"melee"))
|
||||
assert_true(hud.player_health_label.text.contains("Player HP:"))
|
||||
assert_true(hud.event_log.get_parsed_text().contains("You strike the goblin"))
|
||||
@@ -0,0 +1 @@
|
||||
uid://cglna5tkvvmyo
|
||||
@@ -41,9 +41,12 @@ func test_real_input_opens_door_then_chest_and_preserves_stairs_route() -> void:
|
||||
for keycode in [KEY_UP, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_UP, KEY_UP]:
|
||||
game._unhandled_input(_key_event(keycode))
|
||||
assert_eq(state.player.cell, Vector2i(18, 4))
|
||||
game.get_run_state().current_floor_deadline().turns_remaining = 2 * FloorDeadline.TURNS_PER_DAY
|
||||
hud.refresh(state, [], game.get_run_state())
|
||||
assert_eq(prompt_label.text, "Espace — Descendre l’escalier")
|
||||
game._unhandled_input(_key_event(KEY_SPACE))
|
||||
assert_true(state.exit_reached)
|
||||
assert_eq(game.get_run_state().current_floor, 1)
|
||||
assert_eq(game.get_game_state().player.cell, game.get_game_state().floor_state.entrance)
|
||||
assert_string_contains(event_log.get_parsed_text(), "You descend the stairs.")
|
||||
|
||||
func _key_event(keycode: Key) -> InputEventKey:
|
||||
|
||||
@@ -8,7 +8,7 @@ func before_each() -> void:
|
||||
add_child_autofree(game)
|
||||
await get_tree().process_frame
|
||||
|
||||
func test_real_input_event_completes_door_to_stairs_exit_without_replacing_the_current_map() -> void:
|
||||
func test_real_input_event_completes_door_to_stairs_descent_and_arrives_on_floor_one() -> void:
|
||||
var state := game.get_game_state()
|
||||
var hud := game.get_node("HUD") as GameHud
|
||||
var prompt_label := game.get_node("HUD/ContextPromptLabel") as Label
|
||||
@@ -27,18 +27,20 @@ func test_real_input_event_completes_door_to_stairs_exit_without_replacing_the_c
|
||||
game._unhandled_input(_key_event(keycode))
|
||||
|
||||
assert_eq(state.player.cell, Vector2i(18, 4))
|
||||
game.get_run_state().current_floor_deadline().turns_remaining = 2 * FloorDeadline.TURNS_PER_DAY
|
||||
hud.refresh(state, [], game.get_run_state())
|
||||
assert_eq(hud.get_context_prompt(), "Espace — Descendre l’escalier")
|
||||
game._unhandled_input(_key_event(KEY_E))
|
||||
|
||||
assert_true(state.exit_reached)
|
||||
assert_eq(hud.get_context_prompt(), "Sortie atteinte — prochain étage bientôt disponible")
|
||||
assert_eq(prompt_label.text, "Sortie atteinte — prochain étage bientôt disponible")
|
||||
assert_eq(game.get_run_state().current_floor, 1)
|
||||
assert_eq(hud.get_context_prompt(), "Espace — Monter l’escalier")
|
||||
assert_eq(prompt_label.text, "Espace — Monter l’escalier")
|
||||
assert_string_contains(event_log.get_parsed_text(), "You open the door.")
|
||||
assert_string_contains(event_log.get_parsed_text(), "You descend the stairs.")
|
||||
assert_same(state.map, initial_map)
|
||||
assert_eq(state.map.size, initial_map_size)
|
||||
assert_eq(state.map.get_cell(Vector2i(18, 4)), GridMapState.CellKind.STAIRS)
|
||||
assert_eq(state.player.cell, Vector2i(18, 4))
|
||||
assert_ne(state.map, initial_map)
|
||||
assert_ne(state.map.size, initial_map_size)
|
||||
assert_eq(initial_map.get_cell(Vector2i(18, 4)), GridMapState.CellKind.STAIRS)
|
||||
assert_eq(state.player.cell, state.floor_state.entrance)
|
||||
|
||||
func _key_event(keycode: Key) -> InputEventKey:
|
||||
var event := InputEventKey.new()
|
||||
|
||||
@@ -31,13 +31,15 @@ func test_real_game_exposes_door_and_stairs_prompts_with_help_and_event_log() ->
|
||||
|
||||
state.map.set_cell(Vector2i(4, 11), GridMapState.CellKind.FLOOR)
|
||||
state.player.cell = Vector2i(18, 4)
|
||||
hud.refresh(state)
|
||||
game.get_run_state().current_floor_deadline().turns_remaining = 2 * FloorDeadline.TURNS_PER_DAY
|
||||
hud.refresh(state, [], game.get_run_state())
|
||||
assert_eq(hud.get_context_prompt(), "Espace — Descendre l’escalier")
|
||||
assert_eq(prompt_label.text, "Espace — Descendre l’escalier")
|
||||
var stairs_results := game.submit_test_interact()
|
||||
assert_eq(stairs_results[0].kind, &"stairs_used")
|
||||
assert_eq(hud.get_context_prompt(), "Sortie atteinte — prochain étage bientôt disponible")
|
||||
assert_eq(prompt_label.text, "Sortie atteinte — prochain étage bientôt disponible")
|
||||
assert_eq(game.get_run_state().current_floor, 1)
|
||||
assert_eq(hud.get_context_prompt(), "Espace — Monter l’escalier")
|
||||
assert_eq(prompt_label.text, "Espace — Monter l’escalier")
|
||||
|
||||
var results := game.submit_test_action(Vector2i.LEFT)
|
||||
assert_eq(results[0].kind, &"moved")
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
extends GutTest
|
||||
|
||||
const MainMenuScene = preload("res://scenes/menu/MainMenu.tscn")
|
||||
var menu: MainMenu
|
||||
|
||||
func before_each() -> void:
|
||||
menu = MainMenuScene.instantiate()
|
||||
add_child_autofree(menu)
|
||||
await get_tree().process_frame
|
||||
await get_tree().process_frame
|
||||
|
||||
func test_actual_menu_new_run_descends_to_generated_floor_one_and_returns_to_surface() -> void:
|
||||
await _click_button(menu.get_node("Menu/Layout/NewRunButton") as Button)
|
||||
var creation := menu.get_node("CharacterCreation") as CharacterCreation
|
||||
(creation.get_node("Panel/Layout/Fields/SeedEdit") as LineEdit).text = "B5-MENU-E2E"
|
||||
await _click_button(creation.get_node("Panel/Layout/Actions/StartRunButton") as Button)
|
||||
await get_tree().process_frame
|
||||
|
||||
var game := menu.get_node("Game") as Game
|
||||
assert_not_null(game)
|
||||
assert_eq(game.get_run_state().current_floor, 0)
|
||||
var surface := game.get_game_state().floor_state
|
||||
assert_true(surface.metadata.get("hand_authored", false))
|
||||
game.get_game_state().player.cell = surface.exit
|
||||
game.get_run_state().current_floor_deadline().turns_remaining = 2 * FloorDeadline.TURNS_PER_DAY
|
||||
game.submit_test_interact()
|
||||
await get_tree().process_frame
|
||||
|
||||
var first_floor := game.get_game_state().floor_state
|
||||
assert_eq(game.get_run_state().current_floor, 1)
|
||||
assert_false(first_floor.metadata.get("hand_authored", false))
|
||||
assert_eq(game.get_game_state().player.cell, first_floor.entrance)
|
||||
assert_eq(first_floor.map.get_cell(first_floor.entrance), GridMapState.CellKind.STAIRS)
|
||||
assert_eq((game.get_node("HUD") as GameHud).get_context_prompt(), "Espace — Monter l’escalier")
|
||||
game.get_game_state().player.cell = first_floor.entrance
|
||||
game.submit_test_interact()
|
||||
await get_tree().process_frame
|
||||
|
||||
assert_string_contains((game.get_node("HUD/EventLog") as RichTextLabel).get_parsed_text(), "You ascend the stairs.")
|
||||
assert_eq(game.get_run_state().current_floor, 0)
|
||||
assert_same(game.get_game_state().floor_state, surface)
|
||||
assert_eq(game.get_game_state().player.cell, surface.exit)
|
||||
|
||||
func _click_button(button: Button) -> void:
|
||||
assert_not_null(button)
|
||||
assert_true(button.visible)
|
||||
var click_position := button.get_global_rect().get_center()
|
||||
get_tree().root.push_input(_mouse_motion_event(click_position), true)
|
||||
await get_tree().process_frame
|
||||
get_tree().root.push_input(_mouse_button_event(click_position, true), true)
|
||||
await get_tree().process_frame
|
||||
get_tree().root.push_input(_mouse_button_event(click_position, false), true)
|
||||
await get_tree().process_frame
|
||||
|
||||
func _mouse_motion_event(position: Vector2) -> InputEventMouseMotion:
|
||||
var event := InputEventMouseMotion.new()
|
||||
event.position = position
|
||||
event.global_position = position
|
||||
return event
|
||||
|
||||
func _mouse_button_event(position: Vector2, pressed: bool) -> InputEventMouseButton:
|
||||
var event := InputEventMouseButton.new()
|
||||
event.position = position
|
||||
event.global_position = position
|
||||
event.button_index = MOUSE_BUTTON_LEFT
|
||||
event.button_mask = MOUSE_BUTTON_MASK_LEFT if pressed else 0
|
||||
event.pressed = pressed
|
||||
return event
|
||||
@@ -0,0 +1 @@
|
||||
uid://ctrkpp7a6m58j
|
||||
@@ -0,0 +1,40 @@
|
||||
extends GutTest
|
||||
|
||||
const GameScene = preload("res://scenes/Game.tscn")
|
||||
var game: Game
|
||||
|
||||
func before_each() -> void:
|
||||
game = GameScene.instantiate()
|
||||
add_child_autofree(game)
|
||||
await get_tree().process_frame
|
||||
|
||||
func test_real_game_early_down_stairs_are_blocked_then_rest_makes_descent_eligible() -> void:
|
||||
var state := game.get_game_state()
|
||||
var hud := game.get_node("HUD") as GameHud
|
||||
var prompt_label := game.get_node("HUD/ContextPromptLabel") as Label
|
||||
var log := game.get_node("HUD/EventLog") as RichTextLabel
|
||||
state.enemies.clear()
|
||||
state.player.cell = state.floor_state.exit
|
||||
|
||||
assert_string_contains(hud.get_context_prompt(), "encore 13 jour")
|
||||
game._unhandled_input(_key_event(KEY_E))
|
||||
assert_eq(game.get_run_state().current_floor, 0)
|
||||
assert_eq(prompt_label.text, hud.get_context_prompt())
|
||||
assert_string_contains(log.get_parsed_text(), "Les escaliers refusent")
|
||||
assert_string_contains(log.get_parsed_text(), "13 jour")
|
||||
|
||||
game.advance_floor_deadline(13 * FloorDeadline.REAL_SECONDS_PER_DAY)
|
||||
assert_eq(game.get_run_state().deadline_for(0).remaining_days(), 2)
|
||||
assert_eq(hud.get_context_prompt(), "Espace — Descendre l’escalier")
|
||||
|
||||
game._unhandled_input(_key_event(KEY_E))
|
||||
assert_eq(game.get_run_state().current_floor, 1)
|
||||
assert_eq(state.player.cell, state.floor_state.entrance)
|
||||
assert_eq(hud.get_context_prompt(), "Espace — Monter l’escalier")
|
||||
|
||||
func _key_event(keycode: Key) -> InputEventKey:
|
||||
var event := InputEventKey.new()
|
||||
event.keycode = keycode
|
||||
event.physical_keycode = keycode
|
||||
event.pressed = true
|
||||
return event
|
||||
@@ -0,0 +1 @@
|
||||
uid://br1b1ews1owee
|
||||
@@ -8,7 +8,9 @@ const SUPPORTED_CATALOGS := {
|
||||
"spells.json": "spell",
|
||||
"loot_tables.json": "loot_table",
|
||||
"npcs.json": "npc",
|
||||
"traps.json": "trap",
|
||||
"quests": "quest",
|
||||
"events": "event",
|
||||
}
|
||||
|
||||
func test_every_supported_ascii_id_has_exactly_one_catalog_entry() -> void:
|
||||
@@ -23,7 +25,7 @@ func test_every_supported_ascii_id_has_exactly_one_catalog_entry() -> void:
|
||||
|
||||
func _source_ids(source_path: String) -> Array[StringName]:
|
||||
var ids: Array[StringName] = []
|
||||
if source_path == "quests":
|
||||
if source_path in ["quests", "events"]:
|
||||
var directory := DirAccess.open(ASCII_DATA_PATH.path_join(source_path))
|
||||
directory.list_dir_begin()
|
||||
var filename := directory.get_next()
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
extends GutTest
|
||||
|
||||
const Attributes = preload("res://scripts/domain/entities/attributes.gd")
|
||||
const PlayerState = preload("res://scripts/domain/entities/player_state.gd")
|
||||
const ActorState = preload("res://scripts/domain/actor_state.gd")
|
||||
const GameState = preload("res://scripts/domain/game_state.gd")
|
||||
const GridMapState = preload("res://scripts/domain/grid_map_state.gd")
|
||||
|
||||
func test_player_state_adapter_preserves_actor_and_game_state_contract() -> void:
|
||||
var player := PlayerState.new({"id": &"player", "cell": Vector2i(2, 2), "attributes": Attributes.new({"end": 5})})
|
||||
var actor := player.as_actor_state(3)
|
||||
var map := GridMapState.new(Vector2i(5, 5), GridMapState.CellKind.FLOOR)
|
||||
var state := GameState.new(map, actor, {})
|
||||
|
||||
assert_true(actor is ActorState)
|
||||
assert_eq(actor.id, &"player")
|
||||
assert_eq(actor.cell, Vector2i(2, 2))
|
||||
assert_eq(actor.hit_points, player.hit_points)
|
||||
assert_eq(actor.max_hit_points, player.max_hp())
|
||||
assert_eq(actor.attack_damage, 3)
|
||||
assert_eq(state.player, actor)
|
||||
@@ -0,0 +1 @@
|
||||
uid://1rgi8tkrgnlu
|
||||
@@ -0,0 +1,65 @@
|
||||
extends GutTest
|
||||
|
||||
const ContentCatalogType = preload("res://scripts/domain/content/content_catalog.gd")
|
||||
const FloorGeneratorType = preload("res://scripts/domain/world/floor_generator.gd")
|
||||
const GridMapStateType = preload("res://scripts/domain/grid_map_state.gd")
|
||||
|
||||
const ASCII_CATALOG_PATH := "res://data/ascii"
|
||||
const CARDINAL_DIRECTIONS := [Vector2i.LEFT, Vector2i.RIGHT, Vector2i.UP, Vector2i.DOWN]
|
||||
|
||||
func test_one_hundred_seeds_have_safe_catalog_backed_reachable_population() -> void:
|
||||
var catalog := ContentCatalogType.load_from_directory(ASCII_CATALOG_PATH)
|
||||
assert_eq(Array(catalog.get_diagnostics()), [])
|
||||
|
||||
for seed_index in range(100):
|
||||
var floor := FloorGeneratorType.generate("B4-safety-%03d" % seed_index, 1 + seed_index % 10, catalog)
|
||||
var reachable := _reachable_cells_treating_closed_doors_openable(floor.map, floor.entrance)
|
||||
var occupied: Dictionary[Vector2i, bool] = {}
|
||||
|
||||
assert_false(_has_blocking_occupant_at(floor, floor.entrance), "seed %d keeps entrance clear" % seed_index)
|
||||
assert_false(_has_blocking_occupant_at(floor, floor.exit), "seed %d keeps exit clear" % seed_index)
|
||||
assert_true(reachable.has(floor.exit), "seed %d keeps exit reachable" % seed_index)
|
||||
|
||||
for enemy in floor.enemies.values():
|
||||
assert_ne(catalog.get_enemy(enemy.content_id), {}, "seed %d enemy is catalog backed" % seed_index)
|
||||
assert_lte(int(catalog.get_enemy(enemy.content_id).get("min_floor", 1)), floor.floor_number)
|
||||
_assert_valid_unique_reachable_cell(floor, enemy.cell, occupied, reachable, seed_index)
|
||||
for npc in floor.npcs.values():
|
||||
assert_ne(catalog.get_npc(npc.content_id), {}, "seed %d NPC is catalog backed" % seed_index)
|
||||
_assert_valid_unique_reachable_cell(floor, npc.cell, occupied, reachable, seed_index)
|
||||
for cell in floor.chests:
|
||||
assert_ne(catalog.get_loot_table(StringName(floor.chests[cell]["loot_table_id"])), {})
|
||||
_assert_valid_unique_reachable_cell(floor, cell, occupied, reachable, seed_index)
|
||||
for cell in floor.traps:
|
||||
assert_ne(catalog.get_trap(StringName(floor.traps[cell]["trap_id"])), {})
|
||||
_assert_valid_unique_reachable_cell(floor, cell, occupied, reachable, seed_index)
|
||||
for event in floor.events:
|
||||
assert_ne(catalog.get_event(StringName(event["event_id"])), {})
|
||||
var cell_data: Array = event["cell"]
|
||||
_assert_valid_unique_reachable_cell(floor, Vector2i(int(cell_data[0]), int(cell_data[1])), occupied, reachable, seed_index)
|
||||
|
||||
func _assert_valid_unique_reachable_cell(floor: FloorState, cell: Vector2i, occupied: Dictionary[Vector2i, bool], reachable: Dictionary[Vector2i, bool], seed_index: int) -> void:
|
||||
assert_false(occupied.has(cell), "seed %d has no overlapping population" % seed_index)
|
||||
occupied[cell] = true
|
||||
assert_ne(cell, floor.entrance)
|
||||
assert_ne(cell, floor.exit)
|
||||
assert_true(reachable.has(cell), "seed %d population is reachable" % seed_index)
|
||||
assert_eq(floor.map.get_cell(cell), GridMapStateType.CellKind.FLOOR)
|
||||
|
||||
func _has_blocking_occupant_at(floor: FloorState, cell: Vector2i) -> bool:
|
||||
for actor in floor.enemies.values() + floor.npcs.values():
|
||||
if actor.cell == cell:
|
||||
return true
|
||||
return floor.chests.has(cell) or floor.traps.has(cell)
|
||||
|
||||
func _reachable_cells_treating_closed_doors_openable(map: GridMapState, start: Vector2i) -> Dictionary[Vector2i, bool]:
|
||||
var reachable: Dictionary[Vector2i, bool] = {start: true}
|
||||
var frontier: Array[Vector2i] = [start]
|
||||
while not frontier.is_empty():
|
||||
var current := frontier.pop_front()
|
||||
for direction in CARDINAL_DIRECTIONS:
|
||||
var next_cell: Vector2i = current + direction
|
||||
if (map.is_walkable(next_cell) or map.get_cell(next_cell) == GridMapStateType.CellKind.CLOSED_DOOR) and not reachable.has(next_cell):
|
||||
reachable[next_cell] = true
|
||||
frontier.append(next_cell)
|
||||
return reachable
|
||||
@@ -0,0 +1 @@
|
||||
uid://dfpcbrduher8h
|
||||
@@ -0,0 +1,48 @@
|
||||
extends GutTest
|
||||
|
||||
const AttributesType = preload("res://scripts/domain/entities/attributes.gd")
|
||||
const PlayerStateType = preload("res://scripts/domain/entities/player_state.gd")
|
||||
const StatusEffectType = preload("res://scripts/domain/combat/status_effect.gd")
|
||||
const ConditionEngineType = preload("res://scripts/domain/combat/condition_engine.gd")
|
||||
|
||||
func test_data_backed_primary_attributes_skills_and_derived_resources() -> void:
|
||||
var attributes := AttributesType.new({"end": 6, "wil": 7, "str_": 5})
|
||||
var player := PlayerStateType.new({"attributes": attributes, "skills": {"traps": 4}, "level": 3})
|
||||
|
||||
assert_eq(player.max_hp(), 102)
|
||||
assert_eq(player.max_focus(), 56)
|
||||
assert_eq(player.effective_attribute(&"str_"), 5)
|
||||
assert_eq(player.effective_skill(&"traps"), 4)
|
||||
|
||||
func test_effective_attributes_combine_equipment_and_active_status_modifiers() -> void:
|
||||
var player := PlayerStateType.new({"attributes": {"str_": 4}})
|
||||
player.equipment_attribute_modifiers = {&"str_": 3}
|
||||
player.apply_status(StatusEffectType.new(&"wounded", 2))
|
||||
player.apply_status(StatusEffectType.new(&"strengthened", 2))
|
||||
|
||||
assert_eq(player.effective_attribute(&"str_"), 8)
|
||||
|
||||
func test_condition_engine_evaluates_content_conditions_and_reports_unknown_conditions() -> void:
|
||||
var player := PlayerStateType.new({"attributes": {"per": 6}, "skills": {"traps": 8}, "level": 4})
|
||||
player.flags[&"terminal_open"] = true
|
||||
var engine := ConditionEngineType.new()
|
||||
var context := {"player": player, "payload": {"method": "ranged", "tags": ["narrative"]}}
|
||||
|
||||
assert_true(engine.evaluate({"type": "all", "conds": [
|
||||
{"type": "attr", "attr": "per", "min": 6},
|
||||
{"type": "skill", "skill": "traps", "min": 8},
|
||||
{"type": "level", "min": 4},
|
||||
{"type": "flag", "flag": "terminal_open", "equals": true},
|
||||
{"type": "payload_equals", "key": "method", "value": "ranged"},
|
||||
{"type": "payload_contains", "key": "tags", "value": "narrative"},
|
||||
]}, context))
|
||||
engine.apply_effects([
|
||||
{"type": "set_flag", "flag": "rewarded"},
|
||||
{"type": "add_attr", "attr": "per", "amount": 1},
|
||||
{"type": "add_skill", "skill": "traps", "amount": 1},
|
||||
], context)
|
||||
assert_true(player.flags[&"rewarded"])
|
||||
assert_eq(player.effective_attribute(&"per"), 7)
|
||||
assert_eq(player.effective_skill(&"traps"), 9)
|
||||
assert_false(engine.evaluate({"type": "not_a_content_condition"}, context))
|
||||
assert_true(engine.diagnostics.find("Unknown condition type: not_a_content_condition") >= 0)
|
||||
@@ -0,0 +1 @@
|
||||
uid://b45kschi80lx7
|
||||
@@ -12,6 +12,12 @@ func test_item_fixture_preserves_rusty_sword_fields() -> void:
|
||||
assert_eq(sword.get("rarity"), "commun")
|
||||
assert_eq(sword.get("damage"), 6)
|
||||
|
||||
func test_catalog_exposes_ascii_traps_and_events() -> void:
|
||||
var catalog := ContentCatalog.load_from_directory("res://data/ascii")
|
||||
|
||||
assert_ne(catalog.get_trap(&"trap_spikes"), {})
|
||||
assert_ne(catalog.get_event(&"event_narrative_note"), {})
|
||||
|
||||
func test_missing_required_id_records_explicit_diagnostic() -> void:
|
||||
var catalog := ContentCatalog.load_from_directory("res://tests/fixtures/content_loader_missing_id")
|
||||
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
extends GutTest
|
||||
|
||||
const RunSettingsType = preload("res://scripts/domain/run/run_settings.gd")
|
||||
const RunStateType = preload("res://scripts/domain/run/run_state.gd")
|
||||
const FloorDeadlinePath := "res://scripts/domain/run/floor_deadline.gd"
|
||||
|
||||
func test_ascii_deadline_days_increase_by_five_for_each_dungeon_floor() -> void:
|
||||
var deadline_script := load(FloorDeadlinePath)
|
||||
assert_not_null(deadline_script, "B6 must provide the per-floor deadline domain model")
|
||||
if deadline_script == null:
|
||||
return
|
||||
var first_floor = deadline_script.new(1)
|
||||
var second_floor = deadline_script.new(2)
|
||||
|
||||
assert_eq(first_floor.turns_remaining, 15 * first_floor.TURNS_PER_DAY)
|
||||
assert_eq(second_floor.turns_remaining, 20 * second_floor.TURNS_PER_DAY)
|
||||
assert_eq(first_floor.remaining_days(), 15)
|
||||
|
||||
func test_rest_costs_one_day_warns_once_and_deadline_then_collapses() -> void:
|
||||
var deadline_script := load(FloorDeadlinePath)
|
||||
assert_not_null(deadline_script, "B6 must provide rest/deadline rules")
|
||||
if deadline_script == null:
|
||||
return
|
||||
var deadline = deadline_script.new(1)
|
||||
deadline.turns_remaining = 2 * deadline.TURNS_PER_DAY
|
||||
|
||||
var rest_events: Array[StringName] = deadline.rest()
|
||||
assert_eq(deadline.turns_remaining, deadline.TURNS_PER_DAY)
|
||||
assert_has(rest_events, &"deadline_warning")
|
||||
assert_false(deadline.collapsing)
|
||||
|
||||
var collapse_events: Array[StringName] = deadline.rest()
|
||||
assert_eq(deadline.turns_remaining, 0)
|
||||
assert_true(deadline.collapsing)
|
||||
assert_has(collapse_events, &"floor_collapsed")
|
||||
assert_eq(deadline.tick(), &"collapse_damage")
|
||||
|
||||
func test_explicit_real_time_seam_consumes_only_full_days_and_opens_stairs_at_two_days() -> void:
|
||||
var deadline_script := load(FloorDeadlinePath)
|
||||
assert_not_null(deadline_script, "B6 must provide a deterministic real-time seam")
|
||||
if deadline_script == null:
|
||||
return
|
||||
var deadline = deadline_script.new(1)
|
||||
|
||||
deadline.advance_real_seconds(deadline.REAL_SECONDS_PER_DAY * 12 + deadline.REAL_SECONDS_PER_DAY - 1)
|
||||
assert_eq(deadline.remaining_days(), 3)
|
||||
assert_false(deadline.can_descend())
|
||||
deadline.advance_real_seconds(1)
|
||||
assert_eq(deadline.remaining_days(), 2)
|
||||
assert_true(deadline.can_descend())
|
||||
|
||||
func test_rest_requires_a_bed_and_bed_interaction_consumes_one_day() -> void:
|
||||
var game_scene := preload("res://scenes/Game.tscn")
|
||||
var game := game_scene.instantiate() as Game
|
||||
add_child_autofree(game)
|
||||
await get_tree().process_frame
|
||||
var state := game.get_game_state()
|
||||
var deadline := game.get_run_state().current_floor_deadline()
|
||||
var before := deadline.turns_remaining
|
||||
|
||||
game._unhandled_input(_key_event(KEY_H))
|
||||
assert_eq(deadline.turns_remaining, before)
|
||||
assert_string_contains((game.get_node("HUD/EventLog") as RichTextLabel).get_parsed_text(), "Il faut un lit")
|
||||
|
||||
state.map.set_cell(state.player.cell, GridMapState.CellKind.BED)
|
||||
game._unhandled_input(_key_event(KEY_E))
|
||||
assert_eq(deadline.turns_remaining, before - FloorDeadline.BED_REST_DAY_COST * FloorDeadline.TURNS_PER_DAY)
|
||||
assert_string_contains((game.get_node("HUD/EventLog") as RichTextLabel).get_parsed_text(), "Vous vous reposez")
|
||||
|
||||
func test_collapse_damages_the_player_on_the_next_gameplay_action() -> void:
|
||||
var game_scene := preload("res://scenes/Game.tscn")
|
||||
var game := game_scene.instantiate() as Game
|
||||
add_child_autofree(game)
|
||||
await get_tree().process_frame
|
||||
var state := game.get_game_state()
|
||||
state.enemies.clear()
|
||||
var deadline := game.get_run_state().current_floor_deadline()
|
||||
deadline.turns_remaining = 0
|
||||
deadline.collapsing = true
|
||||
var before := state.player.hit_points
|
||||
|
||||
game.submit_test_action(Vector2i.RIGHT)
|
||||
|
||||
assert_eq(state.player.hit_points, before - FloorDeadline.COLLAPSE_DAMAGE_PER_TURN)
|
||||
assert_string_contains((game.get_node("HUD/EventLog") as RichTextLabel).get_parsed_text(), "L’étage s’effondre")
|
||||
|
||||
func test_run_state_keeps_independent_deadline_state_for_each_floor() -> void:
|
||||
var deadline_script := load(FloorDeadlinePath)
|
||||
assert_not_null(deadline_script, "B6 must persist deadline state in RunState by floor")
|
||||
if deadline_script == null:
|
||||
return
|
||||
var run := RunStateType.new("B6-persistence", RunSettingsType.new("B6-persistence"))
|
||||
var first = run.ensure_floor_deadline(1)
|
||||
first.rest()
|
||||
var second = run.ensure_floor_deadline(2)
|
||||
|
||||
assert_same(run.deadline_for(1), first)
|
||||
assert_eq(run.deadline_for(1).remaining_days(), 14)
|
||||
assert_eq(second.remaining_days(), 20)
|
||||
|
||||
func _key_event(keycode: Key) -> InputEventKey:
|
||||
var event := InputEventKey.new()
|
||||
event.keycode = keycode
|
||||
event.physical_keycode = keycode
|
||||
event.pressed = true
|
||||
return event
|
||||
@@ -0,0 +1 @@
|
||||
uid://bv747te1tt53k
|
||||
@@ -0,0 +1,131 @@
|
||||
extends GutTest
|
||||
|
||||
const ContentCatalogType = preload("res://scripts/domain/content/content_catalog.gd")
|
||||
const FloorGeneratorType = preload("res://scripts/domain/world/floor_generator.gd")
|
||||
const FloorPopulatorType = preload("res://scripts/domain/world/floor_populator.gd")
|
||||
const SpawnRulesType = preload("res://scripts/domain/world/spawn_rules.gd")
|
||||
const FloorStateType = preload("res://scripts/domain/world/floor_state.gd")
|
||||
const GridMapStateType = preload("res://scripts/domain/grid_map_state.gd")
|
||||
const RoomStateType = preload("res://scripts/domain/world/room_state.gd")
|
||||
|
||||
const ASCII_CATALOG_PATH := "res://data/ascii"
|
||||
const ROLE_KINDS := [&"entrance", &"combat", &"boss", &"arena", &"treasure", &"trap", &"shop", &"guild", &"sanctuary", &"refuge", &"narrative", &"mystery", &"puzzle"]
|
||||
|
||||
func test_population_is_deterministic_for_an_identical_seed_and_catalog() -> void:
|
||||
var catalog := ContentCatalogType.load_from_directory(ASCII_CATALOG_PATH)
|
||||
var first := FloorGeneratorType.generate("B4-identical", 3, catalog)
|
||||
var second := FloorGeneratorType.generate("B4-identical", 3, catalog)
|
||||
|
||||
assert_eq(first.to_dict(), second.to_dict())
|
||||
|
||||
func test_population_varies_with_the_seed() -> void:
|
||||
var catalog := ContentCatalogType.load_from_directory(ASCII_CATALOG_PATH)
|
||||
var first := FloorGeneratorType.generate("B4-variation-a", 3, catalog)
|
||||
var second := FloorGeneratorType.generate("B4-variation-b", 3, catalog)
|
||||
|
||||
assert_ne(_population_snapshot(first), _population_snapshot(second))
|
||||
|
||||
func test_spawn_rules_filter_enemies_by_minimum_floor() -> void:
|
||||
var catalog := ContentCatalogType.load_from_directory(ASCII_CATALOG_PATH)
|
||||
var first_floor := SpawnRulesType.eligible_enemies(catalog, 1)
|
||||
var late_floor := SpawnRulesType.eligible_enemies(catalog, 20)
|
||||
|
||||
assert_gt(first_floor.size(), 0)
|
||||
assert_gt(late_floor.size(), first_floor.size())
|
||||
for definition: Dictionary in first_floor:
|
||||
assert_lte(int(definition.get("min_floor", 1)), 1)
|
||||
|
||||
func test_role_population_uses_catalog_content_and_respects_reserved_cells() -> void:
|
||||
var catalog := ContentCatalogType.load_from_directory(ASCII_CATALOG_PATH)
|
||||
var floor := _role_fixture_floor()
|
||||
|
||||
FloorPopulatorType.populate(floor, catalog, "B4-role-contract")
|
||||
|
||||
assert_eq(floor.enemies.size(), 3, "combat, boss, and arena rooms receive enemies")
|
||||
assert_eq(floor.chests.size(), 1, "treasure rooms receive a chest")
|
||||
assert_eq(floor.traps.size(), 1, "trap rooms receive a trap")
|
||||
assert_eq(floor.npcs.size(), 4, "shop, guild, sanctuary, and refuge rooms receive NPC records")
|
||||
assert_eq(floor.events.size(), 3, "narrative, mystery, and puzzle rooms receive event records")
|
||||
assert_eq(_npc_content_ids(floor, &"shop"), [&"npc_wandering_merchant"])
|
||||
assert_eq(_npc_content_ids(floor, &"guild"), [&"npc_guild_keeper"])
|
||||
_assert_all_records_are_catalog_backed(catalog, floor)
|
||||
_assert_reserved_cells_are_clear_and_all_occupants_are_distinct(floor)
|
||||
|
||||
func _role_fixture_floor() -> FloorState:
|
||||
var map := GridMapStateType.new(Vector2i(96, 12), GridMapStateType.CellKind.WALL)
|
||||
var floor := FloorStateType.new(map, 44, 3)
|
||||
for index in range(ROLE_KINDS.size()):
|
||||
var bounds := Rect2i(Vector2i(1 + index * 7, 3), Vector2i(5, 5))
|
||||
var room := RoomStateType.new(StringName("room_%02d" % index), bounds, ROLE_KINDS[index])
|
||||
floor.rooms.append(room)
|
||||
for y in range(bounds.position.y, bounds.end.y):
|
||||
for x in range(bounds.position.x, bounds.end.x):
|
||||
var cell := Vector2i(x, y)
|
||||
map.set_cell(cell, GridMapStateType.CellKind.FLOOR)
|
||||
map.set_room_id(cell, room.id)
|
||||
floor.entrance = _room_center(floor.rooms[0].bounds)
|
||||
floor.exit = _room_center(floor.rooms[1].bounds)
|
||||
map.set_cell(floor.exit, GridMapStateType.CellKind.STAIRS)
|
||||
return floor
|
||||
|
||||
func _population_snapshot(floor: FloorState) -> Dictionary:
|
||||
return {
|
||||
"enemies": floor.to_dict()["enemies"],
|
||||
"npcs": floor.to_dict()["npcs"],
|
||||
"chests": floor.to_dict()["chests"],
|
||||
"traps": floor.to_dict()["traps"],
|
||||
"events": floor.events,
|
||||
}
|
||||
|
||||
func _npc_content_ids(floor: FloorState, room_kind: StringName) -> Array[StringName]:
|
||||
var ids: Array[StringName] = []
|
||||
for npc in floor.npcs.values():
|
||||
if _room_for_cell(floor, npc.cell).kind == room_kind:
|
||||
ids.append(npc.content_id)
|
||||
ids.sort()
|
||||
return ids
|
||||
|
||||
func _assert_all_records_are_catalog_backed(catalog: ContentCatalog, floor: FloorState) -> void:
|
||||
for enemy in floor.enemies.values():
|
||||
assert_ne(catalog.get_enemy(enemy.content_id), {})
|
||||
assert_lte(int(catalog.get_enemy(enemy.content_id).get("min_floor", 1)), floor.floor_number)
|
||||
for npc in floor.npcs.values():
|
||||
assert_ne(catalog.get_npc(npc.content_id), {})
|
||||
for chest in floor.chests.values():
|
||||
assert_ne(catalog.get_loot_table(StringName(chest["loot_table_id"])), {})
|
||||
for trap in floor.traps.values():
|
||||
assert_ne(catalog.get_trap(StringName(trap["trap_id"])), {})
|
||||
for event in floor.events:
|
||||
assert_ne(catalog.get_event(StringName(event["event_id"])), {})
|
||||
|
||||
func _assert_reserved_cells_are_clear_and_all_occupants_are_distinct(floor: FloorState) -> void:
|
||||
var occupied: Dictionary[Vector2i, bool] = {}
|
||||
for actor in floor.enemies.values() + floor.npcs.values():
|
||||
assert_false(occupied.has(actor.cell), "actor cells do not overlap")
|
||||
occupied[actor.cell] = true
|
||||
for cell in floor.chests:
|
||||
assert_false(occupied.has(cell), "chests do not overlap actors or each other")
|
||||
occupied[cell] = true
|
||||
for cell in floor.traps:
|
||||
assert_false(occupied.has(cell), "traps do not overlap any other occupant")
|
||||
occupied[cell] = true
|
||||
for event in floor.events:
|
||||
var cell := _event_cell(event)
|
||||
assert_false(occupied.has(cell), "events do not overlap any other occupant")
|
||||
occupied[cell] = true
|
||||
assert_false(occupied.has(floor.entrance))
|
||||
assert_false(occupied.has(floor.exit))
|
||||
|
||||
func _event_cell(event: Dictionary) -> Vector2i:
|
||||
var serialized: Array = event["cell"]
|
||||
return Vector2i(int(serialized[0]), int(serialized[1]))
|
||||
|
||||
func _room_for_cell(floor: FloorState, cell: Vector2i) -> RoomState:
|
||||
var room_id := floor.map.get_room_id(cell)
|
||||
for room in floor.rooms:
|
||||
if room.id == room_id:
|
||||
return room
|
||||
return null
|
||||
|
||||
func _room_center(bounds: Rect2i) -> Vector2i:
|
||||
return bounds.position + Vector2i(bounds.size.x / 2, bounds.size.y / 2)
|
||||
@@ -0,0 +1 @@
|
||||
uid://dnrqxd18bgmdm
|
||||
@@ -18,9 +18,10 @@ func test_floor_state_round_trip_preserves_rooms_tiles_and_floor_collections() -
|
||||
floor.rooms.append(RoomStateType.new(&"exit", Rect2i(5, 3, 2, 2), &"combat"))
|
||||
floor.entrance = Vector2i(2, 2)
|
||||
floor.exit = Vector2i(6, 4)
|
||||
floor.enemies[&"goblin"] = ActorStateType.new(&"goblin", Vector2i(5, 4), 6, 2)
|
||||
floor.npcs[&"guide"] = ActorStateType.new(&"guide", Vector2i(3, 3), 9, 0)
|
||||
floor.enemies[&"goblin"] = ActorStateType.new(&"goblin", Vector2i(5, 4), 6, 2, &"enemy_goblin")
|
||||
floor.npcs[&"guide"] = ActorStateType.new(&"guide", Vector2i(3, 3), 9, 0, &"npc_guide_mordecai")
|
||||
floor.chests[Vector2i(3, 2)] = {"opened": false, "loot": [{"id": "potion_minor", "quantity": 2}]}
|
||||
floor.traps[Vector2i(3, 3)] = {"trap_id": "trap_spikes"}
|
||||
floor.ground_items[Vector2i(4, 2)] = [{"id": "gold", "quantity": 10}]
|
||||
floor.events.append({"id": "entry_event", "resolved": false})
|
||||
floor.explored_cells[Vector2i(2, 2)] = true
|
||||
@@ -45,10 +46,13 @@ func test_floor_state_round_trip_preserves_rooms_tiles_and_floor_collections() -
|
||||
assert_eq(restored.entrance, Vector2i(2, 2))
|
||||
assert_eq(restored.exit, Vector2i(6, 4))
|
||||
assert_eq(restored.enemies[&"goblin"].cell, Vector2i(5, 4))
|
||||
assert_eq(restored.enemies[&"goblin"].content_id, &"enemy_goblin")
|
||||
assert_eq(restored.npcs[&"guide"].cell, Vector2i(3, 3))
|
||||
assert_eq(restored.npcs[&"guide"].content_id, &"npc_guide_mordecai")
|
||||
assert_true(restored.entities.has(&"goblin"))
|
||||
assert_false(restored.entities.has(&"guide"))
|
||||
assert_eq(restored.chests[Vector2i(3, 2)], {"opened": false, "loot": [{"id": "potion_minor", "quantity": 2}]})
|
||||
assert_eq(restored.traps[Vector2i(3, 3)], {"trap_id": "trap_spikes"})
|
||||
assert_eq(restored.ground_items[Vector2i(4, 2)], [{"id": "gold", "quantity": 10}])
|
||||
assert_eq(restored.events, [{"id": "entry_event", "resolved": false}])
|
||||
assert_eq(restored.explored_cells[Vector2i(2, 2)], true)
|
||||
|
||||
@@ -22,7 +22,8 @@ func test_context_prompt_describes_stairs_under_player_and_nothing_else() -> voi
|
||||
|
||||
state.map.set_cell(Vector2i(4, 11), GridMapState.CellKind.FLOOR)
|
||||
state.player.cell = Vector2i(18, 4)
|
||||
hud.refresh(state)
|
||||
game.get_run_state().current_floor_deadline().turns_remaining = 2 * FloorDeadline.TURNS_PER_DAY
|
||||
hud.refresh(state, [], game.get_run_state())
|
||||
assert_eq(hud.get_context_prompt(), "Espace — Descendre l’escalier")
|
||||
|
||||
state.map.set_cell(state.player.cell, GridMapState.CellKind.FLOOR)
|
||||
|
||||
@@ -48,7 +48,7 @@ func test_stairs_usage_triggers_exactly_one_enemy_response_without_transitioning
|
||||
assert_eq(state.player.cell, stairs)
|
||||
assert_same(state.map, map)
|
||||
|
||||
func test_stairs_usage_refreshes_exact_exit_prompt_and_writes_the_journal() -> void:
|
||||
func test_stairs_usage_transitions_to_floor_one_and_writes_the_journal() -> void:
|
||||
var game := GameScene.instantiate() as Game
|
||||
add_child_autofree(game)
|
||||
await get_tree().process_frame
|
||||
@@ -58,11 +58,13 @@ func test_stairs_usage_refreshes_exact_exit_prompt_and_writes_the_journal() -> v
|
||||
var event_log := game.get_node("HUD/EventLog") as RichTextLabel
|
||||
state.map.set_cell(Vector2i(4, 11), GridMapState.CellKind.FLOOR)
|
||||
state.player.cell = Vector2i(18, 4)
|
||||
game.get_run_state().current_floor_deadline().turns_remaining = 2 * FloorDeadline.TURNS_PER_DAY
|
||||
|
||||
var results := game.submit_test_interact()
|
||||
|
||||
assert_eq(results[0].kind, &"stairs_used")
|
||||
assert_true(state.exit_reached)
|
||||
assert_eq(hud.get_context_prompt(), "Sortie atteinte — prochain étage bientôt disponible")
|
||||
assert_eq(prompt_label.text, "Sortie atteinte — prochain étage bientôt disponible")
|
||||
assert_eq(game.get_run_state().current_floor, 1)
|
||||
assert_eq(game.get_game_state().player.cell, game.get_game_state().floor_state.entrance)
|
||||
assert_eq(hud.get_context_prompt(), "Espace — Monter l’escalier")
|
||||
assert_eq(prompt_label.text, "Espace — Monter l’escalier")
|
||||
assert_string_contains(event_log.get_parsed_text(), "You descend the stairs.")
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
extends GutTest
|
||||
|
||||
const PlayerStateType = preload("res://scripts/domain/entities/player_state.gd")
|
||||
const StatusEffectType = preload("res://scripts/domain/combat/status_effect.gd")
|
||||
|
||||
func test_status_uses_data_default_duration_and_refreshes_without_stacking() -> void:
|
||||
var player := PlayerStateType.new()
|
||||
player.apply_status(StatusEffectType.new(&"poison"))
|
||||
player.apply_status(StatusEffectType.new(&"poison", 6, 5))
|
||||
|
||||
assert_eq(player.status_effects.size(), 1)
|
||||
assert_eq(player.status_effects[0].duration, 6)
|
||||
assert_eq(player.status_effects[0].magnitude, 5)
|
||||
|
||||
func test_status_tick_applies_effect_before_expiring_and_reports_tick() -> void:
|
||||
var player := PlayerStateType.new({"attributes": {"end": 4}})
|
||||
player.hit_points = 20
|
||||
player.apply_status(StatusEffectType.new(&"poison", 2))
|
||||
player.apply_status(StatusEffectType.new(&"regenerating", 1))
|
||||
|
||||
var ticks := player.tick_status_effects()
|
||||
|
||||
assert_eq(player.hit_points, 21)
|
||||
assert_eq(ticks.size(), 2)
|
||||
assert_eq(ticks[0]["hit_point_delta"], -3)
|
||||
assert_eq(ticks[1]["hit_point_delta"], 4)
|
||||
assert_eq(player.status_effects.size(), 1)
|
||||
assert_eq(player.status_effects[0].key, &"poison")
|
||||
assert_eq(player.status_effects[0].duration, 1)
|
||||
|
||||
func test_expired_status_is_removed_after_its_final_tick() -> void:
|
||||
var player := PlayerStateType.new()
|
||||
player.apply_status(StatusEffectType.new(&"stunned", 1))
|
||||
|
||||
player.tick_status_effects()
|
||||
|
||||
assert_false(player.has_status(&"stunned"))
|
||||
@@ -0,0 +1 @@
|
||||
uid://jbbilbj72nq4
|
||||
@@ -0,0 +1,66 @@
|
||||
extends GutTest
|
||||
|
||||
const ContentCatalogType = preload("res://scripts/domain/content/content_catalog.gd")
|
||||
const SurfaceGeneratorType = preload("res://scripts/domain/world/surface_generator.gd")
|
||||
const FloorTransitionType = preload("res://scripts/domain/run/floor_transition.gd")
|
||||
const RunStateType = preload("res://scripts/domain/run/run_state.gd")
|
||||
const GridMapStateType = preload("res://scripts/domain/grid_map_state.gd")
|
||||
|
||||
const ASCII_CATALOG_PATH := "res://data/ascii"
|
||||
|
||||
func test_floor_zero_is_hand_authored_and_floor_one_is_seed_floor_one_procedural() -> void:
|
||||
var catalog := ContentCatalogType.load_from_directory(ASCII_CATALOG_PATH)
|
||||
var run := RunStateType.new("B5-surface-contract")
|
||||
var transitions := FloorTransitionType.new(catalog)
|
||||
|
||||
var surface := transitions.initial_floor(run)
|
||||
var descend := transitions.transition(run, surface, surface.exit)
|
||||
var first_floor: FloorState = descend["floor"]
|
||||
|
||||
assert_eq(surface.floor_number, 0)
|
||||
assert_true(surface.metadata.get("hand_authored", false))
|
||||
assert_eq(surface.map.size, Vector2i(30, 20))
|
||||
assert_eq(surface.entrance, Vector2i(4, 12))
|
||||
assert_eq(surface.exit, Vector2i(18, 4))
|
||||
assert_eq(surface.map.get_cell(surface.exit), GridMapStateType.CellKind.STAIRS)
|
||||
assert_eq(first_floor.floor_number, 1)
|
||||
assert_false(first_floor.metadata.get("hand_authored", false))
|
||||
assert_eq(first_floor.seed, _seed_value("B5-surface-contract", 1))
|
||||
assert_eq(first_floor.map.get_cell(first_floor.entrance), GridMapStateType.CellKind.STAIRS)
|
||||
assert_eq(first_floor.map.get_cell(first_floor.exit), GridMapStateType.CellKind.STAIRS)
|
||||
assert_eq(descend["arrival"], first_floor.entrance)
|
||||
|
||||
var independently_authored := SurfaceGeneratorType.generate("another-seed")
|
||||
assert_eq(independently_authored.to_dict(), surface.to_dict(), "floor zero is authored rather than seed-generated")
|
||||
|
||||
func test_transition_cache_keeps_mutated_floor_state_and_arrival_cells_across_return_trip() -> void:
|
||||
var catalog := ContentCatalogType.load_from_directory(ASCII_CATALOG_PATH)
|
||||
var run := RunStateType.new("B5-cache-contract")
|
||||
var transitions := FloorTransitionType.new(catalog)
|
||||
var surface := transitions.initial_floor(run)
|
||||
var first_descent := transitions.transition(run, surface, surface.exit)
|
||||
var first_floor: FloorState = first_descent["floor"]
|
||||
first_floor.chests[Vector2i(3, 3)] = {"opened": true}
|
||||
first_floor.enemies.clear()
|
||||
first_floor.events.append({"id": "first-floor-event", "resolved": true})
|
||||
|
||||
var ascent := transitions.transition(run, first_floor, first_floor.entrance)
|
||||
var returned_surface: FloorState = ascent["floor"]
|
||||
returned_surface.map.set_cell(Vector2i(4, 7), GridMapStateType.CellKind.FLOOR)
|
||||
var second_descent := transitions.transition(run, returned_surface, returned_surface.exit)
|
||||
var cached_first_floor: FloorState = second_descent["floor"]
|
||||
|
||||
assert_same(returned_surface, surface)
|
||||
assert_eq(ascent["arrival"], surface.exit)
|
||||
assert_same(cached_first_floor, first_floor)
|
||||
assert_eq(second_descent["arrival"], first_floor.entrance)
|
||||
assert_eq(cached_first_floor.chests[Vector2i(3, 3)], {"opened": true})
|
||||
assert_eq(cached_first_floor.enemies.size(), 0)
|
||||
assert_true(cached_first_floor.events.has({"id": "first-floor-event", "resolved": true}))
|
||||
assert_eq(surface.map.get_cell(Vector2i(4, 7)), GridMapStateType.CellKind.FLOOR)
|
||||
|
||||
func _seed_value(seed: String, floor_number: int) -> int:
|
||||
var value := 0
|
||||
for index in range(seed.length()):
|
||||
value = (value * 31 + seed.unicode_at(index)) % 2147483647
|
||||
return value + floor_number
|
||||
@@ -0,0 +1 @@
|
||||
uid://20vpsc7klakm
|
||||
Reference in New Issue
Block a user