DeckCodeUtility.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text.RegularExpressions;
  7. using UnityEngine;
  8. public class DeckCodeUtility
  9. {
  10. public static string GetDeckBuilderFile(DeckData data)
  11. {
  12. string DeckBuilderFile = "";
  13. DeckBuilderFile += $"Name: {data.DeckName}\n";
  14. DeckBuilderFile += $"Key Card: {data.KeyCardId}\n";
  15. DeckBuilderFile += $"Sort Index: {data.SortValue}\n\n";
  16. DeckBuilderFile += GetDeckBuilderDeckCode(data.AllDeckCards());
  17. return DeckBuilderFile;
  18. }
  19. [Obsolete]
  20. public static string GetTTSDeckCode(List<CEntity_Base> AllDeckCards)
  21. {
  22. string TTSDeckCode = "";
  23. TTSDeckCode += "[\"Exported from DCGO\"";
  24. foreach (CEntity_Base cEntity_Base in AllDeckCards)
  25. {
  26. TTSDeckCode += $",\"{cEntity_Base.CardID}\"";
  27. }
  28. TTSDeckCode += "]";
  29. return TTSDeckCode;
  30. }
  31. public static string GetDeckBuilderDeckCode(List<CEntity_Base> AllDeckCards)
  32. {
  33. string DeckBuilderDeckCode = "";
  34. DeckBuilderDeckCode += "// DeckList\n\n";
  35. List<CEntity_Base> distinctAllDeckCards = new List<CEntity_Base>();
  36. foreach (CEntity_Base cEntity_Base in AllDeckCards)
  37. {
  38. if (distinctAllDeckCards.Count((cEntity_Base1) => cEntity_Base.CardSpriteName == cEntity_Base1.CardSpriteName) == 0)
  39. {
  40. distinctAllDeckCards.Add(cEntity_Base);
  41. }
  42. }
  43. foreach (CEntity_Base cEntity_Base in distinctAllDeckCards)
  44. {
  45. string lineString = "";
  46. int count = AllDeckCards.Count((cEntity_Base1) => cEntity_Base.CardSpriteName == cEntity_Base1.CardSpriteName);
  47. if (count >= 1)
  48. {
  49. lineString += $"{count} {cEntity_Base.CardName_ENG} {cEntity_Base.CardSpriteName} \n";
  50. }
  51. DeckBuilderDeckCode += lineString;
  52. }
  53. DeckBuilderDeckCode = DataBase.ReplaceToASCII(DeckBuilderDeckCode);
  54. return DeckBuilderDeckCode;
  55. }
  56. public static List<CEntity_Base> GetAllDeckCardsFromTTSDeckCode(string TTSDeckCode)
  57. {
  58. List<CEntity_Base> AllDeckCards = new List<CEntity_Base>();
  59. if (!string.IsNullOrEmpty(TTSDeckCode))
  60. {
  61. TTSDeckCode = TTSDeckCode.Replace("[", "").Replace("]", "").Replace("\"", "");
  62. string[] parseByComma = TTSDeckCode.Split(',');
  63. for (int i = 0; i < parseByComma.Length; i++)
  64. {
  65. // if (i != 0)
  66. {
  67. CEntity_Base cEntity_Base = GetCardFromCardID(parseByComma[i]);
  68. if (cEntity_Base != null)
  69. {
  70. AllDeckCards.Add(cEntity_Base);
  71. }
  72. }
  73. }
  74. }
  75. return AllDeckCards;
  76. }
  77. public static List<CEntity_Base> GetAllDeckCardsFromDeckBuilderDeckCode(string DeckBuilderDeckCode, int plusCount = 0)
  78. {
  79. int value;
  80. List<CEntity_Base> AllDeckCards = new List<CEntity_Base>();
  81. if (!string.IsNullOrEmpty(DeckBuilderDeckCode))
  82. {
  83. Debug.Log($"DeckCode\n{DeckBuilderDeckCode}");
  84. using (StringReader reader = new StringReader(DeckBuilderDeckCode))
  85. {
  86. string line;
  87. while ((line = reader.ReadLine()) != null)
  88. {
  89. if (String.IsNullOrEmpty(line))
  90. continue;
  91. if (char.IsDigit(line[0]))
  92. {
  93. int count = 0;
  94. if (int.TryParse(line[0].ToString(), out value))
  95. count = value + plusCount;
  96. for (int i = 0; i < 4; i++)
  97. {
  98. line = line.TrimEnd();
  99. int lastSpaceIndex = line.LastIndexOf(" ");
  100. string cardID = line.Substring(lastSpaceIndex + 1);
  101. CEntity_Base cEntity_Base = GetCardFromCardID(cardID);
  102. if (cEntity_Base != null)
  103. {
  104. for (int k = 0; k < count; k++)
  105. AllDeckCards.Add(cEntity_Base);
  106. Debug.Log($"SUCCESSFULLY ADDED: {count}: {cardID}");
  107. break;
  108. }
  109. else
  110. {
  111. line += "/" + reader.ReadLine();
  112. }
  113. }
  114. }
  115. }
  116. }
  117. }
  118. return AllDeckCards;
  119. }
  120. static CEntity_Base GetCardFromCardID(string cardID)
  121. {
  122. CEntity_Base card = null;
  123. card = ContinuousController.instance.CardList.ToList().Find(cEntity_Base => cEntity_Base.CardID == cardID);
  124. if (card == null)
  125. return ContinuousController.instance.CardList.ToList().Find(cEntity_Base => cEntity_Base.CardSpriteName == cardID);
  126. return card;
  127. }
  128. }