MeidoManager.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. namespace COM3D2.MeidoPhotoStudio.Plugin
  6. {
  7. public 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<Meido> ActiveMeidoList { get; private set; }
  13. public Meido ActiveMeido => ActiveMeidoList.Count > 0 ? ActiveMeidoList[selectedMeido] : null;
  14. public bool HasActiveMeido => ActiveMeido != null;
  15. public bool IsFade { get; set; } = false;
  16. public int numberOfMeidos;
  17. public event EventHandler<MeidoChangeEventArgs> SelectMeido;
  18. public event EventHandler CalledMeidos;
  19. public event EventHandler AnimeChange;
  20. private int selectedMeido = 0;
  21. public int SelectedMeido
  22. {
  23. get => selectedMeido;
  24. private set => selectedMeido = Mathf.Clamp(value, 0, ActiveMeidoList.Count);
  25. }
  26. public bool IsBusy
  27. {
  28. get
  29. {
  30. foreach (Meido meido in ActiveMeidoList)
  31. {
  32. if (meido.Maid.IsBusy)
  33. {
  34. Debug.Log(meido.NameEN + " is busy!");
  35. return true;
  36. }
  37. }
  38. return false;
  39. }
  40. }
  41. public MeidoManager()
  42. {
  43. numberOfMeidos = characterMgr.GetStockMaidCount();
  44. ActiveMeidoList = new List<Meido>();
  45. meidos = new Meido[numberOfMeidos];
  46. MaidSwitcherPane.MaidChange += ChangeMeido;
  47. MaidSwitcherPane.meidoManager = this;
  48. for (int stockMaidIndex = 0; stockMaidIndex < numberOfMeidos; stockMaidIndex++)
  49. {
  50. meidos[stockMaidIndex] = new Meido(stockMaidIndex);
  51. }
  52. }
  53. ~MeidoManager()
  54. {
  55. MaidSwitcherPane.MaidChange -= ChangeMeido;
  56. }
  57. public void Update()
  58. {
  59. if (Input.GetKeyDown(KeyCode.H)) UndressAll();
  60. foreach (Meido activeMeido in ActiveMeidoList)
  61. {
  62. activeMeido.Update();
  63. }
  64. }
  65. private void UndressAll()
  66. {
  67. if (!HasActiveMeido) return;
  68. undress = Utility.Wrap(undress + 1, 0, 3);
  69. TBody.MaskMode maskMode = TBody.MaskMode.None;
  70. switch (undress)
  71. {
  72. case 0: maskMode = TBody.MaskMode.None; break;
  73. case 1: maskMode = TBody.MaskMode.Underwear; break;
  74. case 2: maskMode = TBody.MaskMode.Nude; break;
  75. }
  76. foreach (Meido activeMeido in ActiveMeidoList)
  77. {
  78. activeMeido.SetMaskMode(maskMode);
  79. }
  80. OnSelectMeido(new MeidoChangeEventArgs(SelectedMeido));
  81. }
  82. public void UnloadMeidos()
  83. {
  84. foreach (Meido meido in ActiveMeidoList)
  85. {
  86. meido.SelectMeido -= ChangeMeido;
  87. meido.BodyLoad -= EndCallMeidos;
  88. meido.AnimeChange -= OnAnimeChangeEvent;
  89. meido.Unload();
  90. }
  91. ActiveMeidoList.Clear();
  92. }
  93. public void DeactivateMeidos()
  94. {
  95. foreach (Meido meido in meidos)
  96. {
  97. meido.SelectMeido -= ChangeMeido;
  98. meido.BodyLoad -= EndCallMeidos;
  99. meido.AnimeChange -= OnAnimeChangeEvent;
  100. meido.Deactivate();
  101. }
  102. ActiveMeidoList.Clear();
  103. }
  104. public void CallMeidos(List<int> selectedMaids)
  105. {
  106. IsFade = true;
  107. UnloadMeidos();
  108. foreach (int slot in selectedMaids)
  109. {
  110. Meido meido = meidos[slot];
  111. ActiveMeidoList.Add(meido);
  112. meido.SelectMeido += ChangeMeido;
  113. meido.BodyLoad += EndCallMeidos;
  114. meido.AnimeChange += OnAnimeChangeEvent;
  115. }
  116. for (int i = 0; i < ActiveMeidoList.Count; i++)
  117. {
  118. Meido meido = ActiveMeidoList[i];
  119. meido.Load(i);
  120. }
  121. SelectedMeido = 0;
  122. OnSelectMeido(new MeidoChangeEventArgs(SelectedMeido));
  123. if (selectedMaids.Count == 0) EndCallMeidos(this, EventArgs.Empty);
  124. }
  125. private void OnAnimeChangeEvent(object sender, EventArgs args)
  126. {
  127. this.AnimeChange?.Invoke(this.ActiveMeido, EventArgs.Empty);
  128. }
  129. private void OnSelectMeido(MeidoChangeEventArgs args)
  130. {
  131. SelectMeido?.Invoke(this, args);
  132. }
  133. private void ChangeMeido(object sender, MeidoChangeEventArgs args)
  134. {
  135. SelectedMeido = args.selected;
  136. OnSelectMeido(args);
  137. }
  138. private void EndCallMeidos(object sender, EventArgs args)
  139. {
  140. if (!IsBusy)
  141. {
  142. IsFade = false;
  143. GameMain.Instance.MainCamera.FadeIn(1f);
  144. CalledMeidos?.Invoke(this, EventArgs.Empty);
  145. foreach (Meido meido in ActiveMeidoList)
  146. {
  147. meido.BodyLoad -= EndCallMeidos;
  148. }
  149. }
  150. }
  151. }
  152. public class MeidoChangeEventArgs : EventArgs
  153. {
  154. public int selected;
  155. public bool isBody;
  156. public bool fromMeido = false;
  157. public MeidoChangeEventArgs(int selected, bool fromMaid = false, bool isBody = true)
  158. {
  159. this.selected = selected;
  160. this.isBody = isBody;
  161. this.fromMeido = fromMaid;
  162. }
  163. }
  164. }