ContinuousController.cs 56 KB

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