123 lines
2.9 KiB
GDScript
123 lines
2.9 KiB
GDScript
@tool
|
|
extends Node2D
|
|
|
|
signal player_entered
|
|
|
|
@export var one_shot := true
|
|
@export var freeze_time := 5.0
|
|
@export var hook_animation = ""
|
|
@export var lock_player_on_playing_dialogue = true
|
|
@export_enum("c01", "c02") var hook_dialogue_res = "c01":
|
|
set(val):
|
|
hook_dialogue_res = val
|
|
match val:
|
|
"c01":
|
|
dialogue_res = dialogue_c01
|
|
"c02":
|
|
dialogue_res = dialogue_c02
|
|
if is_node_ready():
|
|
notify_property_list_changed()
|
|
var hook_dialogue_title = ""
|
|
|
|
var dialogue_c01 = preload("res://asset/dialogue/c01.dialogue")
|
|
var dialogue_c02 = preload("res://asset/dialogue/c02.dialogue")
|
|
var dialogue_res = dialogue_c01
|
|
|
|
var played_time := 0.0
|
|
var played := false:
|
|
set(val):
|
|
played = val
|
|
_save_archive()
|
|
|
|
@onready var area2d = %Area2D as Area2D
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
if Engine.is_editor_hint():
|
|
return
|
|
_load_archive()
|
|
if one_shot and played:
|
|
if GlobalConfig.DEBUG:
|
|
print("Ambush already played, key=", _get_key())
|
|
return
|
|
area2d.body_entered.connect(_entered)
|
|
|
|
|
|
func _get_key() -> String:
|
|
var ground_loader = get_node_or_null("../../..") as GroundLoader
|
|
if ground_loader:
|
|
return ground_loader.current_scene + "_" + name
|
|
return name
|
|
|
|
|
|
func _save_archive():
|
|
if Engine.is_editor_hint():
|
|
return
|
|
ArchiveManager.archive.ambush_data[_get_key()] = {"played": played}
|
|
|
|
|
|
func _load_archive():
|
|
if Engine.is_editor_hint():
|
|
return
|
|
var key = _get_key()
|
|
if ArchiveManager.archive.ambush_data.has(key):
|
|
var data = ArchiveManager.archive.ambush_data[key]
|
|
if data.has("played"):
|
|
played = data.played
|
|
|
|
|
|
func _entered(_body):
|
|
if not one_shot:
|
|
var time = Time.get_ticks_msec()
|
|
var time_left = freeze_time - (time - played_time) * 0.001
|
|
if time_left > 0:
|
|
if GlobalConfig.DEBUG:
|
|
print("Ambush freeze time not reached, time left=", time_left)
|
|
return
|
|
played_time = time
|
|
# hook_animation
|
|
if hook_animation:
|
|
$AnimationPlayer.play(hook_animation)
|
|
# hook_dialogue
|
|
if hook_dialogue_title:
|
|
if lock_player_on_playing_dialogue:
|
|
SceneManager.freeze_player(0.0, "")
|
|
DialogueManager.show_dialogue_balloon(dialogue_res, hook_dialogue_title)
|
|
DialogueManager.dialogue_ended.connect(_on_dialogue_ended, CONNECT_ONE_SHOT)
|
|
if one_shot:
|
|
played = true
|
|
player_entered.emit()
|
|
print("ambush body_entered!")
|
|
|
|
|
|
func _on_dialogue_ended(_res):
|
|
if GlobalConfig.DEBUG:
|
|
print("Ambush dialogue ended")
|
|
if lock_player_on_playing_dialogue:
|
|
SceneManager.release_player()
|
|
|
|
|
|
func _get(property: StringName) -> Variant:
|
|
if property == "hook_dialogue_title":
|
|
return hook_dialogue_title
|
|
return null
|
|
|
|
|
|
func _set(property: StringName, value: Variant) -> bool:
|
|
if property == "hook_dialogue_title":
|
|
hook_dialogue_title = value
|
|
return true
|
|
return false
|
|
|
|
|
|
func _get_property_list() -> Array[Dictionary]:
|
|
return [
|
|
{
|
|
"name": "hook_dialogue_title",
|
|
"type": TYPE_STRING,
|
|
"hint": PROPERTY_HINT_ENUM_SUGGESTION,
|
|
"hint_string": ",".join(dialogue_res.get_ordered_titles())
|
|
}
|
|
]
|