ContinuousController.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5. using Photon.Pun;
  6. using System;
  7. using Hashtable = ExitGames.Client.Photon.Hashtable;
  8. using UnityEngine.EventSystems;
  9. using System.Linq;
  10. using System.Threading.Tasks;
  11. using System.Globalization;
  12. public class ContinuousController : MonoBehaviour
  13. {
  14. [Header("game language")]
  15. // public Language language;
  16. [Header("Game version")]
  17. public float GameVer;
  18. [Header("ignore updates")]
  19. public bool IgnoreUpdate;
  20. [Header("card list")]
  21. public CEntity_Base[] CardList = new CEntity_Base[] { };
  22. [Header("Card list sorted by card ID")]
  23. public CEntity_Base[] SortedCardList = new CEntity_Base[] { };
  24. [Header("Card back image")]
  25. public Sprite ReverseCard;
  26. public Sprite ReverseCard_Digitama;
  27. [Header("SE prefab")]
  28. public SoundObject soundObject;
  29. [Header("deck code encryption")]
  30. public ShuffleDeckCode ShuffleDeckCode;
  31. DeckData _battleDeckData = null;
  32. public DeckData BattleDeckData
  33. {
  34. get
  35. {
  36. return _battleDeckData;
  37. }
  38. set
  39. {
  40. _battleDeckData = value;
  41. if (value != null)
  42. {
  43. LastBattleDeckData = value;
  44. }
  45. }
  46. }
  47. public DeckData LastBattleDeckData { get; private set; } = null;
  48. public bool NeedUpdate { get; set; }
  49. public bool isRandomMatch { get; set; }
  50. [HideInInspector] public List<SkillInfo> nullSkillInfos = null;
  51. public String GameVerString => Application.version;//GameVer.ToString(CultureInfo.InvariantCulture);
  52. #region Key for property to save deck data for battle
  53. public static string DeckDataPropertyKey => "BattleDeckData";
  54. #endregion
  55. #region Key for the property that stores the player name data
  56. public static string PlayerNameKey => "PlayerNameKey";
  57. #endregion
  58. #region Key for the property that stores the win count data
  59. public static string WinCountKey => "WinCountKey";
  60. #endregion
  61. [Header("Player name character limit")]
  62. public int PlayerNameMaxLength;
  63. #region Call up a scene for data storage
  64. public static IEnumerator LoadCoroutine()
  65. {
  66. if (instance == null)
  67. {
  68. SceneManager.LoadSceneAsync("ContinuousControllerScene", LoadSceneMode.Additive);
  69. while (instance == null)
  70. {
  71. yield return null;
  72. }
  73. instance.Init();
  74. }
  75. }
  76. #endregion
  77. #region List of Deck Recipes
  78. public List<DeckData> DeckDatas { get; set; } = new List<DeckData>();
  79. #endregion
  80. #region Deck Recipe Key
  81. public string DeckDatasPlayerPrefsKey { get { return "DeckDatas3"; } }
  82. #endregion
  83. public CEntity_Base DiaboromonToken { get; private set; }
  84. public CEntity_Base AmonToken { get; private set; }
  85. public CEntity_Base UmonToken { get; private set; }
  86. public CEntity_Base FujitsumonToken { get; private set; }
  87. public CEntity_Base GyuukimonToken { get; private set; }
  88. public CEntity_Base KoHagurumonToken { get; private set; }
  89. public CardRestriction BanList { get; private set; } = new CardRestriction(new List<CardLimitCount>(), new List<BannedPair>());
  90. void LoadBanList()
  91. {
  92. BanList = DataBase.ENGBanList;
  93. }
  94. async Task CreateTokenData()
  95. {
  96. DiaboromonToken = new CEntity_Base()
  97. {
  98. cardColors = new List<CardColor>() { CardColor.White },
  99. PlayCost = 14,
  100. Level = 6,
  101. CardName_JPN = "ディアボロモン",
  102. CardName_ENG = "Diaboromon",
  103. Form_JPN = new List<string>() { "究極体" },
  104. Form_ENG = new List<string>() { "Mega" },
  105. Attribute_JPN = new List<string>() { "不明" },
  106. Attribute_ENG = new List<string>() { "Unknown" },
  107. Type_JPN = new List<string>() { "種族不明" },
  108. Type_ENG = new List<string>() { "Unidentified" },
  109. CardSpriteName = "BT2-082-token",
  110. cardKind = CardKind.Digimon,
  111. DP = 3000,
  112. };
  113. await DiaboromonToken.GetCardSprite();
  114. AmonToken = new CEntity_Base()
  115. {
  116. cardColors = new List<CardColor>() { CardColor.Red },
  117. PlayCost = -1,
  118. Level = 0,
  119. CardName_JPN = "紅炎のアモン",
  120. CardName_ENG = "Amon of Crimson Flame",
  121. Form_JPN = new List<string>(),
  122. Form_ENG = new List<string>(),
  123. Attribute_JPN = new List<string>(),
  124. Attribute_ENG = new List<string>(),
  125. Type_JPN = new List<string>(),
  126. Type_ENG = new List<string>(),
  127. CardSpriteName = "BT14-018-token-red",
  128. cardKind = CardKind.Digimon,
  129. DP = 6000,
  130. CardEffectClassName = "Bushiagumon_BT4_038"
  131. };
  132. await AmonToken.GetCardSprite();
  133. UmonToken = new CEntity_Base()
  134. {
  135. cardColors = new List<CardColor>() { CardColor.Yellow },
  136. PlayCost = -1,
  137. Level = 0,
  138. CardName_JPN = "蒼雷のウモン",
  139. CardName_ENG = "Umon of Blue Thunder",
  140. Form_JPN = new List<string>(),
  141. Form_ENG = new List<string>(),
  142. Attribute_JPN = new List<string>(),
  143. Attribute_ENG = new List<string>(),
  144. Type_JPN = new List<string>(),
  145. Type_ENG = new List<string>(),
  146. CardSpriteName = "BT14-018-token-yellow",
  147. cardKind = CardKind.Digimon,
  148. DP = 6000,
  149. CardEffectClassName = "Koemon_BT1_031"
  150. };
  151. await UmonToken.GetCardSprite();
  152. FujitsumonToken = new CEntity_Base()
  153. {
  154. cardColors = new List<CardColor>() { CardColor.Purple },
  155. PlayCost = -1,
  156. Level = 0,
  157. CardName_JPN = "フジツモン",
  158. CardName_ENG = "Fujitsumon",
  159. Form_JPN = new List<string>(),
  160. Form_ENG = new List<string>(),
  161. Attribute_JPN = new List<string>(),
  162. Attribute_ENG = new List<string>(),
  163. Type_JPN = new List<string>(),
  164. Type_ENG = new List<string>(),
  165. CardSpriteName = "EX5-058-token",
  166. cardKind = CardKind.Digimon,
  167. DP = 3000,
  168. CardEffectClassName = "Fujitsumon_EX5_058_token"
  169. };
  170. await FujitsumonToken.GetCardSprite();
  171. GyuukimonToken = new CEntity_Base()
  172. {
  173. cardColors = new List<CardColor>() { CardColor.Purple },
  174. PlayCost = 7,
  175. Level = 5,
  176. CardName_JPN = "ギュウキモン",
  177. CardName_ENG = "Gyuukimon",
  178. Form_JPN = new List<string>() { "究極の" },
  179. Form_ENG = new List<string>() { "Ultimate" },
  180. Attribute_JPN = new List<string>() { "ウイルス" },
  181. Attribute_ENG = new List<string>() { "Virus" },
  182. Type_JPN = new List<string>() { "ダークアニマル" },
  183. Type_ENG = new List<string>() { "Dark Animal" },
  184. CardSpriteName = "LM-018-token",
  185. cardKind = CardKind.Digimon,
  186. DP = 3000,
  187. };
  188. await GyuukimonToken.GetCardSprite();
  189. KoHagurumonToken = new CEntity_Base()
  190. {
  191. cardColors = new List<CardColor>() { CardColor.Black },
  192. PlayCost = -1,
  193. Level = 0,
  194. CardName_JPN = "",
  195. CardName_ENG = "KoHagurumon",
  196. Form_JPN = new List<string>(),
  197. Form_ENG = new List<string>(),
  198. Attribute_JPN = new List<string>(),
  199. Attribute_ENG = new List<string>(),
  200. Type_JPN = new List<string>(),
  201. Type_ENG = new List<string>(),
  202. CardSpriteName = "BT16-052-token",
  203. cardKind = CardKind.Digimon,
  204. DP = 1000,
  205. CardEffectClassName = "KoHagurumon_BT16_052_token"
  206. };
  207. await KoHagurumonToken.GetCardSprite();
  208. }
  209. public static ContinuousController instance = null;
  210. private void Awake()
  211. {
  212. instance = this;
  213. }
  214. public async void Init()
  215. {
  216. int random = RandomUtility.getRamdom();
  217. UnityEngine.Random.InitState(random);
  218. Debug.Log($"Game Initialize - random number sequence initialization,InitState:{random}");
  219. Sprite reverseCardSprite = await StreamingAssetsUtility.GetSprite("card_back_main");
  220. if (reverseCardSprite != null)
  221. {
  222. ReverseCard = reverseCardSprite;
  223. }
  224. Sprite reverseDigieggCardSprite = await StreamingAssetsUtility.GetSprite("card_back_sub");
  225. if (reverseDigieggCardSprite != null)
  226. {
  227. ReverseCard_Digitama = reverseDigieggCardSprite;
  228. }
  229. // deck data
  230. DeckDatas = PlayerPrefsUtil.LoadList<DeckData>(DeckDatasPlayerPrefsKey);
  231. ModifyAllDeckDatas();
  232. GetComponent<StarterDeck>().SetStarterDecks();
  233. SaveDeckDatas();
  234. // player data
  235. LoadPlayerName();
  236. LoadWinCount();
  237. // game play
  238. LoadAutoEffectOrder();
  239. LoadAutoDeckBottomOrder();
  240. LoadAutoDeckTopOrder();
  241. LoadAutoMinDigivolutionCost();
  242. LoadAutoMaxCardCount();
  243. LoadAutoHatch();
  244. LoadShowCutInAnimation();
  245. LoadReverseOpponentsCards();
  246. LoadTurnSuspendedCards();
  247. LoadCheckBeforeEndingSelection();
  248. LoadSuspendedCardsDirectionIsLeft();
  249. //Graphics
  250. LoadShowBackgroundParticle();
  251. // Sound
  252. LoadVolume();
  253. // ServerRegion
  254. LoadServerRegion();
  255. // Language
  256. LoadLanguage();
  257. await CreateTokenData();
  258. LoadBanList();
  259. DontDestroyOnLoad(gameObject);
  260. }
  261. public void ModifyAllDeckDatas()
  262. {
  263. List<DeckData> tempDeckDatas = new List<DeckData>();
  264. foreach (DeckData deckData in DeckDatas)
  265. {
  266. tempDeckDatas.Add(deckData);
  267. }
  268. foreach (DeckData deckData in tempDeckDatas)
  269. {
  270. if (deckData.AllDeckCards().Count == 0)
  271. {
  272. DeckDatas.Remove(deckData);
  273. }
  274. }
  275. for (int i = 0; i < DeckDatas.Count; i++)
  276. {
  277. //DeckData deckData = new DeckData(DeckData.GetDeckCode(DeckDatas[i].DeckName, DeckData.SortedDeckCardsList(DeckDatas[i].DeckCards()), DeckData.SortedDeckCardsList(DeckDatas[i].DigitamaDeckCards()), DeckDatas[i].KeyCard));
  278. DeckData deckData = DeckDatas[i];
  279. DeckDatas[i] = deckData.ModifiedDeckData();
  280. }
  281. SaveDeckDatas();
  282. }
  283. public void SaveDeckDatas()
  284. {
  285. PlayerPrefsUtil.SaveList(DeckDatasPlayerPrefsKey, DeckDatas);
  286. PlayerPrefs.Save();
  287. }
  288. #region Player Name
  289. string _playerName;
  290. string _playerNameKey = "PlayerName";
  291. public string PlayerName
  292. {
  293. get
  294. {
  295. if (string.IsNullOrEmpty(_playerName))
  296. {
  297. return "Player";
  298. }
  299. return _playerName;
  300. }
  301. set
  302. {
  303. _playerName = value;
  304. }
  305. }
  306. public void SavePlayerName(string playerName)
  307. {
  308. PlayerName = playerName;
  309. PlayerPrefs.SetString(_playerNameKey, playerName);
  310. PlayerPrefs.Save();
  311. }
  312. public void LoadPlayerName()
  313. {
  314. if (PlayerPrefs.HasKey(_playerNameKey))
  315. {
  316. PlayerName = PlayerPrefs.GetString(_playerNameKey);
  317. }
  318. if (string.IsNullOrEmpty(PlayerName))
  319. {
  320. PlayerName = "Player";
  321. }
  322. }
  323. #endregion
  324. #region number of victories
  325. public int WinCount { get; set; }
  326. string _winCountKey = "WinCount";
  327. public void SaveWinCount()
  328. {
  329. PlayerPrefs.SetInt(_winCountKey, WinCount);
  330. PlayerPrefs.Save();
  331. }
  332. public void LoadWinCount()
  333. {
  334. if (PlayerPrefs.HasKey(_winCountKey))
  335. {
  336. WinCount = PlayerPrefs.GetInt(_winCountKey);
  337. }
  338. }
  339. #endregion
  340. #region Auto effect order
  341. [HideInInspector] public bool autoEffectOrder = false;
  342. string _autoEffectOrderKey = "AutoEffectOrder";
  343. public void SaveAutoEffectOrder()
  344. {
  345. PlayerPrefsUtil.SetBool(_autoEffectOrderKey, autoEffectOrder);
  346. PlayerPrefs.Save();
  347. }
  348. public void LoadAutoEffectOrder()
  349. {
  350. autoEffectOrder = PlayerPrefsUtil.GetBool(_autoEffectOrderKey, false);
  351. }
  352. #endregion
  353. #region Auto deck bottom order
  354. [HideInInspector] public bool autoDeckBottomOrder = false;
  355. string _autoDeckBottomOrderKey = "AutoDeckBottomOrder";
  356. public void SaveAutoDeckBottomOrder()
  357. {
  358. PlayerPrefsUtil.SetBool(_autoDeckBottomOrderKey, autoDeckBottomOrder);
  359. PlayerPrefs.Save();
  360. }
  361. public void LoadAutoDeckBottomOrder()
  362. {
  363. autoDeckBottomOrder = PlayerPrefsUtil.GetBool(_autoDeckBottomOrderKey, false);
  364. }
  365. #endregion
  366. #region Auto deck top order
  367. [HideInInspector] public bool autoDeckTopOrder = false;
  368. string _autoDeckTopOrderKey = "AutoDeckTopOrder";
  369. public void SaveAutoDeckTopOrder()
  370. {
  371. PlayerPrefsUtil.SetBool(_autoDeckTopOrderKey, autoDeckTopOrder);
  372. PlayerPrefs.Save();
  373. }
  374. public void LoadAutoDeckTopOrder()
  375. {
  376. autoDeckTopOrder = PlayerPrefsUtil.GetBool(_autoDeckTopOrderKey, false);
  377. }
  378. #endregion
  379. #region Auto min digivolution cost
  380. [HideInInspector] public bool autoMinDigivolutionCost = false;
  381. string _autoMinDigivolutionCostKey = "AutoMinDigivolutionCost";
  382. public void SaveAutoMinDigivolutionCost()
  383. {
  384. PlayerPrefsUtil.SetBool(_autoMinDigivolutionCostKey, autoMinDigivolutionCost);
  385. PlayerPrefs.Save();
  386. }
  387. public void LoadAutoMinDigivolutionCost()
  388. {
  389. autoMinDigivolutionCost = PlayerPrefsUtil.GetBool(_autoMinDigivolutionCostKey, false);
  390. }
  391. #endregion
  392. #region Auto max card count
  393. [HideInInspector] public bool autoMaxCardCount = false;
  394. string _autoMaxCardCountKey = "AutoMaxCardCount";
  395. public void SaveAutoMaxCardCount()
  396. {
  397. PlayerPrefsUtil.SetBool(_autoMaxCardCountKey, autoMaxCardCount);
  398. PlayerPrefs.Save();
  399. }
  400. public void LoadAutoMaxCardCount()
  401. {
  402. autoMaxCardCount = PlayerPrefsUtil.GetBool(_autoMaxCardCountKey, false);
  403. }
  404. #endregion
  405. #region Auto hatch
  406. [HideInInspector] public bool autoHatch = false;
  407. string _autoHatchKey = "AutoHatch";
  408. public void SaveAutoHatch()
  409. {
  410. PlayerPrefsUtil.SetBool(_autoHatchKey, autoHatch);
  411. PlayerPrefs.Save();
  412. }
  413. public void LoadAutoHatch()
  414. {
  415. autoHatch = PlayerPrefsUtil.GetBool(_autoHatchKey, false);
  416. }
  417. #endregion
  418. #region Show CutIn Animation
  419. [HideInInspector] public bool showCutInAnimation = false;
  420. string _showCutInAnimationKey = "ShowCutInAnimation";
  421. public void SaveShowCutInAnimation()
  422. {
  423. PlayerPrefsUtil.SetBool(_showCutInAnimationKey, showCutInAnimation);
  424. PlayerPrefs.Save();
  425. }
  426. public void LoadShowCutInAnimation()
  427. {
  428. showCutInAnimation = PlayerPrefsUtil.GetBool(_showCutInAnimationKey, true);
  429. }
  430. #endregion
  431. #region Reverse opponents' cards
  432. [HideInInspector] public bool reverseOpponentsCards = false;
  433. string _reverseOpponentsCardsKey = "ReverseOpponentsCards";
  434. public void SaveReverseOpponentsCards()
  435. {
  436. PlayerPrefsUtil.SetBool(_reverseOpponentsCardsKey, reverseOpponentsCards);
  437. PlayerPrefs.Save();
  438. }
  439. public void LoadReverseOpponentsCards()
  440. {
  441. reverseOpponentsCards = PlayerPrefsUtil.GetBool(_reverseOpponentsCardsKey, false);
  442. }
  443. #endregion
  444. #region Turn suspended cards
  445. [HideInInspector] public bool turnSuspendedCards = false;
  446. string _turnSuspendedCardsKey = "TurnSuspendedCards";
  447. public void SaveTurnSuspendedCards()
  448. {
  449. PlayerPrefsUtil.SetBool(_turnSuspendedCardsKey, turnSuspendedCards);
  450. PlayerPrefs.Save();
  451. }
  452. public void LoadTurnSuspendedCards()
  453. {
  454. turnSuspendedCards = PlayerPrefsUtil.GetBool(_turnSuspendedCardsKey, true);
  455. }
  456. #endregion
  457. #region Check before ending selection
  458. [HideInInspector] public bool checkBeforeEndingSelection = false;
  459. string _checkBeforeEndingSelectionKey = "CheckBeforeEndingSelection";
  460. public void SaveCheckBeforeEndingSelection()
  461. {
  462. PlayerPrefsUtil.SetBool(_checkBeforeEndingSelectionKey, checkBeforeEndingSelection);
  463. PlayerPrefs.Save();
  464. }
  465. public void LoadCheckBeforeEndingSelection()
  466. {
  467. checkBeforeEndingSelection = PlayerPrefsUtil.GetBool(_checkBeforeEndingSelectionKey, true);
  468. }
  469. #endregion
  470. #region Suspended cards' direction is left
  471. [HideInInspector] public bool suspendedCardsDirectionIsLeft = false;
  472. string _suspendedCardsDirectionIsLeftKey = "SuspendedCardsDirectionIsLeft";
  473. public void SaveSuspendedCardsDirectionIsLeft()
  474. {
  475. PlayerPrefsUtil.SetBool(_suspendedCardsDirectionIsLeftKey, suspendedCardsDirectionIsLeft);
  476. PlayerPrefs.Save();
  477. }
  478. public void LoadSuspendedCardsDirectionIsLeft()
  479. {
  480. suspendedCardsDirectionIsLeft = PlayerPrefsUtil.GetBool(_suspendedCardsDirectionIsLeftKey, true);
  481. }
  482. #endregion
  483. #region Show background particle
  484. [HideInInspector] public bool showBackgroundParticle = false;
  485. string _showBackgroundParticleKey = "ShowBackgroundParticle";
  486. public void SaveShowBackgroundParticle()
  487. {
  488. PlayerPrefsUtil.SetBool(_showBackgroundParticleKey, showBackgroundParticle);
  489. PlayerPrefs.Save();
  490. }
  491. public void LoadShowBackgroundParticle()
  492. {
  493. showBackgroundParticle = PlayerPrefsUtil.GetBool(_showBackgroundParticleKey, true);
  494. }
  495. #endregion
  496. #region Sound volume
  497. public float BGMVolume { get; set; }
  498. public float SEVolume { get; set; }
  499. public void SetBGMVolume(float BGMVolume)
  500. {
  501. this.BGMVolume = BGMVolume;
  502. PlayerPrefs.SetFloat("BGMVolume", BGMVolume);
  503. PlayerPrefs.Save();
  504. }
  505. public void SetSEVolume(float SEVolume)
  506. {
  507. this.SEVolume = SEVolume;
  508. PlayerPrefs.SetFloat("SEVolume", SEVolume);
  509. PlayerPrefs.Save();
  510. }
  511. public void ChangeBGMVolume(AudioSource audioSource)
  512. {
  513. audioSource.volume = BGMVolume * 0.25f * 0.8f;
  514. }
  515. public void ChangeSEVolume(AudioSource audioSource)
  516. {
  517. audioSource.volume = SEVolume * 0.5f * 0.8f;
  518. }
  519. void LoadVolume()
  520. {
  521. BGMVolume = 0.5f;
  522. SEVolume = 0.5f;
  523. if (PlayerPrefs.HasKey("BGMVolume"))
  524. {
  525. BGMVolume = PlayerPrefs.GetFloat("BGMVolume");
  526. }
  527. if (PlayerPrefs.HasKey("SEVolume"))
  528. {
  529. SEVolume = PlayerPrefs.GetFloat("SEVolume");
  530. }
  531. }
  532. #endregion
  533. #region Server region
  534. [HideInInspector] public string serverRegion = "us";
  535. string _serverRegionKey = "ServerRegion";
  536. public void SaveServerRegion()
  537. {
  538. PlayerPrefs.SetString(_serverRegionKey, serverRegion);
  539. PlayerPrefs.Save();
  540. }
  541. public void LoadServerRegion()
  542. {
  543. serverRegion = PlayerPrefs.GetString(_serverRegionKey, "us");
  544. }
  545. public string LastConnectServerRegion = "";
  546. #endregion
  547. #region Language
  548. [HideInInspector] public Language language = Language.ENG;
  549. string _languageKey = "Language";
  550. public void SaveLanguage()
  551. {
  552. PlayerPrefs.SetString(_languageKey, language.ToString());
  553. PlayerPrefs.Save();
  554. }
  555. public void LoadLanguage()
  556. {
  557. language = (Language)Enum.Parse(typeof(Language), PlayerPrefs.GetString(_languageKey, "ENG"));
  558. }
  559. #endregion
  560. #region PlaySE(AudioClip clip)
  561. public SoundObject PlaySE(AudioClip clip)
  562. {
  563. SoundObject _soundObject = Instantiate(soundObject);
  564. _soundObject.PlaySE(clip);
  565. return _soundObject;
  566. }
  567. #endregion
  568. #region カードIndexからカードを取得
  569. public CEntity_Base getCardEntityByCardID(int cardIndex)
  570. {
  571. int searchIndex = cardIndex - 1;
  572. int count = 0;
  573. do
  574. {
  575. if (count != 0)
  576. {
  577. searchIndex += (int)Math.Pow(-1, count % 2) * count / 2;
  578. }
  579. if (0 <= searchIndex)
  580. {
  581. if (searchIndex <= SortedCardList.Length - 1)
  582. {
  583. CEntity_Base cEntity_Base = SortedCardList[searchIndex];
  584. if (cEntity_Base != null)
  585. {
  586. if (cEntity_Base.CardIndex == cardIndex)
  587. {
  588. return cEntity_Base;
  589. }
  590. }
  591. }
  592. else
  593. {
  594. for (int i = 0; i < 300; i++)
  595. {
  596. CEntity_Base cEntity_Base = SortedCardList[SortedCardList.Length - 1 - i];
  597. if (cEntity_Base != null)
  598. {
  599. if (cEntity_Base.CardIndex == cardIndex)
  600. {
  601. return cEntity_Base;
  602. }
  603. }
  604. }
  605. return null;
  606. }
  607. }
  608. if (count != 0)
  609. {
  610. searchIndex -= (int)Math.Pow(-1, count % 2) * count / 2;
  611. }
  612. count++;
  613. }
  614. while (count <= 20);
  615. return null;
  616. }
  617. #endregion
  618. public Coroutine LoadingTextCoroutine;
  619. bool _endBattle = false;
  620. public void EndBattle()
  621. {
  622. if (!_endBattle)
  623. {
  624. _endBattle = true;
  625. StartCoroutine(EndBattleCoroutine());
  626. }
  627. }
  628. public IEnumerator EndBattleCoroutine()
  629. {
  630. if (Opening.instance == null)
  631. {
  632. yield break;
  633. }
  634. Opening.instance.openingObject.SetActive(true);
  635. //yield return StartCoroutine(Opening.instance.LoadingObject_Unload.StartLoading("Now Loading"));
  636. //Camera camera1 = Camera.main;
  637. //Destroy(camera1.gameObject);
  638. //yield return null;
  639. isAI = false;
  640. int random = RandomUtility.getRamdom();
  641. UnityEngine.Random.InitState(random);
  642. Debug.Log($"random number sequence initialization, InitState:{random}");
  643. var unload = SceneManager.UnloadSceneAsync("BattleScene");
  644. yield return unload;
  645. yield return Resources.UnloadUnusedAssets();
  646. yield return StartCoroutine(Opening.instance.LoadingObject_Unload.StartLoading("Now Loading"));
  647. //Opening.instance.MainCamera.gameObject.SetActive(true);
  648. foreach (Camera camera in Opening.instance.openingCameras)
  649. {
  650. camera.gameObject.SetActive(true);
  651. }
  652. Opening.instance.LoadingObject_light.gameObject.SetActive(false);
  653. yield return ContinuousController.instance.StartCoroutine(PhotonUtility.SetPlayerName());
  654. if (isRandomMatch)
  655. {
  656. Debug.Log("Unload from Random Match");
  657. yield return StartCoroutine(Opening.instance.battle.lobbyManager_RandomMatch.CloseLobbyCoroutine());
  658. yield return StartCoroutine(Opening.instance.battle.selectBattleMode.SetUpSelectBattleModeCoroutine());
  659. }
  660. else
  661. {
  662. Debug.Log("Unload from Room Match");
  663. yield return StartCoroutine(Opening.instance.battle.roomManager.Init(true));
  664. yield return new WaitForSeconds(0.1f);
  665. }
  666. yield return new WaitWhile(() => GManager.instance != null);
  667. Opening.instance.LoadingObject.gameObject.SetActive(false);
  668. yield return StartCoroutine(Opening.instance.LoadingObject_Unload.EndLoading());
  669. _endBattle = false;
  670. if (!isRandomMatch)
  671. {
  672. Hashtable PlayerProp = PhotonNetwork.LocalPlayer.CustomProperties;
  673. if (PlayerProp.TryGetValue("isBattle", out object value))
  674. {
  675. PlayerProp["isBattle"] = false;
  676. }
  677. else
  678. {
  679. PlayerProp.Add("isBattle", false);
  680. }
  681. PhotonNetwork.LocalPlayer.SetCustomProperties(PlayerProp);
  682. }
  683. Scene newScene = SceneManager.GetSceneByName("Opening");
  684. SceneManager.SetActiveScene(newScene);
  685. for (int i = 0; i < 3; i++)
  686. {
  687. yield return new WaitForSeconds(0.1f);
  688. EventSystem.current.SetSelectedGameObject(Opening.instance.battle.selectBattleMode.transform.GetChild(0).gameObject);
  689. //Debug.Log("フォーカスを設定");
  690. }
  691. //GUI.UnfocusWindow();
  692. yield return null;
  693. //StartCoroutine(DestroyEffectCoroutine());
  694. if (Opening.instance.OpeningBGM != null)
  695. {
  696. if (!Opening.instance.OpeningBGM.isPlaying)
  697. {
  698. Opening.instance.OpeningBGM.StartPlayBGM(Opening.instance.bgm);
  699. }
  700. }
  701. }
  702. private void Update()
  703. {
  704. #if UNITY_WINDOWS
  705. if (Input.GetKey(KeyCode.Escape))
  706. {
  707. Application.Quit();
  708. }
  709. #endif
  710. }
  711. int _frameCount = 0;
  712. int _updateFrame = 40;
  713. void LateUpdate()
  714. {
  715. #region Update only once every few frames
  716. _frameCount++;
  717. if (_frameCount < _updateFrame)
  718. {
  719. return;
  720. }
  721. else
  722. {
  723. _frameCount = 0;
  724. }
  725. #endregion
  726. if (PhotonNetwork.InRoom)
  727. {
  728. if (!isAI)
  729. {
  730. bool notEnterOther = false;
  731. if (PhotonNetwork.PlayerList.Length == 1)
  732. {
  733. if (GManager.instance != null)
  734. {
  735. notEnterOther = true;
  736. }
  737. }
  738. if (notEnterOther)
  739. {
  740. if (PhotonNetwork.CurrentRoom.MaxPlayers != 1)
  741. {
  742. PhotonNetwork.CurrentRoom.MaxPlayers = 1;
  743. }
  744. }
  745. else
  746. {
  747. if (PhotonNetwork.CurrentRoom.MaxPlayers != 2)
  748. {
  749. PhotonNetwork.CurrentRoom.MaxPlayers = 2;
  750. }
  751. }
  752. }
  753. }
  754. }
  755. public bool isAI { get; set; } = false;
  756. //Flag that the sharing of the random number sequence is over.
  757. public bool DoneSetRandom { get; set; } = false;
  758. public bool CanSetRandom { get; set; } = false;
  759. [PunRPC]
  760. public void SetRandom(int random)
  761. {
  762. StartCoroutine(SetRandomCoroutine(random));
  763. }
  764. IEnumerator SetRandomCoroutine(int random)
  765. {
  766. yield return new WaitWhile(() => !CanSetRandom);
  767. UnityEngine.Random.InitState(random);
  768. DoneSetRandom = true;
  769. Debug.Log($"random number sequence initialization,InitState:{random}");
  770. }
  771. }
  772. #region Manage random numbers
  773. public static class RandomUtility
  774. {
  775. private static System.Random random;
  776. public static int getRamdom()
  777. {
  778. int _max = 1500000000;
  779. if (random == null)
  780. {
  781. random = new System.Random((int)DateTime.Now.Ticks);
  782. }
  783. return random.Next(0, _max);
  784. }
  785. #region IsSucceedProbability(float Probability)
  786. public static bool IsSucceedProbability(float Probability)
  787. {
  788. if (Probability >= 1)
  789. {
  790. return true;
  791. }
  792. if (Probability <= 0)
  793. {
  794. return false;
  795. }
  796. float random = UnityEngine.Random.Range(0f, 1f);
  797. if (random <= Probability)
  798. {
  799. return true;
  800. }
  801. return false;
  802. }
  803. #endregion
  804. #region Shuffle the deck
  805. public static List<CEntity_Base> ShuffledDeckCards(List<CEntity_Base> DeckCards)
  806. {
  807. List<CEntity_Base> CardDatas = new List<CEntity_Base>();
  808. foreach (CEntity_Base cEntity_Base in DeckCards)
  809. {
  810. CardDatas.Add(cEntity_Base);
  811. }
  812. // The initial value of integer n is the number of cards in the deck
  813. int n = CardDatas.Count;
  814. for (int i = 0; i < 20; i++)
  815. {
  816. // Repeat until n is less than 1
  817. while (n > 1)
  818. {
  819. n--;
  820. // k is a random value between 0 and n+1
  821. int k = UnityEngine.Random.Range(0, n + 1);
  822. // Assign the kth card to temp
  823. CEntity_Base temp = CardDatas[k];
  824. CardDatas[k] = CardDatas[n];
  825. CardDatas[n] = temp;
  826. }
  827. }
  828. return CardDatas;
  829. }
  830. public static List<CardSource> ShuffledDeckCards(List<CardSource> DeckCards)
  831. {
  832. List<CardSource> CardDatas = new List<CardSource>();
  833. foreach (CardSource cardSource in DeckCards)
  834. {
  835. CardDatas.Add(cardSource);
  836. }
  837. // 整数 n の初期値はデッキの枚数
  838. int n = CardDatas.Count;
  839. for (int i = 0; i < 20; i++)
  840. {
  841. // nが1より小さくなるまで繰り返す
  842. while (n > 1)
  843. {
  844. n--;
  845. // kは 0 ~ n+1 の間のランダムな値
  846. int k = UnityEngine.Random.Range(0, n + 1);
  847. // k番目のカードをtempに代入
  848. CardSource temp = CardDatas[k];
  849. CardDatas[k] = CardDatas[n];
  850. CardDatas[n] = temp;
  851. }
  852. }
  853. return CardDatas;
  854. }
  855. #endregion
  856. }
  857. #endregion
  858. #region Manage connections to Photon
  859. public class PhotonUtility
  860. {
  861. #region Disconnected from Photon
  862. public static IEnumerator DisconnectCoroutine()
  863. {
  864. #region Exit Room
  865. if (PhotonNetwork.InRoom)
  866. {
  867. PhotonNetwork.LeaveRoom();
  868. }
  869. yield return new WaitWhile(() => PhotonNetwork.InRoom);
  870. #endregion
  871. #region Exit from the lobby
  872. if (PhotonNetwork.InLobby)
  873. {
  874. PhotonNetwork.LeaveLobby();
  875. }
  876. yield return new WaitWhile(() => PhotonNetwork.InLobby);
  877. #endregion
  878. #region Disconnected from Photon
  879. if (PhotonNetwork.IsConnected)
  880. {
  881. PhotonNetwork.Disconnect();
  882. }
  883. yield return new WaitWhile(() => PhotonNetwork.IsConnected);
  884. #endregion
  885. }
  886. #endregion
  887. #region Connect to Photon server
  888. public static IEnumerator ConnectToMasterServerCoroutine()
  889. {
  890. if (!PhotonNetwork.IsConnected || ContinuousController.instance.LastConnectServerRegion != ContinuousController.instance.serverRegion)
  891. {
  892. if (PhotonNetwork.IsConnected)
  893. {
  894. yield return ContinuousController.instance.StartCoroutine(DisconnectCoroutine());
  895. yield return new WaitWhile(() => PhotonNetwork.IsConnected);
  896. }
  897. PhotonNetwork.NetworkingClient.AppId = PhotonNetwork.PhotonServerSettings.AppSettings.AppIdRealtime;
  898. PhotonNetwork.ConnectToRegion(ContinuousController.instance.serverRegion);
  899. PhotonNetwork.NickName = ContinuousController.instance.PlayerName;
  900. PhotonNetwork.GameVersion = ContinuousController.instance.GameVerString;
  901. ContinuousController.instance.LastConnectServerRegion = ContinuousController.instance.serverRegion;
  902. }
  903. yield return new WaitWhile(() => !PhotonNetwork.IsConnectedAndReady);
  904. }
  905. #endregion
  906. #region Connect to Photon Server and Lobby
  907. public static IEnumerator ConnectToLobbyCoroutine()
  908. {
  909. #region Connect to Photon server
  910. yield return ContinuousController.instance.StartCoroutine(ConnectToMasterServerCoroutine());
  911. #endregion
  912. #region Save player name to custom properties
  913. yield return ContinuousController.instance.StartCoroutine(SetPlayerName());
  914. #endregion
  915. #region Save the number of wins to a custom property
  916. Hashtable hash = PhotonNetwork.LocalPlayer.CustomProperties;
  917. object value;
  918. hash = PhotonNetwork.LocalPlayer.CustomProperties;
  919. if (hash.TryGetValue(ContinuousController.WinCountKey, out value))
  920. {
  921. hash[ContinuousController.WinCountKey] = ContinuousController.instance.WinCount;
  922. }
  923. else
  924. {
  925. hash.Add(ContinuousController.WinCountKey, ContinuousController.instance.WinCount);
  926. }
  927. PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
  928. while (true)
  929. {
  930. Hashtable _hash = PhotonNetwork.LocalPlayer.CustomProperties;
  931. if (_hash.TryGetValue(ContinuousController.WinCountKey, out value))
  932. {
  933. if ((int)value == ContinuousController.instance.WinCount)
  934. {
  935. break;
  936. }
  937. }
  938. yield return null;
  939. }
  940. #endregion
  941. #region Connect to Lobby
  942. if (!PhotonNetwork.InLobby)
  943. {
  944. PhotonNetwork.JoinLobby();
  945. }
  946. yield return new WaitWhile(() => !PhotonNetwork.InLobby);
  947. yield return new WaitUntil(() => PhotonNetwork.InLobby && PhotonNetwork.IsConnectedAndReady);
  948. #endregion
  949. }
  950. #endregion
  951. #region Save player name to properties
  952. public static IEnumerator SetPlayerName()
  953. {
  954. Hashtable hash = PhotonNetwork.LocalPlayer.CustomProperties;
  955. object value;
  956. hash = PhotonNetwork.LocalPlayer.CustomProperties;
  957. if (hash.TryGetValue(ContinuousController.PlayerNameKey, out value))
  958. {
  959. hash[ContinuousController.PlayerNameKey] = ContinuousController.instance.PlayerName;
  960. }
  961. else
  962. {
  963. hash.Add(ContinuousController.PlayerNameKey, ContinuousController.instance.PlayerName);
  964. }
  965. PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
  966. while (true)
  967. {
  968. Hashtable _hash = PhotonNetwork.LocalPlayer.CustomProperties;
  969. if (_hash.TryGetValue(ContinuousController.PlayerNameKey, out value))
  970. {
  971. if ((string)value == ContinuousController.instance.PlayerName)
  972. {
  973. break;
  974. }
  975. }
  976. yield return null;
  977. }
  978. }
  979. #endregion
  980. #region Save deck data to custom properties
  981. public static IEnumerator SignUpBattleDeckData()
  982. {
  983. Hashtable hash = PhotonNetwork.LocalPlayer.CustomProperties;
  984. if (hash.TryGetValue(ContinuousController.DeckDataPropertyKey, out object value))
  985. {
  986. hash[ContinuousController.DeckDataPropertyKey] = ContinuousController.instance.BattleDeckData.GetThisDeckCode();
  987. }
  988. else
  989. {
  990. hash.Add(ContinuousController.DeckDataPropertyKey, ContinuousController.instance.BattleDeckData.GetThisDeckCode());
  991. }
  992. //Debug.Log($"バトルデッキデータ登録,KeyCard:{ContinuousController.instance.BattleDeckData.KeyCard.CardName_JPN}");
  993. PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
  994. while (true)
  995. {
  996. Hashtable _hash = PhotonNetwork.LocalPlayer.CustomProperties;
  997. if (_hash.TryGetValue(ContinuousController.DeckDataPropertyKey, out value))
  998. {
  999. if ((string)value == ContinuousController.instance.BattleDeckData.GetThisDeckCode())
  1000. {
  1001. break;
  1002. }
  1003. }
  1004. yield return null;
  1005. }
  1006. }
  1007. #endregion
  1008. #region Remove custom properties from deck data
  1009. public static IEnumerator DeleteBattleDeckData()
  1010. {
  1011. Hashtable hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1012. if (hash.TryGetValue(ContinuousController.DeckDataPropertyKey, out object value))
  1013. {
  1014. hash.Remove(ContinuousController.DeckDataPropertyKey);
  1015. }
  1016. PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
  1017. while (true)
  1018. {
  1019. Hashtable _hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1020. if (!_hash.TryGetValue(ContinuousController.DeckDataPropertyKey, out value))
  1021. {
  1022. break;
  1023. }
  1024. yield return null;
  1025. }
  1026. }
  1027. #endregion
  1028. }
  1029. #endregion
  1030. public enum Language
  1031. {
  1032. ENG,
  1033. JPN,
  1034. }