TurnStateMachine.cs 161 KB

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