OnDeletion.cs 13 KB

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