MeidoManager.cs 6.0 KB

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