123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- 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<DataBase.Data> GetAllDatas(bool onlyEnabled)
- {
- DataBase.CreateData();
- List<DataBase.Data> list = new List<DataBase.Data>();
- foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair in DataBase.commonIdManager.idMap)
- {
- if (!onlyEnabled || DataBase.commonIdManager.enabledIdList.Contains(keyValuePair.Key))
- {
- list.Add(DataBase.basicDatas[keyValuePair.Key]);
- }
- }
- return list;
- }
- public static List<DataBase.BG> GetAllBGDatas()
- {
- DataBase.CreateData();
- return new List<DataBase.BG>(DataBase.bgDatas.Values);
- }
- public static DataBase.BG GetBGData(string uniqueNameBG)
- {
- DataBase.CreateData();
- foreach (KeyValuePair<string, DataBase.BG> 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<int, DataBase.Data>();
- string[] array = new string[]
- {
- "list"
- };
- KeyValuePair<AFileBase, CsvParser>[] array2 = new KeyValuePair<AFileBase, CsvParser>[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>(afileBase, csvParser);
- }
- Dictionary<string, DataBase.BG.Event[]> dictionary = new Dictionary<string, DataBase.BG.Event[]>();
- 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(j, csvParser2, ref key);
- if (!dictionary.ContainsKey(key))
- {
- dictionary.Add(key, new DataBase.BG.Event[2]);
- }
- dictionary[key][(!@event.isNoon) ? 1 : 0] = @event;
- }
- }
- }
- Dictionary<string, List<DataBase.BG.Location>> dictionary2 = new Dictionary<string, List<DataBase.BG.Location>>();
- foreach (KeyValuePair<int, KeyValuePair<string, string>> 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<DataBase.BG.Location>());
- }
- List<DataBase.BG.Location> list = dictionary2[key3];
- list.Add(item);
- }
- Dictionary<string, DataBase.BG> dictionary3 = new Dictionary<string, DataBase.BG>();
- 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<int, KeyValuePair<string, string>> 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<AFileBase, CsvParser> keyValuePair3 in array2)
- {
- keyValuePair3.Value.Dispose();
- keyValuePair3.Key.Dispose();
- }
- }
- 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 static CsvCommonIdManager commonIdManager;
- private static Dictionary<int, DataBase.Data> basicDatas;
- private static Dictionary<string, DataBase.BG> bgDatas;
- public class BG
- {
- public BG(int lineY, CsvParser basicCsv, Dictionary<string, List<DataBase.BG.Location>> locationList, Dictionary<string, DataBase.BG.Event[]> 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<int> list = new List<int>();
- 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);
- @event.ShuffleEventPlayOrder();
- }
- }
- }
- }
- 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(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";
- }
- List<DataBase.BG.Event.PointData> list = new List<DataBase.BG.Event.PointData>();
- for (int i = num; i < basicCsv.max_cell_x; i++)
- {
- int no = i - num + 1;
- string cellAsString = basicCsv.GetCellAsString(i, lineY);
- if (!string.IsNullOrEmpty(cellAsString))
- {
- List<string> list2 = new List<string>();
- foreach (string text in cellAsString.Split(new char[]
- {
- '/'
- }))
- {
- list2.Add(text.Trim());
- }
- list.Add(new DataBase.BG.Event.PointData(no, list2));
- }
- }
- this.eventPointList = list.ToArray();
- }
- public DataBase.BG parentBg { get; private set; }
- 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)
- {
- int hashCode = eventData.GetHashCode();
- if (!this.scenarioIndexDictionary.ContainsKey(hashCode))
- {
- this.scenarioIndexDictionary.Add(hashCode, 0);
- }
- ScriptManager scriptMgr = GameMain.Instance.ScriptMgr;
- string str = this.eventScriptFile;
- if (maid != null)
- {
- str = ScriptManager.ReplacePersonal(maid, this.eventScriptFile);
- }
- int num = this.scenarioIndexDictionary[hashCode];
- if (eventData.labelList.Count <= num)
- {
- num = 0;
- }
- if (maid != null && this.lastMaidGuid != maid.status.guid)
- {
- num = 0;
- this.lastMaidGuid = maid.status.guid;
- }
- GameMain.Instance.ScriptMgr.EvalScript("global.__private_maid_mode_adv_file = '" + str + "';");
- GameMain.Instance.ScriptMgr.EvalScript("global.__private_maid_mode_adv_label = '" + eventData.labelList[num++] + "';");
- this.scenarioIndexDictionary[hashCode] = num;
- scriptMgr.LoadAdvScenarioScript("private_maid_mode_adv_call.ks", "*ADVスタート");
- scriptMgr.adv_kag.Exec();
- return true;
- }
- return false;
- }
- public void ShuffleEventPlayOrder()
- {
- }
- public void SetParentBg(DataBase.BG parentBg)
- {
- this.parentBg = parentBg;
- }
- public readonly bool isNoon;
- public readonly string hitPrefabPath;
- public readonly string eventScriptFile;
- public readonly DataBase.BG.Event.PointData[] eventPointList;
- private Dictionary<int, int> scenarioIndexDictionary = new Dictionary<int, int>();
- private string lastMaidGuid = string.Empty;
- public class PointData
- {
- public PointData(int no, List<string> labelList)
- {
- this.no = no;
- this.labelList = labelList;
- }
- public List<string> labelList { get; private set; }
- public void ShuffleLabel()
- {
- string[] array = this.labelList.ToArray();
- System.Random random = new System.Random();
- int i = array.Length;
- while (i > 1)
- {
- i--;
- int num = random.Next(i + 1);
- string text = array[num];
- array[num] = array[i];
- array[i] = text;
- }
- this.labelList = new List<string>(array);
- }
- public readonly int no;
- }
- }
- }
- public class Data
- {
- public Data(int uniqueId, CsvParser basicCsv, Dictionary<string, DataBase.BG> 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;
- }
- }
- }
|