JobClass.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. using System;
  2. using System.Collections.Generic;
  3. using MaidStatus.CsvData;
  4. using wf;
  5. namespace MaidStatus
  6. {
  7. public static class JobClass
  8. {
  9. public static int Count
  10. {
  11. get
  12. {
  13. JobClass.CreateData();
  14. return JobClass.commonIdManager.idMap.Count;
  15. }
  16. }
  17. public static bool Contains(string name)
  18. {
  19. return JobClass.commonIdManager.nameMap.ContainsKey(name);
  20. }
  21. public static bool Contains(int id)
  22. {
  23. return JobClass.commonIdManager.idMap.ContainsKey(id);
  24. }
  25. public static int uniqueNameToId(string name)
  26. {
  27. JobClass.CreateData();
  28. NDebug.Assert(JobClass.commonIdManager.nameMap.ContainsKey(name), "ジョブクラス\nユニーク名[" + name + "]をIDに変換できませんでした");
  29. return JobClass.commonIdManager.nameMap[name];
  30. }
  31. public static string IdToUniqueName(int id)
  32. {
  33. JobClass.CreateData();
  34. NDebug.Assert(JobClass.commonIdManager.idMap.ContainsKey(id), "ジョブクラス\nID[" + id + "]をユニーク名に変換できませんでした");
  35. return JobClass.commonIdManager.idMap[id].Key;
  36. }
  37. public static JobClass.Data GetData(int id)
  38. {
  39. JobClass.CreateData();
  40. NDebug.Assert(JobClass.basicDatas.ContainsKey(id), "ジョブクラス\nID[" + id + "]のデータは存在しません");
  41. return JobClass.basicDatas[id];
  42. }
  43. public static JobClass.Data GetData(string uniqueName)
  44. {
  45. return JobClass.GetData(JobClass.uniqueNameToId(uniqueName));
  46. }
  47. public static bool IsEnabled(string uniqueName)
  48. {
  49. JobClass.CreateData();
  50. return JobClass.commonIdManager.enabledIdList.Contains(JobClass.uniqueNameToId(uniqueName));
  51. }
  52. public static bool IsEnabled(int id)
  53. {
  54. JobClass.CreateData();
  55. return JobClass.commonIdManager.enabledIdList.Contains(id);
  56. }
  57. public static List<JobClass.Data> GetAllDatas(bool onlyEnabled)
  58. {
  59. JobClass.CreateData();
  60. List<JobClass.Data> list = new List<JobClass.Data>();
  61. foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair in JobClass.commonIdManager.idMap)
  62. {
  63. if (!onlyEnabled || JobClass.commonIdManager.enabledIdList.Contains(keyValuePair.Key))
  64. {
  65. list.Add(JobClass.basicDatas[keyValuePair.Key]);
  66. }
  67. }
  68. return list;
  69. }
  70. public static void CreateData()
  71. {
  72. if (JobClass.commonIdManager != null)
  73. {
  74. return;
  75. }
  76. JobClass.commonIdManager = new CsvCommonIdManager("maid_status_jobclass", "ジョブクラス", CsvCommonIdManager.Type.IdAndUniqueName, null);
  77. JobClass.basicDatas = new Dictionary<int, JobClass.Data>();
  78. string[] array = new string[]
  79. {
  80. "list",
  81. "acquired_condition",
  82. "bonus",
  83. "experiences"
  84. };
  85. KeyValuePair<AFileBase, CsvParser>[] array2 = new KeyValuePair<AFileBase, CsvParser>[array.Length];
  86. for (int i = 0; i < array2.Length; i++)
  87. {
  88. string text = "maid_status_jobclass_" + array[i] + ".nei";
  89. AFileBase afileBase = GameUty.FileSystem.FileOpen(text);
  90. CsvParser csvParser = new CsvParser();
  91. bool condition = csvParser.Open(afileBase);
  92. NDebug.Assert(condition, text + "\nopen failed.");
  93. array2[i] = new KeyValuePair<AFileBase, CsvParser>(afileBase, csvParser);
  94. }
  95. foreach (KeyValuePair<string, int> keyValuePair in JobClass.commonIdManager.nameMap)
  96. {
  97. string key = keyValuePair.Key;
  98. JobClass.Data value = new JobClass.Data(key, array2[0].Value, array2[1].Value, array2[2].Value, array2[3].Value);
  99. JobClass.basicDatas.Add(keyValuePair.Value, value);
  100. }
  101. foreach (KeyValuePair<AFileBase, CsvParser> keyValuePair2 in array2)
  102. {
  103. keyValuePair2.Value.Dispose();
  104. keyValuePair2.Key.Dispose();
  105. }
  106. if (GameUty.FileSystemOld.IsExistentFile("maid_class_enabled_list.nei"))
  107. {
  108. Dictionary<string, string> enabledIdListOld = new Dictionary<string, string>();
  109. Action<string> action = delegate(string file_name)
  110. {
  111. file_name += ".nei";
  112. if (!GameUty.FileSystemOld.IsExistentFile(file_name))
  113. {
  114. return;
  115. }
  116. using (AFileBase afileBase3 = GameUty.FileSystemOld.FileOpen(file_name))
  117. {
  118. using (CsvParser csvParser3 = new CsvParser())
  119. {
  120. bool condition3 = csvParser3.Open(afileBase3);
  121. NDebug.Assert(condition3, file_name + "\nopen failed.");
  122. for (int n = 1; n < csvParser3.max_cell_y; n++)
  123. {
  124. if (csvParser3.IsCellToExistData(0, n))
  125. {
  126. string cellAsString2 = csvParser3.GetCellAsString(0, n);
  127. string cellAsString3 = csvParser3.GetCellAsString(1, n);
  128. if (!enabledIdListOld.ContainsKey(cellAsString2))
  129. {
  130. enabledIdListOld.Add(cellAsString2, cellAsString3);
  131. }
  132. }
  133. }
  134. }
  135. }
  136. };
  137. action("maid_class_enabled_list");
  138. array = new string[]
  139. {
  140. "infotext",
  141. "acquisition_data",
  142. "bonus_status",
  143. "exp_list"
  144. };
  145. array2 = new KeyValuePair<AFileBase, CsvParser>[array.Length];
  146. for (int k = 0; k < array2.Length; k++)
  147. {
  148. string text2 = "maid_class_" + array[k] + ".nei";
  149. AFileBase afileBase2 = GameUty.FileSystemOld.FileOpen(text2);
  150. CsvParser csvParser2 = new CsvParser();
  151. bool condition2 = csvParser2.Open(afileBase2);
  152. NDebug.Assert(condition2, text2 + "\nopen failed.");
  153. array2[k] = new KeyValuePair<AFileBase, CsvParser>(afileBase2, csvParser2);
  154. }
  155. Dictionary<int, KeyValuePair<string, string>> dictionary = new Dictionary<int, KeyValuePair<string, string>>();
  156. Dictionary<string, int> dictionary2 = new Dictionary<string, int>();
  157. for (int l = 1; l < array2[0].Value.max_cell_y; l++)
  158. {
  159. int num = l - 1;
  160. if (!JobClass.basicDatas.ContainsKey(num))
  161. {
  162. string cellAsString = array2[0].Value.GetCellAsString(0, l);
  163. string text3 = (!enabledIdListOld.ContainsKey(cellAsString)) ? cellAsString : enabledIdListOld[cellAsString];
  164. JobClass.Data value2 = new JobClass.Data(cellAsString, text3, array2[0].Value, array2[1].Value, array2[2].Value, array2[3].Value);
  165. JobClass.basicDatas.Add(num, value2);
  166. dictionary.Add(num, new KeyValuePair<string, string>(cellAsString, text3));
  167. dictionary2.Add(cellAsString, num);
  168. }
  169. else
  170. {
  171. JobClass.basicDatas[num].SetClassType(AbstractClassData.ClassType.Share);
  172. }
  173. }
  174. Dictionary<int, KeyValuePair<string, string>> dictionary3 = new Dictionary<int, KeyValuePair<string, string>>(JobClass.commonIdManager.idMap);
  175. Dictionary<string, int> dictionary4 = new Dictionary<string, int>(JobClass.commonIdManager.nameMap);
  176. HashSet<int> hashSet = new HashSet<int>(JobClass.commonIdManager.enabledIdList);
  177. foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair3 in dictionary)
  178. {
  179. dictionary3.Add(keyValuePair3.Key, keyValuePair3.Value);
  180. dictionary4.Add(keyValuePair3.Value.Key, keyValuePair3.Key);
  181. }
  182. foreach (KeyValuePair<string, string> keyValuePair4 in enabledIdListOld)
  183. {
  184. if (dictionary2.ContainsKey(keyValuePair4.Key) && !hashSet.Contains(dictionary2[keyValuePair4.Key]))
  185. {
  186. hashSet.Add(dictionary2[keyValuePair4.Key]);
  187. }
  188. }
  189. JobClass.commonIdManager = new CsvCommonIdManager(dictionary3, dictionary4, hashSet, CsvCommonIdManager.Type.IdAndUniqueName);
  190. foreach (KeyValuePair<AFileBase, CsvParser> keyValuePair5 in array2)
  191. {
  192. keyValuePair5.Value.Dispose();
  193. keyValuePair5.Key.Dispose();
  194. }
  195. }
  196. }
  197. private const string csvTopCommonName = "maid_status_jobclass";
  198. private const string typeNameForErrorLog = "ジョブクラス";
  199. private static CsvCommonIdManager commonIdManager;
  200. private static Dictionary<int, JobClass.Data> basicDatas;
  201. public class Data : AbstractClassData
  202. {
  203. public Data(string uniqueName, CsvParser basicCsv, CsvParser acquiredConditionCsv, CsvParser bonusCsv, CsvParser experienceCsv) : base(uniqueName, basicCsv, acquiredConditionCsv, bonusCsv, experienceCsv)
  204. {
  205. }
  206. public Data(string uniqueName, string drawName, CsvParser infoCsv, CsvParser acquiredConditionCsv, CsvParser bonusCsv, CsvParser experienceCsv) : base(uniqueName, drawName, infoCsv, acquiredConditionCsv, bonusCsv, experienceCsv)
  207. {
  208. }
  209. protected override string termCategoryName
  210. {
  211. get
  212. {
  213. return "ジョブクラス";
  214. }
  215. }
  216. }
  217. }
  218. }