ContinuousController.cs 43 KB

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