373 lines
18 KiB
C#
373 lines
18 KiB
C#
using UnityEngine;
|
|
using CodeJay.Enum;
|
|
using System.Collections.Generic;
|
|
|
|
public partial class GamePanel : MonoBehaviour
|
|
{
|
|
public enum EFlipCenterState
|
|
{
|
|
FlipCenterCard,
|
|
MatchedWithDiscardType,
|
|
NotMatchedWithDiscardType,
|
|
WaitforBbugDirect,
|
|
WaitforBbugPopupClose,
|
|
WaitForCardSelect,
|
|
WaitForKissDirect,
|
|
Complete
|
|
}
|
|
|
|
internal int _flipCenterIndex = 0;
|
|
internal EFlipCenterState _flipCenterState;
|
|
private CardSlot _flipedCardSlot;
|
|
private Dictionary<ECardType, ECardMonthType> _dicReservedBonusCard;
|
|
|
|
public void InitFlipCenterData()
|
|
{
|
|
this._flipCenterIndex = 0;
|
|
_flipCenterState = EFlipCenterState.FlipCenterCard;
|
|
|
|
if (_dicReservedBonusCard == null)
|
|
_dicReservedBonusCard = new Dictionary<ECardType, ECardMonthType>();
|
|
else
|
|
_dicReservedBonusCard.Clear();
|
|
}
|
|
|
|
public void FlipCenterStateMachine()
|
|
{
|
|
switch (_flipCenterState)
|
|
{
|
|
// 카드를 뒤집는다.
|
|
case EFlipCenterState.FlipCenterCard:
|
|
{
|
|
for (int i = 0; i < _lstCardSlots.Count; i++)
|
|
{
|
|
if (_lstCardSlots[i].LocationType == ECardLocationType.Center)
|
|
{
|
|
_flipedCardSlot = _lstCardSlots[i];
|
|
break;
|
|
}
|
|
}
|
|
|
|
// 보너스 카드라면
|
|
if (_flipedCardSlot.CardType == ECardType.Bonus_1 || _flipedCardSlot.CardType == ECardType.Bonus_2 || _flipedCardSlot.CardType == ECardType.Bonus_3)
|
|
{
|
|
RectTransform rt = null;
|
|
if (_discardSlot != null)
|
|
{
|
|
rt = GetRectTransformAndModifyContainer(ECardLocationType.Floor, _discardSlot.CardType);
|
|
_dicReservedBonusCard.Add(_flipedCardSlot.CardType, _discardSlot.MonthType);
|
|
}
|
|
else
|
|
{
|
|
rt = GetRectTransformAndModifyContainer(ECardLocationType.Floor, _flipedCardSlot.CardType);
|
|
_dicReservedBonusCard.Add(_flipedCardSlot.CardType, _flipedCardSlot.MonthType);
|
|
}
|
|
|
|
_flipedCardSlot.Move(ECardLocationType.Center, ECardLocationType.Floor, rt);
|
|
GameManager.Sound.ReserveSFX(ESFXType.Card_Hit, 0.25f);
|
|
_lstAvailableCardTypes.Add(_flipedCardSlot.CardType);
|
|
_delay = CardSlot.TWEEN_FROM_CENTER_TO_FLOOR;
|
|
}
|
|
// 중앙 카드덱에서 뒤집은 카드가 '뒤집기' 카드라면
|
|
else if (_flipedCardSlot.CardType == ECardType.FlipCard_1 || _flipedCardSlot.CardType == ECardType.FlipCard_2)
|
|
{
|
|
LogicalError($"{nameof(FlipCenterStateMachine)} Fliped Card Can't be FlipCard_1 or FlipCard_2");
|
|
}
|
|
// 제출한 카드와 중앙 카드덱에서 뒤집은 카드의 '월'이 일치한다면
|
|
else if (_discardSlot != null && _discardSlot.MonthType == _flipedCardSlot.MonthType)
|
|
{
|
|
GameManager.Sound.ReserveSFX(ESFXType.FlipCard_Hit, CardSlot.TWEEN_DURATION);
|
|
RectTransform rt = GetRectTransformAndModifyContainer(ECardLocationType.Floor, _flipedCardSlot.CardType);
|
|
_flipedCardSlot.Move(ECardLocationType.Center, ECardLocationType.Floor, rt);
|
|
_flipCenterState = EFlipCenterState.MatchedWithDiscardType;
|
|
_delay = CardSlot.TWEEN_FROM_CENTER_TO_FLOOR;
|
|
}
|
|
// 그 외
|
|
else
|
|
{
|
|
GameManager.Sound.ReserveSFX(ESFXType.Card_NoHit, CardSlot.TWEEN_DURATION);
|
|
RectTransform rt = GetRectTransformAndModifyContainer(ECardLocationType.Floor, _flipedCardSlot.CardType);
|
|
_flipedCardSlot.Move(ECardLocationType.Center, ECardLocationType.Floor, rt);
|
|
_delay = CardSlot.TWEEN_FROM_CENTER_TO_FLOOR;
|
|
_flipCenterState = EFlipCenterState.NotMatchedWithDiscardType;
|
|
}
|
|
}
|
|
break;
|
|
case EFlipCenterState.NotMatchedWithDiscardType:
|
|
{
|
|
var matchedFloorCards = GetMatchedCardSlots(ECardLocationType.Floor, _flipedCardSlot.MonthType);
|
|
|
|
// 뻑 먹기
|
|
if (matchedFloorCards.Count == 4)
|
|
{
|
|
EEffectDirectType effectType = EEffectDirectType.Max;
|
|
if (_dicBbug_State.ContainsKey(_flipedCardSlot.MonthType))
|
|
{
|
|
if (_dicBbug_State[_flipedCardSlot.MonthType] == EBbugState.Player)
|
|
{
|
|
effectType = PlayerTurn ? EEffectDirectType.GetBbug_Own : EEffectDirectType.GetBbug;
|
|
_flipCenterIndex = PlayerTurn ? 2 : 1;
|
|
}
|
|
else if (_dicBbug_State[_flipedCardSlot.MonthType] == EBbugState.AI)
|
|
{
|
|
effectType = PlayerTurn ? EEffectDirectType.GetBbug : EEffectDirectType.GetBbug_Own;
|
|
_flipCenterIndex = PlayerTurn ? 1 : 2;
|
|
}
|
|
else
|
|
{
|
|
LogicalError($"Plz Check {nameof(_dicBbug_State)}");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
effectType = EEffectDirectType.GetBbug;
|
|
_flipCenterIndex = 1;
|
|
}
|
|
|
|
for (int i = 0; i < matchedFloorCards.Count; i++)
|
|
_lstAvailableCardTypes.Add(matchedFloorCards[i].CardType);
|
|
|
|
// 같이 있던 보너스카드도 가져온다.
|
|
if (_dicReservedBonusCard.ContainsKey(ECardType.Bonus_1))
|
|
{
|
|
if (_dicReservedBonusCard[ECardType.Bonus_1] == _flipedCardSlot.MonthType)
|
|
_lstAvailableCardTypes.Add(ECardType.Bonus_1);
|
|
}
|
|
if (_dicReservedBonusCard.ContainsKey(ECardType.Bonus_2))
|
|
{
|
|
if (_dicReservedBonusCard[ECardType.Bonus_2] == _flipedCardSlot.MonthType)
|
|
_lstAvailableCardTypes.Add(ECardType.Bonus_2);
|
|
}
|
|
if (_dicReservedBonusCard.ContainsKey(ECardType.Bonus_3))
|
|
{
|
|
if (_dicReservedBonusCard[ECardType.Bonus_3] == _flipedCardSlot.MonthType)
|
|
_lstAvailableCardTypes.Add(ECardType.Bonus_3);
|
|
}
|
|
|
|
_delay = EffectPanel.Direct(effectType, PlayerTurn);
|
|
BringOtherPlayersPeeCard(_flipCenterIndex, PlayerTurn);
|
|
_flipCenterIndex = 0;
|
|
_flipCenterState = EFlipCenterState.Complete;
|
|
}
|
|
// 선택할 수 있다.
|
|
else if (matchedFloorCards.Count == 3)
|
|
{
|
|
ECardType leftCard = ECardType.Max;
|
|
ECardType rightCard = ECardType.Max;
|
|
|
|
// 선택할 카드 셋팅
|
|
for (int i = 0; i < matchedFloorCards.Count; i++)
|
|
{
|
|
if (matchedFloorCards[i].CardType == _flipedCardSlot.CardType)
|
|
continue;
|
|
else
|
|
{
|
|
if (leftCard == ECardType.Max)
|
|
leftCard = matchedFloorCards[i].CardType;
|
|
else if (rightCard == ECardType.Max)
|
|
rightCard = matchedFloorCards[i].CardType;
|
|
else
|
|
break;
|
|
}
|
|
}
|
|
|
|
ECardScoreType leftScoreType = CodeJay.CodeJayUtility.Converter.CardTypeToScoreType(leftCard);
|
|
ECardScoreType rightScoreType = CodeJay.CodeJayUtility.Converter.CardTypeToScoreType(rightCard);
|
|
bool isDoublePee_left = CodeJay.CodeJayUtility.Utility.IsDoublePee(leftCard, UseSepYulgget_To_Pee);
|
|
bool isDoublePee_right = CodeJay.CodeJayUtility.Utility.IsDoublePee(rightCard, UseSepYulgget_To_Pee);
|
|
|
|
// 쌍피가 아니고 고를 카드가 둘 다 '피' 일 때
|
|
if (isDoublePee_left == false && isDoublePee_right == false && leftScoreType == ECardScoreType.Pee && rightScoreType == ECardScoreType.Pee)
|
|
{
|
|
CardSelectCallback_Flip(Random.Range(0, 2) == 0 ? leftCard : rightCard);
|
|
_flipCenterState = EFlipCenterState.Complete;
|
|
_delay = 0.2f;
|
|
}
|
|
else
|
|
{
|
|
if (PlayerTurn)
|
|
{
|
|
GameManager.UI.ShowNStackPopup<FloorCardSelectPopup>(EPopupType.FloorCardSelectPopup).SetData(leftCard, rightCard, this.CardSelectCallback_Flip);
|
|
_flipCenterState = EFlipCenterState.WaitForCardSelect;
|
|
_delay = 0.2f;
|
|
}
|
|
else
|
|
{
|
|
GameManager.UI.ShowNStackPopup<WaitForAIBehaviourPopup>(EPopupType.WaitForAIBehaviourPopup).SetData(1f);
|
|
CardSelectCallback_Flip(Random.Range(0, 2) > 0 ? leftCard : rightCard);
|
|
|
|
_delay = 1f;
|
|
_flipCenterState = EFlipCenterState.WaitForCardSelect;
|
|
}
|
|
}
|
|
}
|
|
// 바닥패와 매치됨
|
|
else if (matchedFloorCards.Count == 2)
|
|
{
|
|
_lstAvailableCardTypes.Add(matchedFloorCards[0].CardType);
|
|
_lstAvailableCardTypes.Add(matchedFloorCards[1].CardType);
|
|
_flipCenterState = EFlipCenterState.Complete;
|
|
}
|
|
// 매치되지 않음.
|
|
else if (matchedFloorCards.Count == 1)
|
|
{
|
|
_flipCenterState = EFlipCenterState.Complete;
|
|
}
|
|
else
|
|
{
|
|
LogicalError($"{nameof(FlipCenterStateMachine)} {nameof(EFlipCenterState.NotMatchedWithDiscardType)} case logical error");
|
|
}
|
|
}
|
|
break;
|
|
// 제출한 카드와 동일한 '월' 이라면
|
|
case EFlipCenterState.MatchedWithDiscardType:
|
|
{
|
|
int matchedCardNumber = GetMatchedCardSlotNumber(ECardLocationType.Floor, _flipedCardSlot.MonthType);
|
|
|
|
// 따닥!
|
|
if (matchedCardNumber == 4)
|
|
{
|
|
EffectPanel.Direct(EEffectDirectType.Ddadak, PlayerTurn);
|
|
_delay = EffectPanel.GetEffectDuration(EEffectDirectType.Ddadak);
|
|
_dicBbug_State.Remove(_flipedCardSlot.MonthType);
|
|
|
|
// 중복되지 않도록 비워준다.
|
|
_lstAvailableCardTypes.Clear();
|
|
|
|
for (int i = 0; i < _lstCardSlots.Count; i++)
|
|
{
|
|
if (_lstCardSlots[i].MonthType == _flipedCardSlot.MonthType)
|
|
_lstAvailableCardTypes.Add(_lstCardSlots[i].CardType);
|
|
|
|
// 바닥 패에 있는 자뻑했던 월 타입 카드들에 보너스카드가 있다면 가져올 수 있도록 추가한다.
|
|
if (_dicReservedBonusCard.ContainsKey(_lstCardSlots[i].CardType) &&
|
|
_dicReservedBonusCard[_lstCardSlots[i].CardType] == _flipedCardSlot.MonthType)
|
|
{
|
|
_lstAvailableCardTypes.Add(_lstCardSlots[i].CardType);
|
|
_dicReservedBonusCard.Remove(_lstCardSlots[i].CardType);
|
|
}
|
|
}
|
|
|
|
_flipCenterState = EFlipCenterState.Complete;
|
|
}
|
|
// 뻑
|
|
else if (matchedCardNumber == 3)
|
|
{
|
|
if (PlayerTurn)
|
|
{
|
|
EffectPanel.Direct(EEffectDirectType.Bbug_Own, true);
|
|
_delay = EffectPanel.GetEffectDuration(EEffectDirectType.Bbug_Own);
|
|
_dicBbug_State.Add(_flipedCardSlot.MonthType, EBbugState.Player);
|
|
Player_Bbug++;
|
|
}
|
|
else
|
|
{
|
|
EffectPanel.Direct(EEffectDirectType.Bbug_Own, false);
|
|
_delay = EffectPanel.GetEffectDuration(EEffectDirectType.Bbug_Own);
|
|
_dicBbug_State.Add(_flipedCardSlot.MonthType, EBbugState.AI);
|
|
AI_Bbug++;
|
|
}
|
|
|
|
GameManager.Event.InvokeEvent(EEventType.OnSynchronizeGameData);
|
|
|
|
// 가져올 수 있도록 담아놨던 리스트를 비워준다.
|
|
_lstAvailableCardTypes.Clear();
|
|
|
|
_flipCenterState = EFlipCenterState.WaitforBbugDirect;
|
|
}
|
|
else if (matchedCardNumber == 2)
|
|
{
|
|
_lstAvailableCardTypes.Add(_discardSlot.CardType);
|
|
_lstAvailableCardTypes.Add(_flipedCardSlot.CardType);
|
|
|
|
if (_dicReservedBonusCard.ContainsKey(ECardType.Bonus_1) && _dicReservedBonusCard[ECardType.Bonus_1] == _discardSlot.MonthType)
|
|
{
|
|
_lstAvailableCardTypes.Add(ECardType.Bonus_1);
|
|
_dicReservedBonusCard.Remove(ECardType.Bonus_1);
|
|
}
|
|
if (_dicReservedBonusCard.ContainsKey(ECardType.Bonus_2) && _dicReservedBonusCard[ECardType.Bonus_2] == _discardSlot.MonthType)
|
|
{
|
|
_lstAvailableCardTypes.Add(ECardType.Bonus_2);
|
|
_dicReservedBonusCard.Remove(ECardType.Bonus_2);
|
|
}
|
|
if (_dicReservedBonusCard.ContainsKey(ECardType.Bonus_3) && _dicReservedBonusCard[ECardType.Bonus_3] == _discardSlot.MonthType)
|
|
{
|
|
_lstAvailableCardTypes.Add(ECardType.Bonus_3);
|
|
_dicReservedBonusCard.Remove(ECardType.Bonus_3);
|
|
}
|
|
|
|
_delay = EffectPanel.Direct(EEffectDirectType.Kiss, PlayerTurn);
|
|
_flipCenterState = EFlipCenterState.WaitForKissDirect;
|
|
}
|
|
else
|
|
{
|
|
LogicalError($"{nameof(FlipCenterStateMachine)} Flor matched Card Number Can't be zero or less than 2.");
|
|
}
|
|
}
|
|
break;
|
|
// '뻑'연출을 기다린다.
|
|
case EFlipCenterState.WaitforBbugDirect:
|
|
if (PlayerTurn)
|
|
{
|
|
if (_isFirstTurn_Player)
|
|
{
|
|
GameManager.UI.ShowNStackPopup<FirstBbugPopup>(EPopupType.FirstBbugPopup).SetData(true);
|
|
_flipCenterState = EFlipCenterState.WaitforBbugPopupClose;
|
|
}
|
|
else
|
|
_flipCenterState = EFlipCenterState.Complete;
|
|
|
|
_delay = 0.1f;
|
|
}
|
|
else
|
|
{
|
|
if (_isFirstTurn_AI)
|
|
{
|
|
GameManager.UI.ShowNStackPopup<FirstBbugPopup>(EPopupType.FirstBbugPopup).SetData(false);
|
|
_flipCenterState = EFlipCenterState.WaitforBbugPopupClose;
|
|
}
|
|
else
|
|
_flipCenterState = EFlipCenterState.Complete;
|
|
_delay = 0.1f;
|
|
}
|
|
|
|
break;
|
|
// 첫뻑일경우 팝업이 열리기 때문에 기다린다.
|
|
case EFlipCenterState.WaitforBbugPopupClose:
|
|
if (GameManager.UI.IsAnyPopupOpened() == false)
|
|
{
|
|
_flipCenterState = EFlipCenterState.Complete;
|
|
}
|
|
break;
|
|
// 카드 선택을 기다린다.
|
|
case EFlipCenterState.WaitForCardSelect:
|
|
if (GameManager.UI.IsAnyPopupOpened() == false)
|
|
{
|
|
_flipCenterState = EFlipCenterState.Complete;
|
|
}
|
|
break;
|
|
case EFlipCenterState.WaitForKissDirect:
|
|
{
|
|
BringOtherPlayersPeeCard(1, PlayerTurn);
|
|
_delay = 0.25f;
|
|
_flipCenterState = EFlipCenterState.Complete;
|
|
}
|
|
break;
|
|
// 완료
|
|
case EFlipCenterState.Complete:
|
|
{
|
|
this._flipCenterIndex = 0;
|
|
_flipCenterState = EFlipCenterState.FlipCenterCard;
|
|
CurrentCoroutineType = EGameWorkFlowType.BringTheGetableCards;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void CardSelectCallback_Flip(ECardType type)
|
|
{
|
|
_lstAvailableCardTypes.Add(_flipedCardSlot.CardType);
|
|
_lstAvailableCardTypes.Add(type);
|
|
}
|
|
}
|