Guard.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. bool PermanentCondition(Permanent otherPermanent)
  68. {
  69. return otherPermanent != guardPermanent
  70. && CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(otherPermanent, guardPermanent.TopCard);
  71. }
  72. Player owner = guardPermanent.TopCard.Owner;
  73. string selectPlayerMessage = "Will you delete this digimon to prevent the removal?";
  74. string notSelectPlayerMessage = "The opponent is choosing if they will use Guard.";
  75. List<SelectionElement<bool>> command_SelectCommands = new List<SelectionElement<bool>>()
  76. {
  77. new SelectionElement<bool>(message: $"Yes", value: true, spriteIndex: 0),
  78. new SelectionElement<bool>(message: $"No", value: false, spriteIndex: 1),
  79. };
  80. GManager.instance.userSelectionManager.SetBoolSelection(selectionElements: command_SelectCommands, selectPlayer: owner, selectPlayerMessage: selectPlayerMessage, notSelectPlayerMessage: notSelectPlayerMessage);
  81. yield return ContinuousController.instance.StartCoroutine(GManager.instance.userSelectionManager.WaitForEndSelect());
  82. if (GManager.instance.userSelectionManager.SelectedBoolValue)
  83. {
  84. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.DeletePeremanentAndProcessAccordingToResult(targetPermanents: new List<Permanent>() { guardPermanent }, activateClass: activateClass, successProcess: permanents => SuccessProcess(), failureProcess: null));
  85. IEnumerator SuccessProcess()
  86. {
  87. List<Permanent> removedPermanents = CardEffectCommons.GetPermanentsFromHashtable(hashtable).Filter(PermanentCondition);
  88. foreach (Permanent removed in removedPermanents)
  89. {
  90. removed.willBeRemoveField = false;
  91. removed.HideDeleteEffect();
  92. removed.HideHandBounceEffect();
  93. removed.HideDeckBounceEffect();
  94. removed.HideWillRemoveFieldEffect();
  95. }
  96. yield return null;
  97. }
  98. }
  99. }
  100. #endregion
  101. #region Target 1 Digimon gains [Guard]
  102. public static IEnumerator GainGuard(Permanent targetPermanent, EffectDuration effectDuration, ICardEffect activateClass)
  103. {
  104. if (targetPermanent == null) yield break;
  105. if (!CardEffectCommons.IsPermanentExistsOnBattleArea(targetPermanent)) yield break;
  106. if (activateClass == null) yield break;
  107. if (activateClass.EffectSourceCard == null) yield break;
  108. CardSource card = activateClass.EffectSourceCard;
  109. bool CanUseCondition()
  110. {
  111. return CardEffectCommons.IsPermanentExistsOnBattleArea(targetPermanent)
  112. && !targetPermanent.TopCard.CanNotBeAffected(activateClass);
  113. }
  114. ActivateClass guard = CardEffectFactory.GuardEffect(
  115. targetPermanent: targetPermanent,
  116. isInheritedEffect: false,
  117. condition: CanUseCondition,
  118. rootCardEffect: activateClass,
  119. card: targetPermanent.TopCard);
  120. CardEffectCommons.AddEffectToPermanent(
  121. targetPermanent: targetPermanent,
  122. effectDuration: effectDuration,
  123. card: card,
  124. cardEffect: guard,
  125. timing: EffectTiming.WhenRemoveField);
  126. if (!targetPermanent.TopCard.CanNotBeAffected(activateClass))
  127. {
  128. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateBuffEffect(targetPermanent));
  129. }
  130. }
  131. #endregion
  132. }