ScenarioSelectMgr.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using UnityEngine;
  6. using wf;
  7. public class ScenarioSelectMgr
  8. {
  9. public ScenarioData[] AddedScenario
  10. {
  11. get
  12. {
  13. if (this.m_AddedScenerio == null)
  14. {
  15. this.IsEventAdded();
  16. }
  17. return this.m_AddedScenerio;
  18. }
  19. }
  20. public bool DeserializeFiled { get; private set; }
  21. public float nSaveVer { get; private set; }
  22. private void ReadConvertData(CsvParser csv, int cy)
  23. {
  24. this.m_PersonalConvertData.Add(csv.GetCellAsString(0, cy), csv.GetCellAsString(1, cy));
  25. }
  26. public void InitScenarioData()
  27. {
  28. if (this.m_AllScenarioData.Count > 0)
  29. {
  30. return;
  31. }
  32. HashSet<int> enabled_id_list = new HashSet<int>();
  33. Action<string> action = delegate(string file_name)
  34. {
  35. file_name += ".nei";
  36. if (!GameUty.FileSystem.IsExistentFile(file_name))
  37. {
  38. return;
  39. }
  40. using (AFileBase afileBase2 = GameUty.FileSystem.FileOpen(file_name))
  41. {
  42. using (CsvParser csvParser2 = new CsvParser())
  43. {
  44. bool condition2 = csvParser2.Open(afileBase2);
  45. NDebug.Assert(condition2, file_name + "\nopen failed.");
  46. for (int k = 1; k < csvParser2.max_cell_y; k++)
  47. {
  48. if (csvParser2.IsCellToExistData(0, k))
  49. {
  50. int cellAsInteger2 = csvParser2.GetCellAsInteger(0, k);
  51. if (!enabled_id_list.Contains(cellAsInteger2))
  52. {
  53. enabled_id_list.Add(cellAsInteger2);
  54. }
  55. }
  56. }
  57. }
  58. }
  59. };
  60. action("selectable_scenario_id");
  61. for (int i = 0; i < GameUty.PathList.Count; i++)
  62. {
  63. action("selectable_scenario_id_" + GameUty.PathList[i]);
  64. }
  65. using (AFileBase afileBase = GameUty.FileSystem.FileOpen("select_scenario_data.nei"))
  66. {
  67. using (CsvParser csvParser = new CsvParser())
  68. {
  69. bool condition = csvParser.Open(afileBase);
  70. NDebug.Assert(condition, "select_scenario_data.nei]");
  71. for (int j = 1; j < csvParser.max_cell_y; j++)
  72. {
  73. if (csvParser.IsCellToExistData(0, j))
  74. {
  75. int cellAsInteger = csvParser.GetCellAsInteger(0, j);
  76. if (enabled_id_list.Contains(cellAsInteger))
  77. {
  78. if (!this.m_AllScenarioData.ContainsKey(cellAsInteger))
  79. {
  80. this.m_AllScenarioData.Add(cellAsInteger, new ScenarioData(csvParser, j));
  81. }
  82. }
  83. }
  84. }
  85. }
  86. }
  87. KasaiUtility.CsvReadY("personal_convert_data.nei", new Action<CsvParser, int>(this.ReadConvertData), 2, null);
  88. }
  89. public bool IsEventAdded()
  90. {
  91. List<ScenarioData> list = (from e in this.m_AllScenarioData.Values
  92. where e.ImportantPlayable
  93. select e).ToList<ScenarioData>();
  94. ScenarioData[] array = (from e in list
  95. where !this.m_ImportantScenarioList.Contains(e)
  96. select e).ToArray<ScenarioData>();
  97. this.m_AddedScenerio = array;
  98. this.m_ImportantScenarioList = list;
  99. return array.Length > 0;
  100. }
  101. public ScenarioData GetScenarioData(string title)
  102. {
  103. foreach (ScenarioData scenarioData in this.m_AllScenarioData.Values)
  104. {
  105. if (scenarioData.NotLineTitle == title)
  106. {
  107. return scenarioData;
  108. }
  109. }
  110. return null;
  111. }
  112. public ScenarioData GetScenarioData(int id)
  113. {
  114. return (!this.m_AllScenarioData.ContainsKey(id)) ? null : this.m_AllScenarioData[id];
  115. }
  116. public ScenarioData[] GetAllScenarioData()
  117. {
  118. return this.m_AllScenarioData.Values.ToArray<ScenarioData>();
  119. }
  120. public bool ExistConvertData(string check_data)
  121. {
  122. return this.m_PersonalConvertData.ContainsValue(check_data);
  123. }
  124. public string GetConvertPersonal(Maid maid)
  125. {
  126. if (this.m_PersonalConvertData.ContainsKey(maid.status.personal.uniqueName))
  127. {
  128. return this.m_PersonalConvertData[maid.status.personal.uniqueName];
  129. }
  130. return string.Empty;
  131. }
  132. public void Serialize(BinaryWriter writer)
  133. {
  134. writer.Write("COM3D2_SCENARIO_SELECT");
  135. writer.Write(1.3f);
  136. writer.Write("CM3D2_SCENARIO_ID_START");
  137. foreach (ScenarioData scenarioData in this.m_AllScenarioData.Values)
  138. {
  139. writer.Write(scenarioData.ID.ToString());
  140. }
  141. writer.Write("CM3D2_SCENARIO_ID_END");
  142. writer.Write("CM3D2_SELECTABLE_START");
  143. foreach (ScenarioData scenarioData2 in this.m_ImportantScenarioList)
  144. {
  145. writer.Write(scenarioData2.ID.ToString());
  146. }
  147. writer.Write("CM3D2_SELECTABLE_END");
  148. foreach (ScenarioData scenarioData3 in this.m_AllScenarioData.Values)
  149. {
  150. scenarioData3.Serialize(writer);
  151. }
  152. }
  153. public void Deserialize(BinaryReader reader)
  154. {
  155. string a = reader.ReadString();
  156. NDebug.Assert(a == "CM3D2_SCENARIO_SELECT" || a == "COM3D2_SCENARIO_SELECT", "セーブデータファイルのヘッダーが不正です。");
  157. if (a == "COM3D2_SCENARIO_SELECT")
  158. {
  159. this.nSaveVer = reader.ReadSingle();
  160. }
  161. else
  162. {
  163. this.nSaveVer = -1f;
  164. }
  165. this.DeserializeFiled = false;
  166. int count = this.m_AllScenarioData.Count;
  167. foreach (ScenarioData scenarioData in this.m_AllScenarioData.Values)
  168. {
  169. scenarioData.Recet();
  170. }
  171. List<int> list = new List<int>();
  172. string a2 = reader.ReadString();
  173. if (a2 == "CM3D2_SCENARIO_ID_START")
  174. {
  175. string text = reader.ReadString();
  176. while (text != "CM3D2_SCENARIO_ID_END")
  177. {
  178. list.Add(int.Parse(text));
  179. text = reader.ReadString();
  180. }
  181. List<int> list2 = new List<int>();
  182. string a3 = reader.ReadString();
  183. if (a3 == "CM3D2_SELECTABLE_START")
  184. {
  185. string text2 = reader.ReadString();
  186. while (text2 != "CM3D2_SELECTABLE_END")
  187. {
  188. list2.Add(int.Parse(text2));
  189. text2 = reader.ReadString();
  190. }
  191. }
  192. else
  193. {
  194. this.DeserializeFiled = true;
  195. Debug.Log("ScenarioSelectMgr.cs:重要シナリオデータIDを書き込む前のバージョンのデータです(2017/10/24より前)");
  196. }
  197. foreach (int key in list)
  198. {
  199. if (this.m_AllScenarioData.ContainsKey(key))
  200. {
  201. this.m_AllScenarioData[key].Deserialize(reader);
  202. }
  203. else
  204. {
  205. ScenarioData scenarioData2 = new ScenarioData();
  206. scenarioData2.Deserialize(reader);
  207. }
  208. }
  209. this.m_ImportantScenarioList.Clear();
  210. foreach (int key2 in list2)
  211. {
  212. if (this.m_AllScenarioData.ContainsKey(key2))
  213. {
  214. this.m_ImportantScenarioList.Add(this.m_AllScenarioData[key2]);
  215. }
  216. }
  217. }
  218. else
  219. {
  220. Debug.Log("ScenarioSelectMgr.cs:有効IDを書き込む前のバージョンのデータです(2017/10/23より前)");
  221. this.DeserializeFiled = true;
  222. foreach (ScenarioData scenarioData3 in this.m_AllScenarioData.Values)
  223. {
  224. scenarioData3.Deserialize(reader);
  225. }
  226. this.m_ImportantScenarioList = (from e in this.m_AllScenarioData.Values
  227. where e.IsPlayable && e.IsImportant
  228. select e).ToList<ScenarioData>();
  229. }
  230. }
  231. public void AddedDisplay(string label)
  232. {
  233. GameObject gameObject = Utility.CreatePrefab(null, "SceneScenarioSelect/Prefab/AdditionalScenario", false);
  234. gameObject.GetComponent<AdditionalScenario>().Init(label);
  235. }
  236. public bool ExistScenario(int id)
  237. {
  238. return this.m_AllScenarioData.ContainsKey(id);
  239. }
  240. public const int CheckVersion = 206;
  241. private const float m_SaveVer = 1.3f;
  242. private Dictionary<int, ScenarioData> m_AllScenarioData = new Dictionary<int, ScenarioData>();
  243. private List<ScenarioData> m_ImportantScenarioList = new List<ScenarioData>();
  244. private ScenarioData[] m_AddedScenerio;
  245. private Dictionary<string, string> m_PersonalConvertData = new Dictionary<string, string>();
  246. }