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