Execute.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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, isExecute: true);
  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, isExecute: true))
  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.UntilEndAttackEffects.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. yield return ContinuousController.instance.StartCoroutine(selectAttackEffect.Activate());
  53. #endregion
  54. #region Delete this Digimon
  55. selectedPermanent.UntilEndAttackEffects.Add(GetCardEffect);
  56. selectedPermanent.UntilEndAttackEffects.Add(GetDetailEffect);
  57. ICardEffect GetCardEffect(EffectTiming timing)
  58. {
  59. if (timing == EffectTiming.OnEndAttack)
  60. {
  61. return PermanentEffectFactory.DeleteSelfEffect(selectedPermanent, activateClass);
  62. }
  63. return null;
  64. }
  65. ICardEffect GetDetailEffect(EffectTiming timing)
  66. {
  67. if (timing == EffectTiming.None)
  68. {
  69. return PermanentEffectFactory.AddDetailClass(selectedPermanent, "At end of attack, delete this Digimon.", true, activateClass);
  70. }
  71. return null;
  72. }
  73. #endregion
  74. }
  75. }
  76. #endregion
  77. #region Target 1 Digimon gains [Execute]
  78. public static IEnumerator GainExecute(Permanent targetPermanent, EffectDuration effectDuration, ICardEffect activateClass)
  79. {
  80. if (targetPermanent == null) yield break;
  81. if (!IsPermanentExistsOnBattleArea(targetPermanent)) yield break;
  82. if (activateClass == null) yield break;
  83. if (activateClass.EffectSourceCard == null) yield break;
  84. CardSource card = activateClass.EffectSourceCard;
  85. bool CanUseCondition()
  86. {
  87. return IsPermanentExistsOnBattleArea(targetPermanent) &&
  88. !targetPermanent.TopCard.CanNotBeAffected(activateClass);
  89. }
  90. ActivateClass execute = CardEffectFactory.ExecuteEffect(
  91. targetPermanent: targetPermanent,
  92. isInheritedEffect: false,
  93. condition: CanUseCondition,
  94. rootCardEffect: activateClass,
  95. targetPermanent.TopCard);
  96. AddEffectToPermanent(
  97. targetPermanent: targetPermanent,
  98. effectDuration: effectDuration,
  99. card: card,
  100. cardEffect: execute,
  101. timing: EffectTiming.OnEndTurn);
  102. if (!targetPermanent.TopCard.CanNotBeAffected(activateClass))
  103. {
  104. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>()
  105. .CreateBuffEffect(targetPermanent));
  106. }
  107. }
  108. #endregion
  109. }