GetFromHashtable.cs 21 KB

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