RoomData.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using wf;
  5. namespace Kasizuki
  6. {
  7. public static class RoomData
  8. {
  9. public static int Count
  10. {
  11. get
  12. {
  13. RoomData.CreateData();
  14. return RoomData.commonIdManager.idMap.Count;
  15. }
  16. }
  17. public static bool Contains(string name)
  18. {
  19. return RoomData.commonIdManager.nameMap.ContainsKey(name);
  20. }
  21. public static bool Contains(int id)
  22. {
  23. return RoomData.commonIdManager.idMap.ContainsKey(id);
  24. }
  25. public static int uniqueNameToId(string uniqueName)
  26. {
  27. RoomData.CreateData();
  28. NDebug.Assert(RoomData.commonIdManager.nameMap.ContainsKey(uniqueName), "傅き.部屋データ\nユニーク名[" + uniqueName + "]をIDに変換できませんでした");
  29. return RoomData.commonIdManager.nameMap[uniqueName];
  30. }
  31. public static string IdToUniqueName(int id)
  32. {
  33. RoomData.CreateData();
  34. NDebug.Assert(RoomData.commonIdManager.idMap.ContainsKey(id), "傅き.部屋データ\nID[" + id + "]をユニーク名に変換できませんでした");
  35. return RoomData.commonIdManager.idMap[id].Key;
  36. }
  37. public static RoomData.Data GetData(int id)
  38. {
  39. RoomData.CreateData();
  40. NDebug.Assert(RoomData.basicDatas.ContainsKey(id), "傅き.部屋データ\nID[" + id + "]のデータは存在しません");
  41. return RoomData.basicDatas[id];
  42. }
  43. public static RoomData.Data GetData(string uniqueName)
  44. {
  45. return RoomData.GetData(RoomData.uniqueNameToId(uniqueName));
  46. }
  47. public static bool IsEnabled(string uniqueName)
  48. {
  49. RoomData.CreateData();
  50. return RoomData.commonIdManager.enabledIdList.Contains(RoomData.uniqueNameToId(uniqueName));
  51. }
  52. public static bool IsEnabled(int id)
  53. {
  54. RoomData.CreateData();
  55. return RoomData.commonIdManager.enabledIdList.Contains(id);
  56. }
  57. public static List<RoomData.Data> GetAllDatas(bool onlyEnabled)
  58. {
  59. RoomData.CreateData();
  60. List<RoomData.Data> list = new List<RoomData.Data>();
  61. foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair in RoomData.commonIdManager.idMap)
  62. {
  63. if (!onlyEnabled || RoomData.commonIdManager.enabledIdList.Contains(keyValuePair.Key))
  64. {
  65. list.Add(RoomData.basicDatas[keyValuePair.Key]);
  66. }
  67. }
  68. return list;
  69. }
  70. public static List<RoomData.Data> GetDatas(Func<RoomData.Data, bool> customCheckFunction)
  71. {
  72. RoomData.CreateData();
  73. List<RoomData.Data> list = new List<RoomData.Data>();
  74. foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair in RoomData.commonIdManager.idMap)
  75. {
  76. RoomData.Data data = RoomData.basicDatas[keyValuePair.Key];
  77. if (customCheckFunction(data))
  78. {
  79. list.Add(data);
  80. }
  81. }
  82. return list;
  83. }
  84. public static void CreateData()
  85. {
  86. if (RoomData.commonIdManager != null)
  87. {
  88. return;
  89. }
  90. RoomData.commonIdManager = new CsvCommonIdManager("kasizuki_room", "傅き.部屋データ", CsvCommonIdManager.Type.IdAndUniqueName, null);
  91. RoomData.basicDatas = new Dictionary<int, RoomData.Data>();
  92. string[] array = new string[]
  93. {
  94. "list"
  95. };
  96. KeyValuePair<AFileBase, CsvParser>[] array2 = new KeyValuePair<AFileBase, CsvParser>[array.Length];
  97. for (int i = 0; i < array2.Length; i++)
  98. {
  99. string text = "kasizuki_room_" + array[i] + ".nei";
  100. AFileBase afileBase = GameUty.FileSystem.FileOpen(text);
  101. CsvParser csvParser = new CsvParser();
  102. bool condition = csvParser.Open(afileBase);
  103. NDebug.Assert(condition, text + "\nopen failed.");
  104. array2[i] = new KeyValuePair<AFileBase, CsvParser>(afileBase, csvParser);
  105. }
  106. foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair in RoomData.commonIdManager.idMap)
  107. {
  108. int key = keyValuePair.Key;
  109. RoomData.Data value = new RoomData.Data(key, array2[0].Value);
  110. RoomData.basicDatas.Add(key, value);
  111. }
  112. foreach (KeyValuePair<AFileBase, CsvParser> keyValuePair2 in array2)
  113. {
  114. keyValuePair2.Value.Dispose();
  115. keyValuePair2.Key.Dispose();
  116. }
  117. }
  118. private const string csvTopCommonName = "kasizuki_room";
  119. private const string typeNameForErrorLog = "傅き.部屋データ";
  120. private static CsvCommonIdManager commonIdManager;
  121. private static Dictionary<int, RoomData.Data> basicDatas;
  122. public class Data
  123. {
  124. public Data(int uniqueID, CsvParser csv)
  125. {
  126. for (int i = 0; i < csv.max_cell_y; i++)
  127. {
  128. if (csv.IsCellToExistData(0, i) && csv.GetCellAsInteger(0, i) == uniqueID)
  129. {
  130. int num = 1;
  131. this.ID = uniqueID;
  132. this.uniqueName = csv.GetCellAsString(num++, i);
  133. this.isExistUpwardRoom = csv.IsCellToExistData(num, i);
  134. if (this.isExistUpwardRoom)
  135. {
  136. this.upwardRoomID = csv.GetCellAsInteger(num, i);
  137. }
  138. num++;
  139. this.facilityTypeID = csv.GetCellAsInteger(num++, i);
  140. this.facilityDefaultName = csv.GetCellAsString(num++, i);
  141. this.drawName = csv.GetCellAsString(num++, i);
  142. this.thumbnailName = csv.GetCellAsString(num++, i);
  143. this.explanatoryText = csv.GetCellAsString(num++, i);
  144. bool flag = FacilityDataTable.GetFacilityStatus(this.facilityTypeID, true) != null;
  145. bool flag2 = FacilityDataTable.GetFacilityTypeID(this.facilityDefaultName) != -1;
  146. if (!flag && !flag2)
  147. {
  148. Debug.LogWarning("表データ内の施設ID、施設名がどちらも正しくない");
  149. }
  150. else if (flag && !flag2)
  151. {
  152. Debug.LogWarning("表データ内の施設名が正しくない");
  153. this.facilityDefaultName = FacilityDataTable.GetFacilityStatus(this.facilityTypeID, true).name;
  154. }
  155. else if (!flag && flag2)
  156. {
  157. Debug.LogWarning("表データ内の施設IDが正しくない");
  158. this.facilityTypeID = FacilityDataTable.GetFacilityTypeID(this.facilityDefaultName);
  159. }
  160. string cellAsString = csv.GetCellAsString(num++, i);
  161. if (!string.IsNullOrEmpty(cellAsString))
  162. {
  163. try
  164. {
  165. string[] array = cellAsString.Split(new char[]
  166. {
  167. ','
  168. });
  169. for (int j = 0; j < array.Length; j++)
  170. {
  171. array[j] = array[j].Trim();
  172. }
  173. this.strConditionsArraySystemFlag = array;
  174. }
  175. catch (Exception ex)
  176. {
  177. NDebug.Assert(ex.ToString(), false);
  178. Debug.LogError(ex);
  179. }
  180. }
  181. Dictionary<ManDataType, bool> dictionary = new Dictionary<ManDataType, bool>();
  182. int count = ManData.Count;
  183. for (int k = 0; k < count; k++)
  184. {
  185. string cellAsString2 = csv.GetCellAsString(num, 0);
  186. ManDataType manType = ManData.GetData(cellAsString2).manType;
  187. dictionary.Add(manType, csv.GetCellAsString(num++, i) == "○");
  188. }
  189. this.enableManTypeDic = new ReadOnlyDictionary<ManDataType, bool>(dictionary);
  190. FacilityDataTable.FacilityDefaultData facilityDefaultData = FacilityDataTable.GetFacilityDefaultData(this.facilityTypeID, true);
  191. this.isEnableNTR = facilityDefaultData.isEnableNTR;
  192. this.isOnlyNTR = facilityDefaultData.isOnlyNTR;
  193. }
  194. }
  195. }
  196. public string drawNameTerm
  197. {
  198. get
  199. {
  200. return "SceneKasizukiMainMenu/部屋名/" + this.drawName;
  201. }
  202. }
  203. public string explanatoryTextTerm
  204. {
  205. get
  206. {
  207. return "SceneKasizukiMainMenu/部屋説明/" + this.drawName;
  208. }
  209. }
  210. public RoomData.Data GetUpwardRoomData()
  211. {
  212. if (this.isExistUpwardRoom)
  213. {
  214. if (RoomData.IsEnabled(this.upwardRoomID))
  215. {
  216. return RoomData.GetData(this.upwardRoomID);
  217. }
  218. string message = string.Concat(new object[]
  219. {
  220. "傅き.部屋データ\n部屋[",
  221. this.uniqueName,
  222. "]の上位ID[",
  223. this.upwardRoomID,
  224. "]のデータは存在しません"
  225. });
  226. NDebug.Assert(message, false);
  227. }
  228. return null;
  229. }
  230. public RoomData.Data GetSubordinateRoomData()
  231. {
  232. List<RoomData.Data> datas = RoomData.GetDatas((RoomData.Data data) => data.upwardRoomID == this.ID);
  233. RoomData.Data result = null;
  234. if (datas != null && datas.Count == 1)
  235. {
  236. result = datas[0];
  237. }
  238. return result;
  239. }
  240. public List<PlayData.Data> GetPlayDatas()
  241. {
  242. List<PlayData.Data> datas = PlayData.GetDatas((PlayData.Data playData) => playData.roomID == this.ID);
  243. RoomData.Data subordinateRoomData = this.GetSubordinateRoomData();
  244. if (subordinateRoomData != null)
  245. {
  246. foreach (PlayData.Data item in subordinateRoomData.GetPlayDatas())
  247. {
  248. if (!datas.Contains(item))
  249. {
  250. datas.Add(item);
  251. }
  252. }
  253. }
  254. return datas;
  255. }
  256. public bool IsExistFacility()
  257. {
  258. if (!FacilityDataTable.IsExistFacilityData(this.facilityTypeID, true))
  259. {
  260. string message = string.Concat(new object[]
  261. {
  262. "傅き.部屋データ\n部屋データ[",
  263. this.uniqueName,
  264. "]に対応する施設のID[",
  265. this.facilityTypeID,
  266. "は存在しない施設データです"
  267. });
  268. Debug.LogWarning(message);
  269. return false;
  270. }
  271. FacilityManager facilityMgr = GameMain.Instance.FacilityMgr;
  272. if (facilityMgr == null)
  273. {
  274. string message2 = "施設マネージャクラスが見つかりませんでした";
  275. Debug.LogWarning(message2);
  276. return false;
  277. }
  278. return facilityMgr.IsExistTypeFacility(this.facilityTypeID);
  279. }
  280. public readonly int ID;
  281. public readonly string uniqueName;
  282. public readonly int upwardRoomID;
  283. public readonly int facilityTypeID;
  284. public readonly string facilityDefaultName;
  285. public readonly string drawName;
  286. public readonly string thumbnailName;
  287. public readonly string explanatoryText;
  288. public readonly string[] strConditionsArraySystemFlag;
  289. public readonly ReadOnlyDictionary<ManDataType, bool> enableManTypeDic;
  290. public readonly bool isExistUpwardRoom;
  291. public readonly bool isEnableNTR;
  292. public readonly bool isOnlyNTR;
  293. }
  294. }
  295. }