Guard.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System;
  4. public partial class CardEffectFactory
  5. {
  6. #region [Guard] self effect
  7. public static ActivateClass GuardSelfEffect(bool isInheritedEffect, CardSource card, Func<bool> condition, bool isLinkedEffect = false)
  8. {
  9. return GuardEffect(
  10. targetPermanent: card.PermanentOfThisCard(),
  11. isInheritedEffect,
  12. condition,
  13. rootCardEffect: null,
  14. card,
  15. isLinkedEffect);
  16. }
  17. #endregion
  18. #region [Guard] Effect
  19. public static ActivateClass GuardEffect(Permanent targetPermanent, bool isInheritedEffect, Func<bool> condition, ICardEffect rootCardEffect, CardSource card, bool isLinkedEffect = false)
  20. {
  21. if (targetPermanent == null) return null;
  22. if (targetPermanent.TopCard == null) return null;
  23. if (card == null) return null;
  24. ActivateClass activateClass = new ActivateClass();
  25. activateClass.SetUpICardEffect("Guard", CanUseCondition, card);
  26. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, false, DataBase.GuardEffectDescription());
  27. activateClass.SetIsInheritedEffect(isInheritedEffect);
  28. activateClass.SetIsLinkedEffect(isLinkedEffect);
  29. activateClass.SetIsSkippable(true);
  30. if (rootCardEffect != null)
  31. {
  32. activateClass.SetIsInheritedEffect(false);
  33. activateClass.SetEffectSourcePermanent(targetPermanent);
  34. activateClass.SetRootCardEffect(rootCardEffect);
  35. }
  36. bool CanUseCondition(Hashtable hashtable)
  37. {
  38. return CardEffectCommons.IsPermanentExistsOnBattleAreaDigimon(targetPermanent)
  39. && !targetPermanent.TopCard.CanNotBeAffected(activateClass)
  40. && CardEffectCommons.CanTriggerWhenPermanentRemoveField(hashtable, PermanentCondition)
  41. && CardEffectCommons.IsByEffect(hashtable, effect => CardEffectCommons.IsOpponentEffect(effect, card));
  42. }
  43. bool PermanentCondition(Permanent permanent) => permanent != targetPermanent && CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card);
  44. bool CanActivateCondition(Hashtable hashtable)
  45. {
  46. return CanActivateGuard(targetPermanent, activateClass);
  47. }
  48. IEnumerator ActivateCoroutine(Hashtable hashtable)
  49. {
  50. yield return ContinuousController.instance.StartCoroutine(GuardProcess(hashtable, activateClass, targetPermanent));
  51. }
  52. return activateClass;
  53. }
  54. #endregion
  55. #region Can activate [Guard]
  56. public static bool CanActivateGuard(Permanent permanent, ICardEffect activateClass)
  57. {
  58. return CardEffectCommons.IsPermanentExistsOnBattleArea(permanent)
  59. && permanent.CanBeDestroyedBySkill(activateClass);
  60. }
  61. #endregion
  62. #region Effect process of [Guard]
  63. public static IEnumerator GuardProcess(Hashtable hashtable, ICardEffect activateClass, Permanent guardPermanent)
  64. {
  65. if (guardPermanent == null) yield break;
  66. if (guardPermanent.TopCard == null) yield break;
  67. CardSource topCard = guardPermanent.TopCard;
  68. bool PermanentCondition(Permanent otherPermanent)
  69. {
  70. return otherPermanent != guardPermanent
  71. && CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(otherPermanent, topCard);
  72. }
  73. Player owner = topCard.Owner;
  74. string selectPlayerMessage = "Will you delete this digimon to prevent the removal?";
  75. string notSelectPlayerMessage = "The opponent is choosing if they will use Guard.";
  76. List<SelectionElement<bool>> command_SelectCommands = new List<SelectionElement<bool>>()
  77. {
  78. new SelectionElement<bool>(message: $"Yes", value: true, spriteIndex: 0),
  79. new SelectionElement<bool>(message: $"No", value: false, spriteIndex: 1),
  80. };
  81. GManager.instance.userSelectionManager.SetBoolSelection(selectionElements: command_SelectCommands, selectPlayer: owner, selectPlayerMessage: selectPlayerMessage, notSelectPlayerMessage: notSelectPlayerMessage);
  82. yield return ContinuousController.instance.StartCoroutine(GManager.instance.userSelectionManager.WaitForEndSelect());
  83. if (GManager.instance.userSelectionManager.SelectedBoolValue)
  84. {
  85. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.DeletePeremanentAndProcessAccordingToResult(targetPermanents: new List<Permanent>() { guardPermanent }, activateClass: activateClass, successProcess: permanents => SuccessProcess(), failureProcess: null));
  86. IEnumerator SuccessProcess()
  87. {
  88. List<Permanent> removedPermanents = CardEffectCommons.GetPermanentsFromHashtable(hashtable).Filter(PermanentCondition);
  89. foreach (Permanent removed in removedPermanents)
  90. {
  91. removed.willBeRemoveField = false;
  92. removed.HideDeleteEffect();
  93. removed.HideHandBounceEffect();
  94. removed.HideDeckBounceEffect();
  95. removed.HideWillRemoveFieldEffect();
  96. }
  97. yield return null;
  98. }
  99. }
  100. }
  101. #endregion
  102. #region Target 1 Digimon gains [Guard]
  103. public static IEnumerator GainGuard(Permanent targetPermanent, EffectDuration effectDuration, ICardEffect activateClass)
  104. {
  105. if (targetPermanent == null) yield break;
  106. if (!CardEffectCommons.IsPermanentExistsOnBattleArea(targetPermanent)) yield break;
  107. if (activateClass == null) yield break;
  108. if (activateClass.EffectSourceCard == null) yield break;
  109. CardSource card = activateClass.EffectSourceCard;
  110. bool CanUseCondition()
  111. {
  112. return CardEffectCommons.IsPermanentExistsOnBattleArea(targetPermanent)
  113. && !targetPermanent.TopCard.CanNotBeAffected(activateClass);
  114. }
  115. ActivateClass guard = CardEffectFactory.GuardEffect(
  116. targetPermanent: targetPermanent,
  117. isInheritedEffect: false,
  118. condition: CanUseCondition,
  119. rootCardEffect: activateClass,
  120. card: targetPermanent.TopCard);
  121. CardEffectCommons.AddEffectToPermanent(
  122. targetPermanent: targetPermanent,
  123. effectDuration: effectDuration,
  124. card: card,
  125. cardEffect: guard,
  126. timing: EffectTiming.WhenRemoveField);
  127. if (!targetPermanent.TopCard.CanNotBeAffected(activateClass))
  128. {
  129. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateBuffEffect(targetPermanent));
  130. }
  131. }
  132. #endregion
  133. }