ContinuousController.cs 35 KB

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