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