Overclock.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. public partial class CardEffectCommons
  4. {
  5. static bool CanSelectPermanentCondition(Permanent permanent, string trait, CardSource cardSource)
  6. {
  7. return IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, cardSource) &&
  8. permanent != cardSource.PermanentOfThisCard() &&
  9. (permanent.IsToken || permanent.TopCard.ContainsTraits(trait));
  10. }
  11. #region Can activate [Overclock]
  12. public static bool CanActivateOverclock(string trait, CardSource cardSource, ICardEffect activateClass)
  13. {
  14. return IsExistOnBattleArea(cardSource) &&
  15. HasMatchConditionPermanent(permanent => CanSelectPermanentCondition(permanent, trait, cardSource));
  16. }
  17. #endregion
  18. #region Effect process of [Overclock]
  19. public static IEnumerator OverclockProcess(string trait, CardSource cardSource, ICardEffect activateClass)
  20. {
  21. Permanent selectedPermanent = null;
  22. bool isDeleted = false;
  23. if (HasMatchConditionPermanent(permanent => CanSelectPermanentCondition(permanent, trait, cardSource)))
  24. {
  25. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  26. selectPermanentEffect.SetUp(
  27. selectPlayer: cardSource.Owner,
  28. canTargetCondition: permanent => CanSelectPermanentCondition(permanent, trait, cardSource),
  29. canTargetCondition_ByPreSelecetedList: null,
  30. canEndSelectCondition: null,
  31. maxCount: 1,
  32. canNoSelect: true,
  33. canEndNotMax: false,
  34. selectPermanentCoroutine: SelectPermanentCoroutine,
  35. afterSelectPermanentCoroutine: null,
  36. mode: SelectPermanentEffect.Mode.Custom,
  37. cardEffect: activateClass);
  38. selectPermanentEffect.SetUpCustomMessage("Select 1 Digimon to delete.",
  39. "The opponent is selecting 1 Digimon to delete.");
  40. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  41. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  42. {
  43. selectedPermanent = permanent;
  44. yield return null;
  45. }
  46. if(selectedPermanent != null)
  47. {
  48. yield return ContinuousController.instance.StartCoroutine(
  49. DeletePeremanentAndProcessAccordingToResult(
  50. targetPermanents: new List<Permanent>() { selectedPermanent },
  51. activateClass: activateClass,
  52. successProcess: _ => SuccessProcess(),
  53. failureProcess: null));
  54. IEnumerator SuccessProcess()
  55. {
  56. isDeleted = true;
  57. yield return null;
  58. }
  59. if (isDeleted)
  60. {
  61. Permanent attacker = cardSource.PermanentOfThisCard();
  62. if(attacker != null)
  63. {
  64. if (attacker.CanAttack(activateClass, withoutTap: true))
  65. {
  66. SelectAttackEffect selectAttackEffect = GManager.instance.GetComponent<SelectAttackEffect>();
  67. selectAttackEffect.SetUp(
  68. attacker: attacker,
  69. canAttackPlayerCondition: () => true,
  70. defenderCondition: _ => false,
  71. cardEffect: activateClass);
  72. selectAttackEffect.SetWithoutTap();
  73. selectAttackEffect.SetCanNotSelectNotAttack();
  74. yield return ContinuousController.instance.StartCoroutine(selectAttackEffect.Activate());
  75. }
  76. }
  77. }
  78. }
  79. }
  80. }
  81. #endregion
  82. #region Target 1 Digimon gains [Overclock]
  83. public static IEnumerator GainOverclock(string trait, Permanent targetPermanent, EffectDuration effectDuration,
  84. ICardEffect activateClass)
  85. {
  86. if (targetPermanent == null) yield break;
  87. if (!IsPermanentExistsOnBattleArea(targetPermanent)) yield break;
  88. if (activateClass == null) yield break;
  89. if (activateClass.EffectSourceCard == null) yield break;
  90. CardSource card = activateClass.EffectSourceCard;
  91. bool CanUseCondition()
  92. {
  93. return IsPermanentExistsOnBattleArea(targetPermanent) &&
  94. !targetPermanent.TopCard.CanNotBeAffected(activateClass);
  95. }
  96. ActivateClass overclock = CardEffectFactory.OverclockEffect(
  97. trait: trait,
  98. targetPermanent: targetPermanent,
  99. isInheritedEffect: false,
  100. condition: CanUseCondition,
  101. rootCardEffect: activateClass,
  102. targetPermanent.TopCard);
  103. AddEffectToPermanent(
  104. targetPermanent: targetPermanent,
  105. effectDuration: effectDuration,
  106. card: card,
  107. cardEffect: overclock,
  108. timing: EffectTiming.OnAllyAttack);
  109. if (!targetPermanent.TopCard.CanNotBeAffected(activateClass))
  110. {
  111. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>()
  112. .CreateBuffEffect(targetPermanent));
  113. }
  114. }
  115. #endregion
  116. }