feat: add player standing and quest generation from village needs
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
|
||||
@@ -13,6 +13,7 @@ const OPPORTUNITY_LEGACY_SCHEMA_VERSION := 8
|
||||
const ANIMAL_LEGACY_SCHEMA_VERSION := 9
|
||||
const ROUTINE_LEGACY_SCHEMA_VERSION := 10
|
||||
const PREVIOUS_SCHEMA_VERSION := 7
|
||||
const PLAYER_LEGACY_SCHEMA_VERSION := 11
|
||||
|
||||
var simulation: Dictionary
|
||||
var village: VillageStateRecord
|
||||
@@ -24,6 +25,8 @@ var economic_events: Array[EconomicEventRecord] = []
|
||||
var relationships: Array[RelationshipStateRecord] = []
|
||||
var event_knowledge: Array[KnownEventStateRecord] = []
|
||||
var opportunities: Array[OpportunityStateRecord] = []
|
||||
var player_standing: PlayerStandingRecord
|
||||
var player_quests: Array[PlayerQuestRecord] = []
|
||||
|
||||
|
||||
func to_dictionary() -> Dictionary:
|
||||
@@ -52,6 +55,9 @@ func to_dictionary() -> Dictionary:
|
||||
var opportunity_data: Array[Dictionary] = []
|
||||
for opportunity_record in opportunities:
|
||||
opportunity_data.append(opportunity_record.to_dictionary())
|
||||
var player_quest_data: Array[Dictionary] = []
|
||||
for player_quest_record in player_quests:
|
||||
player_quest_data.append(player_quest_record.to_dictionary())
|
||||
|
||||
return {
|
||||
"schema": SCHEMA_NAME,
|
||||
@@ -65,7 +71,9 @@ func to_dictionary() -> Dictionary:
|
||||
"economic_events": event_data,
|
||||
"relationships": relationship_data,
|
||||
"event_knowledge": knowledge_data,
|
||||
"opportunities": opportunity_data
|
||||
"opportunities": opportunity_data,
|
||||
"player_standing": player_standing.to_dictionary(),
|
||||
"player_quests": player_quest_data
|
||||
}
|
||||
|
||||
|
||||
@@ -97,6 +105,7 @@ static func from_dictionary(record_data: Dictionary) -> SimulationStateRecord:
|
||||
OPPORTUNITY_LEGACY_SCHEMA_VERSION,
|
||||
ANIMAL_LEGACY_SCHEMA_VERSION,
|
||||
ROUTINE_LEGACY_SCHEMA_VERSION,
|
||||
PLAYER_LEGACY_SCHEMA_VERSION,
|
||||
]
|
||||
):
|
||||
record_data = _migrate_legacy(record_data, version)
|
||||
@@ -116,6 +125,8 @@ static func from_dictionary(record_data: Dictionary) -> SimulationStateRecord:
|
||||
"relationships",
|
||||
"event_knowledge",
|
||||
"opportunities",
|
||||
"player_standing",
|
||||
"player_quests",
|
||||
]
|
||||
)
|
||||
):
|
||||
@@ -418,6 +429,7 @@ static func from_dictionary(record_data: Dictionary) -> SimulationStateRecord:
|
||||
record.relationships.append(relationship_record)
|
||||
|
||||
var opportunity_ids := {}
|
||||
var opportunity_records_by_id := {}
|
||||
var trigger_event_ids := {}
|
||||
var resolution_event_ids := {}
|
||||
var has_open_opportunity := false
|
||||
@@ -452,12 +464,58 @@ static func from_dictionary(record_data: Dictionary) -> SimulationStateRecord:
|
||||
):
|
||||
return null
|
||||
opportunity_ids[opportunity_id] = true
|
||||
opportunity_records_by_id[opportunity_id] = opportunity_record
|
||||
trigger_event_ids[trigger_event_id] = true
|
||||
highest_opportunity_id = maxi(highest_opportunity_id, opportunity_id)
|
||||
record.opportunities.append(opportunity_record)
|
||||
if int(record.simulation["next_opportunity_id"]) <= highest_opportunity_id:
|
||||
return null
|
||||
|
||||
var standing_data = record_data["player_standing"]
|
||||
if not standing_data is Dictionary:
|
||||
return null
|
||||
var standing_record := PlayerStandingRecord.from_dictionary(standing_data)
|
||||
if standing_record == null:
|
||||
return null
|
||||
record.player_standing = standing_record
|
||||
|
||||
var player_quest_data = record_data["player_quests"]
|
||||
if not player_quest_data is Array:
|
||||
return null
|
||||
var quest_ids := {}
|
||||
var quest_opportunity_ids := {}
|
||||
var highest_quest_id := -1
|
||||
for item in player_quest_data:
|
||||
if not item is Dictionary:
|
||||
return null
|
||||
var quest_record := PlayerQuestRecord.from_dictionary(item)
|
||||
if quest_record == null:
|
||||
return null
|
||||
var quest_id := quest_record.get_quest_id()
|
||||
var quest_opportunity_id := quest_record.get_opportunity_id()
|
||||
var requester_id := quest_record.get_requester_npc_id()
|
||||
if (
|
||||
quest_ids.has(quest_id)
|
||||
or quest_opportunity_ids.has(quest_opportunity_id)
|
||||
or not npc_ids.has(requester_id)
|
||||
or not opportunity_ids.has(quest_opportunity_id)
|
||||
):
|
||||
return null
|
||||
if (
|
||||
quest_record.get_status() == PlayerQuestRecord.STATUS_OPEN
|
||||
and not opportunity_records_by_id.has(quest_opportunity_id)
|
||||
):
|
||||
return null
|
||||
if (
|
||||
quest_record.get_resolution_event_id() >= 0
|
||||
and not event_ids.has(quest_record.get_resolution_event_id())
|
||||
):
|
||||
return null
|
||||
quest_ids[quest_id] = true
|
||||
quest_opportunity_ids[quest_opportunity_id] = true
|
||||
highest_quest_id = maxi(highest_quest_id, quest_id)
|
||||
record.player_quests.append(quest_record)
|
||||
|
||||
return record
|
||||
|
||||
|
||||
@@ -772,6 +830,12 @@ static func _migrate_legacy(legacy_data: Dictionary, version: int) -> Dictionary
|
||||
var opportunity_simulation_data: Dictionary = migrated.get("simulation", {})
|
||||
opportunity_simulation_data["next_opportunity_id"] = 0
|
||||
migrated["simulation"] = opportunity_simulation_data
|
||||
if version <= PLAYER_LEGACY_SCHEMA_VERSION:
|
||||
migrated["player_standing"] = PlayerStandingRecord.create().to_dictionary()
|
||||
migrated["player_quests"] = []
|
||||
var quest_simulation_data: Dictionary = migrated.get("simulation", {})
|
||||
quest_simulation_data["next_quest_id"] = 0
|
||||
migrated["simulation"] = quest_simulation_data
|
||||
return migrated
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user