ContinuousController.cs 39 KB

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