MeidoManager.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace COM3D2.MeidoPhotoStudio.Plugin
  5. {
  6. public class MeidoManager
  7. {
  8. private static CharacterMgr characterMgr = GameMain.Instance.CharacterMgr;
  9. private int undress = 0;
  10. public Meido[] meidos { get; private set; }
  11. public List<Meido> ActiveMeidoList { get; private set; }
  12. public Meido ActiveMeido { get; private set; }
  13. public bool HasActiveMeido { get => ActiveMeido != null; }
  14. public bool IsFade { get; set; } = false;
  15. public int numberOfMeidos;
  16. public event EventHandler<MeidoChangeEventArgs> SelectMeido;
  17. public event EventHandler CalledMeidos;
  18. private int selectedMeido = 0;
  19. public int SelectedMeido
  20. {
  21. get => selectedMeido;
  22. set
  23. {
  24. int max = Math.Max(ActiveMeidoList.Count, 0);
  25. selectedMeido = Mathf.Clamp(value, 0, max);
  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. undress = Utility.Wrap(undress + 1, 0, 3);
  74. TBody.MaskMode maskMode = TBody.MaskMode.None;
  75. switch (undress)
  76. {
  77. case 0: maskMode = TBody.MaskMode.None; break;
  78. case 1: maskMode = TBody.MaskMode.Underwear; break;
  79. case 2: maskMode = TBody.MaskMode.Nude; break;
  80. }
  81. foreach (Meido activeMeido in ActiveMeidoList)
  82. {
  83. activeMeido.Maid.body0.SetMaskMode(maskMode);
  84. }
  85. }
  86. public void UnloadMeidos()
  87. {
  88. foreach (Meido meido in ActiveMeidoList)
  89. {
  90. meido.Unload();
  91. }
  92. ActiveMeidoList.Clear();
  93. }
  94. public void DeactivateMeidos()
  95. {
  96. foreach (Meido meido in meidos)
  97. {
  98. meido.Deactivate();
  99. }
  100. ActiveMeidoList.Clear();
  101. }
  102. public void CallMeidos(List<int> selectedMaids)
  103. {
  104. IsFade = true;
  105. UnloadMeidos();
  106. foreach (int slot in selectedMaids)
  107. {
  108. Meido meido = meidos[slot];
  109. ActiveMeidoList.Add(meido);
  110. }
  111. for (int i = 0; i < ActiveMeidoList.Count; i++)
  112. {
  113. Meido meido = ActiveMeidoList[i];
  114. meido.Load(i);
  115. }
  116. if (selectedMaids.Count == 0)
  117. {
  118. EndCallMeidos(this, EventArgs.Empty);
  119. return;
  120. }
  121. SelectedMeido = 0;
  122. }
  123. public void SetMeidoPose(string pose, int meidoIndex = -1)
  124. {
  125. Meido meido = meidoIndex == -1 ? ActiveMeido : ActiveMeidoList[meidoIndex];
  126. meido.SetPose(pose);
  127. }
  128. private void ChangeMeido(object sender, MeidoChangeEventArgs args)
  129. {
  130. SelectedMeido = args.selected;
  131. SelectMeido?.Invoke(this, args);
  132. }
  133. private void EndCallMeidos(object sender, EventArgs args)
  134. {
  135. if (!IsBusy)
  136. {
  137. IsFade = false;
  138. GameMain.Instance.MainCamera.FadeIn(1f);
  139. CalledMeidos?.Invoke(this, EventArgs.Empty);
  140. }
  141. }
  142. }
  143. public class MeidoChangeEventArgs : EventArgs
  144. {
  145. public int selected;
  146. public bool isBody;
  147. public bool fromMeido = false;
  148. public MeidoChangeEventArgs(int selected, bool fromMaid = false, bool isBody = true)
  149. {
  150. this.selected = selected;
  151. this.isBody = isBody;
  152. this.fromMeido = fromMaid;
  153. }
  154. }
  155. }