using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using FacilityFlag; using UnityEngine; public class EmpireLifeModeManager : MonoBehaviour { public List nowEventList { get { return this.m_EventList; } } public Dictionary> nowMaidAllocationDic { get { return this.m_NowMaidAllocationDic; } } public List executedEventList { get { return this.m_ExecutedEventList; } } public List lifeModeAllMaidList { get { return this.m_LifeModeAllMaidList; } } public void SetAllMaidList(IEnumerable maidCorrection) { this.m_LifeModeAllMaidList = new List(maidCorrection); } public void UpdateAllMaidList() { this.m_LifeModeAllMaidList = new List(from maid in this.m_LifeModeAllMaidList where maid != null select maid); } public List executedMaidList { get { return this.m_ExecutedMaidList; } } private void CreateAndCacheEvent(EmpireLifeModeData.Data data, Facility targetFacility, IEnumerable targetMaidList) { EmpireLifeModeManager.EventDataObject eventDataObject = new EmpireLifeModeManager.EventDataObject(); eventDataObject.targetEvent = data; eventDataObject.targetFacility = targetFacility; eventDataObject.targetMaidList = new List(targetMaidList); this.nowEventList.Add(eventDataObject); } public void CreateStoryEvent() { if (this.nowEventList.Exists((EmpireLifeModeManager.EventDataObject d) => d.targetEvent.dataScenarioType == EmpireLifeModeData.ScenarioType.スト\u30FCリ\u30FC)) { Debug.Log("既にストーリーイベントが存在していたので、ストーリーイベントの追加は行いません。"); return; } if (this.executedEventList.Exists((EmpireLifeModeManager.EventDataObject d) => d.targetEvent.dataScenarioType == EmpireLifeModeData.ScenarioType.スト\u30FCリ\u30FC)) { Debug.Log("既にストーリーイベントは実行された後なので、ストーリーイベントの追加は行いません。"); return; } List datas = EmpireLifeModeData.GetDatas((EmpireLifeModeData.Data d) => EmpireLifeModeData.IsEnabled(d.ID) && d.dataScenarioType == EmpireLifeModeData.ScenarioType.スト\u30FCリ\u30FC, true); if (datas == null || datas.Count <= 0) { Debug.Log("種類が「ストーリー」であるイベントは存在しなかった。"); return; } foreach (EmpireLifeModeData.Data data in datas) { if (data.IsCorrectScenarioAnyNumberPlay()) { if (data.IsCorrectUniqueComparisonObject()) { List correctFacilityList = data.GetCorrectFacilityList(); if (correctFacilityList != null && correctFacilityList.Count > 0) { List list; if (EmpireLifeModeManager.TryGetMaidListOfEventDataBodyTypeEquals(data, this.GetNotAllocatedMaidList(this.lifeModeAllMaidList), out list)) { Facility facility = correctFacilityList[UnityEngine.Random.Range(0, correctFacilityList.Count)]; this.CreateAndCacheEvent(data, facility, list); if (!this.nowMaidAllocationDic.ContainsKey(facility)) { this.nowMaidAllocationDic.Add(facility, new List()); } this.nowMaidAllocationDic[facility].AddRange(list); break; } } } } } } public void CreateRandomEventOfNowState() { Debug.Log("イベント基準で何かしらのイベントを作成します。"); List datas = EmpireLifeModeData.GetDatas((EmpireLifeModeData.Data data) => data.IsCorrectUniqueComparisonObject() && data.dataScenarioType != EmpireLifeModeData.ScenarioType.スト\u30FCリ\u30FC && data.dataMaidPersonalUniqueNameAndActiveSlotDic.Count > 1 && !this.nowEventList.Exists((EmpireLifeModeManager.EventDataObject d) => d.targetEvent.ID == data.ID) && !this.executedEventList.Exists((EmpireLifeModeManager.EventDataObject d) => d.targetEvent.ID == data.ID), true); IOrderedEnumerable orderedEnumerable = from d in datas orderby d.dataMaidPersonalUniqueNameAndActiveSlotDic.Count descending, this.GetScenarioExecuteCount(d.ID) select d; foreach (EmpireLifeModeData.Data data2 in orderedEnumerable) { List correctFacilityList = data2.GetCorrectFacilityList(); foreach (KeyValuePair> keyValuePair in this.nowMaidAllocationDic) { if (correctFacilityList.Contains(keyValuePair.Key) && 3 - keyValuePair.Value.Count < data2.dataMaidPersonalUniqueNameAndActiveSlotDic.Count) { correctFacilityList.Remove(keyValuePair.Key); } } if (correctFacilityList != null && correctFacilityList.Count > 0) { List list; if (EmpireLifeModeManager.TryGetMaidListOfEventDataBodyTypeEquals(data2, this.GetNotAllocatedMaidList(this.lifeModeAllMaidList), out list)) { Facility facility = correctFacilityList[UnityEngine.Random.Range(0, correctFacilityList.Count)]; this.CreateAndCacheEvent(data2, facility, list); if (!this.nowMaidAllocationDic.ContainsKey(facility)) { this.nowMaidAllocationDic.Add(facility, new List()); } this.nowMaidAllocationDic[facility].AddRange(list); break; } } } } public void AllMaidRandomAllocate() { Dictionary dictionary = new Dictionary(); foreach (Facility key in EmpireLifeModeAPI.GetEnabledFacilityList()) { int num = 0; if (!this.nowMaidAllocationDic.ContainsKey(key)) { this.nowMaidAllocationDic.Add(key, new List()); } else if (this.nowMaidAllocationDic[key] != null) { num = this.nowMaidAllocationDic[key].Count; } else { num = 0; } if (num < 3) { if (!dictionary.ContainsKey(key)) { dictionary.Add(key, num); } } } List notAllocatedMaidList = this.GetNotAllocatedMaidList(this.lifeModeAllMaidList); from maid in notAllocatedMaidList orderby UnityEngine.Random.Range(0, 100) select maid; foreach (Maid item in notAllocatedMaidList) { List list = new List(dictionary.Keys); List list2 = new List(dictionary.Values); int index = UnityEngine.Random.Range(0, dictionary.Count); this.nowMaidAllocationDic[list[index]].Add(item); Dictionary dictionary2; Facility key2; if (((dictionary2 = dictionary)[key2 = list[index]] = dictionary2[key2] + 1) >= 3) { dictionary.Remove(list[index]); if (dictionary.Count <= 0) { break; } } } } public void CreateEventListOfMaidAllocateData() { foreach (KeyValuePair> keyValuePair in this.nowMaidAllocationDic) { Facility facility = keyValuePair.Key; List list = new List(keyValuePair.Value); foreach (EmpireLifeModeManager.EventDataObject eventDataObject in from d in this.nowEventList where d.targetFacility == facility select d) { foreach (Maid item in eventDataObject.targetMaidList) { list.Remove(item); } } List datas = EmpireLifeModeData.GetDatas((EmpireLifeModeData.Data data) => data.IsCorrectUniqueComparisonObject() && data.dataScenarioType != EmpireLifeModeData.ScenarioType.スト\u30FCリ\u30FC && data.IsCorrectFacility(facility.defaultName) && data.IsCorrectScenarioAnyNumberPlay(), true); IOrderedEnumerable source = from d in datas orderby d.dataMaidPersonalUniqueNameAndActiveSlotDic.Count descending select d; if (EmpireLifeModeManager.<>f__mg$cache0 == null) { EmpireLifeModeManager.<>f__mg$cache0 = new Func(EmpireLifeModeAPI.GetPriorityScenarioType); } IOrderedEnumerable orderedEnumerable = source.ThenByDescending(EmpireLifeModeManager.<>f__mg$cache0); Dictionary eventSelectCountDic = new Dictionary(); foreach (EmpireLifeModeData.Data data3 in orderedEnumerable) { eventSelectCountDic.Add(data3.ID, 0); } while (list.Count > 0) { bool flag = false; foreach (EmpireLifeModeData.Data data2 in orderedEnumerable.ThenBy((EmpireLifeModeData.Data d) => eventSelectCountDic[d.ID]).ThenBy((EmpireLifeModeData.Data d) => UnityEngine.Random.Range(0, 10))) { List list2; if (EmpireLifeModeManager.TryGetMaidListOfEventDataBodyTypeEquals(data2, list, out list2)) { this.CreateAndCacheEvent(data2, facility, list2); Dictionary eventSelectCountDic2; int id; (eventSelectCountDic2 = eventSelectCountDic)[id = data2.ID] = eventSelectCountDic2[id] + 1; flag = true; foreach (Maid item2 in list2) { list.Remove(item2); } if (list.Count == 0) { break; } } } if (!flag) { break; } } } } public void DeleteNowEventList() { this.nowEventList.Clear(); this.nowMaidAllocationDic.Clear(); } public void OnTimeZoneChanged() { this.nowEventList.Clear(); this.nowMaidAllocationDic.Clear(); this.executedEventList.Clear(); this.executedMaidList.Clear(); this.UpdateAllMaidList(); EmpireLifeModeAPI.DestroyScenarioTypeIconDic(); } public void OnNextDay() { this.nowEventList.Clear(); this.nowMaidAllocationDic.Clear(); this.executedEventList.Clear(); this.executedMaidList.Clear(); } public void SetupScenarioEvent(EmpireLifeModeManager.EventDataObject eventObj, Action OnComplete) { base.StartCoroutine(this.CoSetupScenarioEvent(eventObj, OnComplete)); GameMain.Instance.ScriptMgr.EvalScript("&tf['scenario_file_name'] = '" + eventObj.targetEvent.dataScenarioFileName + "';"); GameMain.Instance.ScriptMgr.EvalScript("&tf['label_name'] = '" + eventObj.targetEvent.dataScenarioFileLabel + "';"); this.nowEventList.Remove(eventObj); this.executedEventList.Add(eventObj); foreach (Maid maid in eventObj.targetMaidList) { this.IncrementMaidScenarioExecuteCount(eventObj.targetEvent.ID, maid); } foreach (Maid item in eventObj.targetMaidList) { this.executedMaidList.Add(item); } } private IEnumerator CoSetupScenarioEvent(EmpireLifeModeManager.EventDataObject eventObj, Action OnComplete) { EmpireLifeModeData.Data data = eventObj.targetEvent; List targetMaidList = new List(eventObj.targetMaidList); foreach (KeyValuePair maidPersonalSlotPair in data.dataMaidPersonalUniqueNameAndActiveSlotDic) { int slotNo = maidPersonalSlotPair.Key; string personalUniqueName = maidPersonalSlotPair.Value; Maid maid = targetMaidList.Find((Maid m) => m.status.personal.uniqueName == personalUniqueName); targetMaidList.Remove(maid); GameMain.Instance.CharacterMgr.SetActiveMaid(maid, slotNo); maid.Visible = true; maid.AllProcPropSeqStart(); while (maid.IsBusy) { yield return null; } if (data.dataFacilityCostumeChange) { if (eventObj.targetFacility.typeCostume == Facility.CostumeType.Default) { eventObj.targetFacility.UpdateMaidCostumeToDefaultCostume(maid); } else if (eventObj.targetFacility.typeCostume == Facility.CostumeType.Edit) { eventObj.targetFacility.UpdateMaidCostumeToEditCostume(maid, false); } } maid.AllProcPropSeqStart(); } for (;;) { bool isAllMaidLoadComplete = true; foreach (Maid maid2 in eventObj.targetMaidList) { if (maid2.IsBusy) { isAllMaidLoadComplete = false; break; } } if (isAllMaidLoadComplete) { break; } yield return null; } if (OnComplete != null) { OnComplete(); } yield break; } private static bool TryGetMaidListOfEventData(EmpireLifeModeData.Data data, IEnumerable maidList, out List resultList) { resultList = new List(); List list = new List(data.dataMaidPersonalUniqueNameAndActiveSlotDic.Values); List list2 = new List(maidList); if (list.Count > list2.Count) { return false; } foreach (string b in list) { Maid maid = null; foreach (Maid maid2 in list2) { if (maid2.status.personal.uniqueName == b && data.IsCorrectMaid(maid2)) { maid = maid2; break; } } if (!(maid != null)) { return false; } resultList.Add(maid); if (resultList.Count == list.Count) { return true; } list2.Remove(maid); } return false; } private static bool TryGetMaidListOfEventDataBodyTypeEquals(EmpireLifeModeData.Data data, IEnumerable maidList, out List resultList) { List list = new List(from d in maidList where !data.dataNewBodyBlock || (data.dataNewBodyBlock && !d.IsCrcBody) select d); if (!data.dataRequestBodyTypeEquals) { return EmpireLifeModeManager.TryGetMaidListOfEventData(data, list, out resultList); } if (data.dataMaidPersonalUniqueNameAndActiveSlotDic.Count == 1) { return EmpireLifeModeManager.TryGetMaidListOfEventData(data, list, out resultList); } if (EmpireLifeModeManager.TryGetMaidListOfEventData(data, from d in list where d.IsCrcBody select d, out resultList)) { return true; } return EmpireLifeModeManager.TryGetMaidListOfEventData(data, from d in list where !d.IsCrcBody select d, out resultList); } public List GetNotAllocatedMaidList(List maidList) { List list = new List(); if (maidList == null || maidList.Count <= 0) { return list; } for (int i = maidList.Count - 1; i >= 0; i--) { if (!this.executedMaidList.Contains(maidList[i])) { if (!this.IsAllocatedMaid(maidList[i])) { list.Add(maidList[i]); } } } return list; } public bool IsAllocatedMaid(Maid maid) { NDebug.Assert(maid != null, "判定するキャラクターにnullが指定されました"); foreach (EmpireLifeModeManager.EventDataObject eventDataObject in this.nowEventList) { if (eventDataObject.targetMaidList != null && eventDataObject.targetMaidList.Contains(maid)) { return true; } } return false; } private DataArray CreateMaidDataArray(Maid maid) { NDebug.AssertNull(maid); string guid = maid.status.guid; if (this.m_SaveDataMaidScenarioExecuteCountArray.ContainsKey(guid)) { return this.m_SaveDataMaidScenarioExecuteCountArray[guid]; } DataArray dataArray = new DataArray(); this.m_SaveDataMaidScenarioExecuteCountArray.Add(guid, dataArray); Debug.LogFormat("メイド「{0}」の情報を作成しました。", new object[] { maid.status.fullNameJpStyle }); return dataArray; } public int GetMaidScenarioExecuteCount(int eventID, Maid maid) { NDebug.AssertNull(maid); string guid = maid.status.guid; if (!this.m_SaveDataMaidScenarioExecuteCountArray.ContainsKey(guid)) { return 0; } return (int)this.m_SaveDataMaidScenarioExecuteCountArray[guid].Get(eventID, false); } private void IncrementMaidScenarioExecuteCount(int eventID, Maid maid) { NDebug.AssertNull(maid); string guid = maid.status.guid; DataArray dataArray = this.CreateMaidDataArray(maid); byte b = dataArray.Get(eventID, false); if (b < 255) { b += 1; } dataArray.Add(eventID, b, true); this.m_SaveDataScenarioExecuteCountArray.Add(eventID, b, true); } public int GetScenarioExecuteCount(int eventID) { if (!this.m_SaveDataScenarioExecuteCountArray.Contains(eventID)) { return 0; } return (int)this.m_SaveDataScenarioExecuteCountArray.Get(eventID, false); } public bool Serialize(BinaryWriter brWrite) { brWrite.Write("CM3D21_LIFE_MODE_MGR"); brWrite.Write(1570); brWrite.Write("2"); DataArray saveDataScenarioExecuteCountArray = this.m_SaveDataScenarioExecuteCountArray; if (EmpireLifeModeManager.<>f__mg$cache1 == null) { EmpireLifeModeManager.<>f__mg$cache1 = new Converter(Util.GetBytes); } saveDataScenarioExecuteCountArray.Serialize(brWrite, EmpireLifeModeManager.<>f__mg$cache1, (byte data) => new byte[] { data }); int count = this.m_SaveDataMaidScenarioExecuteCountArray.Count; brWrite.Write(count); foreach (KeyValuePair> keyValuePair in this.m_SaveDataMaidScenarioExecuteCountArray) { brWrite.Write(keyValuePair.Key); DataArray value = keyValuePair.Value; if (EmpireLifeModeManager.<>f__mg$cache2 == null) { EmpireLifeModeManager.<>f__mg$cache2 = new Converter(Util.GetBytes); } value.Serialize(brWrite, EmpireLifeModeManager.<>f__mg$cache2, (byte data) => new byte[] { data }); } List list = new List(); foreach (Maid maid in this.lifeModeAllMaidList) { if (maid != null) { list.Add(maid.status.guid); } } brWrite.Write(list.Count); foreach (string value2 in list) { brWrite.Write(value2); } return true; } public bool Deserialize(BinaryReader brRead) { this.m_SaveDataScenarioExecuteCountArray.Clear(); this.m_SaveDataMaidScenarioExecuteCountArray.Clear(); if (brRead.BaseStream.Length <= brRead.BaseStream.Position + 1L) { Debug.Log("LifeMode\nこれ以上は読めない"); return false; } long position = brRead.BaseStream.Position; string text = brRead.ReadString(); if (text != "CM3D21_LIFE_MODE_MGR") { Debug.Log("LifeMode\nヘッダー取得に失敗しました。\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 && 100 > num3) { num2 = num3; } else { num2 = 0; brRead.BaseStream.Seek(position, SeekOrigin.Begin); } } if (num2 <= 1) { if (EmpireLifeModeManager.<>f__mg$cache3 == null) { EmpireLifeModeManager.<>f__mg$cache3 = new Func(Util.ToInt32); } Func func_read_key = EmpireLifeModeManager.<>f__mg$cache3; if (EmpireLifeModeManager.<>f__mg$cache4 == null) { EmpireLifeModeManager.<>f__mg$cache4 = new Func(Util.ToInt32); } DataArray.Skip(brRead, func_read_key, EmpireLifeModeManager.<>f__mg$cache4); } else { DataArray saveDataScenarioExecuteCountArray = this.m_SaveDataScenarioExecuteCountArray; if (EmpireLifeModeManager.<>f__mg$cache5 == null) { EmpireLifeModeManager.<>f__mg$cache5 = new Func(Util.ToInt32); } Func func_read_key2 = EmpireLifeModeManager.<>f__mg$cache5; if (EmpireLifeModeManager.<>f__mg$cache6 == null) { EmpireLifeModeManager.<>f__mg$cache6 = new Func(Util.ToByte); } saveDataScenarioExecuteCountArray.Deserialize(brRead, func_read_key2, EmpireLifeModeManager.<>f__mg$cache6); int num4 = brRead.ReadInt32(); for (int i = 0; i < num4; i++) { string text3 = brRead.ReadString(); Maid stockMaid = GameMain.Instance.CharacterMgr.GetStockMaid(text3); if (stockMaid == null) { Debug.LogFormat("■GUID「{0}」のメイドは存在しなかったので、このメイドの情報は読み飛ばします", new object[] { text3 }); if (EmpireLifeModeManager.<>f__mg$cache7 == null) { EmpireLifeModeManager.<>f__mg$cache7 = new Func(Util.ToInt32); } Func func_read_key3 = EmpireLifeModeManager.<>f__mg$cache7; if (EmpireLifeModeManager.<>f__mg$cache8 == null) { EmpireLifeModeManager.<>f__mg$cache8 = new Func(Util.ToByte); } DataArray.Skip(brRead, func_read_key3, EmpireLifeModeManager.<>f__mg$cache8); } else { DataArray dataArray = this.CreateMaidDataArray(stockMaid); DataArray dataArray2 = dataArray; if (EmpireLifeModeManager.<>f__mg$cache9 == null) { EmpireLifeModeManager.<>f__mg$cache9 = new Func(Util.ToInt32); } Func func_read_key4 = EmpireLifeModeManager.<>f__mg$cache9; if (EmpireLifeModeManager.<>f__mg$cacheA == null) { EmpireLifeModeManager.<>f__mg$cacheA = new Func(Util.ToByte); } dataArray2.Deserialize(brRead, func_read_key4, EmpireLifeModeManager.<>f__mg$cacheA); } } List list = new List(); num4 = brRead.ReadInt32(); for (int j = 0; j < num4; j++) { string guid = brRead.ReadString(); Maid stockMaid2 = GameMain.Instance.CharacterMgr.GetStockMaid(guid); if (stockMaid2 != null) { list.Add(stockMaid2); } } this.SetAllMaidList(list); } return true; } private const int MAX_COUNT_MAID_ALLOCATE = 3; private List m_EventList = new List(); private Dictionary> m_NowMaidAllocationDic = new Dictionary>(); private List m_ExecutedEventList = new List(); private List m_LifeModeAllMaidList = new List(); private List m_ExecutedMaidList = new List(); private Dictionary> m_SaveDataMaidScenarioExecuteCountArray = new Dictionary>(); private DataArray m_SaveDataScenarioExecuteCountArray = new DataArray(); private const string STR_LOG_HEAD = "LifeMode\n"; private const string STR_LIFE_MODE_SERIALIZE_HEADER = "CM3D21_LIFE_MODE_MGR"; private const string STR_LIFE_MODE_SERIALIZE_VER = "2"; [CompilerGenerated] private static Func <>f__mg$cache0; [CompilerGenerated] private static Converter <>f__mg$cache1; [CompilerGenerated] private static Converter <>f__mg$cache2; [CompilerGenerated] private static Func <>f__mg$cache3; [CompilerGenerated] private static Func <>f__mg$cache4; [CompilerGenerated] private static Func <>f__mg$cache5; [CompilerGenerated] private static Func <>f__mg$cache6; [CompilerGenerated] private static Func <>f__mg$cache7; [CompilerGenerated] private static Func <>f__mg$cache8; [CompilerGenerated] private static Func <>f__mg$cache9; [CompilerGenerated] private static Func <>f__mg$cacheA; public class EventDataObject { public Facility targetFacility { get; set; } public EmpireLifeModeData.Data targetEvent { get; set; } public List targetMaidList; } }