TurnStateMachine.cs 161 KB

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