TurnStateMachine.cs 156 KB

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