Improved quest system
This commit is contained in:
@@ -9,6 +9,7 @@ var _title: String
|
||||
var _description: String
|
||||
var _active: bool = false
|
||||
var _complete: bool = false
|
||||
var _next_quest: Quest
|
||||
func _init(title: String, description: String):
|
||||
_title = title
|
||||
_description = description
|
||||
@@ -21,10 +22,10 @@ func is_active():
|
||||
func update():
|
||||
if !_active:
|
||||
return
|
||||
var m = get_meta("quest")
|
||||
if m != null:
|
||||
for k in _objectives:
|
||||
k.set_meta("quest", m)
|
||||
# var m = get_meta("quest")
|
||||
# if m != null:
|
||||
# for k in _objectives:
|
||||
# k.set_meta("quest", m)
|
||||
for k in _objectives:
|
||||
k.update()
|
||||
for k in _children:
|
||||
@@ -35,19 +36,32 @@ func update():
|
||||
_complete = false
|
||||
break
|
||||
if !_complete:
|
||||
print("quest: ", _title, " objectives incomplete")
|
||||
return
|
||||
for k in _children:
|
||||
if !k.is_complete():
|
||||
_complete = false
|
||||
break
|
||||
if !_complete:
|
||||
print("quest: ", _title, " children incomplete")
|
||||
if _complete:
|
||||
emit_signal("complete", self)
|
||||
_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():
|
||||
_active = true
|
||||
for k in _children:
|
||||
k.connect("complete", self, "quest_complete_handler")
|
||||
k.start()
|
||||
emit_signal("started", self)
|
||||
print("children: ", _children)
|
||||
print("quest: ", _title, " started")
|
||||
func get_cur_task_text():
|
||||
var ret: String = "No current task"
|
||||
if _active:
|
||||
@@ -64,3 +78,15 @@ func get_title():
|
||||
return _title
|
||||
func get_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()
|
||||
Reference in New Issue
Block a user