OnDeletion.cs 13 KB

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