ContinuousController.cs 40 KB

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