MeidoManager.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  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. public Meido[] meidos { get; private set; }
  12. public List<int> SelectMeidoList { get; private set; } = new List<int>();
  13. public List<Meido> ActiveMeidoList { get; private set; } = new List<Meido>();
  14. public Meido ActiveMeido => ActiveMeidoList.Count > 0 ? ActiveMeidoList[SelectedMeido] : null;
  15. public bool HasActiveMeido => ActiveMeido != null;
  16. public int numberOfMeidos;
  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. private void UndressAll()
  92. {
  93. if (!HasActiveMeido) return;
  94. undress = Utility.Wrap(undress + 1, 0, 3);
  95. TBody.MaskMode maskMode = TBody.MaskMode.None;
  96. switch (undress)
  97. {
  98. case 0: maskMode = TBody.MaskMode.None; break;
  99. case 1: maskMode = TBody.MaskMode.Underwear; break;
  100. case 2: maskMode = TBody.MaskMode.Nude; break;
  101. }
  102. foreach (Meido activeMeido in ActiveMeidoList)
  103. {
  104. activeMeido.SetMaskMode(maskMode);
  105. }
  106. this.UpdateMeido?.Invoke(ActiveMeido, new MeidoUpdateEventArgs(SelectedMeido));
  107. }
  108. private void UnloadMeidos()
  109. {
  110. foreach (Meido meido in ActiveMeidoList)
  111. {
  112. meido.UpdateMeido -= OnUpdateMeido;
  113. meido.Unload();
  114. }
  115. ActiveMeidoList.Clear();
  116. }
  117. private void OnUpdateMeido(object sender, MeidoUpdateEventArgs args)
  118. {
  119. if (!args.IsEmpty) this.SelectedMeido = args.SelectedMeido;
  120. this.UpdateMeido?.Invoke(ActiveMeido, args);
  121. }
  122. private void OnEndCallMeidos(object sender, EventArgs args)
  123. {
  124. if (!IsBusy)
  125. {
  126. GameMain.Instance.MainCamera.FadeIn(1f);
  127. EndCallMeidos?.Invoke(this, EventArgs.Empty);
  128. foreach (Meido meido in ActiveMeidoList)
  129. {
  130. meido.BodyLoad -= OnEndCallMeidos;
  131. }
  132. }
  133. }
  134. }
  135. public class MeidoUpdateEventArgs : EventArgs
  136. {
  137. public static new MeidoUpdateEventArgs Empty { get; } = new MeidoUpdateEventArgs(-1);
  138. public bool IsEmpty
  139. {
  140. get
  141. {
  142. return (this == MeidoUpdateEventArgs.Empty) ||
  143. (this.SelectedMeido == -1 && !this.FromMeido && !this.IsBody);
  144. }
  145. }
  146. public int SelectedMeido { get; }
  147. public bool IsBody { get; }
  148. public bool FromMeido { get; } = false;
  149. public MeidoUpdateEventArgs(int meidoIndex, bool fromMaid = false, bool isBody = true)
  150. {
  151. this.SelectedMeido = meidoIndex;
  152. this.IsBody = isBody;
  153. this.FromMeido = fromMaid;
  154. }
  155. }
  156. }