CEntity_Base.cs 9.9 KB

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