ContinuousController.cs 54 KB

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