SelectCountEffect.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Photon.Pun;
  5. using System;
  6. using System.Linq;
  7. public class SelectCountEffect : MonoBehaviourPunCallbacks
  8. {
  9. public void SetUp
  10. (Player SelectPlayer,
  11. Permanent targetPermanent,
  12. int MaxCount,
  13. bool CanNoSelect,
  14. string Message,
  15. string Message_Enemy,
  16. Func<int, IEnumerator> SelectCountCoroutine)
  17. {
  18. _selectPlayer = SelectPlayer;
  19. _targetPermanent = targetPermanent;
  20. _maxCount = MaxCount;
  21. _canNoSelect = CanNoSelect;
  22. _messageForOwner = Message;
  23. _messageForEnemy = Message_Enemy;
  24. _selectCountCoroutine = SelectCountCoroutine;
  25. _preferMin = false;
  26. _notDoSync = false;
  27. _isDigivolutionCost = false;
  28. _candidates = new List<int>();
  29. }
  30. public void SetCandidates(List<int> candidates)
  31. {
  32. _candidates = candidates;
  33. }
  34. public void SetPreferMin(bool preferMin)
  35. {
  36. _preferMin = preferMin;
  37. }
  38. public void SetNotDoSync(bool notDoSync)
  39. {
  40. _notDoSync = notDoSync;
  41. }
  42. public void SetIsDigivolutionCost(bool isDigivolutionCost)
  43. {
  44. _isDigivolutionCost = isDigivolutionCost;
  45. }
  46. Player _selectPlayer = null;
  47. Permanent _targetPermanent = null;
  48. int _maxCount = 0;
  49. bool _canNoSelect = false;
  50. string _messageForOwner = "";
  51. string _messageForEnemy = "";
  52. Func<int, IEnumerator> _selectCountCoroutine = null;
  53. List<int> _candidates = new List<int>();
  54. int _selectedCount = 0;
  55. bool _endSelect = false;
  56. bool _preferMin = true;
  57. bool _notDoSync = false;
  58. bool _isDigivolutionCost = false;
  59. public IEnumerator Activate()
  60. {
  61. if (!_notDoSync)
  62. {
  63. yield return GManager.instance.photonWaitController.StartWait("SelectCountEffect");
  64. }
  65. if (_maxCount >= 1)
  66. {
  67. bool isOldActive_Outline = false;
  68. if (_targetPermanent != null)
  69. {
  70. if (_targetPermanent.ShowingPermanentCard != null)
  71. {
  72. isOldActive_Outline = _targetPermanent.ShowingPermanentCard.Outline_Select.gameObject.activeSelf;
  73. _targetPermanent.ShowingPermanentCard.SetOrangeOutline();
  74. _targetPermanent.ShowingPermanentCard.Outline_Select.gameObject.SetActive(true);
  75. }
  76. }
  77. List<int> candidates = new List<int>();
  78. for (int i = 0; i < _maxCount + 1; i++)
  79. {
  80. if (i == 0)
  81. {
  82. if (!_canNoSelect)
  83. {
  84. continue;
  85. }
  86. }
  87. candidates.Add(i);
  88. }
  89. if (_candidates != null)
  90. {
  91. if (_candidates.Count >= 1)
  92. {
  93. candidates = new List<int>();
  94. foreach (int candidate in _candidates)
  95. {
  96. candidates.Add(candidate);
  97. }
  98. }
  99. }
  100. candidates = candidates.Distinct().OrderBy((value) => value).ToList();
  101. if (candidates.Count >= 1)
  102. {
  103. if (candidates.Count == 1)
  104. {
  105. SetCount(candidates[0]);
  106. }
  107. else
  108. {
  109. if (_selectPlayer.isYou)
  110. {
  111. if ((!_isDigivolutionCost && ContinuousController.instance.autoMaxCardCount && !_preferMin)
  112. || (_isDigivolutionCost && ContinuousController.instance.autoMinDigivolutionCost && _preferMin))
  113. {
  114. int preferedNumber = _preferMin ? candidates.Min() : candidates.Max();
  115. photonView.RPC("SetCount", RpcTarget.All, preferedNumber);
  116. }
  117. else
  118. {
  119. GManager.instance.commandText.OpenCommandText($"{_messageForOwner}");
  120. List<Command_SelectCommand> command_SelectCommands = new List<Command_SelectCommand>()
  121. {
  122. };
  123. for (int i = 0; i < candidates.Count; i++)
  124. {
  125. int k = candidates[i];
  126. string text = $"{k}";
  127. command_SelectCommands.Add(new Command_SelectCommand(text, () => photonView.RPC("SetCount", RpcTarget.All, k), 0));
  128. }
  129. GManager.instance.selectCommandPanel.SetUpCommandButton(command_SelectCommands);
  130. }
  131. }
  132. else
  133. {
  134. #region AI���[�h
  135. if (GManager.instance.IsAI)
  136. {
  137. int preferedNumber = _preferMin ? candidates.Min() : candidates.Max();
  138. SetCount(preferedNumber);
  139. }
  140. #endregion
  141. else
  142. {
  143. GManager.instance.commandText.OpenCommandText($"{_messageForEnemy}");
  144. }
  145. }
  146. }
  147. yield return new WaitWhile(() => !_endSelect);
  148. _endSelect = false;
  149. GManager.instance.commandText.CloseCommandText();
  150. yield return new WaitWhile(() => GManager.instance.commandText.gameObject.activeSelf);
  151. if (_selectCountCoroutine != null)
  152. {
  153. yield return ContinuousController.instance.StartCoroutine(_selectCountCoroutine(_selectedCount));
  154. }
  155. }
  156. if (_targetPermanent != null)
  157. {
  158. if (_targetPermanent.ShowingPermanentCard != null)
  159. {
  160. _targetPermanent.ShowingPermanentCard.Outline_Select.gameObject.SetActive(isOldActive_Outline);
  161. }
  162. }
  163. }
  164. }
  165. [PunRPC]
  166. public void SetCount(int selectedCount)
  167. {
  168. _selectedCount = selectedCount;
  169. _endSelect = true;
  170. }
  171. }