TurnStateMachine.cs 161 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491
  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. }
  1110. #endregion
  1111. }
  1112. #region Added main phase operations
  1113. public IEnumerator SetMainPhase()
  1114. {
  1115. if (isSync)
  1116. {
  1117. yield break;
  1118. }
  1119. yield return new WaitWhile(() => isSync);
  1120. if (gameContext.TurnPhase != GameContext.phase.Main)
  1121. {
  1122. yield break;
  1123. }
  1124. IsSelecting = false;
  1125. #region reset
  1126. OffFieldCardTarget(gameContext.TurnPlayer);
  1127. OffHandCardTarget(gameContext.TurnPlayer);
  1128. #region rearrange cards in hand
  1129. GManager.instance.You.HandTransform.GetComponent<GridLayoutGroup>().enabled = false;
  1130. foreach (HandCard handCard in GManager.instance.You.HandCards.Map(cardSource => cardSource.ShowingHandCard).Filter(handCard => handCard != null)
  1131. .Clone())
  1132. {
  1133. if (handCard != null)
  1134. {
  1135. handCard.transform.SetParent(GManager.instance.You.HandTransform);
  1136. handCard.GetComponent<Draggable_HandCard>().CanPointerEnterExitAction = true;
  1137. }
  1138. }
  1139. GManager.instance.You.HandTransform.GetComponent<GridLayoutGroup>().enabled = true;
  1140. #endregion
  1141. foreach (Player player in gameContext.Players)
  1142. {
  1143. #region Reset permanents in play
  1144. foreach (FieldPermanentCard fieldPermanentCard in player.FieldPermanentObjects)
  1145. {
  1146. fieldPermanentCard.RemoveSelectEffect();
  1147. fieldPermanentCard.RemoveDragTarget();
  1148. fieldPermanentCard.RemoveClickTarget();
  1149. fieldPermanentCard.fieldUnitCommandPanel.CloseCommandPanel();
  1150. }
  1151. #endregion
  1152. #region Reset cards in hand
  1153. foreach (HandCard handCard in player.HandCardObjects)
  1154. {
  1155. handCard.RemoveSelectEffect();
  1156. handCard.RemoveDragTarget();
  1157. handCard.RemoveClickTarget();
  1158. }
  1159. #endregion
  1160. player.securityObject.RemoveClickTarget();
  1161. player.securityObject.securityBreakGlass.gameObject.SetActive(false);
  1162. player.securityObject.OffShowSecurityAttackObject();
  1163. }
  1164. GManager.instance.selectCommandPanel.CloseSelectCommandPanel();
  1165. GManager.instance.BackButton.CloseSelectCommandButton();
  1166. GManager.instance.You.playMatCardFrame.Frame.transform.parent.gameObject.SetActive(false);
  1167. GManager.instance.memoryObject.OffMemoryPredictionLine();
  1168. GManager.instance.commandText.CloseCommandText();
  1169. yield return new WaitWhile(() => GManager.instance.commandText.gameObject.activeSelf);
  1170. #endregion
  1171. // added
  1172. yield return new WaitWhile(() => isSync);
  1173. #region Click/drag operation
  1174. if (gameContext.TurnPlayer.isYou)
  1175. {
  1176. #region permanent of the place
  1177. foreach (FieldPermanentCard fieldPermanentCard in gameContext.TurnPlayer.FieldPermanentObjects)
  1178. {
  1179. if (fieldPermanentCard.gameObject.activeSelf && fieldPermanentCard.ThisPermanent.CanDeclareSkill() || fieldPermanentCard.ThisPermanent.CanAttack(null))
  1180. {
  1181. fieldPermanentCard.OnSelectEffect(1.1f);
  1182. #region Add click operation
  1183. fieldPermanentCard.AddClickTarget((_fieldUnitCard) => StartCoroutine(OnClick_Select()));
  1184. IEnumerator OnClick_Select()
  1185. {
  1186. if (isSync)
  1187. {
  1188. yield break;
  1189. }
  1190. IsSelecting = true;
  1191. #region Reset cards in other places
  1192. foreach (FieldPermanentCard _fieldPermanentCard in gameContext.TurnPlayer.FieldPermanentObjects)
  1193. {
  1194. if (_fieldPermanentCard != fieldPermanentCard)
  1195. {
  1196. _fieldPermanentCard.RemoveSelectEffect();
  1197. }
  1198. }
  1199. foreach (Player player in gameContext.Players)
  1200. {
  1201. OffFieldCardTarget(player);
  1202. }
  1203. #endregion
  1204. #region Reset cards in hand
  1205. foreach (HandCard handCard in gameContext.TurnPlayer.HandCardObjects)
  1206. {
  1207. handCard.RemoveSelectEffect();
  1208. handCard.RemoveClickTarget();
  1209. handCard.RemoveDragTarget();
  1210. }
  1211. #endregion
  1212. List<CardCommand> FieldUnitCommands = new List<CardCommand>();
  1213. #region activated effect
  1214. if (fieldPermanentCard.ThisPermanent.CanDeclareSkill())
  1215. {
  1216. List<ICardEffect> cardEffects = new List<ICardEffect>();
  1217. List<ICardEffect> cardEffects1 = new List<ICardEffect>();
  1218. foreach (ICardEffect cardEffect in fieldPermanentCard.ThisPermanent.EffectList(EffectTiming.OnDeclaration))
  1219. {
  1220. cardEffects1.Add(cardEffect);
  1221. cardEffects.Add(cardEffect);
  1222. }
  1223. cardEffects.Reverse();
  1224. foreach (ICardEffect cardEffect in cardEffects)
  1225. {
  1226. if (cardEffect is ActivateICardEffect)
  1227. {
  1228. CardCommand SkillCommand = new CardCommand(cardEffect.EffectName, OnClick_SetUseSkillPermanent_RPC, cardEffect.CanUse(null), DataBase.CommandColor_Skill);
  1229. FieldUnitCommands.Add(SkillCommand);
  1230. void OnClick_SetUseSkillPermanent_RPC()
  1231. {
  1232. #region Reset cards on the field
  1233. foreach (Player player in gameContext.Players)
  1234. {
  1235. foreach (FieldPermanentCard _fieldUnitCard in player.FieldPermanentObjects)
  1236. {
  1237. _fieldUnitCard.CloseCommandPanel();
  1238. _fieldUnitCard.RemoveClickTarget();
  1239. _fieldUnitCard.RemoveDragTarget();
  1240. _fieldUnitCard.RemoveSelectEffect();
  1241. }
  1242. }
  1243. #endregion
  1244. QueueMainPhaseAction(gameContext.TurnPlayer, new ActivatePermanentAction(fieldPermanentCard.ThisPermanent.TopCard.Owner.GetFieldPermanents().IndexOf(fieldPermanentCard.ThisPermanent), cardEffects1.IndexOf(cardEffect)));
  1245. }
  1246. }
  1247. }
  1248. }
  1249. #endregion
  1250. #region attack
  1251. if (fieldPermanentCard.ThisPermanent.IsDigimon)
  1252. {
  1253. CardCommand SkillCommand = new CardCommand("Attack", () => StartCoroutine(OnClick_SetAttack_RPC()), fieldPermanentCard.ThisPermanent.CanAttack(null), DataBase.CommandColor_Attack);
  1254. FieldUnitCommands.Add(SkillCommand);
  1255. IEnumerator OnClick_SetAttack_RPC()
  1256. {
  1257. if (fieldPermanentCard.ThisPermanent.CanAttack(null))
  1258. {
  1259. #region Reset cards on the field
  1260. foreach (Player player in gameContext.Players)
  1261. {
  1262. foreach (FieldPermanentCard _fieldUnitCard in player.FieldPermanentObjects)
  1263. {
  1264. if (_fieldUnitCard != fieldPermanentCard)
  1265. {
  1266. _fieldUnitCard.RemoveSelectEffect();
  1267. _fieldUnitCard.RemoveDragTarget();
  1268. }
  1269. _fieldUnitCard.CloseCommandPanel();
  1270. _fieldUnitCard.RemoveClickTarget();
  1271. }
  1272. }
  1273. #endregion
  1274. #region When only direct attack is available
  1275. if (fieldPermanentCard.ThisPermanent.CanAttackTargetDigimon(null, null) && gameContext.NonTurnPlayer.GetBattleAreaDigimons().Count((permanent) => fieldPermanentCard.ThisPermanent.CanAttackTargetDigimon(permanent, null)) == 0)
  1276. {
  1277. if (fieldPermanentCard.ThisPermanent.CanAttackTargetDigimon(null, null))
  1278. {
  1279. bool doAttack = false;
  1280. bool endSelect_doAttack = false;
  1281. if (gameContext.NonTurnPlayer.SecurityCards.Count >= 1)
  1282. {
  1283. gameContext.NonTurnPlayer.securityObject.securityBreakGlass.ShowBlueMatarial();
  1284. }
  1285. gameContext.NonTurnPlayer.securityObject.SetSecurityAttackObject();
  1286. gameContext.NonTurnPlayer.securityObject.SetSecurityOutline(true);
  1287. gameContext.NonTurnPlayer.securityObject.AddClickTarget(() =>
  1288. {
  1289. doAttack = true;
  1290. endSelect_doAttack = true;
  1291. });
  1292. GManager.instance.commandText.OpenCommandText($"Will you attack with {fieldPermanentCard.ThisPermanent.TopCard.BaseENGCardNameFromEntity}?");
  1293. List<Command_SelectCommand> command_SelectCommands = new List<Command_SelectCommand>()
  1294. {
  1295. new Command_SelectCommand("Attack",() =>
  1296. {
  1297. doAttack = true;
  1298. GManager.instance.selectCommandPanel.CloseSelectCommandPanel();
  1299. GManager.instance.BackButton.CloseSelectCommandButton();
  1300. endSelect_doAttack = true;
  1301. },0),
  1302. };
  1303. GManager.instance.selectCommandPanel.SetUpCommandButton(command_SelectCommands);
  1304. GManager.instance.BackButton.OpenSelectCommandButton("Return", () =>
  1305. {
  1306. doAttack = false;
  1307. GManager.instance.selectCommandPanel.CloseSelectCommandPanel();
  1308. GManager.instance.BackButton.CloseSelectCommandButton();
  1309. endSelect_doAttack = true;
  1310. }, 0);
  1311. yield return new WaitWhile(() => !endSelect_doAttack);
  1312. endSelect_doAttack = false;
  1313. GManager.instance.selectCommandPanel.Off();
  1314. GManager.instance.commandText.CloseCommandText();
  1315. yield return new WaitWhile(() => GManager.instance.commandText.gameObject.activeSelf);
  1316. gameContext.NonTurnPlayer.securityObject.RemoveClickTarget();
  1317. GManager.instance.BackButton.CloseSelectCommandButton();
  1318. if (doAttack)
  1319. {
  1320. QueueMainPhaseAction(gameContext.TurnPlayer, new AttackPermanentAction(fieldPermanentCard.ThisPermanent.TopCard.Owner.GetFieldPermanents().IndexOf(fieldPermanentCard.ThisPermanent), -1));
  1321. }
  1322. else
  1323. {
  1324. StartCoroutine(SetMainPhase());
  1325. }
  1326. }
  1327. }
  1328. #endregion
  1329. #region When it is possible to attack characters on the field
  1330. else if (gameContext.NonTurnPlayer.GetBattleAreaDigimons().Count((permanent) => fieldPermanentCard.ThisPermanent.CanAttackTargetDigimon(permanent, null)) >= 1)
  1331. {
  1332. bool doAttack = false;
  1333. int attackTargetID = -1;
  1334. bool endSelect_doAttack = false;
  1335. GManager.instance.commandText.OpenCommandText($"Which target will you attack?");
  1336. if (fieldPermanentCard.ThisPermanent.CanAttackTargetDigimon(null, null))
  1337. {
  1338. if (gameContext.NonTurnPlayer.SecurityCards.Count >= 1)
  1339. {
  1340. gameContext.NonTurnPlayer.securityObject.securityBreakGlass.ShowBlueMatarial();
  1341. }
  1342. gameContext.NonTurnPlayer.securityObject.SetSecurityAttackObject();
  1343. gameContext.NonTurnPlayer.securityObject.SetSecurityOutline(true);
  1344. gameContext.NonTurnPlayer.securityObject.AddClickTarget(() =>
  1345. {
  1346. doAttack = true;
  1347. attackTargetID = -1;
  1348. endSelect_doAttack = true;
  1349. });
  1350. }
  1351. foreach (FieldPermanentCard enemyFieldPermanentCard in gameContext.NonTurnPlayer.FieldPermanentObjects)
  1352. {
  1353. if (fieldPermanentCard.ThisPermanent.CanAttackTargetDigimon(enemyFieldPermanentCard.ThisPermanent, null))
  1354. {
  1355. enemyFieldPermanentCard.AddClickTarget((_fieldUnitCard) => StartCoroutine(SelectDefender()));
  1356. enemyFieldPermanentCard.OnSelectEffect(1.1f);
  1357. IEnumerator SelectDefender()
  1358. {
  1359. foreach (Player player in gameContext.Players_ForTurnPlayer)
  1360. {
  1361. foreach (FieldPermanentCard _fieldPermanentCard in gameContext.TurnPlayer.FieldPermanentObjects)
  1362. {
  1363. _fieldPermanentCard.RemoveSelectEffect();
  1364. _fieldPermanentCard.RemoveDragTarget();
  1365. _fieldPermanentCard.RemoveClickTarget();
  1366. }
  1367. }
  1368. GManager.instance.selectCommandPanel.CloseSelectCommandPanel();
  1369. GManager.instance.BackButton.CloseSelectCommandButton();
  1370. doAttack = true;
  1371. attackTargetID = enemyFieldPermanentCard.ThisPermanent.TopCard.Owner.GetFieldPermanents().IndexOf(enemyFieldPermanentCard.ThisPermanent);
  1372. endSelect_doAttack = true;
  1373. yield return null;
  1374. }
  1375. }
  1376. }
  1377. GManager.instance.BackButton.OpenSelectCommandButton("Return", () =>
  1378. {
  1379. doAttack = false;
  1380. GManager.instance.selectCommandPanel.CloseSelectCommandPanel();
  1381. GManager.instance.BackButton.CloseSelectCommandButton();
  1382. endSelect_doAttack = true;
  1383. }, 0);
  1384. yield return new WaitWhile(() => !endSelect_doAttack);
  1385. endSelect_doAttack = false;
  1386. GManager.instance.selectCommandPanel.Off();
  1387. gameContext.NonTurnPlayer.securityObject.OffShowSecurityAttackObject();
  1388. GManager.instance.commandText.CloseCommandText();
  1389. yield return new WaitWhile(() => GManager.instance.commandText.gameObject.activeSelf);
  1390. GManager.instance.BackButton.CloseSelectCommandButton();
  1391. if (doAttack)
  1392. {
  1393. QueueMainPhaseAction(gameContext.TurnPlayer, new AttackPermanentAction(fieldPermanentCard.ThisPermanent.TopCard.Owner.GetFieldPermanents().IndexOf(fieldPermanentCard.ThisPermanent), attackTargetID));
  1394. }
  1395. else
  1396. {
  1397. StartCoroutine(SetMainPhase());
  1398. }
  1399. }
  1400. #endregion
  1401. }
  1402. }
  1403. }
  1404. #endregion
  1405. fieldPermanentCard.fieldUnitCommandPanel.SetUpCommandPanel(FieldUnitCommands, fieldPermanentCard, null);
  1406. fieldPermanentCard.AddClickTarget((_fieldUnitCard) => StartCoroutine(SetMainPhase()));
  1407. fieldPermanentCard.Outline_Select.gameObject.SetActive(true);
  1408. fieldPermanentCard.SetOrangeOutline();
  1409. yield return null;
  1410. }
  1411. #endregion
  1412. AddDragProcess(fieldPermanentCard);
  1413. #region ドラッグ操作を追加
  1414. void AddDragProcess(FieldPermanentCard fieldPermanentCard1)
  1415. {
  1416. if (fieldPermanentCard1.ThisPermanent.CanAttack(null))
  1417. {
  1418. fieldPermanentCard1.AddDragTarget(OnBeginDragAction, OnDragAction, OnEndDragAction);
  1419. #region ドラッグ開始
  1420. void OnBeginDragAction(FieldPermanentCard fieldPermanentCard2)
  1421. {
  1422. if (isSync)
  1423. {
  1424. return;
  1425. }
  1426. if (gameContext.TurnPlayer.FieldPermanentObjects.Count((fieldPermanentCard3) => fieldPermanentCard3.fieldUnitCommandPanel.isActive()) == 0)
  1427. {
  1428. #region 手札のカードをリセット
  1429. foreach (HandCard handCard1 in gameContext.TurnPlayer.HandCardObjects)
  1430. {
  1431. handCard1.RemoveClickTarget();
  1432. handCard1.RemoveDragTarget();
  1433. handCard1.RemoveSelectEffect();
  1434. handCard1.handCardCommandPanel.CloseCommandPanel();
  1435. handCard1.Outline_Select.gameObject.SetActive(false);
  1436. }
  1437. foreach (Player player in gameContext.Players)
  1438. {
  1439. foreach (HandCard handCard2 in player.HandCardObjects)
  1440. {
  1441. handCard2.GetComponent<Draggable_HandCard>().CanPointerEnterExitAction = true;
  1442. }
  1443. }
  1444. #endregion
  1445. IsSelecting = true;
  1446. GManager.instance.commandText.CloseCommandText();
  1447. fieldPermanentCard2.CloseCommandPanel();
  1448. TargetArrow targetArrow = GManager.instance.CreateTargetArrow();
  1449. targetArrow.SetTargetArrow(fieldPermanentCard2.ThisPermanent.PermanentFrame.GetLocalCanvasPosition() + fieldPermanentCard2.ThisPermanent.TopCard.Owner.playerUIObjectParent.localPosition, Draggable.GetLocalPosition(Input.mousePosition, targetArrow.transform));
  1450. foreach (FieldPermanentCard fieldPermanentCard3 in gameContext.TurnPlayer.FieldPermanentObjects)
  1451. {
  1452. if (fieldPermanentCard3 != fieldPermanentCard2)
  1453. {
  1454. fieldPermanentCard3.RemoveSelectEffect();
  1455. fieldPermanentCard3.RemoveClickTarget();
  1456. fieldPermanentCard3.RemoveDragTarget();
  1457. }
  1458. }
  1459. foreach (FieldPermanentCard enemyFieldPermanentCard in gameContext.NonTurnPlayer.FieldPermanentObjects)
  1460. {
  1461. if (fieldPermanentCard2.ThisPermanent.CanAttackTargetDigimon(enemyFieldPermanentCard.ThisPermanent, null))
  1462. {
  1463. enemyFieldPermanentCard.OnSelectEffect(1.1f);
  1464. enemyFieldPermanentCard.SetBlueOutline();
  1465. }
  1466. }
  1467. if (fieldPermanentCard1.ThisPermanent.CanAttackTargetDigimon(null, null))
  1468. {
  1469. if (gameContext.NonTurnPlayer.SecurityCards.Count >= 1)
  1470. {
  1471. gameContext.NonTurnPlayer.securityObject.securityBreakGlass.ShowTransparentMatarial();
  1472. }
  1473. gameContext.NonTurnPlayer.securityObject.SetSecurityAttackObject();
  1474. gameContext.NonTurnPlayer.securityObject.SetSecurityOutline(false);
  1475. }
  1476. }
  1477. }
  1478. #endregion
  1479. #region ドラッグ中
  1480. void OnDragAction(FieldPermanentCard fieldPermanentCard2, List<DropArea> dropAreas)
  1481. {
  1482. if (isSync)
  1483. {
  1484. StartCoroutine(SetMainPhase());
  1485. }
  1486. fieldPermanentCard2.CloseCommandPanel();
  1487. TargetArrow targetArrow = null;
  1488. for (int i = 0; i < GManager.instance.targetArrowParent.childCount; i++)
  1489. {
  1490. if (GManager.instance.targetArrowParent.GetChild(i).GetComponent<TargetArrow>() != null && GManager.instance.targetArrowParent.GetChild(i).gameObject.activeSelf)
  1491. {
  1492. targetArrow = GManager.instance.targetArrowParent.GetChild(i).GetComponent<TargetArrow>();
  1493. }
  1494. }
  1495. if (targetArrow != null)
  1496. {
  1497. targetArrow.SetTargetArrow(fieldPermanentCard2.ThisPermanent.PermanentFrame.GetLocalCanvasPosition() + fieldPermanentCard2.ThisPermanent.TopCard.Owner.playerUIObjectParent.localPosition, Draggable.GetLocalPosition(Input.mousePosition, targetArrow.transform));
  1498. foreach (FieldPermanentCard enemyFieldPermanentCard in GManager.instance.Opponent.FieldPermanentObjects)
  1499. {
  1500. if (fieldPermanentCard2.ThisPermanent.CanAttackTargetDigimon(enemyFieldPermanentCard.ThisPermanent, null))
  1501. {
  1502. bool OnSelect = false;
  1503. if (dropAreas.Count((dropArea) => dropArea.IsChildThisDropArea(enemyFieldPermanentCard.gameObject)) > 0)
  1504. {
  1505. if (fieldPermanentCard2.ThisPermanent.CanAttackTargetDigimon(enemyFieldPermanentCard.ThisPermanent, null))
  1506. {
  1507. OnSelect = true;
  1508. }
  1509. }
  1510. if (OnSelect)
  1511. {
  1512. enemyFieldPermanentCard.OnSelectEffect(1.1f);
  1513. enemyFieldPermanentCard.SetOrangeOutline();
  1514. }
  1515. else
  1516. {
  1517. enemyFieldPermanentCard.OnSelectEffect(1.1f);
  1518. enemyFieldPermanentCard.SetBlueOutline();
  1519. }
  1520. }
  1521. }
  1522. if (fieldPermanentCard2.ThisPermanent.CanAttackTargetDigimon(null, null))
  1523. {
  1524. if (dropAreas.Count((dropArea) => dropArea.IsChildThisDropArea(gameContext.NonTurnPlayer.securityObject.securityAttackDropArea.gameObject)) > 0)
  1525. {
  1526. if (gameContext.NonTurnPlayer.SecurityCards.Count >= 1)
  1527. {
  1528. gameContext.NonTurnPlayer.securityObject.securityBreakGlass.ShowBlueMatarial();
  1529. }
  1530. gameContext.NonTurnPlayer.securityObject.SetSecurityAttackObject();
  1531. gameContext.NonTurnPlayer.securityObject.SetSecurityOutline(true);
  1532. }
  1533. else
  1534. {
  1535. if (gameContext.NonTurnPlayer.SecurityCards.Count >= 1)
  1536. {
  1537. gameContext.NonTurnPlayer.securityObject.securityBreakGlass.ShowTransparentMatarial();
  1538. }
  1539. gameContext.NonTurnPlayer.securityObject.SetSecurityAttackObject();
  1540. gameContext.NonTurnPlayer.securityObject.SetSecurityOutline(false);
  1541. }
  1542. }
  1543. }
  1544. }
  1545. #endregion
  1546. #region ドラッグ終了
  1547. void OnEndDragAction(FieldPermanentCard fieldPermanentCard2, List<DropArea> dropAreas)
  1548. {
  1549. if (isSync)
  1550. {
  1551. StartCoroutine(SetMainPhase());
  1552. }
  1553. IsSelecting = false;
  1554. TargetArrow targetArrow = null;
  1555. for (int i = 0; i < GManager.instance.targetArrowParent.childCount; i++)
  1556. {
  1557. if (GManager.instance.targetArrowParent.GetChild(i).GetComponent<TargetArrow>() != null && GManager.instance.targetArrowParent.GetChild(i).gameObject.activeSelf)
  1558. {
  1559. targetArrow = GManager.instance.targetArrowParent.GetChild(i).GetComponent<TargetArrow>();
  1560. }
  1561. }
  1562. if (targetArrow != null)
  1563. {
  1564. #region 手札のカードをリセット
  1565. foreach (HandCard handCard1 in gameContext.TurnPlayer.HandCardObjects)
  1566. {
  1567. handCard1.RemoveClickTarget();
  1568. }
  1569. foreach (Player player in gameContext.Players)
  1570. {
  1571. foreach (HandCard handCard2 in player.HandCardObjects)
  1572. {
  1573. handCard2.GetComponent<Draggable_HandCard>().CanPointerEnterExitAction = true;
  1574. }
  1575. }
  1576. #endregion
  1577. GManager.instance.You.playMatCardFrame.OffFrame_Select();
  1578. fieldPermanentCard2.CloseCommandPanel();
  1579. Destroy(targetArrow.gameObject);
  1580. foreach (DropArea dropArea in dropAreas)
  1581. {
  1582. foreach (FieldPermanentCard enemyFieldPermanentCard in GManager.instance.Opponent.FieldPermanentObjects)
  1583. {
  1584. if (dropArea.IsChildThisDropArea(enemyFieldPermanentCard.gameObject))
  1585. {
  1586. if (fieldPermanentCard2.ThisPermanent.CanAttackTargetDigimon(enemyFieldPermanentCard.ThisPermanent, null))
  1587. {
  1588. #region Reset field cards
  1589. foreach (Player player in gameContext.Players)
  1590. {
  1591. foreach (FieldPermanentCard fieldPermanentCard3 in player.FieldPermanentObjects)
  1592. {
  1593. if (fieldPermanentCard3 != fieldPermanentCard2 && fieldPermanentCard3 != enemyFieldPermanentCard)
  1594. {
  1595. fieldPermanentCard3.RemoveSelectEffect();
  1596. }
  1597. fieldPermanentCard3.CloseCommandPanel();
  1598. fieldPermanentCard3.RemoveClickTarget();
  1599. fieldPermanentCard3.RemoveDragTarget();
  1600. }
  1601. }
  1602. #endregion
  1603. //gameContext.NonTurnPlayer.LifeCardFrame.OffFrame_Select();
  1604. QueueMainPhaseAction(gameContext.TurnPlayer, new AttackPermanentAction(gameContext.TurnPlayer.GetFieldPermanents().IndexOf(fieldPermanentCard2.ThisPermanent), gameContext.NonTurnPlayer.GetFieldPermanents().IndexOf(enemyFieldPermanentCard.ThisPermanent)));
  1605. return;
  1606. }
  1607. }
  1608. }
  1609. if (fieldPermanentCard2.ThisPermanent.CanAttackTargetDigimon(null, null))
  1610. {
  1611. if (dropArea.IsChildThisDropArea(gameContext.NonTurnPlayer.securityObject.securityAttackDropArea.gameObject))
  1612. {
  1613. #region Reset field cards
  1614. foreach (Player player in gameContext.Players)
  1615. {
  1616. foreach (FieldPermanentCard fieldPermanentCard3 in player.FieldPermanentObjects)
  1617. {
  1618. if (fieldPermanentCard3 != fieldPermanentCard2)
  1619. {
  1620. fieldPermanentCard3.RemoveSelectEffect();
  1621. }
  1622. fieldPermanentCard3.CloseCommandPanel();
  1623. fieldPermanentCard3.RemoveClickTarget();
  1624. fieldPermanentCard3.RemoveDragTarget();
  1625. }
  1626. }
  1627. #endregion
  1628. QueueMainPhaseAction(gameContext.TurnPlayer, new AttackPermanentAction(gameContext.TurnPlayer.GetFieldPermanents().IndexOf(fieldPermanentCard2.ThisPermanent), -1));
  1629. return;
  1630. }
  1631. }
  1632. }
  1633. StartCoroutine(SetMainPhase());
  1634. }
  1635. }
  1636. #endregion
  1637. }
  1638. }
  1639. #endregion
  1640. }
  1641. }
  1642. #endregion
  1643. #region cards in hand
  1644. foreach (HandCard handCard in gameContext.TurnPlayer.HandCardObjects)
  1645. {
  1646. #region drag and play
  1647. if (handCard.cardSource.CanPlayFromHandDuringMainPhase)
  1648. {
  1649. handCard.SetBlueOutline();
  1650. handCard.AddDragTarget(BeginDrag, OnDropCard, OnDragCard);
  1651. #region At the start of drag
  1652. void BeginDrag(HandCard handCard1)
  1653. {
  1654. if (isSync)
  1655. {
  1656. //return;
  1657. }
  1658. if (gameContext.TurnPlayer.FieldPermanentObjects.Count((_fieldPermanentCard1) => _fieldPermanentCard1.fieldUnitCommandPanel.isActive()) == 0)
  1659. {
  1660. IsSelecting = true;
  1661. OffFieldCardTarget(gameContext.TurnPlayer);
  1662. foreach (HandCard handCard2 in gameContext.TurnPlayer.HandCardObjects)
  1663. {
  1664. handCard2.RemoveOnClickAction();
  1665. if (handCard2 != handCard1)
  1666. {
  1667. handCard2.RemoveSelectEffect();
  1668. }
  1669. }
  1670. foreach (FieldPermanentCard fieldPermanentCard in GManager.instance.You.FieldPermanentObjects)
  1671. {
  1672. fieldPermanentCard.RemoveSelectEffect();
  1673. fieldPermanentCard.RemoveDragTarget();
  1674. fieldPermanentCard.Outline_Select.gameObject.SetActive(false);
  1675. }
  1676. foreach (FieldCardFrame fieldCardFrame in GManager.instance.You.fieldCardFrames)
  1677. {
  1678. fieldCardFrame.OffFrame_Select();
  1679. }
  1680. foreach (Player player in gameContext.Players_ForTurnPlayer)
  1681. {
  1682. foreach (FieldCardFrame fieldCardFrame in player.fieldCardFrames)
  1683. {
  1684. fieldCardFrame.AddClickTarget(null);
  1685. }
  1686. }
  1687. GManager.instance.You.playMatCardFrame.AddClickTarget(null);
  1688. GManager.instance.You.playMatCardFrame.OffFrame_Select();
  1689. handCard1.SetBlueOutline();
  1690. handCard1.OffPlayText();
  1691. handCard1.OffJogressPlayText();
  1692. handCard1.OffBurstPlayText();
  1693. handCard1.OffAppFusionPlayText();
  1694. handCard1.OffClickText();
  1695. #region デジモン・テイマー
  1696. if (handCard1.cardSource.IsPermanent)
  1697. {
  1698. bool CanPlayEmptyFrame = false;
  1699. foreach (FieldCardFrame fieldCardFrame in GManager.instance.You.fieldCardFrames)
  1700. {
  1701. if (fieldCardFrame.IsEmptyFrame() && !handCard1.cardSource.IsOption)
  1702. {
  1703. if (handCard1.cardSource.CanPlayCardTargetFrame(fieldCardFrame, true, null))
  1704. {
  1705. CanPlayEmptyFrame = true;
  1706. break;
  1707. }
  1708. }
  1709. }
  1710. if (CanPlayEmptyFrame)
  1711. {
  1712. GManager.instance.You.playMatCardFrame.Frame.transform.parent.gameObject.SetActive(true);
  1713. GManager.instance.You.playMatCardFrame.OnFrame_Select(DataBase.SelectColor_Blue);
  1714. }
  1715. foreach (FieldCardFrame fieldCardFrame in GManager.instance.You.fieldCardFrames)
  1716. {
  1717. if (handCard1.cardSource.CanPlayCardTargetFrame(fieldCardFrame, true, null) || handCard1.cardSource.CanJogressFromTargetPermanent(fieldCardFrame.GetFramePermanent(), true) || handCard1.cardSource.CanBurstDigivolutionFromTargetPermanent(fieldCardFrame.GetFramePermanent(), true))
  1718. {
  1719. if (fieldCardFrame.GetFramePermanent() != null)
  1720. {
  1721. if (fieldCardFrame.GetFramePermanent().ShowingPermanentCard != null)
  1722. {
  1723. fieldCardFrame.GetFramePermanent().ShowingPermanentCard.Outline_Select.gameObject.SetActive(true);
  1724. fieldCardFrame.GetFramePermanent().ShowingPermanentCard.SetBlueOutline();
  1725. }
  1726. }
  1727. }
  1728. }
  1729. }
  1730. #endregion
  1731. #region オプション
  1732. if (handCard1.cardSource.IsOption && !handCard1.cardSource.CanNotPlayThisOption)
  1733. {
  1734. GManager.instance.You.playMatCardFrame.Frame.transform.parent.gameObject.SetActive(true);
  1735. GManager.instance.You.playMatCardFrame.OnFrame_Select(DataBase.SelectColor_Blue);
  1736. }
  1737. #endregion
  1738. // check playablity
  1739. ContinuousController.instance.StartCoroutine(SetHandCardPlayablity(handCard.cardSource));
  1740. }
  1741. }
  1742. #endregion
  1743. #region At the end of drag
  1744. void OnDropCard(List<DropArea> dropAreas)
  1745. {
  1746. if (isSync)
  1747. {
  1748. StartCoroutine(Return());
  1749. }
  1750. if (gameContext.TurnPlayer.FieldPermanentObjects.Count((_fieldPermanentCard1) => _fieldPermanentCard1.fieldUnitCommandPanel.isActive()) == 0)
  1751. {
  1752. foreach (FieldPermanentCard fieldPermanentCard in gameContext.TurnPlayer.FieldPermanentObjects)
  1753. {
  1754. fieldPermanentCard.RemoveSelectEffect();
  1755. fieldPermanentCard.RemoveDragTarget();
  1756. fieldPermanentCard.Outline_Select.gameObject.SetActive(false);
  1757. }
  1758. foreach (FieldCardFrame fieldCardFrame in GManager.instance.You.fieldCardFrames)
  1759. {
  1760. fieldCardFrame.OffFrame_Select();
  1761. }
  1762. GManager.instance.You.playMatCardFrame.OffFrame_Select();
  1763. handCard.OffPlayText();
  1764. handCard.OffJogressPlayText();
  1765. handCard.OffBurstPlayText();
  1766. handCard.OffAppFusionPlayText();
  1767. #region play cards
  1768. bool isOnHand = dropAreas.Count((dropArea) => dropArea.IsChildThisDropArea(GManager.instance.You.HandDropArea.gameObject)) > 0;
  1769. bool selected = false;
  1770. #region If it is not dropped in the hand area
  1771. if (!isOnHand)
  1772. {
  1773. #region character field
  1774. if (handCard.cardSource.IsPermanent)
  1775. {
  1776. #region Check if it is dropped in the frame
  1777. foreach (FieldCardFrame fieldCardFrame in GManager.instance.You.fieldCardFrames)
  1778. {
  1779. 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))
  1780. {
  1781. if (dropAreas.Count((dropArea) => dropArea.IsChildThisDropArea(fieldCardFrame.Frame)) > 0)
  1782. {
  1783. if (fieldCardFrame.GetFramePermanent() != null)
  1784. {
  1785. if (handCard.cardSource.Owner.HandTransform.GetComponent<HandContoller>() != null)
  1786. {
  1787. handCard.cardSource.Owner.HandTransform.GetComponent<HandContoller>().isDragging = true;
  1788. }
  1789. OffHandCardTarget(gameContext.TurnPlayer);
  1790. handCard.Outline_Select.gameObject.SetActive(false);
  1791. foreach (Player player in gameContext.Players_ForTurnPlayer)
  1792. {
  1793. foreach (FieldCardFrame fieldCardFrame1 in player.fieldCardFrames)
  1794. {
  1795. fieldCardFrame1.RemoveClickTarget();
  1796. }
  1797. }
  1798. GManager.instance.You.playMatCardFrame.RemoveClickTarget();
  1799. GManager.instance.You.playMatCardFrame.Frame.transform.parent.gameObject.SetActive(false);
  1800. selected = true;
  1801. Permanent targetPermanent = fieldCardFrame.GetFramePermanent();
  1802. bool canNormalDigivolution = handCard.cardSource.CanPlayCardTargetFrame(fieldCardFrame, true, null);
  1803. bool canJogressDigivolution = handCard.cardSource.CanJogressFromTargetPermanent(fieldCardFrame.GetFramePermanent(), true);
  1804. bool canBurstDigivolution = handCard.cardSource.CanBurstDigivolutionFromTargetPermanent(fieldCardFrame.GetFramePermanent(), true);
  1805. bool canAppFusion = handCard.cardSource.CanAppFusionFromTargetPermanent(fieldCardFrame.GetFramePermanent(), true);
  1806. //Only normal evolution possible
  1807. if (canNormalDigivolution && !canJogressDigivolution && !canBurstDigivolution && !canAppFusion)
  1808. {
  1809. Digivolution();
  1810. }
  1811. //Only jogless is possible
  1812. else if (!canNormalDigivolution && canJogressDigivolution && !canBurstDigivolution && !canAppFusion)
  1813. {
  1814. SelectJogressDigivolutionCards(true);
  1815. }
  1816. //Only burst evolution possible
  1817. else if (!canNormalDigivolution && !canJogressDigivolution && canBurstDigivolution && !canAppFusion)
  1818. {
  1819. SelectBurstDigivolutionCards(true);
  1820. }
  1821. //Only app fusion possible
  1822. else if (!canNormalDigivolution && !canJogressDigivolution && !canBurstDigivolution && canAppFusion)
  1823. {
  1824. SelectAppFusionCards(true);
  1825. }
  1826. //Normal evolution and Jogress possible
  1827. else if (canNormalDigivolution && canJogressDigivolution && !canBurstDigivolution && !canAppFusion)
  1828. {
  1829. Vector3 Pos = handCard.transform.position;
  1830. ResetUI();
  1831. handCard.transform.GetChild(0).gameObject.SetActive(false);
  1832. handCard.GetComponent<Draggable_HandCard>().ReturnDefaultPosition();
  1833. StartCoroutine(SelectWheterToJogress());
  1834. IEnumerator SelectWheterToJogress()
  1835. {
  1836. isSync = true;
  1837. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect_SetPosition(handCard.cardSource, Pos));
  1838. handCard.transform.position = handCard.cardSource.Owner.brainStormObject.BrainStormHandCards[0].transform.position;
  1839. GManager.instance.selectJogressEffect.SetUp_SelectWheterToJogress
  1840. (card: handCard.cardSource,
  1841. evoRoot: fieldCardFrame.GetFramePermanent().TopCard,
  1842. canNoSelect: true,
  1843. endSelectCoroutine_Digivolve: _Digivolution,
  1844. endSelectCoroutine_Jogress: _SelectJogressDigivolutionCards,
  1845. noSelectCoroutine: _NoSelectCoroutine);
  1846. yield return ContinuousController.instance.StartCoroutine(GManager.instance.selectJogressEffect.SelectWheterToJogress());
  1847. IEnumerator _Digivolution()
  1848. {
  1849. yield return null;
  1850. Digivolution();
  1851. }
  1852. IEnumerator _SelectJogressDigivolutionCards()
  1853. {
  1854. yield return null;
  1855. SelectJogressDigivolutionCards(false);
  1856. }
  1857. IEnumerator _NoSelectCoroutine()
  1858. {
  1859. yield return StartCoroutine(Return());
  1860. }
  1861. }
  1862. }
  1863. //Normal evolution and burst evolution possible
  1864. else if (canNormalDigivolution && !canJogressDigivolution && canBurstDigivolution && !canAppFusion)
  1865. {
  1866. Vector3 Pos = handCard.transform.position;
  1867. ResetUI();
  1868. handCard.transform.GetChild(0).gameObject.SetActive(false);
  1869. handCard.GetComponent<Draggable_HandCard>().ReturnDefaultPosition();
  1870. StartCoroutine(SelectWheterToBurst());
  1871. IEnumerator SelectWheterToBurst()
  1872. {
  1873. isSync = true;
  1874. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect_SetPosition(handCard.cardSource, Pos));
  1875. handCard.transform.position = handCard.cardSource.Owner.brainStormObject.BrainStormHandCards[0].transform.position;
  1876. GManager.instance.selectBurstDigivolutionEffect.SetUp_SelectWheterToBurst
  1877. (card: handCard.cardSource,
  1878. evoRoot: fieldCardFrame.GetFramePermanent().TopCard,
  1879. canNoSelect: true,
  1880. endSelectCoroutine_Digivolve: _Digivolution,
  1881. endSelectCoroutine_Burst: _SelectBurstPermanents,
  1882. noSelectCoroutine: _NoSelectCoroutine);
  1883. yield return ContinuousController.instance.StartCoroutine(GManager.instance.selectBurstDigivolutionEffect.SelectWheterToBurst());
  1884. IEnumerator _Digivolution()
  1885. {
  1886. yield return null;
  1887. Digivolution();
  1888. }
  1889. IEnumerator _SelectBurstPermanents()
  1890. {
  1891. yield return null;
  1892. SelectBurstDigivolutionCards(false);
  1893. }
  1894. IEnumerator _NoSelectCoroutine()
  1895. {
  1896. yield return StartCoroutine(Return());
  1897. }
  1898. }
  1899. }
  1900. //Normal evolution and App Fusion possible
  1901. else if (canNormalDigivolution && !canJogressDigivolution && !canBurstDigivolution && canAppFusion)
  1902. {
  1903. Vector3 Pos = handCard.transform.position;
  1904. ResetUI();
  1905. handCard.transform.GetChild(0).gameObject.SetActive(false);
  1906. handCard.GetComponent<Draggable_HandCard>().ReturnDefaultPosition();
  1907. StartCoroutine(SelectWheterToAppFusion());
  1908. IEnumerator SelectWheterToAppFusion()
  1909. {
  1910. isSync = true;
  1911. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect_SetPosition(handCard.cardSource, Pos));
  1912. handCard.transform.position = handCard.cardSource.Owner.brainStormObject.BrainStormHandCards[0].transform.position;
  1913. GManager.instance.selectAppFusionEffect.SetUp_SelectWheterToAppFusion
  1914. (card: handCard.cardSource,
  1915. evoRoot: fieldCardFrame.GetFramePermanent().TopCard,
  1916. canNoSelect: true,
  1917. endSelectCoroutine_Digivolve: _Digivolution,
  1918. endSelectCoroutine_AppFusion: _SelectAppFusionPermanents,
  1919. noSelectCoroutine: _NoSelectCoroutine);
  1920. yield return ContinuousController.instance.StartCoroutine(GManager.instance.selectAppFusionEffect.SelectWheterToAppFusion());
  1921. IEnumerator _Digivolution()
  1922. {
  1923. yield return null;
  1924. Digivolution();
  1925. }
  1926. IEnumerator _SelectAppFusionPermanents()
  1927. {
  1928. yield return null;
  1929. SelectAppFusionCards(false);
  1930. }
  1931. IEnumerator _NoSelectCoroutine()
  1932. {
  1933. yield return StartCoroutine(Return());
  1934. }
  1935. }
  1936. }
  1937. #region Select Jogress evolution source
  1938. void SelectJogressDigivolutionCards(bool move)
  1939. {
  1940. Vector3 Pos = handCard.transform.position;
  1941. ResetUI();
  1942. handCard.transform.GetChild(0).gameObject.SetActive(false);
  1943. StartCoroutine(SelectJogressTarget());
  1944. IEnumerator SelectJogressTarget()
  1945. {
  1946. isSync = true;
  1947. if (move)
  1948. {
  1949. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect_SetPosition(handCard.cardSource, Pos));
  1950. handCard.transform.position = handCard.cardSource.Owner.brainStormObject.BrainStormHandCards[0].transform.position;
  1951. }
  1952. yield return ContinuousController.instance.StartCoroutine(handCard.cardSource.Owner.brainStormObject.BrainStormCoroutine(handCard.cardSource));
  1953. GManager.instance.selectJogressEffect.SetUp_SelectDigivolutionRoots
  1954. (card: handCard.cardSource,
  1955. isLocal: true,
  1956. isPayCost: true,
  1957. canNoSelect: true,
  1958. endSelectCoroutine_SelectDigivolutionRoots: _EndSelectCoroutine_SelectDigivolutionRoots,
  1959. noSelectCoroutine: _NoSelectCoroutine);
  1960. yield return ContinuousController.instance.StartCoroutine(GManager.instance.selectJogressEffect.SelectDigivolutionRoots());
  1961. IEnumerator _EndSelectCoroutine_SelectDigivolutionRoots(List<Permanent> permanents)
  1962. {
  1963. yield return null;
  1964. QueueMainPhaseAction(gameContext.TurnPlayer, new PlayCardAction(handCard.cardSource.CardIndex, fieldCardFrame.FrameID, new int[] { permanents[0].PermanentFrame.FrameID, permanents[1].PermanentFrame.FrameID }, -1, new int[0]));
  1965. }
  1966. IEnumerator _NoSelectCoroutine()
  1967. {
  1968. yield return null;
  1969. yield return StartCoroutine(Return());
  1970. }
  1971. isSync = false;
  1972. }
  1973. }
  1974. #endregion
  1975. #region Select the burst evolution source and tamer
  1976. void SelectBurstDigivolutionCards(bool move)
  1977. {
  1978. Vector3 Pos = handCard.transform.position;
  1979. ResetUI();
  1980. handCard.transform.GetChild(0).gameObject.SetActive(false);
  1981. StartCoroutine(SelectJogressTarget());
  1982. IEnumerator SelectJogressTarget()
  1983. {
  1984. isSync = true;
  1985. if (move)
  1986. {
  1987. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect_SetPosition(handCard.cardSource, Pos));
  1988. handCard.transform.position = handCard.cardSource.Owner.brainStormObject.BrainStormHandCards[0].transform.position;
  1989. }
  1990. yield return ContinuousController.instance.StartCoroutine(handCard.cardSource.Owner.brainStormObject.BrainStormCoroutine(handCard.cardSource));
  1991. GManager.instance.selectBurstDigivolutionEffect.SetUp_SelectTamer
  1992. (card: handCard.cardSource,
  1993. isLocal: true,
  1994. isPayCost: true,
  1995. canNoSelect: true,
  1996. endSelectCoroutine_SelectTamer: EndSelectCoroutine_SelectTamer,
  1997. noSelectCoroutine: _NoSelectCoroutine);
  1998. yield return ContinuousController.instance.StartCoroutine(GManager.instance.selectBurstDigivolutionEffect.SelectTamer());
  1999. IEnumerator EndSelectCoroutine_SelectTamer(Permanent permanent)
  2000. {
  2001. yield return null;
  2002. QueueMainPhaseAction(gameContext.TurnPlayer, new PlayCardAction(handCard.cardSource.CardIndex, fieldCardFrame.FrameID, new int[0], permanent.PermanentFrame.FrameID, new int[0]));
  2003. }
  2004. IEnumerator _NoSelectCoroutine()
  2005. {
  2006. yield return null;
  2007. yield return StartCoroutine(Return());
  2008. }
  2009. isSync = false;
  2010. }
  2011. }
  2012. #endregion
  2013. #region Select the app fusion source and link card
  2014. void SelectAppFusionCards(bool move)
  2015. {
  2016. Vector3 Pos = handCard.transform.position;
  2017. ResetUI();
  2018. handCard.transform.GetChild(0).gameObject.SetActive(false);
  2019. StartCoroutine(SelectAppFusionTarget());
  2020. IEnumerator SelectAppFusionTarget()
  2021. {
  2022. isSync = true;
  2023. if (move)
  2024. {
  2025. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect_SetPosition(handCard.cardSource, Pos));
  2026. handCard.transform.position = handCard.cardSource.Owner.brainStormObject.BrainStormHandCards[0].transform.position;
  2027. }
  2028. yield return ContinuousController.instance.StartCoroutine(handCard.cardSource.Owner.brainStormObject.BrainStormCoroutine(handCard.cardSource));
  2029. GManager.instance.selectAppFusionEffect.SetUp_SelectLink
  2030. (card: handCard.cardSource,
  2031. isLocal: true,
  2032. isPayCost: true,
  2033. canNoSelect: true,
  2034. endSelectCoroutine_SelectLink: EndSelectCoroutine_SelectLink,
  2035. noSelectCoroutine: _NoSelectCoroutine);
  2036. yield return ContinuousController.instance.StartCoroutine(GManager.instance.selectAppFusionEffect.SelectLink(targetPermanent));
  2037. IEnumerator EndSelectCoroutine_SelectLink(CardSource cardSource)
  2038. {
  2039. yield return null;
  2040. QueueMainPhaseAction(gameContext.TurnPlayer, new PlayCardAction(handCard.cardSource.CardIndex, fieldCardFrame.FrameID, new int[0], -1, new int[] { targetPermanent.PermanentFrame.FrameID, targetPermanent.LinkedCards.IndexOf(cardSource) }));
  2041. }
  2042. IEnumerator _NoSelectCoroutine()
  2043. {
  2044. yield return null;
  2045. yield return StartCoroutine(Return());
  2046. }
  2047. isSync = false;
  2048. }
  2049. }
  2050. #endregion
  2051. #region usually evolves
  2052. void Digivolution()
  2053. {
  2054. QueueMainPhaseAction(gameContext.TurnPlayer, new PlayCardAction(handCard.cardSource.CardIndex, fieldCardFrame.FrameID, new int[0], -1, new int[0]));
  2055. }
  2056. #endregion
  2057. return;
  2058. }
  2059. }
  2060. }
  2061. }
  2062. #endregion
  2063. bool CanPlayEmptyFrame = false;
  2064. if (!handCard.cardSource.IsOption)
  2065. {
  2066. foreach (FieldCardFrame fieldCardFrame in GManager.instance.You.fieldCardFrames)
  2067. {
  2068. if (fieldCardFrame.IsEmptyFrame())
  2069. {
  2070. if (handCard.cardSource.CanPlayCardTargetFrame(fieldCardFrame, true, null))
  2071. {
  2072. CanPlayEmptyFrame = true;
  2073. break;
  2074. }
  2075. }
  2076. }
  2077. }
  2078. if (CanPlayEmptyFrame)
  2079. {
  2080. #region Check for drops on the playmat
  2081. if (dropAreas.Count((dropArea) => dropArea.IsChildThisDropArea(GManager.instance.You.playMatCardFrame.Frame)) > 0)
  2082. {
  2083. if (handCard.cardSource.Owner.HandTransform.GetComponent<HandContoller>() != null)
  2084. {
  2085. handCard.cardSource.Owner.HandTransform.GetComponent<HandContoller>().isDragging = true;
  2086. }
  2087. OffHandCardTarget(gameContext.TurnPlayer);
  2088. handCard.Outline_Select.gameObject.SetActive(false);
  2089. foreach (Player player in gameContext.Players_ForTurnPlayer)
  2090. {
  2091. foreach (FieldCardFrame fieldCardFrame in player.fieldCardFrames)
  2092. {
  2093. fieldCardFrame.RemoveClickTarget();
  2094. }
  2095. }
  2096. GManager.instance.You.playMatCardFrame.RemoveClickTarget();
  2097. GManager.instance.You.playMatCardFrame.Frame.transform.parent.gameObject.SetActive(false);
  2098. QueueMainPhaseAction(gameContext.TurnPlayer, new PlayCardAction(handCard.cardSource.CardIndex, handCard.cardSource.PreferredFrame().FrameID, new int[0], -1, new int[0]));
  2099. selected = true;
  2100. return;
  2101. }
  2102. #endregion
  2103. }
  2104. }
  2105. #endregion
  2106. #region option
  2107. if (handCard.cardSource.IsOption && !handCard.cardSource.CanNotPlayThisOption)
  2108. {
  2109. #region Check for drops on the playmat
  2110. if (dropAreas.Count((dropArea) => dropArea.IsChildThisDropArea(GManager.instance.You.playMatCardFrame.Frame)) > 0)
  2111. {
  2112. if (handCard.cardSource.Owner.HandTransform.GetComponent<HandContoller>() != null)
  2113. {
  2114. handCard.cardSource.Owner.HandTransform.GetComponent<HandContoller>().isDragging = true;
  2115. }
  2116. OffHandCardTarget(gameContext.TurnPlayer);
  2117. handCard.Outline_Select.gameObject.SetActive(false);
  2118. foreach (Player player in gameContext.Players_ForTurnPlayer)
  2119. {
  2120. foreach (FieldCardFrame fieldCardFrame in player.fieldCardFrames)
  2121. {
  2122. fieldCardFrame.RemoveClickTarget();
  2123. }
  2124. }
  2125. GManager.instance.You.playMatCardFrame.RemoveClickTarget();
  2126. GManager.instance.You.playMatCardFrame.Frame.transform.parent.gameObject.SetActive(false);
  2127. QueueMainPhaseAction(gameContext.TurnPlayer, new PlayCardAction(handCard.cardSource.CardIndex, 0, new int[0], -1, new int[0]));
  2128. selected = true;
  2129. return;
  2130. }
  2131. #endregion
  2132. }
  2133. #endregion
  2134. }
  2135. #endregion
  2136. #endregion
  2137. if (!selected)
  2138. {
  2139. StartCoroutine(Return());
  2140. }
  2141. }
  2142. }
  2143. #endregion
  2144. #region While dragging
  2145. void OnDragCard(List<DropArea> dropAreas)
  2146. {
  2147. if (isSync)
  2148. {
  2149. StartCoroutine(Return());
  2150. }
  2151. GManager.instance.memoryObject.OffMemoryPredictionLine();
  2152. if (gameContext.TurnPlayer.FieldPermanentObjects.Count((_fieldUnitCard1) => _fieldUnitCard1.fieldUnitCommandPanel.isActive()) == 0)
  2153. {
  2154. OffFieldCardTarget(gameContext.TurnPlayer);
  2155. foreach (FieldPermanentCard fieldPermanentCard in gameContext.TurnPlayer.FieldPermanentObjects)
  2156. {
  2157. fieldPermanentCard.RemoveDragTarget();
  2158. fieldPermanentCard.Outline_Select.gameObject.SetActive(false);
  2159. }
  2160. handCard.SetBlueOutline();
  2161. handCard.OffPlayText();
  2162. handCard.OffJogressPlayText();
  2163. handCard.OffBurstPlayText();
  2164. handCard.OffAppFusionPlayText();
  2165. bool isOnPermanentFrameAndCanEvolve = false;
  2166. #region Digimon/Tamer
  2167. if (handCard.cardSource.IsPermanent)
  2168. {
  2169. #region Check if it is on the frame
  2170. foreach (FieldCardFrame fieldCardFrame in GManager.instance.You.fieldCardFrames)
  2171. {
  2172. int frameIndex = GManager.instance.You.fieldCardFrames.IndexOf(fieldCardFrame);
  2173. if (_canPlayTargetFrames[frameIndex])
  2174. {
  2175. if (fieldCardFrame.GetFramePermanent() != null)
  2176. {
  2177. if (fieldCardFrame.GetFramePermanent().ShowingPermanentCard != null)
  2178. {
  2179. if (dropAreas.Count((dropArea) => dropArea.IsChildThisDropArea(fieldCardFrame.Frame)) > 0)
  2180. {
  2181. isOnPermanentFrameAndCanEvolve = true;
  2182. if (_canDigivolves[frameIndex])
  2183. {
  2184. handCard.SetPlayText("DIGIVOLVE", new Color32(255, 135, 8, 255));
  2185. }
  2186. if (_canJogresses[frameIndex])
  2187. {
  2188. handCard.SetJogressPlayText();
  2189. }
  2190. if (_canBursts[frameIndex])
  2191. {
  2192. handCard.SetBurstPlayText();
  2193. }
  2194. if (_canAppFusions[frameIndex])
  2195. handCard.SetAppFusionPlayText();
  2196. handCard.SetOrangeOutline();
  2197. fieldCardFrame.GetFramePermanent().ShowingPermanentCard.OnSelectEffect(1.1f);
  2198. fieldCardFrame.GetFramePermanent().ShowingPermanentCard.Outline_Select.gameObject.SetActive(true);
  2199. GManager.instance.memoryObject.ShowMemoryPredictionLine(gameContext.TurnPlayer.ExpectedMemory(_payingCosts[frameIndex]));
  2200. }
  2201. else
  2202. {
  2203. fieldCardFrame.GetFramePermanent().ShowingPermanentCard.RemoveSelectEffect();
  2204. fieldCardFrame.GetFramePermanent().ShowingPermanentCard.SetBlueOutline();
  2205. fieldCardFrame.GetFramePermanent().ShowingPermanentCard.Outline_Select.gameObject.SetActive(true);
  2206. }
  2207. }
  2208. }
  2209. }
  2210. }
  2211. if (_canPlayEmptyFrame)
  2212. {
  2213. GManager.instance.You.playMatCardFrame.Frame.transform.parent.gameObject.SetActive(true);
  2214. #region プレイマットの上にあるかチェック
  2215. if (!isOnPermanentFrameAndCanEvolve && dropAreas.Count((dropArea) =>
  2216. dropArea.IsChildThisDropArea(GManager.instance.You.playMatCardFrame.Frame)) > 0)
  2217. {
  2218. handCard.SetPlayText("PLAY", new Color32(47, 255, 64, 255));
  2219. handCard.SetOrangeOutline();
  2220. GManager.instance.You.playMatCardFrame.OnFrame_Select(DataBase.SelectColor_Orange);
  2221. GManager.instance.memoryObject.ShowMemoryPredictionLine(gameContext.TurnPlayer.ExpectedMemory(handCard.cardSource.PayingCost(SelectCardEffect.Root.Hand, null, checkAvailability: false)));
  2222. }
  2223. else
  2224. {
  2225. GManager.instance.You.playMatCardFrame.OffFrame_Select();
  2226. }
  2227. #endregion
  2228. }
  2229. #endregion
  2230. }
  2231. #endregion
  2232. #region option
  2233. if (handCard.cardSource.IsOption)
  2234. {
  2235. #region プレイマットの上にあるかチェック
  2236. if (!isOnPermanentFrameAndCanEvolve && dropAreas.Count((dropArea) =>
  2237. dropArea.IsChildThisDropArea(GManager.instance.You.playMatCardFrame.Frame)) > 0)
  2238. {
  2239. handCard.SetPlayText("USE", new Color32(47, 255, 64, 255));
  2240. handCard.SetOrangeOutline();
  2241. GManager.instance.You.playMatCardFrame.OnFrame_Select(DataBase.SelectColor_Orange);
  2242. GManager.instance.memoryObject.ShowMemoryPredictionLine(gameContext.TurnPlayer.ExpectedMemory(handCard.cardSource.PayingCost(SelectCardEffect.Root.Hand, null, checkAvailability: false)));
  2243. }
  2244. else
  2245. {
  2246. GManager.instance.You.playMatCardFrame.OffFrame_Select();
  2247. }
  2248. #endregion
  2249. }
  2250. #endregion
  2251. }
  2252. }
  2253. #endregion
  2254. IEnumerator Return()
  2255. {
  2256. foreach (Player player in gameContext.Players_ForTurnPlayer)
  2257. {
  2258. foreach (FieldCardFrame fieldCardFrame in player.fieldCardFrames)
  2259. {
  2260. fieldCardFrame.RemoveClickTarget();
  2261. }
  2262. player.brainStormObject.EndBrainStorm();
  2263. }
  2264. GManager.instance.You.playMatCardFrame.RemoveClickTarget();
  2265. handCard.GetComponent<Draggable_HandCard>().ReturnDefaultPosition();
  2266. handCard.transform.GetChild(0).gameObject.SetActive(true);
  2267. if (handCard.transform.parent != null)
  2268. {
  2269. if (handCard.transform.parent.GetComponent<GridLayoutGroup>() != null)
  2270. {
  2271. handCard.transform.parent.GetComponent<GridLayoutGroup>().enabled = false;
  2272. }
  2273. }
  2274. yield return new WaitForSeconds(Time.deltaTime);
  2275. if (handCard.transform.parent != null)
  2276. {
  2277. if (handCard.transform.parent.GetComponent<GridLayoutGroup>() != null)
  2278. {
  2279. handCard.transform.parent.GetComponent<GridLayoutGroup>().enabled = true;
  2280. }
  2281. }
  2282. isSync = false;
  2283. StartCoroutine(SetMainPhase());
  2284. }
  2285. }
  2286. #endregion
  2287. #region Click to declare activation effect
  2288. if (handCard.cardSource.CanDeclareSkill)
  2289. {
  2290. handCard.SetOrangeOutline();
  2291. handCard.SetClickText();
  2292. handCard.AddClickTarget((_handCard) => StartCoroutine(OnClick_Select()));
  2293. IEnumerator OnClick_Select()
  2294. {
  2295. foreach (HandCard handCard2 in handCard.cardSource.Owner.HandCardObjects)
  2296. {
  2297. handCard2.GetComponent<Draggable_HandCard>().CanPointerEnterExitAction = false;
  2298. }
  2299. yield return null;
  2300. IsSelecting = true;
  2301. #region Reset cards on the field
  2302. foreach (FieldPermanentCard fieldPermanentCard in gameContext.TurnPlayer.FieldPermanentObjects)
  2303. {
  2304. fieldPermanentCard.RemoveSelectEffect();
  2305. fieldPermanentCard.RemoveClickTarget();
  2306. fieldPermanentCard.RemoveDragTarget();
  2307. fieldPermanentCard.Outline_Select.gameObject.SetActive(false);
  2308. fieldPermanentCard.CloseCommandPanel();
  2309. }
  2310. foreach (Player player in gameContext.Players)
  2311. {
  2312. OffFieldCardTarget(player);
  2313. }
  2314. #endregion
  2315. #region Reset cards in hand
  2316. foreach (HandCard handCard1 in gameContext.TurnPlayer.HandCardObjects)
  2317. {
  2318. handCard.Outline_Select.gameObject.SetActive(false);
  2319. handCard1.RemoveSelectEffect();
  2320. handCard1.RemoveClickTarget();
  2321. handCard1.RemoveDragTarget();
  2322. }
  2323. #endregion
  2324. List<CardCommand> FieldUnitCommands = new List<CardCommand>();
  2325. #region Open launch effect command
  2326. if (handCard.cardSource.CanDeclareSkill)
  2327. {
  2328. List<ICardEffect> cardEffects = new List<ICardEffect>();
  2329. List<ICardEffect> cardEffects1 = new List<ICardEffect>();
  2330. foreach (ICardEffect cardEffect in handCard.cardSource.EffectList(EffectTiming.OnDeclaration))
  2331. {
  2332. cardEffects1.Add(cardEffect);
  2333. cardEffects.Add(cardEffect);
  2334. }
  2335. cardEffects.Reverse();
  2336. foreach (ICardEffect cardEffect in cardEffects)
  2337. {
  2338. if (cardEffect is ActivateICardEffect)
  2339. {
  2340. CardCommand SkillCommand = new CardCommand(cardEffect.EffectName, OnClick_SetUseSkillUnit_RPC, cardEffect.CanUse(null), DataBase.CommandColor_Skill);
  2341. FieldUnitCommands.Add(SkillCommand);
  2342. void OnClick_SetUseSkillUnit_RPC()
  2343. {
  2344. #region Reset cards on the field
  2345. foreach (Player player in gameContext.Players)
  2346. {
  2347. foreach (FieldPermanentCard fieldPermanentCard in player.FieldPermanentObjects)
  2348. {
  2349. fieldPermanentCard.RemoveSelectEffect();
  2350. fieldPermanentCard.RemoveClickTarget();
  2351. fieldPermanentCard.RemoveDragTarget();
  2352. fieldPermanentCard.Outline_Select.gameObject.SetActive(false);
  2353. fieldPermanentCard.CloseCommandPanel();
  2354. }
  2355. }
  2356. #endregion
  2357. #region Reset cards in hand
  2358. foreach (HandCard handCard1 in gameContext.TurnPlayer.HandCardObjects)
  2359. {
  2360. handCard.Outline_Select.gameObject.SetActive(false);
  2361. handCard1.RemoveSelectEffect();
  2362. handCard1.RemoveClickTarget();
  2363. handCard1.RemoveDragTarget();
  2364. }
  2365. #endregion
  2366. handCard.GetComponent<Draggable_HandCard>().CanPointerEnterExitAction = true;
  2367. QueueMainPhaseAction(gameContext.TurnPlayer, new ActivateCardAction(handCard.cardSource.CardIndex, cardEffects1.IndexOf(cardEffect)));
  2368. }
  2369. }
  2370. }
  2371. }
  2372. #endregion
  2373. handCard.handCardCommandPanel.SetUpCommandPanel(FieldUnitCommands, null, handCard);
  2374. handCard.AddClickTarget((_fieldUnitCard) => StartCoroutine(SetMainPhase()));
  2375. handCard.Outline_Select.gameObject.SetActive(true);
  2376. handCard.SetOrangeOutline();
  2377. }
  2378. }
  2379. #endregion
  2380. }
  2381. #endregion
  2382. }
  2383. #endregion
  2384. }
  2385. #endregion
  2386. #region Get whether the card in hand is playable
  2387. IEnumerator SetHandCardPlayablity(CardSource cardSource)
  2388. {
  2389. FieldCardFrame foundEmptyFrame = GManager.instance.You.fieldCardFrames
  2390. .Find(fieldCardFrame => fieldCardFrame.IsEmptyFrame() && fieldCardFrame.IsBattleAreaFrame());
  2391. bool canPlayEmpty = foundEmptyFrame != null && cardSource.CanPlayCardTargetFrame(foundEmptyFrame, true, null);
  2392. _canPlayEmptyFrame = canPlayEmpty;
  2393. _canPlayTargetFrames = new bool[GManager.instance.You.fieldCardFrames.Count];
  2394. _canDigivolves = new bool[GManager.instance.You.fieldCardFrames.Count];
  2395. _canJogresses = new bool[GManager.instance.You.fieldCardFrames.Count];
  2396. _canBursts = new bool[GManager.instance.You.fieldCardFrames.Count];
  2397. _canAppFusions = new bool[GManager.instance.You.fieldCardFrames.Count];
  2398. _payingCosts = new int[GManager.instance.You.fieldCardFrames.Count];
  2399. if (cardSource.IsDigimon)
  2400. {
  2401. List<FieldCardFrame> FramesWithPermanent = GManager.instance.You.fieldCardFrames.Filter(frame => frame.GetFramePermanent() != null);
  2402. foreach (FieldCardFrame frame in FramesWithPermanent)
  2403. {
  2404. int frameIndex = GManager.instance.You.fieldCardFrames.IndexOf(frame);
  2405. FieldCardFrame fieldCardFrame = GManager.instance.You.fieldCardFrames[frameIndex];
  2406. Permanent targetPermanent = fieldCardFrame.GetFramePermanent();
  2407. bool canPlay = targetPermanent == null ? canPlayEmpty : cardSource.CanPlayCardTargetFrame(fieldCardFrame, true, null);
  2408. bool canDigivolve = targetPermanent != null && cardSource.CanEvolve(targetPermanent, true);
  2409. bool canJogress = targetPermanent != null && cardSource.CanJogressFromTargetPermanent(targetPermanent, true);
  2410. bool canBurst = targetPermanent != null && cardSource.CanBurstDigivolutionFromTargetPermanent(targetPermanent, true);
  2411. bool canAppFusion = targetPermanent != null && cardSource.CanAppFusionFromTargetPermanent(targetPermanent, true);
  2412. _canPlayTargetFrames[frameIndex] = canPlay || canJogress || canBurst || canAppFusion;
  2413. _canDigivolves[frameIndex] = canDigivolve;
  2414. _canJogresses[frameIndex] = canJogress;
  2415. _canBursts[frameIndex] = canBurst;
  2416. _canAppFusions[frameIndex] = canAppFusion;
  2417. List<int> payingCosts = new List<int>(); ;
  2418. int minPayingCost = 0;
  2419. payingCosts.Add(cardSource.PayingCost(SelectCardEffect.Root.Hand, new List<Permanent>() { targetPermanent }, checkAvailability: false));
  2420. if (canJogress)
  2421. {
  2422. foreach(JogressCondition dnaCondition in cardSource.jogressCondition)
  2423. payingCosts.Add(cardSource.GetPayingCostWithBaseCost(dnaCondition.cost, SelectCardEffect.Root.Hand, new List<Permanent>() { targetPermanent }, checkAvailability: false));
  2424. }
  2425. if (canBurst)
  2426. {
  2427. payingCosts.Add(cardSource.GetPayingCostWithBaseCost(cardSource.burstDigivolutionCondition.cost, SelectCardEffect.Root.Hand, new List<Permanent>() { targetPermanent }, checkAvailability: false));
  2428. }
  2429. if (canAppFusion)
  2430. {
  2431. payingCosts.Add(cardSource.GetPayingCostWithBaseCost(cardSource.appFusionCondition.cost, SelectCardEffect.Root.Hand, new List<Permanent>() { targetPermanent }, checkAvailability: false));
  2432. }
  2433. if (payingCosts.Count > 1)
  2434. {
  2435. minPayingCost = payingCosts.Min();
  2436. }
  2437. else if (payingCosts.Count == 1)
  2438. {
  2439. minPayingCost = payingCosts[0];
  2440. }
  2441. _payingCosts[frameIndex] = minPayingCost;
  2442. yield return null;
  2443. }
  2444. }
  2445. else if (cardSource.IsTamer)
  2446. {
  2447. for (int i = 0; i < GManager.instance.You.fieldCardFrames.Count; i++)
  2448. {
  2449. FieldCardFrame fieldCardFrame = GManager.instance.You.fieldCardFrames[i];
  2450. Permanent targetPermanent = fieldCardFrame.GetFramePermanent();
  2451. bool canPlay = targetPermanent == null && canPlayEmpty;
  2452. _canPlayTargetFrames[i] = canPlay;
  2453. _payingCosts[i] = cardSource.PayingCost(SelectCardEffect.Root.Hand, new List<Permanent>() { targetPermanent }, checkAvailability: false);
  2454. yield return null;
  2455. }
  2456. }
  2457. }
  2458. #endregion
  2459. #region Reset UI display/click/drag operations
  2460. void ResetUI()
  2461. {
  2462. foreach (Player player in gameContext.Players)
  2463. {
  2464. player.brainStormObject.EndBrainStorm();
  2465. OffHandCardTarget(player);
  2466. OffFieldCardTarget(player);
  2467. player.securityObject.RemoveClickTarget();
  2468. foreach (HandCard handCard in player.HandCardObjects)
  2469. {
  2470. handCard.RemoveSelectEffect();
  2471. handCard.RemoveClickTarget();
  2472. handCard.RemoveDragTarget();
  2473. handCard.Outline_Select.gameObject.SetActive(false);
  2474. handCard.transform.GetChild(0).gameObject.SetActive(true);
  2475. }
  2476. foreach (FieldPermanentCard fieldPermanentCard in player.FieldPermanentObjects)
  2477. {
  2478. fieldPermanentCard.RemoveSelectEffect();
  2479. fieldPermanentCard.RemoveClickTarget();
  2480. fieldPermanentCard.RemoveDragTarget();
  2481. fieldPermanentCard.CloseCommandPanel();
  2482. }
  2483. foreach (FieldCardFrame fieldCardFrame in player.fieldCardFrames)
  2484. {
  2485. fieldCardFrame.OffFrame_Select();
  2486. }
  2487. player.playMatCardFrame.OffFrame_Select();
  2488. player.securityObject.securityBreakGlass.gameObject.SetActive(false);
  2489. player.securityObject.OffShowSecurityAttackObject();
  2490. }
  2491. GManager.instance.memoryObject.OffMemoryPredictionLine();
  2492. GManager.instance.You.playMatCardFrame.Frame.transform.parent.gameObject.SetActive(false);
  2493. GManager.instance.BackButton.CloseSelectCommandButton();
  2494. GManager.instance.selectCommandPanel.CloseSelectCommandPanel();
  2495. GManager.instance.commandText.CloseCommandText();
  2496. }
  2497. #endregion
  2498. #region Queue Main Phase Action
  2499. public void QueueMainPhaseAction(Player player, MainPhaseAction action)
  2500. {
  2501. photonView.RPC("QueueMainPhaseAction_Internal", RpcTarget.All, player.PlayerID, GamePacketFactory.GetId(action.GetType()), action.Serialize());
  2502. }
  2503. [PunRPC]
  2504. void QueueMainPhaseAction_Internal(int playerID, byte packetId, byte[] bytes)
  2505. {
  2506. Player player = GManager.instance.GetPlayerFromID(playerID);
  2507. if (player == null)
  2508. {
  2509. return;
  2510. }
  2511. MainPhaseAction action = GamePacketFactory.Create(packetId, bytes) as MainPhaseAction;
  2512. if (action != null)
  2513. {
  2514. player.QueueMainPhaseAction(action);
  2515. }
  2516. }
  2517. #endregion
  2518. #region Activation effect permanent determination
  2519. public void SetActSkill(int permanentIndex, int skillIndex)
  2520. {
  2521. List<Permanent> feild = gameContext.TurnPlayer.GetFieldPermanents();
  2522. if (permanentIndex < 0 || permanentIndex >= feild.Count)
  2523. {
  2524. return;
  2525. }
  2526. Permanent UseSkillPermanent = feild[permanentIndex];
  2527. if (0 <= skillIndex && skillIndex < UseSkillPermanent.EffectList(EffectTiming.OnDeclaration).Count)
  2528. {
  2529. this.UseCardEffect = UseSkillPermanent.EffectList(EffectTiming.OnDeclaration)[skillIndex];
  2530. }
  2531. }
  2532. #endregion
  2533. #region Activation effect card determination
  2534. public void SetActCardSkill(int cardIndex, int skillIndex)
  2535. {
  2536. if (cardIndex < 0 || cardIndex >= gameContext.ActiveCardList.Count)
  2537. {
  2538. return;
  2539. }
  2540. CardSource UseSkillCard = gameContext.ActiveCardList[cardIndex];
  2541. if (0 <= skillIndex && skillIndex < UseSkillCard.EffectList(EffectTiming.OnDeclaration).Count)
  2542. {
  2543. this.UseCardEffect = UseSkillCard.EffectList(EffectTiming.OnDeclaration)[skillIndex];
  2544. }
  2545. }
  2546. #endregion
  2547. #region Play card decision
  2548. public void SetPlayCard(int cardIndex, int TargetFrameID, int[] JogressEvoRootsFrameIDs, int BurstTamerFrameID, int[] AppFusionFrameIDs)
  2549. {
  2550. if (cardIndex < 0 || cardIndex >= gameContext.ActiveCardList.Count)
  2551. {
  2552. return;
  2553. }
  2554. PlayCard = gameContext.ActiveCardList[cardIndex];
  2555. this.TargetFrameID = TargetFrameID;
  2556. if (JogressEvoRootsFrameIDs != null)
  2557. {
  2558. if (JogressEvoRootsFrameIDs.Length == 2)
  2559. {
  2560. this.JogressEvoRootsFrameIDs = new int[JogressEvoRootsFrameIDs.Length];
  2561. for (int i = 0; i < JogressEvoRootsFrameIDs.Length; i++)
  2562. {
  2563. this.JogressEvoRootsFrameIDs[i] = JogressEvoRootsFrameIDs[i];
  2564. }
  2565. }
  2566. }
  2567. this.BurstTamerFrameID = BurstTamerFrameID;
  2568. if (AppFusionFrameIDs != null)
  2569. {
  2570. if (AppFusionFrameIDs.Length == 2)
  2571. {
  2572. this.AppFusionFrameIDs = new int[AppFusionFrameIDs.Length];
  2573. for (int i = 0; i < AppFusionFrameIDs.Length; i++)
  2574. {
  2575. this.AppFusionFrameIDs[i] = AppFusionFrameIDs[i];
  2576. }
  2577. }
  2578. }
  2579. }
  2580. #endregion
  2581. #region Attack permanent determination
  2582. public void SetAttackingPermaent(int permanentIndex, int attackTargetPermanentIndex)
  2583. {
  2584. List<Permanent> turnPlayerField = gameContext.TurnPlayer.GetFieldPermanents();
  2585. List<Permanent> nonTurnPlayerFeid = gameContext.NonTurnPlayer.GetFieldPermanents();
  2586. AttackingPermanent = null;
  2587. DefendingPermanent = null;
  2588. if (permanentIndex >= 0 && permanentIndex < turnPlayerField.Count)
  2589. {
  2590. AttackingPermanent = turnPlayerField[permanentIndex];
  2591. }
  2592. if (attackTargetPermanentIndex >= 0 && attackTargetPermanentIndex < nonTurnPlayerFeid.Count)
  2593. {
  2594. DefendingPermanent = nonTurnPlayerFeid[attackTargetPermanentIndex];
  2595. }
  2596. }
  2597. #endregion
  2598. #endregion
  2599. #region end phase
  2600. public bool Passed { get; set; } = true;
  2601. IEnumerator EndPhase()
  2602. {
  2603. #region Add log
  2604. PlayLog.OnAddLog?.Invoke($"\nEnd Turn:\n{gameContext.TurnPlayer.PlayerName}\n");
  2605. #endregion
  2606. #region Deselect
  2607. OffHandCardTarget(gameContext.TurnPlayer);
  2608. OffFieldCardTarget(gameContext.TurnPlayer);
  2609. #endregion
  2610. isSync = true;
  2611. gameContext.TurnPhase = GameContext.phase.End;
  2612. Debug.Log($"{gameContext.TurnPlayer}:End Phase");
  2613. yield return GManager.instance.photonWaitController.StartWait("EndPhase");
  2614. isSync = false;
  2615. isFirstPlayerFirstTurn = false;
  2616. //Automatic processing check timing
  2617. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  2618. #region Reset status until end of turn
  2619. GManager.instance.attackProcess.AttackCount = 0;
  2620. foreach (Player player in gameContext.Players)
  2621. {
  2622. player.UntilEachTurnEndEffects = new List<Func<EffectTiming, ICardEffect>>();
  2623. player.UntilCalculateFixedCostEffect = new List<Func<EffectTiming, ICardEffect>>();
  2624. player.DigivolveCount_ThisTurn = 0;
  2625. foreach (Permanent permanent in player.GetFieldPermanents())
  2626. {
  2627. permanent.UntilEachTurnEndEffects = new List<Func<EffectTiming, ICardEffect>>();
  2628. }
  2629. }
  2630. foreach (Permanent permanent in gameContext.TurnPlayer.GetFieldPermanents())
  2631. {
  2632. permanent.UntilOwnerTurnEndEffects = new List<Func<EffectTiming, ICardEffect>>();
  2633. }
  2634. gameContext.NonTurnPlayer.UntilOpponentTurnEndEffects = new List<Func<EffectTiming, ICardEffect>>();
  2635. gameContext.TurnPlayer.UntilOwnerTurnEndEffects = new List<Func<EffectTiming, ICardEffect>>();
  2636. foreach (Permanent pokemon in gameContext.NonTurnPlayer.GetFieldPermanents())
  2637. {
  2638. pokemon.UntilOpponentTurnEndEffects = new List<Func<EffectTiming, ICardEffect>>();
  2639. }
  2640. #endregion
  2641. #region Reset the number of times the effect is used
  2642. foreach (CardSource cardSource in gameContext.ActiveCardList)
  2643. {
  2644. cardSource.cEntity_EffectController.InitUseCountThisTurn();
  2645. }
  2646. #endregion
  2647. }
  2648. #endregion
  2649. #region resetting of selection status
  2650. #region Release waiting status of cards in hand for selection
  2651. public void OffHandCardTarget(Player player)
  2652. {
  2653. foreach (HandCard _handCard in player.HandCardObjects)
  2654. {
  2655. if (_handCard != null)
  2656. {
  2657. _handCard.RemoveDragTarget();
  2658. _handCard.RemoveClickTarget();
  2659. _handCard.RemoveSelectEffect();
  2660. _handCard.handCardCommandPanel.CloseCommandPanel();
  2661. _handCard.OffPlayText();
  2662. }
  2663. }
  2664. }
  2665. #endregion
  2666. #region Release waiting status of cards in the field for selection
  2667. public void OffFieldCardTarget(Player player)
  2668. {
  2669. foreach (FieldPermanentCard fieldPermanentCard in player.FieldPermanentObjects)
  2670. {
  2671. fieldPermanentCard.RemoveClickTarget();
  2672. fieldPermanentCard.CloseCommandPanel();
  2673. fieldPermanentCard.Outline_Select.gameObject.SetActive(false);
  2674. }
  2675. }
  2676. #endregion
  2677. #endregion
  2678. #region Game over
  2679. public bool endGame { get; set; } = false;
  2680. public void OnClickSurrenderButton()
  2681. {
  2682. int localPlayerID = 0;
  2683. if (PhotonNetwork.IsMasterClient)
  2684. {
  2685. localPlayerID = 0;
  2686. }
  2687. else
  2688. {
  2689. localPlayerID = 1;
  2690. }
  2691. photonView.RPC("Surrender", RpcTarget.All, localPlayerID);
  2692. }
  2693. [PunRPC]
  2694. public void Surrender(int loserPlayerID)
  2695. {
  2696. Player player = null;
  2697. if (loserPlayerID == 0)
  2698. {
  2699. if (PhotonNetwork.IsMasterClient)
  2700. {
  2701. player = GManager.instance.You;
  2702. }
  2703. else
  2704. {
  2705. player = GManager.instance.Opponent;
  2706. }
  2707. }
  2708. else if (loserPlayerID == 1)
  2709. {
  2710. if (PhotonNetwork.IsMasterClient)
  2711. {
  2712. player = GManager.instance.Opponent;
  2713. }
  2714. else
  2715. {
  2716. player = GManager.instance.You;
  2717. }
  2718. }
  2719. if (player != null)
  2720. {
  2721. EndGame(player.Enemy, true);
  2722. }
  2723. //EndGame(gameContext.NonTurnPlayer, true);
  2724. }
  2725. public void EndGame(Player Winner, bool Surrendered, string effectName = "")
  2726. {
  2727. foreach (GameObject gb in GManager.instance.CloseWhenEndingGameObjects)
  2728. {
  2729. if (gb != null)
  2730. {
  2731. gb.SetActive(false);
  2732. }
  2733. }
  2734. ContinuousController.instance.CanSetRandom = false;
  2735. GManager.instance.photonWaitController.ResetKeys();
  2736. if (PhotonNetwork.InRoom)
  2737. {
  2738. PhotonNetwork.CurrentRoom.SetCustomProperties(new ExitGames.Client.Photon.Hashtable());
  2739. }
  2740. if (!ContinuousController.instance.isRandomMatch && !ContinuousController.instance.isAI)
  2741. {
  2742. Debug.Log("Player property initialization");
  2743. PhotonNetwork.LocalPlayer.SetCustomProperties(new ExitGames.Client.Photon.Hashtable());
  2744. }
  2745. endGame = true;
  2746. if (gameContext.TurnPlayer != null)
  2747. {
  2748. OffFieldCardTarget(gameContext.TurnPlayer);
  2749. OffHandCardTarget(gameContext.TurnPlayer);
  2750. }
  2751. foreach (Player player in gameContext.Players)
  2752. {
  2753. player.securityObject.OffShowSecurityAttackObject();
  2754. }
  2755. GManager.instance.optionPanel.Close_(false);
  2756. GManager.instance.LoadingObject.gameObject.SetActive(false);
  2757. GManager.instance.resultObject.ShowResult(Winner, Surrendered, effectName);
  2758. EventSystem.current.SetSelectedGameObject(GManager.instance.resultObject.transform.GetChild(3).gameObject);
  2759. GManager.instance.commandText.CloseCommandText();
  2760. StopAllCoroutines();
  2761. GManager.instance.StopAllCoroutines();
  2762. ContinuousController.instance.StopAllCoroutines();
  2763. ContinuousController.instance.StartCoroutine(GManager.instance.BattleBGM.FadeOut(1));
  2764. if (GManager.instance.isAuto && GManager.instance.IsAI)
  2765. {
  2766. ContinuousController.instance.isAI = true;
  2767. UnityEngine.SceneManagement.SceneManager.LoadScene("BattleScene");
  2768. }
  2769. }
  2770. #endregion
  2771. #region Go to the next phase
  2772. public void PassTurn()
  2773. {
  2774. if (gameContext.TurnPhase == GameContext.phase.Main)
  2775. {
  2776. ResetUI();
  2777. ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.EndTurnProcess());
  2778. }
  2779. }
  2780. #endregion
  2781. }