Doing some more quest stuff
This commit is contained in:
@@ -26,3 +26,6 @@ func isCompleted() -> bool:
|
||||
|
||||
func isStarted() -> bool:
|
||||
return questStarted
|
||||
|
||||
func objectiveUpdated(objective:QuestObjective) -> void:
|
||||
QUEST.questUpdated.emit(self)
|
@@ -7,7 +7,34 @@ enum Type {
|
||||
@export var objectiveName:String = "Some objective"
|
||||
@export var objectiveType:Type = Type.Item
|
||||
|
||||
var quest:Quest
|
||||
@export var itemType:Item.Type = Item.Type.POTION
|
||||
@export var quantity:int = 1
|
||||
|
||||
func onQuestReady(quest:Quest) -> void:
|
||||
self.quest = quest
|
||||
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
|
Reference in New Issue
Block a user