Execute.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. ICardEffect GetCardEffect(EffectTiming timing)
  57. {
  58. if (timing == EffectTiming.OnEndAttack)
  59. {
  60. return PermanentEffectFactory.DeleteSelfEffect(selectedPermanent);
  61. }
  62. return null;
  63. }
  64. #endregion
  65. }
  66. }
  67. #endregion
  68. #region Target 1 Digimon gains [Execute]
  69. public static IEnumerator GainExecute(Permanent targetPermanent, EffectDuration effectDuration, ICardEffect activateClass)
  70. {
  71. if (targetPermanent == null) yield break;
  72. if (!IsPermanentExistsOnBattleArea(targetPermanent)) yield break;
  73. if (activateClass == null) yield break;
  74. if (activateClass.EffectSourceCard == null) yield break;
  75. CardSource card = activateClass.EffectSourceCard;
  76. bool CanUseCondition()
  77. {
  78. return IsPermanentExistsOnBattleArea(targetPermanent) &&
  79. !targetPermanent.TopCard.CanNotBeAffected(activateClass);
  80. }
  81. ActivateClass execute = CardEffectFactory.ExecuteEffect(
  82. targetPermanent: targetPermanent,
  83. isInheritedEffect: false,
  84. condition: CanUseCondition,
  85. rootCardEffect: activateClass,
  86. targetPermanent.TopCard);
  87. AddEffectToPermanent(
  88. targetPermanent: targetPermanent,
  89. effectDuration: effectDuration,
  90. card: card,
  91. cardEffect: execute,
  92. timing: EffectTiming.OnEndTurn);
  93. if (!targetPermanent.TopCard.CanNotBeAffected(activateClass))
  94. {
  95. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>()
  96. .CreateBuffEffect(targetPermanent));
  97. }
  98. }
  99. #endregion
  100. }