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

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

	public float ChipSetSpace
	{
		get
		{
			return this.m_ChipSetSpace;
		}
	}

	public Vector3 ChipStackSpace
	{
		get
		{
			return this.m_ChipStackSpace;
		}
	}

	public float FallingLength
	{
		get
		{
			return this.m_FallingLength;
		}
	}

	public float FallingTime
	{
		get
		{
			return this.m_FallingTime;
		}
	}

	public int StackCount
	{
		get
		{
			return this.m_StackCount;
		}
	}

	public float TimeOffset
	{
		get
		{
			return this.m_TimeOffset;
		}
	}

	public List<ChipManager.Chip> ChipList
	{
		get
		{
			return this.m_ChipDataList;
		}
	}

	public ChipStack[] ChipStacks
	{
		get
		{
			return this.m_ChipStack;
		}
	}

	private void Awake()
	{
		ChipManager.Instance = this;
		this.m_ChipDataList = (from chip in this.ChipList
		orderby chip.value descending
		select chip).ToList<ChipManager.Chip>();
		foreach (ChipManager.Chip chip2 in this.m_ChipDataList)
		{
			chip2.chip_obj = Resources.Load<GameObject>(BlackjackGame.BlackJackResource("Prefab/Coin/" + chip2.chipname));
		}
	}

	private void StackCall()
	{
		if (this.StackEndCallBack != null)
		{
			this.StackEndCallBack();
		}
		this.StackEndCallBack = null;
	}

	public void StackEndAction()
	{
		if (this.m_ChipStack.Any((ChipStack chip) => !chip.ChipUpdateEnd))
		{
			return;
		}
		base.Invoke("StackCall", this.m_StackEndPause);
	}

	public void ClearBet()
	{
		BjPlayer.Instance.ClearBet();
		this.ResetStacks();
	}

	public void UpdateStacks()
	{
		foreach (ChipStack chipStack in this.ChipStacks)
		{
			chipStack.UpdateChips();
		}
		this.StackEndAction();
	}

	public void HardReset()
	{
		foreach (ChipStack chipStack in this.ChipStacks)
		{
			chipStack.IsWinningStack = false;
		}
	}

	public void ResetStacks()
	{
		foreach (ChipStack chipStack in this.ChipStacks)
		{
			chipStack.ResetChips();
		}
	}

	[SerializeField]
	private float m_StackEndPause = 0.5f;

	[SerializeField]
	[Header("チップの設置間隔(アニメーション開始時)")]
	private float m_ChipSetSpace = 0.5f;

	[SerializeField]
	[Header("チップの設置間隔(通常時)")]
	private Vector3 m_ChipStackSpace = Vector3.zero;

	[SerializeField]
	[Header("チップは最低この高さから落とす")]
	private float m_FallingLength = 2.75f;

	[SerializeField]
	[Header("チップのアニメーション所要時間")]
	private float m_FallingTime = 0.7f;

	[SerializeField]
	[Header("チップのアニメーションラグ時間")]
	private float m_TimeOffset = 0.05f;

	[SerializeField]
	[Header("この枚数毎にスタック")]
	private int m_StackCount = 10;

	[SerializeField]
	private List<ChipManager.Chip> m_ChipDataList = new List<ChipManager.Chip>();

	public Action StackEndCallBack;

	[SerializeField]
	[Header("チップを載せておく場所")]
	private ChipStack[] m_ChipStack = new ChipStack[4];

	[Serializable]
	public class Chip
	{
		public int value;

		public string chipname;

		[HideInInspector]
		public GameObject chip_obj;
	}
}
