feat: complete playtest parity improvements
This commit is contained in:
@@ -3,33 +3,40 @@ extends RefCounted
|
||||
|
||||
const CompanionStateType = preload("res://scripts/domain/entities/companion_state.gd")
|
||||
const PathfindingType = preload("res://scripts/domain/ai/pathfinding.gd")
|
||||
const SUPPORT_HEAL_THRESHOLD := 0.5
|
||||
const SUPPORT_HEAL_RANGE := 4
|
||||
const SUPPORT_HEAL_AMOUNT := 2
|
||||
|
||||
static func decide(companion: CompanionState, player: ActorState, enemies: Dictionary[StringName, ActorState], map: GridMapState, blocked_cells: Dictionary[Vector2i, bool] = {}) -> Dictionary:
|
||||
static func decide(companion: CompanionState, player: ActorState, enemies: Dictionary[StringName, ActorState], map: GridMapState, blocked_cells: Dictionary[Vector2i, bool] = {}, detected_cells: Dictionary[Vector2i, bool] = {}) -> Dictionary:
|
||||
if companion == null or not companion.is_alive():
|
||||
return {"kind": &"idle"}
|
||||
match companion.stance:
|
||||
CompanionStateType.Stance.FOLLOW:
|
||||
match CompanionStateType.normalize_stance(companion.stance):
|
||||
CompanionStateType.Stance.STAY_BACK:
|
||||
return _follow(companion.actor, player, map, blocked_cells)
|
||||
CompanionStateType.Stance.DEFEND:
|
||||
CompanionStateType.Stance.DEFEND_ME:
|
||||
return _defend(companion.actor, player, enemies, map, blocked_cells)
|
||||
CompanionStateType.Stance.SUPPORT:
|
||||
return {"kind": &"idle"}
|
||||
CompanionStateType.Stance.ATTACK_ON_SIGHT:
|
||||
return _aggressive(companion.actor, player, enemies, map, blocked_cells, detected_cells)
|
||||
_:
|
||||
return {"kind": &"idle"}
|
||||
|
||||
static func _aggressive(actor: ActorState, player: ActorState, enemies: Dictionary[StringName, ActorState], map: GridMapState, blocked_cells: Dictionary[Vector2i, bool], detected_cells: Dictionary[Vector2i, bool]) -> Dictionary:
|
||||
var target := _nearest_enemy(actor.cell, enemies, detected_cells)
|
||||
if target == null:
|
||||
return _follow(actor, player, map, blocked_cells)
|
||||
if actor.cell.distance_to(target.cell) <= 1.5:
|
||||
return {"kind": &"melee", "target_id": target.id}
|
||||
return _move_toward(actor, target.cell, player.cell, map, blocked_cells)
|
||||
|
||||
static func _support(actor: ActorState, player: ActorState, map: GridMapState, blocked_cells: Dictionary[Vector2i, bool]) -> Dictionary:
|
||||
if player.is_alive() and float(player.hit_points) / float(maxi(1, player.effective_max_hit_points())) < SUPPORT_HEAL_THRESHOLD and actor.cell.distance_to(player.cell) <= SUPPORT_HEAL_RANGE:
|
||||
return {"kind": &"heal_player", "amount": SUPPORT_HEAL_AMOUNT}
|
||||
return _follow(actor, player, map, blocked_cells)
|
||||
|
||||
static func _follow(actor: ActorState, player: ActorState, map: GridMapState, blocked_cells: Dictionary[Vector2i, bool]) -> Dictionary:
|
||||
if actor.cell.distance_to(player.cell) <= 1.5:
|
||||
return {"kind": &"idle"}
|
||||
var occupied := blocked_cells.duplicate()
|
||||
occupied.erase(actor.cell)
|
||||
occupied[player.cell] = true
|
||||
var goals: Array[Vector2i] = []
|
||||
for direction: Vector2i in PathfindingType.CARDINAL_DIRECTIONS:
|
||||
var cell := player.cell + direction
|
||||
if map.is_walkable(cell) and not occupied.has(cell):
|
||||
goals.append(cell)
|
||||
var path := PathfindingType.find_path_to_any(map, actor.cell, goals, occupied)
|
||||
return {"kind": &"move", "to_cell": path.front()} if not path.is_empty() else {"kind": &"idle"}
|
||||
return _move_toward(actor, player.cell, player.cell, map, blocked_cells)
|
||||
|
||||
static func _defend(actor: ActorState, player: ActorState, enemies: Dictionary[StringName, ActorState], map: GridMapState, blocked_cells: Dictionary[Vector2i, bool]) -> Dictionary:
|
||||
var targets: Array[ActorState] = []
|
||||
@@ -37,6 +44,33 @@ static func _defend(actor: ActorState, player: ActorState, enemies: Dictionary[S
|
||||
if enemy.is_alive() and enemy.cell.distance_to(player.cell) <= 1.5:
|
||||
targets.append(enemy)
|
||||
targets.sort_custom(func(first: ActorState, second: ActorState) -> bool: return String(first.id) < String(second.id))
|
||||
if not targets.is_empty() and actor.cell.distance_to(targets[0].cell) <= 1.5:
|
||||
return {"kind": &"melee", "target_id": targets[0].id}
|
||||
if not targets.is_empty():
|
||||
if actor.cell.distance_to(targets[0].cell) <= 1.5:
|
||||
return {"kind": &"melee", "target_id": targets[0].id}
|
||||
return _move_toward(actor, targets[0].cell, player.cell, map, blocked_cells)
|
||||
return _follow(actor, player, map, blocked_cells)
|
||||
|
||||
static func _move_toward(actor: ActorState, destination: Vector2i, player_cell: Vector2i, map: GridMapState, blocked_cells: Dictionary[Vector2i, bool]) -> Dictionary:
|
||||
var occupied := blocked_cells.duplicate()
|
||||
occupied.erase(actor.cell)
|
||||
occupied[player_cell] = true
|
||||
occupied[destination] = true
|
||||
var goals: Array[Vector2i] = []
|
||||
for direction: Vector2i in PathfindingType.CARDINAL_DIRECTIONS:
|
||||
var cell := destination + direction
|
||||
if map.is_walkable(cell) and not occupied.has(cell):
|
||||
goals.append(cell)
|
||||
var path := PathfindingType.find_path_to_any(map, actor.cell, goals, occupied)
|
||||
return {"kind": &"move", "to_cell": path.front()} if not path.is_empty() else {"kind": &"idle"}
|
||||
|
||||
static func _nearest_enemy(origin: Vector2i, enemies: Dictionary[StringName, ActorState], detected_cells: Dictionary[Vector2i, bool]) -> ActorState:
|
||||
var candidates: Array[ActorState] = []
|
||||
for enemy: ActorState in enemies.values():
|
||||
if enemy.is_alive() and detected_cells.has(enemy.cell):
|
||||
candidates.append(enemy)
|
||||
candidates.sort_custom(func(first: ActorState, second: ActorState) -> bool:
|
||||
var first_distance := origin.distance_squared_to(first.cell)
|
||||
var second_distance := origin.distance_squared_to(second.cell)
|
||||
return String(first.id) < String(second.id) if first_distance == second_distance else first_distance < second_distance
|
||||
)
|
||||
return candidates[0] if not candidates.is_empty() else null
|
||||
|
||||
@@ -15,7 +15,8 @@ func _init(scripted_rolls: Array[float] = []) -> void:
|
||||
_rolls.assign(scripted_rolls)
|
||||
|
||||
func resolve_attack(attacker: ActorState, defender: ActorState, grant_xp: bool = true) -> Dictionary:
|
||||
var events: Array[Dictionary] = [_event(&"attack_started", attacker, defender, {"stance": String(attacker.stance)})]
|
||||
var attack_method := String(attacker.metadata.get("melee_weapon_name", "mains nues" if attacker.id == &"player" else "attaque naturelle"))
|
||||
var events: Array[Dictionary] = [_event(&"attack_started", attacker, defender, {"stance": String(attacker.stance), "attack_method": attack_method})]
|
||||
var attack_score := attacker.accuracy - attacker.wound_severity(&"arms") * ARM_WOUND_PENALTY
|
||||
var defense_score := defender.defense * 3 - defender.wound_severity(&"legs") * LEG_WOUND_PENALTY
|
||||
if defender.stance == &"dodge":
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
class_name HealthRegeneration
|
||||
extends RefCounted
|
||||
|
||||
const ENDURANCE_DIVISOR := 3
|
||||
const SKILL_AMPLIFIER := 0.15
|
||||
const DIFFICULTY_MULTIPLIERS := {
|
||||
&"touriste": 1.5,
|
||||
&"crawler": 1.0,
|
||||
&"veteran": 0.75,
|
||||
&"masochiste": 0.5,
|
||||
}
|
||||
|
||||
static func amount(endurance: int, regeneration_skill: int = 1, perk_bonus: int = 0, difficulty_id: StringName = &"crawler") -> int:
|
||||
var base := maxi(1, endurance / ENDURANCE_DIVISOR)
|
||||
var skill_bonus := maxi(0, regeneration_skill - 1)
|
||||
var total := float(base + maxi(0, perk_bonus)) * (1.0 + float(skill_bonus) * SKILL_AMPLIFIER)
|
||||
return maxi(0, int(total * float(DIFFICULTY_MULTIPLIERS.get(difficulty_id, 1.0))))
|
||||
|
||||
static func apply(actor: ActorState, endurance: int, regeneration_skill: int = 1, perk_bonus: int = 0, difficulty_id: StringName = &"crawler") -> int:
|
||||
if actor == null or not actor.is_alive():
|
||||
return 0
|
||||
var before := actor.hit_points
|
||||
actor.hit_points = mini(actor.effective_max_hit_points(), actor.hit_points + amount(endurance, regeneration_skill, perk_bonus, difficulty_id))
|
||||
return actor.hit_points - before
|
||||
@@ -0,0 +1 @@
|
||||
uid://3ccnf6g0ily8
|
||||
@@ -37,6 +37,9 @@ func resolve(map: GridMapState, attacker: ActorState, target: ActorState) -> Dic
|
||||
"events": events,
|
||||
}
|
||||
|
||||
func validation_reason(map: GridMapState, attacker: ActorState, target: ActorState) -> StringName:
|
||||
return _validation_reason(map, attacker, target)
|
||||
|
||||
func _validation_reason(map: GridMapState, attacker: ActorState, target: ActorState) -> StringName:
|
||||
if attacker == null or target == null or attacker == target or attacker.id == target.id or not target.is_alive():
|
||||
return &"invalid_target"
|
||||
|
||||
@@ -4,36 +4,70 @@ extends RefCounted
|
||||
# E4 deliberately owns only the companion's earned-XP ledger. F1 remains the
|
||||
# sole owner of level thresholds and character progression.
|
||||
class Stance:
|
||||
const STAY_BACK: StringName = &"stay_back"
|
||||
const DEFEND_ME: StringName = &"defend_me"
|
||||
const ATTACK_ON_SIGHT: StringName = &"attack_on_sight"
|
||||
# Legacy identifiers remain readable for code and saves created before the
|
||||
# player-facing behavior names were introduced.
|
||||
const FOLLOW: StringName = &"follow"
|
||||
const DEFEND: StringName = &"defend"
|
||||
const SUPPORT: StringName = &"support"
|
||||
|
||||
const ActorStateType = preload("res://scripts/domain/actor_state.gd")
|
||||
const ExperienceType = preload("res://scripts/domain/progression/experience.gd")
|
||||
const VALID_STANCES: Array[StringName] = [Stance.FOLLOW, Stance.DEFEND, Stance.SUPPORT]
|
||||
const VALID_STANCES: Array[StringName] = [Stance.STAY_BACK, Stance.DEFEND_ME, Stance.ATTACK_ON_SIGHT]
|
||||
|
||||
var choice_id: StringName
|
||||
var actor: ActorState
|
||||
var stance: StringName = Stance.FOLLOW
|
||||
var stance: StringName = Stance.STAY_BACK
|
||||
var name := "Familier"
|
||||
var species := "Animal"
|
||||
var endurance := 4
|
||||
var regeneration_skill := 1
|
||||
var regeneration_perk_bonus := 0
|
||||
|
||||
func _init(new_choice_id: StringName, new_actor: ActorState) -> void:
|
||||
choice_id = new_choice_id
|
||||
actor = new_actor
|
||||
|
||||
static func from_choice(new_choice_id: StringName, cell: Vector2i, hit_points: int = 8) -> CompanionState:
|
||||
static func from_choice(new_choice_id: StringName, cell: Vector2i, hit_points: int = 8, new_name: String = "Familier", new_species: String = "Animal") -> CompanionState:
|
||||
var id := new_choice_id if not new_choice_id.is_empty() else &"moth"
|
||||
var companion_actor := ActorStateType.new(&"companion", cell, maxi(1, hit_points), 3, id, {"accuracy": 30, "xp": 0})
|
||||
return CompanionState.new(id, companion_actor)
|
||||
var companion := CompanionState.new(id, companion_actor)
|
||||
companion.name = new_name.strip_edges() if not new_name.strip_edges().is_empty() else "Familier"
|
||||
companion.species = new_species.strip_edges() if not new_species.strip_edges().is_empty() else "Animal"
|
||||
return companion
|
||||
|
||||
func is_alive() -> bool:
|
||||
return actor != null and actor.is_alive()
|
||||
|
||||
func set_stance(new_stance: StringName) -> bool:
|
||||
if not new_stance in VALID_STANCES:
|
||||
var normalized := normalize_stance(new_stance)
|
||||
if not normalized in VALID_STANCES:
|
||||
return false
|
||||
stance = new_stance
|
||||
stance = normalized
|
||||
return true
|
||||
|
||||
static func normalize_stance(value: StringName) -> StringName:
|
||||
match value:
|
||||
Stance.FOLLOW, &"aggressif": return Stance.ATTACK_ON_SIGHT
|
||||
Stance.DEFEND, Stance.SUPPORT, &"defensif", &"soutien": return Stance.DEFEND_ME
|
||||
return value
|
||||
|
||||
static func stance_label(value: StringName) -> String:
|
||||
match normalize_stance(value):
|
||||
Stance.STAY_BACK: return "Reste en arrière"
|
||||
Stance.DEFEND_ME: return "Défends-moi"
|
||||
Stance.ATTACK_ON_SIGHT: return "Attaque à vue"
|
||||
return "Inconnu"
|
||||
|
||||
static func stance_description(value: StringName) -> String:
|
||||
match normalize_stance(value):
|
||||
Stance.STAY_BACK: return "Suit le joueur sans engager les ennemis."
|
||||
Stance.DEFEND_ME: return "Intercepte et attaque les ennemis qui menacent le joueur."
|
||||
Stance.ATTACK_ON_SIGHT: return "Poursuit et attaque l’ennemi visible le plus proche."
|
||||
return ""
|
||||
|
||||
# This is intentionally a neutral allocation seam: it records earned XP only
|
||||
# and neither reads nor changes levels, thresholds, attributes, or skills.
|
||||
func share_xp(player: ActorState, amount: int) -> Dictionary:
|
||||
|
||||
@@ -7,6 +7,7 @@ const TrapEngineType = preload("res://scripts/domain/world/trap_engine.gd")
|
||||
const SpecialInteractionsType = preload("res://scripts/domain/world/special_interactions.gd")
|
||||
const CompanionStateType = preload("res://scripts/domain/entities/companion_state.gd")
|
||||
const PartyStateType = preload("res://scripts/domain/entities/party_state.gd")
|
||||
const PLAYER_VISION_RADIUS := 6
|
||||
|
||||
var player: ActorState
|
||||
# E4 keeps the selected pet run-scoped rather than making it a floor entity.
|
||||
@@ -109,7 +110,7 @@ func compute_visible_cells(game_map: GridMapState, origin: Vector2i, radius: int
|
||||
return visible
|
||||
|
||||
func update_exploration() -> void:
|
||||
visible_cells = compute_visible_cells(map, player.cell, 6)
|
||||
visible_cells = compute_visible_cells(map, player.cell, PLAYER_VISION_RADIUS)
|
||||
for cell in visible_cells:
|
||||
explored_cells[cell] = true
|
||||
|
||||
|
||||
@@ -71,6 +71,11 @@ func recompute_player(player) -> void:
|
||||
player.normalize_resources()
|
||||
elif player is ActorState:
|
||||
player.recompute_equipment_modifiers(attributes, skills, combat)
|
||||
var main_hand := item_in_slot(&"main_hand")
|
||||
if main_hand != null and main_hand.definition != null and StringName(main_hand.definition.raw.get("weapon_kind", "")) != &"ranged":
|
||||
player.metadata["melee_weapon_name"] = main_hand.definition.name
|
||||
else:
|
||||
player.metadata.erase("melee_weapon_name")
|
||||
|
||||
func _accumulate_combat_modifiers(item: ItemInstance, combat: Dictionary[StringName, Variant]) -> void:
|
||||
var raw := item.definition.raw
|
||||
|
||||
@@ -92,6 +92,8 @@ func use_item(instance_id: StringName, default_target, identification: ItemIdent
|
||||
var status := StringName(effect_data.get("status", ""))
|
||||
recipient.apply_status(StatusEffect.new(status, int(effect_data.get("duration", -1)), int(effect_data.get("magnitude", 0)), item.definition.id))
|
||||
effects.append({"type": effect_type, "status": status})
|
||||
&"learn_spell":
|
||||
effects.append({"type": effect_type, "spell": StringName(effect_data.get("spell", ""))})
|
||||
_:
|
||||
effects.append({"type": effect_type})
|
||||
var consumed := remove_item(instance_id)
|
||||
|
||||
@@ -10,15 +10,21 @@ static func resolve(table: Dictionary, seed: String, context: String = "") -> Di
|
||||
var items: Array[Dictionary] = []
|
||||
var gold := 0
|
||||
var entries: Array = table.get("entries", [])
|
||||
var selected_item_ids: Dictionary[StringName, bool] = {}
|
||||
var rolls := maxi(0, int(table.get("rolls", 0)))
|
||||
for _roll in range(rolls):
|
||||
var entry := _choose_entry(entries, rng)
|
||||
var eligible_entries := entries.filter(func(value) -> bool:
|
||||
return not (value is Dictionary and value.has("item") and selected_item_ids.has(StringName(value.item)))
|
||||
)
|
||||
var entry := _choose_entry(eligible_entries, rng)
|
||||
if entry.is_empty():
|
||||
continue
|
||||
if bool(entry.get("gold", false)):
|
||||
gold += _range_value(entry, "min_gold", "max_gold", rng)
|
||||
elif entry.has("item"):
|
||||
_append_item(items, StringName(entry.item), _range_value(entry, "min_qty", "max_qty", rng, 1))
|
||||
var item_id := StringName(entry.item)
|
||||
selected_item_ids[item_id] = true
|
||||
_append_item(items, item_id, _range_value(entry, "min_qty", "max_qty", rng, 1))
|
||||
return {
|
||||
"items": items,
|
||||
"gold": gold,
|
||||
|
||||
@@ -33,6 +33,17 @@ func resolve(map: GridMapState, caster: ActorState, target: ActorState, spell: D
|
||||
var xp_event := _event(&"xp_granted", caster, target, spell, {})
|
||||
xp_event.payload = xp_payload
|
||||
events.append(xp_event)
|
||||
events.append({
|
||||
"kind": &"loot_dropped",
|
||||
"actor_id": target.id,
|
||||
"target_id": caster.id,
|
||||
"cell": target.cell,
|
||||
"payload": {
|
||||
"loot_table": String(target.loot_table),
|
||||
"actor_content_id": target.content_id,
|
||||
"target_content_id": caster.content_id,
|
||||
},
|
||||
})
|
||||
return {"valid": true, "reason": &"", "damage": damage, "events": events}
|
||||
|
||||
func valid_targets(map: GridMapState, caster: ActorState, enemies: Dictionary[StringName, ActorState], spell: Dictionary, spells: SpellState) -> Dictionary[StringName, Vector2i]:
|
||||
|
||||
@@ -33,7 +33,15 @@ func race_definitions() -> Array[Dictionary]:
|
||||
var definitions: Array[Dictionary] = []
|
||||
for id: StringName in _races:
|
||||
definitions.append(_races[id].duplicate(true))
|
||||
definitions.sort_custom(func(a: Dictionary, b: Dictionary) -> bool: return String(a.id) < String(b.id))
|
||||
definitions.sort_custom(func(a: Dictionary, b: Dictionary) -> bool: return String(a.get("name", a.id)) < String(b.get("name", b.id)))
|
||||
return definitions
|
||||
|
||||
func class_definitions(race_id: StringName = &"") -> Array[Dictionary]:
|
||||
var definitions: Array[Dictionary] = []
|
||||
for id: StringName in _classes:
|
||||
if race_id.is_empty() or is_compatible(race_id, id):
|
||||
definitions.append(_classes[id].duplicate(true))
|
||||
definitions.sort_custom(func(a: Dictionary, b: Dictionary) -> bool: return String(a.get("name", a.id)) < String(b.get("name", b.id)))
|
||||
return definitions
|
||||
|
||||
func is_compatible(race_id: StringName, class_id: StringName) -> bool:
|
||||
@@ -75,12 +83,32 @@ func apply_creation(player: PlayerState, race_id: StringName, class_id: StringNa
|
||||
var choice := creation_choice(race_id, class_id)
|
||||
if not bool(choice.get("accepted", false)):
|
||||
return choice
|
||||
var race := _races[race_id]
|
||||
var race_result := choose_race(player, race_id)
|
||||
if not bool(race_result.get("accepted", false)):
|
||||
return race_result
|
||||
return choose_class(player, class_id)
|
||||
|
||||
func choose_race(player: PlayerState, race_id: StringName) -> Dictionary:
|
||||
if player == null or not player.race.is_empty():
|
||||
return {"accepted": false, "reason": &"already_chosen"}
|
||||
if not _races.has(race_id):
|
||||
return {"accepted": false, "reason": &"unknown_race"}
|
||||
player.race = race_id
|
||||
_apply_bonuses(player, _races[race_id])
|
||||
return {"accepted": true, "race_id": race_id}
|
||||
|
||||
func choose_class(player: PlayerState, class_id: StringName) -> Dictionary:
|
||||
if player == null or not player.archetype.is_empty():
|
||||
return {"accepted": false, "reason": &"already_chosen"}
|
||||
if player.race.is_empty():
|
||||
return {"accepted": false, "reason": &"race_required"}
|
||||
if not _classes.has(class_id):
|
||||
return {"accepted": false, "reason": &"unknown_class"}
|
||||
if not is_compatible(player.race, class_id):
|
||||
return {"accepted": false, "reason": &"incompatible"}
|
||||
player.archetype = class_id
|
||||
_apply_bonuses(player, race)
|
||||
_apply_bonuses(player, _classes[class_id])
|
||||
return choice
|
||||
return {"accepted": true, "race_id": player.race, "class_id": class_id}
|
||||
|
||||
func eligible_evolutions(player: PlayerState) -> Array[Dictionary]:
|
||||
var eligible: Array[Dictionary] = []
|
||||
|
||||
@@ -7,17 +7,23 @@ var seed: String
|
||||
var difficulty_id: StringName
|
||||
var permadeath: bool
|
||||
var pet_enabled: bool
|
||||
var pet_name: String
|
||||
var pet_species: String
|
||||
|
||||
func _init(
|
||||
new_seed: String = "",
|
||||
new_difficulty_id: StringName = &"crawler",
|
||||
new_permadeath: bool = false,
|
||||
new_pet_enabled: bool = false
|
||||
new_pet_enabled: bool = false,
|
||||
new_pet_name: String = "Familier",
|
||||
new_pet_species: String = "Animal"
|
||||
) -> void:
|
||||
seed = new_seed.strip_edges()
|
||||
difficulty_id = new_difficulty_id
|
||||
permadeath = new_permadeath
|
||||
pet_enabled = new_pet_enabled
|
||||
pet_name = new_pet_name.strip_edges() if not new_pet_name.strip_edges().is_empty() else "Familier"
|
||||
pet_species = new_pet_species.strip_edges() if not new_pet_species.strip_edges().is_empty() else "Animal"
|
||||
|
||||
func is_valid() -> bool:
|
||||
return not seed.is_empty() and difficulty_id in DIFFICULTY_IDS
|
||||
|
||||
@@ -4,7 +4,7 @@ extends RefCounted
|
||||
var seed: String
|
||||
var settings: RunSettings
|
||||
var player_name := "Sans-Nom"
|
||||
var base_archetype: StringName = &"vanguard"
|
||||
var base_archetype: StringName = &""
|
||||
var current_floor := 0
|
||||
var floors: Dictionary[int, FloorState] = {}
|
||||
# Deadline records are intentionally independent from generated FloorState so
|
||||
|
||||
@@ -13,6 +13,15 @@ static func resolve_player_action(state: GameState, direction: Vector2i) -> Arra
|
||||
return results
|
||||
var player: ActorState = state.player
|
||||
var destination: Vector2i = player.cell + direction
|
||||
if abs(direction.x) == 1 and abs(direction.y) == 1:
|
||||
# Diagonal movement cannot squeeze between blocking cardinal cells. A
|
||||
# closed door must therefore gate the room instead of being bypassable at
|
||||
# either corner; walls and chests obey the same geometry.
|
||||
var horizontal := player.cell + Vector2i(direction.x, 0)
|
||||
var vertical := player.cell + Vector2i(0, direction.y)
|
||||
if not state.map.is_walkable(horizontal) or not state.map.is_walkable(vertical):
|
||||
results.append(TurnResultType.new(player.id, &"blocked", player.cell, destination, &"", 0, "Your way is blocked."))
|
||||
return results
|
||||
var enemy: ActorState = _enemy_at(state, destination)
|
||||
if enemy != null:
|
||||
# A companion-owning run takes the neutral shared-XP seam. Combat must
|
||||
@@ -89,7 +98,8 @@ static func append_enemy_response(state: GameState, results: Array[TurnResult])
|
||||
var enemy: ActorState = state.enemies.get(enemy_id)
|
||||
if enemy == null or not enemy.is_alive():
|
||||
continue
|
||||
var decision: Dictionary = EnemyBehaviorsType.decide(enemy, state.player, state.map, occupied)
|
||||
var target := _enemy_target(state, enemy)
|
||||
var decision: Dictionary = EnemyBehaviorsType.decide(enemy, target, state.map, occupied)
|
||||
if decision.has("diagnostic"):
|
||||
results.append(TurnResultType.new(
|
||||
enemy.id,
|
||||
@@ -103,25 +113,33 @@ static func append_enemy_response(state: GameState, results: Array[TurnResult])
|
||||
))
|
||||
match decision.get("kind", &"idle"):
|
||||
&"melee":
|
||||
if _support_companion_intercepts(state, enemy, results):
|
||||
if target == state.player and _support_companion_intercepts(state, enemy, results):
|
||||
continue
|
||||
_append_combat_results(results, CombatEngineType.new().resolve_attack(enemy, state.player), enemy.cell, state.player.cell)
|
||||
if not state.player.is_alive():
|
||||
_append_combat_results(results, CombatEngineType.new().resolve_attack(enemy, target), enemy.cell, target.cell)
|
||||
if target == state.player and not state.player.is_alive():
|
||||
return
|
||||
&"move":
|
||||
var target: Vector2i = decision.get("to_cell", enemy.cell)
|
||||
var move_target: Vector2i = decision.get("to_cell", enemy.cell)
|
||||
# The behavior contract has already rejected these cells; retain the
|
||||
# resolver guard as the authoritative state mutation boundary.
|
||||
if state.map.is_walkable(target) and target != state.player.cell and not occupied.has(target):
|
||||
if state.map.is_walkable(move_target) and move_target != target.cell and not occupied.has(move_target):
|
||||
var from: Vector2i = enemy.cell
|
||||
occupied.erase(from)
|
||||
enemy.cell = target
|
||||
occupied[target] = true
|
||||
results.append(TurnResultType.new(enemy.id, &"enemy_moved", from, target, &"", 0, "%s moves." % _actor_label(enemy.id)))
|
||||
enemy.cell = move_target
|
||||
occupied[move_target] = true
|
||||
results.append(TurnResultType.new(enemy.id, &"enemy_moved", from, move_target, &"", 0, "%s moves." % _actor_label(enemy.id)))
|
||||
|
||||
static func _enemy_target(state: GameState, enemy: ActorState) -> ActorState:
|
||||
var companion: CompanionState = state.companion
|
||||
if companion == null or not companion.is_alive():
|
||||
return state.player
|
||||
var player_distance := enemy.cell.distance_squared_to(state.player.cell)
|
||||
var companion_distance := enemy.cell.distance_squared_to(companion.actor.cell)
|
||||
return companion.actor if companion_distance <= player_distance else state.player
|
||||
|
||||
static func _support_companion_intercepts(state: GameState, enemy: ActorState, results: Array[TurnResult]) -> bool:
|
||||
var companion: CompanionState = state.companion
|
||||
if companion == null or not companion.is_alive() or companion.stance != CompanionStateType.Stance.SUPPORT:
|
||||
if companion == null or not companion.is_alive() or CompanionStateType.normalize_stance(companion.stance) != CompanionStateType.Stance.DEFEND_ME:
|
||||
return false
|
||||
if companion.actor.cell.distance_to(state.player.cell) > 1.5:
|
||||
return false
|
||||
@@ -143,7 +161,8 @@ static func _append_companion_response(state: GameState, results: Array[TurnResu
|
||||
return
|
||||
var occupied := _occupied_enemy_cells(state)
|
||||
occupied[companion.actor.cell] = true
|
||||
var decision := CompanionBehaviorsType.decide(companion, state.player, state.enemies, state.map, occupied)
|
||||
var detected_cells := state.compute_visible_cells(state.map, state.player.cell, state.PLAYER_VISION_RADIUS)
|
||||
var decision := CompanionBehaviorsType.decide(companion, state.player, state.enemies, state.map, occupied, detected_cells)
|
||||
match decision.get("kind", &"idle"):
|
||||
&"move":
|
||||
var target: Vector2i = decision.get("to_cell", companion.actor.cell)
|
||||
@@ -156,9 +175,15 @@ static func _append_companion_response(state: GameState, results: Array[TurnResu
|
||||
if enemy != null and enemy.is_alive() and companion.actor.cell.distance_to(enemy.cell) <= 1.5:
|
||||
_append_combat_results(results, CombatEngineType.new().resolve_attack(companion.actor, enemy), companion.actor.cell, enemy.cell)
|
||||
results.back().kind = &"companion_melee"
|
||||
results.back().message = "Your companion defends you."
|
||||
results.back().message = "%s attacks." % companion.name
|
||||
if not enemy.is_alive():
|
||||
state.enemies.erase(enemy.id)
|
||||
&"heal_player":
|
||||
var before := state.player.hit_points
|
||||
state.player.hit_points = mini(state.player.effective_max_hit_points(), before + int(decision.get("amount", 0)))
|
||||
var healed := state.player.hit_points - before
|
||||
if healed > 0:
|
||||
results.append(TurnResultType.new(companion.actor.id, &"companion_healed_player", companion.actor.cell, state.player.cell, state.player.id, -healed, "%s restores %d PV." % [companion.name, healed], {"healing": healed}))
|
||||
|
||||
static func _occupied_enemy_cells(state: GameState) -> Dictionary[Vector2i, bool]:
|
||||
var occupied: Dictionary[Vector2i, bool] = {state.player.cell: true}
|
||||
@@ -176,10 +201,11 @@ static func _append_combat_results(results: Array[TurnResult], outcome: Dictiona
|
||||
var target_id := StringName(first.target_id)
|
||||
var legacy_kind := &"melee" if actor_id == &"player" else &"enemy_melee"
|
||||
var damage := int(outcome.damage)
|
||||
var message := "You strike the goblin for %d." % damage if actor_id == &"player" else "%s hits you for %d." % [_actor_label(actor_id), damage]
|
||||
results.append(TurnResultType.new(actor_id, legacy_kind, from_cell, to_cell, target_id, damage, message, {"domain_events": descriptors}))
|
||||
var attack_method := String(first.payload.get("attack_method", "mains nues" if actor_id == &"player" else "attaque naturelle"))
|
||||
var message := "You strike the goblin with %s for %d." % [attack_method, damage] if actor_id == &"player" else "%s hits you with %s for %d." % [_actor_label(actor_id), attack_method, damage]
|
||||
results.append(TurnResultType.new(actor_id, legacy_kind, from_cell, to_cell, target_id, damage, message, {"domain_events": descriptors, "attack_method": attack_method}))
|
||||
if not bool(outcome.hit):
|
||||
results.back().message = "You miss the goblin." if actor_id == &"player" else "%s misses you." % _actor_label(actor_id)
|
||||
results.back().message = "You miss the goblin with %s." % attack_method if actor_id == &"player" else "%s misses you with %s." % [_actor_label(actor_id), attack_method]
|
||||
if not (results.back().payload.domain_events as Array).filter(func(event: Dictionary) -> bool: return event.kind == &"actor_died").is_empty():
|
||||
var defeated := target_id if actor_id == &"player" else actor_id
|
||||
results.append(TurnResultType.new(defeated, &"enemy_defeated", to_cell, to_cell, actor_id, 0, "%s is defeated." % _actor_label(defeated)))
|
||||
|
||||
@@ -3,8 +3,6 @@ extends RefCounted
|
||||
|
||||
const MAX_MAP_SIZE := Vector2i(700, 350)
|
||||
const MAX_ROOM_COUNT := 500
|
||||
const SHALLOW_ROOM_MIN_SIZE := Vector2i(5, 4)
|
||||
const SHALLOW_ROOM_MAX_SIZE := Vector2i(10, 8)
|
||||
const DEEP_ROOM_MIN_SIZE := Vector2i(4, 3)
|
||||
const DEEP_ROOM_MAX_SIZE := Vector2i(6, 5)
|
||||
const ROOM_PADDING := 2
|
||||
@@ -38,13 +36,6 @@ const EconomyType = preload("res://scripts/domain/items/economy.gd")
|
||||
# impractical. It is also the sole sizing input to generation, making a seed
|
||||
# and floor number reproduce exactly the same layout.
|
||||
static func generation_profile(floor_number: int) -> Dictionary:
|
||||
if floor_number <= 1:
|
||||
return {
|
||||
"map_size": Vector2i(80, 50),
|
||||
"target_room_count": 8,
|
||||
"room_min_size": SHALLOW_ROOM_MIN_SIZE,
|
||||
"room_max_size": SHALLOW_ROOM_MAX_SIZE,
|
||||
}
|
||||
var normalized_floor := maxi(1, floor_number)
|
||||
return {
|
||||
"map_size": Vector2i(
|
||||
@@ -75,6 +66,7 @@ static func generate(seed: String, floor_number: int, catalog: ContentCatalog) -
|
||||
graph.add_local_loops(rooms, rng)
|
||||
for edge in graph.loop_edges:
|
||||
_carve_l_corridor_preserving_doors(map, _room_center(rooms[edge.from].bounds), _room_center(rooms[edge.to].bounds))
|
||||
tree_door_cells = _remove_nonfunctional_doors(map, tree_door_cells)
|
||||
for serialized_door in tree_door_cells:
|
||||
map.set_cell(Vector2i(int(serialized_door[0]), int(serialized_door[1])), GridMapStateType.CellKind.CLOSED_DOOR)
|
||||
|
||||
@@ -176,6 +168,24 @@ static func _place_tree_boundary_doors(map: GridMapState, path: Array[Vector2i],
|
||||
break
|
||||
return serialized_cells
|
||||
|
||||
static func _remove_nonfunctional_doors(map: GridMapState, serialized_doors: Array[Array]) -> Array[Array]:
|
||||
var functional: Array[Array] = []
|
||||
for serialized_door: Array in serialized_doors:
|
||||
var cell := Vector2i(int(serialized_door[0]), int(serialized_door[1]))
|
||||
var walkable_directions: Array[Vector2i] = []
|
||||
for direction: Vector2i in [Vector2i.LEFT, Vector2i.RIGHT, Vector2i.UP, Vector2i.DOWN]:
|
||||
if map.is_walkable(cell + direction):
|
||||
walkable_directions.append(direction)
|
||||
var controls_straight_passage := walkable_directions.size() == 2 and (
|
||||
(walkable_directions.has(Vector2i.LEFT) and walkable_directions.has(Vector2i.RIGHT))
|
||||
or (walkable_directions.has(Vector2i.UP) and walkable_directions.has(Vector2i.DOWN))
|
||||
)
|
||||
if controls_straight_passage:
|
||||
functional.append(serialized_door)
|
||||
else:
|
||||
map.set_cell(cell, GridMapStateType.CellKind.FLOOR)
|
||||
return functional
|
||||
|
||||
static func _is_adjacent_to_serialized_door(cell: Vector2i, serialized_doors: Array[Array]) -> bool:
|
||||
for serialized_door in serialized_doors:
|
||||
var door_cell := Vector2i(int(serialized_door[0]), int(serialized_door[1]))
|
||||
|
||||
@@ -55,11 +55,10 @@ static func _spawn_enemy(floor: FloorState, catalog: ContentCatalog, room: RoomS
|
||||
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 definition := catalog.get_loot_table(&"floor_treasure")
|
||||
var cell := _available_cell(floor, room, rng, occupied)
|
||||
if definitions.is_empty() or cell == Vector2i(-1, -1):
|
||||
if definition.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,
|
||||
|
||||
@@ -3,44 +3,36 @@ 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")
|
||||
const RoomStateType = preload("res://scripts/domain/world/room_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.
|
||||
const SURFACE_SIZE := Vector2i(42, 16)
|
||||
const ENTRANCE := Vector2i(4, 7)
|
||||
const DOOR := Vector2i(36, 7)
|
||||
const EXIT := Vector2i(39, 7)
|
||||
|
||||
# The surface mirrors DCWASCII's current floor-zero contract: an empty authored
|
||||
# staging area, a straight corridor, one door, and the stairs to the procedural
|
||||
# dungeon. It intentionally contains no enemies, chest, deadline content, or
|
||||
# seed-dependent population.
|
||||
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 map := GridMapStateType.new(SURFACE_SIZE, GridMapStateType.CellKind.WALL)
|
||||
var entrance_room := RoomStateType.new(&"surface_entrance", Rect2i(2, 2, 18, 11), &"entrance")
|
||||
var landing := RoomStateType.new(&"surface_landing", Rect2i(37, 6, 4, 3), &"open")
|
||||
_carve_room(map, entrance_room.bounds)
|
||||
for x in range(20, DOOR.x):
|
||||
map.set_cell(Vector2i(x, ENTRANCE.y), GridMapStateType.CellKind.FLOOR)
|
||||
map.set_cell(DOOR, GridMapStateType.CellKind.CLOSED_DOOR)
|
||||
_carve_room(map, landing.bounds)
|
||||
map.set_cell(EXIT, 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)] = {
|
||||
"loot_table_id": &"floor1_reward",
|
||||
"opened": false,
|
||||
}
|
||||
floor.rooms = [entrance_room, landing]
|
||||
floor.entrance = ENTRANCE
|
||||
floor.exit = EXIT
|
||||
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):
|
||||
static func _carve_room(map: GridMapState, bounds: Rect2i) -> void:
|
||||
for y in range(bounds.position.y, bounds.end.y):
|
||||
for x in range(bounds.position.x, bounds.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)
|
||||
|
||||
@@ -50,12 +50,24 @@ static func trigger(floor: FloorState, player: ActorState, cell: Vector2i, catal
|
||||
trap["discovered"] = true
|
||||
floor.traps[cell] = trap
|
||||
var payload := {"trap_id": StringName(trap.get("trap_id", "")), "damage": actual_damage}
|
||||
var events: Array[Dictionary] = [{"kind": &"trap_triggered", "payload": payload}]
|
||||
var events: Array[Dictionary] = [_event(&"trap_triggered", player, cell, payload)]
|
||||
# Content chance remains deterministic in this turn-based seam: a declared
|
||||
# majority chance applies, while lower chances are safely represented as no
|
||||
# status until a future RNG-owned rules slice supplies a roll stream.
|
||||
var status := StringName(definition.get("status", ""))
|
||||
# JSON `null` is a valid declaration for traps without a status effect.
|
||||
# Convert only textual IDs; StringName(null) is not a valid constructor.
|
||||
var status_value: Variant = definition.get("status")
|
||||
var status := StringName(status_value) if status_value is String else &""
|
||||
if not status.is_empty() and float(definition.get("status_chance", 0.0)) >= 0.5:
|
||||
player.apply_status(StatusEffectType.new(status, int(definition.get("status_duration", -1)), 0, StringName(trap.get("trap_id", ""))))
|
||||
events.append({"kind": &"trap_status_applied", "payload": {"trap_id": StringName(trap.get("trap_id", "")), "status": status}})
|
||||
events.append(_event(&"trap_status_applied", player, cell, {"trap_id": StringName(trap.get("trap_id", "")), "status": status}))
|
||||
return {"triggered": true, "damage": actual_damage, "trap_id": StringName(trap.get("trap_id", "")), "message": String(definition.get("message", "A trap triggers.")), "events": events}
|
||||
|
||||
static func _event(kind: StringName, player: ActorState, cell: Vector2i, payload: Dictionary) -> Dictionary:
|
||||
return {
|
||||
"kind": kind,
|
||||
"actor_id": player.id,
|
||||
"target_id": player.id,
|
||||
"cell": cell,
|
||||
"payload": payload,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user