BlastDigivolution.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System;
  4. using System.Linq;
  5. using UnityEngine;
  6. public partial class CardEffectFactory
  7. {
  8. #region Trigger effect of [Blast Digivolve]
  9. public static ActivateClass BlastDigivolveEffect(CardSource card, Func<bool> condition)
  10. {
  11. if (card == null) return null;
  12. if (!CardEffectCommons.IsExistOnHand(card)) return null;
  13. if (card.Owner.GetBattleAreaPermanents().Count == 0) return null;
  14. ActivateClass activateClass = new ActivateClass();
  15. activateClass.SetUpICardEffect("Blast Digivolve", CanUseCondition, card);
  16. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, true, DataBase.BlastDigivolveEffectDiscription());
  17. activateClass.SetIsCounterEffect(true);
  18. bool CanSelectPermanentCondition(Permanent permanent)
  19. {
  20. if (CardEffectCommons.IsPermanentExistsOnOwnerBattleArea(permanent, card))
  21. {
  22. if (permanent.IsDigimon)
  23. {
  24. if (card.CanPlayCardTargetFrame(permanent.PermanentFrame, false, activateClass))
  25. {
  26. if (!permanent.TopCard.CanNotBeAffected(activateClass))
  27. return true;
  28. }
  29. }
  30. }
  31. return false;
  32. }
  33. bool CanUseCondition(Hashtable hashtable)
  34. {
  35. if (CardEffectCommons.CanTriggerOnPermanentAttack(hashtable, permanent => CardEffectCommons.IsOpponentPermanent(permanent, card)))
  36. {
  37. if (card.Owner.HandCards.Contains(card))
  38. {
  39. if (condition == null || condition())
  40. {
  41. return true;
  42. }
  43. }
  44. }
  45. return false;
  46. }
  47. bool CanActivateCondition(Hashtable hashtable)
  48. {
  49. if (card.Owner.HandCards.Contains(card))
  50. {
  51. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentCondition))
  52. {
  53. if (condition == null || condition())
  54. {
  55. return true;
  56. }
  57. }
  58. }
  59. return false;
  60. }
  61. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  62. {
  63. Permanent selectedPermanent = null;
  64. int maxCount = Math.Min(1, CardEffectCommons.MatchConditionPermanentCount(CanSelectPermanentCondition));
  65. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  66. selectPermanentEffect.SetUp(
  67. selectPlayer: card.Owner,
  68. canTargetCondition: CanSelectPermanentCondition,
  69. canTargetCondition_ByPreSelecetedList: null,
  70. canEndSelectCondition: null,
  71. maxCount: maxCount,
  72. canNoSelect: false,
  73. canEndNotMax: false,
  74. selectPermanentCoroutine: SelectPermanentCoroutine,
  75. afterSelectPermanentCoroutine: null,
  76. mode: SelectPermanentEffect.Mode.Custom,
  77. cardEffect: activateClass);
  78. selectPermanentEffect.SetUpCustomMessage("Select 1 Digimon to digivolve.", "The opponent is selecting 1 Digimon to digivolve.");
  79. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  80. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  81. {
  82. selectedPermanent = permanent;
  83. yield return null;
  84. }
  85. if (selectedPermanent != null)
  86. {
  87. if (card.CanPlayCardTargetFrame(selectedPermanent.PermanentFrame, false, activateClass))
  88. {
  89. PlayCardClass playCardClass = new PlayCardClass(
  90. cardSources: new List<CardSource>() { card },
  91. hashtable: CardEffectCommons.CardEffectHashtable(activateClass),
  92. payCost: false,
  93. targetPermanent: selectedPermanent,
  94. isTapped: false,
  95. root: SelectCardEffect.Root.Hand,
  96. activateETB: true);
  97. yield return ContinuousController.instance.StartCoroutine(playCardClass.PlayCard());
  98. }
  99. }
  100. }
  101. return activateClass;
  102. }
  103. #endregion
  104. }