OnDeletion.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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 leaves the battle area" effect
  44. public static bool CanTriggerOnPermanentLeave(Hashtable hashtable, Func<Permanent, bool> permanentCondition)
  45. {
  46. List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
  47. if (hashtables != null)
  48. {
  49. foreach (Hashtable hashtable1 in hashtables)
  50. {
  51. Permanent permanent = GetPermanentFromHashtable(hashtable1);
  52. if (permanent != null)
  53. {
  54. if (permanent.TopCard != null)
  55. {
  56. if (permanentCondition != null)
  57. {
  58. if (permanentCondition(permanent))
  59. {
  60. return true;
  61. }
  62. }
  63. }
  64. }
  65. }
  66. }
  67. return false;
  68. }
  69. #endregion
  70. #region Can trigger "when permanent is deleted by battle" effects
  71. public static bool IsByBattle(Hashtable hashtable)
  72. {
  73. return GetBattleFromHashtable(hashtable) != null;
  74. }
  75. #endregion
  76. #region Can trigger "when permanent is deleted or played by effect that satisfies the condition" effects
  77. public static bool IsByEffect(Hashtable hashtable, Func<ICardEffect, bool> cardEffectCondition)
  78. {
  79. ICardEffect CardEffect = GetCardEffectFromHashtable(hashtable);
  80. if (CardEffect != null)
  81. {
  82. if (CardEffect.EffectSourceCard != null)
  83. {
  84. if (cardEffectCondition == null || cardEffectCondition(CardEffect))
  85. {
  86. return true;
  87. }
  88. }
  89. }
  90. return false;
  91. }
  92. #endregion
  93. #endregion
  94. #region Can activate
  95. #region Can activate [On Deletion] effect
  96. public static bool CanActivateOnDeletion(Hashtable hashtable, CardSource card)
  97. {
  98. if (card.IsToken)
  99. return true;
  100. List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
  101. if (hashtables != null)
  102. {
  103. foreach (Hashtable hashtable1 in hashtables)
  104. {
  105. CardSource TopCard = GetTopCardFromOneHashtable(hashtable1);
  106. if (TopCard != null)
  107. {
  108. if (TopCard.PermanentJustBeforeRemoveField != null)
  109. {
  110. if (card.PermanentJustBeforeRemoveField == TopCard.PermanentJustBeforeRemoveField)
  111. {
  112. return IsExistOnTrash(TopCard);
  113. }
  114. }
  115. }
  116. }
  117. }
  118. return false;
  119. }
  120. #endregion
  121. #region Whether any TopCard is in trash when check [On Deletion] effect
  122. public static bool IsTopCardInTrashOnDeletion(Hashtable hashtable)
  123. {
  124. List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
  125. if (hashtables != null)
  126. {
  127. foreach (Hashtable hashtable1 in hashtables)
  128. {
  129. CardSource TopCard = GetTopCardFromOneHashtable(hashtable1);
  130. if (TopCard != null)
  131. {
  132. if (IsExistOnTrash(TopCard) || TopCard.IsToken)
  133. {
  134. return true;
  135. }
  136. }
  137. }
  138. }
  139. return false;
  140. }
  141. #endregion
  142. #region Whether the card that uses the effect and the top card belonged to the same permanent
  143. public static bool IsTopCardSamePermanent(Hashtable hashtable, CardSource card)
  144. {
  145. if (card == null) return false;
  146. if (card.PermanentJustBeforeRemoveField == null) return false;
  147. List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
  148. if (hashtables != null)
  149. {
  150. foreach (Hashtable hashtable1 in hashtables)
  151. {
  152. CardSource TopCard = GetTopCardFromOneHashtable(hashtable1);
  153. if (TopCard != null)
  154. {
  155. if (TopCard.PermanentJustBeforeRemoveField != null)
  156. {
  157. if (card.PermanentJustBeforeRemoveField == TopCard.PermanentJustBeforeRemoveField)
  158. {
  159. return true;
  160. }
  161. }
  162. }
  163. }
  164. }
  165. return false;
  166. }
  167. #endregion
  168. #region Can activate [On Deletion] effect that can activate if the permanent conains specific name
  169. public static bool CanActivateSelfOnDeletionWithContainingCardName(Hashtable hashtable, string name, CardSource card)
  170. {
  171. return CanActivateOnDeletionWithContainingCardName(
  172. hashtable: hashtable,
  173. name: name,
  174. cardCondition: cardSource => cardSource == card
  175. );
  176. }
  177. public static bool CanActivateOnDeletionWithContainingCardName(
  178. Hashtable hashtable,
  179. string name,
  180. Func<CardSource, bool> cardCondition)
  181. {
  182. List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
  183. if (hashtables != null)
  184. {
  185. foreach (Hashtable hashtable1 in hashtables)
  186. {
  187. if (hashtable1 != null)
  188. {
  189. List<CardSource> CardSources = GetCardSourcesFromHashtable(hashtable1);
  190. if (CardSources != null)
  191. {
  192. if (CardSources.Some(cardSource => cardCondition == null || cardCondition(cardSource)))
  193. {
  194. if (hashtable1.ContainsKey("CardNames"))
  195. {
  196. if (hashtable1["CardNames"] is List<string>)
  197. {
  198. List<string> CardNames = (List<string>)hashtable1["CardNames"];
  199. if (CardNames != null)
  200. {
  201. if (CardNames.Count((cardName) => cardName.Contains(name)) >= 1)
  202. {
  203. return true;
  204. }
  205. }
  206. }
  207. }
  208. }
  209. }
  210. }
  211. }
  212. }
  213. return false;
  214. }
  215. #endregion
  216. #region Can activate [On Deletion] effect that can activate if the permanent conains specific trait
  217. public static bool CanActivateSelfOnDeletionWithContainingTrait(Hashtable hashtable, string name, CardSource card)
  218. {
  219. return CanActivateOnDeletionWithContainingTrait(
  220. hashtable: hashtable,
  221. name: name,
  222. cardCondition: cardSource => cardSource == card
  223. );
  224. }
  225. public static bool CanActivateOnDeletionWithContainingTrait(
  226. Hashtable hashtable,
  227. string name,
  228. Func<CardSource, bool> cardCondition)
  229. {
  230. List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
  231. if (hashtables != null)
  232. {
  233. foreach (Hashtable hashtable1 in hashtables)
  234. {
  235. if (hashtable1 != null)
  236. {
  237. List<CardSource> CardSources = GetCardSourcesFromHashtable(hashtable1);
  238. if (CardSources != null)
  239. {
  240. if (CardSources.Some(cardSource => cardCondition == null || cardCondition(cardSource)))
  241. {
  242. if (hashtable1.ContainsKey("TopCard"))
  243. {
  244. if (hashtable1["TopCard"] is CardSource)
  245. {
  246. CardSource topCard = (CardSource)hashtable1["TopCard"];
  247. if (topCard != null)
  248. {
  249. if (topCard.ContainsTraits(name))
  250. {
  251. return true;
  252. }
  253. }
  254. }
  255. }
  256. }
  257. }
  258. }
  259. }
  260. }
  261. return false;
  262. }
  263. #endregion
  264. #region Can activate [On Deletion] effect that can activate if the permanent has specific colors
  265. public static bool CanActivateSelfOnDeletionWithCardColors(Hashtable hashtable, Func<List<CardColor>, bool> cardColorCondition, CardSource card)
  266. {
  267. return CanActivateOnDeletionWithCardColors(
  268. hashtable: hashtable,
  269. cardColorCondition: cardColorCondition,
  270. cardCondition: cardSource => cardSource == card
  271. );
  272. }
  273. public static bool CanActivateOnDeletionWithCardColors(
  274. Hashtable hashtable,
  275. Func<List<CardColor>, bool> cardColorCondition,
  276. Func<CardSource, bool> cardCondition)
  277. {
  278. if (hashtable != null)
  279. {
  280. List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
  281. if (hashtables != null)
  282. {
  283. foreach (Hashtable hashtable1 in hashtables)
  284. {
  285. List<CardSource> CardSources = GetCardSourcesFromHashtable(hashtable1);
  286. if (CardSources != null)
  287. {
  288. if (CardSources.Some(cardSource => cardCondition == null || cardCondition(cardSource)))
  289. {
  290. if (hashtable1.ContainsKey("CardColors"))
  291. {
  292. if (hashtable1["CardColors"] is List<CardColor>)
  293. {
  294. List<CardColor> CardColors = (List<CardColor>)hashtable1["CardColors"];
  295. if (CardColors != null)
  296. {
  297. if (cardColorCondition == null || cardColorCondition(CardColors))
  298. {
  299. return true;
  300. }
  301. }
  302. }
  303. }
  304. }
  305. }
  306. }
  307. }
  308. }
  309. return false;
  310. }
  311. #endregion
  312. #region Can activate [On Deletion] effect that can activate if the permanent has Save text
  313. public static bool CanActivateSelefOnDeletionWithSaveText(Hashtable hashtable, CardSource card)
  314. {
  315. return CanActivateOnDeletionWithSaveText(
  316. hashtable: hashtable,
  317. cardCondition: cardSource => cardSource == card
  318. );
  319. }
  320. public static bool CanActivateOnDeletionWithSaveText(
  321. Hashtable hashtable,
  322. Func<CardSource, bool> cardCondition)
  323. {
  324. List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
  325. if (hashtables != null)
  326. {
  327. foreach (Hashtable hashtable1 in hashtables)
  328. {
  329. List<CardSource> CardSources = GetCardSourcesFromHashtable(hashtable1);
  330. if (CardSources != null)
  331. {
  332. if (CardSources.Some(cardSource => cardCondition == null || cardCondition(cardSource)))
  333. {
  334. if (hashtable1.ContainsKey("HasSaveText"))
  335. {
  336. if (hashtable1["HasSaveText"] is bool)
  337. {
  338. bool HasSaveText = (bool)hashtable1["HasSaveText"];
  339. if (HasSaveText)
  340. {
  341. return true;
  342. }
  343. }
  344. }
  345. }
  346. }
  347. }
  348. }
  349. return false;
  350. }
  351. #endregion
  352. #endregion
  353. }