TurnStateMachine.cs 159 KB

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