TurnStateMachine.cs 156 KB

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