diff --git a/scenes/Maps/TestMap/TestMap.tscn b/scenes/Maps/TestMap/TestMap.tscn index 2d603fd..afd36ba 100644 --- a/scenes/Maps/TestMap/TestMap.tscn +++ b/scenes/Maps/TestMap/TestMap.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=18 format=3 uid="uid://dx6fv8n4jl5ku"] +[gd_scene load_steps=17 format=3 uid="uid://dx6fv8n4jl5ku"] [ext_resource type="PackedScene" uid="uid://yhtpoum3eek7" path="res://scenes/Entities/Rosa.tscn" id="1_7b7hx"] [ext_resource type="Script" uid="uid://c37crdel0m5mw" path="res://scripts/Map/Map.gd" id="1_ru75d"] @@ -11,9 +11,8 @@ [ext_resource type="Script" uid="uid://c4d7nithqnx5y" path="res://scripts/Event/Quest/EventStartQuest.gd" id="7_brp0k"] [ext_resource type="PackedScene" uid="uid://bkj630bhmnvsi" path="res://scenes/Entities/Sign.tscn" id="9_xfqoe"] [ext_resource type="Script" uid="uid://b41umpbgqfuc2" path="res://scripts/Event/Item/EventGetItem.gd" id="10_avybc"] -[ext_resource type="Script" uid="uid://0ygswaohp7kj" path="res://scripts/Event/EventFlagModify.gd" id="12_ncdgy"] -[ext_resource type="Script" uid="uid://ccujhcc446mvh" path="res://scripts/Event/Condition/EventIfFlag.gd" id="13_60ixl"] -[ext_resource type="Script" uid="uid://cvrib7pjlip8g" path="res://scripts/Event/Condition/EventIfQuestObjective.gd" id="14_i48p6"] +[ext_resource type="Script" uid="uid://0ev1l0bf85gj" path="res://scripts/Event/Quest/EventIfQuest.gd" id="10_i48p6"] +[ext_resource type="Script" uid="uid://cs7voh47aoca8" path="res://scripts/Event/EventTrigger.gd" id="13_60ixl"] [sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_e1h75"] sky_horizon_color = Color(0.59625, 0.6135, 0.6375, 1) @@ -103,21 +102,29 @@ omni_range = 281.646 script = ExtResource("5_cg1ph") [node name="After Quest Started" type="Node" parent="Events/TestConversation"] -script = ExtResource("13_60ixl") -event = 1 -eventFlag = 1 -metadata/_custom_type_script = "uid://ccujhcc446mvh" +script = ExtResource("10_i48p6") +type = 6 +metadata/_custom_type_script = "uid://0ev1l0bf85gj" -[node name="Text 2" type="Node" parent="Events/TestConversation/After Quest Started"] +[node name="EventIfQuest" type="Node" parent="Events/TestConversation/After Quest Started"] +script = ExtResource("10_i48p6") + +[node name="Text 2" type="Node" parent="Events/TestConversation/After Quest Started/EventIfQuest"] +script = ExtResource("6_gxq5o") +text = "You are reading the words fo god" + +[node name="EventIfQuest2" type="Node" parent="Events/TestConversation/After Quest Started"] +script = ExtResource("10_i48p6") +type = 2 + +[node name="Text 2" type="Node" parent="Events/TestConversation/After Quest Started/EventIfQuest2"] script = ExtResource("6_gxq5o") text = "map.test_map.event.gather_onion.text2" [node name="Before Quest Started" type="Node" parent="Events/TestConversation"] -script = ExtResource("13_60ixl") -event = 1 -type = 2 -eventFlag = 1 -metadata/_custom_type_script = "uid://ccujhcc446mvh" +script = ExtResource("10_i48p6") +type = 7 +metadata/_custom_type_script = "uid://0ev1l0bf85gj" [node name="Text 0" type="Node" parent="Events/TestConversation/Before Quest Started"] script = ExtResource("6_gxq5o") @@ -136,17 +143,14 @@ script = ExtResource("10_avybc") getType = 1 metadata/_custom_type_script = "uid://b41umpbgqfuc2" -[node name="EventFlagModify" type="Node" parent="Events/TestConversation/Before Quest Started"] -script = ExtResource("12_ncdgy") -event = 1 -eventFlag = 1 -metadata/_custom_type_script = "uid://0ygswaohp7kj" +[node name="EventTrigger" type="Node" parent="Events"] +script = ExtResource("13_60ixl") -[node name="EventQuestAllObjectivesComplete" type="Node" parent="Events"] -script = ExtResource("14_i48p6") -metadata/_custom_type_script = "uid://cvrib7pjlip8g" +[node name="EventIf" type="Node" parent="Events/EventTrigger"] +script = ExtResource("10_i48p6") +type = 6 +metadata/_custom_type_script = "uid://0ev1l0bf85gj" -[node name="TextTest" type="Node" parent="Events/EventQuestAllObjectivesComplete"] +[node name="Text 0" type="Node" parent="Events/EventTrigger/EventIf"] script = ExtResource("6_gxq5o") -text = "testestest -" +text = "Triggered" diff --git a/scripts/Event/Condition/EventIf.gd b/scripts/Event/Condition/EventIf.gd index 65149c6..93bc108 100644 --- a/scripts/Event/Condition/EventIf.gd +++ b/scripts/Event/Condition/EventIf.gd @@ -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() \ No newline at end of file + startEventGroup() + +func onEventTrigger() -> void: + if !ifCondition(): + return + eventConditionMet.emit() + +func onTriggerListening(_trigger:EventTrigger) -> void: + subscribeEvents() + +func onTriggerNotListening(_trigger:EventTrigger) -> void: + unsubscribeEvents() diff --git a/scripts/Event/Condition/EventIfQuest.gd.uid b/scripts/Event/Condition/EventIfQuest.gd.uid new file mode 100644 index 0000000..22c3718 --- /dev/null +++ b/scripts/Event/Condition/EventIfQuest.gd.uid @@ -0,0 +1 @@ +uid://dwcd277pv3p1t diff --git a/scripts/Event/EventTrigger.gd b/scripts/Event/EventTrigger.gd new file mode 100644 index 0000000..fce921d --- /dev/null +++ b/scripts/Event/EventTrigger.gd @@ -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() \ No newline at end of file diff --git a/scripts/Event/EventTrigger.gd.uid b/scripts/Event/EventTrigger.gd.uid new file mode 100644 index 0000000..83918a8 --- /dev/null +++ b/scripts/Event/EventTrigger.gd.uid @@ -0,0 +1 @@ +uid://cs7voh47aoca8 diff --git a/scripts/Event/Condition/EventIfQuestObjective.gd b/scripts/Event/Quest/EventIfQuest.gd similarity index 56% rename from scripts/Event/Condition/EventIfQuestObjective.gd rename to scripts/Event/Quest/EventIfQuest.gd index 88c744d..1f47542 100644 --- a/scripts/Event/Condition/EventIfQuestObjective.gd +++ b/scripts/Event/Quest/EventIfQuest.gd @@ -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() diff --git a/scripts/Event/Quest/EventIfQuest.gd.uid b/scripts/Event/Quest/EventIfQuest.gd.uid new file mode 100644 index 0000000..b85422b --- /dev/null +++ b/scripts/Event/Quest/EventIfQuest.gd.uid @@ -0,0 +1 @@ +uid://0ev1l0bf85gj diff --git a/scripts/Event/Quest/EventQuestAllObjectivesComplete.gd.uid b/scripts/Event/Quest/EventQuestAllObjectivesComplete.gd.uid new file mode 100644 index 0000000..f51265d --- /dev/null +++ b/scripts/Event/Quest/EventQuestAllObjectivesComplete.gd.uid @@ -0,0 +1 @@ +uid://0aipsu5ele44 diff --git a/scripts/Event/Quest/EventQuestObjectiveComplete.gd.uid b/scripts/Event/Quest/EventQuestObjectiveComplete.gd.uid new file mode 100644 index 0000000..f69a1e5 --- /dev/null +++ b/scripts/Event/Quest/EventQuestObjectiveComplete.gd.uid @@ -0,0 +1 @@ +uid://cnbl4x8p2xsx5 diff --git a/scripts/Event/Quest/EventQuestObjectiveUpdate.gd.uid b/scripts/Event/Quest/EventQuestObjectiveUpdate.gd.uid new file mode 100644 index 0000000..d632248 --- /dev/null +++ b/scripts/Event/Quest/EventQuestObjectiveUpdate.gd.uid @@ -0,0 +1 @@ +uid://c2aj13e48jjd4 diff --git a/scripts/Event/Trigger/EventAutoStart.gd b/scripts/Event/Trigger/EventAutoStart.gd deleted file mode 100644 index 852532f..0000000 --- a/scripts/Event/Trigger/EventAutoStart.gd +++ /dev/null @@ -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() \ No newline at end of file diff --git a/scripts/Event/Trigger/EventAutoStart.gd.uid b/scripts/Event/Trigger/EventAutoStart.gd.uid deleted file mode 100644 index fcf1820..0000000 --- a/scripts/Event/Trigger/EventAutoStart.gd.uid +++ /dev/null @@ -1 +0,0 @@ -uid://ckeqruxf6boav diff --git a/scripts/Event/Trigger/EventQuestAllObjectivesComplete.gd b/scripts/Event/Trigger/EventQuestAllObjectivesComplete.gd deleted file mode 100644 index 271b2f2..0000000 --- a/scripts/Event/Trigger/EventQuestAllObjectivesComplete.gd +++ /dev/null @@ -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() \ No newline at end of file diff --git a/scripts/Event/Trigger/EventQuestAllObjectivesComplete.gd.uid b/scripts/Event/Trigger/EventQuestAllObjectivesComplete.gd.uid deleted file mode 100644 index 66c8ec6..0000000 --- a/scripts/Event/Trigger/EventQuestAllObjectivesComplete.gd.uid +++ /dev/null @@ -1 +0,0 @@ -uid://ck0vs0awnc4n2 diff --git a/scripts/Event/Trigger/EventQuestObjectiveComplete.gd b/scripts/Event/Trigger/EventQuestObjectiveComplete.gd deleted file mode 100644 index aa14c05..0000000 --- a/scripts/Event/Trigger/EventQuestObjectiveComplete.gd +++ /dev/null @@ -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() \ No newline at end of file diff --git a/scripts/Event/Trigger/EventQuestObjectiveComplete.gd.uid b/scripts/Event/Trigger/EventQuestObjectiveComplete.gd.uid deleted file mode 100644 index 425520c..0000000 --- a/scripts/Event/Trigger/EventQuestObjectiveComplete.gd.uid +++ /dev/null @@ -1 +0,0 @@ -uid://baywtxo4wy5i4 diff --git a/scripts/Quest/Quest.gd b/scripts/Quest/Quest.gd index 75abe5b..a1b8c64 100644 --- a/scripts/Quest/Quest.gd +++ b/scripts/Quest/Quest.gd @@ -27,7 +27,7 @@ func isCompleted() -> bool: func isStarted() -> bool: return questStarted -func objectiveUpdated(objective:QuestObjective) -> void: +func objectiveUpdated(_objective:QuestObjective) -> void: QUEST.questUpdated.emit(self) func getTransContext() -> TransContext: