Guard.cs 6.6 KB

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