feat: let the player talk to villagers and accept or decline personal requests
This commit is contained in:
@@ -56,6 +56,7 @@ var event_knowledge_system := EventKnowledgeSystemScript.new()
|
||||
var opportunity_system := VillageOpportunitySystem.new()
|
||||
var player_quest_system := PlayerQuestSystem.new()
|
||||
var player_needs := PlayerNeedsSystem.new()
|
||||
var player_negotiation := PlayerNegotiationSystem.new()
|
||||
var _last_player_tier := PlayerStandingRecord.TIER_STRANGER
|
||||
var storage_states: Dictionary:
|
||||
get:
|
||||
@@ -88,6 +89,15 @@ func _ready() -> void:
|
||||
event_recorder.set_npcs(npcs)
|
||||
player_needs.configure(economy, event_recorder)
|
||||
player_needs.set_resource_states(resource_states)
|
||||
player_negotiation.configure(
|
||||
player_quest_system,
|
||||
Callable(self, "_find_npc_by_id"),
|
||||
Callable(self, "get_active_opportunity"),
|
||||
Callable(self, "get_active_opportunity_player_response"),
|
||||
player_quest_opened,
|
||||
player_quest_expired,
|
||||
player_standing_changed
|
||||
)
|
||||
economy.inventory_changed.connect(_on_economy_inventory_changed)
|
||||
economy.economic_event_requested.connect(event_recorder.record_economic)
|
||||
economy.narrative_event_requested.connect(event_recorder.record_narrative)
|
||||
@@ -181,7 +191,10 @@ func simulate_tick() -> void:
|
||||
if debug_logs:
|
||||
print("--- Tick ", tick_count, " ---")
|
||||
animal_care.advance(tick_count)
|
||||
_consider_animal_care_quests()
|
||||
for quest in player_quest_system.consider_animal_care_quests(
|
||||
animal_care, npcs, get_pantry(), tick_count
|
||||
):
|
||||
player_quest_opened.emit(quest)
|
||||
_advance_player_needs()
|
||||
var village_was_changed := false
|
||||
_population_view.rebuild(npcs)
|
||||
@@ -594,15 +607,15 @@ func _finish_quest_resolution(resolution: Dictionary) -> void:
|
||||
if not resolution.has("quest"):
|
||||
return
|
||||
var quest: PlayerQuestRecord = resolution["quest"]
|
||||
if not resolution["completed"]:
|
||||
player_quest_expired.emit(quest)
|
||||
if resolution["completed"]:
|
||||
player_quest_completed.emit(quest)
|
||||
var standing := player_quest_system.standing
|
||||
player_standing_changed.emit(standing)
|
||||
if standing.get_tier() > _last_player_tier:
|
||||
_last_player_tier = standing.get_tier()
|
||||
player_tier_advanced.emit(standing.get_tier(), standing.get_tier_name())
|
||||
return
|
||||
player_quest_completed.emit(quest)
|
||||
var standing := player_quest_system.standing
|
||||
player_standing_changed.emit(standing)
|
||||
if standing.get_tier() > _last_player_tier:
|
||||
_last_player_tier = standing.get_tier()
|
||||
player_tier_advanced.emit(standing.get_tier(), standing.get_tier_name())
|
||||
player_quest_expired.emit(quest)
|
||||
|
||||
|
||||
func try_communicate_at_shared_activity(speaker_id: int, listener_id: int) -> bool:
|
||||
@@ -764,10 +777,8 @@ func get_player_state() -> PlayerStateRecord:
|
||||
|
||||
|
||||
func player_eat(amount: float) -> float:
|
||||
var eaten := player_needs.eat(amount)
|
||||
if eaten > 0.0:
|
||||
player_needs_changed.emit(player_needs.state)
|
||||
return eaten
|
||||
player_needs_changed.emit(player_needs.state)
|
||||
return player_needs.eat(amount)
|
||||
|
||||
|
||||
func player_gather(node: ResourceNode) -> float:
|
||||
@@ -785,33 +796,22 @@ func player_deposit(resource_id: StringName) -> float:
|
||||
return deposited
|
||||
|
||||
|
||||
func _consider_animal_care_quests() -> void:
|
||||
var pantry: StorageStateRecord = get_pantry()
|
||||
for animal_state in animal_care.get_all_states():
|
||||
var quest := player_quest_system.consider_animal_care(
|
||||
animal_state, _nearest_npc_id(animal_state.get_position()), tick_count, pantry
|
||||
)
|
||||
if quest != null:
|
||||
player_quest_opened.emit(quest)
|
||||
|
||||
|
||||
func _nearest_npc_id(from_position: Vector3) -> int:
|
||||
var nearest_id := -1
|
||||
var nearest_distance := INF
|
||||
for npc in npcs:
|
||||
if npc.is_dead:
|
||||
continue
|
||||
var distance := npc.position.distance_squared_to(from_position)
|
||||
if distance < nearest_distance:
|
||||
nearest_distance = distance
|
||||
nearest_id = npc.id
|
||||
return nearest_id
|
||||
|
||||
|
||||
func get_player_quests() -> Array[PlayerQuestRecord]:
|
||||
return player_quest_system.get_all_sorted()
|
||||
|
||||
|
||||
func get_villager_talk(npc_id: int) -> PlayerTalkResult:
|
||||
return player_negotiation.get_talk(npc_id)
|
||||
|
||||
|
||||
func accept_villager_request(npc_id: int) -> PlayerQuestRecord:
|
||||
return player_negotiation.accept_request(npc_id, tick_count)
|
||||
|
||||
|
||||
func decline_villager_request(npc_id: int) -> PlayerQuestRecord:
|
||||
return player_negotiation.decline_request(npc_id, tick_count)
|
||||
|
||||
|
||||
func get_latest_player_quest_for_requester(requester_npc_id: int) -> PlayerQuestRecord:
|
||||
return player_quest_system.get_latest_for_requester(requester_npc_id)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user