Files
Dawn-Godot/scripts/Quest/QuestObjective.gd

54 lines
1.2 KiB
GDScript

class_name QuestObjective extends Node
enum Type {
Item,
}
@export_multiline var title:String = ""
@export_multiline var description:String = ""
@export var objectiveType:Type = Type.Item
@export var itemType:Item.Type = Item.Type.POTION
@export var quantity:int = 1
var completed:bool = false
var quest:Quest = null
func onQuestReady(_quest:Quest) -> void:
self.quest = _quest
if objectiveType == Type.Item:
QUEST.playerInventoryUpdated.connect(_onPlayerInventoryUpdated)
_onPlayerInventoryUpdated()
func _exit_tree() -> void:
QUEST.playerInventoryUpdated.disconnect(_onPlayerInventoryUpdated)
func _onPlayerInventoryUpdated() -> void:
if !quest.isStarted():
return
# Ensure player has the item
var hasItem = ITEM.PLAYER_INVENTORY.hasItem(itemType, quantity)
if hasItem && !completed:
self.completed = true
quest.objectiveUpdated(self)
else:
self.completed = false
quest.objectiveUpdated(self)
func isCompleted() -> bool:
return completed
func getTransContext() -> TransContext:
var ctx = TransContext.new()
ctx.addTrans("title", title)
ctx.addTrans("description", description)
if objectiveType == Type.Item:
ctx.addInteger("quantity", quantity)
ctx.addContext("item", ITEM.getItem(itemType).getTransContext())
return ctx