Guard.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System;
  4. public partial class CardEffectFactory
  5. {
  6. #region Trigger effect of [Guard]
  7. public static ActivateClass GuardEffect(Permanent targetPermanent, bool isInheritedEffect, Func<bool> condition, ICardEffect rootCardEffect, CardSource card)
  8. {
  9. if (targetPermanent == null) return null;
  10. if (targetPermanent.TopCard == null) return null;
  11. if (card == null) return null;
  12. ActivateClass activateClass = new ActivateClass();
  13. activateClass.SetUpICardEffect("Guard", CanUseCondition, card);
  14. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, false, DataBase.GuardEffectDescription());
  15. activateClass.SetIsInheritedEffect(isInheritedEffect);
  16. if (rootCardEffect != null)
  17. {
  18. activateClass.SetIsInheritedEffect(false);
  19. activateClass.SetEffectSourcePermanent(targetPermanent);
  20. activateClass.SetRootCardEffect(rootCardEffect);
  21. }
  22. bool CanUseCondition(Hashtable hashtable)
  23. {
  24. return CardEffectCommons.IsPermanentExistsOnBattleAreaDigimon(targetPermanent)
  25. && !targetPermanent.TopCard.CanNotBeAffected(activateClass);
  26. }
  27. bool CanActivateCondition(Hashtable hashtable)
  28. {
  29. return CanActivateGuard(targetPermanent, activateClass);
  30. }
  31. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  32. {
  33. return CardEffectFactory.GuardProcess(_hashtable, activateClass, targetPermanent);
  34. }
  35. return activateClass;
  36. }
  37. #endregion
  38. #region Can activate [Guard]
  39. public static bool CanActivateGuard(Permanent permanent, ICardEffect activateClass)
  40. {
  41. return CardEffectCommons.IsPermanentExistsOnBattleArea(permanent)
  42. && permanent.CanBeDestroyedBySkill(activateClass);
  43. }
  44. #endregion
  45. #region Effect process of [Guard]
  46. public static IEnumerator GuardProcess(Hashtable hashtable, ICardEffect activateClass, Permanent permanent)
  47. {
  48. if (permanent == null) yield break;
  49. if (permanent.TopCard == null) yield break;
  50. Player owner = permanent.TopCard.Owner;
  51. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.DeletePeremanentAndProcessAccordingToResult(targetPermanents: new List<Permanent>() { permanent }, activateClass: activateClass, successProcess: permanents => SuccessProcess(), failureProcess: null));
  52. IEnumerator SuccessProcess()
  53. {
  54. permanent.willBeRemoveField = false;
  55. permanent.HideDeleteEffect();
  56. permanent.HideHandBounceEffect();
  57. permanent.HideDeckBounceEffect();
  58. permanent.HideWillRemoveFieldEffect();
  59. yield return null;
  60. }
  61. }
  62. #endregion
  63. #region Target 1 Digimon gains [Guard]
  64. public static IEnumerator GainGuard(Permanent targetPermanent, EffectDuration effectDuration, ICardEffect activateClass)
  65. {
  66. if (targetPermanent == null) yield break;
  67. if (!CardEffectCommons.IsPermanentExistsOnBattleArea(targetPermanent)) yield break;
  68. if (activateClass == null) yield break;
  69. if (activateClass.EffectSourceCard == null) yield break;
  70. CardSource card = activateClass.EffectSourceCard;
  71. bool CanUseCondition()
  72. {
  73. return CardEffectCommons.IsPermanentExistsOnBattleArea(targetPermanent)
  74. && !targetPermanent.TopCard.CanNotBeAffected(activateClass);
  75. }
  76. ActivateClass guard = CardEffectFactory.GuardEffect(
  77. targetPermanent: targetPermanent,
  78. isInheritedEffect: false,
  79. condition: CanUseCondition,
  80. rootCardEffect: activateClass,
  81. card: targetPermanent.TopCard);
  82. CardEffectCommons.AddEffectToPermanent(
  83. targetPermanent: targetPermanent,
  84. effectDuration: effectDuration,
  85. card: card,
  86. cardEffect: guard,
  87. timing: EffectTiming.WhenRemoveField);
  88. if (!targetPermanent.TopCard.CanNotBeAffected(activateClass))
  89. {
  90. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateBuffEffect(targetPermanent));
  91. }
  92. }
  93. #endregion
  94. #region Player gains effect to have Digimon gains [Guard]
  95. public static IEnumerator GainGuardPlayerEffect(Func<Permanent, bool> permanentCondition, EffectDuration effectDuration, ICardEffect activateClass)
  96. {
  97. if (activateClass == null) yield break;
  98. if (activateClass.EffectSourceCard == null) yield break;
  99. CardSource card = activateClass.EffectSourceCard;
  100. bool PermanentCondition(Permanent permanent)
  101. {
  102. return CardEffectCommons.IsPermanentExistsOnBattleArea(permanent)
  103. && !permanent.TopCard.CanNotBeAffected(activateClass)
  104. && (permanentCondition == null
  105. || permanentCondition(permanent));
  106. }
  107. bool CanUseCondition()
  108. {
  109. return true;
  110. }
  111. ICardEffect guard = CardEffectFactory.GuardStaticEffect(permanentCondition: PermanentCondition, isInheritedEffect: false, card: card, condition: CanUseCondition);
  112. CardEffectCommons.AddEffectToPlayer(effectDuration: effectDuration, card: card, cardEffect: guard, timing: EffectTiming.WhenRemoveField);
  113. foreach (Permanent permanent in GManager.instance.turnStateMachine.gameContext.PermanentsForTurnPlayer)
  114. {
  115. if (PermanentCondition(permanent))
  116. {
  117. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateBuffEffect(permanent));
  118. }
  119. }
  120. }
  121. #endregion
  122. #region Static effect of [Guard] to all PermanentCondition Digimon
  123. public static ActivateClass GuardStaticEffect(Func<Permanent, bool> permanentCondition, bool isInheritedEffect, CardSource card, Func<bool> condition)
  124. {
  125. ActivateClass activateClass = new ActivateClass();
  126. activateClass.SetUpICardEffect("Guard", CanUseCondition, card);
  127. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, false, DataBase.GuardEffectDescription());
  128. activateClass.SetIsInheritedEffect(isInheritedEffect);
  129. bool CanUseCondition(Hashtable hashtable)
  130. {
  131. return CardEffectCommons.IsExistOnBattleAreaDigimonTrigger(card, activateClass)
  132. && (condition == null
  133. || condition());
  134. }
  135. bool CanActivateCondition(Hashtable hashtable)
  136. {
  137. return CardEffectFactory.CanActivateGuard(card.PermanentOfThisCard(), activateClass)
  138. && (condition == null
  139. || condition());
  140. }
  141. IEnumerator ActivateCoroutine(Hashtable hashtable)
  142. {
  143. return CardEffectFactory.GuardProcess(hashtable, activateClass, card.PermanentOfThisCard());
  144. }
  145. return activateClass;
  146. }
  147. #endregion
  148. }