ContinuousController.cs 47 KB

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