63 lines
2.2 KiB
GDScript
63 lines
2.2 KiB
GDScript
class_name RunState
|
|
extends RefCounted
|
|
|
|
var seed: String
|
|
var settings: RunSettings
|
|
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] = []
|
|
# Currency is run-scoped like inventory, so chest rewards persist through floors.
|
|
var gold := 0
|
|
# D1 owns inventory at run scope so it persists while the player changes floors.
|
|
var inventory: InventoryState = InventoryState.new()
|
|
# D3 keeps item identity and equipment with the run so swaps persist across floors.
|
|
var equipment: EquipmentState = EquipmentState.new()
|
|
var identification: ItemIdentification = ItemIdentification.new()
|
|
# E3 quest progress belongs to the run rather than a generated floor.
|
|
var quest_records: Array[Dictionary] = []
|
|
var quest_manager: QuestManager
|
|
|
|
func _init(new_seed: String, new_settings: RunSettings = null) -> void:
|
|
settings = new_settings if new_settings != null else RunSettings.new(new_seed)
|
|
seed = settings.seed
|
|
|
|
func set_floor_state(floor: FloorState) -> void:
|
|
floors[floor.floor_number] = floor
|
|
|
|
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
|
|
|
|
func append_events(events: Array[GameEvent]) -> void:
|
|
for event in events:
|
|
log.append(event)
|
|
|
|
func recent_events(count: int) -> Array[GameEvent]:
|
|
if count <= 0:
|
|
return []
|
|
var first_index: int = max(0, log.size() - count)
|
|
var events: Array[GameEvent] = []
|
|
for index in range(first_index, log.size()):
|
|
events.append(log[index])
|
|
return events
|