CanNotSuspend.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 Permanent gains effect to can't digivolve
  9. public static IEnumerator GainCanNotSuspendEffect(Permanent targetPermanent, EffectDuration effectDuration, ICardEffect activateClass, bool isOnlyActivePhase, string effectName)
  10. {
  11. if (activateClass == null || activateClass.EffectSourceCard == null) yield break;
  12. if (targetPermanent == null || targetPermanent.TopCard == null) yield break;
  13. CardSource card = activateClass.EffectSourceCard;
  14. bool PermanentCondition(Permanent permanent)
  15. {
  16. if (IsPermanentExistsOnBattleArea(permanent))
  17. {
  18. if (!permanent.TopCard.CanNotBeAffected(activateClass))
  19. {
  20. return permanent == targetPermanent;
  21. }
  22. }
  23. return false;
  24. }
  25. bool CanUseCondition()
  26. {
  27. return !isOnlyActivePhase || GManager.instance.turnStateMachine.gameContext.TurnPhase == GameContext.phase.Active;
  28. }
  29. CanNotSuspendClass canNotSuspendClass = CardEffectFactory.CantSuspendStaticEffect(
  30. permanentCondition: PermanentCondition,
  31. isInheritedEffect: false,
  32. card: card,
  33. condition: CanUseCondition,
  34. effectName: effectName);
  35. AddEffectToPermanent(targetPermanent: targetPermanent, effectDuration: effectDuration, card: card, cardEffect: activateClass, timing: EffectTiming.None);
  36. if (!targetPermanent.TopCard.CanNotBeAffected(activateClass))
  37. {
  38. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(targetPermanent));
  39. }
  40. }
  41. #endregion
  42. #region Player gains effect to have Digimon can't suspend
  43. public static IEnumerator GainCanNotSuspendPlayerEffect(Func<Permanent, bool> permanentCondition, EffectDuration effectDuration, ICardEffect activateClass, bool isOnlyActivePhase, string effectName)
  44. {
  45. if (activateClass == null) yield break;
  46. if (activateClass.EffectSourceCard == null) yield break;
  47. CardSource card = activateClass.EffectSourceCard;
  48. bool _PermanentCondition(Permanent permanent)
  49. {
  50. if (IsPermanentExistsOnBattleArea(permanent))
  51. {
  52. if (!permanent.TopCard.CanNotBeAffected(activateClass))
  53. {
  54. if (permanentCondition == null || permanentCondition(permanent))
  55. {
  56. return true;
  57. }
  58. }
  59. }
  60. return false;
  61. }
  62. bool PermanentCondition(Permanent permanent)
  63. {
  64. if (_PermanentCondition(permanent))
  65. {
  66. if (!isOnlyActivePhase || GManager.instance.turnStateMachine.gameContext.TurnPlayer == permanent.TopCard.Owner)
  67. {
  68. return true;
  69. }
  70. }
  71. return false;
  72. }
  73. bool CanUseCondition()
  74. {
  75. return !isOnlyActivePhase || GManager.instance.turnStateMachine.gameContext.TurnPhase == GameContext.phase.Active;
  76. }
  77. CanNotSuspendClass canNotSuspendClass = CardEffectFactory.CantSuspendStaticEffect(
  78. permanentCondition: PermanentCondition,
  79. isInheritedEffect: false,
  80. card: card,
  81. condition: CanUseCondition,
  82. effectName: effectName);
  83. AddEffectToPlayer(effectDuration: effectDuration, card: card, cardEffect: canNotSuspendClass, timing: EffectTiming.None);
  84. foreach (Permanent permanent in GManager.instance.turnStateMachine.gameContext.PermanentsForTurnPlayer)
  85. {
  86. if (_PermanentCondition(permanent))
  87. {
  88. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(permanent));
  89. }
  90. }
  91. }
  92. #endregion
  93. }