MeidoManager.cs 5.8 KB

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