ContinuousController.cs 48 KB

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