ContinuousController.cs 45 KB

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