GetFromHashtable.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  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 battle info from hashtable
  288. public static IBattle GetBattleFromHashtable(Hashtable hashtable)
  289. {
  290. if (hashtable != null)
  291. {
  292. if (hashtable.ContainsKey("battle"))
  293. {
  294. if (hashtable["battle"] is IBattle)
  295. {
  296. return (IBattle)hashtable["battle"];
  297. }
  298. }
  299. }
  300. return null;
  301. }
  302. #endregion
  303. #region Get IsDP0 Delete from 1 hashtable
  304. public static bool IsDPZeroDelete(Hashtable hashtable)
  305. {
  306. if (hashtable != null)
  307. {
  308. if (hashtable.ContainsKey("DPZero"))
  309. {
  310. if (hashtable["DPZero"] is bool)
  311. {
  312. bool DPZero = (bool)hashtable["DPZero"];
  313. if (DPZero)
  314. {
  315. return true;
  316. }
  317. }
  318. }
  319. }
  320. return false;
  321. }
  322. #endregion
  323. #region Get whehter only 1 permanent is played from hashtable
  324. public static bool IsOnly1CadPlayed(Hashtable hashtable)
  325. {
  326. PlayCardClass playCardClass = GetPlayCardClassFromHashtable(hashtable);
  327. if (playCardClass != null)
  328. {
  329. if (playCardClass.CardSources.Count == 1)
  330. {
  331. return true;
  332. }
  333. }
  334. return false;
  335. }
  336. #endregion
  337. #region Get PlayCardClass from hashtable
  338. public static PlayCardClass GetPlayCardClassFromHashtable(Hashtable hashtable)
  339. {
  340. if (hashtable != null)
  341. {
  342. if (hashtable.ContainsKey("PlayCardClass"))
  343. {
  344. if (hashtable["PlayCardClass"] is PlayCardClass)
  345. {
  346. PlayCardClass IPlayCard = (PlayCardClass)hashtable["PlayCardClass"];
  347. if (IPlayCard != null)
  348. {
  349. return IPlayCard;
  350. }
  351. }
  352. }
  353. }
  354. return null;
  355. }
  356. #endregion
  357. #region Get IsEvolution Delete from 1 hashtable
  358. public static bool IsEvolution(Hashtable hashtable)
  359. {
  360. if (hashtable.ContainsKey("isEvolution"))
  361. {
  362. if (hashtable["isEvolution"] is bool)
  363. {
  364. bool isEvolution = (bool)hashtable["isEvolution"];
  365. if (isEvolution)
  366. {
  367. return true;
  368. }
  369. }
  370. }
  371. return false;
  372. }
  373. #endregion
  374. #region Get Player from hashtable
  375. public static Player GetPlayerFromHashtable(Hashtable hashtable)
  376. {
  377. if (hashtable != null)
  378. {
  379. if (hashtable.ContainsKey("Player"))
  380. {
  381. if (hashtable["Player"] is Player)
  382. {
  383. Player Player = (Player)hashtable["Player"];
  384. return Player;
  385. }
  386. }
  387. }
  388. return null;
  389. }
  390. #endregion
  391. #region Get Players from hashtable
  392. public static List<Player> GetPlayersFromHashtable(Hashtable hashtable)
  393. {
  394. if (hashtable != null)
  395. {
  396. if (hashtable.ContainsKey("Players"))
  397. {
  398. if (hashtable["Players"] is List<Player>)
  399. {
  400. List<Player> Players = (List<Player>)hashtable["Players"];
  401. if (Players != null)
  402. {
  403. return Players;
  404. }
  405. }
  406. }
  407. }
  408. return null;
  409. }
  410. #endregion
  411. #region Get Permanents from hashtable
  412. public static List<Permanent> GetPermanentsFromHashtable(Hashtable hashtable)
  413. {
  414. if (hashtable != null)
  415. {
  416. if (hashtable.ContainsKey("Permanents"))
  417. {
  418. if (hashtable["Permanents"] is List<Permanent>)
  419. {
  420. List<Permanent> Permanents = (List<Permanent>)hashtable["Permanents"];
  421. if (Permanents != null)
  422. {
  423. return Permanents;
  424. }
  425. }
  426. }
  427. }
  428. return null;
  429. }
  430. #endregion
  431. #region Get WinnerPermanents_real from hashtable
  432. public static List<Permanent> GetWinnerPermanentsRealFromHashtable(Hashtable hashtable)
  433. {
  434. if (hashtable != null)
  435. {
  436. if (hashtable.ContainsKey("WinnerPermanents_real"))
  437. {
  438. if (hashtable["WinnerPermanents_real"] is List<Permanent>)
  439. {
  440. List<Permanent> WinnerPermanents_real = (List<Permanent>)hashtable["WinnerPermanents_real"];
  441. if (WinnerPermanents_real != null)
  442. {
  443. return WinnerPermanents_real;
  444. }
  445. }
  446. }
  447. }
  448. return null;
  449. }
  450. #endregion
  451. #region Get LoserPermanents from hashtable
  452. public static List<Permanent> GetLoserPermanentsFromHashtable(Hashtable hashtable)
  453. {
  454. if (hashtable != null)
  455. {
  456. if (hashtable.ContainsKey("LoserPermanents"))
  457. {
  458. if (hashtable["LoserPermanents"] is List<Permanent>)
  459. {
  460. List<Permanent> LoserPermanents = (List<Permanent>)hashtable["LoserPermanents"];
  461. if (LoserPermanents != null)
  462. {
  463. return LoserPermanents;
  464. }
  465. }
  466. }
  467. }
  468. return null;
  469. }
  470. #endregion
  471. #region Get Discarded Cards from hashtable
  472. public static List<CardSource> GetDiscardedCardsFromHashtable(Hashtable hashtable)
  473. {
  474. if (hashtable != null)
  475. {
  476. if (hashtable.ContainsKey("DiscardedCards"))
  477. {
  478. if (hashtable["DiscardedCards"] is List<CardSource>)
  479. {
  480. List<CardSource> DiscardedCards = (List<CardSource>)hashtable["DiscardedCards"];
  481. if (DiscardedCards != null)
  482. {
  483. return DiscardedCards;
  484. }
  485. }
  486. }
  487. }
  488. return null;
  489. }
  490. #endregion
  491. #region Get CardSources from hashtable
  492. public static List<CardSource> GetCardSourcesFromHashtable(Hashtable hashtable)
  493. {
  494. if (hashtable != null)
  495. {
  496. if (hashtable.ContainsKey("CardSources"))
  497. {
  498. if (hashtable["CardSources"] is List<CardSource>)
  499. {
  500. List<CardSource> CardSources = (List<CardSource>)hashtable["CardSources"];
  501. if (CardSources != null)
  502. {
  503. return CardSources;
  504. }
  505. }
  506. }
  507. }
  508. return null;
  509. }
  510. #endregion
  511. #region Get DeckBottom Cards from hashtable
  512. public static List<CardSource> GetDeckBottomCardsFromHashtable(Hashtable hashtable)
  513. {
  514. if (hashtable != null)
  515. {
  516. if (hashtable.ContainsKey("DeckBottomCards"))
  517. {
  518. if (hashtable["DeckBottomCards"] is List<CardSource>)
  519. {
  520. List<CardSource> DeckBottomCards = (List<CardSource>)hashtable["DeckBottomCards"];
  521. if (DeckBottomCards != null)
  522. {
  523. return DeckBottomCards;
  524. }
  525. }
  526. }
  527. }
  528. return null;
  529. }
  530. #endregion
  531. #region Get Digivolution roots from hashtable
  532. public static List<CardSource> GetDigivolutionRootsFromEnterFieldHashtable(Hashtable hashtable, Func<Permanent, bool> permanentCondition)
  533. {
  534. List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
  535. if (hashtables != null)
  536. {
  537. foreach (Hashtable hashtable1 in hashtables)
  538. {
  539. Permanent permanent1 = GetPermanentFromHashtable(hashtable1);
  540. if (permanent1 != null)
  541. {
  542. if (permanentCondition == null || permanentCondition(permanent1))
  543. {
  544. if (hashtable1 != null)
  545. {
  546. if (hashtable1.ContainsKey("evoRoots"))
  547. {
  548. if (hashtable1["evoRoots"] is List<CardSource>)
  549. {
  550. List<CardSource> evoRoots = (List<CardSource>)hashtable1["evoRoots"];
  551. if (evoRoots != null)
  552. {
  553. return evoRoots;
  554. }
  555. }
  556. }
  557. }
  558. }
  559. }
  560. }
  561. }
  562. return null;
  563. }
  564. #endregion
  565. #region Get Permanent from hashtable
  566. public static Permanent GetPermanentFromHashtable(Hashtable hashtable)
  567. {
  568. if (hashtable.ContainsKey("Permanent"))
  569. {
  570. if (hashtable["Permanent"] is Permanent)
  571. {
  572. Permanent Permanent = (Permanent)hashtable["Permanent"];
  573. if (Permanent != null)
  574. {
  575. return Permanent;
  576. }
  577. }
  578. }
  579. return null;
  580. }
  581. #endregion
  582. #region Get whether to digivolve from the same level from hashtable
  583. public static bool IsDigivolvedFromSameLevelFromEnterFieldHashtable(Hashtable hashtable, Permanent permanent)
  584. {
  585. if (IsPermanentExistsOnBattleArea(permanent))
  586. {
  587. if (permanent.TopCard.HasLevel)
  588. {
  589. List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
  590. if (hashtables != null)
  591. {
  592. foreach (Hashtable hashtable1 in hashtables)
  593. {
  594. Permanent permanent1 = GetPermanentFromHashtable(hashtable1);
  595. if (permanent1 == permanent)
  596. {
  597. if (hashtable1 != null)
  598. {
  599. if (hashtable1.ContainsKey("oldLevels"))
  600. {
  601. if (hashtable1["oldLevels"] is List<int>)
  602. {
  603. List<int> oldLevels = (List<int>)hashtable1["oldLevels"];
  604. if (oldLevels != null)
  605. {
  606. if (oldLevels.Count((oldLevel) => oldLevel == permanent.Level) >= 1)
  607. {
  608. return true;
  609. }
  610. }
  611. }
  612. }
  613. }
  614. }
  615. }
  616. }
  617. }
  618. }
  619. return false;
  620. }
  621. #endregion
  622. #region Get IsAlliance from 1 hashtable
  623. public static bool IsAlliance(Hashtable hashtable)
  624. {
  625. ICardEffect CardEffect = GetCardEffectFromHashtable(hashtable);
  626. if (CardEffect != null)
  627. {
  628. if (CardEffect.EffectName == "Alliance")
  629. {
  630. return true;
  631. }
  632. }
  633. return false;
  634. }
  635. #endregion
  636. #region Get isJogress from hashtable
  637. public static bool IsJogress(Hashtable hashtable)
  638. {
  639. if (hashtable != null)
  640. {
  641. if (hashtable.ContainsKey("isJogress"))
  642. {
  643. if (hashtable["isJogress"] is bool)
  644. {
  645. return (bool)hashtable["isJogress"];
  646. }
  647. }
  648. }
  649. return false;
  650. }
  651. #endregion
  652. #region Get IsDijiXros from hashtable
  653. public static bool IsDijiXros(Hashtable hashtable, Func<int, bool> digixrosCountCondition)
  654. {
  655. int digiXrosCount = GetDigiXrosCount(hashtable);
  656. if (digixrosCountCondition != null)
  657. {
  658. return digixrosCountCondition(digiXrosCount);
  659. }
  660. return false;
  661. }
  662. #endregion
  663. #region Get DigiXrosCount from hashtable
  664. public static int GetDigiXrosCount(Hashtable hashtable)
  665. {
  666. if (hashtable != null)
  667. {
  668. if (hashtable.ContainsKey("DigiXrosCount"))
  669. {
  670. if (hashtable["DigiXrosCount"] is int)
  671. {
  672. return (int)hashtable["DigiXrosCount"]; ;
  673. }
  674. }
  675. }
  676. return 0;
  677. }
  678. #endregion
  679. }