using System; using System.Collections.Generic; using System.IO; using MaidStatus; using UnityEngine; using wf; namespace PrivateMaidMode { public static class DataBase { public static int Count { get { DataBase.CreateData(); return DataBase.commonIdManager.idMap.Count; } } public static bool Contains(int id) { return DataBase.commonIdManager.idMap.ContainsKey(id); } public static DataBase.Data GetData(int id) { DataBase.CreateData(); NDebug.Assert(DataBase.basicDatas.ContainsKey(id), "プライベートメイドモード\nID[" + id + "]のデータは存在しません"); return DataBase.basicDatas[id]; } public static bool IsEnabled(int id) { DataBase.CreateData(); return DataBase.commonIdManager.enabledIdList.Contains(id); } public static List GetAllDatas(bool onlyEnabled) { DataBase.CreateData(); List list = new List(); foreach (KeyValuePair> keyValuePair in DataBase.commonIdManager.idMap) { if (!onlyEnabled || DataBase.commonIdManager.enabledIdList.Contains(keyValuePair.Key)) { list.Add(DataBase.basicDatas[keyValuePair.Key]); } } return list; } public static List GetAllBGDatas() { DataBase.CreateData(); return new List(DataBase.bgDatas.Values); } public static DataBase.BG GetBGData(string uniqueNameBG) { DataBase.CreateData(); foreach (KeyValuePair keyValuePair in DataBase.bgDatas) { if (keyValuePair.Key == uniqueNameBG) { return keyValuePair.Value; } } return null; } public static void CreateData() { if (DataBase.commonIdManager != null) { return; } DataBase.commonIdManager = new CsvCommonIdManager("private_maidmode_group", "プライベートメイドモード", CsvCommonIdManager.Type.IdOnly, null); DataBase.basicDatas = new Dictionary(); string[] array = new string[] { "list" }; KeyValuePair[] array2 = new KeyValuePair[array.Length]; for (int i = 0; i < array2.Length; i++) { string text = "private_maidmode_group_" + array[i] + ".nei"; AFileBase afileBase = GameUty.FileSystem.FileOpen(text); CsvParser csvParser = new CsvParser(); bool condition = csvParser.Open(afileBase); NDebug.Assert(condition, text + "\nopen failed."); array2[i] = new KeyValuePair(afileBase, csvParser); } Dictionary>> eventInfoDatabase = DataBase.LoadPointInformation(); Dictionary dictionary = new Dictionary(); using (AFileBase afileBase2 = GameUty.FileSystem.FileOpen("private_maidmode_event_list.nei")) { using (CsvParser csvParser2 = new CsvParser()) { csvParser2.Open(afileBase2); NDebug.Assert(csvParser2.IsValid(), "private_maidmode_event_list.nei\nopen failed."); for (int j = 1; j < csvParser2.max_cell_y; j++) { string key; DataBase.BG.Event @event = new DataBase.BG.Event(eventInfoDatabase, j, csvParser2, ref key); if (!dictionary.ContainsKey(key)) { dictionary.Add(key, new DataBase.BG.Event[2]); } dictionary[key][(!@event.isNoon) ? 1 : 0] = @event; } } } Dictionary> dictionary2 = new Dictionary>(); foreach (KeyValuePair> keyValuePair in DataBase.commonIdManager.idMap) { int key2 = keyValuePair.Key; string key3; DataBase.BG.Location item = new DataBase.BG.Location(key2, array2[0].Value, ref key3); if (!dictionary2.ContainsKey(key3)) { dictionary2.Add(key3, new List()); } List list = dictionary2[key3]; list.Add(item); } Dictionary dictionary3 = new Dictionary(); using (AFileBase afileBase3 = GameUty.FileSystem.FileOpen("private_maidmode_bg_list.nei")) { using (CsvParser csvParser3 = new CsvParser()) { csvParser3.Open(afileBase3); NDebug.Assert(csvParser3.IsValid(), "private_maidmode_bg_list.nei\nopen failed."); for (int k = 1; k < csvParser3.max_cell_y; k++) { DataBase.BG bg = new DataBase.BG(k, csvParser3, dictionary2, dictionary); dictionary3.Add(bg.uniqueName, bg); } } } DataBase.bgDatas = dictionary3; foreach (KeyValuePair> keyValuePair2 in DataBase.commonIdManager.idMap) { int key4 = keyValuePair2.Key; DataBase.Data value = new DataBase.Data(key4, array2[0].Value, dictionary3); DataBase.basicDatas.Add(key4, value); } foreach (KeyValuePair keyValuePair3 in array2) { keyValuePair3.Value.Dispose(); keyValuePair3.Key.Dispose(); } } private static Dictionary>> LoadPointInformation() { Dictionary>> dictionary = new Dictionary>>(); Dictionary dictionary2 = new Dictionary(); using (AFileBase afileBase = GameUty.FileSystem.FileOpen("private_maidmode_eventinformation_list.nei")) { using (CsvParser csvParser = new CsvParser()) { csvParser.Open(afileBase); NDebug.Assert(csvParser.IsValid(), "private_maidmode_eventinformation_list.nei\nopen failed."); for (int i = 1; i < csvParser.max_cell_y; i++) { int num = 0; int cellAsInteger = csvParser.GetCellAsInteger(num++, i); string cellAsString = csvParser.GetCellAsString(num++, i); string cellAsString2 = csvParser.GetCellAsString(num++, i); string a = csvParser.GetCellAsString(num++, i).ToLower(); DataBase.BG.Event.PointData.Information.IconType iconType = DataBase.BG.Event.PointData.Information.IconType.Normal; if (a == "h") { iconType = DataBase.BG.Event.PointData.Information.IconType.H; } else if (a == "n") { iconType = DataBase.BG.Event.PointData.Information.IconType.NTR; } if (dictionary2.ContainsKey(cellAsInteger)) { NDebug.Assert("csv parse error.\nprivate_maidmode_eventinformation_list.nei", false); } dictionary2.Add(cellAsInteger, new DataBase.BG.Event.PointData.Information(cellAsString, new List(cellAsString2.Split(new char[] { '|' })), iconType)); } } } using (AFileBase afileBase2 = GameUty.FileSystem.FileOpen("private_maidmode_eventlink_list.nei")) { using (CsvParser csvParser2 = new CsvParser()) { csvParser2.Open(afileBase2); NDebug.Assert(csvParser2.IsValid(), "private_maidmode_eventlink_list.nei\nopen failed."); for (int j = 1; j < csvParser2.max_cell_y; j++) { int cell_x = 0; string cellAsString3 = csvParser2.GetCellAsString(cell_x++, j); string cellAsString4 = csvParser2.GetCellAsString(cell_x++, j); while (csvParser2.IsCellToExistData(cell_x, j)) { string cellAsString5 = csvParser2.GetCellAsString(cell_x++, j); List list = new List(); if (!string.IsNullOrEmpty(cellAsString5)) { foreach (string s in cellAsString5.Split(new char[] { '/' })) { int item = 0; if (int.TryParse(s, out item)) { list.Add(item); } else { NDebug.Assert("csv parse error.\nprivate_maidmode_eventlink_list.nei", false); } } } if (!dictionary.ContainsKey(cellAsString3)) { dictionary.Add(cellAsString3, new List>()); for (int l = 0; l < 2; l++) { dictionary[cellAsString3].Add(new List()); } } List list2 = new List(); foreach (int key in list) { if (!dictionary2.ContainsKey(key)) { NDebug.Assert("csv parse error.\nprivate_maidmode_eventlink_list.nei", false); } list2.Add(dictionary2[key]); } dictionary[cellAsString3][(!(cellAsString4 == "昼")) ? 1 : 0].Add(list2.ToArray()); } } } } return dictionary; } private const string csvTopCommonName = "private_maidmode_group"; private const string typeNameForErrorLog = "プライベートメイドモード"; private const string bgDefineFileName = "private_maidmode_bg_list.nei"; private const string eventDefineFileName = "private_maidmode_event_list.nei"; private const string eventLinkFileName = "private_maidmode_eventlink_list.nei"; private const string eventInformationFileName = "private_maidmode_eventinformation_list.nei"; private static CsvCommonIdManager commonIdManager; private static Dictionary basicDatas; private static Dictionary bgDatas; public class BG { public BG(int lineY, CsvParser basicCsv, Dictionary> locationList, Dictionary eventList) { if (!basicCsv.IsCellToExistData(0, lineY)) { return; } int num = 0; this.uniqueName = basicCsv.GetCellAsString(num++, lineY); this.drawName = basicCsv.GetCellAsString(num++, lineY); string cellAsString = basicCsv.GetCellAsString(num++, lineY); List list = new List(); if (!string.IsNullOrEmpty(cellAsString)) { foreach (string text in cellAsString.Split(new char[] { ',' })) { int minValue = int.MinValue; if (int.TryParse(text.Trim(), out minValue)) { list.Add(minValue); } } } this.requestFacilityId = list.ToArray(); this.prefabName = new string[2]; this.prefabName[0] = basicCsv.GetCellAsString(num++, lineY); this.prefabName[1] = basicCsv.GetCellAsString(num++, lineY); if (locationList != null && locationList.ContainsKey(this.uniqueName)) { this.locations = locationList[this.uniqueName].ToArray(); foreach (DataBase.BG.Location location in this.locations) { if (location != null) { location.SetParentBg(this); } } } if (eventList != null && eventList.ContainsKey(this.uniqueName) && eventList[this.uniqueName] != null) { this.events = eventList[this.uniqueName]; foreach (DataBase.BG.Event @event in this.events) { if (@event != null) { @event.SetParentBg(this); } } } } public bool enabled { get { if (this.requestFacilityId == null || this.requestFacilityId.Length <= 0) { return true; } FacilityManager facilityManager = (!(GameMain.Instance != null)) ? null : GameMain.Instance.FacilityMgr; if (facilityManager != null) { foreach (int facilityTypeID in this.requestFacilityId) { Facility[] array2; if (facilityManager.IsExistTypeFacility(facilityTypeID, out array2)) { return true; } } } return false; } } public string drawNameTerm { get { return string.Empty; } } public DataBase.BG.Location GetLocation(string locationName) { foreach (DataBase.BG.Location location in this.locations) { if (location != null && location.drawName == locationName) { return location; } } return null; } public DataBase.BG.Event GetEvent(bool isNoon) { return (this.events != null && this.events.Length != 0) ? this.events[(!isNoon) ? 1 : 0] : null; } public void Apply(bool isNoon) { if (GameMain.Instance != null && GameMain.Instance.BgMgr != null) { GameMain.Instance.BgMgr.ChangeBg(this.prefabName[(!isNoon) ? 1 : 0]); } } public readonly string uniqueName; public readonly string drawName; public readonly int[] requestFacilityId; public readonly string[] prefabName; public readonly DataBase.BG.Location[] locations; public readonly DataBase.BG.Event[] events; public class Location { public Location(int uniqueId, CsvParser basicCsv, out string uniqueBgName) { uniqueBgName = string.Empty; for (int i = 1; i < basicCsv.max_cell_y; i++) { if (basicCsv.IsCellToExistData(0, i) && basicCsv.GetCellAsInteger(0, i) == uniqueId) { int num = 1; uniqueBgName = basicCsv.GetCellAsString(num++, i); this.drawName = basicCsv.GetCellAsString(num++, i); this.fileName = basicCsv.GetCellAsString(num++, i); if (!Path.HasExtension(this.fileName)) { this.fileName += ".ks"; } this.labelName = basicCsv.GetCellAsString(num++, i); break; } } } public DataBase.BG parentBg { get; private set; } public string drawNameTerm { get { return string.Empty; } } public void SetParentBg(DataBase.BG parentBg) { this.parentBg = parentBg; } public bool LoadScript() { if (!string.IsNullOrEmpty(this.labelName) && GameMain.Instance != null && GameMain.Instance.ScriptMgr != null) { ScriptManager scriptMgr = GameMain.Instance.ScriptMgr; scriptMgr.tmp_kag.LoadScriptFile(this.fileName, this.labelName); scriptMgr.tmp_kag.enabled = true; scriptMgr.tmp_kag.Exec(); scriptMgr.tmp_kag.enabled = false; return true; } return false; } public readonly string drawName; public readonly string fileName; public readonly string labelName; } public class Event { public Event(Dictionary>> eventInfoDatabase, int lineY, CsvParser basicCsv, out string uniqueBgName) { uniqueBgName = string.Empty; if (!basicCsv.IsCellToExistData(0, lineY)) { return; } int num = 0; uniqueBgName = basicCsv.GetCellAsString(num++, lineY); this.isNoon = (basicCsv.GetCellAsString(num++, lineY) == "昼"); this.hitPrefabPath = basicCsv.GetCellAsString(num++, lineY); this.eventScriptFile = basicCsv.GetCellAsString(num++, lineY); if (!Path.HasExtension(this.eventScriptFile)) { this.eventScriptFile += ".ks"; } if (!eventInfoDatabase.ContainsKey(uniqueBgName)) { NDebug.Assert(this.ToString() + "生成エラー", false); } List list = eventInfoDatabase[uniqueBgName][(!this.isNoon) ? 1 : 0]; List list2 = new List(); for (int i = num; i < basicCsv.max_cell_x; i++) { int num2 = i - num + 1; string text = basicCsv.GetCellAsString(i, lineY); if (!string.IsNullOrEmpty(text)) { List list3 = new List(); if (text.IndexOf("|") != -1) { string[] array = text.Split(new char[] { '|' }); text = array[0]; string text2 = array[1]; foreach (string text3 in text2.Split(new char[] { ',' })) { list3.Add(text3.Trim()); } } List list4 = new List(); foreach (string text4 in text.Split(new char[] { '/' })) { list4.Add(text4.Trim()); } DataBase.BG.Event.PointData.Information[] array4 = (list.Count > num2 - 1) ? list[num2 - 1] : null; if (array4 == null || list4.Count != array4.Length) { NDebug.Assert(this.ToString() + "生成エラー2", false); } list2.Add(new DataBase.BG.Event.PointData(num2, list4, list3, new List(array4))); } } this.eventPointList = list2.ToArray(); } public DataBase.BG parentBg { get; private set; } public bool IsExec(Maid maid, int pointNo) { Status maidStatus = (!(maid != null)) ? null : maid.status; return this.IsExec(maidStatus, pointNo); } public bool IsExec(Status maidStatus, int pointNo) { DataBase.BG.Event.PointData eventData = this.GetEventData(pointNo); return eventData.IsExec(maidStatus); } public bool IsFinishedReadingFile(Maid maid, DataBase.BG.Event.PointData pointData, int index) { string file_name = this.eventScriptFile; file_name = ScriptManager.ReplacePersonal(maid, this.eventScriptFile); return GameMain.Instance.ScriptMgr.adv_kag.kag.GetRecordLabel(file_name, pointData.labelList[index]); } public GameObject InstantiateHitPrefab(GameObject parent) { GameObject result; try { result = Utility.CreatePrefab(parent, this.hitPrefabPath, true); } catch (Exception exception) { Debug.LogException(exception); result = null; } return result; } public DataBase.BG.Event.PointData GetEventData(int pointNo) { if (this.eventPointList != null) { foreach (DataBase.BG.Event.PointData pointData in this.eventPointList) { if (pointData != null && pointData.no == pointNo) { return pointData; } } } return null; } public bool ContainsEvent(int pointNo) { return this.GetEventData(pointNo) != null; } public bool LoadScript(Maid maid, int pointNo) { DataBase.BG.Event.PointData eventData = this.GetEventData(pointNo); if (eventData != null && GameMain.Instance != null && GameMain.Instance.ScriptMgr != null) { ScriptManager scriptMgr = GameMain.Instance.ScriptMgr; string str = this.eventScriptFile; if (maid != null) { str = ScriptManager.ReplacePersonal(maid, this.eventScriptFile); } int nextScenarioIndex = this.GetNextScenarioIndex(maid, eventData); GameMain.Instance.ScriptMgr.EvalScript("global.__private_maid_mode_adv_file = '" + str + "';"); GameMain.Instance.ScriptMgr.EvalScript("global.__private_maid_mode_adv_label = '" + eventData.labelList[nextScenarioIndex++] + "';"); this.SetScenarioIndex(maid, eventData, nextScenarioIndex); scriptMgr.LoadAdvScenarioScript("private_maid_mode_adv_call.ks", "*ADVスタート"); scriptMgr.adv_kag.Exec(); return true; } return false; } public int GetNextScenarioIndex(Maid maid, DataBase.BG.Event.PointData pointData) { int num = maid.status.GetFlag("__private_maid_mode_scenario_index_" + pointData.no.ToString()); if (pointData.labelList.Count <= num) { num = 0; } return num; } public void SetParentBg(DataBase.BG parentBg) { this.parentBg = parentBg; } private void SetScenarioIndex(Maid maid, DataBase.BG.Event.PointData pointData, int scenarioIndex) { maid.status.SetFlag("__private_maid_mode_scenario_index_" + pointData.no.ToString(), scenarioIndex); } public readonly bool isNoon; public readonly string hitPrefabPath; public readonly string eventScriptFile; public readonly DataBase.BG.Event.PointData[] eventPointList; public class PointData { public PointData(int no, List labelList, List checkMaidFlag, List information) { this.no = no; this.labelList = labelList; this.checkMaidFlag = checkMaidFlag; this.information = information; } public bool IsExec(Maid maid) { return (!(maid != null)) ? this.IsExec(null) : this.IsExec(maid.status); } public bool IsExec(Status maidStatus) { if (this.checkMaidFlag.Count <= 0) { return true; } if (maidStatus == null) { return false; } foreach (string flagName in this.checkMaidFlag) { if (maidStatus.GetFlag(flagName) <= 0) { return false; } } return true; } public readonly int no; public readonly List labelList; public readonly List checkMaidFlag; public readonly List information; public class Information { public Information(string title, List conditions, DataBase.BG.Event.PointData.Information.IconType iconType) { this.title = title; this.conditions = conditions; this.iconType = iconType; } public string titleTerm { get { return this.title; } } public readonly DataBase.BG.Event.PointData pointData; public readonly string title; public readonly List conditions; public readonly DataBase.BG.Event.PointData.Information.IconType iconType; public enum IconType { Normal, H, NTR } } } } } public class Data { public Data(int uniqueId, CsvParser basicCsv, Dictionary bgDataList) { for (int i = 1; i < basicCsv.max_cell_y; i++) { if (basicCsv.IsCellToExistData(0, i) && basicCsv.GetCellAsInteger(0, i) == uniqueId) { int num = 1; this.id = uniqueId; string cellAsString = basicCsv.GetCellAsString(num++, i); this.bgData = bgDataList[cellAsString]; string cellAsString2 = basicCsv.GetCellAsString(num++, i); this.locationData = this.bgData.GetLocation(cellAsString2); break; } } } public readonly int id; public readonly DataBase.BG bgData; public readonly DataBase.BG.Location locationData; } } }