Execute.cs 4.2 KB

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