DeckData.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  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. Debug.Log(DeckCardIDs.Count);
  188. foreach (int DeckCardID in DeckCardIDs)
  189. {
  190. CEntity_Base cEntity_Base = ContinuousController.instance.getCardEntityByCardID(DeckCardID);
  191. if (cEntity_Base != null)
  192. {
  193. deckCards.Add(cEntity_Base);
  194. }
  195. }
  196. }
  197. return deckCards;
  198. }
  199. #endregion
  200. #region List of cards included in the Digitama deck
  201. public List<CEntity_Base> DigitamaDeckCards()
  202. {
  203. List<CEntity_Base> deckCards = new List<CEntity_Base>();
  204. foreach (int DeckCardID in DigitamaDeckCardIDs)
  205. {
  206. CEntity_Base cEntity_Base = ContinuousController.instance.getCardEntityByCardID(DeckCardID);
  207. if (cEntity_Base != null)
  208. {
  209. deckCards.Add(cEntity_Base);
  210. }
  211. }
  212. return deckCards;
  213. }
  214. #endregion
  215. #region all cards in the deck
  216. public List<CEntity_Base> AllDeckCards()
  217. {
  218. List<CEntity_Base> AllDeckCards = new List<CEntity_Base>();
  219. foreach (CEntity_Base cEntity_Base in DigitamaDeckCards())
  220. {
  221. AllDeckCards.Add(cEntity_Base);
  222. }
  223. foreach (CEntity_Base cEntity_Base in DeckCards())
  224. {
  225. AllDeckCards.Add(cEntity_Base);
  226. }
  227. return AllDeckCards;
  228. }
  229. #endregion
  230. #region key card
  231. public int KeyCardId { get; set; } = -1;
  232. public CEntity_Base KeyCard
  233. {
  234. get
  235. {
  236. if (KeyCardId >= 0)
  237. {
  238. foreach (CEntity_Base Card in ContinuousController.instance.CardList)
  239. {
  240. if (Card.CardIndex == KeyCardId)
  241. {
  242. return Card;
  243. }
  244. }
  245. }
  246. if (DeckCards().Count >= 1)
  247. {
  248. List<CEntity_Base> deckCards = new List<CEntity_Base>();
  249. foreach (CEntity_Base cEntity_Base in DeckCards())
  250. {
  251. deckCards.Add(cEntity_Base);
  252. }
  253. deckCards = deckCards
  254. .OrderBy(value => Array.IndexOf(DataBase.cardKinds, value.cardKind))
  255. .ThenByDescending(value => value.Level)
  256. .ThenBy(value => Array.IndexOf(DataBase.cardColors, value.cardColors[0]))
  257. .ThenByDescending(value => value.PlayCost)
  258. .ThenByDescending(value => value.DP)
  259. .ThenBy(value => value.CardIndex)
  260. .ToList();
  261. return deckCards[0];
  262. }
  263. else if (DigitamaDeckCards().Count >= 1)
  264. {
  265. return DigitamaDeckCards()[0];
  266. }
  267. return null;
  268. }
  269. }
  270. #endregion
  271. #region List of card IDs included in the deck
  272. public List<int> DeckCardIDs { get; set; } = new List<int>();
  273. public List<int> DigitamaDeckCardIDs { get; set; } = new List<int>();
  274. #region カードを追加する
  275. public void AddCard(CEntity_Base cEntity_Base)
  276. {
  277. if (cEntity_Base.cardKind == CardKind.DigiEgg)
  278. {
  279. AddDigitamaDeckCard(cEntity_Base);
  280. }
  281. else
  282. {
  283. AddDeckCard(cEntity_Base);
  284. }
  285. }
  286. #endregion
  287. #region カードを除く
  288. public void RemoveCard(CEntity_Base cEntity_Base)
  289. {
  290. if (cEntity_Base.cardKind == CardKind.DigiEgg)
  291. {
  292. RemoveDigitamaDeckCard(cEntity_Base);
  293. }
  294. else
  295. {
  296. RemoveDeckCard(cEntity_Base);
  297. }
  298. }
  299. #endregion
  300. #region デッキにカードを追加する
  301. void AddDeckCard(CEntity_Base cEntity_Base)
  302. {
  303. List<CEntity_Base> _DeckCards = DeckCards();
  304. _DeckCards.Add(cEntity_Base);
  305. _DeckCards = SortedDeckCardsList(_DeckCards);
  306. DeckCardIDs = GetDeckCardCodes(_DeckCards);
  307. }
  308. #endregion
  309. #region デッキからカードを抜く
  310. void RemoveDeckCard(CEntity_Base cEntity_Base)
  311. {
  312. List<CEntity_Base> _DeckCards = DeckCards();
  313. _DeckCards.Remove(cEntity_Base);
  314. _DeckCards = SortedDeckCardsList(_DeckCards);
  315. DeckCardIDs = GetDeckCardCodes(_DeckCards);
  316. }
  317. #endregion
  318. #region デジタマデッキにカードを追加する
  319. void AddDigitamaDeckCard(CEntity_Base cEntity_Base)
  320. {
  321. List<CEntity_Base> _DeckCards = DigitamaDeckCards();
  322. _DeckCards.Add(cEntity_Base);
  323. _DeckCards = SortedDeckCardsList(_DeckCards);
  324. DigitamaDeckCardIDs = GetDeckCardCodes(_DeckCards);
  325. }
  326. #endregion
  327. #region デジタマデッキからカードを抜く
  328. void RemoveDigitamaDeckCard(CEntity_Base cEntity_Base)
  329. {
  330. List<CEntity_Base> _DeckCards = DigitamaDeckCards();
  331. _DeckCards.Remove(cEntity_Base);
  332. _DeckCards = SortedDeckCardsList(_DeckCards);
  333. DigitamaDeckCardIDs = GetDeckCardCodes(_DeckCards);
  334. }
  335. #endregion
  336. #region カードリストからカードIDリストを取得
  337. public static List<int> GetDeckCardCodes(List<CEntity_Base> DeckCards)
  338. {
  339. List<int> _DeckCardCodes = new List<int>();
  340. foreach (CEntity_Base DeckCard in DeckCards)
  341. {
  342. _DeckCardCodes.Add(DeckCard.CardIndex);
  343. }
  344. return _DeckCardCodes;
  345. }
  346. #endregion
  347. #endregion
  348. #region Sort card list
  349. public static List<CEntity_Base> SortedDeckCardsList(List<CEntity_Base> DeckCards)
  350. {
  351. List<CEntity_Base> DeckCards1 = new List<CEntity_Base>();
  352. foreach (CEntity_Base cEntity_Base in DeckCards)
  353. {
  354. DeckCards1.Add(cEntity_Base);
  355. }
  356. DeckCards1 = DeckCards1
  357. .OrderBy(value => Array.IndexOf(DataBase.cardKinds, value.cardKind))
  358. .ThenBy(value => value.Level)
  359. .ThenBy(value => Array.IndexOf(DataBase.cardColors, value.cardColors[0]))
  360. .ThenByDescending(value => value.PlayCost)
  361. .ThenByDescending(value => value.DP)
  362. .ThenBy(value => value.CardIndex)
  363. .ToList();
  364. return DeckCards1;
  365. }
  366. public static List<CEntity_Base> SortedCardPoolList(List<CEntity_Base> DeckCards)
  367. {
  368. List<CEntity_Base> DeckCards1 = new List<CEntity_Base>();
  369. foreach (CEntity_Base cEntity_Base in DeckCards)
  370. {
  371. DeckCards1.Add(cEntity_Base);
  372. }
  373. DeckCards1 = DeckCards1
  374. .OrderBy(value => Array.IndexOf(DataBase.SetIDs, value.SetID))
  375. .ThenBy(value => Array.IndexOf(DataBase.cardColors, value.cardColors[0]))
  376. .ThenBy(value => value.CardID)
  377. .ThenBy(value => value.CardIndex)
  378. .ToList();
  379. return DeckCards1;
  380. }
  381. public static List<CardSource> SortedCardsList(List<CardSource> DeckCards)
  382. {
  383. List<CardSource> DeckCards1 = new List<CardSource>();
  384. foreach (CardSource cardSource in DeckCards)
  385. {
  386. DeckCards1.Add(cardSource);
  387. }
  388. DeckCards1 = DeckCards1
  389. .OrderBy(value => value.SetID)
  390. .ThenBy(value => Array.IndexOf(DataBase.cardKinds, value.CardKind))
  391. .ThenBy(value => Array.IndexOf(DataBase.cardColors, value.BaseCardColorsFromEntity[0]))
  392. .ThenByDescending(value => value.BaseEvoCostsFromEntity.Count)
  393. .ThenByDescending(value => value.CardDP)
  394. .ThenBy(value => value.CardEntityIndex)
  395. .ToList();
  396. return DeckCards1;
  397. }
  398. #endregion
  399. #region Get 256 hexadecimal deck code
  400. #region Get the 256-decimal deck code from the deck name and deck card.
  401. public static string GetDeckCode(string _DeckName, List<CEntity_Base> _DeckCards, List<CEntity_Base> _DigitamaDeckCards, CEntity_Base keyCard)
  402. {
  403. string _DeckDataString = null;
  404. //deck name
  405. _DeckDataString += _DeckName + ",";
  406. SetDeckCard(_DeckCards);
  407. SetDeckCard(_DigitamaDeckCards);
  408. if (keyCard != null)
  409. {
  410. _DeckDataString += $"{keyCard.CardIndex},";
  411. }
  412. else
  413. {
  414. _DeckDataString += $"-1,";
  415. }
  416. //Debug.Log($"raw deck cord:{_DeckDataString}");
  417. void SetDeckCard(List<CEntity_Base> cEntity_Bases)
  418. {
  419. //Make the card list a non-duplicate list
  420. List<CEntity_Base> DistinctDeckCards = cEntity_Bases.Distinct().ToList();
  421. //Register a card ID list without duplicates
  422. foreach (CEntity_Base cardData in DistinctDeckCards)
  423. {
  424. _DeckDataString += cardData.CardIndex_String;
  425. }
  426. _DeckDataString += ",";
  427. //Save the number of cards of each card type (reduce by 1)
  428. List<int> _DistinctDeckCardCounts = new List<int>();
  429. foreach (CEntity_Base cardData in DistinctDeckCards)
  430. {
  431. _DistinctDeckCardCounts.Add(cEntity_Bases.Count((_CardData) => _CardData == cardData) - 1);
  432. }
  433. string x_n = null;
  434. //Convert the number of cards in the deck to n-ary number
  435. for (int i = 0; i < _DistinctDeckCardCounts.Count; i++)
  436. {
  437. x_n += ConvertBinaryNumber.IntToNString(_DistinctDeckCardCounts[i], n);
  438. }
  439. //Fill with 0s so that the number of digits is log(n)m digits
  440. if (x_n != null)
  441. {
  442. while (x_n.Count() % log_n_m != 0)
  443. {
  444. x_n += "0";
  445. }
  446. }
  447. //Convert n-ary number to m-ary number
  448. if (x_n != null)
  449. {
  450. string x_m = ConvertBinaryNumber.NStringToNKString(x_n, n, log_n_m);
  451. _DeckDataString += x_m;
  452. }
  453. _DeckDataString += ",";
  454. }
  455. return _DeckDataString;
  456. }
  457. #endregion
  458. #region Get the deck code for this deck
  459. public string GetThisDeckCode()
  460. {
  461. return DeckData.GetDeckCode(DeckName, DeckCards(), DigitamaDeckCards(), KeyCard);
  462. }
  463. #endregion
  464. #endregion
  465. #region Is the string suitable as a deck code?
  466. public static bool IsValidDeckCode(string DeckCode)
  467. {
  468. if (!DeckCode.Contains(","))
  469. {
  470. return false;
  471. }
  472. string[] parseByComma = DeckCode.Split(',');
  473. if (parseByComma.Length != 5 && parseByComma.Length != 6)
  474. {
  475. return false;
  476. }
  477. if (!string.IsNullOrEmpty(parseByComma[1]))
  478. {
  479. string[] SplitText = SplitClass.Split(parseByComma[1], 1);
  480. for (int j = 0; j < SplitText.Length; j++)
  481. {
  482. if (ConvertBinaryNumber.NStringToInt(SplitText[j], m) == 114514)
  483. {
  484. return false;
  485. }
  486. }
  487. }
  488. else
  489. {
  490. return false;
  491. }
  492. if (!string.IsNullOrEmpty(parseByComma[2]))
  493. {
  494. //256進数の文字列
  495. string x_m = parseByComma[2];
  496. //256進数をn進数に変換
  497. string x_n = ConvertBinaryNumber.NKStringToNString(x_m, n, log_n_m);
  498. if (x_n == "114514")
  499. {
  500. Debug.Log("[2]:114514");
  501. return false;
  502. }
  503. }
  504. else
  505. {
  506. return false;
  507. }
  508. if (!string.IsNullOrEmpty(parseByComma[3]))
  509. {
  510. string[] SplitText = SplitClass.Split(parseByComma[3], 1);
  511. for (int j = 0; j < SplitText.Length; j++)
  512. {
  513. if (ConvertBinaryNumber.NStringToInt(SplitText[j], m) == 114514)
  514. {
  515. return false;
  516. }
  517. }
  518. }
  519. if (!string.IsNullOrEmpty(parseByComma[4]))
  520. {
  521. //256進数の文字列
  522. string x_m = parseByComma[4];
  523. //256進数をn進数に変換
  524. string x_n = ConvertBinaryNumber.NKStringToNString(x_m, n, log_n_m);
  525. if (x_n == "114514")
  526. {
  527. Debug.Log("[4]:114514");
  528. return false;
  529. }
  530. }
  531. if (parseByComma.Length >= 6)
  532. {
  533. if (!string.IsNullOrEmpty(parseByComma[5]))
  534. {
  535. if (!int.TryParse(parseByComma[5], out int value))
  536. {
  537. return false;
  538. }
  539. }
  540. }
  541. return true;
  542. }
  543. #endregion
  544. #region Can this deck data be used in battle?
  545. public bool IsValidDeckData()
  546. {
  547. //The number of cards in the deck is exactly 50.
  548. if (DeckCards().Count != 50)
  549. {
  550. return false;
  551. }
  552. if (DigitamaDeckCards().Count > 5)
  553. {
  554. return false;
  555. }
  556. foreach (CEntity_Base cEntity_Base in DeckCards())
  557. {
  558. if (!cEntity_Base.IsStandardValid)
  559. {
  560. return false;
  561. }
  562. }
  563. foreach (CEntity_Base cEntity_Base in DigitamaDeckCards())
  564. {
  565. if (!cEntity_Base.IsStandardValid)
  566. {
  567. return false;
  568. }
  569. }
  570. return true;
  571. }
  572. #endregion
  573. #region blank deck code
  574. public static DeckData EmptyDeckData()
  575. {
  576. return new DeckData("");
  577. }
  578. #endregion
  579. #region Correct imported deck data
  580. public DeckData ModifiedDeckData()
  581. {
  582. List<CEntity_Base> deckCards = new List<CEntity_Base>();
  583. List<CEntity_Base> digitamaDeckCards = new List<CEntity_Base>();
  584. foreach (CEntity_Base cEntity_Base in AllDeckCards())
  585. {
  586. if (cEntity_Base.cardKind != CardKind.DigiEgg)
  587. {
  588. deckCards.Add(cEntity_Base);
  589. }
  590. else
  591. {
  592. digitamaDeckCards.Add(cEntity_Base);
  593. }
  594. }
  595. List<CEntity_Base> modifiedDeckCards = modifiedList(deckCards);
  596. List<CEntity_Base> modifiedDigitamaDeckCards = modifiedList(digitamaDeckCards);
  597. List<CEntity_Base> modifiedList(List<CEntity_Base> cEntity_Bases)
  598. {
  599. //Make the card list a non-duplicate list
  600. List<CEntity_Base> DistinctDeckCards = cEntity_Bases.Distinct().ToList();
  601. List<CEntity_Base> DistinctDeckCards1 = new List<CEntity_Base>();
  602. foreach (CEntity_Base cEntity_Base in DistinctDeckCards)
  603. {
  604. if (DistinctDeckCards1.Count((cEntity_Base1) => cEntity_Base.CardID == cEntity_Base1.CardID) == 0)
  605. {
  606. DistinctDeckCards1.Add(cEntity_Base);
  607. }
  608. }
  609. List<CEntity_Base> deckCards = new List<CEntity_Base>();
  610. foreach (CEntity_Base cEntity_Base in cEntity_Bases)
  611. {
  612. deckCards.Add(cEntity_Base);
  613. }
  614. //Remove more than the specified number of cards
  615. foreach (CEntity_Base cEntity_Base in DistinctDeckCards1)
  616. {
  617. while (cEntity_Base.SameCardIDCount(deckCards) > cEntity_Base.MaxCountInDeck)
  618. {
  619. CEntity_Base removeCard = null;
  620. foreach (CEntity_Base cEntity_Base1 in deckCards)
  621. {
  622. if (cEntity_Base1.CardID == cEntity_Base.CardID)
  623. {
  624. removeCard = cEntity_Base1;
  625. break;
  626. }
  627. }
  628. if (removeCard != null)
  629. {
  630. deckCards.Remove(removeCard);
  631. }
  632. }
  633. }
  634. return deckCards;
  635. }
  636. DeckData deckData = new DeckData(GetDeckCode(ValidateDeckName(this._deckName), modifiedDeckCards, modifiedDigitamaDeckCards, KeyCard), DeckID);
  637. if (!deckData.AllDeckCards().Contains(deckData.KeyCard))
  638. {
  639. deckData.KeyCardId = -1;
  640. }
  641. DeckData deckData1 = DeckBuildingRule.ModifiedDeckData(deckData);
  642. return deckData1;
  643. }
  644. #endregion
  645. #region Fixed deck name
  646. public static string ValidateDeckName(string deckName)
  647. {
  648. if (String.IsNullOrEmpty(deckName))
  649. {
  650. return deckName;
  651. }
  652. StringBuilder sb = new StringBuilder();
  653. foreach (char c in deckName)
  654. {
  655. if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c == ' '))
  656. {
  657. sb.Append(c);
  658. }
  659. }
  660. deckName = sb.ToString();
  661. var filter = new ProfanityFilter.ProfanityFilter();
  662. deckName = filter.CensorString(deckName);
  663. return deckName;
  664. }
  665. #endregion
  666. }
  667. #region split string
  668. public static class SplitClass
  669. {
  670. public static string[] Split(this string str, int count)
  671. {
  672. var list = new List<string>();
  673. int length = (int)Math.Ceiling((double)str.Length / count);
  674. for (int i = 0; i < length; i++)
  675. {
  676. int start = count * i;
  677. if (str.Length <= start)
  678. {
  679. break;
  680. }
  681. if (str.Length < start + count)
  682. {
  683. list.Add(str.Substring(start));
  684. }
  685. else
  686. {
  687. list.Add(str.Substring(start, count));
  688. }
  689. }
  690. return list.ToArray();
  691. }
  692. }
  693. #endregion