TurnStateMachine.cs 148 KB

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