234 lines
9.4 KiB
C#
234 lines
9.4 KiB
C#
|
|
using CodeJay.Enum;
|
||
|
|
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;
|
||
|
|
}
|
||
|
|
|
||
|
|
private void DistributeStateMachine()
|
||
|
|
{
|
||
|
|
switch (_distributeState)
|
||
|
|
{
|
||
|
|
case EDistributeState.Initialize:
|
||
|
|
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;
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|