123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Diagnostics;
- using System.IO;
- using System.Runtime.CompilerServices;
- using FacilityFlag;
- using UnityEngine;
- public class FacilityManager : MonoBehaviour
- {
- public int NowBusinessTypeID
- {
- get
- {
- return this.m_NowBusinessTypeID;
- }
- set
- {
- this.m_NowBusinessTypeID = value;
- }
- }
- public int NextDayBusinessTypeID
- {
- get
- {
- return this.m_NextDayBusinessTypeID;
- }
- set
- {
- this.m_NextDayBusinessTypeID = value;
- }
- }
- public Facility tempSelectFacility
- {
- get
- {
- return this.m_TempSelectingFacility;
- }
- set
- {
- this.m_TempSelectingFacility = value;
- }
- }
- private GameObject parentFacility
- {
- get
- {
- return this.m_ParentFacility;
- }
- }
- private GameObject parentNowFacility
- {
- get
- {
- if (this.m_ParentNowFacility == null)
- {
- this.m_ParentNowFacility = new GameObject("Parent Now Facility");
- this.m_ParentNowFacility.transform.SetParent(this.parentFacility.transform, false);
- }
- return this.m_ParentNowFacility;
- }
- }
- private GameObject parentNextDayFacility
- {
- get
- {
- if (this.m_ParentNextDayFacility == null)
- {
- this.m_ParentNextDayFacility = new GameObject("Parent Next Day Facility");
- this.m_ParentNextDayFacility.transform.SetParent(this.parentFacility.transform, false);
- }
- return this.m_ParentNextDayFacility;
- }
- }
- public void Init(GameMain gameMain)
- {
- if (this.m_ParentFacility == null)
- {
- this.m_ParentFacility = new GameObject("Facility");
- this.m_ParentFacility.transform.SetParent(gameMain.transform, false);
- }
- FacilityDataTable.Init();
- this.ResetData();
- this.SetUpFixedFacilityArray();
- }
- private void SetUpFixedFacilityArray()
- {
- Facility.FacilityStatus[] facilityStatusArray = FacilityDataTable.GetFacilityStatusArray(true);
- for (int i = 0; i < facilityStatusArray.Length; i++)
- {
- int typeID = facilityStatusArray[i].typeID;
- if (FacilityDataTable.GetFacilityDefaultPlacement(typeID, true))
- {
- this.AddNewFacility(typeID);
- }
- }
- int[] facilityBusinessTypeIDArray = FacilityDataTable.GetFacilityBusinessTypeIDArray(true);
- foreach (int num in facilityBusinessTypeIDArray)
- {
- if (this.IsExistBusinessTypeFacility(num))
- {
- this.m_NowBusinessTypeID = num;
- break;
- }
- }
- }
- public int GetEmptySlot()
- {
- bool flag = false;
- int i;
- for (i = 0; i < this.FacilityCountMax; i++)
- {
- if (this.m_FacilityArray.Count < i || !this.m_FacilityArray[i])
- {
- flag = true;
- break;
- }
- }
- if (flag)
- {
- return i;
- }
- return -1;
- }
- public Facility[] GetFacilityArray()
- {
- return this.m_FacilityArray.ToArray();
- }
- public Facility GetFacility(int index)
- {
- if (this.m_FacilityArray.Count <= index)
- {
- return null;
- }
- if (index < 0)
- {
- return null;
- }
- return this.m_FacilityArray[index];
- }
- public bool GetFacilityExist(int index)
- {
- return index >= 0 && this.m_FacilityArray.Count > index && this.m_FacilityArray[index] != null;
- }
- public int GetFacilityIndex(Facility facility)
- {
- if (facility == null)
- {
- UnityEngine.Debug.LogError("[FacilityManager]引数にnullが指定されました");
- return -1;
- }
- if (this.m_FacilityArray.Contains(facility))
- {
- return this.m_FacilityArray.IndexOf(facility);
- }
- if (this.m_NextDayFacilityArray.ContainsValue(facility))
- {
- List<int> list = new List<int>(this.m_NextDayFacilityArray.Keys);
- List<Facility> list2 = new List<Facility>(this.m_NextDayFacilityArray.Values);
- return list[list2.IndexOf(facility)];
- }
- UnityEngine.Debug.Log(string.Format("[FacilityManager]施設『{0}』は施設マネージャクラスの管理外です", facility.facilityName));
- return -1;
- }
- public bool GetFacilityPowerUpItemEnable(int materialID)
- {
- if (this.m_PowerUpMaterialArray == null)
- {
- UnityEngine.Debug.LogError("[FacilityManager]強化素材の配列が未初期化状態です");
- return false;
- }
- return this.m_PowerUpMaterialArray.Get(materialID, false);
- }
- public Facility.PowerUpMaterial[] GetFacilityPowerUpItemEnableArray(int materialCategoryID)
- {
- Facility.PowerUpMaterial[] facilityPowerUpMaterialArray = FacilityDataTable.GetFacilityPowerUpMaterialArray(materialCategoryID);
- List<Facility.PowerUpMaterial> list = new List<Facility.PowerUpMaterial>();
- for (int i = 0; i < facilityPowerUpMaterialArray.Length; i++)
- {
- if (this.GetFacilityPowerUpItemEnable(facilityPowerUpMaterialArray[i].id))
- {
- list.Add(facilityPowerUpMaterialArray[i]);
- }
- }
- return list.ToArray();
- }
- public bool AddNewFacility(int facilityTypeID)
- {
- int emptySlot = this.GetEmptySlot();
- if (emptySlot < 0)
- {
- UnityEngine.Debug.Log(string.Format("[FacilityManager]施設は{0}個よりも多くは作れません", this.FacilityCountMax));
- return false;
- }
- Facility facility = this.CreateNewFacility(facilityTypeID);
- this.SetFacility(emptySlot, facility);
- return true;
- }
- public Facility CreateNewFacility(int facilityTypeID)
- {
- GameObject gameObject = new GameObject("Facility");
- Facility facility = gameObject.AddComponent<Facility>();
- facility.Init(facilityTypeID);
- gameObject.transform.SetParent(this.parentNowFacility.transform, false);
- return facility;
- }
- public Facility CreateNewFacility()
- {
- GameObject gameObject = new GameObject("Facility");
- Facility facility = gameObject.AddComponent<Facility>();
- facility.Init(FacilityDataTable.GetFacilityTypeID("劇場"));
- gameObject.transform.SetParent(this.parentNowFacility.transform, false);
- return facility;
- }
- public bool AddFacility(Facility facility)
- {
- int emptySlot = this.GetEmptySlot();
- if (emptySlot < 0)
- {
- UnityEngine.Debug.Log(string.Format("[FacilityManager]施設は{0}個よりも多くは作れません", this.FacilityCountMax));
- return false;
- }
- this.SetFacility(emptySlot, facility);
- return true;
- }
- public bool SetFacility(int index, Facility facility)
- {
- if (this.m_FacilityArray.Count <= index || index < 0)
- {
- UnityEngine.Debug.LogError(string.Format("[FacilityManager]施設の管理インデックスの値が不正です\n指定された値:{0}", index));
- return false;
- }
- if (facility != null && this.m_FacilityArray.Contains(facility))
- {
- UnityEngine.Debug.LogError(string.Format("[FacilityManager]施設「{0}」は既にマネージャクラスで管理されています", facility.facilityName));
- return false;
- }
- Facility facility2 = this.m_FacilityArray[index];
- if (facility2)
- {
- UnityEngine.Debug.Log(string.Format("[FacilityManager]管理している施設を置き換えた\n[{0}]番目:「{1}」から「{2}」へ", index, facility2.facilityName, (!facility) ? "空き部屋" : facility.facilityName));
- this.DestroyFacility(facility2);
- }
- this.m_FacilityArray[index] = facility;
- if (facility)
- {
- facility.gameObject.transform.SetParent(this.parentNowFacility.transform, false);
- int typeID = facility.param.typeID;
- int num = (!this.m_FacilityBuildCount.Contains(typeID)) ? 0 : this.m_FacilityBuildCount.Get(typeID, false);
- this.m_FacilityBuildCount.Add(typeID, num + 1, true);
- }
- return true;
- }
- public bool DestroyFacility(int index)
- {
- if (this.GetFacility(index) == null)
- {
- UnityEngine.Debug.Log(string.Format("[FacilityManager]施設の管理インデックス[{0}]番の施設は存在しない", index));
- return false;
- }
- Facility facility = this.m_FacilityArray[index];
- this.m_FacilityArray[index] = null;
- UnityEngine.Object.Destroy(facility.gameObject);
- return true;
- }
- public bool DestroyFacility(Facility facility)
- {
- if (facility == null)
- {
- UnityEngine.Debug.LogError("[FacilityManager]削除したい施設としてnullが指定されました");
- return false;
- }
- string facilityName = facility.facilityName;
- if (!this.m_FacilityArray.Contains(facility))
- {
- UnityEngine.Debug.Log(string.Format("[FacilityManager]施設『{0}』は施設マネージャクラスの管理外です", facilityName));
- return false;
- }
- int facilityIndex = this.GetFacilityIndex(facility);
- this.m_FacilityArray[facilityIndex] = null;
- UnityEngine.Object.Destroy(facility.gameObject);
- UnityEngine.Debug.Log(string.Format("[FacilityManager]施設『{0}』の削除に成功", facilityName));
- return true;
- }
- public void SetHavePowerUpMaterial(int materialID, bool isHave = true)
- {
- if (this.m_PowerUpMaterialArray == null)
- {
- UnityEngine.Debug.LogError("[FacilityManager]強化素材配列が未初期化状態です");
- return;
- }
- if (!this.m_PowerUpMaterialArray.Contains(materialID))
- {
- UnityEngine.Debug.Log(string.Format("[FacilityManager]強化素材ID[{0}]番は存在しない情報です", materialID));
- return;
- }
- this.m_PowerUpMaterialArray.Add(materialID, isHave, true);
- }
- public int GetFacilityLevel(int facilityTypeID)
- {
- if (this.m_FacilityExpArray == null)
- {
- UnityEngine.Debug.LogError("[FacilityManager]施設の種類ごとの施設レベル配列が未初期化です");
- return -1;
- }
- if (!this.m_FacilityExpArray.Contains(facilityTypeID))
- {
- UnityEngine.Debug.LogWarningFormat("[FacilityManager]施設の種類ID[{0}]番に対応する施設レベル情報がありません", new object[]
- {
- facilityTypeID
- });
- return -1;
- }
- return this.m_FacilityExpArray.Get(facilityTypeID, false).GetCurrentLevel();
- }
- public SimpleExperienceSystem GetFacilityExpSystem(int facilityTypeID)
- {
- if (this.m_FacilityExpArray == null)
- {
- UnityEngine.Debug.LogError("[FacilityManager]施設の種類ごとの施設レベル配列が未初期化です");
- return null;
- }
- if (!this.m_FacilityExpArray.Contains(facilityTypeID))
- {
- UnityEngine.Debug.LogWarningFormat("[FacilityManager]施設の種類ID[{0}]番に対応する施設レベル情報がありません", new object[]
- {
- facilityTypeID
- });
- return null;
- }
- return this.m_FacilityExpArray.Get(facilityTypeID, false);
- }
- public Dictionary<int, Facility> GetNextDayFacilityArray()
- {
- return this.m_NextDayFacilityArray;
- }
- public Facility GetNextDayFacility(int nowFacilityIndex)
- {
- if (!this.GetNextDayFacilityExist(nowFacilityIndex))
- {
- return null;
- }
- return this.m_NextDayFacilityArray[nowFacilityIndex];
- }
- public Facility GetNextDayFacility(Facility nowFacility)
- {
- int facilityIndex = this.GetFacilityIndex(nowFacility);
- if (!this.GetNextDayFacilityExist(facilityIndex))
- {
- UnityEngine.Debug.Log(string.Format("[FacilityManager]次の日に設置する施設の情報が存在しない\n管理インデックス:[{0}]", facilityIndex));
- return null;
- }
- return this.m_NextDayFacilityArray[facilityIndex];
- }
- public bool GetNextDayFacilityExist(int nowFacilityIndex)
- {
- return this.m_NextDayFacilityArray.ContainsKey(nowFacilityIndex);
- }
- public bool GetNextDayFacilityExist(Facility nowFacility)
- {
- int facilityIndex = this.GetFacilityIndex(nowFacility);
- return this.m_NextDayFacilityArray.ContainsKey(facilityIndex);
- }
- public void SetNextDayFacility(int index, Facility nextDayFacility)
- {
- if (this.m_NextDayFacilityArray.ContainsKey(index))
- {
- this.m_NextDayFacilityArray[index] = nextDayFacility;
- UnityEngine.Debug.Log(string.Format("[FacilityManager]次の日の施設情報を上書きした\n[{0}]番目:{1}", index, (!nextDayFacility) ? "空き部屋" : nextDayFacility.facilityName));
- return;
- }
- this.m_NextDayFacilityArray.Add(index, nextDayFacility);
- UnityEngine.Debug.Log(string.Format("[FacilityManager]次の日の施設情報を追加した\n[{0}]番目:{1}", index, (!nextDayFacility) ? "空き部屋" : nextDayFacility.facilityName));
- if (nextDayFacility != null)
- {
- nextDayFacility.transform.SetParent(this.parentNextDayFacility.transform, false);
- }
- }
- public void RemoveNextDayFacility(int index)
- {
- if (!this.m_NextDayFacilityArray.ContainsKey(index))
- {
- UnityEngine.Debug.Log(string.Format("[FacilityManager]キーの値[{0}]のノードは存在しない", index));
- return;
- }
- this.m_NextDayFacilityArray.Remove(index);
- }
- public void ClearNextDayFacilityArray()
- {
- List<Facility> list = new List<Facility>(this.m_NextDayFacilityArray.Values);
- for (int i = 0; i < list.Count; i++)
- {
- if (list[i])
- {
- UnityEngine.Object.Destroy(list[i].gameObject);
- }
- }
- this.m_NextDayFacilityArray.Clear();
- }
- private void UpdateNextDayFacility()
- {
- CharacterMgr characterMgr = null;
- if (GameMain.Instance != null && GameMain.Instance.CharacterMgr != null)
- {
- characterMgr = GameMain.Instance.CharacterMgr;
- }
- Dictionary<int, Facility> nextDayFacilityArray = this.GetNextDayFacilityArray();
- int count = nextDayFacilityArray.Count;
- List<int> list = new List<int>(nextDayFacilityArray.Keys);
- List<Facility> list2 = new List<Facility>(nextDayFacilityArray.Values);
- for (int i = 0; i < count; i++)
- {
- int num = 0;
- if (list2[i] != null)
- {
- num = list2[i].defaultData.cost;
- }
- if (characterMgr != null && characterMgr.status.money - (long)num >= 0L)
- {
- characterMgr.status.money -= (long)num;
- this.RemoveNextDayFacility(list[i]);
- this.SetFacility(list[i], list2[i]);
- }
- else
- {
- this.RemoveNextDayFacility(list[i]);
- UnityEngine.Object.Destroy(list2[i].gameObject);
- }
- }
- }
- public void UpdateNextDay()
- {
- this.UpdateNextDayFacility();
- if (this.m_NowBusinessTypeID != this.m_NextDayBusinessTypeID && FacilityDataTable.IsExistFacilityBusinessTypeData(this.m_NextDayBusinessTypeID))
- {
- this.m_NowBusinessTypeID = this.m_NextDayBusinessTypeID;
- }
- int num = 0;
- foreach (Facility x in this.GetFacilityArray())
- {
- if (x != null)
- {
- num++;
- }
- }
- int facilityAchievement = this.GetFacilityAchievement<int>("施設総数");
- if (facilityAchievement < num)
- {
- this.SetFacilityAchievement("施設総数", num.ToString());
- }
- }
- public bool IsExistBusinessTypeFacility(int businessTypeID)
- {
- Facility[] array = this.m_FacilityArray.ToArray();
- foreach (Facility facility in array)
- {
- if (!(facility == null))
- {
- if (facility.defaultData.businessTypeID == businessTypeID)
- {
- return true;
- }
- }
- }
- return false;
- }
- public bool IsExistBusinessTypeFacility(FacilityDataTable.BusinessTypeData businessData)
- {
- return this.IsExistBusinessTypeFacility(businessData.ID);
- }
- public bool IsExistBusinessTypeFacility(string businessName)
- {
- return this.IsExistBusinessTypeFacility(FacilityDataTable.GetFacilityBusinessTypeData(businessName).ID);
- }
- public bool IsExistTypeFacility(int facilityTypeID)
- {
- Facility[] array = this.m_FacilityArray.ToArray();
- foreach (Facility facility in array)
- {
- if (!(facility == null))
- {
- if (facility.param.typeID == facilityTypeID)
- {
- return true;
- }
- }
- }
- return false;
- }
- public bool IsExistTypeFacility(int facilityTypeID, out Facility[] matchingFacilityArray)
- {
- Facility[] array = this.m_FacilityArray.ToArray();
- List<Facility> list = new List<Facility>();
- foreach (Facility facility in array)
- {
- if (!(facility == null))
- {
- if (facility.param.typeID == facilityTypeID)
- {
- list.Add(facility);
- }
- }
- }
- matchingFacilityArray = list.ToArray();
- return matchingFacilityArray.Length > 0;
- }
- public bool IsExistTypeFacilityInOperation(int facilityTypeID)
- {
- Facility[] array = this.m_FacilityArray.ToArray();
- foreach (Facility facility in array)
- {
- if (!(facility == null))
- {
- if (facility.isOperationDayTime && facility.param.typeID == facilityTypeID)
- {
- return true;
- }
- }
- }
- return false;
- }
- public bool IsExistTypeFacilityInOperation(int facilityTypeID, out Facility[] matchingFacilityArray)
- {
- Facility[] array = this.m_FacilityArray.ToArray();
- List<Facility> list = new List<Facility>();
- foreach (Facility facility in array)
- {
- if (!(facility == null))
- {
- if (facility.isOperationDayTime && facility.param.typeID == facilityTypeID)
- {
- list.Add(facility);
- }
- }
- }
- matchingFacilityArray = list.ToArray();
- return matchingFacilityArray.Length > 0;
- }
- public bool IsFacilityBuildFlag(int facilityTypeID)
- {
- return this.m_FacilityBuildCount.Contains(facilityTypeID) && this.m_FacilityBuildCount.Get(facilityTypeID, false) > 0;
- }
- public Facility GetMaidAssignedFacility(Maid maid, ScheduleMgr.ScheduleTime scheduleTime)
- {
- for (int i = 0; i < this.m_FacilityArray.Count; i++)
- {
- if (!(this.m_FacilityArray[i] == null))
- {
- if (this.m_FacilityArray[i].IsAllocationMaid(maid, scheduleTime))
- {
- return this.m_FacilityArray[i];
- }
- }
- }
- return null;
- }
- public void UpdateFacilityAssignedMaidData()
- {
- for (int i = 0; i < this.m_FacilityArray.Count; i++)
- {
- if (!(this.m_FacilityArray[i] == null))
- {
- this.m_FacilityArray[i].UpdateAllocationMaidList();
- }
- }
- }
- public void AddCacheFacilityPowewrUpResult(Maid maid, Facility facility, Facility.RecipeData recipe)
- {
- if (maid == null)
- {
- NDebug.Assert("メイドにnullが指定されました", false);
- }
- if (this.m_CacheFacilityPowerUpResult.ContainsKey(maid.status.guid))
- {
- UnityEngine.Debug.LogWarningFormat("メイド「{0}」の情報は既にキャッシュしています", new object[]
- {
- maid
- });
- return;
- }
- this.m_CacheFacilityPowerUpResult.Add(maid.status.guid, new KeyValuePair<Facility, Facility.RecipeData>(facility, recipe));
- }
- public bool IsExistCacheFacilityPowerUpResult(Maid maid)
- {
- NDebug.Assert(maid != null, "メイドにnullが指定されました");
- return this.m_CacheFacilityPowerUpResult.ContainsKey(maid.status.guid);
- }
- public bool TryGetCacheFacilityPowerUpResult(Maid maid, out Facility facility, out Facility.RecipeData recipe)
- {
- facility = null;
- recipe = null;
- if (!this.IsExistCacheFacilityPowerUpResult(maid))
- {
- return false;
- }
- KeyValuePair<Facility, Facility.RecipeData> keyValuePair = this.m_CacheFacilityPowerUpResult[maid.status.guid];
- facility = keyValuePair.Key;
- recipe = keyValuePair.Value;
- return true;
- }
- public void ClearCacheFacilityPowerUpResult()
- {
- this.m_CacheFacilityPowerUpResult.Clear();
- }
- public bool Serialize(BinaryWriter brWrite)
- {
- Stopwatch stopwatch = new Stopwatch();
- stopwatch.Start();
- brWrite.Write("CM3D21_FACILITY_MGR");
- brWrite.Write(1300);
- brWrite.Write("5");
- int num = 0;
- for (int i = 0; i < this.m_FacilityArray.Count; i++)
- {
- if (this.m_FacilityArray[i])
- {
- num++;
- }
- }
- brWrite.Write(num);
- for (int j = 0; j < this.m_FacilityArray.Count; j++)
- {
- if (this.m_FacilityArray[j])
- {
- brWrite.Write(j);
- this.m_FacilityArray[j].Serialize(brWrite);
- }
- }
- DataArray<int, bool> powerUpMaterialArray = this.m_PowerUpMaterialArray;
- if (FacilityManager.<>f__mg$cache0 == null)
- {
- FacilityManager.<>f__mg$cache0 = new Converter<int, byte[]>(Util.GetBytes);
- }
- Converter<int, byte[]> converter_key = FacilityManager.<>f__mg$cache0;
- if (FacilityManager.<>f__mg$cache1 == null)
- {
- FacilityManager.<>f__mg$cache1 = new Converter<bool, byte[]>(Util.GetBytes);
- }
- powerUpMaterialArray.Serialize(brWrite, converter_key, FacilityManager.<>f__mg$cache1);
- int count = this.m_NextDayFacilityArray.Count;
- brWrite.Write(count);
- for (int k = 0; k < this.m_FacilityArray.Count; k++)
- {
- if (this.GetNextDayFacilityExist(k))
- {
- Facility nextDayFacility = this.GetNextDayFacility(k);
- if (nextDayFacility)
- {
- brWrite.Write(k);
- brWrite.Write(true);
- nextDayFacility.Serialize(brWrite);
- }
- else
- {
- brWrite.Write(k);
- brWrite.Write(false);
- }
- }
- }
- DataArray<int, SimpleExperienceSystem> facilityExpArray = this.m_FacilityExpArray;
- if (FacilityManager.<>f__mg$cache2 == null)
- {
- FacilityManager.<>f__mg$cache2 = new Converter<int, byte[]>(Util.GetBytes);
- }
- Converter<int, byte[]> converter_key2 = FacilityManager.<>f__mg$cache2;
- if (FacilityManager.<>f__mg$cache3 == null)
- {
- FacilityManager.<>f__mg$cache3 = new Converter<SimpleExperienceSystem, byte[]>(Util.GetBytes);
- }
- facilityExpArray.Serialize(brWrite, converter_key2, FacilityManager.<>f__mg$cache3);
- DataArray<int, int> facilityBuildCount = this.m_FacilityBuildCount;
- if (FacilityManager.<>f__mg$cache4 == null)
- {
- FacilityManager.<>f__mg$cache4 = new Converter<int, byte[]>(Util.GetBytes);
- }
- Converter<int, byte[]> converter_key3 = FacilityManager.<>f__mg$cache4;
- if (FacilityManager.<>f__mg$cache5 == null)
- {
- FacilityManager.<>f__mg$cache5 = new Converter<int, byte[]>(Util.GetBytes);
- }
- facilityBuildCount.Serialize(brWrite, converter_key3, FacilityManager.<>f__mg$cache5);
- DataArray<string, string> facilityAchievementList = this.m_FacilityAchievementList;
- if (FacilityManager.<>f__mg$cache6 == null)
- {
- FacilityManager.<>f__mg$cache6 = new Converter<string, byte[]>(Util.GetBytes);
- }
- Converter<string, byte[]> converter_key4 = FacilityManager.<>f__mg$cache6;
- if (FacilityManager.<>f__mg$cache7 == null)
- {
- FacilityManager.<>f__mg$cache7 = new Converter<string, byte[]>(Util.GetBytes);
- }
- facilityAchievementList.Serialize(brWrite, converter_key4, FacilityManager.<>f__mg$cache7);
- stopwatch.Stop();
- return true;
- }
- public bool Deserialize(BinaryReader brRead)
- {
- Stopwatch stopwatch = new Stopwatch();
- stopwatch.Start();
- this.ResetData();
- if (brRead.BaseStream.Length <= brRead.BaseStream.Position + 1L)
- {
- this.SetUpFixedFacilityArray();
- return false;
- }
- long position = brRead.BaseStream.Position;
- string text = brRead.ReadString();
- if (text != "CM3D21_FACILITY_MGR")
- {
- NDebug.Warning("セーブデータファイルのヘッダーが不正です。FACILITY_MGR\n" + text);
- brRead.BaseStream.Seek(position, SeekOrigin.Begin);
- return false;
- }
- int num = brRead.ReadInt32();
- position = brRead.BaseStream.Position;
- string text2 = brRead.ReadString();
- int num2;
- if (string.IsNullOrEmpty(text2))
- {
- num2 = 0;
- brRead.BaseStream.Seek(position, SeekOrigin.Begin);
- }
- else
- {
- int num3 = 0;
- if (int.TryParse(text2, out num3) && num3 > 0 && 10 > num3)
- {
- num2 = num3;
- }
- else
- {
- num2 = 0;
- brRead.BaseStream.Seek(position, SeekOrigin.Begin);
- }
- }
- int num4 = brRead.ReadInt32();
- for (int i = 0; i < num4; i++)
- {
- int index3 = brRead.ReadInt32();
- Facility facility = this.CreateNewFacility();
- if (facility.Deserialize(brRead, num2))
- {
- this.m_FacilityArray[index3] = facility;
- }
- else
- {
- UnityEngine.Object.Destroy(facility);
- }
- }
- DataArray<int, bool> dataArray = new DataArray<int, bool>();
- DataArray<int, bool> dataArray2 = dataArray;
- if (FacilityManager.<>f__mg$cache8 == null)
- {
- FacilityManager.<>f__mg$cache8 = new Func<BinaryReader, int>(Util.ToInt32);
- }
- Func<BinaryReader, int> func_read_key = FacilityManager.<>f__mg$cache8;
- if (FacilityManager.<>f__mg$cache9 == null)
- {
- FacilityManager.<>f__mg$cache9 = new Func<BinaryReader, bool>(Util.ToBoolean);
- }
- dataArray2.Deserialize(brRead, func_read_key, FacilityManager.<>f__mg$cache9);
- dataArray.Loop(delegate(int index, int key, bool value)
- {
- this.m_PowerUpMaterialArray.Add(key, value, true);
- });
- int num5 = brRead.ReadInt32();
- for (int j = 0; j < num5; j++)
- {
- int index2 = brRead.ReadInt32();
- bool flag = brRead.ReadBoolean();
- bool flag2 = false;
- Facility facility2 = null;
- if (flag)
- {
- facility2 = this.CreateNewFacility();
- flag2 = facility2.Deserialize(brRead, num2);
- }
- if (flag2)
- {
- this.SetNextDayFacility(index2, facility2);
- }
- else
- {
- UnityEngine.Object.Destroy(facility2);
- }
- }
- if (num2 > 1)
- {
- DataArray<int, SimpleExperienceSystem> array = new DataArray<int, SimpleExperienceSystem>();
- DataArray<int, SimpleExperienceSystem> array2 = array;
- if (FacilityManager.<>f__mg$cacheA == null)
- {
- FacilityManager.<>f__mg$cacheA = new Func<BinaryReader, int>(Util.ToInt32);
- }
- Func<BinaryReader, int> func_read_key2 = FacilityManager.<>f__mg$cacheA;
- if (FacilityManager.<>f__mg$cacheB == null)
- {
- FacilityManager.<>f__mg$cacheB = new Func<BinaryReader, SimpleExperienceSystem>(Util.ToSimpleExp);
- }
- array2.Deserialize(brRead, func_read_key2, FacilityManager.<>f__mg$cacheB);
- array.Loop(delegate(int index, int key, SimpleExperienceSystem value)
- {
- FacilityDataTable.FacilityDefaultData facilityDefaultData = FacilityDataTable.GetFacilityDefaultData(key, true);
- if (facilityDefaultData != null)
- {
- value.SetExreienceList(facilityDefaultData.levelTable);
- }
- else
- {
- string message = string.Format("施設Expテーブル:施設ID[{0}]のデータは存在しません", key);
- UnityEngine.Debug.LogWarning(message);
- }
- });
- this.m_FacilityExpArray.Loop(delegate(int index, int id, SimpleExperienceSystem exp)
- {
- if (array.Contains(id))
- {
- this.m_FacilityExpArray.Add(id, array.Get(id, false), true);
- }
- });
- }
- else
- {
- if (FacilityManager.<>f__mg$cacheC == null)
- {
- FacilityManager.<>f__mg$cacheC = new Func<BinaryReader, int>(Util.ToInt32);
- }
- Func<BinaryReader, int> func_read_key3 = FacilityManager.<>f__mg$cacheC;
- if (FacilityManager.<>f__mg$cacheD == null)
- {
- FacilityManager.<>f__mg$cacheD = new Func<BinaryReader, int>(Util.ToInt32);
- }
- DataArray<int, int>.Skip(brRead, func_read_key3, FacilityManager.<>f__mg$cacheD);
- }
- DataArray<int, int> facilityBuildCount = this.m_FacilityBuildCount;
- if (FacilityManager.<>f__mg$cacheE == null)
- {
- FacilityManager.<>f__mg$cacheE = new Func<BinaryReader, int>(Util.ToInt32);
- }
- Func<BinaryReader, int> func_read_key4 = FacilityManager.<>f__mg$cacheE;
- if (FacilityManager.<>f__mg$cacheF == null)
- {
- FacilityManager.<>f__mg$cacheF = new Func<BinaryReader, int>(Util.ToInt32);
- }
- facilityBuildCount.Deserialize(brRead, func_read_key4, FacilityManager.<>f__mg$cacheF);
- if (num2 >= 4)
- {
- DataArray<string, string> facilityAchievementList = this.m_FacilityAchievementList;
- if (FacilityManager.<>f__mg$cache10 == null)
- {
- FacilityManager.<>f__mg$cache10 = new Func<BinaryReader, string>(Util.ToString);
- }
- Func<BinaryReader, string> func_read_key5 = FacilityManager.<>f__mg$cache10;
- if (FacilityManager.<>f__mg$cache11 == null)
- {
- FacilityManager.<>f__mg$cache11 = new Func<BinaryReader, string>(Util.ToString);
- }
- facilityAchievementList.Deserialize(brRead, func_read_key5, FacilityManager.<>f__mg$cache11);
- }
- Facility.DeleteTmpEditCostumeThumnails();
- stopwatch.Stop();
- return true;
- }
- private void ResetData()
- {
- this.m_TempSelectingFacility = null;
- if (this.m_CacheFacilityPowerUpResult != null)
- {
- this.m_CacheFacilityPowerUpResult.Clear();
- }
- if (this.m_FacilityArray != null)
- {
- foreach (Facility facility in this.m_FacilityArray)
- {
- if (facility)
- {
- UnityEngine.Object.Destroy(facility.gameObject);
- }
- }
- this.m_FacilityArray.Clear();
- }
- this.m_FacilityArray = new List<Facility>();
- for (int i = 0; i < this.FacilityCountMax; i++)
- {
- this.m_FacilityArray.Add(null);
- }
- if (this.m_NextDayFacilityArray != null)
- {
- foreach (KeyValuePair<int, Facility> keyValuePair in this.m_NextDayFacilityArray)
- {
- if (keyValuePair.Value)
- {
- UnityEngine.Object.Destroy(keyValuePair.Value.gameObject);
- }
- }
- this.m_NextDayFacilityArray.Clear();
- }
- this.m_NextDayFacilityArray = new Dictionary<int, Facility>();
- this.m_PowerUpMaterialArray = new DataArray<int, bool>();
- int[] facilityPowerUpMaterialIDArray = FacilityDataTable.GetFacilityPowerUpMaterialIDArray();
- for (int j = 0; j < facilityPowerUpMaterialIDArray.Length; j++)
- {
- this.m_PowerUpMaterialArray.Add(facilityPowerUpMaterialIDArray[j], false, true);
- }
- Facility.FacilityStatus[] facilityStatusArray = FacilityDataTable.GetFacilityStatusArray(true);
- this.m_FacilityExpArray = new DataArray<int, SimpleExperienceSystem>();
- for (int k = 0; k < facilityStatusArray.Length; k++)
- {
- List<int> need_exp_list = new List<int>();
- need_exp_list = FacilityDataTable.GetFacilityDefaultData(facilityStatusArray[k].typeID, true).levelTable;
- SimpleExperienceSystem value = new SimpleExperienceSystem(need_exp_list);
- this.m_FacilityExpArray.Add(facilityStatusArray[k].typeID, value, true);
- }
- this.m_FacilityBuildCount = new DataArray<int, int>();
- this.m_CacheFacilityPowerUpResult = new Dictionary<string, KeyValuePair<Facility, Facility.RecipeData>>();
- this.m_FacilityAchievementList = new DataArray<string, string>();
- }
- public T GetFacilityAchievement<T>(string key)
- {
- T result = default(T);
- string text = this.m_FacilityAchievementList.Get(key, false);
- if (!string.IsNullOrEmpty(text))
- {
- try
- {
- TypeConverter converter = TypeDescriptor.GetConverter(typeof(T));
- if (converter != null)
- {
- result = (T)((object)converter.ConvertFromString(text));
- }
- }
- catch (Exception ex)
- {
- UnityEngine.Debug.LogWarning(ex);
- NDebug.Warning(ex.Message);
- }
- }
- return result;
- }
- public void SetFacilityAchievement(string key, string value)
- {
- this.m_FacilityAchievementList.Add(key, value, true);
- }
- [Obsolete("[FacilityManager]使用しなくなる関数です\u3000Deserialize(BinaryReader)を使用して下さい", false)]
- public void Deserialize()
- {
- for (int i = 0; i < this.m_FacilityArray.Count; i++)
- {
- if (this.m_FacilityArray[i])
- {
- UnityEngine.Object.Destroy(this.m_FacilityArray[i].gameObject);
- }
- this.m_FacilityArray[i] = null;
- }
- this.ClearNextDayFacilityArray();
- string text = Path.GetFullPath(".\\") + "SaveData(営業施設)\\";
- string str = "Facility.save";
- if (!Directory.Exists(text))
- {
- Directory.CreateDirectory(text);
- }
- if (!File.Exists(text + str))
- {
- UnityEngine.Debug.LogWarning("[FacilityManager]施設のセーブデータが見つかりません");
- return;
- }
- using (FileStream fileStream = new FileStream(text + str, FileMode.Open))
- {
- byte[] buffer = new byte[fileStream.Length];
- fileStream.Read(buffer, 0, (int)fileStream.Length);
- using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(buffer)))
- {
- this.Deserialize(binaryReader);
- }
- }
- UnityEngine.Debug.Log("[FacilityManager]ロード完了");
- }
- [Obsolete("[FacilityManager]使用しなくなる関数です\u3000Serialize(BinaryWriter)を使用して下さい", false)]
- public void Serialize()
- {
- string text = Path.GetFullPath(".\\") + "SaveData(営業施設)\\";
- string str = "Facility.save";
- if (!Directory.Exists(text))
- {
- Directory.CreateDirectory(text);
- }
- using (MemoryStream memoryStream = new MemoryStream())
- {
- using (BinaryWriter binaryWriter = new BinaryWriter(memoryStream))
- {
- this.Serialize(binaryWriter);
- }
- File.WriteAllBytes(text + str, memoryStream.ToArray());
- }
- UnityEngine.Debug.Log("[FacilityManager]セーブ完了");
- }
- public void OnDestroy()
- {
- if (this.m_FacilityArray != null)
- {
- foreach (Facility facility in this.m_FacilityArray)
- {
- if (facility && facility.gameObject)
- {
- UnityEngine.Object.DestroyImmediate(facility.gameObject);
- }
- }
- this.m_FacilityArray.Clear();
- }
- if (this.m_NextDayFacilityArray != null)
- {
- foreach (KeyValuePair<int, Facility> keyValuePair in this.m_NextDayFacilityArray)
- {
- if (keyValuePair.Value && keyValuePair.Value.gameObject)
- {
- UnityEngine.Object.DestroyImmediate(keyValuePair.Value.gameObject);
- }
- }
- this.m_NextDayFacilityArray.Clear();
- }
- if (this.m_PowerUpMaterialArray != null)
- {
- this.m_PowerUpMaterialArray.Clear();
- }
- if (this.m_FacilityExpArray != null)
- {
- this.m_FacilityExpArray.Clear();
- this.m_FacilityExpArray = null;
- }
- if (this.m_FacilityBuildCount != null)
- {
- this.m_FacilityBuildCount.Clear();
- this.m_FacilityBuildCount = null;
- }
- if (this.m_ParentNowFacility)
- {
- UnityEngine.Object.DestroyImmediate(this.m_ParentNowFacility);
- }
- if (this.m_ParentNextDayFacility)
- {
- UnityEngine.Object.DestroyImmediate(this.m_ParentNextDayFacility);
- }
- }
- public readonly int FacilityCountMax = 12;
- private List<Facility> m_FacilityArray;
- private Dictionary<int, Facility> m_NextDayFacilityArray;
- private DataArray<int, bool> m_PowerUpMaterialArray;
- private int m_NowBusinessTypeID = -1;
- private int m_NextDayBusinessTypeID = -1;
- private Facility m_TempSelectingFacility;
- private DataArray<int, SimpleExperienceSystem> m_FacilityExpArray;
- private DataArray<int, int> m_FacilityBuildCount;
- private DataArray<string, string> m_FacilityAchievementList;
- private GameObject m_ParentFacility;
- private GameObject m_ParentNowFacility;
- private GameObject m_ParentNextDayFacility;
- private Dictionary<string, KeyValuePair<Facility, Facility.RecipeData>> m_CacheFacilityPowerUpResult;
- private const string STR_FACILITY_SERIALIZE_VER = "5";
- [CompilerGenerated]
- private static Converter<int, byte[]> <>f__mg$cache0;
- [CompilerGenerated]
- private static Converter<bool, byte[]> <>f__mg$cache1;
- [CompilerGenerated]
- private static Converter<int, byte[]> <>f__mg$cache2;
- [CompilerGenerated]
- private static Converter<SimpleExperienceSystem, byte[]> <>f__mg$cache3;
- [CompilerGenerated]
- private static Converter<int, byte[]> <>f__mg$cache4;
- [CompilerGenerated]
- private static Converter<int, byte[]> <>f__mg$cache5;
- [CompilerGenerated]
- private static Converter<string, byte[]> <>f__mg$cache6;
- [CompilerGenerated]
- private static Converter<string, byte[]> <>f__mg$cache7;
- [CompilerGenerated]
- private static Func<BinaryReader, int> <>f__mg$cache8;
- [CompilerGenerated]
- private static Func<BinaryReader, bool> <>f__mg$cache9;
- [CompilerGenerated]
- private static Func<BinaryReader, int> <>f__mg$cacheA;
- [CompilerGenerated]
- private static Func<BinaryReader, SimpleExperienceSystem> <>f__mg$cacheB;
- [CompilerGenerated]
- private static Func<BinaryReader, int> <>f__mg$cacheC;
- [CompilerGenerated]
- private static Func<BinaryReader, int> <>f__mg$cacheD;
- [CompilerGenerated]
- private static Func<BinaryReader, int> <>f__mg$cacheE;
- [CompilerGenerated]
- private static Func<BinaryReader, int> <>f__mg$cacheF;
- [CompilerGenerated]
- private static Func<BinaryReader, string> <>f__mg$cache10;
- [CompilerGenerated]
- private static Func<BinaryReader, string> <>f__mg$cache11;
- }
|