CardObjectController.cs 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135
  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.Contains(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. //TODO: This might not even be necessary at all? - MB
  306. if(!cardSource.IsFlipped || cardSource.IsBeingRevealed || GManager.instance.turnStateMachine.gameContext.IsSecurityLooking)
  307. cardSource.SetFace();
  308. if (cardSource.Owner.HandCards.Contains(cardSource))
  309. {
  310. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeleteHandCardEffectCoroutine(cardSource));
  311. }
  312. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  313. {
  314. List<Permanent> permanents = new List<Permanent>();
  315. foreach (Permanent permanent in player.GetFieldPermanents())
  316. {
  317. permanents.Add(permanent);
  318. }
  319. foreach (Permanent permanent in permanents)
  320. {
  321. if (permanent.cardSources.Contains(cardSource))
  322. {
  323. if (permanent.LinkedCards.Contains(cardSource))
  324. {
  325. yield return ContinuousController.instance.StartCoroutine(permanent.RemoveLinkedCard(cardSource, trashCard: false));
  326. }
  327. else
  328. {
  329. yield return ContinuousController.instance.StartCoroutine(permanent.RemoveCardSource(cardSource));
  330. }
  331. }
  332. }
  333. }
  334. //手札から取り除く
  335. while (cardSource.Owner.HandCards.Contains(cardSource))
  336. {
  337. cardSource.Owner.HandCards.Remove(cardSource);
  338. }
  339. //デッキから取り除く
  340. while (cardSource.Owner.LibraryCards.Contains(cardSource))
  341. {
  342. cardSource.Owner.LibraryCards.Remove(cardSource);
  343. }
  344. //デジタマデッキから取り除く
  345. while (cardSource.Owner.DigitamaLibraryCards.Contains(cardSource))
  346. {
  347. cardSource.Owner.DigitamaLibraryCards.Remove(cardSource);
  348. }
  349. //トラッシュから取り除く
  350. while (CardEffectCommons.IsExistOnTrash(cardSource))
  351. {
  352. cardSource.Owner.TrashCards.Remove(cardSource);
  353. }
  354. //思い出から取り除く
  355. while (cardSource.Owner.LostCards.Contains(cardSource))
  356. {
  357. cardSource.Owner.LostCards.Remove(cardSource);
  358. }
  359. //ライフから取り除く
  360. while (cardSource.Owner.SecurityCards.Contains(cardSource))
  361. {
  362. cardSource.Owner.SecurityCards.Remove(cardSource);
  363. }
  364. //処理領域から取り除く
  365. while (cardSource.Owner.ExecutingCards.Contains(cardSource))
  366. {
  367. cardSource.Owner.ExecutingCards.Remove(cardSource);
  368. }
  369. }
  370. #endregion
  371. #region 手札のカードを整列する
  372. public static void AlignHand(Player player)
  373. {
  374. int n = player.HandTransform.childCount;
  375. float scale = player.HandTransform.transform.localScale.x;
  376. if (n > 0)
  377. {
  378. float CardWidth = player.HandTransform.GetChild(0).GetComponent<RectTransform>().sizeDelta.x;
  379. //If it fits within the area as it is.
  380. if (n * scale * CardWidth < player.HandWidth)
  381. {
  382. player.HandTransform.GetComponent<GridLayoutGroup>().spacing = new Vector2(0, 0);
  383. //player.HandTransform.GetComponent<GridLayoutGroup>().spacing = new Vector2(7, 0);
  384. }
  385. //If it sticks out as it is
  386. else
  387. {
  388. float delta = (n * scale * CardWidth - player.HandWidth) / ((n - 1) * scale);
  389. player.HandTransform.GetComponent<GridLayoutGroup>().spacing = new Vector2(-delta, 0);
  390. }
  391. }
  392. }
  393. #endregion
  394. #region 新しいパーマネントを生成する
  395. public static IEnumerator CreateNewPermanent(Permanent permanent, int frameID)
  396. {
  397. if (permanent.TopCard != null)
  398. {
  399. if (permanent.TopCard.Owner != null)
  400. {
  401. yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(permanent.TopCard));
  402. if (0 <= frameID && frameID <= permanent.TopCard.Owner.FieldPermanents.Length)
  403. {
  404. permanent.TopCard.Owner.FieldPermanents[frameID] = permanent;
  405. permanent.TopCard.Owner.fieldCardFrames[frameID].SetFramePermanent(permanent);
  406. permanent.TopCard.SetFace();
  407. FieldPermanentCard fieldPermanentCard = Instantiate(GManager.instance.fieldCardPrefab, permanent.TopCard.Owner.PermanentTransform);
  408. fieldPermanentCard.SetPermanentData(permanent, false);
  409. fieldPermanentCard.StartScale = fieldPermanentCard.transform.localScale;
  410. permanent.ShowingPermanentCard = fieldPermanentCard;
  411. fieldPermanentCard.transform.localPosition = permanent.TopCard.Owner.fieldCardFrames[frameID].GetLocalCanvasPosition();
  412. fieldPermanentCard.gameObject.SetActive(false);
  413. }
  414. }
  415. }
  416. }
  417. #endregion
  418. #region leave the place
  419. public static IEnumerator RemoveField(Permanent permanent, bool ignoreOverflow = false)
  420. {
  421. if (permanent == null) yield break;
  422. if (permanent.TopCard == null) yield break;
  423. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  424. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  425. new List<Permanent> { permanent },
  426. null,
  427. null
  428. ),
  429. EffectTiming.OnRemovedField));
  430. if (!ignoreOverflow)
  431. {
  432. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(permanent.cardSources).Overflow());
  433. }
  434. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  435. {
  436. while (player.GetFieldPermanents().Contains(permanent))
  437. {
  438. for (int i = 0; i < permanent.TopCard.Owner.FieldPermanents.Length; i++)
  439. {
  440. if (permanent.TopCard.Owner.FieldPermanents[i] == permanent)
  441. {
  442. permanent.TopCard.Owner.FieldPermanents[i] = null;
  443. permanent.TopCard.Owner.fieldCardFrames[i].SetFramePermanent(null);
  444. }
  445. }
  446. }
  447. }
  448. if (permanent.TopCard != null)
  449. {
  450. foreach (CardSource cardSource in permanent.cardSources)
  451. {
  452. cardSource.Init();
  453. }
  454. permanent.cardSources = new List<CardSource>();
  455. }
  456. }
  457. #endregion
  458. #region add card to hand
  459. public static IEnumerator AddHandCards(List<CardSource> cardSources, bool isDraw, ICardEffect cardEffect)
  460. {
  461. if (cardSources.Count == 0) yield break;
  462. bool isFromTrash = cardSources.Some(cardSource => CardEffectCommons.IsExistOnTrash(cardSource));
  463. cardSources = cardSources.Filter(cardSource => cardSource != null && !cardSource.Owner.HandCards.Contains(cardSource));
  464. if (isFromTrash)
  465. {
  466. #region "Effect of "When a card is returned from the trash to the hand"
  467. #region Hashtable Setting
  468. System.Collections.Hashtable hashtable = new System.Collections.Hashtable()
  469. {
  470. {"CardSources", cardSources}
  471. };
  472. #endregion
  473. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnReturnCardsToHandFromTrash));
  474. #endregion
  475. }
  476. foreach (CardSource cardSource in cardSources)
  477. {
  478. if (cardSource.IsToken)
  479. {
  480. yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
  481. }
  482. }
  483. List<CardSource> eggCards = cardSources.Filter(cardSource => cardSource.IsDigiEgg);
  484. List<CardSource> addedCards = cardSources.Filter(cardSource => !cardSource.IsDigiEgg && !cardSource.IsToken);
  485. if (eggCards.Count <= 0)
  486. yield return ContinuousController.instance.StartCoroutine(AddLibraryBottomCards(eggCards));
  487. if (addedCards.Count <= 0) yield break;
  488. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(addedCards).Overflow());
  489. foreach (CardSource cardSource in addedCards)
  490. {
  491. yield return ContinuousController.instance.StartCoroutine(AddHandCard(cardSource, isDraw));
  492. }
  493. if (GManager.instance.turnStateMachine.DoneStartGame && addedCards.Count > 0)
  494. {
  495. List<Player> Players = addedCards.Map(cardSource => cardSource.Owner).Distinct().ToList();
  496. #region Effect of "When the number of cards in hand increases"
  497. #region Hashtable Setting
  498. System.Collections.Hashtable _hashtable = new System.Collections.Hashtable()
  499. {
  500. {"Players", Players},
  501. {"CardEffect", cardEffect},
  502. {"CardSources", addedCards},
  503. };
  504. #endregion
  505. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(_hashtable, EffectTiming.OnAddHand));
  506. #endregion
  507. }
  508. }
  509. public static IEnumerator AddHandCard(CardSource cardSource, bool isDraw)
  510. {
  511. cardSource.Init();
  512. cardSource.SetFace();
  513. if (!cardSource.Owner.HandCards.Contains(cardSource))
  514. {
  515. yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
  516. if (!cardSource.IsToken)
  517. {
  518. cardSource.Owner.HandCards.Add(cardSource);
  519. if (isDraw)
  520. {
  521. if (GManager.instance.turnStateMachine.DoneStartGame)
  522. {
  523. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().AddHandCardEffect(cardSource));
  524. }
  525. }
  526. else
  527. {
  528. ContinuousController.instance.PlaySE(GManager.instance.DrawSE);
  529. }
  530. HandCard handCard = Instantiate(GManager.instance.handCardPrefab, cardSource.Owner.HandTransform);
  531. handCard.gameObject.name = $"handCard_{cardSource.Owner.PlayerName}";
  532. handCard.GetComponent<Draggable_HandCard>().startScale = handCard.transform.localScale;
  533. handCard.GetComponent<Draggable_HandCard>().DefaultY = -9;
  534. handCard.SetUpHandCard(cardSource);
  535. AlignHand(cardSource.Owner);
  536. cardSource.SetShowingHandCard(handCard);
  537. if (cardSource.Owner.isYou)
  538. {
  539. handCard.SetUpHandCardImage();
  540. handCard.ShowCostLevel();
  541. }
  542. yield return new WaitForSeconds(Time.deltaTime);
  543. #region アニメーション
  544. if (GManager.instance.turnStateMachine.DoneStartGame)
  545. {
  546. cardSource.Owner.HandTransform.GetComponent<GridLayoutGroup>().enabled = false;
  547. Vector3 startPosition = Vector3.zero;
  548. Vector3 targetPositon = handCard.transform.localPosition;
  549. if (cardSource.Owner.isYou)
  550. {
  551. startPosition = handCard.transform.localPosition + new Vector3(0, 70, 0);
  552. }
  553. else
  554. {
  555. startPosition = handCard.transform.localPosition - new Vector3(0, 70, 0);
  556. }
  557. handCard.transform.localPosition = startPosition;
  558. bool end = false;
  559. var sequence = DOTween.Sequence();
  560. sequence
  561. .Append(handCard.transform.DOLocalMove(targetPositon, 0.08f).SetEase(Ease.OutBack))
  562. .AppendCallback(() => { end = true; });
  563. yield return new WaitWhile(() => !end);
  564. end = false;
  565. cardSource.Owner.HandTransform.GetComponent<GridLayoutGroup>().enabled = true;
  566. }
  567. #endregion
  568. if (cardSource.Owner.isYou)
  569. {
  570. handCard.SetUpHandCardImage();
  571. handCard.ShowCostLevel();
  572. }
  573. }
  574. }
  575. }
  576. #endregion
  577. #region put the card in the trash
  578. public static IEnumerator AddTrashCard(CardSource cardSource)
  579. {
  580. if (!CardEffectCommons.IsExistOnTrash(cardSource))
  581. {
  582. yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
  583. if (!cardSource.IsToken)
  584. {
  585. cardSource.SetFace();
  586. if (!CardEffectCommons.IsExistOnTrash(cardSource))
  587. {
  588. cardSource.Owner.TrashCards.Insert(0, cardSource);
  589. }
  590. cardSource.Init();
  591. }
  592. }
  593. }
  594. #endregion
  595. #region Put the cards together in the trash
  596. public static IEnumerator AddTrashCards(List<CardSource> cardSources)
  597. {
  598. List<CardSource> handCards = new List<CardSource>();
  599. foreach (CardSource cardSource in cardSources)
  600. {
  601. if (cardSource.Owner.HandCards.Contains(cardSource))
  602. {
  603. handCards.Add(cardSource);
  604. }
  605. }
  606. foreach (CardSource cardSource in handCards)
  607. {
  608. ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeleteHandCardEffectCoroutine(cardSource));
  609. }
  610. yield return new WaitForSeconds(GManager.instance.GetComponent<Effects>().waitTime_DeleteHandEffect);
  611. foreach (CardSource cardSource in cardSources)
  612. {
  613. if (!CardEffectCommons.IsExistOnTrash(cardSource))
  614. {
  615. yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
  616. if (!cardSource.IsToken)
  617. {
  618. cardSource.SetFace();
  619. if (!CardEffectCommons.IsExistOnTrash(cardSource))
  620. {
  621. cardSource.Owner.TrashCards.Insert(0, cardSource);
  622. }
  623. cardSource.Init();
  624. }
  625. }
  626. }
  627. }
  628. #endregion
  629. #region place a card on top of the deck
  630. public static IEnumerator AddLibraryTopCards(List<CardSource> cardSources, bool notAddLog = false)
  631. {
  632. if (cardSources.Count <= 0) yield break;
  633. bool isFromTrash = cardSources.Some(cardSource => CardEffectCommons.IsExistOnTrash(cardSource));
  634. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(cardSources).Overflow());
  635. if (isFromTrash)
  636. {
  637. #region "Effect of "When a card is returned from the trash to the deck"
  638. #region Hashtable Setting
  639. System.Collections.Hashtable hashtable = new System.Collections.Hashtable()
  640. {
  641. {"CardSources", cardSources}
  642. };
  643. #endregion
  644. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnReturnCardsToLibraryFromTrash));
  645. #endregion
  646. }
  647. foreach (CardSource cardSource in cardSources)
  648. {
  649. bool isFromHand = CardEffectCommons.IsExistOnHand(cardSource);
  650. yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
  651. if (isFromHand && GManager.instance.turnStateMachine.DoneStartGame)
  652. {
  653. yield return new WaitForSeconds(GManager.instance.GetComponent<Effects>().waitTime_DeleteHandEffect);
  654. }
  655. if (!cardSource.IsToken)
  656. {
  657. cardSource.SetFace();
  658. if (!cardSource.IsDigiEgg)
  659. {
  660. if (!cardSource.Owner.LibraryCards.Contains(cardSource))
  661. {
  662. cardSource.Owner.LibraryCards.Insert(0, cardSource);
  663. }
  664. }
  665. else
  666. {
  667. if (!cardSource.Owner.DigitamaLibraryCards.Contains(cardSource))
  668. {
  669. cardSource.Owner.DigitamaLibraryCards.Insert(0, cardSource);
  670. }
  671. }
  672. cardSource.Init();
  673. }
  674. }
  675. #region Log
  676. if (!notAddLog)
  677. {
  678. if (cardSources.Count >= 1)
  679. {
  680. string log = "";
  681. log += $"\nDeck Top card{Utils.PluralFormSuffix(cardSources.Count)}:";
  682. foreach (CardSource cardSource in cardSources)
  683. {
  684. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  685. }
  686. log += "\n";
  687. PlayLog.OnAddLog?.Invoke(log);
  688. }
  689. }
  690. #endregion
  691. }
  692. #endregion
  693. #region put a card at the bottom of the deck
  694. public static IEnumerator AddLibraryBottomCards(List<CardSource> cardSources, bool notAddLog = false)
  695. {
  696. if (cardSources.Count <= 0) yield break;
  697. bool isFromTrash = cardSources.Some(cardSource => CardEffectCommons.IsExistOnTrash(cardSource));
  698. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(cardSources).Overflow());
  699. if (isFromTrash)
  700. {
  701. #region Effect of "When a card returns from the trash to the deck"
  702. #region Hashtable Setting
  703. System.Collections.Hashtable hashtable = new System.Collections.Hashtable()
  704. {
  705. {"CardSources", cardSources}
  706. };
  707. #endregion
  708. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnReturnCardsToLibraryFromTrash));
  709. #endregion
  710. }
  711. foreach (CardSource cardSource in cardSources)
  712. {
  713. if (cardSource.PermanentOfThisCard() != null)
  714. {
  715. if (cardSource.PermanentOfThisCard().DigivolutionCards.Contains(cardSource))
  716. {
  717. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>()
  718. .RemoveDigivolveRootEffect(cardSource, cardSource.PermanentOfThisCard()));
  719. }
  720. }
  721. }
  722. foreach (CardSource cardSource in cardSources.Clone())
  723. {
  724. bool isFromHand = CardEffectCommons.IsExistOnHand(cardSource);
  725. yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
  726. if (isFromHand && GManager.instance.turnStateMachine.DoneStartGame)
  727. {
  728. yield return new WaitForSeconds(GManager.instance.GetComponent<Effects>().waitTime_DeleteHandEffect);
  729. }
  730. if (!cardSource.IsToken)
  731. {
  732. cardSource.SetFace();
  733. if (!cardSource.IsDigiEgg)
  734. {
  735. if (!cardSource.Owner.LibraryCards.Contains(cardSource))
  736. {
  737. cardSource.Owner.LibraryCards.Add(cardSource);
  738. }
  739. }
  740. else
  741. {
  742. if (!cardSource.Owner.DigitamaLibraryCards.Contains(cardSource))
  743. {
  744. cardSource.Owner.DigitamaLibraryCards.Add(cardSource);
  745. }
  746. }
  747. cardSource.Init();
  748. }
  749. }
  750. #region Log
  751. if (!notAddLog)
  752. {
  753. if (cardSources.Count >= 1)
  754. {
  755. string log = "";
  756. log += $"\nDeck Bottom card{Utils.PluralFormSuffix(cardSources.Count)}:";
  757. foreach (CardSource cardSource in cardSources)
  758. {
  759. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  760. }
  761. log += "\n";
  762. PlayLog.OnAddLog?.Invoke(log);
  763. }
  764. }
  765. #endregion
  766. }
  767. #endregion
  768. #region Place the card in the processing area
  769. public static IEnumerator AddExecutingCard(CardSource cardSource)
  770. {
  771. if (!cardSource.Owner.ExecutingCards.Contains(cardSource))
  772. {
  773. yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
  774. if (!cardSource.IsToken)
  775. {
  776. cardSource.SetFace();
  777. cardSource.Owner.ExecutingCards.Insert(0, cardSource);
  778. cardSource.Init();
  779. }
  780. }
  781. }
  782. #endregion
  783. #region Add card to security
  784. public static IEnumerator AddSecurityCard(CardSource cardSource, bool toTop = true, bool faceUp = false, bool useEffect = true)
  785. {
  786. if (!cardSource.Owner.SecurityCards.Contains(cardSource))
  787. {
  788. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(new List<CardSource>() { cardSource }).Overflow());
  789. yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
  790. if (cardSource.IsDigiEgg)
  791. {
  792. cardSource.Owner.DigitamaLibraryCards.Add(cardSource);
  793. }
  794. else if (!cardSource.IsToken)
  795. {
  796. if (!faceUp)
  797. cardSource.SetReverse();
  798. else
  799. cardSource.SetFace();
  800. cardSource.Owner.SecurityCards.Insert(0, cardSource);
  801. if (!toTop)
  802. {
  803. cardSource.Owner.SecurityCards.Remove(cardSource);
  804. cardSource.Owner.SecurityCards.Add(cardSource);
  805. }
  806. if(useEffect)
  807. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateRecoveryEffect(cardSource.Owner));
  808. yield return ContinuousController.instance.StartCoroutine(new IAddSecurity(cardSource).AddSecurity());
  809. }
  810. }
  811. }
  812. #endregion
  813. #region Shuffle
  814. public static IEnumerator Shuffle(Player player)
  815. {
  816. ContinuousController.instance.PlaySE(GManager.instance.ShuffleSE);
  817. player.LibraryCards = RandomUtility.ShuffledDeckCards(player.LibraryCards);
  818. yield return ContinuousController.instance.StartCoroutine(player.ShuffleAnimation());
  819. }
  820. #endregion
  821. #region move permanent
  822. public static IEnumerator MovePermanent(FieldCardFrame movingPermanentFrame, bool toBreeding = false, ICardEffect effect = null)
  823. {
  824. if (movingPermanentFrame != null)
  825. {
  826. Player player = movingPermanentFrame.player;
  827. Permanent movingPermanent = movingPermanentFrame.GetFramePermanent();
  828. if (movingPermanent != null)
  829. {
  830. bool prevIsFrontLine = movingPermanentFrame.IsBattleAreaFrame();
  831. FieldCardFrame moveTargetFrame = movingPermanent.TopCard.PreferredFrame();
  832. if (toBreeding)
  833. {
  834. moveTargetFrame = player.fieldCardFrames.Filter(frame => frame.isBreedingAreaFrame()).ToList()[0];
  835. #region cut in effect
  836. // "When permanents would remove field" effect
  837. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  838. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  839. new List<Permanent> { movingPermanent },
  840. effect,
  841. null
  842. ),
  843. EffectTiming.WhenRemoveField));
  844. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  845. {
  846. // effect
  847. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  848. // cut in effect process
  849. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  850. }
  851. #endregion
  852. }
  853. if (moveTargetFrame != null && moveTargetFrame != null)
  854. {
  855. if (moveTargetFrame.GetFramePermanent() == null)
  856. {
  857. int oldFrameID = movingPermanentFrame.FrameID;
  858. int newFrameID = moveTargetFrame.FrameID;
  859. player.FieldPermanents[oldFrameID] = null;
  860. player.fieldCardFrames[oldFrameID].SetFramePermanent(null);
  861. player.FieldPermanents[newFrameID] = movingPermanent;
  862. player.fieldCardFrames[newFrameID].SetFramePermanent(movingPermanent);
  863. #region animation
  864. bool end = false;
  865. var sequence = DOTween.Sequence();
  866. FieldPermanentCard movingPermanentCard = movingPermanent.ShowingPermanentCard;
  867. Vector3 TargetPosition = moveTargetFrame.GetLocalCanvasPosition();
  868. Vector3 oldPosition = movingPermanentFrame.GetLocalCanvasPosition();
  869. float GoTime = 0.2f;
  870. sequence
  871. .Append(movingPermanentCard.transform.DOLocalMove(TargetPosition, GoTime).SetEase(Ease.OutCubic))
  872. .AppendCallback(() =>
  873. {
  874. end = true;
  875. });
  876. sequence.Play();
  877. yield return new WaitWhile(() => !end);
  878. end = false;
  879. #endregion
  880. if (!prevIsFrontLine)
  881. {
  882. movingPermanent.TopCard.SetChangedLocationTime();//register that the card moved for the purpose of the start of timestamped continuous effects
  883. #region Effect of "when moving from the training area"
  884. #region Hashtable Setting
  885. System.Collections.Hashtable hashtable = new System.Collections.Hashtable()
  886. {
  887. {"Permanent", movingPermanent}
  888. };
  889. #endregion
  890. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnMove));
  891. #endregion
  892. }
  893. if (toBreeding)
  894. {
  895. // "When permanents leave the battle area" effect
  896. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
  897. CardEffectCommons.OnDeletionHashtable(
  898. new List<Permanent> { movingPermanent },
  899. effect,
  900. null,
  901. false
  902. ),
  903. EffectTiming.OnLeaveFieldAnyone));
  904. }
  905. }
  906. }
  907. }
  908. }
  909. }
  910. #endregion
  911. }