2025-07-14 04:43:33 +00:00
|
|
|
|
@tool
|
2024-12-23 01:29:31 +00:00
|
|
|
|
extends Node
|
|
|
|
|
|
2025-07-15 06:54:13 +00:00
|
|
|
|
## 当任何事件的状态(stage)发生变化时发出此信号。
|
|
|
|
|
## 其他系统(如UI、角色状态机等)可以监听此信号来做出反应。
|
2025-06-27 14:52:46 +00:00
|
|
|
|
signal stage_updated(event_name: StringName, stage: int)
|
|
|
|
|
|
|
|
|
|
|
2025-07-15 06:54:13 +00:00
|
|
|
|
# 节点初始化时,异步加载并解析事件规则。
|
|
|
|
|
func _ready() -> void:
|
|
|
|
|
stage_updated.connect(_on_stage_updated_for_handnote)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# --- 公共 API ---
|
|
|
|
|
|
2025-07-14 04:43:33 +00:00
|
|
|
|
func get_chapter_stage() -> int:
|
2025-07-15 06:54:13 +00:00
|
|
|
|
return get_stage(&"current_chapter_stage")
|
2025-07-14 04:43:33 +00:00
|
|
|
|
|
|
|
|
|
|
2025-06-27 14:52:46 +00:00
|
|
|
|
func get_stage(event_name: StringName) -> int:
|
|
|
|
|
if not ArchiveManager.archive or ArchiveManager.archive.event_stage == null:
|
2025-07-15 06:54:13 +00:00
|
|
|
|
printerr("[EventManager] Archive or event_stage is null. Cannot get stage for '", event_name, "'.")
|
2025-06-27 14:52:46 +00:00
|
|
|
|
return 0
|
2025-07-15 06:54:13 +00:00
|
|
|
|
return ArchiveManager.archive.event_stage.get(event_name, 0)
|
2025-06-27 14:52:46 +00:00
|
|
|
|
|
|
|
|
|
|
2025-07-15 06:54:13 +00:00
|
|
|
|
# 核心的 stage 设置函数
|
2025-06-27 14:52:46 +00:00
|
|
|
|
# default 为 0,首次更新为 1
|
|
|
|
|
func set_stage(event_name: StringName, stage := 1) -> void:
|
|
|
|
|
if not ArchiveManager.archive or ArchiveManager.archive.event_stage == null:
|
2025-07-15 06:54:13 +00:00
|
|
|
|
printerr("[EventManager] Archive or event_stage is null. Cannot set stage for '", event_name, "'.")
|
2025-06-27 14:52:46 +00:00
|
|
|
|
return
|
|
|
|
|
ArchiveManager.archive.event_stage[event_name] = stage
|
2025-07-15 06:54:13 +00:00
|
|
|
|
print("[EventManager] Stage updated: %s -> %s" % [event_name, stage])
|
2025-06-27 14:52:46 +00:00
|
|
|
|
stage_updated.emit(event_name, stage)
|
2025-07-15 06:54:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 仅当设置的 stage > 当前 stage 时更新
|
|
|
|
|
func set_stage_if_greater(event_name: StringName, stage: int) -> bool:
|
|
|
|
|
if stage > get_stage(event_name):
|
2025-06-27 14:52:46 +00:00
|
|
|
|
set_stage(event_name, stage)
|
2025-07-02 18:29:39 +00:00
|
|
|
|
return true
|
|
|
|
|
return false
|
2025-06-27 14:52:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# stage 最大 99999
|
2025-07-15 06:54:13 +00:00
|
|
|
|
func next_stage(event_name: StringName, stage_max := 99999) -> int:
|
2025-06-27 14:52:46 +00:00
|
|
|
|
var current_stage = get_stage(event_name)
|
|
|
|
|
if current_stage < stage_max:
|
2025-07-15 06:54:13 +00:00
|
|
|
|
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")
|
2025-06-27 14:52:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##### 其他事件 #####
|
2025-01-13 08:09:57 +00:00
|
|
|
|
|
|
|
|
|
|
2025-06-17 05:01:19 +00:00
|
|
|
|
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])
|