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

274 lines
11 KiB
C#

using CodeJay.Enum;
using System.Collections.Generic;
using System.Reflection.Emit;
using UnityEngine;
public partial class GamePanel : MonoBehaviour
{
public enum EDistributeState
{
Initialize,
MoveToPlayerHand,
MoveToFloor,
MoveToAIHand,
CheckChongTong_Floor,
CheckChongTong_Player,
CheckChongTong_AI,
WaitForChongTongSelect_Player,
WaitForChongTongSelect_AI,
Complete
}
private const float DISTRIBUTE_INTERVAL_INIT = 0.02f;
private int _distributeCardIndex = 0;
private EDistributeState _distributeState = EDistributeState.Initialize;
private void InitDistributeData()
{
_distributeCardIndex = 0;
_distributeState = EDistributeState.Initialize;
}
#if UNITY_EDITOR
public void SetCardsAtIndex(List<CardSlot> slots, List<ECardType> cards, int startIndex)
{
for (int i = 0; i < cards.Count; i++)
{
int targetIndex = startIndex + i;
// 해당 카드의 현재 인덱스 찾기
int currentIndex = slots.FindIndex(slot => slot.CardType == cards[i]);
// 이미 올바른 위치면 스킵
if (currentIndex == targetIndex) continue;
if (currentIndex >= 0)
{
// 값 스왑
var temp = slots[targetIndex];
slots[targetIndex] = slots[currentIndex];
slots[currentIndex] = temp;
}
}
}
#endif
private void DistributeStateMachine()
{
switch (_distributeState)
{
case EDistributeState.Initialize:
#if UNITY_EDITOR
// 테스트 (원하는 카드 세팅)
{
// 고정시킬 카드 순서
var fixedCards = new List<ECardType> { ECardType.Jan_Ghwang, ECardType.Jan_Hongdan,
ECardType.Jan_Normal_1, ECardType.Jan_Normal_2 };
//SetCardsAtIndex(_lstCardSlots, fixedCards, 0); // 플레이어 총통
//SetCardsAtIndex(_lstCardSlots, fixedCards, 9); // AI 총통
//SetCardsAtIndex(_lstCardSlots,
// new List<ECardType> { ECardType.Jan_Ghwang, ECardType.Jan_Hongdan, ECardType.Jan_Normal_1 }, 9); // AI 흔들기
}
#endif
if (_distributeCardIndex < _lstCardSlots.Count)
{
if (_distributeCardIndex == 0)
Debug.Log("DistributeCard Method!");
_lstCardSlots[_distributeCardIndex++].Move(ECardLocationType.Max, ECardLocationType.Center,
GetRectTransformAndModifyContainer(ECardLocationType.Center, ECardType.Max));
if (_distributeCardIndex % 2 == 0)
GameManager.Sound.PlaySFX(ESFXType.CardMove_1);
}
else
{
_delay = 0.2f;
_distributeCardIndex = 0;
_distributeState = EDistributeState.MoveToPlayerHand;
GameManager.Event.InvokeEvent(EEventType.OnDistributeCardCompletedToCenter);
}
break;
case EDistributeState.MoveToPlayerHand:
// 0 ~ 4, 14 ~ 18
if (_distributeCardIndex < 5 || (_distributeCardIndex >= 14 && _distributeCardIndex <= 18))
{
_lstCardSlots[_distributeCardIndex].Move(ECardLocationType.Center, ECardLocationType.Player_Hand,
GetRectTransformAndModifyContainer(ECardLocationType.Player_Hand, _lstCardSlots[_distributeCardIndex].CardType));
_delay = DISTRIBUTE_INTERVAL_INIT;
_distributeCardIndex++;
if (_distributeCardIndex % 2 == 0)
GameManager.Sound.PlaySFX(ESFXType.CardMove_1);
}
else
{
_delay = 0.1f;
_distributeState = EDistributeState.MoveToFloor;
}
break;
// 5 ~ 8, 19 ~ 22
case EDistributeState.MoveToFloor:
if ((_distributeCardIndex >= 5 && _distributeCardIndex <= 8) || (_distributeCardIndex >= 19 && _distributeCardIndex <= 22))
{
_lstCardSlots[_distributeCardIndex].Move(ECardLocationType.Center, ECardLocationType.Floor,
GetRectTransformAndModifyContainer(ECardLocationType.Floor, _lstCardSlots[_distributeCardIndex].CardType), isDistribute: true);
_delay = DISTRIBUTE_INTERVAL_INIT;
_distributeCardIndex++;
if (_distributeCardIndex % 2 == 0)
GameManager.Sound.PlaySFX(ESFXType.CardMove_1);
}
else
{
_delay = 0.1f;
_distributeState = EDistributeState.MoveToAIHand;
}
break;
// 9 ~13, 23 ~ 27
case EDistributeState.MoveToAIHand:
if ((_distributeCardIndex >= 9 && _distributeCardIndex <= 13) || (_distributeCardIndex >= 23 && _distributeCardIndex <= 27))
{
_lstCardSlots[_distributeCardIndex].Move(ECardLocationType.Center, ECardLocationType.AI_Hand,
GetRectTransformAndModifyContainer(ECardLocationType.AI_Hand, _lstCardSlots[_distributeCardIndex].CardType));
_delay = DISTRIBUTE_INTERVAL_INIT;
_distributeCardIndex++;
if (_distributeCardIndex % 2 == 0)
GameManager.Sound.PlaySFX(ESFXType.CardMove_1);
}
else
{
if (_distributeCardIndex > 27)
{
_distributeState = EDistributeState.CheckChongTong_Floor;
_delay = 0.5f;
}
else
{
_distributeState = EDistributeState.MoveToPlayerHand;
_delay = 0.25f;
}
}
break;
#region Chong Tong
case EDistributeState.CheckChongTong_Floor:
{
ECardMonthType monthType;
for (int i = 0; i < _lstFloorCards.Count; i++)
{
monthType = CodeJay.CodeJayUtility.Converter.CardTypeToMonthType(_lstFloorCards[i]);
if (GetMatchedCardSlotNumber(ECardLocationType.Floor, monthType) >= 4)
{
GameManager.UI.ShowNStackPopup<AllMonthTypePopup_Floor>(EPopupType.AllMonthTypePopup_Floor).SetCardMonthType(monthType);
this.InitDistributeData();
GameOver = true;
break;
}
}
if (!GameOver)
_distributeState = EDistributeState.CheckChongTong_Player;
}
break;
case EDistributeState.CheckChongTong_Player:
{
ECardMonthType monthType;
for (int i = 0; i < _lstPlayerHandCardTypes.Count; i++)
{
monthType = CodeJay.CodeJayUtility.Converter.CardTypeToMonthType(_lstPlayerHandCardTypes[i]);
if (GetMatchedCardSlotNumber(ECardLocationType.Player_Hand, monthType) >= 4)
{
GameManager.UI.ShowNStackPopup<AllMonthTypePopup>(EPopupType.AllMonthTypePopup).SetCardMonthType(monthType);
_distributeState = EDistributeState.WaitForChongTongSelect_Player;
_delay = 0.1f;
break;
}
}
if (_distributeState != EDistributeState.WaitForChongTongSelect_Player)
_distributeState = EDistributeState.CheckChongTong_AI;
}
break;
case EDistributeState.WaitForChongTongSelect_Player:
{
if (GameManager.UI.IsOpendPopup(EPopupType.AllMonthTypePopup) == false)
{
if (GameOver)
{
_distributeCardIndex = 0;
_delay = 0;
_distributeState = EDistributeState.Initialize;
}
else
{
_delay = 0.5f;
_distributeState = EDistributeState.CheckChongTong_AI;
}
}
}
break;
case EDistributeState.CheckChongTong_AI:
{
ECardMonthType monthType;
for (int i = 0; i < _lstAIHandCardTypes.Count; i++)
{
monthType = CodeJay.CodeJayUtility.Converter.CardTypeToMonthType(_lstAIHandCardTypes[i]);
if (GetMatchedCardSlotNumber(ECardLocationType.AI_Hand, monthType) >= 4)
{
GameManager.UI.ShowNStackPopup<AllMonthTypePopup_AI>(EPopupType.AllMonthTypePopup_AI);
_distributeState = EDistributeState.WaitForChongTongSelect_AI;
_delay = 0.1f;
break;
}
}
if (_distributeState != EDistributeState.WaitForChongTongSelect_AI)
_distributeState = EDistributeState.Complete;
}
break;
case EDistributeState.WaitForChongTongSelect_AI:
{
if (GameManager.UI.IsOpendPopup(EPopupType.AllMonthTypePopup_AI) == false)
{
if (GameOver)
{
_distributeCardIndex = 0;
_delay = 0;
_distributeState = EDistributeState.Initialize;
}
else
{
_delay = 0.5f;
_distributeState = EDistributeState.Complete;
}
}
}
break;
#endregion
case EDistributeState.Complete:
{
this.InitDistributeData();
this.CheckFloorBonus();
_currentCoroutineType = EGameWorkFlowType.DiscardNEffectBeforeDiscard;
if (!GameOver) Set_Mission();
}
break;
}
}
}