GetFromHashtable.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System;
  4. using System.Linq;
  5. using UnityEngine;
  6. public partial class CardEffectCommons
  7. {
  8. #region Get CardEffect from hashtable
  9. public static ICardEffect GetCardEffectFromHashtable(Hashtable hashtable)
  10. {
  11. if (hashtable != null)
  12. {
  13. if (hashtable.ContainsKey("CardEffect"))
  14. {
  15. if (hashtable["CardEffect"] is ICardEffect)
  16. {
  17. ICardEffect CardEffect = (ICardEffect)hashtable["CardEffect"];
  18. return CardEffect;
  19. }
  20. }
  21. }
  22. return null;
  23. }
  24. #endregion
  25. #region Get Root from hashtable
  26. public static SelectCardEffect.Root GetRootFromHashtable(Hashtable hashtable)
  27. {
  28. if (hashtable != null)
  29. {
  30. if (hashtable.ContainsKey("Root"))
  31. {
  32. if (hashtable["Root"] is SelectCardEffect.Root)
  33. {
  34. SelectCardEffect.Root Root = (SelectCardEffect.Root)hashtable["Root"];
  35. return Root;
  36. }
  37. }
  38. }
  39. return SelectCardEffect.Root.None;
  40. }
  41. #endregion
  42. #region Get IsAttack from hashtable
  43. public static bool IsAttack(Hashtable hashtable)
  44. {
  45. if (hashtable != null)
  46. {
  47. if (hashtable.ContainsKey("IsAttack"))
  48. {
  49. if (hashtable["IsAttack"] is bool)
  50. {
  51. return (bool)hashtable["IsAttack"];
  52. }
  53. }
  54. }
  55. return false;
  56. }
  57. #endregion
  58. #region Get IsBlock from hashtable
  59. public static bool IsBlock(Hashtable hashtable)
  60. {
  61. if (hashtable != null)
  62. {
  63. if (hashtable.ContainsKey("IsBlock"))
  64. {
  65. if (hashtable["IsBlock"] is bool)
  66. {
  67. return (bool)hashtable["IsBlock"];
  68. }
  69. }
  70. }
  71. return false;
  72. }
  73. #endregion
  74. #region Get IsBurst from hashtable
  75. public static bool IsBurst(Hashtable hashtable)
  76. {
  77. if (hashtable != null)
  78. {
  79. if (hashtable.ContainsKey("IsBurst"))
  80. {
  81. if (hashtable["IsBurst"] is bool)
  82. {
  83. return (bool)hashtable["IsBurst"];
  84. }
  85. }
  86. }
  87. return false;
  88. }
  89. #endregion
  90. #region Get IsFromSameDigimon from hashtable
  91. public static bool IsFromSameDigimon(Hashtable hashtable)
  92. {
  93. if (hashtable != null)
  94. {
  95. if (hashtable.ContainsKey("isFromSameDigimon"))
  96. {
  97. if (hashtable["isFromSameDigimon"] is bool)
  98. {
  99. return (bool)hashtable["isFromSameDigimon"];
  100. }
  101. }
  102. }
  103. return false;
  104. }
  105. #endregion
  106. #region Get IsFromDigimon from hashtable
  107. public static bool IsFromDigimon(Hashtable hashtable)
  108. {
  109. if (hashtable != null)
  110. {
  111. if (hashtable.ContainsKey("isFromDigimon"))
  112. {
  113. if (hashtable["isFromDigimon"] is bool)
  114. {
  115. return (bool)hashtable["isFromDigimon"];
  116. }
  117. }
  118. }
  119. return false;
  120. }
  121. #endregion
  122. #region Get IsFromDigimonDigivolutionCards from hashtable
  123. public static bool IsFromDigimonDigivolutionCards(Hashtable hashtable)
  124. {
  125. if (hashtable != null)
  126. {
  127. if (hashtable.ContainsKey("isFromDigimonDigivolutionCards"))
  128. {
  129. if (hashtable["isFromDigimonDigivolutionCards"] is bool)
  130. {
  131. return (bool)hashtable["isFromDigimonDigivolutionCards"];
  132. }
  133. }
  134. }
  135. return false;
  136. }
  137. #endregion
  138. #region Get TopCard from hashtable of card effect
  139. public static CardSource GetTopCardFromEffectHashtable(Hashtable hashtable)
  140. {
  141. List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
  142. if (hashtables != null)
  143. {
  144. foreach (Hashtable hashtable1 in hashtables)
  145. {
  146. CardSource TopCard = GetTopCardFromOneHashtable(hashtable1);
  147. if (TopCard != null)
  148. {
  149. return TopCard;
  150. }
  151. }
  152. }
  153. return null;
  154. }
  155. #endregion
  156. #region Get EvoRootTops from hashtable of card effect
  157. public static List<CardSource> GetEvoRootTopsFromEnterFieldHashtable(Hashtable hashtable, Func<Permanent, bool> permanentCondition)
  158. {
  159. List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
  160. if (hashtables != null)
  161. {
  162. foreach (Hashtable hashtable1 in hashtables)
  163. {
  164. Permanent permanent1 = GetPermanentFromHashtable(hashtable1);
  165. if (permanent1 != null)
  166. {
  167. if (permanentCondition == null || permanentCondition(permanent1))
  168. {
  169. if (hashtable1 != null)
  170. {
  171. if (hashtable1.ContainsKey("evoRootTops"))
  172. {
  173. if (hashtable1["evoRootTops"] is List<CardSource>)
  174. {
  175. return (List<CardSource>)hashtable1["evoRootTops"];
  176. }
  177. }
  178. }
  179. }
  180. }
  181. }
  182. }
  183. return null;
  184. }
  185. #endregion
  186. #region Get Permanents from hashtable
  187. public static List<Permanent> GetPlayedPermanentsFromEnterFieldHashtable(Hashtable hashtable, Func<SelectCardEffect.Root, bool> rootCondition)
  188. {
  189. List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
  190. if (hashtables != null)
  191. {
  192. return hashtables
  193. .Filter(hashtable1 => rootCondition == null || rootCondition(GetRootFromHashtable(hashtable1)))
  194. .Map(hashtable1 => GetPermanentFromHashtable(hashtable1)).Filter(permanent => permanent != null && permanent.TopCard != null);
  195. }
  196. return null;
  197. }
  198. #endregion
  199. #region Get hashtables from hashtable of card effect
  200. public static List<Hashtable> GetHashtablesFromHashtable(Hashtable hashtable)
  201. {
  202. if (hashtable != null)
  203. {
  204. if (hashtable.ContainsKey("hashtables"))
  205. {
  206. if (hashtable["hashtables"] is List<Hashtable>)
  207. {
  208. List<Hashtable> hashtables = (List<Hashtable>)hashtable["hashtables"];
  209. if (hashtables != null)
  210. {
  211. return hashtables;
  212. }
  213. }
  214. }
  215. }
  216. return null;
  217. }
  218. #endregion
  219. #region Get TopCard from 1 hashtable
  220. public static CardSource GetTopCardFromOneHashtable(Hashtable hashtable)
  221. {
  222. if (hashtable != null)
  223. {
  224. if (hashtable.ContainsKey("TopCard"))
  225. {
  226. if (hashtable["TopCard"] is CardSource)
  227. {
  228. CardSource TopCard = (CardSource)hashtable["TopCard"];
  229. return TopCard;
  230. }
  231. }
  232. }
  233. return null;
  234. }
  235. #endregion
  236. #region Get Card from 1 hashtable
  237. public static CardSource GetCardFromHashtable(Hashtable hashtable)
  238. {
  239. if (hashtable != null)
  240. {
  241. if (hashtable.ContainsKey("Card"))
  242. {
  243. if (hashtable["Card"] is CardSource)
  244. {
  245. CardSource Card = (CardSource)hashtable["Card"];
  246. return Card;
  247. }
  248. }
  249. }
  250. return null;
  251. }
  252. #endregion
  253. #region Get battle info from hashtable
  254. public static IBattle GetBattleFromHashtable(Hashtable hashtable)
  255. {
  256. if (hashtable != null)
  257. {
  258. if (hashtable.ContainsKey("battle"))
  259. {
  260. if (hashtable["battle"] is IBattle)
  261. {
  262. return (IBattle)hashtable["battle"];
  263. }
  264. }
  265. }
  266. return null;
  267. }
  268. #endregion
  269. #region Get IsDP0 Delete from 1 hashtable
  270. public static bool IsDPZeroDelete(Hashtable hashtable)
  271. {
  272. if (hashtable != null)
  273. {
  274. if (hashtable.ContainsKey("DPZero"))
  275. {
  276. if (hashtable["DPZero"] is bool)
  277. {
  278. bool DPZero = (bool)hashtable["DPZero"];
  279. if (DPZero)
  280. {
  281. return true;
  282. }
  283. }
  284. }
  285. }
  286. return false;
  287. }
  288. #endregion
  289. #region Get whehter only 1 permanent is played from hashtable
  290. public static bool IsOnly1CadPlayed(Hashtable hashtable)
  291. {
  292. PlayCardClass playCardClass = GetPlayCardClassFromHashtable(hashtable);
  293. if (playCardClass != null)
  294. {
  295. if (playCardClass.CardSources.Count == 1)
  296. {
  297. return true;
  298. }
  299. }
  300. return false;
  301. }
  302. #endregion
  303. #region Get PlayCardClass from hashtable
  304. public static PlayCardClass GetPlayCardClassFromHashtable(Hashtable hashtable)
  305. {
  306. if (hashtable != null)
  307. {
  308. if (hashtable.ContainsKey("PlayCardClass"))
  309. {
  310. if (hashtable["PlayCardClass"] is PlayCardClass)
  311. {
  312. PlayCardClass IPlayCard = (PlayCardClass)hashtable["PlayCardClass"];
  313. if (IPlayCard != null)
  314. {
  315. return IPlayCard;
  316. }
  317. }
  318. }
  319. }
  320. return null;
  321. }
  322. #endregion
  323. #region Get IsEvolution Delete from 1 hashtable
  324. public static bool IsEvolution(Hashtable hashtable)
  325. {
  326. if (hashtable.ContainsKey("isEvolution"))
  327. {
  328. if (hashtable["isEvolution"] is bool)
  329. {
  330. bool isEvolution = (bool)hashtable["isEvolution"];
  331. if (isEvolution)
  332. {
  333. return true;
  334. }
  335. }
  336. }
  337. return false;
  338. }
  339. #endregion
  340. #region Get Player from hashtable
  341. public static Player GetPlayerFromHashtable(Hashtable hashtable)
  342. {
  343. if (hashtable != null)
  344. {
  345. if (hashtable.ContainsKey("Player"))
  346. {
  347. if (hashtable["Player"] is Player)
  348. {
  349. Player Player = (Player)hashtable["Player"];
  350. return Player;
  351. }
  352. }
  353. }
  354. return null;
  355. }
  356. #endregion
  357. #region Get Players from hashtable
  358. public static List<Player> GetPlayersFromHashtable(Hashtable hashtable)
  359. {
  360. if (hashtable != null)
  361. {
  362. if (hashtable.ContainsKey("Players"))
  363. {
  364. if (hashtable["Players"] is List<Player>)
  365. {
  366. List<Player> Players = (List<Player>)hashtable["Players"];
  367. if (Players != null)
  368. {
  369. return Players;
  370. }
  371. }
  372. }
  373. }
  374. return null;
  375. }
  376. #endregion
  377. #region Get Permanents from hashtable
  378. public static List<Permanent> GetPermanentsFromHashtable(Hashtable hashtable)
  379. {
  380. if (hashtable != null)
  381. {
  382. if (hashtable.ContainsKey("Permanents"))
  383. {
  384. if (hashtable["Permanents"] is List<Permanent>)
  385. {
  386. List<Permanent> Permanents = (List<Permanent>)hashtable["Permanents"];
  387. if (Permanents != null)
  388. {
  389. return Permanents;
  390. }
  391. }
  392. }
  393. }
  394. return null;
  395. }
  396. #endregion
  397. #region Get WinnerPermanents_real from hashtable
  398. public static List<Permanent> GetWinnerPermanentsRealFromHashtable(Hashtable hashtable)
  399. {
  400. if (hashtable != null)
  401. {
  402. if (hashtable.ContainsKey("WinnerPermanents_real"))
  403. {
  404. if (hashtable["WinnerPermanents_real"] is List<Permanent>)
  405. {
  406. List<Permanent> WinnerPermanents_real = (List<Permanent>)hashtable["WinnerPermanents_real"];
  407. if (WinnerPermanents_real != null)
  408. {
  409. return WinnerPermanents_real;
  410. }
  411. }
  412. }
  413. }
  414. return null;
  415. }
  416. #endregion
  417. #region Get LoserPermanents from hashtable
  418. public static List<Permanent> GetLoserPermanentsFromHashtable(Hashtable hashtable)
  419. {
  420. if (hashtable != null)
  421. {
  422. if (hashtable.ContainsKey("LoserPermanents"))
  423. {
  424. if (hashtable["LoserPermanents"] is List<Permanent>)
  425. {
  426. List<Permanent> LoserPermanents = (List<Permanent>)hashtable["LoserPermanents"];
  427. if (LoserPermanents != null)
  428. {
  429. return LoserPermanents;
  430. }
  431. }
  432. }
  433. }
  434. return null;
  435. }
  436. #endregion
  437. #region Get Discarded Cards from hashtable
  438. public static List<CardSource> GetDiscardedCardsFromHashtable(Hashtable hashtable)
  439. {
  440. if (hashtable != null)
  441. {
  442. if (hashtable.ContainsKey("DiscardedCards"))
  443. {
  444. if (hashtable["DiscardedCards"] is List<CardSource>)
  445. {
  446. List<CardSource> DiscardedCards = (List<CardSource>)hashtable["DiscardedCards"];
  447. if (DiscardedCards != null)
  448. {
  449. return DiscardedCards;
  450. }
  451. }
  452. }
  453. }
  454. return null;
  455. }
  456. #endregion
  457. #region Get CardSources from hashtable
  458. public static List<CardSource> GetCardSourcesFromHashtable(Hashtable hashtable)
  459. {
  460. if (hashtable != null)
  461. {
  462. if (hashtable.ContainsKey("CardSources"))
  463. {
  464. if (hashtable["CardSources"] is List<CardSource>)
  465. {
  466. List<CardSource> CardSources = (List<CardSource>)hashtable["CardSources"];
  467. if (CardSources != null)
  468. {
  469. return CardSources;
  470. }
  471. }
  472. }
  473. }
  474. return null;
  475. }
  476. #endregion
  477. #region Get DeckBottom Cards from hashtable
  478. public static List<CardSource> GetDeckBottomCardsFromHashtable(Hashtable hashtable)
  479. {
  480. if (hashtable != null)
  481. {
  482. if (hashtable.ContainsKey("DeckBottomCards"))
  483. {
  484. if (hashtable["DeckBottomCards"] is List<CardSource>)
  485. {
  486. List<CardSource> DeckBottomCards = (List<CardSource>)hashtable["DeckBottomCards"];
  487. if (DeckBottomCards != null)
  488. {
  489. return DeckBottomCards;
  490. }
  491. }
  492. }
  493. }
  494. return null;
  495. }
  496. #endregion
  497. #region Get Digivolution roots from hashtable
  498. public static List<CardSource> GetDigivolutionRootsFromEnterFieldHashtable(Hashtable hashtable, Func<Permanent, bool> permanentCondition)
  499. {
  500. List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
  501. if (hashtables != null)
  502. {
  503. foreach (Hashtable hashtable1 in hashtables)
  504. {
  505. Permanent permanent1 = GetPermanentFromHashtable(hashtable1);
  506. if (permanent1 != null)
  507. {
  508. if (permanentCondition == null || permanentCondition(permanent1))
  509. {
  510. if (hashtable1 != null)
  511. {
  512. if (hashtable1.ContainsKey("evoRoots"))
  513. {
  514. if (hashtable1["evoRoots"] is List<CardSource>)
  515. {
  516. List<CardSource> evoRoots = (List<CardSource>)hashtable1["evoRoots"];
  517. if (evoRoots != null)
  518. {
  519. return evoRoots;
  520. }
  521. }
  522. }
  523. }
  524. }
  525. }
  526. }
  527. }
  528. return null;
  529. }
  530. #endregion
  531. #region Get Permanent from hashtable
  532. public static Permanent GetPermanentFromHashtable(Hashtable hashtable)
  533. {
  534. if (hashtable.ContainsKey("Permanent"))
  535. {
  536. if (hashtable["Permanent"] is Permanent)
  537. {
  538. Permanent Permanent = (Permanent)hashtable["Permanent"];
  539. if (Permanent != null)
  540. {
  541. return Permanent;
  542. }
  543. }
  544. }
  545. return null;
  546. }
  547. #endregion
  548. #region Get whether to digivolve from the same level from hashtable
  549. public static bool IsDigivolvedFromSameLevelFromEnterFieldHashtable(Hashtable hashtable, Permanent permanent)
  550. {
  551. if (IsPermanentExistsOnBattleArea(permanent))
  552. {
  553. if (permanent.TopCard.HasLevel)
  554. {
  555. List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
  556. if (hashtables != null)
  557. {
  558. foreach (Hashtable hashtable1 in hashtables)
  559. {
  560. Permanent permanent1 = GetPermanentFromHashtable(hashtable1);
  561. if (permanent1 == permanent)
  562. {
  563. if (hashtable1 != null)
  564. {
  565. if (hashtable1.ContainsKey("oldLevels"))
  566. {
  567. if (hashtable1["oldLevels"] is List<int>)
  568. {
  569. List<int> oldLevels = (List<int>)hashtable1["oldLevels"];
  570. if (oldLevels != null)
  571. {
  572. if (oldLevels.Count((oldLevel) => oldLevel == permanent.Level) >= 1)
  573. {
  574. return true;
  575. }
  576. }
  577. }
  578. }
  579. }
  580. }
  581. }
  582. }
  583. }
  584. }
  585. return false;
  586. }
  587. #endregion
  588. #region Get IsAlliance from 1 hashtable
  589. public static bool IsAlliance(Hashtable hashtable)
  590. {
  591. ICardEffect CardEffect = GetCardEffectFromHashtable(hashtable);
  592. if (CardEffect != null)
  593. {
  594. if (CardEffect.EffectName == "Alliance")
  595. {
  596. return true;
  597. }
  598. }
  599. return false;
  600. }
  601. #endregion
  602. #region Get isJogress from hashtable
  603. public static bool IsJogress(Hashtable hashtable)
  604. {
  605. if (hashtable != null)
  606. {
  607. if (hashtable.ContainsKey("isJogress"))
  608. {
  609. if (hashtable["isJogress"] is bool)
  610. {
  611. return (bool)hashtable["isJogress"];
  612. }
  613. }
  614. }
  615. return false;
  616. }
  617. #endregion
  618. #region Get IsDijiXros from hashtable
  619. public static bool IsDijiXros(Hashtable hashtable, Func<int, bool> digixrosCountCondition)
  620. {
  621. int digiXrosCount = GetDigiXrosCount(hashtable);
  622. if (digixrosCountCondition != null)
  623. {
  624. return digixrosCountCondition(digiXrosCount);
  625. }
  626. return false;
  627. }
  628. #endregion
  629. #region Get DigiXrosCount from hashtable
  630. public static int GetDigiXrosCount(Hashtable hashtable)
  631. {
  632. if (hashtable != null)
  633. {
  634. if (hashtable.ContainsKey("DigiXrosCount"))
  635. {
  636. if (hashtable["DigiXrosCount"] is int)
  637. {
  638. return (int)hashtable["DigiXrosCount"]; ;
  639. }
  640. }
  641. }
  642. return 0;
  643. }
  644. #endregion
  645. }