DeckCodeUtility.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System;
  5. using System.Linq;
  6. using System.Text.RegularExpressions;
  7. public class DeckCodeUtility
  8. {
  9. public static string GetDeckBuilderFile(DeckData data)
  10. {
  11. string DeckBuilderFile = "";
  12. DeckBuilderFile += $"Name: {data.DeckName}\n";
  13. DeckBuilderFile += $"Key Card: {data.KeyCardId}\n";
  14. DeckBuilderFile += $"Sort Index: {data.SortValue}\n\n";
  15. DeckBuilderFile += GetDeckBuilderDeckCode(data.AllDeckCards());
  16. return DeckBuilderFile;
  17. }
  18. [Obsolete]
  19. public static string GetTTSDeckCode(List<CEntity_Base> AllDeckCards)
  20. {
  21. string TTSDeckCode = "";
  22. TTSDeckCode += "[\"Exported from DCGO\"";
  23. foreach (CEntity_Base cEntity_Base in AllDeckCards)
  24. {
  25. TTSDeckCode += $",\"{cEntity_Base.CardID}\"";
  26. }
  27. TTSDeckCode += "]";
  28. return TTSDeckCode;
  29. }
  30. public static string GetDeckBuilderDeckCode(List<CEntity_Base> AllDeckCards)
  31. {
  32. string DeckBuilderDeckCode = "";
  33. DeckBuilderDeckCode += "// DeckList\n\n";
  34. List<CEntity_Base> distinctAllDeckCards = new List<CEntity_Base>();
  35. foreach (CEntity_Base cEntity_Base in AllDeckCards)
  36. {
  37. if (distinctAllDeckCards.Count((cEntity_Base1) => cEntity_Base.CardID == cEntity_Base1.CardID) == 0)
  38. {
  39. distinctAllDeckCards.Add(cEntity_Base);
  40. }
  41. }
  42. foreach (CEntity_Base cEntity_Base in distinctAllDeckCards)
  43. {
  44. string lineString = "";
  45. int count = AllDeckCards.Count((cEntity_Base1) => cEntity_Base.CardID == cEntity_Base1.CardID);
  46. if (count >= 1)
  47. {
  48. lineString += $"{count} {cEntity_Base.CardName_ENG} {cEntity_Base.CardID} \n";
  49. }
  50. DeckBuilderDeckCode += lineString;
  51. }
  52. DeckBuilderDeckCode = DataBase.ReplaceToASCII(DeckBuilderDeckCode);
  53. return DeckBuilderDeckCode;
  54. }
  55. public static List<CEntity_Base> GetAllDeckCardsFromTTSDeckCode(string TTSDeckCode)
  56. {
  57. List<CEntity_Base> AllDeckCards = new List<CEntity_Base>();
  58. if (!string.IsNullOrEmpty(TTSDeckCode))
  59. {
  60. TTSDeckCode = TTSDeckCode.Replace("[", "").Replace("]", "").Replace("\"", "");
  61. string[] parseByComma = TTSDeckCode.Split(',');
  62. for (int i = 0; i < parseByComma.Length; i++)
  63. {
  64. // if (i != 0)
  65. {
  66. CEntity_Base cEntity_Base = GetCardFromCardID(parseByComma[i]);
  67. if (cEntity_Base == null)
  68. {
  69. cEntity_Base = GetCardFromSpriteName(parseByComma[i]);
  70. }
  71. if (cEntity_Base != null)
  72. {
  73. AllDeckCards.Add(cEntity_Base);
  74. }
  75. }
  76. }
  77. }
  78. return AllDeckCards;
  79. }
  80. public static List<CEntity_Base> GetAllDeckCardsFromDeckBuilderDeckCode(string DeckBuilderDeckCode, int plusCount = 0)
  81. {
  82. int value;
  83. List<CEntity_Base> AllDeckCards = new List<CEntity_Base>();
  84. if (!string.IsNullOrEmpty(DeckBuilderDeckCode))
  85. {
  86. DeckBuilderDeckCode = DeckBuilderDeckCode.Replace("\r", "\n");
  87. string[] parseByEnter = DeckBuilderDeckCode.Split('\n');
  88. for (int i = 0; i < parseByEnter.Length; i++)
  89. {
  90. if (!string.IsNullOrEmpty(parseByEnter[i]))
  91. {
  92. if (parseByEnter[i].Length >= 5)
  93. {
  94. if (parseByEnter[i][0] == '/' && parseByEnter[i][1] == '/')
  95. {
  96. continue;
  97. }
  98. int count = 0;
  99. string numberString = "";
  100. for (int j = 0; j < parseByEnter[i].Length; j++)
  101. {
  102. if (int.TryParse(parseByEnter[i][j].ToString(), out value))
  103. {
  104. numberString += parseByEnter[i][j].ToString();
  105. }
  106. else
  107. {
  108. break;
  109. }
  110. }
  111. if (int.TryParse(numberString, out value))
  112. {
  113. count = value + plusCount;
  114. }
  115. if (count >= 1)
  116. {
  117. if (parseByEnter[i][numberString.Length].ToString() == " " || parseByEnter[i][numberString.Length].ToString() == "\t")
  118. {
  119. string cardIDString = "";
  120. for (int j = 0; j < parseByEnter[i].Length; j++)
  121. {
  122. char targetChar = parseByEnter[i][parseByEnter[i].Length - 1 - j];
  123. if (targetChar.ToString() == " " || targetChar.ToString() == "\t")
  124. {
  125. if (!String.IsNullOrEmpty(cardIDString))
  126. {
  127. break;
  128. }
  129. }
  130. else
  131. {
  132. cardIDString += targetChar;
  133. }
  134. }
  135. cardIDString = new string(cardIDString.Reverse().ToArray());
  136. string cardIDStringCopy = cardIDString;
  137. for (int j = 0; j < cardIDStringCopy.Length - 1; j++)
  138. {
  139. bool result = Regex.IsMatch(cardIDStringCopy[j].ToString(), "[A-Z]");
  140. if (result)
  141. {
  142. break;
  143. }
  144. cardIDString = cardIDStringCopy.Substring(j + 1);
  145. }
  146. CEntity_Base cEntity_Base = GetCardFromCardID(cardIDString);
  147. if (cEntity_Base == null)
  148. {
  149. cEntity_Base = GetCardFromSpriteName(cardIDString);
  150. }
  151. if (cEntity_Base != null)
  152. {
  153. for (int k = 0; k < count; k++)
  154. {
  155. AllDeckCards.Add(cEntity_Base);
  156. }
  157. }
  158. else
  159. {
  160. Debug.Log($"cardIDString:{cardIDString}, cardEntity = null");
  161. }
  162. }
  163. }
  164. }
  165. }
  166. }
  167. }
  168. return AllDeckCards;
  169. }
  170. static CEntity_Base GetCardFromCardID(string cardID)
  171. {
  172. return ContinuousController.instance.CardList.ToList().Find(cEntity_Base => cEntity_Base.CardID == cardID);
  173. }
  174. static CEntity_Base GetCardFromSpriteName(string cardSpriteName)
  175. {
  176. return ContinuousController.instance.CardList.ToList().Find(cEntity_Base => cEntity_Base.CardSpriteName == cardSpriteName);
  177. }
  178. }