CEntity_Base.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using System;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  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 = 0;
  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 CardKind 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 bool HasInhetitedEffect => !string.IsNullOrEmpty(InheritedEffectDiscription_ENG);
  35. public bool HasSecutiryEffect => !string.IsNullOrEmpty(SecurityEffectDiscription_ENG);
  36. public string CardID = "";
  37. public int MaxCountInDeck = 4;
  38. public bool HasLoadStarted { get; set; } = false;
  39. public Sprite CardSprite { get; set; } = null;
  40. public async Task LoadCardImage()
  41. {
  42. if (String.IsNullOrEmpty(CardSpriteName))
  43. {
  44. return;
  45. }
  46. if (HasLoadStarted)
  47. {
  48. return;
  49. }
  50. HasLoadStarted = true;
  51. Sprite sprite = await StreamingAssetsUtility.GetSprite(CardSpriteName, isCard: true);
  52. CardSprite = sprite;
  53. }
  54. public async Task<Sprite> GetCardSprite()
  55. {
  56. if (!HasLoadStarted)
  57. {
  58. await LoadCardImage();
  59. }
  60. return CardSprite;
  61. }
  62. public bool IsACE => OverflowMemory >= 1;
  63. public bool IsStandardValid => true;
  64. #region regulation mark
  65. public string RegulationMark
  66. {
  67. get
  68. {
  69. string regulationMark = "";
  70. switch (GetParseByHyphen(CardSpriteName)[0])
  71. {
  72. case "ST1":
  73. regulationMark = "00";
  74. break;
  75. case "ST2":
  76. regulationMark = "00";
  77. break;
  78. case "ST3":
  79. regulationMark = "00";
  80. break;
  81. case "ST4":
  82. regulationMark = "00";
  83. break;
  84. case "ST5":
  85. regulationMark = "00";
  86. break;
  87. case "ST6":
  88. regulationMark = "00";
  89. break;
  90. case "ST7":
  91. regulationMark = "01";
  92. break;
  93. case "ST8":
  94. regulationMark = "01";
  95. break;
  96. case "ST9":
  97. regulationMark = "01";
  98. break;
  99. case "ST10":
  100. regulationMark = "01";
  101. break;
  102. case "ST11":
  103. regulationMark = "01";
  104. break;
  105. case "ST12":
  106. regulationMark = "02";
  107. break;
  108. case "ST13":
  109. regulationMark = "02";
  110. break;
  111. case "ST14":
  112. regulationMark = "02";
  113. break;
  114. case "BT1":
  115. regulationMark = "00";
  116. break;
  117. case "BT2":
  118. regulationMark = "00";
  119. break;
  120. case "BT3":
  121. regulationMark = "00";
  122. break;
  123. case "BT4":
  124. regulationMark = "00";
  125. break;
  126. case "BT5":
  127. regulationMark = "00";
  128. break;
  129. case "BT6":
  130. regulationMark = "01";
  131. break;
  132. case "BT7":
  133. regulationMark = "01";
  134. break;
  135. case "BT8":
  136. regulationMark = "01";
  137. break;
  138. case "BT9":
  139. regulationMark = "01";
  140. break;
  141. case "BT10":
  142. regulationMark = "02";
  143. break;
  144. case "BT11":
  145. regulationMark = "02";
  146. break;
  147. case "BT12":
  148. regulationMark = "02";
  149. break;
  150. case "BT13":
  151. regulationMark = "02";
  152. break;
  153. case "EX1":
  154. regulationMark = "01";
  155. break;
  156. case "EX2":
  157. regulationMark = "01";
  158. break;
  159. case "EX3":
  160. regulationMark = "02";
  161. break;
  162. case "EX4":
  163. regulationMark = "02";
  164. break;
  165. case "RB1":
  166. regulationMark = "02";
  167. break;
  168. }
  169. return regulationMark;
  170. }
  171. }
  172. #endregion
  173. #region セットID
  174. public string SetID
  175. {
  176. get
  177. {
  178. if (GetParseByHyphen(CardSpriteName).Length >= 1)
  179. {
  180. return GetParseByHyphen(CardSpriteName)[0];
  181. }
  182. return "";
  183. }
  184. }
  185. #endregion
  186. #region whether it is permanent card
  187. public bool IsPermanent => cardKind == CardKind.Digimon || cardKind == CardKind.Tamer || cardKind == CardKind.DigiEgg;
  188. #endregion
  189. #region カードIndexをデッキコードに用いる文字列に変換(256進数)
  190. public string CardIndex_String
  191. {
  192. get
  193. {
  194. string CardID_String = ConvertBinaryNumber.IntToNString(CardIndex, DeckData.m);
  195. while (CardID_String.Length < DeckData.CardKindCellLength)
  196. {
  197. CardID_String = $"0{CardID_String}";
  198. }
  199. return CardID_String;
  200. }
  201. }
  202. #endregion
  203. #region カード画像名をアンダーバーで区切り
  204. public static string[] GetParseByUnderBar(string CardImageName)
  205. {
  206. string[] parseByUnderBar = new string[] { CardImageName };
  207. if (CardImageName.Contains('_'))
  208. {
  209. parseByUnderBar = CardImageName.Split('_');
  210. }
  211. return parseByUnderBar;
  212. }
  213. #endregion
  214. #region カード画像名をハイフンで区切り
  215. public static string[] GetParseByHyphen(string CardImageName)
  216. {
  217. string[] parseByHyphen = new string[] { CardImageName };
  218. if (CardImageName.Contains('-'))
  219. {
  220. parseByHyphen = CardImageName.Split('-');
  221. }
  222. return parseByHyphen;
  223. }
  224. #endregion
  225. #region デッキにこれと同カードIDのカードが入っている枚数
  226. public int SameCardIDCount(List<CEntity_Base> DeckCards)
  227. {
  228. return DeckCards.Count((cEntity_Base) => cEntity_Base.CardID == CardID);
  229. }
  230. #endregion
  231. #region パラレルか
  232. public bool isParallel
  233. {
  234. get
  235. {
  236. if (!string.IsNullOrEmpty(CardSpriteName))
  237. {
  238. string s = CardSpriteName.Replace(CardID, "");
  239. if (!string.IsNullOrEmpty(s))
  240. {
  241. if (s.Contains("_P"))
  242. {
  243. return true;
  244. }
  245. }
  246. }
  247. return false;
  248. }
  249. }
  250. #endregion
  251. #region レベルを持つか
  252. public bool HasLevel
  253. {
  254. get
  255. {
  256. if (Level == 0)
  257. {
  258. return false;
  259. }
  260. if (cardKind != CardKind.Digimon && cardKind != CardKind.DigiEgg)
  261. {
  262. return false;
  263. }
  264. return true;
  265. }
  266. }
  267. #endregion
  268. #region コストを持つか
  269. public bool HasCost => cardKind != CardKind.DigiEgg && PlayCost >= 0;
  270. #endregion
  271. #region Wheter the card has play cost
  272. public bool HasPlayCost => cardKind != CardKind.DigiEgg && cardKind != CardKind.Option && PlayCost >= 0;
  273. #endregion
  274. #region Wheter the card has use cost
  275. public bool HasUseCost => cardKind == CardKind.Option && PlayCost >= 0;
  276. #endregion
  277. }
  278. public enum CardKind
  279. {
  280. Digimon,
  281. Tamer,
  282. Option,
  283. DigiEgg,
  284. }
  285. [Serializable]
  286. public class EvoCost : IEquatable<EvoCost>
  287. {
  288. public CardColor CardColor;
  289. public int Level;
  290. public int MemoryCost;
  291. public bool Equals(EvoCost other)
  292. {
  293. if (other is null)
  294. {
  295. return false;
  296. }
  297. if (object.ReferenceEquals(this, other))
  298. {
  299. return true;
  300. }
  301. return CardColor.Equals(other.CardColor) && Level.Equals(other.Level) && MemoryCost.Equals(other.MemoryCost);
  302. }
  303. public override int GetHashCode() => CardColor.GetHashCode() ^ Level.GetHashCode() + MemoryCost.GetHashCode();
  304. }
  305. public enum CardColor
  306. {
  307. Red,
  308. Blue,
  309. Yellow,
  310. Green,
  311. White,
  312. Black,
  313. Purple,
  314. None,
  315. }
  316. public enum Rarity
  317. {
  318. C,
  319. U,
  320. R,
  321. SR,
  322. SEC,
  323. P,
  324. None,
  325. }