using CodeJay.Enum; using System.Collections.Generic; using System.Linq; using UnityEngine; using Image = UnityEngine.UI.Image; public partial class GamePanel : MonoBehaviour { #region Statics public static void LogicalError(string message) { Debug.LogError(message); } #endregion public static float GameSpeed = 1f; public static GamePanel Instance; public GameObject CardSlotPrefab, go_toppanel, go_previewbtn, go_missionbtn; public CanvasGroup cg; public Image i_ai; public TMPro.TextMeshProUGUI AINameTMP, t_PointMoney; public TMPro.TextMeshProUGUI AIGoldTMP; private List _lstCardSlots; private int _prevScore_Player = 0; private int _prevScore_AI = 0; private bool _isFirstTurn_Player = true; private bool _isFirstTurn_AI = true; private float _delay = 0f; public bool IsChallengeMode { get; private set; } = false; public GamePanel_Effect EffectPanel { get; private set; } = null; private bool _isSelctedSepYulggetState = false; public bool UseSepYulgget_To_Pee { get; set; } = false; public int Player_Bell { get; set; } = 0; public int Player_Milgi { get; set; } = 0; public int AI_Bell { get; set; } = 0; public int Player_Bbug { get; set; } = 0; public int AI_Bbug { get; set; } = 0; public int Player_Go { get; set; } = 0; public int AI_Go { get; set; } = 0; public bool PlayerTurn { get; set; } = true; public bool GameOver { get; set; } = true; public int Stake { get; set; } = 100; public bool IsPreview { get; set; } = false; public Dictionary dic_missionRate = new Dictionary { { eMainMission.Godori, 5 }, { eMainMission.Chodan, 3 }, { eMainMission.Hongdan, 3 }, { eMainMission.Chungdan, 3 }, { eMainMission.Gwang5, 10 }, { eMainMission.Gwang4, 5 }, { eMainMission.All_1, 4 }, { eMainMission.All_2, 4 }, { eMainMission.All_3, 4 }, { eMainMission.All_4, 4 }, { eMainMission.All_5, 4 }, { eMainMission.All_6, 4 }, { eMainMission.All_7, 4 }, { eMainMission.All_8, 4 }, { eMainMission.All_9, 4 }, { eMainMission.All_10, 4 }, { eMainMission.All_11, 4 }, { eMainMission.All_12, 4 }, { eMainMission.Max, 0 } }; public Dictionary dic_submisstionRate = new Dictionary { { eSubMission.Dobule3, 3 }, { eSubMission.YulGgeut3, 3 }, { eSubMission.Ddee3, 3 }, { eSubMission.Gwang3, 3 }, { eSubMission.Be3Gwang, 2 }, { eSubMission.Max, 0 } }; public eMainMission CurMission = eMainMission.Max; bool ShowMainMissionPopup = false; public eSubMission CurSubMission = eSubMission.Max; bool ShowSubMissionPopup = false; #region MonoBehaviour private void Awake() { if (Instance == null) Instance = this; else Debug.LogError("Error!!!!"); EffectPanel = this.GetComponent(); if (GameManager.Instance != null) { GameManager.Event.RegistEvent(EEventType.OnStartNormalGame, this.StartNormalGame); GameManager.Event.RegistEvent(EEventType.OnChallengeStart, this.OnChallengeStart); GameManager.Event.RegistEvent(EEventType.OnReturnToHome, this.ReturnToHome); GameManager.Event.RegistEvent(EEventType.OnReturnToHunting, this.OnReturnToHunting); GameManager.Event.RegistEvent(EEventType.OnGameEnd, this.OnGameEnd); GameManager.Event.RegistEvent(EEventType.OnSynchronizeNormalGameData, this.UpdateAIGold); } if (_hashScoreMultiplyTypes == null) _hashScoreMultiplyTypes = new HashSet(); _hashScoreMultiplyTypes.Clear(); _dicCoroutineStates = new Dictionary(); for (EGameWorkFlowType i = 0; i < EGameWorkFlowType.Max; i++) _dicCoroutineStates.Add(i, EGameStateType.None); GameSpeed = GameManager.DB.GameSpeed; } private void Start() { this.GamePanelEnabled(false); } private void OnDestroy() { if (GameManager.Instance != null) { GameManager.Event.RemoveEvent(EEventType.OnStartNormalGame, this.StartNormalGame); GameManager.Event.RemoveEvent(EEventType.OnChallengeStart, this.OnChallengeStart); GameManager.Event.RemoveEvent(EEventType.OnReturnToHome, this.ReturnToHome); GameManager.Event.RemoveEvent(EEventType.OnReturnToHunting, this.OnReturnToHunting); GameManager.Event.RemoveEvent(EEventType.OnGameEnd, this.OnGameEnd); GameManager.Event.RemoveEvent(EEventType.OnSynchronizeNormalGameData, this.UpdateAIGold); } for (int i = 0; i < _lstCardSlots.Count; i++) { _lstCardSlots[i].DestroyCardSlot(); } } private void Update() { //if (Input.GetKeyDown(KeyCode.S)) // this.ShowLog(); if (GameOver) { return; } if (_delay > 0f) _delay -= Time.deltaTime * GameSpeed; else { _delay = 0f; switch (CurrentCoroutineType) { case EGameWorkFlowType.DistributeCard: this.DistributeStateMachine(); break; case EGameWorkFlowType.DiscardNEffectBeforeDiscard: this.DiscardStateMachine(); break; case EGameWorkFlowType.CheckMatchedCardAfterDiscard: this.CheckDiscardMatchedStateMachine(); break; case EGameWorkFlowType.FlipCenterCard: this.FlipCenterStateMachine(); break; case EGameWorkFlowType.BringTheGetableCards: this.BringGetableStateMachine(); break; case EGameWorkFlowType.CheckCombination: Debug.Log("CheckCombination Method!"); CurrentCoroutineType = EGameWorkFlowType.Max; StartCoroutine(coroCheckCombination()); break; case EGameWorkFlowType.CheckEndOrGoStop: Debug.Log("CheckEndOrGoStop Method!"); CurrentCoroutineType = EGameWorkFlowType.Max; StartCoroutine(coroCheckEndOrGoStop()); break; } } } #endregion private void GamePanelEnabled(bool b) { if (gameObject.activeInHierarchy != b) this.gameObject.SetActive(b); } private void StartNormalGame() { //GameManager.Flamingo.Flamingo.StartPlaySession(GameManager.DB.NormalGameLevel.ToString(), "Normal"); GameManager.Sound.PlaySFX(ESFXType.Start_1); IsChallengeMode = false; GameManager.DB.MinInterstitialADCount(1); // Get Highest Clear level var data = DB_HuntingData.GetEntity((GameManager.DB.GetUnlockTargetIndex(true) << 1) - 2); Stake = data.DBF_Stake; this.UpdateAIGold(); this.Initialize(); this.Shuffle(); this.FrontBonusCard(); this.SetGuideData(false); this.EnabledPlayerHandRaycast(false); _delay = 0.2f; GameOver = false; CurrentCoroutineType = EGameWorkFlowType.DistributeCard; GameManager.Event.InvokeEvent(EEventType.OnSynchronizeGameData); } private void ReturnToHome() { GameManager.Sound.PlayBGM(EBGMType.BGM_1); this.GamePanelEnabled(false); ECardType type = 0; for (int i = _lstCardSlots.Count - 1; i >= 0; i--) { if (_lstCardSlots[i].CardType == ECardType.FlipCard_1 || _lstCardSlots[i].CardType == ECardType.FlipCard_2) { CardSlot slot = _lstCardSlots[i]; _lstCardSlots.RemoveAt(i); Destroy(slot.gameObject); } else { _lstCardSlots[i].Initialize(CenterDeckRT); _lstCardSlots[i].SetData(type++); } } GameOver = true; } private void OnReturnToHunting() { GameManager.Sound.PlayBGM(EBGMType.BGM_1); this.GamePanelEnabled(false); ECardType type = 0; for (int i = _lstCardSlots.Count - 1; i >= 0; i--) { if (_lstCardSlots[i].CardType == ECardType.FlipCard_1 || _lstCardSlots[i].CardType == ECardType.FlipCard_2) { CardSlot slot = _lstCardSlots[i]; _lstCardSlots.RemoveAt(i); Destroy(slot.gameObject); } else { _lstCardSlots[i].Initialize(CenterDeckRT); _lstCardSlots[i].SetData(type++); } } GameOver = true; } public void StartNextGame() { // 두배면 두배 이펙트 실행 if(_hashScoreMultiplyTypes.Contains(EScoreMutiplyType.ClickedFromResultPopup)) { EffectPanel.Direct(EEffectDirectType.Double, true); } if (IsChallengeMode) GameManager.Event.InvokeEvent(EEventType.OnChallengeStart); else GameManager.Event.InvokeEvent(EEventType.OnStartNormalGame); } public void AddMultiplyType(EScoreMutiplyType type) { switch (type) { case EScoreMutiplyType.Go: case EScoreMutiplyType.Gobak: case EScoreMutiplyType.Peebak: case EScoreMutiplyType.Gwhangbak: case EScoreMutiplyType.Shake: case EScoreMutiplyType.Nagari: case EScoreMutiplyType.ClickedFromResultPopup: case EScoreMutiplyType.MeongTeonguri: case EScoreMutiplyType.MainMission: case EScoreMutiplyType.SubMission: _hashScoreMultiplyTypes.Add(type); break; case EScoreMutiplyType.Max: break; } } private void OnGameEnd() { if(IsChallengeMode) { //GameManager.Flamingo.Flamingo.EndPlaySession(GameManager.DB.GetUnlockTargetIndex().ToString(), "Hunting"); } else { //GameManager.Flamingo.Flamingo.EndPlaySession(GameManager.DB.NormalGameLevel.ToString(), "Normal"); } GameOver = true; CurrentCoroutineType = EGameWorkFlowType.Max; ResetScortMultiplyType(); for (int i = 0; i < _lstCardSlots.Count; i++) { _lstCardSlots[i].transform.SetParent(CenterDeckRT); } } private void OnChallengeStart() { ////GameManager.Flamingo.Flamingo.StartPlaySession(GameManager.DB.GetUnlockTargetIndex().ToString(), "Hunting"); //GameManager.Sound.PlaySFX(ESFXType.Start_1); //IsChallengeMode = true; //// Get Highest Clear level //var data = GameManager.DB.GetHuntingData(GameManager.DB.GetUnlockTargetIndex()); //this.UpdateAIGold(); //Stake = data.Stake; //this.Initialize(); //this.Shuffle(); //this.FrontBonusCard(); //this.SetGuideData(false); //this.EnabledPlayerHandRaycast(false); //_delay = 0.2f; //GameOver = false; //CurrentCoroutineType = EGameWorkFlowType.DistributeCard; //GameManager.Event.InvokeEvent(EEventType.OnSynchronizeGameData); } public void ResetScortMultiplyType() { _hashScoreMultiplyTypes.Clear(); if (Player_Milgi > 0) AddMultiplyType(EScoreMutiplyType.ClickedFromResultPopup); } public void UpdateAIGold() { if (IsChallengeMode) { var data = GameManager.DB.GetHuntingData(GameManager.DB.GetUnlockTargetIndex(true)); AINameTMP.text = data.Name; AIGoldTMP.text = GameManager.DB.GetReaminingTargetConditionString(data.Index); } else { AINameTMP.text = "Lv." + GameManager.DB.NormalGameLevel.ToString(); AIGoldTMP.text = CodeJay.CodeJayUtility.Converter.MoneyToString(GameManager.DB.GetRemainigNormalGameAIGold()); } } public void UnintentionalDestroyOfCardSlot(CardSlot slot) { for (int i = 0; i < _lstCardSlots.Count; i++) { if (_lstCardSlots[i].CardType == slot.CardType) { _lstCardSlots[i] = slot; return; } } } public void OnClick_Preview() { GameManager.UI.ShowNStackPopup(EPopupType.PreViewPopup); } void Set_Mission() { if (DSUtil.RandomTrue(0.1f + GameManager.DB.MissionAddRate)) //if (true) // 테스트 : 미션 100% { GameManager.DB.Set_Mission(false); // 메인 미션 { System.Random rand = new System.Random(); var keys = dic_missionRate.Keys .Where(k => k != eMainMission.Max) // Max 제외 .ToList(); CurMission = keys[rand.Next(keys.Count)]; } // 서브 미션 { System.Random rand = new System.Random(); var keys = dic_submisstionRate.Keys .Where(k => k != eSubMission.Max) // Max 제외 .ToList(); CurSubMission = keys[rand.Next(keys.Count)]; } MissionOpenPopup.NeedBtn = true; GameManager.UI.ShowNStackPopup(EPopupType.MissionOpenPopup); go_missionbtn.SetActive(true); } else { CurMission = eMainMission.Max; CurSubMission = eSubMission.Max; GameManager.DB.Set_Mission(true); go_missionbtn.SetActive(false); } go_previewbtn.SetActive(true); } public void OnClick_Mission() { MissionOpenPopup.NeedBtn = false; GameManager.UI.ShowNStackPopup(EPopupType.MissionOpenPopup); } #region Core private void Initialize() { GameManager.Sound.PlayBGM(EBGMType.BGM_2); go_previewbtn.SetActive(false); go_missionbtn.SetActive(false); ShowMainMissionPopup = ShowSubMissionPopup = false; IsPreview = UseSepYulgget_To_Pee = false; this.GamePanelEnabled(true); go_toppanel.SetActive(false); i_ai.sprite = DB_HuntingData.GetEntity((GameManager.DB.GetUnlockTargetIndex(true) << 1) - 2).DBF_UnlockImage; t_PointMoney.text = $"판돈\n{Stake}냥"; GameManager.Event.InvokeEvent(EEventType.OnInitializeGame); GameManager.Event.InvokeEvent(EEventType.OnSynchronizeGold); EffectPanel.PlayerTurnDirectEnabled(false); if (_lstCardSlots == null) { _lstCardSlots = new List(); for (ECardType i = 0; i < ECardType.Dec_Pee_2 + 1; i++) { CardSlot slot = Instantiate(CardSlotPrefab).GetComponent(); slot.Initialize(CenterDeckRT); _lstCardSlots.Add(slot); } // Use Bonus Card { // Bonus 1 (Double) CardSlot slot = Instantiate(CardSlotPrefab).GetComponent(); slot.Initialize(CenterDeckRT); slot.SetData(ECardType.Bonus_1); _lstCardSlots.Add(slot); // Bonus 2 (Double) slot = Instantiate(CardSlotPrefab).GetComponent(); slot.Initialize(CenterDeckRT); slot.SetData(ECardType.Bonus_2); _lstCardSlots.Add(slot); // Bonus 3 (Triple) slot = Instantiate(CardSlotPrefab).GetComponent(); slot.Initialize(CenterDeckRT); slot.SetData(ECardType.Bonus_3); _lstCardSlots.Add(slot); } } else { for (int i = _lstCardSlots.Count - 1; i >= 0; i--) { if (_lstCardSlots[i].CardType == ECardType.FlipCard_1 || _lstCardSlots[i].CardType == ECardType.FlipCard_2) { CardSlot slot = _lstCardSlots[i]; _lstCardSlots.RemoveAt(i); Destroy(slot.gameObject); } } } ECardType type = ECardType.Jan_Ghwang; for (int i = 0; i < _lstCardSlots.Count; i++) { if (_lstCardSlots[i] != null) { _lstCardSlots[i].gameObject.name = "CardSlot " + (int)i; _lstCardSlots[i].SetData(type++); if (type == ECardType.Back) type = ECardType.Bonus_1; } } _isSelctedSepYulggetState = false; _prevScore_Player = 0; _prevScore_AI = 0; _useBomb = false; _isFirstTurn_Player = true; _isFirstTurn_AI = true; PlayerTurn = true; GameOver = false; Player_Bell = 0; AI_Bell = 0; Player_Bbug = 0; AI_Bbug = 0; Player_Go = 0; AI_Go = 0; _discardSlot = null; for (EGameWorkFlowType i = 0; i < EGameWorkFlowType.Max; i++) _dicCoroutineStates[i] = EGameStateType.None; CurrentCoroutineType = EGameWorkFlowType.Max; this.DataInitialize(); } private void Shuffle() { List indices = new List(); for (int i = 0; i < _lstCardSlots.Count; i++) indices.Add(i); // Bomb Test { //indices.Remove(0); //indices.Remove(1); //indices.Remove(2); //indices.Remove(3); //indices.Remove(5); //CardSlot temp = _lstCardSlots[3]; //_lstCardSlots[3] = _lstCardSlots[5]; //_lstCardSlots[5] = temp; } // Bell Test { //indices.Remove(0); //indices.Remove(1); //indices.Remove(2); //indices.Remove(3); //indices.Remove(9); //CardSlot temp = _lstCardSlots[3]; //_lstCardSlots[3] = _lstCardSlots[9]; //_lstCardSlots[9] = temp; } // Get Bbug Test { //indices.Remove(0); //indices.Remove(1); //indices.Remove(2); //indices.Remove(3); //indices.Remove(5); //indices.Remove(6); //indices.Remove(7); //CardSlot temp = _lstCardSlots[1]; //_lstCardSlots[1] = _lstCardSlots[5]; //_lstCardSlots[5] = temp; //temp = _lstCardSlots[2]; //_lstCardSlots[2] = _lstCardSlots[6]; //_lstCardSlots[6] = temp; //temp = _lstCardSlots[3]; //_lstCardSlots[3] = _lstCardSlots[7]; //_lstCardSlots[7] = temp; } // Select Test { //indices.Remove(0); //indices.Remove(1); //indices.Remove(5); //indices.Remove(6); //CardSlot temp = _lstCardSlots[1]; //_lstCardSlots[1] = _lstCardSlots[5]; //_lstCardSlots[5] = temp; //temp = _lstCardSlots[2]; //_lstCardSlots[2] = _lstCardSlots[6]; //_lstCardSlots[6] = temp; } // Bonus Test In Player Hand { //indices.Remove(0); //indices.Remove(47); //CardSlot temp = _lstCardSlots[0]; //_lstCardSlots[0] = _lstCardSlots[48]; //_lstCardSlots[48] = temp; } // Bonus Test In Center { //indices.Remove(5); //indices.Remove(48); //CardSlot temp = _lstCardSlots[5]; //_lstCardSlots[5] = _lstCardSlots[48]; //_lstCardSlots[48] = temp; } // 총통 테스트 { // Player (유저 총통 만들기, 안되고 폭탄만 만들어짐) { //indices.Remove(0); //indices.Remove(1); //indices.Remove(2); //indices.Remove(3); } // Floor (바닥패를 총통으로 만들어 다음판 or 로비로) { //indices.Remove(0); //indices.Remove(1); //indices.Remove(2); //indices.Remove(3); //indices.Remove(5); //indices.Remove(6); //indices.Remove(7); //indices.Remove(8); //CardSlot temp = _lstCardSlots[0]; //_lstCardSlots[0] = _lstCardSlots[5]; //_lstCardSlots[5] = temp; //temp = _lstCardSlots[1]; //_lstCardSlots[1] = _lstCardSlots[6]; //_lstCardSlots[6] = temp; //temp = _lstCardSlots[2]; //_lstCardSlots[2] = _lstCardSlots[7]; //_lstCardSlots[7] = temp; //temp = _lstCardSlots[3]; //_lstCardSlots[3] = _lstCardSlots[8]; //_lstCardSlots[8] = temp; } } // Select Text { //indices.Remove(0); //indices.Remove(1); //indices.Remove(2); //indices.Remove(3); //indices.Remove(5); //indices.Remove(6); //// Set Floor //CardSlot temp = _lstCardSlots[2]; //_lstCardSlots[2] = _lstCardSlots[5]; //_lstCardSlots[5] = temp; //temp = _lstCardSlots[3]; //_lstCardSlots[3] = _lstCardSlots[6]; //_lstCardSlots[6] = temp; //// Set AI Hand //temp = _lstCardSlots[1]; //_lstCardSlots[1] = _lstCardSlots[9]; //_lstCardSlots[9] = temp; } // Bug Test { //indices.Remove(0); //indices.Remove(5); //indices.Remove(6); //indices.Remove(12); //indices.Remove(14); //indices.Remove(15); //CardSlot temp = _lstCardSlots[0]; //_lstCardSlots[0] = _lstCardSlots[15]; //_lstCardSlots[15] = temp; //temp = _lstCardSlots[5]; //_lstCardSlots[5] = _lstCardSlots[12]; //_lstCardSlots[12] = temp; //// Set AI Hand //temp = _lstCardSlots[6]; //_lstCardSlots[6] = _lstCardSlots[14]; //_lstCardSlots[14] = temp; } for (int i = 0; i < _lstCardSlots.Count; i++) { int rnd = indices[UnityEngine.Random.Range(0, indices.Count)]; if (rnd == i || indices.Contains(i) == false) continue; CardSlot slot = _lstCardSlots[rnd]; _lstCardSlots[rnd] = _lstCardSlots[i]; _lstCardSlots[i] = slot; } } private void FrontBonusCard() { for (int i = 0; i < _lstCardSlots.Count; i++) { if (_lstCardSlots[i].CardType == ECardType.Bonus_1 || _lstCardSlots[i].CardType == ECardType.Bonus_2 || _lstCardSlots[i].CardType == ECardType.Bonus_3) { CardSlot slot = _lstCardSlots[i]; _lstCardSlots[i] = _lstCardSlots[0]; _lstCardSlots[0] = slot; break; } } } #endregion }