OnDeletion.cs 12 KB

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