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