using System.Collections.Generic; using System.Threading.Tasks; using ColdMint.scripts.character; using ColdMint.scripts.utils; using Godot; namespace ColdMint.scripts.deathInfo; public static class DeathInfoGenerator { private static List? _deathInfoHandlers; /// /// Register the death message handler /// 注册死亡信息处理器 /// /// public static void RegisterDeathInfoHandler(IDeathInfoHandler deathInfoHandler) { _deathInfoHandlers ??= new List(); _deathInfoHandlers.Add(deathInfoHandler); } /// /// Unregister the death message handler /// 取消注册死亡信息处理器 /// /// public static void UnregisterDeathInfoHandler(IDeathInfoHandler deathInfoHandler) { if (_deathInfoHandlers == null) { return; } _deathInfoHandlers.Remove(deathInfoHandler); } /// /// Generate death info /// 生成死亡信息 /// /// /// /// public static async Task GenerateDeathInfo(Player victim, Node killer) { var victimName = victim.ReadOnlyCharacterName ?? victim.Name; string killerName = killer.Name; if (killer is CharacterTemplate characterTemplate) { killerName = characterTemplate.ReadOnlyCharacterName ?? killer.Name; } if (_deathInfoHandlers == null || _deathInfoHandlers.Count == 0) { return GenerateDefaultDeathInfo(victimName, killerName) ?? string.Empty; } foreach (var deathInfoHandler in _deathInfoHandlers) { var deathInfo = await deathInfoHandler.GenerateDeathInfo(victimName, killerName, victim, killer); if (!string.IsNullOrEmpty(deathInfo)) { return deathInfo; } } return GenerateDefaultDeathInfo(victimName, killerName) ?? string.Empty; } /// /// Generate a default death message /// 生成默认的死亡信息 /// /// /// /// private static string? GenerateDefaultDeathInfo(string victimName, string killerName) { return TranslationServerUtils.TranslateWithFormat("death_info_default", victimName, killerName); } }