ContinuousController.cs 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665
  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. }
  1050. int _frameCount = 0;
  1051. int _updateFrame = 40;
  1052. void LateUpdate()
  1053. {
  1054. #region Update only once every few frames
  1055. _frameCount++;
  1056. if (_frameCount < _updateFrame)
  1057. {
  1058. return;
  1059. }
  1060. else
  1061. {
  1062. _frameCount = 0;
  1063. }
  1064. #endregion
  1065. if (PhotonNetwork.InRoom)
  1066. {
  1067. if (!isAI)
  1068. {
  1069. bool notEnterOther = false;
  1070. if (PhotonNetwork.PlayerList.Length == 1)
  1071. {
  1072. if (GManager.instance != null)
  1073. {
  1074. notEnterOther = true;
  1075. }
  1076. }
  1077. if (notEnterOther)
  1078. {
  1079. if (PhotonNetwork.CurrentRoom.MaxPlayers != 1)
  1080. {
  1081. PhotonNetwork.CurrentRoom.MaxPlayers = 1;
  1082. }
  1083. }
  1084. else
  1085. {
  1086. if (PhotonNetwork.CurrentRoom.MaxPlayers != 2)
  1087. {
  1088. PhotonNetwork.CurrentRoom.MaxPlayers = 2;
  1089. }
  1090. }
  1091. }
  1092. }
  1093. }
  1094. public bool isAI { get; set; } = false;
  1095. //Flag that the sharing of the random number sequence is over.
  1096. public bool DoneSetRandom { get; set; } = false;
  1097. public bool CanSetRandom { get; set; } = false;
  1098. [PunRPC]
  1099. public void SetRandom(int random)
  1100. {
  1101. StartCoroutine(SetRandomCoroutine(random));
  1102. }
  1103. IEnumerator SetRandomCoroutine(int random)
  1104. {
  1105. yield return new WaitWhile(() => !CanSetRandom);
  1106. UnityEngine.Random.InitState(random);
  1107. DoneSetRandom = true;
  1108. Debug.Log($"random number sequence initialization,InitState:{random}");
  1109. }
  1110. }
  1111. #region Manage random numbers
  1112. public static class RandomUtility
  1113. {
  1114. private static System.Random random;
  1115. public static int getRamdom()
  1116. {
  1117. int _max = 1500000000;
  1118. if (random == null)
  1119. {
  1120. random = new System.Random((int)DateTime.Now.Ticks);
  1121. }
  1122. return random.Next(0, _max);
  1123. }
  1124. #region IsSucceedProbability(float Probability)
  1125. public static bool IsSucceedProbability(float Probability)
  1126. {
  1127. if (Probability >= 1)
  1128. {
  1129. return true;
  1130. }
  1131. if (Probability <= 0)
  1132. {
  1133. return false;
  1134. }
  1135. float random = UnityEngine.Random.Range(0f, 1f);
  1136. if (random <= Probability)
  1137. {
  1138. return true;
  1139. }
  1140. return false;
  1141. }
  1142. #endregion
  1143. #region Shuffle the deck
  1144. public static List<CEntity_Base> ShuffledDeckCards(List<CEntity_Base> DeckCards)
  1145. {
  1146. List<CEntity_Base> CardDatas = new List<CEntity_Base>();
  1147. CardDatas.AddRange(DeckCards);
  1148. // The initial value of the integer n is the number of cards in the deck
  1149. int n = CardDatas.Count;
  1150. while (n > 0)
  1151. {
  1152. n--;
  1153. // Random index from 0 to i (inclusive)
  1154. int k = UnityEngine.Random.Range(0, n + 1);
  1155. // Swap elements at indices i and k
  1156. CEntity_Base temp = CardDatas[n];
  1157. CardDatas[n] = CardDatas[k];
  1158. CardDatas[k] = temp;
  1159. }
  1160. return CardDatas;
  1161. }
  1162. public static List<CardSource> ShuffledDeckCards(List<CardSource> DeckCards)
  1163. {
  1164. List<CardSource> CardDatas = new List<CardSource>();
  1165. CardDatas.AddRange(DeckCards);
  1166. // The initial value of the integer n is the number of cards in the deck
  1167. int n = CardDatas.Count;
  1168. while (n > 0)
  1169. {
  1170. n--;
  1171. // Random index from 0 to i (inclusive)
  1172. int k = UnityEngine.Random.Range(0, n + 1);
  1173. // Swap elements at indices i and k
  1174. CardSource temp = CardDatas[n];
  1175. if (!temp.IsFlipped)
  1176. {
  1177. temp.SetReverse();
  1178. if(temp.Owner.SecurityCards.Contains(temp))
  1179. GManager.OnSecurityStackChanged?.Invoke(temp.Owner);
  1180. }
  1181. CardDatas[n] = CardDatas[k];
  1182. CardDatas[k] = temp;
  1183. }
  1184. return CardDatas;
  1185. }
  1186. #endregion
  1187. }
  1188. #endregion
  1189. #region Manage connections to Photon
  1190. public class PhotonUtility
  1191. {
  1192. #region Disconnected from Photon
  1193. public static IEnumerator DisconnectCoroutine()
  1194. {
  1195. #region Exit Room
  1196. if (PhotonNetwork.InRoom)
  1197. {
  1198. PhotonNetwork.LeaveRoom();
  1199. }
  1200. yield return new WaitWhile(() => PhotonNetwork.InRoom);
  1201. #endregion
  1202. #region Exit from the lobby
  1203. if (PhotonNetwork.InLobby)
  1204. {
  1205. PhotonNetwork.LeaveLobby();
  1206. }
  1207. yield return new WaitWhile(() => PhotonNetwork.InLobby);
  1208. #endregion
  1209. #region Disconnected from Photon
  1210. if (PhotonNetwork.IsConnected)
  1211. {
  1212. PhotonNetwork.Disconnect();
  1213. }
  1214. yield return new WaitWhile(() => PhotonNetwork.IsConnected);
  1215. #endregion
  1216. }
  1217. #endregion
  1218. #region Connect to Photon server
  1219. public static IEnumerator ConnectToMasterServerCoroutine()
  1220. {
  1221. if (!PhotonNetwork.IsConnected || ContinuousController.instance.LastConnectServerRegion != ContinuousController.instance.serverRegion)
  1222. {
  1223. if (PhotonNetwork.IsConnected)
  1224. {
  1225. yield return ContinuousController.instance.StartCoroutine(DisconnectCoroutine());
  1226. yield return new WaitWhile(() => PhotonNetwork.IsConnected);
  1227. }
  1228. PhotonNetwork.NetworkingClient.AppId = PhotonNetwork.PhotonServerSettings.AppSettings.AppIdRealtime;
  1229. PhotonNetwork.ConnectToRegion(ContinuousController.instance.serverRegion);
  1230. PhotonNetwork.NickName = ContinuousController.instance.PlayerName;
  1231. PhotonNetwork.GameVersion = ContinuousController.instance.GameVerString;
  1232. ContinuousController.instance.LastConnectServerRegion = ContinuousController.instance.serverRegion;
  1233. }
  1234. yield return new WaitWhile(() => !PhotonNetwork.IsConnectedAndReady);
  1235. }
  1236. #endregion
  1237. #region Connect to Photon Server and Lobby
  1238. public static IEnumerator ConnectToLobbyCoroutine()
  1239. {
  1240. #region Connect to Photon server
  1241. yield return ContinuousController.instance.StartCoroutine(ConnectToMasterServerCoroutine());
  1242. #endregion
  1243. #region Save player name to custom properties
  1244. yield return ContinuousController.instance.StartCoroutine(SetPlayerName());
  1245. #endregion
  1246. #region Save the number of wins to a custom property
  1247. Hashtable hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1248. object value;
  1249. hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1250. if (hash.TryGetValue(ContinuousController.WinCountKey, out value))
  1251. {
  1252. hash[ContinuousController.WinCountKey] = ContinuousController.instance.WinCount;
  1253. }
  1254. else
  1255. {
  1256. hash.Add(ContinuousController.WinCountKey, ContinuousController.instance.WinCount);
  1257. }
  1258. PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
  1259. while (true)
  1260. {
  1261. Hashtable _hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1262. if (_hash.TryGetValue(ContinuousController.WinCountKey, out value))
  1263. {
  1264. if ((int)value == ContinuousController.instance.WinCount)
  1265. {
  1266. break;
  1267. }
  1268. }
  1269. yield return null;
  1270. }
  1271. #endregion
  1272. #region Connect to Lobby
  1273. if (!PhotonNetwork.InLobby)
  1274. {
  1275. PhotonNetwork.JoinLobby();
  1276. }
  1277. yield return new WaitWhile(() => !PhotonNetwork.InLobby);
  1278. yield return new WaitUntil(() => PhotonNetwork.InLobby && PhotonNetwork.IsConnectedAndReady);
  1279. #endregion
  1280. }
  1281. #endregion
  1282. #region Save player name to properties
  1283. public static IEnumerator SetPlayerName()
  1284. {
  1285. Hashtable hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1286. object value;
  1287. hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1288. if (hash.TryGetValue(ContinuousController.PlayerNameKey, out value))
  1289. {
  1290. hash[ContinuousController.PlayerNameKey] = ContinuousController.instance.PlayerName;
  1291. }
  1292. else
  1293. {
  1294. hash.Add(ContinuousController.PlayerNameKey, ContinuousController.instance.PlayerName);
  1295. }
  1296. PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
  1297. while (true)
  1298. {
  1299. Hashtable _hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1300. if (_hash.TryGetValue(ContinuousController.PlayerNameKey, out value))
  1301. {
  1302. if ((string)value == ContinuousController.instance.PlayerName)
  1303. {
  1304. break;
  1305. }
  1306. }
  1307. yield return null;
  1308. }
  1309. }
  1310. #endregion
  1311. #region Save deck data to custom properties
  1312. public static IEnumerator SignUpBattleDeckData()
  1313. {
  1314. Hashtable hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1315. if (hash.TryGetValue(ContinuousController.DeckDataPropertyKey, out object value))
  1316. {
  1317. hash[ContinuousController.DeckDataPropertyKey] = ContinuousController.instance.BattleDeckData.GetThisDeckCode();
  1318. }
  1319. else
  1320. {
  1321. hash.Add(ContinuousController.DeckDataPropertyKey, ContinuousController.instance.BattleDeckData.GetThisDeckCode());
  1322. }
  1323. PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
  1324. while (true)
  1325. {
  1326. Hashtable _hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1327. if (_hash.TryGetValue(ContinuousController.DeckDataPropertyKey, out value))
  1328. {
  1329. if ((string)value == ContinuousController.instance.BattleDeckData.GetThisDeckCode())
  1330. {
  1331. break;
  1332. }
  1333. }
  1334. yield return null;
  1335. }
  1336. }
  1337. #endregion
  1338. #region Remove custom properties from deck data
  1339. public static IEnumerator DeleteBattleDeckData()
  1340. {
  1341. Hashtable hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1342. if (hash.TryGetValue(ContinuousController.DeckDataPropertyKey, out object value))
  1343. {
  1344. hash.Remove(ContinuousController.DeckDataPropertyKey);
  1345. }
  1346. PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
  1347. while (true)
  1348. {
  1349. Hashtable _hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1350. if (!_hash.TryGetValue(ContinuousController.DeckDataPropertyKey, out value))
  1351. {
  1352. break;
  1353. }
  1354. yield return null;
  1355. }
  1356. }
  1357. #endregion
  1358. }
  1359. #endregion
  1360. public enum Language
  1361. {
  1362. ENG,
  1363. JPN,
  1364. }