ScoutManager.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using MaidStatus;
  5. using UnityEngine;
  6. using wf;
  7. namespace scoutmode
  8. {
  9. public class ScoutManager
  10. {
  11. public ScoutManager()
  12. {
  13. this.scoutMaidList = new List<ScoutMaidData>();
  14. }
  15. public static bool isModeEnabled
  16. {
  17. get
  18. {
  19. return Product.type == Product.Type.JpAdult && PluginData.IsEnabled("GP001FB") && GameMain.Instance.CharacterMgr.status.GetFlag("借金返済_完済") != 0;
  20. }
  21. }
  22. public static ScoutManager Instance { get; private set; }
  23. public static ScoutManager CreateInstance()
  24. {
  25. if (ScoutManager.Instance == null)
  26. {
  27. ScoutManager.Instance = new ScoutManager();
  28. }
  29. GameMain instance = GameMain.Instance;
  30. instance.onFinalizeEvent = (Action)Delegate.Combine(instance.onFinalizeEvent, new Action(ScoutManager.Instance.OnOnFinalize));
  31. return ScoutManager.Instance;
  32. }
  33. public static ScoutManager ReCreateInstance()
  34. {
  35. if (ScoutManager.Instance != null)
  36. {
  37. ScoutManager.Instance.DeleteAllTempThumbnailFile();
  38. }
  39. ScoutManager.Instance = null;
  40. return ScoutManager.CreateInstance();
  41. }
  42. public List<ScoutMaidData> scoutMaidList { get; private set; }
  43. public ScoutMaidData GetScoutMaid(string guid)
  44. {
  45. foreach (ScoutMaidData scoutMaidData in this.scoutMaidList)
  46. {
  47. if (guid == scoutMaidData.status.guid || (scoutMaidData.isOverRideData && guid == scoutMaidData.overrideData.guid))
  48. {
  49. return scoutMaidData;
  50. }
  51. }
  52. return null;
  53. }
  54. public void AddScoutMaid(Maid maid)
  55. {
  56. ScoutMaidData scoutMaidData = new ScoutMaidData();
  57. scoutMaidData.CreateData(maid);
  58. this.scoutMaidList.Add(scoutMaidData);
  59. this.scoutMaidList.Sort((ScoutMaidData a, ScoutMaidData b) => a.status.creationTimeNum.CompareTo(b.status.creationTimeNum));
  60. string guid = scoutMaidData.status.guid;
  61. string thumbnailDictionary = Maid.ThumbnailDictionary;
  62. this.RenameFile(Path.Combine(thumbnailDictionary, "_tmp_thum_" + guid + ".png"), ScoutMaidData.GetThumbnailFilePath(guid, true));
  63. this.RenameFile(Path.Combine(thumbnailDictionary, "icon_thum_" + guid + ".png"), ScoutMaidData.GetIconThumbnailFilePath(guid, true));
  64. this.RenameFile(Path.Combine(thumbnailDictionary, "_tmp_kasizuki_" + guid + ".png"), ScoutMaidData.GetKasizukiThumbnailFilePath(guid, true));
  65. }
  66. public bool CreateRandomScoutMaidData(ScoutMaidData scoutMaid, ScoutOptionData execOptions)
  67. {
  68. if (execOptions == null || scoutMaid == null)
  69. {
  70. return false;
  71. }
  72. scoutMaid.overrideData.Destroy();
  73. if (execOptions.inheritPersonality && execOptions.inheritSeikeiken && execOptions.inheritMaidPoint)
  74. {
  75. return false;
  76. }
  77. scoutMaid.overrideData.CreateStatus(scoutMaid.status);
  78. ScoutMaidOverrideData.Status status = scoutMaid.overrideData.status;
  79. if (!execOptions.inheritPersonality)
  80. {
  81. List<Personal.Data> list = new List<Personal.Data>();
  82. foreach (Personal.Data data in Personal.GetAllDatas(true))
  83. {
  84. if (LockData.personalEnabledIdList.Contains(data.uniqueName))
  85. {
  86. string a = data.uniqueName.ToLower();
  87. if (data.oldPersonal)
  88. {
  89. if (a == "pure" || a == "cool" || a == "pride")
  90. {
  91. if (GameMain.Instance.CharacterMgr.status.isAvailableTransfer)
  92. {
  93. list.Add(data);
  94. }
  95. }
  96. else if (data.single)
  97. {
  98. list.Add(data);
  99. }
  100. else if (!string.IsNullOrEmpty(GameMain.Instance.CMSystem.CM3D2Path) && data.compatible)
  101. {
  102. list.Add(data);
  103. }
  104. }
  105. else
  106. {
  107. list.Add(data);
  108. }
  109. }
  110. }
  111. status.personalId = list[UnityEngine.Random.Range(0, list.Count)].id;
  112. }
  113. if (!execOptions.inheritSeikeiken)
  114. {
  115. status.seikeiken = (Seikeiken)UnityEngine.Random.Range(0, 4);
  116. }
  117. if (!execOptions.inheritMaidPoint)
  118. {
  119. status.ClearStatus();
  120. int num = scoutMaid.status.maidPoint;
  121. while (0 < num)
  122. {
  123. if (!status.AddRandomStatusValue(20))
  124. {
  125. for (int i = 0; i < 5; i++)
  126. {
  127. if (status.AddRandomStatusValue(20))
  128. {
  129. break;
  130. }
  131. }
  132. }
  133. num--;
  134. }
  135. }
  136. return true;
  137. }
  138. public void RemoveScoutMaid(ScoutMaidData scoutMaid)
  139. {
  140. this.scoutMaidList.Remove(scoutMaid);
  141. }
  142. public bool StartScout(Maid maid, string stageName, ScoutOptionData options)
  143. {
  144. ScoutMaidData scoutMaid = this.GetScoutMaid(maid.status.guid);
  145. if (scoutMaid != null && !scoutMaid.instanceData.enabled)
  146. {
  147. scoutMaid.instanceData.Create(maid, stageName, options);
  148. return true;
  149. }
  150. return false;
  151. }
  152. public Maid ActiveScoutMaid(ScoutMaidData scoutMaid, int slotNo)
  153. {
  154. if (scoutMaid == null)
  155. {
  156. return null;
  157. }
  158. Maid maid = GameMain.Instance.CharacterMgr.AddStockMaid();
  159. maid.Visible = true;
  160. GameMain.Instance.CharacterMgr.SetActiveMaid(maid, slotNo);
  161. scoutMaid.Apply(maid);
  162. return maid;
  163. }
  164. public bool SuspendedScout(Maid maid)
  165. {
  166. if (maid == null || maid.status.GetFlag("__スカウトメイド") != 1)
  167. {
  168. return false;
  169. }
  170. ScoutMaidData scoutMaid = this.GetScoutMaid(maid.status.guid);
  171. NDebug.Assert(scoutMaid != null, "スカウトメイドデータの特定ができませんでした");
  172. scoutMaid.instanceData.Update(maid);
  173. GameMain.Instance.CharacterMgr.DeactivateMaid(maid);
  174. GameMain.Instance.CharacterMgr.BanishmentMaid(maid);
  175. return true;
  176. }
  177. public bool CancelScout(Maid maid)
  178. {
  179. if (maid == null || maid.status.GetFlag("__スカウトメイド") != 1)
  180. {
  181. return false;
  182. }
  183. ScoutMaidData scoutMaid = this.GetScoutMaid(maid.status.guid);
  184. NDebug.Assert(scoutMaid != null, "スカウトメイドデータの特定ができませんでした");
  185. if (!this.CancelScout(scoutMaid))
  186. {
  187. return false;
  188. }
  189. GameMain.Instance.CharacterMgr.DeactivateMaid(maid);
  190. GameMain.Instance.CharacterMgr.BanishmentMaid(maid);
  191. return true;
  192. }
  193. public bool CancelScout(ScoutMaidData scoutMaid)
  194. {
  195. if (scoutMaid == null || !scoutMaid.instanceData.enabled)
  196. {
  197. return false;
  198. }
  199. scoutMaid.overrideData.Destroy();
  200. scoutMaid.instanceData.Destroy();
  201. return true;
  202. }
  203. public void HireScoutMaid(Maid maid)
  204. {
  205. if (maid == null)
  206. {
  207. return;
  208. }
  209. ScoutMaidData scoutMaid = this.GetScoutMaid(maid.status.guid);
  210. NDebug.Assert(scoutMaid != null, "スカウトメイドデータの特定ができませんでした");
  211. maid.status.SetNewGuidAndCreationTime(null, null);
  212. maid.status.employmentDay = GameMain.Instance.CharacterMgr.status.days;
  213. byte[] iconImageBinary = scoutMaid.GetIconImageBinary();
  214. if (iconImageBinary != null)
  215. {
  216. Texture2D texture2D = new Texture2D(1, 1, TextureFormat.ARGB32, false);
  217. texture2D.LoadImage(iconImageBinary);
  218. maid.SetThumIcon(texture2D);
  219. }
  220. foreach (string text in new string[]
  221. {
  222. ScoutMaidData.GetThumbnailFilePath(scoutMaid.status.guid, true),
  223. ScoutMaidData.GetThumbnailFilePath(scoutMaid.status.guid, false)
  224. })
  225. {
  226. string thumbnailFilePath = Maid.GetThumbnailFilePath(maid.status.guid, true);
  227. if (File.Exists(text) && !File.Exists(thumbnailFilePath))
  228. {
  229. File.Copy(text, thumbnailFilePath);
  230. break;
  231. }
  232. }
  233. foreach (string text2 in new string[]
  234. {
  235. ScoutMaidData.GetIconThumbnailFilePath(scoutMaid.status.guid, true),
  236. ScoutMaidData.GetIconThumbnailFilePath(scoutMaid.status.guid, false)
  237. })
  238. {
  239. string thumbnailFilePath2 = Maid.GetThumbnailFilePath(maid.status.guid, true);
  240. if (File.Exists(text2) && !File.Exists(thumbnailFilePath2))
  241. {
  242. File.Copy(text2, thumbnailFilePath2);
  243. break;
  244. }
  245. }
  246. foreach (string text3 in new string[]
  247. {
  248. ScoutMaidData.GetKasizukiThumbnailFilePath(scoutMaid.status.guid, true),
  249. ScoutMaidData.GetKasizukiThumbnailFilePath(scoutMaid.status.guid, false)
  250. })
  251. {
  252. string kasizukiThumbnailFilePath = Maid.GetKasizukiThumbnailFilePath(maid.status.guid, true);
  253. if (File.Exists(text3) && !File.Exists(kasizukiThumbnailFilePath))
  254. {
  255. File.Copy(text3, kasizukiThumbnailFilePath);
  256. break;
  257. }
  258. }
  259. scoutMaid.overrideData.Destroy();
  260. scoutMaid.instanceData.Destroy();
  261. if (scoutMaid.instanceData.options.isBaseCharaDelete)
  262. {
  263. this.RemoveScoutMaid(scoutMaid);
  264. }
  265. GameMain.Instance.CharacterMgr.DeactivateMaid(maid);
  266. }
  267. public ScoutMaidData GetRandomWaitingScoutmaid()
  268. {
  269. List<ScoutMaidData> list = new List<ScoutMaidData>();
  270. foreach (ScoutMaidData scoutMaidData in this.scoutMaidList)
  271. {
  272. if (!scoutMaidData.instanceData.enabled && !scoutMaidData.isOverRideData)
  273. {
  274. list.Add(scoutMaidData);
  275. }
  276. }
  277. return (list.Count <= 0) ? null : list[UnityEngine.Random.Range(0, list.Count)];
  278. }
  279. public void Serialize(BinaryWriter bw)
  280. {
  281. byte[] array = new byte[0];
  282. MemoryStream memoryStream = new MemoryStream();
  283. BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
  284. int count = this.scoutMaidList.Count;
  285. binaryWriter.Write(count);
  286. foreach (ScoutMaidData scoutMaidData in this.scoutMaidList)
  287. {
  288. byte[] array2 = scoutMaidData.Serialize();
  289. binaryWriter.Write(array2.Length);
  290. binaryWriter.Write(array2);
  291. }
  292. array = Utility.ZlibCompresss(memoryStream.ToArray());
  293. bw.Write(array.Length);
  294. bw.Write(array);
  295. bw.Write(JsonUtility.ToJson(this.options));
  296. }
  297. public void DeSerialize(BinaryReader br)
  298. {
  299. int count = br.ReadInt32();
  300. byte[] buffer = Utility.ZlibUncompress(br.ReadBytes(count));
  301. BinaryReader binaryReader = new BinaryReader(new MemoryStream(buffer));
  302. int num = binaryReader.ReadInt32();
  303. this.scoutMaidList.Clear();
  304. for (int i = 0; i < num; i++)
  305. {
  306. ScoutMaidData scoutMaidData = new ScoutMaidData();
  307. int count2 = binaryReader.ReadInt32();
  308. scoutMaidData.DeSerialize(binaryReader.ReadBytes(count2));
  309. this.scoutMaidList.Add(scoutMaidData);
  310. }
  311. this.options = JsonUtility.FromJson<ScoutOptionData>(br.ReadString());
  312. }
  313. public void FixThumbnail()
  314. {
  315. foreach (ScoutMaidData scoutMaidData in this.scoutMaidList)
  316. {
  317. string guid = scoutMaidData.status.guid;
  318. this.RenameFile(ScoutMaidData.GetThumbnailFilePath(guid, true), ScoutMaidData.GetThumbnailFilePath(guid, false));
  319. this.RenameFile(ScoutMaidData.GetIconThumbnailFilePath(guid, true), ScoutMaidData.GetIconThumbnailFilePath(guid, false));
  320. this.RenameFile(ScoutMaidData.GetKasizukiThumbnailFilePath(guid, true), ScoutMaidData.GetKasizukiThumbnailFilePath(guid, false));
  321. }
  322. foreach (string guid2 in this.removeScoutMaidGuid)
  323. {
  324. foreach (string path in new string[]
  325. {
  326. ScoutMaidData.GetThumbnailFilePath(guid2, false),
  327. ScoutMaidData.GetIconThumbnailFilePath(guid2, false),
  328. ScoutMaidData.GetKasizukiThumbnailFilePath(guid2, false)
  329. })
  330. {
  331. if (File.Exists(path))
  332. {
  333. File.Delete(path);
  334. }
  335. }
  336. }
  337. this.DeleteAllTempThumbnailFile();
  338. }
  339. public void DeleteAllTempThumbnailFile()
  340. {
  341. foreach (string guid in this.removeScoutMaidGuid)
  342. {
  343. foreach (string path in new string[]
  344. {
  345. ScoutMaidData.GetThumbnailFilePath(guid, true),
  346. ScoutMaidData.GetIconThumbnailFilePath(guid, true),
  347. ScoutMaidData.GetKasizukiThumbnailFilePath(guid, true)
  348. })
  349. {
  350. if (File.Exists(path))
  351. {
  352. File.Delete(path);
  353. }
  354. }
  355. }
  356. foreach (ScoutMaidData scoutMaidData in this.scoutMaidList)
  357. {
  358. string guid2 = scoutMaidData.status.guid;
  359. foreach (string path2 in new string[]
  360. {
  361. ScoutMaidData.GetThumbnailFilePath(guid2, true),
  362. ScoutMaidData.GetIconThumbnailFilePath(guid2, true),
  363. ScoutMaidData.GetKasizukiThumbnailFilePath(guid2, true)
  364. })
  365. {
  366. if (File.Exists(path2))
  367. {
  368. File.Delete(path2);
  369. }
  370. }
  371. }
  372. this.removeScoutMaidGuid.Clear();
  373. }
  374. private void OnOnFinalize()
  375. {
  376. this.DeleteAllTempThumbnailFile();
  377. }
  378. private void RenameFile(string src, string dest)
  379. {
  380. if (!File.Exists(src))
  381. {
  382. return;
  383. }
  384. if (File.Exists(dest))
  385. {
  386. File.Delete(dest);
  387. }
  388. File.Move(src, dest);
  389. }
  390. public ScoutOptionData options = new ScoutOptionData();
  391. private HashSet<string> removeScoutMaidGuid = new HashSet<string>();
  392. }
  393. }