Guard.cs 6.5 KB

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