Quest system done

This commit is contained in:
2ndbeam 2024-06-08 13:21:45 +03:00
commit 231ff2bb1d
10 changed files with 52 additions and 9 deletions

View file

@ -29,6 +29,7 @@ func _process(_delta):
[node name="KamikazeShip" type="Node2D"]
script = ExtResource("1_82bba")
id = "SHIP_KAMIKAZE"
[node name="HullHolder" type="Node" parent="."]

View file

@ -31,6 +31,7 @@ func _process(_delta):
[node name="ShooterShip" type="Node2D"]
process_mode = 1
script = ExtResource("1_o387g")
id = "SHIP_SHOOTER"
[node name="HullHolder" type="Node" parent="."]

View file

@ -98,6 +98,7 @@ func _process(_delta):
[node name="PlayerShip" type="Node2D"]
process_mode = 1
script = ExtResource("2_oqdd7")
id = "SHIP_PLAYER"
[node name="InputController" type="Node2D" parent="."]
script = ExtResource("3_0e84a")

View file

@ -26,7 +26,7 @@ color_background = Color(0.276474, 0.0962249, 0.200656, 1)
[node name="PlayerShip" parent="FactionPlayer" index="0" instance=ExtResource("7_jyplv")]
process_mode = 0
position = Vector2(19, 10)
position = Vector2(732, 100)
[node name="Base" parent="FactionPeaceful" index="0" instance=ExtResource("3_m5ica")]
position = Vector2(719, -559)
@ -42,7 +42,13 @@ base_name = "BASE_NAME_1"
quest = ExtResource("10_gy1bh")
[node name="KamikazeShip" parent="FactionAggressive" index="0" instance=ExtResource("4_i6rbg")]
position = Vector2(-1712, -608)
position = Vector2(-161, 851)
[node name="ShooterShip" parent="FactionAggressive" index="1" instance=ExtResource("5_o3ny8")]
position = Vector2(-1852, 618)
[node name="KamikazeShip2" parent="FactionAggressive" index="2" instance=ExtResource("4_i6rbg")]
position = Vector2(-190, 621)
[node name="KamikazeShip3" parent="FactionAggressive" index="3" instance=ExtResource("4_i6rbg")]
position = Vector2(-47, 1056)

View file

@ -16,6 +16,8 @@ const ACCEPT_QUEST = "BASE_QUEST_ACCEPT"
const CANCEL_QUEST = "BASE_QUEST_CANCEL"
## This message will trigger quest node to get quest info
const QUEST_INFO = "BASE_QUEST_INFO"
## This message will trigger dialogue node to reward player
const QUEST_REWARD = "BASE_QUEST_REWARD"
## Quest progress template
const QUEST_PROGRESS = "{cur} / {max}"
@ -26,8 +28,7 @@ const QUEST_PROGRESS = "{cur} / {max}"
@onready var quest = $"../../Quest"
func _ready():
var tween = create_tween() \
.tween_property(dialogue,"visible_ratio",1.0, 2)
create_tween().tween_property(dialogue,"visible_ratio",1.0, 2)
func send_message(msg: Message):
var format = {}
@ -69,10 +70,14 @@ func send_message(msg: Message):
format["answer"] = quest.info
format["given_by"] = tr(cur_quest.data["given_by"])
format["progress"] = QUEST_PROGRESS.format({"cur": cur_quest.progress, "max": cur_quest.progress_max})
QUEST_REWARD:
var player_ship = actions_menu.player_ship
var reward = player_ship.quest.reward_money
player_ship.money += reward
player_ship.quest = null
format["reward"] = reward
var new_msg = tr(msg.fact + "_RECEIVED").format(format)
var old_len = len(dialogue.get_parsed_text())
dialogue.append_text(new_msg)
dialogue.visible_characters = old_len
var tween = create_tween() \
.tween_property(dialogue,"visible_ratio",1.0, 2)
create_tween().tween_property(dialogue,"visible_ratio",1.0, 2)

View file

@ -66,5 +66,6 @@ func assign_to_player() -> Quest:
quest.status = Quest.Status.Taken
var temp_quest = quest
quest = null
base.quest = null
make_answer(quest)
return temp_quest

View file

@ -2,3 +2,13 @@ extends Control
## Base which provided this menu
var base: Base
func _ready():
get_tree().create_timer(0.05).timeout.connect(check_for_delivery)
func check_for_delivery():
var player_ship = get_tree().current_scene.player_ship
if player_ship.quest == null:
return
if player_ship.quest.type == Quest.Type.Delivery and player_ship.quest.data["base_name"] == base.base_name:
player_ship.quest.do_progress()

View file

@ -40,8 +40,12 @@ enum Status{
@export var progress_max : int = 1
var progress : int = 0:
set(value):
if status == Status.Taken:
if value >= progress_max:
progress = progress_max
end()
else:
progress = value
@export var reward_money : float
@export var restrictions : Array[Restriction] = []
@export var data : Dictionary = {}

View file

@ -5,6 +5,9 @@ class_name Ship
## Emits when hull hp reaches zero.
signal destroyed
## Ship ID to define its type
@export var id: String
## Reference to the engine module
@onready var engine: ShipEngine = $Engine
## Reference to the hull module
@ -24,6 +27,7 @@ var faction : Game.Faction
func _ready() -> void:
hull.global_position = global_position
destroyed.connect(destroy_timeout)
destroyed.connect(star_system.on_ship_destroyed.bind(self))
hull.mouse_entered.connect(star_system.set_targeted_node.bind(self))
hull.mouse_exited.connect(star_system.clear_targeted_node)

View file

@ -71,3 +71,13 @@ func find_base_by_name(base_name: String) -> Base:
return base
return null
## Progress by elimination quest if destroyed ship is of required type
func on_ship_destroyed(ship: Ship):
if player_ship == null:
return
if player_ship.quest == null:
return
if player_ship.quest.type != Quest.Type.Elimination:
return
if player_ship.quest.data["target_class"] == ship.id:
player_ship.quest.do_progress()