feat: add protected tourist encounters
This commit is contained in:
@@ -12,6 +12,9 @@ var max_hit_points: int
|
||||
# Legacy basic damage remains the unarmed/default weapon damage.
|
||||
var attack_damage: int
|
||||
var content_id: StringName
|
||||
# Non-combat authored NPC state (including protected tourist health) persists
|
||||
# alongside the actor without exposing it to normal combat resolution.
|
||||
var metadata: Dictionary = {}
|
||||
|
||||
# Data-backed combat stats. Defaults retain the pre-C2 prototype fixtures.
|
||||
var accuracy := 30
|
||||
@@ -65,6 +68,7 @@ func _init(new_id: StringName, new_cell: Vector2i, new_hit_points: int, new_atta
|
||||
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
|
||||
metadata = combat_data.get("metadata", {}).duplicate(true)
|
||||
accuracy = int(combat_data.get("accuracy", accuracy))
|
||||
defense = int(combat_data.get("defense", defense))
|
||||
armor = int(combat_data.get("armor", armor))
|
||||
|
||||
@@ -3,6 +3,7 @@ extends RefCounted
|
||||
|
||||
const StatusEffectType = preload("res://scripts/domain/combat/status_effect.gd")
|
||||
const SafeRoomServiceType = preload("res://scripts/domain/world/safe_room_service.gd")
|
||||
const TouristServiceType = preload("res://scripts/domain/world/tourist_service.gd")
|
||||
|
||||
var diagnostics := PackedStringArray()
|
||||
|
||||
@@ -117,6 +118,13 @@ func apply_effect(effect: Dictionary, context: Dictionary) -> Dictionary:
|
||||
if not moderation_fn.is_valid():
|
||||
return {"applied": false, "type": kind, "reason": &"missing_moderation_context"}
|
||||
return moderation_fn.call(StringName(effect.get("reason", "propos_interdits")))
|
||||
&"tourist_selfie", &"endanger_tourist":
|
||||
var tourist_run: RunState = context.get("run_state")
|
||||
var tourist_id := StringName(context.get("npc_id", ""))
|
||||
if tourist_run == null or tourist_id.is_empty():
|
||||
return {"applied": false, "type": kind, "reason": &"missing_tourist_context"}
|
||||
var tourist_events := TouristServiceType.selfie(tourist_run, tourist_id) if kind == &"tourist_selfie" else TouristServiceType.endanger(tourist_run, tourist_id, int(effect.get("amount", 0)))
|
||||
return {"applied": not tourist_events.is_empty(), "type": kind, "events": tourist_events}
|
||||
&"give_item":
|
||||
var run: RunState = context.get("run_state")
|
||||
var npc_id: StringName = StringName(context.get("npc_id", ""))
|
||||
@@ -133,7 +141,7 @@ func apply_effect(effect: Dictionary, context: Dictionary) -> Dictionary:
|
||||
return {"applied": false, "type": kind, "reason": &"missing_party_context"}
|
||||
var result := party.recruit(recruit, player.cell, map, context.get("blocked_cells", {}))
|
||||
return {"applied": bool(result.get("accepted", false)), "type": kind, "result": result}
|
||||
&"message", &"remove_item", &"learn_spell", &"learn_random_spell", &"complete_objective", &"endanger_tourist", &"augment_companion", &"tourist_selfie":
|
||||
&"message", &"remove_item", &"learn_spell", &"learn_random_spell", &"complete_objective", &"augment_companion":
|
||||
# Later content slices own the corresponding inventory, quest, NPC, and spell mutations.
|
||||
pass
|
||||
_:
|
||||
|
||||
@@ -5,6 +5,7 @@ const DeterministicRngType = preload("res://scripts/domain/run/deterministic_rng
|
||||
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")
|
||||
const TouristServiceType = preload("res://scripts/domain/world/tourist_service.gd")
|
||||
|
||||
static func populate(floor: FloorState, catalog: ContentCatalog, population_seed: String) -> void:
|
||||
_clear_population(floor)
|
||||
@@ -32,6 +33,7 @@ static func populate(floor: FloorState, catalog: ContentCatalog, population_seed
|
||||
serial = _spawn_bobka(floor, catalog, room, rng, occupied, serial)
|
||||
&"narrative", &"mystery", &"puzzle":
|
||||
_spawn_event(floor, catalog, room, rng, occupied)
|
||||
TouristServiceType.try_spawn(floor, catalog, rng)
|
||||
|
||||
static func _clear_population(floor: FloorState) -> void:
|
||||
floor.enemies.clear()
|
||||
|
||||
@@ -175,6 +175,7 @@ static func _actor_to_dict(actor: ActorState) -> Dictionary:
|
||||
"ranged_weapon": actor.ranged_weapon.duplicate(true),
|
||||
"ammunition": actor.ammunition,
|
||||
"wounds": actor.wounds.to_dictionary(),
|
||||
"metadata": actor.metadata.duplicate(true),
|
||||
}
|
||||
|
||||
static func _actor_from_dict(data: Dictionary) -> ActorState:
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
class_name TouristService
|
||||
extends RefCounted
|
||||
|
||||
const ActorStateType = preload("res://scripts/domain/actor_state.gd")
|
||||
const AudienceStateType = preload("res://scripts/domain/meta/audience_state.gd")
|
||||
const ModerationType = preload("res://scripts/domain/meta/moderation.gd")
|
||||
const GameEventType = preload("res://scripts/domain/run/game_event.gd")
|
||||
const GridMapStateType = preload("res://scripts/domain/grid_map_state.gd")
|
||||
|
||||
const TOURIST_CONTENT_ID := &"npc_tourist_influencer"
|
||||
const TOURIST_MIN_FLOOR := 6
|
||||
const TOURIST_MAX_PER_FLOOR := 1
|
||||
const SELFIE_SPECTACLE := 10
|
||||
const SPAWN_DENOMINATOR := 4
|
||||
const SAFE_ROOM_KINDS := [&"sanctuary", &"refuge", &"narrative", &"mystery", &"puzzle"]
|
||||
|
||||
# Population owns the RNG, while this service owns the tourist contract. The
|
||||
# resulting record is an ordinary NPC with private metadata, never a combatant.
|
||||
static func try_spawn(floor: FloorState, catalog: ContentCatalog, rng: DeterministicRng) -> Array[GameEvent]:
|
||||
if floor.floor_number < TOURIST_MIN_FLOOR or _active_tourists(floor).size() >= TOURIST_MAX_PER_FLOOR:
|
||||
return []
|
||||
var definition := catalog.get_npc(TOURIST_CONTENT_ID)
|
||||
if definition.is_empty() or rng.next_int() % SPAWN_DENOMINATOR != 0:
|
||||
return []
|
||||
var candidates: Array[Vector2i] = []
|
||||
var occupied := _occupied_cells(floor)
|
||||
for room: RoomState in floor.rooms:
|
||||
if room.kind not in SAFE_ROOM_KINDS or room.kind in [&"entrance", &"boss"]:
|
||||
continue
|
||||
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 []
|
||||
var actor_id := StringName("npc_tourist_influencer_%02d" % floor.npcs.size())
|
||||
var tourist := ActorStateType.new(actor_id, candidates[rng.next_int() % candidates.size()], 1, 0, TOURIST_CONTENT_ID)
|
||||
tourist.metadata = {
|
||||
"is_tourist": true,
|
||||
"hidden_health": maxi(1, int(definition.get("hidden_health", 30))),
|
||||
"ejected": false,
|
||||
"moderation_struck": false,
|
||||
}
|
||||
floor.npcs[actor_id] = tourist
|
||||
return []
|
||||
|
||||
static func selfie(run: RunState, tourist_id: StringName) -> Array[GameEvent]:
|
||||
var tourist := _tourist(run, tourist_id)
|
||||
if tourist == null or bool(tourist.metadata.get("ejected", false)):
|
||||
return []
|
||||
var audience := AudienceStateType.new(run.audience_state)
|
||||
var audience_result := audience.add_spectacle(SELFIE_SPECTACLE)
|
||||
return [_event(run, &"tourist_selfie", tourist, {
|
||||
"audience": audience_result,
|
||||
"hidden_health": int(tourist.metadata.get("hidden_health", 0)),
|
||||
}, "Selfie avec le touriste : l'audience s'emballe.")]
|
||||
|
||||
static func meet(run: RunState, tourist_id: StringName, character_level: int) -> Array[GameEvent]:
|
||||
var tourist := _tourist(run, tourist_id)
|
||||
if tourist == null or character_level < 4:
|
||||
return []
|
||||
var met_ids: Array = run.audience_state.get("met_tourist_ids", [])
|
||||
if tourist.id in met_ids:
|
||||
return []
|
||||
met_ids.append(tourist.id)
|
||||
run.audience_state["met_tourist_ids"] = met_ids
|
||||
return [_event(run, &"tourist_met", tourist, {}, "Vous rencontrez un touriste dans les profondeurs.")]
|
||||
|
||||
static func endanger(run: RunState, tourist_id: StringName, amount: int) -> Array[GameEvent]:
|
||||
var tourist := _tourist(run, tourist_id)
|
||||
if tourist == null or bool(tourist.metadata.get("ejected", false)):
|
||||
return []
|
||||
var remaining := maxi(0, int(tourist.metadata.get("hidden_health", 0)) - maxi(0, amount))
|
||||
tourist.metadata["hidden_health"] = remaining
|
||||
var events: Array[GameEvent] = [_event(run, &"tourist_endangered", tourist, {"amount": maxi(0, amount), "hidden_health": remaining}, "Le touriste est mis en danger.")]
|
||||
if remaining > 0:
|
||||
return events
|
||||
tourist.metadata["ejected"] = true
|
||||
run.current_floor_state().npcs.erase(tourist.id)
|
||||
events.append(_event(run, &"tourist_ejected", tourist, {}, "Évacuation du touriste par contrat de protection."))
|
||||
if not bool(tourist.metadata.get("moderation_struck", false)):
|
||||
tourist.metadata["moderation_struck"] = true
|
||||
var result := ModerationType.new(run.moderation_state).apply(&"mise_en_danger_touriste", run.current_floor_deadline())
|
||||
events.append(_event(run, &"moderation_strike", tourist, result, "[SYSTÈME] Mise en danger d’un touriste : évacuation et sanction."))
|
||||
return events
|
||||
|
||||
static func _tourist(run: RunState, tourist_id: StringName) -> ActorState:
|
||||
var floor := run.current_floor_state()
|
||||
if floor == null:
|
||||
return null
|
||||
var tourist: ActorState = floor.npcs.get(tourist_id)
|
||||
return tourist if tourist != null and bool(tourist.metadata.get("is_tourist", false)) else null
|
||||
|
||||
static func _active_tourists(floor: FloorState) -> Array[ActorState]:
|
||||
var tourists: Array[ActorState] = []
|
||||
for npc: ActorState in floor.npcs.values():
|
||||
if npc.content_id == TOURIST_CONTENT_ID and not bool(npc.metadata.get("ejected", false)):
|
||||
tourists.append(npc)
|
||||
return tourists
|
||||
|
||||
static func _occupied_cells(floor: FloorState) -> Dictionary[Vector2i, bool]:
|
||||
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
|
||||
for actor: ActorState in floor.enemies.values() + floor.npcs.values():
|
||||
occupied[actor.cell] = true
|
||||
for cell: Vector2i in floor.chests:
|
||||
occupied[cell] = true
|
||||
for cell: Vector2i in floor.traps:
|
||||
occupied[cell] = true
|
||||
for entry: Dictionary in floor.events:
|
||||
var serialized: Array = entry.get("cell", [])
|
||||
if serialized.size() == 2:
|
||||
occupied[Vector2i(int(serialized[0]), int(serialized[1]))] = true
|
||||
return occupied
|
||||
|
||||
static func _event(run: RunState, kind: StringName, tourist: ActorState, payload: Dictionary, message: String) -> GameEvent:
|
||||
return GameEventType.new(run.current_turn, run.current_floor, kind, payload, message, &"player", tourist.id, tourist.cell)
|
||||
@@ -0,0 +1 @@
|
||||
uid://b7ctobdcyrday
|
||||
Reference in New Issue
Block a user