123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using MaidStatus;
- using UnityEngine;
- using wf;
- namespace scoutmode
- {
- public class ScoutManager
- {
- public ScoutManager()
- {
- this.scoutMaidList = new List<ScoutMaidData>();
- }
- public static bool isModeEnabled
- {
- get
- {
- return Product.type == Product.Type.JpAdult && PluginData.IsEnabled("GP001FB") && GameMain.Instance.CharacterMgr.status.GetFlag("借金返済_完済") != 0;
- }
- }
- public static ScoutManager Instance { get; private set; }
- public static ScoutManager CreateInstance()
- {
- if (ScoutManager.Instance == null)
- {
- ScoutManager.Instance = new ScoutManager();
- }
- GameMain instance = GameMain.Instance;
- instance.onFinalizeEvent = (Action)Delegate.Combine(instance.onFinalizeEvent, new Action(ScoutManager.Instance.OnOnFinalize));
- return ScoutManager.Instance;
- }
- public static ScoutManager ReCreateInstance()
- {
- if (ScoutManager.Instance != null)
- {
- ScoutManager.Instance.DeleteAllTempThumbnailFile();
- }
- ScoutManager.Instance = null;
- return ScoutManager.CreateInstance();
- }
- public List<ScoutMaidData> scoutMaidList { get; private set; }
- public ScoutMaidData GetScoutMaid(string guid)
- {
- foreach (ScoutMaidData scoutMaidData in this.scoutMaidList)
- {
- if (guid == scoutMaidData.status.guid || (scoutMaidData.isOverRideData && guid == scoutMaidData.overrideData.guid))
- {
- return scoutMaidData;
- }
- }
- return null;
- }
- public void AddScoutMaid(Maid maid)
- {
- ScoutMaidData scoutMaidData = new ScoutMaidData();
- scoutMaidData.CreateData(maid);
- this.scoutMaidList.Add(scoutMaidData);
- this.scoutMaidList.Sort((ScoutMaidData a, ScoutMaidData b) => a.status.creationTimeNum.CompareTo(b.status.creationTimeNum));
- string guid = scoutMaidData.status.guid;
- string thumbnailDictionary = Maid.ThumbnailDictionary;
- this.RenameFile(Path.Combine(thumbnailDictionary, "_tmp_thum_" + guid + ".png"), ScoutMaidData.GetThumbnailFilePath(guid, true));
- this.RenameFile(Path.Combine(thumbnailDictionary, "icon_thum_" + guid + ".png"), ScoutMaidData.GetIconThumbnailFilePath(guid, true));
- this.RenameFile(Path.Combine(thumbnailDictionary, "_tmp_kasizuki_" + guid + ".png"), ScoutMaidData.GetKasizukiThumbnailFilePath(guid, true));
- }
- public bool CreateRandomScoutMaidData(ScoutMaidData scoutMaid, ScoutOptionData execOptions)
- {
- if (execOptions == null || scoutMaid == null)
- {
- return false;
- }
- scoutMaid.overrideData.Destroy();
- if (execOptions.inheritPersonality && execOptions.inheritSeikeiken && execOptions.inheritMaidPoint)
- {
- return false;
- }
- scoutMaid.overrideData.CreateStatus(scoutMaid.status);
- ScoutMaidOverrideData.Status status = scoutMaid.overrideData.status;
- if (!execOptions.inheritPersonality)
- {
- List<Personal.Data> list = new List<Personal.Data>();
- foreach (Personal.Data data in Personal.GetAllDatas(true))
- {
- if (LockData.personalEnabledIdList.Contains(data.uniqueName))
- {
- string a = data.uniqueName.ToLower();
- if (data.oldPersonal)
- {
- if (a == "pure" || a == "cool" || a == "pride")
- {
- if (GameMain.Instance.CharacterMgr.status.isAvailableTransfer)
- {
- list.Add(data);
- }
- }
- else if (data.single)
- {
- list.Add(data);
- }
- else if (!string.IsNullOrEmpty(GameMain.Instance.CMSystem.CM3D2Path) && data.compatible)
- {
- list.Add(data);
- }
- }
- else
- {
- list.Add(data);
- }
- }
- }
- status.personalId = list[UnityEngine.Random.Range(0, list.Count)].id;
- }
- if (!execOptions.inheritSeikeiken)
- {
- status.seikeiken = (Seikeiken)UnityEngine.Random.Range(0, 4);
- }
- if (!execOptions.inheritMaidPoint)
- {
- status.ClearStatus();
- int num = scoutMaid.status.maidPoint;
- while (0 < num)
- {
- if (!status.AddRandomStatusValue(20))
- {
- for (int i = 0; i < 5; i++)
- {
- if (status.AddRandomStatusValue(20))
- {
- break;
- }
- }
- }
- num--;
- }
- }
- return true;
- }
- public void RemoveScoutMaid(ScoutMaidData scoutMaid)
- {
- this.scoutMaidList.Remove(scoutMaid);
- }
- public bool StartScout(Maid maid, string stageName, ScoutOptionData options)
- {
- ScoutMaidData scoutMaid = this.GetScoutMaid(maid.status.guid);
- if (scoutMaid != null && !scoutMaid.instanceData.enabled)
- {
- scoutMaid.instanceData.Create(maid, stageName, options);
- return true;
- }
- return false;
- }
- public Maid ActiveScoutMaid(ScoutMaidData scoutMaid, int slotNo)
- {
- if (scoutMaid == null)
- {
- return null;
- }
- Maid maid = GameMain.Instance.CharacterMgr.AddStockMaid();
- maid.Visible = true;
- GameMain.Instance.CharacterMgr.SetActiveMaid(maid, slotNo);
- scoutMaid.Apply(maid);
- return maid;
- }
- public bool SuspendedScout(Maid maid)
- {
- if (maid == null || maid.status.GetFlag("__スカウトメイド") != 1)
- {
- return false;
- }
- ScoutMaidData scoutMaid = this.GetScoutMaid(maid.status.guid);
- NDebug.Assert(scoutMaid != null, "スカウトメイドデータの特定ができませんでした");
- scoutMaid.instanceData.Update(maid);
- GameMain.Instance.CharacterMgr.DeactivateMaid(maid);
- GameMain.Instance.CharacterMgr.BanishmentMaid(maid);
- return true;
- }
- public bool CancelScout(Maid maid)
- {
- if (maid == null || maid.status.GetFlag("__スカウトメイド") != 1)
- {
- return false;
- }
- ScoutMaidData scoutMaid = this.GetScoutMaid(maid.status.guid);
- NDebug.Assert(scoutMaid != null, "スカウトメイドデータの特定ができませんでした");
- if (!this.CancelScout(scoutMaid))
- {
- return false;
- }
- GameMain.Instance.CharacterMgr.DeactivateMaid(maid);
- GameMain.Instance.CharacterMgr.BanishmentMaid(maid);
- return true;
- }
- public bool CancelScout(ScoutMaidData scoutMaid)
- {
- if (scoutMaid == null || !scoutMaid.instanceData.enabled)
- {
- return false;
- }
- scoutMaid.overrideData.Destroy();
- scoutMaid.instanceData.Destroy();
- return true;
- }
- public void HireScoutMaid(Maid maid)
- {
- if (maid == null)
- {
- return;
- }
- ScoutMaidData scoutMaid = this.GetScoutMaid(maid.status.guid);
- NDebug.Assert(scoutMaid != null, "スカウトメイドデータの特定ができませんでした");
- maid.status.SetNewGuidAndCreationTime(null, null);
- maid.status.employmentDay = GameMain.Instance.CharacterMgr.status.days;
- byte[] iconImageBinary = scoutMaid.GetIconImageBinary();
- if (iconImageBinary != null)
- {
- Texture2D texture2D = new Texture2D(1, 1, TextureFormat.ARGB32, false);
- texture2D.LoadImage(iconImageBinary);
- maid.SetThumIcon(texture2D);
- }
- foreach (string text in new string[]
- {
- ScoutMaidData.GetThumbnailFilePath(scoutMaid.status.guid, true),
- ScoutMaidData.GetThumbnailFilePath(scoutMaid.status.guid, false)
- })
- {
- string thumbnailFilePath = Maid.GetThumbnailFilePath(maid.status.guid, true);
- if (File.Exists(text) && !File.Exists(thumbnailFilePath))
- {
- File.Copy(text, thumbnailFilePath);
- break;
- }
- }
- foreach (string text2 in new string[]
- {
- ScoutMaidData.GetIconThumbnailFilePath(scoutMaid.status.guid, true),
- ScoutMaidData.GetIconThumbnailFilePath(scoutMaid.status.guid, false)
- })
- {
- string thumbnailFilePath2 = Maid.GetThumbnailFilePath(maid.status.guid, true);
- if (File.Exists(text2) && !File.Exists(thumbnailFilePath2))
- {
- File.Copy(text2, thumbnailFilePath2);
- break;
- }
- }
- foreach (string text3 in new string[]
- {
- ScoutMaidData.GetKasizukiThumbnailFilePath(scoutMaid.status.guid, true),
- ScoutMaidData.GetKasizukiThumbnailFilePath(scoutMaid.status.guid, false)
- })
- {
- string kasizukiThumbnailFilePath = Maid.GetKasizukiThumbnailFilePath(maid.status.guid, true);
- if (File.Exists(text3) && !File.Exists(kasizukiThumbnailFilePath))
- {
- File.Copy(text3, kasizukiThumbnailFilePath);
- break;
- }
- }
- scoutMaid.overrideData.Destroy();
- scoutMaid.instanceData.Destroy();
- if (scoutMaid.instanceData.options.isBaseCharaDelete)
- {
- this.RemoveScoutMaid(scoutMaid);
- }
- GameMain.Instance.CharacterMgr.DeactivateMaid(maid);
- }
- public ScoutMaidData GetRandomWaitingScoutmaid()
- {
- List<ScoutMaidData> list = new List<ScoutMaidData>();
- foreach (ScoutMaidData scoutMaidData in this.scoutMaidList)
- {
- if (!scoutMaidData.instanceData.enabled && !scoutMaidData.isOverRideData)
- {
- list.Add(scoutMaidData);
- }
- }
- return (list.Count <= 0) ? null : list[UnityEngine.Random.Range(0, list.Count)];
- }
- public void Serialize(BinaryWriter bw)
- {
- byte[] array = new byte[0];
- MemoryStream memoryStream = new MemoryStream();
- BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
- int count = this.scoutMaidList.Count;
- binaryWriter.Write(count);
- foreach (ScoutMaidData scoutMaidData in this.scoutMaidList)
- {
- byte[] array2 = scoutMaidData.Serialize();
- binaryWriter.Write(array2.Length);
- binaryWriter.Write(array2);
- }
- array = Utility.ZlibCompresss(memoryStream.ToArray());
- bw.Write(array.Length);
- bw.Write(array);
- bw.Write(JsonUtility.ToJson(this.options));
- }
- public void DeSerialize(BinaryReader br)
- {
- int count = br.ReadInt32();
- byte[] buffer = Utility.ZlibUncompress(br.ReadBytes(count));
- BinaryReader binaryReader = new BinaryReader(new MemoryStream(buffer));
- int num = binaryReader.ReadInt32();
- this.scoutMaidList.Clear();
- for (int i = 0; i < num; i++)
- {
- ScoutMaidData scoutMaidData = new ScoutMaidData();
- int count2 = binaryReader.ReadInt32();
- scoutMaidData.DeSerialize(binaryReader.ReadBytes(count2));
- this.scoutMaidList.Add(scoutMaidData);
- }
- this.options = JsonUtility.FromJson<ScoutOptionData>(br.ReadString());
- }
- public void FixThumbnail()
- {
- foreach (ScoutMaidData scoutMaidData in this.scoutMaidList)
- {
- string guid = scoutMaidData.status.guid;
- this.RenameFile(ScoutMaidData.GetThumbnailFilePath(guid, true), ScoutMaidData.GetThumbnailFilePath(guid, false));
- this.RenameFile(ScoutMaidData.GetIconThumbnailFilePath(guid, true), ScoutMaidData.GetIconThumbnailFilePath(guid, false));
- this.RenameFile(ScoutMaidData.GetKasizukiThumbnailFilePath(guid, true), ScoutMaidData.GetKasizukiThumbnailFilePath(guid, false));
- }
- foreach (string guid2 in this.removeScoutMaidGuid)
- {
- foreach (string path in new string[]
- {
- ScoutMaidData.GetThumbnailFilePath(guid2, false),
- ScoutMaidData.GetIconThumbnailFilePath(guid2, false),
- ScoutMaidData.GetKasizukiThumbnailFilePath(guid2, false)
- })
- {
- if (File.Exists(path))
- {
- File.Delete(path);
- }
- }
- }
- this.DeleteAllTempThumbnailFile();
- }
- public void DeleteAllTempThumbnailFile()
- {
- foreach (string guid in this.removeScoutMaidGuid)
- {
- foreach (string path in new string[]
- {
- ScoutMaidData.GetThumbnailFilePath(guid, true),
- ScoutMaidData.GetIconThumbnailFilePath(guid, true),
- ScoutMaidData.GetKasizukiThumbnailFilePath(guid, true)
- })
- {
- if (File.Exists(path))
- {
- File.Delete(path);
- }
- }
- }
- foreach (ScoutMaidData scoutMaidData in this.scoutMaidList)
- {
- string guid2 = scoutMaidData.status.guid;
- foreach (string path2 in new string[]
- {
- ScoutMaidData.GetThumbnailFilePath(guid2, true),
- ScoutMaidData.GetIconThumbnailFilePath(guid2, true),
- ScoutMaidData.GetKasizukiThumbnailFilePath(guid2, true)
- })
- {
- if (File.Exists(path2))
- {
- File.Delete(path2);
- }
- }
- }
- this.removeScoutMaidGuid.Clear();
- }
- private void OnOnFinalize()
- {
- this.DeleteAllTempThumbnailFile();
- }
- private void RenameFile(string src, string dest)
- {
- if (!File.Exists(src))
- {
- return;
- }
- if (File.Exists(dest))
- {
- File.Delete(dest);
- }
- File.Move(src, dest);
- }
- public ScoutOptionData options = new ScoutOptionData();
- private HashSet<string> removeScoutMaidGuid = new HashSet<string>();
- }
- }
|