| | |
| | | //-------------------------------------------------------- |
| | | // [Author]: 第二世界 |
| | | // [ Date ]: Saturday, January 06, 2018 |
| | | // [Author]: Fish |
| | | // [ Date ]: Wednesday, February 13, 2019 |
| | | //-------------------------------------------------------- |
| | | |
| | | using UnityEngine; |
| | | using System.Collections.Generic; |
| | | using System.IO; |
| | | using System.Threading; |
| | | using System; |
| | | using UnityEngine; |
| | | |
| | | namespace TableConfig { |
| | | public partial class WorldBossConfig |
| | | { |
| | | |
| | | |
| | | public partial class WorldBossConfig : ConfigBase { |
| | | public readonly int NPCID; |
| | | public readonly int[] RareItemID; |
| | | public readonly int MapID; |
| | | public readonly string PortraitID; |
| | | |
| | | public int NPCID { get ; private set ; } |
| | | public int[] RareItemID; |
| | | public int MapID { get ; private set; } |
| | | public string PortraitID { get ; private set; } |
| | | |
| | | public override string getKey() |
| | | public WorldBossConfig(string input) |
| | | { |
| | | try |
| | | { |
| | | return NPCID.ToString(); |
| | | var tables = input.Split('\t'); |
| | | |
| | | int.TryParse(tables[0],out NPCID); |
| | | |
| | | string[] RareItemIDStringArray = tables[1].Trim().Split(StringUtility.splitSeparator,StringSplitOptions.RemoveEmptyEntries); |
| | | RareItemID = new int[RareItemIDStringArray.Length]; |
| | | for (int i=0;i<RareItemIDStringArray.Length;i++) |
| | | { |
| | | int.TryParse(RareItemIDStringArray[i],out RareItemID[i]); |
| | | } |
| | | |
| | | int.TryParse(tables[2],out MapID); |
| | | |
| | | PortraitID = tables[3]; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | DebugEx.Log(ex); |
| | | } |
| | | } |
| | | |
| | | static Dictionary<int, WorldBossConfig> configs = new Dictionary<int, WorldBossConfig>(); |
| | | public static WorldBossConfig Get(int id) |
| | | { |
| | | if (!inited) |
| | | { |
| | | Debug.Log("WorldBossConfig 还未完成初始化。"); |
| | | return null; |
| | | } |
| | | |
| | | if (configs.ContainsKey(id)) |
| | | { |
| | | return configs[id]; |
| | | } |
| | | |
| | | public override void Parse() { |
| | | try |
| | | { |
| | | NPCID=IsNumeric(rawContents[0]) ? int.Parse(rawContents[0]):0; |
| | | |
| | | string[] RareItemIDStringArray = rawContents[1].Trim().Split(StringUtility.splitSeparator,StringSplitOptions.RemoveEmptyEntries); |
| | | RareItemID = new int[RareItemIDStringArray.Length]; |
| | | for (int i=0;i<RareItemIDStringArray.Length;i++) |
| | | { |
| | | int.TryParse(RareItemIDStringArray[i],out RareItemID[i]); |
| | | } |
| | | |
| | | MapID = IsNumeric(rawContents[2]) ? int.Parse(rawContents[2]) : 0; |
| | | WorldBossConfig config = null; |
| | | if (rawDatas.ContainsKey(id)) |
| | | { |
| | | config = configs[id] = new WorldBossConfig(rawDatas[id]); |
| | | rawDatas.Remove(id); |
| | | } |
| | | |
| | | PortraitID = rawContents[3].Trim(); |
| | | } |
| | | catch (Exception ex) |
| | | return config; |
| | | } |
| | | |
| | | public static bool Has(int id) |
| | | { |
| | | return configs.ContainsKey(id) || rawDatas.ContainsKey(id); |
| | | } |
| | | |
| | | public static bool inited { get; private set; } |
| | | protected static Dictionary<int, string> rawDatas = null; |
| | | public static void Init(bool sync=false) |
| | | { |
| | | inited = false; |
| | | var path = string.Empty; |
| | | if (AssetSource.refdataFromEditor) |
| | | { |
| | | path = ResourcesPath.CONFIG_FODLER +"/WorldBoss.txt"; |
| | | } |
| | | else |
| | | { |
| | | path = AssetVersionUtility.GetAssetFilePath("config/WorldBoss.txt"); |
| | | } |
| | | |
| | | if (sync) |
| | | { |
| | | var lines = File.ReadAllLines(path); |
| | | rawDatas = new Dictionary<int, string>(lines.Length - 3); |
| | | for (int i = 3; i < lines.Length; i++) |
| | | { |
| | | DesignDebug.Log(ex); |
| | | var line = lines[i]; |
| | | var index = line.IndexOf("\t"); |
| | | var idString = line.Substring(0, index); |
| | | var id = int.Parse(idString); |
| | | |
| | | rawDatas[id] = line; |
| | | } |
| | | } |
| | | |
| | | } |
| | | inited = true; |
| | | } |
| | | else |
| | | { |
| | | ThreadPool.QueueUserWorkItem((object _object) => |
| | | { |
| | | var lines = File.ReadAllLines(path); |
| | | rawDatas = new Dictionary<int, string>(lines.Length - 3); |
| | | for (int i = 3; i < lines.Length; i++) |
| | | { |
| | | var line = lines[i]; |
| | | var index = line.IndexOf("\t"); |
| | | var idString = line.Substring(0, index); |
| | | var id = int.Parse(idString); |
| | | |
| | | rawDatas[id] = line; |
| | | } |
| | | |
| | | inited = true; |
| | | }); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |