TurnStateMachine.cs 157 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376
  1. using Photon.Pun;
  2. using Photon.Pun.Demo.PunBasics;
  3. using Photon.Realtime;
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using UnityEngine;
  9. //using Hashtable = ExitGames.Client.Photon.Hashtable;
  10. using UnityEngine.EventSystems;
  11. using UnityEngine.UI;
  12. using static UnityEngine.ParticleSystem;
  13. using static UnityEngine.UIElements.UxmlAttributeDescription;
  14. public class TurnStateMachine : MonoBehaviourPunCallbacks
  15. {
  16. private static WaitForSeconds _waitForSeconds0_2 = new WaitForSeconds(0.2f);
  17. //Class to manage battle status
  18. public GameContext gameContext;
  19. //Wheteher Selecting some card
  20. public bool IsSelecting = false;
  21. //Effects in use
  22. public bool isExecuting;
  23. //Whether it is the first turn of the first player
  24. public bool isFirstPlayerFirstTurn { get; set; } = true;
  25. //Turn Count
  26. public int TurnCount { get; set; } = 0;
  27. public bool isSecurityCehck { get; set; } = false;
  28. #region Initialization
  29. public IEnumerator Init()
  30. {
  31. yield return StartCoroutine(GManager.instance.LoadingObject.StartLoading("Now Loading"));
  32. yield return StartCoroutine(ContinuousController.LoadCoroutine());
  33. ContinuousController.instance.PlaySE(GManager.instance.StartBattleSE);
  34. #region initialize parameter
  35. _canPlayTargetFrames = new bool[GManager.instance.You.fieldCardFrames.Count];
  36. _canDigivolves = new bool[GManager.instance.You.fieldCardFrames.Count];
  37. _canJogresses = new bool[GManager.instance.You.fieldCardFrames.Count];
  38. _canBursts = new bool[GManager.instance.You.fieldCardFrames.Count];
  39. _canAppFusions = new bool[GManager.instance.You.fieldCardFrames.Count];
  40. _payingCosts = new int[GManager.instance.You.fieldCardFrames.Count];
  41. #endregion
  42. #region AIモード
  43. if (GManager.instance.IsAI)
  44. {
  45. ContinuousController.instance.isRandomMatch = true;
  46. if (!PhotonNetwork.IsConnected)
  47. {
  48. yield return ContinuousController.instance.StartCoroutine(PhotonUtility.ConnectToMasterServerCoroutine());
  49. }
  50. yield return new WaitWhile(() => !PhotonNetwork.IsConnectedAndReady);
  51. if (!PhotonNetwork.InLobby)
  52. {
  53. PhotonNetwork.JoinLobby();
  54. }
  55. yield return new WaitWhile(() => !PhotonNetwork.InLobby);
  56. if (!PhotonNetwork.InRoom)
  57. {
  58. //Setting up the room to be created
  59. RoomOptions roomOptions = new RoomOptions
  60. {
  61. IsVisible = false, //Make the room invisible in the lobby.
  62. IsOpen = false, //Not Allow other players to enter the room
  63. PublishUserId = true,
  64. MaxPlayers = 1
  65. };
  66. string RoomName = StringUtils.GeneratePassword_AlpahabetNum(50);
  67. //Create Room
  68. PhotonNetwork.CreateRoom(RoomName, roomOptions, null);
  69. }
  70. yield return new WaitWhile(() => !PhotonNetwork.InRoom);
  71. }
  72. #endregion
  73. #region gameContextの設定
  74. gameContext = new GameContext(GManager.instance.You, GManager.instance.Opponent);
  75. #endregion
  76. #region プレイヤー名設定
  77. #region Extract master and non-master clients among Photon clients
  78. Photon.Realtime.Player MasterPlayer = null;
  79. Photon.Realtime.Player nonMasterPlayer = null;
  80. foreach (Photon.Realtime.Player player in PhotonNetwork.PlayerList)
  81. {
  82. if (player.ActorNumber != PhotonNetwork.CurrentRoom.MasterClientId)
  83. {
  84. nonMasterPlayer = player;
  85. }
  86. else
  87. {
  88. MasterPlayer = player;
  89. }
  90. }
  91. #endregion
  92. #region Save each player name
  93. SetPlayerName(0, PlayerName(MasterPlayer));
  94. SetPlayerName(1, PlayerName(nonMasterPlayer));
  95. #endregion
  96. #region Player name for that Photon client
  97. string PlayerName(Photon.Realtime.Player player)
  98. {
  99. #region 対人戦
  100. if (!GManager.instance.IsAI)
  101. {
  102. ExitGames.Client.Photon.Hashtable hashtable = player.CustomProperties;
  103. if (HasPlayerName(player))
  104. {
  105. if (hashtable.TryGetValue(ContinuousController.PlayerNameKey, out object value))
  106. {
  107. string playerName = (string)value;
  108. Debug.Log($"playername:{playerName}");
  109. if (!string.IsNullOrEmpty(playerName) && playerName != "Player")
  110. {
  111. return playerName;
  112. }
  113. if (player == PhotonNetwork.LocalPlayer)
  114. {
  115. return "You";
  116. }
  117. else
  118. {
  119. return "Opponent";
  120. }
  121. //return playerName;
  122. }
  123. }
  124. Debug.Log($"playername:None");
  125. return "";
  126. }
  127. #endregion
  128. #region AI mode
  129. else
  130. {
  131. #region Player Name
  132. if (player == MasterPlayer)
  133. {
  134. return ContinuousController.instance.PlayerName;
  135. }
  136. #endregion
  137. #region AI Player Name
  138. else
  139. {
  140. return "Bot";
  141. }
  142. #endregion
  143. }
  144. #endregion
  145. #region Determine if that Photon client has custom properties for player names
  146. bool HasPlayerName(Photon.Realtime.Player _player)
  147. {
  148. ExitGames.Client.Photon.Hashtable _hashtable = _player.CustomProperties;
  149. if (_hashtable.TryGetValue(ContinuousController.PlayerNameKey, out object value))
  150. {
  151. string playerName = (string)value;
  152. if (!string.IsNullOrEmpty(playerName))
  153. {
  154. if (playerName.Length <= ContinuousController.instance.PlayerNameMaxLength)
  155. {
  156. return true;
  157. }
  158. }
  159. }
  160. return false;
  161. }
  162. #endregion
  163. }
  164. #endregion
  165. #region Store player names in Player class and display UI
  166. void SetPlayerName(int _PlayerID, string _PlayerName)
  167. {
  168. Player player = gameContext.PlayerFromID(_PlayerID);
  169. player.PlayerName = _PlayerName;
  170. if (player.PlayerNameText != null)
  171. {
  172. player.PlayerNameText.transform.parent.gameObject.SetActive(true);
  173. player.PlayerNameText.gameObject.SetActive(true);
  174. if(player.isYou || GManager.instance.IsAI)
  175. player.PlayerNameText.text = player.PlayerName;
  176. }
  177. }
  178. #endregion
  179. #endregion
  180. #region 乱数列初期化
  181. if (PhotonNetwork.IsMasterClient)
  182. {
  183. ContinuousController.instance.GetComponent<PhotonView>().RPC("SetRandom", RpcTarget.All, RandomUtility.GetSecureRandom());
  184. }
  185. yield return new WaitWhile(() => !ContinuousController.instance.DoneSetRandom);
  186. ContinuousController.instance.DoneSetRandom = false;
  187. #endregion
  188. #region デッキカード生成
  189. yield return StartCoroutine(CardObjectController.CreatePlayerDecks(GManager.instance.CardPrefab, gameContext));
  190. yield return _waitForSeconds0_2;
  191. #endregion
  192. /*#region ログのクリック処理を追加
  193. foreach (CardSource cardSource in gameContext.ActiveCardList)
  194. {
  195. GManager.instance.playLog.AddOnClick_ShowCard(cardSource);
  196. }
  197. #endregion*/
  198. #region メモリーを初期化
  199. GManager.instance.memoryObject.Init();
  200. #endregion
  201. foreach (Player player in gameContext.Players)
  202. {
  203. yield return StartCoroutine(player.brainStormObject.Init());
  204. }
  205. #region Deciding whether to attack first or last
  206. gameContext.TurnPlayer = gameContext.PlayerFromID(GameRandom.Range(0, 2));
  207. #region get first player from room custom property
  208. int firstPlayerId = -1;
  209. ExitGames.Client.Photon.Hashtable roomHash = PhotonNetwork.CurrentRoom.CustomProperties;
  210. if (roomHash != null)
  211. {
  212. if (roomHash.TryGetValue(DataBase.FirstPlayerKey, out object value))
  213. {
  214. if (value is int)
  215. {
  216. firstPlayerId = (int)value;
  217. }
  218. }
  219. }
  220. if (firstPlayerId >= 0)
  221. {
  222. foreach (Photon.Realtime.Player player in PhotonNetwork.PlayerList)
  223. {
  224. if (player.ActorNumber == firstPlayerId)
  225. {
  226. int playerID = player.ActorNumber == PhotonNetwork.CurrentRoom.MasterClientId ? 0 : 1;
  227. gameContext.TurnPlayer = gameContext.PlayerFromID(playerID).Enemy;
  228. }
  229. }
  230. }
  231. #endregion
  232. #endregion
  233. yield return StartCoroutine(GManager.instance.LoadingObject.EndLoading());
  234. StartCoroutine(GameStateMachine());
  235. if (GManager.instance.bgms.Count >= 1)
  236. {
  237. GManager.instance.BattleBGM.StartPlayBGM(GManager.instance.bgms[UnityEngine.Random.Range(0, GManager.instance.bgms.Count)]);
  238. }
  239. }
  240. #endregion
  241. #region Manage turn progress
  242. public IEnumerator GameStateMachine()
  243. {
  244. yield return StartCoroutine(StartGame());
  245. while (true)
  246. {
  247. if (endGame)
  248. {
  249. yield break;
  250. }
  251. gameContext.SwitchTurnPlayer();
  252. yield return StartCoroutine(ActivePhase());
  253. yield return StartCoroutine(DrawPhase());
  254. if (endGame)
  255. {
  256. yield break;
  257. }
  258. yield return StartCoroutine(BreedingPhase());
  259. yield return StartCoroutine(MainPhase());
  260. if (endGame)
  261. {
  262. yield break;
  263. }
  264. yield return StartCoroutine(EndPhase());
  265. }
  266. }
  267. #endregion
  268. #region At the start of the game
  269. public bool DoneStartGame { get; set; } = false;
  270. bool _isRedraw = false;
  271. IEnumerator StartGame()
  272. {
  273. #if UNITY_EDITOR
  274. //gameContext.TurnPlayer = GManager.instance.Opponent;
  275. #endif
  276. #region 先攻・後攻の決定
  277. if (gameContext.NonTurnPlayer.isYou)
  278. {
  279. //GManager.instance.commandText.OpenCommandText("You are the FIRST player.");
  280. }
  281. else
  282. {
  283. //GManager.instance.commandText.OpenCommandText("You are the SECOND player.");
  284. }
  285. gameContext.FirstPlayer = gameContext.NonTurnPlayer;
  286. gameContext.NonTurnPlayer.FirstObject.SetActive(true);
  287. //yield return new WaitForSeconds(0.6f);
  288. GManager.instance.commandText.CloseCommandText();
  289. yield return new WaitWhile(() => GManager.instance.commandText.gameObject.activeSelf);
  290. #endregion
  291. foreach (Player player in gameContext.Players_ForNonTurnPlayer)
  292. {
  293. yield return StartCoroutine(new DrawClass(player, 5, null).Draw());
  294. }
  295. #region マリガン
  296. foreach (Player player in gameContext.Players_ForNonTurnPlayer)
  297. {
  298. _isRedraw = false;
  299. if (!player.isYou)
  300. {
  301. GManager.instance.commandText.OpenCommandText("The opponent is selecting mulligan.");
  302. }
  303. if (player.isYou)
  304. {
  305. if (GManager.instance.isAuto && GManager.instance.IsAI)
  306. {
  307. SetRedraw(player.PlayerID, RandomUtility.IsSucceedProbability(0.5f));
  308. }
  309. else
  310. {
  311. string message = "Will you mulligan your hand?";
  312. if (player == gameContext.NonTurnPlayer)
  313. {
  314. message += "\n(You are <color=#FF633E>FIRST</color>)";
  315. }
  316. else
  317. {
  318. message += "\n(You are <color=#FF633E>SECOND</color>)";
  319. }
  320. yield return StartCoroutine(GManager.instance.selectCardPanel.OpenSelectCardPanel(
  321. Message: message,
  322. NotSelectButtonMessage: "Keep Hand",
  323. EndSelectButtonMessage: "Mulligan",
  324. _OnClickNotSelectButtonAction: () => SetRedraw_RPC(player.PlayerID, false),
  325. _OnClickEndSelectButtonAction: () => SetRedraw_RPC(player.PlayerID, true),
  326. RootCardSources: player.HandCards,
  327. _CanTargetCondition: (cardSource) => false,
  328. _CanTargetCondition_ByPreSelecetedList: null,
  329. _CanEndSelectCondition: null,
  330. _MaxCount: 6,
  331. _CanEndNotMax: true,
  332. _CanNoSelect: () => true,
  333. CanLookReverseCard: true,
  334. skillInfos: null,
  335. root: SelectCardEffect.Root.None));
  336. void SetRedraw_RPC(int playerId, bool _isDraw)
  337. {
  338. photonView.RPC("SetRedraw", RpcTarget.All, playerId, _isDraw);
  339. }
  340. }
  341. }
  342. else
  343. {
  344. #region AI
  345. if (GManager.instance.IsAI)
  346. {
  347. bool doRedraw = false;
  348. if (player.HandCards.Count((cardSource) => cardSource.IsDigimon && cardSource.Level == 3) == 0)
  349. {
  350. doRedraw = true;
  351. }
  352. SetRedraw(player.PlayerID, doRedraw);
  353. }
  354. #endregion
  355. }
  356. yield return new WaitUntil(() => player.HasPlayerSelection());
  357. ValueSelection valueSeletion = player.DequeuePlayerSelection<ValueSelection>();
  358. _isRedraw = valueSeletion != null ? valueSeletion.ValueAsBool() : false;
  359. GManager.instance.selectCardPanel.CloseSelectCardPanel();
  360. GManager.instance.commandText.CloseCommandText();
  361. yield return new WaitWhile(() => GManager.instance.commandText.gameObject.activeSelf);
  362. if (_isRedraw)
  363. {
  364. #region マリガンを行う
  365. #region 手札のカードを削除
  366. List<HandCard> HandCardObjects = new List<HandCard>();
  367. foreach (HandCard handCard in player.HandCardObjects)
  368. {
  369. HandCardObjects.Add(handCard);
  370. }
  371. for (int i = 0; i < HandCardObjects.Count; i++)
  372. {
  373. Destroy(HandCardObjects[i].gameObject);
  374. }
  375. #endregion
  376. #region 手札のカードを山札の下に加える
  377. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(player.HandCards.Clone(),true));
  378. #region Log
  379. if (_isRedraw)
  380. PlayLog.OnAddLog?.Invoke($"\nMulligan Hand\n{player.PlayerName}\n");
  381. #endregion
  382. #endregion
  383. #region シャッフル
  384. yield return ContinuousController.instance.StartCoroutine(CardObjectController.Shuffle(player));
  385. #endregion
  386. #region 5枚引き直す
  387. yield return StartCoroutine(new DrawClass(player, 5, null).Draw());
  388. #endregion
  389. #endregion
  390. }
  391. }
  392. #endregion
  393. #region set up security
  394. foreach (Player player in gameContext.Players_ForNonTurnPlayer)
  395. {
  396. yield return StartCoroutine(new IAddSecurityFromLibrary(player, 5).AddSecurity());
  397. }
  398. #endregion
  399. DoneStartGame = true;
  400. }
  401. [PunRPC]
  402. public void SetStartPlayer(bool doChange)
  403. {
  404. if (doChange)
  405. {
  406. gameContext.TurnPlayer = gameContext.NonTurnPlayer;
  407. }
  408. }
  409. [PunRPC]
  410. void SetRedraw(int playerID, bool isRedraw)
  411. {
  412. Player selectionPlayer = GManager.instance.GetPlayerFromID(playerID);
  413. if (selectionPlayer == null)
  414. {
  415. return;
  416. }
  417. selectionPlayer.QueuePlayerSelection(new ValueSelection(isRedraw));
  418. }
  419. #endregion
  420. #region Active Phase
  421. IEnumerator ActivePhase()
  422. {
  423. gameContext.TurnPlayer.SetTurnStartTime();
  424. foreach (Permanent permanent in gameContext.TurnPlayer.GetFieldPermanents())
  425. {
  426. permanent.UntilOwnerTurnStartEffects = new List<Func<EffectTiming, ICardEffect>>();
  427. }
  428. ContinuousController.instance.PlaySE(GManager.instance.StartBattleSE);
  429. foreach (Player player in gameContext.Players_ForTurnPlayer)
  430. {
  431. player.FirstObject.SetActive(false);
  432. }
  433. #region ログ追加
  434. PlayLog.OnAddLog?.Invoke($"\n---------------------------------\nActive Phase:\n{gameContext.TurnPlayer.PlayerName}\n");
  435. #endregion
  436. TurnCount++;
  437. gameContext.TurnPlayer.TurnCount++;
  438. gameContext.TurnPhase = GameContext.phase.Active;
  439. Debug.Log($"{gameContext.TurnPlayer}:Start Turn({TurnCount}th Turn)");
  440. GManager.instance.showTurnPlayerObject.ShowTurnPlayer(gameContext.TurnPlayer);
  441. GManager.instance.nextPhaseButton.SwitchTurnSprite();
  442. yield return new WaitWhile(() => !GManager.instance.showTurnPlayerObject.isClose);
  443. // ターン開始時の効果
  444. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(null, EffectTiming.OnStartTurn));
  445. // 自動処理チェックタイミング
  446. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  447. //Handle attacks by effect caused in this phase
  448. while (GManager.instance.attackProcess.ActiveAttack())
  449. {
  450. yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.ProcessNextState());
  451. //自動処理チェックタイミング
  452. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  453. }
  454. //ターン終了チェック
  455. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.EndTurnCheck());
  456. if (gameContext.TurnPhase == GameContext.phase.End)
  457. {
  458. yield break;
  459. }
  460. #region Unsuspend
  461. #region Untap permanents in play
  462. List<Permanent> unsuspendPermanents = new List<Permanent>();
  463. //Add field Permanents to unsuspend list
  464. foreach (Permanent permanent in gameContext.PermanentsForTurnPlayer)
  465. {
  466. if (permanent.IsSuspended && permanent.CanUnsuspend)
  467. {
  468. if (permanent.TopCard.Owner == gameContext.TurnPlayer || permanent.HasReboot)
  469. {
  470. unsuspendPermanents.Add(permanent);
  471. }
  472. }
  473. }
  474. //Unsuspend raising area Permanents
  475. foreach (Permanent permanent in gameContext.TurnPlayer.GetBreedingAreaPermanents())
  476. {
  477. if (permanent.IsSuspended)
  478. {
  479. permanent.IsSuspended = false;
  480. if (permanent.ShowingPermanentCard != null)
  481. {
  482. permanent.ShowingPermanentCard.ShowPermanentData(true);
  483. }
  484. /*if (permanent.TopCard.Owner == gameContext.TurnPlayer)
  485. {
  486. unsuspendPermanents.Add(permanent);
  487. }*/
  488. }
  489. }
  490. yield return ContinuousController.instance.StartCoroutine(new IUnsuspendPermanents(unsuspendPermanents, null).Unsuspend());
  491. #endregion
  492. #endregion
  493. //自動処理チェックタイミング
  494. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  495. //Handle attacks by effect caused in this phase
  496. while (GManager.instance.attackProcess.ActiveAttack())
  497. {
  498. yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.ProcessNextState());
  499. //自動処理チェックタイミング
  500. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  501. }
  502. //ターン終了チェック
  503. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.EndTurnCheck());
  504. #region アクティブフェイズ終了時までの効果をリセット
  505. gameContext.TurnPlayer.UntilOwnerActivePhaseEffects = new List<Func<EffectTiming, ICardEffect>>();
  506. foreach(Permanent permanent in gameContext.TurnPlayer.GetBattleAreaDigimons())
  507. permanent.UntilNextUntapEffects = new List<Func<EffectTiming, ICardEffect>>();
  508. #endregion
  509. }
  510. #endregion
  511. #region Draw Phase
  512. IEnumerator DrawPhase()
  513. {
  514. //ターン終了チェック
  515. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.EndTurnCheck());
  516. if (gameContext.TurnPhase == GameContext.phase.End)
  517. {
  518. yield break;
  519. }
  520. #region ログ追加
  521. PlayLog.OnAddLog?.Invoke($"\nDraw Phase:\n{gameContext.TurnPlayer.PlayerName}\n");
  522. #endregion
  523. gameContext.TurnPhase = GameContext.phase.Draw;
  524. #region ドロー
  525. if (TurnCount != 1)
  526. {
  527. #region 引けなかったら負け
  528. if (gameContext.TurnPlayer.LibraryCards.Count == 0)
  529. {
  530. EndGame(gameContext.NonTurnPlayer, false);
  531. yield break;
  532. }
  533. #endregion
  534. yield return StartCoroutine(new DrawClass(gameContext.TurnPlayer, 1, null).Draw());
  535. }
  536. #endregion
  537. //自動処理チェックタイミング
  538. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  539. //Handle attacks by effect caused in this phase
  540. while (GManager.instance.attackProcess.ActiveAttack())
  541. {
  542. yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.ProcessNextState());
  543. //自動処理チェックタイミング
  544. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  545. }
  546. //ターン終了チェック
  547. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.EndTurnCheck());
  548. }
  549. #endregion
  550. #region Breeding Phase
  551. IEnumerator BreedingPhase()
  552. {
  553. //ターン終了チェック
  554. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.EndTurnCheck());
  555. if (gameContext.TurnPhase == GameContext.phase.End)
  556. {
  557. yield break;
  558. }
  559. #region ログ追加
  560. PlayLog.OnAddLog?.Invoke($"\nBreeding Phase:\n{gameContext.TurnPlayer.PlayerName}\n");
  561. #endregion
  562. gameContext.TurnPhase = GameContext.phase.Breeding;
  563. IsSelecting = false;
  564. if (gameContext.TurnPlayer.CanHatch || gameContext.TurnPlayer.CanMove)
  565. {
  566. GManager.instance.showPhaseNotificationObject.ShowPhase(GameContext.phase.Breeding);
  567. yield return new WaitWhile(() => !GManager.instance.showPhaseNotificationObject.isClose);
  568. if (gameContext.TurnPlayer.isYou)
  569. {
  570. #region If hatching is possible
  571. if (gameContext.TurnPlayer.CanHatch || !gameContext.TurnPlayer.CanMove)
  572. {
  573. GManager.instance.hideCannotSelectObject.SetUpHideCannotSelectObject(new List<FieldPermanentCard>() { null }, true);
  574. //GManager.instance.commandText.OpenCommandText("BreedingPhase : Will you hatch Digiegg?");
  575. if (ContinuousController.instance.autoHatch)
  576. {
  577. SendShouldHatch(true);
  578. }
  579. else
  580. {
  581. gameContext.TurnPlayer.SetUpHatchObject(() => SendShouldHatch(true));
  582. }
  583. }
  584. #endregion
  585. #region If you can move
  586. else if (!gameContext.TurnPlayer.CanHatch || gameContext.TurnPlayer.CanMove)
  587. {
  588. //GManager.instance.commandText.OpenCommandText("BreedingPhase : Will you move your Digimon to Battle Area?");
  589. FieldPermanentCard fieldPermanentCard = gameContext.TurnPlayer.GetBreedingAreaPermanents()[0].ShowingPermanentCard;
  590. if (fieldPermanentCard != null)
  591. {
  592. GManager.instance.hideCannotSelectObject.SetUpHideCannotSelectObject(new List<FieldPermanentCard>() { fieldPermanentCard }, false);
  593. fieldPermanentCard.AddClickTarget((fieldPermanentCard1) => SendShouldHatch(true));
  594. fieldPermanentCard.Outline_Select.gameObject.SetActive(true);
  595. fieldPermanentCard.SetOrangeOutline();
  596. }
  597. }
  598. #endregion
  599. if (gameContext.TurnPlayer.isYou && GManager.instance.isAuto && GManager.instance.IsAI)
  600. {
  601. gameContext.TurnPhase = GameContext.phase.Main;
  602. }
  603. }
  604. else
  605. {
  606. //GManager.instance.commandText.OpenCommandText("BreedingPhase : The opponent is selecting the action.");
  607. #region AI
  608. if (GManager.instance.IsAI)
  609. {
  610. bool doHatch = RandomUtility.IsSucceedProbability(0.85f);
  611. if (gameContext.TurnPlayer.CanHatch)
  612. {
  613. doHatch = true;
  614. }
  615. SetBreedingPhase(gameContext.TurnPlayer.PlayerID, doHatch);
  616. }
  617. #endregion
  618. }
  619. yield return new WaitWhile(() => !gameContext.TurnPlayer.HasPlayerSelection() && gameContext.TurnPhase == GameContext.phase.Breeding);
  620. ValueSelection breedSelection = gameContext.TurnPlayer.DequeuePlayerSelection<ValueSelection>();
  621. doAction_BreedingPhase = breedSelection != null ? breedSelection.ValueAsBool() : false;
  622. GManager.instance.hideCannotSelectObject.Close();
  623. gameContext.TurnPlayer.OffHatchObject();
  624. OffFieldCardTarget(gameContext.TurnPlayer);
  625. IsSelecting = true;
  626. if (gameContext.TurnPhase == GameContext.phase.Breeding)
  627. {
  628. if (doAction_BreedingPhase)
  629. {
  630. //hatching
  631. if (gameContext.TurnPlayer.CanHatch || !gameContext.TurnPlayer.CanMove)
  632. {
  633. yield return ContinuousController.instance.StartCoroutine(new HatchDigiEggClass(player: gameContext.TurnPlayer, hashtable: null).Hatch());
  634. }
  635. //move
  636. else if (!gameContext.TurnPlayer.CanHatch || gameContext.TurnPlayer.CanMove)
  637. {
  638. yield return ContinuousController.instance.StartCoroutine(CardObjectController.MovePermanent(gameContext.TurnPlayer.GetBreedingAreaPermanents()[0].PermanentFrame));
  639. }
  640. }
  641. }
  642. gameContext.TurnPhase = GameContext.phase.Breeding;
  643. }
  644. //自動処理チェックタイミング
  645. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  646. //Handle attacks by effect caused in this phase
  647. while (GManager.instance.attackProcess.ActiveAttack())
  648. {
  649. yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.ProcessNextState());
  650. //自動処理チェックタイミング
  651. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  652. }
  653. //ターン終了チェック
  654. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.EndTurnCheck());
  655. if (gameContext.TurnPhase == GameContext.phase.End)
  656. {
  657. yield break;
  658. }
  659. }
  660. public void SendShouldHatch(bool shouldHatch)
  661. {
  662. gameContext.TurnPlayer.OffHatchObject();
  663. photonView.RPC("SetBreedingPhase", RpcTarget.All, gameContext.TurnPlayer.PlayerID, shouldHatch);
  664. }
  665. bool doAction_BreedingPhase = false;
  666. [PunRPC]
  667. public void SetBreedingPhase(int playerID, bool doBreeding)
  668. {
  669. Player selectionPlayer = GManager.instance.GetPlayerFromID(playerID);
  670. if (selectionPlayer == null)
  671. {
  672. return;
  673. }
  674. selectionPlayer.QueuePlayerSelection(new ValueSelection(doBreeding));
  675. }
  676. #endregion
  677. #region main phase
  678. CardSource PlayCard { get; set; } = null;
  679. int TargetFrameID { get; set; } = 0;
  680. int[] JogressEvoRootsFrameIDs { get; set; } = new int[0];
  681. int BurstTamerFrameID { get; set; } = 0;
  682. int[] AppFusionFrameIDs { get; set; } = new int[0];
  683. ICardEffect UseCardEffect { get; set; } = null;
  684. Permanent AttackingPermanent { get; set; } = null;
  685. Permanent DefendingPermanent { get; set; } = null;
  686. float _timer = 0f;
  687. bool _canPlayEmptyFrame = true;
  688. bool[] _canPlayTargetFrames = new bool[GManager.instance.You.fieldCardFrames.Count];
  689. bool[] _canDigivolves = new bool[GManager.instance.You.fieldCardFrames.Count];
  690. bool[] _canJogresses = new bool[GManager.instance.You.fieldCardFrames.Count];
  691. bool[] _canBursts = new bool[GManager.instance.You.fieldCardFrames.Count];
  692. bool[] _canAppFusions = new bool[GManager.instance.You.fieldCardFrames.Count];
  693. int[] _payingCosts = new int[GManager.instance.You.fieldCardFrames.Count];
  694. IEnumerator MainPhase()
  695. {
  696. //ターン終了チェック
  697. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.EndTurnCheck());
  698. if (gameContext.TurnPhase == GameContext.phase.End)
  699. {
  700. goto EndMainPhase;
  701. }
  702. #region Add log
  703. PlayLog.OnAddLog?.Invoke($"\nMain Phase:\n{gameContext.TurnPlayer.PlayerName}\n");
  704. #endregion
  705. #region Reset the selection status of cards in your hand and cards on the field.
  706. OffHandCardTarget(gameContext.TurnPlayer);
  707. OffFieldCardTarget(gameContext.TurnPlayer);
  708. #endregion
  709. gameContext.TurnPhase = GameContext.phase.Main;
  710. Debug.Log($"{gameContext.TurnPlayer}:Main Phase");
  711. GManager.instance.showPhaseNotificationObject.ShowPhase(GameContext.phase.Main);
  712. yield return new WaitWhile(() => !GManager.instance.showPhaseNotificationObject.isClose);
  713. // Effects at the start of main phase
  714. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(null, EffectTiming.OnStartMainPhase));
  715. // Automatic processing check timing
  716. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  717. bool CanSelect()
  718. {
  719. //You can play cards from your hand.
  720. if (gameContext.TurnPlayer.HandCards.Some((_card) => _card.CanPlayFromHandDuringMainPhase))
  721. return true;
  722. //There is a permanent in play that can use the effect.
  723. if (gameContext.TurnPlayer.GetFieldPermanents().Count((permanent) => permanent.CanDeclareSkill()) > 0)
  724. return true;
  725. //There is a permanent in play that can attack.
  726. if (gameContext.TurnPlayer.GetFieldPermanents().Count((permanent) => permanent.CanAttack(null)) > 0)
  727. return true;
  728. //I have a card in my hand that can use an effect.
  729. if (gameContext.TurnPlayer.HandCards.Count((_card) => _card.CanDeclareSkill) > 0)
  730. return true;
  731. //I have a card in my trash that can use an effect.
  732. if (gameContext.TurnPlayer.TrashCards.Count(_card => _card.CanDeclareSkill) > 0)
  733. return true;
  734. return false;
  735. }
  736. #region Repeat until turn player selects
  737. while (!endGame)
  738. {
  739. //自動処理チェックタイミング
  740. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  741. //Handle attack steps
  742. while (GManager.instance.attackProcess.ActiveAttack())
  743. {
  744. Debug.Log($"Active Attack, {Enum.GetName(typeof(AttackProcess.AttackState),GManager.instance.attackProcess.State)} Step");
  745. yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.ProcessNextState());
  746. //自動処理チェックタイミング
  747. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  748. }
  749. //ターン終了チェック
  750. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.EndTurnCheck());
  751. #region パラメータリセット
  752. ResetMainPhaseParameter();
  753. #endregion
  754. if (gameContext.TurnPhase == GameContext.phase.Main)
  755. {
  756. if (!CanSelect())
  757. {
  758. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.EndTurnProcess());
  759. }
  760. }
  761. if (gameContext.TurnPhase != GameContext.phase.Main)
  762. {
  763. goto EndMainPhase;
  764. }
  765. StartCoroutine(SetMainPhase());
  766. #region Wait until selection is complete
  767. while (PlayCard == null && UseCardEffect == null && AttackingPermanent == null)
  768. {
  769. yield return null;
  770. if (endGame)
  771. {
  772. yield break;
  773. }
  774. if (!GManager.instance.IsAI || gameContext.TurnPlayer.isYou)
  775. {
  776. if (gameContext.TurnPlayer.HasMainPhaseAction())
  777. {
  778. gameContext.TurnPlayer.DequeueMainPhaseAction().Execute(this);
  779. }
  780. }
  781. #region AIモード
  782. if (GManager.instance.IsAI && !gameContext.TurnPlayer.isYou)
  783. {
  784. if (RandomUtility.IsSucceedProbability(0.99f))
  785. {
  786. if (gameContext.TurnPlayer.GetFieldPermanents().Count((permanent) => permanent.CanAttack(null)) > 0)
  787. {
  788. #region アタック
  789. List<Permanent> CanAttackPermenents = new List<Permanent>();
  790. foreach (Permanent permanent in gameContext.TurnPlayer.GetFieldPermanents())
  791. {
  792. if (permanent.CanAttack(null))
  793. {
  794. CanAttackPermenents.Add(permanent);
  795. }
  796. }
  797. if (CanAttackPermenents.Count >= 1)
  798. {
  799. AttackingPermanent = CanAttackPermenents[UnityEngine.Random.Range(0, CanAttackPermenents.Count)];
  800. bool isSecurityAttack = true;
  801. List<Permanent> DefendingPermanentCandidates = new List<Permanent>();
  802. foreach (Permanent permanent in gameContext.NonTurnPlayer.GetFieldPermanents())
  803. {
  804. if (AttackingPermanent.CanAttackTargetDigimon(permanent, null) && AttackingPermanent.DP >= permanent.DP)
  805. {
  806. DefendingPermanentCandidates.Add(permanent);
  807. }
  808. }
  809. if (DefendingPermanentCandidates.Count >= 1)
  810. {
  811. if (RandomUtility.IsSucceedProbability(0.5f))
  812. {
  813. isSecurityAttack = false;
  814. }
  815. }
  816. if (gameContext.NonTurnPlayer.SecurityCards.Count <= 1)
  817. {
  818. isSecurityAttack = true;
  819. }
  820. if (!isSecurityAttack)
  821. {
  822. if (DefendingPermanentCandidates.Count >= 1)
  823. {
  824. DefendingPermanent = DefendingPermanentCandidates[UnityEngine.Random.Range(0, DefendingPermanentCandidates.Count)];
  825. }
  826. else
  827. {
  828. AttackingPermanent = null;
  829. }
  830. }
  831. else
  832. {
  833. if (!AttackingPermanent.CanAttackTargetDigimon(null, null))
  834. {
  835. AttackingPermanent = null;
  836. }
  837. }
  838. }
  839. #endregion
  840. }
  841. #if UNITY_EDITOR
  842. AttackingPermanent = null;
  843. #endif
  844. if (AttackingPermanent == null)
  845. {
  846. if (gameContext.TurnPlayer.HandCards.Some((cardSource) => cardSource.CanPlayFromHandDuringMainPhase))
  847. {
  848. #region カードをプレイ
  849. List<CardSource> CanPlayCards = new List<CardSource>();
  850. foreach (CardSource cardSource in gameContext.TurnPlayer.HandCards)
  851. {
  852. if (cardSource.CanPlayFromHandDuringMainPhase)
  853. {
  854. CanPlayCards.Add(cardSource);
  855. }
  856. }
  857. CanPlayCards = CanPlayCards
  858. .OrderBy((value) => Array.IndexOf(DataBase.cardKinds, value.CardKinds))
  859. .ThenBy((value) => Array.IndexOf(new bool[] { true, false }, value.Owner.fieldCardFrames.Count((frame) => value.CanPlayCardTargetFrame(frame, true, null) && !frame.IsEmptyFrame()) >= 1))
  860. .ToList();
  861. if (CanPlayCards.Count > 0)
  862. {
  863. foreach (CardSource cardSource in CanPlayCards)
  864. {
  865. if (RandomUtility.IsSucceedProbability(0.99f))
  866. {
  867. PlayCard = cardSource;
  868. if (PlayCard.IsPermanent)
  869. {
  870. List<int> frameIDCandidates = new List<int>();
  871. for (int i = 0; i < gameContext.TurnPlayer.fieldCardFrames.Count; i++)
  872. {
  873. if (PlayCard.CanPlayCardTargetFrame(gameContext.TurnPlayer.fieldCardFrames[i], true, null))
  874. {
  875. int k = i;
  876. int count = 4;
  877. if (gameContext.TurnPlayer.fieldCardFrames[k].IsEmptyFrame())
  878. {
  879. if (frameIDCandidates.Count((id) => gameContext.TurnPlayer.fieldCardFrames[id].IsEmptyFrame()) >= 1)
  880. {
  881. continue;
  882. }
  883. count = 1;
  884. }
  885. for (int j = 0; j < count; j++)
  886. {
  887. frameIDCandidates.Add(k);
  888. }
  889. }
  890. }
  891. if (frameIDCandidates.Count >= 1)
  892. {
  893. TargetFrameID = frameIDCandidates[UnityEngine.Random.Range(0, frameIDCandidates.Count)];
  894. if (gameContext.TurnPlayer.fieldCardFrames[TargetFrameID].IsEmptyFrame())
  895. {
  896. TargetFrameID = PlayCard.PreferredFrame().FrameID;
  897. }
  898. break;
  899. }
  900. }
  901. else
  902. {
  903. break;
  904. }
  905. }
  906. }
  907. }
  908. #endregion
  909. }
  910. }
  911. }
  912. if (PlayCard == null && UseCardEffect == null && UseCardEffect == null && AttackingPermanent == null)
  913. {
  914. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.EndTurnProcess());
  915. }
  916. }
  917. #endregion
  918. else
  919. {
  920. if (gameContext.TurnPlayer.isYou && GManager.instance.isAuto && GManager.instance.IsAI)
  921. {
  922. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.EndTurnProcess());
  923. }
  924. }
  925. //EndTurnProcess
  926. if (gameContext.TurnPhase != GameContext.phase.Main)
  927. {
  928. goto EndMainPhase;
  929. }
  930. }
  931. ResetUI();
  932. #endregion
  933. #region Use activation effect
  934. if (UseCardEffect != null)
  935. {
  936. if (UseCardEffect is ActivateICardEffect)
  937. {
  938. if (UseCardEffect.CanUse(null))
  939. {
  940. UseCardEffect.SetIsDeclarative(true);
  941. //Count up the number of uses
  942. if (UseCardEffect.MaxCountPerTurn < 100)
  943. {
  944. UseCardEffect.EffectSourceCard.cEntity_EffectController.RegisterUseEffectThisTurn(UseCardEffect);
  945. }
  946. // yield return StartCoroutine(((ActivateICardEffect)UseCardEffect).Activate_Optional_Effect_Execute(null));
  947. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ActivateEffectProcess(
  948. UseCardEffect,
  949. null));
  950. }
  951. }
  952. }
  953. #endregion
  954. #region play cards
  955. else if (PlayCard != null)
  956. {
  957. yield return StartCoroutine(GManager.instance.GetComponent<Effects>().DeleteHandCardEffectCoroutine(PlayCard));
  958. yield return StartCoroutine(GManager.instance.GetComponent<Effects>().ShowUseHandCardEffect_PlayCard(PlayCard));
  959. Permanent targetPermanent = null;
  960. if (0 <= TargetFrameID && TargetFrameID <= gameContext.TurnPlayer.fieldCardFrames.Count - 1)
  961. {
  962. targetPermanent = gameContext.TurnPlayer.fieldCardFrames[TargetFrameID].GetFramePermanent();
  963. }
  964. //ログ追加
  965. PlayLog.OnAddLog?.Invoke($"\nPlay Card:\n{PlayCard.BaseENGCardNameFromEntity}({PlayCard.CardID})\n");
  966. PlayCardClass playCard = new PlayCardClass(
  967. cardSources: new List<CardSource>() { PlayCard },
  968. hashtable: null,
  969. payCost: true,
  970. targetPermanent: targetPermanent,
  971. isTapped: false,
  972. root: SelectCardEffect.Root.Hand,
  973. activateETB: true);
  974. if (JogressEvoRootsFrameIDs != null)
  975. {
  976. if (JogressEvoRootsFrameIDs.Length == 2)
  977. {
  978. playCard.SetJogress(JogressEvoRootsFrameIDs);
  979. }
  980. }
  981. if (0 <= BurstTamerFrameID && BurstTamerFrameID <= gameContext.TurnPlayer.fieldCardFrames.Count - 1)
  982. {
  983. playCard.SetBurst(BurstTamerFrameID, PlayCard);
  984. }
  985. if (AppFusionFrameIDs != null && AppFusionFrameIDs.Length == 2)
  986. {
  987. playCard.SetAppFusion(AppFusionFrameIDs);
  988. }
  989. yield return StartCoroutine(playCard.PlayCard());
  990. }
  991. #endregion
  992. #region attack
  993. else if (AttackingPermanent != null)
  994. {
  995. yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.Attack(AttackingPermanent, DefendingPermanent, null));
  996. }
  997. #endregion
  998. }
  999. #endregion
  1000. EndMainPhase:;
  1001. #region Main phase ends
  1002. GManager.instance.selectCommandPanel.CloseSelectCommandPanel();
  1003. GManager.instance.commandText.CloseCommandText();
  1004. _timer = 0f;
  1005. while (true)
  1006. {
  1007. yield return null;
  1008. _timer += Time.deltaTime;
  1009. if (!GManager.instance.commandText.gameObject.activeSelf)
  1010. {
  1011. break;
  1012. }
  1013. if (_timer >= 0.6f)
  1014. {
  1015. GManager.instance.commandText.gameObject.SetActive(false);
  1016. }
  1017. }
  1018. yield return new WaitWhile(() => GManager.instance.commandText.gameObject.activeSelf);
  1019. GManager.instance.OffTargetArrow();
  1020. ResetMainPhaseParameter();
  1021. #endregion
  1022. //Automatic processing check timing
  1023. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  1024. //ターン終了
  1025. #region Parameter reset
  1026. void ResetMainPhaseParameter()
  1027. {
  1028. GManager.instance.OffTargetArrow();
  1029. GManager.instance.memoryObject.OffMemoryPredictionLine();
  1030. #region Reset the display of cards in hand, cards on the field, and frames
  1031. foreach (Player player in gameContext.Players)
  1032. {
  1033. foreach (FieldCardFrame fieldCardFrame in player.fieldCardFrames)
  1034. {
  1035. fieldCardFrame.OffFrame_Select();
  1036. }
  1037. player.playMatCardFrame.OffFrame_Select();
  1038. foreach (FieldPermanentCard fieldCharaCard in player.FieldPermanentObjects)
  1039. {
  1040. fieldCharaCard.RemoveSelectEffect();
  1041. fieldCharaCard.RemoveClickTarget();
  1042. fieldCharaCard.RemoveDragTarget();
  1043. fieldCharaCard.CloseCommandPanel();
  1044. }
  1045. foreach (HandCard handCard in player.HandCardObjects)
  1046. {
  1047. handCard.RemoveSelectEffect();
  1048. handCard.RemoveClickTarget();
  1049. handCard.RemoveDragTarget();
  1050. }
  1051. player.securityObject.securityBreakGlass.gameObject.SetActive(false);
  1052. player.securityObject.OffShowSecurityAttackObject();
  1053. }
  1054. #endregion
  1055. #region Reset cards in hand and field
  1056. OffHandCardTarget(gameContext.TurnPlayer);
  1057. OffFieldCardTarget(gameContext.TurnPlayer);
  1058. foreach (HandCard handCard in gameContext.TurnPlayer.HandCardObjects)
  1059. {
  1060. handCard.GetComponent<Draggable_HandCard>().CanPointerEnterExitAction = true;
  1061. }
  1062. #endregion
  1063. IsSelecting = false;
  1064. PlayCard = null;
  1065. TargetFrameID = -1;
  1066. JogressEvoRootsFrameIDs = new int[0];
  1067. BurstTamerFrameID = -1;
  1068. AppFusionFrameIDs = new int[0];
  1069. UseCardEffect = null;
  1070. AttackingPermanent = null;
  1071. DefendingPermanent = null;
  1072. CardEffectCommons.ClearEffectLocations();
  1073. }
  1074. #endregion
  1075. }
  1076. #region Added main phase operations
  1077. public IEnumerator SetMainPhase()
  1078. {
  1079. if (gameContext.TurnPhase != GameContext.phase.Main)
  1080. {
  1081. yield break;
  1082. }
  1083. IsSelecting = false;
  1084. #region reset
  1085. OffFieldCardTarget(gameContext.TurnPlayer);
  1086. OffHandCardTarget(gameContext.TurnPlayer);
  1087. #region rearrange cards in hand
  1088. GManager.instance.You.HandTransform.GetComponent<GridLayoutGroup>().enabled = false;
  1089. foreach (HandCard handCard in GManager.instance.You.HandCards.Map(cardSource => cardSource.ShowingHandCard).Filter(handCard => handCard != null)
  1090. .Clone())
  1091. {
  1092. if (handCard != null)
  1093. {
  1094. handCard.transform.SetParent(GManager.instance.You.HandTransform);
  1095. handCard.GetComponent<Draggable_HandCard>().CanPointerEnterExitAction = true;
  1096. }
  1097. }
  1098. GManager.instance.You.HandTransform.GetComponent<GridLayoutGroup>().enabled = true;
  1099. #endregion
  1100. foreach (Player player in gameContext.Players)
  1101. {
  1102. #region Reset permanents in play
  1103. foreach (FieldPermanentCard fieldPermanentCard in player.FieldPermanentObjects)
  1104. {
  1105. fieldPermanentCard.RemoveSelectEffect();
  1106. fieldPermanentCard.RemoveDragTarget();
  1107. fieldPermanentCard.RemoveClickTarget();
  1108. fieldPermanentCard.fieldUnitCommandPanel.CloseCommandPanel();
  1109. }
  1110. #endregion
  1111. #region Reset cards in hand
  1112. foreach (HandCard handCard in player.HandCardObjects)
  1113. {
  1114. handCard.RemoveSelectEffect();
  1115. handCard.RemoveDragTarget();
  1116. handCard.RemoveClickTarget();
  1117. }
  1118. #endregion
  1119. player.securityObject.RemoveClickTarget();
  1120. player.securityObject.securityBreakGlass.gameObject.SetActive(false);
  1121. player.securityObject.OffShowSecurityAttackObject();
  1122. }
  1123. GManager.instance.selectCommandPanel.CloseSelectCommandPanel();
  1124. GManager.instance.BackButton.CloseSelectCommandButton();
  1125. GManager.instance.You.playMatCardFrame.Frame.transform.parent.gameObject.SetActive(false);
  1126. GManager.instance.memoryObject.OffMemoryPredictionLine();
  1127. GManager.instance.commandText.CloseCommandText();
  1128. yield return new WaitWhile(() => GManager.instance.commandText.gameObject.activeSelf);
  1129. #endregion
  1130. #region Click/drag operation
  1131. if (gameContext.TurnPlayer.isYou)
  1132. {
  1133. #region permanent of the place
  1134. foreach (FieldPermanentCard fieldPermanentCard in gameContext.TurnPlayer.FieldPermanentObjects)
  1135. {
  1136. if (fieldPermanentCard.gameObject.activeSelf && fieldPermanentCard.ThisPermanent.CanDeclareSkill() || fieldPermanentCard.ThisPermanent.CanAttack(null))
  1137. {
  1138. fieldPermanentCard.OnSelectEffect(1.1f);
  1139. #region Add click operation
  1140. fieldPermanentCard.AddClickTarget((_fieldUnitCard) => StartCoroutine(OnClick_Select()));
  1141. IEnumerator OnClick_Select()
  1142. {
  1143. IsSelecting = true;
  1144. #region Reset cards in other places
  1145. foreach (FieldPermanentCard _fieldPermanentCard in gameContext.TurnPlayer.FieldPermanentObjects)
  1146. {
  1147. if (_fieldPermanentCard != fieldPermanentCard)
  1148. {
  1149. _fieldPermanentCard.RemoveSelectEffect();
  1150. }
  1151. }
  1152. foreach (Player player in gameContext.Players)
  1153. {
  1154. OffFieldCardTarget(player);
  1155. }
  1156. #endregion
  1157. #region Reset cards in hand
  1158. foreach (HandCard handCard in gameContext.TurnPlayer.HandCardObjects)
  1159. {
  1160. handCard.RemoveSelectEffect();
  1161. handCard.RemoveClickTarget();
  1162. handCard.RemoveDragTarget();
  1163. }
  1164. #endregion
  1165. List<CardCommand> FieldUnitCommands = new List<CardCommand>();
  1166. #region activated effect
  1167. if (fieldPermanentCard.ThisPermanent.CanDeclareSkill())
  1168. {
  1169. List<ICardEffect> cardEffects = new List<ICardEffect>();
  1170. List<ICardEffect> cardEffects1 = new List<ICardEffect>();
  1171. foreach (ICardEffect cardEffect in fieldPermanentCard.ThisPermanent.EffectList(EffectTiming.OnDeclaration))
  1172. {
  1173. cardEffects1.Add(cardEffect);
  1174. cardEffects.Add(cardEffect);
  1175. }
  1176. cardEffects.Reverse();
  1177. foreach (ICardEffect cardEffect in cardEffects)
  1178. {
  1179. if (cardEffect is ActivateICardEffect)
  1180. {
  1181. CardCommand SkillCommand = new CardCommand(cardEffect.EffectName, OnClick_SetUseSkillPermanent_RPC, cardEffect.CanUse(null), DataBase.CommandColor_Skill);
  1182. FieldUnitCommands.Add(SkillCommand);
  1183. void OnClick_SetUseSkillPermanent_RPC()
  1184. {
  1185. #region Reset cards on the field
  1186. foreach (Player player in gameContext.Players)
  1187. {
  1188. foreach (FieldPermanentCard _fieldUnitCard in player.FieldPermanentObjects)
  1189. {
  1190. _fieldUnitCard.CloseCommandPanel();
  1191. _fieldUnitCard.RemoveClickTarget();
  1192. _fieldUnitCard.RemoveDragTarget();
  1193. _fieldUnitCard.RemoveSelectEffect();
  1194. }
  1195. }
  1196. #endregion
  1197. QueueMainPhaseAction(gameContext.TurnPlayer, new ActivatePermanentAction(fieldPermanentCard.ThisPermanent.TopCard.Owner.GetFieldPermanents().IndexOf(fieldPermanentCard.ThisPermanent), cardEffects1.IndexOf(cardEffect)));
  1198. }
  1199. }
  1200. }
  1201. }
  1202. #endregion
  1203. #region attack
  1204. if (fieldPermanentCard.ThisPermanent.IsDigimon)
  1205. {
  1206. CardCommand SkillCommand = new CardCommand("Attack", () => StartCoroutine(OnClick_SetAttack_RPC()), fieldPermanentCard.ThisPermanent.CanAttack(null), DataBase.CommandColor_Attack);
  1207. FieldUnitCommands.Add(SkillCommand);
  1208. IEnumerator OnClick_SetAttack_RPC()
  1209. {
  1210. if (fieldPermanentCard.ThisPermanent.CanAttack(null))
  1211. {
  1212. #region Reset cards on the field
  1213. foreach (Player player in gameContext.Players)
  1214. {
  1215. foreach (FieldPermanentCard _fieldUnitCard in player.FieldPermanentObjects)
  1216. {
  1217. if (_fieldUnitCard != fieldPermanentCard)
  1218. {
  1219. _fieldUnitCard.RemoveSelectEffect();
  1220. _fieldUnitCard.RemoveDragTarget();
  1221. }
  1222. _fieldUnitCard.CloseCommandPanel();
  1223. _fieldUnitCard.RemoveClickTarget();
  1224. }
  1225. }
  1226. #endregion
  1227. #region When only direct attack is available
  1228. if (fieldPermanentCard.ThisPermanent.CanAttackTargetDigimon(null, null) && gameContext.NonTurnPlayer.GetBattleAreaDigimons().Count((permanent) => fieldPermanentCard.ThisPermanent.CanAttackTargetDigimon(permanent, null)) == 0)
  1229. {
  1230. if (fieldPermanentCard.ThisPermanent.CanAttackTargetDigimon(null, null))
  1231. {
  1232. bool doAttack = false;
  1233. bool endSelect_doAttack = false;
  1234. if (gameContext.NonTurnPlayer.SecurityCards.Count >= 1)
  1235. {
  1236. gameContext.NonTurnPlayer.securityObject.securityBreakGlass.ShowBlueMatarial();
  1237. }
  1238. gameContext.NonTurnPlayer.securityObject.SetSecurityAttackObject();
  1239. gameContext.NonTurnPlayer.securityObject.SetSecurityOutline(true);
  1240. gameContext.NonTurnPlayer.securityObject.AddClickTarget(() =>
  1241. {
  1242. doAttack = true;
  1243. endSelect_doAttack = true;
  1244. });
  1245. GManager.instance.commandText.OpenCommandText($"Will you attack with {fieldPermanentCard.ThisPermanent.TopCard.BaseENGCardNameFromEntity}?");
  1246. List<Command_SelectCommand> command_SelectCommands = new List<Command_SelectCommand>()
  1247. {
  1248. new Command_SelectCommand("Attack",() =>
  1249. {
  1250. doAttack = true;
  1251. GManager.instance.selectCommandPanel.CloseSelectCommandPanel();
  1252. GManager.instance.BackButton.CloseSelectCommandButton();
  1253. endSelect_doAttack = true;
  1254. },0),
  1255. };
  1256. GManager.instance.selectCommandPanel.SetUpCommandButton(command_SelectCommands);
  1257. GManager.instance.BackButton.OpenSelectCommandButton("Return", () =>
  1258. {
  1259. doAttack = false;
  1260. GManager.instance.selectCommandPanel.CloseSelectCommandPanel();
  1261. GManager.instance.BackButton.CloseSelectCommandButton();
  1262. endSelect_doAttack = true;
  1263. }, 0);
  1264. yield return new WaitWhile(() => !endSelect_doAttack);
  1265. endSelect_doAttack = false;
  1266. GManager.instance.selectCommandPanel.Off();
  1267. GManager.instance.commandText.CloseCommandText();
  1268. yield return new WaitWhile(() => GManager.instance.commandText.gameObject.activeSelf);
  1269. gameContext.NonTurnPlayer.securityObject.RemoveClickTarget();
  1270. GManager.instance.BackButton.CloseSelectCommandButton();
  1271. if (doAttack)
  1272. {
  1273. QueueMainPhaseAction(gameContext.TurnPlayer, new AttackPermanentAction(fieldPermanentCard.ThisPermanent.TopCard.Owner.GetFieldPermanents().IndexOf(fieldPermanentCard.ThisPermanent), -1));
  1274. }
  1275. else
  1276. {
  1277. StartCoroutine(SetMainPhase());
  1278. }
  1279. }
  1280. }
  1281. #endregion
  1282. #region When it is possible to attack characters on the field
  1283. else if (gameContext.NonTurnPlayer.GetBattleAreaDigimons().Count((permanent) => fieldPermanentCard.ThisPermanent.CanAttackTargetDigimon(permanent, null)) >= 1)
  1284. {
  1285. bool doAttack = false;
  1286. int attackTargetID = -1;
  1287. bool endSelect_doAttack = false;
  1288. GManager.instance.commandText.OpenCommandText($"Which target will you attack?");
  1289. if (fieldPermanentCard.ThisPermanent.CanAttackTargetDigimon(null, null))
  1290. {
  1291. if (gameContext.NonTurnPlayer.SecurityCards.Count >= 1)
  1292. {
  1293. gameContext.NonTurnPlayer.securityObject.securityBreakGlass.ShowBlueMatarial();
  1294. }
  1295. gameContext.NonTurnPlayer.securityObject.SetSecurityAttackObject();
  1296. gameContext.NonTurnPlayer.securityObject.SetSecurityOutline(true);
  1297. gameContext.NonTurnPlayer.securityObject.AddClickTarget(() =>
  1298. {
  1299. doAttack = true;
  1300. attackTargetID = -1;
  1301. endSelect_doAttack = true;
  1302. });
  1303. }
  1304. foreach (FieldPermanentCard enemyFieldPermanentCard in gameContext.NonTurnPlayer.FieldPermanentObjects)
  1305. {
  1306. if (fieldPermanentCard.ThisPermanent.CanAttackTargetDigimon(enemyFieldPermanentCard.ThisPermanent, null))
  1307. {
  1308. enemyFieldPermanentCard.AddClickTarget((_fieldUnitCard) => StartCoroutine(SelectDefender()));
  1309. enemyFieldPermanentCard.OnSelectEffect(1.1f);
  1310. IEnumerator SelectDefender()
  1311. {
  1312. foreach (Player player in gameContext.Players_ForTurnPlayer)
  1313. {
  1314. foreach (FieldPermanentCard _fieldPermanentCard in gameContext.TurnPlayer.FieldPermanentObjects)
  1315. {
  1316. _fieldPermanentCard.RemoveSelectEffect();
  1317. _fieldPermanentCard.RemoveDragTarget();
  1318. _fieldPermanentCard.RemoveClickTarget();
  1319. }
  1320. }
  1321. GManager.instance.selectCommandPanel.CloseSelectCommandPanel();
  1322. GManager.instance.BackButton.CloseSelectCommandButton();
  1323. doAttack = true;
  1324. attackTargetID = enemyFieldPermanentCard.ThisPermanent.TopCard.Owner.GetFieldPermanents().IndexOf(enemyFieldPermanentCard.ThisPermanent);
  1325. endSelect_doAttack = true;
  1326. yield return null;
  1327. }
  1328. }
  1329. }
  1330. GManager.instance.BackButton.OpenSelectCommandButton("Return", () =>
  1331. {
  1332. doAttack = false;
  1333. GManager.instance.selectCommandPanel.CloseSelectCommandPanel();
  1334. GManager.instance.BackButton.CloseSelectCommandButton();
  1335. endSelect_doAttack = true;
  1336. }, 0);
  1337. yield return new WaitWhile(() => !endSelect_doAttack);
  1338. endSelect_doAttack = false;
  1339. GManager.instance.selectCommandPanel.Off();
  1340. gameContext.NonTurnPlayer.securityObject.OffShowSecurityAttackObject();
  1341. GManager.instance.commandText.CloseCommandText();
  1342. yield return new WaitWhile(() => GManager.instance.commandText.gameObject.activeSelf);
  1343. GManager.instance.BackButton.CloseSelectCommandButton();
  1344. if (doAttack)
  1345. {
  1346. QueueMainPhaseAction(gameContext.TurnPlayer, new AttackPermanentAction(fieldPermanentCard.ThisPermanent.TopCard.Owner.GetFieldPermanents().IndexOf(fieldPermanentCard.ThisPermanent), attackTargetID));
  1347. }
  1348. else
  1349. {
  1350. StartCoroutine(SetMainPhase());
  1351. }
  1352. }
  1353. #endregion
  1354. }
  1355. }
  1356. }
  1357. #endregion
  1358. fieldPermanentCard.fieldUnitCommandPanel.SetUpCommandPanel(FieldUnitCommands, fieldPermanentCard, null);
  1359. fieldPermanentCard.AddClickTarget((_fieldUnitCard) => StartCoroutine(SetMainPhase()));
  1360. fieldPermanentCard.Outline_Select.gameObject.SetActive(true);
  1361. fieldPermanentCard.SetOrangeOutline();
  1362. yield return null;
  1363. }
  1364. #endregion
  1365. AddDragProcess(fieldPermanentCard);
  1366. #region ドラッグ操作を追加
  1367. void AddDragProcess(FieldPermanentCard fieldPermanentCard1)
  1368. {
  1369. if (fieldPermanentCard1.ThisPermanent.CanAttack(null))
  1370. {
  1371. fieldPermanentCard1.AddDragTarget(OnBeginDragAction, OnDragAction, OnEndDragAction);
  1372. #region ドラッグ開始
  1373. void OnBeginDragAction(FieldPermanentCard fieldPermanentCard2)
  1374. {
  1375. if (gameContext.TurnPlayer.FieldPermanentObjects.Count((fieldPermanentCard3) => fieldPermanentCard3.fieldUnitCommandPanel.isActive()) == 0)
  1376. {
  1377. #region 手札のカードをリセット
  1378. foreach (HandCard handCard1 in gameContext.TurnPlayer.HandCardObjects)
  1379. {
  1380. handCard1.RemoveClickTarget();
  1381. handCard1.RemoveDragTarget();
  1382. handCard1.RemoveSelectEffect();
  1383. handCard1.handCardCommandPanel.CloseCommandPanel();
  1384. handCard1.Outline_Select.SetActive(false);
  1385. }
  1386. foreach (Player player in gameContext.Players)
  1387. {
  1388. foreach (HandCard handCard2 in player.HandCardObjects)
  1389. {
  1390. handCard2.GetComponent<Draggable_HandCard>().CanPointerEnterExitAction = true;
  1391. }
  1392. }
  1393. #endregion
  1394. IsSelecting = true;
  1395. GManager.instance.commandText.CloseCommandText();
  1396. fieldPermanentCard2.CloseCommandPanel();
  1397. TargetArrow targetArrow = GManager.instance.CreateTargetArrow();
  1398. targetArrow.SetTargetArrow(fieldPermanentCard2.ThisPermanent.PermanentFrame.GetLocalCanvasPosition() + fieldPermanentCard2.ThisPermanent.TopCard.Owner.playerUIObjectParent.localPosition, Draggable.GetLocalPosition(Input.mousePosition, targetArrow.transform));
  1399. foreach (FieldPermanentCard fieldPermanentCard3 in gameContext.TurnPlayer.FieldPermanentObjects)
  1400. {
  1401. if (fieldPermanentCard3 != fieldPermanentCard2)
  1402. {
  1403. fieldPermanentCard3.RemoveSelectEffect();
  1404. fieldPermanentCard3.RemoveClickTarget();
  1405. fieldPermanentCard3.RemoveDragTarget();
  1406. }
  1407. }
  1408. foreach (FieldPermanentCard enemyFieldPermanentCard in gameContext.NonTurnPlayer.FieldPermanentObjects)
  1409. {
  1410. if (fieldPermanentCard2.ThisPermanent.CanAttackTargetDigimon(enemyFieldPermanentCard.ThisPermanent, null))
  1411. {
  1412. enemyFieldPermanentCard.OnSelectEffect(1.1f);
  1413. enemyFieldPermanentCard.SetBlueOutline();
  1414. }
  1415. }
  1416. if (fieldPermanentCard1.ThisPermanent.CanAttackTargetDigimon(null, null))
  1417. {
  1418. if (gameContext.NonTurnPlayer.SecurityCards.Count >= 1)
  1419. {
  1420. gameContext.NonTurnPlayer.securityObject.securityBreakGlass.ShowTransparentMatarial();
  1421. }
  1422. gameContext.NonTurnPlayer.securityObject.SetSecurityAttackObject();
  1423. gameContext.NonTurnPlayer.securityObject.SetSecurityOutline(false);
  1424. }
  1425. }
  1426. }
  1427. #endregion
  1428. #region ドラッグ中
  1429. void OnDragAction(FieldPermanentCard fieldPermanentCard2, List<DropArea> dropAreas)
  1430. {
  1431. fieldPermanentCard2.CloseCommandPanel();
  1432. TargetArrow targetArrow = null;
  1433. for (int i = 0; i < GManager.instance.targetArrowParent.childCount; i++)
  1434. {
  1435. if (GManager.instance.targetArrowParent.GetChild(i).GetComponent<TargetArrow>() != null && GManager.instance.targetArrowParent.GetChild(i).gameObject.activeSelf)
  1436. {
  1437. targetArrow = GManager.instance.targetArrowParent.GetChild(i).GetComponent<TargetArrow>();
  1438. }
  1439. }
  1440. if (targetArrow != null)
  1441. {
  1442. targetArrow.SetTargetArrow(fieldPermanentCard2.ThisPermanent.PermanentFrame.GetLocalCanvasPosition() + fieldPermanentCard2.ThisPermanent.TopCard.Owner.playerUIObjectParent.localPosition, Draggable.GetLocalPosition(Input.mousePosition, targetArrow.transform));
  1443. foreach (FieldPermanentCard enemyFieldPermanentCard in GManager.instance.Opponent.FieldPermanentObjects)
  1444. {
  1445. if (fieldPermanentCard2.ThisPermanent.CanAttackTargetDigimon(enemyFieldPermanentCard.ThisPermanent, null))
  1446. {
  1447. bool OnSelect = false;
  1448. if (dropAreas.Count((dropArea) => dropArea.IsChildThisDropArea(enemyFieldPermanentCard.gameObject)) > 0)
  1449. {
  1450. if (fieldPermanentCard2.ThisPermanent.CanAttackTargetDigimon(enemyFieldPermanentCard.ThisPermanent, null))
  1451. {
  1452. OnSelect = true;
  1453. }
  1454. }
  1455. if (OnSelect)
  1456. {
  1457. enemyFieldPermanentCard.OnSelectEffect(1.1f);
  1458. enemyFieldPermanentCard.SetOrangeOutline();
  1459. }
  1460. else
  1461. {
  1462. enemyFieldPermanentCard.OnSelectEffect(1.1f);
  1463. enemyFieldPermanentCard.SetBlueOutline();
  1464. }
  1465. }
  1466. }
  1467. if (fieldPermanentCard2.ThisPermanent.CanAttackTargetDigimon(null, null))
  1468. {
  1469. if (dropAreas.Count((dropArea) => dropArea.IsChildThisDropArea(gameContext.NonTurnPlayer.securityObject.securityAttackDropArea.gameObject)) > 0)
  1470. {
  1471. if (gameContext.NonTurnPlayer.SecurityCards.Count >= 1)
  1472. {
  1473. gameContext.NonTurnPlayer.securityObject.securityBreakGlass.ShowBlueMatarial();
  1474. }
  1475. gameContext.NonTurnPlayer.securityObject.SetSecurityAttackObject();
  1476. gameContext.NonTurnPlayer.securityObject.SetSecurityOutline(true);
  1477. }
  1478. else
  1479. {
  1480. if (gameContext.NonTurnPlayer.SecurityCards.Count >= 1)
  1481. {
  1482. gameContext.NonTurnPlayer.securityObject.securityBreakGlass.ShowTransparentMatarial();
  1483. }
  1484. gameContext.NonTurnPlayer.securityObject.SetSecurityAttackObject();
  1485. gameContext.NonTurnPlayer.securityObject.SetSecurityOutline(false);
  1486. }
  1487. }
  1488. }
  1489. }
  1490. #endregion
  1491. #region ドラッグ終了
  1492. void OnEndDragAction(FieldPermanentCard fieldPermanentCard2, List<DropArea> dropAreas)
  1493. {
  1494. IsSelecting = false;
  1495. TargetArrow targetArrow = null;
  1496. for (int i = 0; i < GManager.instance.targetArrowParent.childCount; i++)
  1497. {
  1498. if (GManager.instance.targetArrowParent.GetChild(i).GetComponent<TargetArrow>() != null && GManager.instance.targetArrowParent.GetChild(i).gameObject.activeSelf)
  1499. {
  1500. targetArrow = GManager.instance.targetArrowParent.GetChild(i).GetComponent<TargetArrow>();
  1501. }
  1502. }
  1503. if (targetArrow != null)
  1504. {
  1505. #region 手札のカードをリセット
  1506. foreach (HandCard handCard1 in gameContext.TurnPlayer.HandCardObjects)
  1507. {
  1508. handCard1.RemoveClickTarget();
  1509. }
  1510. foreach (Player player in gameContext.Players)
  1511. {
  1512. foreach (HandCard handCard2 in player.HandCardObjects)
  1513. {
  1514. handCard2.GetComponent<Draggable_HandCard>().CanPointerEnterExitAction = true;
  1515. }
  1516. }
  1517. #endregion
  1518. GManager.instance.You.playMatCardFrame.OffFrame_Select();
  1519. fieldPermanentCard2.CloseCommandPanel();
  1520. Destroy(targetArrow.gameObject);
  1521. foreach (DropArea dropArea in dropAreas)
  1522. {
  1523. foreach (FieldPermanentCard enemyFieldPermanentCard in GManager.instance.Opponent.FieldPermanentObjects)
  1524. {
  1525. if (dropArea.IsChildThisDropArea(enemyFieldPermanentCard.gameObject))
  1526. {
  1527. if (fieldPermanentCard2.ThisPermanent.CanAttackTargetDigimon(enemyFieldPermanentCard.ThisPermanent, null))
  1528. {
  1529. #region Reset field cards
  1530. foreach (Player player in gameContext.Players)
  1531. {
  1532. foreach (FieldPermanentCard fieldPermanentCard3 in player.FieldPermanentObjects)
  1533. {
  1534. if (fieldPermanentCard3 != fieldPermanentCard2 && fieldPermanentCard3 != enemyFieldPermanentCard)
  1535. {
  1536. fieldPermanentCard3.RemoveSelectEffect();
  1537. }
  1538. fieldPermanentCard3.CloseCommandPanel();
  1539. fieldPermanentCard3.RemoveClickTarget();
  1540. fieldPermanentCard3.RemoveDragTarget();
  1541. }
  1542. }
  1543. #endregion
  1544. //gameContext.NonTurnPlayer.LifeCardFrame.OffFrame_Select();
  1545. QueueMainPhaseAction(gameContext.TurnPlayer, new AttackPermanentAction(gameContext.TurnPlayer.GetFieldPermanents().IndexOf(fieldPermanentCard2.ThisPermanent), gameContext.NonTurnPlayer.GetFieldPermanents().IndexOf(enemyFieldPermanentCard.ThisPermanent)));
  1546. return;
  1547. }
  1548. }
  1549. }
  1550. if (fieldPermanentCard2.ThisPermanent.CanAttackTargetDigimon(null, null))
  1551. {
  1552. if (dropArea.IsChildThisDropArea(gameContext.NonTurnPlayer.securityObject.securityAttackDropArea.gameObject))
  1553. {
  1554. #region Reset field cards
  1555. foreach (Player player in gameContext.Players)
  1556. {
  1557. foreach (FieldPermanentCard fieldPermanentCard3 in player.FieldPermanentObjects)
  1558. {
  1559. if (fieldPermanentCard3 != fieldPermanentCard2)
  1560. {
  1561. fieldPermanentCard3.RemoveSelectEffect();
  1562. }
  1563. fieldPermanentCard3.CloseCommandPanel();
  1564. fieldPermanentCard3.RemoveClickTarget();
  1565. fieldPermanentCard3.RemoveDragTarget();
  1566. }
  1567. }
  1568. #endregion
  1569. QueueMainPhaseAction(gameContext.TurnPlayer, new AttackPermanentAction(gameContext.TurnPlayer.GetFieldPermanents().IndexOf(fieldPermanentCard2.ThisPermanent), -1));
  1570. return;
  1571. }
  1572. }
  1573. }
  1574. StartCoroutine(SetMainPhase());
  1575. }
  1576. }
  1577. #endregion
  1578. }
  1579. }
  1580. #endregion
  1581. }
  1582. }
  1583. #endregion
  1584. #region cards in hand
  1585. foreach (HandCard handCard in gameContext.TurnPlayer.HandCardObjects)
  1586. {
  1587. #region drag and play
  1588. if (handCard.cardSource.CanPlayFromHandDuringMainPhase)
  1589. {
  1590. handCard.SetBlueOutline();
  1591. handCard.AddDragTarget(BeginDrag, OnDropCard, OnDragCard);
  1592. #region At the start of drag
  1593. void BeginDrag(HandCard handCard1)
  1594. {
  1595. if (gameContext.TurnPlayer.FieldPermanentObjects.Count((_fieldPermanentCard1) => _fieldPermanentCard1.fieldUnitCommandPanel.isActive()) == 0)
  1596. {
  1597. IsSelecting = true;
  1598. OffFieldCardTarget(gameContext.TurnPlayer);
  1599. foreach (HandCard handCard2 in gameContext.TurnPlayer.HandCardObjects)
  1600. {
  1601. handCard2.RemoveOnClickAction();
  1602. if (handCard2 != handCard1)
  1603. {
  1604. handCard2.RemoveSelectEffect();
  1605. }
  1606. }
  1607. foreach (FieldPermanentCard fieldPermanentCard in GManager.instance.You.FieldPermanentObjects)
  1608. {
  1609. fieldPermanentCard.RemoveSelectEffect();
  1610. fieldPermanentCard.RemoveDragTarget();
  1611. fieldPermanentCard.Outline_Select.gameObject.SetActive(false);
  1612. }
  1613. foreach (FieldCardFrame fieldCardFrame in GManager.instance.You.fieldCardFrames)
  1614. {
  1615. fieldCardFrame.OffFrame_Select();
  1616. }
  1617. foreach (Player player in gameContext.Players_ForTurnPlayer)
  1618. {
  1619. foreach (FieldCardFrame fieldCardFrame in player.fieldCardFrames)
  1620. {
  1621. fieldCardFrame.AddClickTarget(null);
  1622. }
  1623. }
  1624. GManager.instance.You.playMatCardFrame.AddClickTarget(null);
  1625. GManager.instance.You.playMatCardFrame.OffFrame_Select();
  1626. handCard1.SetBlueOutline();
  1627. handCard1.OffPlayText();
  1628. handCard1.OffJogressPlayText();
  1629. handCard1.OffBurstPlayText();
  1630. handCard1.OffAppFusionPlayText();
  1631. handCard1.OffClickText();
  1632. #region デジモン・テイマー
  1633. if (handCard1.cardSource.IsPermanent)
  1634. {
  1635. bool CanPlayEmptyFrame = false;
  1636. foreach (FieldCardFrame fieldCardFrame in GManager.instance.You.fieldCardFrames)
  1637. {
  1638. if (fieldCardFrame.IsEmptyFrame() && !handCard1.cardSource.IsOption)
  1639. {
  1640. if (handCard1.cardSource.CanPlayCardTargetFrame(fieldCardFrame, true, null))
  1641. {
  1642. CanPlayEmptyFrame = true;
  1643. break;
  1644. }
  1645. }
  1646. }
  1647. if (CanPlayEmptyFrame)
  1648. {
  1649. GManager.instance.You.playMatCardFrame.Frame.transform.parent.gameObject.SetActive(true);
  1650. GManager.instance.You.playMatCardFrame.OnFrame_Select(DataBase.SelectColor_Blue);
  1651. }
  1652. foreach (FieldCardFrame fieldCardFrame in GManager.instance.You.fieldCardFrames)
  1653. {
  1654. if (handCard1.cardSource.CanPlayCardTargetFrame(fieldCardFrame, true, null) || handCard1.cardSource.CanJogressFromTargetPermanent(fieldCardFrame.GetFramePermanent(), true) || handCard1.cardSource.CanBurstDigivolutionFromTargetPermanent(fieldCardFrame.GetFramePermanent(), true))
  1655. {
  1656. if (fieldCardFrame.GetFramePermanent() != null)
  1657. {
  1658. if (fieldCardFrame.GetFramePermanent().ShowingPermanentCard != null)
  1659. {
  1660. fieldCardFrame.GetFramePermanent().ShowingPermanentCard.Outline_Select.gameObject.SetActive(true);
  1661. fieldCardFrame.GetFramePermanent().ShowingPermanentCard.SetBlueOutline();
  1662. }
  1663. }
  1664. }
  1665. }
  1666. }
  1667. #endregion
  1668. #region オプション
  1669. if (handCard1.cardSource.IsOption && !handCard1.cardSource.CanNotPlayThisOption)
  1670. {
  1671. GManager.instance.You.playMatCardFrame.Frame.transform.parent.gameObject.SetActive(true);
  1672. GManager.instance.You.playMatCardFrame.OnFrame_Select(DataBase.SelectColor_Blue);
  1673. }
  1674. #endregion
  1675. // check playablity
  1676. ContinuousController.instance.StartCoroutine(SetHandCardPlayablity(handCard.cardSource));
  1677. }
  1678. }
  1679. #endregion
  1680. #region At the end of drag
  1681. void OnDropCard(List<DropArea> dropAreas)
  1682. {
  1683. if (gameContext.TurnPlayer.FieldPermanentObjects.Count((_fieldPermanentCard1) => _fieldPermanentCard1.fieldUnitCommandPanel.isActive()) == 0)
  1684. {
  1685. foreach (FieldPermanentCard fieldPermanentCard in gameContext.TurnPlayer.FieldPermanentObjects)
  1686. {
  1687. fieldPermanentCard.RemoveSelectEffect();
  1688. fieldPermanentCard.RemoveDragTarget();
  1689. fieldPermanentCard.Outline_Select.gameObject.SetActive(false);
  1690. }
  1691. foreach (FieldCardFrame fieldCardFrame in GManager.instance.You.fieldCardFrames)
  1692. {
  1693. fieldCardFrame.OffFrame_Select();
  1694. }
  1695. GManager.instance.You.playMatCardFrame.OffFrame_Select();
  1696. handCard.OffPlayText();
  1697. handCard.OffJogressPlayText();
  1698. handCard.OffBurstPlayText();
  1699. handCard.OffAppFusionPlayText();
  1700. #region play cards
  1701. bool isOnHand = dropAreas.Count((dropArea) => dropArea.IsChildThisDropArea(GManager.instance.You.HandDropArea.gameObject)) > 0;
  1702. bool selected = false;
  1703. #region If it is not dropped in the hand area
  1704. if (!isOnHand)
  1705. {
  1706. #region character field
  1707. if (handCard.cardSource.IsPermanent)
  1708. {
  1709. #region Check if it is dropped in the frame
  1710. foreach (FieldCardFrame fieldCardFrame in GManager.instance.You.fieldCardFrames)
  1711. {
  1712. if (handCard.cardSource.CanPlayCardTargetFrame(fieldCardFrame, true, null) || handCard.cardSource.CanJogressFromTargetPermanent(fieldCardFrame.GetFramePermanent(), true) || handCard.cardSource.CanBurstDigivolutionFromTargetPermanent(fieldCardFrame.GetFramePermanent(), true) || handCard.cardSource.CanAppFusionFromTargetPermanent(fieldCardFrame.GetFramePermanent(), true))
  1713. {
  1714. if (dropAreas.Count((dropArea) => dropArea.IsChildThisDropArea(fieldCardFrame.Frame)) > 0)
  1715. {
  1716. if (fieldCardFrame.GetFramePermanent() != null)
  1717. {
  1718. if (handCard.cardSource.Owner.HandTransform.GetComponent<HandContoller>() != null)
  1719. {
  1720. handCard.cardSource.Owner.HandTransform.GetComponent<HandContoller>().isDragging = true;
  1721. }
  1722. OffHandCardTarget(gameContext.TurnPlayer);
  1723. handCard.Outline_Select.SetActive(false);
  1724. foreach (Player player in gameContext.Players_ForTurnPlayer)
  1725. {
  1726. foreach (FieldCardFrame fieldCardFrame1 in player.fieldCardFrames)
  1727. {
  1728. fieldCardFrame1.RemoveClickTarget();
  1729. }
  1730. }
  1731. GManager.instance.You.playMatCardFrame.RemoveClickTarget();
  1732. GManager.instance.You.playMatCardFrame.Frame.transform.parent.gameObject.SetActive(false);
  1733. selected = true;
  1734. Permanent targetPermanent = fieldCardFrame.GetFramePermanent();
  1735. bool canNormalDigivolution = handCard.cardSource.CanPlayCardTargetFrame(fieldCardFrame, true, null);
  1736. bool canJogressDigivolution = handCard.cardSource.CanJogressFromTargetPermanent(fieldCardFrame.GetFramePermanent(), true);
  1737. bool canBurstDigivolution = handCard.cardSource.CanBurstDigivolutionFromTargetPermanent(fieldCardFrame.GetFramePermanent(), true);
  1738. bool canAppFusion = handCard.cardSource.CanAppFusionFromTargetPermanent(fieldCardFrame.GetFramePermanent(), true);
  1739. //Only normal evolution possible
  1740. if (canNormalDigivolution && !canJogressDigivolution && !canBurstDigivolution && !canAppFusion)
  1741. {
  1742. Digivolution();
  1743. }
  1744. //Only jogless is possible
  1745. else if (!canNormalDigivolution && canJogressDigivolution && !canBurstDigivolution && !canAppFusion)
  1746. {
  1747. SelectJogressDigivolutionCards(true);
  1748. }
  1749. //Only burst evolution possible
  1750. else if (!canNormalDigivolution && !canJogressDigivolution && canBurstDigivolution && !canAppFusion)
  1751. {
  1752. SelectBurstDigivolutionCards(true);
  1753. }
  1754. //Only app fusion possible
  1755. else if (!canNormalDigivolution && !canJogressDigivolution && !canBurstDigivolution && canAppFusion)
  1756. {
  1757. SelectAppFusionCards(true);
  1758. }
  1759. //Normal evolution and Jogress possible
  1760. else if (canNormalDigivolution && canJogressDigivolution && !canBurstDigivolution && !canAppFusion)
  1761. {
  1762. Vector3 Pos = handCard.transform.position;
  1763. ResetUI();
  1764. handCard.transform.GetChild(0).gameObject.SetActive(false);
  1765. handCard.GetComponent<Draggable_HandCard>().ReturnDefaultPosition();
  1766. StartCoroutine(SelectWheterToJogress());
  1767. IEnumerator SelectWheterToJogress()
  1768. {
  1769. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect_SetPosition(handCard.cardSource, Pos));
  1770. handCard.transform.position = handCard.cardSource.Owner.brainStormObject.BrainStormHandCards[0].transform.position;
  1771. GManager.instance.selectJogressEffect.SetUp_SelectWheterToJogress
  1772. (card: handCard.cardSource,
  1773. evoRoot: fieldCardFrame.GetFramePermanent().TopCard,
  1774. canNoSelect: true,
  1775. endSelectCoroutine_Digivolve: _Digivolution,
  1776. endSelectCoroutine_Jogress: _SelectJogressDigivolutionCards,
  1777. noSelectCoroutine: _NoSelectCoroutine);
  1778. yield return ContinuousController.instance.StartCoroutine(GManager.instance.selectJogressEffect.SelectWheterToJogress());
  1779. IEnumerator _Digivolution()
  1780. {
  1781. yield return null;
  1782. Digivolution();
  1783. }
  1784. IEnumerator _SelectJogressDigivolutionCards()
  1785. {
  1786. yield return null;
  1787. SelectJogressDigivolutionCards(false);
  1788. }
  1789. IEnumerator _NoSelectCoroutine()
  1790. {
  1791. yield return StartCoroutine(Return());
  1792. }
  1793. }
  1794. }
  1795. //Normal evolution and burst evolution possible
  1796. else if (canNormalDigivolution && !canJogressDigivolution && canBurstDigivolution && !canAppFusion)
  1797. {
  1798. Vector3 Pos = handCard.transform.position;
  1799. ResetUI();
  1800. handCard.transform.GetChild(0).gameObject.SetActive(false);
  1801. handCard.GetComponent<Draggable_HandCard>().ReturnDefaultPosition();
  1802. StartCoroutine(SelectWheterToBurst());
  1803. IEnumerator SelectWheterToBurst()
  1804. {
  1805. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect_SetPosition(handCard.cardSource, Pos));
  1806. handCard.transform.position = handCard.cardSource.Owner.brainStormObject.BrainStormHandCards[0].transform.position;
  1807. GManager.instance.selectBurstDigivolutionEffect.SetUp_SelectWheterToBurst
  1808. (card: handCard.cardSource,
  1809. evoRoot: fieldCardFrame.GetFramePermanent().TopCard,
  1810. canNoSelect: true,
  1811. endSelectCoroutine_Digivolve: _Digivolution,
  1812. endSelectCoroutine_Burst: _SelectBurstPermanents,
  1813. noSelectCoroutine: _NoSelectCoroutine);
  1814. yield return ContinuousController.instance.StartCoroutine(GManager.instance.selectBurstDigivolutionEffect.SelectWheterToBurst());
  1815. IEnumerator _Digivolution()
  1816. {
  1817. yield return null;
  1818. Digivolution();
  1819. }
  1820. IEnumerator _SelectBurstPermanents()
  1821. {
  1822. yield return null;
  1823. SelectBurstDigivolutionCards(false);
  1824. }
  1825. IEnumerator _NoSelectCoroutine()
  1826. {
  1827. yield return StartCoroutine(Return());
  1828. }
  1829. }
  1830. }
  1831. //Normal evolution and App Fusion possible
  1832. else if (canNormalDigivolution && !canJogressDigivolution && !canBurstDigivolution && canAppFusion)
  1833. {
  1834. Vector3 Pos = handCard.transform.position;
  1835. ResetUI();
  1836. handCard.transform.GetChild(0).gameObject.SetActive(false);
  1837. handCard.GetComponent<Draggable_HandCard>().ReturnDefaultPosition();
  1838. StartCoroutine(SelectWheterToAppFusion());
  1839. IEnumerator SelectWheterToAppFusion()
  1840. {
  1841. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect_SetPosition(handCard.cardSource, Pos));
  1842. handCard.transform.position = handCard.cardSource.Owner.brainStormObject.BrainStormHandCards[0].transform.position;
  1843. GManager.instance.selectAppFusionEffect.SetUp_SelectWheterToAppFusion
  1844. (card: handCard.cardSource,
  1845. evoRoot: fieldCardFrame.GetFramePermanent().TopCard,
  1846. canNoSelect: true,
  1847. endSelectCoroutine_Digivolve: _Digivolution,
  1848. endSelectCoroutine_AppFusion: _SelectAppFusionPermanents,
  1849. noSelectCoroutine: _NoSelectCoroutine);
  1850. yield return ContinuousController.instance.StartCoroutine(GManager.instance.selectAppFusionEffect.SelectWheterToAppFusion());
  1851. IEnumerator _Digivolution()
  1852. {
  1853. yield return null;
  1854. Digivolution();
  1855. }
  1856. IEnumerator _SelectAppFusionPermanents()
  1857. {
  1858. yield return null;
  1859. SelectAppFusionCards(false);
  1860. }
  1861. IEnumerator _NoSelectCoroutine()
  1862. {
  1863. yield return StartCoroutine(Return());
  1864. }
  1865. }
  1866. }
  1867. #region Select Jogress evolution source
  1868. void SelectJogressDigivolutionCards(bool move)
  1869. {
  1870. Vector3 Pos = handCard.transform.position;
  1871. ResetUI();
  1872. handCard.transform.GetChild(0).gameObject.SetActive(false);
  1873. StartCoroutine(SelectJogressTarget());
  1874. IEnumerator SelectJogressTarget()
  1875. {
  1876. if (move)
  1877. {
  1878. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect_SetPosition(handCard.cardSource, Pos));
  1879. handCard.transform.position = handCard.cardSource.Owner.brainStormObject.BrainStormHandCards[0].transform.position;
  1880. }
  1881. yield return ContinuousController.instance.StartCoroutine(handCard.cardSource.Owner.brainStormObject.BrainStormCoroutine(handCard.cardSource));
  1882. GManager.instance.selectJogressEffect.SetUp_SelectDigivolutionRoots
  1883. (card: handCard.cardSource,
  1884. isLocal: true,
  1885. isPayCost: true,
  1886. canNoSelect: true,
  1887. endSelectCoroutine_SelectDigivolutionRoots: _EndSelectCoroutine_SelectDigivolutionRoots,
  1888. noSelectCoroutine: _NoSelectCoroutine);
  1889. yield return ContinuousController.instance.StartCoroutine(GManager.instance.selectJogressEffect.SelectDigivolutionRoots());
  1890. IEnumerator _EndSelectCoroutine_SelectDigivolutionRoots(List<Permanent> permanents)
  1891. {
  1892. yield return null;
  1893. QueueMainPhaseAction(gameContext.TurnPlayer, new PlayCardAction(handCard.cardSource.CardIndex, fieldCardFrame.FrameID, new int[] { permanents[0].PermanentFrame.FrameID, permanents[1].PermanentFrame.FrameID }, -1, new int[0]));
  1894. }
  1895. IEnumerator _NoSelectCoroutine()
  1896. {
  1897. yield return null;
  1898. yield return StartCoroutine(Return());
  1899. }
  1900. }
  1901. }
  1902. #endregion
  1903. #region Select the burst evolution source and tamer
  1904. void SelectBurstDigivolutionCards(bool move)
  1905. {
  1906. Vector3 Pos = handCard.transform.position;
  1907. ResetUI();
  1908. handCard.transform.GetChild(0).gameObject.SetActive(false);
  1909. StartCoroutine(SelectJogressTarget());
  1910. IEnumerator SelectJogressTarget()
  1911. {
  1912. if (move)
  1913. {
  1914. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect_SetPosition(handCard.cardSource, Pos));
  1915. handCard.transform.position = handCard.cardSource.Owner.brainStormObject.BrainStormHandCards[0].transform.position;
  1916. }
  1917. yield return ContinuousController.instance.StartCoroutine(handCard.cardSource.Owner.brainStormObject.BrainStormCoroutine(handCard.cardSource));
  1918. GManager.instance.selectBurstDigivolutionEffect.SetUp_SelectTamer
  1919. (card: handCard.cardSource,
  1920. isLocal: true,
  1921. isPayCost: true,
  1922. canNoSelect: true,
  1923. endSelectCoroutine_SelectTamer: EndSelectCoroutine_SelectTamer,
  1924. noSelectCoroutine: _NoSelectCoroutine);
  1925. yield return ContinuousController.instance.StartCoroutine(GManager.instance.selectBurstDigivolutionEffect.SelectTamer());
  1926. IEnumerator EndSelectCoroutine_SelectTamer(Permanent permanent)
  1927. {
  1928. yield return null;
  1929. QueueMainPhaseAction(gameContext.TurnPlayer, new PlayCardAction(handCard.cardSource.CardIndex, fieldCardFrame.FrameID, new int[0], permanent.PermanentFrame.FrameID, new int[0]));
  1930. }
  1931. IEnumerator _NoSelectCoroutine()
  1932. {
  1933. yield return null;
  1934. yield return StartCoroutine(Return());
  1935. }
  1936. }
  1937. }
  1938. #endregion
  1939. #region Select the app fusion source and link card
  1940. void SelectAppFusionCards(bool move)
  1941. {
  1942. Vector3 Pos = handCard.transform.position;
  1943. ResetUI();
  1944. handCard.transform.GetChild(0).gameObject.SetActive(false);
  1945. StartCoroutine(SelectAppFusionTarget());
  1946. IEnumerator SelectAppFusionTarget()
  1947. {
  1948. if (move)
  1949. {
  1950. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect_SetPosition(handCard.cardSource, Pos));
  1951. handCard.transform.position = handCard.cardSource.Owner.brainStormObject.BrainStormHandCards[0].transform.position;
  1952. }
  1953. yield return ContinuousController.instance.StartCoroutine(handCard.cardSource.Owner.brainStormObject.BrainStormCoroutine(handCard.cardSource));
  1954. GManager.instance.selectAppFusionEffect.SetUp_SelectLink
  1955. (card: handCard.cardSource,
  1956. isLocal: true,
  1957. isPayCost: true,
  1958. canNoSelect: false,
  1959. endSelectCoroutine_SelectLink: EndSelectCoroutine_SelectLink,
  1960. noSelectCoroutine: _NoSelectCoroutine);
  1961. yield return ContinuousController.instance.StartCoroutine(GManager.instance.selectAppFusionEffect.SelectLink(targetPermanent));
  1962. IEnumerator EndSelectCoroutine_SelectLink(CardSource cardSource)
  1963. {
  1964. yield return null;
  1965. QueueMainPhaseAction(gameContext.TurnPlayer, new PlayCardAction(handCard.cardSource.CardIndex, fieldCardFrame.FrameID, new int[0], -1, new int[] { targetPermanent.PermanentFrame.FrameID, targetPermanent.LinkedCards.IndexOf(cardSource) }));
  1966. }
  1967. IEnumerator _NoSelectCoroutine()
  1968. {
  1969. yield return null;
  1970. yield return StartCoroutine(Return());
  1971. }
  1972. }
  1973. }
  1974. #endregion
  1975. #region usually evolves
  1976. void Digivolution()
  1977. {
  1978. QueueMainPhaseAction(gameContext.TurnPlayer, new PlayCardAction(handCard.cardSource.CardIndex, fieldCardFrame.FrameID, new int[0], -1, new int[0]));
  1979. }
  1980. #endregion
  1981. return;
  1982. }
  1983. }
  1984. }
  1985. }
  1986. #endregion
  1987. bool CanPlayEmptyFrame = false;
  1988. if (!handCard.cardSource.IsOption)
  1989. {
  1990. foreach (FieldCardFrame fieldCardFrame in GManager.instance.You.fieldCardFrames)
  1991. {
  1992. if (fieldCardFrame.IsEmptyFrame())
  1993. {
  1994. if (handCard.cardSource.CanPlayCardTargetFrame(fieldCardFrame, true, null))
  1995. {
  1996. CanPlayEmptyFrame = true;
  1997. break;
  1998. }
  1999. }
  2000. }
  2001. }
  2002. if (CanPlayEmptyFrame)
  2003. {
  2004. #region Check for drops on the playmat
  2005. if (dropAreas.Count((dropArea) => dropArea.IsChildThisDropArea(GManager.instance.You.playMatCardFrame.Frame)) > 0)
  2006. {
  2007. if (handCard.cardSource.Owner.HandTransform.GetComponent<HandContoller>() != null)
  2008. {
  2009. handCard.cardSource.Owner.HandTransform.GetComponent<HandContoller>().isDragging = true;
  2010. }
  2011. OffHandCardTarget(gameContext.TurnPlayer);
  2012. handCard.Outline_Select.SetActive(false);
  2013. foreach (Player player in gameContext.Players_ForTurnPlayer)
  2014. {
  2015. foreach (FieldCardFrame fieldCardFrame in player.fieldCardFrames)
  2016. {
  2017. fieldCardFrame.RemoveClickTarget();
  2018. }
  2019. }
  2020. GManager.instance.You.playMatCardFrame.RemoveClickTarget();
  2021. GManager.instance.You.playMatCardFrame.Frame.transform.parent.gameObject.SetActive(false);
  2022. QueueMainPhaseAction(gameContext.TurnPlayer, new PlayCardAction(handCard.cardSource.CardIndex, handCard.cardSource.PreferredFrame().FrameID, new int[0], -1, new int[0]));
  2023. selected = true;
  2024. return;
  2025. }
  2026. #endregion
  2027. }
  2028. }
  2029. #endregion
  2030. #region option
  2031. if (handCard.cardSource.IsOption && !handCard.cardSource.CanNotPlayThisOption)
  2032. {
  2033. #region Check for drops on the playmat
  2034. if (dropAreas.Count((dropArea) => dropArea.IsChildThisDropArea(GManager.instance.You.playMatCardFrame.Frame)) > 0)
  2035. {
  2036. if (handCard.cardSource.Owner.HandTransform.GetComponent<HandContoller>() != null)
  2037. {
  2038. handCard.cardSource.Owner.HandTransform.GetComponent<HandContoller>().isDragging = true;
  2039. }
  2040. OffHandCardTarget(gameContext.TurnPlayer);
  2041. handCard.Outline_Select.SetActive(false);
  2042. foreach (Player player in gameContext.Players_ForTurnPlayer)
  2043. {
  2044. foreach (FieldCardFrame fieldCardFrame in player.fieldCardFrames)
  2045. {
  2046. fieldCardFrame.RemoveClickTarget();
  2047. }
  2048. }
  2049. GManager.instance.You.playMatCardFrame.RemoveClickTarget();
  2050. GManager.instance.You.playMatCardFrame.Frame.transform.parent.gameObject.SetActive(false);
  2051. QueueMainPhaseAction(gameContext.TurnPlayer, new PlayCardAction(handCard.cardSource.CardIndex, 0, new int[0], -1, new int[0]));
  2052. selected = true;
  2053. return;
  2054. }
  2055. #endregion
  2056. }
  2057. #endregion
  2058. }
  2059. #endregion
  2060. #endregion
  2061. if (!selected)
  2062. {
  2063. StartCoroutine(Return());
  2064. }
  2065. }
  2066. }
  2067. #endregion
  2068. #region While dragging
  2069. void OnDragCard(List<DropArea> dropAreas)
  2070. {
  2071. GManager.instance.memoryObject.OffMemoryPredictionLine();
  2072. if (gameContext.TurnPlayer.FieldPermanentObjects.Count((_fieldUnitCard1) => _fieldUnitCard1.fieldUnitCommandPanel.isActive()) == 0)
  2073. {
  2074. OffFieldCardTarget(gameContext.TurnPlayer);
  2075. foreach (FieldPermanentCard fieldPermanentCard in gameContext.TurnPlayer.FieldPermanentObjects)
  2076. {
  2077. fieldPermanentCard.RemoveDragTarget();
  2078. fieldPermanentCard.Outline_Select.gameObject.SetActive(false);
  2079. }
  2080. handCard.SetBlueOutline();
  2081. handCard.OffPlayText();
  2082. handCard.OffJogressPlayText();
  2083. handCard.OffBurstPlayText();
  2084. handCard.OffAppFusionPlayText();
  2085. bool isOnPermanentFrameAndCanEvolve = false;
  2086. #region Digimon/Tamer
  2087. if (handCard.cardSource.IsPermanent)
  2088. {
  2089. #region Check if it is on the frame
  2090. foreach (FieldCardFrame fieldCardFrame in GManager.instance.You.fieldCardFrames)
  2091. {
  2092. int frameIndex = GManager.instance.You.fieldCardFrames.IndexOf(fieldCardFrame);
  2093. if (_canPlayTargetFrames[frameIndex])
  2094. {
  2095. if (fieldCardFrame.GetFramePermanent() != null)
  2096. {
  2097. if (fieldCardFrame.GetFramePermanent().ShowingPermanentCard != null)
  2098. {
  2099. if (dropAreas.Count((dropArea) => dropArea.IsChildThisDropArea(fieldCardFrame.Frame)) > 0)
  2100. {
  2101. isOnPermanentFrameAndCanEvolve = true;
  2102. if (_canDigivolves[frameIndex])
  2103. {
  2104. handCard.SetPlayText("DIGIVOLVE", new Color32(255, 135, 8, 255));
  2105. }
  2106. if (_canJogresses[frameIndex])
  2107. {
  2108. handCard.SetJogressPlayText();
  2109. }
  2110. if (_canBursts[frameIndex])
  2111. {
  2112. handCard.SetBurstPlayText();
  2113. }
  2114. if (_canAppFusions[frameIndex])
  2115. handCard.SetAppFusionPlayText();
  2116. handCard.SetOrangeOutline();
  2117. fieldCardFrame.GetFramePermanent().ShowingPermanentCard.OnSelectEffect(1.1f);
  2118. fieldCardFrame.GetFramePermanent().ShowingPermanentCard.Outline_Select.gameObject.SetActive(true);
  2119. GManager.instance.memoryObject.ShowMemoryPredictionLine(gameContext.TurnPlayer.ExpectedMemory(_payingCosts[frameIndex]));
  2120. }
  2121. else
  2122. {
  2123. fieldCardFrame.GetFramePermanent().ShowingPermanentCard.RemoveSelectEffect();
  2124. fieldCardFrame.GetFramePermanent().ShowingPermanentCard.SetBlueOutline();
  2125. fieldCardFrame.GetFramePermanent().ShowingPermanentCard.Outline_Select.gameObject.SetActive(true);
  2126. }
  2127. }
  2128. }
  2129. }
  2130. }
  2131. if (_canPlayEmptyFrame)
  2132. {
  2133. GManager.instance.You.playMatCardFrame.Frame.transform.parent.gameObject.SetActive(true);
  2134. #region プレイマットの上にあるかチェック
  2135. if (!isOnPermanentFrameAndCanEvolve && dropAreas.Count((dropArea) =>
  2136. dropArea.IsChildThisDropArea(GManager.instance.You.playMatCardFrame.Frame)) > 0)
  2137. {
  2138. handCard.SetPlayText("PLAY", new Color32(47, 255, 64, 255));
  2139. handCard.SetOrangeOutline();
  2140. GManager.instance.You.playMatCardFrame.OnFrame_Select(DataBase.SelectColor_Orange);
  2141. GManager.instance.memoryObject.ShowMemoryPredictionLine(gameContext.TurnPlayer.ExpectedMemory(handCard.cardSource.PayingCost(SelectCardEffect.Root.Hand, null, checkAvailability: false)));
  2142. }
  2143. else
  2144. {
  2145. GManager.instance.You.playMatCardFrame.OffFrame_Select();
  2146. }
  2147. #endregion
  2148. }
  2149. #endregion
  2150. }
  2151. #endregion
  2152. #region option
  2153. if (handCard.cardSource.IsOption)
  2154. {
  2155. #region プレイマットの上にあるかチェック
  2156. if (!isOnPermanentFrameAndCanEvolve && dropAreas.Count((dropArea) =>
  2157. dropArea.IsChildThisDropArea(GManager.instance.You.playMatCardFrame.Frame)) > 0)
  2158. {
  2159. handCard.SetPlayText("USE", new Color32(47, 255, 64, 255));
  2160. handCard.SetOrangeOutline();
  2161. GManager.instance.You.playMatCardFrame.OnFrame_Select(DataBase.SelectColor_Orange);
  2162. GManager.instance.memoryObject.ShowMemoryPredictionLine(gameContext.TurnPlayer.ExpectedMemory(handCard.cardSource.PayingCost(SelectCardEffect.Root.Hand, null, checkAvailability: false)));
  2163. }
  2164. else
  2165. {
  2166. GManager.instance.You.playMatCardFrame.OffFrame_Select();
  2167. }
  2168. #endregion
  2169. }
  2170. #endregion
  2171. }
  2172. }
  2173. #endregion
  2174. IEnumerator Return()
  2175. {
  2176. foreach (Player player in gameContext.Players_ForTurnPlayer)
  2177. {
  2178. foreach (FieldCardFrame fieldCardFrame in player.fieldCardFrames)
  2179. {
  2180. fieldCardFrame.RemoveClickTarget();
  2181. }
  2182. player.brainStormObject.EndBrainStorm();
  2183. }
  2184. GManager.instance.You.playMatCardFrame.RemoveClickTarget();
  2185. handCard.GetComponent<Draggable_HandCard>().ReturnDefaultPosition();
  2186. handCard.transform.GetChild(0).gameObject.SetActive(true);
  2187. if (handCard.transform.parent != null)
  2188. {
  2189. if (handCard.transform.parent.GetComponent<GridLayoutGroup>() != null)
  2190. {
  2191. handCard.transform.parent.GetComponent<GridLayoutGroup>().enabled = false;
  2192. }
  2193. }
  2194. yield return new WaitForSeconds(Time.deltaTime);
  2195. if (handCard.transform.parent != null)
  2196. {
  2197. if (handCard.transform.parent.GetComponent<GridLayoutGroup>() != null)
  2198. {
  2199. handCard.transform.parent.GetComponent<GridLayoutGroup>().enabled = true;
  2200. }
  2201. }
  2202. StartCoroutine(SetMainPhase());
  2203. }
  2204. }
  2205. #endregion
  2206. #region Click to declare activation effect
  2207. if (handCard.cardSource.CanDeclareSkill)
  2208. {
  2209. handCard.SetOrangeOutline();
  2210. handCard.SetClickText();
  2211. handCard.AddClickTarget((_handCard) => StartCoroutine(OnClick_Select()));
  2212. IEnumerator OnClick_Select()
  2213. {
  2214. foreach (HandCard handCard2 in handCard.cardSource.Owner.HandCardObjects)
  2215. {
  2216. handCard2.GetComponent<Draggable_HandCard>().CanPointerEnterExitAction = false;
  2217. }
  2218. yield return null;
  2219. IsSelecting = true;
  2220. #region Reset cards on the field
  2221. foreach (FieldPermanentCard fieldPermanentCard in gameContext.TurnPlayer.FieldPermanentObjects)
  2222. {
  2223. fieldPermanentCard.RemoveSelectEffect();
  2224. fieldPermanentCard.RemoveClickTarget();
  2225. fieldPermanentCard.RemoveDragTarget();
  2226. fieldPermanentCard.Outline_Select.gameObject.SetActive(false);
  2227. fieldPermanentCard.CloseCommandPanel();
  2228. }
  2229. foreach (Player player in gameContext.Players)
  2230. {
  2231. OffFieldCardTarget(player);
  2232. }
  2233. #endregion
  2234. #region Reset cards in hand
  2235. foreach (HandCard handCard1 in gameContext.TurnPlayer.HandCardObjects)
  2236. {
  2237. handCard1.Outline_Select.SetActive(false);
  2238. handCard1.RemoveSelectEffect();
  2239. handCard1.RemoveClickTarget();
  2240. handCard1.RemoveDragTarget();
  2241. }
  2242. #endregion
  2243. List<CardCommand> FieldUnitCommands = new List<CardCommand>();
  2244. #region Open launch effect command
  2245. if (handCard.cardSource.CanDeclareSkill)
  2246. {
  2247. List<ICardEffect> cardEffects = new List<ICardEffect>();
  2248. List<ICardEffect> cardEffects1 = new List<ICardEffect>();
  2249. foreach (ICardEffect cardEffect in handCard.cardSource.CanDeclareSkillList)
  2250. {
  2251. cardEffects1.Add(cardEffect);
  2252. cardEffects.Add(cardEffect);
  2253. }
  2254. cardEffects.Reverse();
  2255. foreach (ICardEffect cardEffect in cardEffects)
  2256. {
  2257. if (cardEffect is ActivateICardEffect)
  2258. {
  2259. CardCommand SkillCommand = new CardCommand(cardEffect.EffectName, OnClick_SetUseSkillUnit_RPC, cardEffect.CanUse(null), DataBase.CommandColor_Skill);
  2260. FieldUnitCommands.Add(SkillCommand);
  2261. void OnClick_SetUseSkillUnit_RPC()
  2262. {
  2263. #region Reset cards on the field
  2264. foreach (Player player in gameContext.Players)
  2265. {
  2266. foreach (FieldPermanentCard fieldPermanentCard in player.FieldPermanentObjects)
  2267. {
  2268. fieldPermanentCard.RemoveSelectEffect();
  2269. fieldPermanentCard.RemoveClickTarget();
  2270. fieldPermanentCard.RemoveDragTarget();
  2271. fieldPermanentCard.Outline_Select.gameObject.SetActive(false);
  2272. fieldPermanentCard.CloseCommandPanel();
  2273. }
  2274. }
  2275. #endregion
  2276. #region Reset cards in hand
  2277. foreach (HandCard handCard1 in gameContext.TurnPlayer.HandCardObjects)
  2278. {
  2279. handCard1.Outline_Select.SetActive(false);
  2280. handCard1.RemoveSelectEffect();
  2281. handCard1.RemoveClickTarget();
  2282. handCard1.RemoveDragTarget();
  2283. }
  2284. #endregion
  2285. handCard.GetComponent<Draggable_HandCard>().CanPointerEnterExitAction = true;
  2286. QueueMainPhaseAction(gameContext.TurnPlayer, new ActivateCardAction(handCard.cardSource.CardIndex, cardEffects1.IndexOf(cardEffect)));
  2287. }
  2288. }
  2289. }
  2290. }
  2291. #endregion
  2292. handCard.handCardCommandPanel.SetUpCommandPanel(FieldUnitCommands, null, handCard);
  2293. handCard.AddClickTarget((_fieldUnitCard) => StartCoroutine(SetMainPhase()));
  2294. handCard.Outline_Select.SetActive(true);
  2295. handCard.SetOrangeOutline();
  2296. }
  2297. }
  2298. #endregion
  2299. }
  2300. #endregion
  2301. }
  2302. #endregion
  2303. }
  2304. #endregion
  2305. #region Get whether the card in hand is playable
  2306. IEnumerator SetHandCardPlayablity(CardSource cardSource)
  2307. {
  2308. FieldCardFrame foundEmptyFrame = GManager.instance.You.fieldCardFrames
  2309. .Find(fieldCardFrame => fieldCardFrame.IsEmptyFrame() && fieldCardFrame.IsBattleAreaFrame());
  2310. bool canPlayEmpty = foundEmptyFrame != null && cardSource.CanPlayCardTargetFrame(foundEmptyFrame, true, null);
  2311. _canPlayEmptyFrame = canPlayEmpty;
  2312. _canPlayTargetFrames = new bool[GManager.instance.You.fieldCardFrames.Count];
  2313. _canDigivolves = new bool[GManager.instance.You.fieldCardFrames.Count];
  2314. _canJogresses = new bool[GManager.instance.You.fieldCardFrames.Count];
  2315. _canBursts = new bool[GManager.instance.You.fieldCardFrames.Count];
  2316. _canAppFusions = new bool[GManager.instance.You.fieldCardFrames.Count];
  2317. _payingCosts = new int[GManager.instance.You.fieldCardFrames.Count];
  2318. if (cardSource.IsDigimon)
  2319. {
  2320. List<FieldCardFrame> FramesWithPermanent = GManager.instance.You.fieldCardFrames.Filter(frame => frame.GetFramePermanent() != null);
  2321. foreach (FieldCardFrame frame in FramesWithPermanent)
  2322. {
  2323. int frameIndex = GManager.instance.You.fieldCardFrames.IndexOf(frame);
  2324. FieldCardFrame fieldCardFrame = GManager.instance.You.fieldCardFrames[frameIndex];
  2325. Permanent targetPermanent = fieldCardFrame.GetFramePermanent();
  2326. bool canPlay = targetPermanent == null ? canPlayEmpty : cardSource.CanPlayCardTargetFrame(fieldCardFrame, true, null);
  2327. bool canDigivolve = targetPermanent != null && cardSource.CanEvolve(targetPermanent, true);
  2328. bool canJogress = targetPermanent != null && cardSource.CanJogressFromTargetPermanent(targetPermanent, true);
  2329. bool canBurst = targetPermanent != null && cardSource.CanBurstDigivolutionFromTargetPermanent(targetPermanent, true);
  2330. bool canAppFusion = targetPermanent != null && cardSource.CanAppFusionFromTargetPermanent(targetPermanent, true);
  2331. _canPlayTargetFrames[frameIndex] = canPlay || canJogress || canBurst || canAppFusion;
  2332. _canDigivolves[frameIndex] = canDigivolve;
  2333. _canJogresses[frameIndex] = canJogress;
  2334. _canBursts[frameIndex] = canBurst;
  2335. _canAppFusions[frameIndex] = canAppFusion;
  2336. List<int> payingCosts = new List<int>(); ;
  2337. int minPayingCost = 0;
  2338. payingCosts.Add(cardSource.PayingCost(SelectCardEffect.Root.Hand, new List<Permanent>() { targetPermanent }, checkAvailability: false));
  2339. if (canJogress)
  2340. {
  2341. foreach(JogressCondition dnaCondition in cardSource.jogressCondition)
  2342. payingCosts.Add(cardSource.GetPayingCostWithBaseCost(dnaCondition.cost, SelectCardEffect.Root.Hand, new List<Permanent>() { targetPermanent }, checkAvailability: false));
  2343. }
  2344. if (canBurst)
  2345. {
  2346. payingCosts.Add(cardSource.GetPayingCostWithBaseCost(cardSource.burstDigivolutionCondition.cost, SelectCardEffect.Root.Hand, new List<Permanent>() { targetPermanent }, checkAvailability: false));
  2347. }
  2348. if (canAppFusion)
  2349. {
  2350. payingCosts.Add(cardSource.GetPayingCostWithBaseCost(cardSource.appFusionCondition.cost, SelectCardEffect.Root.Hand, new List<Permanent>() { targetPermanent }, checkAvailability: false));
  2351. }
  2352. if (payingCosts.Count > 1)
  2353. {
  2354. minPayingCost = payingCosts.Min();
  2355. }
  2356. else if (payingCosts.Count == 1)
  2357. {
  2358. minPayingCost = payingCosts[0];
  2359. }
  2360. _payingCosts[frameIndex] = minPayingCost;
  2361. yield return null;
  2362. }
  2363. }
  2364. else if (cardSource.IsTamer)
  2365. {
  2366. for (int i = 0; i < GManager.instance.You.fieldCardFrames.Count; i++)
  2367. {
  2368. FieldCardFrame fieldCardFrame = GManager.instance.You.fieldCardFrames[i];
  2369. Permanent targetPermanent = fieldCardFrame.GetFramePermanent();
  2370. bool canPlay = targetPermanent == null && canPlayEmpty;
  2371. _canPlayTargetFrames[i] = canPlay;
  2372. _payingCosts[i] = cardSource.PayingCost(SelectCardEffect.Root.Hand, new List<Permanent>() { targetPermanent }, checkAvailability: false);
  2373. yield return null;
  2374. }
  2375. }
  2376. }
  2377. #endregion
  2378. #region Reset UI display/click/drag operations
  2379. void ResetUI()
  2380. {
  2381. foreach (Player player in gameContext.Players)
  2382. {
  2383. player.brainStormObject.EndBrainStorm();
  2384. OffHandCardTarget(player);
  2385. OffFieldCardTarget(player);
  2386. player.securityObject.RemoveClickTarget();
  2387. foreach (HandCard handCard in player.HandCardObjects)
  2388. {
  2389. handCard.RemoveSelectEffect();
  2390. handCard.RemoveClickTarget();
  2391. handCard.RemoveDragTarget();
  2392. handCard.Outline_Select.SetActive(false);
  2393. handCard.transform.GetChild(0).gameObject.SetActive(true);
  2394. }
  2395. foreach (FieldPermanentCard fieldPermanentCard in player.FieldPermanentObjects)
  2396. {
  2397. fieldPermanentCard.RemoveSelectEffect();
  2398. fieldPermanentCard.RemoveClickTarget();
  2399. fieldPermanentCard.RemoveDragTarget();
  2400. fieldPermanentCard.CloseCommandPanel();
  2401. }
  2402. foreach (FieldCardFrame fieldCardFrame in player.fieldCardFrames)
  2403. {
  2404. fieldCardFrame.OffFrame_Select();
  2405. }
  2406. player.playMatCardFrame.OffFrame_Select();
  2407. player.securityObject.securityBreakGlass.gameObject.SetActive(false);
  2408. player.securityObject.OffShowSecurityAttackObject();
  2409. }
  2410. GManager.instance.memoryObject.OffMemoryPredictionLine();
  2411. GManager.instance.You.playMatCardFrame.Frame.transform.parent.gameObject.SetActive(false);
  2412. GManager.instance.BackButton.CloseSelectCommandButton();
  2413. GManager.instance.selectCommandPanel.CloseSelectCommandPanel();
  2414. GManager.instance.commandText.CloseCommandText();
  2415. }
  2416. #endregion
  2417. #region Queue Main Phase Action
  2418. public void QueueMainPhaseAction(Player player, MainPhaseAction action)
  2419. {
  2420. photonView.RPC("QueueMainPhaseAction_Internal", RpcTarget.All, player.PlayerID, GamePacketFactory.GetId(action.GetType()), action.Serialize());
  2421. }
  2422. [PunRPC]
  2423. void QueueMainPhaseAction_Internal(int playerID, byte packetId, byte[] bytes)
  2424. {
  2425. Player player = GManager.instance.GetPlayerFromID(playerID);
  2426. if (player == null)
  2427. {
  2428. return;
  2429. }
  2430. if (GamePacketFactory.Create(packetId, bytes) is MainPhaseAction action)
  2431. {
  2432. player.QueueMainPhaseAction(action);
  2433. }
  2434. }
  2435. #endregion
  2436. #region Activation effect permanent determination
  2437. public void SetActSkill(int permanentIndex, int skillIndex)
  2438. {
  2439. List<Permanent> feild = gameContext.TurnPlayer.GetFieldPermanents();
  2440. if (permanentIndex < 0 || permanentIndex >= feild.Count)
  2441. {
  2442. return;
  2443. }
  2444. Permanent UseSkillPermanent = feild[permanentIndex];
  2445. if (0 <= skillIndex && skillIndex < UseSkillPermanent.EffectList(EffectTiming.OnDeclaration).Count)
  2446. {
  2447. this.UseCardEffect = UseSkillPermanent.EffectList(EffectTiming.OnDeclaration)[skillIndex];
  2448. }
  2449. }
  2450. #endregion
  2451. #region Activation effect card determination
  2452. public void SetActCardSkill(int cardIndex, int skillIndex)
  2453. {
  2454. if (cardIndex < 0 || cardIndex >= gameContext.ActiveCardList.Count)
  2455. {
  2456. return;
  2457. }
  2458. CardSource UseSkillCard = gameContext.ActiveCardList[cardIndex];
  2459. if (0 <= skillIndex && skillIndex < UseSkillCard.CanDeclareSkillList.Count)
  2460. {
  2461. this.UseCardEffect = UseSkillCard.CanDeclareSkillList[skillIndex];
  2462. }
  2463. }
  2464. #endregion
  2465. #region Play card decision
  2466. public void SetPlayCard(int cardIndex, int TargetFrameID, int[] JogressEvoRootsFrameIDs, int BurstTamerFrameID, int[] AppFusionFrameIDs)
  2467. {
  2468. if (cardIndex < 0 || cardIndex >= gameContext.ActiveCardList.Count)
  2469. {
  2470. return;
  2471. }
  2472. PlayCard = gameContext.ActiveCardList[cardIndex];
  2473. this.TargetFrameID = TargetFrameID;
  2474. if (JogressEvoRootsFrameIDs != null)
  2475. {
  2476. if (JogressEvoRootsFrameIDs.Length == 2)
  2477. {
  2478. this.JogressEvoRootsFrameIDs = new int[JogressEvoRootsFrameIDs.Length];
  2479. for (int i = 0; i < JogressEvoRootsFrameIDs.Length; i++)
  2480. {
  2481. this.JogressEvoRootsFrameIDs[i] = JogressEvoRootsFrameIDs[i];
  2482. }
  2483. }
  2484. }
  2485. this.BurstTamerFrameID = BurstTamerFrameID;
  2486. if (AppFusionFrameIDs != null)
  2487. {
  2488. if (AppFusionFrameIDs.Length == 2)
  2489. {
  2490. this.AppFusionFrameIDs = new int[AppFusionFrameIDs.Length];
  2491. for (int i = 0; i < AppFusionFrameIDs.Length; i++)
  2492. {
  2493. this.AppFusionFrameIDs[i] = AppFusionFrameIDs[i];
  2494. }
  2495. }
  2496. }
  2497. }
  2498. #endregion
  2499. #region Attack permanent determination
  2500. public void SetAttackingPermaent(int permanentIndex, int attackTargetPermanentIndex)
  2501. {
  2502. List<Permanent> turnPlayerField = gameContext.TurnPlayer.GetFieldPermanents();
  2503. List<Permanent> nonTurnPlayerFeid = gameContext.NonTurnPlayer.GetFieldPermanents();
  2504. AttackingPermanent = null;
  2505. DefendingPermanent = null;
  2506. if (permanentIndex >= 0 && permanentIndex < turnPlayerField.Count)
  2507. {
  2508. AttackingPermanent = turnPlayerField[permanentIndex];
  2509. }
  2510. if (attackTargetPermanentIndex >= 0 && attackTargetPermanentIndex < nonTurnPlayerFeid.Count)
  2511. {
  2512. DefendingPermanent = nonTurnPlayerFeid[attackTargetPermanentIndex];
  2513. }
  2514. }
  2515. #endregion
  2516. #endregion
  2517. #region end phase
  2518. public bool Passed { get; set; } = true;
  2519. IEnumerator EndPhase()
  2520. {
  2521. #region Add log
  2522. PlayLog.OnAddLog?.Invoke($"\nEnd Turn:\n{gameContext.TurnPlayer.PlayerName}\n");
  2523. #endregion
  2524. #region Deselect
  2525. OffHandCardTarget(gameContext.TurnPlayer);
  2526. OffFieldCardTarget(gameContext.TurnPlayer);
  2527. #endregion
  2528. gameContext.TurnPhase = GameContext.phase.End;
  2529. Debug.Log($"{gameContext.TurnPlayer}:End Phase");
  2530. isFirstPlayerFirstTurn = false;
  2531. //Automatic processing check timing
  2532. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  2533. #region Reset status until end of turn
  2534. GManager.instance.attackProcess.AttackCount = 0;
  2535. CardEffectCommons.ClearEffectLocations();
  2536. foreach (Player player in gameContext.Players)
  2537. {
  2538. player.UntilEachTurnEndEffects = new List<Func<EffectTiming, ICardEffect>>();
  2539. player.UntilCalculateFixedCostEffect = new List<Func<EffectTiming, ICardEffect>>();
  2540. player.DigivolveCount_ThisTurn = 0;
  2541. foreach (Permanent permanent in player.GetFieldPermanents())
  2542. {
  2543. permanent.UntilEachTurnEndEffects = new List<Func<EffectTiming, ICardEffect>>();
  2544. }
  2545. }
  2546. foreach (Permanent permanent in gameContext.TurnPlayer.GetFieldPermanents())
  2547. {
  2548. permanent.UntilOwnerTurnEndEffects = new List<Func<EffectTiming, ICardEffect>>();
  2549. }
  2550. gameContext.NonTurnPlayer.UntilOpponentTurnEndEffects = new List<Func<EffectTiming, ICardEffect>>();
  2551. gameContext.TurnPlayer.UntilOwnerTurnEndEffects = new List<Func<EffectTiming, ICardEffect>>();
  2552. foreach (Permanent pokemon in gameContext.NonTurnPlayer.GetFieldPermanents())
  2553. {
  2554. pokemon.UntilOpponentTurnEndEffects = new List<Func<EffectTiming, ICardEffect>>();
  2555. }
  2556. #endregion
  2557. #region Reset the number of times the effect is used
  2558. foreach (CardSource cardSource in gameContext.ActiveCardList)
  2559. {
  2560. cardSource.cEntity_EffectController.InitUseCountThisTurn();
  2561. }
  2562. #endregion
  2563. }
  2564. #endregion
  2565. #region resetting of selection status
  2566. #region Release waiting status of cards in hand for selection
  2567. public void OffHandCardTarget(Player player)
  2568. {
  2569. foreach (HandCard _handCard in player.HandCardObjects)
  2570. {
  2571. if (_handCard != null)
  2572. {
  2573. _handCard.RemoveDragTarget();
  2574. _handCard.RemoveClickTarget();
  2575. _handCard.RemoveSelectEffect();
  2576. _handCard.handCardCommandPanel.CloseCommandPanel();
  2577. _handCard.OffPlayText();
  2578. }
  2579. }
  2580. }
  2581. #endregion
  2582. #region Release waiting status of cards in the field for selection
  2583. public void OffFieldCardTarget(Player player)
  2584. {
  2585. foreach (FieldPermanentCard fieldPermanentCard in player.FieldPermanentObjects)
  2586. {
  2587. fieldPermanentCard.RemoveClickTarget();
  2588. fieldPermanentCard.CloseCommandPanel();
  2589. fieldPermanentCard.Outline_Select.gameObject.SetActive(false);
  2590. }
  2591. }
  2592. #endregion
  2593. #endregion
  2594. #region Game over
  2595. public bool endGame { get; set; } = false;
  2596. public void OnClickSurrenderButton()
  2597. {
  2598. int localPlayerID;
  2599. if (PhotonNetwork.IsMasterClient)
  2600. {
  2601. localPlayerID = 0;
  2602. }
  2603. else
  2604. {
  2605. localPlayerID = 1;
  2606. }
  2607. photonView.RPC("Surrender", RpcTarget.All, localPlayerID);
  2608. }
  2609. [PunRPC]
  2610. public void Surrender(int loserPlayerID)
  2611. {
  2612. Player player = null;
  2613. if (loserPlayerID == 0)
  2614. {
  2615. if (PhotonNetwork.IsMasterClient)
  2616. {
  2617. player = GManager.instance.You;
  2618. }
  2619. else
  2620. {
  2621. player = GManager.instance.Opponent;
  2622. }
  2623. }
  2624. else if (loserPlayerID == 1)
  2625. {
  2626. if (PhotonNetwork.IsMasterClient)
  2627. {
  2628. player = GManager.instance.Opponent;
  2629. }
  2630. else
  2631. {
  2632. player = GManager.instance.You;
  2633. }
  2634. }
  2635. if (player != null)
  2636. {
  2637. EndGame(player.Enemy, true);
  2638. }
  2639. //EndGame(gameContext.NonTurnPlayer, true);
  2640. }
  2641. public void EndGame(Player Winner, bool Surrendered, string effectName = "")
  2642. {
  2643. foreach (GameObject gb in GManager.instance.CloseWhenEndingGameObjects)
  2644. {
  2645. if (gb != null)
  2646. {
  2647. gb.SetActive(false);
  2648. }
  2649. }
  2650. ContinuousController.instance.CanSetRandom = false;
  2651. if (PhotonNetwork.InRoom)
  2652. {
  2653. PhotonNetwork.CurrentRoom.SetCustomProperties(new ExitGames.Client.Photon.Hashtable());
  2654. }
  2655. if (!ContinuousController.instance.isRandomMatch && !ContinuousController.instance.isAI)
  2656. {
  2657. Debug.Log("Player property initialization");
  2658. PhotonNetwork.LocalPlayer.SetCustomProperties(new ExitGames.Client.Photon.Hashtable());
  2659. }
  2660. endGame = true;
  2661. if (gameContext.TurnPlayer != null)
  2662. {
  2663. OffFieldCardTarget(gameContext.TurnPlayer);
  2664. OffHandCardTarget(gameContext.TurnPlayer);
  2665. }
  2666. foreach (Player player in gameContext.Players)
  2667. {
  2668. player.securityObject.OffShowSecurityAttackObject();
  2669. }
  2670. GManager.instance.optionPanel.Close_(false);
  2671. GManager.instance.LoadingObject.gameObject.SetActive(false);
  2672. GManager.instance.resultObject.ShowResult(Winner, Surrendered, effectName);
  2673. EventSystem.current.SetSelectedGameObject(GManager.instance.resultObject.transform.GetChild(3).gameObject);
  2674. GManager.instance.commandText.CloseCommandText();
  2675. StopAllCoroutines();
  2676. GManager.instance.StopAllCoroutines();
  2677. ContinuousController.instance.StopAllCoroutines();
  2678. ContinuousController.instance.StartCoroutine(GManager.instance.BattleBGM.FadeOut(1));
  2679. if (GManager.instance.isAuto && GManager.instance.IsAI)
  2680. {
  2681. ContinuousController.instance.isAI = true;
  2682. UnityEngine.SceneManagement.SceneManager.LoadScene("BattleScene");
  2683. }
  2684. }
  2685. #endregion
  2686. #region Go to the next phase
  2687. public void PassTurn()
  2688. {
  2689. if (gameContext.TurnPhase == GameContext.phase.Main)
  2690. {
  2691. ResetUI();
  2692. ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.EndTurnProcess());
  2693. }
  2694. }
  2695. #endregion
  2696. }