MeidoManager.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using UnityEngine;
  5. namespace COM3D2.MeidoPhotoStudio.Plugin
  6. {
  7. internal class MeidoManager
  8. {
  9. private static CharacterMgr characterMgr = GameMain.Instance.CharacterMgr;
  10. private int undress = 0;
  11. public Meido[] meidos { get; private set; }
  12. public List<int> SelectMeidoList { get; private set; } = new List<int>();
  13. public List<Meido> ActiveMeidoList { get; private set; } = new List<Meido>();
  14. public Meido ActiveMeido => ActiveMeidoList.Count > 0 ? ActiveMeidoList[SelectedMeido] : null;
  15. public bool HasActiveMeido => ActiveMeido != null;
  16. public int numberOfMeidos;
  17. public event EventHandler<MeidoUpdateEventArgs> UpdateMeido;
  18. public event EventHandler EndCallMeidos;
  19. public event EventHandler BeginCallMeidos;
  20. private int selectedMeido = 0;
  21. public string[] ActiveMeidoNameList
  22. {
  23. get
  24. {
  25. return ActiveMeidoList.Count == 0
  26. ? new[] { Translation.Get("systemMessage", "noMaids") }
  27. : ActiveMeidoList.Select(meido => $"{meido.FirstName} {meido.LastName}").ToArray();
  28. }
  29. }
  30. public int SelectedMeido
  31. {
  32. get => selectedMeido;
  33. private set => selectedMeido = Mathf.Clamp(value, 0, ActiveMeidoList.Count - 1);
  34. }
  35. public bool IsBusy
  36. {
  37. get
  38. {
  39. foreach (Meido meido in ActiveMeidoList)
  40. {
  41. if (meido.Maid.IsBusy) return true;
  42. }
  43. return false;
  44. }
  45. }
  46. public void ChangeMaid(int index)
  47. {
  48. OnUpdateMeido(null, new MeidoUpdateEventArgs(index));
  49. }
  50. public void Activate()
  51. {
  52. GameMain.Instance.CharacterMgr.ResetCharaPosAll();
  53. numberOfMeidos = characterMgr.GetStockMaidCount();
  54. meidos = new Meido[numberOfMeidos];
  55. for (int stockMaidIndex = 0; stockMaidIndex < numberOfMeidos; stockMaidIndex++)
  56. {
  57. meidos[stockMaidIndex] = new Meido(stockMaidIndex);
  58. }
  59. }
  60. public void Deactivate()
  61. {
  62. foreach (Meido meido in meidos)
  63. {
  64. meido.UpdateMeido -= OnUpdateMeido;
  65. meido.Deactivate();
  66. }
  67. SelectMeidoList.Clear();
  68. ActiveMeidoList.Clear();
  69. }
  70. public void Update()
  71. {
  72. if (Input.GetKeyDown(KeyCode.H)) UndressAll();
  73. foreach (Meido activeMeido in ActiveMeidoList)
  74. {
  75. activeMeido.Update();
  76. }
  77. }
  78. public void CallMeidos()
  79. {
  80. this.BeginCallMeidos?.Invoke(this, EventArgs.Empty);
  81. GameMain.Instance.MainCamera.FadeOut(0.01f, false, () =>
  82. {
  83. UnloadMeidos();
  84. foreach (int slot in this.SelectMeidoList)
  85. {
  86. Meido meido = meidos[slot];
  87. ActiveMeidoList.Add(meido);
  88. meido.BodyLoad += OnEndCallMeidos;
  89. meido.UpdateMeido += OnUpdateMeido;
  90. }
  91. for (int i = 0; i < ActiveMeidoList.Count; i++)
  92. {
  93. Meido meido = ActiveMeidoList[i];
  94. meido.Load(i, this.SelectMeidoList[i]);
  95. }
  96. SelectedMeido = 0;
  97. if (this.SelectMeidoList.Count == 0) OnEndCallMeidos(this, EventArgs.Empty);
  98. }, false);
  99. }
  100. public Meido GetMeido(string guid)
  101. {
  102. foreach (Meido meido in ActiveMeidoList)
  103. {
  104. if (meido.Maid.status.guid == guid) return meido;
  105. }
  106. return null;
  107. }
  108. public Meido GetMeido(int activeIndex)
  109. {
  110. if (activeIndex >= 0 && activeIndex < ActiveMeidoList.Count)
  111. {
  112. return ActiveMeidoList[activeIndex];
  113. }
  114. return null;
  115. }
  116. private void UndressAll()
  117. {
  118. if (!HasActiveMeido) return;
  119. undress = Utility.Wrap(undress + 1, 0, 3);
  120. TBody.MaskMode maskMode = TBody.MaskMode.None;
  121. switch (undress)
  122. {
  123. case 0: maskMode = TBody.MaskMode.None; break;
  124. case 1: maskMode = TBody.MaskMode.Underwear; break;
  125. case 2: maskMode = TBody.MaskMode.Nude; break;
  126. }
  127. foreach (Meido activeMeido in ActiveMeidoList)
  128. {
  129. activeMeido.SetMaskMode(maskMode);
  130. }
  131. this.UpdateMeido?.Invoke(ActiveMeido, new MeidoUpdateEventArgs(SelectedMeido));
  132. }
  133. private void UnloadMeidos()
  134. {
  135. foreach (Meido meido in ActiveMeidoList)
  136. {
  137. meido.UpdateMeido -= OnUpdateMeido;
  138. meido.Unload();
  139. }
  140. ActiveMeidoList.Clear();
  141. }
  142. private void OnUpdateMeido(object sender, MeidoUpdateEventArgs args)
  143. {
  144. if (!args.IsEmpty) this.SelectedMeido = args.SelectedMeido;
  145. this.UpdateMeido?.Invoke(ActiveMeido, args);
  146. }
  147. private void OnEndCallMeidos(object sender, EventArgs args)
  148. {
  149. if (!IsBusy)
  150. {
  151. GameMain.Instance.MainCamera.FadeIn(1f);
  152. EndCallMeidos?.Invoke(this, EventArgs.Empty);
  153. foreach (Meido meido in ActiveMeidoList)
  154. {
  155. meido.BodyLoad -= OnEndCallMeidos;
  156. }
  157. }
  158. }
  159. }
  160. public class MeidoUpdateEventArgs : EventArgs
  161. {
  162. public static new MeidoUpdateEventArgs Empty { get; } = new MeidoUpdateEventArgs(-1);
  163. public bool IsEmpty
  164. {
  165. get
  166. {
  167. return (this == MeidoUpdateEventArgs.Empty) ||
  168. (this.SelectedMeido == -1 && !this.FromMeido && !this.IsBody);
  169. }
  170. }
  171. public int SelectedMeido { get; }
  172. public bool IsBody { get; }
  173. public bool FromMeido { get; }
  174. public MeidoUpdateEventArgs(int meidoIndex, bool fromMaid = false, bool isBody = true)
  175. {
  176. this.SelectedMeido = meidoIndex;
  177. this.IsBody = isBody;
  178. this.FromMeido = fromMaid;
  179. }
  180. }
  181. }