feat: let villagers witness and trust the player restock
This commit is contained in:
@@ -2,7 +2,7 @@ class_name SimulationStateRecord
|
||||
extends RefCounted
|
||||
|
||||
const SCHEMA_NAME := "the_steward.simulation"
|
||||
const SCHEMA_VERSION := 11
|
||||
const SCHEMA_VERSION := 12
|
||||
const LEGACY_SCHEMA_VERSION := 1
|
||||
const EVENT_LEGACY_SCHEMA_VERSION := 2
|
||||
const RELATIONSHIP_LEGACY_SCHEMA_VERSION := 3
|
||||
@@ -12,6 +12,7 @@ const RETENTION_LEGACY_SCHEMA_VERSION := 6
|
||||
const OPPORTUNITY_LEGACY_SCHEMA_VERSION := 8
|
||||
const ANIMAL_LEGACY_SCHEMA_VERSION := 9
|
||||
const ROUTINE_LEGACY_SCHEMA_VERSION := 10
|
||||
const PLAYER_RELATIONSHIP_SCHEMA_VERSION := 11
|
||||
const PREVIOUS_SCHEMA_VERSION := 7
|
||||
|
||||
var simulation: Dictionary
|
||||
@@ -97,6 +98,7 @@ static func from_dictionary(record_data: Dictionary) -> SimulationStateRecord:
|
||||
OPPORTUNITY_LEGACY_SCHEMA_VERSION,
|
||||
ANIMAL_LEGACY_SCHEMA_VERSION,
|
||||
ROUTINE_LEGACY_SCHEMA_VERSION,
|
||||
PLAYER_RELATIONSHIP_SCHEMA_VERSION,
|
||||
]
|
||||
):
|
||||
record_data = _migrate_legacy(record_data, version)
|
||||
@@ -386,7 +388,10 @@ static func from_dictionary(record_data: Dictionary) -> SimulationStateRecord:
|
||||
return null
|
||||
var observer_id := relationship_record.get_observer_id()
|
||||
var subject_id := relationship_record.get_subject_id()
|
||||
if not npc_ids.has(observer_id) or not npc_ids.has(subject_id):
|
||||
var is_player_subject := subject_id == SimulationIds.PLAYER_ACTOR_ID
|
||||
if not npc_ids.has(observer_id):
|
||||
return null
|
||||
if not is_player_subject and not npc_ids.has(subject_id):
|
||||
return null
|
||||
var relationship_key := "%d:%d" % [observer_id, subject_id]
|
||||
if relationship_keys.has(relationship_key):
|
||||
@@ -404,15 +409,7 @@ static func from_dictionary(record_data: Dictionary) -> SimulationStateRecord:
|
||||
return null
|
||||
if cause_event_id != RelationshipStateRecord.NO_CAUSE_EVENT:
|
||||
var cause_event := event_records_by_id[cause_event_id] as EconomicEventRecord
|
||||
if (
|
||||
int(cause_event.data["actor_id"]) != subject_id
|
||||
or (
|
||||
StringName(cause_event.data["event_type"])
|
||||
!= SimulationIds.EVENT_STORAGE_DEPOSITED
|
||||
)
|
||||
or StringName(cause_event.data["item_id"]) != SimulationIds.RESOURCE_FOOD
|
||||
or float(cause_event.data["amount"]) <= 0.0
|
||||
):
|
||||
if not _is_valid_relationship_cause(cause_event, subject_id, is_player_subject):
|
||||
return null
|
||||
relationship_keys[relationship_key] = true
|
||||
record.relationships.append(relationship_record)
|
||||
@@ -672,6 +669,27 @@ static func _is_valid_pantry_empty_trigger(event: EconomicEventRecord, npc_ids:
|
||||
)
|
||||
|
||||
|
||||
static func _is_valid_relationship_cause(
|
||||
cause_event: EconomicEventRecord, subject_id: int, is_player_subject: bool
|
||||
) -> bool:
|
||||
if not is_player_subject:
|
||||
return (
|
||||
int(cause_event.data["actor_id"]) == subject_id
|
||||
and (
|
||||
StringName(cause_event.data["event_type"]) == SimulationIds.EVENT_STORAGE_DEPOSITED
|
||||
)
|
||||
and StringName(cause_event.data["item_id"]) == SimulationIds.RESOURCE_FOOD
|
||||
and float(cause_event.data["amount"]) > 0.0
|
||||
)
|
||||
return (
|
||||
int(cause_event.data["actor_id"]) == SimulationIds.PLAYER_ACTOR_ID
|
||||
and StringName(cause_event.data["event_type"]) == SimulationIds.EVENT_RESOURCE_EXTRACTED
|
||||
and (StringName(cause_event.data["destination_id"]) == SimulationIds.STORAGE_VILLAGE_PANTRY)
|
||||
and StringName(cause_event.data["item_id"]) == SimulationIds.RESOURCE_FOOD
|
||||
and float(cause_event.data["amount"]) > 0.0
|
||||
)
|
||||
|
||||
|
||||
static func _is_valid_supply_resolution(
|
||||
event: EconomicEventRecord,
|
||||
opportunity: OpportunityStateRecord,
|
||||
@@ -766,6 +784,7 @@ static func _migrate_legacy(legacy_data: Dictionary, version: int) -> Dictionary
|
||||
OPPORTUNITY_LEGACY_SCHEMA_VERSION,
|
||||
ANIMAL_LEGACY_SCHEMA_VERSION,
|
||||
ROUTINE_LEGACY_SCHEMA_VERSION,
|
||||
PLAYER_RELATIONSHIP_SCHEMA_VERSION,
|
||||
]
|
||||
):
|
||||
migrated["opportunities"] = []
|
||||
|
||||
Reference in New Issue
Block a user