ContinuousController.cs 39 KB

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