TinyAdventure/quests/builder_missing_tool_quest.gd

55 lines
1.5 KiB
GDScript
Raw Normal View History

class_name QuestBuilderMissingTool
2024-07-12 14:32:33 +02:00
extends Node
@export var is_hammer_found:bool = false
@export var is_hammer_delivered:bool = false
2024-07-15 22:20:49 +02:00
@export var is_bridge_built:bool = false
@export var is_completed:bool = false
2024-07-20 09:49:49 +02:00
2024-07-15 22:20:49 +02:00
@onready var bridge = %Bridge
@onready var merchant: NonPlayerCharacter = %Merchant
2024-07-15 22:20:49 +02:00
var _bridge_transform:Transform3D = Transform3D.IDENTITY
var _player:Player = null
var _merchant_conversation_actionable:ConversationActionable = null
2024-07-15 22:20:49 +02:00
signal wrench_delivered
func _ready():
_bridge_transform = bridge.global_transform
bridge.global_transform = Transform3D.IDENTITY.translated(Vector3.UP * -1000)
_player = get_tree().root.find_child("Player", true, false)
_merchant_conversation_actionable = merchant.find_child("Conversation", true, false)
assert(_merchant_conversation_actionable != null)
_merchant_conversation_actionable.conversation_started.connect(on_dialogue_started)
2024-07-15 22:20:49 +02:00
func on_dialogue_started() -> void:
_player.is_conversation_active = true
2024-07-20 09:49:49 +02:00
2024-07-15 22:20:49 +02:00
func on_dialogue_ended(_dialog_resource: DialogueResource) -> void:
_player.is_conversation_active = false
if is_completed:
return
if is_hammer_delivered and not is_bridge_built:
2024-07-15 22:20:49 +02:00
print ("Will build bridge!")
wrench_delivered.emit()
2024-07-15 22:20:49 +02:00
2024-07-20 09:49:49 +02:00
func _process(_delta):
if is_hammer_delivered:
is_bridge_built = true
bridge.global_transform = _bridge_transform
if is_completed:
return
var hammer_item:ItemResource = load("res://data/items/hammer.tres")
if _player.inventory.has_all([hammer_item]):
is_hammer_found = true
2024-07-20 09:49:49 +02:00
if is_bridge_built:
is_completed = true