using System;
using System.Collections.Generic;
using MaidStatus.CsvData;
using wf;

namespace MaidStatus
{
	public static class JobClass
	{
		public static int Count
		{
			get
			{
				JobClass.CreateData();
				return JobClass.commonIdManager.idMap.Count;
			}
		}

		public static bool Contains(string name)
		{
			return JobClass.commonIdManager.nameMap.ContainsKey(name);
		}

		public static bool Contains(int id)
		{
			return JobClass.commonIdManager.idMap.ContainsKey(id);
		}

		public static int uniqueNameToId(string name)
		{
			JobClass.CreateData();
			NDebug.Assert(JobClass.commonIdManager.nameMap.ContainsKey(name), "ジョブクラス\nユニーク名[" + name + "]をIDに変換できませんでした");
			return JobClass.commonIdManager.nameMap[name];
		}

		public static string IdToUniqueName(int id)
		{
			JobClass.CreateData();
			NDebug.Assert(JobClass.commonIdManager.idMap.ContainsKey(id), "ジョブクラス\nID[" + id + "]をユニーク名に変換できませんでした");
			return JobClass.commonIdManager.idMap[id].Key;
		}

		public static JobClass.Data GetData(int id)
		{
			JobClass.CreateData();
			NDebug.Assert(JobClass.basicDatas.ContainsKey(id), "ジョブクラス\nID[" + id + "]のデータは存在しません");
			return JobClass.basicDatas[id];
		}

		public static JobClass.Data GetData(string uniqueName)
		{
			return JobClass.GetData(JobClass.uniqueNameToId(uniqueName));
		}

		public static bool IsEnabled(string uniqueName)
		{
			JobClass.CreateData();
			return JobClass.commonIdManager.enabledIdList.Contains(JobClass.uniqueNameToId(uniqueName));
		}

		public static bool IsEnabled(int id)
		{
			JobClass.CreateData();
			return JobClass.commonIdManager.enabledIdList.Contains(id);
		}

		public static List<JobClass.Data> GetAllDatas(bool onlyEnabled)
		{
			JobClass.CreateData();
			List<JobClass.Data> list = new List<JobClass.Data>();
			foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair in JobClass.commonIdManager.idMap)
			{
				if (!onlyEnabled || JobClass.commonIdManager.enabledIdList.Contains(keyValuePair.Key))
				{
					list.Add(JobClass.basicDatas[keyValuePair.Key]);
				}
			}
			return list;
		}

		public static void CreateData()
		{
			if (JobClass.commonIdManager != null)
			{
				return;
			}
			JobClass.commonIdManager = new CsvCommonIdManager("maid_status_jobclass", "ジョブクラス", CsvCommonIdManager.Type.IdAndUniqueName, null);
			JobClass.basicDatas = new Dictionary<int, JobClass.Data>();
			string[] array = new string[]
			{
				"list",
				"acquired_condition",
				"bonus",
				"experiences"
			};
			KeyValuePair<AFileBase, CsvParser>[] array2 = new KeyValuePair<AFileBase, CsvParser>[array.Length];
			for (int i = 0; i < array2.Length; i++)
			{
				string text = "maid_status_jobclass_" + array[i] + ".nei";
				AFileBase afileBase = GameUty.FileSystem.FileOpen(text);
				CsvParser csvParser = new CsvParser();
				bool condition = csvParser.Open(afileBase);
				NDebug.Assert(condition, text + "\nopen failed.");
				array2[i] = new KeyValuePair<AFileBase, CsvParser>(afileBase, csvParser);
			}
			foreach (KeyValuePair<string, int> keyValuePair in JobClass.commonIdManager.nameMap)
			{
				string key = keyValuePair.Key;
				JobClass.Data value = new JobClass.Data(key, array2[0].Value, array2[1].Value, array2[2].Value, array2[3].Value);
				JobClass.basicDatas.Add(keyValuePair.Value, value);
			}
			foreach (KeyValuePair<AFileBase, CsvParser> keyValuePair2 in array2)
			{
				keyValuePair2.Value.Dispose();
				keyValuePair2.Key.Dispose();
			}
			if (GameUty.FileSystemOld.IsExistentFile("maid_class_enabled_list.nei"))
			{
				Dictionary<string, string> enabledIdListOld = new Dictionary<string, string>();
				Action<string> action = delegate(string file_name)
				{
					file_name += ".nei";
					if (!GameUty.FileSystemOld.IsExistentFile(file_name))
					{
						return;
					}
					using (AFileBase afileBase3 = GameUty.FileSystemOld.FileOpen(file_name))
					{
						using (CsvParser csvParser3 = new CsvParser())
						{
							bool condition3 = csvParser3.Open(afileBase3);
							NDebug.Assert(condition3, file_name + "\nopen failed.");
							for (int n = 1; n < csvParser3.max_cell_y; n++)
							{
								if (csvParser3.IsCellToExistData(0, n))
								{
									string cellAsString2 = csvParser3.GetCellAsString(0, n);
									string cellAsString3 = csvParser3.GetCellAsString(1, n);
									if (!enabledIdListOld.ContainsKey(cellAsString2))
									{
										enabledIdListOld.Add(cellAsString2, cellAsString3);
									}
								}
							}
						}
					}
				};
				action("maid_class_enabled_list");
				array = new string[]
				{
					"infotext",
					"acquisition_data",
					"bonus_status",
					"exp_list"
				};
				array2 = new KeyValuePair<AFileBase, CsvParser>[array.Length];
				for (int k = 0; k < array2.Length; k++)
				{
					string text2 = "maid_class_" + array[k] + ".nei";
					AFileBase afileBase2 = GameUty.FileSystemOld.FileOpen(text2);
					CsvParser csvParser2 = new CsvParser();
					bool condition2 = csvParser2.Open(afileBase2);
					NDebug.Assert(condition2, text2 + "\nopen failed.");
					array2[k] = new KeyValuePair<AFileBase, CsvParser>(afileBase2, csvParser2);
				}
				Dictionary<int, KeyValuePair<string, string>> dictionary = new Dictionary<int, KeyValuePair<string, string>>();
				Dictionary<string, int> dictionary2 = new Dictionary<string, int>();
				for (int l = 1; l < array2[0].Value.max_cell_y; l++)
				{
					int num = l - 1;
					if (!JobClass.basicDatas.ContainsKey(num))
					{
						string cellAsString = array2[0].Value.GetCellAsString(0, l);
						string text3 = (!enabledIdListOld.ContainsKey(cellAsString)) ? cellAsString : enabledIdListOld[cellAsString];
						JobClass.Data value2 = new JobClass.Data(cellAsString, text3, array2[0].Value, array2[1].Value, array2[2].Value, array2[3].Value);
						JobClass.basicDatas.Add(num, value2);
						dictionary.Add(num, new KeyValuePair<string, string>(cellAsString, text3));
						dictionary2.Add(cellAsString, num);
					}
					else
					{
						JobClass.basicDatas[num].SetClassType(AbstractClassData.ClassType.Share);
					}
				}
				Dictionary<int, KeyValuePair<string, string>> dictionary3 = new Dictionary<int, KeyValuePair<string, string>>(JobClass.commonIdManager.idMap);
				Dictionary<string, int> dictionary4 = new Dictionary<string, int>(JobClass.commonIdManager.nameMap);
				HashSet<int> hashSet = new HashSet<int>(JobClass.commonIdManager.enabledIdList);
				foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair3 in dictionary)
				{
					dictionary3.Add(keyValuePair3.Key, keyValuePair3.Value);
					dictionary4.Add(keyValuePair3.Value.Key, keyValuePair3.Key);
				}
				foreach (KeyValuePair<string, string> keyValuePair4 in enabledIdListOld)
				{
					if (dictionary2.ContainsKey(keyValuePair4.Key) && !hashSet.Contains(dictionary2[keyValuePair4.Key]))
					{
						hashSet.Add(dictionary2[keyValuePair4.Key]);
					}
				}
				JobClass.commonIdManager = new CsvCommonIdManager(dictionary3, dictionary4, hashSet, CsvCommonIdManager.Type.IdAndUniqueName);
				foreach (KeyValuePair<AFileBase, CsvParser> keyValuePair5 in array2)
				{
					keyValuePair5.Value.Dispose();
					keyValuePair5.Key.Dispose();
				}
			}
		}

		private const string csvTopCommonName = "maid_status_jobclass";

		private const string typeNameForErrorLog = "ジョブクラス";

		private static CsvCommonIdManager commonIdManager;

		private static Dictionary<int, JobClass.Data> basicDatas;

		public class Data : AbstractClassData
		{
			public Data(string uniqueName, CsvParser basicCsv, CsvParser acquiredConditionCsv, CsvParser bonusCsv, CsvParser experienceCsv) : base(uniqueName, basicCsv, acquiredConditionCsv, bonusCsv, experienceCsv)
			{
			}

			public Data(string uniqueName, string drawName, CsvParser infoCsv, CsvParser acquiredConditionCsv, CsvParser bonusCsv, CsvParser experienceCsv) : base(uniqueName, drawName, infoCsv, acquiredConditionCsv, bonusCsv, experienceCsv)
			{
			}

			protected override string termCategoryName
			{
				get
				{
					return "ジョブクラス";
				}
			}
		}
	}
}
