ContinuousController.cs 56 KB

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