ContinuousController.cs 39 KB

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