ContinuousController.cs 48 KB

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