parent
abc33fd06c
commit
0170a53b5a
@ -0,0 +1,163 @@
|
||||
@tool
|
||||
extends DialogicEvent
|
||||
class_name DialogicQuestConditionEvent
|
||||
|
||||
## Event that allows branching a timeline based on a condition.
|
||||
|
||||
#enum ConditionTypes {IF, ELIF, ELSE}
|
||||
|
||||
### Settings
|
||||
## condition type (see [ConditionTypes]). Defaults to if.
|
||||
#var condition_type := ConditionTypes.IF
|
||||
## The condition as a string. Will be executed as an Expression.
|
||||
#var condition := ""
|
||||
var quest_resource: String
|
||||
var compare_status: QuestEventUtils.QuestStatusOrActive
|
||||
|
||||
################################################################################
|
||||
## EXECUTE
|
||||
################################################################################
|
||||
|
||||
func _execute() -> void:
|
||||
var resource = ResourceLoader.load(quest_resource)
|
||||
|
||||
var result: bool
|
||||
if compare_status == QuestEventUtils.QuestStatusOrActive.ACTIVE:
|
||||
result = QuestManager.GetFollowQuest() == resource
|
||||
elif compare_status == QuestEventUtils.QuestStatusOrActive.NOT_ACTIVE:
|
||||
result = QuestManager.GetFollowQuest() != resource
|
||||
else:
|
||||
result = QuestManager.GetQuestStatus(resource).status == compare_status
|
||||
|
||||
if not result:
|
||||
var idx: int = dialogic.current_event_idx
|
||||
var ignore := 1
|
||||
while true:
|
||||
idx += 1
|
||||
if not dialogic.current_timeline.get_event(idx) or ignore == 0:
|
||||
break
|
||||
elif dialogic.current_timeline.get_event(idx).can_contain_events:
|
||||
ignore += 1
|
||||
elif dialogic.current_timeline.get_event(idx) is DialogicEndBranchEvent:
|
||||
ignore -= 1
|
||||
|
||||
dialogic.current_event_idx = idx-1
|
||||
finish()
|
||||
|
||||
|
||||
## only called if the previous event was an end-branch event
|
||||
## return true if this event should be executed if the previous event was an end-branch event
|
||||
func should_execute_this_branch() -> bool:
|
||||
return true
|
||||
|
||||
|
||||
################################################################################
|
||||
## INITIALIZE
|
||||
################################################################################
|
||||
|
||||
func _init() -> void:
|
||||
event_name = "Quest Condition"
|
||||
set_default_color('Color3')
|
||||
event_category = "Quest"
|
||||
event_sorting_index = 1
|
||||
can_contain_events = true
|
||||
|
||||
|
||||
# return a control node that should show on the END BRANCH node
|
||||
func get_end_branch_control() -> Control:
|
||||
return load(get_script().resource_path.get_base_dir().path_join('ui_quest_condition_end.tscn')).instantiate()
|
||||
|
||||
################################################################################
|
||||
## SAVING/LOADING
|
||||
################################################################################
|
||||
|
||||
func to_text() -> String:
|
||||
return 'ifquest ' + quest_resource + ', ' + str(compare_status) + ':'
|
||||
|
||||
|
||||
func from_text(string:String) -> void:
|
||||
#if string.strip_edges().begins_with('if'):
|
||||
# condition = string.strip_edges().trim_prefix('if ').trim_suffix(':').strip_edges()
|
||||
# condition_type = ConditionTypes.IF
|
||||
var strings:Array[String]
|
||||
strings.assign(string.strip_edges().trim_prefix('ifquest ').trim_suffix(':').strip_edges().split(','))
|
||||
quest_resource = strings[0].strip_edges()
|
||||
var compare_string: String = strings[1].strip_edges()
|
||||
if compare_string.is_valid_int():
|
||||
compare_status = compare_string.to_int()
|
||||
else:
|
||||
compare_status = QuestEventUtils.QuestStatusOrActive.get(compare_string)
|
||||
|
||||
|
||||
func is_valid_event(string:String) -> bool:
|
||||
if string.strip_edges().begins_with('ifquest '):
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
################################################################################
|
||||
## EDITOR REPRESENTATION
|
||||
################################################################################
|
||||
|
||||
func build_event_editor() -> void:
|
||||
add_header_label("IF")
|
||||
add_header_edit(
|
||||
"quest_resource",
|
||||
ValueType.DYNAMIC_OPTIONS,
|
||||
{
|
||||
"mode":2,
|
||||
"suggestions_func":QuestEventUtils.quest_resource_suggestrions
|
||||
})
|
||||
add_header_label("IS")
|
||||
add_header_edit("compare_status",ValueType.FIXED_OPTIONS,{
|
||||
'options': [
|
||||
{
|
||||
'label': 'HIDDEN',
|
||||
'value': QuestEventUtils.QuestStatusOrActive.HIDDEN,
|
||||
},
|
||||
{
|
||||
'label': 'AVAILABLE',
|
||||
'value': QuestEventUtils.QuestStatusOrActive.AVAILABLE,
|
||||
},
|
||||
{
|
||||
'label': 'DONE',
|
||||
'value': QuestEventUtils.QuestStatusOrActive.DONE,
|
||||
},
|
||||
{
|
||||
'label': 'CANCLED',
|
||||
'value': QuestEventUtils.QuestStatusOrActive.CANCLED,
|
||||
},
|
||||
{
|
||||
'label': 'ACTIVE',
|
||||
'value': QuestEventUtils.QuestStatusOrActive.ACTIVE,
|
||||
},
|
||||
{
|
||||
'label': 'NOT_ACTIVE',
|
||||
'value': QuestEventUtils.QuestStatusOrActive.NOT_ACTIVE,
|
||||
}
|
||||
]})
|
||||
|
||||
func _get_icon() -> Resource:
|
||||
return load("res://addons/dialogic/Modules/Condition/icon.svg")
|
||||
|
||||
####################### CODE COMPLETION ########################################
|
||||
################################################################################
|
||||
|
||||
func _get_code_completion(CodeCompletionHelper:Node, TextNode:TextEdit, line:String, _word:String, symbol:String) -> void:
|
||||
pass
|
||||
|
||||
|
||||
func _get_start_code_completion(_CodeCompletionHelper:Node, TextNode:TextEdit) -> void:
|
||||
TextNode.add_code_completion_option(CodeEdit.KIND_PLAIN_TEXT, 'ifquest', 'ifquest ', TextNode.syntax_highlighter.code_flow_color)
|
||||
|
||||
|
||||
#################### SYNTAX HIGHLIGHTING #######################################
|
||||
################################################################################
|
||||
|
||||
|
||||
func _get_syntax_highlighting(Highlighter:SyntaxHighlighter, dict:Dictionary, line:String) -> Dictionary:
|
||||
var word := line.get_slice(' ', 0)
|
||||
dict[line.find(word)] = {"color":Highlighter.code_flow_color}
|
||||
dict[line.find(word)+len(word)] = {"color":Highlighter.normal_color}
|
||||
dict = Highlighter.color_condition(dict, line)
|
||||
return dict
|
||||
@ -0,0 +1 @@
|
||||
uid://b2ggc2f5kh61j
|
||||
@ -0,0 +1,51 @@
|
||||
@tool
|
||||
extends HBoxContainer
|
||||
|
||||
var parent_resource: DialogicEvent = null
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
$AddElif.button_up.connect(add_elif)
|
||||
$AddElse.button_up.connect(add_else)
|
||||
|
||||
|
||||
func refresh() -> void:
|
||||
if parent_resource is DialogicQuestConditionEvent:
|
||||
# hide add elif and add else button on ELSE event
|
||||
$AddElif.visible = false# parent_resource.condition_type != DialogicConditionEvent.ConditionTypes.ELSE
|
||||
$AddElse.visible = true# parent_resource.condition_type != DialogicConditionEvent.ConditionTypes.ELSE
|
||||
$Label.text = "End of If Quest" #"End of "+["IF", "ELIF", "ELSE"][parent_resource.condition_type]+" ("+parent_resource.condition+")"
|
||||
|
||||
# hide add add else button if followed by ELIF or ELSE event
|
||||
var timeline_editor := find_parent('VisualEditor')
|
||||
if timeline_editor:
|
||||
var next_event: DialogicEvent = null
|
||||
if timeline_editor.get_block_below(get_parent()):
|
||||
next_event = timeline_editor.get_block_below(get_parent()).resource
|
||||
if next_event is DialogicConditionEvent:
|
||||
if next_event.condition_type != DialogicConditionEvent.ConditionTypes.IF:
|
||||
$AddElse.hide()
|
||||
#if parent_resource.condition_type == DialogicConditionEvent.ConditionTypes.ELSE:
|
||||
# $Label.text = "End of ELSE"
|
||||
else:
|
||||
hide()
|
||||
|
||||
|
||||
func add_elif() -> void:
|
||||
var timeline := find_parent('VisualEditor')
|
||||
if timeline:
|
||||
var resource := DialogicConditionEvent.new()
|
||||
resource.condition_type = DialogicConditionEvent.ConditionTypes.ELIF
|
||||
timeline.add_event_undoable(resource, get_parent().get_index()+1)
|
||||
timeline.indent_events()
|
||||
timeline.something_changed()
|
||||
|
||||
|
||||
func add_else() -> void:
|
||||
var timeline := find_parent('VisualEditor')
|
||||
if timeline:
|
||||
var resource := DialogicConditionEvent.new()
|
||||
resource.condition_type = DialogicConditionEvent.ConditionTypes.ELSE
|
||||
timeline.add_event_undoable(resource, get_parent().get_index()+1)
|
||||
timeline.indent_events()
|
||||
timeline.something_changed()
|
||||
@ -0,0 +1 @@
|
||||
uid://dlrnhnnonum4o
|
||||
@ -0,0 +1,20 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://dnrpcgjkyoiau"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dlrnhnnonum4o" path="res://addons/dialogic_additions/Quest/ui_condition_end.gd" id="1_f3miq"]
|
||||
|
||||
[node name="Condition_End" type="HBoxContainer"]
|
||||
offset_right = 90.0
|
||||
offset_bottom = 23.0
|
||||
script = ExtResource("1_f3miq")
|
||||
|
||||
[node name="Label" type="Label" parent="."]
|
||||
layout_mode = 2
|
||||
text = "End of condition X"
|
||||
|
||||
[node name="AddElif" type="Button" parent="."]
|
||||
layout_mode = 2
|
||||
text = "Add Elif"
|
||||
|
||||
[node name="AddElse" type="Button" parent="."]
|
||||
layout_mode = 2
|
||||
text = "Add Else"
|
||||
@ -0,0 +1,15 @@
|
||||
Quest\: {ACTIVEQUEST}
|
||||
ifquest res://resources/quests/test/test_01.tres, 4:
|
||||
Test 1 active
|
||||
else:
|
||||
Test 1 is not active
|
||||
ifquest res://resources/quests/test/test_01.tres, 1:
|
||||
But its available
|
||||
else:
|
||||
And not available
|
||||
ifquest res://resources/quests/test/test_02.tres, 4:
|
||||
Test 2 active
|
||||
ifquest res://resources/quests/test/test_02.tres, 1:
|
||||
And Available
|
||||
else:
|
||||
Else 2
|
||||
@ -0,0 +1 @@
|
||||
uid://xfkdvitmhgln
|
||||
@ -1,4 +1,8 @@
|
||||
if {ACTIVEQUEST} == "1_talk_yeli_1":
|
||||
jump quest1_ducks_start/
|
||||
elif {ACTIVEQUEST} == "3_talk_yeli_2":
|
||||
jump quest2_tomatoes_start/
|
||||
elif {ACTIVEQUEST} == "5_talk_yeli_3":
|
||||
jump quest2_tomatoes_interim/
|
||||
else:
|
||||
No Dialog for active quest {ACTIVEQUEST}
|
||||
No Dialog for active quest "{ACTIVEQUEST}"
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
[gd_resource type="Resource" script_class="QuestResource" load_steps=2 format=3 uid="uid://d2swjixbnqkbw"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://vji5lp4qc8pp" path="res://scripts/CSharp/Common/Quest/QuestResource.cs" id="1_e51xd"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_e51xd")
|
||||
id = "4_collect_tools"
|
||||
title = "Collect the farm tools"
|
||||
description = "Collect the Watering Can next to the well and the Hoe by the fence."
|
||||
metadata/_custom_type_script = "uid://vji5lp4qc8pp"
|
||||
@ -0,0 +1,10 @@
|
||||
[gd_resource type="Resource" script_class="QuestResource" load_steps=2 format=3 uid="uid://5t8g0firdif0"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://vji5lp4qc8pp" path="res://scripts/CSharp/Common/Quest/QuestResource.cs" id="1_x7fvu"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_x7fvu")
|
||||
id = "5_talk_yeli_3"
|
||||
title = "Talk to Yeli again"
|
||||
description = "After the long and agonizing task of finding and collecting two tools, go talk to Yeli once again."
|
||||
metadata/_custom_type_script = "uid://vji5lp4qc8pp"
|
||||
@ -0,0 +1,10 @@
|
||||
[gd_resource type="Resource" script_class="QuestResource" load_steps=2 format=3 uid="uid://h05jgxqtq37m"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://vji5lp4qc8pp" path="res://scripts/CSharp/Common/Quest/QuestResource.cs" id="1_745w5"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_745w5")
|
||||
id = "6_till_and_water"
|
||||
title = "Till and water the fields"
|
||||
description = "Use the hoe to break up the soil. Then plant the seeds and water the fields."
|
||||
metadata/_custom_type_script = "uid://vji5lp4qc8pp"
|
||||
@ -0,0 +1,74 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://baunkb4wwtl32"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cldtt4atgymm5" path="res://scripts/CSharp/Common/Quest/QuestTrigger.cs" id="1_wnfrg"]
|
||||
[ext_resource type="Resource" uid="uid://0aruj4lm74n6" path="res://resources/quests/test/test_01.tres" id="2_nud5h"]
|
||||
[ext_resource type="Resource" uid="uid://be1dmc6d2mxl5" path="res://resources/quests/test/test_02.tres" id="3_tb5fn"]
|
||||
[ext_resource type="Script" uid="uid://d2486x6upmwqq" path="res://scripts/GdScript/dialogic_starter.gd" id="4_6p0xc"]
|
||||
|
||||
[node name="BabushkaTestsQuestDialogic" type="Node2D"]
|
||||
|
||||
[node name="Button" type="Button" parent="."]
|
||||
offset_left = 105.0
|
||||
offset_top = 47.0
|
||||
offset_right = 423.0
|
||||
offset_bottom = 185.0
|
||||
text = "Start Quest 1"
|
||||
|
||||
[node name="Node" type="Node" parent="Button"]
|
||||
script = ExtResource("1_wnfrg")
|
||||
questResource = ExtResource("2_nud5h")
|
||||
toStatus = 1
|
||||
makeCurrent = true
|
||||
|
||||
[node name="Button2" type="Button" parent="."]
|
||||
offset_left = 460.0
|
||||
offset_top = 49.0
|
||||
offset_right = 778.0
|
||||
offset_bottom = 187.0
|
||||
text = "End Quest 1"
|
||||
|
||||
[node name="Node" type="Node" parent="Button2"]
|
||||
script = ExtResource("1_wnfrg")
|
||||
questResource = ExtResource("2_nud5h")
|
||||
toStatus = 2
|
||||
|
||||
[node name="Button3" type="Button" parent="."]
|
||||
offset_left = 105.0
|
||||
offset_top = 215.0
|
||||
offset_right = 423.0
|
||||
offset_bottom = 353.0
|
||||
text = "Start Quest 2"
|
||||
|
||||
[node name="Node" type="Node" parent="Button3"]
|
||||
script = ExtResource("1_wnfrg")
|
||||
questResource = ExtResource("3_tb5fn")
|
||||
toStatus = 1
|
||||
makeCurrent = true
|
||||
|
||||
[node name="Button4" type="Button" parent="."]
|
||||
offset_left = 460.0
|
||||
offset_top = 217.0
|
||||
offset_right = 778.0
|
||||
offset_bottom = 355.0
|
||||
text = "End Quest 2"
|
||||
|
||||
[node name="Node" type="Node" parent="Button4"]
|
||||
script = ExtResource("1_wnfrg")
|
||||
questResource = ExtResource("3_tb5fn")
|
||||
toStatus = 2
|
||||
|
||||
[node name="Button5" type="Button" parent="."]
|
||||
offset_left = 1314.0
|
||||
offset_top = 67.0
|
||||
offset_right = 1632.0
|
||||
offset_bottom = 205.0
|
||||
text = "Start Dialog"
|
||||
|
||||
[node name="Node" type="Node" parent="Button5"]
|
||||
script = ExtResource("4_6p0xc")
|
||||
|
||||
[connection signal="pressed" from="Button" to="Button/Node" method="Trigger"]
|
||||
[connection signal="pressed" from="Button2" to="Button2/Node" method="Trigger"]
|
||||
[connection signal="pressed" from="Button3" to="Button3/Node" method="Trigger"]
|
||||
[connection signal="pressed" from="Button4" to="Button4/Node" method="Trigger"]
|
||||
[connection signal="pressed" from="Button5" to="Button5/Node" method="open" binds= ["test_1"]]
|
||||
@ -1,20 +1,22 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Babushka.scripts.CSharp.Common.Quest;
|
||||
using Godot.Collections;
|
||||
|
||||
public partial class QuestTestingScript : Node
|
||||
{
|
||||
[Export(PropertyHint.ArrayType)]
|
||||
private Array<QuestResource> _questsToActivate;
|
||||
private Array<QuestResource>? _questsToActivate;
|
||||
|
||||
public override void _EnterTree()
|
||||
{
|
||||
Debug.Assert(_questsToActivate != null);
|
||||
|
||||
foreach (var questResource in _questsToActivate)
|
||||
{
|
||||
QuestManager.Instance.ChangeQuestStatus(questResource, QuestStatus.Status.Active);
|
||||
QuestManager.Instance!.ChangeQuestStatus(questResource, QuestStatus.Status.Active);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Babushka.scripts.CSharp.Common.Inventory;
|
||||
using Babushka.scripts.CSharp.Common.Quest;
|
||||
|
||||
public partial class DetectInventoryContains : QuestFulfillmentBase
|
||||
{
|
||||
[Export(PropertyHint.ArrayType)] private ItemInstance[] _itemsToContain = null!;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
QuestManager.Instance!.QuestsChanged += CheckInventory;
|
||||
InventoryManager.Instance.playerInventory.InventoryContentsChanged += CheckInventory;
|
||||
|
||||
CheckInventory();
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
QuestManager.Instance!.QuestsChanged -= CheckInventory;
|
||||
InventoryManager.Instance.playerInventory.InventoryContentsChanged -= CheckInventory;
|
||||
}
|
||||
|
||||
private void CheckInventory()
|
||||
{
|
||||
if (IsQuestActive() && InventoryManager.Instance.playerInventory.HasItems(_itemsToContain))
|
||||
{
|
||||
Fulfill();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
uid://c741nyedy26mx
|
||||
@ -0,0 +1,6 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class DetectToolCollection : Node
|
||||
{
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
uid://caohn76m3n3nm
|
||||
@ -0,0 +1,35 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Babushka.scripts.CSharp.Common.Quest;
|
||||
|
||||
public abstract partial class QuestFulfillmentBase : Node
|
||||
{
|
||||
[Export] private QuestResource _onActiveQuest;
|
||||
[Export] private QuestResource _toNextQuest;
|
||||
|
||||
[Export] private bool _whenFulfilledSetActiveQuestToDone = true;
|
||||
[Export] private bool _whenFulfilledSetNextQuestToActive = true;
|
||||
[Export] private bool _whenFulfilledSetNextQuestToFollow = true;
|
||||
|
||||
protected void Fulfill()
|
||||
{
|
||||
if (_whenFulfilledSetActiveQuestToDone)
|
||||
{
|
||||
QuestManager.Instance!.ChangeQuestStatus(_onActiveQuest, QuestStatus.Status.Done);
|
||||
}
|
||||
if (_whenFulfilledSetNextQuestToActive)
|
||||
{
|
||||
QuestManager.Instance!.ChangeQuestStatus(_toNextQuest, QuestStatus.Status.Active);
|
||||
}
|
||||
if (_whenFulfilledSetNextQuestToFollow)
|
||||
{
|
||||
QuestManager.Instance!.SetFollowQuest(_toNextQuest);
|
||||
}
|
||||
}
|
||||
|
||||
protected bool IsQuestActive()
|
||||
{
|
||||
return QuestManager.Instance!.GetActiveQuests().Any(q => q.Key == _onActiveQuest);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
uid://dw158xraniqkd
|
||||
Loading…
Reference in new issue