DeckData.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  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.Contains(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.Contains(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 => GetCardKindPriority(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. static int GetCardKindPriority(List<CardKind> kinds)
  365. {
  366. if (kinds == null || kinds.Count == 0)
  367. return 99;
  368. bool hasDigimon = kinds.Contains(CardKind.Digimon);
  369. bool hasOption = kinds.Contains(CardKind.Option);
  370. bool hasTamer = kinds.Contains(CardKind.Tamer);
  371. bool hasEgg = kinds.Contains(CardKind.DigiEgg);
  372. if (hasEgg && kinds.Count == 1) return 0;
  373. if (hasDigimon && kinds.Count == 1) return 1;
  374. if (hasDigimon && hasOption && kinds.Count == 2) return 2;
  375. if (hasTamer && kinds.Count == 1) return 3;
  376. if (hasOption && kinds.Count == 1) return 4;
  377. return 99;
  378. }
  379. }
  380. public static List<CEntity_Base> SortedCardPoolList(List<CEntity_Base> DeckCards)
  381. {
  382. List<CEntity_Base> DeckCards1 = new List<CEntity_Base>();
  383. foreach (CEntity_Base cEntity_Base in DeckCards)
  384. {
  385. DeckCards1.Add(cEntity_Base);
  386. }
  387. DeckCards1 = DeckCards1
  388. .OrderBy(value => Array.IndexOf(DataBase.SetIDs, value.SetID))
  389. .ThenBy(value => Array.IndexOf(DataBase.cardColors, value.cardColors.Count > 0 ? value.cardColors[0] : "None"))
  390. .ThenBy(value => value.CardID)
  391. .ThenBy(value => value.CardIndex)
  392. .ToList();
  393. return DeckCards1;
  394. }
  395. public static List<CardSource> SortedCardsList(List<CardSource> DeckCards)
  396. {
  397. List<CardSource> DeckCards1 = new List<CardSource>();
  398. foreach (CardSource cardSource in DeckCards)
  399. {
  400. DeckCards1.Add(cardSource);
  401. }
  402. DeckCards1 = DeckCards1
  403. .OrderBy(value => value.SetID)
  404. .ThenBy(value => Array.IndexOf(DataBase.cardKinds, value.CardKinds))
  405. .ThenBy(value => Array.IndexOf(DataBase.cardColors, value.BaseCardColorsFromEntity[0]))
  406. .ThenByDescending(value => value.BaseEvoCostsFromEntity.Count)
  407. .ThenByDescending(value => value.CardDP)
  408. .ThenBy(value => value.CardEntityIndex)
  409. .ToList();
  410. return DeckCards1;
  411. }
  412. #endregion
  413. #region Get 256 hexadecimal deck code
  414. #region Get the 256-decimal deck code from the deck name and deck card.
  415. public static string GetDeckCode(string _DeckName, List<CEntity_Base> _DeckCards, List<CEntity_Base> _DigitamaDeckCards, CEntity_Base keyCard)
  416. {
  417. string _DeckDataString = null;
  418. //deck name
  419. _DeckDataString += _DeckName + ",";
  420. SetDeckCard(_DeckCards);
  421. SetDeckCard(_DigitamaDeckCards);
  422. if (keyCard != null)
  423. {
  424. _DeckDataString += $"{keyCard.CardIndex},";
  425. }
  426. else
  427. {
  428. _DeckDataString += $"-1,";
  429. }
  430. //Debug.Log($"raw deck cord:{_DeckDataString}");
  431. void SetDeckCard(List<CEntity_Base> cEntity_Bases)
  432. {
  433. //Make the card list a non-duplicate list
  434. List<CEntity_Base> DistinctDeckCards = cEntity_Bases.Distinct().ToList();
  435. //Register a card ID list without duplicates
  436. foreach (CEntity_Base cardData in DistinctDeckCards)
  437. {
  438. _DeckDataString += cardData.CardIndex_String;
  439. }
  440. _DeckDataString += ",";
  441. //Save the number of cards of each card type (reduce by 1)
  442. List<int> _DistinctDeckCardCounts = new List<int>();
  443. foreach (CEntity_Base cardData in DistinctDeckCards)
  444. {
  445. _DistinctDeckCardCounts.Add(cEntity_Bases.Count((_CardData) => _CardData == cardData) - 1);
  446. }
  447. string x_n = null;
  448. //Convert the number of cards in the deck to n-ary number
  449. for (int i = 0; i < _DistinctDeckCardCounts.Count; i++)
  450. {
  451. x_n += ConvertBinaryNumber.IntToNString(_DistinctDeckCardCounts[i], n);
  452. }
  453. //Fill with 0s so that the number of digits is log(n)m digits
  454. if (x_n != null)
  455. {
  456. while (x_n.Count() % log_n_m != 0)
  457. {
  458. x_n += "0";
  459. }
  460. }
  461. //Convert n-ary number to m-ary number
  462. if (x_n != null)
  463. {
  464. string x_m = ConvertBinaryNumber.NStringToNKString(x_n, n, log_n_m);
  465. _DeckDataString += x_m;
  466. }
  467. _DeckDataString += ",";
  468. }
  469. return _DeckDataString;
  470. }
  471. #endregion
  472. #region Get the deck code for this deck
  473. public string GetThisDeckCode()
  474. {
  475. return DeckData.GetDeckCode(DeckName, DeckCards(), DigitamaDeckCards(), KeyCard);
  476. }
  477. #endregion
  478. #endregion
  479. #region Is the string suitable as a deck code?
  480. public static bool IsValidDeckCode(string DeckCode)
  481. {
  482. if (!DeckCode.Contains(","))
  483. {
  484. return false;
  485. }
  486. string[] parseByComma = DeckCode.Split(',');
  487. if (parseByComma.Length != 5 && parseByComma.Length != 6)
  488. {
  489. return false;
  490. }
  491. if (!string.IsNullOrEmpty(parseByComma[1]))
  492. {
  493. string[] SplitText = SplitClass.Split(parseByComma[1], 1);
  494. for (int j = 0; j < SplitText.Length; j++)
  495. {
  496. if (ConvertBinaryNumber.NStringToInt(SplitText[j], m) == 114514)
  497. {
  498. return false;
  499. }
  500. }
  501. }
  502. else
  503. {
  504. return false;
  505. }
  506. if (!string.IsNullOrEmpty(parseByComma[2]))
  507. {
  508. //256進数の文字列
  509. string x_m = parseByComma[2];
  510. //256進数をn進数に変換
  511. string x_n = ConvertBinaryNumber.NKStringToNString(x_m, n, log_n_m);
  512. if (x_n == "114514")
  513. {
  514. Debug.Log("[2]:114514");
  515. return false;
  516. }
  517. }
  518. else
  519. {
  520. return false;
  521. }
  522. if (!string.IsNullOrEmpty(parseByComma[3]))
  523. {
  524. string[] SplitText = SplitClass.Split(parseByComma[3], 1);
  525. for (int j = 0; j < SplitText.Length; j++)
  526. {
  527. if (ConvertBinaryNumber.NStringToInt(SplitText[j], m) == 114514)
  528. {
  529. return false;
  530. }
  531. }
  532. }
  533. if (!string.IsNullOrEmpty(parseByComma[4]))
  534. {
  535. //256進数の文字列
  536. string x_m = parseByComma[4];
  537. //256進数をn進数に変換
  538. string x_n = ConvertBinaryNumber.NKStringToNString(x_m, n, log_n_m);
  539. if (x_n == "114514")
  540. {
  541. Debug.Log("[4]:114514");
  542. return false;
  543. }
  544. }
  545. if (parseByComma.Length >= 6)
  546. {
  547. if (!string.IsNullOrEmpty(parseByComma[5]))
  548. {
  549. if (!int.TryParse(parseByComma[5], out int value))
  550. {
  551. return false;
  552. }
  553. }
  554. }
  555. return true;
  556. }
  557. #endregion
  558. #region Can this deck data be used in battle?
  559. public bool IsValidDeckData()
  560. {
  561. //The number of cards in the deck is exactly 50.
  562. if (DeckCards().Count != 50)
  563. {
  564. return false;
  565. }
  566. if (DigitamaDeckCards().Count > 5)
  567. {
  568. return false;
  569. }
  570. foreach (CEntity_Base cEntity_Base in DeckCards())
  571. {
  572. if (!cEntity_Base.IsStandardValid)
  573. {
  574. return false;
  575. }
  576. }
  577. foreach (CEntity_Base cEntity_Base in DigitamaDeckCards())
  578. {
  579. if (!cEntity_Base.IsStandardValid)
  580. {
  581. return false;
  582. }
  583. }
  584. return true;
  585. }
  586. #endregion
  587. #region blank deck code
  588. public static DeckData EmptyDeckData()
  589. {
  590. return new DeckData("");
  591. }
  592. #endregion
  593. #region Correct imported deck data
  594. public DeckData ModifiedDeckData()
  595. {
  596. List<CEntity_Base> deckCards = new List<CEntity_Base>();
  597. List<CEntity_Base> digitamaDeckCards = new List<CEntity_Base>();
  598. foreach (CEntity_Base cEntity_Base in AllDeckCards())
  599. {
  600. if (!cEntity_Base.cardKind.Contains(CardKind.DigiEgg))
  601. {
  602. deckCards.Add(cEntity_Base);
  603. }
  604. else
  605. {
  606. digitamaDeckCards.Add(cEntity_Base);
  607. }
  608. }
  609. List<CEntity_Base> modifiedDeckCards = modifiedList(deckCards);
  610. List<CEntity_Base> modifiedDigitamaDeckCards = modifiedList(digitamaDeckCards);
  611. List<CEntity_Base> modifiedList(List<CEntity_Base> cEntity_Bases)
  612. {
  613. //Make the card list a non-duplicate list
  614. List<CEntity_Base> DistinctDeckCards = cEntity_Bases.Distinct().ToList();
  615. List<CEntity_Base> DistinctDeckCards1 = new List<CEntity_Base>();
  616. foreach (CEntity_Base cEntity_Base in DistinctDeckCards)
  617. {
  618. if (DistinctDeckCards1.Count((cEntity_Base1) => cEntity_Base.CardID == cEntity_Base1.CardID) == 0)
  619. {
  620. DistinctDeckCards1.Add(cEntity_Base);
  621. }
  622. }
  623. List<CEntity_Base> deckCards = new List<CEntity_Base>();
  624. foreach (CEntity_Base cEntity_Base in cEntity_Bases)
  625. {
  626. deckCards.Add(cEntity_Base);
  627. }
  628. //Remove more than the specified number of cards
  629. foreach (CEntity_Base cEntity_Base in DistinctDeckCards1)
  630. {
  631. while (cEntity_Base.SameCardIDCount(deckCards) > cEntity_Base.MaxCountInDeck)
  632. {
  633. CEntity_Base removeCard = null;
  634. foreach (CEntity_Base cEntity_Base1 in deckCards)
  635. {
  636. if (cEntity_Base1.CardID == cEntity_Base.CardID)
  637. {
  638. removeCard = cEntity_Base1;
  639. break;
  640. }
  641. }
  642. if (removeCard != null)
  643. {
  644. deckCards.Remove(removeCard);
  645. }
  646. }
  647. }
  648. return deckCards;
  649. }
  650. DeckData deckData = new DeckData(GetDeckCode(this._deckName, modifiedDeckCards, modifiedDigitamaDeckCards, KeyCard), DeckID);
  651. if (!deckData.AllDeckCards().Contains(deckData.KeyCard))
  652. {
  653. deckData.KeyCardId = -1;
  654. }
  655. DeckData deckData1 = DeckBuildingRule.ModifiedDeckData(deckData);
  656. return deckData1;
  657. }
  658. #endregion
  659. #region Fixed deck name
  660. public static string ValidateDeckName(string deckName)
  661. {
  662. if (String.IsNullOrEmpty(deckName))
  663. {
  664. return deckName;
  665. }
  666. StringBuilder sb = new StringBuilder();
  667. foreach (char c in deckName)
  668. {
  669. if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c == ' '))
  670. {
  671. sb.Append(c);
  672. }
  673. }
  674. deckName = sb.ToString();
  675. var filter = new ProfanityFilter.ProfanityFilter();
  676. deckName = filter.CensorString(deckName);
  677. return deckName;
  678. }
  679. #endregion
  680. }
  681. #region split string
  682. public static class SplitClass
  683. {
  684. public static string[] Split(this string str, int count)
  685. {
  686. var list = new List<string>();
  687. int length = (int)Math.Ceiling((double)str.Length / count);
  688. for (int i = 0; i < length; i++)
  689. {
  690. int start = count * i;
  691. if (str.Length <= start)
  692. {
  693. break;
  694. }
  695. if (str.Length < start + count)
  696. {
  697. list.Add(str.Substring(start));
  698. }
  699. else
  700. {
  701. list.Add(str.Substring(start, count));
  702. }
  703. }
  704. return list.ToArray();
  705. }
  706. }
  707. #endregion