ContinuousController.cs 55 KB

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