ContinuousController.cs 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629
  1. using Photon.Pun;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Threading.Tasks;
  8. using UnityEngine;
  9. using UnityEngine.Events;
  10. using UnityEngine.EventSystems;
  11. using UnityEngine.SceneManagement;
  12. using Hashtable = ExitGames.Client.Photon.Hashtable;
  13. public class ContinuousController : MonoBehaviour
  14. {
  15. [Header("game language")]
  16. // public Language language;
  17. [Header("Game version")]
  18. public float GameVer;
  19. [Header("ignore updates")]
  20. public bool IgnoreUpdate;
  21. [Header("card list")]
  22. public CEntity_Base[] CardList = new CEntity_Base[] { };
  23. [Header("Card list sorted by card ID")]
  24. public CEntity_Base[] SortedCardList = new CEntity_Base[] { };
  25. [Header("Card back image")]
  26. public Sprite ReverseCard;
  27. public Sprite ReverseCard_Digitama;
  28. [Header("SE prefab")]
  29. public SoundObject soundObject;
  30. [Header("deck code encryption")]
  31. public ShuffleDeckCode ShuffleDeckCode;
  32. DeckData _battleDeckData = null;
  33. public DeckData BattleDeckData
  34. {
  35. get
  36. {
  37. return _battleDeckData;
  38. }
  39. set
  40. {
  41. _battleDeckData = value;
  42. if (value != null)
  43. {
  44. LastBattleDeckData = value;
  45. }
  46. }
  47. }
  48. public DeckData LastBattleDeckData { get; private set; } = null;
  49. public bool NeedUpdate { get; set; }
  50. public bool isRandomMatch { get; set; }
  51. [HideInInspector] public List<SkillInfo> nullSkillInfos = null;
  52. public String GameVerString => Application.version;//GameVer.ToString(CultureInfo.InvariantCulture);
  53. #region Key for property to save deck data for battle
  54. public static string DeckDataPropertyKey => "BattleDeckData";
  55. #endregion
  56. #region Key for the property that stores the player name data
  57. public static string PlayerNameKey => "PlayerNameKey";
  58. #endregion
  59. #region Key for the property that stores the win count data
  60. public static string WinCountKey => "WinCountKey";
  61. #endregion
  62. [Header("Player name character limit")]
  63. public int PlayerNameMaxLength;
  64. #region Call up a scene for data storage
  65. public static IEnumerator LoadCoroutine()
  66. {
  67. if (instance == null)
  68. {
  69. SceneManager.LoadSceneAsync("ContinuousControllerScene", LoadSceneMode.Additive);
  70. while (instance == null)
  71. {
  72. yield return null;
  73. }
  74. instance.Init();
  75. }
  76. }
  77. #endregion
  78. #region List of Deck Recipes
  79. public List<DeckData> DeckDatas { get; set; } = new List<DeckData>();
  80. #endregion
  81. #region Deck Recipe Key
  82. public string DeckDatasPlayerPrefsKey { get { return "DeckDatas3"; } }
  83. #endregion
  84. public CEntity_Base DiaboromonToken { get; private set; }
  85. public CEntity_Base AmonToken { get; private set; }
  86. public CEntity_Base UmonToken { get; private set; }
  87. public CEntity_Base FujitsumonToken { get; private set; }
  88. public CEntity_Base GyuukimonToken { get; private set; }
  89. public CEntity_Base KoHagurumonToken { get; private set; }
  90. public CEntity_Base FamiliarToken { get; private set; }
  91. public CEntity_Base SelfDeleteFamiliarToken { get; private set; }
  92. public CEntity_Base VoleeZerdruckenToken { get; private set; }
  93. public CEntity_Base UkaNoMitamaToken { get; private set; }
  94. public CEntity_Base WarGrowlmonToken { get; private set; }
  95. public CEntity_Base TaomonToken { get; private set; }
  96. public CEntity_Base RapidmonToken { get; private set; }
  97. public CEntity_Base PipeFoxToken { get; private set; }
  98. public CEntity_Base AthoRenePorToken { get; private set; }
  99. public CEntity_Base HinukamuyToken { get; private set; }
  100. public CEntity_Base PetrificationToken { get; private set; }
  101. public CardRestriction BanList { get; private set; } = new CardRestriction(new List<CardLimitCount>(), new List<BannedPair>());
  102. void LoadBanList()
  103. {
  104. BanList = DataBase.ENGBanList;
  105. }
  106. async Task CreateTokenData()
  107. {
  108. DiaboromonToken = new CEntity_Base()
  109. {
  110. cardColors = new List<CardColor>() { CardColor.White },
  111. PlayCost = 14,
  112. Level = 6,
  113. CardName_JPN = "ディアボロモン",
  114. CardName_ENG = "Diaboromon",
  115. Form_JPN = new List<string>() { "究極体" },
  116. Form_ENG = new List<string>() { "Mega" },
  117. Attribute_JPN = new List<string>() { "不明" },
  118. Attribute_ENG = new List<string>() { "Unknown" },
  119. Type_JPN = new List<string>() { "種族不明" },
  120. Type_ENG = new List<string>() { "Unidentified" },
  121. CardSpriteName = "BT2-082-token",
  122. cardKind = new List<CardKind> { CardKind.Digimon },
  123. DP = 3000,
  124. };
  125. await DiaboromonToken.GetCardSprite();
  126. AmonToken = new CEntity_Base()
  127. {
  128. cardColors = new List<CardColor>() { CardColor.Red },
  129. PlayCost = -1,
  130. Level = 0,
  131. CardName_JPN = "紅炎のアモン",
  132. CardName_ENG = "Amon of Crimson Flame",
  133. Form_JPN = new List<string>(),
  134. Form_ENG = new List<string>(),
  135. Attribute_JPN = new List<string>(),
  136. Attribute_ENG = new List<string>(),
  137. Type_JPN = new List<string>(),
  138. Type_ENG = new List<string>(),
  139. CardSpriteName = "BT14-018-token-red",
  140. cardKind = new List<CardKind> { CardKind.Digimon },
  141. DP = 6000,
  142. CardEffectClassName = "BT4_038"
  143. };
  144. await AmonToken.GetCardSprite();
  145. UmonToken = new CEntity_Base()
  146. {
  147. cardColors = new List<CardColor>() { CardColor.Yellow },
  148. PlayCost = -1,
  149. Level = 0,
  150. CardName_JPN = "蒼雷のウモン",
  151. CardName_ENG = "Umon of Blue Thunder",
  152. Form_JPN = new List<string>(),
  153. Form_ENG = new List<string>(),
  154. Attribute_JPN = new List<string>(),
  155. Attribute_ENG = new List<string>(),
  156. Type_JPN = new List<string>(),
  157. Type_ENG = new List<string>(),
  158. CardSpriteName = "BT14-018-token-yellow",
  159. cardKind = new List<CardKind> { CardKind.Digimon },
  160. DP = 6000,
  161. CardEffectClassName = "BT1_031"
  162. };
  163. await UmonToken.GetCardSprite();
  164. FujitsumonToken = new CEntity_Base()
  165. {
  166. cardColors = new List<CardColor>() { CardColor.Purple },
  167. PlayCost = -1,
  168. Level = 0,
  169. CardName_JPN = "フジツモン",
  170. CardName_ENG = "Fujitsumon",
  171. Form_JPN = new List<string>(),
  172. Form_ENG = new List<string>(),
  173. Attribute_JPN = new List<string>(),
  174. Attribute_ENG = new List<string>(),
  175. Type_JPN = new List<string>(),
  176. Type_ENG = new List<string>(),
  177. CardSpriteName = "EX5-058-token",
  178. cardKind = new List<CardKind> { CardKind.Digimon },
  179. DP = 3000,
  180. CardEffectClassName = "EX5_058_token"
  181. };
  182. await FujitsumonToken.GetCardSprite();
  183. GyuukimonToken = new CEntity_Base()
  184. {
  185. cardColors = new List<CardColor>() { CardColor.Purple },
  186. PlayCost = 7,
  187. Level = 5,
  188. CardName_JPN = "ギュウキモン",
  189. CardName_ENG = "Gyuukimon",
  190. Form_JPN = new List<string>() { "究極の" },
  191. Form_ENG = new List<string>() { "Ultimate" },
  192. Attribute_JPN = new List<string>() { "ウイルス" },
  193. Attribute_ENG = new List<string>() { "Virus" },
  194. Type_JPN = new List<string>() { "ダークアニマル" },
  195. Type_ENG = new List<string>() { "Dark Animal" },
  196. CardSpriteName = "LM-018-token",
  197. cardKind = new List<CardKind> { CardKind.Digimon },
  198. DP = 3000,
  199. };
  200. await GyuukimonToken.GetCardSprite();
  201. KoHagurumonToken = new CEntity_Base()
  202. {
  203. cardColors = new List<CardColor>() { CardColor.Black },
  204. PlayCost = -1,
  205. Level = 0,
  206. CardName_JPN = "",
  207. CardName_ENG = "KoHagurumon",
  208. Form_JPN = new List<string>(),
  209. Form_ENG = new List<string>(),
  210. Attribute_JPN = new List<string>(),
  211. Attribute_ENG = new List<string>(),
  212. Type_JPN = new List<string>(),
  213. Type_ENG = new List<string>(),
  214. CardSpriteName = "BT16-052-token",
  215. cardKind = new List<CardKind> { CardKind.Digimon },
  216. DP = 1000,
  217. CardEffectClassName = "BT16_052_token"
  218. };
  219. await KoHagurumonToken.GetCardSprite();
  220. FamiliarToken = new CEntity_Base()
  221. {
  222. cardColors = new List<CardColor>() { CardColor.Yellow },
  223. PlayCost = -1,
  224. Level = 0,
  225. CardName_JPN = "",
  226. CardName_ENG = "Familiar",
  227. Form_JPN = new List<string>(),
  228. Form_ENG = new List<string>(),
  229. Attribute_JPN = new List<string>(),
  230. Attribute_ENG = new List<string>(),
  231. Type_JPN = new List<string>(),
  232. Type_ENG = new List<string>(),
  233. CardSpriteName = "EX7-030-token",
  234. cardKind = new List<CardKind> { CardKind.Digimon },
  235. DP = 3000,
  236. CardEffectClassName = "EX7_030_token"
  237. };
  238. await FamiliarToken.GetCardSprite();
  239. SelfDeleteFamiliarToken = new CEntity_Base()
  240. {
  241. cardColors = new List<CardColor>() { CardColor.Yellow },
  242. PlayCost = -1,
  243. Level = 0,
  244. CardName_JPN = "",
  245. CardName_ENG = "Familiar",
  246. Form_JPN = new List<string>(),
  247. Form_ENG = new List<string>(),
  248. Attribute_JPN = new List<string>(),
  249. Attribute_ENG = new List<string>(),
  250. Type_JPN = new List<string>(),
  251. Type_ENG = new List<string>(),
  252. CardSpriteName = "EX7-030-token",
  253. cardKind = new List<CardKind> { CardKind.Digimon },
  254. DP = 3000,
  255. CardEffectClassName = "P_165_token"
  256. };
  257. await SelfDeleteFamiliarToken.GetCardSprite();
  258. VoleeZerdruckenToken = new CEntity_Base()
  259. {
  260. cardColors = new List<CardColor>() { CardColor.Purple },
  261. PlayCost = -1,
  262. Level = 4,
  263. CardName_JPN = "",
  264. CardName_ENG = "Volée & Zerdrücken",
  265. Form_JPN = new List<string>(),
  266. Form_ENG = new List<string>(),
  267. Attribute_JPN = new List<string>(),
  268. Attribute_ENG = new List<string>(),
  269. Type_JPN = new List<string>(),
  270. Type_ENG = new List<string>(),
  271. CardSpriteName = "EX7-058-token",
  272. cardKind = new List<CardKind> { CardKind.Digimon },
  273. DP = 5000,
  274. CardEffectClassName = "EX7_058_token"
  275. };
  276. await VoleeZerdruckenToken.GetCardSprite();
  277. UkaNoMitamaToken = new CEntity_Base()
  278. {
  279. cardColors = new List<CardColor>() { CardColor.Yellow },
  280. PlayCost = -1,
  281. Level = 0,
  282. CardName_JPN = "",
  283. CardName_ENG = "Uka-no-Mitama",
  284. Form_JPN = new List<string>(),
  285. Form_ENG = new List<string>(),
  286. Attribute_JPN = new List<string>(),
  287. Attribute_ENG = new List<string>(),
  288. Type_JPN = new List<string>(),
  289. Type_ENG = new List<string>(),
  290. CardSpriteName = "EX8-037-token",
  291. cardKind = new List<CardKind> { CardKind.Digimon },
  292. DP = 9000,
  293. CardEffectClassName = "EX8_037_token"
  294. };
  295. await UkaNoMitamaToken.GetCardSprite();
  296. WarGrowlmonToken = new CEntity_Base()
  297. {
  298. cardColors = new List<CardColor>() { CardColor.Red },
  299. PlayCost = -1,
  300. Level = 0,
  301. CardName_JPN = "",
  302. CardName_ENG = "WarGrowlmon",
  303. Form_JPN = new List<string>(),
  304. Form_ENG = new List<string>(),
  305. Attribute_JPN = new List<string>(),
  306. Attribute_ENG = new List<string>(),
  307. Type_JPN = new List<string>(),
  308. Type_ENG = new List<string>(),
  309. CardSpriteName = "BT19-091-token-red",
  310. cardKind = new List<CardKind> { CardKind.Digimon },
  311. DP = 6000
  312. };
  313. await WarGrowlmonToken.GetCardSprite();
  314. TaomonToken = new CEntity_Base()
  315. {
  316. cardColors = new List<CardColor>() { CardColor.Yellow },
  317. PlayCost = -1,
  318. Level = 0,
  319. CardName_JPN = "",
  320. CardName_ENG = "Taomon",
  321. Form_JPN = new List<string>(),
  322. Form_ENG = new List<string>(),
  323. Attribute_JPN = new List<string>(),
  324. Attribute_ENG = new List<string>(),
  325. Type_JPN = new List<string>(),
  326. Type_ENG = new List<string>(),
  327. CardSpriteName = "BT19-091-token-yellow",
  328. cardKind = new List<CardKind> { CardKind.Digimon },
  329. DP = 6000
  330. };
  331. await TaomonToken.GetCardSprite();
  332. RapidmonToken = new CEntity_Base()
  333. {
  334. cardColors = new List<CardColor>() { CardColor.Green },
  335. PlayCost = -1,
  336. Level = 0,
  337. CardName_JPN = "",
  338. CardName_ENG = "Rapidmon",
  339. Form_JPN = new List<string>(),
  340. Form_ENG = new List<string>(),
  341. Attribute_JPN = new List<string>(),
  342. Attribute_ENG = new List<string>(),
  343. Type_JPN = new List<string>(),
  344. Type_ENG = new List<string>(),
  345. CardSpriteName = "BT19-091-token-green",
  346. cardKind = new List<CardKind> { CardKind.Digimon },
  347. DP = 6000
  348. };
  349. await RapidmonToken.GetCardSprite();
  350. PipeFoxToken = new CEntity_Base()
  351. {
  352. cardColors = new List<CardColor>() { CardColor.Yellow },
  353. PlayCost = -1,
  354. Level = 0,
  355. CardName_JPN = "",
  356. CardName_ENG = "Pipe-Fox",
  357. Form_JPN = new List<string>(),
  358. Form_ENG = new List<string>(),
  359. Attribute_JPN = new List<string>(),
  360. Attribute_ENG = new List<string>(),
  361. Type_JPN = new List<string>(),
  362. Type_ENG = new List<string>(),
  363. CardSpriteName = "BT19-040-token",
  364. cardKind = new List<CardKind> { CardKind.Digimon },
  365. DP = 6000,
  366. CardEffectClassName = "BT19_040_token"
  367. };
  368. await PipeFoxToken.GetCardSprite();
  369. AthoRenePorToken = new CEntity_Base()
  370. {
  371. cardColors = new List<CardColor>() { CardColor.White },
  372. PlayCost = -1,
  373. Level = 0,
  374. CardName_JPN = "",
  375. CardName_ENG = "Atho, René & Por",
  376. Form_JPN = new List<string>(),
  377. Form_ENG = new List<string>(),
  378. Attribute_JPN = new List<string>(),
  379. Attribute_ENG = new List<string>(),
  380. Type_JPN = new List<string>(),
  381. Type_ENG = new List<string>(),
  382. CardSpriteName = "BT20-017-token",
  383. cardKind = new List<CardKind> { CardKind.Digimon },
  384. DP = 6000,
  385. CardEffectClassName = "BT20_017_token"
  386. };
  387. await AthoRenePorToken.GetCardSprite();
  388. HinukamuyToken = new CEntity_Base()
  389. {
  390. cardColors = new List<CardColor>() { CardColor.White },
  391. PlayCost = -1,
  392. Level = 0,
  393. CardName_JPN = "",
  394. CardName_ENG = "HinukamuyToken",
  395. Form_JPN = new List<string>(),
  396. Form_ENG = new List<string>(),
  397. Attribute_JPN = new List<string>(),
  398. Attribute_ENG = new List<string>(),
  399. Type_JPN = new List<string>(),
  400. Type_ENG = new List<string>(),
  401. CardSpriteName = "BT23-057-token",
  402. cardKind = new List<CardKind> { CardKind.Digimon },
  403. DP = 6000,
  404. CardEffectClassName = "BT23_057_token"
  405. };
  406. await HinukamuyToken.GetCardSprite();
  407. PetrificationToken = new CEntity_Base()
  408. {
  409. cardColors = new List<CardColor>() { CardColor.White },
  410. PlayCost = -1,
  411. Level = 0,
  412. CardName_JPN = "",
  413. CardName_ENG = "Petrification",
  414. Form_JPN = new List<string>(),
  415. Form_ENG = new List<string>(),
  416. Attribute_JPN = new List<string>(),
  417. Attribute_ENG = new List<string>(),
  418. Type_JPN = new List<string>(),
  419. Type_ENG = new List<string>(),
  420. CardSpriteName = "BT21-029-token",
  421. cardKind = new List<CardKind> { CardKind.Digimon },
  422. DP = 3000,
  423. CardEffectClassName = "BT21_029_token"
  424. };
  425. await PetrificationToken.GetCardSprite();
  426. }
  427. public static ContinuousController instance = null;
  428. private void Awake()
  429. {
  430. instance = this;
  431. }
  432. public async void Init()
  433. {
  434. Application.targetFrameRate = 60;
  435. int random = RandomUtility.getRamdom();
  436. UnityEngine.Random.InitState(random);
  437. Debug.Log($"Game Initialize - random number sequence initialization,InitState:{random}");
  438. Sprite reverseCardSprite = await StreamingAssetsUtility.GetSprite("card_back_main");
  439. if (reverseCardSprite != null)
  440. {
  441. ReverseCard = reverseCardSprite;
  442. }
  443. Sprite reverseDigieggCardSprite = await StreamingAssetsUtility.GetSprite("card_back_sub");
  444. if (reverseDigieggCardSprite != null)
  445. {
  446. ReverseCard_Digitama = reverseDigieggCardSprite;
  447. }
  448. LoadBanList();
  449. // deck data
  450. //DeckDatas = PlayerPrefsUtil.LoadList<DeckData>(DeckDatasPlayerPrefsKey);
  451. LoadDeckLists();
  452. GetComponent<StarterDeck>().SetStarterDecks();
  453. // player data
  454. LoadPlayerName();
  455. LoadWinCount();
  456. // game play
  457. LoadAutoEffectOrder();
  458. LoadAutoDeckBottomOrder();
  459. LoadAutoDeckTopOrder();
  460. LoadAutoMinDigivolutionCost();
  461. LoadAutoMaxCardCount();
  462. LoadAutoHatch();
  463. LoadShowCutInAnimation();
  464. LoadReverseOpponentsCards();
  465. LoadTurnSuspendedCards();
  466. LoadCheckBeforeEndingSelection();
  467. LoadSuspendedCardsDirectionIsLeft();
  468. //Graphics
  469. LoadShowBackgroundParticle();
  470. // Sound
  471. LoadVolume();
  472. // ServerRegion
  473. LoadServerRegion();
  474. // Language
  475. LoadLanguage();
  476. await CreateTokenData();
  477. DontDestroyOnLoad(gameObject);
  478. }
  479. [Obsolete("This is obsolete, switching to save files")]
  480. public void ModifyAllDeckDatas()
  481. {
  482. List<DeckData> tempDeckDatas = new List<DeckData>();
  483. foreach (DeckData deckData in DeckDatas)
  484. {
  485. tempDeckDatas.Add(deckData);
  486. }
  487. foreach (DeckData deckData in tempDeckDatas)
  488. {
  489. if (deckData.AllDeckCards().Count == 0)
  490. {
  491. DeckDatas.Remove(deckData);
  492. }
  493. }
  494. for (int i = 0; i < DeckDatas.Count; i++)
  495. {
  496. //DeckData deckData = new DeckData(DeckData.GetDeckCode(DeckDatas[i].DeckName, DeckData.SortedDeckCardsList(DeckDatas[i].DeckCards()), DeckData.SortedDeckCardsList(DeckDatas[i].DigitamaDeckCards()), DeckDatas[i].KeyCard));
  497. DeckData deckData = DeckDatas[i];
  498. DeckDatas[i] = deckData.ModifiedDeckData();
  499. }
  500. SaveDeckDatas();
  501. }
  502. [Obsolete("This is obsolete, switching to save files")]
  503. public void SaveDeckDatas()
  504. {
  505. PlayerPrefsUtil.SaveList(DeckDatasPlayerPrefsKey, DeckDatas);
  506. PlayerPrefs.Save();
  507. }
  508. public void SaveDeckData(DeckData data)
  509. {
  510. string savePath = StreamingAssetsUtility.GetStreamingAssetPath("Decks", false);
  511. File.WriteAllText($"{savePath}/{data.DeckName}_{data.DeckID}.txt", DeckCodeUtility.GetDeckBuilderFile(data));
  512. }
  513. public void RenameDeck(DeckData data, string newName)
  514. {
  515. string savePath = StreamingAssetsUtility.GetStreamingAssetPath("Decks", false);
  516. if (File.Exists($"{savePath}/{data.DeckName}_{data.DeckID}.txt"))
  517. {
  518. File.Move($"{savePath}/{data.DeckName}_{data.DeckID}.txt", $"{savePath}/{newName}_{data.DeckID}.txt");
  519. data.DeckName = newName;
  520. SaveDeckData(data);
  521. }
  522. else
  523. data.DeckName = newName;
  524. }
  525. public void DeleteDeck(DeckData data)
  526. {
  527. string filePath = StreamingAssetsUtility.GetStreamingAssetPath("Decks", false);
  528. if (!Directory.Exists(filePath))
  529. return;
  530. if (!File.Exists($"{filePath}/{data.DeckName}_{data.DeckID}.txt"))
  531. return;
  532. File.Delete($"{filePath}/{data.DeckName}_{data.DeckID}.txt");
  533. }
  534. public void DeleteAllDecks()
  535. {
  536. foreach(DeckData data in DeckDatas)
  537. {
  538. DeleteDeck(data);
  539. }
  540. }
  541. public void LoadDeckLists()
  542. {
  543. string loadPath = StreamingAssetsUtility.GetStreamingAssetPath("Decks", false);
  544. if (!Directory.Exists(loadPath))
  545. return;
  546. string[] deckLists = Directory.GetFiles(loadPath);
  547. foreach(string deckPath in deckLists)
  548. {
  549. string fileName = Path.GetFileNameWithoutExtension(deckPath);
  550. if (!fileName.Contains("_"))
  551. continue;
  552. string deckList = File.ReadAllText(deckPath);
  553. StreamReader sr = new StreamReader(deckPath);
  554. string deckName = sr.ReadLine().Replace("Name: ", "");
  555. int KeyCard = int.Parse(sr.ReadLine().Replace("Key Card: ", ""));
  556. int SortValue = int.Parse(sr.ReadLine().Replace("Sort Index: ", ""));
  557. sr.Close();
  558. string deck = deckList.Substring(deckList.IndexOf("//"));
  559. //Debug.Log(deckName);
  560. if(SortValue < 0)
  561. SortValue = 0;
  562. CreateDeckFromFile(fileName.Split("_")[1], deckName, KeyCard, deck, SortValue);
  563. }
  564. DeckDatas = DeckDatas.OrderBy(x => x.DeckName).ToList();
  565. }
  566. private void CreateDeckFromFile(string id, string name, int keyID, string deckCode, int index = 0)
  567. {
  568. List<CEntity_Base> AllDeckCards = DeckCodeUtility.GetAllDeckCardsFromDeckBuilderDeckCode(deckCode);
  569. if (AllDeckCards.Count == 0)
  570. {
  571. AllDeckCards = DeckCodeUtility.GetAllDeckCardsFromTTSDeckCode(deckCode);
  572. }
  573. List<CEntity_Base> deckCards = new List<CEntity_Base>();
  574. List<CEntity_Base> digitamaDeckCards = new List<CEntity_Base>();
  575. foreach (CEntity_Base cEntity_Base in AllDeckCards)
  576. {
  577. if (cEntity_Base.cardKind.Contains(CardKind.DigiEgg))
  578. {
  579. digitamaDeckCards.Add(cEntity_Base);
  580. }
  581. else
  582. {
  583. deckCards.Add(cEntity_Base);
  584. }
  585. }
  586. Debug.Log($"Create Deck From File: {name}");
  587. DeckData deckData = (new DeckData(DeckData.GetDeckCode(name, deckCards, digitamaDeckCards, null),id)).ModifiedDeckData();
  588. deckData.KeyCardId = keyID;
  589. deckData.DeckName = name;
  590. deckData.SortValue = index;
  591. DeckDatas.Insert(index, deckData);
  592. }
  593. #region Player Name
  594. string _playerName;
  595. string _playerNameKey = "PlayerName";
  596. public string PlayerName
  597. {
  598. get
  599. {
  600. if (string.IsNullOrEmpty(_playerName))
  601. {
  602. return "Player";
  603. }
  604. return _playerName;
  605. }
  606. set
  607. {
  608. _playerName = DeckData.ValidateDeckName(value);
  609. }
  610. }
  611. public void SavePlayerName(string playerName)
  612. {
  613. PlayerName = playerName;
  614. PlayerPrefs.SetString(_playerNameKey, playerName);
  615. PlayerPrefs.Save();
  616. }
  617. public void LoadPlayerName()
  618. {
  619. if (PlayerPrefs.HasKey(_playerNameKey))
  620. {
  621. PlayerName = PlayerPrefs.GetString(_playerNameKey);
  622. }
  623. if (string.IsNullOrEmpty(PlayerName))
  624. {
  625. PlayerName = "Player";
  626. }
  627. }
  628. #endregion
  629. #region number of victories
  630. public int WinCount { get; set; }
  631. string _winCountKey = "WinCount";
  632. public void SaveWinCount()
  633. {
  634. PlayerPrefs.SetInt(_winCountKey, WinCount);
  635. PlayerPrefs.Save();
  636. }
  637. public void LoadWinCount()
  638. {
  639. if (PlayerPrefs.HasKey(_winCountKey))
  640. {
  641. WinCount = PlayerPrefs.GetInt(_winCountKey);
  642. }
  643. }
  644. #endregion
  645. #region Auto effect order
  646. [HideInInspector] public bool autoEffectOrder = false;
  647. string _autoEffectOrderKey = "AutoEffectOrder";
  648. public void SaveAutoEffectOrder()
  649. {
  650. PlayerPrefsUtil.SetBool(_autoEffectOrderKey, autoEffectOrder);
  651. PlayerPrefs.Save();
  652. }
  653. public void LoadAutoEffectOrder()
  654. {
  655. autoEffectOrder = PlayerPrefsUtil.GetBool(_autoEffectOrderKey, false);
  656. }
  657. #endregion
  658. #region Auto deck bottom order
  659. [HideInInspector] public bool autoDeckBottomOrder = false;
  660. string _autoDeckBottomOrderKey = "AutoDeckBottomOrder";
  661. public void SaveAutoDeckBottomOrder()
  662. {
  663. PlayerPrefsUtil.SetBool(_autoDeckBottomOrderKey, autoDeckBottomOrder);
  664. PlayerPrefs.Save();
  665. }
  666. public void LoadAutoDeckBottomOrder()
  667. {
  668. autoDeckBottomOrder = PlayerPrefsUtil.GetBool(_autoDeckBottomOrderKey, false);
  669. }
  670. #endregion
  671. #region Auto deck top order
  672. [HideInInspector] public bool autoDeckTopOrder = false;
  673. string _autoDeckTopOrderKey = "AutoDeckTopOrder";
  674. public void SaveAutoDeckTopOrder()
  675. {
  676. PlayerPrefsUtil.SetBool(_autoDeckTopOrderKey, autoDeckTopOrder);
  677. PlayerPrefs.Save();
  678. }
  679. public void LoadAutoDeckTopOrder()
  680. {
  681. autoDeckTopOrder = PlayerPrefsUtil.GetBool(_autoDeckTopOrderKey, false);
  682. }
  683. #endregion
  684. #region Auto min digivolution cost
  685. [HideInInspector] public bool autoMinDigivolutionCost = false;
  686. string _autoMinDigivolutionCostKey = "AutoMinDigivolutionCost";
  687. public void SaveAutoMinDigivolutionCost()
  688. {
  689. PlayerPrefsUtil.SetBool(_autoMinDigivolutionCostKey, autoMinDigivolutionCost);
  690. PlayerPrefs.Save();
  691. }
  692. public void LoadAutoMinDigivolutionCost()
  693. {
  694. autoMinDigivolutionCost = PlayerPrefsUtil.GetBool(_autoMinDigivolutionCostKey, false);
  695. }
  696. #endregion
  697. #region Auto max card count
  698. [HideInInspector] public bool autoMaxCardCount = false;
  699. string _autoMaxCardCountKey = "AutoMaxCardCount";
  700. public void SaveAutoMaxCardCount()
  701. {
  702. PlayerPrefsUtil.SetBool(_autoMaxCardCountKey, autoMaxCardCount);
  703. PlayerPrefs.Save();
  704. }
  705. public void LoadAutoMaxCardCount()
  706. {
  707. autoMaxCardCount = PlayerPrefsUtil.GetBool(_autoMaxCardCountKey, false);
  708. }
  709. #endregion
  710. #region Auto hatch
  711. [HideInInspector] public bool autoHatch = false;
  712. string _autoHatchKey = "AutoHatch";
  713. public void SaveAutoHatch()
  714. {
  715. PlayerPrefsUtil.SetBool(_autoHatchKey, autoHatch);
  716. PlayerPrefs.Save();
  717. }
  718. public void LoadAutoHatch()
  719. {
  720. autoHatch = PlayerPrefsUtil.GetBool(_autoHatchKey, false);
  721. }
  722. #endregion
  723. #region Show CutIn Animation
  724. [HideInInspector] public bool showCutInAnimation = false;
  725. string _showCutInAnimationKey = "ShowCutInAnimation";
  726. public void SaveShowCutInAnimation()
  727. {
  728. PlayerPrefsUtil.SetBool(_showCutInAnimationKey, showCutInAnimation);
  729. PlayerPrefs.Save();
  730. }
  731. public void LoadShowCutInAnimation()
  732. {
  733. //TODO: Setting default to false, to fix animation syncing bug, MB
  734. showCutInAnimation = false;
  735. //showCutInAnimation = PlayerPrefsUtil.GetBool(_showCutInAnimationKey, true);
  736. }
  737. #endregion
  738. #region Reverse opponents' cards
  739. [HideInInspector] public bool reverseOpponentsCards = false;
  740. string _reverseOpponentsCardsKey = "ReverseOpponentsCards";
  741. public void SaveReverseOpponentsCards()
  742. {
  743. PlayerPrefsUtil.SetBool(_reverseOpponentsCardsKey, reverseOpponentsCards);
  744. PlayerPrefs.Save();
  745. }
  746. public void LoadReverseOpponentsCards()
  747. {
  748. reverseOpponentsCards = PlayerPrefsUtil.GetBool(_reverseOpponentsCardsKey, false);
  749. }
  750. #endregion
  751. #region Turn suspended cards
  752. [HideInInspector] public bool turnSuspendedCards = false;
  753. string _turnSuspendedCardsKey = "TurnSuspendedCards";
  754. public void SaveTurnSuspendedCards()
  755. {
  756. PlayerPrefsUtil.SetBool(_turnSuspendedCardsKey, turnSuspendedCards);
  757. PlayerPrefs.Save();
  758. }
  759. public void LoadTurnSuspendedCards()
  760. {
  761. turnSuspendedCards = PlayerPrefsUtil.GetBool(_turnSuspendedCardsKey, true);
  762. }
  763. #endregion
  764. #region Check before ending selection
  765. [HideInInspector] public bool checkBeforeEndingSelection = false;
  766. string _checkBeforeEndingSelectionKey = "CheckBeforeEndingSelection";
  767. public void SaveCheckBeforeEndingSelection()
  768. {
  769. PlayerPrefsUtil.SetBool(_checkBeforeEndingSelectionKey, checkBeforeEndingSelection);
  770. PlayerPrefs.Save();
  771. }
  772. public void LoadCheckBeforeEndingSelection()
  773. {
  774. checkBeforeEndingSelection = PlayerPrefsUtil.GetBool(_checkBeforeEndingSelectionKey, true);
  775. }
  776. #endregion
  777. #region Suspended cards' direction is left
  778. [HideInInspector] public bool suspendedCardsDirectionIsLeft = false;
  779. string _suspendedCardsDirectionIsLeftKey = "SuspendedCardsDirectionIsLeft";
  780. public void SaveSuspendedCardsDirectionIsLeft()
  781. {
  782. PlayerPrefsUtil.SetBool(_suspendedCardsDirectionIsLeftKey, suspendedCardsDirectionIsLeft);
  783. PlayerPrefs.Save();
  784. }
  785. public void LoadSuspendedCardsDirectionIsLeft()
  786. {
  787. suspendedCardsDirectionIsLeft = PlayerPrefsUtil.GetBool(_suspendedCardsDirectionIsLeftKey, true);
  788. }
  789. #endregion
  790. #region Show background particle
  791. [HideInInspector] public bool showBackgroundParticle = false;
  792. string _showBackgroundParticleKey = "ShowBackgroundParticle";
  793. public void SaveShowBackgroundParticle()
  794. {
  795. PlayerPrefsUtil.SetBool(_showBackgroundParticleKey, showBackgroundParticle);
  796. PlayerPrefs.Save();
  797. }
  798. public void LoadShowBackgroundParticle()
  799. {
  800. showBackgroundParticle = PlayerPrefsUtil.GetBool(_showBackgroundParticleKey, true);
  801. }
  802. #endregion
  803. #region Sound volume
  804. public float BGMVolume { get; set; }
  805. public float SEVolume { get; set; }
  806. public void SetBGMVolume(float BGMVolume)
  807. {
  808. this.BGMVolume = BGMVolume;
  809. PlayerPrefs.SetFloat("BGMVolume", BGMVolume);
  810. PlayerPrefs.Save();
  811. }
  812. public void SetSEVolume(float SEVolume)
  813. {
  814. this.SEVolume = SEVolume;
  815. PlayerPrefs.SetFloat("SEVolume", SEVolume);
  816. PlayerPrefs.Save();
  817. }
  818. public void ChangeBGMVolume(AudioSource audioSource)
  819. {
  820. audioSource.volume = BGMVolume * 0.25f * 0.8f;
  821. }
  822. public void ChangeSEVolume(AudioSource audioSource)
  823. {
  824. audioSource.volume = SEVolume * 0.5f * 0.8f;
  825. }
  826. void LoadVolume()
  827. {
  828. BGMVolume = 0.5f;
  829. SEVolume = 0.5f;
  830. if (PlayerPrefs.HasKey("BGMVolume"))
  831. {
  832. BGMVolume = PlayerPrefs.GetFloat("BGMVolume");
  833. }
  834. if (PlayerPrefs.HasKey("SEVolume"))
  835. {
  836. SEVolume = PlayerPrefs.GetFloat("SEVolume");
  837. }
  838. }
  839. #endregion
  840. #region Server region
  841. [HideInInspector] public string serverRegion = "us";
  842. string _serverRegionKey = "ServerRegion";
  843. public void SaveServerRegion()
  844. {
  845. PlayerPrefs.SetString(_serverRegionKey, serverRegion);
  846. PlayerPrefs.Save();
  847. }
  848. public void LoadServerRegion()
  849. {
  850. //serverRegion = PlayerPrefs.GetString(_serverRegionKey, "us");
  851. }
  852. public string LastConnectServerRegion = "";
  853. #endregion
  854. #region Language
  855. [HideInInspector] public Language language = Language.ENG;
  856. string _languageKey = "Language";
  857. public void SaveLanguage()
  858. {
  859. PlayerPrefs.SetString(_languageKey, language.ToString());
  860. PlayerPrefs.Save();
  861. }
  862. public void LoadLanguage()
  863. {
  864. language = (Language)Enum.Parse(typeof(Language), PlayerPrefs.GetString(_languageKey, "ENG"));
  865. }
  866. #endregion
  867. #region PlaySE(AudioClip clip)
  868. public SoundObject PlaySE(AudioClip clip)
  869. {
  870. SoundObject _soundObject = Instantiate(soundObject);
  871. _soundObject.PlaySE(clip);
  872. return _soundObject;
  873. }
  874. #endregion
  875. #region カードIndexからカードを取得
  876. public CEntity_Base getCardEntityByCardID(int cardIndex)
  877. {
  878. //int searchIndex = cardIndex - 1;
  879. //int count = 0;
  880. CEntity_Base cEntity_Base = SortedCardList.First(entity => entity.CardIndex == cardIndex);
  881. return cEntity_Base;
  882. //TODO: REMOVE IN FUTURE
  883. /*do
  884. {
  885. if (count != 0)
  886. {
  887. searchIndex += (int)Math.Pow(-1, count % 2) * count / 2;
  888. }
  889. if (0 <= searchIndex)
  890. {
  891. if (searchIndex <= SortedCardList.Length - 1)
  892. {
  893. CEntity_Base cEntity_Base = SortedCardList[searchIndex];
  894. if (cEntity_Base != null)
  895. {
  896. if (cEntity_Base.CardIndex == cardIndex)
  897. {
  898. return cEntity_Base;
  899. }
  900. }
  901. }
  902. else
  903. {
  904. for (int i = 0; i < 300; i++)
  905. {
  906. CEntity_Base cEntity_Base = SortedCardList[SortedCardList.Length - 1 - i];
  907. if (cEntity_Base != null)
  908. {
  909. if (cEntity_Base.CardIndex == cardIndex)
  910. {
  911. return cEntity_Base;
  912. }
  913. }
  914. }
  915. return null;
  916. }
  917. }
  918. if (count != 0)
  919. {
  920. searchIndex -= (int)Math.Pow(-1, count % 2) * count / 2;
  921. }
  922. count++;
  923. }
  924. while (count <= 20);
  925. return null;*/
  926. }
  927. #endregion
  928. public Coroutine LoadingTextCoroutine;
  929. bool _endBattle = false;
  930. public void EndBattle()
  931. {
  932. if (!_endBattle)
  933. {
  934. _endBattle = true;
  935. StartCoroutine(EndBattleCoroutine());
  936. }
  937. }
  938. public IEnumerator EndBattleCoroutine()
  939. {
  940. if (Opening.instance == null)
  941. {
  942. yield break;
  943. }
  944. Opening.instance.openingObject.SetActive(true);
  945. //yield return StartCoroutine(Opening.instance.LoadingObject_Unload.StartLoading("Now Loading"));
  946. //Camera camera1 = Camera.main;
  947. //Destroy(camera1.gameObject);
  948. //yield return null;
  949. isAI = false;
  950. int random = RandomUtility.getRamdom();
  951. UnityEngine.Random.InitState(random);
  952. Debug.Log($"random number sequence initialization, InitState:{random}");
  953. var unload = SceneManager.UnloadSceneAsync("BattleScene");
  954. yield return unload;
  955. yield return Resources.UnloadUnusedAssets();
  956. yield return StartCoroutine(Opening.instance.LoadingObject_Unload.StartLoading("Now Loading"));
  957. //Opening.instance.MainCamera.gameObject.SetActive(true);
  958. foreach (Camera camera in Opening.instance.openingCameras)
  959. {
  960. camera.gameObject.SetActive(true);
  961. }
  962. Opening.instance.LoadingObject_light.gameObject.SetActive(false);
  963. yield return ContinuousController.instance.StartCoroutine(PhotonUtility.SetPlayerName());
  964. if (isRandomMatch)
  965. {
  966. Debug.Log("Unload from Random Match");
  967. yield return StartCoroutine(Opening.instance.battle.lobbyManager_RandomMatch.CloseLobbyCoroutine());
  968. yield return StartCoroutine(Opening.instance.battle.selectBattleMode.SetUpSelectBattleModeCoroutine());
  969. }
  970. else
  971. {
  972. Debug.Log("Unload from Room Match");
  973. yield return StartCoroutine(Opening.instance.battle.roomManager.Init(true));
  974. yield return new WaitForSeconds(0.1f);
  975. }
  976. yield return new WaitWhile(() => GManager.instance != null);
  977. Opening.instance.LoadingObject.gameObject.SetActive(false);
  978. yield return StartCoroutine(Opening.instance.LoadingObject_Unload.EndLoading());
  979. _endBattle = false;
  980. if (!isRandomMatch)
  981. {
  982. Hashtable PlayerProp = PhotonNetwork.LocalPlayer.CustomProperties;
  983. if (PlayerProp.TryGetValue("isBattle", out object value))
  984. {
  985. PlayerProp["isBattle"] = false;
  986. }
  987. else
  988. {
  989. PlayerProp.Add("isBattle", false);
  990. }
  991. PhotonNetwork.LocalPlayer.SetCustomProperties(PlayerProp);
  992. }
  993. Scene newScene = SceneManager.GetSceneByName("Opening");
  994. SceneManager.SetActiveScene(newScene);
  995. for (int i = 0; i < 3; i++)
  996. {
  997. yield return new WaitForSeconds(0.1f);
  998. EventSystem.current.SetSelectedGameObject(Opening.instance.battle.selectBattleMode.transform.GetChild(0).gameObject);
  999. }
  1000. //GUI.UnfocusWindow();
  1001. yield return null;
  1002. //StartCoroutine(DestroyEffectCoroutine());
  1003. if (Opening.instance.OpeningBGM != null)
  1004. {
  1005. if (!Opening.instance.OpeningBGM.isPlaying)
  1006. {
  1007. Opening.instance.OpeningBGM.StartPlayBGM(Opening.instance.bgm);
  1008. }
  1009. }
  1010. }
  1011. private void Update()
  1012. {
  1013. #if UNITY_WINDOWS
  1014. if (Input.GetKey(KeyCode.Escape))
  1015. {
  1016. Application.Quit();
  1017. }
  1018. #endif
  1019. }
  1020. int _frameCount = 0;
  1021. int _updateFrame = 40;
  1022. void LateUpdate()
  1023. {
  1024. #region Update only once every few frames
  1025. _frameCount++;
  1026. if (_frameCount < _updateFrame)
  1027. {
  1028. return;
  1029. }
  1030. else
  1031. {
  1032. _frameCount = 0;
  1033. }
  1034. #endregion
  1035. if (PhotonNetwork.InRoom)
  1036. {
  1037. if (!isAI)
  1038. {
  1039. bool notEnterOther = false;
  1040. if (PhotonNetwork.PlayerList.Length == 1)
  1041. {
  1042. if (GManager.instance != null)
  1043. {
  1044. notEnterOther = true;
  1045. }
  1046. }
  1047. if (notEnterOther)
  1048. {
  1049. if (PhotonNetwork.CurrentRoom.MaxPlayers != 1)
  1050. {
  1051. PhotonNetwork.CurrentRoom.MaxPlayers = 1;
  1052. }
  1053. }
  1054. else
  1055. {
  1056. if (PhotonNetwork.CurrentRoom.MaxPlayers != 2)
  1057. {
  1058. PhotonNetwork.CurrentRoom.MaxPlayers = 2;
  1059. }
  1060. }
  1061. }
  1062. }
  1063. }
  1064. public bool isAI { get; set; } = false;
  1065. //Flag that the sharing of the random number sequence is over.
  1066. public bool DoneSetRandom { get; set; } = false;
  1067. public bool CanSetRandom { get; set; } = false;
  1068. [PunRPC]
  1069. public void SetRandom(int random)
  1070. {
  1071. StartCoroutine(SetRandomCoroutine(random));
  1072. }
  1073. IEnumerator SetRandomCoroutine(int random)
  1074. {
  1075. yield return new WaitWhile(() => !CanSetRandom);
  1076. UnityEngine.Random.InitState(random);
  1077. DoneSetRandom = true;
  1078. Debug.Log($"random number sequence initialization,InitState:{random}");
  1079. }
  1080. }
  1081. #region Manage random numbers
  1082. public static class RandomUtility
  1083. {
  1084. private static System.Random random;
  1085. public static int getRamdom()
  1086. {
  1087. int _max = 1500000000;
  1088. if (random == null)
  1089. {
  1090. random = new System.Random((int)DateTime.Now.Ticks);
  1091. }
  1092. return random.Next(0, _max);
  1093. }
  1094. #region IsSucceedProbability(float Probability)
  1095. public static bool IsSucceedProbability(float Probability)
  1096. {
  1097. if (Probability >= 1)
  1098. {
  1099. return true;
  1100. }
  1101. if (Probability <= 0)
  1102. {
  1103. return false;
  1104. }
  1105. float random = UnityEngine.Random.Range(0f, 1f);
  1106. if (random <= Probability)
  1107. {
  1108. return true;
  1109. }
  1110. return false;
  1111. }
  1112. #endregion
  1113. #region Shuffle the deck
  1114. public static List<CEntity_Base> ShuffledDeckCards(List<CEntity_Base> DeckCards)
  1115. {
  1116. List<CEntity_Base> CardDatas = new List<CEntity_Base>();
  1117. CardDatas.AddRange(DeckCards);
  1118. // The initial value of the integer n is the number of cards in the deck
  1119. int n = CardDatas.Count;
  1120. while (n > 0)
  1121. {
  1122. n--;
  1123. // Random index from 0 to i (inclusive)
  1124. int k = UnityEngine.Random.Range(0, n + 1);
  1125. // Swap elements at indices i and k
  1126. CEntity_Base temp = CardDatas[n];
  1127. CardDatas[n] = CardDatas[k];
  1128. CardDatas[k] = temp;
  1129. }
  1130. return CardDatas;
  1131. }
  1132. public static List<CardSource> ShuffledDeckCards(List<CardSource> DeckCards)
  1133. {
  1134. List<CardSource> CardDatas = new List<CardSource>();
  1135. CardDatas.AddRange(DeckCards);
  1136. // The initial value of the integer n is the number of cards in the deck
  1137. int n = CardDatas.Count;
  1138. while (n > 0)
  1139. {
  1140. n--;
  1141. // Random index from 0 to i (inclusive)
  1142. int k = UnityEngine.Random.Range(0, n + 1);
  1143. // Swap elements at indices i and k
  1144. CardSource temp = CardDatas[n];
  1145. if (!temp.IsFlipped)
  1146. {
  1147. temp.SetReverse();
  1148. if(temp.Owner.SecurityCards.Contains(temp))
  1149. GManager.OnSecurityStackChanged?.Invoke(temp.Owner);
  1150. }
  1151. CardDatas[n] = CardDatas[k];
  1152. CardDatas[k] = temp;
  1153. }
  1154. return CardDatas;
  1155. }
  1156. #endregion
  1157. }
  1158. #endregion
  1159. #region Manage connections to Photon
  1160. public class PhotonUtility
  1161. {
  1162. #region Disconnected from Photon
  1163. public static IEnumerator DisconnectCoroutine()
  1164. {
  1165. #region Exit Room
  1166. if (PhotonNetwork.InRoom)
  1167. {
  1168. PhotonNetwork.LeaveRoom();
  1169. }
  1170. yield return new WaitWhile(() => PhotonNetwork.InRoom);
  1171. #endregion
  1172. #region Exit from the lobby
  1173. if (PhotonNetwork.InLobby)
  1174. {
  1175. PhotonNetwork.LeaveLobby();
  1176. }
  1177. yield return new WaitWhile(() => PhotonNetwork.InLobby);
  1178. #endregion
  1179. #region Disconnected from Photon
  1180. if (PhotonNetwork.IsConnected)
  1181. {
  1182. PhotonNetwork.Disconnect();
  1183. }
  1184. yield return new WaitWhile(() => PhotonNetwork.IsConnected);
  1185. #endregion
  1186. }
  1187. #endregion
  1188. #region Connect to Photon server
  1189. public static IEnumerator ConnectToMasterServerCoroutine()
  1190. {
  1191. if (!PhotonNetwork.IsConnected || ContinuousController.instance.LastConnectServerRegion != ContinuousController.instance.serverRegion)
  1192. {
  1193. if (PhotonNetwork.IsConnected)
  1194. {
  1195. yield return ContinuousController.instance.StartCoroutine(DisconnectCoroutine());
  1196. yield return new WaitWhile(() => PhotonNetwork.IsConnected);
  1197. }
  1198. PhotonNetwork.NetworkingClient.AppId = PhotonNetwork.PhotonServerSettings.AppSettings.AppIdRealtime;
  1199. PhotonNetwork.ConnectToRegion(ContinuousController.instance.serverRegion);
  1200. PhotonNetwork.NickName = ContinuousController.instance.PlayerName;
  1201. PhotonNetwork.GameVersion = ContinuousController.instance.GameVerString;
  1202. ContinuousController.instance.LastConnectServerRegion = ContinuousController.instance.serverRegion;
  1203. }
  1204. yield return new WaitWhile(() => !PhotonNetwork.IsConnectedAndReady);
  1205. }
  1206. #endregion
  1207. #region Connect to Photon Server and Lobby
  1208. public static IEnumerator ConnectToLobbyCoroutine()
  1209. {
  1210. #region Connect to Photon server
  1211. yield return ContinuousController.instance.StartCoroutine(ConnectToMasterServerCoroutine());
  1212. #endregion
  1213. #region Save player name to custom properties
  1214. yield return ContinuousController.instance.StartCoroutine(SetPlayerName());
  1215. #endregion
  1216. #region Save the number of wins to a custom property
  1217. Hashtable hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1218. object value;
  1219. hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1220. if (hash.TryGetValue(ContinuousController.WinCountKey, out value))
  1221. {
  1222. hash[ContinuousController.WinCountKey] = ContinuousController.instance.WinCount;
  1223. }
  1224. else
  1225. {
  1226. hash.Add(ContinuousController.WinCountKey, ContinuousController.instance.WinCount);
  1227. }
  1228. PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
  1229. while (true)
  1230. {
  1231. Hashtable _hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1232. if (_hash.TryGetValue(ContinuousController.WinCountKey, out value))
  1233. {
  1234. if ((int)value == ContinuousController.instance.WinCount)
  1235. {
  1236. break;
  1237. }
  1238. }
  1239. yield return null;
  1240. }
  1241. #endregion
  1242. #region Connect to Lobby
  1243. if (!PhotonNetwork.InLobby)
  1244. {
  1245. PhotonNetwork.JoinLobby();
  1246. }
  1247. yield return new WaitWhile(() => !PhotonNetwork.InLobby);
  1248. yield return new WaitUntil(() => PhotonNetwork.InLobby && PhotonNetwork.IsConnectedAndReady);
  1249. #endregion
  1250. }
  1251. #endregion
  1252. #region Save player name to properties
  1253. public static IEnumerator SetPlayerName()
  1254. {
  1255. Hashtable hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1256. object value;
  1257. hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1258. if (hash.TryGetValue(ContinuousController.PlayerNameKey, out value))
  1259. {
  1260. hash[ContinuousController.PlayerNameKey] = ContinuousController.instance.PlayerName;
  1261. }
  1262. else
  1263. {
  1264. hash.Add(ContinuousController.PlayerNameKey, ContinuousController.instance.PlayerName);
  1265. }
  1266. PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
  1267. while (true)
  1268. {
  1269. Hashtable _hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1270. if (_hash.TryGetValue(ContinuousController.PlayerNameKey, out value))
  1271. {
  1272. if ((string)value == ContinuousController.instance.PlayerName)
  1273. {
  1274. break;
  1275. }
  1276. }
  1277. yield return null;
  1278. }
  1279. }
  1280. #endregion
  1281. #region Save deck data to custom properties
  1282. public static IEnumerator SignUpBattleDeckData()
  1283. {
  1284. Hashtable hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1285. if (hash.TryGetValue(ContinuousController.DeckDataPropertyKey, out object value))
  1286. {
  1287. hash[ContinuousController.DeckDataPropertyKey] = ContinuousController.instance.BattleDeckData.GetThisDeckCode();
  1288. }
  1289. else
  1290. {
  1291. hash.Add(ContinuousController.DeckDataPropertyKey, ContinuousController.instance.BattleDeckData.GetThisDeckCode());
  1292. }
  1293. PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
  1294. while (true)
  1295. {
  1296. Hashtable _hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1297. if (_hash.TryGetValue(ContinuousController.DeckDataPropertyKey, out value))
  1298. {
  1299. if ((string)value == ContinuousController.instance.BattleDeckData.GetThisDeckCode())
  1300. {
  1301. break;
  1302. }
  1303. }
  1304. yield return null;
  1305. }
  1306. }
  1307. #endregion
  1308. #region Remove custom properties from deck data
  1309. public static IEnumerator DeleteBattleDeckData()
  1310. {
  1311. Hashtable hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1312. if (hash.TryGetValue(ContinuousController.DeckDataPropertyKey, out object value))
  1313. {
  1314. hash.Remove(ContinuousController.DeckDataPropertyKey);
  1315. }
  1316. PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
  1317. while (true)
  1318. {
  1319. Hashtable _hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1320. if (!_hash.TryGetValue(ContinuousController.DeckDataPropertyKey, out value))
  1321. {
  1322. break;
  1323. }
  1324. yield return null;
  1325. }
  1326. }
  1327. #endregion
  1328. }
  1329. #endregion
  1330. public enum Language
  1331. {
  1332. ENG,
  1333. JPN,
  1334. }