MeidoManager.cs 5.3 KB

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