OnDeletion.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System;
  4. using System.Linq;
  5. using UnityEngine;
  6. using UnityEditor.Rendering;
  7. public partial class CardEffectCommons
  8. {
  9. #region Can trigger
  10. #region Can trigger [On Deletion] effect
  11. public static bool CanTriggerOnDeletion(Hashtable hashtable, CardSource card)
  12. {
  13. return CanTriggerOnPermanentDeleted(hashtable, (permanent) => permanent.cardSources.Contains(card));
  14. }
  15. #endregion
  16. #region Can trigger "when permanent is deleted" effect
  17. public static bool CanTriggerOnPermanentDeleted(Hashtable hashtable, Func<Permanent, bool> permanentCondition)
  18. {
  19. List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
  20. if (hashtables != null)
  21. {
  22. foreach (Hashtable hashtable1 in hashtables)
  23. {
  24. Permanent permanent = GetPermanentFromHashtable(hashtable1);
  25. if (permanent != null)
  26. {
  27. if (permanent.TopCard != null)
  28. {
  29. if (permanentCondition != null)
  30. {
  31. if (permanentCondition(permanent))
  32. {
  33. return true;
  34. }
  35. }
  36. }
  37. }
  38. }
  39. }
  40. return false;
  41. }
  42. #endregion
  43. #region Can trigger "when permanent is deleted by battle" effects
  44. public static bool IsByBattle(Hashtable hashtable)
  45. {
  46. return GetBattleFromHashtable(hashtable) != null;
  47. }
  48. #endregion
  49. #region Can trigger "when permanent is deleted or played by effect that satisfies the condition" effects
  50. public static bool IsByEffect(Hashtable hashtable, Func<ICardEffect, bool> cardEffectCondition)
  51. {
  52. ICardEffect CardEffect = GetCardEffectFromHashtable(hashtable);
  53. if (CardEffect != null)
  54. {
  55. if (CardEffect.EffectSourceCard != null)
  56. {
  57. if (cardEffectCondition == null || cardEffectCondition(CardEffect))
  58. {
  59. return true;
  60. }
  61. }
  62. }
  63. return false;
  64. }
  65. #endregion
  66. #endregion
  67. #region Can activate
  68. #region Can activate [On Deletion] effect(not inherited)
  69. public static bool CanActivateOnDeletion(CardSource card)
  70. {
  71. return IsExistOnTrash(card);
  72. }
  73. #endregion
  74. #region Can activate [On Deletion] effect(inherited)
  75. public static bool CanActivateOnDeletionInherited(Hashtable hashtable, CardSource card)
  76. {
  77. if (IsExistOnTrash(card))
  78. {
  79. if (IsTopCardInTrashOnDeletion(hashtable))
  80. {
  81. if (IsTopCardSamePermanent(hashtable, card))
  82. {
  83. return true;
  84. }
  85. }
  86. }
  87. return false;
  88. }
  89. #endregion
  90. #region Whether TopCard is in trash when check [On Deletion] effect
  91. public static bool IsTopCardInTrashOnDeletion(Hashtable hashtable)
  92. {
  93. List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
  94. if (hashtables != null)
  95. {
  96. foreach (Hashtable hashtable1 in hashtables)
  97. {
  98. CardSource TopCard = GetTopCardFromOneHashtable(hashtable1);
  99. if (TopCard != null)
  100. {
  101. if (IsExistOnTrash(TopCard))
  102. {
  103. return true;
  104. }
  105. }
  106. }
  107. }
  108. return false;
  109. }
  110. #endregion
  111. #region Whether the card that uses the effect and the top card belonged to the same permanent
  112. public static bool IsTopCardSamePermanent(Hashtable hashtable, CardSource card)
  113. {
  114. if (card == null) return false;
  115. if (card.PermanentJustBeforeRemoveField == null) return false;
  116. List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
  117. if (hashtables != null)
  118. {
  119. foreach (Hashtable hashtable1 in hashtables)
  120. {
  121. CardSource TopCard = GetTopCardFromOneHashtable(hashtable1);
  122. if (TopCard != null)
  123. {
  124. if (TopCard.PermanentJustBeforeRemoveField != null)
  125. {
  126. if (card.PermanentJustBeforeRemoveField == TopCard.PermanentJustBeforeRemoveField)
  127. {
  128. return true;
  129. }
  130. }
  131. }
  132. }
  133. }
  134. return false;
  135. }
  136. #endregion
  137. #region Can activate [On Deletion] effect that can activate if the permanent conains specific name
  138. public static bool CanActivateSelfOnDeletionWithContainingCardName(Hashtable hashtable, string name, CardSource card)
  139. {
  140. return CanActivateOnDeletionWithContainingCardName(
  141. hashtable: hashtable,
  142. name: name,
  143. cardCondition: cardSource => cardSource == card
  144. );
  145. }
  146. public static bool CanActivateOnDeletionWithContainingCardName(
  147. Hashtable hashtable,
  148. string name,
  149. Func<CardSource, bool> cardCondition)
  150. {
  151. List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
  152. if (hashtables != null)
  153. {
  154. foreach (Hashtable hashtable1 in hashtables)
  155. {
  156. if (hashtable1 != null)
  157. {
  158. List<CardSource> CardSources = GetCardSourcesFromHashtable(hashtable1);
  159. if (CardSources != null)
  160. {
  161. if (CardSources.Some(cardSource => cardCondition == null || cardCondition(cardSource)))
  162. {
  163. if (hashtable1.ContainsKey("CardNames"))
  164. {
  165. if (hashtable1["CardNames"] is List<string>)
  166. {
  167. List<string> CardNames = (List<string>)hashtable1["CardNames"];
  168. if (CardNames != null)
  169. {
  170. if (CardNames.Count((cardName) => cardName.Contains(name)) >= 1)
  171. {
  172. return true;
  173. }
  174. }
  175. }
  176. }
  177. }
  178. }
  179. }
  180. }
  181. }
  182. return false;
  183. }
  184. #endregion
  185. #region Can activate [On Deletion] effect that can activate if the permanent has specific colors
  186. public static bool CanActivateSelfOnDeletionWithCardColors(Hashtable hashtable, Func<List<CardColor>, bool> cardColorCondition, CardSource card)
  187. {
  188. return CanActivateOnDeletionWithCardColors(
  189. hashtable: hashtable,
  190. cardColorCondition: cardColorCondition,
  191. cardCondition: cardSource => cardSource == card
  192. );
  193. }
  194. public static bool CanActivateOnDeletionWithCardColors(
  195. Hashtable hashtable,
  196. Func<List<CardColor>, bool> cardColorCondition,
  197. Func<CardSource, bool> cardCondition)
  198. {
  199. if (hashtable != null)
  200. {
  201. List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
  202. if (hashtables != null)
  203. {
  204. foreach (Hashtable hashtable1 in hashtables)
  205. {
  206. List<CardSource> CardSources = GetCardSourcesFromHashtable(hashtable1);
  207. if (CardSources != null)
  208. {
  209. if (CardSources.Some(cardSource => cardCondition == null || cardCondition(cardSource)))
  210. {
  211. if (hashtable1.ContainsKey("CardColors"))
  212. {
  213. if (hashtable1["CardColors"] is List<CardColor>)
  214. {
  215. List<CardColor> CardColors = (List<CardColor>)hashtable1["CardColors"];
  216. if (CardColors != null)
  217. {
  218. if (cardColorCondition == null || cardColorCondition(CardColors))
  219. {
  220. return true;
  221. }
  222. }
  223. }
  224. }
  225. }
  226. }
  227. }
  228. }
  229. }
  230. return false;
  231. }
  232. #endregion
  233. #region Can activate [On Deletion] effect that can activate if the permanent has Save text
  234. public static bool CanActivateSelefOnDeletionWithSaveText(Hashtable hashtable, CardSource card)
  235. {
  236. return CanActivateOnDeletionWithSaveText(
  237. hashtable: hashtable,
  238. cardCondition: cardSource => cardSource == card
  239. );
  240. }
  241. public static bool CanActivateOnDeletionWithSaveText(
  242. Hashtable hashtable,
  243. Func<CardSource, bool> cardCondition)
  244. {
  245. List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
  246. if (hashtables != null)
  247. {
  248. foreach (Hashtable hashtable1 in hashtables)
  249. {
  250. List<CardSource> CardSources = GetCardSourcesFromHashtable(hashtable1);
  251. if (CardSources != null)
  252. {
  253. if (CardSources.Some(cardSource => cardCondition == null || cardCondition(cardSource)))
  254. {
  255. if (hashtable1.ContainsKey("HasSaveText"))
  256. {
  257. if (hashtable1["HasSaveText"] is bool)
  258. {
  259. bool HasSaveText = (bool)hashtable1["HasSaveText"];
  260. if (HasSaveText)
  261. {
  262. return true;
  263. }
  264. }
  265. }
  266. }
  267. }
  268. }
  269. }
  270. return false;
  271. }
  272. #endregion
  273. #endregion
  274. }