CardObjectController.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044
  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 お互いのプレイヤーのデッキのカードを生成する
  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());
  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());
  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 カードを生成
  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.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 カードをすべての領域から取り除く
  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. }
  324. }
  325. //手札から取り除く
  326. while (cardSource.Owner.HandCards.Contains(cardSource))
  327. {
  328. cardSource.Owner.HandCards.Remove(cardSource);
  329. }
  330. //デッキから取り除く
  331. while (cardSource.Owner.LibraryCards.Contains(cardSource))
  332. {
  333. cardSource.Owner.LibraryCards.Remove(cardSource);
  334. }
  335. //デジタマデッキから取り除く
  336. while (cardSource.Owner.DigitamaLibraryCards.Contains(cardSource))
  337. {
  338. cardSource.Owner.DigitamaLibraryCards.Remove(cardSource);
  339. }
  340. //トラッシュから取り除く
  341. while (CardEffectCommons.IsExistOnTrash(cardSource))
  342. {
  343. cardSource.Owner.TrashCards.Remove(cardSource);
  344. }
  345. //思い出から取り除く
  346. while (cardSource.Owner.LostCards.Contains(cardSource))
  347. {
  348. cardSource.Owner.LostCards.Remove(cardSource);
  349. }
  350. //ライフから取り除く
  351. while (cardSource.Owner.SecurityCards.Contains(cardSource))
  352. {
  353. cardSource.Owner.SecurityCards.Remove(cardSource);
  354. }
  355. //処理領域から取り除く
  356. while (cardSource.Owner.ExecutingCards.Contains(cardSource))
  357. {
  358. cardSource.Owner.ExecutingCards.Remove(cardSource);
  359. }
  360. }
  361. #endregion
  362. #region 手札のカードを整列する
  363. public static void AlignHand(Player player)
  364. {
  365. int n = player.HandTransform.childCount;
  366. float scale = player.HandTransform.transform.localScale.x;
  367. if (n > 0)
  368. {
  369. float CardWidth = player.HandTransform.GetChild(0).GetComponent<RectTransform>().sizeDelta.x;
  370. //If it fits within the area as it is.
  371. if (n * scale * CardWidth < player.HandWidth)
  372. {
  373. player.HandTransform.GetComponent<GridLayoutGroup>().spacing = new Vector2(0, 0);
  374. //player.HandTransform.GetComponent<GridLayoutGroup>().spacing = new Vector2(7, 0);
  375. }
  376. //If it sticks out as it is
  377. else
  378. {
  379. float delta = (n * scale * CardWidth - player.HandWidth) / ((n - 1) * scale);
  380. player.HandTransform.GetComponent<GridLayoutGroup>().spacing = new Vector2(-delta, 0);
  381. }
  382. }
  383. }
  384. #endregion
  385. #region 新しいパーマネントを生成する
  386. public static IEnumerator CreateNewPermanent(Permanent permanent, int frameID)
  387. {
  388. if (permanent.TopCard != null)
  389. {
  390. if (permanent.TopCard.Owner != null)
  391. {
  392. yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(permanent.TopCard));
  393. if (0 <= frameID && frameID <= permanent.TopCard.Owner.FieldPermanents.Length)
  394. {
  395. permanent.TopCard.Owner.FieldPermanents[frameID] = permanent;
  396. permanent.TopCard.Owner.fieldCardFrames[frameID].SetFramePermanent(permanent);
  397. permanent.TopCard.SetFace();
  398. FieldPermanentCard fieldPermanentCard = Instantiate(GManager.instance.fieldCardPrefab, permanent.TopCard.Owner.PermanentTransform);
  399. fieldPermanentCard.SetPermanentData(permanent, false);
  400. fieldPermanentCard.StartScale = fieldPermanentCard.transform.localScale;
  401. permanent.ShowingPermanentCard = fieldPermanentCard;
  402. fieldPermanentCard.transform.localPosition = permanent.TopCard.Owner.fieldCardFrames[frameID].GetLocalCanvasPosition();
  403. fieldPermanentCard.gameObject.SetActive(false);
  404. }
  405. }
  406. }
  407. }
  408. #endregion
  409. #region 場を離れさせる
  410. public static IEnumerator RemoveField(Permanent permanent, bool ignoreOverflow = false)
  411. {
  412. if (permanent == null) yield break;
  413. if (permanent.TopCard == null) yield break;
  414. if (!ignoreOverflow)
  415. {
  416. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(permanent.cardSources).Overflow());
  417. }
  418. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  419. {
  420. while (player.GetFieldPermanents().Contains(permanent))
  421. {
  422. for (int i = 0; i < permanent.TopCard.Owner.FieldPermanents.Length; i++)
  423. {
  424. if (permanent.TopCard.Owner.FieldPermanents[i] == permanent)
  425. {
  426. permanent.TopCard.Owner.FieldPermanents[i] = null;
  427. permanent.TopCard.Owner.fieldCardFrames[i].SetFramePermanent(null);
  428. }
  429. }
  430. }
  431. }
  432. if (permanent.TopCard != null)
  433. {
  434. foreach (CardSource cardSource in permanent.cardSources)
  435. {
  436. cardSource.Init();
  437. }
  438. permanent.cardSources = new List<CardSource>();
  439. }
  440. }
  441. #endregion
  442. #region カードを手札に加える
  443. public static IEnumerator AddHandCards(List<CardSource> cardSources, bool isDraw, ICardEffect cardEffect)
  444. {
  445. if (cardSources.Count == 0) yield break;
  446. cardSources = cardSources.Filter(cardSource => cardSource != null && !cardSource.Owner.HandCards.Contains(cardSource));
  447. foreach (CardSource cardSource in cardSources)
  448. {
  449. if (cardSource.IsToken)
  450. {
  451. yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
  452. }
  453. }
  454. List<CardSource> addedCards = cardSources.Filter(cardSource => !cardSource.IsToken);
  455. if (addedCards.Count <= 0) yield break;
  456. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(addedCards).Overflow());
  457. foreach (CardSource cardSource in addedCards)
  458. {
  459. yield return ContinuousController.instance.StartCoroutine(AddHandCard(cardSource, isDraw));
  460. }
  461. if (GManager.instance.turnStateMachine.DoneStartGame)
  462. {
  463. List<Player> Players = addedCards.Map(cardSource => cardSource.Owner).Distinct().ToList();
  464. #region "手札が増えた時"の効果
  465. #region Hashtable Setting
  466. System.Collections.Hashtable _hashtable = new System.Collections.Hashtable()
  467. {
  468. {"Players", Players},
  469. {"CardEffect", cardEffect},
  470. {"CardSources", addedCards},
  471. };
  472. #endregion
  473. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(_hashtable, EffectTiming.OnAddHand));
  474. #endregion
  475. }
  476. }
  477. static IEnumerator AddHandCard(CardSource cardSource, bool isDraw)
  478. {
  479. cardSource.Init();
  480. cardSource.SetFace();
  481. if (!cardSource.Owner.HandCards.Contains(cardSource))
  482. {
  483. yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
  484. if (!cardSource.IsToken)
  485. {
  486. cardSource.Owner.HandCards.Add(cardSource);
  487. if (isDraw)
  488. {
  489. if (GManager.instance.turnStateMachine.DoneStartGame)
  490. {
  491. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().AddHandCardEffect(cardSource));
  492. }
  493. }
  494. else
  495. {
  496. ContinuousController.instance.PlaySE(GManager.instance.DrawSE);
  497. }
  498. HandCard handCard = Instantiate(GManager.instance.handCardPrefab, cardSource.Owner.HandTransform);
  499. handCard.gameObject.name = $"handCard_{cardSource.Owner.PlayerName}";
  500. handCard.GetComponent<Draggable_HandCard>().startScale = handCard.transform.localScale;
  501. handCard.GetComponent<Draggable_HandCard>().DefaultY = -9;
  502. handCard.SetUpHandCard(cardSource);
  503. AlignHand(cardSource.Owner);
  504. cardSource.SetShowingHandCard(handCard);
  505. if (cardSource.Owner.isYou)
  506. {
  507. handCard.SetUpHandCardImage();
  508. handCard.ShowCostLevel();
  509. }
  510. yield return new WaitForSeconds(Time.deltaTime);
  511. #region アニメーション
  512. if (GManager.instance.turnStateMachine.DoneStartGame)
  513. {
  514. cardSource.Owner.HandTransform.GetComponent<GridLayoutGroup>().enabled = false;
  515. Vector3 startPosition = Vector3.zero;
  516. Vector3 targetPositon = handCard.transform.localPosition;
  517. if (cardSource.Owner.isYou)
  518. {
  519. startPosition = handCard.transform.localPosition + new Vector3(0, 70, 0);
  520. }
  521. else
  522. {
  523. startPosition = handCard.transform.localPosition - new Vector3(0, 70, 0);
  524. }
  525. handCard.transform.localPosition = startPosition;
  526. bool end = false;
  527. var sequence = DOTween.Sequence();
  528. sequence
  529. .Append(handCard.transform.DOLocalMove(targetPositon, 0.08f).SetEase(Ease.OutBack))
  530. .AppendCallback(() => { end = true; });
  531. yield return new WaitWhile(() => !end);
  532. end = false;
  533. cardSource.Owner.HandTransform.GetComponent<GridLayoutGroup>().enabled = true;
  534. }
  535. #endregion
  536. if (cardSource.Owner.isYou)
  537. {
  538. handCard.SetUpHandCardImage();
  539. handCard.ShowCostLevel();
  540. }
  541. }
  542. }
  543. }
  544. #endregion
  545. #region カードをトラッシュに置く
  546. public static IEnumerator AddTrashCard(CardSource cardSource)
  547. {
  548. if (!CardEffectCommons.IsExistOnTrash(cardSource))
  549. {
  550. yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
  551. if (!cardSource.IsToken)
  552. {
  553. cardSource.SetFace();
  554. if (!CardEffectCommons.IsExistOnTrash(cardSource))
  555. {
  556. cardSource.Owner.TrashCards.Insert(0, cardSource);
  557. }
  558. cardSource.Init();
  559. }
  560. }
  561. }
  562. #endregion
  563. #region カードをまとめてトラッシュに置く
  564. public static IEnumerator AddTrashCards(List<CardSource> cardSources)
  565. {
  566. List<CardSource> handCards = new List<CardSource>();
  567. foreach (CardSource cardSource in cardSources)
  568. {
  569. if (cardSource.Owner.HandCards.Contains(cardSource))
  570. {
  571. handCards.Add(cardSource);
  572. }
  573. }
  574. foreach (CardSource cardSource in handCards)
  575. {
  576. ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeleteHandCardEffectCoroutine(cardSource));
  577. }
  578. yield return new WaitForSeconds(GManager.instance.GetComponent<Effects>().waitTime_DeleteHandEffect);
  579. foreach (CardSource cardSource in cardSources)
  580. {
  581. if (!CardEffectCommons.IsExistOnTrash(cardSource))
  582. {
  583. yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
  584. if (!cardSource.IsToken)
  585. {
  586. cardSource.SetFace();
  587. if (!CardEffectCommons.IsExistOnTrash(cardSource))
  588. {
  589. cardSource.Owner.TrashCards.Insert(0, cardSource);
  590. }
  591. cardSource.Init();
  592. }
  593. }
  594. }
  595. }
  596. #endregion
  597. #region カードを山札の上に置く
  598. public static IEnumerator AddLibraryTopCards(List<CardSource> cardSources, bool notAddLog = false)
  599. {
  600. if (cardSources.Count <= 0) yield break;
  601. bool isFromTrash = cardSources.Some(cardSource => CardEffectCommons.IsExistOnTrash(cardSource));
  602. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(cardSources).Overflow());
  603. if (isFromTrash)
  604. {
  605. #region "カードがトラッシュから山札に戻った時"の効果
  606. #region Hashtable Setting
  607. System.Collections.Hashtable hashtable = new System.Collections.Hashtable()
  608. {
  609. {"CardSources", cardSources}
  610. };
  611. #endregion
  612. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnReturnCardsToLibraryFromTrash));
  613. #endregion
  614. }
  615. foreach (CardSource cardSource in cardSources)
  616. {
  617. bool isFromHand = CardEffectCommons.IsExistOnHand(cardSource);
  618. yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
  619. if (isFromHand && GManager.instance.turnStateMachine.DoneStartGame)
  620. {
  621. yield return new WaitForSeconds(GManager.instance.GetComponent<Effects>().waitTime_DeleteHandEffect);
  622. }
  623. if (!cardSource.IsToken)
  624. {
  625. cardSource.SetFace();
  626. if (!cardSource.IsDigiEgg)
  627. {
  628. if (!cardSource.Owner.LibraryCards.Contains(cardSource))
  629. {
  630. cardSource.Owner.LibraryCards.Insert(0, cardSource);
  631. }
  632. }
  633. else
  634. {
  635. if (!cardSource.Owner.DigitamaLibraryCards.Contains(cardSource))
  636. {
  637. cardSource.Owner.DigitamaLibraryCards.Insert(0, cardSource);
  638. }
  639. }
  640. cardSource.Init();
  641. }
  642. }
  643. #region Log
  644. if (!notAddLog)
  645. {
  646. if (cardSources.Count >= 1)
  647. {
  648. string log = "";
  649. log += $"\nDeck Top card{Utils.PluralFormSuffix(cardSources.Count)}:";
  650. foreach (CardSource cardSource in cardSources)
  651. {
  652. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  653. }
  654. log += "\n";
  655. GManager.instance.playLog.AddLogString(log);
  656. }
  657. }
  658. #endregion
  659. }
  660. #endregion
  661. #region カードを山札の下に置く
  662. public static IEnumerator AddLibraryBottomCards(List<CardSource> cardSources, bool notAddLog = false)
  663. {
  664. if (cardSources.Count <= 0) yield break;
  665. bool isFromTrash = cardSources.Some(cardSource => CardEffectCommons.IsExistOnTrash(cardSource));
  666. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(cardSources).Overflow());
  667. if (isFromTrash)
  668. {
  669. #region "カードがトラッシュから山札に戻った時"の効果
  670. #region Hashtable Setting
  671. System.Collections.Hashtable hashtable = new System.Collections.Hashtable()
  672. {
  673. {"CardSources", cardSources}
  674. };
  675. #endregion
  676. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnReturnCardsToLibraryFromTrash));
  677. #endregion
  678. }
  679. foreach (CardSource cardSource in cardSources)
  680. {
  681. if (cardSource.PermanentOfThisCard() != null)
  682. {
  683. if (cardSource.PermanentOfThisCard().DigivolutionCards.Contains(cardSource))
  684. {
  685. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>()
  686. .RemoveDigivolveRootEffect(cardSource, cardSource.PermanentOfThisCard()));
  687. }
  688. }
  689. }
  690. foreach (CardSource cardSource in cardSources)
  691. {
  692. bool isFromHand = CardEffectCommons.IsExistOnHand(cardSource);
  693. yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
  694. if (isFromHand && GManager.instance.turnStateMachine.DoneStartGame)
  695. {
  696. yield return new WaitForSeconds(GManager.instance.GetComponent<Effects>().waitTime_DeleteHandEffect);
  697. }
  698. if (!cardSource.IsToken)
  699. {
  700. cardSource.SetFace();
  701. if (!cardSource.IsDigiEgg)
  702. {
  703. if (!cardSource.Owner.LibraryCards.Contains(cardSource))
  704. {
  705. cardSource.Owner.LibraryCards.Add(cardSource);
  706. }
  707. }
  708. else
  709. {
  710. if (!cardSource.Owner.DigitamaLibraryCards.Contains(cardSource))
  711. {
  712. cardSource.Owner.DigitamaLibraryCards.Add(cardSource);
  713. }
  714. }
  715. cardSource.Init();
  716. }
  717. }
  718. #region Log
  719. if (!notAddLog)
  720. {
  721. if (cardSources.Count >= 1)
  722. {
  723. string log = "";
  724. log += $"\nDeck Bottom card{Utils.PluralFormSuffix(cardSources.Count)}:";
  725. foreach (CardSource cardSource in cardSources)
  726. {
  727. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  728. }
  729. log += "\n";
  730. GManager.instance.playLog.AddLogString(log);
  731. }
  732. }
  733. #endregion
  734. }
  735. #endregion
  736. #region カードを処理領域に置く
  737. public static IEnumerator AddExecutingCard(CardSource cardSource)
  738. {
  739. if (!cardSource.Owner.ExecutingCards.Contains(cardSource))
  740. {
  741. yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
  742. if (!cardSource.IsToken)
  743. {
  744. cardSource.SetFace();
  745. cardSource.Owner.ExecutingCards.Insert(0, cardSource);
  746. cardSource.Init();
  747. }
  748. }
  749. }
  750. #endregion
  751. #region カードをセキュリティに追加する
  752. public static IEnumerator AddSecurityCard(CardSource cardSource, bool toTop = true)
  753. {
  754. if (!cardSource.Owner.SecurityCards.Contains(cardSource))
  755. {
  756. yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
  757. if (!cardSource.IsToken)
  758. {
  759. cardSource.SetReverse();
  760. cardSource.Owner.SecurityCards.Insert(0, cardSource);
  761. if (!toTop)
  762. {
  763. cardSource.Owner.SecurityCards.Remove(cardSource);
  764. cardSource.Owner.SecurityCards.Add(cardSource);
  765. }
  766. }
  767. }
  768. }
  769. #endregion
  770. #region デッキをシャッフル
  771. public static IEnumerator Shuffle(Player player)
  772. {
  773. ContinuousController.instance.PlaySE(GManager.instance.ShuffleSE);
  774. player.LibraryCards = RandomUtility.ShuffledDeckCards(player.LibraryCards);
  775. yield return ContinuousController.instance.StartCoroutine(player.ShuffleAnimation());
  776. }
  777. #endregion
  778. #region パーマネントを移動
  779. public static IEnumerator MovePermanent(FieldCardFrame movingPermanentFrame)
  780. {
  781. if (movingPermanentFrame != null)
  782. {
  783. Player player = movingPermanentFrame.player;
  784. Permanent movingPermanent = movingPermanentFrame.GetFramePermanent();
  785. if (movingPermanent != null)
  786. {
  787. bool oldIsFrontLine = movingPermanentFrame.IsBattleAreaFrame();
  788. FieldCardFrame moveTargetFrame = movingPermanent.TopCard.PreferredFrame();
  789. if (moveTargetFrame != null && moveTargetFrame != null)
  790. {
  791. if (moveTargetFrame.GetFramePermanent() == null)
  792. {
  793. int oldFrameID = movingPermanentFrame.FrameID;
  794. int newFrameID = moveTargetFrame.FrameID;
  795. player.FieldPermanents[oldFrameID] = null;
  796. player.fieldCardFrames[oldFrameID].SetFramePermanent(null);
  797. player.FieldPermanents[newFrameID] = movingPermanent;
  798. player.fieldCardFrames[newFrameID].SetFramePermanent(movingPermanent);
  799. #region アニメーション
  800. bool end = false;
  801. var sequence = DOTween.Sequence();
  802. FieldPermanentCard movingPermanentCard = movingPermanent.ShowingPermanentCard;
  803. Vector3 TargetPosition = moveTargetFrame.GetLocalCanvasPosition();
  804. Vector3 oldPosition = movingPermanentFrame.GetLocalCanvasPosition();
  805. float GoTime = 0.2f;
  806. sequence
  807. .Append(movingPermanentCard.transform.DOLocalMove(TargetPosition, GoTime).SetEase(Ease.OutCubic))
  808. .AppendCallback(() =>
  809. {
  810. end = true;
  811. });
  812. sequence.Play();
  813. yield return new WaitWhile(() => !end);
  814. end = false;
  815. #endregion
  816. if (!oldIsFrontLine)
  817. {
  818. #region "育成エリアから移動した時"の効果
  819. #region Hashtable Setting
  820. System.Collections.Hashtable hashtable = new System.Collections.Hashtable()
  821. {
  822. {"Permanent", movingPermanent}
  823. };
  824. #endregion
  825. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnMove));
  826. #endregion
  827. }
  828. }
  829. }
  830. }
  831. }
  832. }
  833. #endregion
  834. }