using System;
using System.Collections.Generic;
using UnityEngine;

public class CardDeck : MonoBehaviour
{
	public static CardDeck Instance { get; private set; }

	public float RightOffset
	{
		get
		{
			return this.m_RightOffset;
		}
	}

	public Vector3 FlipupAngle
	{
		get
		{
			return this.m_UpAngle;
		}
	}

	public Vector3 FlipdownAngle
	{
		get
		{
			return this.m_DownAngle;
		}
	}

	private void Awake()
	{
		CardDeck.Instance = this;
		if (CardDeck.m_CardObjData == null)
		{
			CardDeck.m_CardObjData = new Dictionary<CardData.Suit, Dictionary<CardData.Rank, GameObject>>
			{
				{
					CardData.Suit.Spades,
					new Dictionary<CardData.Rank, GameObject>()
				},
				{
					CardData.Suit.Diamonds,
					new Dictionary<CardData.Rank, GameObject>()
				},
				{
					CardData.Suit.Hearts,
					new Dictionary<CardData.Rank, GameObject>()
				},
				{
					CardData.Suit.Clubs,
					new Dictionary<CardData.Rank, GameObject>()
				}
			};
			CardData.Suit[] array = (CardData.Suit[])Enum.GetValues(typeof(CardData.Suit));
			CardData.Rank[] array2 = (CardData.Rank[])Enum.GetValues(typeof(CardData.Rank));
			foreach (CardData.Suit key in array)
			{
				foreach (CardData.Rank key2 in array2)
				{
					GameObject gameObject = Resources.Load<GameObject>(BlackjackGame.BlackJackResource("Prefab/Cards/" + key.ToString()));
					gameObject = gameObject.transform.Find(key2.ToString().ToLower() + key.ToString().ToLower()).gameObject;
					CardDeck.m_CardObjData[key].Add(key2, gameObject);
				}
			}
		}
	}

	public void Shuffle(int deckCount)
	{
		this.m_CardDeck = new List<CardData>(52 * deckCount);
		while (deckCount > 0)
		{
			this.AddDeck();
			deckCount--;
		}
		this.RandomiseDeck();
	}

	public CardData GetCard()
	{
		CardData result = this.m_CardDeck[0];
		this.m_CardDeck.RemoveAt(0);
		return result;
	}

	private void AddDeck()
	{
		CardData.Suit[] array = (CardData.Suit[])Enum.GetValues(typeof(CardData.Suit));
		CardData.Rank[] array2 = (CardData.Rank[])Enum.GetValues(typeof(CardData.Rank));
		for (int i = 0; i < array2.Length; i++)
		{
			for (int j = 0; j < array.Length; j++)
			{
				this.m_CardDeck.Add(new CardData(array[j], array2[i]));
			}
		}
	}

	private void RandomiseDeck()
	{
		this.FisherYatesCardDeckShuffle(this.m_CardDeck);
	}

	private List<CardData> FisherYatesCardDeckShuffle(List<CardData> aList)
	{
		System.Random random = new System.Random();
		int count = aList.Count;
		for (int i = 0; i < count; i++)
		{
			int index = i + (int)(random.NextDouble() * (double)(count - i));
			CardData value = aList[index];
			aList[index] = aList[i];
			aList[i] = value;
		}
		return aList;
	}

	public GameObject GetCardObj(CardData.Suit suit, CardData.Rank rank)
	{
		return CardDeck.m_CardObjData[suit][rank];
	}

	[SerializeField]
	private bool m_ForceSplit;

	[SerializeField]
	private bool m_ForceBJ;

	[SerializeField]
	private bool m_NotShufflue;

	[SerializeField]
	[Header("右手に持たせたときのオフセット値")]
	private float m_RightOffset;

	[SerializeField]
	[Header("表向きの時のカードのワールド角度")]
	private Vector3 m_UpAngle = Vector3.up * 90f;

	[SerializeField]
	[Header("裏向きの時のカードのワールド角度")]
	private Vector3 m_DownAngle = Vector3.up * 90f;

	private List<CardData> m_CardDeck = new List<CardData>();

	private static Dictionary<CardData.Suit, Dictionary<CardData.Rank, GameObject>> m_CardObjData;
}
