TurnStateMachine.cs 159 KB

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