ContinuousController.cs 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391
  1. using Photon.Pun;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Threading.Tasks;
  7. using UnityEngine;
  8. using UnityEngine.Events;
  9. using UnityEngine.EventSystems;
  10. using UnityEngine.SceneManagement;
  11. using Hashtable = ExitGames.Client.Photon.Hashtable;
  12. public class ContinuousController : MonoBehaviour
  13. {
  14. [Header("game language")]
  15. // public Language language;
  16. [Header("Game version")]
  17. public float GameVer;
  18. [Header("ignore updates")]
  19. public bool IgnoreUpdate;
  20. [Header("card list")]
  21. public CEntity_Base[] CardList = new CEntity_Base[] { };
  22. [Header("Card list sorted by card ID")]
  23. public CEntity_Base[] SortedCardList = new CEntity_Base[] { };
  24. [Header("Card back image")]
  25. public Sprite ReverseCard;
  26. public Sprite ReverseCard_Digitama;
  27. [Header("SE prefab")]
  28. public SoundObject soundObject;
  29. [Header("deck code encryption")]
  30. public ShuffleDeckCode ShuffleDeckCode;
  31. DeckData _battleDeckData = null;
  32. public DeckData BattleDeckData
  33. {
  34. get
  35. {
  36. return _battleDeckData;
  37. }
  38. set
  39. {
  40. _battleDeckData = value;
  41. if (value != null)
  42. {
  43. LastBattleDeckData = value;
  44. }
  45. }
  46. }
  47. public DeckData LastBattleDeckData { get; private set; } = null;
  48. public bool NeedUpdate { get; set; }
  49. public bool isRandomMatch { get; set; }
  50. [HideInInspector] public List<SkillInfo> nullSkillInfos = null;
  51. public String GameVerString => Application.version;//GameVer.ToString(CultureInfo.InvariantCulture);
  52. #region Key for property to save deck data for battle
  53. public static string DeckDataPropertyKey => "BattleDeckData";
  54. #endregion
  55. #region Key for the property that stores the player name data
  56. public static string PlayerNameKey => "PlayerNameKey";
  57. #endregion
  58. #region Key for the property that stores the win count data
  59. public static string WinCountKey => "WinCountKey";
  60. #endregion
  61. [Header("Player name character limit")]
  62. public int PlayerNameMaxLength;
  63. #region Call up a scene for data storage
  64. public static IEnumerator LoadCoroutine()
  65. {
  66. if (instance == null)
  67. {
  68. SceneManager.LoadSceneAsync("ContinuousControllerScene", LoadSceneMode.Additive);
  69. while (instance == null)
  70. {
  71. yield return null;
  72. }
  73. instance.Init();
  74. }
  75. }
  76. #endregion
  77. #region List of Deck Recipes
  78. public List<DeckData> DeckDatas { get; set; } = new List<DeckData>();
  79. #endregion
  80. #region Deck Recipe Key
  81. public string DeckDatasPlayerPrefsKey { get { return "DeckDatas3"; } }
  82. #endregion
  83. public CEntity_Base DiaboromonToken { get; private set; }
  84. public CEntity_Base AmonToken { get; private set; }
  85. public CEntity_Base UmonToken { get; private set; }
  86. public CEntity_Base FujitsumonToken { get; private set; }
  87. public CEntity_Base GyuukimonToken { get; private set; }
  88. public CEntity_Base KoHagurumonToken { get; private set; }
  89. public CardRestriction BanList { get; private set; } = new CardRestriction(new List<CardLimitCount>(), new List<BannedPair>());
  90. void LoadBanList()
  91. {
  92. BanList = DataBase.ENGBanList;
  93. }
  94. async Task CreateTokenData()
  95. {
  96. DiaboromonToken = new CEntity_Base()
  97. {
  98. cardColors = new List<CardColor>() { CardColor.White },
  99. PlayCost = 14,
  100. Level = 6,
  101. CardName_JPN = "ディアボロモン",
  102. CardName_ENG = "Diaboromon",
  103. Form_JPN = new List<string>() { "究極体" },
  104. Form_ENG = new List<string>() { "Mega" },
  105. Attribute_JPN = new List<string>() { "不明" },
  106. Attribute_ENG = new List<string>() { "Unknown" },
  107. Type_JPN = new List<string>() { "種族不明" },
  108. Type_ENG = new List<string>() { "Unidentified" },
  109. CardSpriteName = "BT2-082-token",
  110. cardKind = CardKind.Digimon,
  111. DP = 3000,
  112. };
  113. await DiaboromonToken.GetCardSprite();
  114. AmonToken = new CEntity_Base()
  115. {
  116. cardColors = new List<CardColor>() { CardColor.Red },
  117. PlayCost = -1,
  118. Level = 0,
  119. CardName_JPN = "紅炎のアモン",
  120. CardName_ENG = "Amon of Crimson Flame",
  121. Form_JPN = new List<string>(),
  122. Form_ENG = new List<string>(),
  123. Attribute_JPN = new List<string>(),
  124. Attribute_ENG = new List<string>(),
  125. Type_JPN = new List<string>(),
  126. Type_ENG = new List<string>(),
  127. CardSpriteName = "BT14-018-token-red",
  128. cardKind = CardKind.Digimon,
  129. DP = 6000,
  130. CardEffectClassName = "Bushiagumon_BT4_038"
  131. };
  132. await AmonToken.GetCardSprite();
  133. UmonToken = new CEntity_Base()
  134. {
  135. cardColors = new List<CardColor>() { CardColor.Yellow },
  136. PlayCost = -1,
  137. Level = 0,
  138. CardName_JPN = "蒼雷のウモン",
  139. CardName_ENG = "Umon of Blue Thunder",
  140. Form_JPN = new List<string>(),
  141. Form_ENG = new List<string>(),
  142. Attribute_JPN = new List<string>(),
  143. Attribute_ENG = new List<string>(),
  144. Type_JPN = new List<string>(),
  145. Type_ENG = new List<string>(),
  146. CardSpriteName = "BT14-018-token-yellow",
  147. cardKind = CardKind.Digimon,
  148. DP = 6000,
  149. CardEffectClassName = "Koemon_BT1_031"
  150. };
  151. await UmonToken.GetCardSprite();
  152. FujitsumonToken = new CEntity_Base()
  153. {
  154. cardColors = new List<CardColor>() { CardColor.Purple },
  155. PlayCost = -1,
  156. Level = 0,
  157. CardName_JPN = "フジツモン",
  158. CardName_ENG = "Fujitsumon",
  159. Form_JPN = new List<string>(),
  160. Form_ENG = new List<string>(),
  161. Attribute_JPN = new List<string>(),
  162. Attribute_ENG = new List<string>(),
  163. Type_JPN = new List<string>(),
  164. Type_ENG = new List<string>(),
  165. CardSpriteName = "EX5-058-token",
  166. cardKind = CardKind.Digimon,
  167. DP = 3000,
  168. CardEffectClassName = "Fujitsumon_EX5_058_token"
  169. };
  170. await FujitsumonToken.GetCardSprite();
  171. GyuukimonToken = new CEntity_Base()
  172. {
  173. cardColors = new List<CardColor>() { CardColor.Purple },
  174. PlayCost = 7,
  175. Level = 5,
  176. CardName_JPN = "ギュウキモン",
  177. CardName_ENG = "Gyuukimon",
  178. Form_JPN = new List<string>() { "究極の" },
  179. Form_ENG = new List<string>() { "Ultimate" },
  180. Attribute_JPN = new List<string>() { "ウイルス" },
  181. Attribute_ENG = new List<string>() { "Virus" },
  182. Type_JPN = new List<string>() { "ダークアニマル" },
  183. Type_ENG = new List<string>() { "Dark Animal" },
  184. CardSpriteName = "LM-018-token",
  185. cardKind = CardKind.Digimon,
  186. DP = 3000,
  187. };
  188. await GyuukimonToken.GetCardSprite();
  189. KoHagurumonToken = new CEntity_Base()
  190. {
  191. cardColors = new List<CardColor>() { CardColor.Black },
  192. PlayCost = -1,
  193. Level = 0,
  194. CardName_JPN = "",
  195. CardName_ENG = "KoHagurumon",
  196. Form_JPN = new List<string>(),
  197. Form_ENG = new List<string>(),
  198. Attribute_JPN = new List<string>(),
  199. Attribute_ENG = new List<string>(),
  200. Type_JPN = new List<string>(),
  201. Type_ENG = new List<string>(),
  202. CardSpriteName = "BT16-052-token",
  203. cardKind = CardKind.Digimon,
  204. DP = 1000,
  205. CardEffectClassName = "KoHagurumon_BT16_052_token"
  206. };
  207. await KoHagurumonToken.GetCardSprite();
  208. }
  209. public static ContinuousController instance = null;
  210. private void Awake()
  211. {
  212. instance = this;
  213. }
  214. public async void Init()
  215. {
  216. Application.targetFrameRate = 60;
  217. int random = RandomUtility.getRamdom();
  218. UnityEngine.Random.InitState(random);
  219. Debug.Log($"Game Initialize - random number sequence initialization,InitState:{random}");
  220. Sprite reverseCardSprite = await StreamingAssetsUtility.GetSprite("card_back_main");
  221. if (reverseCardSprite != null)
  222. {
  223. ReverseCard = reverseCardSprite;
  224. }
  225. Sprite reverseDigieggCardSprite = await StreamingAssetsUtility.GetSprite("card_back_sub");
  226. if (reverseDigieggCardSprite != null)
  227. {
  228. ReverseCard_Digitama = reverseDigieggCardSprite;
  229. }
  230. // deck data
  231. //DeckDatas = PlayerPrefsUtil.LoadList<DeckData>(DeckDatasPlayerPrefsKey);
  232. LoadDeckLists();
  233. GetComponent<StarterDeck>().SetStarterDecks();
  234. // player data
  235. LoadPlayerName();
  236. LoadWinCount();
  237. // game play
  238. LoadAutoEffectOrder();
  239. LoadAutoDeckBottomOrder();
  240. LoadAutoDeckTopOrder();
  241. LoadAutoMinDigivolutionCost();
  242. LoadAutoMaxCardCount();
  243. LoadAutoHatch();
  244. LoadShowCutInAnimation();
  245. LoadReverseOpponentsCards();
  246. LoadTurnSuspendedCards();
  247. LoadCheckBeforeEndingSelection();
  248. LoadSuspendedCardsDirectionIsLeft();
  249. //Graphics
  250. LoadShowBackgroundParticle();
  251. // Sound
  252. LoadVolume();
  253. // ServerRegion
  254. LoadServerRegion();
  255. // Language
  256. LoadLanguage();
  257. await CreateTokenData();
  258. LoadBanList();
  259. DontDestroyOnLoad(gameObject);
  260. }
  261. [Obsolete("This is obsolete, switching to save files")]
  262. public void ModifyAllDeckDatas()
  263. {
  264. List<DeckData> tempDeckDatas = new List<DeckData>();
  265. foreach (DeckData deckData in DeckDatas)
  266. {
  267. tempDeckDatas.Add(deckData);
  268. }
  269. foreach (DeckData deckData in tempDeckDatas)
  270. {
  271. if (deckData.AllDeckCards().Count == 0)
  272. {
  273. DeckDatas.Remove(deckData);
  274. }
  275. }
  276. for (int i = 0; i < DeckDatas.Count; i++)
  277. {
  278. //DeckData deckData = new DeckData(DeckData.GetDeckCode(DeckDatas[i].DeckName, DeckData.SortedDeckCardsList(DeckDatas[i].DeckCards()), DeckData.SortedDeckCardsList(DeckDatas[i].DigitamaDeckCards()), DeckDatas[i].KeyCard));
  279. DeckData deckData = DeckDatas[i];
  280. DeckDatas[i] = deckData.ModifiedDeckData();
  281. }
  282. SaveDeckDatas();
  283. }
  284. [Obsolete("This is obsolete, switching to save files")]
  285. public void SaveDeckDatas()
  286. {
  287. PlayerPrefsUtil.SaveList(DeckDatasPlayerPrefsKey, DeckDatas);
  288. PlayerPrefs.Save();
  289. }
  290. public void SaveDeckData(DeckData data)
  291. {
  292. string savePath = StreamingAssetsUtility.GetStreamingAssetPath("Decks", false);
  293. File.WriteAllText($"{savePath}/{data.DeckName}_{data.DeckID}.txt", DeckCodeUtility.GetDeckBuilderFile(data));
  294. }
  295. public void RenameDeck(DeckData data, string newName)
  296. {
  297. string savePath = StreamingAssetsUtility.GetStreamingAssetPath("Decks", false);
  298. if (File.Exists($"{savePath}/{data.DeckName}_{data.DeckID}.txt"))
  299. {
  300. File.Move($"{savePath}/{data.DeckName}_{data.DeckID}.txt", $"{savePath}/{newName}_{data.DeckID}.txt");
  301. data.DeckName = newName;
  302. SaveDeckData(data);
  303. }
  304. else
  305. data.DeckName = newName;
  306. }
  307. public void DeleteDeck(DeckData data)
  308. {
  309. string filePath = StreamingAssetsUtility.GetStreamingAssetPath("Decks", false);
  310. if (!Directory.Exists(filePath))
  311. return;
  312. if (!File.Exists($"{filePath}/{data.DeckName}_{data.DeckID}.txt"))
  313. return;
  314. File.Delete($"{filePath}/{data.DeckName}_{data.DeckID}.txt");
  315. }
  316. public void DeleteAllDecks()
  317. {
  318. foreach(DeckData data in DeckDatas)
  319. {
  320. DeleteDeck(data);
  321. }
  322. }
  323. public void LoadDeckLists()
  324. {
  325. string loadPath = StreamingAssetsUtility.GetStreamingAssetPath("Decks", false);
  326. if (!Directory.Exists(loadPath))
  327. return;
  328. string[] deckLists = Directory.GetFiles(loadPath);
  329. foreach(string deckPath in deckLists)
  330. {
  331. string fileName = Path.GetFileNameWithoutExtension(deckPath);
  332. if (!fileName.Contains("_"))
  333. continue;
  334. string deckList = File.ReadAllText(deckPath);
  335. StreamReader sr = new StreamReader(deckPath);
  336. string deckName = sr.ReadLine().Replace("Name: ", "");
  337. int KeyCard = int.Parse(sr.ReadLine().Replace("Key Card: ", ""));
  338. int SortValue = int.Parse(sr.ReadLine().Replace("Sort Index: ", ""));
  339. sr.Close();
  340. string deck = deckList.Substring(deckList.IndexOf("//"));
  341. //Debug.Log(deckName);
  342. if(SortValue < 0)
  343. SortValue = 0;
  344. CreateDeckFromFile(fileName.Split("_")[1], deckName, KeyCard, deck, SortValue);
  345. }
  346. }
  347. private void CreateDeckFromFile(string id, string name, int keyID, string deckCode, int index = 0)
  348. {
  349. List<CEntity_Base> AllDeckCards = DeckCodeUtility.GetAllDeckCardsFromDeckBuilderDeckCode(deckCode);
  350. if (AllDeckCards.Count == 0)
  351. {
  352. AllDeckCards = DeckCodeUtility.GetAllDeckCardsFromTTSDeckCode(deckCode);
  353. }
  354. List<CEntity_Base> deckCards = new List<CEntity_Base>();
  355. List<CEntity_Base> digitamaDeckCards = new List<CEntity_Base>();
  356. foreach (CEntity_Base cEntity_Base in AllDeckCards)
  357. {
  358. if (cEntity_Base.cardKind == CardKind.DigiEgg)
  359. {
  360. digitamaDeckCards.Add(cEntity_Base);
  361. }
  362. else
  363. {
  364. deckCards.Add(cEntity_Base);
  365. }
  366. }
  367. DeckData deckData = (new DeckData(DeckData.GetDeckCode(name, deckCards, digitamaDeckCards, null),id)).ModifiedDeckData();
  368. deckData.KeyCardId = keyID;
  369. deckData.DeckName = name;
  370. deckData.SortValue = index;
  371. DeckDatas.Insert(index, deckData);
  372. }
  373. #region Player Name
  374. string _playerName;
  375. string _playerNameKey = "PlayerName";
  376. public string PlayerName
  377. {
  378. get
  379. {
  380. if (string.IsNullOrEmpty(_playerName))
  381. {
  382. return "Player";
  383. }
  384. return _playerName;
  385. }
  386. set
  387. {
  388. _playerName = DeckData.ValidateDeckName(value);
  389. }
  390. }
  391. public void SavePlayerName(string playerName)
  392. {
  393. PlayerName = playerName;
  394. PlayerPrefs.SetString(_playerNameKey, playerName);
  395. PlayerPrefs.Save();
  396. }
  397. public void LoadPlayerName()
  398. {
  399. if (PlayerPrefs.HasKey(_playerNameKey))
  400. {
  401. PlayerName = PlayerPrefs.GetString(_playerNameKey);
  402. }
  403. if (string.IsNullOrEmpty(PlayerName))
  404. {
  405. PlayerName = "Player";
  406. }
  407. }
  408. #endregion
  409. #region number of victories
  410. public int WinCount { get; set; }
  411. string _winCountKey = "WinCount";
  412. public void SaveWinCount()
  413. {
  414. PlayerPrefs.SetInt(_winCountKey, WinCount);
  415. PlayerPrefs.Save();
  416. }
  417. public void LoadWinCount()
  418. {
  419. if (PlayerPrefs.HasKey(_winCountKey))
  420. {
  421. WinCount = PlayerPrefs.GetInt(_winCountKey);
  422. }
  423. }
  424. #endregion
  425. #region Auto effect order
  426. [HideInInspector] public bool autoEffectOrder = false;
  427. string _autoEffectOrderKey = "AutoEffectOrder";
  428. public void SaveAutoEffectOrder()
  429. {
  430. PlayerPrefsUtil.SetBool(_autoEffectOrderKey, autoEffectOrder);
  431. PlayerPrefs.Save();
  432. }
  433. public void LoadAutoEffectOrder()
  434. {
  435. autoEffectOrder = PlayerPrefsUtil.GetBool(_autoEffectOrderKey, false);
  436. }
  437. #endregion
  438. #region Auto deck bottom order
  439. [HideInInspector] public bool autoDeckBottomOrder = false;
  440. string _autoDeckBottomOrderKey = "AutoDeckBottomOrder";
  441. public void SaveAutoDeckBottomOrder()
  442. {
  443. PlayerPrefsUtil.SetBool(_autoDeckBottomOrderKey, autoDeckBottomOrder);
  444. PlayerPrefs.Save();
  445. }
  446. public void LoadAutoDeckBottomOrder()
  447. {
  448. autoDeckBottomOrder = PlayerPrefsUtil.GetBool(_autoDeckBottomOrderKey, false);
  449. }
  450. #endregion
  451. #region Auto deck top order
  452. [HideInInspector] public bool autoDeckTopOrder = false;
  453. string _autoDeckTopOrderKey = "AutoDeckTopOrder";
  454. public void SaveAutoDeckTopOrder()
  455. {
  456. PlayerPrefsUtil.SetBool(_autoDeckTopOrderKey, autoDeckTopOrder);
  457. PlayerPrefs.Save();
  458. }
  459. public void LoadAutoDeckTopOrder()
  460. {
  461. autoDeckTopOrder = PlayerPrefsUtil.GetBool(_autoDeckTopOrderKey, false);
  462. }
  463. #endregion
  464. #region Auto min digivolution cost
  465. [HideInInspector] public bool autoMinDigivolutionCost = false;
  466. string _autoMinDigivolutionCostKey = "AutoMinDigivolutionCost";
  467. public void SaveAutoMinDigivolutionCost()
  468. {
  469. PlayerPrefsUtil.SetBool(_autoMinDigivolutionCostKey, autoMinDigivolutionCost);
  470. PlayerPrefs.Save();
  471. }
  472. public void LoadAutoMinDigivolutionCost()
  473. {
  474. autoMinDigivolutionCost = PlayerPrefsUtil.GetBool(_autoMinDigivolutionCostKey, false);
  475. }
  476. #endregion
  477. #region Auto max card count
  478. [HideInInspector] public bool autoMaxCardCount = false;
  479. string _autoMaxCardCountKey = "AutoMaxCardCount";
  480. public void SaveAutoMaxCardCount()
  481. {
  482. PlayerPrefsUtil.SetBool(_autoMaxCardCountKey, autoMaxCardCount);
  483. PlayerPrefs.Save();
  484. }
  485. public void LoadAutoMaxCardCount()
  486. {
  487. autoMaxCardCount = PlayerPrefsUtil.GetBool(_autoMaxCardCountKey, false);
  488. }
  489. #endregion
  490. #region Auto hatch
  491. [HideInInspector] public bool autoHatch = false;
  492. string _autoHatchKey = "AutoHatch";
  493. public void SaveAutoHatch()
  494. {
  495. PlayerPrefsUtil.SetBool(_autoHatchKey, autoHatch);
  496. PlayerPrefs.Save();
  497. }
  498. public void LoadAutoHatch()
  499. {
  500. autoHatch = PlayerPrefsUtil.GetBool(_autoHatchKey, false);
  501. }
  502. #endregion
  503. #region Show CutIn Animation
  504. [HideInInspector] public bool showCutInAnimation = false;
  505. string _showCutInAnimationKey = "ShowCutInAnimation";
  506. public void SaveShowCutInAnimation()
  507. {
  508. PlayerPrefsUtil.SetBool(_showCutInAnimationKey, showCutInAnimation);
  509. PlayerPrefs.Save();
  510. }
  511. public void LoadShowCutInAnimation()
  512. {
  513. //TODO: Setting default to false, to fix animation syncing bug, MB
  514. showCutInAnimation = false;
  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. }