TurnStateMachine.cs 157 KB

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