Execute.cs 4.4 KB

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