WhenDeleteOpponentDigimon.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 trigger "when a Digimon deletes opponent's Digimon" effect
  9. public static bool CanTriggerWhenDeleteOpponentDigimon(
  10. Hashtable hashtable,
  11. Func<Permanent, bool> winnerCondition,
  12. Func<Permanent, bool> loserCondition)
  13. {
  14. if (hashtable != null)
  15. {
  16. ICardEffect effect = GetCardEffectFromHashtable(hashtable);
  17. IBattle battle = GetBattleFromHashtable(hashtable);
  18. if (effect != null)
  19. {
  20. List<Permanent> permanents = new List<Permanent>();
  21. List<Hashtable> effectHashtables = GetHashtablesFromHashtable(hashtable);
  22. foreach (Hashtable effTable in effectHashtables)
  23. {
  24. Permanent permanent = GetPermanentFromHashtable(effTable);
  25. if (loserCondition == null || loserCondition(permanent))
  26. permanents.Add(permanent);
  27. }
  28. permanents = permanents.Filter(loserCondition);
  29. if (winnerCondition == null || winnerCondition(effect.EffectSourcePermanent))
  30. {
  31. if(loserCondition == null || permanents.Count > 0)
  32. {
  33. return true;
  34. }
  35. }
  36. }
  37. if (battle != null)
  38. {
  39. Hashtable battleHashtable = battle.hashtable;
  40. if (battleHashtable != null)
  41. {
  42. List<Permanent> WinnerPermanents = null;
  43. if (battleHashtable.ContainsKey("WinnerPermanents"))
  44. {
  45. if (battleHashtable["WinnerPermanents"] is List<Permanent>)
  46. {
  47. WinnerPermanents = (List<Permanent>)battleHashtable["WinnerPermanents"];
  48. }
  49. }
  50. bool WinnerCondition()
  51. {
  52. if (WinnerPermanents == null || WinnerPermanents.Count == 0)
  53. {
  54. if (winnerCondition == null)
  55. {
  56. return true;
  57. }
  58. }
  59. else
  60. {
  61. if (WinnerPermanents.Some((permanent) => permanent != null && permanent.TopCard != null && (winnerCondition == null || winnerCondition(permanent))))
  62. {
  63. return true;
  64. }
  65. }
  66. return false;
  67. }
  68. if (WinnerCondition())
  69. {
  70. if (battleHashtable.ContainsKey("LoserPermanents"))
  71. {
  72. List<Permanent> LoserPermanents = (List<Permanent>)battleHashtable["LoserPermanents"];
  73. if (LoserPermanents != null)
  74. {
  75. if (winnerCondition == null || LoserPermanents.Count((permanent) => permanent != null && permanent.TopCard != null && winnerCondition(permanent)) == 0)
  76. {
  77. if (loserCondition == null || LoserPermanents.Some((permanent) => permanent != null && permanent.TopCard != null && loserCondition(permanent)))
  78. {
  79. if (battleHashtable.ContainsKey("LoserPermanents_real"))
  80. {
  81. List<Permanent> LoserPermanents_real = (List<Permanent>)battleHashtable["LoserPermanents_real"];
  82. if (LoserPermanents_real != null)
  83. {
  84. if (LoserPermanents_real.Some((permanent) => permanent.IsDestroyedByBattle))
  85. {
  86. if (battleHashtable.ContainsKey("WinnerPermanents_real"))
  87. {
  88. List<Permanent> WinnerPermanents_real = (List<Permanent>)battleHashtable["WinnerPermanents_real"];
  89. if (WinnerPermanents_real != null)
  90. {
  91. if (WinnerPermanents_real.Some((permanent) => permanent != null && permanent.TopCard != null))
  92. {
  93. return true;
  94. }
  95. }
  96. }
  97. }
  98. }
  99. }
  100. }
  101. }
  102. }
  103. }
  104. }
  105. }
  106. }
  107. }
  108. return false;
  109. }
  110. #endregion
  111. }