RandomGFGoStop/Assets/Scripts/UI/GamePanel/GamePanel.cs

664 lines
20 KiB
C#
Raw Blame History

using CodeJay.Enum;
using System.Collections.Generic;
using UnityEngine;
using Image = UnityEngine.UI.Image;
public partial class GamePanel : MonoBehaviour
{
#region Statics
public static void LogicalError(string message)
{
throw new System.Exception(message);
}
#endregion
public static float GameSpeed = 1f;
public static GamePanel Instance;
public GameObject CardSlotPrefab, go_toppanel;
public CanvasGroup cg;
public Image i_ai;
public TMPro.TextMeshProUGUI AINameTMP, t_PointMoney;
public TMPro.TextMeshProUGUI AIGoldTMP;
private List<CardSlot> _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;
#region MonoBehaviour
private void Awake()
{
if (Instance == null)
Instance = this;
else
Debug.LogError("Error!!!!");
EffectPanel = this.GetComponent<GamePanel_Effect>();
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<EScoreMutiplyType>();
_hashScoreMultiplyTypes.Clear();
_dicCoroutineStates = new Dictionary<EGameWorkFlowType, EGameStateType>();
for (EGameWorkFlowType i = 0; i < EGameWorkFlowType.Max; i++)
_dicCoroutineStates.Add(i, EGameStateType.None);
GameSpeed = (1.8f * GameManager.DB.GameSpeed) + 0.2f;
}
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
Stake = GameManager.DB.NormalGameLevel * DBManager.NORMAL_GAME_STAKE_PER_LEVEL;
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.Meongbak:
_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();
}
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;
}
}
}
#region Core
private void Initialize()
{
GameManager.Sound.PlayBGM(EBGMType.BGM_2);
UseSepYulgget_To_Pee = false;
this.GamePanelEnabled(true);
go_toppanel.SetActive(false);
i_ai.sprite = DB_HuntingData.GetEntity(GameManager.DB.GetUnlockTargetIndex(true) << 1).DBF_UnlockImage;
t_PointMoney.text = $"판돈\n<color=#ffd544>{Stake}</color>냥";
GameManager.Event.InvokeEvent(EEventType.OnInitializeGame);
GameManager.Event.InvokeEvent(EEventType.OnSynchronizeGold);
EffectPanel.PlayerTurnDirectEnabled(false);
if (_lstCardSlots == null)
{
_lstCardSlots = new List<CardSlot>();
for (ECardType i = 0; i < ECardType.Dec_Pee_2 + 1; i++)
{
CardSlot slot = Instantiate(CardSlotPrefab).GetComponent<CardSlot>();
slot.Initialize(CenterDeckRT);
_lstCardSlots.Add(slot);
}
// Use Bonus Card
{
// Bonus 1 (Double)
CardSlot slot = Instantiate(CardSlotPrefab).GetComponent<CardSlot>();
slot.Initialize(CenterDeckRT);
slot.SetData(ECardType.Bonus_1);
_lstCardSlots.Add(slot);
// Bonus 2 (Double)
slot = Instantiate(CardSlotPrefab).GetComponent<CardSlot>();
slot.Initialize(CenterDeckRT);
slot.SetData(ECardType.Bonus_2);
_lstCardSlots.Add(slot);
// Bonus 3 (Triple)
slot = Instantiate(CardSlotPrefab).GetComponent<CardSlot>();
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<int> indices = new List<int>();
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;
}
// <20><><EFBFBD><EFBFBD> ó<><C3B3>
{
// Player
{
//indices.Remove(0);
//indices.Remove(1);
//indices.Remove(2);
//indices.Remove(3);
}
// Floor
{
//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
}