using System;
using UnityEngine;

public class PlayerHand : Hand
{
	public bool IsWin { get; private set; }

	public bool IsEven { get; private set; }

	public override void ResetHand()
	{
		base.ResetHand();
		this.IsHit = false;
		this.IsWin = false;
		this.IsEven = false;
		this.m_IsStand = false;
		this.IsDoubleDown = false;
		this.IsSurrender = false;
	}

	public void Stand()
	{
		this.m_IsStand = true;
	}

	public bool DoubleDownWin()
	{
		return this.IsDoubleDown && this.IsWin;
	}

	public bool CanHit()
	{
		return base.CurrentScore > 0 && !this.IsEnded();
	}

	public bool IsEnded()
	{
		return base.CurrentScore > 20 || this.m_IsStand || this.IsSurrender || this.m_TableCards.Count >= 5;
	}

	private bool IsBjDraw(bool dealerBlackjack)
	{
		if (dealerBlackjack)
		{
			return this.IsNatural21();
		}
		return !this.IsNatural21();
	}

	public bool HasPush(int dealerScore, bool dealerBlackjack)
	{
		return this.IsEnded() && base.CurrentScore == dealerScore && this.IsBjDraw(dealerBlackjack) && !base.IsBust();
	}

	public bool HasLost(int dealerScore, bool dealerBlackjack)
	{
		return (dealerScore > base.CurrentScore && dealerScore < 22) || dealerBlackjack;
	}

	public bool DoubleDownAvailable()
	{
		return this.m_TableCards.Count == 2;
	}

	public bool SplitAvailable()
	{
		return !this.IsEnded() && this.m_TableCards.Count == 2 && this.m_HandCardData[this.m_TableCards[0]].CardData.CardRank == this.m_HandCardData[this.m_TableCards[1]].CardData.CardRank;
	}

	public bool IsNatural21()
	{
		if (this.m_TableCards.Count != 2)
		{
			return false;
		}
		bool flag = this.m_HandCardData[this.m_TableCards[0]].CardData.GetValue() + this.m_HandCardData[this.m_TableCards[1]].CardData.GetValue() == 11;
		bool flag2 = this.m_HandCardData[this.m_TableCards[0]].CardData.CardRank == CardData.Rank.Ace || this.m_HandCardData[this.m_TableCards[1]].CardData.CardRank == CardData.Rank.Ace;
		return flag && flag2 && !BjPlayer.Instance.IsSplitGame();
	}

	public GameObject TakeCard(int index)
	{
		GameObject result = this.m_TableCards[index];
		this.m_TableCards.RemoveAt(index);
		base.CalculateScore();
		return result;
	}

	public void StartSplit(GameObject card)
	{
		if (!this.m_HandCardData.ContainsKey(card))
		{
			this.m_HandCardData.Add(card, card.GetComponent<Card>());
		}
		card.transform.SetParent(base.transform, false);
		card.transform.localPosition = BjPlayer.Instance.standardHand.GetCardObj(0).transform.localPosition;
		base.AddCardToHand(card);
	}

	public bool CanSurrender()
	{
		return this.m_TableCards.Count == 2 && !this.IsSurrender && !this.IsNatural21();
	}

	public void ShowOutcome(int dealerScore, bool dealerBlackjack)
	{
		if (this.IsEnded())
		{
			this.IsWin = (!this.IsSurrender && !base.IsBust() && ((!dealerBlackjack && this.IsNatural21()) || base.CurrentScore > dealerScore || dealerScore > 21));
			this.IsEven = (!this.IsSurrender && !base.IsBust() && this.HasPush(dealerScore, dealerBlackjack));
		}
	}

	public GameObject GetCardObj(int index)
	{
		return this.m_TableCards[index];
	}

	private const int m_CardMax = 5;

	[HideInInspector]
	public bool IsDoubleDown;

	private bool m_IsStand;

	[SerializeField]
	[Header("スプリット用の手番かどうか")]
	private bool m_IsSplitHand;

	[HideInInspector]
	public bool IsHit;

	[HideInInspector]
	public bool IsSurrender;
}
