promiscuity/game/scenes/Levels/trigger_zones_level.gd
Zeeshaun fecbefc15c
Some checks failed
Deploy Promiscuity Auth API / deploy (push) Successful in 1m59s
Deploy Promiscuity Character API / deploy (push) Successful in 1m16s
Deploy Promiscuity Inventory API / deploy (push) Has been cancelled
Deploy Promiscuity Locations API / deploy (push) Has been cancelled
Deploy Promiscuity Mail API / deploy (push) Has been cancelled
Deploy Promiscuity World API / deploy (push) Has been cancelled
Deploy Promiscuity Crafting API / deploy (push) Has been cancelled
k8s smoke test / test (push) Has been cancelled
Recommiting glbs for LFS
2026-05-12 15:34:12 -05:00

122 lines
4.1 KiB
GDScript

extends Node3D
@export var player_spawn_position := Vector3(0.0, 0.0, 0.0)
@export var day_length := 120.0
@export var start_light_angle := -90.0
@onready var _player: RigidBody3D = get_node_or_null("Player") as RigidBody3D
@onready var _sun: DirectionalLight3D = $DirectionalLight3D
@onready var _quest_text: RichTextLabel = get_node_or_null("PhoneUI/Control/PhoneFrame/QuestText") as RichTextLabel
const FIRST_QUEST_ID := "first_drive"
const QUEST_PROMPT_META_PREFIX := "quest_intro_prompt_shown_"
const FIRST_QUEST := {
"id": FIRST_QUEST_ID,
"title": "RepoBot's First Task",
"description": "Get familiar with movement and vehicles.",
"steps": [
{
"id": "enter_car_feature",
"text": "Walk through the car teleporter.",
"complete_event": "entered_car_feature",
},
{
"id": "reach_checkpoint",
"text": "Drive the car into the checkpoint marker.",
"complete_event": "reach_checkpoint",
},
],
}
var _time := 0.0
func _ready() -> void:
_move_player_to_spawn()
_setup_quests()
_show_quest_intro_dialog()
func _process(delta: float) -> void:
_update_day_night(delta)
func _move_player_to_spawn() -> void:
if _player == null:
return
var spawn_marker := _consume_spawn_marker()
if spawn_marker != null:
_player.call("teleport_to_spawn", spawn_marker.global_transform)
else:
_player.global_position = player_spawn_position
_player.linear_velocity = Vector3.ZERO
_player.angular_velocity = Vector3.ZERO
func _consume_spawn_marker() -> Node3D:
if TeleportState == null:
return null
var spawn_name: StringName = TeleportState.consume_spawn_name()
if spawn_name == StringName():
return null
return find_child(String(spawn_name), true, false) as Node3D
func _update_day_night(delta: float) -> void:
if _sun == null or day_length <= 0.0:
return
_time = fmod(_time + delta, day_length)
var t: float = _time / day_length
var angle: float = lerp(start_light_angle, start_light_angle + 360.0, t)
_sun.rotation_degrees.x = angle
var energy_curve: float = -sin((t * TAU) + (start_light_angle * PI / 180.0))
_sun.light_energy = clamp((energy_curve * 1.0) + 0.2, 0.0, 1.2)
func _setup_quests() -> void:
if QuestManager == null:
return
if not QuestManager.has_quest(FIRST_QUEST_ID):
QuestManager.register_quest(FIRST_QUEST)
if not QuestManager.is_active_quest(FIRST_QUEST_ID) and not QuestManager.is_quest_completed(FIRST_QUEST_ID):
QuestManager.start_quest(FIRST_QUEST_ID)
if not QuestManager.is_connected("quest_state_changed", Callable(self, "_refresh_quest_ui")):
QuestManager.quest_state_changed.connect(_refresh_quest_ui)
_refresh_quest_ui()
func _refresh_quest_ui() -> void:
if _quest_text == null or QuestManager == null:
return
var state: Dictionary = QuestManager.get_active_quest_state()
if not bool(state.get("active", false)):
_quest_text.text = "No active quest."
return
var title := String(state.get("title", "Quest"))
if bool(state.get("completed", false)):
_quest_text.text = "[b]%s[/b]\nComplete." % title
return
var step_index: int = int(state.get("current_step_index", 0))
var total_steps: int = int(state.get("total_steps", 0))
var step_text := String(state.get("current_step_text", ""))
_quest_text.text = "[b]%s[/b]\nStep %d/%d\n%s" % [title, step_index + 1, total_steps, step_text]
func _show_quest_intro_dialog() -> void:
if QuestManager == null:
return
var state: Dictionary = QuestManager.get_active_quest_state()
if not bool(state.get("active", false)) or bool(state.get("completed", false)):
return
var quest_id := String(state.get("quest_id", "")).strip_edges()
var step_id := String(state.get("current_step_id", "")).strip_edges()
var step_text := String(state.get("current_step_text", ""))
if quest_id.is_empty() or step_id.is_empty() or step_text.is_empty():
return
var prompt_key := "%s%s_%s" % [QUEST_PROMPT_META_PREFIX, quest_id, step_id]
if QuestManager.has_meta(prompt_key) and bool(QuestManager.get_meta(prompt_key)):
return
if DialogSystem and DialogSystem.has_method("show_text"):
DialogSystem.show_text("RepoBot: New task assigned.\n\n%s" % step_text)
QuestManager.set_meta(prompt_key, true)