ContinuousController.cs 56 KB

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