DeckData.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using UnityEngine;
  6. [System.Serializable]
  7. public class DeckData
  8. {
  9. public static int m = 256;
  10. public static int n = 256;
  11. public static int log_n_m = (int)Mathf.Log(m, n);
  12. public static int maxCardKind = 37000;
  13. public static int CardKindCellLength = (int)Math.Ceiling(Mathf.Log(maxCardKind, m));
  14. #region constructor
  15. public DeckData(string DeckCode, string ID = "")
  16. {
  17. List<int> _DeckCardIDs = new List<int>();
  18. List<int> _DigitamaDeckCardIDs = new List<int>();
  19. //separated by commas
  20. string[] parseByComma = DeckCode.Split(',');
  21. List<int> DistinctDeckCardIDs = new List<int>();
  22. List<int> DistinctDeckCardCounts = new List<int>();
  23. List<int> DistinctDigitamaDeckCardIDs = new List<int>();
  24. List<int> DistinctDigitamaDeckCardCounts = new List<int>();
  25. DeckID = ID;
  26. for (int i = 0; i < parseByComma.Length; i++)
  27. {
  28. //deck name
  29. if (i == 0)
  30. {
  31. DeckName = parseByComma[i];
  32. }
  33. //Cards in the deck(no duplicates)
  34. else if (i == 1)
  35. {
  36. //Separate every 2 characters
  37. string[] SplitText = SplitClass.Split(parseByComma[i], CardKindCellLength);
  38. for (int j = 0; j < SplitText.Length; j++)
  39. {
  40. DistinctDeckCardIDs.Add(ConvertBinaryNumber.NStringToInt(SplitText[j], m));
  41. }
  42. }
  43. //Number of each type of card
  44. else if (i == 2)
  45. {
  46. //m-ary string
  47. string x_m = parseByComma[i];
  48. if (!string.IsNullOrEmpty(x_m))
  49. {
  50. //Convert m-ary number to n-ary number
  51. string x_n = ConvertBinaryNumber.NKStringToNString(x_m, n, log_n_m);
  52. //Separate n-ary string by character
  53. string[] Split_x_n = SplitClass.Split(x_n, 1);
  54. for (int j = 0; j < Split_x_n.Length; j++)
  55. {
  56. //Convert n-ary number to int
  57. DistinctDeckCardCounts.Add(ConvertBinaryNumber.NStringToInt(Split_x_n[j], n) + 1);
  58. }
  59. }
  60. }
  61. //Digitama deck cards (no duplicates)
  62. else if (i == 3)
  63. {
  64. //Separate every 2 characters
  65. string[] SplitText = SplitClass.Split(parseByComma[i], CardKindCellLength);
  66. for (int j = 0; j < SplitText.Length; j++)
  67. {
  68. DistinctDigitamaDeckCardIDs.Add(ConvertBinaryNumber.NStringToInt(SplitText[j], m));
  69. }
  70. }
  71. //Number of each type of card
  72. else if (i == 4)
  73. {
  74. //m-ary string
  75. string x_m = parseByComma[i];
  76. if (!string.IsNullOrEmpty(x_m))
  77. {
  78. //Convert m-ary number to n-ary number
  79. string x_n = ConvertBinaryNumber.NKStringToNString(x_m, n, log_n_m);
  80. //Separate n-ary string by character
  81. string[] Split_x_n = SplitClass.Split(x_n, 1);
  82. for (int j = 0; j < Split_x_n.Length; j++)
  83. {
  84. //Convert n-ary number to int
  85. DistinctDigitamaDeckCardCounts.Add(ConvertBinaryNumber.NStringToInt(Split_x_n[j], n) + 1);
  86. }
  87. }
  88. }
  89. //key card id
  90. else if (i == 5)
  91. {
  92. if (int.TryParse(parseByComma[i], out int value))
  93. {
  94. KeyCardId = value;
  95. }
  96. }
  97. }
  98. for (int i = 0; i < DistinctDeckCardIDs.Count; i++)
  99. {
  100. if (i < DistinctDeckCardCounts.Count)
  101. {
  102. for (int j = 0; j < DistinctDeckCardCounts[i]; j++)
  103. {
  104. _DeckCardIDs.Add(DistinctDeckCardIDs[i]);
  105. }
  106. }
  107. }
  108. for (int i = 0; i < DistinctDigitamaDeckCardIDs.Count; i++)
  109. {
  110. if (i < DistinctDigitamaDeckCardCounts.Count)
  111. {
  112. for (int j = 0; j < DistinctDigitamaDeckCardCounts[i]; j++)
  113. {
  114. _DigitamaDeckCardIDs.Add(DistinctDigitamaDeckCardIDs[i]);
  115. }
  116. }
  117. }
  118. DeckCardIDs = _DeckCardIDs;
  119. DigitamaDeckCardIDs = _DigitamaDeckCardIDs;
  120. }
  121. #endregion
  122. #region sort value
  123. int _sortValue = 0;
  124. public int SortValue
  125. {
  126. get
  127. {
  128. return _sortValue;
  129. }
  130. set
  131. {
  132. _sortValue = value;
  133. }
  134. }
  135. #endregion
  136. #region deck id
  137. string _deckID = "";
  138. public string DeckID
  139. {
  140. get
  141. {
  142. if (string.IsNullOrEmpty(_deckID))
  143. {
  144. StringBuilder builder = new StringBuilder();
  145. Enumerable
  146. .Range(65, 26)
  147. .Select(e => ((char)e).ToString())
  148. .Concat(Enumerable.Range(97, 26).Select(e => ((char)e).ToString()))
  149. .Concat(Enumerable.Range(0, 10).Select(e => e.ToString()))
  150. .OrderBy(e => Guid.NewGuid())
  151. .Take(11)
  152. .ToList().ForEach(e => builder.Append(e));
  153. _deckID = builder.ToString();
  154. }
  155. return _deckID;
  156. }
  157. set
  158. {
  159. _deckID = value;
  160. }
  161. }
  162. #endregion
  163. #region deck name
  164. string _deckName = "";
  165. public string DeckName
  166. {
  167. get
  168. {
  169. if (string.IsNullOrEmpty(_deckName))
  170. {
  171. return "NewDeck";
  172. }
  173. return _deckName;
  174. }
  175. set
  176. {
  177. _deckName = value;
  178. }
  179. }
  180. #endregion
  181. #region List of cards included in the deck
  182. public List<CEntity_Base> DeckCards()
  183. {
  184. List<CEntity_Base> deckCards = new List<CEntity_Base>();
  185. if (DeckCardIDs != null)
  186. {
  187. foreach (int DeckCardID in DeckCardIDs)
  188. {
  189. CEntity_Base cEntity_Base = ContinuousController.instance.getCardEntityByCardID(DeckCardID);
  190. if (cEntity_Base != null)
  191. {
  192. deckCards.Add(cEntity_Base);
  193. }
  194. }
  195. }
  196. return deckCards;
  197. }
  198. #endregion
  199. #region List of cards included in the Digitama deck
  200. public List<CEntity_Base> DigitamaDeckCards()
  201. {
  202. List<CEntity_Base> deckCards = new List<CEntity_Base>();
  203. foreach (int DeckCardID in DigitamaDeckCardIDs)
  204. {
  205. CEntity_Base cEntity_Base = ContinuousController.instance.getCardEntityByCardID(DeckCardID);
  206. if (cEntity_Base != null)
  207. {
  208. deckCards.Add(cEntity_Base);
  209. }
  210. }
  211. return deckCards;
  212. }
  213. #endregion
  214. #region all cards in the deck
  215. public List<CEntity_Base> AllDeckCards()
  216. {
  217. List<CEntity_Base> AllDeckCards = new List<CEntity_Base>();
  218. foreach (CEntity_Base cEntity_Base in DigitamaDeckCards())
  219. {
  220. AllDeckCards.Add(cEntity_Base);
  221. }
  222. foreach (CEntity_Base cEntity_Base in DeckCards())
  223. {
  224. AllDeckCards.Add(cEntity_Base);
  225. }
  226. return AllDeckCards;
  227. }
  228. #endregion
  229. #region key card
  230. public int KeyCardId { get; set; } = -1;
  231. public CEntity_Base KeyCard
  232. {
  233. get
  234. {
  235. if (KeyCardId >= 0)
  236. {
  237. foreach (CEntity_Base Card in ContinuousController.instance.CardList)
  238. {
  239. if (Card.CardIndex == KeyCardId)
  240. {
  241. return Card;
  242. }
  243. }
  244. }
  245. if (DeckCards().Count >= 1)
  246. {
  247. List<CEntity_Base> deckCards = new List<CEntity_Base>();
  248. foreach (CEntity_Base cEntity_Base in DeckCards())
  249. {
  250. deckCards.Add(cEntity_Base);
  251. }
  252. deckCards = deckCards
  253. .OrderBy(value => Array.IndexOf(DataBase.cardKinds, value.cardKind))
  254. .ThenByDescending(value => value.Level)
  255. .ThenBy(value => Array.IndexOf(DataBase.cardColors, value.cardColors[0]))
  256. .ThenByDescending(value => value.PlayCost)
  257. .ThenByDescending(value => value.DP)
  258. .ThenBy(value => value.CardIndex)
  259. .ToList();
  260. return deckCards[0];
  261. }
  262. else if (DigitamaDeckCards().Count >= 1)
  263. {
  264. return DigitamaDeckCards()[0];
  265. }
  266. return null;
  267. }
  268. }
  269. #endregion
  270. #region List of card IDs included in the deck
  271. public List<int> DeckCardIDs { get; set; } = new List<int>();
  272. public List<int> DigitamaDeckCardIDs { get; set; } = new List<int>();
  273. #region カードを追加する
  274. public void AddCard(CEntity_Base cEntity_Base)
  275. {
  276. if (cEntity_Base.cardKind == CardKind.DigiEgg)
  277. {
  278. AddDigitamaDeckCard(cEntity_Base);
  279. }
  280. else
  281. {
  282. AddDeckCard(cEntity_Base);
  283. }
  284. }
  285. #endregion
  286. #region カードを除く
  287. public void RemoveCard(CEntity_Base cEntity_Base)
  288. {
  289. if (cEntity_Base.cardKind == CardKind.DigiEgg)
  290. {
  291. RemoveDigitamaDeckCard(cEntity_Base);
  292. }
  293. else
  294. {
  295. RemoveDeckCard(cEntity_Base);
  296. }
  297. }
  298. #endregion
  299. #region デッキにカードを追加する
  300. void AddDeckCard(CEntity_Base cEntity_Base)
  301. {
  302. List<CEntity_Base> _DeckCards = DeckCards();
  303. _DeckCards.Add(cEntity_Base);
  304. _DeckCards = SortedDeckCardsList(_DeckCards);
  305. DeckCardIDs = GetDeckCardCodes(_DeckCards);
  306. }
  307. #endregion
  308. #region デッキからカードを抜く
  309. void RemoveDeckCard(CEntity_Base cEntity_Base)
  310. {
  311. List<CEntity_Base> _DeckCards = DeckCards();
  312. _DeckCards.Remove(cEntity_Base);
  313. _DeckCards = SortedDeckCardsList(_DeckCards);
  314. DeckCardIDs = GetDeckCardCodes(_DeckCards);
  315. }
  316. #endregion
  317. #region デジタマデッキにカードを追加する
  318. void AddDigitamaDeckCard(CEntity_Base cEntity_Base)
  319. {
  320. List<CEntity_Base> _DeckCards = DigitamaDeckCards();
  321. _DeckCards.Add(cEntity_Base);
  322. _DeckCards = SortedDeckCardsList(_DeckCards);
  323. DigitamaDeckCardIDs = GetDeckCardCodes(_DeckCards);
  324. }
  325. #endregion
  326. #region デジタマデッキからカードを抜く
  327. void RemoveDigitamaDeckCard(CEntity_Base cEntity_Base)
  328. {
  329. List<CEntity_Base> _DeckCards = DigitamaDeckCards();
  330. _DeckCards.Remove(cEntity_Base);
  331. _DeckCards = SortedDeckCardsList(_DeckCards);
  332. DigitamaDeckCardIDs = GetDeckCardCodes(_DeckCards);
  333. }
  334. #endregion
  335. #region カードリストからカードIDリストを取得
  336. public static List<int> GetDeckCardCodes(List<CEntity_Base> DeckCards)
  337. {
  338. List<int> _DeckCardCodes = new List<int>();
  339. foreach (CEntity_Base DeckCard in DeckCards)
  340. {
  341. _DeckCardCodes.Add(DeckCard.CardIndex);
  342. }
  343. return _DeckCardCodes;
  344. }
  345. #endregion
  346. #endregion
  347. #region Sort card list
  348. public static List<CEntity_Base> SortedDeckCardsList(List<CEntity_Base> DeckCards)
  349. {
  350. List<CEntity_Base> DeckCards1 = new List<CEntity_Base>();
  351. foreach (CEntity_Base cEntity_Base in DeckCards)
  352. {
  353. DeckCards1.Add(cEntity_Base);
  354. }
  355. DeckCards1 = DeckCards1
  356. .OrderBy(value => Array.IndexOf(DataBase.cardKinds, value.cardKind))
  357. .ThenBy(value => value.Level)
  358. .ThenBy(value => Array.IndexOf(DataBase.cardColors, value.cardColors[0]))
  359. .ThenByDescending(value => value.PlayCost)
  360. .ThenByDescending(value => value.DP)
  361. .ThenBy(value => value.CardIndex)
  362. .ToList();
  363. return DeckCards1;
  364. }
  365. public static List<CEntity_Base> SortedCardPoolList(List<CEntity_Base> DeckCards)
  366. {
  367. List<CEntity_Base> DeckCards1 = new List<CEntity_Base>();
  368. foreach (CEntity_Base cEntity_Base in DeckCards)
  369. {
  370. DeckCards1.Add(cEntity_Base);
  371. }
  372. DeckCards1 = DeckCards1
  373. .OrderBy(value => Array.IndexOf(DataBase.SetIDs, value.SetID))
  374. .ThenBy(value => Array.IndexOf(DataBase.cardColors, value.cardColors[0]))
  375. .ThenBy(value => value.CardID)
  376. .ThenBy(value => value.CardIndex)
  377. .ToList();
  378. return DeckCards1;
  379. }
  380. public static List<CardSource> SortedCardsList(List<CardSource> DeckCards)
  381. {
  382. List<CardSource> DeckCards1 = new List<CardSource>();
  383. foreach (CardSource cardSource in DeckCards)
  384. {
  385. DeckCards1.Add(cardSource);
  386. }
  387. DeckCards1 = DeckCards1
  388. .OrderBy(value => value.SetID)
  389. .ThenBy(value => Array.IndexOf(DataBase.cardKinds, value.CardKind))
  390. .ThenBy(value => Array.IndexOf(DataBase.cardColors, value.BaseCardColorsFromEntity[0]))
  391. .ThenByDescending(value => value.BaseEvoCostsFromEntity.Count)
  392. .ThenByDescending(value => value.CardDP)
  393. .ThenBy(value => value.CardEntityIndex)
  394. .ToList();
  395. return DeckCards1;
  396. }
  397. #endregion
  398. #region Get 256 hexadecimal deck code
  399. #region Get the 256-decimal deck code from the deck name and deck card.
  400. public static string GetDeckCode(string _DeckName, List<CEntity_Base> _DeckCards, List<CEntity_Base> _DigitamaDeckCards, CEntity_Base keyCard)
  401. {
  402. string _DeckDataString = null;
  403. //deck name
  404. _DeckDataString += _DeckName + ",";
  405. SetDeckCard(_DeckCards);
  406. SetDeckCard(_DigitamaDeckCards);
  407. if (keyCard != null)
  408. {
  409. _DeckDataString += $"{keyCard.CardIndex},";
  410. }
  411. else
  412. {
  413. _DeckDataString += $"-1,";
  414. }
  415. //Debug.Log($"raw deck cord:{_DeckDataString}");
  416. void SetDeckCard(List<CEntity_Base> cEntity_Bases)
  417. {
  418. //Make the card list a non-duplicate list
  419. List<CEntity_Base> DistinctDeckCards = cEntity_Bases.Distinct().ToList();
  420. //Register a card ID list without duplicates
  421. foreach (CEntity_Base cardData in DistinctDeckCards)
  422. {
  423. _DeckDataString += cardData.CardIndex_String;
  424. }
  425. _DeckDataString += ",";
  426. //Save the number of cards of each card type (reduce by 1)
  427. List<int> _DistinctDeckCardCounts = new List<int>();
  428. foreach (CEntity_Base cardData in DistinctDeckCards)
  429. {
  430. _DistinctDeckCardCounts.Add(cEntity_Bases.Count((_CardData) => _CardData == cardData) - 1);
  431. }
  432. string x_n = null;
  433. //Convert the number of cards in the deck to n-ary number
  434. for (int i = 0; i < _DistinctDeckCardCounts.Count; i++)
  435. {
  436. x_n += ConvertBinaryNumber.IntToNString(_DistinctDeckCardCounts[i], n);
  437. }
  438. //Fill with 0s so that the number of digits is log(n)m digits
  439. if (x_n != null)
  440. {
  441. while (x_n.Count() % log_n_m != 0)
  442. {
  443. x_n += "0";
  444. }
  445. }
  446. //Convert n-ary number to m-ary number
  447. if (x_n != null)
  448. {
  449. string x_m = ConvertBinaryNumber.NStringToNKString(x_n, n, log_n_m);
  450. _DeckDataString += x_m;
  451. }
  452. _DeckDataString += ",";
  453. }
  454. return _DeckDataString;
  455. }
  456. #endregion
  457. #region Get the deck code for this deck
  458. public string GetThisDeckCode()
  459. {
  460. return DeckData.GetDeckCode(DeckName, DeckCards(), DigitamaDeckCards(), KeyCard);
  461. }
  462. #endregion
  463. #endregion
  464. #region Is the string suitable as a deck code?
  465. public static bool IsValidDeckCode(string DeckCode)
  466. {
  467. if (!DeckCode.Contains(","))
  468. {
  469. return false;
  470. }
  471. string[] parseByComma = DeckCode.Split(',');
  472. if (parseByComma.Length != 5 && parseByComma.Length != 6)
  473. {
  474. return false;
  475. }
  476. if (!string.IsNullOrEmpty(parseByComma[1]))
  477. {
  478. string[] SplitText = SplitClass.Split(parseByComma[1], 1);
  479. for (int j = 0; j < SplitText.Length; j++)
  480. {
  481. if (ConvertBinaryNumber.NStringToInt(SplitText[j], m) == 114514)
  482. {
  483. return false;
  484. }
  485. }
  486. }
  487. else
  488. {
  489. return false;
  490. }
  491. if (!string.IsNullOrEmpty(parseByComma[2]))
  492. {
  493. //256進数の文字列
  494. string x_m = parseByComma[2];
  495. //256進数をn進数に変換
  496. string x_n = ConvertBinaryNumber.NKStringToNString(x_m, n, log_n_m);
  497. if (x_n == "114514")
  498. {
  499. Debug.Log("[2]:114514");
  500. return false;
  501. }
  502. }
  503. else
  504. {
  505. return false;
  506. }
  507. if (!string.IsNullOrEmpty(parseByComma[3]))
  508. {
  509. string[] SplitText = SplitClass.Split(parseByComma[3], 1);
  510. for (int j = 0; j < SplitText.Length; j++)
  511. {
  512. if (ConvertBinaryNumber.NStringToInt(SplitText[j], m) == 114514)
  513. {
  514. return false;
  515. }
  516. }
  517. }
  518. if (!string.IsNullOrEmpty(parseByComma[4]))
  519. {
  520. //256進数の文字列
  521. string x_m = parseByComma[4];
  522. //256進数をn進数に変換
  523. string x_n = ConvertBinaryNumber.NKStringToNString(x_m, n, log_n_m);
  524. if (x_n == "114514")
  525. {
  526. Debug.Log("[4]:114514");
  527. return false;
  528. }
  529. }
  530. if (parseByComma.Length >= 6)
  531. {
  532. if (!string.IsNullOrEmpty(parseByComma[5]))
  533. {
  534. if (!int.TryParse(parseByComma[5], out int value))
  535. {
  536. return false;
  537. }
  538. }
  539. }
  540. return true;
  541. }
  542. #endregion
  543. #region Can this deck data be used in battle?
  544. public bool IsValidDeckData()
  545. {
  546. //The number of cards in the deck is exactly 50.
  547. if (DeckCards().Count != 50)
  548. {
  549. return false;
  550. }
  551. if (DigitamaDeckCards().Count > 5)
  552. {
  553. return false;
  554. }
  555. foreach (CEntity_Base cEntity_Base in DeckCards())
  556. {
  557. if (!cEntity_Base.IsStandardValid)
  558. {
  559. return false;
  560. }
  561. }
  562. foreach (CEntity_Base cEntity_Base in DigitamaDeckCards())
  563. {
  564. if (!cEntity_Base.IsStandardValid)
  565. {
  566. return false;
  567. }
  568. }
  569. return true;
  570. }
  571. #endregion
  572. #region blank deck code
  573. public static DeckData EmptyDeckData()
  574. {
  575. return new DeckData("");
  576. }
  577. #endregion
  578. #region Correct imported deck data
  579. public DeckData ModifiedDeckData()
  580. {
  581. List<CEntity_Base> deckCards = new List<CEntity_Base>();
  582. List<CEntity_Base> digitamaDeckCards = new List<CEntity_Base>();
  583. foreach (CEntity_Base cEntity_Base in AllDeckCards())
  584. {
  585. if (cEntity_Base.cardKind != CardKind.DigiEgg)
  586. {
  587. deckCards.Add(cEntity_Base);
  588. }
  589. else
  590. {
  591. digitamaDeckCards.Add(cEntity_Base);
  592. }
  593. }
  594. List<CEntity_Base> modifiedDeckCards = modifiedList(deckCards);
  595. List<CEntity_Base> modifiedDigitamaDeckCards = modifiedList(digitamaDeckCards);
  596. List<CEntity_Base> modifiedList(List<CEntity_Base> cEntity_Bases)
  597. {
  598. //Make the card list a non-duplicate list
  599. List<CEntity_Base> DistinctDeckCards = cEntity_Bases.Distinct().ToList();
  600. List<CEntity_Base> DistinctDeckCards1 = new List<CEntity_Base>();
  601. foreach (CEntity_Base cEntity_Base in DistinctDeckCards)
  602. {
  603. if (DistinctDeckCards1.Count((cEntity_Base1) => cEntity_Base.CardID == cEntity_Base1.CardID) == 0)
  604. {
  605. DistinctDeckCards1.Add(cEntity_Base);
  606. }
  607. }
  608. List<CEntity_Base> deckCards = new List<CEntity_Base>();
  609. foreach (CEntity_Base cEntity_Base in cEntity_Bases)
  610. {
  611. deckCards.Add(cEntity_Base);
  612. }
  613. //Remove more than the specified number of cards
  614. foreach (CEntity_Base cEntity_Base in DistinctDeckCards1)
  615. {
  616. while (cEntity_Base.SameCardIDCount(deckCards) > cEntity_Base.MaxCountInDeck)
  617. {
  618. CEntity_Base removeCard = null;
  619. foreach (CEntity_Base cEntity_Base1 in deckCards)
  620. {
  621. if (cEntity_Base1.CardID == cEntity_Base.CardID)
  622. {
  623. removeCard = cEntity_Base1;
  624. break;
  625. }
  626. }
  627. if (removeCard != null)
  628. {
  629. deckCards.Remove(removeCard);
  630. }
  631. }
  632. }
  633. return deckCards;
  634. }
  635. DeckData deckData = new DeckData(GetDeckCode(ValidateDeckName(this._deckName), modifiedDeckCards, modifiedDigitamaDeckCards, KeyCard), DeckID);
  636. if (!deckData.AllDeckCards().Contains(deckData.KeyCard))
  637. {
  638. deckData.KeyCardId = -1;
  639. }
  640. DeckData deckData1 = DeckBuildingRule.ModifiedDeckData(deckData);
  641. return deckData1;
  642. }
  643. #endregion
  644. #region Fixed deck name
  645. public static string ValidateDeckName(string deckName)
  646. {
  647. if (String.IsNullOrEmpty(deckName))
  648. {
  649. return deckName;
  650. }
  651. StringBuilder sb = new StringBuilder();
  652. foreach (char c in deckName)
  653. {
  654. if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c == ' '))
  655. {
  656. sb.Append(c);
  657. }
  658. }
  659. deckName = sb.ToString();
  660. var filter = new ProfanityFilter.ProfanityFilter();
  661. deckName = filter.CensorString(deckName);
  662. return deckName;
  663. }
  664. #endregion
  665. }
  666. #region split string
  667. public static class SplitClass
  668. {
  669. public static string[] Split(this string str, int count)
  670. {
  671. var list = new List<string>();
  672. int length = (int)Math.Ceiling((double)str.Length / count);
  673. for (int i = 0; i < length; i++)
  674. {
  675. int start = count * i;
  676. if (str.Length <= start)
  677. {
  678. break;
  679. }
  680. if (str.Length < start + count)
  681. {
  682. list.Add(str.Substring(start));
  683. }
  684. else
  685. {
  686. list.Add(str.Substring(start, count));
  687. }
  688. }
  689. return list.ToArray();
  690. }
  691. }
  692. #endregion