OnDeletion.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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 (IsTopCardInTrashOnDeletion(hashtable))
  78. {
  79. if (IsTopCardSamePermanent(hashtable, card))
  80. {
  81. return true;
  82. }
  83. }
  84. return false;
  85. }
  86. #endregion
  87. #region Whether TopCard is in trash when check [On Deletion] effect
  88. public static bool IsTopCardInTrashOnDeletion(Hashtable hashtable)
  89. {
  90. List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
  91. if (hashtables != null)
  92. {
  93. foreach (Hashtable hashtable1 in hashtables)
  94. {
  95. CardSource TopCard = GetTopCardFromOneHashtable(hashtable1);
  96. if (TopCard != null)
  97. {
  98. if (IsExistOnTrash(TopCard) || TopCard.IsToken)
  99. {
  100. return true;
  101. }
  102. }
  103. }
  104. }
  105. return false;
  106. }
  107. #endregion
  108. #region Whether the card that uses the effect and the top card belonged to the same permanent
  109. public static bool IsTopCardSamePermanent(Hashtable hashtable, CardSource card)
  110. {
  111. if (card == null) return false;
  112. if (card.PermanentJustBeforeRemoveField == null) return false;
  113. List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
  114. if (hashtables != null)
  115. {
  116. foreach (Hashtable hashtable1 in hashtables)
  117. {
  118. CardSource TopCard = GetTopCardFromOneHashtable(hashtable1);
  119. if (TopCard != null)
  120. {
  121. if (TopCard.PermanentJustBeforeRemoveField != null)
  122. {
  123. if (card.PermanentJustBeforeRemoveField == TopCard.PermanentJustBeforeRemoveField)
  124. {
  125. return true;
  126. }
  127. }
  128. }
  129. }
  130. }
  131. return false;
  132. }
  133. #endregion
  134. #region Can activate [On Deletion] effect that can activate if the permanent conains specific name
  135. public static bool CanActivateSelfOnDeletionWithContainingCardName(Hashtable hashtable, string name, CardSource card)
  136. {
  137. return CanActivateOnDeletionWithContainingCardName(
  138. hashtable: hashtable,
  139. name: name,
  140. cardCondition: cardSource => cardSource == card
  141. );
  142. }
  143. public static bool CanActivateOnDeletionWithContainingCardName(
  144. Hashtable hashtable,
  145. string name,
  146. Func<CardSource, bool> cardCondition)
  147. {
  148. List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
  149. if (hashtables != null)
  150. {
  151. foreach (Hashtable hashtable1 in hashtables)
  152. {
  153. if (hashtable1 != null)
  154. {
  155. List<CardSource> CardSources = GetCardSourcesFromHashtable(hashtable1);
  156. if (CardSources != null)
  157. {
  158. if (CardSources.Some(cardSource => cardCondition == null || cardCondition(cardSource)))
  159. {
  160. if (hashtable1.ContainsKey("CardNames"))
  161. {
  162. if (hashtable1["CardNames"] is List<string>)
  163. {
  164. List<string> CardNames = (List<string>)hashtable1["CardNames"];
  165. if (CardNames != null)
  166. {
  167. if (CardNames.Count((cardName) => cardName.Contains(name)) >= 1)
  168. {
  169. return true;
  170. }
  171. }
  172. }
  173. }
  174. }
  175. }
  176. }
  177. }
  178. }
  179. return false;
  180. }
  181. #endregion
  182. #region Can activate [On Deletion] effect that can activate if the permanent conains specific trait
  183. public static bool CanActivateSelfOnDeletionWithContainingTrait(Hashtable hashtable, string name, CardSource card)
  184. {
  185. return CanActivateOnDeletionWithContainingTrait(
  186. hashtable: hashtable,
  187. name: name,
  188. cardCondition: cardSource => cardSource == card
  189. );
  190. }
  191. public static bool CanActivateOnDeletionWithContainingTrait(
  192. Hashtable hashtable,
  193. string name,
  194. Func<CardSource, bool> cardCondition)
  195. {
  196. List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
  197. if (hashtables != null)
  198. {
  199. foreach (Hashtable hashtable1 in hashtables)
  200. {
  201. if (hashtable1 != null)
  202. {
  203. List<CardSource> CardSources = GetCardSourcesFromHashtable(hashtable1);
  204. if (CardSources != null)
  205. {
  206. if (CardSources.Some(cardSource => cardCondition == null || cardCondition(cardSource)))
  207. {
  208. if (hashtable1.ContainsKey("TopCard"))
  209. {
  210. if (hashtable1["TopCard"] is CardSource)
  211. {
  212. CardSource topCard = (CardSource)hashtable1["TopCard"];
  213. if (topCard != null)
  214. {
  215. if (topCard.ContainsTraits(name))
  216. {
  217. return true;
  218. }
  219. }
  220. }
  221. }
  222. }
  223. }
  224. }
  225. }
  226. }
  227. return false;
  228. }
  229. #endregion
  230. #region Can activate [On Deletion] effect that can activate if the permanent has specific colors
  231. public static bool CanActivateSelfOnDeletionWithCardColors(Hashtable hashtable, Func<List<CardColor>, bool> cardColorCondition, CardSource card)
  232. {
  233. return CanActivateOnDeletionWithCardColors(
  234. hashtable: hashtable,
  235. cardColorCondition: cardColorCondition,
  236. cardCondition: cardSource => cardSource == card
  237. );
  238. }
  239. public static bool CanActivateOnDeletionWithCardColors(
  240. Hashtable hashtable,
  241. Func<List<CardColor>, bool> cardColorCondition,
  242. Func<CardSource, bool> cardCondition)
  243. {
  244. if (hashtable != null)
  245. {
  246. List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
  247. if (hashtables != null)
  248. {
  249. foreach (Hashtable hashtable1 in hashtables)
  250. {
  251. List<CardSource> CardSources = GetCardSourcesFromHashtable(hashtable1);
  252. if (CardSources != null)
  253. {
  254. if (CardSources.Some(cardSource => cardCondition == null || cardCondition(cardSource)))
  255. {
  256. if (hashtable1.ContainsKey("CardColors"))
  257. {
  258. if (hashtable1["CardColors"] is List<CardColor>)
  259. {
  260. List<CardColor> CardColors = (List<CardColor>)hashtable1["CardColors"];
  261. if (CardColors != null)
  262. {
  263. if (cardColorCondition == null || cardColorCondition(CardColors))
  264. {
  265. return true;
  266. }
  267. }
  268. }
  269. }
  270. }
  271. }
  272. }
  273. }
  274. }
  275. return false;
  276. }
  277. #endregion
  278. #region Can activate [On Deletion] effect that can activate if the permanent has Save text
  279. public static bool CanActivateSelefOnDeletionWithSaveText(Hashtable hashtable, CardSource card)
  280. {
  281. return CanActivateOnDeletionWithSaveText(
  282. hashtable: hashtable,
  283. cardCondition: cardSource => cardSource == card
  284. );
  285. }
  286. public static bool CanActivateOnDeletionWithSaveText(
  287. Hashtable hashtable,
  288. Func<CardSource, bool> cardCondition)
  289. {
  290. List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
  291. if (hashtables != null)
  292. {
  293. foreach (Hashtable hashtable1 in hashtables)
  294. {
  295. List<CardSource> CardSources = GetCardSourcesFromHashtable(hashtable1);
  296. if (CardSources != null)
  297. {
  298. if (CardSources.Some(cardSource => cardCondition == null || cardCondition(cardSource)))
  299. {
  300. if (hashtable1.ContainsKey("HasSaveText"))
  301. {
  302. if (hashtable1["HasSaveText"] is bool)
  303. {
  304. bool HasSaveText = (bool)hashtable1["HasSaveText"];
  305. if (HasSaveText)
  306. {
  307. return true;
  308. }
  309. }
  310. }
  311. }
  312. }
  313. }
  314. }
  315. return false;
  316. }
  317. #endregion
  318. #endregion
  319. }