TurnStateMachine.cs 157 KB

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