ContinuousController.cs 39 KB

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