Dealer.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using UnityEngine;
  6. public class Dealer : Hand
  7. {
  8. public static Dealer Instance { get; private set; }
  9. public bool NeedCardMove
  10. {
  11. get
  12. {
  13. return !this.m_IsCardMove && this.m_TableCards.Count >= 3;
  14. }
  15. }
  16. public Vector3 LastCardPos
  17. {
  18. get
  19. {
  20. if (this.m_TableCards.Count == 4)
  21. {
  22. return base.transform.position;
  23. }
  24. int num = this.m_TableCards.Count - 1;
  25. return this.m_TableCards[num - 1].transform.position + this.m_CardOffset;
  26. }
  27. }
  28. private void Awake()
  29. {
  30. Dealer.Instance = this;
  31. }
  32. private void OnDestroy()
  33. {
  34. foreach (GameObject gameObject in this.m_TableCards)
  35. {
  36. if (gameObject)
  37. {
  38. UnityEngine.Object.DestroyImmediate(gameObject);
  39. }
  40. }
  41. }
  42. public void CheckSurrender()
  43. {
  44. this.m_IsForceWin = false;
  45. }
  46. public override void ResetHand()
  47. {
  48. base.ResetHand();
  49. this.m_IsForceWin = false;
  50. this.m_IsCardMove = false;
  51. }
  52. public void CardMove()
  53. {
  54. this.m_IsCardMove = true;
  55. base.StartCoroutine(this.CardMoveCoroutine());
  56. }
  57. private IEnumerator CardMoveCoroutine()
  58. {
  59. yield return null;
  60. Func<Vector3, Vector3> maid_local = (Vector3 pos) => BjMotionControl.Instance.TargetMaid.transform.InverseTransformPoint(pos);
  61. Vector3 last_hand = maid_local(BjMotionControl.Instance.RightHandPos());
  62. bool move_start = false;
  63. int lap_count = 1;
  64. List<Transform> move_card = new List<Transform>();
  65. List<Vector3> orijin_pos = new List<Vector3>();
  66. Transform target = this.m_TableCards[this.m_TableCards.Count - lap_count].transform;
  67. Vector3 next_pos = target.position;
  68. float length = 0f;
  69. for (;;)
  70. {
  71. Vector3 now_hand = maid_local(BjMotionControl.Instance.RightHandPos());
  72. Vector3 card_local = (move_card.Count == 0) ? Vector3.zero : maid_local(move_card.Last<Transform>().position);
  73. if (!move_start)
  74. {
  75. if (last_hand.x < now_hand.x)
  76. {
  77. move_start = true;
  78. lap_count++;
  79. move_card.Add(target);
  80. orijin_pos.Add(target.position);
  81. target.SetParent(BjMotionControl.Instance.RightHand, true);
  82. target = this.m_TableCards[this.m_TableCards.Count - lap_count].transform;
  83. next_pos = target.position + base.transform.TransformDirection(Vector3.right) * this.m_RecetCardX;
  84. length = maid_local(next_pos).x - maid_local(move_card.Last<Transform>().position).x;
  85. BlackjackGame.Instance.CardSe.Play();
  86. }
  87. }
  88. else
  89. {
  90. for (int i = 0; i < move_card.Count; i++)
  91. {
  92. move_card[i].eulerAngles = CardDeck.Instance.FlipupAngle;
  93. }
  94. if (lap_count <= this.m_TableCards.Count)
  95. {
  96. float num = 1f - Mathf.Clamp01(Mathf.Max(maid_local(next_pos).x - card_local.x, 0f) / length);
  97. for (int j = 0; j < move_card.Count; j++)
  98. {
  99. Vector3 position = move_card[j].position;
  100. position.x = orijin_pos[j].x;
  101. position.y = Mathf.Lerp(orijin_pos[j].y, orijin_pos[j].y + 0.001f, num);
  102. position.z = Mathf.Min(next_pos.z, position.z);
  103. move_card[j].position = position;
  104. }
  105. if (num == 1f)
  106. {
  107. lap_count++;
  108. for (int k = 0; k < orijin_pos.Count; k++)
  109. {
  110. orijin_pos[k] = move_card[k].position;
  111. }
  112. move_card.Add(target);
  113. orijin_pos.Add(target.position);
  114. target.SetParent(BjMotionControl.Instance.RightHand, true);
  115. if (lap_count <= this.m_TableCards.Count)
  116. {
  117. target = this.m_TableCards[this.m_TableCards.Count - lap_count].transform;
  118. next_pos = target.position + base.transform.TransformDirection(Vector3.right) * this.m_RecetCardX;
  119. length = maid_local(next_pos).x - card_local.x;
  120. BlackjackGame.Instance.CardSe.Play();
  121. }
  122. }
  123. }
  124. else
  125. {
  126. for (int l = 0; l < move_card.Count; l++)
  127. {
  128. Vector3 position2 = move_card[l].position;
  129. position2.x = orijin_pos[l].x;
  130. position2.y = orijin_pos[l].y;
  131. if (l + 1 < move_card.Count)
  132. {
  133. position2.z = Mathf.Min(position2.z, move_card[l + 1].position.z - this.m_RecetCardX);
  134. }
  135. move_card[l].position = position2;
  136. }
  137. if (now_hand.x > maid_local(base.transform.TransformPoint(Vector3.left * this.m_MaxMoveX)).x)
  138. {
  139. break;
  140. }
  141. }
  142. }
  143. last_hand = now_hand;
  144. yield return null;
  145. }
  146. base.ResetNextPosition();
  147. foreach (Transform transform in move_card)
  148. {
  149. transform.SetParent(base.transform, true);
  150. }
  151. yield break;
  152. yield break;
  153. }
  154. public bool IsEnded()
  155. {
  156. return base.CurrentScore > 16 || this.m_IsForceWin || this.m_TableCards.Count >= 7;
  157. }
  158. protected override Card.CardState GetCardState()
  159. {
  160. if (this.m_TableCards.Count == 0 || this.m_TableCards.Count > 1)
  161. {
  162. return Card.CardState.FlipUp;
  163. }
  164. return Card.CardState.FlipDown;
  165. }
  166. public bool HasFacedownCard()
  167. {
  168. return this.m_TableCards.Count == 2 && this.m_HandCardData[this.m_TableCards[1]].CurrentState == Card.CardState.FlipDown;
  169. }
  170. public GameObject GetFacedownCard()
  171. {
  172. GameObject result = null;
  173. if (this.HasFacedownCard())
  174. {
  175. result = this.m_TableCards[1];
  176. }
  177. return result;
  178. }
  179. public bool IsNatural21()
  180. {
  181. bool flag = this.m_HandCardData[this.m_TableCards[0]].CardData.GetValue() + this.m_HandCardData[this.m_TableCards[1]].CardData.GetValue() == 11;
  182. 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;
  183. return this.m_TableCards.Count == 2 && flag && flag2;
  184. }
  185. public bool MayHaveNatural21()
  186. {
  187. return this.HasFacedownCard() && this.m_HandCardData[this.m_TableCards[0]].CardData.CardRank == CardData.Rank.Ace;
  188. }
  189. public bool HasBlackjack()
  190. {
  191. Card card = this.m_HandCardData[this.GetFacedownCard()];
  192. return card.CardData.GetValue() == 10;
  193. }
  194. public void SetCardOffset()
  195. {
  196. this.m_CardOffset = this.m_TableCards[1].transform.position - this.m_TableCards[0].transform.position;
  197. }
  198. private const int m_CardMax = 7;
  199. private const float m_Cardlap = 0.001f;
  200. public const int CardRecetNum = 3;
  201. public const int SetOffsetNum = 5;
  202. private bool m_IsForceWin;
  203. private bool m_IsCardMove;
  204. [SerializeField]
  205. private float m_MaxMoveX = 0.5f;
  206. [SerializeField]
  207. private float m_RecetCardX = 0.02f;
  208. }