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

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

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

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

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

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

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

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

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

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

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

		public static SortedList<int, List<Skill.Data>> GetLearnSkillList(string uniqueName)
		{
			return YotogiClass.GetLearnSkillList(YotogiClass.uniqueNameToId(uniqueName));
		}

		public static SortedList<int, List<Skill.Data>> GetLearnSkillList(int id)
		{
			if (YotogiClass.learnSkillList == null)
			{
				YotogiClass.learnSkillList = new Dictionary<int, SortedList<int, List<Skill.Data>>>();
				Skill.CreateData();
				YotogiClass.CreateData();
				foreach (YotogiClass.Data data in YotogiClass.GetAllDatas(false))
				{
					YotogiClass.learnSkillList.Add(data.id, new SortedList<int, List<Skill.Data>>());
				}
				for (int i = 0; i < Skill.skill_data_list.Length; i++)
				{
					foreach (Skill.Data data2 in Skill.skill_data_list[i].Values)
					{
						if (data2.getcondition_data.yotogi_class != null)
						{
							if (YotogiClass.learnSkillList.ContainsKey(data2.getcondition_data.yotogi_class.id))
							{
								SortedList<int, List<Skill.Data>> sortedList = YotogiClass.learnSkillList[data2.getcondition_data.yotogi_class.id];
								if (sortedList.ContainsKey(data2.getcondition_data.yotogi_class_level))
								{
									sortedList[data2.getcondition_data.yotogi_class_level].Add(data2);
								}
								else
								{
									List<Skill.Data> list = new List<Skill.Data>();
									list.Add(data2);
									sortedList.Add(data2.getcondition_data.yotogi_class_level, list);
								}
							}
						}
					}
				}
			}
			NDebug.Assert(YotogiClass.learnSkillList.ContainsKey(id), "夜伽クラス\nID[" + id + "]のデータは存在しません");
			return YotogiClass.learnSkillList[id];
		}

		public static SortedList<int, List<Skill.Old.Data>> GetLearnSkillOldList(string uniqueName)
		{
			return YotogiClass.GetLearnSkillOldList(YotogiClass.uniqueNameToId(uniqueName));
		}

		public static SortedList<int, List<Skill.Old.Data>> GetLearnSkillOldList(int id)
		{
			if (YotogiClass.learnSkillOldList == null)
			{
				YotogiClass.learnSkillOldList = new Dictionary<int, SortedList<int, List<Skill.Old.Data>>>();
				Skill.CreateData();
				YotogiClass.CreateData();
				foreach (YotogiClass.Data data in YotogiClass.GetAllDatas(false))
				{
					YotogiClass.learnSkillOldList.Add(data.id, new SortedList<int, List<Skill.Old.Data>>());
				}
				for (int i = 0; i < Skill.Old.skill_data_list.Length; i++)
				{
					foreach (Skill.Old.Data data2 in Skill.Old.skill_data_list[i].Values)
					{
						if (1 <= data2.getcondition_data.yotogi_class_level)
						{
							if (YotogiClass.learnSkillOldList.ContainsKey(data2.getcondition_data.yotogi_class.id))
							{
								SortedList<int, List<Skill.Old.Data>> sortedList = YotogiClass.learnSkillOldList[data2.getcondition_data.yotogi_class.id];
								if (sortedList.ContainsKey(data2.getcondition_data.yotogi_class_level))
								{
									sortedList[data2.getcondition_data.yotogi_class_level].Add(data2);
								}
								else
								{
									List<Skill.Old.Data> list = new List<Skill.Old.Data>();
									list.Add(data2);
									sortedList.Add(data2.getcondition_data.yotogi_class_level, list);
								}
							}
						}
					}
				}
			}
			NDebug.Assert(YotogiClass.learnSkillOldList.ContainsKey(id), "夜伽クラス\nID[" + id + "]のデータは存在しません");
			return YotogiClass.learnSkillOldList[id];
		}

		public static bool IsNTRClass(int id, bool refOld)
		{
			YotogiClass.Data data = YotogiClass.GetData(id);
			if (refOld && data.classType == AbstractClassData.ClassType.New)
			{
				refOld = false;
			}
			else if (!refOld && data.classType == AbstractClassData.ClassType.Old)
			{
				refOld = true;
			}
			bool flag = true;
			if (refOld)
			{
				SortedList<int, List<Skill.Old.Data>> sortedList = YotogiClass.GetLearnSkillOldList(data.id);
				if (sortedList.Count == 0)
				{
					flag = false;
				}
				foreach (KeyValuePair<int, List<Skill.Old.Data>> keyValuePair in sortedList)
				{
					List<Skill.Old.Data> value = keyValuePair.Value;
					for (int i = 0; i < value.Count; i++)
					{
						if (value[i].category != YotogiOld.Category.交換 && value[i].category != YotogiOld.Category.乱交)
						{
							flag = false;
							break;
						}
						if (!flag)
						{
							break;
						}
					}
					if (!flag)
					{
						break;
					}
				}
			}
			else
			{
				SortedList<int, List<Skill.Data>> sortedList2 = YotogiClass.GetLearnSkillList(data.id);
				if (sortedList2.Count == 0)
				{
					flag = false;
				}
				foreach (KeyValuePair<int, List<Skill.Data>> keyValuePair2 in sortedList2)
				{
					List<Skill.Data> value2 = keyValuePair2.Value;
					for (int j = 0; j < value2.Count; j++)
					{
						if (value2[j].category != Yotogi.Category.交換 && value2[j].category != Yotogi.Category.乱交)
						{
							flag = false;
							break;
						}
						if (!flag)
						{
							break;
						}
					}
					if (!flag)
					{
						break;
					}
				}
			}
			return flag;
		}

		public static void CreateData()
		{
			if (YotogiClass.commonIdManager != null)
			{
				return;
			}
			YotogiClass.commonIdManager = new CsvCommonIdManager("maid_status_yotogiclass", "夜伽クラス", CsvCommonIdManager.Type.IdAndUniqueName, null);
			YotogiClass.basicDatas = new Dictionary<int, YotogiClass.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_yotogiclass_" + 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 YotogiClass.commonIdManager.nameMap)
			{
				string key = keyValuePair.Key;
				YotogiClass.Data value = new YotogiClass.Data(key, array2[0].Value, array2[1].Value, array2[2].Value, array2[3].Value);
				YotogiClass.basicDatas.Add(keyValuePair.Value, value);
			}
			foreach (KeyValuePair<AFileBase, CsvParser> keyValuePair2 in array2)
			{
				keyValuePair2.Value.Dispose();
				keyValuePair2.Key.Dispose();
			}
			if (GameUty.FileSystemOld.IsExistentFile("yotogi_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 num = 1; num < csvParser3.max_cell_y; num++)
							{
								if (csvParser3.IsCellToExistData(0, num))
								{
									string cellAsString2 = csvParser3.GetCellAsString(0, num);
									string cellAsString3 = csvParser3.GetCellAsString(1, num);
									if (!enabledIdListOld.ContainsKey(cellAsString2))
									{
										enabledIdListOld.Add(cellAsString2, cellAsString3);
									}
								}
							}
						}
					}
				};
				action("yotogi_class_enabled_list");
				for (int k = 0; k < GameUty.PathListOld.Count; k++)
				{
					action("yotogi_class_enabled_list_" + GameUty.PathListOld[k]);
				}
				array = new string[]
				{
					"infotext",
					"acquisition_data",
					"bonus_status",
					"exp_list"
				};
				array2 = new KeyValuePair<AFileBase, CsvParser>[array.Length];
				for (int l = 0; l < array2.Length; l++)
				{
					string text2 = "yotogi_class_" + array[l] + ".nei";
					AFileBase afileBase2 = GameUty.FileSystemOld.FileOpen(text2);
					CsvParser csvParser2 = new CsvParser();
					bool condition2 = csvParser2.Open(afileBase2);
					NDebug.Assert(condition2, text2 + "\nopen failed.");
					array2[l] = 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 m = 1; m < array2[0].Value.max_cell_y; m++)
				{
					int cellAsInteger = array2[0].Value.GetCellAsInteger(0, m);
					if (!YotogiClass.basicDatas.ContainsKey(cellAsInteger))
					{
						string cellAsString = array2[0].Value.GetCellAsString(1, m);
						string text3 = (!enabledIdListOld.ContainsKey(cellAsString)) ? cellAsString : enabledIdListOld[cellAsString];
						YotogiClass.Data value2 = new YotogiClass.Data(cellAsString, text3, array2[0].Value, array2[1].Value, array2[2].Value, array2[3].Value);
						YotogiClass.basicDatas.Add(cellAsInteger, value2);
						dictionary.Add(cellAsInteger, new KeyValuePair<string, string>(cellAsString, text3));
						dictionary2.Add(cellAsString, cellAsInteger);
					}
					else
					{
						YotogiClass.basicDatas[cellAsInteger].SetClassType(AbstractClassData.ClassType.Share);
					}
				}
				Dictionary<int, KeyValuePair<string, string>> dictionary3 = new Dictionary<int, KeyValuePair<string, string>>(YotogiClass.commonIdManager.idMap);
				Dictionary<string, int> dictionary4 = new Dictionary<string, int>(YotogiClass.commonIdManager.nameMap);
				HashSet<int> hashSet = new HashSet<int>(YotogiClass.commonIdManager.enabledIdList);
				foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair3 in dictionary)
				{
					dictionary3.Add(keyValuePair3.Key, keyValuePair3.Value);
					NDebug.Assert(!dictionary4.ContainsKey(keyValuePair3.Value.Key), "夜伽クラスのユニーク名[" + keyValuePair3.Value.Key + "]が重複しています");
					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]);
					}
				}
				YotogiClass.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_yotogiclass";

		private const string typeNameForErrorLog = "夜伽クラス";

		private static CsvCommonIdManager commonIdManager;

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

		private static Dictionary<int, SortedList<int, List<Skill.Data>>> learnSkillList;

		private static Dictionary<int, SortedList<int, List<Skill.Old.Data>>> learnSkillOldList;

		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 "夜伽クラス";
				}
			}
		}
	}
}
