xiandie/manager/event_manager/event_manager.gd

79 lines
2.4 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@tool
extends Node
## 当任何事件的状态stage发生变化时发出此信号。
## 其他系统如UI、角色状态机等可以监听此信号来做出反应。
signal stage_updated(event_name: StringName, stage: int)
# 节点初始化时,异步加载并解析事件规则。
func _ready() -> void:
stage_updated.connect(_on_stage_updated_for_handnote)
# --- 公共 API ---
func get_chapter_stage() -> int:
return get_stage(&"current_chapter_stage")
func get_stage(event_name: StringName) -> int:
if not ArchiveManager.archive or ArchiveManager.archive.event_stage == null:
printerr("[EventManager] Archive or event_stage is null. Cannot get stage for '", event_name, "'.")
return 0
return ArchiveManager.archive.event_stage.get(event_name, 0)
# 核心的 stage 设置函数
# default 为 0首次更新为 1
func set_stage(event_name: StringName, stage := 1) -> void:
if not ArchiveManager.archive or ArchiveManager.archive.event_stage == null:
printerr("[EventManager] Archive or event_stage is null. Cannot set stage for '", event_name, "'.")
return
ArchiveManager.archive.event_stage[event_name] = stage
print("[EventManager] Stage updated: %s -> %s" % [event_name, stage])
stage_updated.emit(event_name, stage)
# 仅当设置的 stage > 当前 stage 时更新
func set_stage_if_greater(event_name: StringName, stage: int) -> bool:
if stage > get_stage(event_name):
set_stage(event_name, stage)
return true
return false
# stage 最大 99999
func next_stage(event_name: StringName, stage_max := 99999) -> int:
var current_stage = get_stage(event_name)
if current_stage < stage_max:
var new_stage = current_stage + 1
set_stage(event_name, new_stage)
return new_stage
return stage_max
# --- 游戏特定逻辑 ---
func _on_stage_updated_for_handnote(event_name: StringName, stage: int) -> void:
# 检查条件是否满足
if not (
SceneManager.is_node_ready()
and SceneManager.get_player()
and SceneManager.get_player().character.begins_with("吕萍")
):
return
if event_name.begins_with("handnote_"):
# 笔记条目更新
# 0 初始化隐藏1 开始显示2 划掉3 结束隐藏
if stage == 1:
SceneManager.lock_player(3.0, 16, true)
SceneManager.pop_notification("ui_notify_note_update")
##### 其他事件 #####
func prop_interacted(e_name, prop_key, interacted_times) -> void:
print("Event: %s interacted with %s. total times: %s" % [e_name, prop_key, interacted_times])