274 lines
11 KiB
C#
274 lines
11 KiB
C#
using System.Collections.Generic;
|
||
using CodeJay.Enum;
|
||
using UnityEngine;
|
||
|
||
public partial class GamePanel : MonoBehaviour
|
||
{
|
||
public enum EDiscardState
|
||
{
|
||
ActionBeforeDiscard,
|
||
WaitForDiscard,
|
||
|
||
CheckGuide,
|
||
BonusCardAction,
|
||
|
||
CheckBellCard,
|
||
WaitForShake,
|
||
|
||
CheckBombCard,
|
||
BringTheCardAfterBomb,
|
||
|
||
MoveToFloor,
|
||
Complete
|
||
}
|
||
|
||
private int _discardIndex = 0;
|
||
private EDiscardState _discardState = EDiscardState.ActionBeforeDiscard;
|
||
private bool _useBomb = false;
|
||
|
||
private void InitDiscardData()
|
||
{
|
||
_discardIndex = 0;
|
||
_discardState = EDiscardState.ActionBeforeDiscard;
|
||
}
|
||
|
||
private void DiscardStateMachine()
|
||
{
|
||
switch (_discardState)
|
||
{
|
||
case EDiscardState.ActionBeforeDiscard:
|
||
{
|
||
SetGuideData(true);
|
||
_discardSlot = null;
|
||
_useBomb = false;
|
||
|
||
if (PlayerTurn)
|
||
{
|
||
if (_isFirstTurn_Player)
|
||
SortPlayerCards();
|
||
|
||
EnabledPlayerHandRaycast(true);
|
||
EffectPanel.PlayerTurnDirectEnabled(true);
|
||
}
|
||
|
||
_discardState = EDiscardState.WaitForDiscard;
|
||
}
|
||
break;
|
||
case EDiscardState.WaitForDiscard:
|
||
if (PlayerTurn)
|
||
{
|
||
if (_discardSlot != null)
|
||
{
|
||
_discardState = EDiscardState.CheckGuide;
|
||
|
||
EnabledPlayerHandRaycast(false);
|
||
SetGuideData(false);
|
||
EffectPanel.PlayerTurnDirectEnabled(false);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
var aihandCardSlots = GetMatchedCardSlots(ECardLocationType.AI_Hand);
|
||
_discardSlot = aihandCardSlots[Random.Range(0, aihandCardSlots.Count)];
|
||
_discardState = EDiscardState.CheckGuide;
|
||
}
|
||
break;
|
||
#region Bonus
|
||
case EDiscardState.BonusCardAction:
|
||
{
|
||
for (int i = 0; i < _lstCardSlots.Count; i++)
|
||
{
|
||
if (_lstCardSlots[i].LocationType == ECardLocationType.Center)
|
||
{
|
||
if (PlayerTurn)
|
||
_lstCardSlots[i].Move(ECardLocationType.Center, ECardLocationType.Player_Hand, GetRectTransformAndModifyContainer(ECardLocationType.Player_Hand, _lstCardSlots[i].CardType));
|
||
else
|
||
_lstCardSlots[i].Move(ECardLocationType.Center, ECardLocationType.AI_Hand, GetRectTransformAndModifyContainer(ECardLocationType.AI_Hand, _lstCardSlots[i].CardType));
|
||
break;
|
||
}
|
||
}
|
||
|
||
GameManager.Sound.ReserveSFX(ESFXType.Card_Hit, 0.25f);
|
||
EffectPanel.Direct(EEffectDirectType.Bonus, PlayerTurn);
|
||
BringOtherPlayersPeeCard(1, PlayerTurn);
|
||
|
||
_delay = 0.25f;
|
||
_discardState = EDiscardState.ActionBeforeDiscard;
|
||
_discardSlot = null;
|
||
|
||
if (PlayerTurn)
|
||
SortPlayerCards();
|
||
}
|
||
break;
|
||
case EDiscardState.CheckGuide:
|
||
if (_discardSlot.CardType == ECardType.Bonus_1 || _discardSlot.CardType == ECardType.Bonus_2 || _discardSlot.CardType == ECardType.Bonus_3)
|
||
{
|
||
if (PlayerTurn)
|
||
{
|
||
_discardSlot.Move(ECardLocationType.Player_Hand, ECardLocationType.Player_Score, GetRectTransformAndModifyContainer(ECardLocationType.Player_Score, _discardSlot.CardType));
|
||
DataMove(ECardLocationType.Player_Hand, _discardSlot.CardType);
|
||
|
||
}
|
||
else
|
||
{
|
||
_discardSlot.Move(ECardLocationType.AI_Hand, ECardLocationType.AI_Score, GetRectTransformAndModifyContainer(ECardLocationType.AI_Score, _discardSlot.CardType));
|
||
DataMove(ECardLocationType.AI_Hand, _discardSlot.CardType);
|
||
}
|
||
|
||
_discardState = EDiscardState.BonusCardAction;
|
||
}
|
||
else if (_discardSlot.GuideType == EGuideType.Bell)
|
||
{
|
||
_discardState = EDiscardState.CheckBellCard;
|
||
}
|
||
else if (_discardSlot.GuideType == EGuideType.Bomb_Double || _discardSlot.GuideType == EGuideType.Bomb_Triple)
|
||
{
|
||
_discardIndex = 0;
|
||
_discardState = EDiscardState.CheckBombCard;
|
||
}
|
||
else if (_discardSlot.CardType == ECardType.FlipCard_1 || _discardSlot.CardType == ECardType.FlipCard_2)
|
||
{
|
||
DataMove(PlayerTurn ? ECardLocationType.Player_Hand : ECardLocationType.AI_Hand, _discardSlot.CardType);
|
||
_lstCardSlots.Remove(_discardSlot);
|
||
Destroy(_discardSlot.gameObject);
|
||
_discardSlot = null;
|
||
_discardState = EDiscardState.Complete;
|
||
}
|
||
else
|
||
{
|
||
_discardState = EDiscardState.MoveToFloor;
|
||
}
|
||
break;
|
||
#endregion
|
||
|
||
|
||
#region Shake (Bell)
|
||
case EDiscardState.CheckBellCard:
|
||
if (PlayerTurn)
|
||
{
|
||
var cardSlots = GetMatchedCardSlots(ECardLocationType.Player_Hand, _discardSlot.MonthType);
|
||
|
||
List<ECardType> cardTypes = new List<ECardType>();
|
||
for (int i = 0; i < cardSlots.Count; i++)
|
||
cardTypes.Add(cardSlots[i].CardType);
|
||
|
||
GameManager.UI.ShowNStackPopup<ShakeSelectPopup>(EPopupType.ShakeSelectPopup).SetData(cardTypes.ToArray(), cardSlots.Count >= 4);
|
||
_discardState = EDiscardState.WaitForShake;
|
||
_delay = 0.05f;
|
||
_discardIndex = Player_Bell;
|
||
}
|
||
else
|
||
{
|
||
var cardSlots = GetMatchedCardSlots(ECardLocationType.Player_Hand, _discardSlot.MonthType);
|
||
|
||
List<ECardType> cardTypes = new List<ECardType>();
|
||
for (int i = 0; i < cardSlots.Count; i++)
|
||
cardTypes.Add(cardSlots[i].CardType);
|
||
|
||
GameManager.UI.ShowNStackPopup<ShakeSelectPopup_AI>(EPopupType.ShakeSelectPopup_AI).SetData(cardTypes.ToArray(), cardSlots.Count >= 4);
|
||
_discardState = EDiscardState.WaitForShake;
|
||
_delay = 2;
|
||
}
|
||
|
||
break;
|
||
case EDiscardState.WaitForShake:
|
||
if (GameManager.UI.IsAnyPopupOpened() == false)
|
||
{
|
||
if (PlayerTurn)
|
||
{
|
||
if (Player_Bell == _discardIndex)
|
||
_delay = 1.6f;
|
||
}
|
||
_discardState = EDiscardState.MoveToFloor;
|
||
_discardIndex = 0;
|
||
}
|
||
|
||
break;
|
||
#endregion
|
||
|
||
case EDiscardState.CheckBombCard:
|
||
if (_discardSlot.GuideType == EGuideType.Bomb_Double || _discardSlot.GuideType == EGuideType.Bomb_Triple)
|
||
{
|
||
ECardLocationType location = PlayerTurn ? ECardLocationType.Player_Hand : ECardLocationType.AI_Hand;
|
||
var matchedSlot = GetMatchedCardSlots(location, _discardSlot.MonthType);
|
||
|
||
if (matchedSlot.Count > 0)
|
||
{
|
||
RectTransform rt = GetRectTransformAndModifyContainer(ECardLocationType.Floor, matchedSlot[matchedSlot.Count - 1].CardType);
|
||
matchedSlot[matchedSlot.Count - 1].Move(location, ECardLocationType.Floor, rt);
|
||
DataMove(location, matchedSlot[matchedSlot.Count - 1].CardType);
|
||
_delay = 0.1f;
|
||
GameManager.Sound.ReserveSFX(ESFXType.Card_Hit, CardSlot.TWEEN_DURATION);
|
||
}
|
||
else
|
||
{
|
||
_useBomb = true;
|
||
int num;
|
||
if (_discardSlot.GuideType == EGuideType.Bomb_Double)
|
||
num = 1;
|
||
else
|
||
num = 2;
|
||
|
||
var matchedCardSlot = GetMatchedCardSlots(ECardLocationType.Floor, _discardSlot.MonthType);
|
||
for (int i = 0; i < matchedCardSlot.Count; i++)
|
||
_lstAvailableCardTypes.Add(matchedCardSlot[i].CardType);
|
||
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ī<>带 <20><>´<EFBFBD>.
|
||
for (int i = 0; i < num; i++)
|
||
{
|
||
CardSlot slot = Instantiate(CardSlotPrefab).GetComponent<CardSlot>();
|
||
|
||
slot.Initialize();
|
||
slot.SetData(ECardType.FlipCard_1 + i);
|
||
slot.Move(ECardLocationType.Max, location, GetRectTransformAndModifyContainer(location, slot.CardType));
|
||
_lstCardSlots.Add(slot);
|
||
}
|
||
|
||
if (_discardSlot.GuideType == EGuideType.Bomb_Double)
|
||
{
|
||
_delay = EffectPanel.GetEffectDuration(EEffectDirectType.Bomb_Double);
|
||
EffectPanel.Direct(EEffectDirectType.Bomb_Double, PlayerTurn);
|
||
}
|
||
else
|
||
{
|
||
_delay = EffectPanel.GetEffectDuration(EEffectDirectType.Bomb_Triple);
|
||
EffectPanel.Direct(EEffectDirectType.Bomb_Triple, PlayerTurn);
|
||
}
|
||
|
||
_discardState = EDiscardState.BringTheCardAfterBomb;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
LogicalError($"Only Reached {nameof(_discardSlot)}.GuideType : Bomb_Double, Bomb_Triple");
|
||
}
|
||
break;
|
||
case EDiscardState.BringTheCardAfterBomb:
|
||
{
|
||
BringOtherPlayersPeeCard(1, PlayerTurn);
|
||
_delay = 0.1f;
|
||
_discardState = EDiscardState.Complete;
|
||
}
|
||
break;
|
||
case EDiscardState.MoveToFloor:
|
||
{
|
||
RectTransform rt = GetRectTransformAndModifyContainer(ECardLocationType.Floor, _discardSlot.CardType);
|
||
ECardLocationType location = PlayerTurn ? ECardLocationType.Player_Hand : ECardLocationType.AI_Hand;
|
||
|
||
DataMove(location, _discardSlot.CardType);
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD>ߴ<EFBFBD> CardSlot<6F><74> <20><><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD>.
|
||
_discardSlot.Move(location, ECardLocationType.Floor, rt);
|
||
_delay = 0.25f;
|
||
_discardState = EDiscardState.Complete;
|
||
}
|
||
break;
|
||
case EDiscardState.Complete:
|
||
{
|
||
this.InitDiscardData();
|
||
CurrentCoroutineType = EGameWorkFlowType.CheckMatchedCardAfterDiscard;
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
}
|