feat: add provenance-aware npc communication
This commit is contained in:
@@ -1,7 +1,15 @@
|
||||
class_name KnownEventStateRecord
|
||||
extends RefCounted
|
||||
|
||||
const SCHEMA_VERSION := 1
|
||||
const SCHEMA_VERSION := 2
|
||||
const NO_SOURCE_NPC_ID := -1
|
||||
|
||||
const VALID_ACQUISITION_METHODS := [
|
||||
SimulationIds.KNOWLEDGE_ACQUISITION_PERFORMED,
|
||||
SimulationIds.KNOWLEDGE_ACQUISITION_WITNESSED,
|
||||
SimulationIds.KNOWLEDGE_ACQUISITION_COMMUNICATED,
|
||||
SimulationIds.KNOWLEDGE_ACQUISITION_LEGACY,
|
||||
]
|
||||
|
||||
var data: Dictionary
|
||||
|
||||
@@ -10,7 +18,12 @@ func _init(record_data: Dictionary = {}) -> void:
|
||||
data = record_data.duplicate(true)
|
||||
|
||||
|
||||
static func create(knower_id: int, event_id: int) -> KnownEventStateRecord:
|
||||
static func create(
|
||||
knower_id: int,
|
||||
event_id: int,
|
||||
acquisition_method: StringName = SimulationIds.KNOWLEDGE_ACQUISITION_LEGACY,
|
||||
source_npc_id: int = NO_SOURCE_NPC_ID
|
||||
) -> KnownEventStateRecord:
|
||||
return (
|
||||
KnownEventStateRecord
|
||||
. new(
|
||||
@@ -18,6 +31,8 @@ static func create(knower_id: int, event_id: int) -> KnownEventStateRecord:
|
||||
"schema_version": SCHEMA_VERSION,
|
||||
"knower_id": knower_id,
|
||||
"event_id": event_id,
|
||||
"acquisition_method": String(acquisition_method),
|
||||
"source_npc_id": source_npc_id,
|
||||
}
|
||||
)
|
||||
)
|
||||
@@ -26,13 +41,22 @@ static func create(knower_id: int, event_id: int) -> KnownEventStateRecord:
|
||||
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"]):
|
||||
if not record_data.has_all(["knower_id", "event_id", "acquisition_method", "source_npc_id"]):
|
||||
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:
|
||||
return null
|
||||
return create(knower_id, event_id)
|
||||
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:
|
||||
return null
|
||||
return create(knower_id, event_id, acquisition_method, source_npc_id)
|
||||
|
||||
|
||||
func get_knower_id() -> int:
|
||||
@@ -43,5 +67,13 @@ func get_event_id() -> int:
|
||||
return int(data["event_id"])
|
||||
|
||||
|
||||
func get_acquisition_method() -> StringName:
|
||||
return StringName(data["acquisition_method"])
|
||||
|
||||
|
||||
func get_source_npc_id() -> int:
|
||||
return int(data["source_npc_id"])
|
||||
|
||||
|
||||
func to_dictionary() -> Dictionary:
|
||||
return data.duplicate(true)
|
||||
|
||||
Reference in New Issue
Block a user