OptionalSkill.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using Photon;
  2. using Photon.Pun;
  3. using Photon.Realtime;
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using UnityEngine;
  9. public class OptionalSkill : MonoBehaviourPunCallbacks
  10. {
  11. public string waitingText { get; set; } = "The opponent is considering whether to use the effect.";
  12. bool _useOptional = false;
  13. public IEnumerator SelectOptional(ICardEffect cardEffect, Hashtable hash)
  14. {
  15. List<string> _YesNoTexts = new List<string>() { "Use", "Not use" };
  16. Player player = cardEffect.EffectSourceCard.Owner;
  17. _useOptional = false;
  18. string _Message;
  19. List<Permanent> effectTargets = cardEffect.EffectTargets != null ? cardEffect.EffectTargets(hash) : null;
  20. if (effectTargets == null || effectTargets.Count == 0)
  21. {
  22. _Message = $"Will you use \"{cardEffect.EffectName}\"?";
  23. }
  24. else
  25. {
  26. _Message = $"Will you use \"{cardEffect.EffectName}\" targeting {string.Join(", ", effectTargets.Select(permanent => permanent.TopCard.CardNames[0]))}?";
  27. }
  28. #region ƒgƒ‰ƒbƒVƒ…‚̃J[ƒh‚ð•\ަ
  29. if (cardEffect != null)
  30. {
  31. if (cardEffect.EffectSourceCard != null)
  32. {
  33. if (cardEffect.EffectSourceCard.Owner.TrashCards.Contains(cardEffect.EffectSourceCard) || cardEffect.EffectSourceCard.Owner.LostCards.Contains(cardEffect.EffectSourceCard))
  34. {
  35. if (cardEffect.EffectSourceCard.Owner.TrashHandCard != null)
  36. {
  37. if (!cardEffect.EffectSourceCard.Owner.TrashHandCard.gameObject.activeSelf)
  38. {
  39. cardEffect.EffectSourceCard.Owner.TrashHandCard.gameObject.SetActive(true);
  40. cardEffect.EffectSourceCard.Owner.TrashHandCard.SetUpHandCard(cardEffect.EffectSourceCard);
  41. cardEffect.EffectSourceCard.Owner.TrashHandCard.SetUpHandCardImage();
  42. cardEffect.EffectSourceCard.Owner.TrashHandCard.OnOutline();
  43. cardEffect.EffectSourceCard.Owner.TrashHandCard.SetBlueOutline();
  44. cardEffect.EffectSourceCard.Owner.TrashHandCard.transform.localScale = new Vector3(1.4f, 1.4f, 1.4f);
  45. }
  46. }
  47. }
  48. }
  49. }
  50. #endregion
  51. if (cardEffect.EffectSourceCard.Owner.isYou)
  52. {
  53. Permanent permanent = cardEffect.EffectSourceCard.PermanentOfThisCard();
  54. List<FieldPermanentCard> highlightPermanents = new List<FieldPermanentCard>();
  55. if (permanent != null)
  56. {
  57. if (permanent.ShowingPermanentCard != null)
  58. {
  59. highlightPermanents.Add(permanent.ShowingPermanentCard);
  60. }
  61. }
  62. if (effectTargets != null)
  63. {
  64. foreach (Permanent targetPermanent in effectTargets)
  65. {
  66. if (targetPermanent.ShowingPermanentCard != null)
  67. {
  68. highlightPermanents.Add(targetPermanent.ShowingPermanentCard);
  69. }
  70. }
  71. }
  72. if (highlightPermanents.Count > 0)
  73. {
  74. GManager.instance.hideCannotSelectObject.SetUpHideCannotSelectObject(highlightPermanents, false);
  75. }
  76. GManager.instance.commandText.OpenCommandText(_Message);
  77. List<Command_SelectCommand> commands = new List<Command_SelectCommand>()
  78. {
  79. new Command_SelectCommand(_YesNoTexts[0] ,() => photonView.RPC("SetUseOptional",RpcTarget.All, player.PlayerID, true),0),
  80. };
  81. GManager.instance.BackButton.OpenSelectCommandButton(_YesNoTexts[1], () => { photonView.RPC("SetUseOptional", RpcTarget.All, player.PlayerID, false); }, 0);
  82. GManager.instance.selectCommandPanel.SetUpCommandButton(commands);
  83. }
  84. else
  85. {
  86. bool ShowOpponentMessage = cardEffect.EffectDiscription.Contains("[Hand]") && GManager.instance.autoProcessing.executingMultipleSkills != null && !GManager.instance.autoProcessing.executingMultipleSkills.IsOnlyHandEffectStacked;
  87. if (ShowOpponentMessage)
  88. {
  89. GManager.instance.commandText.OpenCommandText(waitingText);
  90. }
  91. if (GManager.instance.IsAI)
  92. {
  93. SetUseOptional(player.PlayerID, RandomUtility.IsSucceedProbability(0.9f));
  94. }
  95. }
  96. yield return new WaitUntil(() => player.HasPlayerSelection());
  97. ValueSelection valueSelection = player.DequeuePlayerSelection<ValueSelection>();
  98. _useOptional = valueSelection != null ? valueSelection.ValueAsBool() : false;
  99. GManager.instance.selectCommandPanel.Off();
  100. GManager.instance.BackButton.CloseSelectCommandButton();
  101. GManager.instance.hideCannotSelectObject.Close();
  102. GManager.instance.commandText.CloseCommandText();
  103. yield return new WaitWhile(() => GManager.instance.commandText.gameObject.activeSelf);
  104. cardEffect.SetUseOptional(_useOptional);
  105. cardEffect.EffectSourceCard.Owner.TrashHandCard.gameObject.SetActive(false);
  106. }
  107. [PunRPC]
  108. public void SetUseOptional(int playerID, bool useOptional)
  109. {
  110. Player selectionPlayer = GManager.instance.GetPlayerFromID(playerID);
  111. if (selectionPlayer == null)
  112. {
  113. return;
  114. }
  115. selectionPlayer.QueuePlayerSelection(new ValueSelection(useOptional));
  116. }
  117. }