Raid.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System;
  4. using System.Linq;
  5. using UnityEngine;
  6. public partial class CardEffectCommons
  7. {
  8. #region Can activate [Raid]
  9. public static bool CanActivateRaid(Permanent targetPermanent)
  10. {
  11. if (targetPermanent == null) return false;
  12. if (targetPermanent.TopCard == null) return false;
  13. bool CanSelectPermanentCondition(Permanent permanent)
  14. {
  15. bool PermanentCondition(Permanent permanent1) => permanent1 != GManager.instance.attackProcess.DefendingPermanent && !permanent1.IsSuspended;
  16. return IsMaxDP(permanent, targetPermanent.TopCard.Owner.Enemy, PermanentCondition);
  17. }
  18. if (IsPermanentExistsOnBattleArea(targetPermanent))
  19. {
  20. if (GManager.instance.attackProcess.IsAttacking)
  21. {
  22. if (GManager.instance.attackProcess.AttackingPermanent == targetPermanent)
  23. {
  24. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentCondition))
  25. {
  26. return true;
  27. }
  28. }
  29. }
  30. }
  31. return false;
  32. }
  33. #endregion
  34. #region Effect process of [Raid]
  35. public static IEnumerator RaidProcess(Permanent targetPermanent, ICardEffect activateClass)
  36. {
  37. if (targetPermanent == null) yield break;
  38. if (targetPermanent.TopCard == null) yield break;
  39. bool CanSelectPermanentCondition(Permanent permanent)
  40. {
  41. bool PermanentCondition(Permanent permanent1) => !permanent1.IsSuspended;
  42. return IsMaxDP(permanent, targetPermanent.TopCard.Owner.Enemy, PermanentCondition);
  43. }
  44. int maxCount = Math.Min(1, CardEffectCommons.MatchConditionPermanentCount(CanSelectPermanentCondition));
  45. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  46. selectPermanentEffect.SetUp(
  47. selectPlayer: targetPermanent.TopCard.Owner,
  48. canTargetCondition: CanSelectPermanentCondition,
  49. canTargetCondition_ByPreSelecetedList: null,
  50. canEndSelectCondition: null,
  51. maxCount: maxCount,
  52. canNoSelect: true,
  53. canEndNotMax: false,
  54. selectPermanentCoroutine: SelectPermanentCoroutine,
  55. afterSelectPermanentCoroutine: null,
  56. mode: SelectPermanentEffect.Mode.Custom,
  57. cardEffect: activateClass);
  58. selectPermanentEffect.SetUpCustomMessage("Select 1 Digimon that this Digimon attacks to.", "The opponent is selecting 1 Digimon that this Digimon attacks to.");
  59. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  60. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  61. {
  62. yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SwitchDefender(activateClass, false, permanent));
  63. }
  64. }
  65. #endregion
  66. #region Target 1 Digimon gains [Raid]
  67. public static IEnumerator GainRaid(Permanent targetPermanent, EffectDuration effectDuration, ICardEffect activateClass)
  68. {
  69. if (targetPermanent == null) yield break;
  70. if (!IsPermanentExistsOnBattleArea(targetPermanent)) yield break;
  71. if (activateClass == null) yield break;
  72. if (activateClass.EffectSourceCard == null) yield break;
  73. CardSource card = activateClass.EffectSourceCard;
  74. bool CanUseCondition()
  75. {
  76. if (IsPermanentExistsOnBattleArea(targetPermanent))
  77. {
  78. if (!targetPermanent.TopCard.CanNotBeAffected(activateClass))
  79. {
  80. return true;
  81. }
  82. }
  83. return false;
  84. }
  85. ActivateClass raid = CardEffectFactory.RaidEffect(
  86. targetPermanent: targetPermanent,
  87. isInheritedEffect: false,
  88. condition: CanUseCondition,
  89. rootCardEffect: activateClass,
  90. targetPermanent.TopCard);
  91. AddEffectToPermanent(
  92. targetPermanent: targetPermanent,
  93. effectDuration: effectDuration,
  94. card: card,
  95. cardEffect: raid,
  96. timing: EffectTiming.OnAllyAttack);
  97. if (!targetPermanent.TopCard.CanNotBeAffected(activateClass))
  98. {
  99. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateBuffEffect(targetPermanent));
  100. }
  101. }
  102. #endregion
  103. }