Alliance.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System;
  4. using System.Linq;
  5. using UnityEngine;
  6. public partial class CardEffectCommons
  7. {
  8. #region Can activate [Alliance]
  9. public static bool CanActivateAlliance(Hashtable hashtable, CardSource card)
  10. {
  11. bool CanSelectPermanentCondition(Permanent permanent)
  12. {
  13. if (IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card))
  14. {
  15. if (permanent != card.PermanentOfThisCard())
  16. {
  17. if (CanActivateSuspendCostEffect(permanent.TopCard))
  18. {
  19. return true;
  20. }
  21. }
  22. }
  23. return false;
  24. }
  25. if (CardEffectCommons.IsExistOnBattleArea(card))
  26. {
  27. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentCondition))
  28. {
  29. return true;
  30. }
  31. }
  32. return false;
  33. }
  34. #endregion
  35. #region Effect process of [Alliance]
  36. public static IEnumerator AllianceProcess(Hashtable hashtable, ICardEffect activateClass, Permanent targetPermanent, CardSource card)
  37. {
  38. bool CanSelectPermanentCondition(Permanent permanent)
  39. {
  40. if (IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card))
  41. {
  42. if (permanent != targetPermanent)
  43. {
  44. if (CanActivateSuspendCostEffect(permanent.TopCard))
  45. {
  46. return true;
  47. }
  48. }
  49. }
  50. return false;
  51. }
  52. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentCondition))
  53. {
  54. Permanent selectedPermanent = null;
  55. int maxCount = Math.Min(1, MatchConditionPermanentCount(CanSelectPermanentCondition));
  56. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  57. selectPermanentEffect.SetUp(
  58. selectPlayer: card.Owner,
  59. canTargetCondition: CanSelectPermanentCondition,
  60. canTargetCondition_ByPreSelecetedList: null,
  61. canEndSelectCondition: null,
  62. maxCount: maxCount,
  63. canNoSelect: true,
  64. canEndNotMax: false,
  65. selectPermanentCoroutine: SelectPermanentCoroutine,
  66. afterSelectPermanentCoroutine: null,
  67. mode: SelectPermanentEffect.Mode.Custom,
  68. cardEffect: activateClass);
  69. selectPermanentEffect.SetUpCustomMessage("Select 1 Digimon to suspend.", "The opponent is selecting 1 Digimon to suspend.");
  70. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  71. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  72. {
  73. selectedPermanent = permanent;
  74. yield return null;
  75. }
  76. if (selectedPermanent != null)
  77. {
  78. if (selectedPermanent.TopCard != null)
  79. {
  80. if (!selectedPermanent.TopCard.CanNotBeAffected(activateClass))
  81. {
  82. if (CanActivateSuspendCostEffect(selectedPermanent.TopCard))
  83. {
  84. Permanent tapPermanent = selectedPermanent;
  85. yield return ContinuousController.instance.StartCoroutine(new SuspendPermanentsClass(
  86. new List<Permanent>() { tapPermanent },
  87. CardEffectHashtable(activateClass)).Tap());
  88. if (tapPermanent.TopCard != null)
  89. {
  90. if (tapPermanent.IsSuspended)
  91. {
  92. if (IsPermanentExistsOnOwnerBattleAreaDigimon(targetPermanent, card))
  93. {
  94. int plusDP = tapPermanent.DP;
  95. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.ChangeDigimonDP(
  96. targetPermanent: targetPermanent,
  97. changeValue: plusDP,
  98. effectDuration: EffectDuration.UntilEndAttack,
  99. activateClass: activateClass));
  100. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.ChangeDigimonSAttack(
  101. targetPermanent: targetPermanent,
  102. changeValue: 1,
  103. effectDuration: EffectDuration.UntilEndAttack,
  104. activateClass: activateClass));
  105. }
  106. }
  107. }
  108. }
  109. }
  110. }
  111. }
  112. }
  113. }
  114. #endregion
  115. #region Target 1 Digimon gains [Alliance]
  116. public static IEnumerator GainAlliance(Permanent targetPermanent, EffectDuration effectDuration, ICardEffect activateClass)
  117. {
  118. if (targetPermanent == null) yield break;
  119. if (!IsPermanentExistsOnBattleArea(targetPermanent)) yield break;
  120. if (activateClass == null) yield break;
  121. if (activateClass.EffectSourceCard == null) yield break;
  122. CardSource card = activateClass.EffectSourceCard;
  123. bool CanUseCondition()
  124. {
  125. if (IsPermanentExistsOnBattleArea(targetPermanent))
  126. {
  127. if (!targetPermanent.TopCard.CanNotBeAffected(activateClass))
  128. {
  129. return true;
  130. }
  131. }
  132. return false;
  133. }
  134. ActivateClass retaliation = CardEffectFactory.AllianceEffect(
  135. targetPermanent: targetPermanent,
  136. isInheritedEffect: false,
  137. condition: CanUseCondition,
  138. rootCardEffect: activateClass,
  139. card: targetPermanent.TopCard);
  140. AddEffectToPermanent(
  141. targetPermanent: targetPermanent,
  142. effectDuration: effectDuration,
  143. card: card,
  144. cardEffect: retaliation,
  145. timing: EffectTiming.OnAllyAttack);
  146. if (!targetPermanent.TopCard.CanNotBeAffected(activateClass))
  147. {
  148. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateBuffEffect(targetPermanent));
  149. }
  150. }
  151. #endregion
  152. #region Player gains effect to have Digimon gains [Alliance]
  153. public static IEnumerator GainAlliancePlayerEffect(Func<Permanent, bool> permanentCondition, EffectDuration effectDuration, ICardEffect activateClass)
  154. {
  155. if (activateClass == null) yield break;
  156. if (activateClass.EffectSourceCard == null) yield break;
  157. CardSource card = activateClass.EffectSourceCard;
  158. bool PermanentCondition(Permanent permanent)
  159. {
  160. if (IsPermanentExistsOnBattleArea(permanent))
  161. {
  162. if (!permanent.TopCard.CanNotBeAffected(activateClass))
  163. {
  164. if (permanentCondition == null || permanentCondition(permanent))
  165. {
  166. return true;
  167. }
  168. }
  169. }
  170. return false;
  171. }
  172. bool CanUseCondition()
  173. {
  174. return true;
  175. }
  176. ICardEffect alliance = CardEffectFactory.AllianceStaticEffect(permanentCondition: PermanentCondition, isInheritedEffect: false, card: card, condition: CanUseCondition);
  177. AddEffectToPlayer(effectDuration: effectDuration, card: card, cardEffect: alliance, timing: EffectTiming.OnAllyAttack);
  178. foreach (Permanent permanent in GManager.instance.turnStateMachine.gameContext.PermanentsForTurnPlayer)
  179. {
  180. if (PermanentCondition(permanent))
  181. {
  182. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateBuffEffect(permanent));
  183. }
  184. }
  185. }
  186. #endregion
  187. }