ContinuousController.cs 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746
  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. cardKind = new List<CardKind> { CardKind.Digimon },
  329. DP = 6000
  330. };
  331. await TaomonToken.GetCardSprite();
  332. RapidmonToken = new CEntity_Base()
  333. {
  334. cardColors = new List<CardColor>() { CardColor.Green },
  335. PlayCost = -1,
  336. Level = 0,
  337. CardName_JPN = "",
  338. CardName_ENG = "Rapidmon",
  339. Form_JPN = new List<string>(),
  340. Form_ENG = new List<string>(),
  341. Attribute_JPN = new List<string>(),
  342. Attribute_ENG = new List<string>(),
  343. Type_JPN = new List<string>(),
  344. Type_ENG = new List<string>(),
  345. CardSpriteName = "BT19-091-token-green",
  346. cardKind = new List<CardKind> { CardKind.Digimon },
  347. DP = 6000
  348. };
  349. await RapidmonToken.GetCardSprite();
  350. PipeFoxToken = new CEntity_Base()
  351. {
  352. cardColors = new List<CardColor>() { CardColor.Yellow },
  353. PlayCost = -1,
  354. Level = 0,
  355. CardName_JPN = "",
  356. CardName_ENG = "Pipe-Fox",
  357. Form_JPN = new List<string>(),
  358. Form_ENG = new List<string>(),
  359. Attribute_JPN = new List<string>(),
  360. Attribute_ENG = new List<string>(),
  361. Type_JPN = new List<string>(),
  362. Type_ENG = new List<string>(),
  363. CardSpriteName = "BT19-040-token",
  364. cardKind = new List<CardKind> { CardKind.Digimon },
  365. DP = 6000,
  366. CardEffectClassName = "BT19_040_token"
  367. };
  368. await PipeFoxToken.GetCardSprite();
  369. AthoRenePorToken = new CEntity_Base()
  370. {
  371. cardColors = new List<CardColor>() { CardColor.White },
  372. PlayCost = -1,
  373. Level = 0,
  374. CardName_JPN = "",
  375. CardName_ENG = "Atho, René & Por",
  376. Form_JPN = new List<string>(),
  377. Form_ENG = new List<string>(),
  378. Attribute_JPN = new List<string>(),
  379. Attribute_ENG = new List<string>(),
  380. Type_JPN = new List<string>(),
  381. Type_ENG = new List<string>(),
  382. CardSpriteName = "BT20-017-token",
  383. cardKind = new List<CardKind> { CardKind.Digimon },
  384. DP = 6000,
  385. CardEffectClassName = "BT20_017_token"
  386. };
  387. await AthoRenePorToken.GetCardSprite();
  388. HinukamuyToken = new CEntity_Base()
  389. {
  390. cardColors = new List<CardColor>() { CardColor.White },
  391. PlayCost = -1,
  392. Level = 0,
  393. CardName_JPN = "",
  394. CardName_ENG = "HinukamuyToken",
  395. Form_JPN = new List<string>(),
  396. Form_ENG = new List<string>(),
  397. Attribute_JPN = new List<string>(),
  398. Attribute_ENG = new List<string>(),
  399. Type_JPN = new List<string>(),
  400. Type_ENG = new List<string>(),
  401. CardSpriteName = "BT23-057-token",
  402. cardKind = new List<CardKind> { CardKind.Digimon },
  403. DP = 6000,
  404. CardEffectClassName = "BT23_057_token"
  405. };
  406. await HinukamuyToken.GetCardSprite();
  407. PetrificationToken = new CEntity_Base()
  408. {
  409. cardColors = new List<CardColor>() { CardColor.White },
  410. PlayCost = -1,
  411. Level = 0,
  412. CardName_JPN = "",
  413. CardName_ENG = "Petrification",
  414. Form_JPN = new List<string>(),
  415. Form_ENG = new List<string>(),
  416. Attribute_JPN = new List<string>(),
  417. Attribute_ENG = new List<string>(),
  418. Type_JPN = new List<string>(),
  419. Type_ENG = new List<string>(),
  420. CardSpriteName = "BT21-029-token",
  421. cardKind = new List<CardKind> { CardKind.Digimon },
  422. DP = 3000,
  423. CardEffectClassName = "BT21_029_token"
  424. };
  425. await PetrificationToken.GetCardSprite();
  426. }
  427. public static ContinuousController instance = null;
  428. private void Awake()
  429. {
  430. instance = this;
  431. }
  432. public async void Init()
  433. {
  434. Application.targetFrameRate = 60;
  435. int random = RandomUtility.getRamdom();
  436. UnityEngine.Random.InitState(random);
  437. Debug.Log($"Game Initialize - random number sequence initialization,InitState:{random}");
  438. Sprite reverseCardSprite = await StreamingAssetsUtility.GetSprite("card_back_main");
  439. if (reverseCardSprite != null)
  440. {
  441. ReverseCard = reverseCardSprite;
  442. }
  443. Sprite reverseDigieggCardSprite = await StreamingAssetsUtility.GetSprite("card_back_sub");
  444. if (reverseDigieggCardSprite != null)
  445. {
  446. ReverseCard_Digitama = reverseDigieggCardSprite;
  447. }
  448. LoadBanList();
  449. // deck data
  450. //DeckDatas = PlayerPrefsUtil.LoadList<DeckData>(DeckDatasPlayerPrefsKey);
  451. LoadDeckLists();
  452. GetComponent<StarterDeck>().SetStarterDecks();
  453. // player data
  454. LoadPlayerName();
  455. LoadWinCount();
  456. // game play
  457. LoadAutoEffectOrder();
  458. LoadAutoDeckBottomOrder();
  459. LoadAutoDeckTopOrder();
  460. LoadAutoMinDigivolutionCost();
  461. LoadAutoMaxCardCount();
  462. LoadAutoHatch();
  463. LoadShowCutInAnimation();
  464. LoadReverseOpponentsCards();
  465. LoadTurnSuspendedCards();
  466. LoadCheckBeforeEndingSelection();
  467. LoadSuspendedCardsDirectionIsLeft();
  468. //Graphics
  469. LoadShowBackgroundParticle();
  470. // Sound
  471. LoadVolume();
  472. // ServerRegion
  473. LoadServerRegion();
  474. // Language
  475. LoadLanguage();
  476. await CreateTokenData();
  477. DontDestroyOnLoad(gameObject);
  478. }
  479. [Obsolete("This is obsolete, switching to save files")]
  480. public void ModifyAllDeckDatas()
  481. {
  482. List<DeckData> tempDeckDatas = new List<DeckData>();
  483. foreach (DeckData deckData in DeckDatas)
  484. {
  485. tempDeckDatas.Add(deckData);
  486. }
  487. foreach (DeckData deckData in tempDeckDatas)
  488. {
  489. if (deckData.AllDeckCards().Count == 0)
  490. {
  491. DeckDatas.Remove(deckData);
  492. }
  493. }
  494. for (int i = 0; i < DeckDatas.Count; i++)
  495. {
  496. //DeckData deckData = new DeckData(DeckData.GetDeckCode(DeckDatas[i].DeckName, DeckData.SortedDeckCardsList(DeckDatas[i].DeckCards()), DeckData.SortedDeckCardsList(DeckDatas[i].DigitamaDeckCards()), DeckDatas[i].KeyCard));
  497. DeckData deckData = DeckDatas[i];
  498. DeckDatas[i] = deckData.ModifiedDeckData();
  499. }
  500. SaveDeckDatas();
  501. }
  502. [Obsolete("This is obsolete, switching to save files")]
  503. public void SaveDeckDatas()
  504. {
  505. PlayerPrefsUtil.SaveList(DeckDatasPlayerPrefsKey, DeckDatas);
  506. PlayerPrefs.Save();
  507. }
  508. public void SaveDeckData(DeckData data)
  509. {
  510. string savePath = StreamingAssetsUtility.GetStreamingAssetPath("Decks", false);
  511. File.WriteAllText($"{savePath}/{data.DeckName}_{data.DeckID}.txt", DeckCodeUtility.GetDeckBuilderFile(data));
  512. }
  513. public void RenameDeck(DeckData data, string newName)
  514. {
  515. string savePath = StreamingAssetsUtility.GetStreamingAssetPath("Decks", false);
  516. if (File.Exists($"{savePath}/{data.DeckName}_{data.DeckID}.txt"))
  517. {
  518. File.Move($"{savePath}/{data.DeckName}_{data.DeckID}.txt", $"{savePath}/{newName}_{data.DeckID}.txt");
  519. data.DeckName = newName;
  520. SaveDeckData(data);
  521. }
  522. else
  523. data.DeckName = newName;
  524. }
  525. public void DeleteDeck(DeckData data)
  526. {
  527. string filePath = StreamingAssetsUtility.GetStreamingAssetPath("Decks", false);
  528. if (!Directory.Exists(filePath))
  529. return;
  530. if (!File.Exists($"{filePath}/{data.DeckName}_{data.DeckID}.txt"))
  531. return;
  532. File.Delete($"{filePath}/{data.DeckName}_{data.DeckID}.txt");
  533. }
  534. public void DeleteAllDecks()
  535. {
  536. foreach(DeckData data in DeckDatas)
  537. {
  538. DeleteDeck(data);
  539. }
  540. }
  541. public void LoadDeckLists()
  542. {
  543. string loadPath = StreamingAssetsUtility.GetStreamingAssetPath("Decks", false);
  544. if (!Directory.Exists(loadPath))
  545. return;
  546. string[] deckLists = Directory.GetFiles(loadPath);
  547. foreach(string deckPath in deckLists)
  548. {
  549. string fileName = Path.GetFileNameWithoutExtension(deckPath);
  550. if (!fileName.Contains("_"))
  551. continue;
  552. string deckList = File.ReadAllText(deckPath);
  553. StreamReader sr = new StreamReader(deckPath);
  554. string deckName = sr.ReadLine().Replace("Name: ", "");
  555. int KeyCard = int.Parse(sr.ReadLine().Replace("Key Card: ", ""));
  556. int SortValue = int.Parse(sr.ReadLine().Replace("Sort Index: ", ""));
  557. sr.Close();
  558. string deck = deckList.Substring(deckList.IndexOf("//"));
  559. //Debug.Log(deckName);
  560. if(SortValue < 0)
  561. SortValue = 0;
  562. CreateDeckFromFile(fileName.Split("_")[1], deckName, KeyCard, deck, SortValue);
  563. }
  564. DeckDatas = DeckDatas.OrderBy(x => x.DeckName).ToList();
  565. }
  566. private void CreateDeckFromFile(string id, string name, int keyID, string deckCode, int index = 0)
  567. {
  568. List<CEntity_Base> AllDeckCards = DeckCodeUtility.GetAllDeckCardsFromDeckBuilderDeckCode(deckCode);
  569. if (AllDeckCards.Count == 0)
  570. {
  571. AllDeckCards = DeckCodeUtility.GetAllDeckCardsFromTTSDeckCode(deckCode);
  572. }
  573. List<CEntity_Base> deckCards = new List<CEntity_Base>();
  574. List<CEntity_Base> digitamaDeckCards = new List<CEntity_Base>();
  575. foreach (CEntity_Base cEntity_Base in AllDeckCards)
  576. {
  577. if (cEntity_Base.cardKind.Contains(CardKind.DigiEgg))
  578. {
  579. digitamaDeckCards.Add(cEntity_Base);
  580. }
  581. else
  582. {
  583. deckCards.Add(cEntity_Base);
  584. }
  585. }
  586. Debug.Log($"Create Deck From File: {name}");
  587. DeckData deckData = (new DeckData(DeckData.GetDeckCode(name, deckCards, digitamaDeckCards, null),id)).ModifiedDeckData();
  588. deckData.KeyCardId = keyID;
  589. deckData.DeckName = name;
  590. deckData.SortValue = index;
  591. DeckDatas.Insert(index, deckData);
  592. }
  593. #region Player Name
  594. string _playerName;
  595. string _playerNameKey = "PlayerName";
  596. public string PlayerName
  597. {
  598. get
  599. {
  600. if (string.IsNullOrEmpty(_playerName))
  601. {
  602. return "Player";
  603. }
  604. return _playerName;
  605. }
  606. set
  607. {
  608. _playerName = DeckData.ValidateDeckName(value);
  609. }
  610. }
  611. public void SavePlayerName(string playerName)
  612. {
  613. PlayerName = playerName;
  614. PlayerPrefs.SetString(_playerNameKey, playerName);
  615. PlayerPrefs.Save();
  616. }
  617. public void LoadPlayerName()
  618. {
  619. if (PlayerPrefs.HasKey(_playerNameKey))
  620. {
  621. PlayerName = PlayerPrefs.GetString(_playerNameKey);
  622. }
  623. if (string.IsNullOrEmpty(PlayerName))
  624. {
  625. PlayerName = "Player";
  626. }
  627. }
  628. #endregion
  629. #region number of victories
  630. public int WinCount { get; set; }
  631. string _winCountKey = "WinCount";
  632. public void SaveWinCount()
  633. {
  634. PlayerPrefs.SetInt(_winCountKey, WinCount);
  635. PlayerPrefs.Save();
  636. }
  637. public void LoadWinCount()
  638. {
  639. if (PlayerPrefs.HasKey(_winCountKey))
  640. {
  641. WinCount = PlayerPrefs.GetInt(_winCountKey);
  642. }
  643. }
  644. #endregion
  645. #region Auto effect order
  646. [HideInInspector] public bool autoEffectOrder = false;
  647. string _autoEffectOrderKey = "AutoEffectOrder";
  648. public void SaveAutoEffectOrder()
  649. {
  650. PlayerPrefsUtil.SetBool(_autoEffectOrderKey, autoEffectOrder);
  651. PlayerPrefs.Save();
  652. }
  653. public void LoadAutoEffectOrder()
  654. {
  655. autoEffectOrder = PlayerPrefsUtil.GetBool(_autoEffectOrderKey, false);
  656. }
  657. #endregion
  658. #region Auto deck bottom order
  659. [HideInInspector] public bool autoDeckBottomOrder = false;
  660. string _autoDeckBottomOrderKey = "AutoDeckBottomOrder";
  661. public void SaveAutoDeckBottomOrder()
  662. {
  663. PlayerPrefsUtil.SetBool(_autoDeckBottomOrderKey, autoDeckBottomOrder);
  664. PlayerPrefs.Save();
  665. }
  666. public void LoadAutoDeckBottomOrder()
  667. {
  668. autoDeckBottomOrder = PlayerPrefsUtil.GetBool(_autoDeckBottomOrderKey, false);
  669. }
  670. #endregion
  671. #region Auto deck top order
  672. [HideInInspector] public bool autoDeckTopOrder = false;
  673. string _autoDeckTopOrderKey = "AutoDeckTopOrder";
  674. public void SaveAutoDeckTopOrder()
  675. {
  676. PlayerPrefsUtil.SetBool(_autoDeckTopOrderKey, autoDeckTopOrder);
  677. PlayerPrefs.Save();
  678. }
  679. public void LoadAutoDeckTopOrder()
  680. {
  681. autoDeckTopOrder = PlayerPrefsUtil.GetBool(_autoDeckTopOrderKey, false);
  682. }
  683. #endregion
  684. #region Auto min digivolution cost
  685. [HideInInspector] public bool autoMinDigivolutionCost = false;
  686. string _autoMinDigivolutionCostKey = "AutoMinDigivolutionCost";
  687. public void SaveAutoMinDigivolutionCost()
  688. {
  689. PlayerPrefsUtil.SetBool(_autoMinDigivolutionCostKey, autoMinDigivolutionCost);
  690. PlayerPrefs.Save();
  691. }
  692. public void LoadAutoMinDigivolutionCost()
  693. {
  694. autoMinDigivolutionCost = PlayerPrefsUtil.GetBool(_autoMinDigivolutionCostKey, false);
  695. }
  696. #endregion
  697. #region Auto max card count
  698. [HideInInspector] public bool autoMaxCardCount = false;
  699. string _autoMaxCardCountKey = "AutoMaxCardCount";
  700. public void SaveAutoMaxCardCount()
  701. {
  702. PlayerPrefsUtil.SetBool(_autoMaxCardCountKey, autoMaxCardCount);
  703. PlayerPrefs.Save();
  704. }
  705. public void LoadAutoMaxCardCount()
  706. {
  707. autoMaxCardCount = PlayerPrefsUtil.GetBool(_autoMaxCardCountKey, false);
  708. }
  709. #endregion
  710. #region Auto hatch
  711. [HideInInspector] public bool autoHatch = false;
  712. string _autoHatchKey = "AutoHatch";
  713. public void SaveAutoHatch()
  714. {
  715. PlayerPrefsUtil.SetBool(_autoHatchKey, autoHatch);
  716. PlayerPrefs.Save();
  717. }
  718. public void LoadAutoHatch()
  719. {
  720. autoHatch = PlayerPrefsUtil.GetBool(_autoHatchKey, false);
  721. }
  722. #endregion
  723. #region Show CutIn Animation
  724. [HideInInspector] public bool showCutInAnimation = false;
  725. string _showCutInAnimationKey = "ShowCutInAnimation";
  726. public void SaveShowCutInAnimation()
  727. {
  728. PlayerPrefsUtil.SetBool(_showCutInAnimationKey, showCutInAnimation);
  729. PlayerPrefs.Save();
  730. }
  731. public void LoadShowCutInAnimation()
  732. {
  733. //TODO: Setting default to false, to fix animation syncing bug, MB
  734. showCutInAnimation = false;
  735. //showCutInAnimation = PlayerPrefsUtil.GetBool(_showCutInAnimationKey, true);
  736. }
  737. #endregion
  738. #region Reverse opponents' cards
  739. [HideInInspector] public bool reverseOpponentsCards = false;
  740. string _reverseOpponentsCardsKey = "ReverseOpponentsCards";
  741. public void SaveReverseOpponentsCards()
  742. {
  743. PlayerPrefsUtil.SetBool(_reverseOpponentsCardsKey, reverseOpponentsCards);
  744. PlayerPrefs.Save();
  745. }
  746. public void LoadReverseOpponentsCards()
  747. {
  748. reverseOpponentsCards = PlayerPrefsUtil.GetBool(_reverseOpponentsCardsKey, false);
  749. }
  750. #endregion
  751. #region Turn suspended cards
  752. [HideInInspector] public bool turnSuspendedCards = false;
  753. string _turnSuspendedCardsKey = "TurnSuspendedCards";
  754. public void SaveTurnSuspendedCards()
  755. {
  756. PlayerPrefsUtil.SetBool(_turnSuspendedCardsKey, turnSuspendedCards);
  757. PlayerPrefs.Save();
  758. }
  759. public void LoadTurnSuspendedCards()
  760. {
  761. turnSuspendedCards = PlayerPrefsUtil.GetBool(_turnSuspendedCardsKey, true);
  762. }
  763. #endregion
  764. #region Check before ending selection
  765. [HideInInspector] public bool checkBeforeEndingSelection = false;
  766. string _checkBeforeEndingSelectionKey = "CheckBeforeEndingSelection";
  767. public void SaveCheckBeforeEndingSelection()
  768. {
  769. PlayerPrefsUtil.SetBool(_checkBeforeEndingSelectionKey, checkBeforeEndingSelection);
  770. PlayerPrefs.Save();
  771. }
  772. public void LoadCheckBeforeEndingSelection()
  773. {
  774. checkBeforeEndingSelection = PlayerPrefsUtil.GetBool(_checkBeforeEndingSelectionKey, true);
  775. }
  776. #endregion
  777. #region Suspended cards' direction is left
  778. [HideInInspector] public bool suspendedCardsDirectionIsLeft = false;
  779. string _suspendedCardsDirectionIsLeftKey = "SuspendedCardsDirectionIsLeft";
  780. public void SaveSuspendedCardsDirectionIsLeft()
  781. {
  782. PlayerPrefsUtil.SetBool(_suspendedCardsDirectionIsLeftKey, suspendedCardsDirectionIsLeft);
  783. PlayerPrefs.Save();
  784. }
  785. public void LoadSuspendedCardsDirectionIsLeft()
  786. {
  787. suspendedCardsDirectionIsLeft = PlayerPrefsUtil.GetBool(_suspendedCardsDirectionIsLeftKey, true);
  788. }
  789. #endregion
  790. #region Show background particle
  791. [HideInInspector] public bool showBackgroundParticle = false;
  792. string _showBackgroundParticleKey = "ShowBackgroundParticle";
  793. public void SaveShowBackgroundParticle()
  794. {
  795. PlayerPrefsUtil.SetBool(_showBackgroundParticleKey, showBackgroundParticle);
  796. PlayerPrefs.Save();
  797. }
  798. public void LoadShowBackgroundParticle()
  799. {
  800. showBackgroundParticle = PlayerPrefsUtil.GetBool(_showBackgroundParticleKey, true);
  801. }
  802. #endregion
  803. #region Sound volume
  804. public float BGMVolume { get; set; }
  805. public float SEVolume { get; set; }
  806. public void SetBGMVolume(float BGMVolume)
  807. {
  808. this.BGMVolume = BGMVolume;
  809. PlayerPrefs.SetFloat("BGMVolume", BGMVolume);
  810. PlayerPrefs.Save();
  811. }
  812. public void SetSEVolume(float SEVolume)
  813. {
  814. this.SEVolume = SEVolume;
  815. PlayerPrefs.SetFloat("SEVolume", SEVolume);
  816. PlayerPrefs.Save();
  817. }
  818. public void ChangeBGMVolume(AudioSource audioSource)
  819. {
  820. audioSource.volume = BGMVolume * 0.25f * 0.8f;
  821. }
  822. public void ChangeSEVolume(AudioSource audioSource)
  823. {
  824. audioSource.volume = SEVolume * 0.5f * 0.8f;
  825. }
  826. void LoadVolume()
  827. {
  828. BGMVolume = 0.5f;
  829. SEVolume = 0.5f;
  830. if (PlayerPrefs.HasKey("BGMVolume"))
  831. {
  832. BGMVolume = PlayerPrefs.GetFloat("BGMVolume");
  833. }
  834. if (PlayerPrefs.HasKey("SEVolume"))
  835. {
  836. SEVolume = PlayerPrefs.GetFloat("SEVolume");
  837. }
  838. }
  839. #endregion
  840. #region Server region
  841. [HideInInspector] public string serverRegion = "us";
  842. string _serverRegionKey = "ServerRegion";
  843. public void SaveServerRegion()
  844. {
  845. PlayerPrefs.SetString(_serverRegionKey, serverRegion);
  846. PlayerPrefs.Save();
  847. }
  848. public void LoadServerRegion()
  849. {
  850. //serverRegion = PlayerPrefs.GetString(_serverRegionKey, "us");
  851. }
  852. public string LastConnectServerRegion = "";
  853. #endregion
  854. #region Language
  855. [HideInInspector] public Language language = Language.ENG;
  856. string _languageKey = "Language";
  857. public void SaveLanguage()
  858. {
  859. PlayerPrefs.SetString(_languageKey, language.ToString());
  860. PlayerPrefs.Save();
  861. }
  862. public void LoadLanguage()
  863. {
  864. language = (Language)Enum.Parse(typeof(Language), PlayerPrefs.GetString(_languageKey, "ENG"));
  865. }
  866. #endregion
  867. #region PlaySE(AudioClip clip)
  868. public SoundObject PlaySE(AudioClip clip)
  869. {
  870. SoundObject _soundObject = Instantiate(soundObject);
  871. _soundObject.PlaySE(clip);
  872. return _soundObject;
  873. }
  874. #endregion
  875. #region カードIndexからカードを取得
  876. public CEntity_Base getCardEntityByCardID(int cardIndex)
  877. {
  878. //int searchIndex = cardIndex - 1;
  879. //int count = 0;
  880. CEntity_Base cEntity_Base = SortedCardList.First(entity => entity.CardIndex == cardIndex);
  881. return cEntity_Base;
  882. //TODO: REMOVE IN FUTURE
  883. /*do
  884. {
  885. if (count != 0)
  886. {
  887. searchIndex += (int)Math.Pow(-1, count % 2) * count / 2;
  888. }
  889. if (0 <= searchIndex)
  890. {
  891. if (searchIndex <= SortedCardList.Length - 1)
  892. {
  893. CEntity_Base cEntity_Base = SortedCardList[searchIndex];
  894. if (cEntity_Base != null)
  895. {
  896. if (cEntity_Base.CardIndex == cardIndex)
  897. {
  898. return cEntity_Base;
  899. }
  900. }
  901. }
  902. else
  903. {
  904. for (int i = 0; i < 300; i++)
  905. {
  906. CEntity_Base cEntity_Base = SortedCardList[SortedCardList.Length - 1 - i];
  907. if (cEntity_Base != null)
  908. {
  909. if (cEntity_Base.CardIndex == cardIndex)
  910. {
  911. return cEntity_Base;
  912. }
  913. }
  914. }
  915. return null;
  916. }
  917. }
  918. if (count != 0)
  919. {
  920. searchIndex -= (int)Math.Pow(-1, count % 2) * count / 2;
  921. }
  922. count++;
  923. }
  924. while (count <= 20);
  925. return null;*/
  926. }
  927. #endregion
  928. public Coroutine LoadingTextCoroutine;
  929. bool _endBattle = false;
  930. public void EndBattle()
  931. {
  932. if (!_endBattle)
  933. {
  934. _endBattle = true;
  935. StartCoroutine(EndBattleCoroutine());
  936. }
  937. }
  938. public IEnumerator EndBattleCoroutine()
  939. {
  940. if (Opening.instance == null)
  941. {
  942. yield break;
  943. }
  944. Opening.instance.openingObject.SetActive(true);
  945. //yield return StartCoroutine(Opening.instance.LoadingObject_Unload.StartLoading("Now Loading"));
  946. //Camera camera1 = Camera.main;
  947. //Destroy(camera1.gameObject);
  948. //yield return null;
  949. isAI = false;
  950. int random = RandomUtility.getRamdom();
  951. UnityEngine.Random.InitState(random);
  952. Debug.Log($"random number sequence initialization, InitState:{random}");
  953. var unload = SceneManager.UnloadSceneAsync("BattleScene");
  954. yield return unload;
  955. yield return Resources.UnloadUnusedAssets();
  956. yield return StartCoroutine(Opening.instance.LoadingObject_Unload.StartLoading("Now Loading"));
  957. //Opening.instance.MainCamera.gameObject.SetActive(true);
  958. foreach (Camera camera in Opening.instance.openingCameras)
  959. {
  960. camera.gameObject.SetActive(true);
  961. }
  962. Opening.instance.LoadingObject_light.gameObject.SetActive(false);
  963. yield return ContinuousController.instance.StartCoroutine(PhotonUtility.SetPlayerName());
  964. if (isRandomMatch)
  965. {
  966. Debug.Log("Unload from Random Match");
  967. yield return StartCoroutine(Opening.instance.battle.lobbyManager_RandomMatch.CloseLobbyCoroutine());
  968. yield return StartCoroutine(Opening.instance.battle.selectBattleMode.SetUpSelectBattleModeCoroutine());
  969. }
  970. else
  971. {
  972. Debug.Log("Unload from Room Match");
  973. yield return StartCoroutine(Opening.instance.battle.roomManager.Init(true));
  974. yield return new WaitForSeconds(0.1f);
  975. }
  976. yield return new WaitWhile(() => GManager.instance != null);
  977. Opening.instance.LoadingObject.gameObject.SetActive(false);
  978. yield return StartCoroutine(Opening.instance.LoadingObject_Unload.EndLoading());
  979. _endBattle = false;
  980. if (!isRandomMatch)
  981. {
  982. Hashtable PlayerProp = PhotonNetwork.LocalPlayer.CustomProperties;
  983. if (PlayerProp.TryGetValue("isBattle", out object value))
  984. {
  985. PlayerProp["isBattle"] = false;
  986. }
  987. else
  988. {
  989. PlayerProp.Add("isBattle", false);
  990. }
  991. PhotonNetwork.LocalPlayer.SetCustomProperties(PlayerProp);
  992. }
  993. Scene newScene = SceneManager.GetSceneByName("Opening");
  994. SceneManager.SetActiveScene(newScene);
  995. for (int i = 0; i < 3; i++)
  996. {
  997. yield return new WaitForSeconds(0.1f);
  998. EventSystem.current.SetSelectedGameObject(Opening.instance.battle.selectBattleMode.transform.GetChild(0).gameObject);
  999. }
  1000. //GUI.UnfocusWindow();
  1001. yield return null;
  1002. //StartCoroutine(DestroyEffectCoroutine());
  1003. if (Opening.instance.OpeningBGM != null)
  1004. {
  1005. if (!Opening.instance.OpeningBGM.isPlaying)
  1006. {
  1007. Opening.instance.OpeningBGM.StartPlayBGM(Opening.instance.bgm);
  1008. }
  1009. }
  1010. }
  1011. private void Update()
  1012. {
  1013. #if UNITY_WINDOWS
  1014. if (Input.GetKey(KeyCode.Escape))
  1015. {
  1016. Application.Quit();
  1017. }
  1018. #endif
  1019. if (Input.GetKeyDown(KeyCode.F1))
  1020. {
  1021. _showPhotonDebug = !_showPhotonDebug;
  1022. }
  1023. }
  1024. int _frameCount = 0;
  1025. int _updateFrame = 40;
  1026. void LateUpdate()
  1027. {
  1028. #region Update only once every few frames
  1029. _frameCount++;
  1030. if (_frameCount < _updateFrame)
  1031. {
  1032. return;
  1033. }
  1034. else
  1035. {
  1036. _frameCount = 0;
  1037. }
  1038. #endregion
  1039. if (PhotonNetwork.InRoom)
  1040. {
  1041. if (!isAI)
  1042. {
  1043. bool notEnterOther = false;
  1044. if (PhotonNetwork.PlayerList.Length == 1)
  1045. {
  1046. if (GManager.instance != null)
  1047. {
  1048. notEnterOther = true;
  1049. }
  1050. }
  1051. if (notEnterOther)
  1052. {
  1053. if (PhotonNetwork.CurrentRoom.MaxPlayers != 1)
  1054. {
  1055. PhotonNetwork.CurrentRoom.MaxPlayers = 1;
  1056. }
  1057. }
  1058. else
  1059. {
  1060. if (PhotonNetwork.CurrentRoom.MaxPlayers != 2)
  1061. {
  1062. PhotonNetwork.CurrentRoom.MaxPlayers = 2;
  1063. }
  1064. }
  1065. }
  1066. }
  1067. }
  1068. public bool isAI { get; set; } = false;
  1069. //Flag that the sharing of the random number sequence is over.
  1070. public bool DoneSetRandom { get; set; } = false;
  1071. public bool CanSetRandom { get; set; } = false;
  1072. [PunRPC]
  1073. public void SetRandom(int random)
  1074. {
  1075. StartCoroutine(SetRandomCoroutine(random));
  1076. }
  1077. IEnumerator SetRandomCoroutine(int random)
  1078. {
  1079. yield return new WaitWhile(() => !CanSetRandom);
  1080. UnityEngine.Random.InitState(random);
  1081. DoneSetRandom = true;
  1082. Debug.Log($"random number sequence initialization,InitState:{random}");
  1083. }
  1084. #region Photon Debug HUD
  1085. bool _showPhotonDebug = false;
  1086. Photon.Realtime.IConnectionCallbacks _connectionCallbacks;
  1087. Photon.Realtime.IMatchmakingCallbacks _matchmakingCallbacks;
  1088. Photon.Realtime.ILobbyCallbacks _lobbyCallbacks;
  1089. void OnEnable()
  1090. {
  1091. var listener = new PhotonDebugListener();
  1092. _connectionCallbacks = listener;
  1093. _matchmakingCallbacks = listener;
  1094. _lobbyCallbacks = listener;
  1095. PhotonNetwork.AddCallbackTarget(listener);
  1096. }
  1097. void OnDisable()
  1098. {
  1099. if (_connectionCallbacks != null)
  1100. PhotonNetwork.RemoveCallbackTarget(_connectionCallbacks);
  1101. }
  1102. class PhotonDebugListener :
  1103. Photon.Realtime.IConnectionCallbacks,
  1104. Photon.Realtime.IMatchmakingCallbacks,
  1105. Photon.Realtime.ILobbyCallbacks
  1106. {
  1107. public void OnDisconnected(Photon.Realtime.DisconnectCause cause)
  1108. {
  1109. Debug.LogWarning($"[Photon Debug] Disconnected: {cause}");
  1110. }
  1111. public void OnConnected() { }
  1112. public void OnConnectedToMaster()
  1113. {
  1114. Debug.Log("[Photon Debug] Connected to Master");
  1115. }
  1116. public void OnRegionListReceived(Photon.Realtime.RegionHandler handler) { }
  1117. public void OnCustomAuthenticationResponse(Dictionary<string, object> data) { }
  1118. public void OnCustomAuthenticationFailed(string debugMessage)
  1119. {
  1120. Debug.LogError($"[Photon Debug] Auth failed: {debugMessage}");
  1121. }
  1122. public void OnJoinedLobby()
  1123. {
  1124. Debug.Log("[Photon Debug] Joined Lobby");
  1125. }
  1126. public void OnLeftLobby()
  1127. {
  1128. Debug.Log("[Photon Debug] Left Lobby");
  1129. }
  1130. public void OnLobbyStatisticsUpdate(List<Photon.Realtime.TypedLobbyInfo> lobbyStatistics) { }
  1131. public void OnRoomListUpdate(List<Photon.Realtime.RoomInfo> roomList) { }
  1132. public void OnJoinedRoom()
  1133. {
  1134. Debug.Log($"[Photon Debug] Joined Room: {PhotonNetwork.CurrentRoom?.Name}");
  1135. }
  1136. public void OnJoinRoomFailed(short returnCode, string message)
  1137. {
  1138. Debug.LogError($"[Photon Debug] Join Room FAILED: [{returnCode}] {message}");
  1139. }
  1140. public void OnJoinRandomFailed(short returnCode, string message)
  1141. {
  1142. Debug.LogError($"[Photon Debug] Join Random FAILED: [{returnCode}] {message}");
  1143. }
  1144. public void OnCreateRoomFailed(short returnCode, string message)
  1145. {
  1146. Debug.LogError($"[Photon Debug] Create Room FAILED: [{returnCode}] {message}");
  1147. }
  1148. public void OnCreatedRoom()
  1149. {
  1150. Debug.Log("[Photon Debug] Created Room");
  1151. }
  1152. public void OnLeftRoom()
  1153. {
  1154. Debug.Log("[Photon Debug] Left Room");
  1155. }
  1156. public void OnFriendListUpdate(List<Photon.Realtime.FriendInfo> friendList) { }
  1157. }
  1158. void OnGUI()
  1159. {
  1160. if (!_showPhotonDebug) return;
  1161. string status;
  1162. if (!PhotonNetwork.IsConnected)
  1163. {
  1164. status = "<color=#FF4444>[Photon] Disconnected</color>";
  1165. }
  1166. else if (PhotonNetwork.InRoom)
  1167. {
  1168. string roomName = PhotonNetwork.CurrentRoom != null ? PhotonNetwork.CurrentRoom.Name : "?";
  1169. int players = PhotonNetwork.CurrentRoom != null ? PhotonNetwork.CurrentRoom.PlayerCount : 0;
  1170. status = $"<color=#44FF44>[Photon] Connected | Region: {PhotonNetwork.CloudRegion} | Room: {roomName} ({players} players)</color>";
  1171. }
  1172. else if (PhotonNetwork.InLobby)
  1173. {
  1174. status = $"<color=#44FF44>[Photon] Connected | Region: {PhotonNetwork.CloudRegion} | In Lobby</color>";
  1175. }
  1176. else
  1177. {
  1178. status = $"<color=#FFAA00>[Photon] Connected | Region: {PhotonNetwork.CloudRegion} | Not in Lobby/Room</color>";
  1179. }
  1180. GUIStyle style = new GUIStyle(GUI.skin.label);
  1181. style.fontSize = 16;
  1182. style.richText = true;
  1183. style.fontStyle = FontStyle.Bold;
  1184. GUI.Label(new Rect(10, 10, 800, 30), status, style);
  1185. }
  1186. #endregion
  1187. }
  1188. #region Manage random numbers
  1189. public static class RandomUtility
  1190. {
  1191. private static System.Random random;
  1192. public static int getRamdom()
  1193. {
  1194. int _max = 1500000000;
  1195. if (random == null)
  1196. {
  1197. random = new System.Random((int)DateTime.Now.Ticks);
  1198. }
  1199. return random.Next(0, _max);
  1200. }
  1201. #region IsSucceedProbability(float Probability)
  1202. public static bool IsSucceedProbability(float Probability)
  1203. {
  1204. if (Probability >= 1)
  1205. {
  1206. return true;
  1207. }
  1208. if (Probability <= 0)
  1209. {
  1210. return false;
  1211. }
  1212. float random = UnityEngine.Random.Range(0f, 1f);
  1213. if (random <= Probability)
  1214. {
  1215. return true;
  1216. }
  1217. return false;
  1218. }
  1219. #endregion
  1220. #region Shuffle the deck
  1221. public static List<CEntity_Base> ShuffledDeckCards(List<CEntity_Base> DeckCards)
  1222. {
  1223. List<CEntity_Base> CardDatas = new List<CEntity_Base>();
  1224. CardDatas.AddRange(DeckCards);
  1225. // The initial value of the integer n is the number of cards in the deck
  1226. int n = CardDatas.Count;
  1227. while (n > 0)
  1228. {
  1229. n--;
  1230. // Random index from 0 to i (inclusive)
  1231. int k = UnityEngine.Random.Range(0, n + 1);
  1232. // Swap elements at indices i and k
  1233. CEntity_Base temp = CardDatas[n];
  1234. CardDatas[n] = CardDatas[k];
  1235. CardDatas[k] = temp;
  1236. }
  1237. return CardDatas;
  1238. }
  1239. public static List<CardSource> ShuffledDeckCards(List<CardSource> DeckCards)
  1240. {
  1241. List<CardSource> CardDatas = new List<CardSource>();
  1242. CardDatas.AddRange(DeckCards);
  1243. // The initial value of the integer n is the number of cards in the deck
  1244. int n = CardDatas.Count;
  1245. while (n > 0)
  1246. {
  1247. n--;
  1248. // Random index from 0 to i (inclusive)
  1249. int k = UnityEngine.Random.Range(0, n + 1);
  1250. // Swap elements at indices i and k
  1251. CardSource temp = CardDatas[n];
  1252. if (!temp.IsFlipped)
  1253. {
  1254. temp.SetReverse();
  1255. if(temp.Owner.SecurityCards.Contains(temp))
  1256. GManager.OnSecurityStackChanged?.Invoke(temp.Owner);
  1257. }
  1258. CardDatas[n] = CardDatas[k];
  1259. CardDatas[k] = temp;
  1260. }
  1261. return CardDatas;
  1262. }
  1263. #endregion
  1264. }
  1265. #endregion
  1266. #region Manage connections to Photon
  1267. public class PhotonUtility
  1268. {
  1269. #region Disconnected from Photon
  1270. public static IEnumerator DisconnectCoroutine()
  1271. {
  1272. #region Exit Room
  1273. if (PhotonNetwork.InRoom)
  1274. {
  1275. PhotonNetwork.LeaveRoom();
  1276. }
  1277. yield return new WaitWhile(() => PhotonNetwork.InRoom);
  1278. #endregion
  1279. #region Exit from the lobby
  1280. if (PhotonNetwork.InLobby)
  1281. {
  1282. PhotonNetwork.LeaveLobby();
  1283. }
  1284. yield return new WaitWhile(() => PhotonNetwork.InLobby);
  1285. #endregion
  1286. #region Disconnected from Photon
  1287. if (PhotonNetwork.IsConnected)
  1288. {
  1289. PhotonNetwork.Disconnect();
  1290. }
  1291. yield return new WaitWhile(() => PhotonNetwork.IsConnected);
  1292. #endregion
  1293. }
  1294. #endregion
  1295. #region Connect to Photon server
  1296. public static IEnumerator ConnectToMasterServerCoroutine()
  1297. {
  1298. if (!PhotonNetwork.IsConnected || ContinuousController.instance.LastConnectServerRegion != ContinuousController.instance.serverRegion)
  1299. {
  1300. if (PhotonNetwork.IsConnected)
  1301. {
  1302. yield return ContinuousController.instance.StartCoroutine(DisconnectCoroutine());
  1303. yield return new WaitWhile(() => PhotonNetwork.IsConnected);
  1304. }
  1305. PhotonNetwork.NetworkingClient.AppId = PhotonNetwork.PhotonServerSettings.AppSettings.AppIdRealtime;
  1306. PhotonNetwork.ConnectToRegion(ContinuousController.instance.serverRegion);
  1307. PhotonNetwork.NickName = ContinuousController.instance.PlayerName;
  1308. PhotonNetwork.GameVersion = ContinuousController.instance.GameVerString;
  1309. ContinuousController.instance.LastConnectServerRegion = ContinuousController.instance.serverRegion;
  1310. }
  1311. yield return new WaitWhile(() => !PhotonNetwork.IsConnectedAndReady);
  1312. }
  1313. #endregion
  1314. #region Connect to Photon Server and Lobby
  1315. public static IEnumerator ConnectToLobbyCoroutine()
  1316. {
  1317. #region Connect to Photon server
  1318. yield return ContinuousController.instance.StartCoroutine(ConnectToMasterServerCoroutine());
  1319. #endregion
  1320. #region Save player name to custom properties
  1321. yield return ContinuousController.instance.StartCoroutine(SetPlayerName());
  1322. #endregion
  1323. #region Save the number of wins to a custom property
  1324. Hashtable hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1325. object value;
  1326. hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1327. if (hash.TryGetValue(ContinuousController.WinCountKey, out value))
  1328. {
  1329. hash[ContinuousController.WinCountKey] = ContinuousController.instance.WinCount;
  1330. }
  1331. else
  1332. {
  1333. hash.Add(ContinuousController.WinCountKey, ContinuousController.instance.WinCount);
  1334. }
  1335. PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
  1336. while (true)
  1337. {
  1338. Hashtable _hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1339. if (_hash.TryGetValue(ContinuousController.WinCountKey, out value))
  1340. {
  1341. if ((int)value == ContinuousController.instance.WinCount)
  1342. {
  1343. break;
  1344. }
  1345. }
  1346. yield return null;
  1347. }
  1348. #endregion
  1349. #region Connect to Lobby
  1350. if (!PhotonNetwork.InLobby)
  1351. {
  1352. PhotonNetwork.JoinLobby();
  1353. }
  1354. yield return new WaitWhile(() => !PhotonNetwork.InLobby);
  1355. yield return new WaitUntil(() => PhotonNetwork.InLobby && PhotonNetwork.IsConnectedAndReady);
  1356. #endregion
  1357. }
  1358. #endregion
  1359. #region Save player name to properties
  1360. public static IEnumerator SetPlayerName()
  1361. {
  1362. Hashtable hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1363. object value;
  1364. hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1365. if (hash.TryGetValue(ContinuousController.PlayerNameKey, out value))
  1366. {
  1367. hash[ContinuousController.PlayerNameKey] = ContinuousController.instance.PlayerName;
  1368. }
  1369. else
  1370. {
  1371. hash.Add(ContinuousController.PlayerNameKey, ContinuousController.instance.PlayerName);
  1372. }
  1373. PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
  1374. while (true)
  1375. {
  1376. Hashtable _hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1377. if (_hash.TryGetValue(ContinuousController.PlayerNameKey, out value))
  1378. {
  1379. if ((string)value == ContinuousController.instance.PlayerName)
  1380. {
  1381. break;
  1382. }
  1383. }
  1384. yield return null;
  1385. }
  1386. }
  1387. #endregion
  1388. #region Save deck data to custom properties
  1389. public static IEnumerator SignUpBattleDeckData()
  1390. {
  1391. Hashtable hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1392. if (hash.TryGetValue(ContinuousController.DeckDataPropertyKey, out object value))
  1393. {
  1394. hash[ContinuousController.DeckDataPropertyKey] = ContinuousController.instance.BattleDeckData.GetThisDeckCode();
  1395. }
  1396. else
  1397. {
  1398. hash.Add(ContinuousController.DeckDataPropertyKey, ContinuousController.instance.BattleDeckData.GetThisDeckCode());
  1399. }
  1400. PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
  1401. while (true)
  1402. {
  1403. Hashtable _hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1404. if (_hash.TryGetValue(ContinuousController.DeckDataPropertyKey, out value))
  1405. {
  1406. if ((string)value == ContinuousController.instance.BattleDeckData.GetThisDeckCode())
  1407. {
  1408. break;
  1409. }
  1410. }
  1411. yield return null;
  1412. }
  1413. }
  1414. #endregion
  1415. #region Remove custom properties from deck data
  1416. public static IEnumerator DeleteBattleDeckData()
  1417. {
  1418. Hashtable hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1419. if (hash.TryGetValue(ContinuousController.DeckDataPropertyKey, out object value))
  1420. {
  1421. hash.Remove(ContinuousController.DeckDataPropertyKey);
  1422. }
  1423. PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
  1424. while (true)
  1425. {
  1426. Hashtable _hash = PhotonNetwork.LocalPlayer.CustomProperties;
  1427. if (!_hash.TryGetValue(ContinuousController.DeckDataPropertyKey, out value))
  1428. {
  1429. break;
  1430. }
  1431. yield return null;
  1432. }
  1433. }
  1434. #endregion
  1435. }
  1436. #endregion
  1437. public enum Language
  1438. {
  1439. ENG,
  1440. JPN,
  1441. }