feat: add bounded npc memory retention
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
class_name KnownEventStateRecord
|
||||
extends RefCounted
|
||||
|
||||
const SCHEMA_VERSION := 2
|
||||
const SCHEMA_VERSION := 3
|
||||
const NO_SOURCE_NPC_ID := -1
|
||||
|
||||
const VALID_ACQUISITION_METHODS := [
|
||||
@@ -10,6 +10,10 @@ const VALID_ACQUISITION_METHODS := [
|
||||
SimulationIds.KNOWLEDGE_ACQUISITION_COMMUNICATED,
|
||||
SimulationIds.KNOWLEDGE_ACQUISITION_LEGACY,
|
||||
]
|
||||
const DIRECT_ACQUISITION_METHODS := [
|
||||
SimulationIds.KNOWLEDGE_ACQUISITION_PERFORMED,
|
||||
SimulationIds.KNOWLEDGE_ACQUISITION_WITNESSED,
|
||||
]
|
||||
|
||||
var data: Dictionary
|
||||
|
||||
@@ -22,7 +26,9 @@ static func create(
|
||||
knower_id: int,
|
||||
event_id: int,
|
||||
acquisition_method: StringName = SimulationIds.KNOWLEDGE_ACQUISITION_LEGACY,
|
||||
source_npc_id: int = NO_SOURCE_NPC_ID
|
||||
source_npc_id: int = NO_SOURCE_NPC_ID,
|
||||
acquired_tick: int = 0,
|
||||
source_acquisition_method: StringName = &""
|
||||
) -> KnownEventStateRecord:
|
||||
return (
|
||||
KnownEventStateRecord
|
||||
@@ -33,6 +39,8 @@ static func create(
|
||||
"event_id": event_id,
|
||||
"acquisition_method": String(acquisition_method),
|
||||
"source_npc_id": source_npc_id,
|
||||
"acquired_tick": acquired_tick,
|
||||
"source_acquisition_method": String(source_acquisition_method),
|
||||
}
|
||||
)
|
||||
)
|
||||
@@ -41,22 +49,45 @@ static func create(
|
||||
static func from_dictionary(record_data: Dictionary) -> KnownEventStateRecord:
|
||||
if int(record_data.get("schema_version", -1)) != SCHEMA_VERSION:
|
||||
return null
|
||||
if not record_data.has_all(["knower_id", "event_id", "acquisition_method", "source_npc_id"]):
|
||||
if not (
|
||||
record_data
|
||||
. has_all(
|
||||
[
|
||||
"knower_id",
|
||||
"event_id",
|
||||
"acquisition_method",
|
||||
"source_npc_id",
|
||||
"acquired_tick",
|
||||
"source_acquisition_method",
|
||||
]
|
||||
)
|
||||
):
|
||||
return null
|
||||
var knower_id := int(record_data["knower_id"])
|
||||
var event_id := int(record_data["event_id"])
|
||||
var acquisition_method := StringName(record_data["acquisition_method"])
|
||||
var source_npc_id := int(record_data["source_npc_id"])
|
||||
if knower_id < 0 or event_id < 0:
|
||||
var acquired_tick := int(record_data["acquired_tick"])
|
||||
var source_acquisition_method := StringName(record_data["source_acquisition_method"])
|
||||
if knower_id < 0 or event_id < 0 or acquired_tick < 0:
|
||||
return null
|
||||
if acquisition_method not in VALID_ACQUISITION_METHODS:
|
||||
return null
|
||||
if acquisition_method == SimulationIds.KNOWLEDGE_ACQUISITION_COMMUNICATED:
|
||||
if source_npc_id < 0 or source_npc_id == knower_id:
|
||||
return null
|
||||
elif source_npc_id != NO_SOURCE_NPC_ID:
|
||||
if source_acquisition_method not in DIRECT_ACQUISITION_METHODS:
|
||||
return null
|
||||
elif source_npc_id != NO_SOURCE_NPC_ID or not source_acquisition_method.is_empty():
|
||||
return null
|
||||
return create(knower_id, event_id, acquisition_method, source_npc_id)
|
||||
return create(
|
||||
knower_id,
|
||||
event_id,
|
||||
acquisition_method,
|
||||
source_npc_id,
|
||||
acquired_tick,
|
||||
source_acquisition_method
|
||||
)
|
||||
|
||||
|
||||
func get_knower_id() -> int:
|
||||
@@ -75,5 +106,13 @@ func get_source_npc_id() -> int:
|
||||
return int(data["source_npc_id"])
|
||||
|
||||
|
||||
func get_acquired_tick() -> int:
|
||||
return int(data["acquired_tick"])
|
||||
|
||||
|
||||
func get_source_acquisition_method() -> StringName:
|
||||
return StringName(data["source_acquisition_method"])
|
||||
|
||||
|
||||
func to_dictionary() -> Dictionary:
|
||||
return data.duplicate(true)
|
||||
|
||||
Reference in New Issue
Block a user