Event Trigger Update
This commit is contained in:
@@ -1,8 +1,18 @@
|
||||
class_name EventIf extends "res://scripts/Event/Flow/EventGroup.gd"
|
||||
|
||||
signal eventConditionMet
|
||||
|
||||
func ifCondition() -> bool:
|
||||
return false
|
||||
|
||||
func subscribeEvents() -> void:
|
||||
# Override this method to subscribe to any events needed for the condition check
|
||||
pass
|
||||
|
||||
func unsubscribeEvents() -> void:
|
||||
# Override this method to unsubscribe from any events when the condition is no longer needed
|
||||
pass
|
||||
|
||||
func shouldAutoStart() -> bool:
|
||||
return false
|
||||
|
||||
@@ -10,4 +20,15 @@ func start() -> void:
|
||||
super.start()
|
||||
|
||||
if ifCondition():
|
||||
startEventGroup()
|
||||
startEventGroup()
|
||||
|
||||
func onEventTrigger() -> void:
|
||||
if !ifCondition():
|
||||
return
|
||||
eventConditionMet.emit()
|
||||
|
||||
func onTriggerListening(_trigger:EventTrigger) -> void:
|
||||
subscribeEvents()
|
||||
|
||||
func onTriggerNotListening(_trigger:EventTrigger) -> void:
|
||||
unsubscribeEvents()
|
||||
|
1
scripts/Event/Condition/EventIfQuest.gd.uid
Normal file
1
scripts/Event/Condition/EventIfQuest.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dwcd277pv3p1t
|
32
scripts/Event/EventTrigger.gd
Normal file
32
scripts/Event/EventTrigger.gd
Normal file
@@ -0,0 +1,32 @@
|
||||
class_name EventTrigger extends Node
|
||||
|
||||
@export var triggerMultipleTimes: bool = false
|
||||
|
||||
var eventIf:EventIf = null
|
||||
|
||||
func _enter_tree() -> void:
|
||||
for child in get_children():
|
||||
if !(child is EventIf):
|
||||
continue
|
||||
eventIf = child
|
||||
break
|
||||
|
||||
if eventIf == null:
|
||||
push_error(self, "requires an EventIf child to function properly")
|
||||
return
|
||||
|
||||
eventIf.eventConditionMet.connect(onConditionTriggered)
|
||||
eventIf.onTriggerListening(self)
|
||||
|
||||
func _exit_tree() -> void:
|
||||
if eventIf != null:
|
||||
eventIf.eventConditionMet.disconnect(onConditionTriggered)
|
||||
eventIf.onTriggerNotListening(self)
|
||||
|
||||
eventIf = null
|
||||
|
||||
func onConditionTriggered() -> void:
|
||||
if !triggerMultipleTimes:
|
||||
eventIf.eventConditionMet.disconnect(onConditionTriggered)
|
||||
eventIf.onTriggerNotListening(self)
|
||||
eventIf.start()
|
1
scripts/Event/EventTrigger.gd.uid
Normal file
1
scripts/Event/EventTrigger.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cs7voh47aoca8
|
@@ -1,4 +1,9 @@
|
||||
class_name EventIfQuestObjective extends "res://scripts/Event/Condition/EventIf.gd"
|
||||
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,
|
||||
@@ -7,64 +12,66 @@ enum Type {
|
||||
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
|
||||
@export var triggerMultipleTimes: bool = false
|
||||
|
||||
func _enter_tree() -> void:
|
||||
QUEST.questUpdated.connect(onQuestUpdated)
|
||||
func ifCondition() -> bool:
|
||||
var quest:Quest = QUEST.quests.get(questKey)
|
||||
|
||||
func _exit_tree() -> void:
|
||||
QUEST.questUpdated.disconnect(onQuestUpdated)
|
||||
|
||||
func onQuestUpdated(quest:Quest) -> void:
|
||||
if self.ended:
|
||||
if !self.triggerMultipleTimes:
|
||||
return
|
||||
self.reset()
|
||||
|
||||
if quest.questKey != self.questKey:
|
||||
return
|
||||
|
||||
if !quest.isStarted():
|
||||
return
|
||||
|
||||
match type:
|
||||
Type.ANY_OF_OBJECTIVES_COMPLETED:
|
||||
for objective in quest.objecitves:
|
||||
if !objective.isCompleted():
|
||||
continue
|
||||
self.start()
|
||||
return
|
||||
return true
|
||||
|
||||
Type.ALL_OF_OBJECTIVES_COMPLETED:
|
||||
for objective in quest.objectives:
|
||||
if !objective.isCompleted():
|
||||
return
|
||||
self.start()
|
||||
return false
|
||||
return true
|
||||
|
||||
Type.ANY_OF_OBJECTIVES_NOT_COMPLETED:
|
||||
for objective in quest.objectives:
|
||||
if objective.isCompleted():
|
||||
continue
|
||||
self.start()
|
||||
return
|
||||
if !objective.isCompleted():
|
||||
return true
|
||||
|
||||
Type.ALL_OF_OBJECTIVES_NOT_COMPLETED:
|
||||
for objective in quest.objectives:
|
||||
if objective.isCompleted():
|
||||
return
|
||||
self.start()
|
||||
return false
|
||||
return true
|
||||
|
||||
Type.SPECIFIC_OBJECTIVE_COMPLETED:
|
||||
if quest.objectives[objective].isCompleted():
|
||||
self.start()
|
||||
return
|
||||
return true
|
||||
|
||||
Type.SPECIFIC_OBJECTIVE_NOT_COMPLETED:
|
||||
if quest.objectives[objective].isCompleted():
|
||||
return
|
||||
self.start()
|
||||
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()
|
1
scripts/Event/Quest/EventIfQuest.gd.uid
Normal file
1
scripts/Event/Quest/EventIfQuest.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://0ev1l0bf85gj
|
@@ -0,0 +1 @@
|
||||
uid://0aipsu5ele44
|
1
scripts/Event/Quest/EventQuestObjectiveComplete.gd.uid
Normal file
1
scripts/Event/Quest/EventQuestObjectiveComplete.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cnbl4x8p2xsx5
|
1
scripts/Event/Quest/EventQuestObjectiveUpdate.gd.uid
Normal file
1
scripts/Event/Quest/EventQuestObjectiveUpdate.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://c2aj13e48jjd4
|
@@ -1,17 +0,0 @@
|
||||
class_name EventAutoStart extends "res://scripts/Event/Flow/EventGroup.gd"
|
||||
|
||||
@export var restartWhenEnded: bool = false
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
super._process(delta)
|
||||
|
||||
if self.ended:
|
||||
if !self.restartWhenEnded:
|
||||
return
|
||||
|
||||
self.reset()
|
||||
|
||||
if self.started && !self.ended:
|
||||
return
|
||||
|
||||
self.start()
|
@@ -1 +0,0 @@
|
||||
uid://ckeqruxf6boav
|
@@ -1,28 +0,0 @@
|
||||
class_name EventQuestAllObjectivesComplete extends "res://scripts/Event/Flow/EventGroup.gd"
|
||||
|
||||
@export var questKey:QuestSystem.QuestKey = QuestSystem.QuestKey.TEST_QUEST
|
||||
@export var triggerMultipleTimes: bool = false
|
||||
|
||||
func _enter_tree() -> void:
|
||||
QUEST.questUpdated.connect(onQuestUpdated)
|
||||
|
||||
func _exit_tree() -> void:
|
||||
QUEST.questUpdated.disconnect(onQuestUpdated)
|
||||
|
||||
func onQuestUpdated(quest:Quest) -> void:
|
||||
if self.ended:
|
||||
if !self.triggerMultipleTimes:
|
||||
return
|
||||
self.reset()
|
||||
|
||||
if quest.questKey != self.questKey:
|
||||
return
|
||||
|
||||
if !quest.isStarted():
|
||||
return
|
||||
|
||||
for objective in quest.objectives:
|
||||
if !objective.isCompleted():
|
||||
return
|
||||
|
||||
self.start()
|
@@ -1 +0,0 @@
|
||||
uid://ck0vs0awnc4n2
|
@@ -1,24 +0,0 @@
|
||||
class_name EventQuestObjectiveComplete extends "res://scripts/Event/Flow/EventGroup.gd"
|
||||
|
||||
@export var triggerIfObjectiveUncompletedThenComplatedAgain: bool = false
|
||||
@export var quest:QuestSystem.QuestKey = QuestSystem.QuestKey.TEST_QUEST
|
||||
@export var objectiveIndex:int = 0
|
||||
|
||||
func _enter_tree() -> void:
|
||||
QUEST.questUpdated.connect(onQuestUpdated)
|
||||
|
||||
func _exit_tree() -> void:
|
||||
QUEST.questUpdated.disconnect(onQuestUpdated)
|
||||
|
||||
func onQuestUpdated(quest:Quest) -> void:
|
||||
if self.ended:
|
||||
if !self.triggerIfObjectiveUncompletedThenComplatedAgain:
|
||||
return
|
||||
self.reset()
|
||||
|
||||
if !quest.isStarted():
|
||||
return
|
||||
|
||||
if !quest.objectives[objectiveIndex].isCompleted():
|
||||
return
|
||||
self.start()
|
@@ -1 +0,0 @@
|
||||
uid://baywtxo4wy5i4
|
Reference in New Issue
Block a user