68 lines
2.1 KiB
GDScript
68 lines
2.1 KiB
GDScript
class_name PlayerNegotiationSystem
|
|
extends RefCounted
|
|
|
|
var quest_system: PlayerQuestSystem
|
|
var npc_lookup: Callable
|
|
var opportunity_provider: Callable
|
|
var player_response_provider: Callable
|
|
var quest_opened_signal: Signal
|
|
var quest_expired_signal: Signal
|
|
var standing_changed_signal: Signal
|
|
|
|
|
|
func configure(
|
|
quests: PlayerQuestSystem,
|
|
lookup: Callable,
|
|
opportunity_source: Callable,
|
|
response_source: Callable,
|
|
opened: Signal,
|
|
expired: Signal,
|
|
standing: Signal
|
|
) -> void:
|
|
quest_system = quests
|
|
npc_lookup = lookup
|
|
opportunity_provider = opportunity_source
|
|
player_response_provider = response_source
|
|
quest_opened_signal = opened
|
|
quest_expired_signal = expired
|
|
standing_changed_signal = standing
|
|
|
|
|
|
func get_talk(npc_id: int) -> PlayerTalkResult:
|
|
var npc := npc_lookup.call(npc_id) as SimNPC
|
|
if npc == null or npc.is_dead:
|
|
return null
|
|
return quest_system.get_talk_for_requester(npc.id, npc.npc_name, opportunity_provider.call())
|
|
|
|
|
|
func accept_request(npc_id: int, current_tick: int) -> PlayerQuestRecord:
|
|
var npc := npc_lookup.call(npc_id) as SimNPC
|
|
if npc == null:
|
|
return null
|
|
var opportunity: OpportunityStateRecord = opportunity_provider.call()
|
|
if opportunity == null or opportunity.get_interested_npc_id() != npc.id:
|
|
return null
|
|
var result: Dictionary = quest_system.accept_opportunity_quest(
|
|
opportunity, player_response_provider.call(), current_tick
|
|
)
|
|
var quest := result.get("quest") as PlayerQuestRecord
|
|
if quest != null and result.get("created", false) and not quest_opened_signal.is_null():
|
|
quest_opened_signal.emit(quest)
|
|
return quest
|
|
|
|
|
|
func decline_request(npc_id: int, current_tick: int) -> PlayerQuestRecord:
|
|
var npc := npc_lookup.call(npc_id) as SimNPC
|
|
if npc == null:
|
|
return null
|
|
var opportunity: OpportunityStateRecord = opportunity_provider.call()
|
|
if opportunity == null or opportunity.get_interested_npc_id() != npc.id:
|
|
return null
|
|
var quest := quest_system.decline_opportunity_quest(opportunity, current_tick)
|
|
if quest != null:
|
|
if not quest_expired_signal.is_null():
|
|
quest_expired_signal.emit(quest)
|
|
if not standing_changed_signal.is_null():
|
|
standing_changed_signal.emit(quest_system.standing)
|
|
return quest
|