ScenarioSelectMgr.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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 string GetConvertPersonalTerm(Maid maid)
  133. {
  134. if (this.m_PersonalConvertData.ContainsKey(maid.status.personal.uniqueName))
  135. {
  136. return "SceneScenarioSelect/性格名/" + this.m_PersonalConvertData[maid.status.personal.uniqueName];
  137. }
  138. return string.Empty;
  139. }
  140. public void Serialize(BinaryWriter writer)
  141. {
  142. writer.Write("COM3D2_SCENARIO_SELECT");
  143. writer.Write(1.3f);
  144. writer.Write("CM3D2_SCENARIO_ID_START");
  145. foreach (ScenarioData scenarioData in this.m_AllScenarioData.Values)
  146. {
  147. writer.Write(scenarioData.ID.ToString());
  148. }
  149. writer.Write("CM3D2_SCENARIO_ID_END");
  150. writer.Write("CM3D2_SELECTABLE_START");
  151. foreach (ScenarioData scenarioData2 in this.m_ImportantScenarioList)
  152. {
  153. writer.Write(scenarioData2.ID.ToString());
  154. }
  155. writer.Write("CM3D2_SELECTABLE_END");
  156. foreach (ScenarioData scenarioData3 in this.m_AllScenarioData.Values)
  157. {
  158. scenarioData3.Serialize(writer);
  159. }
  160. }
  161. public void Deserialize(BinaryReader reader)
  162. {
  163. string a = reader.ReadString();
  164. NDebug.Assert(a == "CM3D2_SCENARIO_SELECT" || a == "COM3D2_SCENARIO_SELECT", "セーブデータファイルのヘッダーが不正です。");
  165. if (a == "COM3D2_SCENARIO_SELECT")
  166. {
  167. this.nSaveVer = reader.ReadSingle();
  168. }
  169. else
  170. {
  171. this.nSaveVer = -1f;
  172. }
  173. this.DeserializeFiled = false;
  174. int count = this.m_AllScenarioData.Count;
  175. foreach (ScenarioData scenarioData in this.m_AllScenarioData.Values)
  176. {
  177. scenarioData.Recet();
  178. }
  179. List<int> list = new List<int>();
  180. string a2 = reader.ReadString();
  181. if (a2 == "CM3D2_SCENARIO_ID_START")
  182. {
  183. string text = reader.ReadString();
  184. while (text != "CM3D2_SCENARIO_ID_END")
  185. {
  186. list.Add(int.Parse(text));
  187. text = reader.ReadString();
  188. }
  189. List<int> list2 = new List<int>();
  190. string a3 = reader.ReadString();
  191. if (a3 == "CM3D2_SELECTABLE_START")
  192. {
  193. string text2 = reader.ReadString();
  194. while (text2 != "CM3D2_SELECTABLE_END")
  195. {
  196. list2.Add(int.Parse(text2));
  197. text2 = reader.ReadString();
  198. }
  199. }
  200. else
  201. {
  202. this.DeserializeFiled = true;
  203. Debug.Log("ScenarioSelectMgr.cs:重要シナリオデータIDを書き込む前のバージョンのデータです(2017/10/24より前)");
  204. }
  205. foreach (int key in list)
  206. {
  207. if (this.m_AllScenarioData.ContainsKey(key))
  208. {
  209. this.m_AllScenarioData[key].Deserialize(reader);
  210. }
  211. else
  212. {
  213. ScenarioData scenarioData2 = new ScenarioData();
  214. scenarioData2.Deserialize(reader);
  215. }
  216. }
  217. this.m_ImportantScenarioList.Clear();
  218. foreach (int key2 in list2)
  219. {
  220. if (this.m_AllScenarioData.ContainsKey(key2))
  221. {
  222. this.m_ImportantScenarioList.Add(this.m_AllScenarioData[key2]);
  223. }
  224. }
  225. }
  226. else
  227. {
  228. Debug.Log("ScenarioSelectMgr.cs:有効IDを書き込む前のバージョンのデータです(2017/10/23より前)");
  229. this.DeserializeFiled = true;
  230. foreach (ScenarioData scenarioData3 in this.m_AllScenarioData.Values)
  231. {
  232. scenarioData3.Deserialize(reader);
  233. }
  234. this.m_ImportantScenarioList = (from e in this.m_AllScenarioData.Values
  235. where e.IsPlayable && e.IsImportant
  236. select e).ToList<ScenarioData>();
  237. }
  238. }
  239. public void AddedDisplay(string label)
  240. {
  241. GameObject gameObject = Utility.CreatePrefab(null, "SceneScenarioSelect/Prefab/AdditionalScenario", false);
  242. gameObject.GetComponent<AdditionalScenario>().Init(label);
  243. }
  244. public bool ExistScenario(int id)
  245. {
  246. return this.m_AllScenarioData.ContainsKey(id);
  247. }
  248. public const int CheckVersion = 206;
  249. private const float m_SaveVer = 1.3f;
  250. private Dictionary<int, ScenarioData> m_AllScenarioData = new Dictionary<int, ScenarioData>();
  251. private List<ScenarioData> m_ImportantScenarioList = new List<ScenarioData>();
  252. private ScenarioData[] m_AddedScenerio;
  253. private Dictionary<string, string> m_PersonalConvertData = new Dictionary<string, string>();
  254. }