GManager.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. using Photon.Pun;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. public class GManager : MonoBehaviourPun
  9. {
  10. [Header("あなた")]
  11. public Player You;
  12. [Header("対戦相手")]
  13. public Player Opponent;
  14. [Header("CardSourceプレハブ")]
  15. public CardSource CardPrefab;
  16. [Header("場のポケモンカードプレハブ")]
  17. public FieldPermanentCard fieldCardPrefab;
  18. [Header("手札のカードプレハブ")]
  19. public HandCard handCardPrefab;
  20. [Header("読み込み中オブジェクト")]
  21. public LoadingObject LoadingObject;
  22. [Header("コマンド選択パネル")]
  23. public SelectCommandPanel selectCommandPanel;
  24. [Header("戻るボタン")]
  25. public SelectCommand BackButton;
  26. [Header("結果表示オブジェクト")]
  27. public ResultObject resultObject;
  28. [Header("メッセージテキスト")]
  29. public CommandText commandText;
  30. [Header("ターンプレイヤー表示")]
  31. public ShowTurnPlayerObject showTurnPlayerObject;
  32. [Header("フェイズ通知")]
  33. public ShowPhaseNotificationObject showPhaseNotificationObject;
  34. [Header("キャンバス")]
  35. public Canvas canvas;
  36. [Header("キャンバス2")]
  37. public Canvas canvas2;
  38. [Header("カード詳細")]
  39. public CardDetail cardDetail;
  40. [Header("パーマネント詳細")]
  41. public PermanentDetail pokemonDetail;
  42. [Header("カード選択パネル")]
  43. public SelectCardPanel selectCardPanel;
  44. [Header("カード確認パネル")]
  45. public CheckCardPanel checkCardPanel;
  46. [Header("次のフェイズに進むボタン")]
  47. public NextPhaseButton nextPhaseButton;
  48. [Header("設定パネル")]
  49. public OptionPanel optionPanel;
  50. [Header("ターゲット矢印プレハブ")]
  51. public TargetArrow targetArrowPrefab;
  52. [Header("ターゲット矢印親")]
  53. public Transform targetArrowParent;
  54. [Header("Camera")]
  55. public Camera camara;
  56. [Header("StartBattleSE")]
  57. public AudioClip StartBattleSE;
  58. [Header("自動処理チェック")]
  59. public AutoProcessing autoProcessing;
  60. [Header("プレイログ")]
  61. public PlayLog playLog;
  62. [Header("メモリー")]
  63. public MemoryObject memoryObject;
  64. [Header("背景")]
  65. public Image BackgroundImage;
  66. [Header("背景")]
  67. public SpriteRenderer BackgroundSpriteRenderer;
  68. [Header("攻撃処理")]
  69. public AttackProcess attackProcess;
  70. [Header("ジョグレス選択")]
  71. public SelectJogressEffect selectJogressEffect;
  72. public SelectDNACondition selectDNACondition;
  73. [Header("burst evolution selection")]
  74. public SelectBurstDigivolutionEffect selectBurstDigivolutionEffect;
  75. [Header("app fusion selection")]
  76. public SelectAppFusionEffect selectAppFusionEffect;
  77. [Header("自動処理チェック(割り込み処理)")]
  78. public AutoProcessing autoProcessing_CutIn;
  79. [Header("ユーザー選択")]
  80. public UserSelectionManager userSelectionManager;
  81. [Header("選択可能なものだけ表示")]
  82. public HideCannotSelectObject hideCannotSelectObject;
  83. [Header("サイドバー")]
  84. public SideBar sideBar;
  85. [Header("UseSkillSE")]
  86. public AudioClip UseSkillSE;
  87. [Header("サイド取得SE")]
  88. public AudioClip GetSideSE;
  89. [Header("DeleteHandSE")]
  90. public AudioClip DeleteHandSE;
  91. [Header("エネルギー追加SE")]
  92. public AudioClip AddEnergySE;
  93. [Header("ShowPlayCardSE")]
  94. public AudioClip ShowPlayCardSE;
  95. [Header("ポケモンプレイ時SE")]
  96. public AudioClip PlayPokemonSE;
  97. [Header("ShuffleSE")]
  98. public AudioClip ShuffleSE;
  99. [Header("DrawSE")]
  100. public AudioClip DrawSE;
  101. [Header("TargetArrowSE")]
  102. public AudioClip TargetArrowSE;
  103. [Header("MoveSE")]
  104. public AudioClip MoveSE;
  105. [Header("気絶SE")]
  106. public AudioClip KnockOutSE;
  107. [Header("ダメージSE")]
  108. public AudioClip DamageSE;
  109. [Header("コイントスSE")]
  110. public AudioClip CointTossSE;
  111. [Header("回復SE")]
  112. public AudioClip HealSE;
  113. [Header("毒SE")]
  114. public AudioClip PoisonSE;
  115. [Header("火傷SE")]
  116. public AudioClip BurnedSE;
  117. [Header("WinSE")]
  118. public AudioClip WinSE;
  119. [Header("LoseSE")]
  120. public AudioClip LoseSE;
  121. [Header("DecisionSE")]
  122. [SerializeField] AudioClip DecisionSE;
  123. [Header("CancelSE")]
  124. [SerializeField] AudioClip CancelSE;
  125. [Header("BGM")]
  126. public List<AudioClip> bgms;
  127. [Header("BGMObject")]
  128. public BGMObject BattleBGM;
  129. [Header("オートモード")]
  130. public bool isAuto;
  131. [Header("進化演出")]
  132. public EvolutionEffectObject EvolutionEffectObject;
  133. [Header("ジョグレス進化演出")]
  134. public JogressEffectObject jogressEffectObject;
  135. [Header("デジクロス演出")]
  136. public DigiXrosEffectObject digiXrosEffectObject;
  137. [Header("バースト進化演出")]
  138. public BurstEffectObject burstEffectObject;
  139. [Header("Background Particle effects")]
  140. [SerializeField] List<ParticleSystem> _backgroundParticles = new List<ParticleSystem>();
  141. [Header("Photon wait controller")]
  142. public PhotonWaitController photonWaitController;
  143. [Header("Gameobjects closed when ending game")]
  144. public List<GameObject> CloseWhenEndingGameObjects = new List<GameObject>();
  145. //Turn progression management state machine
  146. public TurnStateMachine turnStateMachine { get; set; }
  147. public static GManager instance = null;
  148. public bool IsAI { get; private set; } = false;
  149. public int CardIndex { get; set; } = 0;
  150. public bool ActivateShortcuts = false;
  151. #region Events
  152. //Cards flipped
  153. public static Action OnReverseOpponentsCardsChanged;
  154. public static Action OnCardFlippedChanged;
  155. public static Action<Player> OnSecurityStackChanged;
  156. #endregion
  157. private async void Awake()
  158. {
  159. //return;
  160. if (Opening.instance != null)
  161. {
  162. if (Opening.instance.OpeningBGM != null)
  163. {
  164. Opening.instance.OpeningBGM.StopPlayBGM();
  165. }
  166. }
  167. instance = this;
  168. StartCoroutine(AwakeCoroutine());
  169. }
  170. IEnumerator AwakeCoroutine()
  171. {
  172. #if UNITY_EDITOR
  173. #endif
  174. if (!PhotonNetwork.IsConnected)
  175. {
  176. IsAI = true;
  177. }
  178. if (ContinuousController.instance != null)
  179. {
  180. if (ContinuousController.instance.isAI)
  181. {
  182. IsAI = true;
  183. }
  184. }
  185. if (!IsAI)
  186. {
  187. isAuto = false;
  188. }
  189. turnStateMachine = gameObject.AddComponent<TurnStateMachine>();
  190. GetComponent<Effects>().Init();
  191. playLog.Init();
  192. hideCannotSelectObject.Init();
  193. ChangeBackground();
  194. yield return StartCoroutine(Init());
  195. StartCoroutine(turnStateMachine.Init());
  196. StartCoroutine(CheckDisconnect());
  197. if (Opening.instance != null)
  198. {
  199. Opening.instance.openingObject.SetActive(false);
  200. }
  201. Debug.Log("Battle Initialization");
  202. yield return new WaitWhile(() => ContinuousController.instance == null);
  203. ContinuousController.instance.CanSetRandom = true;
  204. }
  205. protected virtual void OnDestroy()
  206. {
  207. if (instance == this)
  208. {
  209. instance = null;
  210. }
  211. }
  212. public void PlayDecisionSE()
  213. {
  214. ContinuousController.instance.PlaySE(DecisionSE);
  215. }
  216. public void PlayCancelSE()
  217. {
  218. ContinuousController.instance.PlaySE(CancelSE);
  219. }
  220. public async void ChangeBackground()
  221. {
  222. Sprite backgroundSprite = await StreamingAssetsUtility.GetSprite("Background_battle");
  223. if (backgroundSprite != null)
  224. {
  225. BackgroundImage.sprite = backgroundSprite;
  226. BackgroundSpriteRenderer.sprite = backgroundSprite;
  227. BackgroundImage.gameObject.SetActive(true);
  228. BackgroundSpriteRenderer.transform.localPosition = new Vector3(-134, BackgroundSpriteRenderer.transform.localPosition.y, -77f);
  229. BackgroundSpriteRenderer.gameObject.SetActive(true);
  230. }
  231. else
  232. {
  233. BackgroundImage.gameObject.SetActive(false);
  234. BackgroundSpriteRenderer.gameObject.SetActive(false);
  235. }
  236. }
  237. IEnumerator CheckDisconnect()
  238. {
  239. if (IsAI)
  240. {
  241. yield break;
  242. }
  243. yield return new WaitWhile(() => turnStateMachine == null);
  244. yield return new WaitForSeconds(5f);
  245. while (true)
  246. {
  247. if (!PhotonNetwork.IsConnected)
  248. {
  249. break;
  250. }
  251. else
  252. {
  253. if (!PhotonNetwork.InRoom)
  254. {
  255. break;
  256. }
  257. else
  258. {
  259. if (PhotonNetwork.CurrentRoom != null)
  260. {
  261. if (PhotonNetwork.PlayerList.Length < 2)
  262. {
  263. break;
  264. }
  265. }
  266. }
  267. }
  268. yield return null;
  269. }
  270. if (!turnStateMachine.endGame)
  271. {
  272. turnStateMachine.EndGame(null, false);
  273. }
  274. }
  275. public IEnumerator Init()
  276. {
  277. yield return StartCoroutine(LoadingObject.StartLoading("Now Loading"));
  278. selectCommandPanel.Off();
  279. BackButton.CloseSelectCommandButton();
  280. resultObject.Init();
  281. commandText.Init();
  282. sideBar.Init();
  283. showTurnPlayerObject.Init();
  284. showPhaseNotificationObject.Init();
  285. OffTargetArrow();
  286. cardDetail.CloseCardDetail();
  287. pokemonDetail.CloseUnitDetail();
  288. selectCardPanel.CloseSelectCardPanel();
  289. yield return StartCoroutine(checkCardPanel.CloseSelectCardPanelCoroutine());
  290. optionPanel.Init();
  291. EvolutionEffectObject.Init();
  292. jogressEffectObject.Init();
  293. digiXrosEffectObject.Init();
  294. burstEffectObject.Init();
  295. }
  296. public void ReturnToTitle()
  297. {
  298. ContinuousController.instance.EndBattle();
  299. }
  300. public void ReportBug()
  301. {
  302. Application.OpenURL("https://forms.gle/GhZgGVJS1qLeUMcG8");
  303. }
  304. public void OnClickSurrenderButton()
  305. {
  306. if (turnStateMachine != null)
  307. {
  308. if (turnStateMachine.endGame)
  309. {
  310. return;
  311. }
  312. turnStateMachine.OnClickSurrenderButton();
  313. }
  314. }
  315. public TargetArrow CreateTargetArrow()
  316. {
  317. TargetArrow targetArrow = Instantiate(targetArrowPrefab, targetArrowParent);
  318. return targetArrow;
  319. }
  320. public Coroutine OnTargetArrow(Vector3 InitialPosition, Vector3 targetPosition, FieldPermanentCard StartFieldUnitCard, FieldPermanentCard EndFieldUnitCard)
  321. {
  322. TargetArrow targetArrow = CreateTargetArrow();
  323. return targetArrow.OnTargetArrow(InitialPosition, targetPosition, StartFieldUnitCard, EndFieldUnitCard);
  324. }
  325. public void OffTargetArrow()
  326. {
  327. if (targetArrowParent.childCount > 0)
  328. {
  329. if (targetArrowParent.GetChild(targetArrowParent.childCount - 1).GetComponent<TargetArrow>() != null)
  330. {
  331. targetArrowParent.GetChild(targetArrowParent.childCount - 1).GetComponent<TargetArrow>().Destroyed = true;
  332. }
  333. Destroy(targetArrowParent.GetChild(targetArrowParent.childCount - 1).gameObject);
  334. }
  335. }
  336. void Update()
  337. {
  338. if (ContinuousController.instance != null)
  339. {
  340. foreach (ParticleSystem particleSystem in _backgroundParticles)
  341. {
  342. if (particleSystem != null)
  343. {
  344. particleSystem.gameObject.SetActive(ContinuousController.instance.showBackgroundParticle);
  345. }
  346. }
  347. }
  348. if (Input.GetKey(KeyCode.LeftControl) &&
  349. Input.GetKey(KeyCode.LeftShift) &&
  350. Input.GetKey(KeyCode.LeftAlt) &&
  351. Input.GetKeyDown(KeyCode.A))
  352. ActivateShortcuts = !ActivateShortcuts;
  353. AllowAlphaInputs();
  354. }
  355. void AllowAlphaInputs()
  356. {
  357. if (ContinuousController.instance.isRandomMatch && !ContinuousController.instance.isAI)
  358. return;
  359. if (turnStateMachine == null)
  360. return;
  361. if (!ActivateShortcuts)
  362. return;
  363. //Draw a card
  364. if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.D))
  365. {
  366. photonView.RPC("DrawCardRPC", RpcTarget.Others);
  367. StartCoroutine(DrawCard(You));
  368. }
  369. //Trash a card
  370. if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.T))
  371. {
  372. photonView.RPC("TrashCardRPC", RpcTarget.Others);
  373. StartCoroutine(TrashCard(You));
  374. }
  375. //Top deck a card
  376. if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.L))
  377. {
  378. photonView.RPC("TopDeckCardRPC", RpcTarget.Others);
  379. StartCoroutine(TopDeckCard(You));
  380. }
  381. //Place Top Security
  382. if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.R))
  383. {
  384. bool keyInput = Input.GetKey(KeyCode.LeftShift);
  385. photonView.RPC("PlaceInSecurityRPC", RpcTarget.Others, keyInput);
  386. StartCoroutine(PlaceInSecurity(You, keyInput));
  387. }
  388. //Gain Memory
  389. if(Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.Equals))
  390. {
  391. photonView.RPC("AlterMemoryRPC", RpcTarget.Others, -1);
  392. StartCoroutine(AlterMemory(You, 1));
  393. }
  394. //Lose Memory
  395. if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.Minus))
  396. {
  397. photonView.RPC("AlterMemoryRPC", RpcTarget.Others, 1);
  398. StartCoroutine(AlterMemory(You, -1));
  399. }
  400. }
  401. [PunRPC]
  402. public void DrawCardRPC()
  403. {
  404. StartCoroutine(DrawCard(Opponent));
  405. }
  406. [PunRPC]
  407. public void TrashCardRPC()
  408. {
  409. StartCoroutine(TrashCard(Opponent));
  410. }
  411. [PunRPC]
  412. public void TopDeckCardRPC()
  413. {
  414. StartCoroutine(TopDeckCard(Opponent));
  415. }
  416. [PunRPC]
  417. public void PlaceInSecurityRPC(bool keyInput)
  418. {
  419. StartCoroutine(PlaceInSecurity(Opponent, keyInput));
  420. }
  421. [PunRPC]
  422. public void AlterMemoryRPC(int value)
  423. {
  424. StartCoroutine(AlterMemory(Opponent,value));
  425. }
  426. public IEnumerator DrawCard(Player _player)
  427. {
  428. yield return StartCoroutine(new DrawClass(_player, 1, null).Draw());
  429. yield return StartCoroutine(turnStateMachine.SetMainPhase());
  430. }
  431. IEnumerator AlterMemory(Player _player, int value)
  432. {
  433. yield return StartCoroutine(You.AddMemory(value, null));
  434. yield return StartCoroutine(turnStateMachine.SetMainPhase());
  435. yield return StartCoroutine(autoProcessing.EndTurnCheck());
  436. }
  437. IEnumerator TrashCard(Player _player)
  438. {
  439. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  440. selectHandEffect.SetUp(
  441. selectPlayer: _player,
  442. canTargetCondition: (CardSource) => true,
  443. canTargetCondition_ByPreSelecetedList: null,
  444. canEndSelectCondition: null,
  445. maxCount: _player.HandCards.Count,
  446. canNoSelect: true,
  447. canEndNotMax: true,
  448. isShowOpponent: true,
  449. selectCardCoroutine: null,
  450. afterSelectCardCoroutine: null,
  451. mode: SelectHandEffect.Mode.Discard,
  452. cardEffect: null);
  453. yield return StartCoroutine(selectHandEffect.Activate());
  454. yield return StartCoroutine(turnStateMachine.SetMainPhase());
  455. }
  456. IEnumerator TopDeckCard(Player _player)
  457. {
  458. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  459. selectHandEffect.SetUp(
  460. selectPlayer: _player,
  461. canTargetCondition: (CardSource) => true,
  462. canTargetCondition_ByPreSelecetedList: null,
  463. canEndSelectCondition: null,
  464. maxCount: _player.HandCards.Count,
  465. canNoSelect: true,
  466. canEndNotMax: true,
  467. isShowOpponent: true,
  468. selectCardCoroutine: null,
  469. afterSelectCardCoroutine: null,
  470. mode: SelectHandEffect.Mode.PutLibraryTop,
  471. cardEffect: null);
  472. yield return StartCoroutine(selectHandEffect.Activate());
  473. yield return StartCoroutine(turnStateMachine.SetMainPhase());
  474. }
  475. IEnumerator PlaceInSecurity(Player _player, bool placeFaceup)
  476. {
  477. CardSource selectedSource = null;
  478. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  479. selectHandEffect.SetUp(
  480. selectPlayer: _player,
  481. canTargetCondition: (CardSource) => true,
  482. canTargetCondition_ByPreSelecetedList: null,
  483. canEndSelectCondition: null,
  484. maxCount: 1,
  485. canNoSelect: true,
  486. canEndNotMax: false,
  487. isShowOpponent: true,
  488. selectCardCoroutine: CardSelectCoroutine,
  489. afterSelectCardCoroutine: null,
  490. mode: SelectHandEffect.Mode.Custom,
  491. cardEffect: null);
  492. yield return StartCoroutine(selectHandEffect.Activate());
  493. IEnumerator CardSelectCoroutine(CardSource source)
  494. {
  495. if (source != null)
  496. selectedSource = source;
  497. yield return null;
  498. }
  499. if (selectedSource != null)
  500. {
  501. // Place this card face up as the top security card
  502. yield return StartCoroutine(CardObjectController.AddSecurityCard(selectedSource, toTop: true, faceUp: placeFaceup));
  503. }
  504. yield return StartCoroutine(turnStateMachine.SetMainPhase());
  505. }
  506. }