ContinuousController.cs 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277
  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. //TODO: Setting default to false, to fix animation syncing bug, MB
  429. showCutInAnimation = false;
  430. //showCutInAnimation = PlayerPrefsUtil.GetBool(_showCutInAnimationKey, true);
  431. }
  432. #endregion
  433. #region Reverse opponents' cards
  434. [HideInInspector] public bool reverseOpponentsCards = false;
  435. string _reverseOpponentsCardsKey = "ReverseOpponentsCards";
  436. public void SaveReverseOpponentsCards()
  437. {
  438. PlayerPrefsUtil.SetBool(_reverseOpponentsCardsKey, reverseOpponentsCards);
  439. PlayerPrefs.Save();
  440. }
  441. public void LoadReverseOpponentsCards()
  442. {
  443. reverseOpponentsCards = PlayerPrefsUtil.GetBool(_reverseOpponentsCardsKey, false);
  444. }
  445. #endregion
  446. #region Turn suspended cards
  447. [HideInInspector] public bool turnSuspendedCards = false;
  448. string _turnSuspendedCardsKey = "TurnSuspendedCards";
  449. public void SaveTurnSuspendedCards()
  450. {
  451. PlayerPrefsUtil.SetBool(_turnSuspendedCardsKey, turnSuspendedCards);
  452. PlayerPrefs.Save();
  453. }
  454. public void LoadTurnSuspendedCards()
  455. {
  456. turnSuspendedCards = PlayerPrefsUtil.GetBool(_turnSuspendedCardsKey, true);
  457. }
  458. #endregion
  459. #region Check before ending selection
  460. [HideInInspector] public bool checkBeforeEndingSelection = false;
  461. string _checkBeforeEndingSelectionKey = "CheckBeforeEndingSelection";
  462. public void SaveCheckBeforeEndingSelection()
  463. {
  464. PlayerPrefsUtil.SetBool(_checkBeforeEndingSelectionKey, checkBeforeEndingSelection);
  465. PlayerPrefs.Save();
  466. }
  467. public void LoadCheckBeforeEndingSelection()
  468. {
  469. checkBeforeEndingSelection = PlayerPrefsUtil.GetBool(_checkBeforeEndingSelectionKey, true);
  470. }
  471. #endregion
  472. #region Suspended cards' direction is left
  473. [HideInInspector] public bool suspendedCardsDirectionIsLeft = false;
  474. string _suspendedCardsDirectionIsLeftKey = "SuspendedCardsDirectionIsLeft";
  475. public void SaveSuspendedCardsDirectionIsLeft()
  476. {
  477. PlayerPrefsUtil.SetBool(_suspendedCardsDirectionIsLeftKey, suspendedCardsDirectionIsLeft);
  478. PlayerPrefs.Save();
  479. }
  480. public void LoadSuspendedCardsDirectionIsLeft()
  481. {
  482. suspendedCardsDirectionIsLeft = PlayerPrefsUtil.GetBool(_suspendedCardsDirectionIsLeftKey, true);
  483. }
  484. #endregion
  485. #region Show background particle
  486. [HideInInspector] public bool showBackgroundParticle = false;
  487. string _showBackgroundParticleKey = "ShowBackgroundParticle";
  488. public void SaveShowBackgroundParticle()
  489. {
  490. PlayerPrefsUtil.SetBool(_showBackgroundParticleKey, showBackgroundParticle);
  491. PlayerPrefs.Save();
  492. }
  493. public void LoadShowBackgroundParticle()
  494. {
  495. showBackgroundParticle = PlayerPrefsUtil.GetBool(_showBackgroundParticleKey, true);
  496. }
  497. #endregion
  498. #region Sound volume
  499. public float BGMVolume { get; set; }
  500. public float SEVolume { get; set; }
  501. public void SetBGMVolume(float BGMVolume)
  502. {
  503. this.BGMVolume = BGMVolume;
  504. PlayerPrefs.SetFloat("BGMVolume", BGMVolume);
  505. PlayerPrefs.Save();
  506. }
  507. public void SetSEVolume(float SEVolume)
  508. {
  509. this.SEVolume = SEVolume;
  510. PlayerPrefs.SetFloat("SEVolume", SEVolume);
  511. PlayerPrefs.Save();
  512. }
  513. public void ChangeBGMVolume(AudioSource audioSource)
  514. {
  515. audioSource.volume = BGMVolume * 0.25f * 0.8f;
  516. }
  517. public void ChangeSEVolume(AudioSource audioSource)
  518. {
  519. audioSource.volume = SEVolume * 0.5f * 0.8f;
  520. }
  521. void LoadVolume()
  522. {
  523. BGMVolume = 0.5f;
  524. SEVolume = 0.5f;
  525. if (PlayerPrefs.HasKey("BGMVolume"))
  526. {
  527. BGMVolume = PlayerPrefs.GetFloat("BGMVolume");
  528. }
  529. if (PlayerPrefs.HasKey("SEVolume"))
  530. {
  531. SEVolume = PlayerPrefs.GetFloat("SEVolume");
  532. }
  533. }
  534. #endregion
  535. #region Server region
  536. [HideInInspector] public string serverRegion = "us";
  537. string _serverRegionKey = "ServerRegion";
  538. public void SaveServerRegion()
  539. {
  540. PlayerPrefs.SetString(_serverRegionKey, serverRegion);
  541. PlayerPrefs.Save();
  542. }
  543. public void LoadServerRegion()
  544. {
  545. serverRegion = PlayerPrefs.GetString(_serverRegionKey, "us");
  546. }
  547. public string LastConnectServerRegion = "";
  548. #endregion
  549. #region Language
  550. [HideInInspector] public Language language = Language.ENG;
  551. string _languageKey = "Language";
  552. public void SaveLanguage()
  553. {
  554. PlayerPrefs.SetString(_languageKey, language.ToString());
  555. PlayerPrefs.Save();
  556. }
  557. public void LoadLanguage()
  558. {
  559. language = (Language)Enum.Parse(typeof(Language), PlayerPrefs.GetString(_languageKey, "ENG"));
  560. }
  561. #endregion
  562. #region PlaySE(AudioClip clip)
  563. public SoundObject PlaySE(AudioClip clip)
  564. {
  565. SoundObject _soundObject = Instantiate(soundObject);
  566. _soundObject.PlaySE(clip);
  567. return _soundObject;
  568. }
  569. #endregion
  570. #region カードIndexからカードを取得
  571. public CEntity_Base getCardEntityByCardID(int cardIndex)
  572. {
  573. int searchIndex = cardIndex - 1;
  574. int count = 0;
  575. do
  576. {
  577. if (count != 0)
  578. {
  579. searchIndex += (int)Math.Pow(-1, count % 2) * count / 2;
  580. }
  581. if (0 <= searchIndex)
  582. {
  583. if (searchIndex <= SortedCardList.Length - 1)
  584. {
  585. CEntity_Base cEntity_Base = SortedCardList[searchIndex];
  586. if (cEntity_Base != null)
  587. {
  588. if (cEntity_Base.CardIndex == cardIndex)
  589. {
  590. return cEntity_Base;
  591. }
  592. }
  593. }
  594. else
  595. {
  596. for (int i = 0; i < 300; i++)
  597. {
  598. CEntity_Base cEntity_Base = SortedCardList[SortedCardList.Length - 1 - i];
  599. if (cEntity_Base != null)
  600. {
  601. if (cEntity_Base.CardIndex == cardIndex)
  602. {
  603. return cEntity_Base;
  604. }
  605. }
  606. }
  607. return null;
  608. }
  609. }
  610. if (count != 0)
  611. {
  612. searchIndex -= (int)Math.Pow(-1, count % 2) * count / 2;
  613. }
  614. count++;
  615. }
  616. while (count <= 20);
  617. return null;
  618. }
  619. #endregion
  620. public Coroutine LoadingTextCoroutine;
  621. bool _endBattle = false;
  622. public void EndBattle()
  623. {
  624. if (!_endBattle)
  625. {
  626. _endBattle = true;
  627. StartCoroutine(EndBattleCoroutine());
  628. }
  629. }
  630. public IEnumerator EndBattleCoroutine()
  631. {
  632. if (Opening.instance == null)
  633. {
  634. yield break;
  635. }
  636. Opening.instance.openingObject.SetActive(true);
  637. //yield return StartCoroutine(Opening.instance.LoadingObject_Unload.StartLoading("Now Loading"));
  638. //Camera camera1 = Camera.main;
  639. //Destroy(camera1.gameObject);
  640. //yield return null;
  641. isAI = false;
  642. int random = RandomUtility.getRamdom();
  643. UnityEngine.Random.InitState(random);
  644. Debug.Log($"random number sequence initialization, InitState:{random}");
  645. var unload = SceneManager.UnloadSceneAsync("BattleScene");
  646. yield return unload;
  647. yield return Resources.UnloadUnusedAssets();
  648. yield return StartCoroutine(Opening.instance.LoadingObject_Unload.StartLoading("Now Loading"));
  649. //Opening.instance.MainCamera.gameObject.SetActive(true);
  650. foreach (Camera camera in Opening.instance.openingCameras)
  651. {
  652. camera.gameObject.SetActive(true);
  653. }
  654. Opening.instance.LoadingObject_light.gameObject.SetActive(false);
  655. yield return ContinuousController.instance.StartCoroutine(PhotonUtility.SetPlayerName());
  656. if (isRandomMatch)
  657. {
  658. Debug.Log("Unload from Random Match");
  659. yield return StartCoroutine(Opening.instance.battle.lobbyManager_RandomMatch.CloseLobbyCoroutine());
  660. yield return StartCoroutine(Opening.instance.battle.selectBattleMode.SetUpSelectBattleModeCoroutine());
  661. }
  662. else
  663. {
  664. Debug.Log("Unload from Room Match");
  665. yield return StartCoroutine(Opening.instance.battle.roomManager.Init(true));
  666. yield return new WaitForSeconds(0.1f);
  667. }
  668. yield return new WaitWhile(() => GManager.instance != null);
  669. Opening.instance.LoadingObject.gameObject.SetActive(false);
  670. yield return StartCoroutine(Opening.instance.LoadingObject_Unload.EndLoading());
  671. _endBattle = false;
  672. if (!isRandomMatch)
  673. {
  674. Hashtable PlayerProp = PhotonNetwork.LocalPlayer.CustomProperties;
  675. if (PlayerProp.TryGetValue("isBattle", out object value))
  676. {
  677. PlayerProp["isBattle"] = false;
  678. }
  679. else
  680. {
  681. PlayerProp.Add("isBattle", false);
  682. }
  683. PhotonNetwork.LocalPlayer.SetCustomProperties(PlayerProp);
  684. }
  685. Scene newScene = SceneManager.GetSceneByName("Opening");
  686. SceneManager.SetActiveScene(newScene);
  687. for (int i = 0; i < 3; i++)
  688. {
  689. yield return new WaitForSeconds(0.1f);
  690. EventSystem.current.SetSelectedGameObject(Opening.instance.battle.selectBattleMode.transform.GetChild(0).gameObject);
  691. //Debug.Log("フォーカスを設定");
  692. }
  693. //GUI.UnfocusWindow();
  694. yield return null;
  695. //StartCoroutine(DestroyEffectCoroutine());
  696. if (Opening.instance.OpeningBGM != null)
  697. {
  698. if (!Opening.instance.OpeningBGM.isPlaying)
  699. {
  700. Opening.instance.OpeningBGM.StartPlayBGM(Opening.instance.bgm);
  701. }
  702. }
  703. }
  704. private void Update()
  705. {
  706. #if UNITY_WINDOWS
  707. if (Input.GetKey(KeyCode.Escape))
  708. {
  709. Application.Quit();
  710. }
  711. #endif
  712. }
  713. int _frameCount = 0;
  714. int _updateFrame = 40;
  715. void LateUpdate()
  716. {
  717. #region Update only once every few frames
  718. _frameCount++;
  719. if (_frameCount < _updateFrame)
  720. {
  721. return;
  722. }
  723. else
  724. {
  725. _frameCount = 0;
  726. }
  727. #endregion
  728. if (PhotonNetwork.InRoom)
  729. {
  730. if (!isAI)
  731. {
  732. bool notEnterOther = false;
  733. if (PhotonNetwork.PlayerList.Length == 1)
  734. {
  735. if (GManager.instance != null)
  736. {
  737. notEnterOther = true;
  738. }
  739. }
  740. if (notEnterOther)
  741. {
  742. if (PhotonNetwork.CurrentRoom.MaxPlayers != 1)
  743. {
  744. PhotonNetwork.CurrentRoom.MaxPlayers = 1;
  745. }
  746. }
  747. else
  748. {
  749. if (PhotonNetwork.CurrentRoom.MaxPlayers != 2)
  750. {
  751. PhotonNetwork.CurrentRoom.MaxPlayers = 2;
  752. }
  753. }
  754. }
  755. }
  756. }
  757. public bool isAI { get; set; } = false;
  758. //Flag that the sharing of the random number sequence is over.
  759. public bool DoneSetRandom { get; set; } = false;
  760. public bool CanSetRandom { get; set; } = false;
  761. [PunRPC]
  762. public void SetRandom(int random)
  763. {
  764. StartCoroutine(SetRandomCoroutine(random));
  765. }
  766. IEnumerator SetRandomCoroutine(int random)
  767. {
  768. yield return new WaitWhile(() => !CanSetRandom);
  769. UnityEngine.Random.InitState(random);
  770. DoneSetRandom = true;
  771. Debug.Log($"random number sequence initialization,InitState:{random}");
  772. }
  773. }
  774. #region Manage random numbers
  775. public static class RandomUtility
  776. {
  777. private static System.Random random;
  778. public static int getRamdom()
  779. {
  780. int _max = 1500000000;
  781. if (random == null)
  782. {
  783. random = new System.Random((int)DateTime.Now.Ticks);
  784. }
  785. return random.Next(0, _max);
  786. }
  787. #region IsSucceedProbability(float Probability)
  788. public static bool IsSucceedProbability(float Probability)
  789. {
  790. if (Probability >= 1)
  791. {
  792. return true;
  793. }
  794. if (Probability <= 0)
  795. {
  796. return false;
  797. }
  798. float random = UnityEngine.Random.Range(0f, 1f);
  799. if (random <= Probability)
  800. {
  801. return true;
  802. }
  803. return false;
  804. }
  805. #endregion
  806. #region Shuffle the deck
  807. public static List<CEntity_Base> ShuffledDeckCards(List<CEntity_Base> DeckCards)
  808. {
  809. List<CEntity_Base> CardDatas = new List<CEntity_Base>();
  810. foreach (CEntity_Base cEntity_Base in DeckCards)
  811. {
  812. CardDatas.Add(cEntity_Base);
  813. }
  814. // The initial value of integer n is the number of cards in the deck
  815. int n = CardDatas.Count;
  816. for (int i = 0; i < 20; i++)
  817. {
  818. // Repeat until n is less than 1
  819. while (n > 1)
  820. {
  821. n--;
  822. // k is a random value between 0 and n+1
  823. int k = UnityEngine.Random.Range(0, n + 1);
  824. // Assign the kth card to temp
  825. CEntity_Base temp = CardDatas[k];
  826. CardDatas[k] = CardDatas[n];
  827. CardDatas[n] = temp;
  828. }
  829. }
  830. return CardDatas;
  831. }
  832. public static List<CardSource> ShuffledDeckCards(List<CardSource> DeckCards)
  833. {
  834. List<CardSource> CardDatas = new List<CardSource>();
  835. foreach (CardSource cardSource in DeckCards)
  836. {
  837. CardDatas.Add(cardSource);
  838. }
  839. // 整数 n の初期値はデッキの枚数
  840. int n = CardDatas.Count;
  841. for (int i = 0; i < 20; i++)
  842. {
  843. // nが1より小さくなるまで繰り返す
  844. while (n > 1)
  845. {
  846. n--;
  847. // kは 0 ~ n+1 の間のランダムな値
  848. int k = UnityEngine.Random.Range(0, n + 1);
  849. // k番目のカードをtempに代入
  850. CardSource temp = CardDatas[k];
  851. CardDatas[k] = CardDatas[n];
  852. CardDatas[n] = temp;
  853. }
  854. }
  855. return CardDatas;
  856. }
  857. #endregion
  858. }
  859. #endregion
  860. #region Manage connections to Photon
  861. public class PhotonUtility
  862. {
  863. #region Disconnected from Photon
  864. public static IEnumerator DisconnectCoroutine()
  865. {
  866. #region Exit Room
  867. if (PhotonNetwork.InRoom)
  868. {
  869. PhotonNetwork.LeaveRoom();
  870. }
  871. yield return new WaitWhile(() => PhotonNetwork.InRoom);
  872. #endregion
  873. #region Exit from the lobby
  874. if (PhotonNetwork.InLobby)
  875. {
  876. PhotonNetwork.LeaveLobby();
  877. }
  878. yield return new WaitWhile(() => PhotonNetwork.InLobby);
  879. #endregion
  880. #region Disconnected from Photon
  881. if (PhotonNetwork.IsConnected)
  882. {
  883. PhotonNetwork.Disconnect();
  884. }
  885. yield return new WaitWhile(() => PhotonNetwork.IsConnected);
  886. #endregion
  887. }
  888. #endregion
  889. #region Connect to Photon server
  890. public static IEnumerator ConnectToMasterServerCoroutine()
  891. {
  892. if (!PhotonNetwork.IsConnected || ContinuousController.instance.LastConnectServerRegion != ContinuousController.instance.serverRegion)
  893. {
  894. if (PhotonNetwork.IsConnected)
  895. {
  896. yield return ContinuousController.instance.StartCoroutine(DisconnectCoroutine());
  897. yield return new WaitWhile(() => PhotonNetwork.IsConnected);
  898. }
  899. PhotonNetwork.NetworkingClient.AppId = PhotonNetwork.PhotonServerSettings.AppSettings.AppIdRealtime;
  900. PhotonNetwork.ConnectToRegion(ContinuousController.instance.serverRegion);
  901. PhotonNetwork.NickName = ContinuousController.instance.PlayerName;
  902. PhotonNetwork.GameVersion = ContinuousController.instance.GameVerString;
  903. ContinuousController.instance.LastConnectServerRegion = ContinuousController.instance.serverRegion;
  904. }
  905. yield return new WaitWhile(() => !PhotonNetwork.IsConnectedAndReady);
  906. }
  907. #endregion
  908. #region Connect to Photon Server and Lobby
  909. public static IEnumerator ConnectToLobbyCoroutine()
  910. {
  911. #region Connect to Photon server
  912. yield return ContinuousController.instance.StartCoroutine(ConnectToMasterServerCoroutine());
  913. #endregion
  914. #region Save player name to custom properties
  915. yield return ContinuousController.instance.StartCoroutine(SetPlayerName());
  916. #endregion
  917. #region Save the number of wins to a custom property
  918. Hashtable hash = PhotonNetwork.LocalPlayer.CustomProperties;
  919. object value;
  920. hash = PhotonNetwork.LocalPlayer.CustomProperties;
  921. if (hash.TryGetValue(ContinuousController.WinCountKey, out value))
  922. {
  923. hash[ContinuousController.WinCountKey] = ContinuousController.instance.WinCount;
  924. }
  925. else
  926. {
  927. hash.Add(ContinuousController.WinCountKey, ContinuousController.instance.WinCount);
  928. }
  929. PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
  930. while (true)
  931. {
  932. Hashtable _hash = PhotonNetwork.LocalPlayer.CustomProperties;
  933. if (_hash.TryGetValue(ContinuousController.WinCountKey, out value))
  934. {
  935. if ((int)value == ContinuousController.instance.WinCount)
  936. {
  937. break;
  938. }
  939. }
  940. yield return null;
  941. }
  942. #endregion
  943. #region Connect to Lobby
  944. if (!PhotonNetwork.InLobby)
  945. {
  946. PhotonNetwork.JoinLobby();
  947. }
  948. yield return new WaitWhile(() => !PhotonNetwork.InLobby);
  949. yield return new WaitUntil(() => PhotonNetwork.InLobby && PhotonNetwork.IsConnectedAndReady);
  950. #endregion
  951. }
  952. #endregion
  953. #region Save player name to properties
  954. public static IEnumerator SetPlayerName()
  955. {
  956. Hashtable hash = PhotonNetwork.LocalPlayer.CustomProperties;
  957. object value;
  958. hash = PhotonNetwork.LocalPlayer.CustomProperties;
  959. if (hash.TryGetValue(ContinuousController.PlayerNameKey, out value))
  960. {
  961. hash[ContinuousController.PlayerNameKey] = ContinuousController.instance.PlayerName;
  962. }
  963. else
  964. {
  965. hash.Add(ContinuousController.PlayerNameKey, ContinuousController.instance.PlayerName);
  966. }
  967. PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
  968. while (true)
  969. {
  970. Hashtable _hash = PhotonNetwork.LocalPlayer.CustomProperties;
  971. if (_hash.TryGetValue(ContinuousController.PlayerNameKey, out value))
  972. {
  973. if ((string)value == ContinuousController.instance.PlayerName)
  974. {
  975. break;
  976. }
  977. }
  978. yield return null;
  979. }
  980. }
  981. #endregion
  982. #region Save deck data to custom properties
  983. public static IEnumerator SignUpBattleDeckData()
  984. {
  985. Hashtable hash = PhotonNetwork.LocalPlayer.CustomProperties;
  986. if (hash.TryGetValue(ContinuousController.DeckDataPropertyKey, out object value))
  987. {
  988. hash[ContinuousController.DeckDataPropertyKey] = ContinuousController.instance.BattleDeckData.GetThisDeckCode();
  989. }
  990. else
  991. {
  992. hash.Add(ContinuousController.DeckDataPropertyKey, ContinuousController.instance.BattleDeckData.GetThisDeckCode());
  993. }
  994. //Debug.Log($"バトルデッキデータ登録,KeyCard:{ContinuousController.instance.BattleDeckData.KeyCard.CardName_JPN}");
  995. PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
  996. while (true)
  997. {
  998. Hashtable _hash = PhotonNetwork.LocalPlayer.CustomProperties;
  999. if (_hash.TryGetValue(ContinuousController.DeckDataPropertyKey, out value))
  1000. {
  1001. if ((string)value == ContinuousController.instance.BattleDeckData.GetThisDeckCode())
  1002. {
  1003. break;
  1004. }
  1005. }
  1006. yield return null;
  1007. }
  1008. }
  1009. #endregion
  1010. #region Remove custom properties from deck data
  1011. public static IEnumerator DeleteBattleDeckData()
  1012. {
  1013. Hashtable hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1014. if (hash.TryGetValue(ContinuousController.DeckDataPropertyKey, out object value))
  1015. {
  1016. hash.Remove(ContinuousController.DeckDataPropertyKey);
  1017. }
  1018. PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
  1019. while (true)
  1020. {
  1021. Hashtable _hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1022. if (!_hash.TryGetValue(ContinuousController.DeckDataPropertyKey, out value))
  1023. {
  1024. break;
  1025. }
  1026. yield return null;
  1027. }
  1028. }
  1029. #endregion
  1030. }
  1031. #endregion
  1032. public enum Language
  1033. {
  1034. ENG,
  1035. JPN,
  1036. }