DeckCodeUtility.cs 7.3 KB

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