FacilityManager.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Diagnostics;
  5. using System.IO;
  6. using System.Runtime.CompilerServices;
  7. using FacilityFlag;
  8. using UnityEngine;
  9. public class FacilityManager : MonoBehaviour
  10. {
  11. public int NowBusinessTypeID
  12. {
  13. get
  14. {
  15. return this.m_NowBusinessTypeID;
  16. }
  17. set
  18. {
  19. this.m_NowBusinessTypeID = value;
  20. }
  21. }
  22. public int NextDayBusinessTypeID
  23. {
  24. get
  25. {
  26. return this.m_NextDayBusinessTypeID;
  27. }
  28. set
  29. {
  30. this.m_NextDayBusinessTypeID = value;
  31. }
  32. }
  33. public Facility tempSelectFacility
  34. {
  35. get
  36. {
  37. return this.m_TempSelectingFacility;
  38. }
  39. set
  40. {
  41. this.m_TempSelectingFacility = value;
  42. }
  43. }
  44. private GameObject parentFacility
  45. {
  46. get
  47. {
  48. return this.m_ParentFacility;
  49. }
  50. }
  51. private GameObject parentNowFacility
  52. {
  53. get
  54. {
  55. if (this.m_ParentNowFacility == null)
  56. {
  57. this.m_ParentNowFacility = new GameObject("Parent Now Facility");
  58. this.m_ParentNowFacility.transform.SetParent(this.parentFacility.transform, false);
  59. }
  60. return this.m_ParentNowFacility;
  61. }
  62. }
  63. private GameObject parentNextDayFacility
  64. {
  65. get
  66. {
  67. if (this.m_ParentNextDayFacility == null)
  68. {
  69. this.m_ParentNextDayFacility = new GameObject("Parent Next Day Facility");
  70. this.m_ParentNextDayFacility.transform.SetParent(this.parentFacility.transform, false);
  71. }
  72. return this.m_ParentNextDayFacility;
  73. }
  74. }
  75. public void Init(GameMain gameMain)
  76. {
  77. if (this.m_ParentFacility == null)
  78. {
  79. this.m_ParentFacility = new GameObject("Facility");
  80. this.m_ParentFacility.transform.SetParent(gameMain.transform, false);
  81. }
  82. FacilityDataTable.Init();
  83. this.ResetData();
  84. this.SetUpFixedFacilityArray();
  85. }
  86. private void SetUpFixedFacilityArray()
  87. {
  88. Facility.FacilityStatus[] facilityStatusArray = FacilityDataTable.GetFacilityStatusArray(true);
  89. for (int i = 0; i < facilityStatusArray.Length; i++)
  90. {
  91. int typeID = facilityStatusArray[i].typeID;
  92. if (FacilityDataTable.GetFacilityDefaultPlacement(typeID, true))
  93. {
  94. this.AddNewFacility(typeID);
  95. }
  96. }
  97. int[] facilityBusinessTypeIDArray = FacilityDataTable.GetFacilityBusinessTypeIDArray(true);
  98. foreach (int num in facilityBusinessTypeIDArray)
  99. {
  100. if (this.IsExistBusinessTypeFacility(num))
  101. {
  102. this.m_NowBusinessTypeID = num;
  103. break;
  104. }
  105. }
  106. }
  107. public int GetEmptySlot()
  108. {
  109. bool flag = false;
  110. int i;
  111. for (i = 0; i < this.FacilityCountMax; i++)
  112. {
  113. if (this.m_FacilityArray.Count < i || !this.m_FacilityArray[i])
  114. {
  115. flag = true;
  116. break;
  117. }
  118. }
  119. if (flag)
  120. {
  121. return i;
  122. }
  123. return -1;
  124. }
  125. public Facility[] GetFacilityArray()
  126. {
  127. return this.m_FacilityArray.ToArray();
  128. }
  129. public Facility GetFacility(int index)
  130. {
  131. if (this.m_FacilityArray.Count <= index)
  132. {
  133. return null;
  134. }
  135. if (index < 0)
  136. {
  137. return null;
  138. }
  139. return this.m_FacilityArray[index];
  140. }
  141. public bool GetFacilityExist(int index)
  142. {
  143. return index >= 0 && this.m_FacilityArray.Count > index && this.m_FacilityArray[index] != null;
  144. }
  145. public int GetFacilityIndex(Facility facility)
  146. {
  147. if (facility == null)
  148. {
  149. UnityEngine.Debug.LogError("[FacilityManager]引数にnullが指定されました");
  150. return -1;
  151. }
  152. if (this.m_FacilityArray.Contains(facility))
  153. {
  154. return this.m_FacilityArray.IndexOf(facility);
  155. }
  156. if (this.m_NextDayFacilityArray.ContainsValue(facility))
  157. {
  158. List<int> list = new List<int>(this.m_NextDayFacilityArray.Keys);
  159. List<Facility> list2 = new List<Facility>(this.m_NextDayFacilityArray.Values);
  160. return list[list2.IndexOf(facility)];
  161. }
  162. UnityEngine.Debug.Log(string.Format("[FacilityManager]施設『{0}』は施設マネージャクラスの管理外です", facility.facilityName));
  163. return -1;
  164. }
  165. public bool GetFacilityPowerUpItemEnable(int materialID)
  166. {
  167. if (this.m_PowerUpMaterialArray == null)
  168. {
  169. UnityEngine.Debug.LogError("[FacilityManager]強化素材の配列が未初期化状態です");
  170. return false;
  171. }
  172. return this.m_PowerUpMaterialArray.Get(materialID, false);
  173. }
  174. public Facility.PowerUpMaterial[] GetFacilityPowerUpItemEnableArray(int materialCategoryID)
  175. {
  176. Facility.PowerUpMaterial[] facilityPowerUpMaterialArray = FacilityDataTable.GetFacilityPowerUpMaterialArray(materialCategoryID);
  177. List<Facility.PowerUpMaterial> list = new List<Facility.PowerUpMaterial>();
  178. for (int i = 0; i < facilityPowerUpMaterialArray.Length; i++)
  179. {
  180. if (this.GetFacilityPowerUpItemEnable(facilityPowerUpMaterialArray[i].id))
  181. {
  182. list.Add(facilityPowerUpMaterialArray[i]);
  183. }
  184. }
  185. return list.ToArray();
  186. }
  187. public bool AddNewFacility(int facilityTypeID)
  188. {
  189. int emptySlot = this.GetEmptySlot();
  190. if (emptySlot < 0)
  191. {
  192. UnityEngine.Debug.Log(string.Format("[FacilityManager]施設は{0}個よりも多くは作れません", this.FacilityCountMax));
  193. return false;
  194. }
  195. Facility facility = this.CreateNewFacility(facilityTypeID);
  196. this.SetFacility(emptySlot, facility);
  197. return true;
  198. }
  199. public Facility CreateNewFacility(int facilityTypeID)
  200. {
  201. GameObject gameObject = new GameObject("Facility");
  202. Facility facility = gameObject.AddComponent<Facility>();
  203. facility.Init(facilityTypeID);
  204. gameObject.transform.SetParent(this.parentNowFacility.transform, false);
  205. return facility;
  206. }
  207. public Facility CreateNewFacility()
  208. {
  209. GameObject gameObject = new GameObject("Facility");
  210. Facility facility = gameObject.AddComponent<Facility>();
  211. facility.Init(FacilityDataTable.GetFacilityTypeID("劇場"));
  212. gameObject.transform.SetParent(this.parentNowFacility.transform, false);
  213. return facility;
  214. }
  215. public bool AddFacility(Facility facility)
  216. {
  217. int emptySlot = this.GetEmptySlot();
  218. if (emptySlot < 0)
  219. {
  220. UnityEngine.Debug.Log(string.Format("[FacilityManager]施設は{0}個よりも多くは作れません", this.FacilityCountMax));
  221. return false;
  222. }
  223. this.SetFacility(emptySlot, facility);
  224. return true;
  225. }
  226. public bool SetFacility(int index, Facility facility)
  227. {
  228. if (this.m_FacilityArray.Count <= index || index < 0)
  229. {
  230. UnityEngine.Debug.LogError(string.Format("[FacilityManager]施設の管理インデックスの値が不正です\n指定された値:{0}", index));
  231. return false;
  232. }
  233. if (facility != null && this.m_FacilityArray.Contains(facility))
  234. {
  235. UnityEngine.Debug.LogError(string.Format("[FacilityManager]施設「{0}」は既にマネージャクラスで管理されています", facility.facilityName));
  236. return false;
  237. }
  238. Facility facility2 = this.m_FacilityArray[index];
  239. if (facility2)
  240. {
  241. UnityEngine.Debug.Log(string.Format("[FacilityManager]管理している施設を置き換えた\n[{0}]番目:「{1}」から「{2}」へ", index, facility2.facilityName, (!facility) ? "空き部屋" : facility.facilityName));
  242. this.DestroyFacility(facility2);
  243. }
  244. this.m_FacilityArray[index] = facility;
  245. if (facility)
  246. {
  247. facility.gameObject.transform.SetParent(this.parentNowFacility.transform, false);
  248. int typeID = facility.param.typeID;
  249. int num = (!this.m_FacilityBuildCount.Contains(typeID)) ? 0 : this.m_FacilityBuildCount.Get(typeID, false);
  250. this.m_FacilityBuildCount.Add(typeID, num + 1, true);
  251. }
  252. return true;
  253. }
  254. public bool DestroyFacility(int index)
  255. {
  256. if (this.GetFacility(index) == null)
  257. {
  258. UnityEngine.Debug.Log(string.Format("[FacilityManager]施設の管理インデックス[{0}]番の施設は存在しない", index));
  259. return false;
  260. }
  261. Facility facility = this.m_FacilityArray[index];
  262. this.m_FacilityArray[index] = null;
  263. UnityEngine.Object.Destroy(facility.gameObject);
  264. return true;
  265. }
  266. public bool DestroyFacility(Facility facility)
  267. {
  268. if (facility == null)
  269. {
  270. UnityEngine.Debug.LogError("[FacilityManager]削除したい施設としてnullが指定されました");
  271. return false;
  272. }
  273. string facilityName = facility.facilityName;
  274. if (!this.m_FacilityArray.Contains(facility))
  275. {
  276. UnityEngine.Debug.Log(string.Format("[FacilityManager]施設『{0}』は施設マネージャクラスの管理外です", facilityName));
  277. return false;
  278. }
  279. int facilityIndex = this.GetFacilityIndex(facility);
  280. this.m_FacilityArray[facilityIndex] = null;
  281. UnityEngine.Object.Destroy(facility.gameObject);
  282. UnityEngine.Debug.Log(string.Format("[FacilityManager]施設『{0}』の削除に成功", facilityName));
  283. return true;
  284. }
  285. public void SetHavePowerUpMaterial(int materialID, bool isHave = true)
  286. {
  287. if (this.m_PowerUpMaterialArray == null)
  288. {
  289. UnityEngine.Debug.LogError("[FacilityManager]強化素材配列が未初期化状態です");
  290. return;
  291. }
  292. if (!this.m_PowerUpMaterialArray.Contains(materialID))
  293. {
  294. UnityEngine.Debug.Log(string.Format("[FacilityManager]強化素材ID[{0}]番は存在しない情報です", materialID));
  295. return;
  296. }
  297. this.m_PowerUpMaterialArray.Add(materialID, isHave, true);
  298. }
  299. public int GetFacilityLevel(int facilityTypeID)
  300. {
  301. if (this.m_FacilityExpArray == null)
  302. {
  303. UnityEngine.Debug.LogError("[FacilityManager]施設の種類ごとの施設レベル配列が未初期化です");
  304. return -1;
  305. }
  306. if (!this.m_FacilityExpArray.Contains(facilityTypeID))
  307. {
  308. UnityEngine.Debug.LogWarningFormat("[FacilityManager]施設の種類ID[{0}]番に対応する施設レベル情報がありません", new object[]
  309. {
  310. facilityTypeID
  311. });
  312. return -1;
  313. }
  314. return this.m_FacilityExpArray.Get(facilityTypeID, false).GetCurrentLevel();
  315. }
  316. public SimpleExperienceSystem GetFacilityExpSystem(int facilityTypeID)
  317. {
  318. if (this.m_FacilityExpArray == null)
  319. {
  320. UnityEngine.Debug.LogError("[FacilityManager]施設の種類ごとの施設レベル配列が未初期化です");
  321. return null;
  322. }
  323. if (!this.m_FacilityExpArray.Contains(facilityTypeID))
  324. {
  325. UnityEngine.Debug.LogWarningFormat("[FacilityManager]施設の種類ID[{0}]番に対応する施設レベル情報がありません", new object[]
  326. {
  327. facilityTypeID
  328. });
  329. return null;
  330. }
  331. return this.m_FacilityExpArray.Get(facilityTypeID, false);
  332. }
  333. public Dictionary<int, Facility> GetNextDayFacilityArray()
  334. {
  335. return this.m_NextDayFacilityArray;
  336. }
  337. public Facility GetNextDayFacility(int nowFacilityIndex)
  338. {
  339. if (!this.GetNextDayFacilityExist(nowFacilityIndex))
  340. {
  341. return null;
  342. }
  343. return this.m_NextDayFacilityArray[nowFacilityIndex];
  344. }
  345. public Facility GetNextDayFacility(Facility nowFacility)
  346. {
  347. int facilityIndex = this.GetFacilityIndex(nowFacility);
  348. if (!this.GetNextDayFacilityExist(facilityIndex))
  349. {
  350. UnityEngine.Debug.Log(string.Format("[FacilityManager]次の日に設置する施設の情報が存在しない\n管理インデックス:[{0}]", facilityIndex));
  351. return null;
  352. }
  353. return this.m_NextDayFacilityArray[facilityIndex];
  354. }
  355. public bool GetNextDayFacilityExist(int nowFacilityIndex)
  356. {
  357. return this.m_NextDayFacilityArray.ContainsKey(nowFacilityIndex);
  358. }
  359. public bool GetNextDayFacilityExist(Facility nowFacility)
  360. {
  361. int facilityIndex = this.GetFacilityIndex(nowFacility);
  362. return this.m_NextDayFacilityArray.ContainsKey(facilityIndex);
  363. }
  364. public void SetNextDayFacility(int index, Facility nextDayFacility)
  365. {
  366. if (this.m_NextDayFacilityArray.ContainsKey(index))
  367. {
  368. this.m_NextDayFacilityArray[index] = nextDayFacility;
  369. UnityEngine.Debug.Log(string.Format("[FacilityManager]次の日の施設情報を上書きした\n[{0}]番目:{1}", index, (!nextDayFacility) ? "空き部屋" : nextDayFacility.facilityName));
  370. return;
  371. }
  372. this.m_NextDayFacilityArray.Add(index, nextDayFacility);
  373. UnityEngine.Debug.Log(string.Format("[FacilityManager]次の日の施設情報を追加した\n[{0}]番目:{1}", index, (!nextDayFacility) ? "空き部屋" : nextDayFacility.facilityName));
  374. if (nextDayFacility != null)
  375. {
  376. nextDayFacility.transform.SetParent(this.parentNextDayFacility.transform, false);
  377. }
  378. }
  379. public void RemoveNextDayFacility(int index)
  380. {
  381. if (!this.m_NextDayFacilityArray.ContainsKey(index))
  382. {
  383. UnityEngine.Debug.Log(string.Format("[FacilityManager]キーの値[{0}]のノードは存在しない", index));
  384. return;
  385. }
  386. this.m_NextDayFacilityArray.Remove(index);
  387. }
  388. public void ClearNextDayFacilityArray()
  389. {
  390. List<Facility> list = new List<Facility>(this.m_NextDayFacilityArray.Values);
  391. for (int i = 0; i < list.Count; i++)
  392. {
  393. if (list[i])
  394. {
  395. UnityEngine.Object.Destroy(list[i].gameObject);
  396. }
  397. }
  398. this.m_NextDayFacilityArray.Clear();
  399. }
  400. private void UpdateNextDayFacility()
  401. {
  402. CharacterMgr characterMgr = null;
  403. if (GameMain.Instance != null && GameMain.Instance.CharacterMgr != null)
  404. {
  405. characterMgr = GameMain.Instance.CharacterMgr;
  406. }
  407. Dictionary<int, Facility> nextDayFacilityArray = this.GetNextDayFacilityArray();
  408. int count = nextDayFacilityArray.Count;
  409. List<int> list = new List<int>(nextDayFacilityArray.Keys);
  410. List<Facility> list2 = new List<Facility>(nextDayFacilityArray.Values);
  411. for (int i = 0; i < count; i++)
  412. {
  413. int num = 0;
  414. if (list2[i] != null)
  415. {
  416. num = list2[i].defaultData.cost;
  417. }
  418. if (characterMgr != null && characterMgr.status.money - (long)num >= 0L)
  419. {
  420. characterMgr.status.money -= (long)num;
  421. this.RemoveNextDayFacility(list[i]);
  422. this.SetFacility(list[i], list2[i]);
  423. }
  424. else
  425. {
  426. this.RemoveNextDayFacility(list[i]);
  427. UnityEngine.Object.Destroy(list2[i].gameObject);
  428. }
  429. }
  430. }
  431. public void UpdateNextDay()
  432. {
  433. this.UpdateNextDayFacility();
  434. if (this.m_NowBusinessTypeID != this.m_NextDayBusinessTypeID && FacilityDataTable.IsExistFacilityBusinessTypeData(this.m_NextDayBusinessTypeID))
  435. {
  436. this.m_NowBusinessTypeID = this.m_NextDayBusinessTypeID;
  437. }
  438. int num = 0;
  439. foreach (Facility x in this.GetFacilityArray())
  440. {
  441. if (x != null)
  442. {
  443. num++;
  444. }
  445. }
  446. int facilityAchievement = this.GetFacilityAchievement<int>("施設総数");
  447. if (facilityAchievement < num)
  448. {
  449. this.SetFacilityAchievement("施設総数", num.ToString());
  450. }
  451. }
  452. public bool IsExistBusinessTypeFacility(int businessTypeID)
  453. {
  454. Facility[] array = this.m_FacilityArray.ToArray();
  455. foreach (Facility facility in array)
  456. {
  457. if (!(facility == null))
  458. {
  459. if (facility.defaultData.businessTypeID == businessTypeID)
  460. {
  461. return true;
  462. }
  463. }
  464. }
  465. return false;
  466. }
  467. public bool IsExistBusinessTypeFacility(FacilityDataTable.BusinessTypeData businessData)
  468. {
  469. return this.IsExistBusinessTypeFacility(businessData.ID);
  470. }
  471. public bool IsExistBusinessTypeFacility(string businessName)
  472. {
  473. return this.IsExistBusinessTypeFacility(FacilityDataTable.GetFacilityBusinessTypeData(businessName).ID);
  474. }
  475. public bool IsExistTypeFacility(int facilityTypeID)
  476. {
  477. Facility[] array = this.m_FacilityArray.ToArray();
  478. foreach (Facility facility in array)
  479. {
  480. if (!(facility == null))
  481. {
  482. if (facility.param.typeID == facilityTypeID)
  483. {
  484. return true;
  485. }
  486. }
  487. }
  488. return false;
  489. }
  490. public bool IsExistTypeFacility(int facilityTypeID, out Facility[] matchingFacilityArray)
  491. {
  492. Facility[] array = this.m_FacilityArray.ToArray();
  493. List<Facility> list = new List<Facility>();
  494. foreach (Facility facility in array)
  495. {
  496. if (!(facility == null))
  497. {
  498. if (facility.param.typeID == facilityTypeID)
  499. {
  500. list.Add(facility);
  501. }
  502. }
  503. }
  504. matchingFacilityArray = list.ToArray();
  505. return matchingFacilityArray.Length > 0;
  506. }
  507. public bool IsExistTypeFacilityInOperation(int facilityTypeID)
  508. {
  509. Facility[] array = this.m_FacilityArray.ToArray();
  510. foreach (Facility facility in array)
  511. {
  512. if (!(facility == null))
  513. {
  514. if (facility.isOperationDayTime && facility.param.typeID == facilityTypeID)
  515. {
  516. return true;
  517. }
  518. }
  519. }
  520. return false;
  521. }
  522. public bool IsExistTypeFacilityInOperation(int facilityTypeID, out Facility[] matchingFacilityArray)
  523. {
  524. Facility[] array = this.m_FacilityArray.ToArray();
  525. List<Facility> list = new List<Facility>();
  526. foreach (Facility facility in array)
  527. {
  528. if (!(facility == null))
  529. {
  530. if (facility.isOperationDayTime && facility.param.typeID == facilityTypeID)
  531. {
  532. list.Add(facility);
  533. }
  534. }
  535. }
  536. matchingFacilityArray = list.ToArray();
  537. return matchingFacilityArray.Length > 0;
  538. }
  539. public bool IsFacilityBuildFlag(int facilityTypeID)
  540. {
  541. return this.m_FacilityBuildCount.Contains(facilityTypeID) && this.m_FacilityBuildCount.Get(facilityTypeID, false) > 0;
  542. }
  543. public Facility GetMaidAssignedFacility(Maid maid, ScheduleMgr.ScheduleTime scheduleTime)
  544. {
  545. for (int i = 0; i < this.m_FacilityArray.Count; i++)
  546. {
  547. if (!(this.m_FacilityArray[i] == null))
  548. {
  549. if (this.m_FacilityArray[i].IsAllocationMaid(maid, scheduleTime))
  550. {
  551. return this.m_FacilityArray[i];
  552. }
  553. }
  554. }
  555. return null;
  556. }
  557. public void UpdateFacilityAssignedMaidData()
  558. {
  559. for (int i = 0; i < this.m_FacilityArray.Count; i++)
  560. {
  561. if (!(this.m_FacilityArray[i] == null))
  562. {
  563. this.m_FacilityArray[i].UpdateAllocationMaidList();
  564. }
  565. }
  566. }
  567. public void AddCacheFacilityPowewrUpResult(Maid maid, Facility facility, Facility.RecipeData recipe)
  568. {
  569. if (maid == null)
  570. {
  571. NDebug.Assert("メイドにnullが指定されました", false);
  572. }
  573. if (this.m_CacheFacilityPowerUpResult.ContainsKey(maid.status.guid))
  574. {
  575. UnityEngine.Debug.LogWarningFormat("メイド「{0}」の情報は既にキャッシュしています", new object[]
  576. {
  577. maid
  578. });
  579. return;
  580. }
  581. this.m_CacheFacilityPowerUpResult.Add(maid.status.guid, new KeyValuePair<Facility, Facility.RecipeData>(facility, recipe));
  582. }
  583. public bool IsExistCacheFacilityPowerUpResult(Maid maid)
  584. {
  585. NDebug.Assert(maid != null, "メイドにnullが指定されました");
  586. return this.m_CacheFacilityPowerUpResult.ContainsKey(maid.status.guid);
  587. }
  588. public bool TryGetCacheFacilityPowerUpResult(Maid maid, out Facility facility, out Facility.RecipeData recipe)
  589. {
  590. facility = null;
  591. recipe = null;
  592. if (!this.IsExistCacheFacilityPowerUpResult(maid))
  593. {
  594. return false;
  595. }
  596. KeyValuePair<Facility, Facility.RecipeData> keyValuePair = this.m_CacheFacilityPowerUpResult[maid.status.guid];
  597. facility = keyValuePair.Key;
  598. recipe = keyValuePair.Value;
  599. return true;
  600. }
  601. public void ClearCacheFacilityPowerUpResult()
  602. {
  603. this.m_CacheFacilityPowerUpResult.Clear();
  604. }
  605. public bool Serialize(BinaryWriter brWrite)
  606. {
  607. Stopwatch stopwatch = new Stopwatch();
  608. stopwatch.Start();
  609. brWrite.Write("CM3D21_FACILITY_MGR");
  610. brWrite.Write(1270);
  611. brWrite.Write("5");
  612. int num = 0;
  613. for (int i = 0; i < this.m_FacilityArray.Count; i++)
  614. {
  615. if (this.m_FacilityArray[i])
  616. {
  617. num++;
  618. }
  619. }
  620. brWrite.Write(num);
  621. for (int j = 0; j < this.m_FacilityArray.Count; j++)
  622. {
  623. if (this.m_FacilityArray[j])
  624. {
  625. brWrite.Write(j);
  626. this.m_FacilityArray[j].Serialize(brWrite);
  627. }
  628. }
  629. DataArray<int, bool> powerUpMaterialArray = this.m_PowerUpMaterialArray;
  630. if (FacilityManager.<>f__mg$cache0 == null)
  631. {
  632. FacilityManager.<>f__mg$cache0 = new Converter<int, byte[]>(Util.GetBytes);
  633. }
  634. Converter<int, byte[]> converter_key = FacilityManager.<>f__mg$cache0;
  635. if (FacilityManager.<>f__mg$cache1 == null)
  636. {
  637. FacilityManager.<>f__mg$cache1 = new Converter<bool, byte[]>(Util.GetBytes);
  638. }
  639. powerUpMaterialArray.Serialize(brWrite, converter_key, FacilityManager.<>f__mg$cache1);
  640. int count = this.m_NextDayFacilityArray.Count;
  641. brWrite.Write(count);
  642. for (int k = 0; k < this.m_FacilityArray.Count; k++)
  643. {
  644. if (this.GetNextDayFacilityExist(k))
  645. {
  646. Facility nextDayFacility = this.GetNextDayFacility(k);
  647. if (nextDayFacility)
  648. {
  649. brWrite.Write(k);
  650. brWrite.Write(true);
  651. nextDayFacility.Serialize(brWrite);
  652. }
  653. else
  654. {
  655. brWrite.Write(k);
  656. brWrite.Write(false);
  657. }
  658. }
  659. }
  660. DataArray<int, SimpleExperienceSystem> facilityExpArray = this.m_FacilityExpArray;
  661. if (FacilityManager.<>f__mg$cache2 == null)
  662. {
  663. FacilityManager.<>f__mg$cache2 = new Converter<int, byte[]>(Util.GetBytes);
  664. }
  665. Converter<int, byte[]> converter_key2 = FacilityManager.<>f__mg$cache2;
  666. if (FacilityManager.<>f__mg$cache3 == null)
  667. {
  668. FacilityManager.<>f__mg$cache3 = new Converter<SimpleExperienceSystem, byte[]>(Util.GetBytes);
  669. }
  670. facilityExpArray.Serialize(brWrite, converter_key2, FacilityManager.<>f__mg$cache3);
  671. DataArray<int, int> facilityBuildCount = this.m_FacilityBuildCount;
  672. if (FacilityManager.<>f__mg$cache4 == null)
  673. {
  674. FacilityManager.<>f__mg$cache4 = new Converter<int, byte[]>(Util.GetBytes);
  675. }
  676. Converter<int, byte[]> converter_key3 = FacilityManager.<>f__mg$cache4;
  677. if (FacilityManager.<>f__mg$cache5 == null)
  678. {
  679. FacilityManager.<>f__mg$cache5 = new Converter<int, byte[]>(Util.GetBytes);
  680. }
  681. facilityBuildCount.Serialize(brWrite, converter_key3, FacilityManager.<>f__mg$cache5);
  682. DataArray<string, string> facilityAchievementList = this.m_FacilityAchievementList;
  683. if (FacilityManager.<>f__mg$cache6 == null)
  684. {
  685. FacilityManager.<>f__mg$cache6 = new Converter<string, byte[]>(Util.GetBytes);
  686. }
  687. Converter<string, byte[]> converter_key4 = FacilityManager.<>f__mg$cache6;
  688. if (FacilityManager.<>f__mg$cache7 == null)
  689. {
  690. FacilityManager.<>f__mg$cache7 = new Converter<string, byte[]>(Util.GetBytes);
  691. }
  692. facilityAchievementList.Serialize(brWrite, converter_key4, FacilityManager.<>f__mg$cache7);
  693. stopwatch.Stop();
  694. return true;
  695. }
  696. public bool Deserialize(BinaryReader brRead)
  697. {
  698. Stopwatch stopwatch = new Stopwatch();
  699. stopwatch.Start();
  700. this.ResetData();
  701. if (brRead.BaseStream.Length <= brRead.BaseStream.Position + 1L)
  702. {
  703. this.SetUpFixedFacilityArray();
  704. return false;
  705. }
  706. long position = brRead.BaseStream.Position;
  707. string text = brRead.ReadString();
  708. if (text != "CM3D21_FACILITY_MGR")
  709. {
  710. NDebug.Warning("セーブデータファイルのヘッダーが不正です。FACILITY_MGR\n" + text);
  711. brRead.BaseStream.Seek(position, SeekOrigin.Begin);
  712. return false;
  713. }
  714. int num = brRead.ReadInt32();
  715. position = brRead.BaseStream.Position;
  716. string text2 = brRead.ReadString();
  717. int num2;
  718. if (string.IsNullOrEmpty(text2))
  719. {
  720. num2 = 0;
  721. brRead.BaseStream.Seek(position, SeekOrigin.Begin);
  722. }
  723. else
  724. {
  725. int num3 = 0;
  726. if (int.TryParse(text2, out num3) && num3 > 0 && 10 > num3)
  727. {
  728. num2 = num3;
  729. }
  730. else
  731. {
  732. num2 = 0;
  733. brRead.BaseStream.Seek(position, SeekOrigin.Begin);
  734. }
  735. }
  736. int num4 = brRead.ReadInt32();
  737. for (int i = 0; i < num4; i++)
  738. {
  739. int index3 = brRead.ReadInt32();
  740. Facility facility = this.CreateNewFacility();
  741. if (facility.Deserialize(brRead, num2))
  742. {
  743. this.m_FacilityArray[index3] = facility;
  744. }
  745. else
  746. {
  747. UnityEngine.Object.Destroy(facility);
  748. }
  749. }
  750. DataArray<int, bool> dataArray = new DataArray<int, bool>();
  751. DataArray<int, bool> dataArray2 = dataArray;
  752. if (FacilityManager.<>f__mg$cache8 == null)
  753. {
  754. FacilityManager.<>f__mg$cache8 = new Func<BinaryReader, int>(Util.ToInt32);
  755. }
  756. Func<BinaryReader, int> func_read_key = FacilityManager.<>f__mg$cache8;
  757. if (FacilityManager.<>f__mg$cache9 == null)
  758. {
  759. FacilityManager.<>f__mg$cache9 = new Func<BinaryReader, bool>(Util.ToBoolean);
  760. }
  761. dataArray2.Deserialize(brRead, func_read_key, FacilityManager.<>f__mg$cache9);
  762. dataArray.Loop(delegate(int index, int key, bool value)
  763. {
  764. this.m_PowerUpMaterialArray.Add(key, value, true);
  765. });
  766. int num5 = brRead.ReadInt32();
  767. for (int j = 0; j < num5; j++)
  768. {
  769. int index2 = brRead.ReadInt32();
  770. bool flag = brRead.ReadBoolean();
  771. bool flag2 = false;
  772. Facility facility2 = null;
  773. if (flag)
  774. {
  775. facility2 = this.CreateNewFacility();
  776. flag2 = facility2.Deserialize(brRead, num2);
  777. }
  778. if (flag2)
  779. {
  780. this.SetNextDayFacility(index2, facility2);
  781. }
  782. else
  783. {
  784. UnityEngine.Object.Destroy(facility2);
  785. }
  786. }
  787. if (num2 > 1)
  788. {
  789. DataArray<int, SimpleExperienceSystem> array = new DataArray<int, SimpleExperienceSystem>();
  790. DataArray<int, SimpleExperienceSystem> array2 = array;
  791. if (FacilityManager.<>f__mg$cacheA == null)
  792. {
  793. FacilityManager.<>f__mg$cacheA = new Func<BinaryReader, int>(Util.ToInt32);
  794. }
  795. Func<BinaryReader, int> func_read_key2 = FacilityManager.<>f__mg$cacheA;
  796. if (FacilityManager.<>f__mg$cacheB == null)
  797. {
  798. FacilityManager.<>f__mg$cacheB = new Func<BinaryReader, SimpleExperienceSystem>(Util.ToSimpleExp);
  799. }
  800. array2.Deserialize(brRead, func_read_key2, FacilityManager.<>f__mg$cacheB);
  801. array.Loop(delegate(int index, int key, SimpleExperienceSystem value)
  802. {
  803. FacilityDataTable.FacilityDefaultData facilityDefaultData = FacilityDataTable.GetFacilityDefaultData(key, true);
  804. if (facilityDefaultData != null)
  805. {
  806. value.SetExreienceList(facilityDefaultData.levelTable);
  807. }
  808. else
  809. {
  810. string message = string.Format("施設Expテーブル:施設ID[{0}]のデータは存在しません", key);
  811. UnityEngine.Debug.LogWarning(message);
  812. }
  813. });
  814. this.m_FacilityExpArray.Loop(delegate(int index, int id, SimpleExperienceSystem exp)
  815. {
  816. if (array.Contains(id))
  817. {
  818. this.m_FacilityExpArray.Add(id, array.Get(id, false), true);
  819. }
  820. });
  821. }
  822. else
  823. {
  824. if (FacilityManager.<>f__mg$cacheC == null)
  825. {
  826. FacilityManager.<>f__mg$cacheC = new Func<BinaryReader, int>(Util.ToInt32);
  827. }
  828. Func<BinaryReader, int> func_read_key3 = FacilityManager.<>f__mg$cacheC;
  829. if (FacilityManager.<>f__mg$cacheD == null)
  830. {
  831. FacilityManager.<>f__mg$cacheD = new Func<BinaryReader, int>(Util.ToInt32);
  832. }
  833. DataArray<int, int>.Skip(brRead, func_read_key3, FacilityManager.<>f__mg$cacheD);
  834. }
  835. DataArray<int, int> facilityBuildCount = this.m_FacilityBuildCount;
  836. if (FacilityManager.<>f__mg$cacheE == null)
  837. {
  838. FacilityManager.<>f__mg$cacheE = new Func<BinaryReader, int>(Util.ToInt32);
  839. }
  840. Func<BinaryReader, int> func_read_key4 = FacilityManager.<>f__mg$cacheE;
  841. if (FacilityManager.<>f__mg$cacheF == null)
  842. {
  843. FacilityManager.<>f__mg$cacheF = new Func<BinaryReader, int>(Util.ToInt32);
  844. }
  845. facilityBuildCount.Deserialize(brRead, func_read_key4, FacilityManager.<>f__mg$cacheF);
  846. if (num2 >= 4)
  847. {
  848. DataArray<string, string> facilityAchievementList = this.m_FacilityAchievementList;
  849. if (FacilityManager.<>f__mg$cache10 == null)
  850. {
  851. FacilityManager.<>f__mg$cache10 = new Func<BinaryReader, string>(Util.ToString);
  852. }
  853. Func<BinaryReader, string> func_read_key5 = FacilityManager.<>f__mg$cache10;
  854. if (FacilityManager.<>f__mg$cache11 == null)
  855. {
  856. FacilityManager.<>f__mg$cache11 = new Func<BinaryReader, string>(Util.ToString);
  857. }
  858. facilityAchievementList.Deserialize(brRead, func_read_key5, FacilityManager.<>f__mg$cache11);
  859. }
  860. Facility.DeleteTmpEditCostumeThumnails();
  861. stopwatch.Stop();
  862. return true;
  863. }
  864. private void ResetData()
  865. {
  866. this.m_TempSelectingFacility = null;
  867. if (this.m_CacheFacilityPowerUpResult != null)
  868. {
  869. this.m_CacheFacilityPowerUpResult.Clear();
  870. }
  871. if (this.m_FacilityArray != null)
  872. {
  873. foreach (Facility facility in this.m_FacilityArray)
  874. {
  875. if (facility)
  876. {
  877. UnityEngine.Object.Destroy(facility.gameObject);
  878. }
  879. }
  880. this.m_FacilityArray.Clear();
  881. }
  882. this.m_FacilityArray = new List<Facility>();
  883. for (int i = 0; i < this.FacilityCountMax; i++)
  884. {
  885. this.m_FacilityArray.Add(null);
  886. }
  887. if (this.m_NextDayFacilityArray != null)
  888. {
  889. foreach (KeyValuePair<int, Facility> keyValuePair in this.m_NextDayFacilityArray)
  890. {
  891. if (keyValuePair.Value)
  892. {
  893. UnityEngine.Object.Destroy(keyValuePair.Value.gameObject);
  894. }
  895. }
  896. this.m_NextDayFacilityArray.Clear();
  897. }
  898. this.m_NextDayFacilityArray = new Dictionary<int, Facility>();
  899. this.m_PowerUpMaterialArray = new DataArray<int, bool>();
  900. int[] facilityPowerUpMaterialIDArray = FacilityDataTable.GetFacilityPowerUpMaterialIDArray();
  901. for (int j = 0; j < facilityPowerUpMaterialIDArray.Length; j++)
  902. {
  903. this.m_PowerUpMaterialArray.Add(facilityPowerUpMaterialIDArray[j], false, true);
  904. }
  905. Facility.FacilityStatus[] facilityStatusArray = FacilityDataTable.GetFacilityStatusArray(true);
  906. this.m_FacilityExpArray = new DataArray<int, SimpleExperienceSystem>();
  907. for (int k = 0; k < facilityStatusArray.Length; k++)
  908. {
  909. List<int> need_exp_list = new List<int>();
  910. need_exp_list = FacilityDataTable.GetFacilityDefaultData(facilityStatusArray[k].typeID, true).levelTable;
  911. SimpleExperienceSystem value = new SimpleExperienceSystem(need_exp_list);
  912. this.m_FacilityExpArray.Add(facilityStatusArray[k].typeID, value, true);
  913. }
  914. this.m_FacilityBuildCount = new DataArray<int, int>();
  915. this.m_CacheFacilityPowerUpResult = new Dictionary<string, KeyValuePair<Facility, Facility.RecipeData>>();
  916. this.m_FacilityAchievementList = new DataArray<string, string>();
  917. }
  918. public T GetFacilityAchievement<T>(string key)
  919. {
  920. T result = default(T);
  921. string text = this.m_FacilityAchievementList.Get(key, false);
  922. if (!string.IsNullOrEmpty(text))
  923. {
  924. try
  925. {
  926. TypeConverter converter = TypeDescriptor.GetConverter(typeof(T));
  927. if (converter != null)
  928. {
  929. result = (T)((object)converter.ConvertFromString(text));
  930. }
  931. }
  932. catch (Exception ex)
  933. {
  934. UnityEngine.Debug.LogWarning(ex);
  935. NDebug.Warning(ex.Message);
  936. }
  937. }
  938. return result;
  939. }
  940. public void SetFacilityAchievement(string key, string value)
  941. {
  942. this.m_FacilityAchievementList.Add(key, value, true);
  943. }
  944. [Obsolete("[FacilityManager]使用しなくなる関数です\u3000Deserialize(BinaryReader)を使用して下さい", false)]
  945. public void Deserialize()
  946. {
  947. for (int i = 0; i < this.m_FacilityArray.Count; i++)
  948. {
  949. if (this.m_FacilityArray[i])
  950. {
  951. UnityEngine.Object.Destroy(this.m_FacilityArray[i].gameObject);
  952. }
  953. this.m_FacilityArray[i] = null;
  954. }
  955. this.ClearNextDayFacilityArray();
  956. string text = Path.GetFullPath(".\\") + "SaveData(営業施設)\\";
  957. string str = "Facility.save";
  958. if (!Directory.Exists(text))
  959. {
  960. Directory.CreateDirectory(text);
  961. }
  962. if (!File.Exists(text + str))
  963. {
  964. UnityEngine.Debug.LogWarning("[FacilityManager]施設のセーブデータが見つかりません");
  965. return;
  966. }
  967. using (FileStream fileStream = new FileStream(text + str, FileMode.Open))
  968. {
  969. byte[] buffer = new byte[fileStream.Length];
  970. fileStream.Read(buffer, 0, (int)fileStream.Length);
  971. using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(buffer)))
  972. {
  973. this.Deserialize(binaryReader);
  974. }
  975. }
  976. UnityEngine.Debug.Log("[FacilityManager]ロード完了");
  977. }
  978. [Obsolete("[FacilityManager]使用しなくなる関数です\u3000Serialize(BinaryWriter)を使用して下さい", false)]
  979. public void Serialize()
  980. {
  981. string text = Path.GetFullPath(".\\") + "SaveData(営業施設)\\";
  982. string str = "Facility.save";
  983. if (!Directory.Exists(text))
  984. {
  985. Directory.CreateDirectory(text);
  986. }
  987. using (MemoryStream memoryStream = new MemoryStream())
  988. {
  989. using (BinaryWriter binaryWriter = new BinaryWriter(memoryStream))
  990. {
  991. this.Serialize(binaryWriter);
  992. }
  993. File.WriteAllBytes(text + str, memoryStream.ToArray());
  994. }
  995. UnityEngine.Debug.Log("[FacilityManager]セーブ完了");
  996. }
  997. public void OnDestroy()
  998. {
  999. if (this.m_FacilityArray != null)
  1000. {
  1001. foreach (Facility facility in this.m_FacilityArray)
  1002. {
  1003. if (facility && facility.gameObject)
  1004. {
  1005. UnityEngine.Object.DestroyImmediate(facility.gameObject);
  1006. }
  1007. }
  1008. this.m_FacilityArray.Clear();
  1009. }
  1010. if (this.m_NextDayFacilityArray != null)
  1011. {
  1012. foreach (KeyValuePair<int, Facility> keyValuePair in this.m_NextDayFacilityArray)
  1013. {
  1014. if (keyValuePair.Value && keyValuePair.Value.gameObject)
  1015. {
  1016. UnityEngine.Object.DestroyImmediate(keyValuePair.Value.gameObject);
  1017. }
  1018. }
  1019. this.m_NextDayFacilityArray.Clear();
  1020. }
  1021. if (this.m_PowerUpMaterialArray != null)
  1022. {
  1023. this.m_PowerUpMaterialArray.Clear();
  1024. }
  1025. if (this.m_FacilityExpArray != null)
  1026. {
  1027. this.m_FacilityExpArray.Clear();
  1028. this.m_FacilityExpArray = null;
  1029. }
  1030. if (this.m_FacilityBuildCount != null)
  1031. {
  1032. this.m_FacilityBuildCount.Clear();
  1033. this.m_FacilityBuildCount = null;
  1034. }
  1035. if (this.m_ParentNowFacility)
  1036. {
  1037. UnityEngine.Object.DestroyImmediate(this.m_ParentNowFacility);
  1038. }
  1039. if (this.m_ParentNextDayFacility)
  1040. {
  1041. UnityEngine.Object.DestroyImmediate(this.m_ParentNextDayFacility);
  1042. }
  1043. }
  1044. public readonly int FacilityCountMax = 12;
  1045. private List<Facility> m_FacilityArray;
  1046. private Dictionary<int, Facility> m_NextDayFacilityArray;
  1047. private DataArray<int, bool> m_PowerUpMaterialArray;
  1048. private int m_NowBusinessTypeID = -1;
  1049. private int m_NextDayBusinessTypeID = -1;
  1050. private Facility m_TempSelectingFacility;
  1051. private DataArray<int, SimpleExperienceSystem> m_FacilityExpArray;
  1052. private DataArray<int, int> m_FacilityBuildCount;
  1053. private DataArray<string, string> m_FacilityAchievementList;
  1054. private GameObject m_ParentFacility;
  1055. private GameObject m_ParentNowFacility;
  1056. private GameObject m_ParentNextDayFacility;
  1057. private Dictionary<string, KeyValuePair<Facility, Facility.RecipeData>> m_CacheFacilityPowerUpResult;
  1058. private const string STR_FACILITY_SERIALIZE_VER = "5";
  1059. [CompilerGenerated]
  1060. private static Converter<int, byte[]> <>f__mg$cache0;
  1061. [CompilerGenerated]
  1062. private static Converter<bool, byte[]> <>f__mg$cache1;
  1063. [CompilerGenerated]
  1064. private static Converter<int, byte[]> <>f__mg$cache2;
  1065. [CompilerGenerated]
  1066. private static Converter<SimpleExperienceSystem, byte[]> <>f__mg$cache3;
  1067. [CompilerGenerated]
  1068. private static Converter<int, byte[]> <>f__mg$cache4;
  1069. [CompilerGenerated]
  1070. private static Converter<int, byte[]> <>f__mg$cache5;
  1071. [CompilerGenerated]
  1072. private static Converter<string, byte[]> <>f__mg$cache6;
  1073. [CompilerGenerated]
  1074. private static Converter<string, byte[]> <>f__mg$cache7;
  1075. [CompilerGenerated]
  1076. private static Func<BinaryReader, int> <>f__mg$cache8;
  1077. [CompilerGenerated]
  1078. private static Func<BinaryReader, bool> <>f__mg$cache9;
  1079. [CompilerGenerated]
  1080. private static Func<BinaryReader, int> <>f__mg$cacheA;
  1081. [CompilerGenerated]
  1082. private static Func<BinaryReader, SimpleExperienceSystem> <>f__mg$cacheB;
  1083. [CompilerGenerated]
  1084. private static Func<BinaryReader, int> <>f__mg$cacheC;
  1085. [CompilerGenerated]
  1086. private static Func<BinaryReader, int> <>f__mg$cacheD;
  1087. [CompilerGenerated]
  1088. private static Func<BinaryReader, int> <>f__mg$cacheE;
  1089. [CompilerGenerated]
  1090. private static Func<BinaryReader, int> <>f__mg$cacheF;
  1091. [CompilerGenerated]
  1092. private static Func<BinaryReader, string> <>f__mg$cache10;
  1093. [CompilerGenerated]
  1094. private static Func<BinaryReader, string> <>f__mg$cache11;
  1095. }