MeidoManager.cs 6.4 KB

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