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)
|
||
{
|
||
// ī<>带 <20><><EFBFBD><EFBFBD><EFBFBD>´<EFBFBD>.
|
||
case EFlipCenterState.FlipCenterCard:
|
||
{
|
||
for (int i = 0; i < _lstCardSlots.Count; i++)
|
||
{
|
||
if (_lstCardSlots[i].LocationType == ECardLocationType.Center)
|
||
{
|
||
_flipedCardSlot = _lstCardSlots[i];
|
||
break;
|
||
}
|
||
}
|
||
|
||
// <20><><EFBFBD>ʽ<EFBFBD> ī<><C4AB><EFBFBD><EFBFBD>
|
||
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;
|
||
}
|
||
// <20>߾<EFBFBD> ī<>嵦<EFBFBD><E5B5A6><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ī<>尡 '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>' ī<><C4AB><EFBFBD><EFBFBD>
|
||
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");
|
||
}
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ī<><C4AB><EFBFBD> <20>߾<EFBFBD> ī<>嵦<EFBFBD><E5B5A6><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ī<><C4AB><EFBFBD><EFBFBD> '<27><>'<27><> <20><>ġ<EFBFBD>Ѵٸ<D1B4>
|
||
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;
|
||
}
|
||
// <20><> <20><>
|
||
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);
|
||
|
||
// <20><> <20>Ա<EFBFBD>
|
||
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);
|
||
|
||
// <20><><EFBFBD><EFBFBD> <20>ִ<EFBFBD> <20><><EFBFBD>ʽ<EFBFBD>ī<EFBFBD>嵵 <20><><EFBFBD><EFBFBD><EFBFBD>´<EFBFBD>.
|
||
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;
|
||
}
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20>ִ<EFBFBD>.
|
||
else if (matchedFloorCards.Count == 3)
|
||
{
|
||
ECardType leftCard = ECardType.Max;
|
||
ECardType rightCard = ECardType.Max;
|
||
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ī<><C4AB> <20><><EFBFBD><EFBFBD>
|
||
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);
|
||
|
||
// <20><><EFBFBD>ǰ<EFBFBD> <20>ƴϰ<C6B4> <20><><EFBFBD> ī<>尡 <20><> <20><> '<27><>' <20><> <20><>
|
||
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;
|
||
}
|
||
}
|
||
}
|
||
// <20>ٴ<EFBFBD><D9B4>п<EFBFBD> <20><>ġ<EFBFBD><C4A1>
|
||
else if (matchedFloorCards.Count == 2)
|
||
{
|
||
_lstAvailableCardTypes.Add(matchedFloorCards[0].CardType);
|
||
_lstAvailableCardTypes.Add(matchedFloorCards[1].CardType);
|
||
_flipCenterState = EFlipCenterState.Complete;
|
||
}
|
||
// <20><>ġ<EFBFBD><C4A1><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>.
|
||
else if (matchedFloorCards.Count == 1)
|
||
{
|
||
_flipCenterState = EFlipCenterState.Complete;
|
||
}
|
||
else
|
||
{
|
||
LogicalError($"{nameof(FlipCenterStateMachine)} {nameof(EFlipCenterState.NotMatchedWithDiscardType)} case logical error");
|
||
}
|
||
}
|
||
break;
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ī<><C4AB><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> '<27><>' <20>̶<EFBFBD><CCB6>
|
||
case EFlipCenterState.MatchedWithDiscardType:
|
||
{
|
||
int matchedCardNumber = GetMatchedCardSlotNumber(ECardLocationType.Floor, _flipedCardSlot.MonthType);
|
||
|
||
// <20><><EFBFBD><EFBFBD>!
|
||
if (matchedCardNumber == 4)
|
||
{
|
||
EffectPanel.Direct(EEffectDirectType.Ddadak, PlayerTurn);
|
||
_delay = EffectPanel.GetEffectDuration(EEffectDirectType.Ddadak);
|
||
_dicBbug_State.Remove(_flipedCardSlot.MonthType);
|
||
|
||
// <20>ߺ<EFBFBD><DFBA><EFBFBD><EFBFBD><EFBFBD> <20>ʵ<EFBFBD><CAB5><EFBFBD> <20><><EFBFBD><EFBFBD>ش<EFBFBD>.
|
||
_lstAvailableCardTypes.Clear();
|
||
|
||
for (int i = 0; i < _lstCardSlots.Count; i++)
|
||
{
|
||
if (_lstCardSlots[i].MonthType == _flipedCardSlot.MonthType)
|
||
_lstAvailableCardTypes.Add(_lstCardSlots[i].CardType);
|
||
|
||
// <20>ٴ<EFBFBD> <20>п<EFBFBD> <20>ִ<EFBFBD> <20>ڻ<EFBFBD><DABB>ߴ<EFBFBD> <20><> Ÿ<><C5B8> ī<><C4AB>鿡 <20><><EFBFBD>ʽ<EFBFBD>ī<EFBFBD>尡 <20>ִٸ<D6B4> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20>ֵ<EFBFBD><D6B5><EFBFBD> <20>߰<EFBFBD><DFB0>Ѵ<EFBFBD>.
|
||
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;
|
||
}
|
||
// <20><>
|
||
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);
|
||
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20>ֵ<EFBFBD><D6B5><EFBFBD> <20><>Ƴ<EFBFBD><C6B3><EFBFBD> <20><><EFBFBD><EFBFBD>Ʈ<EFBFBD><C6AE> <20><><EFBFBD><EFBFBD>ش<EFBFBD>.
|
||
_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;
|
||
// '<27><>'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>ٸ<EFBFBD><D9B8><EFBFBD>.
|
||
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;
|
||
// ù<><C3B9><EFBFBD>ϰ<EFBFBD><CFB0> <20>˾<EFBFBD><CBBE><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>ٸ<EFBFBD><D9B8><EFBFBD>.
|
||
case EFlipCenterState.WaitforBbugPopupClose:
|
||
if (GameManager.UI.IsAnyPopupOpened() == false)
|
||
{
|
||
_flipCenterState = EFlipCenterState.Complete;
|
||
}
|
||
break;
|
||
// ī<><C4AB> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>ٸ<EFBFBD><D9B8><EFBFBD>.
|
||
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;
|
||
// <20>Ϸ<EFBFBD>
|
||
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);
|
||
}
|
||
}
|