Execute.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. public partial class CardEffectCommons
  4. {
  5. #region Can activate [Execute]
  6. public static bool CanActivateExecute(CardSource cardSource, ICardEffect activateClass)
  7. {
  8. return IsExistOnBattleArea(cardSource) &&
  9. cardSource.PermanentOfThisCard().CanAttack(activateClass);
  10. }
  11. #endregion
  12. #region Effect process of [Execute]
  13. public static IEnumerator ExecuteProcess(CardSource cardSource, ICardEffect activateClass)
  14. {
  15. Permanent selectedPermanent = cardSource.PermanentOfThisCard();
  16. if (selectedPermanent.CanAttack(activateClass))
  17. {
  18. #region Attack unsuspended Digimon
  19. CanAttackTargetDefendingPermanentClass canAttackTargetDefendingPermanentClass = new CanAttackTargetDefendingPermanentClass();
  20. canAttackTargetDefendingPermanentClass.SetUpICardEffect("Can attack unsuspended Digimon", CanUseCondition, cardSource);
  21. canAttackTargetDefendingPermanentClass.SetUpCanAttackTargetDefendingPermanentClass(
  22. attackerCondition: AttackerCondition,
  23. defenderCondition: DefenderCondition,
  24. cardEffectCondition: CardEffectCondition);
  25. selectedPermanent.UntilEachTurnEndEffects.Add(_ => canAttackTargetDefendingPermanentClass);
  26. bool CanUseCondition(Hashtable hashtable)
  27. {
  28. return IsExistOnBattleArea(cardSource) &&
  29. IsOwnerTurn(cardSource);
  30. }
  31. bool AttackerCondition(Permanent attacker)
  32. {
  33. return attacker == selectedPermanent;
  34. }
  35. bool DefenderCondition(Permanent defender)
  36. {
  37. return IsPermanentExistsOnOpponentBattleAreaDigimon(defender, cardSource) &&
  38. !defender.IsSuspended;
  39. }
  40. bool CardEffectCondition(ICardEffect cardEffect)
  41. {
  42. return true;
  43. }
  44. #endregion
  45. #region Attack
  46. SelectAttackEffect selectAttackEffect = GManager.instance.GetComponent<SelectAttackEffect>();
  47. selectAttackEffect.SetUp(
  48. attacker: selectedPermanent,
  49. canAttackPlayerCondition: () => true,
  50. defenderCondition: _ => true,
  51. cardEffect: activateClass);
  52. selectAttackEffect.SetAfterOnAttackCoroutine(AfterAttackCoroutine);
  53. yield return ContinuousController.instance.StartCoroutine(selectAttackEffect.Activate());
  54. #endregion
  55. #region Delete this Digimon
  56. IEnumerator AfterAttackCoroutine()
  57. {
  58. yield return ContinuousController.instance.StartCoroutine(
  59. new DestroyPermanentsClass(new List<Permanent>() { selectedPermanent }, CardEffectHashtable(activateClass)).Destroy());
  60. }
  61. #endregion
  62. }
  63. }
  64. #endregion
  65. #region Target 1 Digimon gains [Execute]
  66. public static IEnumerator GainExecute(Permanent targetPermanent, EffectDuration effectDuration, ICardEffect activateClass)
  67. {
  68. if (targetPermanent == null) yield break;
  69. if (!IsPermanentExistsOnBattleArea(targetPermanent)) yield break;
  70. if (activateClass == null) yield break;
  71. if (activateClass.EffectSourceCard == null) yield break;
  72. CardSource card = activateClass.EffectSourceCard;
  73. bool CanUseCondition()
  74. {
  75. return IsPermanentExistsOnBattleArea(targetPermanent) &&
  76. !targetPermanent.TopCard.CanNotBeAffected(activateClass);
  77. }
  78. ActivateClass execute = CardEffectFactory.ExecuteEffect(
  79. targetPermanent: targetPermanent,
  80. isInheritedEffect: false,
  81. condition: CanUseCondition,
  82. rootCardEffect: activateClass,
  83. targetPermanent.TopCard);
  84. AddEffectToPermanent(
  85. targetPermanent: targetPermanent,
  86. effectDuration: effectDuration,
  87. card: card,
  88. cardEffect: execute,
  89. timing: EffectTiming.OnEndTurn);
  90. if (!targetPermanent.TopCard.CanNotBeAffected(activateClass))
  91. {
  92. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>()
  93. .CreateBuffEffect(targetPermanent));
  94. }
  95. }
  96. #endregion
  97. }