CardObjectController.cs 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076
  1. using Photon.Pun;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using UnityEngine;
  7. using UnityEngine.Events;
  8. using Hashtable = ExitGames.Client.Photon.Hashtable;
  9. using UnityEngine.UI;
  10. using DG.Tweening;
  11. //Card-related operations
  12. public class CardObjectController : MonoBehaviour
  13. {
  14. #region Generate cards for each player's deck
  15. public static IEnumerator CreatePlayerDecks(CardSource CardPrefab, GameContext gameContext)
  16. {
  17. yield return null;
  18. DeckData RandomDeck = null;
  19. if (GManager.instance.IsAI)
  20. {
  21. if (ContinuousController.instance.DeckDatas.Count((deckData) => deckData.IsValidDeckData()) > 0)
  22. {
  23. List<DeckData> deckDatas = new List<DeckData>();
  24. foreach (DeckData deckData in ContinuousController.instance.DeckDatas)
  25. {
  26. if (deckData.IsValidDeckData())
  27. {
  28. deckDatas.Add(deckData);
  29. }
  30. }
  31. DeckData randomDeck = deckDatas[UnityEngine.Random.Range(0, deckDatas.Count)];
  32. RandomDeck = new DeckData(randomDeck.GetThisDeckCode(), randomDeck.DeckID);
  33. #if UNITY_EDITOR && !UNITY_WINDOWS
  34. foreach (DeckData deckData in ContinuousController.instance.DeckDatas)
  35. {
  36. if (deckData.IsValidDeckData())
  37. {
  38. RandomDeck = new DeckData(deckData.GetThisDeckCode(), deckData.DeckID);
  39. break;
  40. }
  41. }
  42. #endif
  43. }
  44. else
  45. {
  46. List<CEntity_Base> mainDeckCards = new List<CEntity_Base>();
  47. List<CEntity_Base> digitamaDeckCards = new List<CEntity_Base>();
  48. List<CEntity_Base> mainDeckCandidates = new List<CEntity_Base>();
  49. List<CEntity_Base> digitamaDeckCandidates = new List<CEntity_Base>();
  50. foreach (CEntity_Base cEntity_Base in ContinuousController.instance.CardList)
  51. {
  52. if (cEntity_Base.cardKind != CardKind.DigiEgg)
  53. {
  54. mainDeckCandidates.Add(cEntity_Base);
  55. }
  56. else
  57. {
  58. digitamaDeckCandidates.Add(cEntity_Base);
  59. }
  60. }
  61. if (mainDeckCandidates.Count >= 1)
  62. {
  63. for (int i = 0; i < 50; i++)
  64. {
  65. mainDeckCards.Add(mainDeckCandidates[UnityEngine.Random.Range(0, mainDeckCandidates.Count)]);
  66. }
  67. }
  68. if (digitamaDeckCandidates.Count >= 1)
  69. {
  70. for (int i = 0; i < 5; i++)
  71. {
  72. digitamaDeckCards.Add(digitamaDeckCandidates[UnityEngine.Random.Range(0, digitamaDeckCandidates.Count)]);
  73. }
  74. }
  75. RandomDeck = new DeckData(DeckData.GetDeckCode("サンプルデッキ", mainDeckCards, digitamaDeckCards, null));
  76. }
  77. }
  78. #region マスタークライアントと非マスタークライアントを抽出
  79. Photon.Realtime.Player MasterPlayer = null;
  80. Photon.Realtime.Player nonMasterPlayer = null;
  81. if (PhotonNetwork.IsMasterClient)
  82. {
  83. MasterPlayer = PhotonNetwork.LocalPlayer;
  84. foreach (Photon.Realtime.Player player in PhotonNetwork.PlayerList)
  85. {
  86. if (player != PhotonNetwork.LocalPlayer)
  87. {
  88. nonMasterPlayer = player;
  89. break;
  90. }
  91. }
  92. }
  93. else
  94. {
  95. nonMasterPlayer = PhotonNetwork.LocalPlayer;
  96. foreach (Photon.Realtime.Player player in PhotonNetwork.PlayerList)
  97. {
  98. if (player != PhotonNetwork.LocalPlayer)
  99. {
  100. MasterPlayer = player;
  101. break;
  102. }
  103. }
  104. }
  105. #endregion
  106. #region そのPhotonクライアントのメインデッキレシピ
  107. List<CEntity_Base> DeckRecipie(Photon.Realtime.Player player)
  108. {
  109. #region 対人戦
  110. if (!GManager.instance.IsAI)
  111. {
  112. Hashtable hashtable = player.CustomProperties;
  113. if (HasDeckRecipie(player))
  114. {
  115. if (hashtable.TryGetValue(ContinuousController.DeckDataPropertyKey, out object value))
  116. {
  117. DeckData deckData = new DeckData((string)value);
  118. return RandomUtility.ShuffledDeckCards(deckData.DeckCards());
  119. }
  120. }
  121. else
  122. {
  123. Debug.Log("!HasDeckRecipie");
  124. }
  125. return null;
  126. }
  127. #endregion
  128. #region vs.AI
  129. else
  130. {
  131. #region プレイヤーのデッキ
  132. if (player == MasterPlayer)
  133. {
  134. if (ContinuousController.instance.BattleDeckData == null)
  135. {
  136. foreach (DeckData deckData in ContinuousController.instance.DeckDatas)
  137. {
  138. if (deckData.IsValidDeckData())
  139. {
  140. return RandomUtility.ShuffledDeckCards(deckData.DeckCards());
  141. }
  142. }
  143. }
  144. else
  145. {
  146. if (ContinuousController.instance.BattleDeckData.IsValidDeckData())
  147. {
  148. return RandomUtility.ShuffledDeckCards(ContinuousController.instance.BattleDeckData.DeckCards());
  149. }
  150. }
  151. if (RandomDeck != null)
  152. {
  153. return RandomUtility.ShuffledDeckCards(RandomDeck.DeckCards());
  154. }
  155. return null;
  156. }
  157. #endregion
  158. #region AIのデッキ
  159. else
  160. {
  161. if (RandomDeck != null)
  162. {
  163. return RandomUtility.ShuffledDeckCards(RandomDeck.DeckCards());
  164. }
  165. foreach (DeckData deckData in ContinuousController.instance.DeckDatas)
  166. {
  167. if (deckData.IsValidDeckData())
  168. {
  169. return RandomUtility.ShuffledDeckCards(deckData.DeckCards());
  170. }
  171. }
  172. return null;
  173. }
  174. #endregion
  175. }
  176. #endregion
  177. }
  178. #endregion
  179. #region そのPhotonクライアントのデジタマデッキレシピ
  180. List<CEntity_Base> DigitamaDeckRecipie(Photon.Realtime.Player player)
  181. {
  182. #region 対人戦
  183. if (!GManager.instance.IsAI)
  184. {
  185. Hashtable hashtable = player.CustomProperties;
  186. if (HasDeckRecipie(player))
  187. {
  188. if (hashtable.TryGetValue(ContinuousController.DeckDataPropertyKey, out object value))
  189. {
  190. DeckData deckData = new DeckData((string)value);
  191. return RandomUtility.ShuffledDeckCards(deckData.DigitamaDeckCards());
  192. }
  193. }
  194. else
  195. {
  196. Debug.Log("!HasDeckRecipie");
  197. }
  198. return null;
  199. }
  200. #endregion
  201. #region vs.AI
  202. else
  203. {
  204. #region プレイヤーのデッキ
  205. if (player == MasterPlayer)
  206. {
  207. if (ContinuousController.instance.BattleDeckData == null)
  208. {
  209. foreach (DeckData deckData in ContinuousController.instance.DeckDatas)
  210. {
  211. if (deckData.IsValidDeckData())
  212. {
  213. return RandomUtility.ShuffledDeckCards(deckData.DigitamaDeckCards());
  214. }
  215. }
  216. }
  217. else
  218. {
  219. if (ContinuousController.instance.BattleDeckData.IsValidDeckData())
  220. {
  221. return RandomUtility.ShuffledDeckCards(ContinuousController.instance.BattleDeckData.DigitamaDeckCards());
  222. }
  223. }
  224. if (RandomDeck != null)
  225. {
  226. return RandomUtility.ShuffledDeckCards(RandomDeck.DigitamaDeckCards());
  227. }
  228. return null;
  229. }
  230. #endregion
  231. #region AIのデッキ
  232. else
  233. {
  234. if (RandomDeck != null)
  235. {
  236. return RandomUtility.ShuffledDeckCards(RandomDeck.DigitamaDeckCards());
  237. }
  238. foreach (DeckData deckData in ContinuousController.instance.DeckDatas)
  239. {
  240. if (deckData.IsValidDeckData())
  241. {
  242. return RandomUtility.ShuffledDeckCards(deckData.DigitamaDeckCards());
  243. }
  244. }
  245. return null;
  246. }
  247. #endregion
  248. }
  249. #endregion
  250. }
  251. #endregion
  252. #region そのPhotonクライアントがデッキレシピのキーを持っているかの判定
  253. bool HasDeckRecipie(Photon.Realtime.Player _player)
  254. {
  255. Hashtable _hashtable = _player.CustomProperties;
  256. if (_hashtable.TryGetValue(ContinuousController.DeckDataPropertyKey, out object value))
  257. {
  258. DeckData deckData = new DeckData((string)value);
  259. if (deckData.IsValidDeckData())
  260. {
  261. return true;
  262. }
  263. }
  264. return false;
  265. }
  266. #endregion
  267. #region カードを生成
  268. GManager.instance.CardIndex = 0;
  269. foreach (CEntity_Base cEntity_Base in DeckRecipie(MasterPlayer))
  270. {
  271. GManager.instance.turnStateMachine.gameContext.PlayerFromID(0).LibraryCards.Add(CreateCardSource(0, cEntity_Base, false));
  272. }
  273. foreach (CEntity_Base cEntity_Base in DigitamaDeckRecipie(MasterPlayer))
  274. {
  275. GManager.instance.turnStateMachine.gameContext.PlayerFromID(0).DigitamaLibraryCards.Add(CreateCardSource(0, cEntity_Base, false));
  276. }
  277. foreach (CEntity_Base cEntity_Base in DeckRecipie(nonMasterPlayer))
  278. {
  279. GManager.instance.turnStateMachine.gameContext.PlayerFromID(1).LibraryCards.Add(CreateCardSource(1, cEntity_Base, false));
  280. }
  281. foreach (CEntity_Base cEntity_Base in DigitamaDeckRecipie(nonMasterPlayer))
  282. {
  283. GManager.instance.turnStateMachine.gameContext.PlayerFromID(1).DigitamaLibraryCards.Add(CreateCardSource(1, cEntity_Base, false));
  284. }
  285. #endregion
  286. }
  287. #endregion
  288. #region generate card
  289. public static CardSource CreateCardSource(int _PlayerID, CEntity_Base cEntity_Base, bool isToken)
  290. {
  291. Player player = GManager.instance.turnStateMachine.gameContext.PlayerFromID(_PlayerID);
  292. CardSource cardSource = Instantiate(GManager.instance.CardPrefab, player.CardSorcesParent);
  293. cardSource.SetBaseData(cEntity_Base, player);
  294. cardSource.cEntity_EffectController.AddCardEffect(cEntity_Base.CardID, cEntity_Base.CardEffectClassName);
  295. cardSource.SetUpCardIndex(GManager.instance.CardIndex);
  296. cardSource.SetIsToken(isToken);
  297. GManager.instance.turnStateMachine.gameContext.ActiveCardList.Add(cardSource);
  298. GManager.instance.CardIndex++;
  299. return cardSource;
  300. }
  301. #endregion
  302. #region Remove cards from all areas
  303. public static IEnumerator RemoveFromAllArea(CardSource cardSource)
  304. {
  305. cardSource.SetFace();
  306. if (cardSource.Owner.HandCards.Contains(cardSource))
  307. {
  308. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeleteHandCardEffectCoroutine(cardSource));
  309. }
  310. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  311. {
  312. List<Permanent> permanents = new List<Permanent>();
  313. foreach (Permanent permanent in player.GetFieldPermanents())
  314. {
  315. permanents.Add(permanent);
  316. }
  317. foreach (Permanent permanent in permanents)
  318. {
  319. if (permanent.cardSources.Contains(cardSource))
  320. {
  321. yield return ContinuousController.instance.StartCoroutine(permanent.RemoveCardSource(cardSource));
  322. }
  323. if(permanent.LinkedCards.Any(linked => linked.Source == cardSource))
  324. {
  325. yield return ContinuousController.instance.StartCoroutine(permanent.RemoveLinkedCard(cardSource));
  326. }
  327. }
  328. }
  329. //手札から取り除く
  330. while (cardSource.Owner.HandCards.Contains(cardSource))
  331. {
  332. cardSource.Owner.HandCards.Remove(cardSource);
  333. }
  334. //デッキから取り除く
  335. while (cardSource.Owner.LibraryCards.Contains(cardSource))
  336. {
  337. cardSource.Owner.LibraryCards.Remove(cardSource);
  338. }
  339. //デジタマデッキから取り除く
  340. while (cardSource.Owner.DigitamaLibraryCards.Contains(cardSource))
  341. {
  342. cardSource.Owner.DigitamaLibraryCards.Remove(cardSource);
  343. }
  344. //トラッシュから取り除く
  345. while (CardEffectCommons.IsExistOnTrash(cardSource))
  346. {
  347. cardSource.Owner.TrashCards.Remove(cardSource);
  348. }
  349. //思い出から取り除く
  350. while (cardSource.Owner.LostCards.Contains(cardSource))
  351. {
  352. cardSource.Owner.LostCards.Remove(cardSource);
  353. }
  354. //ライフから取り除く
  355. while (cardSource.Owner.SecurityCards.Contains(cardSource))
  356. {
  357. cardSource.Owner.SecurityCards.Remove(cardSource);
  358. }
  359. //処理領域から取り除く
  360. while (cardSource.Owner.ExecutingCards.Contains(cardSource))
  361. {
  362. cardSource.Owner.ExecutingCards.Remove(cardSource);
  363. }
  364. }
  365. #endregion
  366. #region 手札のカードを整列する
  367. public static void AlignHand(Player player)
  368. {
  369. int n = player.HandTransform.childCount;
  370. float scale = player.HandTransform.transform.localScale.x;
  371. if (n > 0)
  372. {
  373. float CardWidth = player.HandTransform.GetChild(0).GetComponent<RectTransform>().sizeDelta.x;
  374. //If it fits within the area as it is.
  375. if (n * scale * CardWidth < player.HandWidth)
  376. {
  377. player.HandTransform.GetComponent<GridLayoutGroup>().spacing = new Vector2(0, 0);
  378. //player.HandTransform.GetComponent<GridLayoutGroup>().spacing = new Vector2(7, 0);
  379. }
  380. //If it sticks out as it is
  381. else
  382. {
  383. float delta = (n * scale * CardWidth - player.HandWidth) / ((n - 1) * scale);
  384. player.HandTransform.GetComponent<GridLayoutGroup>().spacing = new Vector2(-delta, 0);
  385. }
  386. }
  387. }
  388. #endregion
  389. #region 新しいパーマネントを生成する
  390. public static IEnumerator CreateNewPermanent(Permanent permanent, int frameID)
  391. {
  392. if (permanent.TopCard != null)
  393. {
  394. if (permanent.TopCard.Owner != null)
  395. {
  396. yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(permanent.TopCard));
  397. if (0 <= frameID && frameID <= permanent.TopCard.Owner.FieldPermanents.Length)
  398. {
  399. permanent.TopCard.Owner.FieldPermanents[frameID] = permanent;
  400. permanent.TopCard.Owner.fieldCardFrames[frameID].SetFramePermanent(permanent);
  401. permanent.TopCard.SetFace();
  402. FieldPermanentCard fieldPermanentCard = Instantiate(GManager.instance.fieldCardPrefab, permanent.TopCard.Owner.PermanentTransform);
  403. fieldPermanentCard.SetPermanentData(permanent, false);
  404. fieldPermanentCard.StartScale = fieldPermanentCard.transform.localScale;
  405. permanent.ShowingPermanentCard = fieldPermanentCard;
  406. fieldPermanentCard.transform.localPosition = permanent.TopCard.Owner.fieldCardFrames[frameID].GetLocalCanvasPosition();
  407. fieldPermanentCard.gameObject.SetActive(false);
  408. }
  409. }
  410. }
  411. }
  412. #endregion
  413. #region leave the place
  414. public static IEnumerator RemoveField(Permanent permanent, bool ignoreOverflow = false)
  415. {
  416. if (permanent == null) yield break;
  417. if (permanent.TopCard == null) yield break;
  418. if (!ignoreOverflow)
  419. {
  420. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(permanent.cardSources).Overflow());
  421. }
  422. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  423. {
  424. while (player.GetFieldPermanents().Contains(permanent))
  425. {
  426. for (int i = 0; i < permanent.TopCard.Owner.FieldPermanents.Length; i++)
  427. {
  428. if (permanent.TopCard.Owner.FieldPermanents[i] == permanent)
  429. {
  430. permanent.TopCard.Owner.FieldPermanents[i] = null;
  431. permanent.TopCard.Owner.fieldCardFrames[i].SetFramePermanent(null);
  432. }
  433. }
  434. }
  435. }
  436. if (permanent.TopCard != null)
  437. {
  438. foreach (CardSource cardSource in permanent.cardSources)
  439. {
  440. cardSource.Init();
  441. }
  442. permanent.cardSources = new List<CardSource>();
  443. }
  444. }
  445. #endregion
  446. #region add card to hand
  447. public static IEnumerator AddHandCards(List<CardSource> cardSources, bool isDraw, ICardEffect cardEffect)
  448. {
  449. if (cardSources.Count == 0) yield break;
  450. bool isFromTrash = cardSources.Some(cardSource => CardEffectCommons.IsExistOnTrash(cardSource));
  451. cardSources = cardSources.Filter(cardSource => cardSource != null && !cardSource.Owner.HandCards.Contains(cardSource));
  452. if (isFromTrash)
  453. {
  454. #region "Effect of "When a card is returned from the trash to the hand"
  455. #region Hashtable Setting
  456. System.Collections.Hashtable hashtable = new System.Collections.Hashtable()
  457. {
  458. {"CardSources", cardSources}
  459. };
  460. #endregion
  461. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnReturnCardsToHandFromTrash));
  462. #endregion
  463. }
  464. foreach (CardSource cardSource in cardSources)
  465. {
  466. if (cardSource.IsToken)
  467. {
  468. yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
  469. }
  470. }
  471. List<CardSource> eggCards = cardSources.Filter(cardSource => cardSource.IsDigiEgg);
  472. List<CardSource> addedCards = cardSources.Filter(cardSource => !cardSource.IsDigiEgg && !cardSource.IsToken);
  473. if (eggCards.Count <= 0)
  474. yield return ContinuousController.instance.StartCoroutine(AddLibraryBottomCards(eggCards));
  475. if (addedCards.Count <= 0) yield break;
  476. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(addedCards).Overflow());
  477. foreach (CardSource cardSource in addedCards)
  478. {
  479. yield return ContinuousController.instance.StartCoroutine(AddHandCard(cardSource, isDraw));
  480. }
  481. if (GManager.instance.turnStateMachine.DoneStartGame && addedCards.Count > 0)
  482. {
  483. List<Player> Players = addedCards.Map(cardSource => cardSource.Owner).Distinct().ToList();
  484. #region Effect of "When the number of cards in hand increases"
  485. #region Hashtable Setting
  486. System.Collections.Hashtable _hashtable = new System.Collections.Hashtable()
  487. {
  488. {"Players", Players},
  489. {"CardEffect", cardEffect},
  490. {"CardSources", addedCards},
  491. };
  492. #endregion
  493. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(_hashtable, EffectTiming.OnAddHand));
  494. #endregion
  495. }
  496. }
  497. public static IEnumerator AddHandCard(CardSource cardSource, bool isDraw)
  498. {
  499. cardSource.Init();
  500. cardSource.SetFace();
  501. if (!cardSource.Owner.HandCards.Contains(cardSource))
  502. {
  503. yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
  504. if (!cardSource.IsToken)
  505. {
  506. cardSource.Owner.HandCards.Add(cardSource);
  507. if (isDraw)
  508. {
  509. if (GManager.instance.turnStateMachine.DoneStartGame)
  510. {
  511. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().AddHandCardEffect(cardSource));
  512. }
  513. }
  514. else
  515. {
  516. ContinuousController.instance.PlaySE(GManager.instance.DrawSE);
  517. }
  518. HandCard handCard = Instantiate(GManager.instance.handCardPrefab, cardSource.Owner.HandTransform);
  519. handCard.gameObject.name = $"handCard_{cardSource.Owner.PlayerName}";
  520. handCard.GetComponent<Draggable_HandCard>().startScale = handCard.transform.localScale;
  521. handCard.GetComponent<Draggable_HandCard>().DefaultY = -9;
  522. handCard.SetUpHandCard(cardSource);
  523. AlignHand(cardSource.Owner);
  524. cardSource.SetShowingHandCard(handCard);
  525. if (cardSource.Owner.isYou)
  526. {
  527. handCard.SetUpHandCardImage();
  528. handCard.ShowCostLevel();
  529. }
  530. yield return new WaitForSeconds(Time.deltaTime);
  531. #region アニメーション
  532. if (GManager.instance.turnStateMachine.DoneStartGame)
  533. {
  534. cardSource.Owner.HandTransform.GetComponent<GridLayoutGroup>().enabled = false;
  535. Vector3 startPosition = Vector3.zero;
  536. Vector3 targetPositon = handCard.transform.localPosition;
  537. if (cardSource.Owner.isYou)
  538. {
  539. startPosition = handCard.transform.localPosition + new Vector3(0, 70, 0);
  540. }
  541. else
  542. {
  543. startPosition = handCard.transform.localPosition - new Vector3(0, 70, 0);
  544. }
  545. handCard.transform.localPosition = startPosition;
  546. bool end = false;
  547. var sequence = DOTween.Sequence();
  548. sequence
  549. .Append(handCard.transform.DOLocalMove(targetPositon, 0.08f).SetEase(Ease.OutBack))
  550. .AppendCallback(() => { end = true; });
  551. yield return new WaitWhile(() => !end);
  552. end = false;
  553. cardSource.Owner.HandTransform.GetComponent<GridLayoutGroup>().enabled = true;
  554. }
  555. #endregion
  556. if (cardSource.Owner.isYou)
  557. {
  558. handCard.SetUpHandCardImage();
  559. handCard.ShowCostLevel();
  560. }
  561. }
  562. }
  563. }
  564. #endregion
  565. #region put the card in the trash
  566. public static IEnumerator AddTrashCard(CardSource cardSource)
  567. {
  568. if (!CardEffectCommons.IsExistOnTrash(cardSource))
  569. {
  570. yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
  571. if (!cardSource.IsToken)
  572. {
  573. cardSource.SetFace();
  574. if (!CardEffectCommons.IsExistOnTrash(cardSource))
  575. {
  576. cardSource.Owner.TrashCards.Insert(0, cardSource);
  577. }
  578. cardSource.Init();
  579. }
  580. }
  581. }
  582. #endregion
  583. #region Put the cards together in the trash
  584. public static IEnumerator AddTrashCards(List<CardSource> cardSources)
  585. {
  586. List<CardSource> handCards = new List<CardSource>();
  587. foreach (CardSource cardSource in cardSources)
  588. {
  589. if (cardSource.Owner.HandCards.Contains(cardSource))
  590. {
  591. handCards.Add(cardSource);
  592. }
  593. }
  594. foreach (CardSource cardSource in handCards)
  595. {
  596. ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeleteHandCardEffectCoroutine(cardSource));
  597. }
  598. yield return new WaitForSeconds(GManager.instance.GetComponent<Effects>().waitTime_DeleteHandEffect);
  599. foreach (CardSource cardSource in cardSources)
  600. {
  601. if (!CardEffectCommons.IsExistOnTrash(cardSource))
  602. {
  603. yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
  604. if (!cardSource.IsToken)
  605. {
  606. cardSource.SetFace();
  607. if (!CardEffectCommons.IsExistOnTrash(cardSource))
  608. {
  609. cardSource.Owner.TrashCards.Insert(0, cardSource);
  610. }
  611. cardSource.Init();
  612. }
  613. }
  614. }
  615. }
  616. #endregion
  617. #region place a card on top of the deck
  618. public static IEnumerator AddLibraryTopCards(List<CardSource> cardSources, bool notAddLog = false)
  619. {
  620. if (cardSources.Count <= 0) yield break;
  621. bool isFromTrash = cardSources.Some(cardSource => CardEffectCommons.IsExistOnTrash(cardSource));
  622. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(cardSources).Overflow());
  623. if (isFromTrash)
  624. {
  625. #region "Effect of "When a card is returned from the trash to the deck"
  626. #region Hashtable Setting
  627. System.Collections.Hashtable hashtable = new System.Collections.Hashtable()
  628. {
  629. {"CardSources", cardSources}
  630. };
  631. #endregion
  632. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnReturnCardsToLibraryFromTrash));
  633. #endregion
  634. }
  635. foreach (CardSource cardSource in cardSources)
  636. {
  637. bool isFromHand = CardEffectCommons.IsExistOnHand(cardSource);
  638. yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
  639. if (isFromHand && GManager.instance.turnStateMachine.DoneStartGame)
  640. {
  641. yield return new WaitForSeconds(GManager.instance.GetComponent<Effects>().waitTime_DeleteHandEffect);
  642. }
  643. if (!cardSource.IsToken)
  644. {
  645. cardSource.SetFace();
  646. if (!cardSource.IsDigiEgg)
  647. {
  648. if (!cardSource.Owner.LibraryCards.Contains(cardSource))
  649. {
  650. cardSource.Owner.LibraryCards.Insert(0, cardSource);
  651. }
  652. }
  653. else
  654. {
  655. if (!cardSource.Owner.DigitamaLibraryCards.Contains(cardSource))
  656. {
  657. cardSource.Owner.DigitamaLibraryCards.Insert(0, cardSource);
  658. }
  659. }
  660. cardSource.Init();
  661. }
  662. }
  663. #region Log
  664. if (!notAddLog)
  665. {
  666. if (cardSources.Count >= 1)
  667. {
  668. string log = "";
  669. log += $"\nDeck Top card{Utils.PluralFormSuffix(cardSources.Count)}:";
  670. foreach (CardSource cardSource in cardSources)
  671. {
  672. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  673. }
  674. log += "\n";
  675. PlayLog.OnAddLog?.Invoke(log);
  676. }
  677. }
  678. #endregion
  679. }
  680. #endregion
  681. #region put a card at the bottom of the deck
  682. public static IEnumerator AddLibraryBottomCards(List<CardSource> cardSources, bool notAddLog = false)
  683. {
  684. if (cardSources.Count <= 0) yield break;
  685. bool isFromTrash = cardSources.Some(cardSource => CardEffectCommons.IsExistOnTrash(cardSource));
  686. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(cardSources).Overflow());
  687. if (isFromTrash)
  688. {
  689. #region Effect of "When a card returns from the trash to the deck"
  690. #region Hashtable Setting
  691. System.Collections.Hashtable hashtable = new System.Collections.Hashtable()
  692. {
  693. {"CardSources", cardSources}
  694. };
  695. #endregion
  696. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnReturnCardsToLibraryFromTrash));
  697. #endregion
  698. }
  699. foreach (CardSource cardSource in cardSources)
  700. {
  701. if (cardSource.PermanentOfThisCard() != null)
  702. {
  703. if (cardSource.PermanentOfThisCard().DigivolutionCards.Contains(cardSource))
  704. {
  705. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>()
  706. .RemoveDigivolveRootEffect(cardSource, cardSource.PermanentOfThisCard()));
  707. }
  708. }
  709. }
  710. foreach (CardSource cardSource in cardSources.Clone())
  711. {
  712. bool isFromHand = CardEffectCommons.IsExistOnHand(cardSource);
  713. yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
  714. if (isFromHand && GManager.instance.turnStateMachine.DoneStartGame)
  715. {
  716. yield return new WaitForSeconds(GManager.instance.GetComponent<Effects>().waitTime_DeleteHandEffect);
  717. }
  718. if (!cardSource.IsToken)
  719. {
  720. cardSource.SetFace();
  721. if (!cardSource.IsDigiEgg)
  722. {
  723. if (!cardSource.Owner.LibraryCards.Contains(cardSource))
  724. {
  725. cardSource.Owner.LibraryCards.Add(cardSource);
  726. }
  727. }
  728. else
  729. {
  730. if (!cardSource.Owner.DigitamaLibraryCards.Contains(cardSource))
  731. {
  732. cardSource.Owner.DigitamaLibraryCards.Add(cardSource);
  733. }
  734. }
  735. cardSource.Init();
  736. }
  737. }
  738. #region Log
  739. if (!notAddLog)
  740. {
  741. if (cardSources.Count >= 1)
  742. {
  743. string log = "";
  744. log += $"\nDeck Bottom card{Utils.PluralFormSuffix(cardSources.Count)}:";
  745. foreach (CardSource cardSource in cardSources)
  746. {
  747. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  748. }
  749. log += "\n";
  750. PlayLog.OnAddLog?.Invoke(log);
  751. }
  752. }
  753. #endregion
  754. }
  755. #endregion
  756. #region Place the card in the processing area
  757. public static IEnumerator AddExecutingCard(CardSource cardSource)
  758. {
  759. if (!cardSource.Owner.ExecutingCards.Contains(cardSource))
  760. {
  761. yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
  762. if (!cardSource.IsToken)
  763. {
  764. cardSource.SetFace();
  765. cardSource.Owner.ExecutingCards.Insert(0, cardSource);
  766. cardSource.Init();
  767. }
  768. }
  769. }
  770. #endregion
  771. #region Add card to security
  772. public static IEnumerator AddSecurityCard(CardSource cardSource, bool toTop = true, bool faceUp = false)
  773. {
  774. if (!cardSource.Owner.SecurityCards.Contains(cardSource))
  775. {
  776. yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
  777. if (!cardSource.IsToken)
  778. {
  779. if (!faceUp)
  780. cardSource.SetReverse();
  781. else
  782. cardSource.SetFace();
  783. cardSource.Owner.SecurityCards.Insert(0, cardSource);
  784. if (!toTop)
  785. {
  786. cardSource.Owner.SecurityCards.Remove(cardSource);
  787. cardSource.Owner.SecurityCards.Add(cardSource);
  788. }
  789. }
  790. }
  791. }
  792. #endregion
  793. #region Shuffle
  794. public static IEnumerator Shuffle(Player player)
  795. {
  796. ContinuousController.instance.PlaySE(GManager.instance.ShuffleSE);
  797. player.LibraryCards = RandomUtility.ShuffledDeckCards(player.LibraryCards);
  798. yield return ContinuousController.instance.StartCoroutine(player.ShuffleAnimation());
  799. }
  800. #endregion
  801. #region move permanent
  802. public static IEnumerator MovePermanent(FieldCardFrame movingPermanentFrame, bool toBreeding = false)
  803. {
  804. if (movingPermanentFrame != null)
  805. {
  806. Player player = movingPermanentFrame.player;
  807. Permanent movingPermanent = movingPermanentFrame.GetFramePermanent();
  808. if (movingPermanent != null)
  809. {
  810. bool prevIsFrontLine = movingPermanentFrame.IsBattleAreaFrame();
  811. FieldCardFrame moveTargetFrame = movingPermanent.TopCard.PreferredFrame();
  812. if (toBreeding)
  813. moveTargetFrame = player.fieldCardFrames.Filter(frame => frame.isBreedingAreaFrame()).ToList()[0];
  814. if (moveTargetFrame != null && moveTargetFrame != null)
  815. {
  816. if (moveTargetFrame.GetFramePermanent() == null)
  817. {
  818. int oldFrameID = movingPermanentFrame.FrameID;
  819. int newFrameID = moveTargetFrame.FrameID;
  820. player.FieldPermanents[oldFrameID] = null;
  821. player.fieldCardFrames[oldFrameID].SetFramePermanent(null);
  822. player.FieldPermanents[newFrameID] = movingPermanent;
  823. player.fieldCardFrames[newFrameID].SetFramePermanent(movingPermanent);
  824. #region animation
  825. bool end = false;
  826. var sequence = DOTween.Sequence();
  827. FieldPermanentCard movingPermanentCard = movingPermanent.ShowingPermanentCard;
  828. Vector3 TargetPosition = moveTargetFrame.GetLocalCanvasPosition();
  829. Vector3 oldPosition = movingPermanentFrame.GetLocalCanvasPosition();
  830. float GoTime = 0.2f;
  831. sequence
  832. .Append(movingPermanentCard.transform.DOLocalMove(TargetPosition, GoTime).SetEase(Ease.OutCubic))
  833. .AppendCallback(() =>
  834. {
  835. end = true;
  836. });
  837. sequence.Play();
  838. yield return new WaitWhile(() => !end);
  839. end = false;
  840. #endregion
  841. if (!prevIsFrontLine)
  842. {
  843. #region Effect of "when moving from the training area"
  844. #region Hashtable Setting
  845. System.Collections.Hashtable hashtable = new System.Collections.Hashtable()
  846. {
  847. {"Permanent", movingPermanent}
  848. };
  849. #endregion
  850. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnMove));
  851. #endregion
  852. }
  853. }
  854. }
  855. }
  856. }
  857. }
  858. #endregion
  859. }