ContinuousController.cs 39 KB

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