Retaliation.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 [Retaliation]
  9. public static bool CanActivateRetaliation(Hashtable hashtable, ICardEffect cardEffect)
  10. {
  11. List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
  12. if (hashtables != null)
  13. {
  14. foreach (Hashtable hashtable1 in hashtables)
  15. {
  16. if (hashtable1 != null)
  17. {
  18. CardSource TopCard = GetTopCardFromOneHashtable(hashtable1);
  19. if (TopCard != null)
  20. {
  21. bool sourceIsToken = cardEffect.EffectSourceCard?.IsToken ?? false;
  22. if (IsTopCardStillInTrash(cardEffect) || sourceIsToken)
  23. {
  24. IBattle battle = GetBattleFromHashtable(hashtable);
  25. if (battle != null)
  26. {
  27. Hashtable battleHashtable = battle.hashtable;
  28. if (battleHashtable != null)
  29. {
  30. List<Permanent> WinnerPermanents = GetWinnerPermanentsRealFromHashtable(battleHashtable);
  31. if (WinnerPermanents != null)
  32. {
  33. if (WinnerPermanents.Some(permanent => IsOpponentPermanent(permanent, TopCard)))
  34. {
  35. return true;
  36. }
  37. }
  38. }
  39. }
  40. }
  41. }
  42. }
  43. }
  44. }
  45. return false;
  46. }
  47. #endregion
  48. #region Effect process of [Retaliation]
  49. public static IEnumerator RetaliationProcess(Hashtable hashtable, ICardEffect activateClass)
  50. {
  51. if (hashtable != null)
  52. {
  53. List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
  54. if (hashtables != null)
  55. {
  56. foreach (Hashtable hashtable1 in hashtables)
  57. {
  58. if (hashtable1 != null)
  59. {
  60. CardSource TopCard = GetTopCardFromOneHashtable(hashtable1);
  61. if (TopCard != null)
  62. {
  63. if (IsByBattle(hashtable))
  64. {
  65. IBattle battle = GetBattleFromHashtable(hashtable);
  66. if (battle != null)
  67. {
  68. Hashtable battleHashtable = battle.hashtable;
  69. if (battleHashtable != null)
  70. {
  71. List<Permanent> WinnerPermanents = GetWinnerPermanentsRealFromHashtable(battleHashtable);
  72. if (WinnerPermanents != null)
  73. {
  74. List<Permanent> destroyTargetPermanents = WinnerPermanents.Filter(permanent => IsOpponentPermanent(permanent, TopCard));
  75. if (destroyTargetPermanents.Count >= 1)
  76. {
  77. yield return ContinuousController.instance.StartCoroutine(new DestroyPermanentsClass(destroyTargetPermanents, CardEffectHashtable(activateClass)).Destroy());
  78. }
  79. else //In case of tie there is no winner permanents but the other loser permanent is the target
  80. {
  81. List<Permanent> LoserPermanents = GetLoserPermanentsFromHashtable(battleHashtable);
  82. if (LoserPermanents != null)
  83. {
  84. destroyTargetPermanents = LoserPermanents.Filter(permanent => IsOpponentPermanent(permanent, TopCard));
  85. if (destroyTargetPermanents.Count >= 1)
  86. {
  87. yield return ContinuousController.instance.StartCoroutine(new DestroyPermanentsClass(destroyTargetPermanents, CardEffectHashtable(activateClass)).Destroy());
  88. }
  89. }
  90. }
  91. }
  92. }
  93. }
  94. }
  95. }
  96. }
  97. }
  98. }
  99. }
  100. }
  101. #endregion
  102. #region Target 1 Digimon gains [Retaliation]
  103. public static IEnumerator GainRetaliation(Permanent targetPermanent, EffectDuration effectDuration, ICardEffect activateClass)
  104. {
  105. if (targetPermanent == null) yield break;
  106. if (!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. if (IsPermanentExistsOnBattleArea(targetPermanent))
  113. {
  114. if (!targetPermanent.TopCard.CanNotBeAffected(activateClass))
  115. {
  116. return true;
  117. }
  118. }
  119. return false;
  120. }
  121. ActivateClass retaliation = CardEffectFactory.RetaliationEffect(targetPermanent: targetPermanent, isInheritedEffect: false, condition: CanUseCondition, rootCardEffect: activateClass, targetPermanent.TopCard);
  122. AddEffectToPermanent(targetPermanent: targetPermanent, effectDuration: effectDuration, card: card, cardEffect: retaliation, timing: EffectTiming.OnDestroyedAnyone);
  123. if (!targetPermanent.TopCard.CanNotBeAffected(activateClass))
  124. {
  125. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateBuffEffect(targetPermanent));
  126. }
  127. }
  128. #endregion
  129. }