| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103 |
- using Photon.Pun;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using UnityEngine;
- using UnityEngine.Events;
- using Hashtable = ExitGames.Client.Photon.Hashtable;
- using UnityEngine.UI;
- using DG.Tweening;
- //Card-related operations
- public class CardObjectController : MonoBehaviour
- {
- #region Generate cards for each player's deck
- public static IEnumerator CreatePlayerDecks(CardSource CardPrefab, GameContext gameContext)
- {
- yield return null;
- DeckData RandomDeck = null;
- if (GManager.instance.IsAI)
- {
- if (ContinuousController.instance.DeckDatas.Count((deckData) => deckData.IsValidDeckData()) > 0)
- {
- List<DeckData> deckDatas = new List<DeckData>();
- foreach (DeckData deckData in ContinuousController.instance.DeckDatas)
- {
- if (deckData.IsValidDeckData())
- {
- deckDatas.Add(deckData);
- }
- }
- DeckData randomDeck = deckDatas[UnityEngine.Random.Range(0, deckDatas.Count)];
- RandomDeck = new DeckData(randomDeck.GetThisDeckCode(), randomDeck.DeckID);
- #if UNITY_EDITOR && !UNITY_WINDOWS
- foreach (DeckData deckData in ContinuousController.instance.DeckDatas)
- {
- if (deckData.IsValidDeckData())
- {
- RandomDeck = new DeckData(deckData.GetThisDeckCode(), deckData.DeckID);
- break;
- }
- }
- #endif
- }
- else
- {
- List<CEntity_Base> mainDeckCards = new List<CEntity_Base>();
- List<CEntity_Base> digitamaDeckCards = new List<CEntity_Base>();
- List<CEntity_Base> mainDeckCandidates = new List<CEntity_Base>();
- List<CEntity_Base> digitamaDeckCandidates = new List<CEntity_Base>();
- foreach (CEntity_Base cEntity_Base in ContinuousController.instance.CardList)
- {
- if (cEntity_Base.cardKind != CardKind.DigiEgg)
- {
- mainDeckCandidates.Add(cEntity_Base);
- }
- else
- {
- digitamaDeckCandidates.Add(cEntity_Base);
- }
- }
- if (mainDeckCandidates.Count >= 1)
- {
- for (int i = 0; i < 50; i++)
- {
- mainDeckCards.Add(mainDeckCandidates[UnityEngine.Random.Range(0, mainDeckCandidates.Count)]);
- }
- }
- if (digitamaDeckCandidates.Count >= 1)
- {
- for (int i = 0; i < 5; i++)
- {
- digitamaDeckCards.Add(digitamaDeckCandidates[UnityEngine.Random.Range(0, digitamaDeckCandidates.Count)]);
- }
- }
- RandomDeck = new DeckData(DeckData.GetDeckCode("サンプルデッキ", mainDeckCards, digitamaDeckCards, null));
- }
- }
- #region マスタークライアントと非マスタークライアントを抽出
- Photon.Realtime.Player MasterPlayer = null;
- Photon.Realtime.Player nonMasterPlayer = null;
- if (PhotonNetwork.IsMasterClient)
- {
- MasterPlayer = PhotonNetwork.LocalPlayer;
- foreach (Photon.Realtime.Player player in PhotonNetwork.PlayerList)
- {
- if (player != PhotonNetwork.LocalPlayer)
- {
- nonMasterPlayer = player;
- break;
- }
- }
- }
- else
- {
- nonMasterPlayer = PhotonNetwork.LocalPlayer;
- foreach (Photon.Realtime.Player player in PhotonNetwork.PlayerList)
- {
- if (player != PhotonNetwork.LocalPlayer)
- {
- MasterPlayer = player;
- break;
- }
- }
- }
- #endregion
- #region そのPhotonクライアントのメインデッキレシピ
- List<CEntity_Base> DeckRecipie(Photon.Realtime.Player player)
- {
- #region 対人戦
- if (!GManager.instance.IsAI)
- {
- Hashtable hashtable = player.CustomProperties;
- if (HasDeckRecipie(player))
- {
- if (hashtable.TryGetValue(ContinuousController.DeckDataPropertyKey, out object value))
- {
- DeckData deckData = new DeckData((string)value);
- return RandomUtility.ShuffledDeckCards(deckData.DeckCards());
- }
- }
- else
- {
- Debug.Log("!HasDeckRecipie");
- }
- return null;
- }
- #endregion
- #region vs.AI
- else
- {
- #region プレイヤーのデッキ
- if (player == MasterPlayer)
- {
- if (ContinuousController.instance.BattleDeckData == null)
- {
- foreach (DeckData deckData in ContinuousController.instance.DeckDatas)
- {
- if (deckData.IsValidDeckData())
- {
- return RandomUtility.ShuffledDeckCards(deckData.DeckCards());
- }
- }
- }
- else
- {
- if (ContinuousController.instance.BattleDeckData.IsValidDeckData())
- {
- return RandomUtility.ShuffledDeckCards(ContinuousController.instance.BattleDeckData.DeckCards());
- }
- }
- if (RandomDeck != null)
- {
- return RandomUtility.ShuffledDeckCards(RandomDeck.DeckCards());
- }
- return null;
- }
- #endregion
- #region AIのデッキ
- else
- {
- if (RandomDeck != null)
- {
- return RandomUtility.ShuffledDeckCards(RandomDeck.DeckCards());
- }
- foreach (DeckData deckData in ContinuousController.instance.DeckDatas)
- {
- if (deckData.IsValidDeckData())
- {
- return RandomUtility.ShuffledDeckCards(deckData.DeckCards());
- }
- }
- return null;
- }
- #endregion
- }
- #endregion
- }
- #endregion
- #region そのPhotonクライアントのデジタマデッキレシピ
- List<CEntity_Base> DigitamaDeckRecipie(Photon.Realtime.Player player)
- {
- #region 対人戦
- if (!GManager.instance.IsAI)
- {
- Hashtable hashtable = player.CustomProperties;
- if (HasDeckRecipie(player))
- {
- if (hashtable.TryGetValue(ContinuousController.DeckDataPropertyKey, out object value))
- {
- DeckData deckData = new DeckData((string)value);
- return RandomUtility.ShuffledDeckCards(deckData.DigitamaDeckCards());
- }
- }
- else
- {
- Debug.Log("!HasDeckRecipie");
- }
- return null;
- }
- #endregion
- #region vs.AI
- else
- {
- #region プレイヤーのデッキ
- if (player == MasterPlayer)
- {
- if (ContinuousController.instance.BattleDeckData == null)
- {
- foreach (DeckData deckData in ContinuousController.instance.DeckDatas)
- {
- if (deckData.IsValidDeckData())
- {
- return RandomUtility.ShuffledDeckCards(deckData.DigitamaDeckCards());
- }
- }
- }
- else
- {
- if (ContinuousController.instance.BattleDeckData.IsValidDeckData())
- {
- return RandomUtility.ShuffledDeckCards(ContinuousController.instance.BattleDeckData.DigitamaDeckCards());
- }
- }
- if (RandomDeck != null)
- {
- return RandomUtility.ShuffledDeckCards(RandomDeck.DigitamaDeckCards());
- }
- return null;
- }
- #endregion
- #region AIのデッキ
- else
- {
- if (RandomDeck != null)
- {
- return RandomUtility.ShuffledDeckCards(RandomDeck.DigitamaDeckCards());
- }
- foreach (DeckData deckData in ContinuousController.instance.DeckDatas)
- {
- if (deckData.IsValidDeckData())
- {
- return RandomUtility.ShuffledDeckCards(deckData.DigitamaDeckCards());
- }
- }
- return null;
- }
- #endregion
- }
- #endregion
- }
- #endregion
- #region そのPhotonクライアントがデッキレシピのキーを持っているかの判定
- bool HasDeckRecipie(Photon.Realtime.Player _player)
- {
- Hashtable _hashtable = _player.CustomProperties;
- if (_hashtable.TryGetValue(ContinuousController.DeckDataPropertyKey, out object value))
- {
- DeckData deckData = new DeckData((string)value);
- if (deckData.IsValidDeckData())
- {
- return true;
- }
- }
- return false;
- }
- #endregion
- #region カードを生成
- GManager.instance.CardIndex = 0;
- foreach (CEntity_Base cEntity_Base in DeckRecipie(MasterPlayer))
- {
- GManager.instance.turnStateMachine.gameContext.PlayerFromID(0).LibraryCards.Add(CreateCardSource(0, cEntity_Base, false));
- }
- foreach (CEntity_Base cEntity_Base in DigitamaDeckRecipie(MasterPlayer))
- {
- GManager.instance.turnStateMachine.gameContext.PlayerFromID(0).DigitamaLibraryCards.Add(CreateCardSource(0, cEntity_Base, false));
- }
- foreach (CEntity_Base cEntity_Base in DeckRecipie(nonMasterPlayer))
- {
- GManager.instance.turnStateMachine.gameContext.PlayerFromID(1).LibraryCards.Add(CreateCardSource(1, cEntity_Base, false));
- }
- foreach (CEntity_Base cEntity_Base in DigitamaDeckRecipie(nonMasterPlayer))
- {
- GManager.instance.turnStateMachine.gameContext.PlayerFromID(1).DigitamaLibraryCards.Add(CreateCardSource(1, cEntity_Base, false));
- }
- #endregion
- }
- #endregion
- #region generate card
- public static CardSource CreateCardSource(int _PlayerID, CEntity_Base cEntity_Base, bool isToken)
- {
- Player player = GManager.instance.turnStateMachine.gameContext.PlayerFromID(_PlayerID);
- CardSource cardSource = Instantiate(GManager.instance.CardPrefab, player.CardSorcesParent);
- cardSource.SetBaseData(cEntity_Base, player);
- cardSource.cEntity_EffectController.AddCardEffect(cEntity_Base.CardID, cEntity_Base.CardEffectClassName);
- cardSource.SetUpCardIndex(GManager.instance.CardIndex);
- cardSource.SetIsToken(isToken);
- GManager.instance.turnStateMachine.gameContext.ActiveCardList.Add(cardSource);
- GManager.instance.CardIndex++;
- return cardSource;
- }
- #endregion
- #region Remove cards from all areas
- public static IEnumerator RemoveFromAllArea(CardSource cardSource)
- {
- //TODO: This might not even be necessary at all? - MB
- if(!cardSource.IsFlipped || cardSource.IsBeingRevealed || GManager.instance.turnStateMachine.gameContext.IsSecurityLooking)
- cardSource.SetFace();
- if (cardSource.Owner.HandCards.Contains(cardSource))
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeleteHandCardEffectCoroutine(cardSource));
- }
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
- {
- List<Permanent> permanents = new List<Permanent>();
- foreach (Permanent permanent in player.GetFieldPermanents())
- {
- permanents.Add(permanent);
- }
- foreach (Permanent permanent in permanents)
- {
- if (permanent.cardSources.Contains(cardSource))
- {
- yield return ContinuousController.instance.StartCoroutine(permanent.RemoveCardSource(cardSource));
- }
- }
- }
- //手札から取り除く
- while (cardSource.Owner.HandCards.Contains(cardSource))
- {
- cardSource.Owner.HandCards.Remove(cardSource);
- }
- //デッキから取り除く
- while (cardSource.Owner.LibraryCards.Contains(cardSource))
- {
- cardSource.Owner.LibraryCards.Remove(cardSource);
- }
- //デジタマデッキから取り除く
- while (cardSource.Owner.DigitamaLibraryCards.Contains(cardSource))
- {
- cardSource.Owner.DigitamaLibraryCards.Remove(cardSource);
- }
- //トラッシュから取り除く
- while (CardEffectCommons.IsExistOnTrash(cardSource))
- {
- cardSource.Owner.TrashCards.Remove(cardSource);
- }
- //思い出から取り除く
- while (cardSource.Owner.LostCards.Contains(cardSource))
- {
- cardSource.Owner.LostCards.Remove(cardSource);
- }
- //ライフから取り除く
- while (cardSource.Owner.SecurityCards.Contains(cardSource))
- {
- cardSource.Owner.SecurityCards.Remove(cardSource);
- }
- //処理領域から取り除く
- while (cardSource.Owner.ExecutingCards.Contains(cardSource))
- {
- cardSource.Owner.ExecutingCards.Remove(cardSource);
- }
- }
- #endregion
- #region 手札のカードを整列する
- public static void AlignHand(Player player)
- {
- int n = player.HandTransform.childCount;
- float scale = player.HandTransform.transform.localScale.x;
- if (n > 0)
- {
- float CardWidth = player.HandTransform.GetChild(0).GetComponent<RectTransform>().sizeDelta.x;
- //If it fits within the area as it is.
- if (n * scale * CardWidth < player.HandWidth)
- {
- player.HandTransform.GetComponent<GridLayoutGroup>().spacing = new Vector2(0, 0);
- //player.HandTransform.GetComponent<GridLayoutGroup>().spacing = new Vector2(7, 0);
- }
- //If it sticks out as it is
- else
- {
- float delta = (n * scale * CardWidth - player.HandWidth) / ((n - 1) * scale);
- player.HandTransform.GetComponent<GridLayoutGroup>().spacing = new Vector2(-delta, 0);
- }
- }
- }
- #endregion
- #region 新しいパーマネントを生成する
- public static IEnumerator CreateNewPermanent(Permanent permanent, int frameID)
- {
- if (permanent.TopCard != null)
- {
- if (permanent.TopCard.Owner != null)
- {
- yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(permanent.TopCard));
- if (0 <= frameID && frameID <= permanent.TopCard.Owner.FieldPermanents.Length)
- {
- permanent.TopCard.Owner.FieldPermanents[frameID] = permanent;
- permanent.TopCard.Owner.fieldCardFrames[frameID].SetFramePermanent(permanent);
- permanent.TopCard.SetFace();
- FieldPermanentCard fieldPermanentCard = Instantiate(GManager.instance.fieldCardPrefab, permanent.TopCard.Owner.PermanentTransform);
- fieldPermanentCard.SetPermanentData(permanent, false);
- fieldPermanentCard.StartScale = fieldPermanentCard.transform.localScale;
- permanent.ShowingPermanentCard = fieldPermanentCard;
- fieldPermanentCard.transform.localPosition = permanent.TopCard.Owner.fieldCardFrames[frameID].GetLocalCanvasPosition();
- fieldPermanentCard.gameObject.SetActive(false);
- }
- }
- }
- }
- #endregion
- #region leave the place
- public static IEnumerator RemoveField(Permanent permanent, bool ignoreOverflow = false)
- {
- if (permanent == null) yield break;
- if (permanent.TopCard == null) yield break;
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
- CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
- new List<Permanent> { permanent },
- null,
- null
- ),
- EffectTiming.OnRemovedField));
- if (!ignoreOverflow)
- {
- yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(permanent.cardSources).Overflow());
- }
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
- {
- while (player.GetFieldPermanents().Contains(permanent))
- {
- for (int i = 0; i < permanent.TopCard.Owner.FieldPermanents.Length; i++)
- {
- if (permanent.TopCard.Owner.FieldPermanents[i] == permanent)
- {
- permanent.TopCard.Owner.FieldPermanents[i] = null;
- permanent.TopCard.Owner.fieldCardFrames[i].SetFramePermanent(null);
- }
- }
- }
- }
- if (permanent.TopCard != null)
- {
- foreach (CardSource cardSource in permanent.cardSources)
- {
- cardSource.Init();
- }
- permanent.cardSources = new List<CardSource>();
- }
- }
- #endregion
- #region add card to hand
- public static IEnumerator AddHandCards(List<CardSource> cardSources, bool isDraw, ICardEffect cardEffect)
- {
- if (cardSources.Count == 0) yield break;
- bool isFromTrash = cardSources.Some(cardSource => CardEffectCommons.IsExistOnTrash(cardSource));
- cardSources = cardSources.Filter(cardSource => cardSource != null && !cardSource.Owner.HandCards.Contains(cardSource));
- if (isFromTrash)
- {
- #region "Effect of "When a card is returned from the trash to the hand"
- #region Hashtable Setting
- System.Collections.Hashtable hashtable = new System.Collections.Hashtable()
- {
- {"CardSources", cardSources}
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnReturnCardsToHandFromTrash));
- #endregion
- }
- foreach (CardSource cardSource in cardSources)
- {
- if (cardSource.IsToken)
- {
- yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
- }
- }
- List<CardSource> eggCards = cardSources.Filter(cardSource => cardSource.IsDigiEgg);
- List<CardSource> addedCards = cardSources.Filter(cardSource => !cardSource.IsDigiEgg && !cardSource.IsToken);
- if (eggCards.Count <= 0)
- yield return ContinuousController.instance.StartCoroutine(AddLibraryBottomCards(eggCards));
- if (addedCards.Count <= 0) yield break;
- yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(addedCards).Overflow());
- foreach (CardSource cardSource in addedCards)
- {
- yield return ContinuousController.instance.StartCoroutine(AddHandCard(cardSource, isDraw));
- }
- if (GManager.instance.turnStateMachine.DoneStartGame && addedCards.Count > 0)
- {
- List<Player> Players = addedCards.Map(cardSource => cardSource.Owner).Distinct().ToList();
- #region Effect of "When the number of cards in hand increases"
- #region Hashtable Setting
- System.Collections.Hashtable _hashtable = new System.Collections.Hashtable()
- {
- {"Players", Players},
- {"CardEffect", cardEffect},
- {"CardSources", addedCards},
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(_hashtable, EffectTiming.OnAddHand));
- #endregion
- }
- }
- public static IEnumerator AddHandCard(CardSource cardSource, bool isDraw)
- {
- cardSource.Init();
- cardSource.SetFace();
- if (!cardSource.Owner.HandCards.Contains(cardSource))
- {
- yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
- if (!cardSource.IsToken)
- {
- cardSource.Owner.HandCards.Add(cardSource);
- if (isDraw)
- {
- if (GManager.instance.turnStateMachine.DoneStartGame)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().AddHandCardEffect(cardSource));
- }
- }
- else
- {
- ContinuousController.instance.PlaySE(GManager.instance.DrawSE);
- }
- HandCard handCard = Instantiate(GManager.instance.handCardPrefab, cardSource.Owner.HandTransform);
- handCard.gameObject.name = $"handCard_{cardSource.Owner.PlayerName}";
- handCard.GetComponent<Draggable_HandCard>().startScale = handCard.transform.localScale;
- handCard.GetComponent<Draggable_HandCard>().DefaultY = -9;
- handCard.SetUpHandCard(cardSource);
- AlignHand(cardSource.Owner);
- cardSource.SetShowingHandCard(handCard);
- if (cardSource.Owner.isYou)
- {
- handCard.SetUpHandCardImage();
- handCard.ShowCostLevel();
- }
- yield return new WaitForSeconds(Time.deltaTime);
- #region アニメーション
- if (GManager.instance.turnStateMachine.DoneStartGame)
- {
- cardSource.Owner.HandTransform.GetComponent<GridLayoutGroup>().enabled = false;
- Vector3 startPosition = Vector3.zero;
- Vector3 targetPositon = handCard.transform.localPosition;
- if (cardSource.Owner.isYou)
- {
- startPosition = handCard.transform.localPosition + new Vector3(0, 70, 0);
- }
- else
- {
- startPosition = handCard.transform.localPosition - new Vector3(0, 70, 0);
- }
- handCard.transform.localPosition = startPosition;
- bool end = false;
- var sequence = DOTween.Sequence();
- sequence
- .Append(handCard.transform.DOLocalMove(targetPositon, 0.08f).SetEase(Ease.OutBack))
- .AppendCallback(() => { end = true; });
- yield return new WaitWhile(() => !end);
- end = false;
- cardSource.Owner.HandTransform.GetComponent<GridLayoutGroup>().enabled = true;
- }
- #endregion
- if (cardSource.Owner.isYou)
- {
- handCard.SetUpHandCardImage();
- handCard.ShowCostLevel();
- }
- }
- }
- }
- #endregion
- #region put the card in the trash
- public static IEnumerator AddTrashCard(CardSource cardSource)
- {
- if (!CardEffectCommons.IsExistOnTrash(cardSource))
- {
- yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
- if (!cardSource.IsToken)
- {
- cardSource.SetFace();
- if (!CardEffectCommons.IsExistOnTrash(cardSource))
- {
- cardSource.Owner.TrashCards.Insert(0, cardSource);
- }
- cardSource.Init();
- }
- }
- }
- #endregion
- #region Put the cards together in the trash
- public static IEnumerator AddTrashCards(List<CardSource> cardSources)
- {
- List<CardSource> handCards = new List<CardSource>();
- foreach (CardSource cardSource in cardSources)
- {
- if (cardSource.Owner.HandCards.Contains(cardSource))
- {
- handCards.Add(cardSource);
- }
- }
- foreach (CardSource cardSource in handCards)
- {
- ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeleteHandCardEffectCoroutine(cardSource));
- }
- yield return new WaitForSeconds(GManager.instance.GetComponent<Effects>().waitTime_DeleteHandEffect);
- foreach (CardSource cardSource in cardSources)
- {
- if (!CardEffectCommons.IsExistOnTrash(cardSource))
- {
- yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
- if (!cardSource.IsToken)
- {
- cardSource.SetFace();
- if (!CardEffectCommons.IsExistOnTrash(cardSource))
- {
- cardSource.Owner.TrashCards.Insert(0, cardSource);
- }
- cardSource.Init();
- }
- }
- }
- }
- #endregion
- #region place a card on top of the deck
- public static IEnumerator AddLibraryTopCards(List<CardSource> cardSources, bool notAddLog = false)
- {
- if (cardSources.Count <= 0) yield break;
- bool isFromTrash = cardSources.Some(cardSource => CardEffectCommons.IsExistOnTrash(cardSource));
- yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(cardSources).Overflow());
- if (isFromTrash)
- {
- #region "Effect of "When a card is returned from the trash to the deck"
- #region Hashtable Setting
- System.Collections.Hashtable hashtable = new System.Collections.Hashtable()
- {
- {"CardSources", cardSources}
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnReturnCardsToLibraryFromTrash));
- #endregion
- }
- foreach (CardSource cardSource in cardSources)
- {
- bool isFromHand = CardEffectCommons.IsExistOnHand(cardSource);
- yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
- if (isFromHand && GManager.instance.turnStateMachine.DoneStartGame)
- {
- yield return new WaitForSeconds(GManager.instance.GetComponent<Effects>().waitTime_DeleteHandEffect);
- }
- if (!cardSource.IsToken)
- {
- cardSource.SetFace();
- if (!cardSource.IsDigiEgg)
- {
- if (!cardSource.Owner.LibraryCards.Contains(cardSource))
- {
- cardSource.Owner.LibraryCards.Insert(0, cardSource);
- }
- }
- else
- {
- if (!cardSource.Owner.DigitamaLibraryCards.Contains(cardSource))
- {
- cardSource.Owner.DigitamaLibraryCards.Insert(0, cardSource);
- }
- }
- cardSource.Init();
- }
- }
- #region Log
- if (!notAddLog)
- {
- if (cardSources.Count >= 1)
- {
- string log = "";
- log += $"\nDeck Top card{Utils.PluralFormSuffix(cardSources.Count)}:";
- foreach (CardSource cardSource in cardSources)
- {
- log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
- }
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- }
- #endregion
- }
- #endregion
- #region put a card at the bottom of the deck
- public static IEnumerator AddLibraryBottomCards(List<CardSource> cardSources, bool notAddLog = false)
- {
- if (cardSources.Count <= 0) yield break;
- bool isFromTrash = cardSources.Some(cardSource => CardEffectCommons.IsExistOnTrash(cardSource));
- yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(cardSources).Overflow());
- if (isFromTrash)
- {
- #region Effect of "When a card returns from the trash to the deck"
- #region Hashtable Setting
- System.Collections.Hashtable hashtable = new System.Collections.Hashtable()
- {
- {"CardSources", cardSources}
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnReturnCardsToLibraryFromTrash));
- #endregion
- }
- foreach (CardSource cardSource in cardSources)
- {
- if (cardSource.PermanentOfThisCard() != null)
- {
- if (cardSource.PermanentOfThisCard().DigivolutionCards.Contains(cardSource))
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>()
- .RemoveDigivolveRootEffect(cardSource, cardSource.PermanentOfThisCard()));
- }
- }
- }
- foreach (CardSource cardSource in cardSources.Clone())
- {
- bool isFromHand = CardEffectCommons.IsExistOnHand(cardSource);
- yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
- if (isFromHand && GManager.instance.turnStateMachine.DoneStartGame)
- {
- yield return new WaitForSeconds(GManager.instance.GetComponent<Effects>().waitTime_DeleteHandEffect);
- }
- if (!cardSource.IsToken)
- {
- cardSource.SetFace();
- if (!cardSource.IsDigiEgg)
- {
- if (!cardSource.Owner.LibraryCards.Contains(cardSource))
- {
- cardSource.Owner.LibraryCards.Add(cardSource);
- }
- }
- else
- {
- if (!cardSource.Owner.DigitamaLibraryCards.Contains(cardSource))
- {
- cardSource.Owner.DigitamaLibraryCards.Add(cardSource);
- }
- }
- cardSource.Init();
- }
- }
- #region Log
- if (!notAddLog)
- {
- if (cardSources.Count >= 1)
- {
- string log = "";
- log += $"\nDeck Bottom card{Utils.PluralFormSuffix(cardSources.Count)}:";
- foreach (CardSource cardSource in cardSources)
- {
- log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
- }
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- }
- #endregion
- }
- #endregion
- #region Place the card in the processing area
- public static IEnumerator AddExecutingCard(CardSource cardSource)
- {
- if (!cardSource.Owner.ExecutingCards.Contains(cardSource))
- {
- yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
- if (!cardSource.IsToken)
- {
- cardSource.SetFace();
- cardSource.Owner.ExecutingCards.Insert(0, cardSource);
- cardSource.Init();
- }
- }
- }
- #endregion
- #region Add card to security
- public static IEnumerator AddSecurityCard(CardSource cardSource, bool toTop = true, bool faceUp = false)
- {
- if (!cardSource.Owner.SecurityCards.Contains(cardSource))
- {
- yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
- if (!cardSource.IsToken)
- {
- if (!faceUp)
- cardSource.SetReverse();
- else
- cardSource.SetFace();
- cardSource.Owner.SecurityCards.Insert(0, cardSource);
- if (!toTop)
- {
- cardSource.Owner.SecurityCards.Remove(cardSource);
- cardSource.Owner.SecurityCards.Add(cardSource);
- }
- }
- }
- }
- #endregion
- #region Shuffle
- public static IEnumerator Shuffle(Player player)
- {
- ContinuousController.instance.PlaySE(GManager.instance.ShuffleSE);
- player.LibraryCards = RandomUtility.ShuffledDeckCards(player.LibraryCards);
- yield return ContinuousController.instance.StartCoroutine(player.ShuffleAnimation());
- }
- #endregion
- #region move permanent
- public static IEnumerator MovePermanent(FieldCardFrame movingPermanentFrame, bool toBreeding = false, ICardEffect effect = null)
- {
- if (movingPermanentFrame != null)
- {
- Player player = movingPermanentFrame.player;
- Permanent movingPermanent = movingPermanentFrame.GetFramePermanent();
- if (movingPermanent != null)
- {
- bool prevIsFrontLine = movingPermanentFrame.IsBattleAreaFrame();
- FieldCardFrame moveTargetFrame = movingPermanent.TopCard.PreferredFrame();
- if (toBreeding)
- {
- moveTargetFrame = player.fieldCardFrames.Filter(frame => frame.isBreedingAreaFrame()).ToList()[0];
- #region cut in effect
- // "When permanents would remove field" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
- CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
- new List<Permanent> { movingPermanent },
- effect,
- null
- ),
- EffectTiming.WhenRemoveField));
- if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
- {
- // effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
- // cut in effect process
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
- }
- #endregion
- }
- if (moveTargetFrame != null && moveTargetFrame != null)
- {
- if (moveTargetFrame.GetFramePermanent() == null)
- {
- int oldFrameID = movingPermanentFrame.FrameID;
- int newFrameID = moveTargetFrame.FrameID;
- player.FieldPermanents[oldFrameID] = null;
- player.fieldCardFrames[oldFrameID].SetFramePermanent(null);
- player.FieldPermanents[newFrameID] = movingPermanent;
- player.fieldCardFrames[newFrameID].SetFramePermanent(movingPermanent);
- #region animation
- bool end = false;
- var sequence = DOTween.Sequence();
- FieldPermanentCard movingPermanentCard = movingPermanent.ShowingPermanentCard;
- Vector3 TargetPosition = moveTargetFrame.GetLocalCanvasPosition();
- Vector3 oldPosition = movingPermanentFrame.GetLocalCanvasPosition();
- float GoTime = 0.2f;
- sequence
- .Append(movingPermanentCard.transform.DOLocalMove(TargetPosition, GoTime).SetEase(Ease.OutCubic))
- .AppendCallback(() =>
- {
- end = true;
- });
- sequence.Play();
- yield return new WaitWhile(() => !end);
- end = false;
- #endregion
- if (!prevIsFrontLine)
- {
- #region Effect of "when moving from the training area"
- #region Hashtable Setting
- System.Collections.Hashtable hashtable = new System.Collections.Hashtable()
- {
- {"Permanent", movingPermanent}
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnMove));
- #endregion
- }
- }
- }
- }
- }
- }
- #endregion
- }
|