CEntity_Base.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using WebSocketSharp;
  6. using UnityEngine;
  7. [CreateAssetMenu(menuName = "Create/CEntity_Base")]
  8. public class CEntity_Base : ScriptableObject
  9. {
  10. public int CardIndex = 0;
  11. public List<CardColor> cardColors = new List<CardColor>();
  12. public int PlayCost = -1;
  13. public List<EvoCost> EvoCosts = new List<EvoCost>();
  14. public int Level = 0;
  15. public string CardName_JPN = "";
  16. public string CardName_ENG = "";
  17. public List<string> Form_JPN = new List<string>();
  18. public List<string> Form_ENG = new List<string>();
  19. public List<string> Attribute_JPN = new List<string>();
  20. public List<string> Attribute_ENG = new List<string>();
  21. public List<string> Type_JPN = new List<string>();
  22. public List<string> Type_ENG = new List<string>();
  23. public string CardSpriteName = "";
  24. public List<CardKind> cardKind = new List<CardKind> { CardKind.Digimon };
  25. [TextArea] public string EffectDiscription_JPN = "";
  26. [TextArea] public string EffectDiscription_ENG = "";
  27. [TextArea] public string InheritedEffectDiscription_JPN = "";
  28. [TextArea] public string InheritedEffectDiscription_ENG = "";
  29. [TextArea] public string SecurityEffectDiscription_JPN = "";
  30. [TextArea] public string SecurityEffectDiscription_ENG = "";
  31. public string CardEffectClassName = "";
  32. public int DP = 0;
  33. public Rarity rarity;
  34. public int OverflowMemory = 0;
  35. public int LinkDP = 0;
  36. [TextArea] public string LinkEffect = "";
  37. [TextArea] public string LinkRequirement = "";
  38. [TextArea] public string dualEffect = "";
  39. public List<CardColor> OptionCardColorRequirements = new List<CardColor>();
  40. [TextArea] public string OptionEffect = "";
  41. public bool HasInhetitedEffect => !string.IsNullOrEmpty(InheritedEffectDiscription_ENG) && !InheritedEffectDiscription_ENG.Equals("-");
  42. public bool HasSecutiryEffect => !string.IsNullOrEmpty(SecurityEffectDiscription_ENG) && !SecurityEffectDiscription_ENG.Equals("-");
  43. public string CardID = "";
  44. public int MaxCountInDeck = 4;
  45. public bool HasLoadStarted { get; set; } = false;
  46. public Sprite CardSprite { get; set; } = null;
  47. public async Task LoadCardImage()
  48. {
  49. if (String.IsNullOrEmpty(CardSpriteName))
  50. {
  51. return;
  52. }
  53. if (HasLoadStarted)
  54. {
  55. return;
  56. }
  57. HasLoadStarted = true;
  58. Sprite sprite = await StreamingAssetsUtility.GetSprite(CardSpriteName, isCard: true);
  59. CardSprite = sprite;
  60. }
  61. public async Task<Sprite> GetCardSprite()
  62. {
  63. if (!HasLoadStarted) await LoadCardImage();
  64. return CardSprite;
  65. }
  66. public bool IsACE => OverflowMemory >= 1;
  67. public bool IsStandardValid => true;
  68. public bool IsDualCard => cardKind.Count > 1;
  69. #region regulation mark
  70. public string RegulationMark
  71. {
  72. get
  73. {
  74. string regulationMark = "";
  75. switch (GetParseByHyphen(CardSpriteName)[0])
  76. {
  77. case "ST1":
  78. regulationMark = "00";
  79. break;
  80. case "ST2":
  81. regulationMark = "00";
  82. break;
  83. case "ST3":
  84. regulationMark = "00";
  85. break;
  86. case "ST4":
  87. regulationMark = "00";
  88. break;
  89. case "ST5":
  90. regulationMark = "00";
  91. break;
  92. case "ST6":
  93. regulationMark = "00";
  94. break;
  95. case "ST7":
  96. regulationMark = "01";
  97. break;
  98. case "ST8":
  99. regulationMark = "01";
  100. break;
  101. case "ST9":
  102. regulationMark = "01";
  103. break;
  104. case "ST10":
  105. regulationMark = "01";
  106. break;
  107. case "ST11":
  108. regulationMark = "01";
  109. break;
  110. case "ST12":
  111. regulationMark = "02";
  112. break;
  113. case "ST13":
  114. regulationMark = "02";
  115. break;
  116. case "ST14":
  117. regulationMark = "02";
  118. break;
  119. case "BT1":
  120. regulationMark = "00";
  121. break;
  122. case "BT2":
  123. regulationMark = "00";
  124. break;
  125. case "BT3":
  126. regulationMark = "00";
  127. break;
  128. case "BT4":
  129. regulationMark = "00";
  130. break;
  131. case "BT5":
  132. regulationMark = "00";
  133. break;
  134. case "BT6":
  135. regulationMark = "01";
  136. break;
  137. case "BT7":
  138. regulationMark = "01";
  139. break;
  140. case "BT8":
  141. regulationMark = "01";
  142. break;
  143. case "BT9":
  144. regulationMark = "01";
  145. break;
  146. case "BT10":
  147. regulationMark = "02";
  148. break;
  149. case "BT11":
  150. regulationMark = "02";
  151. break;
  152. case "BT12":
  153. regulationMark = "02";
  154. break;
  155. case "BT13":
  156. regulationMark = "02";
  157. break;
  158. case "EX1":
  159. regulationMark = "01";
  160. break;
  161. case "EX2":
  162. regulationMark = "01";
  163. break;
  164. case "EX3":
  165. regulationMark = "02";
  166. break;
  167. case "EX4":
  168. regulationMark = "02";
  169. break;
  170. case "RB1":
  171. regulationMark = "02";
  172. break;
  173. }
  174. return regulationMark;
  175. }
  176. }
  177. #endregion
  178. #region ???
  179. public string SetID
  180. {
  181. get
  182. {
  183. if (GetParseByHyphen(CardSpriteName).Length >= 1)
  184. {
  185. return GetParseByHyphen(CardSpriteName)[0];
  186. }
  187. return "";
  188. }
  189. }
  190. #endregion
  191. #region whether it is permanent card
  192. public bool IsPermanent => cardKind.Contains(CardKind.Digimon) || cardKind.Contains(CardKind.Tamer) || cardKind.Contains(CardKind.DigiEgg);
  193. #endregion
  194. #region ???
  195. public string CardIndex_String
  196. {
  197. get
  198. {
  199. string CardID_String = ConvertBinaryNumber.IntToNString(CardIndex, DeckData.m);
  200. while (CardID_String.Length < DeckData.CardKindCellLength)
  201. {
  202. CardID_String = $"0{CardID_String}";
  203. }
  204. return CardID_String;
  205. }
  206. }
  207. #endregion
  208. #region ???
  209. public static string[] GetParseByUnderBar(string CardImageName)
  210. {
  211. string[] parseByUnderBar = new string[] { CardImageName };
  212. if (CardImageName.Contains('_'))
  213. {
  214. parseByUnderBar = CardImageName.Split('_');
  215. }
  216. return parseByUnderBar;
  217. }
  218. #endregion
  219. #region ???
  220. public static string[] GetParseByHyphen(string CardImageName)
  221. {
  222. string[] parseByHyphen = new string[] { CardImageName };
  223. if (CardImageName.Contains('-'))
  224. {
  225. parseByHyphen = CardImageName.Split('-');
  226. }
  227. return parseByHyphen;
  228. }
  229. #endregion
  230. #region ???
  231. public int SameCardIDCount(List<CEntity_Base> DeckCards)
  232. {
  233. return DeckCards.Count((cEntity_Base) => cEntity_Base.CardID == CardID);
  234. }
  235. #endregion
  236. #region ???
  237. public bool isParallel
  238. {
  239. get
  240. {
  241. if (!string.IsNullOrEmpty(CardSpriteName))
  242. {
  243. string s = CardSpriteName.Replace(CardID, "");
  244. if (!string.IsNullOrEmpty(s))
  245. {
  246. if (s.Contains("_P"))
  247. {
  248. return true;
  249. }
  250. }
  251. }
  252. return false;
  253. }
  254. }
  255. #endregion
  256. #region ???
  257. public bool HasLevel
  258. {
  259. get
  260. {
  261. if (Level == 0)
  262. {
  263. return false;
  264. }
  265. if (!cardKind.Contains(CardKind.Digimon) && !cardKind.Contains(CardKind.DigiEgg))
  266. {
  267. return false;
  268. }
  269. return true;
  270. }
  271. }
  272. #endregion
  273. #region Whether the card has any cost
  274. public bool HasCost => PlayCost >= 0;
  275. #endregion
  276. #region Wheter the card has play cost
  277. public bool HasPlayCost => !cardKind.Contains(CardKind.Option) && PlayCost >= 0;
  278. #endregion
  279. #region Wheter the card has use cost
  280. public bool HasUseCost => cardKind.Contains(CardKind.Option) && PlayCost >= 0;
  281. #endregion
  282. }
  283. public enum CardKind
  284. {
  285. Digimon,
  286. Tamer,
  287. Option,
  288. DigiEgg,
  289. }
  290. [Serializable]
  291. public class EvoCost : IEquatable<EvoCost>
  292. {
  293. public CardColor CardColor;
  294. public int Level;
  295. public int MemoryCost;
  296. public bool Equals(EvoCost other)
  297. {
  298. if (other is null)
  299. {
  300. return false;
  301. }
  302. if (object.ReferenceEquals(this, other))
  303. {
  304. return true;
  305. }
  306. return CardColor.Equals(other.CardColor) && Level.Equals(other.Level) && MemoryCost.Equals(other.MemoryCost);
  307. }
  308. public override int GetHashCode() => CardColor.GetHashCode() ^ Level.GetHashCode() + MemoryCost.GetHashCode();
  309. }
  310. public enum CardColor
  311. {
  312. Red,
  313. Blue,
  314. Yellow,
  315. Green,
  316. White,
  317. Black,
  318. Purple,
  319. None,
  320. }
  321. public enum Rarity
  322. {
  323. C,
  324. U,
  325. R,
  326. SR,
  327. UR,
  328. SEC,
  329. P,
  330. None,
  331. }