DataBase.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using UnityEngine;
  5. using wf;
  6. namespace PrivateMaidMode
  7. {
  8. public static class DataBase
  9. {
  10. public static int Count
  11. {
  12. get
  13. {
  14. DataBase.CreateData();
  15. return DataBase.commonIdManager.idMap.Count;
  16. }
  17. }
  18. public static bool Contains(int id)
  19. {
  20. return DataBase.commonIdManager.idMap.ContainsKey(id);
  21. }
  22. public static DataBase.Data GetData(int id)
  23. {
  24. DataBase.CreateData();
  25. NDebug.Assert(DataBase.basicDatas.ContainsKey(id), "プライベートメイドモード\nID[" + id + "]のデータは存在しません");
  26. return DataBase.basicDatas[id];
  27. }
  28. public static bool IsEnabled(int id)
  29. {
  30. DataBase.CreateData();
  31. return DataBase.commonIdManager.enabledIdList.Contains(id);
  32. }
  33. public static List<DataBase.Data> GetAllDatas(bool onlyEnabled)
  34. {
  35. DataBase.CreateData();
  36. List<DataBase.Data> list = new List<DataBase.Data>();
  37. foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair in DataBase.commonIdManager.idMap)
  38. {
  39. if (!onlyEnabled || DataBase.commonIdManager.enabledIdList.Contains(keyValuePair.Key))
  40. {
  41. list.Add(DataBase.basicDatas[keyValuePair.Key]);
  42. }
  43. }
  44. return list;
  45. }
  46. public static List<DataBase.BG> GetAllBGDatas()
  47. {
  48. DataBase.CreateData();
  49. return new List<DataBase.BG>(DataBase.bgDatas.Values);
  50. }
  51. public static DataBase.BG GetBGData(string uniqueNameBG)
  52. {
  53. DataBase.CreateData();
  54. foreach (KeyValuePair<string, DataBase.BG> keyValuePair in DataBase.bgDatas)
  55. {
  56. if (keyValuePair.Key == uniqueNameBG)
  57. {
  58. return keyValuePair.Value;
  59. }
  60. }
  61. return null;
  62. }
  63. public static void CreateData()
  64. {
  65. if (DataBase.commonIdManager != null)
  66. {
  67. return;
  68. }
  69. DataBase.commonIdManager = new CsvCommonIdManager("private_maidmode_group", "プライベートメイドモード", CsvCommonIdManager.Type.IdOnly, null);
  70. DataBase.basicDatas = new Dictionary<int, DataBase.Data>();
  71. string[] array = new string[]
  72. {
  73. "list"
  74. };
  75. KeyValuePair<AFileBase, CsvParser>[] array2 = new KeyValuePair<AFileBase, CsvParser>[array.Length];
  76. for (int i = 0; i < array2.Length; i++)
  77. {
  78. string text = "private_maidmode_group_" + array[i] + ".nei";
  79. AFileBase afileBase = GameUty.FileSystem.FileOpen(text);
  80. CsvParser csvParser = new CsvParser();
  81. bool condition = csvParser.Open(afileBase);
  82. NDebug.Assert(condition, text + "\nopen failed.");
  83. array2[i] = new KeyValuePair<AFileBase, CsvParser>(afileBase, csvParser);
  84. }
  85. Dictionary<string, DataBase.BG.Event[]> dictionary = new Dictionary<string, DataBase.BG.Event[]>();
  86. using (AFileBase afileBase2 = GameUty.FileSystem.FileOpen("private_maidmode_event_list.nei"))
  87. {
  88. using (CsvParser csvParser2 = new CsvParser())
  89. {
  90. csvParser2.Open(afileBase2);
  91. NDebug.Assert(csvParser2.IsValid(), "private_maidmode_event_list.nei\nopen failed.");
  92. for (int j = 1; j < csvParser2.max_cell_y; j++)
  93. {
  94. string key;
  95. DataBase.BG.Event @event = new DataBase.BG.Event(j, csvParser2, ref key);
  96. if (!dictionary.ContainsKey(key))
  97. {
  98. dictionary.Add(key, new DataBase.BG.Event[2]);
  99. }
  100. dictionary[key][(!@event.isNoon) ? 1 : 0] = @event;
  101. }
  102. }
  103. }
  104. Dictionary<string, List<DataBase.BG.Location>> dictionary2 = new Dictionary<string, List<DataBase.BG.Location>>();
  105. foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair in DataBase.commonIdManager.idMap)
  106. {
  107. int key2 = keyValuePair.Key;
  108. string key3;
  109. DataBase.BG.Location item = new DataBase.BG.Location(key2, array2[0].Value, ref key3);
  110. if (!dictionary2.ContainsKey(key3))
  111. {
  112. dictionary2.Add(key3, new List<DataBase.BG.Location>());
  113. }
  114. List<DataBase.BG.Location> list = dictionary2[key3];
  115. list.Add(item);
  116. }
  117. Dictionary<string, DataBase.BG> dictionary3 = new Dictionary<string, DataBase.BG>();
  118. using (AFileBase afileBase3 = GameUty.FileSystem.FileOpen("private_maidmode_bg_list.nei"))
  119. {
  120. using (CsvParser csvParser3 = new CsvParser())
  121. {
  122. csvParser3.Open(afileBase3);
  123. NDebug.Assert(csvParser3.IsValid(), "private_maidmode_bg_list.nei\nopen failed.");
  124. for (int k = 1; k < csvParser3.max_cell_y; k++)
  125. {
  126. DataBase.BG bg = new DataBase.BG(k, csvParser3, dictionary2, dictionary);
  127. dictionary3.Add(bg.uniqueName, bg);
  128. }
  129. }
  130. }
  131. DataBase.bgDatas = dictionary3;
  132. foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair2 in DataBase.commonIdManager.idMap)
  133. {
  134. int key4 = keyValuePair2.Key;
  135. DataBase.Data value = new DataBase.Data(key4, array2[0].Value, dictionary3);
  136. DataBase.basicDatas.Add(key4, value);
  137. }
  138. foreach (KeyValuePair<AFileBase, CsvParser> keyValuePair3 in array2)
  139. {
  140. keyValuePair3.Value.Dispose();
  141. keyValuePair3.Key.Dispose();
  142. }
  143. }
  144. private const string csvTopCommonName = "private_maidmode_group";
  145. private const string typeNameForErrorLog = "プライベートメイドモード";
  146. private const string bgDefineFileName = "private_maidmode_bg_list.nei";
  147. private const string eventDefineFileName = "private_maidmode_event_list.nei";
  148. private static CsvCommonIdManager commonIdManager;
  149. private static Dictionary<int, DataBase.Data> basicDatas;
  150. private static Dictionary<string, DataBase.BG> bgDatas;
  151. public class BG
  152. {
  153. public BG(int lineY, CsvParser basicCsv, Dictionary<string, List<DataBase.BG.Location>> locationList, Dictionary<string, DataBase.BG.Event[]> eventList)
  154. {
  155. if (!basicCsv.IsCellToExistData(0, lineY))
  156. {
  157. return;
  158. }
  159. int num = 0;
  160. this.uniqueName = basicCsv.GetCellAsString(num++, lineY);
  161. this.drawName = basicCsv.GetCellAsString(num++, lineY);
  162. string cellAsString = basicCsv.GetCellAsString(num++, lineY);
  163. List<int> list = new List<int>();
  164. if (!string.IsNullOrEmpty(cellAsString))
  165. {
  166. foreach (string text in cellAsString.Split(new char[]
  167. {
  168. ','
  169. }))
  170. {
  171. int minValue = int.MinValue;
  172. if (int.TryParse(text.Trim(), out minValue))
  173. {
  174. list.Add(minValue);
  175. }
  176. }
  177. }
  178. this.requestFacilityId = list.ToArray();
  179. this.prefabName = new string[2];
  180. this.prefabName[0] = basicCsv.GetCellAsString(num++, lineY);
  181. this.prefabName[1] = basicCsv.GetCellAsString(num++, lineY);
  182. if (locationList != null && locationList.ContainsKey(this.uniqueName))
  183. {
  184. this.locations = locationList[this.uniqueName].ToArray();
  185. foreach (DataBase.BG.Location location in this.locations)
  186. {
  187. if (location != null)
  188. {
  189. location.SetParentBg(this);
  190. }
  191. }
  192. }
  193. if (eventList != null && eventList.ContainsKey(this.uniqueName) && eventList[this.uniqueName] != null)
  194. {
  195. this.events = eventList[this.uniqueName];
  196. foreach (DataBase.BG.Event @event in this.events)
  197. {
  198. if (@event != null)
  199. {
  200. @event.SetParentBg(this);
  201. @event.ShuffleEventPlayOrder();
  202. }
  203. }
  204. }
  205. }
  206. public bool enabled
  207. {
  208. get
  209. {
  210. if (this.requestFacilityId == null || this.requestFacilityId.Length <= 0)
  211. {
  212. return true;
  213. }
  214. FacilityManager facilityManager = (!(GameMain.Instance != null)) ? null : GameMain.Instance.FacilityMgr;
  215. if (facilityManager != null)
  216. {
  217. foreach (int facilityTypeID in this.requestFacilityId)
  218. {
  219. Facility[] array2;
  220. if (facilityManager.IsExistTypeFacility(facilityTypeID, out array2))
  221. {
  222. return true;
  223. }
  224. }
  225. }
  226. return false;
  227. }
  228. }
  229. public string drawNameTerm
  230. {
  231. get
  232. {
  233. return string.Empty;
  234. }
  235. }
  236. public DataBase.BG.Location GetLocation(string locationName)
  237. {
  238. foreach (DataBase.BG.Location location in this.locations)
  239. {
  240. if (location != null && location.drawName == locationName)
  241. {
  242. return location;
  243. }
  244. }
  245. return null;
  246. }
  247. public DataBase.BG.Event GetEvent(bool isNoon)
  248. {
  249. return (this.events != null && this.events.Length != 0) ? this.events[(!isNoon) ? 1 : 0] : null;
  250. }
  251. public void Apply(bool isNoon)
  252. {
  253. if (GameMain.Instance != null && GameMain.Instance.BgMgr != null)
  254. {
  255. GameMain.Instance.BgMgr.ChangeBg(this.prefabName[(!isNoon) ? 1 : 0]);
  256. }
  257. }
  258. public readonly string uniqueName;
  259. public readonly string drawName;
  260. public readonly int[] requestFacilityId;
  261. public readonly string[] prefabName;
  262. public readonly DataBase.BG.Location[] locations;
  263. public readonly DataBase.BG.Event[] events;
  264. public class Location
  265. {
  266. public Location(int uniqueId, CsvParser basicCsv, out string uniqueBgName)
  267. {
  268. uniqueBgName = string.Empty;
  269. for (int i = 1; i < basicCsv.max_cell_y; i++)
  270. {
  271. if (basicCsv.IsCellToExistData(0, i) && basicCsv.GetCellAsInteger(0, i) == uniqueId)
  272. {
  273. int num = 1;
  274. uniqueBgName = basicCsv.GetCellAsString(num++, i);
  275. this.drawName = basicCsv.GetCellAsString(num++, i);
  276. this.fileName = basicCsv.GetCellAsString(num++, i);
  277. if (!Path.HasExtension(this.fileName))
  278. {
  279. this.fileName += ".ks";
  280. }
  281. this.labelName = basicCsv.GetCellAsString(num++, i);
  282. break;
  283. }
  284. }
  285. }
  286. public DataBase.BG parentBg { get; private set; }
  287. public string drawNameTerm
  288. {
  289. get
  290. {
  291. return string.Empty;
  292. }
  293. }
  294. public void SetParentBg(DataBase.BG parentBg)
  295. {
  296. this.parentBg = parentBg;
  297. }
  298. public bool LoadScript()
  299. {
  300. if (!string.IsNullOrEmpty(this.labelName) && GameMain.Instance != null && GameMain.Instance.ScriptMgr != null)
  301. {
  302. ScriptManager scriptMgr = GameMain.Instance.ScriptMgr;
  303. scriptMgr.tmp_kag.LoadScriptFile(this.fileName, this.labelName);
  304. scriptMgr.tmp_kag.enabled = true;
  305. scriptMgr.tmp_kag.Exec();
  306. scriptMgr.tmp_kag.enabled = false;
  307. return true;
  308. }
  309. return false;
  310. }
  311. public readonly string drawName;
  312. public readonly string fileName;
  313. public readonly string labelName;
  314. }
  315. public class Event
  316. {
  317. public Event(int lineY, CsvParser basicCsv, out string uniqueBgName)
  318. {
  319. uniqueBgName = string.Empty;
  320. if (!basicCsv.IsCellToExistData(0, lineY))
  321. {
  322. return;
  323. }
  324. int num = 0;
  325. uniqueBgName = basicCsv.GetCellAsString(num++, lineY);
  326. this.isNoon = (basicCsv.GetCellAsString(num++, lineY) == "昼");
  327. this.hitPrefabPath = basicCsv.GetCellAsString(num++, lineY);
  328. this.eventScriptFile = basicCsv.GetCellAsString(num++, lineY);
  329. if (!Path.HasExtension(this.eventScriptFile))
  330. {
  331. this.eventScriptFile += ".ks";
  332. }
  333. List<DataBase.BG.Event.PointData> list = new List<DataBase.BG.Event.PointData>();
  334. for (int i = num; i < basicCsv.max_cell_x; i++)
  335. {
  336. int no = i - num + 1;
  337. string cellAsString = basicCsv.GetCellAsString(i, lineY);
  338. if (!string.IsNullOrEmpty(cellAsString))
  339. {
  340. List<string> list2 = new List<string>();
  341. foreach (string text in cellAsString.Split(new char[]
  342. {
  343. '/'
  344. }))
  345. {
  346. list2.Add(text.Trim());
  347. }
  348. list.Add(new DataBase.BG.Event.PointData(no, list2));
  349. }
  350. }
  351. this.eventPointList = list.ToArray();
  352. }
  353. public DataBase.BG parentBg { get; private set; }
  354. public GameObject InstantiateHitPrefab(GameObject parent)
  355. {
  356. GameObject result;
  357. try
  358. {
  359. result = Utility.CreatePrefab(parent, this.hitPrefabPath, true);
  360. }
  361. catch (Exception exception)
  362. {
  363. Debug.LogException(exception);
  364. result = null;
  365. }
  366. return result;
  367. }
  368. public DataBase.BG.Event.PointData GetEventData(int pointNo)
  369. {
  370. if (this.eventPointList != null)
  371. {
  372. foreach (DataBase.BG.Event.PointData pointData in this.eventPointList)
  373. {
  374. if (pointData != null && pointData.no == pointNo)
  375. {
  376. return pointData;
  377. }
  378. }
  379. }
  380. return null;
  381. }
  382. public bool ContainsEvent(int pointNo)
  383. {
  384. return this.GetEventData(pointNo) != null;
  385. }
  386. public bool LoadScript(Maid maid, int pointNo)
  387. {
  388. DataBase.BG.Event.PointData eventData = this.GetEventData(pointNo);
  389. if (eventData != null && GameMain.Instance != null && GameMain.Instance.ScriptMgr != null)
  390. {
  391. int hashCode = eventData.GetHashCode();
  392. if (!this.scenarioIndexDictionary.ContainsKey(hashCode))
  393. {
  394. this.scenarioIndexDictionary.Add(hashCode, 0);
  395. }
  396. ScriptManager scriptMgr = GameMain.Instance.ScriptMgr;
  397. string str = this.eventScriptFile;
  398. if (maid != null)
  399. {
  400. str = ScriptManager.ReplacePersonal(maid, this.eventScriptFile);
  401. }
  402. int num = this.scenarioIndexDictionary[hashCode];
  403. if (eventData.labelList.Count <= num)
  404. {
  405. num = 0;
  406. }
  407. if (maid != null && this.lastMaidGuid != maid.status.guid)
  408. {
  409. num = 0;
  410. this.lastMaidGuid = maid.status.guid;
  411. }
  412. GameMain.Instance.ScriptMgr.EvalScript("global.__private_maid_mode_adv_file = '" + str + "';");
  413. GameMain.Instance.ScriptMgr.EvalScript("global.__private_maid_mode_adv_label = '" + eventData.labelList[num++] + "';");
  414. this.scenarioIndexDictionary[hashCode] = num;
  415. scriptMgr.LoadAdvScenarioScript("private_maid_mode_adv_call.ks", "*ADVスタート");
  416. scriptMgr.adv_kag.Exec();
  417. return true;
  418. }
  419. return false;
  420. }
  421. public void ShuffleEventPlayOrder()
  422. {
  423. }
  424. public void SetParentBg(DataBase.BG parentBg)
  425. {
  426. this.parentBg = parentBg;
  427. }
  428. public readonly bool isNoon;
  429. public readonly string hitPrefabPath;
  430. public readonly string eventScriptFile;
  431. public readonly DataBase.BG.Event.PointData[] eventPointList;
  432. private Dictionary<int, int> scenarioIndexDictionary = new Dictionary<int, int>();
  433. private string lastMaidGuid = string.Empty;
  434. public class PointData
  435. {
  436. public PointData(int no, List<string> labelList)
  437. {
  438. this.no = no;
  439. this.labelList = labelList;
  440. }
  441. public List<string> labelList { get; private set; }
  442. public void ShuffleLabel()
  443. {
  444. string[] array = this.labelList.ToArray();
  445. System.Random random = new System.Random();
  446. int i = array.Length;
  447. while (i > 1)
  448. {
  449. i--;
  450. int num = random.Next(i + 1);
  451. string text = array[num];
  452. array[num] = array[i];
  453. array[i] = text;
  454. }
  455. this.labelList = new List<string>(array);
  456. }
  457. public readonly int no;
  458. }
  459. }
  460. }
  461. public class Data
  462. {
  463. public Data(int uniqueId, CsvParser basicCsv, Dictionary<string, DataBase.BG> bgDataList)
  464. {
  465. for (int i = 1; i < basicCsv.max_cell_y; i++)
  466. {
  467. if (basicCsv.IsCellToExistData(0, i) && basicCsv.GetCellAsInteger(0, i) == uniqueId)
  468. {
  469. int num = 1;
  470. this.id = uniqueId;
  471. string cellAsString = basicCsv.GetCellAsString(num++, i);
  472. this.bgData = bgDataList[cellAsString];
  473. string cellAsString2 = basicCsv.GetCellAsString(num++, i);
  474. this.locationData = this.bgData.GetLocation(cellAsString2);
  475. break;
  476. }
  477. }
  478. }
  479. public readonly int id;
  480. public readonly DataBase.BG bgData;
  481. public readonly DataBase.BG.Location locationData;
  482. }
  483. }
  484. }