SelectCountEffect.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. _isDigivolutionCost = false;
  27. _candidates = new List<int>();
  28. }
  29. public void SetCandidates(List<int> candidates)
  30. {
  31. _candidates = candidates;
  32. }
  33. public void SetPreferMin(bool preferMin)
  34. {
  35. _preferMin = preferMin;
  36. }
  37. public void SetIsDigivolutionCost(bool isDigivolutionCost)
  38. {
  39. _isDigivolutionCost = isDigivolutionCost;
  40. }
  41. Player _selectPlayer = null;
  42. Permanent _targetPermanent = null;
  43. int _maxCount = 0;
  44. bool _canNoSelect = false;
  45. string _messageForOwner = "";
  46. string _messageForEnemy = "";
  47. Func<int, IEnumerator> _selectCountCoroutine = null;
  48. List<int> _candidates = new List<int>();
  49. int _selectedCount = 0;
  50. bool _preferMin = true;
  51. bool _isDigivolutionCost = false;
  52. public IEnumerator Activate()
  53. {
  54. if (_maxCount >= 1)
  55. {
  56. bool isOldActive_Outline = false;
  57. if (_targetPermanent != null)
  58. {
  59. if (_targetPermanent.ShowingPermanentCard != null)
  60. {
  61. isOldActive_Outline = _targetPermanent.ShowingPermanentCard.Outline_Select.gameObject.activeSelf;
  62. _targetPermanent.ShowingPermanentCard.SetOrangeOutline();
  63. _targetPermanent.ShowingPermanentCard.Outline_Select.gameObject.SetActive(true);
  64. }
  65. }
  66. List<int> candidates = new List<int>();
  67. for (int i = 0; i < _maxCount + 1; i++)
  68. {
  69. if (i == 0)
  70. {
  71. if (!_canNoSelect)
  72. {
  73. continue;
  74. }
  75. }
  76. candidates.Add(i);
  77. }
  78. if (_candidates != null)
  79. {
  80. if (_candidates.Count >= 1)
  81. {
  82. candidates = new List<int>();
  83. foreach (int candidate in _candidates)
  84. {
  85. candidates.Add(candidate);
  86. }
  87. }
  88. }
  89. candidates = candidates.Distinct().OrderBy((value) => value).ToList();
  90. if (candidates.Count >= 1)
  91. {
  92. if (candidates.Count == 1)
  93. {
  94. SetCount(_selectPlayer.PlayerID, candidates[0]);
  95. }
  96. else
  97. {
  98. if (_selectPlayer.isYou)
  99. {
  100. if ((!_isDigivolutionCost && ContinuousController.instance.autoMaxCardCount && !_preferMin)
  101. || (_isDigivolutionCost && ContinuousController.instance.autoMinDigivolutionCost && _preferMin))
  102. {
  103. int preferedNumber = _preferMin ? candidates.Min() : candidates.Max();
  104. photonView.RPC("SetCount", RpcTarget.All, _selectPlayer.PlayerID, preferedNumber);
  105. }
  106. else
  107. {
  108. GManager.instance.commandText.OpenCommandText($"{_messageForOwner}");
  109. List<Command_SelectCommand> command_SelectCommands = new List<Command_SelectCommand>()
  110. {
  111. };
  112. for (int i = 0; i < candidates.Count; i++)
  113. {
  114. int k = candidates[i];
  115. string text = $"{k}";
  116. command_SelectCommands.Add(new Command_SelectCommand(text, () => photonView.RPC("SetCount", RpcTarget.All, _selectPlayer.PlayerID, k), 0));
  117. }
  118. GManager.instance.selectCommandPanel.SetUpCommandButton(command_SelectCommands);
  119. }
  120. }
  121. else
  122. {
  123. #region AI���[�h
  124. if (GManager.instance.IsAI)
  125. {
  126. int preferedNumber = _preferMin ? candidates.Min() : candidates.Max();
  127. SetCount(_selectPlayer.PlayerID, preferedNumber);
  128. }
  129. #endregion
  130. else
  131. {
  132. GManager.instance.commandText.OpenCommandText($"{_messageForEnemy}");
  133. }
  134. }
  135. }
  136. yield return new WaitUntil(() => _selectPlayer.HasPlayerSelection());
  137. ValueSelection valueSelection = _selectPlayer.DequeuePlayerSelection<ValueSelection>();
  138. _selectedCount = valueSelection != null ? valueSelection.ValueAsInt() : 0;
  139. GManager.instance.commandText.CloseCommandText();
  140. yield return new WaitWhile(() => GManager.instance.commandText.gameObject.activeSelf);
  141. if (_selectCountCoroutine != null)
  142. {
  143. yield return ContinuousController.instance.StartCoroutine(_selectCountCoroutine(_selectedCount));
  144. }
  145. }
  146. if (_targetPermanent != null)
  147. {
  148. if (_targetPermanent.ShowingPermanentCard != null)
  149. {
  150. _targetPermanent.ShowingPermanentCard.Outline_Select.gameObject.SetActive(isOldActive_Outline);
  151. }
  152. }
  153. }
  154. }
  155. [PunRPC]
  156. public void SetCount(int playerID, int selectedCount)
  157. {
  158. Player selectionPlayer = GManager.instance.GetPlayerFromID(playerID);
  159. if (selectionPlayer == null)
  160. {
  161. return;
  162. }
  163. selectionPlayer.QueuePlayerSelection(new ValueSelection(selectedCount));
  164. }
  165. }