| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044 |
- 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 お互いのプレイヤーのデッキのカードを生成する
- 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());
- #if UNITY_EDITOR && !UNITY_WINDOWS
- foreach (DeckData deckData in ContinuousController.instance.DeckDatas)
- {
- if (deckData.IsValidDeckData())
- {
- RandomDeck = new DeckData(deckData.GetThisDeckCode());
- 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 カードを生成
- 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 カードをすべての領域から取り除く
- public static IEnumerator RemoveFromAllArea(CardSource cardSource)
- {
- 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 場を離れさせる
- public static IEnumerator RemoveField(Permanent permanent, bool ignoreOverflow = false)
- {
- if (permanent == null) yield break;
- if (permanent.TopCard == null) yield break;
- 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 カードを手札に加える
- public static IEnumerator AddHandCards(List<CardSource> cardSources, bool isDraw, ICardEffect cardEffect)
- {
- if (cardSources.Count == 0) yield break;
- cardSources = cardSources.Filter(cardSource => cardSource != null && !cardSource.Owner.HandCards.Contains(cardSource));
- foreach (CardSource cardSource in cardSources)
- {
- if (cardSource.IsToken)
- {
- yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
- }
- }
- List<CardSource> addedCards = cardSources.Filter(cardSource => !cardSource.IsToken);
- 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)
- {
- List<Player> Players = addedCards.Map(cardSource => cardSource.Owner).Distinct().ToList();
- #region "手札が増えた時"の効果
- #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
- }
- }
- 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 カードをトラッシュに置く
- 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 カードをまとめてトラッシュに置く
- 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 カードを山札の上に置く
- 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 "カードがトラッシュから山札に戻った時"の効果
- #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";
- GManager.instance.playLog.AddLogString(log);
- }
- }
- #endregion
- }
- #endregion
- #region カードを山札の下に置く
- 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 "カードがトラッシュから山札に戻った時"の効果
- #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)
- {
- 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";
- GManager.instance.playLog.AddLogString(log);
- }
- }
- #endregion
- }
- #endregion
- #region カードを処理領域に置く
- 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 カードをセキュリティに追加する
- public static IEnumerator AddSecurityCard(CardSource cardSource, bool toTop = true)
- {
- if (!cardSource.Owner.SecurityCards.Contains(cardSource))
- {
- yield return ContinuousController.instance.StartCoroutine(RemoveFromAllArea(cardSource));
- if (!cardSource.IsToken)
- {
- cardSource.SetReverse();
- cardSource.Owner.SecurityCards.Insert(0, cardSource);
- if (!toTop)
- {
- cardSource.Owner.SecurityCards.Remove(cardSource);
- cardSource.Owner.SecurityCards.Add(cardSource);
- }
- }
- }
- }
- #endregion
- #region デッキをシャッフル
- 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 パーマネントを移動
- public static IEnumerator MovePermanent(FieldCardFrame movingPermanentFrame)
- {
- if (movingPermanentFrame != null)
- {
- Player player = movingPermanentFrame.player;
- Permanent movingPermanent = movingPermanentFrame.GetFramePermanent();
- if (movingPermanent != null)
- {
- bool oldIsFrontLine = movingPermanentFrame.IsBattleAreaFrame();
- FieldCardFrame moveTargetFrame = movingPermanent.TopCard.PreferredFrame();
- 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 アニメーション
- 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 (!oldIsFrontLine)
- {
- #region "育成エリアから移動した時"の効果
- #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
- }
|