RoomData.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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 num2 = Enum.GetNames(typeof(ManDataType)).Length;
  183. for (int k = 0; k < num2; 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 RoomData.Data GetUpwardRoomData()
  197. {
  198. if (this.isExistUpwardRoom)
  199. {
  200. if (RoomData.IsEnabled(this.upwardRoomID))
  201. {
  202. return RoomData.GetData(this.upwardRoomID);
  203. }
  204. string message = string.Concat(new object[]
  205. {
  206. "傅き.部屋データ\n部屋[",
  207. this.uniqueName,
  208. "]の上位ID[",
  209. this.upwardRoomID,
  210. "]のデータは存在しません"
  211. });
  212. NDebug.Assert(message, false);
  213. }
  214. return null;
  215. }
  216. public RoomData.Data GetSubordinateRoomData()
  217. {
  218. List<RoomData.Data> datas = RoomData.GetDatas((RoomData.Data data) => data.upwardRoomID == this.ID);
  219. RoomData.Data result = null;
  220. if (datas != null && datas.Count == 1)
  221. {
  222. result = datas[0];
  223. }
  224. return result;
  225. }
  226. public List<PlayData.Data> GetPlayDatas()
  227. {
  228. List<PlayData.Data> datas = PlayData.GetDatas((PlayData.Data playData) => playData.roomID == this.ID);
  229. RoomData.Data subordinateRoomData = this.GetSubordinateRoomData();
  230. if (subordinateRoomData != null)
  231. {
  232. foreach (PlayData.Data item in subordinateRoomData.GetPlayDatas())
  233. {
  234. if (!datas.Contains(item))
  235. {
  236. datas.Add(item);
  237. }
  238. }
  239. }
  240. return datas;
  241. }
  242. public bool IsExistFacility()
  243. {
  244. if (!FacilityDataTable.IsExistFacilityData(this.facilityTypeID, true))
  245. {
  246. string message = string.Concat(new object[]
  247. {
  248. "傅き.部屋データ\n部屋データ[",
  249. this.uniqueName,
  250. "]に対応する施設のID[",
  251. this.facilityTypeID,
  252. "は存在しない施設データです"
  253. });
  254. Debug.LogWarning(message);
  255. return false;
  256. }
  257. FacilityManager facilityMgr = GameMain.Instance.FacilityMgr;
  258. if (facilityMgr == null)
  259. {
  260. string message2 = "施設マネージャクラスが見つかりませんでした";
  261. Debug.LogWarning(message2);
  262. return false;
  263. }
  264. return facilityMgr.IsExistTypeFacility(this.facilityTypeID);
  265. }
  266. public readonly int ID;
  267. public readonly string uniqueName;
  268. public readonly int upwardRoomID;
  269. public readonly int facilityTypeID;
  270. public readonly string facilityDefaultName;
  271. public readonly string drawName;
  272. public readonly string thumbnailName;
  273. public readonly string explanatoryText;
  274. public readonly string[] strConditionsArraySystemFlag;
  275. public readonly ReadOnlyDictionary<ManDataType, bool> enableManTypeDic;
  276. public readonly bool isExistUpwardRoom;
  277. public readonly bool isEnableNTR;
  278. public readonly bool isOnlyNTR;
  279. }
  280. }
  281. }