From 788e6d4bcca2f5f5cb6d1b1da15e393734e836fb Mon Sep 17 00:00:00 2001 From: HungDK <> Date: Thu, 23 Oct 2025 10:51:14 +0700 Subject: [PATCH] Update EC_Game.cs --- .../PerfectWorld/Scripts/MainFiles/EC_Game.cs | 134 +++++++++++++++++- 1 file changed, 129 insertions(+), 5 deletions(-) diff --git a/Assets/PerfectWorld/Scripts/MainFiles/EC_Game.cs b/Assets/PerfectWorld/Scripts/MainFiles/EC_Game.cs index dbec590394..8f6d871e66 100644 --- a/Assets/PerfectWorld/Scripts/MainFiles/EC_Game.cs +++ b/Assets/PerfectWorld/Scripts/MainFiles/EC_Game.cs @@ -1,6 +1,9 @@ using ModelRenderer.Scripts.GameData; using PerfectWorld.Scripts.Task; using UnityEngine; +using BrewMonster.Common; +using System.Collections.Generic; +using System.IO; namespace BrewMonster.Network { public class EC_Game @@ -10,16 +13,36 @@ namespace BrewMonster.Network private static elementdataman m_pElementDataMan; // global element templates manager private static CECGameRun m_pGameRun; // Game running object - CECStringTab m_FixedMsgs; // Fixed message table - CECStringTab m_ItemDesc; // Item desciption string table - CECStringTab m_ItemExtDesc; // Item extend description string table - CECStringTab m_SkillDesc; // Skill description string table - CECStringTab m_BuffDesc; // Buff description string table + private static BrewMonster.Common.CECStringTab m_FixedMsgs; // Fixed message table + private static BrewMonster.Common.CECStringTab m_ItemDesc; // Item desciption string table + private static BrewMonster.Common.CECStringTab m_ItemExtDesc; // Item extend description string table + private static BrewMonster.Common.CECStringTab m_SkillDesc; // Skill description string table + private static BrewMonster.Common.CECStringTab m_BuffDesc; // Buff description string table + private static Dictionary m_ItemMsgMap; // TemplateId -> (MessageId, DisplayMode) #endregion #region Properties public static ATaskTemplMan GetTaskTemplateMan() { return m_pTaskMan; } public static elementdataman GetElementDataMan() { return m_pElementDataMan; } + + // String table getters + public static BrewMonster.Common.CECStringTab GetFixedMsgs() { return m_FixedMsgs; } + public static BrewMonster.Common.CECStringTab GetItemDesc() { return m_ItemDesc; } + public static BrewMonster.Common.CECStringTab GetItemExtDesc() { return m_ItemExtDesc; } + public static BrewMonster.Common.CECStringTab GetSkillDesc() { return m_SkillDesc; } + public static BrewMonster.Common.CECStringTab GetBuffDesc() { return m_BuffDesc; } + public static bool TryGetItemMsg(int templateId, out int messageId, out int displayMode) + { + messageId = 0; + displayMode = 0; + if (m_ItemMsgMap != null && m_ItemMsgMap.TryGetValue(templateId, out var entry)) + { + messageId = entry.MessageId; + displayMode = entry.DisplayMode; + return true; + } + return false; + } #endregion #region Public Methods @@ -42,8 +65,109 @@ namespace BrewMonster.Network BMLogger.LogError("CECGame::Init"); return false; } + + // Initialize string tables + InitializeStringTables(); + return true; } + + /// + /// Initialize all string tables with their respective data files + /// + private static void InitializeStringTables() + { + // Initialize string table instances + m_FixedMsgs = new BrewMonster.Common.CECStringTab(); + m_ItemDesc = new BrewMonster.Common.CECStringTab(); + m_ItemExtDesc = new BrewMonster.Common.CECStringTab(); + m_SkillDesc = new BrewMonster.Common.CECStringTab(); + m_BuffDesc = new BrewMonster.Common.CECStringTab(); + + // Load string files from StreamingAssets/configs directory + string dataPath = Application.streamingAssetsPath + "/configs/"; + + try + { + // Load each string table using the actual file names from StreamingAssets/configs + if (!m_FixedMsgs.Init(dataPath + "fixed_msg.txt", true)) + { + Debug.LogWarning("[EC_Game] Failed to load fixed_msg.txt"); + } + + if (!m_ItemDesc.Init(dataPath + "item_desc.txt", true)) + { + Debug.LogWarning("[EC_Game] Failed to load item_desc.txt"); + } + + if (!m_ItemExtDesc.Init(dataPath + "item_ext_desc.txt", true)) + { + Debug.LogWarning("[EC_Game] Failed to load item_ext_desc.txt"); + } + + if (!m_SkillDesc.Init(dataPath + "skillstr.txt", true)) + { + Debug.LogWarning("[EC_Game] Failed to load skillstr.txt"); + } + + // Note: There's no buff_desc.txt file in the configs folder + // You may need to create this file or use a different source for buff descriptions + if (!m_BuffDesc.Init(dataPath + "buff_desc.txt", true)) + { + Debug.LogWarning("[EC_Game] Failed to load buff_desc.txt - file may not exist"); + } + + // Load item message map (template -> message id) + LoadItemMsgMap(); + + Debug.Log("[EC_Game] String tables initialized successfully"); + } + catch (System.Exception ex) + { + Debug.LogError($"[EC_Game] Error initializing string tables: {ex.Message}"); + } + } + + private struct ItemMsgMapEntry + { + public int MessageId; + public int DisplayMode; + } + + private static void LoadItemMsgMap() + { + m_ItemMsgMap = new Dictionary(); + try + { + string path = Application.streamingAssetsPath + "/configs/item_msg_map.txt"; + if (!File.Exists(path)) + { + Debug.LogWarning("[EC_Game] item_msg_map.txt not found; descriptions will fall back to template IDs"); + return; + } + + foreach (var raw in File.ReadLines(path)) + { + var line = raw.Trim(); + if (line.Length == 0) continue; + if (line.StartsWith("//")) continue; + + // Expect: templateId messageId displayMode + var parts = line.Split(new char[] { '\t', ' ' }, System.StringSplitOptions.RemoveEmptyEntries); + if (parts.Length < 2) continue; + if (!int.TryParse(parts[0], out int templateId)) continue; + if (!int.TryParse(parts[1], out int messageId)) continue; + int displayMode = 0; + if (parts.Length >= 3) int.TryParse(parts[2], out displayMode); + + m_ItemMsgMap[templateId] = new ItemMsgMapEntry { MessageId = messageId, DisplayMode = displayMode }; + } + } + catch (System.Exception ex) + { + Debug.LogWarning($"[EC_Game] Failed to load item_msg_map: {ex.Message}"); + } + } public static CECGameRun GetGameRun() { return m_pGameRun; } #endregion }