Retaliation.cs 6.4 KB

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