Retaliation.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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)
  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. if (IsByBattle(hashtable))
  22. {
  23. IBattle battle = GetBattleFromHashtable(hashtable);
  24. if (battle != null)
  25. {
  26. Hashtable battleHashtable = battle.hashtable;
  27. if (battleHashtable != null)
  28. {
  29. List<Permanent> WinnerPermanents = GetWinnerPermanentsRealFromHashtable(battleHashtable);
  30. if (WinnerPermanents != null)
  31. {
  32. if (WinnerPermanents.Count((permanent) => permanent.cardSources.Contains(TopCard)) == 0)
  33. {
  34. bool canDestroyWinner = WinnerPermanents.Some(permanent => IsOpponentPermanent(permanent, TopCard));
  35. if (canDestroyWinner)
  36. {
  37. List<Permanent> LoserPermanents = GetLoserPermanentsFromHashtable(battleHashtable);
  38. if (LoserPermanents != null)
  39. {
  40. if (LoserPermanents.Some((permanent) => permanent.cardSources.Contains(TopCard)))
  41. {
  42. return true;
  43. }
  44. }
  45. }
  46. }
  47. }
  48. }
  49. }
  50. }
  51. }
  52. }
  53. }
  54. }
  55. return false;
  56. }
  57. #endregion
  58. #region Effect process of [Retaliation]
  59. public static IEnumerator RetaliationProcess(Hashtable hashtable, ICardEffect activateClass)
  60. {
  61. if (hashtable != null)
  62. {
  63. List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
  64. if (hashtables != null)
  65. {
  66. foreach (Hashtable hashtable1 in hashtables)
  67. {
  68. if (hashtable1 != null)
  69. {
  70. CardSource TopCard = GetTopCardFromOneHashtable(hashtable1);
  71. if (TopCard != null)
  72. {
  73. if (IsByBattle(hashtable))
  74. {
  75. IBattle battle = GetBattleFromHashtable(hashtable);
  76. if (battle != null)
  77. {
  78. Hashtable battleHashtable = battle.hashtable;
  79. if (battleHashtable != null)
  80. {
  81. List<Permanent> WinnerPermanents = GetWinnerPermanentsRealFromHashtable(battleHashtable);
  82. if (WinnerPermanents != null)
  83. {
  84. List<Permanent> destroyTargetPermanents = WinnerPermanents.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. #endregion
  100. #region Target 1 Digimon gains [Retaliation]
  101. public static IEnumerator GainRetaliation(Permanent targetPermanent, EffectDuration effectDuration, ICardEffect activateClass)
  102. {
  103. if (targetPermanent == null) yield break;
  104. if (!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. if (IsPermanentExistsOnBattleArea(targetPermanent))
  111. {
  112. if (!targetPermanent.TopCard.CanNotBeAffected(activateClass))
  113. {
  114. return true;
  115. }
  116. }
  117. return false;
  118. }
  119. ActivateClass retaliation = CardEffectFactory.RetaliationEffect(targetPermanent: targetPermanent, isInheritedEffect: false, condition: CanUseCondition, rootCardEffect: activateClass, targetPermanent.TopCard);
  120. AddEffectToPermanent(targetPermanent: targetPermanent, effectDuration: effectDuration, card: card, cardEffect: retaliation, timing: EffectTiming.OnDestroyedAnyone);
  121. if (!targetPermanent.TopCard.CanNotBeAffected(activateClass))
  122. {
  123. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateBuffEffect(targetPermanent));
  124. }
  125. }
  126. #endregion
  127. }