//--------------------------------------------------------
|
// [Author]: Fish
|
// [ Date ]: 2024年5月17日
|
//--------------------------------------------------------
|
|
using System.Collections.Generic;
|
using System.IO;
|
using System.Threading;
|
using System;
|
using UnityEngine;
|
using LitJson;
|
|
public partial class DemonJarConfig
|
{
|
|
public readonly int NPCID;
|
public readonly int LineID;
|
public readonly int Time;
|
public readonly int[] MustItemID;
|
public readonly string RareItemID;
|
public readonly int NewItemId;
|
public readonly string PortraitID;
|
public readonly int SpecialItemMark;
|
public readonly int CanEnterTimes;
|
public readonly int AutoAttention;
|
public readonly int CancelAttentionAfterKill;
|
public readonly int[] Job1;
|
public readonly int[] Job2;
|
public readonly int[] Job3;
|
public readonly int KillHurtMin;
|
public readonly int KillHurtMax;
|
public readonly string RewardDescription;
|
|
public DemonJarConfig()
|
{
|
}
|
|
public DemonJarConfig(string input)
|
{
|
try
|
{
|
var tables = input.Split('\t');
|
|
int.TryParse(tables[0],out NPCID);
|
|
int.TryParse(tables[1],out LineID);
|
|
int.TryParse(tables[2],out Time);
|
|
if (tables[3].Contains("["))
|
{
|
MustItemID = JsonMapper.ToObject<int[]>(tables[3]);
|
}
|
else
|
{
|
string[] MustItemIDStringArray = tables[3].Trim().Split(StringUtility.splitSeparator,StringSplitOptions.RemoveEmptyEntries);
|
MustItemID = new int[MustItemIDStringArray.Length];
|
for (int i=0;i<MustItemIDStringArray.Length;i++)
|
{
|
int.TryParse(MustItemIDStringArray[i],out MustItemID[i]);
|
}
|
}
|
|
RareItemID = tables[4];
|
|
int.TryParse(tables[5],out NewItemId);
|
|
PortraitID = tables[6];
|
|
int.TryParse(tables[7],out SpecialItemMark);
|
|
int.TryParse(tables[8],out CanEnterTimes);
|
|
int.TryParse(tables[9],out AutoAttention);
|
|
int.TryParse(tables[10],out CancelAttentionAfterKill);
|
|
if (tables[11].Contains("["))
|
{
|
Job1 = JsonMapper.ToObject<int[]>(tables[11]);
|
}
|
else
|
{
|
string[] Job1StringArray = tables[11].Trim().Split(StringUtility.splitSeparator,StringSplitOptions.RemoveEmptyEntries);
|
Job1 = new int[Job1StringArray.Length];
|
for (int i=0;i<Job1StringArray.Length;i++)
|
{
|
int.TryParse(Job1StringArray[i],out Job1[i]);
|
}
|
}
|
|
if (tables[12].Contains("["))
|
{
|
Job2 = JsonMapper.ToObject<int[]>(tables[12]);
|
}
|
else
|
{
|
string[] Job2StringArray = tables[12].Trim().Split(StringUtility.splitSeparator,StringSplitOptions.RemoveEmptyEntries);
|
Job2 = new int[Job2StringArray.Length];
|
for (int i=0;i<Job2StringArray.Length;i++)
|
{
|
int.TryParse(Job2StringArray[i],out Job2[i]);
|
}
|
}
|
|
if (tables[13].Contains("["))
|
{
|
Job3 = JsonMapper.ToObject<int[]>(tables[13]);
|
}
|
else
|
{
|
string[] Job3StringArray = tables[13].Trim().Split(StringUtility.splitSeparator,StringSplitOptions.RemoveEmptyEntries);
|
Job3 = new int[Job3StringArray.Length];
|
for (int i=0;i<Job3StringArray.Length;i++)
|
{
|
int.TryParse(Job3StringArray[i],out Job3[i]);
|
}
|
}
|
|
int.TryParse(tables[14],out KillHurtMin);
|
|
int.TryParse(tables[15],out KillHurtMax);
|
|
RewardDescription = tables[16];
|
}
|
catch (Exception ex)
|
{
|
DebugEx.Log(ex);
|
}
|
}
|
|
static Dictionary<string, DemonJarConfig> configs = new Dictionary<string, DemonJarConfig>();
|
public static DemonJarConfig Get(string id)
|
{
|
if (!inited)
|
{
|
Debug.LogError("DemonJarConfig 还未完成初始化。");
|
return null;
|
}
|
|
if (configs.ContainsKey(id))
|
{
|
return configs[id];
|
}
|
|
DemonJarConfig config = null;
|
if (rawDatas.ContainsKey(id))
|
{
|
config = configs[id] = new DemonJarConfig(rawDatas[id]);
|
rawDatas.Remove(id);
|
}
|
|
return config;
|
}
|
|
public static DemonJarConfig Get(int id)
|
{
|
return Get(id.ToString());
|
}
|
|
public static List<string> GetKeys()
|
{
|
var keys = new List<string>();
|
keys.AddRange(configs.Keys);
|
keys.AddRange(rawDatas.Keys);
|
return keys;
|
}
|
|
public static List<DemonJarConfig> GetValues()
|
{
|
var values = new List<DemonJarConfig>();
|
values.AddRange(configs.Values);
|
|
var keys = new List<string>(rawDatas.Keys);
|
for (int i = 0; i < keys.Count; i++)
|
{
|
values.Add(Get(keys[i]));
|
}
|
|
return values;
|
}
|
|
public static bool Has(string id)
|
{
|
return configs.ContainsKey(id) || rawDatas.ContainsKey(id);
|
}
|
|
public static bool Has(int id)
|
{
|
return Has(id.ToString());
|
}
|
|
public static bool inited { get; private set; }
|
protected static Dictionary<string, string> rawDatas = new Dictionary<string, string>();
|
public static void Init(bool sync=false)
|
{
|
inited = false;
|
var path = string.Empty;
|
if (AssetSource.refdataFromEditor)
|
{
|
path = ResourcesPath.CONFIG_FODLER +"/DemonJar.txt";
|
}
|
else
|
{
|
path = AssetVersionUtility.GetAssetFilePath("config/DemonJar.txt");
|
}
|
|
configs.Clear();
|
var tempConfig = new DemonJarConfig();
|
var preParse = tempConfig is IConfigPostProcess;
|
|
if (sync)
|
{
|
var lines = File.ReadAllLines(path);
|
if (!preParse)
|
{
|
rawDatas = new Dictionary<string, string>(lines.Length - 3);
|
}
|
for (int i = 3; i < lines.Length; i++)
|
{
|
try
|
{
|
var line = lines[i];
|
var index = line.IndexOf("\t");
|
if (index == -1)
|
{
|
continue;
|
}
|
var id = line.Substring(0, index);
|
|
if (preParse)
|
{
|
var config = new DemonJarConfig(line);
|
configs[id] = config;
|
(config as IConfigPostProcess).OnConfigParseCompleted();
|
}
|
else
|
{
|
rawDatas[id] = line;
|
}
|
}
|
catch (System.Exception ex)
|
{
|
Debug.LogError(ex);
|
}
|
}
|
inited = true;
|
}
|
else
|
{
|
ThreadPool.QueueUserWorkItem((object _object) =>
|
{
|
var lines = File.ReadAllLines(path);
|
if (!preParse)
|
{
|
rawDatas = new Dictionary<string, string>(lines.Length - 3);
|
}
|
for (int i = 3; i < lines.Length; i++)
|
{
|
try
|
{
|
var line = lines[i];
|
var index = line.IndexOf("\t");
|
if (index == -1)
|
{
|
continue;
|
}
|
var id = line.Substring(0, index);
|
|
if (preParse)
|
{
|
var config = new DemonJarConfig(line);
|
configs[id] = config;
|
(config as IConfigPostProcess).OnConfigParseCompleted();
|
}
|
else
|
{
|
rawDatas[id] = line;
|
}
|
}
|
catch (System.Exception ex)
|
{
|
Debug.LogError(ex);
|
}
|
}
|
|
inited = true;
|
});
|
}
|
}
|
|
}
|
|
|
|
|