ContinuousController.cs 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276
  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. Application.targetFrameRate = 60;
  217. int random = RandomUtility.getRamdom();
  218. UnityEngine.Random.InitState(random);
  219. Debug.Log($"Game Initialize - random number sequence initialization,InitState:{random}");
  220. Sprite reverseCardSprite = await StreamingAssetsUtility.GetSprite("card_back_main");
  221. if (reverseCardSprite != null)
  222. {
  223. ReverseCard = reverseCardSprite;
  224. }
  225. Sprite reverseDigieggCardSprite = await StreamingAssetsUtility.GetSprite("card_back_sub");
  226. if (reverseDigieggCardSprite != null)
  227. {
  228. ReverseCard_Digitama = reverseDigieggCardSprite;
  229. }
  230. // deck data
  231. DeckDatas = PlayerPrefsUtil.LoadList<DeckData>(DeckDatasPlayerPrefsKey);
  232. ModifyAllDeckDatas();
  233. GetComponent<StarterDeck>().SetStarterDecks();
  234. SaveDeckDatas();
  235. // player data
  236. LoadPlayerName();
  237. LoadWinCount();
  238. // game play
  239. LoadAutoEffectOrder();
  240. LoadAutoDeckBottomOrder();
  241. LoadAutoDeckTopOrder();
  242. LoadAutoMinDigivolutionCost();
  243. LoadAutoMaxCardCount();
  244. LoadAutoHatch();
  245. LoadShowCutInAnimation();
  246. LoadReverseOpponentsCards();
  247. LoadTurnSuspendedCards();
  248. LoadCheckBeforeEndingSelection();
  249. LoadSuspendedCardsDirectionIsLeft();
  250. //Graphics
  251. LoadShowBackgroundParticle();
  252. // Sound
  253. LoadVolume();
  254. // ServerRegion
  255. LoadServerRegion();
  256. // Language
  257. LoadLanguage();
  258. await CreateTokenData();
  259. LoadBanList();
  260. DontDestroyOnLoad(gameObject);
  261. }
  262. public void ModifyAllDeckDatas()
  263. {
  264. List<DeckData> tempDeckDatas = new List<DeckData>();
  265. foreach (DeckData deckData in DeckDatas)
  266. {
  267. tempDeckDatas.Add(deckData);
  268. }
  269. foreach (DeckData deckData in tempDeckDatas)
  270. {
  271. if (deckData.AllDeckCards().Count == 0)
  272. {
  273. DeckDatas.Remove(deckData);
  274. }
  275. }
  276. for (int i = 0; i < DeckDatas.Count; i++)
  277. {
  278. //DeckData deckData = new DeckData(DeckData.GetDeckCode(DeckDatas[i].DeckName, DeckData.SortedDeckCardsList(DeckDatas[i].DeckCards()), DeckData.SortedDeckCardsList(DeckDatas[i].DigitamaDeckCards()), DeckDatas[i].KeyCard));
  279. DeckData deckData = DeckDatas[i];
  280. DeckDatas[i] = deckData.ModifiedDeckData();
  281. }
  282. SaveDeckDatas();
  283. }
  284. public void SaveDeckDatas()
  285. {
  286. PlayerPrefsUtil.SaveList(DeckDatasPlayerPrefsKey, DeckDatas);
  287. PlayerPrefs.Save();
  288. }
  289. #region Player Name
  290. string _playerName;
  291. string _playerNameKey = "PlayerName";
  292. public string PlayerName
  293. {
  294. get
  295. {
  296. if (string.IsNullOrEmpty(_playerName))
  297. {
  298. return "Player";
  299. }
  300. return _playerName;
  301. }
  302. set
  303. {
  304. _playerName = value;
  305. }
  306. }
  307. public void SavePlayerName(string playerName)
  308. {
  309. PlayerName = playerName;
  310. PlayerPrefs.SetString(_playerNameKey, playerName);
  311. PlayerPrefs.Save();
  312. }
  313. public void LoadPlayerName()
  314. {
  315. if (PlayerPrefs.HasKey(_playerNameKey))
  316. {
  317. PlayerName = PlayerPrefs.GetString(_playerNameKey);
  318. }
  319. if (string.IsNullOrEmpty(PlayerName))
  320. {
  321. PlayerName = "Player";
  322. }
  323. }
  324. #endregion
  325. #region number of victories
  326. public int WinCount { get; set; }
  327. string _winCountKey = "WinCount";
  328. public void SaveWinCount()
  329. {
  330. PlayerPrefs.SetInt(_winCountKey, WinCount);
  331. PlayerPrefs.Save();
  332. }
  333. public void LoadWinCount()
  334. {
  335. if (PlayerPrefs.HasKey(_winCountKey))
  336. {
  337. WinCount = PlayerPrefs.GetInt(_winCountKey);
  338. }
  339. }
  340. #endregion
  341. #region Auto effect order
  342. [HideInInspector] public bool autoEffectOrder = false;
  343. string _autoEffectOrderKey = "AutoEffectOrder";
  344. public void SaveAutoEffectOrder()
  345. {
  346. PlayerPrefsUtil.SetBool(_autoEffectOrderKey, autoEffectOrder);
  347. PlayerPrefs.Save();
  348. }
  349. public void LoadAutoEffectOrder()
  350. {
  351. autoEffectOrder = PlayerPrefsUtil.GetBool(_autoEffectOrderKey, false);
  352. }
  353. #endregion
  354. #region Auto deck bottom order
  355. [HideInInspector] public bool autoDeckBottomOrder = false;
  356. string _autoDeckBottomOrderKey = "AutoDeckBottomOrder";
  357. public void SaveAutoDeckBottomOrder()
  358. {
  359. PlayerPrefsUtil.SetBool(_autoDeckBottomOrderKey, autoDeckBottomOrder);
  360. PlayerPrefs.Save();
  361. }
  362. public void LoadAutoDeckBottomOrder()
  363. {
  364. autoDeckBottomOrder = PlayerPrefsUtil.GetBool(_autoDeckBottomOrderKey, false);
  365. }
  366. #endregion
  367. #region Auto deck top order
  368. [HideInInspector] public bool autoDeckTopOrder = false;
  369. string _autoDeckTopOrderKey = "AutoDeckTopOrder";
  370. public void SaveAutoDeckTopOrder()
  371. {
  372. PlayerPrefsUtil.SetBool(_autoDeckTopOrderKey, autoDeckTopOrder);
  373. PlayerPrefs.Save();
  374. }
  375. public void LoadAutoDeckTopOrder()
  376. {
  377. autoDeckTopOrder = PlayerPrefsUtil.GetBool(_autoDeckTopOrderKey, false);
  378. }
  379. #endregion
  380. #region Auto min digivolution cost
  381. [HideInInspector] public bool autoMinDigivolutionCost = false;
  382. string _autoMinDigivolutionCostKey = "AutoMinDigivolutionCost";
  383. public void SaveAutoMinDigivolutionCost()
  384. {
  385. PlayerPrefsUtil.SetBool(_autoMinDigivolutionCostKey, autoMinDigivolutionCost);
  386. PlayerPrefs.Save();
  387. }
  388. public void LoadAutoMinDigivolutionCost()
  389. {
  390. autoMinDigivolutionCost = PlayerPrefsUtil.GetBool(_autoMinDigivolutionCostKey, false);
  391. }
  392. #endregion
  393. #region Auto max card count
  394. [HideInInspector] public bool autoMaxCardCount = false;
  395. string _autoMaxCardCountKey = "AutoMaxCardCount";
  396. public void SaveAutoMaxCardCount()
  397. {
  398. PlayerPrefsUtil.SetBool(_autoMaxCardCountKey, autoMaxCardCount);
  399. PlayerPrefs.Save();
  400. }
  401. public void LoadAutoMaxCardCount()
  402. {
  403. autoMaxCardCount = PlayerPrefsUtil.GetBool(_autoMaxCardCountKey, false);
  404. }
  405. #endregion
  406. #region Auto hatch
  407. [HideInInspector] public bool autoHatch = false;
  408. string _autoHatchKey = "AutoHatch";
  409. public void SaveAutoHatch()
  410. {
  411. PlayerPrefsUtil.SetBool(_autoHatchKey, autoHatch);
  412. PlayerPrefs.Save();
  413. }
  414. public void LoadAutoHatch()
  415. {
  416. autoHatch = PlayerPrefsUtil.GetBool(_autoHatchKey, false);
  417. }
  418. #endregion
  419. #region Show CutIn Animation
  420. [HideInInspector] public bool showCutInAnimation = false;
  421. string _showCutInAnimationKey = "ShowCutInAnimation";
  422. public void SaveShowCutInAnimation()
  423. {
  424. PlayerPrefsUtil.SetBool(_showCutInAnimationKey, showCutInAnimation);
  425. PlayerPrefs.Save();
  426. }
  427. public void LoadShowCutInAnimation()
  428. {
  429. showCutInAnimation = PlayerPrefsUtil.GetBool(_showCutInAnimationKey, true);
  430. }
  431. #endregion
  432. #region Reverse opponents' cards
  433. [HideInInspector] public bool reverseOpponentsCards = false;
  434. string _reverseOpponentsCardsKey = "ReverseOpponentsCards";
  435. public void SaveReverseOpponentsCards()
  436. {
  437. PlayerPrefsUtil.SetBool(_reverseOpponentsCardsKey, reverseOpponentsCards);
  438. PlayerPrefs.Save();
  439. }
  440. public void LoadReverseOpponentsCards()
  441. {
  442. reverseOpponentsCards = PlayerPrefsUtil.GetBool(_reverseOpponentsCardsKey, false);
  443. }
  444. #endregion
  445. #region Turn suspended cards
  446. [HideInInspector] public bool turnSuspendedCards = false;
  447. string _turnSuspendedCardsKey = "TurnSuspendedCards";
  448. public void SaveTurnSuspendedCards()
  449. {
  450. PlayerPrefsUtil.SetBool(_turnSuspendedCardsKey, turnSuspendedCards);
  451. PlayerPrefs.Save();
  452. }
  453. public void LoadTurnSuspendedCards()
  454. {
  455. turnSuspendedCards = PlayerPrefsUtil.GetBool(_turnSuspendedCardsKey, true);
  456. }
  457. #endregion
  458. #region Check before ending selection
  459. [HideInInspector] public bool checkBeforeEndingSelection = false;
  460. string _checkBeforeEndingSelectionKey = "CheckBeforeEndingSelection";
  461. public void SaveCheckBeforeEndingSelection()
  462. {
  463. PlayerPrefsUtil.SetBool(_checkBeforeEndingSelectionKey, checkBeforeEndingSelection);
  464. PlayerPrefs.Save();
  465. }
  466. public void LoadCheckBeforeEndingSelection()
  467. {
  468. checkBeforeEndingSelection = PlayerPrefsUtil.GetBool(_checkBeforeEndingSelectionKey, true);
  469. }
  470. #endregion
  471. #region Suspended cards' direction is left
  472. [HideInInspector] public bool suspendedCardsDirectionIsLeft = false;
  473. string _suspendedCardsDirectionIsLeftKey = "SuspendedCardsDirectionIsLeft";
  474. public void SaveSuspendedCardsDirectionIsLeft()
  475. {
  476. PlayerPrefsUtil.SetBool(_suspendedCardsDirectionIsLeftKey, suspendedCardsDirectionIsLeft);
  477. PlayerPrefs.Save();
  478. }
  479. public void LoadSuspendedCardsDirectionIsLeft()
  480. {
  481. suspendedCardsDirectionIsLeft = PlayerPrefsUtil.GetBool(_suspendedCardsDirectionIsLeftKey, true);
  482. }
  483. #endregion
  484. #region Show background particle
  485. [HideInInspector] public bool showBackgroundParticle = false;
  486. string _showBackgroundParticleKey = "ShowBackgroundParticle";
  487. public void SaveShowBackgroundParticle()
  488. {
  489. PlayerPrefsUtil.SetBool(_showBackgroundParticleKey, showBackgroundParticle);
  490. PlayerPrefs.Save();
  491. }
  492. public void LoadShowBackgroundParticle()
  493. {
  494. showBackgroundParticle = PlayerPrefsUtil.GetBool(_showBackgroundParticleKey, true);
  495. }
  496. #endregion
  497. #region Sound volume
  498. public float BGMVolume { get; set; }
  499. public float SEVolume { get; set; }
  500. public void SetBGMVolume(float BGMVolume)
  501. {
  502. this.BGMVolume = BGMVolume;
  503. PlayerPrefs.SetFloat("BGMVolume", BGMVolume);
  504. PlayerPrefs.Save();
  505. }
  506. public void SetSEVolume(float SEVolume)
  507. {
  508. this.SEVolume = SEVolume;
  509. PlayerPrefs.SetFloat("SEVolume", SEVolume);
  510. PlayerPrefs.Save();
  511. }
  512. public void ChangeBGMVolume(AudioSource audioSource)
  513. {
  514. audioSource.volume = BGMVolume * 0.25f * 0.8f;
  515. }
  516. public void ChangeSEVolume(AudioSource audioSource)
  517. {
  518. audioSource.volume = SEVolume * 0.5f * 0.8f;
  519. }
  520. void LoadVolume()
  521. {
  522. BGMVolume = 0.5f;
  523. SEVolume = 0.5f;
  524. if (PlayerPrefs.HasKey("BGMVolume"))
  525. {
  526. BGMVolume = PlayerPrefs.GetFloat("BGMVolume");
  527. }
  528. if (PlayerPrefs.HasKey("SEVolume"))
  529. {
  530. SEVolume = PlayerPrefs.GetFloat("SEVolume");
  531. }
  532. }
  533. #endregion
  534. #region Server region
  535. [HideInInspector] public string serverRegion = "us";
  536. string _serverRegionKey = "ServerRegion";
  537. public void SaveServerRegion()
  538. {
  539. PlayerPrefs.SetString(_serverRegionKey, serverRegion);
  540. PlayerPrefs.Save();
  541. }
  542. public void LoadServerRegion()
  543. {
  544. serverRegion = PlayerPrefs.GetString(_serverRegionKey, "us");
  545. }
  546. public string LastConnectServerRegion = "";
  547. #endregion
  548. #region Language
  549. [HideInInspector] public Language language = Language.ENG;
  550. string _languageKey = "Language";
  551. public void SaveLanguage()
  552. {
  553. PlayerPrefs.SetString(_languageKey, language.ToString());
  554. PlayerPrefs.Save();
  555. }
  556. public void LoadLanguage()
  557. {
  558. language = (Language)Enum.Parse(typeof(Language), PlayerPrefs.GetString(_languageKey, "ENG"));
  559. }
  560. #endregion
  561. #region PlaySE(AudioClip clip)
  562. public SoundObject PlaySE(AudioClip clip)
  563. {
  564. SoundObject _soundObject = Instantiate(soundObject);
  565. _soundObject.PlaySE(clip);
  566. return _soundObject;
  567. }
  568. #endregion
  569. #region カードIndexからカードを取得
  570. public CEntity_Base getCardEntityByCardID(int cardIndex)
  571. {
  572. int searchIndex = cardIndex - 1;
  573. int count = 0;
  574. do
  575. {
  576. if (count != 0)
  577. {
  578. searchIndex += (int)Math.Pow(-1, count % 2) * count / 2;
  579. }
  580. if (0 <= searchIndex)
  581. {
  582. if (searchIndex <= SortedCardList.Length - 1)
  583. {
  584. CEntity_Base cEntity_Base = SortedCardList[searchIndex];
  585. if (cEntity_Base != null)
  586. {
  587. if (cEntity_Base.CardIndex == cardIndex)
  588. {
  589. return cEntity_Base;
  590. }
  591. }
  592. }
  593. else
  594. {
  595. for (int i = 0; i < 300; i++)
  596. {
  597. CEntity_Base cEntity_Base = SortedCardList[SortedCardList.Length - 1 - i];
  598. if (cEntity_Base != null)
  599. {
  600. if (cEntity_Base.CardIndex == cardIndex)
  601. {
  602. return cEntity_Base;
  603. }
  604. }
  605. }
  606. return null;
  607. }
  608. }
  609. if (count != 0)
  610. {
  611. searchIndex -= (int)Math.Pow(-1, count % 2) * count / 2;
  612. }
  613. count++;
  614. }
  615. while (count <= 20);
  616. return null;
  617. }
  618. #endregion
  619. public Coroutine LoadingTextCoroutine;
  620. bool _endBattle = false;
  621. public void EndBattle()
  622. {
  623. if (!_endBattle)
  624. {
  625. _endBattle = true;
  626. StartCoroutine(EndBattleCoroutine());
  627. }
  628. }
  629. public IEnumerator EndBattleCoroutine()
  630. {
  631. if (Opening.instance == null)
  632. {
  633. yield break;
  634. }
  635. Opening.instance.openingObject.SetActive(true);
  636. //yield return StartCoroutine(Opening.instance.LoadingObject_Unload.StartLoading("Now Loading"));
  637. //Camera camera1 = Camera.main;
  638. //Destroy(camera1.gameObject);
  639. //yield return null;
  640. isAI = false;
  641. int random = RandomUtility.getRamdom();
  642. UnityEngine.Random.InitState(random);
  643. Debug.Log($"random number sequence initialization, InitState:{random}");
  644. var unload = SceneManager.UnloadSceneAsync("BattleScene");
  645. yield return unload;
  646. yield return Resources.UnloadUnusedAssets();
  647. yield return StartCoroutine(Opening.instance.LoadingObject_Unload.StartLoading("Now Loading"));
  648. //Opening.instance.MainCamera.gameObject.SetActive(true);
  649. foreach (Camera camera in Opening.instance.openingCameras)
  650. {
  651. camera.gameObject.SetActive(true);
  652. }
  653. Opening.instance.LoadingObject_light.gameObject.SetActive(false);
  654. yield return ContinuousController.instance.StartCoroutine(PhotonUtility.SetPlayerName());
  655. if (isRandomMatch)
  656. {
  657. Debug.Log("Unload from Random Match");
  658. yield return StartCoroutine(Opening.instance.battle.lobbyManager_RandomMatch.CloseLobbyCoroutine());
  659. yield return StartCoroutine(Opening.instance.battle.selectBattleMode.SetUpSelectBattleModeCoroutine());
  660. }
  661. else
  662. {
  663. Debug.Log("Unload from Room Match");
  664. yield return StartCoroutine(Opening.instance.battle.roomManager.Init(true));
  665. yield return new WaitForSeconds(0.1f);
  666. }
  667. yield return new WaitWhile(() => GManager.instance != null);
  668. Opening.instance.LoadingObject.gameObject.SetActive(false);
  669. yield return StartCoroutine(Opening.instance.LoadingObject_Unload.EndLoading());
  670. _endBattle = false;
  671. if (!isRandomMatch)
  672. {
  673. Hashtable PlayerProp = PhotonNetwork.LocalPlayer.CustomProperties;
  674. if (PlayerProp.TryGetValue("isBattle", out object value))
  675. {
  676. PlayerProp["isBattle"] = false;
  677. }
  678. else
  679. {
  680. PlayerProp.Add("isBattle", false);
  681. }
  682. PhotonNetwork.LocalPlayer.SetCustomProperties(PlayerProp);
  683. }
  684. Scene newScene = SceneManager.GetSceneByName("Opening");
  685. SceneManager.SetActiveScene(newScene);
  686. for (int i = 0; i < 3; i++)
  687. {
  688. yield return new WaitForSeconds(0.1f);
  689. EventSystem.current.SetSelectedGameObject(Opening.instance.battle.selectBattleMode.transform.GetChild(0).gameObject);
  690. //Debug.Log("フォーカスを設定");
  691. }
  692. //GUI.UnfocusWindow();
  693. yield return null;
  694. //StartCoroutine(DestroyEffectCoroutine());
  695. if (Opening.instance.OpeningBGM != null)
  696. {
  697. if (!Opening.instance.OpeningBGM.isPlaying)
  698. {
  699. Opening.instance.OpeningBGM.StartPlayBGM(Opening.instance.bgm);
  700. }
  701. }
  702. }
  703. private void Update()
  704. {
  705. #if UNITY_WINDOWS
  706. if (Input.GetKey(KeyCode.Escape))
  707. {
  708. Application.Quit();
  709. }
  710. #endif
  711. }
  712. int _frameCount = 0;
  713. int _updateFrame = 40;
  714. void LateUpdate()
  715. {
  716. #region Update only once every few frames
  717. _frameCount++;
  718. if (_frameCount < _updateFrame)
  719. {
  720. return;
  721. }
  722. else
  723. {
  724. _frameCount = 0;
  725. }
  726. #endregion
  727. if (PhotonNetwork.InRoom)
  728. {
  729. if (!isAI)
  730. {
  731. bool notEnterOther = false;
  732. if (PhotonNetwork.PlayerList.Length == 1)
  733. {
  734. if (GManager.instance != null)
  735. {
  736. notEnterOther = true;
  737. }
  738. }
  739. if (notEnterOther)
  740. {
  741. if (PhotonNetwork.CurrentRoom.MaxPlayers != 1)
  742. {
  743. PhotonNetwork.CurrentRoom.MaxPlayers = 1;
  744. }
  745. }
  746. else
  747. {
  748. if (PhotonNetwork.CurrentRoom.MaxPlayers != 2)
  749. {
  750. PhotonNetwork.CurrentRoom.MaxPlayers = 2;
  751. }
  752. }
  753. }
  754. }
  755. }
  756. public bool isAI { get; set; } = false;
  757. //Flag that the sharing of the random number sequence is over.
  758. public bool DoneSetRandom { get; set; } = false;
  759. public bool CanSetRandom { get; set; } = false;
  760. [PunRPC]
  761. public void SetRandom(int random)
  762. {
  763. StartCoroutine(SetRandomCoroutine(random));
  764. }
  765. IEnumerator SetRandomCoroutine(int random)
  766. {
  767. yield return new WaitWhile(() => !CanSetRandom);
  768. UnityEngine.Random.InitState(random);
  769. DoneSetRandom = true;
  770. Debug.Log($"random number sequence initialization,InitState:{random}");
  771. }
  772. }
  773. #region Manage random numbers
  774. public static class RandomUtility
  775. {
  776. private static System.Random random;
  777. public static int getRamdom()
  778. {
  779. int _max = 1500000000;
  780. if (random == null)
  781. {
  782. random = new System.Random((int)DateTime.Now.Ticks);
  783. }
  784. return random.Next(0, _max);
  785. }
  786. #region IsSucceedProbability(float Probability)
  787. public static bool IsSucceedProbability(float Probability)
  788. {
  789. if (Probability >= 1)
  790. {
  791. return true;
  792. }
  793. if (Probability <= 0)
  794. {
  795. return false;
  796. }
  797. float random = UnityEngine.Random.Range(0f, 1f);
  798. if (random <= Probability)
  799. {
  800. return true;
  801. }
  802. return false;
  803. }
  804. #endregion
  805. #region Shuffle the deck
  806. public static List<CEntity_Base> ShuffledDeckCards(List<CEntity_Base> DeckCards)
  807. {
  808. List<CEntity_Base> CardDatas = new List<CEntity_Base>();
  809. foreach (CEntity_Base cEntity_Base in DeckCards)
  810. {
  811. CardDatas.Add(cEntity_Base);
  812. }
  813. // The initial value of integer n is the number of cards in the deck
  814. int n = CardDatas.Count;
  815. for (int i = 0; i < 20; i++)
  816. {
  817. // Repeat until n is less than 1
  818. while (n > 1)
  819. {
  820. n--;
  821. // k is a random value between 0 and n+1
  822. int k = UnityEngine.Random.Range(0, n + 1);
  823. // Assign the kth card to temp
  824. CEntity_Base temp = CardDatas[k];
  825. CardDatas[k] = CardDatas[n];
  826. CardDatas[n] = temp;
  827. }
  828. }
  829. return CardDatas;
  830. }
  831. public static List<CardSource> ShuffledDeckCards(List<CardSource> DeckCards)
  832. {
  833. List<CardSource> CardDatas = new List<CardSource>();
  834. foreach (CardSource cardSource in DeckCards)
  835. {
  836. CardDatas.Add(cardSource);
  837. }
  838. // 整数 n の初期値はデッキの枚数
  839. int n = CardDatas.Count;
  840. for (int i = 0; i < 20; i++)
  841. {
  842. // nが1より小さくなるまで繰り返す
  843. while (n > 1)
  844. {
  845. n--;
  846. // kは 0 ~ n+1 の間のランダムな値
  847. int k = UnityEngine.Random.Range(0, n + 1);
  848. // k番目のカードをtempに代入
  849. CardSource temp = CardDatas[k];
  850. CardDatas[k] = CardDatas[n];
  851. CardDatas[n] = temp;
  852. }
  853. }
  854. return CardDatas;
  855. }
  856. #endregion
  857. }
  858. #endregion
  859. #region Manage connections to Photon
  860. public class PhotonUtility
  861. {
  862. #region Disconnected from Photon
  863. public static IEnumerator DisconnectCoroutine()
  864. {
  865. #region Exit Room
  866. if (PhotonNetwork.InRoom)
  867. {
  868. PhotonNetwork.LeaveRoom();
  869. }
  870. yield return new WaitWhile(() => PhotonNetwork.InRoom);
  871. #endregion
  872. #region Exit from the lobby
  873. if (PhotonNetwork.InLobby)
  874. {
  875. PhotonNetwork.LeaveLobby();
  876. }
  877. yield return new WaitWhile(() => PhotonNetwork.InLobby);
  878. #endregion
  879. #region Disconnected from Photon
  880. if (PhotonNetwork.IsConnected)
  881. {
  882. PhotonNetwork.Disconnect();
  883. }
  884. yield return new WaitWhile(() => PhotonNetwork.IsConnected);
  885. #endregion
  886. }
  887. #endregion
  888. #region Connect to Photon server
  889. public static IEnumerator ConnectToMasterServerCoroutine()
  890. {
  891. if (!PhotonNetwork.IsConnected || ContinuousController.instance.LastConnectServerRegion != ContinuousController.instance.serverRegion)
  892. {
  893. if (PhotonNetwork.IsConnected)
  894. {
  895. yield return ContinuousController.instance.StartCoroutine(DisconnectCoroutine());
  896. yield return new WaitWhile(() => PhotonNetwork.IsConnected);
  897. }
  898. PhotonNetwork.NetworkingClient.AppId = PhotonNetwork.PhotonServerSettings.AppSettings.AppIdRealtime;
  899. PhotonNetwork.ConnectToRegion(ContinuousController.instance.serverRegion);
  900. PhotonNetwork.NickName = ContinuousController.instance.PlayerName;
  901. PhotonNetwork.GameVersion = ContinuousController.instance.GameVerString;
  902. ContinuousController.instance.LastConnectServerRegion = ContinuousController.instance.serverRegion;
  903. }
  904. yield return new WaitWhile(() => !PhotonNetwork.IsConnectedAndReady);
  905. }
  906. #endregion
  907. #region Connect to Photon Server and Lobby
  908. public static IEnumerator ConnectToLobbyCoroutine()
  909. {
  910. #region Connect to Photon server
  911. yield return ContinuousController.instance.StartCoroutine(ConnectToMasterServerCoroutine());
  912. #endregion
  913. #region Save player name to custom properties
  914. yield return ContinuousController.instance.StartCoroutine(SetPlayerName());
  915. #endregion
  916. #region Save the number of wins to a custom property
  917. Hashtable hash = PhotonNetwork.LocalPlayer.CustomProperties;
  918. object value;
  919. hash = PhotonNetwork.LocalPlayer.CustomProperties;
  920. if (hash.TryGetValue(ContinuousController.WinCountKey, out value))
  921. {
  922. hash[ContinuousController.WinCountKey] = ContinuousController.instance.WinCount;
  923. }
  924. else
  925. {
  926. hash.Add(ContinuousController.WinCountKey, ContinuousController.instance.WinCount);
  927. }
  928. PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
  929. while (true)
  930. {
  931. Hashtable _hash = PhotonNetwork.LocalPlayer.CustomProperties;
  932. if (_hash.TryGetValue(ContinuousController.WinCountKey, out value))
  933. {
  934. if ((int)value == ContinuousController.instance.WinCount)
  935. {
  936. break;
  937. }
  938. }
  939. yield return null;
  940. }
  941. #endregion
  942. #region Connect to Lobby
  943. if (!PhotonNetwork.InLobby)
  944. {
  945. PhotonNetwork.JoinLobby();
  946. }
  947. yield return new WaitWhile(() => !PhotonNetwork.InLobby);
  948. yield return new WaitUntil(() => PhotonNetwork.InLobby && PhotonNetwork.IsConnectedAndReady);
  949. #endregion
  950. }
  951. #endregion
  952. #region Save player name to properties
  953. public static IEnumerator SetPlayerName()
  954. {
  955. Hashtable hash = PhotonNetwork.LocalPlayer.CustomProperties;
  956. object value;
  957. hash = PhotonNetwork.LocalPlayer.CustomProperties;
  958. if (hash.TryGetValue(ContinuousController.PlayerNameKey, out value))
  959. {
  960. hash[ContinuousController.PlayerNameKey] = ContinuousController.instance.PlayerName;
  961. }
  962. else
  963. {
  964. hash.Add(ContinuousController.PlayerNameKey, ContinuousController.instance.PlayerName);
  965. }
  966. PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
  967. while (true)
  968. {
  969. Hashtable _hash = PhotonNetwork.LocalPlayer.CustomProperties;
  970. if (_hash.TryGetValue(ContinuousController.PlayerNameKey, out value))
  971. {
  972. if ((string)value == ContinuousController.instance.PlayerName)
  973. {
  974. break;
  975. }
  976. }
  977. yield return null;
  978. }
  979. }
  980. #endregion
  981. #region Save deck data to custom properties
  982. public static IEnumerator SignUpBattleDeckData()
  983. {
  984. Hashtable hash = PhotonNetwork.LocalPlayer.CustomProperties;
  985. if (hash.TryGetValue(ContinuousController.DeckDataPropertyKey, out object value))
  986. {
  987. hash[ContinuousController.DeckDataPropertyKey] = ContinuousController.instance.BattleDeckData.GetThisDeckCode();
  988. }
  989. else
  990. {
  991. hash.Add(ContinuousController.DeckDataPropertyKey, ContinuousController.instance.BattleDeckData.GetThisDeckCode());
  992. }
  993. //Debug.Log($"バトルデッキデータ登録,KeyCard:{ContinuousController.instance.BattleDeckData.KeyCard.CardName_JPN}");
  994. PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
  995. while (true)
  996. {
  997. Hashtable _hash = PhotonNetwork.LocalPlayer.CustomProperties;
  998. if (_hash.TryGetValue(ContinuousController.DeckDataPropertyKey, out value))
  999. {
  1000. if ((string)value == ContinuousController.instance.BattleDeckData.GetThisDeckCode())
  1001. {
  1002. break;
  1003. }
  1004. }
  1005. yield return null;
  1006. }
  1007. }
  1008. #endregion
  1009. #region Remove custom properties from deck data
  1010. public static IEnumerator DeleteBattleDeckData()
  1011. {
  1012. Hashtable hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1013. if (hash.TryGetValue(ContinuousController.DeckDataPropertyKey, out object value))
  1014. {
  1015. hash.Remove(ContinuousController.DeckDataPropertyKey);
  1016. }
  1017. PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
  1018. while (true)
  1019. {
  1020. Hashtable _hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1021. if (!_hash.TryGetValue(ContinuousController.DeckDataPropertyKey, out value))
  1022. {
  1023. break;
  1024. }
  1025. yield return null;
  1026. }
  1027. }
  1028. #endregion
  1029. }
  1030. #endregion
  1031. public enum Language
  1032. {
  1033. ENG,
  1034. JPN,
  1035. }