Files
Dawn-Godot/overworld/entity/EntityInteractableArea.gd
2026-01-15 17:28:39 -06:00

69 lines
1.7 KiB
GDScript

class_name EntityInteractableArea extends Area3D
const ItemAction = preload("res://cutscene/item/ItemAction.gd")
@export var entity:Entity
func isInteractable() -> bool:
if !entity:
return false
if entity.interactType == Entity.InteractType.NONE:
return false
if entity.interactType == Entity.InteractType.CONVERSATION:
if entity.conversation.size() == 0:
return false
return true
if entity.interactType == Entity.InteractType.CUTSCENE:
if entity.cutscene == null:
return false
if !entity.cutscene.canRun():
return false
return true
if entity.interactType == Entity.InteractType.ONE_TIME_ITEM:
if entity.oneTimeItem == null:
return false
if entity.oneTimeItem.quantity <= 0:
return false
if entity.oneTimeItem.item == Item.Id.NULL:
return false
return true
return false
func _onConversationInteract(_other:Entity) -> void:
var cutscene:Cutscene = Cutscene.new()
cutscene.addConversation(entity.conversation)
cutscene.start()
func _onItemInteract(_other:Entity) -> void:
assert(entity.oneTimeItem != null)
var cutscene:Cutscene = Cutscene.new()
cutscene.addCallable(ItemAction.getItemCallable(entity.oneTimeItem.toItemStack()))
await cutscene.start()
entity.queue_free()
func onInteract(other:Entity) -> void:
if entity.interactType == Entity.InteractType.NONE:
return
match entity.interactType:
Entity.InteractType.CONVERSATION:
_onConversationInteract(other)
return
Entity.InteractType.ONE_TIME_ITEM:
_onItemInteract(other)
return
Entity.InteractType.CUTSCENE:
var cutscene:Cutscene = Cutscene.new()
entity.cutscene.queue(cutscene)
cutscene.start()
return
_:
pass