TurnStateMachine.cs 161 KB

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