Some fixes
Disabled feet IK, proper handling of exit room Added quest system from proto2
This commit is contained in:
92
proto3/godot/system/quest.gd
Normal file
92
proto3/godot/system/quest.gd
Normal file
@@ -0,0 +1,92 @@
|
||||
extends Reference
|
||||
class_name Quest
|
||||
signal complete
|
||||
signal failed
|
||||
signal started
|
||||
var _objectives = []
|
||||
var _children = []
|
||||
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
|
||||
func add_child(quest: Quest):
|
||||
_children.push_back(quest)
|
||||
func is_complete():
|
||||
return _complete
|
||||
func is_active():
|
||||
return _active
|
||||
func update():
|
||||
if !_active:
|
||||
return
|
||||
# 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:
|
||||
k.update()
|
||||
_complete = true
|
||||
for k in _objectives:
|
||||
if !k.is_complete():
|
||||
_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:
|
||||
for p in _children:
|
||||
if p.is_active():
|
||||
ret = p.get_cur_task_text()
|
||||
return ret
|
||||
for p in _objectives:
|
||||
if !p.is_complete():
|
||||
return get_title() + ": " + p.get_title()
|
||||
return _title
|
||||
return ret
|
||||
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
|
||||
14
proto3/godot/system/quest_objective.gd
Normal file
14
proto3/godot/system/quest_objective.gd
Normal file
@@ -0,0 +1,14 @@
|
||||
extends Reference
|
||||
class_name QuestObjective
|
||||
|
||||
var _complete: bool = false
|
||||
var _title: String
|
||||
|
||||
func _init(title: String):
|
||||
_title = title
|
||||
func is_complete():
|
||||
return _complete
|
||||
func update():
|
||||
pass
|
||||
func get_title():
|
||||
return _title
|
||||
29
proto3/godot/system/stats_quest.gd
Normal file
29
proto3/godot/system/stats_quest.gd
Normal file
@@ -0,0 +1,29 @@
|
||||
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
|
||||
"team_train_count":
|
||||
if world.team_train_count < 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))
|
||||
61
proto3/godot/system/walk_quest.gd
Normal file
61
proto3/godot/system/walk_quest.gd
Normal file
@@ -0,0 +1,61 @@
|
||||
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
|
||||
var arrow: Spatial
|
||||
var nav: Navigation
|
||||
func _init(title, destination: Spatial).(title):
|
||||
dest = destination
|
||||
arrow = world.arrow
|
||||
nav = world.arrow.get_node("/root/main/nav")
|
||||
func update():
|
||||
var org = world.master_node.global_transform.origin
|
||||
var orgc = nav.get_closest_point(org)
|
||||
var dst = dest.global_transform.origin
|
||||
var dstc = nav.get_closest_point(dst)
|
||||
var path = nav.get_simple_path(orgc, dstc)
|
||||
var arrow_dir : = Vector3()
|
||||
if path.size() > 1:
|
||||
for e in path:
|
||||
if (e - org).length() > 1.0:
|
||||
arrow_dir = e - org
|
||||
break
|
||||
if arrow_dir.length() == 0 && arrow.visible:
|
||||
arrow.hide()
|
||||
elif arrow_dir.length() > 0:
|
||||
if !arrow.visible:
|
||||
arrow.show()
|
||||
arrow_dir.y = 0
|
||||
arrow.look_at(arrow.global_transform.origin + arrow_dir, Vector3.UP)
|
||||
|
||||
if org.distance_to(dest.global_transform.origin) < 2.5:
|
||||
_complete = true
|
||||
arrow.hide()
|
||||
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)
|
||||
if world.arrow:
|
||||
world.arrow.show()
|
||||
|
||||
|
||||
func quest_complete():
|
||||
.quest_complete()
|
||||
quest_marker.queue_free()
|
||||
if world.arrow:
|
||||
world.arrow.hide()
|
||||
Reference in New Issue
Block a user