TurnStateMachine.cs 159 KB

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