Player.cs 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634
  1. using DG.Tweening;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using UnityEngine;
  7. using UnityEngine.Events;
  8. using UnityEngine.UI;
  9. using UnityEngine.EventSystems;
  10. using System.Threading.Tasks;
  11. using TMPro;
  12. public class Player : MonoBehaviour
  13. {
  14. #region 初期化
  15. private async void Start()
  16. {
  17. fieldCardFrames = new List<FieldCardFrame>();
  18. if (BattleAreaFrameParent != null && BreedingAreaFrameParent != null)
  19. {
  20. int count = 0;
  21. for (int i = 0; i < BattleAreaFrameParent.childCount; i++)
  22. {
  23. if (BattleAreaFrameParent.GetChild(i).childCount >= 2)
  24. {
  25. FieldCardFrame fieldCardFrame = new FieldCardFrame
  26. {
  27. Frame = BattleAreaFrameParent.GetChild(i).GetChild(0).gameObject,
  28. Frame_Select = BattleAreaFrameParent.GetChild(i).GetChild(1).GetComponent<Image>(),
  29. FrameID = count,
  30. player = this
  31. };
  32. fieldCardFrame.Frame.GetComponent<Image>().color = new Color(0, 0, 0, 0);
  33. fieldCardFrame.Frame_Select.color = new Color(0, 0, 0, 0);
  34. fieldCardFrames.Add(fieldCardFrame);
  35. count++;
  36. }
  37. }
  38. if (BreedingAreaFrameParent.childCount >= 2)
  39. {
  40. FieldCardFrame fieldCardFrame = new FieldCardFrame
  41. {
  42. Frame = BreedingAreaFrameParent.GetChild(0).gameObject,
  43. Frame_Select = BreedingAreaFrameParent.GetChild(1).GetComponent<Image>(),
  44. FrameID = count,
  45. player = this
  46. };
  47. fieldCardFrame.Frame.GetComponent<Image>().color = new Color(0, 0, 0, 0);
  48. fieldCardFrame.Frame_Select.color = new Color(0, 0, 0, 0);
  49. fieldCardFrames.Add(fieldCardFrame);
  50. count++;
  51. }
  52. BattleAreaFrameParent.gameObject.SetActive(true);
  53. BreedingAreaFrameParent.gameObject.SetActive(true);
  54. }
  55. for (int i = 0; i < HandTransform.childCount; i++)
  56. {
  57. Destroy(HandTransform.GetChild(i).gameObject);
  58. }
  59. for (int i = 0; i < PermanentTransform.childCount; i++)
  60. {
  61. Destroy(PermanentTransform.GetChild(i).gameObject);
  62. }
  63. for (int i = 0; i < fieldCardFrames.Count; i++)
  64. {
  65. fieldCardFrames[i].OffFrame_Select();
  66. fieldCardFrames[i].Frame.GetComponent<Image>().color = new Color(0, 0, 0, 0);
  67. fieldCardFrames[i].Frame_Select.color = new Color(0, 0, 0, 0);
  68. }
  69. TrashHandCard.gameObject.SetActive(false);
  70. FieldPermanents = new Permanent[fieldCardFrames.Count];
  71. SetPlayerUI();
  72. await SetOriginalPlayMat();
  73. FirstObject.SetActive(false);
  74. playMatCardFrame.OffFrame_Select();
  75. if (PlayerNameText != null)
  76. {
  77. PlayerNameText.transform.parent.gameObject.SetActive(false);
  78. }
  79. OffHatchObject();
  80. if (HatchObject != null)
  81. {
  82. Image hatchImage = HatchObject.GetComponent<Image>();
  83. if (hatchImage != null)
  84. {
  85. if (ContinuousController.instance != null)
  86. {
  87. hatchImage.sprite = ContinuousController.instance.ReverseCard_Digitama;
  88. }
  89. }
  90. }
  91. if (_handCountText != null)
  92. {
  93. _handCountText.text = "";
  94. }
  95. }
  96. #endregion
  97. public GameObject FirstObject;
  98. public bool IsLose { get; set; } = false;
  99. public Transform playerUIObjectParent;
  100. public void SetLose()
  101. {
  102. IsLose = true;
  103. }
  104. public void OnClickFrame(int FrameID)
  105. {
  106. FieldCardFrame fieldCardFrame = fieldCardFrames[FrameID];
  107. fieldCardFrame.OnClickAction?.Invoke(fieldCardFrame);
  108. }
  109. int _timerCount = 0;
  110. int _updateFrame = 20;
  111. private void Update()
  112. {
  113. #region Update only once every few frames
  114. _timerCount++;
  115. if (_timerCount < _updateFrame)
  116. {
  117. return;
  118. }
  119. else
  120. {
  121. _timerCount = 0;
  122. }
  123. #endregion
  124. SetPlayerUI();
  125. }
  126. public void SetPlayerUI()
  127. {
  128. AlignHand();
  129. SetLibraryCountText();
  130. SetDigitamaLibraryCountText();
  131. securityObject.SetSecurity(this);
  132. ShowTrash();
  133. SetHandCountText();
  134. }
  135. #region Action Queue
  136. Queue<MainPhaseAction> mainPhaseActions = new Queue<MainPhaseAction>();
  137. public void QueueMainPhaseAction(MainPhaseAction action)
  138. {
  139. mainPhaseActions.Enqueue(action);
  140. }
  141. public MainPhaseAction DequeueMainPhaseAction()
  142. {
  143. if (mainPhaseActions.Count == 0)
  144. {
  145. return null;
  146. }
  147. return mainPhaseActions.Dequeue();
  148. }
  149. public bool HasMainPhaseAction()
  150. {
  151. return mainPhaseActions.Count > 0;
  152. }
  153. #endregion
  154. #region セキュリティアタックの座標
  155. public Vector3 SecurityAttackLocalCanvasPosition;
  156. #endregion
  157. #region 処理領域の座標
  158. public Vector3 ExecutingAreaLocalCanvasPosition;
  159. #endregion
  160. #region そのプレイヤーの何ターン目か
  161. public int TurnCount { get; set; } = 0;
  162. #endregion
  163. #region 処理領域表示オブジェクト
  164. public BrainStormObject brainStormObject;
  165. #endregion
  166. #region 山札の枚数表示テキスト
  167. public Text LibraryCountText;
  168. public List<Image> DeckCardImages;
  169. public Text DigitamaLibraryCountText;
  170. public List<Image> DigitamaDeckCardImages;
  171. public EventTrigger HatchObject;
  172. public UnityAction OnClickHatchObjectAction;
  173. [SerializeField] TextMeshProUGUI _handCountText;
  174. public void OnClickHatchObject()
  175. {
  176. OnClickHatchObjectAction?.Invoke();
  177. }
  178. public void OffHatchObject()
  179. {
  180. this.OnClickHatchObjectAction = null;
  181. if (HatchObject != null)
  182. {
  183. HatchObject.gameObject.SetActive(false);
  184. }
  185. }
  186. public void SetUpHatchObject(UnityAction OnClickHatchObjectAction)
  187. {
  188. this.OnClickHatchObjectAction = OnClickHatchObjectAction;
  189. if (HatchObject != null)
  190. {
  191. HatchObject.gameObject.SetActive(true);
  192. Image targetImage = null;
  193. for (int i = 0; i < DigitamaDeckCardImages.Count; i++)
  194. {
  195. if (DigitamaDeckCardImages[i].gameObject.activeSelf)
  196. {
  197. targetImage = DigitamaDeckCardImages[i];
  198. }
  199. }
  200. if (targetImage != null)
  201. {
  202. HatchObject.transform.localPosition = targetImage.transform.localPosition;
  203. }
  204. }
  205. }
  206. void SetHandCountText()
  207. {
  208. if (_handCountText != null)
  209. {
  210. _handCountText.text = $"Hand\n{HandCards.Count}";
  211. }
  212. }
  213. void SetLibraryCountText()
  214. {
  215. LibraryCountText.text = $"{LibraryCards.Count}";
  216. if (LibraryCards.Count == 0)
  217. {
  218. for (int i = 0; i < DeckCardImages.Count; i++)
  219. {
  220. DeckCardImages[i].gameObject.SetActive(false);
  221. }
  222. }
  223. else
  224. {
  225. int count = LibraryCards.Count / 8;
  226. for (int i = 0; i < DeckCardImages.Count; i++)
  227. {
  228. if (i <= count)
  229. {
  230. DeckCardImages[i].gameObject.SetActive(true);
  231. DeckCardImages[i].sprite = ContinuousController.instance.ReverseCard;
  232. }
  233. else
  234. {
  235. DeckCardImages[i].gameObject.SetActive(false);
  236. }
  237. }
  238. }
  239. }
  240. public void SetDigitamaLibraryCountText()
  241. {
  242. DigitamaLibraryCountText.text = $"{DigitamaLibraryCards.Count}";
  243. if (DigitamaLibraryCards.Count == 0)
  244. {
  245. for (int i = 0; i < DigitamaDeckCardImages.Count; i++)
  246. {
  247. DigitamaDeckCardImages[i].gameObject.SetActive(false);
  248. }
  249. }
  250. else
  251. {
  252. int count = DigitamaLibraryCards.Count;
  253. for (int i = 0; i < DigitamaDeckCardImages.Count; i++)
  254. {
  255. if (i < count)
  256. {
  257. DigitamaDeckCardImages[i].gameObject.SetActive(true);
  258. DigitamaDeckCardImages[i].sprite = ContinuousController.instance.ReverseCard_Digitama;
  259. }
  260. else
  261. {
  262. DigitamaDeckCardImages[i].gameObject.SetActive(false);
  263. }
  264. }
  265. }
  266. }
  267. #endregion
  268. #region トラッシュ
  269. [Header("トラッシュ画像")]
  270. public Image TrashCardImage;
  271. [Header("トラッシュ枚数テキスト")]
  272. public Text TrashCountText;
  273. async void ShowTrash()
  274. {
  275. if (TrashCardImage != null)
  276. {
  277. if (TrashCards.Count == 0)
  278. {
  279. TrashCardImage.gameObject.SetActive(false);
  280. }
  281. else
  282. {
  283. TrashCardImage.gameObject.SetActive(true);
  284. TrashCardImage.sprite = await TrashCards[0].GetCardSprite();
  285. if (!isYou)
  286. {
  287. if (ContinuousController.instance != null)
  288. {
  289. Quaternion localRotation = Quaternion.Euler(0, 0, 0);
  290. if (ContinuousController.instance.reverseOpponentsCards)
  291. {
  292. localRotation = Quaternion.Euler(0, 0, 180);
  293. }
  294. TrashCardImage.transform.localRotation = localRotation;
  295. }
  296. }
  297. }
  298. }
  299. if (TrashCountText != null)
  300. {
  301. TrashCountText.text = $"{TrashCards.Count}";
  302. }
  303. }
  304. #endregion
  305. #region シャッフルアニメーション
  306. public IEnumerator ShuffleAnimation()
  307. {
  308. float animTime = 0.03f;
  309. yield return null;
  310. for (int k = 0; k < 3; k++)
  311. {
  312. for (int j = 0; j < 2; j++)
  313. {
  314. for (int i = 0; i < DeckCardImages.Count; i++)
  315. {
  316. float targetY;
  317. if (j % 2 == 0)
  318. {
  319. targetY = 0;
  320. }
  321. else
  322. {
  323. targetY = 30;
  324. }
  325. if (k % 2 == 0)
  326. {
  327. if (i % 2 == 0)
  328. {
  329. targetY *= -1;
  330. }
  331. }
  332. else
  333. {
  334. if (i % 2 == 1)
  335. {
  336. targetY *= -1;
  337. }
  338. }
  339. DeckCardImages[i].transform.DOLocalMoveY(targetY, animTime);
  340. }
  341. yield return new WaitForSeconds(animTime);
  342. }
  343. }
  344. for (int i = 0; i < DeckCardImages.Count; i++)
  345. {
  346. DeckCardImages[i].transform.localPosition = new Vector2(DeckCardImages[i].transform.localPosition.x, DeckCardImages[i].transform.localPosition.x);
  347. }
  348. }
  349. #endregion
  350. #region セキュリティ表示
  351. public SecurityObject securityObject;
  352. #endregion
  353. #region 手札を整列
  354. public void AlignHand()
  355. {
  356. if (isYou)
  357. {
  358. if (GManager.instance != null)
  359. {
  360. if (GManager.instance.turnStateMachine != null)
  361. {
  362. if (GManager.instance.turnStateMachine.DoneStartGame)
  363. {
  364. if (!HandTransform.GetComponent<HandContoller>().isDragging)
  365. {
  366. foreach (CardSource cardSource in HandCards)
  367. {
  368. if (cardSource.ShowingHandCard != null)
  369. {
  370. cardSource.ShowingHandCard.transform.SetParent(HandTransform);
  371. }
  372. }
  373. CardObjectController.AlignHand(this);
  374. }
  375. }
  376. }
  377. }
  378. }
  379. }
  380. #endregion
  381. #region キーカード
  382. public CEntity_Base KeyCard { get; set; }
  383. #endregion
  384. #region カード情報
  385. #region デッキのカード
  386. public List<CardSource> LibraryCards = new List<CardSource>();
  387. #endregion
  388. #region デジタマデッキのカード
  389. public List<CardSource> DigitamaLibraryCards = new List<CardSource>();
  390. #endregion
  391. #region 手札のカード
  392. public List<CardSource> HandCards = new List<CardSource>();
  393. #endregion
  394. #region 場外のカード
  395. public List<CardSource> TrashCards = new List<CardSource>();
  396. #endregion
  397. #region ロストのカード
  398. public List<CardSource> LostCards = new List<CardSource>();
  399. #endregion
  400. #region ライフのカード
  401. public List<CardSource> SecurityCards = new List<CardSource>();
  402. #endregion
  403. #region 処理領域のカード
  404. public List<CardSource> ExecutingCards = new List<CardSource>();
  405. #endregion
  406. #endregion
  407. #region このプレイヤーがあなたかどうか
  408. [Header("このプレイヤーがあなたかどうか")]
  409. public bool isYou;
  410. #endregion
  411. #region CardSource置き場
  412. [Header("CardSource置き場")]
  413. public Transform CardSorcesParent;
  414. #endregion
  415. #region カード配置場所
  416. [Header("パーマネントの配置場所")]
  417. public Transform PermanentTransform;
  418. [Header("手札の配置場所")]
  419. public Transform HandTransform;
  420. #endregion
  421. #region プレイマットSpriteRenderer
  422. public SpriteRenderer PlayMatSpriteRenderer;
  423. public SpriteRenderer PlayMatSpriteRenderer_Original;
  424. public async Task SetOriginalPlayMat()
  425. {
  426. if (PlayMatSpriteRenderer_Original != null)
  427. {
  428. string filiName;
  429. if (isYou)
  430. {
  431. filiName = "PlayMat_You";
  432. }
  433. else
  434. {
  435. filiName = "PlayMat_Opponent";
  436. }
  437. Sprite playMatSprite = await StreamingAssetsUtility.GetSprite(filiName);
  438. if (playMatSprite != null)
  439. {
  440. Sprite sprite = playMatSprite;
  441. PlayMatSpriteRenderer_Original.sprite = sprite;
  442. PlayMatSpriteRenderer_Original.gameObject.SetActive(true);
  443. float width = 3045f;
  444. float spriteWidth = sprite.rect.width;
  445. float spriteHeight = sprite.rect.height;
  446. if (spriteWidth == 0)
  447. {
  448. spriteWidth = 0.01f;
  449. }
  450. float scale = width / spriteWidth;
  451. PlayMatSpriteRenderer_Original.transform.localScale = new Vector3(scale, scale, 1);
  452. PlayMatSpriteRenderer_Original.transform.localPosition = new Vector3(-15.2f, -6f, 0);
  453. }
  454. else
  455. {
  456. PlayMatSpriteRenderer_Original.gameObject.SetActive(false);
  457. }
  458. }
  459. }
  460. #endregion
  461. #region 枠
  462. [Header("パーマネント枠")]
  463. public List<FieldCardFrame> fieldCardFrames = new List<FieldCardFrame>();
  464. [Header("バトルエリア枠親")]
  465. [SerializeField] Transform BattleAreaFrameParent;
  466. [Header("育成エリア枠親")]
  467. [SerializeField] Transform BreedingAreaFrameParent;
  468. #endregion
  469. #region 手札領域の幅
  470. [Header("手札領域の幅")]
  471. public float HandWidth;
  472. #endregion
  473. #region バトルエリアのパーマネント
  474. public List<Permanent> GetBattleAreaPermanents()
  475. {
  476. List<Permanent> GetBattleAreaPermanents = new List<Permanent>();
  477. for (int i = 0; i < FieldPermanents.Length; i++)
  478. {
  479. if (FieldCardFrame.isBattleAreaFrameID(i))
  480. {
  481. if (FieldPermanents[i] != null)
  482. {
  483. if (FieldPermanents[i].TopCard != null)
  484. {
  485. GetBattleAreaPermanents.Add(FieldPermanents[i]);
  486. }
  487. }
  488. }
  489. }
  490. return GetBattleAreaPermanents;
  491. }
  492. #endregion
  493. #region 育成エリアのパーマネント
  494. public List<Permanent> GetBreedingAreaPermanents()
  495. {
  496. List<Permanent> GetBreedingAreaPermanents = new List<Permanent>();
  497. for (int i = 0; i < FieldPermanents.Length; i++)
  498. {
  499. if (!FieldCardFrame.isBattleAreaFrameID(i))
  500. {
  501. if (FieldPermanents[i] != null)
  502. {
  503. if (FieldPermanents[i].TopCard != null)
  504. {
  505. GetBreedingAreaPermanents.Add(FieldPermanents[i]);
  506. }
  507. }
  508. }
  509. }
  510. return GetBreedingAreaPermanents;
  511. }
  512. #endregion
  513. #region 場のパーマネント
  514. public Permanent[] FieldPermanents = new Permanent[16];
  515. public List<Permanent> GetFieldPermanents()
  516. {
  517. List<Permanent> GetFieldPermanents = new List<Permanent>();
  518. for (int i = 0; i < FieldPermanents.Length; i++)
  519. {
  520. if (FieldPermanents[i] != null)
  521. {
  522. if (FieldPermanents[i].TopCard != null)
  523. {
  524. GetFieldPermanents.Add(FieldPermanents[i]);
  525. }
  526. }
  527. }
  528. return GetFieldPermanents;
  529. }
  530. public List<Permanent> GetBattleAreaDigimons()
  531. {
  532. List<Permanent> battleAreaPermanents = GetBattleAreaPermanents();
  533. List<Permanent> GetBattleAreaDigimons = new List<Permanent>();
  534. for (int i = 0; i < battleAreaPermanents.Count; i++)
  535. {
  536. if (battleAreaPermanents[i] != null)
  537. {
  538. if (battleAreaPermanents[i].TopCard != null)
  539. {
  540. if (battleAreaPermanents[i].IsDigimon)
  541. {
  542. GetBattleAreaDigimons.Add(battleAreaPermanents[i]);
  543. }
  544. }
  545. }
  546. }
  547. return GetBattleAreaDigimons;
  548. }
  549. #endregion
  550. #region Player Name
  551. private string _playerName = "Opponent";
  552. public string PlayerName {
  553. get {
  554. if (isYou || GManager.instance.IsAI)
  555. return _playerName;
  556. else
  557. return "Opponent";
  558. }
  559. set { _playerName = value; }
  560. }
  561. [Header("プレイヤー名")]
  562. public TextMeshProUGUI PlayerNameText;
  563. #endregion
  564. #region 勝利数
  565. public int WinCount { get; set; }
  566. public void ShowWinCount()
  567. {
  568. //WinCountText.transform.parent.gameObject.SetActive(true);
  569. }
  570. public void HideWinCount()
  571. {
  572. //WinCountText.transform.parent.gameObject.SetActive(false);
  573. }
  574. #endregion
  575. #region PlayerID
  576. public int PlayerID { get; set; }
  577. #endregion
  578. #region Enemy
  579. public Player Enemy
  580. {
  581. get
  582. {
  583. if (GManager.instance != null)
  584. {
  585. if (GManager.instance.turnStateMachine != null)
  586. {
  587. if (GManager.instance.turnStateMachine.gameContext != null)
  588. {
  589. if (GManager.instance.turnStateMachine.gameContext.Players.Contains(this))
  590. {
  591. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  592. {
  593. if (player != this)
  594. {
  595. return player;
  596. }
  597. }
  598. }
  599. }
  600. }
  601. }
  602. return null;
  603. }
  604. }
  605. #endregion
  606. #region プレイマット
  607. [Header("PlayMat")]
  608. public GameObject PlayMat;
  609. #endregion
  610. #region プレイマットの枠
  611. public FieldCardFrame playMatCardFrame;
  612. #endregion
  613. #region 手札のドロップエリア
  614. [Header("手札のドロップエリア")]
  615. public DropArea HandDropArea;
  616. #endregion
  617. #region 場のパーマネントカードオブジェクト
  618. public List<FieldPermanentCard> FieldPermanentObjects
  619. {
  620. get
  621. {
  622. List<FieldPermanentCard> _FieldPermanentObjects = new List<FieldPermanentCard>();
  623. for (int i = 0; i < PermanentTransform.childCount; i++)
  624. {
  625. FieldPermanentCard fieldPermanentCard = PermanentTransform.GetChild(i).GetComponent<FieldPermanentCard>();
  626. if (fieldPermanentCard != null)
  627. {
  628. _FieldPermanentObjects.Add(fieldPermanentCard);
  629. }
  630. }
  631. return _FieldPermanentObjects;
  632. }
  633. }
  634. #endregion
  635. #region 手札のカードオブジェクト
  636. public List<HandCard> HandCardObjects
  637. {
  638. get
  639. {
  640. List<HandCard> _HandCards = new List<HandCard>();
  641. foreach (CardSource cardSource in HandCards)
  642. {
  643. if (cardSource.ShowingHandCard != null)
  644. {
  645. _HandCards.Add(cardSource.ShowingHandCard);
  646. }
  647. }
  648. return _HandCards;
  649. }
  650. }
  651. #endregion
  652. #region プレイヤーに掛かっている効果
  653. #region All effects on the player
  654. public List<ICardEffect> EffectList(EffectTiming timing)
  655. {
  656. List<ICardEffect> PlayerEffects = new List<ICardEffect>();
  657. foreach (Func<EffectTiming, ICardEffect> GetCardEffect in PermanentEffects)
  658. {
  659. if (GetCardEffect(timing) != null)
  660. {
  661. PlayerEffects.Add(GetCardEffect(timing));
  662. }
  663. }
  664. foreach (Func<EffectTiming, ICardEffect> GetCardEffect in UntilEndBattleEffects)
  665. {
  666. if (GetCardEffect(timing) != null)
  667. {
  668. PlayerEffects.Add(GetCardEffect(timing));
  669. }
  670. }
  671. foreach (Func<EffectTiming, ICardEffect> GetCardEffect in UntilEachTurnEndEffects)
  672. {
  673. if (GetCardEffect(timing) != null)
  674. {
  675. PlayerEffects.Add(GetCardEffect(timing));
  676. }
  677. }
  678. foreach (Func<EffectTiming, ICardEffect> GetCardEffect in UntilOwnerTurnEndEffects)
  679. {
  680. if (GetCardEffect(timing) != null)
  681. {
  682. PlayerEffects.Add(GetCardEffect(timing));
  683. }
  684. }
  685. foreach (Func<EffectTiming, ICardEffect> GetCardEffect in UntilOwnerActivePhaseEffects)
  686. {
  687. if (GetCardEffect(timing) != null)
  688. {
  689. PlayerEffects.Add(GetCardEffect(timing));
  690. }
  691. }
  692. foreach (Func<EffectTiming, ICardEffect> GetCardEffect in UntilSecurityCheckEndEffects)
  693. {
  694. if (GetCardEffect(timing) != null)
  695. {
  696. PlayerEffects.Add(GetCardEffect(timing));
  697. }
  698. }
  699. foreach (Func<EffectTiming, ICardEffect> GetCardEffect in UntilOpponentTurnEndEffects)
  700. {
  701. if (GetCardEffect(timing) != null)
  702. {
  703. PlayerEffects.Add(GetCardEffect(timing));
  704. }
  705. }
  706. foreach (Func<EffectTiming, ICardEffect> GetCardEffect in UntilCalculateFixedCostEffect)
  707. {
  708. if (GetCardEffect(timing) != null)
  709. {
  710. PlayerEffects.Add(GetCardEffect(timing));
  711. }
  712. }
  713. foreach (ICardEffect cardEffect in PlayerEffects)
  714. {
  715. if (cardEffect.EffectSourceCard == null)
  716. {
  717. foreach (CardSource cardSource in GManager.instance.turnStateMachine.gameContext.ActiveCardList)
  718. {
  719. if (cardSource.Owner == this && !cardSource.IsToken)
  720. {
  721. cardEffect.SetEffectSourceCard(cardSource);
  722. break;
  723. }
  724. }
  725. }
  726. }
  727. return PlayerEffects;
  728. }
  729. #endregion
  730. #region 消えないプレイヤーに掛かっている効果
  731. public List<Func<EffectTiming, ICardEffect>> PermanentEffects = new List<Func<EffectTiming, ICardEffect>>();
  732. #endregion
  733. #region バトル終了時に消えるプレイヤーに掛かっている効果
  734. public List<Func<EffectTiming, ICardEffect>> UntilEndBattleEffects = new List<Func<EffectTiming, ICardEffect>>();
  735. #endregion
  736. #region お互いのターン終了時に消えるプレイヤーに掛かっている効果
  737. public List<Func<EffectTiming, ICardEffect>> UntilEachTurnEndEffects = new List<Func<EffectTiming, ICardEffect>>();
  738. #endregion
  739. #region 自分のターン終了時に消えるプレイヤーに掛かっている効果
  740. public List<Func<EffectTiming, ICardEffect>> UntilOwnerTurnEndEffects = new List<Func<EffectTiming, ICardEffect>>();
  741. #endregion
  742. #region 自分のアクティブフェイズ終了時に消えるプレイヤーに掛かっている効果
  743. public List<Func<EffectTiming, ICardEffect>> UntilOwnerActivePhaseEffects = new List<Func<EffectTiming, ICardEffect>>();
  744. #endregion
  745. #region 相手のターン終了時に消えるプレイヤーに掛かっている効果
  746. public List<Func<EffectTiming, ICardEffect>> UntilOpponentTurnEndEffects = new List<Func<EffectTiming, ICardEffect>>();
  747. #endregion
  748. #region カード使用後に消えるプレイヤーに掛かっている効果
  749. public List<Func<EffectTiming, ICardEffect>> UntilCalculateFixedCostEffect = new List<Func<EffectTiming, ICardEffect>>();
  750. #endregion
  751. #region セキュリティチェック後に消えるプレイヤーに掛かっている効果
  752. public List<Func<EffectTiming, ICardEffect>> UntilSecurityCheckEndEffects = new List<Func<EffectTiming, ICardEffect>>();
  753. #endregion
  754. #endregion
  755. #region トラッシュのカードオブジェクト
  756. public HandCard TrashHandCard;
  757. #endregion
  758. #region このプレイヤーから見た時のメモリー
  759. public int MemoryForPlayer
  760. {
  761. get
  762. {
  763. int memory = GManager.instance.turnStateMachine.gameContext.Memory;
  764. if (PlayerID == 0)
  765. {
  766. memory *= -1;
  767. }
  768. return memory;
  769. }
  770. }
  771. #endregion
  772. #region メモリーを固定の値にする
  773. public IEnumerator SetFixedMemory(int Memory, ICardEffect cardEffect)
  774. {
  775. if (MemoryForPlayer < Memory)
  776. {
  777. #region メモリーを+出来ないなら処理終了
  778. if (cardEffect != null)
  779. {
  780. if (!CanAddMemory(cardEffect))
  781. {
  782. yield break;
  783. }
  784. }
  785. #endregion
  786. }
  787. if (PlayerID == 0)
  788. {
  789. GManager.instance.turnStateMachine.gameContext.Memory = -1 * Memory;
  790. }
  791. else
  792. {
  793. GManager.instance.turnStateMachine.gameContext.Memory = Memory;
  794. }
  795. if (GManager.instance.turnStateMachine.gameContext.Memory >= 10)
  796. {
  797. GManager.instance.turnStateMachine.gameContext.Memory = 10;
  798. }
  799. else if (GManager.instance.turnStateMachine.gameContext.Memory <= -10)
  800. {
  801. GManager.instance.turnStateMachine.gameContext.Memory = -10;
  802. }
  803. yield return ContinuousController.instance.StartCoroutine(GManager.instance.memoryObject.SetMemory());
  804. }
  805. #endregion
  806. #region Can you increase memory?
  807. public bool CanAddMemory(ICardEffect cardEffect)
  808. {
  809. if (this.MemoryForPlayer >= 10)
  810. {
  811. return false;
  812. }
  813. #region Effects that impair memory
  814. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  815. {
  816. foreach (Permanent permanent in player.GetFieldPermanents())
  817. {
  818. #region Effects of permanents in play
  819. foreach (ICardEffect cardEffect1 in permanent.EffectList(EffectTiming.None))
  820. {
  821. if (cardEffect1 is ICannotAddMemoryEffect)
  822. {
  823. if (cardEffect1.CanUse(null))
  824. {
  825. if (((ICannotAddMemoryEffect)cardEffect1).cannotAddMemory(this, cardEffect))
  826. {
  827. return false;
  828. }
  829. }
  830. }
  831. }
  832. #endregion
  833. }
  834. #region player effect
  835. foreach (ICardEffect cardEffect1 in player.EffectList(EffectTiming.None))
  836. {
  837. if (cardEffect1 is ICannotAddMemoryEffect)
  838. {
  839. if (cardEffect1.CanUse(null))
  840. {
  841. if (((ICannotAddMemoryEffect)cardEffect1).cannotAddMemory(this, cardEffect))
  842. {
  843. return false;
  844. }
  845. }
  846. }
  847. }
  848. #endregion
  849. }
  850. #endregion
  851. return true;
  852. }
  853. #endregion
  854. #region メモリーを+する
  855. public IEnumerator AddMemory(int plusMemory, ICardEffect cardEffect)
  856. {
  857. if (plusMemory == 0)
  858. {
  859. yield break;
  860. }
  861. if (plusMemory >= 1)
  862. {
  863. #region メモリーを+出来ないなら処理終了
  864. if (cardEffect != null)
  865. {
  866. if (!CanAddMemory(cardEffect))
  867. {
  868. yield break;
  869. }
  870. }
  871. #endregion
  872. }
  873. if (PlayerID == 0)
  874. {
  875. GManager.instance.turnStateMachine.gameContext.Memory -= plusMemory;
  876. }
  877. else
  878. {
  879. GManager.instance.turnStateMachine.gameContext.Memory += plusMemory;
  880. }
  881. if (GManager.instance.turnStateMachine.gameContext.Memory >= 10)
  882. {
  883. GManager.instance.turnStateMachine.gameContext.Memory = 10;
  884. }
  885. else if (GManager.instance.turnStateMachine.gameContext.Memory <= -10)
  886. {
  887. GManager.instance.turnStateMachine.gameContext.Memory = -10;
  888. }
  889. yield return ContinuousController.instance.StartCoroutine(GManager.instance.memoryObject.SetMemory());
  890. }
  891. #endregion
  892. #region 払えるメモリーコストの上限
  893. public int MaxMemoryCost
  894. {
  895. get
  896. {
  897. int MaxMemoryCost;
  898. if (PlayerID == 0)
  899. {
  900. MaxMemoryCost = Mathf.Abs(10 - GManager.instance.turnStateMachine.gameContext.Memory);
  901. }
  902. else
  903. {
  904. MaxMemoryCost = Mathf.Abs(-10 - GManager.instance.turnStateMachine.gameContext.Memory);
  905. }
  906. return MaxMemoryCost;
  907. }
  908. }
  909. #endregion
  910. #region コスト支払い後のメモリー予測値
  911. public int ExpectedMemory(int memoryCost)
  912. {
  913. int ExpectedMemory = GManager.instance.turnStateMachine.gameContext.Memory;
  914. if (PlayerID == 0)
  915. {
  916. ExpectedMemory += memoryCost;
  917. }
  918. else
  919. {
  920. ExpectedMemory -= memoryCost;
  921. }
  922. return ExpectedMemory;
  923. }
  924. #endregion
  925. #region デジタマを孵化できるか
  926. public bool CanHatch => DigitamaLibraryCards.Count >= 1 && GetBreedingAreaPermanents().Count == 0;
  927. #endregion
  928. #region デジモンを移動できるか
  929. public bool CanMove => GetBreedingAreaPermanents().Count(permanent => permanent.CanMove) >= 1 && fieldCardFrames.Count((frame) => frame.IsEmptyFrame()) >= 1;
  930. #endregion
  931. #region このターンにデジモンを進化させた回数
  932. public int DigivolveCount_ThisTurn { get; set; } = 0;
  933. #endregion
  934. #region 吸収進化でタップできるデジモンの条件(効果可否判定に使用)
  935. public bool CanTapWhenAbsorbEvolution_CheckAvailability(Permanent permanent, ICardEffect cardEffect)
  936. {
  937. if (permanent != null)
  938. {
  939. if (permanent.TopCard != null)
  940. {
  941. if (!permanent.IsSuspended && permanent.CanSuspend)
  942. {
  943. if (permanent.TopCard.Owner.GetBattleAreaDigimons().Contains(permanent))
  944. {
  945. #region 吸収進化でタップできるデジモンの条件を変更させる効果
  946. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  947. {
  948. foreach (Permanent permanent1 in player.GetFieldPermanents())
  949. {
  950. #region 場のパーマネントの効果
  951. foreach (ICardEffect cardEffect1 in permanent1.EffectList(EffectTiming.None))
  952. {
  953. if (cardEffect1 is ICanSuspendByDigisorptionEffect)
  954. {
  955. if (cardEffect1.CanUse(null))
  956. {
  957. if (((ICanSuspendByDigisorptionEffect)cardEffect1).isCheckAvailability())
  958. {
  959. if (((ICanSuspendByDigisorptionEffect)cardEffect1).canSuspendDigisorption(permanent, cardEffect))
  960. {
  961. return true;
  962. }
  963. }
  964. }
  965. }
  966. }
  967. #endregion
  968. }
  969. #region プレイヤーの効果
  970. foreach (ICardEffect cardEffect1 in player.EffectList(EffectTiming.None))
  971. {
  972. if (cardEffect1 is ICanSuspendByDigisorptionEffect)
  973. {
  974. if (cardEffect1.CanUse(null))
  975. {
  976. if (((ICanSuspendByDigisorptionEffect)cardEffect1).isCheckAvailability())
  977. {
  978. if (((ICanSuspendByDigisorptionEffect)cardEffect1).canSuspendDigisorption(permanent, cardEffect))
  979. {
  980. return true;
  981. }
  982. }
  983. }
  984. }
  985. }
  986. #endregion
  987. }
  988. #endregion
  989. if (permanent.TopCard.Owner == this)
  990. {
  991. return true;
  992. }
  993. }
  994. }
  995. }
  996. }
  997. return false;
  998. }
  999. #endregion
  1000. #region 吸収進化でタップできるデジモンの条件
  1001. public bool CanTapWhenAbsorbEvolution(Permanent permanent, ICardEffect cardEffect)
  1002. {
  1003. if (permanent != null)
  1004. {
  1005. if (permanent.TopCard != null)
  1006. {
  1007. if (!permanent.IsSuspended && permanent.CanSuspend)
  1008. {
  1009. if (permanent.TopCard.Owner.GetBattleAreaDigimons().Contains(permanent))
  1010. {
  1011. #region 吸収進化でタップできるデジモンの条件を変更させる効果
  1012. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  1013. {
  1014. foreach (Permanent permanent1 in player.GetFieldPermanents())
  1015. {
  1016. #region 場のパーマネントの効果
  1017. foreach (ICardEffect cardEffect1 in permanent1.EffectList(EffectTiming.None))
  1018. {
  1019. if (cardEffect1 is ICanSuspendByDigisorptionEffect)
  1020. {
  1021. if (cardEffect1.CanUse(null))
  1022. {
  1023. if (!((ICanSuspendByDigisorptionEffect)cardEffect1).isCheckAvailability())
  1024. {
  1025. if (((ICanSuspendByDigisorptionEffect)cardEffect1).canSuspendDigisorption(permanent, cardEffect))
  1026. {
  1027. return true;
  1028. }
  1029. else
  1030. {
  1031. return false;
  1032. }
  1033. }
  1034. }
  1035. }
  1036. }
  1037. #endregion
  1038. }
  1039. #region プレイヤーの効果
  1040. foreach (ICardEffect cardEffect1 in player.EffectList(EffectTiming.None))
  1041. {
  1042. if (cardEffect1 is ICanSuspendByDigisorptionEffect)
  1043. {
  1044. if (cardEffect1.CanUse(null))
  1045. {
  1046. if (!((ICanSuspendByDigisorptionEffect)cardEffect1).isCheckAvailability())
  1047. {
  1048. if (((ICanSuspendByDigisorptionEffect)cardEffect1).canSuspendDigisorption(permanent, cardEffect))
  1049. {
  1050. return true;
  1051. }
  1052. else
  1053. {
  1054. return false;
  1055. }
  1056. }
  1057. }
  1058. }
  1059. }
  1060. #endregion
  1061. }
  1062. #endregion
  1063. if (permanent.TopCard.Owner == this)
  1064. {
  1065. return true;
  1066. }
  1067. }
  1068. }
  1069. }
  1070. }
  1071. return false;
  1072. }
  1073. #endregion
  1074. #region コストを減らせるか
  1075. public bool CanReduceCost(List<Permanent> targetPermanents, CardSource cardSource)
  1076. {
  1077. #region コストを減らせなくさせる効果
  1078. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  1079. {
  1080. foreach (Permanent permanent in player.GetFieldPermanents())
  1081. {
  1082. #region 場のパーマネントの効果
  1083. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  1084. {
  1085. if (cardEffect is ICannotReduceCostEffect)
  1086. {
  1087. if (cardEffect.CanUse(null))
  1088. {
  1089. if (((ICannotReduceCostEffect)cardEffect).CannotReduceCost(this, targetPermanents, cardSource))
  1090. {
  1091. return false;
  1092. }
  1093. }
  1094. }
  1095. }
  1096. #endregion
  1097. }
  1098. #region プレイヤーの効果
  1099. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  1100. {
  1101. if (cardEffect is ICannotReduceCostEffect)
  1102. {
  1103. if (cardEffect.CanUse(null))
  1104. {
  1105. if (((ICannotReduceCostEffect)cardEffect).CannotReduceCost(this, targetPermanents, cardSource))
  1106. {
  1107. return false;
  1108. }
  1109. }
  1110. }
  1111. }
  1112. #endregion
  1113. }
  1114. #endregion
  1115. return true;
  1116. }
  1117. #endregion
  1118. #region DP消滅効果の上限
  1119. public int MaxDP_DeleteEffect(int maxDP, ICardEffect cardEffect)
  1120. {
  1121. int _maxDP = maxDP;
  1122. #region DP消滅効果の上限を変更する効果
  1123. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  1124. {
  1125. foreach (Permanent permanent in player.GetFieldPermanents())
  1126. {
  1127. #region 場のパーマネントの効果
  1128. foreach (ICardEffect cardEffect1 in permanent.EffectList(EffectTiming.None))
  1129. {
  1130. if (cardEffect1 is IChangeDPDeleteEffectMaxDPEffect)
  1131. {
  1132. if (cardEffect1.CanUse(null))
  1133. {
  1134. _maxDP = ((IChangeDPDeleteEffectMaxDPEffect)cardEffect1).GetMaxDP(_maxDP, cardEffect);
  1135. }
  1136. }
  1137. }
  1138. #endregion
  1139. }
  1140. #region プレイヤーの効果
  1141. foreach (ICardEffect cardEffect1 in player.EffectList(EffectTiming.None))
  1142. {
  1143. if (cardEffect1 is IChangeDPDeleteEffectMaxDPEffect)
  1144. {
  1145. if (cardEffect1.CanUse(null))
  1146. {
  1147. _maxDP = ((IChangeDPDeleteEffectMaxDPEffect)cardEffect1).GetMaxDP(_maxDP, cardEffect);
  1148. }
  1149. }
  1150. }
  1151. #endregion
  1152. }
  1153. #endregion
  1154. return _maxDP;
  1155. }
  1156. #endregion
  1157. #region 進化条件を無視できるか
  1158. public bool CanIgnoreDigivolutionRequirement(Permanent targetPermanent, CardSource cardSource)
  1159. {
  1160. #region 進化条件を無視できなくさせる効果
  1161. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  1162. {
  1163. foreach (Permanent permanent in player.GetFieldPermanents())
  1164. {
  1165. #region 場のパーマネントの効果
  1166. foreach (ICardEffect cardEffect1 in permanent.EffectList(EffectTiming.None))
  1167. {
  1168. if (cardEffect1 is ICannotIgnoreDigivolutionConditionEffect)
  1169. {
  1170. if (cardEffect1.CanUse(null))
  1171. {
  1172. if (((ICannotIgnoreDigivolutionConditionEffect)cardEffect1).cannotIgnoreDigivolutionCondition(this, targetPermanent, cardSource))
  1173. {
  1174. return false;
  1175. }
  1176. }
  1177. }
  1178. }
  1179. #endregion
  1180. }
  1181. #region Player effect
  1182. foreach (ICardEffect cardEffect1 in player.EffectList(EffectTiming.None))
  1183. {
  1184. if (cardEffect1 is ICannotIgnoreDigivolutionConditionEffect)
  1185. {
  1186. if (cardEffect1.CanUse(null))
  1187. {
  1188. if (((ICannotIgnoreDigivolutionConditionEffect)cardEffect1).cannotIgnoreDigivolutionCondition(this, targetPermanent, cardSource))
  1189. {
  1190. return false;
  1191. }
  1192. }
  1193. }
  1194. }
  1195. #endregion
  1196. }
  1197. #endregion
  1198. return true;
  1199. }
  1200. #endregion
  1201. #region セキュリティを増やせるか
  1202. public bool CanAddSecurity(ICardEffect cardEffect)
  1203. {
  1204. if (GManager.instance.turnStateMachine.gameContext.IsSecurityLooking)
  1205. {
  1206. return false;
  1207. }
  1208. #region セキュリティを増やせない効果
  1209. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  1210. {
  1211. foreach (Permanent permanent in player.GetFieldPermanents())
  1212. {
  1213. #region 場のパーマネントの効果
  1214. foreach (ICardEffect cardEffect1 in permanent.EffectList(EffectTiming.None))
  1215. {
  1216. if (cardEffect1 is ICannotAddSecurityEffect)
  1217. {
  1218. if (cardEffect1.CanUse(null))
  1219. {
  1220. if (((ICannotAddSecurityEffect)cardEffect1).cannotAddSecurity(this, cardEffect))
  1221. {
  1222. return false;
  1223. }
  1224. }
  1225. }
  1226. }
  1227. #endregion
  1228. }
  1229. #region プレイヤーの効果
  1230. foreach (ICardEffect cardEffect1 in player.EffectList(EffectTiming.None))
  1231. {
  1232. if (cardEffect1 is ICannotAddSecurityEffect)
  1233. {
  1234. if (cardEffect1.CanUse(null))
  1235. {
  1236. if (((ICannotAddSecurityEffect)cardEffect1).cannotAddSecurity(this, cardEffect))
  1237. {
  1238. return false;
  1239. }
  1240. }
  1241. }
  1242. }
  1243. #endregion
  1244. }
  1245. #endregion
  1246. return true;
  1247. }
  1248. #endregion
  1249. #region セキュリティを減らせるか
  1250. public bool CanReduceSecurity()
  1251. {
  1252. if (GManager.instance.turnStateMachine.gameContext.IsSecurityLooking)
  1253. {
  1254. return false;
  1255. }
  1256. return true;
  1257. }
  1258. #endregion
  1259. }
  1260. [Serializable]
  1261. public class ShowSupplyingEnergyIcon
  1262. {
  1263. public CardColor cardColor;
  1264. public Image SupplyingEnergyIcon;
  1265. public Text SupplyingEnergyText;
  1266. }
  1267. [Serializable]
  1268. public class FieldCardFrame
  1269. {
  1270. [Header("枠")]
  1271. public GameObject Frame;
  1272. [Header("選択状態表示枠")]
  1273. public Image Frame_Select;
  1274. [Header("枠ID")]
  1275. public int FrameID;
  1276. [Header("プレイヤー")]
  1277. public Player player;
  1278. public UnityAction<FieldCardFrame> OnClickAction { get; private set; }
  1279. public static bool isBattleAreaFrameID(int FrameID)
  1280. {
  1281. return 0 <= FrameID && FrameID <= GManager.instance.You.fieldCardFrames.Count - 2;
  1282. }
  1283. public bool IsBattleAreaFrame()
  1284. {
  1285. return isBattleAreaFrameID(this.FrameID);
  1286. }
  1287. public bool isBreedingAreaFrame()
  1288. {
  1289. return !IsBattleAreaFrame();
  1290. }
  1291. Permanent framePermanent = null;
  1292. public void SetFramePermanent(Permanent permanent)
  1293. {
  1294. framePermanent = permanent;
  1295. }
  1296. public Permanent GetFramePermanent()
  1297. {
  1298. /*
  1299. foreach (Permanent permanent in player.GetFieldPermanents())
  1300. {
  1301. if (permanent.PermanentFrame == this)
  1302. {
  1303. return permanent;
  1304. }
  1305. }
  1306. */
  1307. if (framePermanent != null)
  1308. {
  1309. return framePermanent;
  1310. }
  1311. return null;
  1312. }
  1313. public bool IsEmptyFrame()
  1314. {
  1315. return GetFramePermanent() == null;
  1316. }
  1317. public void AddClickTarget(UnityAction<FieldCardFrame> OnClickAction)
  1318. {
  1319. this.OnClickAction = OnClickAction;
  1320. if (Frame != null)
  1321. {
  1322. BoxCollider boxCollider = Frame.GetComponent<BoxCollider>();
  1323. if (boxCollider != null)
  1324. {
  1325. boxCollider.enabled = true;
  1326. }
  1327. }
  1328. }
  1329. public void RemoveClickTarget()
  1330. {
  1331. this.OnClickAction = null;
  1332. if (Frame != null)
  1333. {
  1334. BoxCollider boxCollider = Frame.GetComponent<BoxCollider>();
  1335. if (boxCollider != null)
  1336. {
  1337. boxCollider.enabled = false;
  1338. }
  1339. }
  1340. }
  1341. public void OffFrame_Select()
  1342. {
  1343. if (Frame_Select != null)
  1344. {
  1345. Frame_Select.gameObject.SetActive(false);
  1346. }
  1347. }
  1348. public void OnFrame_Select(Color color)
  1349. {
  1350. if (Frame_Select != null)
  1351. {
  1352. Frame_Select.gameObject.SetActive(true);
  1353. Frame_Select.color = color;
  1354. //Frame_Select.color = new Color(color.r, color.g, color.b, 0);
  1355. }
  1356. }
  1357. public Vector3 GetLocalCanvasPosition()
  1358. {
  1359. Vector3 vector = Frame.transform.localPosition + Frame.transform.parent.localPosition + Frame.transform.parent.parent.localPosition;
  1360. return Frame.transform.localPosition + Frame.transform.parent.localPosition + Frame.transform.parent.parent.localPosition;
  1361. }
  1362. public FieldCardFrame FacingFrame
  1363. {
  1364. get
  1365. {
  1366. if (this.IsBattleAreaFrame())
  1367. {
  1368. return player.fieldCardFrames[this.FrameID + 4];
  1369. }
  1370. else
  1371. {
  1372. return player.fieldCardFrames[this.FrameID - 4];
  1373. }
  1374. }
  1375. }
  1376. }