ContinuousController.cs 49 KB

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