ContinuousController.cs 46 KB

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