SelectCountEffect.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 _preferMin = true;
  56. bool _notDoSync = false;
  57. bool _isDigivolutionCost = false;
  58. public IEnumerator Activate()
  59. {
  60. if (!_notDoSync)
  61. {
  62. yield return GManager.instance.photonWaitController.StartWait("SelectCountEffect");
  63. }
  64. if (_maxCount >= 1)
  65. {
  66. bool isOldActive_Outline = false;
  67. if (_targetPermanent != null)
  68. {
  69. if (_targetPermanent.ShowingPermanentCard != null)
  70. {
  71. isOldActive_Outline = _targetPermanent.ShowingPermanentCard.Outline_Select.gameObject.activeSelf;
  72. _targetPermanent.ShowingPermanentCard.SetOrangeOutline();
  73. _targetPermanent.ShowingPermanentCard.Outline_Select.gameObject.SetActive(true);
  74. }
  75. }
  76. List<int> candidates = new List<int>();
  77. for (int i = 0; i < _maxCount + 1; i++)
  78. {
  79. if (i == 0)
  80. {
  81. if (!_canNoSelect)
  82. {
  83. continue;
  84. }
  85. }
  86. candidates.Add(i);
  87. }
  88. if (_candidates != null)
  89. {
  90. if (_candidates.Count >= 1)
  91. {
  92. candidates = new List<int>();
  93. foreach (int candidate in _candidates)
  94. {
  95. candidates.Add(candidate);
  96. }
  97. }
  98. }
  99. candidates = candidates.Distinct().OrderBy((value) => value).ToList();
  100. if (candidates.Count >= 1)
  101. {
  102. if (candidates.Count == 1)
  103. {
  104. SetCount(_selectPlayer.PlayerID, candidates[0]);
  105. }
  106. else
  107. {
  108. if (_selectPlayer.isYou)
  109. {
  110. if ((!_isDigivolutionCost && ContinuousController.instance.autoMaxCardCount && !_preferMin)
  111. || (_isDigivolutionCost && ContinuousController.instance.autoMinDigivolutionCost && _preferMin))
  112. {
  113. int preferedNumber = _preferMin ? candidates.Min() : candidates.Max();
  114. photonView.RPC("SetCount", RpcTarget.All, _selectPlayer.PlayerID, preferedNumber);
  115. }
  116. else
  117. {
  118. GManager.instance.commandText.OpenCommandText($"{_messageForOwner}");
  119. List<Command_SelectCommand> command_SelectCommands = new List<Command_SelectCommand>()
  120. {
  121. };
  122. for (int i = 0; i < candidates.Count; i++)
  123. {
  124. int k = candidates[i];
  125. string text = $"{k}";
  126. command_SelectCommands.Add(new Command_SelectCommand(text, () => photonView.RPC("SetCount", RpcTarget.All, _selectPlayer.PlayerID, k), 0));
  127. }
  128. GManager.instance.selectCommandPanel.SetUpCommandButton(command_SelectCommands);
  129. }
  130. }
  131. else
  132. {
  133. #region AI���[�h
  134. if (GManager.instance.IsAI)
  135. {
  136. int preferedNumber = _preferMin ? candidates.Min() : candidates.Max();
  137. SetCount(_selectPlayer.PlayerID, preferedNumber);
  138. }
  139. #endregion
  140. else
  141. {
  142. GManager.instance.commandText.OpenCommandText($"{_messageForEnemy}");
  143. }
  144. }
  145. }
  146. yield return new WaitUntil(() => _selectPlayer.HasPlayerSelection());
  147. ValueSelection valueSelection = _selectPlayer.DequeuePlayerSelection<ValueSelection>();
  148. _selectedCount = valueSelection != null ? valueSelection.ValueAsInt() : 0;
  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 playerID, int selectedCount)
  167. {
  168. Player selectionPlayer = GManager.instance.GetPlayerFromID(playerID);
  169. if (selectionPlayer == null)
  170. {
  171. return;
  172. }
  173. selectionPlayer.QueuePlayerSelection(new ValueSelection(selectedCount));
  174. }
  175. }