Started quest system implementation
This commit is contained in:
@@ -13,6 +13,7 @@ var room_events = {}
|
||||
var line = {}
|
||||
var training = false
|
||||
var nav: Navigation
|
||||
var quests : = []
|
||||
|
||||
func room_event(ev: String):
|
||||
if current_room:
|
||||
@@ -28,6 +29,23 @@ func register_room_event(roomobj, evname, fname):
|
||||
func _ready():
|
||||
connect("room_event", self, "room_event")
|
||||
|
||||
var master_stats:Dictionary = {
|
||||
"type": 0,
|
||||
"gender": 0,
|
||||
"name": "John",
|
||||
"lastname": "Smith",
|
||||
"speed": 0.5,
|
||||
"strength": 0.5,
|
||||
"agression": 0.5,
|
||||
"charisma": 0.5,
|
||||
"obedience": 0.0,
|
||||
"cost": 0,
|
||||
"xp": 0,
|
||||
"mext_xp": 100,
|
||||
"points": 5,
|
||||
"level": 1
|
||||
}
|
||||
|
||||
func new_candidate() -> Dictionary:
|
||||
var gender = randi() % 2
|
||||
var type = 0
|
||||
@@ -42,6 +60,7 @@ func new_candidate() -> Dictionary:
|
||||
else:
|
||||
ret.name = "Jane"
|
||||
ret.lastname = "Doe"
|
||||
ret.gender = gender
|
||||
ret.type = type
|
||||
ret.speed = 0.3 + randf() * 0.7
|
||||
ret.strength = 0.1 + randf() * 0.9
|
||||
@@ -109,6 +128,7 @@ func init_data():
|
||||
cheer_team = {}
|
||||
print(line)
|
||||
|
||||
|
||||
func dialogue(npc):
|
||||
pass
|
||||
var day_period = 0
|
||||
|
||||
@@ -10,9 +10,21 @@ var frame_tf: Transform = Transform()
|
||||
func master_control(pos):
|
||||
$master.walkto(pos)
|
||||
|
||||
func update_quests():
|
||||
for q in world.quests:
|
||||
if q.is_active():
|
||||
$info/task/task.text = q.get_cur_task_text()
|
||||
break
|
||||
for q in world.quests:
|
||||
if q.is_active():
|
||||
q.update()
|
||||
func start_quest(quest: Quest):
|
||||
$start_quest_notification.start_notification(quest.get_title(), quest.get_description())
|
||||
|
||||
func _ready():
|
||||
$master.add_to_group("master")
|
||||
controls.master_node = $master
|
||||
world.master_node = $master
|
||||
world.init_data()
|
||||
world.nav = $nav
|
||||
controls.camera = $Camera
|
||||
@@ -26,6 +38,7 @@ func _ready():
|
||||
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))
|
||||
char_sc.translation = p
|
||||
char_sc.set_meta("data", cd)
|
||||
# world.team[newkey] = cd
|
||||
# world.line.erase(k)
|
||||
else:
|
||||
@@ -35,8 +48,20 @@ func _ready():
|
||||
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))
|
||||
char_sc.translation = p
|
||||
char_sc.set_meta("data", cd)
|
||||
# world.team[newkey] = cd
|
||||
# cd.scene.set_meta("data", cd)
|
||||
var tut_quest = Quest.new("Tutorial", "This quest shortly introduces to a game")
|
||||
tut_quest.connect("started", self, "start_quest")
|
||||
world.quests.push_back(tut_quest)
|
||||
tut_quest.start()
|
||||
update_quests()
|
||||
var quest_timer : = Timer.new()
|
||||
quest_timer.wait_time = 2.0
|
||||
add_child(quest_timer)
|
||||
quest_timer.connect("timeout", self, "update_quests")
|
||||
quest_timer.start()
|
||||
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -13,9 +13,21 @@ _global_script_classes=[ {
|
||||
"class": "BallGameAI",
|
||||
"language": "GDScript",
|
||||
"path": "res://ai/ball_game_ai.gd"
|
||||
}, {
|
||||
"base": "Reference",
|
||||
"class": "Quest",
|
||||
"language": "GDScript",
|
||||
"path": "res://system/quest.gd"
|
||||
}, {
|
||||
"base": "Reference",
|
||||
"class": "QuestObjective",
|
||||
"language": "GDScript",
|
||||
"path": "res://system/quest_objective.gd"
|
||||
} ]
|
||||
_global_script_class_icons={
|
||||
"BallGameAI": ""
|
||||
"BallGameAI": "",
|
||||
"Quest": "",
|
||||
"QuestObjective": ""
|
||||
}
|
||||
|
||||
[application]
|
||||
|
||||
66
proto2/system/quest.gd
Normal file
66
proto2/system/quest.gd
Normal file
@@ -0,0 +1,66 @@
|
||||
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
|
||||
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:
|
||||
return
|
||||
for k in _children:
|
||||
if !k.is_complete():
|
||||
_complete = false
|
||||
break
|
||||
if _complete:
|
||||
emit_signal("complete", self)
|
||||
_active = false
|
||||
func start():
|
||||
_active = true
|
||||
for k in _children:
|
||||
k.start()
|
||||
emit_signal("started", self)
|
||||
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 p.get_title()
|
||||
return _title
|
||||
return ret
|
||||
func get_title():
|
||||
return _title
|
||||
func get_description():
|
||||
return _description
|
||||
14
proto2/system/quest_objective.gd
Normal file
14
proto2/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
|
||||
35
proto2/ui/start_quest_notification.gd
Normal file
35
proto2/ui/start_quest_notification.gd
Normal file
@@ -0,0 +1,35 @@
|
||||
extends Control
|
||||
|
||||
# Declare member variables here. Examples:
|
||||
# var a = 2
|
||||
# var b = "text"
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
var expose_time:float = 0.0
|
||||
var cooldown_time: float = 0.0
|
||||
var queue = []
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
if queue.size() > 0:
|
||||
if cooldown_time <= 0.0:
|
||||
var item = queue[0]
|
||||
queue.pop_front()
|
||||
if visible:
|
||||
hide()
|
||||
$v/quest_title.text = item.title
|
||||
$v/quest_desc.text = item.desc
|
||||
expose_time = 0.0
|
||||
cooldown_time = 2.0
|
||||
show()
|
||||
if expose_time > 10.0:
|
||||
if visible:
|
||||
hide()
|
||||
cooldown_time -= delta
|
||||
else:
|
||||
expose_time += delta
|
||||
func start_notification(title, desc):
|
||||
queue.push_back({"title": title, "desc": desc})
|
||||
print("start notification", title)
|
||||
58
proto2/ui/start_quest_notification.tscn
Normal file
58
proto2/ui/start_quest_notification.tscn
Normal file
@@ -0,0 +1,58 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://ui/start_quest_notification.gd" type="Script" id=1]
|
||||
|
||||
[node name="start_quest_notification" type="Control"]
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
margin_left = -90.0
|
||||
margin_top = -40.0
|
||||
margin_right = 90.0
|
||||
margin_bottom = 40.0
|
||||
rect_min_size = Vector2( 180, 80 )
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="v" type="VBoxContainer" parent="."]
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
margin_left = -93.0
|
||||
margin_top = -34.0
|
||||
margin_right = 93.0
|
||||
margin_bottom = 34.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="msg" type="Label" parent="v"]
|
||||
margin_right = 186.0
|
||||
margin_bottom = 14.0
|
||||
text = "Starting quest:"
|
||||
align = 1
|
||||
|
||||
[node name="quest_title" type="Label" parent="v"]
|
||||
margin_top = 18.0
|
||||
margin_right = 186.0
|
||||
margin_bottom = 32.0
|
||||
text = "quest title"
|
||||
align = 1
|
||||
|
||||
[node name="quest_desc" type="Label" parent="v"]
|
||||
margin_top = 36.0
|
||||
margin_right = 186.0
|
||||
margin_bottom = 50.0
|
||||
text = "quest description"
|
||||
align = 3
|
||||
|
||||
[node name="msg2" type="Label" parent="v"]
|
||||
margin_top = 54.0
|
||||
margin_right = 186.0
|
||||
margin_bottom = 68.0
|
||||
text = "Quest added to your journal"
|
||||
align = 1
|
||||
Reference in New Issue
Block a user