| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677 |
- using DG.Tweening;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using UnityEngine;
- using UnityEngine.Events;
- using UnityEngine.UI;
- using UnityEngine.EventSystems;
- using System.Threading.Tasks;
- using TMPro;
- public class Player : MonoBehaviour
- {
- #region 初期化
- private async void Start()
- {
- fieldCardFrames = new List<FieldCardFrame>();
- if (BattleAreaFrameParent != null && BreedingAreaFrameParent != null)
- {
- int count = 0;
- for (int i = 0; i < BattleAreaFrameParent.childCount; i++)
- {
- if (BattleAreaFrameParent.GetChild(i).childCount >= 2)
- {
- FieldCardFrame fieldCardFrame = new FieldCardFrame
- {
- Frame = BattleAreaFrameParent.GetChild(i).GetChild(0).gameObject,
- Frame_Select = BattleAreaFrameParent.GetChild(i).GetChild(1).GetComponent<Image>(),
- FrameID = count,
- player = this
- };
- fieldCardFrame.Frame.GetComponent<Image>().color = new Color(0, 0, 0, 0);
- fieldCardFrame.Frame_Select.color = new Color(0, 0, 0, 0);
- fieldCardFrames.Add(fieldCardFrame);
- count++;
- }
- }
- if (BreedingAreaFrameParent.childCount >= 2)
- {
- FieldCardFrame fieldCardFrame = new FieldCardFrame
- {
- Frame = BreedingAreaFrameParent.GetChild(0).gameObject,
- Frame_Select = BreedingAreaFrameParent.GetChild(1).GetComponent<Image>(),
- FrameID = count,
- player = this
- };
- fieldCardFrame.Frame.GetComponent<Image>().color = new Color(0, 0, 0, 0);
- fieldCardFrame.Frame_Select.color = new Color(0, 0, 0, 0);
- fieldCardFrames.Add(fieldCardFrame);
- count++;
- }
- BattleAreaFrameParent.gameObject.SetActive(true);
- BreedingAreaFrameParent.gameObject.SetActive(true);
- }
- for (int i = 0; i < HandTransform.childCount; i++)
- {
- Destroy(HandTransform.GetChild(i).gameObject);
- }
- for (int i = 0; i < PermanentTransform.childCount; i++)
- {
- Destroy(PermanentTransform.GetChild(i).gameObject);
- }
- for (int i = 0; i < fieldCardFrames.Count; i++)
- {
- fieldCardFrames[i].OffFrame_Select();
- fieldCardFrames[i].Frame.GetComponent<Image>().color = new Color(0, 0, 0, 0);
- fieldCardFrames[i].Frame_Select.color = new Color(0, 0, 0, 0);
- }
- TrashHandCard.gameObject.SetActive(false);
- FieldPermanents = new Permanent[fieldCardFrames.Count];
- SetPlayerUI();
- await SetOriginalPlayMat();
- FirstObject.SetActive(false);
- playMatCardFrame.OffFrame_Select();
- if (PlayerNameText != null)
- {
- PlayerNameText.transform.parent.gameObject.SetActive(false);
- }
- OffHatchObject();
- if (HatchObject != null)
- {
- Image hatchImage = HatchObject.GetComponent<Image>();
- if (hatchImage != null)
- {
- if (ContinuousController.instance != null)
- {
- hatchImage.sprite = ContinuousController.instance.ReverseCard_Digitama;
- }
- }
- }
- if (_handCountText != null)
- {
- _handCountText.text = "";
- }
- }
- #endregion
- public GameObject FirstObject;
- public bool IsLose { get; set; } = false;
- public Transform playerUIObjectParent;
- public void SetLose()
- {
- IsLose = true;
- }
- public void OnClickFrame(int FrameID)
- {
- FieldCardFrame fieldCardFrame = fieldCardFrames[FrameID];
- fieldCardFrame.OnClickAction?.Invoke(fieldCardFrame);
- }
- int _timerCount = 0;
- int _updateFrame = 20;
- private void Update()
- {
- #region Update only once every few frames
- _timerCount++;
- if (_timerCount < _updateFrame)
- {
- return;
- }
- else
- {
- _timerCount = 0;
- }
- #endregion
- SetPlayerUI();
- }
- public void SetPlayerUI()
- {
- AlignHand();
- SetLibraryCountText();
- SetDigitamaLibraryCountText();
- securityObject.SetSecurity(this);
- ShowTrash();
- SetHandCountText();
- }
- #region Action Queue
- Queue<MainPhaseAction> mainPhaseActions = new Queue<MainPhaseAction>();
- public void QueueMainPhaseAction(MainPhaseAction action)
- {
- mainPhaseActions.Enqueue(action);
- }
- public MainPhaseAction DequeueMainPhaseAction()
- {
- if (mainPhaseActions.Count == 0)
- {
- return null;
- }
- return mainPhaseActions.Dequeue();
- }
- public bool HasMainPhaseAction()
- {
- return mainPhaseActions.Count > 0;
- }
- #endregion
- #region Selection Queue
- Queue<IPlayerSelection> _playerSelectionQueue = new Queue<IPlayerSelection>();
- public void QueuePlayerSelection(IPlayerSelection selection)
- {
- _playerSelectionQueue.Enqueue(selection);
- }
- public T DequeuePlayerSelection<T>() where T : class, IPlayerSelection
- {
- IPlayerSelection playerSelection = _playerSelectionQueue.Dequeue();
- if (playerSelection is not T)
- {
- Debug.LogWarning("Unexpected Player Selection", this);
- return null;
- }
- return playerSelection as T;
- }
- public bool HasPlayerSelection()
- {
- return _playerSelectionQueue.Count > 0;
- }
- #endregion
- #region セキュリティアタックの座標
- public Vector3 SecurityAttackLocalCanvasPosition;
- #endregion
- #region 処理領域の座標
- public Vector3 ExecutingAreaLocalCanvasPosition;
- #endregion
- #region そのプレイヤーの何ターン目か
- public int TurnCount { get; set; } = 0;
- #endregion
- #region 処理領域表示オブジェクト
- public BrainStormObject brainStormObject;
- #endregion
- #region 山札の枚数表示テキスト
- public Text LibraryCountText;
- public List<Image> DeckCardImages;
- public Text DigitamaLibraryCountText;
- public List<Image> DigitamaDeckCardImages;
- public EventTrigger HatchObject;
- public UnityAction OnClickHatchObjectAction;
- [SerializeField] TextMeshProUGUI _handCountText;
- public void OnClickHatchObject()
- {
- OnClickHatchObjectAction?.Invoke();
- }
- public void OffHatchObject()
- {
- this.OnClickHatchObjectAction = null;
- if (HatchObject != null)
- {
- HatchObject.gameObject.SetActive(false);
- }
- }
- public void SetUpHatchObject(UnityAction OnClickHatchObjectAction)
- {
- this.OnClickHatchObjectAction = OnClickHatchObjectAction;
- if (HatchObject != null)
- {
- HatchObject.gameObject.SetActive(true);
- Image targetImage = null;
- for (int i = 0; i < DigitamaDeckCardImages.Count; i++)
- {
- if (DigitamaDeckCardImages[i].gameObject.activeSelf)
- {
- targetImage = DigitamaDeckCardImages[i];
- }
- }
- if (targetImage != null)
- {
- HatchObject.transform.localPosition = targetImage.transform.localPosition;
- }
- }
- }
- void SetHandCountText()
- {
- if (_handCountText != null)
- {
- _handCountText.text = $"Hand\n{HandCards.Count}";
- }
- }
- void SetLibraryCountText()
- {
- LibraryCountText.text = $"{LibraryCards.Count}";
- if (LibraryCards.Count == 0)
- {
- for (int i = 0; i < DeckCardImages.Count; i++)
- {
- DeckCardImages[i].gameObject.SetActive(false);
- }
- }
- else
- {
- int count = LibraryCards.Count / 8;
- for (int i = 0; i < DeckCardImages.Count; i++)
- {
- if (i <= count)
- {
- DeckCardImages[i].gameObject.SetActive(true);
- DeckCardImages[i].sprite = ContinuousController.instance.ReverseCard;
- }
- else
- {
- DeckCardImages[i].gameObject.SetActive(false);
- }
- }
- }
- }
- public void SetDigitamaLibraryCountText()
- {
- DigitamaLibraryCountText.text = $"{DigitamaLibraryCards.Count}";
- if (DigitamaLibraryCards.Count == 0)
- {
- for (int i = 0; i < DigitamaDeckCardImages.Count; i++)
- {
- DigitamaDeckCardImages[i].gameObject.SetActive(false);
- }
- }
- else
- {
- int count = DigitamaLibraryCards.Count;
- for (int i = 0; i < DigitamaDeckCardImages.Count; i++)
- {
- if (i < count)
- {
- DigitamaDeckCardImages[i].gameObject.SetActive(true);
- DigitamaDeckCardImages[i].sprite = ContinuousController.instance.ReverseCard_Digitama;
- }
- else
- {
- DigitamaDeckCardImages[i].gameObject.SetActive(false);
- }
- }
- }
- }
- #endregion
- #region トラッシュ
- [Header("トラッシュ画像")]
- public Image TrashCardImage;
- [Header("トラッシュ枚数テキスト")]
- public Text TrashCountText;
- async void ShowTrash()
- {
- if (TrashCardImage != null)
- {
- if (TrashCards.Count == 0)
- {
- TrashCardImage.gameObject.SetActive(false);
- }
- else
- {
- TrashCardImage.gameObject.SetActive(true);
- TrashCardImage.sprite = await TrashCards[0].GetCardSprite();
- if (!isYou)
- {
- if (ContinuousController.instance != null)
- {
- Quaternion localRotation = Quaternion.Euler(0, 0, 0);
- if (ContinuousController.instance.reverseOpponentsCards)
- {
- localRotation = Quaternion.Euler(0, 0, 180);
- }
- TrashCardImage.transform.localRotation = localRotation;
- }
- }
- }
- }
- if (TrashCountText != null)
- {
- TrashCountText.text = $"{TrashCards.Count}";
- }
- }
- #endregion
- #region シャッフルアニメーション
- public IEnumerator ShuffleAnimation()
- {
- float animTime = 0.03f;
- yield return null;
- for (int k = 0; k < 3; k++)
- {
- for (int j = 0; j < 2; j++)
- {
- for (int i = 0; i < DeckCardImages.Count; i++)
- {
- float targetY;
- if (j % 2 == 0)
- {
- targetY = 0;
- }
- else
- {
- targetY = 30;
- }
- if (k % 2 == 0)
- {
- if (i % 2 == 0)
- {
- targetY *= -1;
- }
- }
- else
- {
- if (i % 2 == 1)
- {
- targetY *= -1;
- }
- }
- DeckCardImages[i].transform.DOLocalMoveY(targetY, animTime);
- }
- yield return new WaitForSeconds(animTime);
- }
- }
- for (int i = 0; i < DeckCardImages.Count; i++)
- {
- DeckCardImages[i].transform.localPosition = new Vector2(DeckCardImages[i].transform.localPosition.x, DeckCardImages[i].transform.localPosition.x);
- }
- }
- #endregion
- #region セキュリティ表示
- public SecurityObject securityObject;
- #endregion
- #region 手札を整列
- public void AlignHand()
- {
- if (isYou)
- {
- if (GManager.instance != null)
- {
- if (GManager.instance.turnStateMachine != null)
- {
- if (GManager.instance.turnStateMachine.DoneStartGame)
- {
- if (!HandTransform.GetComponent<HandContoller>().isDragging)
- {
- foreach (CardSource cardSource in HandCards)
- {
- if (cardSource.ShowingHandCard != null)
- {
- cardSource.ShowingHandCard.transform.SetParent(HandTransform);
- }
- }
- CardObjectController.AlignHand(this);
- }
- }
- }
- }
- }
- }
- #endregion
- #region キーカード
- public CEntity_Base KeyCard { get; set; }
- #endregion
- #region カード情報
- #region デッキのカード
- public List<CardSource> LibraryCards = new List<CardSource>();
- #endregion
- #region デジタマデッキのカード
- public List<CardSource> DigitamaLibraryCards = new List<CardSource>();
- #endregion
- #region 手札のカード
- public List<CardSource> HandCards = new List<CardSource>();
- #endregion
- #region 場外のカード
- public List<CardSource> TrashCards = new List<CardSource>();
- #endregion
- #region ロストのカード
- public List<CardSource> LostCards = new List<CardSource>();
- #endregion
- #region ライフのカード
- public List<CardSource> SecurityCards = new List<CardSource>();
- #endregion
- #region 処理領域のカード
- public List<CardSource> ExecutingCards = new List<CardSource>();
- #endregion
- #endregion
- #region このプレイヤーがあなたかどうか
- [Header("このプレイヤーがあなたかどうか")]
- public bool isYou;
- #endregion
- #region CardSource置き場
- [Header("CardSource置き場")]
- public Transform CardSorcesParent;
- #endregion
- #region カード配置場所
- [Header("パーマネントの配置場所")]
- public Transform PermanentTransform;
- [Header("手札の配置場所")]
- public Transform HandTransform;
- #endregion
- #region プレイマットSpriteRenderer
- public SpriteRenderer PlayMatSpriteRenderer;
- public SpriteRenderer PlayMatSpriteRenderer_Original;
- public async Task SetOriginalPlayMat()
- {
- if (PlayMatSpriteRenderer_Original != null)
- {
- string filiName;
- if (isYou)
- {
- filiName = "PlayMat_You";
- }
- else
- {
- filiName = "PlayMat_Opponent";
- }
- Sprite playMatSprite = await StreamingAssetsUtility.GetSprite(filiName);
- if (playMatSprite != null)
- {
- Sprite sprite = playMatSprite;
- PlayMatSpriteRenderer_Original.sprite = sprite;
- PlayMatSpriteRenderer_Original.gameObject.SetActive(true);
- float width = 3045f;
- float spriteWidth = sprite.rect.width;
- float spriteHeight = sprite.rect.height;
- if (spriteWidth == 0)
- {
- spriteWidth = 0.01f;
- }
- float scale = width / spriteWidth;
- PlayMatSpriteRenderer_Original.transform.localScale = new Vector3(scale, scale, 1);
- PlayMatSpriteRenderer_Original.transform.localPosition = new Vector3(-15.2f, -6f, 0);
- }
- else
- {
- PlayMatSpriteRenderer_Original.gameObject.SetActive(false);
- }
- }
- }
- #endregion
- #region 枠
- [Header("パーマネント枠")]
- public List<FieldCardFrame> fieldCardFrames = new List<FieldCardFrame>();
- [Header("バトルエリア枠親")]
- [SerializeField] Transform BattleAreaFrameParent;
- [Header("育成エリア枠親")]
- [SerializeField] Transform BreedingAreaFrameParent;
- #endregion
- #region 手札領域の幅
- [Header("手札領域の幅")]
- public float HandWidth;
- #endregion
- #region バトルエリアのパーマネント
- public List<Permanent> GetBattleAreaPermanents()
- {
- List<Permanent> GetBattleAreaPermanents = new List<Permanent>();
- for (int i = 0; i < FieldPermanents.Length; i++)
- {
- if (FieldCardFrame.isBattleAreaFrameID(i))
- {
- if (FieldPermanents[i] != null)
- {
- if (FieldPermanents[i].TopCard != null)
- {
- GetBattleAreaPermanents.Add(FieldPermanents[i]);
- }
- }
- }
- }
- return GetBattleAreaPermanents;
- }
- #endregion
- #region 育成エリアのパーマネント
- public List<Permanent> GetBreedingAreaPermanents()
- {
- List<Permanent> GetBreedingAreaPermanents = new List<Permanent>();
- for (int i = 0; i < FieldPermanents.Length; i++)
- {
- if (!FieldCardFrame.isBattleAreaFrameID(i))
- {
- if (FieldPermanents[i] != null)
- {
- if (FieldPermanents[i].TopCard != null)
- {
- GetBreedingAreaPermanents.Add(FieldPermanents[i]);
- }
- }
- }
- }
- return GetBreedingAreaPermanents;
- }
- #endregion
- #region 場のパーマネント
- public Permanent[] FieldPermanents = new Permanent[16];
- public List<Permanent> GetFieldPermanents()
- {
- List<Permanent> GetFieldPermanents = new List<Permanent>();
- for (int i = 0; i < FieldPermanents.Length; i++)
- {
- if (FieldPermanents[i] != null)
- {
- if (FieldPermanents[i].TopCard != null)
- {
- GetFieldPermanents.Add(FieldPermanents[i]);
- }
- }
- }
- return GetFieldPermanents;
- }
- public List<Permanent> GetBattleAreaDigimons()
- {
- List<Permanent> battleAreaPermanents = GetBattleAreaPermanents();
- List<Permanent> GetBattleAreaDigimons = new List<Permanent>();
- for (int i = 0; i < battleAreaPermanents.Count; i++)
- {
- if (battleAreaPermanents[i] != null)
- {
- if (battleAreaPermanents[i].TopCard != null)
- {
- if (battleAreaPermanents[i].IsDigimon)
- {
- GetBattleAreaDigimons.Add(battleAreaPermanents[i]);
- }
- }
- }
- }
- return GetBattleAreaDigimons;
- }
- #endregion
- #region Player Name
- private string _playerName = "Opponent";
- public string PlayerName {
- get {
- if (isYou || GManager.instance.IsAI)
- return _playerName;
- else
- return "Opponent";
- }
- set { _playerName = value; }
- }
- [Header("プレイヤー名")]
- public TextMeshProUGUI PlayerNameText;
- #endregion
- #region 勝利数
- public int WinCount { get; set; }
- public void ShowWinCount()
- {
- //WinCountText.transform.parent.gameObject.SetActive(true);
- }
- public void HideWinCount()
- {
- //WinCountText.transform.parent.gameObject.SetActive(false);
- }
- #endregion
- #region PlayerID
- public int PlayerID { get; set; }
- #endregion
- #region Enemy
- public Player Enemy
- {
- get
- {
- if (GManager.instance != null)
- {
- if (GManager.instance.turnStateMachine != null)
- {
- if (GManager.instance.turnStateMachine.gameContext != null)
- {
- if (GManager.instance.turnStateMachine.gameContext.Players.Contains(this))
- {
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
- {
- if (player != this)
- {
- return player;
- }
- }
- }
- }
- }
- }
- return null;
- }
- }
- #endregion
- #region プレイマット
- [Header("PlayMat")]
- public GameObject PlayMat;
- #endregion
- #region プレイマットの枠
- public FieldCardFrame playMatCardFrame;
- #endregion
- #region 手札のドロップエリア
- [Header("手札のドロップエリア")]
- public DropArea HandDropArea;
- #endregion
- #region 場のパーマネントカードオブジェクト
- public List<FieldPermanentCard> FieldPermanentObjects
- {
- get
- {
- List<FieldPermanentCard> _FieldPermanentObjects = new List<FieldPermanentCard>();
- for (int i = 0; i < PermanentTransform.childCount; i++)
- {
- FieldPermanentCard fieldPermanentCard = PermanentTransform.GetChild(i).GetComponent<FieldPermanentCard>();
- if (fieldPermanentCard != null)
- {
- _FieldPermanentObjects.Add(fieldPermanentCard);
- }
- }
- return _FieldPermanentObjects;
- }
- }
- #endregion
- #region 手札のカードオブジェクト
- public List<HandCard> HandCardObjects
- {
- get
- {
- List<HandCard> _HandCards = new List<HandCard>();
- foreach (CardSource cardSource in HandCards)
- {
- if (cardSource.ShowingHandCard != null)
- {
- _HandCards.Add(cardSource.ShowingHandCard);
- }
- }
- return _HandCards;
- }
- }
- #endregion
- #region プレイヤーに掛かっている効果
- #region All effects on the player
- public List<ICardEffect> EffectList(EffectTiming timing)
- {
- List<ICardEffect> PlayerEffects = new List<ICardEffect>();
- foreach (Func<EffectTiming, ICardEffect> GetCardEffect in PermanentEffects)
- {
- if (GetCardEffect(timing) != null)
- {
- PlayerEffects.Add(GetCardEffect(timing));
- }
- }
- foreach (Func<EffectTiming, ICardEffect> GetCardEffect in UntilEndBattleEffects)
- {
- if (GetCardEffect(timing) != null)
- {
- PlayerEffects.Add(GetCardEffect(timing));
- }
- }
- foreach (Func<EffectTiming, ICardEffect> GetCardEffect in UntilEachTurnEndEffects)
- {
- if (GetCardEffect(timing) != null)
- {
- PlayerEffects.Add(GetCardEffect(timing));
- }
- }
- foreach (Func<EffectTiming, ICardEffect> GetCardEffect in UntilOwnerTurnEndEffects)
- {
- if (GetCardEffect(timing) != null)
- {
- PlayerEffects.Add(GetCardEffect(timing));
- }
- }
- foreach (Func<EffectTiming, ICardEffect> GetCardEffect in UntilOwnerActivePhaseEffects)
- {
- if (GetCardEffect(timing) != null)
- {
- PlayerEffects.Add(GetCardEffect(timing));
- }
- }
- foreach (Func<EffectTiming, ICardEffect> GetCardEffect in UntilSecurityCheckEndEffects)
- {
- if (GetCardEffect(timing) != null)
- {
- PlayerEffects.Add(GetCardEffect(timing));
- }
- }
- foreach (Func<EffectTiming, ICardEffect> GetCardEffect in UntilOpponentTurnEndEffects)
- {
- if (GetCardEffect(timing) != null)
- {
- PlayerEffects.Add(GetCardEffect(timing));
- }
- }
- foreach (Func<EffectTiming, ICardEffect> GetCardEffect in UntilCalculateFixedCostEffect)
- {
- if (GetCardEffect(timing) != null)
- {
- PlayerEffects.Add(GetCardEffect(timing));
- }
- }
- foreach (ICardEffect cardEffect in PlayerEffects)
- {
- if (cardEffect.EffectSourceCard == null)
- {
- foreach (CardSource cardSource in GManager.instance.turnStateMachine.gameContext.ActiveCardList)
- {
- if (cardSource.Owner == this && !cardSource.IsToken)
- {
- cardEffect.SetEffectSourceCard(cardSource);
- break;
- }
- }
- }
- }
- return PlayerEffects;
- }
- #endregion
- #region 消えないプレイヤーに掛かっている効果
- public List<Func<EffectTiming, ICardEffect>> PermanentEffects = new List<Func<EffectTiming, ICardEffect>>();
- #endregion
- #region バトル終了時に消えるプレイヤーに掛かっている効果
- public List<Func<EffectTiming, ICardEffect>> UntilEndBattleEffects = new List<Func<EffectTiming, ICardEffect>>();
- #endregion
- #region お互いのターン終了時に消えるプレイヤーに掛かっている効果
- public List<Func<EffectTiming, ICardEffect>> UntilEachTurnEndEffects = new List<Func<EffectTiming, ICardEffect>>();
- #endregion
- #region 自分のターン終了時に消えるプレイヤーに掛かっている効果
- public List<Func<EffectTiming, ICardEffect>> UntilOwnerTurnEndEffects = new List<Func<EffectTiming, ICardEffect>>();
- #endregion
- #region 自分のアクティブフェイズ終了時に消えるプレイヤーに掛かっている効果
- public List<Func<EffectTiming, ICardEffect>> UntilOwnerActivePhaseEffects = new List<Func<EffectTiming, ICardEffect>>();
- #endregion
- #region 相手のターン終了時に消えるプレイヤーに掛かっている効果
- public List<Func<EffectTiming, ICardEffect>> UntilOpponentTurnEndEffects = new List<Func<EffectTiming, ICardEffect>>();
- #endregion
- #region カード使用後に消えるプレイヤーに掛かっている効果
- public List<Func<EffectTiming, ICardEffect>> UntilCalculateFixedCostEffect = new List<Func<EffectTiming, ICardEffect>>();
- #endregion
- #region セキュリティチェック後に消えるプレイヤーに掛かっている効果
- public List<Func<EffectTiming, ICardEffect>> UntilSecurityCheckEndEffects = new List<Func<EffectTiming, ICardEffect>>();
- #endregion
- #endregion
- #region Timestamp of the last time the player's turn started, for continuous effects.
- DateTime _turnStartTime = DateTime.MinValue;
- public DateTime TurnStartTime
- {
- get { return _turnStartTime; }
- private set { _turnStartTime = value; }
- }
- public void SetTurnStartTime()
- {
- TurnStartTime = DateTime.Now;
- }
- #endregion
- #region トラッシュのカードオブジェクト
- public HandCard TrashHandCard;
- #endregion
- #region このプレイヤーから見た時のメモリー
- public int MemoryForPlayer
- {
- get
- {
- int memory = GManager.instance.turnStateMachine.gameContext.Memory;
- if (PlayerID == 0)
- {
- memory *= -1;
- }
- return memory;
- }
- }
- #endregion
- #region メモリーを固定の値にする
- public IEnumerator SetFixedMemory(int Memory, ICardEffect cardEffect)
- {
- if (MemoryForPlayer < Memory)
- {
- #region メモリーを+出来ないなら処理終了
- if (cardEffect != null)
- {
- if (!CanAddMemory(cardEffect))
- {
- yield break;
- }
- }
- #endregion
- }
- if (PlayerID == 0)
- {
- GManager.instance.turnStateMachine.gameContext.Memory = -1 * Memory;
- }
- else
- {
- GManager.instance.turnStateMachine.gameContext.Memory = Memory;
- }
- if (GManager.instance.turnStateMachine.gameContext.Memory >= 10)
- {
- GManager.instance.turnStateMachine.gameContext.Memory = 10;
- }
- else if (GManager.instance.turnStateMachine.gameContext.Memory <= -10)
- {
- GManager.instance.turnStateMachine.gameContext.Memory = -10;
- }
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.memoryObject.SetMemory());
- }
- #endregion
- #region Can you increase memory?
- public bool CanAddMemory(ICardEffect cardEffect)
- {
- if (this.MemoryForPlayer >= 10)
- {
- return false;
- }
- #region Effects that impair memory
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
- {
- foreach (Permanent permanent in player.GetFieldPermanents())
- {
- #region Effects of permanents in play
- foreach (ICardEffect cardEffect1 in permanent.EffectList(EffectTiming.None))
- {
- if (cardEffect1 is ICannotAddMemoryEffect)
- {
- if (cardEffect1.CanUse(null))
- {
- if (((ICannotAddMemoryEffect)cardEffect1).cannotAddMemory(this, cardEffect))
- {
- return false;
- }
- }
- }
- }
- #endregion
- }
- #region player effect
- foreach (ICardEffect cardEffect1 in player.EffectList(EffectTiming.None))
- {
- if (cardEffect1 is ICannotAddMemoryEffect)
- {
- if (cardEffect1.CanUse(null))
- {
- if (((ICannotAddMemoryEffect)cardEffect1).cannotAddMemory(this, cardEffect))
- {
- return false;
- }
- }
- }
- }
- #endregion
- }
- #endregion
- return true;
- }
- #endregion
- #region メモリーを+する
- public IEnumerator AddMemory(int plusMemory, ICardEffect cardEffect)
- {
- if (plusMemory == 0)
- {
- yield break;
- }
- if (plusMemory >= 1)
- {
- #region メモリーを+出来ないなら処理終了
- if (cardEffect != null)
- {
- if (!CanAddMemory(cardEffect))
- {
- yield break;
- }
- }
- #endregion
- }
- if (PlayerID == 0)
- {
- GManager.instance.turnStateMachine.gameContext.Memory -= plusMemory;
- }
- else
- {
- GManager.instance.turnStateMachine.gameContext.Memory += plusMemory;
- }
- if (GManager.instance.turnStateMachine.gameContext.Memory >= 10)
- {
- GManager.instance.turnStateMachine.gameContext.Memory = 10;
- }
- else if (GManager.instance.turnStateMachine.gameContext.Memory <= -10)
- {
- GManager.instance.turnStateMachine.gameContext.Memory = -10;
- }
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.memoryObject.SetMemory());
- }
- #endregion
- #region 払えるメモリーコストの上限
- public int MaxMemoryCost
- {
- get
- {
- int MaxMemoryCost;
- if (PlayerID == 0)
- {
- MaxMemoryCost = Mathf.Abs(10 - GManager.instance.turnStateMachine.gameContext.Memory);
- }
- else
- {
- MaxMemoryCost = Mathf.Abs(-10 - GManager.instance.turnStateMachine.gameContext.Memory);
- }
- return MaxMemoryCost;
- }
- }
- #endregion
- #region コスト支払い後のメモリー予測値
- public int ExpectedMemory(int memoryCost)
- {
- int ExpectedMemory = GManager.instance.turnStateMachine.gameContext.Memory;
- if (PlayerID == 0)
- {
- ExpectedMemory += memoryCost;
- }
- else
- {
- ExpectedMemory -= memoryCost;
- }
- return ExpectedMemory;
- }
- #endregion
- #region デジタマを孵化できるか
- public bool CanHatch => DigitamaLibraryCards.Count >= 1 && GetBreedingAreaPermanents().Count == 0;
- #endregion
- #region デジモンを移動できるか
- public bool CanMove => GetBreedingAreaPermanents().Count(permanent => permanent.CanMove) >= 1 && fieldCardFrames.Count((frame) => frame.IsEmptyFrame()) >= 1;
- #endregion
- #region このターンにデジモンを進化させた回数
- public int DigivolveCount_ThisTurn { get; set; } = 0;
- #endregion
- #region 吸収進化でタップできるデジモンの条件(効果可否判定に使用)
- public bool CanTapWhenAbsorbEvolution_CheckAvailability(Permanent permanent, ICardEffect cardEffect)
- {
- if (permanent != null)
- {
- if (permanent.TopCard != null)
- {
- if (!permanent.IsSuspended && permanent.CanSuspend)
- {
- if (permanent.TopCard.Owner.GetBattleAreaDigimons().Contains(permanent))
- {
- #region 吸収進化でタップできるデジモンの条件を変更させる効果
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
- {
- foreach (Permanent permanent1 in player.GetFieldPermanents())
- {
- #region 場のパーマネントの効果
- foreach (ICardEffect cardEffect1 in permanent1.EffectList(EffectTiming.None))
- {
- if (cardEffect1 is ICanSuspendByDigisorptionEffect)
- {
- if (cardEffect1.CanUse(null))
- {
- if (((ICanSuspendByDigisorptionEffect)cardEffect1).isCheckAvailability())
- {
- if (((ICanSuspendByDigisorptionEffect)cardEffect1).canSuspendDigisorption(permanent, cardEffect))
- {
- return true;
- }
- }
- }
- }
- }
- #endregion
- }
- #region プレイヤーの効果
- foreach (ICardEffect cardEffect1 in player.EffectList(EffectTiming.None))
- {
- if (cardEffect1 is ICanSuspendByDigisorptionEffect)
- {
- if (cardEffect1.CanUse(null))
- {
- if (((ICanSuspendByDigisorptionEffect)cardEffect1).isCheckAvailability())
- {
- if (((ICanSuspendByDigisorptionEffect)cardEffect1).canSuspendDigisorption(permanent, cardEffect))
- {
- return true;
- }
- }
- }
- }
- }
- #endregion
- }
- #endregion
- if (permanent.TopCard.Owner == this)
- {
- return true;
- }
- }
- }
- }
- }
- return false;
- }
- #endregion
- #region 吸収進化でタップできるデジモンの条件
- public bool CanTapWhenAbsorbEvolution(Permanent permanent, ICardEffect cardEffect)
- {
- if (permanent != null)
- {
- if (permanent.TopCard != null)
- {
- if (!permanent.IsSuspended && permanent.CanSuspend)
- {
- if (permanent.TopCard.Owner.GetBattleAreaDigimons().Contains(permanent))
- {
- #region 吸収進化でタップできるデジモンの条件を変更させる効果
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
- {
- foreach (Permanent permanent1 in player.GetFieldPermanents())
- {
- #region 場のパーマネントの効果
- foreach (ICardEffect cardEffect1 in permanent1.EffectList(EffectTiming.None))
- {
- if (cardEffect1 is ICanSuspendByDigisorptionEffect)
- {
- if (cardEffect1.CanUse(null))
- {
- if (!((ICanSuspendByDigisorptionEffect)cardEffect1).isCheckAvailability())
- {
- if (((ICanSuspendByDigisorptionEffect)cardEffect1).canSuspendDigisorption(permanent, cardEffect))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- }
- }
- #endregion
- }
- #region プレイヤーの効果
- foreach (ICardEffect cardEffect1 in player.EffectList(EffectTiming.None))
- {
- if (cardEffect1 is ICanSuspendByDigisorptionEffect)
- {
- if (cardEffect1.CanUse(null))
- {
- if (!((ICanSuspendByDigisorptionEffect)cardEffect1).isCheckAvailability())
- {
- if (((ICanSuspendByDigisorptionEffect)cardEffect1).canSuspendDigisorption(permanent, cardEffect))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- }
- }
- #endregion
- }
- #endregion
- if (permanent.TopCard.Owner == this)
- {
- return true;
- }
- }
- }
- }
- }
- return false;
- }
- #endregion
- #region コストを減らせるか
- public bool CanReduceCost(List<Permanent> targetPermanents, CardSource cardSource)
- {
- #region コストを減らせなくさせる効果
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
- {
- foreach (Permanent permanent in player.GetFieldPermanents())
- {
- #region 場のパーマネントの効果
- foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
- {
- if (cardEffect is ICannotReduceCostEffect)
- {
- if (cardEffect.CanUse(null))
- {
- if (((ICannotReduceCostEffect)cardEffect).CannotReduceCost(this, targetPermanents, cardSource))
- {
- return false;
- }
- }
- }
- }
- #endregion
- }
- #region プレイヤーの効果
- foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
- {
- if (cardEffect is ICannotReduceCostEffect)
- {
- if (cardEffect.CanUse(null))
- {
- if (((ICannotReduceCostEffect)cardEffect).CannotReduceCost(this, targetPermanents, cardSource))
- {
- return false;
- }
- }
- }
- }
- #endregion
- }
- #endregion
- return true;
- }
- #endregion
- #region DP消滅効果の上限
- public int MaxDP_DeleteEffect(int maxDP, ICardEffect cardEffect)
- {
- int _maxDP = maxDP;
- #region DP消滅効果の上限を変更する効果
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
- {
- foreach (Permanent permanent in player.GetFieldPermanents())
- {
- #region 場のパーマネントの効果
- foreach (ICardEffect cardEffect1 in permanent.EffectList(EffectTiming.None))
- {
- if (cardEffect1 is IChangeDPDeleteEffectMaxDPEffect)
- {
- if (cardEffect1.CanUse(null))
- {
- _maxDP = ((IChangeDPDeleteEffectMaxDPEffect)cardEffect1).GetMaxDP(_maxDP, cardEffect);
- }
- }
- }
- #endregion
- }
- #region プレイヤーの効果
- foreach (ICardEffect cardEffect1 in player.EffectList(EffectTiming.None))
- {
- if (cardEffect1 is IChangeDPDeleteEffectMaxDPEffect)
- {
- if (cardEffect1.CanUse(null))
- {
- _maxDP = ((IChangeDPDeleteEffectMaxDPEffect)cardEffect1).GetMaxDP(_maxDP, cardEffect);
- }
- }
- }
- #endregion
- }
- #endregion
- return _maxDP;
- }
- #endregion
- #region 進化条件を無視できるか
- public bool CanIgnoreDigivolutionRequirement(Permanent targetPermanent, CardSource cardSource)
- {
- #region 進化条件を無視できなくさせる効果
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
- {
- foreach (Permanent permanent in player.GetFieldPermanents())
- {
- #region 場のパーマネントの効果
- foreach (ICardEffect cardEffect1 in permanent.EffectList(EffectTiming.None))
- {
- if (cardEffect1 is ICannotIgnoreDigivolutionConditionEffect)
- {
- if (cardEffect1.CanUse(null))
- {
- if (((ICannotIgnoreDigivolutionConditionEffect)cardEffect1).cannotIgnoreDigivolutionCondition(this, targetPermanent, cardSource))
- {
- return false;
- }
- }
- }
- }
- #endregion
- }
- #region Player effect
- foreach (ICardEffect cardEffect1 in player.EffectList(EffectTiming.None))
- {
- if (cardEffect1 is ICannotIgnoreDigivolutionConditionEffect)
- {
- if (cardEffect1.CanUse(null))
- {
- if (((ICannotIgnoreDigivolutionConditionEffect)cardEffect1).cannotIgnoreDigivolutionCondition(this, targetPermanent, cardSource))
- {
- return false;
- }
- }
- }
- }
- #endregion
- }
- #endregion
- return true;
- }
- #endregion
- #region セキュリティを増やせるか
- public bool CanAddSecurity(ICardEffect cardEffect)
- {
- if (GManager.instance.turnStateMachine.gameContext.IsSecurityLooking)
- {
- return false;
- }
- #region セキュリティを増やせない効果
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
- {
- foreach (Permanent permanent in player.GetFieldPermanents())
- {
- #region 場のパーマネントの効果
- foreach (ICardEffect cardEffect1 in permanent.EffectList(EffectTiming.None))
- {
- if (cardEffect1 is ICannotAddSecurityEffect)
- {
- if (cardEffect1.CanUse(null))
- {
- if (((ICannotAddSecurityEffect)cardEffect1).cannotAddSecurity(this, cardEffect))
- {
- return false;
- }
- }
- }
- }
- #endregion
- }
- #region プレイヤーの効果
- foreach (ICardEffect cardEffect1 in player.EffectList(EffectTiming.None))
- {
- if (cardEffect1 is ICannotAddSecurityEffect)
- {
- if (cardEffect1.CanUse(null))
- {
- if (((ICannotAddSecurityEffect)cardEffect1).cannotAddSecurity(this, cardEffect))
- {
- return false;
- }
- }
- }
- }
- #endregion
- }
- #endregion
- return true;
- }
- #endregion
- #region セキュリティを減らせるか
- public bool CanReduceSecurity()
- {
- if (GManager.instance.turnStateMachine.gameContext.IsSecurityLooking)
- {
- return false;
- }
- return true;
- }
- #endregion
- }
- [Serializable]
- public class ShowSupplyingEnergyIcon
- {
- public CardColor cardColor;
- public Image SupplyingEnergyIcon;
- public Text SupplyingEnergyText;
- }
- [Serializable]
- public class FieldCardFrame
- {
- [Header("枠")]
- public GameObject Frame;
- [Header("選択状態表示枠")]
- public Image Frame_Select;
- [Header("枠ID")]
- public int FrameID;
- [Header("プレイヤー")]
- public Player player;
- public UnityAction<FieldCardFrame> OnClickAction { get; private set; }
- public static bool isBattleAreaFrameID(int FrameID)
- {
- return 0 <= FrameID && FrameID <= GManager.instance.You.fieldCardFrames.Count - 2;
- }
- public bool IsBattleAreaFrame()
- {
- return isBattleAreaFrameID(this.FrameID);
- }
- public bool isBreedingAreaFrame()
- {
- return !IsBattleAreaFrame();
- }
- Permanent framePermanent = null;
- public void SetFramePermanent(Permanent permanent)
- {
- framePermanent = permanent;
- }
- public Permanent GetFramePermanent()
- {
- /*
- foreach (Permanent permanent in player.GetFieldPermanents())
- {
- if (permanent.PermanentFrame == this)
- {
- return permanent;
- }
- }
- */
- if (framePermanent != null)
- {
- return framePermanent;
- }
- return null;
- }
- public bool IsEmptyFrame()
- {
- return GetFramePermanent() == null;
- }
- public void AddClickTarget(UnityAction<FieldCardFrame> OnClickAction)
- {
- this.OnClickAction = OnClickAction;
- if (Frame != null)
- {
- BoxCollider boxCollider = Frame.GetComponent<BoxCollider>();
- if (boxCollider != null)
- {
- boxCollider.enabled = true;
- }
- }
- }
- public void RemoveClickTarget()
- {
- this.OnClickAction = null;
- if (Frame != null)
- {
- BoxCollider boxCollider = Frame.GetComponent<BoxCollider>();
- if (boxCollider != null)
- {
- boxCollider.enabled = false;
- }
- }
- }
- public void OffFrame_Select()
- {
- if (Frame_Select != null)
- {
- Frame_Select.gameObject.SetActive(false);
- }
- }
- public void OnFrame_Select(Color color)
- {
- if (Frame_Select != null)
- {
- Frame_Select.gameObject.SetActive(true);
- Frame_Select.color = color;
- //Frame_Select.color = new Color(color.r, color.g, color.b, 0);
- }
- }
- public Vector3 GetLocalCanvasPosition()
- {
- Vector3 vector = Frame.transform.localPosition + Frame.transform.parent.localPosition + Frame.transform.parent.parent.localPosition;
- return Frame.transform.localPosition + Frame.transform.parent.localPosition + Frame.transform.parent.parent.localPosition;
- }
- public FieldCardFrame FacingFrame
- {
- get
- {
- if (this.IsBattleAreaFrame())
- {
- return player.fieldCardFrames[this.FrameID + 4];
- }
- else
- {
- return player.fieldCardFrames[this.FrameID - 4];
- }
- }
- }
- }
|