ChipStack.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class ChipStack : MonoBehaviour
  6. {
  7. public bool IsSplitBetStack
  8. {
  9. get
  10. {
  11. return this.m_IsSplitBetStack;
  12. }
  13. }
  14. public bool ChipUpdateEnd { get; private set; }
  15. public void UpdateChips()
  16. {
  17. this.ChipUpdateEnd = false;
  18. this.m_IsStack = false;
  19. long stackBet = this.m_StackBet;
  20. if (!this.CheckStackBet() && BetSetUI.Instance.IsDoBet)
  21. {
  22. this.ChipUpdateEnd = true;
  23. return;
  24. }
  25. if (!BetSetUI.Instance.IsDoBet)
  26. {
  27. this.ResetChips();
  28. this.m_StackBet = 0L;
  29. return;
  30. }
  31. this.m_NotNeedAnimation = (stackBet > this.m_StackBet);
  32. if (this.m_NotNeedAnimation)
  33. {
  34. this.ResetChips();
  35. }
  36. this.m_StackDifference = this.m_StackBet - stackBet;
  37. this.RefreshCoinAmounts();
  38. }
  39. private bool CheckStackBet()
  40. {
  41. long num = (!this.IsSplitBetStack) ? BjPlayer.Instance.CurrentBet : BjPlayer.Instance.SplitBet;
  42. if (this.IsWinningStack && !this.IsEven && !this.IsSurrender)
  43. {
  44. if (this.IsBlackJack)
  45. {
  46. num = (long)Mathf.FloorToInt((float)num * 2.5f);
  47. }
  48. else
  49. {
  50. num *= 2L;
  51. }
  52. this.m_IsStack = true;
  53. this.m_Stackline = 5;
  54. }
  55. else if (this.IsSurrender)
  56. {
  57. num = (long)Mathf.FloorToInt((float)(num / 2L));
  58. }
  59. if (num == this.m_StackBet)
  60. {
  61. return false;
  62. }
  63. this.m_StackBet = num;
  64. return true;
  65. }
  66. private void RefreshCoinAmounts()
  67. {
  68. this.IsEven = false;
  69. this.IsBlackJack = false;
  70. this.IsSurrender = false;
  71. long num = 0L;
  72. int num2 = 0;
  73. int num3 = 0;
  74. bool flag = this.m_IsStack && this.m_ChipFallingHigh.Count > 0;
  75. int num4 = (!this.m_IsStack) ? 0 : this.m_ChipStackList.Count;
  76. PlayerHand playerHand = (!this.m_IsSplitBetStack) ? BjPlayer.Instance.standardHand : BjPlayer.Instance.splitHand;
  77. int num5 = (!this.m_IsStack || !playerHand.IsDoubleDown) ? 1 : 2;
  78. for (int i = 0; i < num5; i++)
  79. {
  80. num += this.m_StackDifference / (long)num5;
  81. foreach (ChipManager.Chip chip in ChipManager.Instance.ChipList)
  82. {
  83. int num6 = Mathf.FloorToInt((float)(num / (long)chip.value));
  84. for (int j = 0; j < num6; j++)
  85. {
  86. GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(chip.chip_obj);
  87. gameObject.transform.SetParent(base.transform, false);
  88. int num7 = this.m_ChipStackList.Count - num4;
  89. int num8 = num7 / ChipManager.Instance.StackCount;
  90. if ((num8 + 1 - num3) / 2 == this.m_Stackline)
  91. {
  92. this.m_Stackline -= 2;
  93. num3 = num8;
  94. num2 = num8 - (5 - this.m_Stackline);
  95. }
  96. int num9 = (!this.m_IsSplitBetStack) ? -1 : 1;
  97. Vector3 zero = Vector3.zero;
  98. zero.x = (float)(num8 - num2) / 2f * (float)num9 * ChipManager.Instance.ChipStackSpace.x;
  99. zero.z = (float)((num8 - num2) % 2 + 5 - this.m_Stackline) * ChipManager.Instance.ChipStackSpace.z;
  100. if (this.m_NotNeedAnimation)
  101. {
  102. zero.y = ChipManager.Instance.ChipStackSpace.y * (float)(num7 % ChipManager.Instance.StackCount);
  103. }
  104. else
  105. {
  106. zero.y = ChipManager.Instance.FallingLength + ChipManager.Instance.ChipSetSpace * (float)(num7 % ChipManager.Instance.StackCount);
  107. if (flag && this.m_ChipFallingHigh.ContainsKey(num8))
  108. {
  109. zero.y += this.m_ChipFallingHigh[num8];
  110. }
  111. this.m_ChipMoveList.Add(gameObject);
  112. }
  113. gameObject.transform.localPosition = zero;
  114. this.m_ChipStackList.Add(gameObject);
  115. }
  116. num %= (long)chip.value;
  117. }
  118. }
  119. if (!this.m_NotNeedAnimation)
  120. {
  121. base.StartCoroutine(this.CoinFallDown());
  122. }
  123. }
  124. private IEnumerator CoinFallDown()
  125. {
  126. float timer = 0f;
  127. bool exist_chip = this.m_IsStack && this.m_ChipFallingHigh.Count > 0;
  128. List<Vector3> start_pos = new List<Vector3>();
  129. foreach (GameObject gameObject in this.m_ChipMoveList)
  130. {
  131. start_pos.Add(gameObject.transform.localPosition);
  132. }
  133. int chip_index = (!this.m_IsStack) ? (this.m_ChipStackList.Count - this.m_ChipMoveList.Count) : 0;
  134. int part_count = this.m_ChipMoveList.Count / ChipManager.Instance.StackCount;
  135. int index_remaind = (this.m_IsStack || chip_index <= 0) ? 0 : (chip_index % ChipManager.Instance.StackCount);
  136. bool sound_play = false;
  137. for (;;)
  138. {
  139. timer += Time.deltaTime;
  140. bool move_end = true;
  141. for (int i = 0; i < this.m_ChipMoveList.Count; i++)
  142. {
  143. float current_time = Mathf.Max(timer - (float)((i + index_remaind) / ChipManager.Instance.StackCount) * ChipManager.Instance.TimeOffset, 0f);
  144. float num = KasaiUtility.SinRate01(current_time, ChipManager.Instance.FallingTime, false, false);
  145. move_end = (num == 1f);
  146. if (num == 0f)
  147. {
  148. break;
  149. }
  150. if (move_end && !sound_play)
  151. {
  152. GameMain.Instance.SoundMgr.PlaySe("casino_SE004.ogg", false);
  153. sound_play = true;
  154. }
  155. Vector3 localPosition = this.m_ChipMoveList[i].transform.localPosition;
  156. localPosition.y = ChipManager.Instance.ChipStackSpace.y * (float)((i + chip_index) % ChipManager.Instance.StackCount);
  157. if (exist_chip && this.m_ChipFallingHigh.ContainsKey(i / ChipManager.Instance.StackCount))
  158. {
  159. localPosition.y += this.m_ChipFallingHigh[i / ChipManager.Instance.StackCount];
  160. }
  161. this.m_ChipMoveList[i].transform.localPosition = Vector3.Lerp(start_pos[i], localPosition, num);
  162. }
  163. if (move_end)
  164. {
  165. break;
  166. }
  167. yield return null;
  168. }
  169. this.ChipUpdateEnd = true;
  170. int num2 = this.m_ChipStackList.Count / ChipManager.Instance.StackCount;
  171. if (this.m_ChipStackList.Count % ChipManager.Instance.StackCount != 0)
  172. {
  173. num2++;
  174. }
  175. for (int j = 0; j < num2; j++)
  176. {
  177. int index = Mathf.Min((j + 1) * ChipManager.Instance.StackCount - 1, this.m_ChipStackList.Count - 1);
  178. float value = this.m_ChipStackList[index].transform.localPosition.y + ChipManager.Instance.ChipStackSpace.y;
  179. if (this.m_ChipFallingHigh.ContainsKey(j))
  180. {
  181. this.m_ChipFallingHigh[j] = value;
  182. }
  183. else
  184. {
  185. this.m_ChipFallingHigh.Add(j, value);
  186. }
  187. }
  188. this.m_ChipMoveList.Clear();
  189. ChipManager.Instance.StackEndAction();
  190. yield break;
  191. yield break;
  192. }
  193. public bool ContainsChip(GameObject chip)
  194. {
  195. return this.m_ChipStackList.Contains(chip);
  196. }
  197. public void ResetChips()
  198. {
  199. if (this.m_ChipStackList != null && this.m_ChipStackList.Count > 0)
  200. {
  201. foreach (GameObject obj in this.m_ChipStackList)
  202. {
  203. UnityEngine.Object.Destroy(obj);
  204. }
  205. }
  206. this.m_ChipFallingHigh.Clear();
  207. this.m_ChipStackList.Clear();
  208. this.m_Stackline = 5;
  209. this.m_IsStack = false;
  210. }
  211. private const int m_BaseStackLine = 5;
  212. [SerializeField]
  213. [Header("スプリット用かどうか")]
  214. private bool m_IsSplitBetStack;
  215. [HideInInspector]
  216. public bool IsWinningStack;
  217. [HideInInspector]
  218. public bool IsSurrender;
  219. [HideInInspector]
  220. public bool IsBlackJack;
  221. [HideInInspector]
  222. public bool IsEven;
  223. private long m_StackBet;
  224. private long m_StackDifference;
  225. private List<GameObject> m_ChipStackList = new List<GameObject>();
  226. private List<GameObject> m_ChipMoveList = new List<GameObject>();
  227. private bool m_NotNeedAnimation;
  228. private bool m_IsStack;
  229. private bool m_ChipUp;
  230. private int m_Stackline = 5;
  231. private Dictionary<int, float> m_ChipFallingHigh = new Dictionary<int, float>();
  232. }