WhenDeleteOpponentDigimonByBattle.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 by battle" effect
  9. public static bool CanTriggerWhenDeleteOpponentDigimonByBattle(
  10. Hashtable hashtable,
  11. Func<Permanent, bool> winnerCondition,
  12. Func<Permanent, bool> loserCondition,
  13. bool isOnlyWinnerSurvive,
  14. Func<Permanent, bool> winnerRealCondition = null,
  15. Func<Permanent, bool> loserRealCondition = null)
  16. {
  17. if (hashtable != null)
  18. {
  19. IBattle battle = GetBattleFromHashtable(hashtable);
  20. if (battle != null)
  21. {
  22. Hashtable battleHashtable = battle.hashtable;
  23. if (battleHashtable != null)
  24. {
  25. List<Permanent> WinnerPermanents = null;
  26. if (battleHashtable.ContainsKey("WinnerPermanents"))
  27. {
  28. if (battleHashtable["WinnerPermanents"] is List<Permanent>)
  29. {
  30. WinnerPermanents = (List<Permanent>)battleHashtable["WinnerPermanents"];
  31. }
  32. }
  33. bool WinnerCondition()
  34. {
  35. if (WinnerPermanents == null || WinnerPermanents.Count == 0)
  36. {
  37. if (winnerCondition == null)
  38. {
  39. return true;
  40. }
  41. }
  42. else
  43. {
  44. if (WinnerPermanents.Some((permanent) => permanent != null && permanent.TopCard != null && (winnerCondition == null || winnerCondition(permanent))))
  45. {
  46. return true;
  47. }
  48. }
  49. return false;
  50. }
  51. if (WinnerCondition())
  52. {
  53. if (battleHashtable.ContainsKey("LoserPermanents"))
  54. {
  55. List<Permanent> LoserPermanents = (List<Permanent>)battleHashtable["LoserPermanents"];
  56. if (LoserPermanents != null)
  57. {
  58. if (!isOnlyWinnerSurvive || winnerCondition == null || LoserPermanents.Count((permanent) => permanent != null && permanent.TopCard != null && winnerCondition(permanent)) == 0)
  59. {
  60. if (loserCondition == null || LoserPermanents.Some((permanent) => permanent != null && permanent.TopCard != null && loserCondition(permanent)))
  61. {
  62. if (battleHashtable.ContainsKey("LoserPermanents_real"))
  63. {
  64. List<Permanent> LoserPermanents_real = (List<Permanent>)battleHashtable["LoserPermanents_real"];
  65. if (LoserPermanents_real != null)
  66. {
  67. if (loserRealCondition == null || LoserPermanents_real.Some((permanent) => permanent.IsDestroyedByBattle &&
  68. (loserRealCondition(permanent))))
  69. {
  70. if (battleHashtable.ContainsKey("WinnerPermanents_real"))
  71. {
  72. List<Permanent> WinnerPermanents_real = (List<Permanent>)battleHashtable["WinnerPermanents_real"];
  73. if (WinnerPermanents_real != null)
  74. {
  75. if (winnerRealCondition == null || WinnerPermanents_real.Some((permanent) => permanent != null && permanent.TopCard != null && (winnerRealCondition(permanent))))
  76. {
  77. return true;
  78. }
  79. }
  80. }
  81. }
  82. }
  83. }
  84. }
  85. }
  86. }
  87. }
  88. }
  89. }
  90. }
  91. }
  92. return false;
  93. }
  94. #endregion
  95. }