216 lines
6.4 KiB
GDScript
216 lines
6.4 KiB
GDScript
@tool
|
|
extends AnimationRoot
|
|
|
|
|
|
# 覆盖该方法
|
|
func _default_data() -> Dictionary:
|
|
return {}
|
|
|
|
|
|
var shelf_game_scene = preload("res://scene/little_game/书架/书架.tscn")
|
|
var shelf_game_node = shelf_game_scene.instantiate()
|
|
var envelope_game_scene = preload("res://scene/little_game/拼凑信件.tscn")
|
|
var envelope_game_node = envelope_game_scene.instantiate()
|
|
|
|
|
|
func _ready() -> void:
|
|
super._ready()
|
|
if Engine.is_editor_hint():
|
|
return
|
|
shelf_game_node.exiting.connect(_on_shelf_game_exiting)
|
|
shelf_game_node.success.connect(_on_shelf_game_success)
|
|
envelope_game_node.exiting.connect(_on_envelope_game_exiting)
|
|
envelope_game_node.success.connect(_on_envelope_game_success)
|
|
|
|
|
|
var counter: Interactable2D
|
|
var envolope_table: Interactable2D
|
|
var ladder: Ambush2D
|
|
var coin: Ambush2D
|
|
var mask: ColorRect
|
|
var left_protal: Portal2D
|
|
var shelf_game_success = false
|
|
var envelope_game_success = false
|
|
var manager
|
|
var mice
|
|
var fall_off
|
|
|
|
|
|
func _on_ground_ready() -> void:
|
|
ladder = $"../DeployLayer/Ambush梯子"
|
|
envolope_table = $"../DeployLayer/Interactable信件书桌"
|
|
mask = $"../DeployLayer/Mask"
|
|
left_protal = $"../DeployLayer/portal_left" as Portal2D
|
|
counter = $"../DeployLayer/Interactable报纸柜台"
|
|
coin = $"../DeployLayer/Ambush银元"
|
|
mice = $"../DeployLayer/自动跟随的老鼠"
|
|
manager = $"../DeployLayer/老板"
|
|
fall_off = $"../DeployLayer/小小蝶坠落"
|
|
# 首先放报纸,触发动画,领取任务
|
|
if counter.interacted_times > 0:
|
|
ladder.enabled = true
|
|
envolope_table.enabled = true
|
|
else:
|
|
counter.interacted.connect(assign_tasks, CONNECT_ONE_SHOT)
|
|
ladder.enabled = false
|
|
envolope_table.enabled = false
|
|
envelope_game_success = ArchiveManager.get_global_value(&"envelope_game_success")
|
|
if envelope_game_success:
|
|
envolope_table.enabled = false
|
|
else:
|
|
if envolope_table.interacted_times >= 2:
|
|
# 两封信都放后,无需接受
|
|
envolope_table.prop_key = ""
|
|
envolope_table.prop_key2 = ""
|
|
envolope_table.interacted.connect(_on_envolope_table_interacted)
|
|
# 书架工作
|
|
shelf_game_success = ArchiveManager.get_global_value(&"c01_shelf_game_success")
|
|
if shelf_game_success:
|
|
_setup_weird_bookstore()
|
|
else:
|
|
mice.visible = false
|
|
_check_portal()
|
|
|
|
|
|
func _check_portal():
|
|
if not shelf_game_success or not envelope_game_success:
|
|
left_protal.holding = true
|
|
left_protal.holding_reason_key = "c01_s08_书店工作"
|
|
elif not coin.played:
|
|
left_protal.holding = true
|
|
left_protal.holding_reason_key = "c01_s08_书店工钱"
|
|
else:
|
|
left_protal.holding = false
|
|
|
|
|
|
func _on_envolope_table_interacted() -> void:
|
|
if envolope_table.interacted_times >= 2:
|
|
# 两封信都放后,无需接受
|
|
envolope_table.prop_key = ""
|
|
envolope_table.prop_key2 = ""
|
|
play_envelope_game()
|
|
|
|
|
|
func first_enter_door() -> void:
|
|
SceneManager.lock_player()
|
|
await Util.wait(1.5)
|
|
DialogueManager.show_dialogue_balloon(dialogue_c01, "c01_s08_书店进门老板台词")
|
|
await DialogueManager.dialogue_ended
|
|
SceneManager.unlock_player()
|
|
|
|
|
|
func assign_tasks() -> void:
|
|
# 放报纸动作
|
|
SceneManager.lock_player(0, 8, true)
|
|
await Util.wait(4.5)
|
|
$"放报纸音效".play()
|
|
DialogueManager.show_dialogue_balloon(dialogue_c01, "c01_s08_书店老板任务")
|
|
await DialogueManager.dialogue_ended
|
|
SceneManager.unlock_player()
|
|
ladder.enabled = true
|
|
envolope_table.enabled = true
|
|
|
|
|
|
func _exit_tree() -> void:
|
|
if is_instance_valid(shelf_game_node):
|
|
shelf_game_node.queue_free()
|
|
|
|
|
|
func play_shelf_game() -> void:
|
|
if shelf_game_node.get_parent() != get_parent():
|
|
get_parent().add_child(shelf_game_node)
|
|
SceneManager.freeze_player(0)
|
|
|
|
|
|
func _on_shelf_game_exiting() -> void:
|
|
if GlobalConfig.DEBUG:
|
|
print("书架游戏 exiting")
|
|
create_tween().tween_property(mask, "color:a", 0.0, 1.0).from(1.0)
|
|
SceneManager.release_player()
|
|
|
|
|
|
func _on_shelf_game_success() -> void:
|
|
ArchiveManager.set_global_entry(&"c01_shelf_game_success", true)
|
|
shelf_game_success = true
|
|
_setup_weird_bookstore()
|
|
var player = SceneManager.get_player() as MainPlayer
|
|
player.hide_sprite = true
|
|
# 设置朝左,与书架的动画结尾一致
|
|
player.set_facing_direction(Vector2(-1, 0))
|
|
# 对齐位置
|
|
player.update_x_with_camera_followed(437.0)
|
|
# 相机抖动
|
|
SceneManager.get_camera_marker().shake_camera()
|
|
# 播放小蝶从书架跌倒的动画
|
|
fall_off.visible = true
|
|
fall_off.play()
|
|
fall_off.animation_finished.connect(_on_fall_off_finished)
|
|
# 从 sfx_生死簿演出 中退出时播放不出来,需要在此处播放 (global_play)
|
|
# Util.timer(0.5, $"摔倒音效".play)
|
|
_check_portal()
|
|
|
|
|
|
func _on_fall_off_finished() -> void:
|
|
fall_off.visible = false
|
|
SceneManager.get_player().hide_sprite = false
|
|
await Util.wait(0.3)
|
|
await SceneManager.pop_os_with_str("c01_s08_书架游戏完成")
|
|
# 耳鸣与眩晕
|
|
$"Sfx头痛耳鸣".play()
|
|
$"../DizzyShader".dizzy()
|
|
await Util.wait(2.5)
|
|
await SceneManager.pop_os_with_str("c01_s08_书架游戏恢复记忆")
|
|
# 最后释放玩家
|
|
SceneManager.release_player()
|
|
|
|
|
|
func _setup_weird_bookstore() -> void:
|
|
# 切换背景音效
|
|
$"环境音".stop()
|
|
$"诡异环境音".play()
|
|
# 光变红
|
|
$"../AmbientLayer/PointLight2D".color = Color.html("#ff2719")
|
|
|
|
coin.enabled = true
|
|
ladder.enabled = false
|
|
manager.visible = false
|
|
mice.visible = true
|
|
$"../DirectionalLight2D".energy = 0.7
|
|
$"../BGSprite2D".texture = preload("res://asset/art/scene/c01/s08_书店/夜晚版/bg_书店夜晚.png")
|
|
$"../ParallaxForeground/FGParallaxLayer/FGSprite2D".texture = preload(
|
|
"res://asset/art/scene/c01/s08_书店/夜晚版/fg_书店夜晚前景.png"
|
|
)
|
|
ladder.texture = preload("res://asset/art/scene/c01/s08_书店/夜晚版/e_梯子 夜晚.png")
|
|
|
|
|
|
func play_envelope_game() -> void:
|
|
if envelope_game_node.get_parent() != get_parent():
|
|
get_parent().add_child(envelope_game_node)
|
|
SceneManager.freeze_player(0)
|
|
|
|
|
|
func _on_envelope_game_exiting() -> void:
|
|
if GlobalConfig.DEBUG:
|
|
print("信封游戏 exiting")
|
|
create_tween().tween_property(mask, "color:a", 0.0, 1.0).from(1.0)
|
|
SceneManager.release_player()
|
|
|
|
|
|
func _on_envelope_game_success() -> void:
|
|
SceneManager.release_player()
|
|
envolope_table.enabled = false
|
|
create_tween().tween_property(mask, "color:a", 0.0, 1.0).from(1.0)
|
|
ArchiveManager.set_global_entry(&"envelope_game_success", true)
|
|
envelope_game_success = true
|
|
_check_portal()
|
|
|
|
|
|
func pay_off_wage() -> void:
|
|
SceneManager.enable_prop_item("prop_银元")
|
|
SceneManager.get_inspector().quit_and_hidden.connect(_on_quit_inspect_coin, CONNECT_ONE_SHOT)
|
|
_check_portal()
|
|
|
|
|
|
func _on_quit_inspect_coin() -> void:
|
|
SceneManager.pop_os_with_str("c01_s08_获得袁大头后")
|