TurnStateMachine.cs 161 KB

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