TurnStateMachine.cs 156 KB

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