Overclock.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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.CanAttack(activateClass, withoutTap: true))
  63. {
  64. SelectAttackEffect selectAttackEffect = GManager.instance.GetComponent<SelectAttackEffect>();
  65. selectAttackEffect.SetUp(
  66. attacker: attacker,
  67. canAttackPlayerCondition: () => true,
  68. defenderCondition: _ => false,
  69. cardEffect: activateClass);
  70. selectAttackEffect.SetWithoutTap();
  71. selectAttackEffect.SetCanNotSelectNotAttack();
  72. yield return ContinuousController.instance.StartCoroutine(selectAttackEffect.Activate());
  73. }
  74. }
  75. }
  76. }
  77. }
  78. #endregion
  79. #region Target 1 Digimon gains [Overclock]
  80. public static IEnumerator GainOverclock(string trait, Permanent targetPermanent, EffectDuration effectDuration,
  81. ICardEffect activateClass)
  82. {
  83. if (targetPermanent == null) yield break;
  84. if (!IsPermanentExistsOnBattleArea(targetPermanent)) yield break;
  85. if (activateClass == null) yield break;
  86. if (activateClass.EffectSourceCard == null) yield break;
  87. CardSource card = activateClass.EffectSourceCard;
  88. bool CanUseCondition()
  89. {
  90. return IsPermanentExistsOnBattleArea(targetPermanent) &&
  91. !targetPermanent.TopCard.CanNotBeAffected(activateClass);
  92. }
  93. ActivateClass overclock = CardEffectFactory.OverclockEffect(
  94. trait: trait,
  95. targetPermanent: targetPermanent,
  96. isInheritedEffect: false,
  97. condition: CanUseCondition,
  98. rootCardEffect: activateClass,
  99. targetPermanent.TopCard);
  100. AddEffectToPermanent(
  101. targetPermanent: targetPermanent,
  102. effectDuration: effectDuration,
  103. card: card,
  104. cardEffect: overclock,
  105. timing: EffectTiming.OnAllyAttack);
  106. if (!targetPermanent.TopCard.CanNotBeAffected(activateClass))
  107. {
  108. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>()
  109. .CreateBuffEffect(targetPermanent));
  110. }
  111. }
  112. #endregion
  113. }