GetFromHashtable.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  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 Attacking Permanent from hashtable
  217. public static Permanent GetAttackerFromHashtable(Hashtable hashtable)
  218. {
  219. if (hashtable != null)
  220. {
  221. if (hashtable.ContainsKey("AttackingPermanent"))
  222. {
  223. if (hashtable["AttackingPermanent"] is Permanent)
  224. {
  225. Permanent permanent = (Permanent)hashtable["AttackingPermanent"];
  226. return permanent;
  227. }
  228. }
  229. }
  230. return null;
  231. }
  232. #endregion
  233. #region Get hashtables from hashtable of card effect
  234. public static List<Hashtable> GetHashtablesFromHashtable(Hashtable hashtable)
  235. {
  236. if (hashtable != null)
  237. {
  238. if (hashtable.ContainsKey("hashtables"))
  239. {
  240. if (hashtable["hashtables"] is List<Hashtable>)
  241. {
  242. List<Hashtable> hashtables = (List<Hashtable>)hashtable["hashtables"];
  243. if (hashtables != null)
  244. {
  245. return hashtables;
  246. }
  247. }
  248. }
  249. }
  250. return null;
  251. }
  252. #endregion
  253. #region Get TopCard from 1 hashtable
  254. public static CardSource GetTopCardFromOneHashtable(Hashtable hashtable)
  255. {
  256. if (hashtable != null)
  257. {
  258. if (hashtable.ContainsKey("TopCard"))
  259. {
  260. if (hashtable["TopCard"] is CardSource)
  261. {
  262. CardSource TopCard = (CardSource)hashtable["TopCard"];
  263. return TopCard;
  264. }
  265. }
  266. }
  267. return null;
  268. }
  269. #endregion
  270. #region Get Card from 1 hashtable
  271. public static CardSource GetCardFromHashtable(Hashtable hashtable)
  272. {
  273. if (hashtable != null)
  274. {
  275. if (hashtable.ContainsKey("Card"))
  276. {
  277. if (hashtable["Card"] is CardSource)
  278. {
  279. CardSource Card = (CardSource)hashtable["Card"];
  280. return Card;
  281. }
  282. }
  283. }
  284. return null;
  285. }
  286. #endregion
  287. #region Get Is Face Up from hashtable
  288. public static bool GetFaceDownFromHashtable(Hashtable hashtable)
  289. {
  290. if (hashtable != null)
  291. {
  292. if (hashtable.ContainsKey("isFaceDown"))
  293. {
  294. if (hashtable["isFaceDown"] is bool)
  295. {
  296. return (bool)hashtable["isFaceDown"];
  297. }
  298. }
  299. }
  300. return true;
  301. }
  302. #endregion
  303. #region Get battle info from hashtable
  304. public static IBattle GetBattleFromHashtable(Hashtable hashtable)
  305. {
  306. if (hashtable != null)
  307. {
  308. if (hashtable.ContainsKey("battle"))
  309. {
  310. if (hashtable["battle"] is IBattle)
  311. {
  312. return (IBattle)hashtable["battle"];
  313. }
  314. }
  315. }
  316. return null;
  317. }
  318. #endregion
  319. #region Get IsDP0 Delete from 1 hashtable
  320. public static bool IsDPZeroDelete(Hashtable hashtable)
  321. {
  322. if (hashtable != null)
  323. {
  324. if (hashtable.ContainsKey("DPZero"))
  325. {
  326. if (hashtable["DPZero"] is bool)
  327. {
  328. bool DPZero = (bool)hashtable["DPZero"];
  329. if (DPZero)
  330. {
  331. return true;
  332. }
  333. }
  334. }
  335. }
  336. return false;
  337. }
  338. #endregion
  339. #region Get whehter only 1 permanent is played from hashtable
  340. public static bool IsOnly1CardPlayed(Hashtable hashtable)
  341. {
  342. PlayCardClass playCardClass = GetPlayCardClassFromHashtable(hashtable);
  343. if (playCardClass != null)
  344. {
  345. if (playCardClass.CardSources.Count == 1)
  346. {
  347. return true;
  348. }
  349. }
  350. return false;
  351. }
  352. #endregion
  353. #region Get PlayCardClass from hashtable
  354. public static PlayCardClass GetPlayCardClassFromHashtable(Hashtable hashtable)
  355. {
  356. if (hashtable != null)
  357. {
  358. if (hashtable.ContainsKey("PlayCardClass"))
  359. {
  360. if (hashtable["PlayCardClass"] is PlayCardClass)
  361. {
  362. PlayCardClass IPlayCard = (PlayCardClass)hashtable["PlayCardClass"];
  363. if (IPlayCard != null)
  364. {
  365. return IPlayCard;
  366. }
  367. }
  368. }
  369. }
  370. return null;
  371. }
  372. #endregion
  373. #region Get IsEvolution Delete from 1 hashtable
  374. public static bool IsEvolution(Hashtable hashtable)
  375. {
  376. if (hashtable.ContainsKey("isEvolution"))
  377. {
  378. if (hashtable["isEvolution"] is bool)
  379. {
  380. bool isEvolution = (bool)hashtable["isEvolution"];
  381. if (isEvolution)
  382. {
  383. return true;
  384. }
  385. }
  386. }
  387. return false;
  388. }
  389. #endregion
  390. #region Get Player from hashtable
  391. public static Player GetPlayerFromHashtable(Hashtable hashtable)
  392. {
  393. if (hashtable != null)
  394. {
  395. if (hashtable.ContainsKey("Player"))
  396. {
  397. if (hashtable["Player"] is Player)
  398. {
  399. Player Player = (Player)hashtable["Player"];
  400. return Player;
  401. }
  402. }
  403. }
  404. return null;
  405. }
  406. #endregion
  407. #region Get Players from hashtable
  408. public static List<Player> GetPlayersFromHashtable(Hashtable hashtable)
  409. {
  410. if (hashtable != null)
  411. {
  412. if (hashtable.ContainsKey("Players"))
  413. {
  414. if (hashtable["Players"] is List<Player>)
  415. {
  416. List<Player> Players = (List<Player>)hashtable["Players"];
  417. if (Players != null)
  418. {
  419. return Players;
  420. }
  421. }
  422. }
  423. }
  424. return null;
  425. }
  426. #endregion
  427. #region Get Permanents from hashtable
  428. public static List<Permanent> GetPermanentsFromHashtable(Hashtable hashtable)
  429. {
  430. if (hashtable != null)
  431. {
  432. if (hashtable.ContainsKey("Permanents"))
  433. {
  434. if (hashtable["Permanents"] is List<Permanent>)
  435. {
  436. List<Permanent> Permanents = (List<Permanent>)hashtable["Permanents"];
  437. if (Permanents != null)
  438. {
  439. return Permanents;
  440. }
  441. }
  442. }
  443. }
  444. return null;
  445. }
  446. #endregion
  447. #region Get WinnerPermanents_real from hashtable
  448. public static List<Permanent> GetWinnerPermanentsRealFromHashtable(Hashtable hashtable)
  449. {
  450. if (hashtable != null)
  451. {
  452. if (hashtable.ContainsKey("WinnerPermanents_real"))
  453. {
  454. if (hashtable["WinnerPermanents_real"] is List<Permanent>)
  455. {
  456. List<Permanent> WinnerPermanents_real = (List<Permanent>)hashtable["WinnerPermanents_real"];
  457. if (WinnerPermanents_real != null)
  458. {
  459. return WinnerPermanents_real;
  460. }
  461. }
  462. }
  463. }
  464. return null;
  465. }
  466. #endregion
  467. #region Get LoserPermanents from hashtable
  468. public static List<Permanent> GetLoserPermanentsFromHashtable(Hashtable hashtable)
  469. {
  470. if (hashtable != null)
  471. {
  472. if (hashtable.ContainsKey("LoserPermanents"))
  473. {
  474. if (hashtable["LoserPermanents"] is List<Permanent>)
  475. {
  476. List<Permanent> LoserPermanents = (List<Permanent>)hashtable["LoserPermanents"];
  477. if (LoserPermanents != null)
  478. {
  479. return LoserPermanents;
  480. }
  481. }
  482. }
  483. }
  484. return null;
  485. }
  486. #endregion
  487. #region Get Discarded Cards from hashtable
  488. public static List<CardSource> GetDiscardedCardsFromHashtable(Hashtable hashtable)
  489. {
  490. if (hashtable != null)
  491. {
  492. if (hashtable.ContainsKey("DiscardedCards"))
  493. {
  494. if (hashtable["DiscardedCards"] is List<CardSource>)
  495. {
  496. List<CardSource> DiscardedCards = (List<CardSource>)hashtable["DiscardedCards"];
  497. if (DiscardedCards != null)
  498. {
  499. return DiscardedCards;
  500. }
  501. }
  502. }
  503. }
  504. return null;
  505. }
  506. #endregion
  507. #region Get CardSources from hashtable
  508. public static List<CardSource> GetCardSourcesFromHashtable(Hashtable hashtable)
  509. {
  510. if (hashtable != null)
  511. {
  512. if (hashtable.ContainsKey("CardSources"))
  513. {
  514. if (hashtable["CardSources"] is List<CardSource>)
  515. {
  516. List<CardSource> CardSources = (List<CardSource>)hashtable["CardSources"];
  517. if (CardSources != null)
  518. {
  519. return CardSources;
  520. }
  521. }
  522. }
  523. }
  524. return null;
  525. }
  526. #endregion
  527. #region Get DigivolutionSources from hashtable
  528. public static List<CardSource> GetDigivolutionSourcesFromHashtable(Hashtable hashtable)
  529. {
  530. if (hashtable != null)
  531. {
  532. if (hashtable.ContainsKey("DigivolutionSources"))
  533. {
  534. if (hashtable["DigivolutionSources"] is List<CardSource>)
  535. {
  536. List<CardSource> CardSources = (List<CardSource>)hashtable["DigivolutionSources"];
  537. if (CardSources != null)
  538. {
  539. return CardSources;
  540. }
  541. }
  542. }
  543. }
  544. return null;
  545. }
  546. #endregion
  547. #region Get DeckBottom Cards from hashtable
  548. public static List<CardSource> GetDeckBottomCardsFromHashtable(Hashtable hashtable)
  549. {
  550. if (hashtable != null)
  551. {
  552. if (hashtable.ContainsKey("DeckBottomCards"))
  553. {
  554. if (hashtable["DeckBottomCards"] is List<CardSource>)
  555. {
  556. List<CardSource> DeckBottomCards = (List<CardSource>)hashtable["DeckBottomCards"];
  557. if (DeckBottomCards != null)
  558. {
  559. return DeckBottomCards;
  560. }
  561. }
  562. }
  563. }
  564. return null;
  565. }
  566. #endregion
  567. #region Get Digivolution roots from hashtable
  568. public static List<CardSource> GetDigivolutionRootsFromEnterFieldHashtable(Hashtable hashtable, Func<Permanent, bool> permanentCondition)
  569. {
  570. List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
  571. if (hashtables != null)
  572. {
  573. foreach (Hashtable hashtable1 in hashtables)
  574. {
  575. Permanent permanent1 = GetPermanentFromHashtable(hashtable1);
  576. if (permanent1 != null)
  577. {
  578. if (permanentCondition == null || permanentCondition(permanent1))
  579. {
  580. if (hashtable1 != null)
  581. {
  582. if (hashtable1.ContainsKey("evoRoots"))
  583. {
  584. if (hashtable1["evoRoots"] is List<CardSource>)
  585. {
  586. List<CardSource> evoRoots = (List<CardSource>)hashtable1["evoRoots"];
  587. if (evoRoots != null)
  588. {
  589. return evoRoots;
  590. }
  591. }
  592. }
  593. }
  594. }
  595. }
  596. }
  597. }
  598. return null;
  599. }
  600. #endregion
  601. #region Get Permanent from hashtable
  602. public static Permanent GetPermanentFromHashtable(Hashtable hashtable)
  603. {
  604. if (hashtable.ContainsKey("Permanent"))
  605. {
  606. if (hashtable["Permanent"] is Permanent)
  607. {
  608. Permanent Permanent = (Permanent)hashtable["Permanent"];
  609. if (Permanent != null)
  610. {
  611. return Permanent;
  612. }
  613. }
  614. }
  615. return null;
  616. }
  617. #endregion
  618. #region Get whether to digivolve from the same level from hashtable
  619. public static bool IsDigivolvedFromSameLevelFromEnterFieldHashtable(Hashtable hashtable, Permanent permanent)
  620. {
  621. if (IsPermanentExistsOnBattleArea(permanent))
  622. {
  623. if (permanent.TopCard.HasLevel)
  624. {
  625. List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
  626. if (hashtables != null)
  627. {
  628. foreach (Hashtable hashtable1 in hashtables)
  629. {
  630. Permanent permanent1 = GetPermanentFromHashtable(hashtable1);
  631. if (permanent1 == permanent)
  632. {
  633. if (hashtable1 != null)
  634. {
  635. if (hashtable1.ContainsKey("oldLevels"))
  636. {
  637. if (hashtable1["oldLevels"] is List<int>)
  638. {
  639. List<int> oldLevels = (List<int>)hashtable1["oldLevels"];
  640. if (oldLevels != null)
  641. {
  642. if (oldLevels.Count((oldLevel) => oldLevel == permanent.Level) >= 1)
  643. {
  644. return true;
  645. }
  646. }
  647. }
  648. }
  649. }
  650. }
  651. }
  652. }
  653. }
  654. }
  655. return false;
  656. }
  657. #endregion
  658. #region Get IsAlliance from 1 hashtable
  659. public static bool IsAlliance(Hashtable hashtable)
  660. {
  661. ICardEffect CardEffect = GetCardEffectFromHashtable(hashtable);
  662. if (CardEffect != null)
  663. {
  664. if (CardEffect.EffectName == "Alliance")
  665. {
  666. return true;
  667. }
  668. }
  669. return false;
  670. }
  671. #endregion
  672. #region Get isJogress from hashtable
  673. public static bool IsJogress(Hashtable hashtable)
  674. {
  675. if (hashtable != null)
  676. {
  677. if (hashtable.ContainsKey("isJogress"))
  678. {
  679. if (hashtable["isJogress"] is bool)
  680. {
  681. return (bool)hashtable["isJogress"];
  682. }
  683. }
  684. }
  685. return false;
  686. }
  687. #endregion
  688. #region If leaving for Digixros
  689. public static bool IsLeavingForDigiXros(Hashtable hashtable)
  690. {
  691. if (hashtable != null)
  692. {
  693. if (hashtable.ContainsKey("digixros"))
  694. {
  695. if (hashtable["digixros"] is bool)
  696. {
  697. return (bool)hashtable["digixros"]; ;
  698. }
  699. }
  700. }
  701. return false;
  702. }
  703. #endregion
  704. #region Get IsDijiXros from hashtable
  705. public static bool IsDijiXros(Hashtable hashtable, Func<int, bool> digixrosCountCondition)
  706. {
  707. int digiXrosCount = GetDigiXrosCount(hashtable);
  708. if (digixrosCountCondition != null)
  709. {
  710. return digixrosCountCondition(digiXrosCount);
  711. }
  712. return false;
  713. }
  714. #endregion
  715. #region Get DigiXrosCount from hashtable
  716. public static int GetDigiXrosCount(Hashtable hashtable)
  717. {
  718. if (hashtable != null)
  719. {
  720. if (hashtable.ContainsKey("DigiXrosCount"))
  721. {
  722. if (hashtable["DigiXrosCount"] is int)
  723. {
  724. return (int)hashtable["DigiXrosCount"]; ;
  725. }
  726. }
  727. }
  728. return 0;
  729. }
  730. #endregion
  731. }