TurnStateMachine.cs 157 KB

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