Retaliation.cs 7.5 KB

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