Overclock.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. cardSource.PermanentOfThisCard().CanAttack(activateClass, withoutTap: true);
  17. }
  18. #endregion
  19. #region Effect process of [Overclock]
  20. public static IEnumerator OverclockProcess(string trait, CardSource cardSource, ICardEffect activateClass)
  21. {
  22. if (HasMatchConditionPermanent(permanent => CanSelectPermanentCondition(permanent, trait, cardSource)))
  23. {
  24. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  25. selectPermanentEffect.SetUp(
  26. selectPlayer: cardSource.Owner,
  27. canTargetCondition: permanent => CanSelectPermanentCondition(permanent, trait, cardSource),
  28. canTargetCondition_ByPreSelecetedList: null,
  29. canEndSelectCondition: null,
  30. maxCount: 1,
  31. canNoSelect: true,
  32. canEndNotMax: false,
  33. selectPermanentCoroutine: SelectPermanentCoroutine,
  34. afterSelectPermanentCoroutine: null,
  35. mode: SelectPermanentEffect.Mode.Custom,
  36. cardEffect: activateClass);
  37. selectPermanentEffect.SetUpCustomMessage("Select 1 Digimon to delete.",
  38. "The opponent is selecting 1 Digimon to delete.");
  39. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  40. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  41. {
  42. yield return ContinuousController.instance.StartCoroutine(
  43. DeletePeremanentAndProcessAccordingToResult(
  44. targetPermanents: new List<Permanent>() { permanent },
  45. activateClass: activateClass,
  46. successProcess: _ => SuccessProcess(),
  47. failureProcess: null));
  48. IEnumerator SuccessProcess()
  49. {
  50. Permanent selectedPermanent = cardSource.PermanentOfThisCard();
  51. if (selectedPermanent.CanAttack(activateClass, withoutTap: true))
  52. {
  53. SelectAttackEffect selectAttackEffect = GManager.instance.GetComponent<SelectAttackEffect>();
  54. selectAttackEffect.SetUp(
  55. attacker: selectedPermanent,
  56. canAttackPlayerCondition: () => true,
  57. defenderCondition: _ => false,
  58. cardEffect: activateClass);
  59. selectAttackEffect.SetWithoutTap();
  60. yield return ContinuousController.instance.StartCoroutine(selectAttackEffect.Activate());
  61. }
  62. }
  63. }
  64. }
  65. }
  66. #endregion
  67. #region Target 1 Digimon gains [Overclock]
  68. public static IEnumerator GainOverclock(string trait, Permanent targetPermanent, EffectDuration effectDuration,
  69. 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 overclock = CardEffectFactory.OverclockEffect(
  82. trait: trait,
  83. targetPermanent: targetPermanent,
  84. isInheritedEffect: false,
  85. condition: CanUseCondition,
  86. rootCardEffect: activateClass,
  87. targetPermanent.TopCard);
  88. AddEffectToPermanent(
  89. targetPermanent: targetPermanent,
  90. effectDuration: effectDuration,
  91. card: card,
  92. cardEffect: overclock,
  93. timing: EffectTiming.OnAllyAttack);
  94. if (!targetPermanent.TopCard.CanNotBeAffected(activateClass))
  95. {
  96. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>()
  97. .CreateBuffEffect(targetPermanent));
  98. }
  99. }
  100. #endregion
  101. }