Improved quest system
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
extends Node
|
extends Node
|
||||||
signal user_click
|
signal user_click
|
||||||
|
signal action1
|
||||||
|
|
||||||
var frame_tf: Transform = Transform()
|
var frame_tf: Transform = Transform()
|
||||||
var master_node: Node
|
var master_node: Node
|
||||||
@@ -25,6 +26,16 @@ func _process(delta):
|
|||||||
if Input.is_action_pressed("move_west"):
|
if Input.is_action_pressed("move_west"):
|
||||||
var tf_turn = Transform(Quat(Vector3(0, 1, 0), PI * 0.6 * delta))
|
var tf_turn = Transform(Quat(Vector3(0, 1, 0), PI * 0.6 * delta))
|
||||||
frame_tf *= tf_turn
|
frame_tf *= tf_turn
|
||||||
|
if Input.is_action_just_pressed("action1"):
|
||||||
|
if monitored_objects.size() > 0:
|
||||||
|
var closest = monitored_objects[0]
|
||||||
|
var dst = master_node.global_transform.origin.distance_to(closest.global_transform.origin)
|
||||||
|
for k in monitored_objects:
|
||||||
|
var ndst = master_node.global_transform.origin.distance_to(k.global_transform.origin)
|
||||||
|
if dst > ndst:
|
||||||
|
dst = ndst
|
||||||
|
closest = k
|
||||||
|
emit_signal("action1", closest)
|
||||||
var act_obj = null
|
var act_obj = null
|
||||||
var act_dist = -1.0
|
var act_dist = -1.0
|
||||||
var opos = master_node.global_transform.origin
|
var opos = master_node.global_transform.origin
|
||||||
|
|||||||
@@ -21,6 +21,10 @@ func update_quests():
|
|||||||
func start_quest(quest: Quest):
|
func start_quest(quest: Quest):
|
||||||
$start_quest_notification.start_notification(quest.get_title(), quest.get_description())
|
$start_quest_notification.start_notification(quest.get_title(), quest.get_description())
|
||||||
|
|
||||||
|
func start_interaction(obj):
|
||||||
|
print("started interaction")
|
||||||
|
$interaction.start_interaction(obj)
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
$master.add_to_group("master")
|
$master.add_to_group("master")
|
||||||
controls.master_node = $master
|
controls.master_node = $master
|
||||||
@@ -31,13 +35,14 @@ func _ready():
|
|||||||
controls.connect("user_click", self, "master_control")
|
controls.connect("user_click", self, "master_control")
|
||||||
for k in world.line.keys():
|
for k in world.line.keys():
|
||||||
var cd = world.line[k]
|
var cd = world.line[k]
|
||||||
if cd.type == 0:
|
if cd.gender == 0:
|
||||||
var char_sc = characters.characters[0].instance()
|
var char_sc = characters.characters[0].instance()
|
||||||
cd.scene = char_sc
|
cd.scene = char_sc
|
||||||
get_tree().get_root().add_child(char_sc)
|
get_tree().get_root().add_child(char_sc)
|
||||||
var nav: Navigation2D = get_node("nav")
|
var nav: Navigation2D = get_node("nav")
|
||||||
var p = nav.get_closest_point(get_node("line_spawn").global_transform.origin + Vector3(randf() * 20.0 - 10.0, 0.0, randf() * 20 - 10.0))
|
var p = nav.get_closest_point(get_node("line_spawn").global_transform.origin + Vector3(randf() * 20.0 - 10.0, 0.0, randf() * 20 - 10.0))
|
||||||
char_sc.translation = p
|
char_sc.translation = p
|
||||||
|
cd.id = k
|
||||||
char_sc.set_meta("data", cd)
|
char_sc.set_meta("data", cd)
|
||||||
# world.team[newkey] = cd
|
# world.team[newkey] = cd
|
||||||
# world.line.erase(k)
|
# world.line.erase(k)
|
||||||
@@ -48,12 +53,21 @@ func _ready():
|
|||||||
var nav: Navigation2D = get_node("nav")
|
var nav: Navigation2D = get_node("nav")
|
||||||
var p = nav.get_closest_point(get_node("line_spawn").global_transform.origin + Vector3(randf() * 20.0 - 10.0, 0.0, randf() * 20 - 10.0))
|
var p = nav.get_closest_point(get_node("line_spawn").global_transform.origin + Vector3(randf() * 20.0 - 10.0, 0.0, randf() * 20 - 10.0))
|
||||||
char_sc.translation = p
|
char_sc.translation = p
|
||||||
|
cd.id = k
|
||||||
char_sc.set_meta("data", cd)
|
char_sc.set_meta("data", cd)
|
||||||
# world.team[newkey] = cd
|
# world.team[newkey] = cd
|
||||||
# cd.scene.set_meta("data", cd)
|
# cd.scene.set_meta("data", cd)
|
||||||
var tut_quest = Quest.new("Tutorial", "This quest shortly introduces to a game")
|
var tut_quest = Quest.new("Tutorial", "This quest shortly introduces to a game")
|
||||||
tut_quest.connect("started", self, "start_quest")
|
tut_quest.connect("started", self, "start_quest")
|
||||||
world.quests.push_back(tut_quest)
|
world.quests.push_back(tut_quest)
|
||||||
|
var tut1_quest = WalkQuest.new("Walk to closet room", "Walk to closet room designated location", get_node("quest_dst_closet"))
|
||||||
|
var tut2_quest = StatsQuest.new("Hire team members", "Hire new team members to start with your team", {"player_count": 6})
|
||||||
|
var tut3_quest = WalkQuest.new("Walk to gym", "Walk to gym designated location", get_node("quest_dst_gym"))
|
||||||
|
var tut4_quest = StatsQuest.new("Train your team", "Complete your team training once", {"team_train_count": 1})
|
||||||
|
tut1_quest.set_next_quest(tut2_quest)
|
||||||
|
tut2_quest.set_next_quest(tut3_quest)
|
||||||
|
tut3_quest.set_next_quest(tut4_quest)
|
||||||
|
tut_quest.add_child(tut1_quest)
|
||||||
tut_quest.start()
|
tut_quest.start()
|
||||||
update_quests()
|
update_quests()
|
||||||
var quest_timer : = Timer.new()
|
var quest_timer : = Timer.new()
|
||||||
@@ -61,10 +75,8 @@ func _ready():
|
|||||||
add_child(quest_timer)
|
add_child(quest_timer)
|
||||||
quest_timer.connect("timeout", self, "update_quests")
|
quest_timer.connect("timeout", self, "update_quests")
|
||||||
quest_timer.start()
|
quest_timer.start()
|
||||||
|
controls.connect("action1", self, "start_interaction")
|
||||||
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
var pos = $master.global_transform.origin
|
var pos = $master.global_transform.origin
|
||||||
pos.y = $Camera.global_transform.origin.y
|
pos.y = $Camera.global_transform.origin.y
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
13
proto2/markers/quest_marker.tscn
Normal file
13
proto2/markers/quest_marker.tscn
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
[gd_scene load_steps=3 format=2]
|
||||||
|
|
||||||
|
[sub_resource type="SphereMesh" id=1]
|
||||||
|
|
||||||
|
[sub_resource type="SpatialMaterial" id=2]
|
||||||
|
flags_transparent = true
|
||||||
|
albedo_color = Color( 1, 0.921569, 0.105882, 0.505882 )
|
||||||
|
|
||||||
|
[node name="quest_marker" type="Spatial"]
|
||||||
|
|
||||||
|
[node name="MeshInstance" type="MeshInstance" parent="."]
|
||||||
|
mesh = SubResource( 1 )
|
||||||
|
material/0 = SubResource( 2 )
|
||||||
@@ -23,11 +23,23 @@ _global_script_classes=[ {
|
|||||||
"class": "QuestObjective",
|
"class": "QuestObjective",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://system/quest_objective.gd"
|
"path": "res://system/quest_objective.gd"
|
||||||
|
}, {
|
||||||
|
"base": "Quest",
|
||||||
|
"class": "StatsQuest",
|
||||||
|
"language": "GDScript",
|
||||||
|
"path": "res://system/stats_quest.gd"
|
||||||
|
}, {
|
||||||
|
"base": "Quest",
|
||||||
|
"class": "WalkQuest",
|
||||||
|
"language": "GDScript",
|
||||||
|
"path": "res://system/walk_quest.gd"
|
||||||
} ]
|
} ]
|
||||||
_global_script_class_icons={
|
_global_script_class_icons={
|
||||||
"BallGameAI": "",
|
"BallGameAI": "",
|
||||||
"Quest": "",
|
"Quest": "",
|
||||||
"QuestObjective": ""
|
"QuestObjective": "",
|
||||||
|
"StatsQuest": "",
|
||||||
|
"WalkQuest": ""
|
||||||
}
|
}
|
||||||
|
|
||||||
[application]
|
[application]
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ var _title: String
|
|||||||
var _description: String
|
var _description: String
|
||||||
var _active: bool = false
|
var _active: bool = false
|
||||||
var _complete: bool = false
|
var _complete: bool = false
|
||||||
|
var _next_quest: Quest
|
||||||
func _init(title: String, description: String):
|
func _init(title: String, description: String):
|
||||||
_title = title
|
_title = title
|
||||||
_description = description
|
_description = description
|
||||||
@@ -21,10 +22,10 @@ func is_active():
|
|||||||
func update():
|
func update():
|
||||||
if !_active:
|
if !_active:
|
||||||
return
|
return
|
||||||
var m = get_meta("quest")
|
# var m = get_meta("quest")
|
||||||
if m != null:
|
# if m != null:
|
||||||
for k in _objectives:
|
# for k in _objectives:
|
||||||
k.set_meta("quest", m)
|
# k.set_meta("quest", m)
|
||||||
for k in _objectives:
|
for k in _objectives:
|
||||||
k.update()
|
k.update()
|
||||||
for k in _children:
|
for k in _children:
|
||||||
@@ -35,19 +36,32 @@ func update():
|
|||||||
_complete = false
|
_complete = false
|
||||||
break
|
break
|
||||||
if !_complete:
|
if !_complete:
|
||||||
|
print("quest: ", _title, " objectives incomplete")
|
||||||
return
|
return
|
||||||
for k in _children:
|
for k in _children:
|
||||||
if !k.is_complete():
|
if !k.is_complete():
|
||||||
_complete = false
|
_complete = false
|
||||||
break
|
break
|
||||||
|
if !_complete:
|
||||||
|
print("quest: ", _title, " children incomplete")
|
||||||
if _complete:
|
if _complete:
|
||||||
emit_signal("complete", self)
|
emit_signal("complete", self)
|
||||||
_active = false
|
_active = false
|
||||||
|
quest_complete()
|
||||||
|
func quest_complete_handler(quest: Quest):
|
||||||
|
var next = quest.get_next_quest()
|
||||||
|
if next != null:
|
||||||
|
add_child(next)
|
||||||
|
next.connect("complete", self, "quest_complete_handler")
|
||||||
|
next.start()
|
||||||
func start():
|
func start():
|
||||||
_active = true
|
_active = true
|
||||||
for k in _children:
|
for k in _children:
|
||||||
|
k.connect("complete", self, "quest_complete_handler")
|
||||||
k.start()
|
k.start()
|
||||||
emit_signal("started", self)
|
emit_signal("started", self)
|
||||||
|
print("children: ", _children)
|
||||||
|
print("quest: ", _title, " started")
|
||||||
func get_cur_task_text():
|
func get_cur_task_text():
|
||||||
var ret: String = "No current task"
|
var ret: String = "No current task"
|
||||||
if _active:
|
if _active:
|
||||||
@@ -64,3 +78,15 @@ func get_title():
|
|||||||
return _title
|
return _title
|
||||||
func get_description():
|
func get_description():
|
||||||
return _description
|
return _description
|
||||||
|
func quest_complete():
|
||||||
|
print("quest: ", _title, " complete")
|
||||||
|
func add_objective(obj: QuestObjective):
|
||||||
|
if !obj in _objectives:
|
||||||
|
_objectives.push_back(obj)
|
||||||
|
func remove_objective(obj: QuestObjective):
|
||||||
|
if obj in _objectives:
|
||||||
|
_objectives.erase(obj)
|
||||||
|
func set_next_quest(obj: Quest):
|
||||||
|
_next_quest = obj
|
||||||
|
func get_next_quest() -> Quest:
|
||||||
|
return _next_quest
|
||||||
|
|||||||
26
proto2/system/stats_quest.gd
Normal file
26
proto2/system/stats_quest.gd
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
extends Quest
|
||||||
|
class_name StatsQuest
|
||||||
|
|
||||||
|
var stat_check: Dictionary
|
||||||
|
|
||||||
|
class StatsCheckObjective extends QuestObjective:
|
||||||
|
var stat_check: Dictionary
|
||||||
|
func _init(title, stats: Dictionary).(title):
|
||||||
|
stat_check = stats
|
||||||
|
func update():
|
||||||
|
_complete = true
|
||||||
|
for k in stat_check.keys():
|
||||||
|
match(k):
|
||||||
|
"player_count":
|
||||||
|
if world.team.keys().size() < stat_check[k]:
|
||||||
|
_complete = false
|
||||||
|
print("player count: ", world.team.keys().size(), " < ", stat_check[k])
|
||||||
|
"cheerleader_count":
|
||||||
|
if world.cheer_team.keys().size() < stat_check[k]:
|
||||||
|
_complete = false
|
||||||
|
_:
|
||||||
|
_complete = false
|
||||||
|
|
||||||
|
func _init(title, desc, stats: Dictionary).(title, desc):
|
||||||
|
stat_check = stats
|
||||||
|
add_objective(StatsCheckObjective.new("Comply to team stats", stat_check))
|
||||||
34
proto2/system/walk_quest.gd
Normal file
34
proto2/system/walk_quest.gd
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
extends Quest
|
||||||
|
class_name WalkQuest
|
||||||
|
|
||||||
|
# Declare member variables here. Examples:
|
||||||
|
# var a = 2
|
||||||
|
# var b = "text"
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
var destination: Spatial
|
||||||
|
var quest_marker: Spatial
|
||||||
|
class WalkQuestObjective extends QuestObjective:
|
||||||
|
var dest: Spatial
|
||||||
|
func _init(title, destination: Spatial).(title):
|
||||||
|
dest = destination
|
||||||
|
func update():
|
||||||
|
var org = world.master_node.global_transform.origin
|
||||||
|
if org.distance_to(dest.global_transform.origin) < 2.5:
|
||||||
|
_complete = true
|
||||||
|
func _init(title, desc, dest).(title, desc):
|
||||||
|
destination = dest
|
||||||
|
add_objective(WalkQuestObjective.new("Walk to destination", dest))
|
||||||
|
func update():
|
||||||
|
.update()
|
||||||
|
func start():
|
||||||
|
.start()
|
||||||
|
quest_marker = load("res://markers/quest_marker.tscn").instance()
|
||||||
|
world.master_node.get_node("/root/main").add_child(quest_marker)
|
||||||
|
quest_marker.global_transform.origin = destination.global_transform.origin
|
||||||
|
print("destination: ", quest_marker.global_transform.origin)
|
||||||
|
|
||||||
|
|
||||||
|
func quest_complete():
|
||||||
|
.quest_complete()
|
||||||
|
quest_marker.queue_free()
|
||||||
45
proto2/ui/interaction.gd
Normal file
45
proto2/ui/interaction.gd
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
extends Control
|
||||||
|
|
||||||
|
var active_npc
|
||||||
|
|
||||||
|
func hire_as_team():
|
||||||
|
var npc_data: Dictionary = active_npc.get_meta("data")
|
||||||
|
var newkey = 0
|
||||||
|
var teamkeys = world.team.keys()
|
||||||
|
if teamkeys.size() > 0:
|
||||||
|
var maxkey = teamkeys.max()
|
||||||
|
newkey = maxkey + 1
|
||||||
|
if npc_data.gender == 0:
|
||||||
|
var dst_node = get_node("/root/main/quest_dst_male_dorm")
|
||||||
|
var dst = dst_node.global_transform.origin
|
||||||
|
active_npc.walkto(dst)
|
||||||
|
world.team[newkey] = npc_data
|
||||||
|
print("line: ", world.line.size())
|
||||||
|
world.line.erase(npc_data.id)
|
||||||
|
npc_data.erase("id")
|
||||||
|
print("line2: ", world.line.size())
|
||||||
|
npc_data.type = 0
|
||||||
|
else:
|
||||||
|
var dst_node = get_node("/root/main/quest_dst_female_dorm")
|
||||||
|
var dst = dst_node.global_transform.origin
|
||||||
|
active_npc.walkto(dst)
|
||||||
|
world.team[newkey] = npc_data
|
||||||
|
print("line: ", world.line.size())
|
||||||
|
world.line.erase(npc_data.id)
|
||||||
|
npc_data.erase("id")
|
||||||
|
print("line2: ", world.line.size())
|
||||||
|
npc_data.type = 0
|
||||||
|
hide()
|
||||||
|
func hire_as_cheer_team():
|
||||||
|
hide()
|
||||||
|
func _ready():
|
||||||
|
hide()
|
||||||
|
$h/hire_team.connect("pressed", self, "hire_as_team")
|
||||||
|
$h/hire_cheer_team.connect("pressed", self, "hire_as_cheer_team")
|
||||||
|
func start_interaction(npc):
|
||||||
|
active_npc = npc
|
||||||
|
show()
|
||||||
|
|
||||||
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
|
#func _process(delta):
|
||||||
|
# pass
|
||||||
41
proto2/ui/interaction.tscn
Normal file
41
proto2/ui/interaction.tscn
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
[gd_scene load_steps=2 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://ui/interaction.gd" type="Script" id=1]
|
||||||
|
|
||||||
|
[node name="interaction" type="Control"]
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
rect_min_size = Vector2( 0, 96 )
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="h" type="HBoxContainer" parent="."]
|
||||||
|
anchor_top = 1.0
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
margin_top = -64.0
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="hire_team" type="TextureButton" parent="h"]
|
||||||
|
margin_right = 64.0
|
||||||
|
margin_bottom = 64.0
|
||||||
|
rect_min_size = Vector2( 64, 64 )
|
||||||
|
|
||||||
|
[node name="Polygon2D" type="Polygon2D" parent="h/hire_team"]
|
||||||
|
polygon = PoolVector2Array( 11.513, 35.9185, 25.1051, 23.7134, 38.1424, 35.0864 )
|
||||||
|
|
||||||
|
[node name="hire_cheer_team" type="TextureButton" parent="h"]
|
||||||
|
margin_left = 68.0
|
||||||
|
margin_right = 132.0
|
||||||
|
margin_bottom = 64.0
|
||||||
|
rect_min_size = Vector2( 64, 64 )
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="Polygon2D2" type="Polygon2D" parent="h/hire_cheer_team"]
|
||||||
|
polygon = PoolVector2Array( 11.513, 35.9185, 25.1051, 23.7134, 38.1424, 35.0864 )
|
||||||
Reference in New Issue
Block a user