PlayerHand.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using System;
  2. using UnityEngine;
  3. public class PlayerHand : Hand
  4. {
  5. public bool IsWin { get; private set; }
  6. public bool IsEven { get; private set; }
  7. public override void ResetHand()
  8. {
  9. base.ResetHand();
  10. this.IsHit = false;
  11. this.IsWin = false;
  12. this.IsEven = false;
  13. this.m_IsStand = false;
  14. this.IsDoubleDown = false;
  15. this.IsSurrender = false;
  16. }
  17. public void Stand()
  18. {
  19. this.m_IsStand = true;
  20. }
  21. public bool DoubleDownWin()
  22. {
  23. return this.IsDoubleDown && this.IsWin;
  24. }
  25. public bool CanHit()
  26. {
  27. return base.CurrentScore > 0 && !this.IsEnded();
  28. }
  29. public bool IsEnded()
  30. {
  31. return base.CurrentScore > 20 || this.m_IsStand || this.IsSurrender || this.m_TableCards.Count >= 5;
  32. }
  33. private bool IsBjDraw(bool dealerBlackjack)
  34. {
  35. if (dealerBlackjack)
  36. {
  37. return this.IsNatural21();
  38. }
  39. return !this.IsNatural21();
  40. }
  41. public bool HasPush(int dealerScore, bool dealerBlackjack)
  42. {
  43. return this.IsEnded() && base.CurrentScore == dealerScore && this.IsBjDraw(dealerBlackjack) && !base.IsBust();
  44. }
  45. public bool HasLost(int dealerScore, bool dealerBlackjack)
  46. {
  47. return (dealerScore > base.CurrentScore && dealerScore < 22) || dealerBlackjack;
  48. }
  49. public bool DoubleDownAvailable()
  50. {
  51. return this.m_TableCards.Count == 2;
  52. }
  53. public bool SplitAvailable()
  54. {
  55. 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;
  56. }
  57. public bool IsNatural21()
  58. {
  59. if (this.m_TableCards.Count != 2)
  60. {
  61. return false;
  62. }
  63. bool flag = this.m_HandCardData[this.m_TableCards[0]].CardData.GetValue() + this.m_HandCardData[this.m_TableCards[1]].CardData.GetValue() == 11;
  64. 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;
  65. return flag && flag2 && !BjPlayer.Instance.IsSplitGame();
  66. }
  67. public GameObject TakeCard(int index)
  68. {
  69. GameObject result = this.m_TableCards[index];
  70. this.m_TableCards.RemoveAt(index);
  71. base.CalculateScore();
  72. return result;
  73. }
  74. public void StartSplit(GameObject card)
  75. {
  76. if (!this.m_HandCardData.ContainsKey(card))
  77. {
  78. this.m_HandCardData.Add(card, card.GetComponent<Card>());
  79. }
  80. card.transform.SetParent(base.transform, false);
  81. card.transform.localPosition = BjPlayer.Instance.standardHand.GetCardObj(0).transform.localPosition;
  82. base.AddCardToHand(card);
  83. }
  84. public bool CanSurrender()
  85. {
  86. return this.m_TableCards.Count == 2 && !this.IsSurrender && !this.IsNatural21();
  87. }
  88. public void ShowOutcome(int dealerScore, bool dealerBlackjack)
  89. {
  90. if (this.IsEnded())
  91. {
  92. this.IsWin = (!this.IsSurrender && !base.IsBust() && ((!dealerBlackjack && this.IsNatural21()) || base.CurrentScore > dealerScore || dealerScore > 21));
  93. this.IsEven = (!this.IsSurrender && !base.IsBust() && this.HasPush(dealerScore, dealerBlackjack));
  94. }
  95. }
  96. public GameObject GetCardObj(int index)
  97. {
  98. return this.m_TableCards[index];
  99. }
  100. private const int m_CardMax = 5;
  101. [HideInInspector]
  102. public bool IsDoubleDown;
  103. private bool m_IsStand;
  104. [SerializeField]
  105. [Header("スプリット用の手番かどうか")]
  106. private bool m_IsSplitHand;
  107. [HideInInspector]
  108. public bool IsHit;
  109. [HideInInspector]
  110. public bool IsSurrender;
  111. }