Files
Dawn-Godot/scripts/Event/Quest/EventIfQuest.gd
2025-06-09 09:24:32 -05:00

78 lines
1.9 KiB
GDScript

class_name EventIfQuest extends "res://scripts/Event/Condition/EventIf.gd"
## Event that checks if a quest is in a specific state, if the condition is met
## then all children events will be run through.
##
## Can also be used as part of a trigger condition to fire if the quest state
## is updated.
enum Type {
ANY_OF_OBJECTIVES_COMPLETED,
ALL_OF_OBJECTIVES_COMPLETED,
ANY_OF_OBJECTIVES_NOT_COMPLETED,
ALL_OF_OBJECTIVES_NOT_COMPLETED,
SPECIFIC_OBJECTIVE_COMPLETED,
SPECIFIC_OBJECTIVE_NOT_COMPLETED,
QUEST_STARTED,
QUEST_NOT_STARTED,
}
@export var questKey:QuestSystem.QuestKey = QuestSystem.QuestKey.TEST_QUEST
@export var type:Type = Type.ALL_OF_OBJECTIVES_COMPLETED
@export var objective:int = 0
func ifCondition() -> bool:
var quest:Quest = QUEST.quests.get(questKey)
match type:
Type.ANY_OF_OBJECTIVES_COMPLETED:
for objective in quest.objecitves:
if !objective.isCompleted():
return true
Type.ALL_OF_OBJECTIVES_COMPLETED:
for objective in quest.objectives:
if !objective.isCompleted():
return false
return true
Type.ANY_OF_OBJECTIVES_NOT_COMPLETED:
for objective in quest.objectives:
if !objective.isCompleted():
return true
Type.ALL_OF_OBJECTIVES_NOT_COMPLETED:
for objective in quest.objectives:
if objective.isCompleted():
return false
return true
Type.SPECIFIC_OBJECTIVE_COMPLETED:
if quest.objectives[objective].isCompleted():
return true
Type.SPECIFIC_OBJECTIVE_NOT_COMPLETED:
if quest.objectives[objective].isCompleted():
return false
return true
Type.QUEST_STARTED:
if quest.isStarted():
return true
Type.QUEST_NOT_STARTED:
if !quest.isStarted():
return true
return false
func subscribeEvents() -> void:
QUEST.questUpdated.connect(onQuestUpdated)
func unsubscribeEvents() -> void:
QUEST.questUpdated.disconnect(onQuestUpdated)
func onQuestUpdated(quest:Quest) -> void:
if quest.questKey != questKey:
return
self.onEventTrigger()