1184 lines
44 KiB
C#
1184 lines
44 KiB
C#
using CodeJay.CodeJayUtility;
|
|
using CodeJay.Enum;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.InteropServices;
|
|
using UnityEngine;
|
|
|
|
public class CardTypeComparer : IComparer<ECardType>
|
|
{
|
|
public int Compare(ECardType a, ECardType b)
|
|
{
|
|
if (a == ECardType.Max && b != ECardType.Max)
|
|
return 1;
|
|
if (a != ECardType.Max && b == ECardType.Max)
|
|
return -1;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
public partial class GamePanel : MonoBehaviour
|
|
{
|
|
private const int FLOOR_CARD_STACK = 6;
|
|
|
|
|
|
public static void ListInitialize(ref List<ECardType> list, int length)
|
|
{
|
|
if (list == null)
|
|
{
|
|
list = new List<ECardType>();
|
|
list.Capacity = length;
|
|
|
|
for (int i = 0; i < length; i++)
|
|
list.Add(ECardType.Max);
|
|
}
|
|
|
|
if (length == 0)
|
|
list.Clear();
|
|
else
|
|
{
|
|
for (int i = 0; i < length; i++)
|
|
{
|
|
if (list.Count > i)
|
|
list[i] = ECardType.Max;
|
|
else
|
|
list.Add(ECardType.Max);
|
|
}
|
|
}
|
|
}
|
|
|
|
[Header("Extension =====")]
|
|
[SerializeField] private RectTransform CenterDeckRT;
|
|
[SerializeField] private RectTransform[] FloorRTs;
|
|
[SerializeField] private RectTransform[] PlayerHandRTs;
|
|
[SerializeField] private RectTransform[] AIHandRTs;
|
|
|
|
[Header("ScoreBoards =====")]
|
|
[SerializeField] private ScorePanelScaler Player_Ghwang;
|
|
[SerializeField] private ScorePanelScaler Player_Yul;
|
|
[SerializeField] private ScorePanelScaler Player_Tee;
|
|
[SerializeField] private ScorePanelScaler Player_Pee;
|
|
[SerializeField] private ScorePanelScaler AI_Ghwang;
|
|
[SerializeField] private ScorePanelScaler AI_Yul;
|
|
[SerializeField] private ScorePanelScaler AI_Tee;
|
|
[SerializeField] private ScorePanelScaler AI_Pee;
|
|
|
|
/// <summary>Floor Card CardTypes.</summary>
|
|
private List<ECardType> _lstFloorCards;
|
|
/// <summary>User's CardTypes</summary>
|
|
private List<ECardType> _lstPlayerHandCardTypes;
|
|
/// <summary>AI CardTypes</summary>
|
|
private List<ECardType> _lstAIHandCardTypes;
|
|
/// <summary>AI Hand Gudide Types.</summary>
|
|
private List<EGuideType> _lstAIHandGuideTypes;
|
|
|
|
/// <summary>user's Card Types In Player ScoreBoard.</summary>
|
|
private List<ECardType> _lstPlayerScoreCards;
|
|
/// <summary>AI's Card Types In Player ScoreBoard.</summary>
|
|
private List<ECardType> _lstAIScoreCards;
|
|
|
|
/// <summary>this List used when Bring a card In coroMoveToScoreBoard Coroutine.</summary>
|
|
private List<ECardType> _lstAvailableCardTypes;
|
|
|
|
/// <summary>if 'Bbug' occurs, add it to this container.
|
|
/// <para>if the value is 'true', the player did it,if not, the AI did it.</para></summary>
|
|
private Dictionary<ECardMonthType, EBbugState> _dicBbug_State;
|
|
|
|
private HashSet<ECombinationType> _hashPlayerCombinations;
|
|
private HashSet<ECombinationType> _hashAICombinations;
|
|
private HashSet<EScoreMutiplyType> _hashScoreMultiplyTypes;
|
|
|
|
// For Debug
|
|
private void ShowLog()
|
|
{
|
|
string str = "\n## Floor Cards ##";
|
|
for (int i = 0; i < _lstFloorCards.Count; i++)
|
|
str += $"\n{i} : {_lstFloorCards[i]}";
|
|
|
|
str += "\n\ns\n## <color=green>Player</color> Hands ##";
|
|
for (int i = 0; i < _lstPlayerHandCardTypes.Count; i++)
|
|
str += $"\n{i} : {_lstPlayerHandCardTypes[i]}";
|
|
|
|
str += "\n\n## <color=green>Player</color> Guide ##";
|
|
for (int i = 0; i < _lstCardSlots.Count; i++)
|
|
{
|
|
if (_lstCardSlots[i].LocationType == ECardLocationType.Player_Hand)
|
|
str += $"\n{i} : {_lstCardSlots[i].GuideType}";
|
|
}
|
|
|
|
str += "\n\n## <color=green>Player</color> Score ##";
|
|
for (int i = 0; i < _lstPlayerScoreCards.Count; i++)
|
|
str += $"\n{i} : {_lstPlayerScoreCards[i]}";
|
|
|
|
|
|
str += "\n\n## <color=red>AI</color> Hands ##";
|
|
for (int i = 0; i < _lstAIHandCardTypes.Count; i++)
|
|
str += $"\n{i} : {_lstAIHandCardTypes[i]}";
|
|
|
|
str += "\n\n## <color=red>AI</color> Hand Guide ##";
|
|
for (int i = 0; i < _lstAIHandGuideTypes.Count; i++)
|
|
str += $"\n{i} : {_lstAIHandGuideTypes[i]}";
|
|
|
|
str += "\n## <color=red>AI</color> Score ##\n";
|
|
for (int i = 0; i < _lstAIScoreCards.Count; i++)
|
|
str += $"\n{i} : {_lstAIScoreCards[i]}";
|
|
|
|
str += "\n## <color=cyan>Getable</color> List ##\n";
|
|
for (int i = 0; i < _lstAvailableCardTypes.Count; i++)
|
|
str += $"\n{i} : {_lstAvailableCardTypes[i]}";
|
|
|
|
str += "\n## <color=cyan>Bbug State</color> List ##\n";
|
|
foreach (var pair in _dicBbug_State)
|
|
str += $"\n{pair.Key} : {pair.Value}";
|
|
|
|
Debug.Log(str);
|
|
|
|
}
|
|
|
|
private void DataInitialize()
|
|
{
|
|
ListInitialize(ref _lstFloorCards, FloorRTs.Length);
|
|
ListInitialize(ref _lstPlayerHandCardTypes, PlayerHandRTs.Length);
|
|
ListInitialize(ref _lstAIHandCardTypes, AIHandRTs.Length);
|
|
ListInitialize(ref _lstPlayerScoreCards, 0);
|
|
ListInitialize(ref _lstAIScoreCards, 0);
|
|
|
|
ListInitialize(ref _lstAvailableCardTypes, 0);
|
|
|
|
if (_hashPlayerCombinations == null) _hashPlayerCombinations = new HashSet<ECombinationType>();
|
|
_hashPlayerCombinations.Clear();
|
|
|
|
if (_hashAICombinations == null) _hashAICombinations = new HashSet<ECombinationType>();
|
|
_hashAICombinations.Clear();
|
|
|
|
if (_dicBbug_State == null) _dicBbug_State = new Dictionary<ECardMonthType, EBbugState>();
|
|
_dicBbug_State.Clear();
|
|
|
|
if (_lstAIHandGuideTypes == null)
|
|
{
|
|
_lstAIHandGuideTypes = new List<EGuideType>();
|
|
|
|
for (int i = 0; i < 10; i++)
|
|
_lstAIHandGuideTypes.Add(EGuideType.None);
|
|
}
|
|
else
|
|
{
|
|
for (int i = 0; i < 10; i++)
|
|
_lstAIHandGuideTypes[i] = EGuideType.None;
|
|
}
|
|
|
|
// Partial Class
|
|
this.InitDistributeData();
|
|
this.InitDiscardData();
|
|
this.InitCheckMatchedAfterDiscardData();
|
|
this.InitFlipCenterData();
|
|
}
|
|
|
|
#region Get
|
|
private CardSlot GetCardSlot(ECardType type)
|
|
{
|
|
for (int i = 0; i < _lstCardSlots.Count; i++)
|
|
{
|
|
if (_lstCardSlots[i].CardType == type)
|
|
return _lstCardSlots[i];
|
|
}
|
|
|
|
// Logically, this Shouldn not be readched.
|
|
throw new System.Exception($"Logical Error. GamePanel_Extension.{nameof(GetCardSlot)}. ECardType: {type}");
|
|
}
|
|
|
|
private List<CardSlot> GetMatchedCardSlots(ECardLocationType location)
|
|
{
|
|
List<CardSlot> slot = new List<CardSlot>();
|
|
|
|
for (int i = 0; i < _lstCardSlots.Count; i++)
|
|
{
|
|
if (_lstCardSlots[i].LocationType == location)
|
|
slot.Add(_lstCardSlots[i]);
|
|
}
|
|
return slot;
|
|
}
|
|
|
|
private List<CardSlot> GetMatchedCardSlots(ECardLocationType location, ECardMonthType monthType)
|
|
{
|
|
List<CardSlot> slot = new List<CardSlot>();
|
|
|
|
for (int i = 0; i < _lstCardSlots.Count; i++)
|
|
{
|
|
if (_lstCardSlots[i].LocationType == location && _lstCardSlots[i].MonthType == monthType)
|
|
slot.Add(_lstCardSlots[i]);
|
|
}
|
|
return slot;
|
|
}
|
|
|
|
private int GetMatchedCardSlotNumber(ECardLocationType location)
|
|
{
|
|
int result = 0;
|
|
|
|
for (int i = 0; i < _lstCardSlots.Count; i++)
|
|
{
|
|
if (_lstCardSlots[i].LocationType == location)
|
|
result++;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
private int GetMatchedCardSlotNumber(ECardLocationType location, ECardMonthType monthType)
|
|
{
|
|
int result = 0;
|
|
|
|
for (int i = 0; i < _lstCardSlots.Count; i++)
|
|
{
|
|
if (_lstCardSlots[i].LocationType == location && _lstCardSlots[i].MonthType == monthType)
|
|
result++;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
private EBbugState GetBbugState(ECardMonthType type)
|
|
{
|
|
if (_dicBbug_State.ContainsKey(type))
|
|
return _dicBbug_State[type];
|
|
else
|
|
return EBbugState.None;
|
|
}
|
|
|
|
private List<ECardType> GetMathcedFloorCardType(ECardType type)
|
|
{
|
|
List<ECardType> list = new List<ECardType>();
|
|
for (int i = 0; i < _lstFloorCards.Count; i++)
|
|
{
|
|
if (Utility.IsSameMonthCard(type, _lstFloorCards[i]))
|
|
list.Add(_lstFloorCards[i]);
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
public int GetTotalScore(bool isPlayer, bool withMultiplyType = true)
|
|
{
|
|
int result = 0;
|
|
int peeNumber = 0;
|
|
int yulNumber = 0;
|
|
int teeNumber = 0;
|
|
|
|
// Calculate Player Score
|
|
if (isPlayer)
|
|
{
|
|
for (int i = 0; i < _lstPlayerScoreCards.Count; i++)
|
|
{
|
|
switch (Converter.CardTypeToScoreType(_lstPlayerScoreCards[i]))
|
|
{
|
|
case ECardScoreType.Pee:
|
|
if (_lstPlayerScoreCards[i] == ECardType.Bonus_3)
|
|
peeNumber += 3;
|
|
else if (Utility.IsDoublePee(_lstPlayerScoreCards[i], UseSepYulgget_To_Pee))
|
|
peeNumber += 2;
|
|
else
|
|
peeNumber++;
|
|
break;
|
|
case ECardScoreType.Yul_ggeut:
|
|
yulNumber++;
|
|
break;
|
|
case ECardScoreType.Tee:
|
|
teeNumber++;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (peeNumber >= 10)
|
|
result += peeNumber - 9;
|
|
if (yulNumber >= 5)
|
|
result += yulNumber - 4;
|
|
if (teeNumber >= 5)
|
|
result += teeNumber - 4;
|
|
|
|
foreach (var pair in _hashPlayerCombinations)
|
|
{
|
|
result += Utility.GetCombinationScore(pair);
|
|
}
|
|
}
|
|
// Calculate AI Score
|
|
else
|
|
{
|
|
for (int i = 0; i < _lstAIScoreCards.Count; i++)
|
|
{
|
|
switch (Converter.CardTypeToScoreType(_lstAIScoreCards[i]))
|
|
{
|
|
case ECardScoreType.Pee:
|
|
if (_lstAIScoreCards[i] == ECardType.Bonus_3)
|
|
peeNumber += 3;
|
|
else if (Utility.IsDoublePee(_lstAIScoreCards[i], UseSepYulgget_To_Pee))
|
|
peeNumber += 2;
|
|
else
|
|
peeNumber++;
|
|
break;
|
|
case ECardScoreType.Yul_ggeut:
|
|
yulNumber++;
|
|
break;
|
|
case ECardScoreType.Tee:
|
|
teeNumber++;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (peeNumber >= 10)
|
|
result += peeNumber - 9;
|
|
if (yulNumber >= 5)
|
|
result += yulNumber - 4;
|
|
if (teeNumber >= 5)
|
|
result += teeNumber - 4;
|
|
|
|
foreach (var pair in _hashAICombinations)
|
|
{
|
|
result += Utility.GetCombinationScore(pair);
|
|
}
|
|
}
|
|
|
|
if (withMultiplyType)
|
|
{
|
|
foreach (var pair in _hashScoreMultiplyTypes)
|
|
{
|
|
if (pair == EScoreMutiplyType.Shake)
|
|
{
|
|
if (isPlayer)
|
|
result *= CodeJay.CodeJayUtility.Utility.GetScoreMultiplyValue(pair) * Player_Bell;
|
|
else
|
|
result *= CodeJay.CodeJayUtility.Utility.GetScoreMultiplyValue(pair) * AI_Bell;
|
|
}
|
|
else if (pair == EScoreMutiplyType.ClickedFromResultPopup)
|
|
result *= CodeJay.CodeJayUtility.Utility.GetScoreMultiplyValue(pair) * Player_Milgi;
|
|
else
|
|
result *= CodeJay.CodeJayUtility.Utility.GetScoreMultiplyValue(pair);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public int GetScoreBoardTypeNumber(bool isPlayer, ECardScoreType scoreType)
|
|
{
|
|
int result = 0;
|
|
|
|
if (isPlayer)
|
|
{
|
|
for (int i = 0; i < _lstPlayerScoreCards.Count; i++)
|
|
{
|
|
if (Converter.CardTypeToScoreType(_lstPlayerScoreCards[i]) == scoreType)
|
|
{
|
|
if (_lstPlayerScoreCards[i] == ECardType.Sep_Yulkkeut)
|
|
{
|
|
if (UseSepYulgget_To_Pee)
|
|
{
|
|
if (scoreType == ECardScoreType.Pee)
|
|
result += 2;
|
|
}
|
|
else
|
|
{
|
|
if (scoreType == ECardScoreType.Yul_ggeut)
|
|
result++;
|
|
}
|
|
}
|
|
else if (scoreType == ECardScoreType.Pee)
|
|
{
|
|
if (_lstPlayerScoreCards[i] == ECardType.Bonus_3)
|
|
result += 3;
|
|
else if (Utility.IsDoublePee(_lstPlayerScoreCards[i], UseSepYulgget_To_Pee))
|
|
result += 2;
|
|
else
|
|
result++;
|
|
}
|
|
else
|
|
result++;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int i = 0; i < _lstAIScoreCards.Count; i++)
|
|
{
|
|
if (Converter.CardTypeToScoreType(_lstAIScoreCards[i]) == scoreType)
|
|
{
|
|
if (_lstAIScoreCards[i] == ECardType.Sep_Yulkkeut)
|
|
{
|
|
if (UseSepYulgget_To_Pee)
|
|
{
|
|
if (scoreType == ECardScoreType.Pee)
|
|
result += 2;
|
|
}
|
|
else
|
|
{
|
|
if (scoreType == ECardScoreType.Yul_ggeut)
|
|
result++;
|
|
}
|
|
}
|
|
else if (scoreType == ECardScoreType.Pee)
|
|
{
|
|
if (_lstAIScoreCards[i] == ECardType.Bonus_3)
|
|
result += 3;
|
|
else if (Utility.IsDoublePee(_lstAIScoreCards[i], UseSepYulgget_To_Pee))
|
|
result += 2;
|
|
else
|
|
result++;
|
|
}
|
|
else
|
|
result++;
|
|
}
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public List<EScoreMutiplyType> GetAndUpdateScoreMultiplyType(bool isPlayerWon)
|
|
{
|
|
int player_pee = GetScoreBoardTypeNumber(true, ECardScoreType.Pee);
|
|
int player_Ghwang = GetScoreBoardTypeNumber(true, ECardScoreType.Ghwang);
|
|
int player_Yul_ggeut = GetScoreBoardTypeNumber(true, ECardScoreType.Yul_ggeut);
|
|
|
|
int ai_pee = GetScoreBoardTypeNumber(false, ECardScoreType.Pee);
|
|
int ai_Ghwang = GetScoreBoardTypeNumber(false, ECardScoreType.Ghwang);
|
|
int ai_Yul_ggeut = GetScoreBoardTypeNumber(false, ECardScoreType.Yul_ggeut);
|
|
|
|
if (isPlayerWon)
|
|
{
|
|
if (AI_Go > 0)
|
|
{
|
|
if (_hashScoreMultiplyTypes.Contains(EScoreMutiplyType.Gobak) == false)
|
|
_hashScoreMultiplyTypes.Add(EScoreMutiplyType.Gobak);
|
|
}
|
|
if (player_pee >= 10 && ai_pee <= 7)
|
|
{
|
|
if (_hashScoreMultiplyTypes.Contains(EScoreMutiplyType.Peebak) == false)
|
|
_hashScoreMultiplyTypes.Add(EScoreMutiplyType.Peebak);
|
|
}
|
|
if (player_Ghwang >= 3 && ai_Ghwang <= 0)
|
|
{
|
|
if (_hashScoreMultiplyTypes.Contains(EScoreMutiplyType.Gwhangbak) == false)
|
|
_hashScoreMultiplyTypes.Add(EScoreMutiplyType.Gwhangbak);
|
|
}
|
|
if (Player_Bell > 0)
|
|
{
|
|
if (_hashScoreMultiplyTypes.Contains(EScoreMutiplyType.Shake) == false)
|
|
_hashScoreMultiplyTypes.Add(EScoreMutiplyType.Shake);
|
|
}
|
|
if (player_Yul_ggeut >= 7)
|
|
{
|
|
if (_hashScoreMultiplyTypes.Contains(EScoreMutiplyType.Meongbak) == false)
|
|
_hashScoreMultiplyTypes.Add(EScoreMutiplyType.Meongbak);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (Player_Go > 0)
|
|
{
|
|
if (_hashScoreMultiplyTypes.Contains(EScoreMutiplyType.Gobak) == false)
|
|
_hashScoreMultiplyTypes.Add(EScoreMutiplyType.Gobak);
|
|
}
|
|
if (ai_pee >= 10 && player_pee <= 7)
|
|
{
|
|
if (_hashScoreMultiplyTypes.Contains(EScoreMutiplyType.Peebak) == false)
|
|
_hashScoreMultiplyTypes.Add(EScoreMutiplyType.Peebak);
|
|
}
|
|
if (ai_Ghwang >= 3 && player_Ghwang <= 0)
|
|
{
|
|
if (_hashScoreMultiplyTypes.Contains(EScoreMutiplyType.Gwhangbak) == false)
|
|
_hashScoreMultiplyTypes.Add(EScoreMutiplyType.Gwhangbak);
|
|
}
|
|
if (AI_Bell > 0)
|
|
{
|
|
if (_hashScoreMultiplyTypes.Contains(EScoreMutiplyType.Shake) == false)
|
|
_hashScoreMultiplyTypes.Add(EScoreMutiplyType.Shake);
|
|
}
|
|
if (ai_Yul_ggeut >= 7)
|
|
{
|
|
if (_hashScoreMultiplyTypes.Contains(EScoreMutiplyType.Meongbak) == false)
|
|
_hashScoreMultiplyTypes.Add(EScoreMutiplyType.Meongbak);
|
|
}
|
|
}
|
|
|
|
if (_hashScoreMultiplyTypes.Count <= 0)
|
|
return null;
|
|
else
|
|
{
|
|
List<EScoreMutiplyType> lst = new List<EScoreMutiplyType>();
|
|
|
|
foreach (var pair in _hashScoreMultiplyTypes)
|
|
lst.Add(pair);
|
|
|
|
return lst;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Get RectTransform Methods
|
|
public RectTransform GetRectTransformAndModifyContainer(ECardLocationType location, ECardType type)
|
|
{
|
|
switch (location)
|
|
{
|
|
case ECardLocationType.Center:
|
|
return CenterDeckRT;
|
|
case ECardLocationType.Floor:
|
|
{
|
|
int i = 0;
|
|
for (i = 0; i < FloorRTs.Length; i += FLOOR_CARD_STACK)
|
|
{
|
|
// 1. Find Matched Month Type In '_lstFloorCards'
|
|
if (Utility.IsSameMonthType(_lstFloorCards[i], type))
|
|
{
|
|
// 1-1. if it Matched, Return Empty RectTransform.
|
|
for (int j = 0; j < FLOOR_CARD_STACK; j++)
|
|
{
|
|
if (_lstFloorCards[i + j] == ECardType.Max)
|
|
{
|
|
_lstFloorCards[i + j] = type;
|
|
return FloorRTs[i + j];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 2. if it is not exist MatchedType, Return Empty RectTransform.
|
|
for (i = 0; i < FloorRTs.Length; i += FLOOR_CARD_STACK)
|
|
{
|
|
if (_lstFloorCards[i] == ECardType.Max)
|
|
{
|
|
_lstFloorCards[i] = type;
|
|
return FloorRTs[i];
|
|
}
|
|
}
|
|
|
|
// Logically, this Shouldn not be readched.
|
|
throw new System.Exception($"Logical Error. GamePanel_Extension.{nameof(GetRectTransformAndModifyContainer)}.{location}" + ": " + type.ToString() + " i: " + i.ToString());
|
|
}
|
|
case ECardLocationType.Player_Hand:
|
|
{
|
|
int i = 0;
|
|
for (i = 0; i < _lstPlayerHandCardTypes.Count; i++)
|
|
{
|
|
if (_lstPlayerHandCardTypes[i] == ECardType.Max)
|
|
{
|
|
_lstPlayerHandCardTypes[i] = type;
|
|
return PlayerHandRTs[i];
|
|
}
|
|
}
|
|
|
|
// Logically, this Shouldn not be readched.
|
|
throw new System.Exception($"Logical Error. GamePanel_Extension.{nameof(GetRectTransformAndModifyContainer)}.{location}" + ": " + type.ToString() + " i: " + i.ToString());
|
|
}
|
|
case ECardLocationType.Player_Score:
|
|
{
|
|
ECardScoreType scoreType = Converter.CardTypeToScoreType(type);
|
|
_lstPlayerScoreCards.Add(type);
|
|
switch (scoreType)
|
|
{
|
|
case ECardScoreType.Ghwang:
|
|
return Player_Ghwang.AddCard(type);
|
|
case ECardScoreType.Yul_ggeut:
|
|
return Player_Yul.AddCard(type);
|
|
case ECardScoreType.Tee:
|
|
return Player_Tee.AddCard(type);
|
|
case ECardScoreType.Pee:
|
|
return Player_Pee.AddCard(type);
|
|
default:
|
|
// Logically, this Shouldn not be readched.
|
|
throw new System.Exception($"Logical Error. GamePanel_Extension.{nameof(GetRectTransformAndModifyContainer)}.{location}");
|
|
}
|
|
}
|
|
case ECardLocationType.AI_Hand:
|
|
{
|
|
int i = 0;
|
|
for (i = 0; i < _lstAIHandCardTypes.Count; i++)
|
|
{
|
|
if (_lstAIHandCardTypes[i] == ECardType.Max)
|
|
{
|
|
_lstAIHandCardTypes[i] = type;
|
|
return AIHandRTs[i];
|
|
}
|
|
}
|
|
|
|
// Logically, this Shouldn not be readched.
|
|
throw new System.Exception($"Logical Error. GamePanel_Extension.{nameof(GetRectTransformAndModifyContainer)}.{location}" + " type: " + type.ToString() + " i: " + i.ToString());
|
|
}
|
|
case ECardLocationType.AI_Score:
|
|
{
|
|
ECardScoreType scoreType = Converter.CardTypeToScoreType(type);
|
|
_lstAIScoreCards.Add(type);
|
|
|
|
switch (scoreType)
|
|
{
|
|
case ECardScoreType.Ghwang:
|
|
return AI_Ghwang.AddCard(type);
|
|
case ECardScoreType.Yul_ggeut:
|
|
return AI_Yul.AddCard(type);
|
|
case ECardScoreType.Tee:
|
|
return AI_Tee.AddCard(type);
|
|
case ECardScoreType.Pee:
|
|
return AI_Pee.AddCard(type);
|
|
default:
|
|
// Logically, this Shouldn not be readched.
|
|
throw new System.Exception($"Logical Error. GamePanel_Extension.{nameof(GetRectTransformAndModifyContainer)}.{location}");
|
|
}
|
|
}
|
|
default:
|
|
// Logically, this Shouldn not be readched.
|
|
throw new System.Exception($"Logical Error. GamePanel_Extension.{nameof(GetRectTransformAndModifyContainer)}.{location}");
|
|
}
|
|
}
|
|
|
|
public RectTransform GetMatchedRectTransform(ECardLocationType location, ECardType type)
|
|
{
|
|
switch (location)
|
|
{
|
|
case ECardLocationType.Floor:
|
|
{
|
|
for (int i = 0; i < _lstFloorCards.Count; i++)
|
|
{
|
|
if (_lstFloorCards[i] == type)
|
|
return FloorRTs[i];
|
|
}
|
|
|
|
// Logically, this Shouldn not be readched.
|
|
throw new System.Exception($"Logical Error. GamePanel_Extension.{nameof(GetRectTransformAndModifyContainer)}.{location} \nECardType: {type}");
|
|
}
|
|
case ECardLocationType.Player_Hand:
|
|
{
|
|
for (int i = 0; i < _lstPlayerHandCardTypes.Count; i++)
|
|
{
|
|
if (_lstPlayerHandCardTypes[i] == type)
|
|
return PlayerHandRTs[i];
|
|
}
|
|
|
|
// Logically, this Shouldn not be readched.
|
|
throw new System.Exception($"Logical Error. GamePanel_Extension.{nameof(GetRectTransformAndModifyContainer)}.{location} \nECardType: {type}");
|
|
}
|
|
case ECardLocationType.AI_Hand:
|
|
{
|
|
for (int i = 0; i < _lstAIHandCardTypes.Count; i++)
|
|
{
|
|
if (_lstAIHandCardTypes[i] == type)
|
|
return AIHandRTs[i];
|
|
}
|
|
|
|
// Logically, this Shouldn not be readched.
|
|
throw new System.Exception($"Logical Error. GamePanel_Extension.{nameof(GetRectTransformAndModifyContainer)}.{location} \nECardType: {type}");
|
|
}
|
|
default:
|
|
// Logically, this Shouldn not be readched.
|
|
throw new System.Exception($"Logical Error. GamePanel_Extension.{nameof(GetMatchedRectTransform)}.{location} \nECardType: {type}");
|
|
}
|
|
}
|
|
|
|
public RectTransform GetMatchedFloorRT(ECardMonthType monthType)
|
|
{
|
|
for (int i = 0; i < _lstFloorCards.Count; i += FLOOR_CARD_STACK)
|
|
{
|
|
if (Converter.CardTypeToMonthType(_lstFloorCards[i]) == monthType)
|
|
{
|
|
for (int j = 0; j < FLOOR_CARD_STACK; j++)
|
|
{
|
|
if (_lstFloorCards[i + j] == ECardType.Max)
|
|
return FloorRTs[i + j];
|
|
}
|
|
}
|
|
}
|
|
|
|
for (int i = 0; i < _lstFloorCards.Count; i += FLOOR_CARD_STACK)
|
|
{
|
|
if (_lstFloorCards[i] == ECardType.Max)
|
|
{
|
|
return FloorRTs[i];
|
|
}
|
|
}
|
|
|
|
// Logically, this Shouldn not be readched.
|
|
throw new System.Exception($"Logical Error. GamePanel_Extension.{nameof(GetMatchedFloorRT)}. ECardMonthType: {monthType}");
|
|
}
|
|
#endregion
|
|
|
|
#region Player Hand
|
|
private void SetGuideData(bool b)
|
|
{
|
|
// Only when it's the Player's turn can be true.
|
|
if (b)
|
|
{
|
|
List<ECardType> lstCardTypes = PlayerTurn ? _lstPlayerHandCardTypes : _lstAIHandCardTypes;
|
|
|
|
// 1. Check Floor, Ai Hand, Player Hand, AI ScoreBoard, Player ScoreBoard
|
|
// 2. Set Guide Image By '1.' result.
|
|
|
|
for (int i = 0; i < lstCardTypes.Count; i++)
|
|
{
|
|
if (lstCardTypes[i] == ECardType.Max)
|
|
{
|
|
if (PlayerTurn)
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
_lstAIHandGuideTypes[i] = EGuideType.Max;
|
|
}
|
|
continue;
|
|
}
|
|
else if (lstCardTypes[i] == ECardType.Bonus_1 || lstCardTypes[i] == ECardType.Bonus_2 || lstCardTypes[i] == ECardType.Bonus_3 ||
|
|
lstCardTypes[i] == ECardType.FlipCard_1 || lstCardTypes[i] == ECardType.FlipCard_2)
|
|
{
|
|
if (PlayerTurn)
|
|
{
|
|
CardSlot slot = GetCardSlot(lstCardTypes[i]);
|
|
slot.GuideType = EGuideType.Discardable;
|
|
}
|
|
else
|
|
_lstAIHandGuideTypes[i] = EGuideType.Discardable;
|
|
|
|
continue;
|
|
}
|
|
|
|
ECardMonthType monthType = Converter.CardTypeToMonthType(lstCardTypes[i]);
|
|
int PH_MathchedNumber = GetMatchedCardSlotNumber(ECardLocationType.Player_Hand, monthType);
|
|
int PS_MathchedNumber = GetMatchedCardSlotNumber(ECardLocationType.Player_Score, monthType);
|
|
int AIS_MathchedNumber = GetMatchedCardSlotNumber(ECardLocationType.AI_Score, monthType);
|
|
int F_MathchedNumber = GetMatchedCardSlotNumber(ECardLocationType.Floor, monthType);
|
|
|
|
EGuideType guideType = EGuideType.None;
|
|
|
|
if (F_MathchedNumber == 0)
|
|
{
|
|
if (PH_MathchedNumber >= 3)
|
|
guideType = EGuideType.Bell;
|
|
else if (PH_MathchedNumber == 2)
|
|
guideType = PS_MathchedNumber == 2 || AIS_MathchedNumber == 2 || (PS_MathchedNumber == 1 && AIS_MathchedNumber == 1) ? EGuideType.OnlyMine : EGuideType.None;
|
|
else
|
|
guideType = EGuideType.None;
|
|
}
|
|
else if (F_MathchedNumber == 1)
|
|
{
|
|
if (PH_MathchedNumber >= 3)
|
|
guideType = EGuideType.Bomb_Triple;
|
|
else if (PH_MathchedNumber == 2)
|
|
guideType = EGuideType.Discardable;
|
|
else if (PH_MathchedNumber == 1)
|
|
guideType = PS_MathchedNumber == 2 || AIS_MathchedNumber == 2 || (PS_MathchedNumber == 1 && AIS_MathchedNumber == 1) ? EGuideType.OnlyMine : EGuideType.Discardable;
|
|
else
|
|
guideType = EGuideType.None;
|
|
}
|
|
else if (F_MathchedNumber == 2)
|
|
{
|
|
if (PH_MathchedNumber >= 2)
|
|
guideType = EGuideType.Bomb_Double;
|
|
else if (PH_MathchedNumber == 1)
|
|
guideType = EGuideType.Selectable;
|
|
else
|
|
guideType = EGuideType.None;
|
|
}
|
|
else if (F_MathchedNumber == 3)
|
|
{
|
|
if (PH_MathchedNumber == 1)
|
|
{
|
|
if (GetBbugState(monthType) == EBbugState.Player)
|
|
guideType = EGuideType.Get_Bbug_Own;
|
|
else
|
|
guideType = EGuideType.Get_Bbug;
|
|
}
|
|
else
|
|
guideType = EGuideType.None;
|
|
}
|
|
else
|
|
{
|
|
// Logically, this Shouldn not be readched.
|
|
throw new System.Exception(
|
|
string.Format("Logical Error. GamePanel_Extension.{0}\nPH: {1}\n PS: {2}\nAIS: {3}\nFS: {4}",
|
|
new string[5] { nameof(SetGuideData), PH_MathchedNumber.ToString(), PS_MathchedNumber.ToString(), AIS_MathchedNumber.ToString(), F_MathchedNumber.ToString() })
|
|
);
|
|
}
|
|
|
|
if (PlayerTurn)
|
|
{
|
|
CardSlot slot = GetCardSlot(lstCardTypes[i]);
|
|
slot.GuideType = guideType;
|
|
}
|
|
else
|
|
{
|
|
_lstAIHandGuideTypes[i] = guideType;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (PlayerTurn)
|
|
{
|
|
var slots = GetMatchedCardSlots(ECardLocationType.Player_Hand);
|
|
|
|
for (int i = 0; i < slots.Count; i++)
|
|
slots[i].GuideTypeImageEnabled = false;
|
|
}
|
|
else
|
|
{
|
|
for (int i = 0; i < _lstAIHandGuideTypes.Count; i++)
|
|
_lstAIHandGuideTypes[i] = EGuideType.None;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void EnabledPlayerHandRaycast(bool b)
|
|
{
|
|
for (int i = 0; i < _lstCardSlots.Count; i++)
|
|
{
|
|
if (b)
|
|
{
|
|
if (_lstCardSlots[i].LocationType == ECardLocationType.Player_Hand)
|
|
_lstCardSlots[i].RaycastTarget = true;
|
|
}
|
|
else
|
|
{
|
|
_lstCardSlots[i].RaycastTarget = false;
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Sort
|
|
public void SortPlayerCards()
|
|
{
|
|
_lstPlayerHandCardTypes.Sort((ECardType a, ECardType b) => { return a.CompareTo(b); });
|
|
|
|
for (int i = 0; i < _lstPlayerHandCardTypes.Count; i++)
|
|
{
|
|
RectTransform rt = this.GetMatchedRectTransform(ECardLocationType.Player_Hand, _lstPlayerHandCardTypes[i]);
|
|
|
|
if (_lstPlayerHandCardTypes[i] != ECardType.Max)
|
|
GetCardSlot(_lstPlayerHandCardTypes[i]).Move(ECardLocationType.Player_Hand, ECardLocationType.Player_Hand, rt);
|
|
}
|
|
}
|
|
|
|
public void SortAICards()
|
|
{
|
|
_lstAIHandCardTypes.Sort((ECardType a, ECardType b) => { return a.CompareTo(b); });
|
|
|
|
for (int i = 0; i < _lstAIHandCardTypes.Count; i++)
|
|
{
|
|
RectTransform rt = this.GetMatchedRectTransform(ECardLocationType.AI_Hand, _lstAIHandCardTypes[i]);
|
|
|
|
if (_lstAIHandCardTypes[i] != ECardType.Max)
|
|
GetCardSlot(_lstAIHandCardTypes[i]).Move(ECardLocationType.AI_Hand, ECardLocationType.AI_Hand, rt);
|
|
}
|
|
}
|
|
|
|
public void SortFloorCards()
|
|
{
|
|
for (int i = 0; i < _lstFloorCards.Count; i += FLOOR_CARD_STACK)
|
|
{
|
|
_lstFloorCards.Sort(i, FLOOR_CARD_STACK, new CardTypeComparer());
|
|
}
|
|
var matchedFloorCardSlots = GetMatchedCardSlots(ECardLocationType.Floor);
|
|
|
|
for (int i = 0; i < _lstFloorCards.Count; i++)
|
|
{
|
|
for (int j = 0; j < matchedFloorCardSlots.Count; j++)
|
|
{
|
|
if (_lstFloorCards[i] == matchedFloorCardSlots[j].CardType)
|
|
{
|
|
matchedFloorCardSlots[j].Move(ECardLocationType.Floor, ECardLocationType.Floor, GetMatchedRectTransform(ECardLocationType.Floor, _lstFloorCards[i]));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
public void CheckFloorBonus()
|
|
{
|
|
for (int i = 0; i < _lstCardSlots.Count; i++)
|
|
{
|
|
if (_lstCardSlots[i].LocationType == ECardLocationType.Floor)
|
|
{
|
|
if (_lstCardSlots[i].CardType == ECardType.Bonus_1 ||
|
|
_lstCardSlots[i].CardType == ECardType.Bonus_2 ||
|
|
_lstCardSlots[i].CardType == ECardType.Bonus_3)
|
|
{
|
|
_lstCardSlots[i].Move(ECardLocationType.Floor, ECardLocationType.Player_Score, GetRectTransformAndModifyContainer(ECardLocationType.Player_Score, _lstCardSlots[i].CardType));
|
|
DataMove(ECardLocationType.Floor, _lstCardSlots[i].CardType);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Discard(CardSlot slot) => _discardSlot = slot;
|
|
|
|
private void BringOtherPlayersPeeCard(int num, bool isPlayer)
|
|
{
|
|
for (int j = 0; j < num; j++)
|
|
{
|
|
if (isPlayer)
|
|
{
|
|
for (int i = 0; i < _lstCardSlots.Count; i++)
|
|
{
|
|
if (_lstCardSlots[i].LocationType == ECardLocationType.AI_Score &&
|
|
_lstCardSlots[i].ScoreType == ECardScoreType.Pee)
|
|
{
|
|
_lstCardSlots[i].Move(ECardLocationType.AI_Score, ECardLocationType.Player_Score, GetRectTransformAndModifyContainer(ECardLocationType.Player_Score, _lstCardSlots[i].CardType));
|
|
DataMove(ECardLocationType.AI_Score, _lstCardSlots[i].CardType);
|
|
AI_Pee.RemoveEmptyRT();
|
|
GameManager.Sound.ReserveSFX(ESFXType.Bring_Card_1, CardSlot.TWEEN_DURATION);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int i = 0; i < _lstCardSlots.Count; i++)
|
|
{
|
|
if (_lstCardSlots[i].LocationType == ECardLocationType.Player_Score &&
|
|
_lstCardSlots[i].ScoreType == ECardScoreType.Pee)
|
|
{
|
|
_lstCardSlots[i].Move(ECardLocationType.Player_Score, ECardLocationType.AI_Score, GetRectTransformAndModifyContainer(ECardLocationType.AI_Score, _lstCardSlots[i].CardType));
|
|
DataMove(ECardLocationType.Player_Score, _lstCardSlots[i].CardType);
|
|
Player_Pee.RemoveEmptyRT();
|
|
GameManager.Sound.ReserveSFX(ESFXType.Bring_Card_1, CardSlot.TWEEN_DURATION);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public string GetDetailString(bool isPlayer)
|
|
{
|
|
System.Text.StringBuilder strBuilder = new System.Text.StringBuilder();
|
|
|
|
int peeNumber = 0;
|
|
int yulNumber = 0;
|
|
int teeNumber = 0;
|
|
|
|
// Calculate Player Score
|
|
if (isPlayer)
|
|
{
|
|
for (int i = 0; i < _lstPlayerScoreCards.Count; i++)
|
|
{
|
|
switch (Converter.CardTypeToScoreType(_lstPlayerScoreCards[i]))
|
|
{
|
|
case ECardScoreType.Pee:
|
|
if (_lstPlayerScoreCards[i] == ECardType.Bonus_3)
|
|
peeNumber += 3;
|
|
else if (Utility.IsDoublePee(_lstPlayerScoreCards[i], UseSepYulgget_To_Pee))
|
|
peeNumber += 2;
|
|
else
|
|
peeNumber++;
|
|
break;
|
|
case ECardScoreType.Yul_ggeut:
|
|
yulNumber++;
|
|
break;
|
|
case ECardScoreType.Tee:
|
|
teeNumber++;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (Player_Go > 0 && Player_Go < 3)
|
|
{
|
|
if (Player_Go == 1)
|
|
strBuilder.Append("(1고1점");
|
|
else if (Player_Go == 2)
|
|
strBuilder.Append("(2고2점");
|
|
}
|
|
|
|
if (peeNumber >= 10)
|
|
{
|
|
if (Player_Go > 0 && Player_Go < 3)
|
|
strBuilder.Append($"+피{peeNumber - 9}점");
|
|
else
|
|
strBuilder.Append($"(피{peeNumber - 9}점");
|
|
}
|
|
if (yulNumber >= 5)
|
|
{
|
|
if ((Player_Go > 0 && Player_Go < 3) || peeNumber >= 10)
|
|
strBuilder.Append($"+열끗{yulNumber - 4}점");
|
|
else
|
|
strBuilder.Append($"(열끗({yulNumber - 4}점");
|
|
}
|
|
if (teeNumber >= 5)
|
|
{
|
|
if ((Player_Go > 0 && Player_Go < 3) || peeNumber >= 10 || yulNumber >= 5)
|
|
strBuilder.Append($"+띠{teeNumber - 4}점");
|
|
else
|
|
strBuilder.Append($"(띠({teeNumber - 4}점");
|
|
}
|
|
|
|
|
|
foreach (var pair in _hashPlayerCombinations)
|
|
{
|
|
strBuilder.Append(CodeJay.CodeJayUtility.Utility.GetCombinationTypeString(pair));
|
|
}
|
|
|
|
if (Player_Go > 2)
|
|
strBuilder.Append($")\nx{Player_Go}고{Player_Go - 1}배");
|
|
else
|
|
strBuilder.Append(')');
|
|
}
|
|
// Calculate AI Score
|
|
else
|
|
{
|
|
for (int i = 0; i < _lstAIScoreCards.Count; i++)
|
|
{
|
|
switch (Converter.CardTypeToScoreType(_lstAIScoreCards[i]))
|
|
{
|
|
case ECardScoreType.Pee:
|
|
if (_lstAIScoreCards[i] == ECardType.Bonus_3)
|
|
peeNumber += 3;
|
|
else if (Utility.IsDoublePee(_lstAIScoreCards[i], UseSepYulgget_To_Pee))
|
|
peeNumber += 2;
|
|
else
|
|
peeNumber++;
|
|
break;
|
|
case ECardScoreType.Yul_ggeut:
|
|
yulNumber++;
|
|
break;
|
|
case ECardScoreType.Tee:
|
|
teeNumber++;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (AI_Go > 0 && AI_Go < 3)
|
|
{
|
|
if (AI_Go == 1)
|
|
strBuilder.Append("(1고1점");
|
|
else if (AI_Go == 2)
|
|
strBuilder.Append("(2고2점");
|
|
}
|
|
|
|
if (peeNumber >= 10)
|
|
{
|
|
if (AI_Go > 0 && AI_Go < 3)
|
|
strBuilder.Append($"+피{peeNumber - 9}점");
|
|
else
|
|
strBuilder.Append($"(피{peeNumber - 9}점");
|
|
}
|
|
if (yulNumber >= 5)
|
|
{
|
|
if ((AI_Go > 0 && AI_Go < 3) || peeNumber >= 10)
|
|
strBuilder.Append($"+열끗{yulNumber - 4}점");
|
|
else
|
|
strBuilder.Append($"(열끗({yulNumber - 4}점");
|
|
}
|
|
if (teeNumber >= 5)
|
|
{
|
|
if ((AI_Go > 0 && AI_Go < 3) || peeNumber >= 10 || yulNumber >= 5)
|
|
strBuilder.Append($"+띠{teeNumber - 4}점");
|
|
else
|
|
strBuilder.Append($"(띠{teeNumber - 4}점");
|
|
}
|
|
|
|
foreach (var pair in _hashAICombinations)
|
|
{
|
|
strBuilder.Append(CodeJay.CodeJayUtility.Utility.GetCombinationTypeString(pair));
|
|
strBuilder.Append(' ');
|
|
}
|
|
|
|
if (AI_Go > 2)
|
|
strBuilder.Append($")\nx{AI_Go}고{AI_Go - 1}배");
|
|
else
|
|
strBuilder.Append(')');
|
|
}
|
|
|
|
this.GetAndUpdateScoreMultiplyType(isPlayer);
|
|
|
|
if (isPlayer)
|
|
{
|
|
if (Player_Go <= 2 && _hashScoreMultiplyTypes.Count > 0)
|
|
strBuilder.Append('\n');
|
|
}
|
|
else
|
|
{
|
|
if (AI_Go <= 2 && _hashScoreMultiplyTypes.Count > 0)
|
|
strBuilder.Append('\n');
|
|
}
|
|
|
|
|
|
foreach (var pair in _hashScoreMultiplyTypes)
|
|
{
|
|
if (pair == EScoreMutiplyType.Shake)
|
|
{
|
|
if (isPlayer)
|
|
{
|
|
strBuilder.Append(Utility.GetScoreMultiplyTypeString(pair, Player_Bell));
|
|
}
|
|
else
|
|
{
|
|
strBuilder.Append(Utility.GetScoreMultiplyTypeString(pair, AI_Bell));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
strBuilder.Append(Utility.GetScoreMultiplyTypeString(pair, 1));
|
|
}
|
|
}
|
|
|
|
|
|
return strBuilder.ToString();
|
|
}
|
|
|
|
#region Data Modify
|
|
public void DataMove(ECardLocationType from, ECardType type)
|
|
{
|
|
switch (from)
|
|
{
|
|
case ECardLocationType.Floor:
|
|
for (int i = 0; i < _lstFloorCards.Count; i++)
|
|
{
|
|
if (_lstFloorCards[i] == type)
|
|
{
|
|
_lstFloorCards[i] = ECardType.Max;
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
case ECardLocationType.Player_Hand:
|
|
for (int i = 0; i < _lstPlayerHandCardTypes.Count; i++)
|
|
{
|
|
if (_lstPlayerHandCardTypes[i] == type)
|
|
{
|
|
_lstPlayerHandCardTypes[i] = ECardType.Max;
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
case ECardLocationType.Player_Score:
|
|
for (int i = 0; i < _lstPlayerScoreCards.Count; i++)
|
|
{
|
|
if (_lstPlayerScoreCards[i] == type)
|
|
{
|
|
_lstPlayerScoreCards[i] = ECardType.Max;
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
case ECardLocationType.AI_Hand:
|
|
for (int i = 0; i < _lstAIHandCardTypes.Count; i++)
|
|
{
|
|
if (_lstAIHandCardTypes[i] == type)
|
|
{
|
|
_lstAIHandCardTypes[i] = ECardType.Max;
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
case ECardLocationType.AI_Score:
|
|
for (int i = 0; i < _lstAIScoreCards.Count; i++)
|
|
{
|
|
if (_lstAIScoreCards[i] == type)
|
|
{
|
|
_lstAIScoreCards[i] = ECardType.Max;
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
#endregion
|
|
}
|