TurnStateMachine.cs 156 KB

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