BjPlayer.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. using System;
  2. using UnityEngine;
  3. public class BjPlayer : MonoBehaviour
  4. {
  5. public static BjPlayer Instance { get; private set; }
  6. public long CurrentBet { get; private set; }
  7. public long SplitBet { get; private set; }
  8. public long TotalWinnings { get; private set; }
  9. public PlayerHand standardHand
  10. {
  11. get
  12. {
  13. return this.m_StandardHand;
  14. }
  15. }
  16. public PlayerHand splitHand
  17. {
  18. get
  19. {
  20. return this.m_SplitHand;
  21. }
  22. }
  23. public PlayerHand CurrentHand { get; private set; }
  24. public long OrijinCredit { get; private set; }
  25. public bool IsDecrease { get; private set; }
  26. public long MoneyDifference
  27. {
  28. get
  29. {
  30. return this.OrijinCredit - GameMain.Instance.CharacterMgr.status.casinoCoin;
  31. }
  32. }
  33. public long FactMoneyDifference { get; private set; }
  34. public bool NotEnoughCredit
  35. {
  36. get
  37. {
  38. return GameMain.Instance.CharacterMgr.status.casinoCoin < BetSetUI.Instance.MoneySetting.MinValue;
  39. }
  40. }
  41. public bool IsNowSplitHand
  42. {
  43. get
  44. {
  45. return this.CurrentHand == this.splitHand;
  46. }
  47. }
  48. private void Awake()
  49. {
  50. BjPlayer.Instance = this;
  51. this.m_Playerhands = new PlayerHand[]
  52. {
  53. this.standardHand,
  54. this.splitHand
  55. };
  56. }
  57. private void Start()
  58. {
  59. this.m_StartingBet = BetSetUI.Instance.MoneySetting.MinValue;
  60. }
  61. public void SubtractBet()
  62. {
  63. this.OrijinCredit = GameMain.Instance.CharacterMgr.status.casinoCoin;
  64. GameMain.Instance.CharacterMgr.status.casinoCoin -= this.CurrentBet;
  65. UIStates.Instance.OnStateChange();
  66. }
  67. public void AwardWinnings(int dealerScore)
  68. {
  69. this.TotalWinnings = 0L;
  70. this.ShowOutcomes(dealerScore, Dealer.Instance.IsNatural21());
  71. foreach (PlayerHand playerHand in this.m_Playerhands)
  72. {
  73. long num = 0L;
  74. if (playerHand.IsEnded() && !playerHand.IsBust())
  75. {
  76. if (playerHand.IsSurrender)
  77. {
  78. num = this.GetPushWinnings(playerHand) / 2L;
  79. }
  80. else if (playerHand.IsEven)
  81. {
  82. num = this.GetPushWinnings(playerHand);
  83. }
  84. else if (playerHand.IsWin)
  85. {
  86. num = this.GetWinnings(playerHand);
  87. }
  88. }
  89. this.TotalWinnings += num;
  90. foreach (ChipStack chipStack in ChipManager.Instance.ChipStacks)
  91. {
  92. if ((chipStack.IsSplitBetStack && playerHand == this.splitHand) || (!chipStack.IsSplitBetStack && playerHand != this.splitHand))
  93. {
  94. chipStack.IsSurrender = playerHand.IsSurrender;
  95. chipStack.IsWinningStack = (num > 0L);
  96. chipStack.IsEven = playerHand.IsEven;
  97. chipStack.IsBlackJack = playerHand.IsNatural21();
  98. }
  99. }
  100. }
  101. bool flag = GameMain.Instance.CharacterMgr.status.casinoCoin + this.TotalWinnings > 999999L;
  102. GameMain.Instance.CharacterMgr.status.casinoCoin += this.TotalWinnings;
  103. if (flag)
  104. {
  105. this.FactMoneyDifference = this.TotalWinnings - (this.SplitBet + this.CurrentBet);
  106. }
  107. else
  108. {
  109. this.FactMoneyDifference = -this.MoneyDifference;
  110. }
  111. this.IsDecrease = (GameMain.Instance.CharacterMgr.status.casinoCoin < this.OrijinCredit);
  112. UIStates.Instance.OnStateChange();
  113. UIStates.Instance.ShowOutcomeText();
  114. ChipManager.Instance.UpdateStacks();
  115. }
  116. private long GetWinnings(PlayerHand hand)
  117. {
  118. long num = this.CurrentBet;
  119. if (hand == this.splitHand)
  120. {
  121. num = this.SplitBet;
  122. }
  123. long result = num * 2L;
  124. if (hand.IsNatural21())
  125. {
  126. result = (long)Mathf.FloorToInt((float)num * 2.5f);
  127. }
  128. return result;
  129. }
  130. private long GetPushWinnings(PlayerHand hand)
  131. {
  132. return (!(hand == this.splitHand)) ? this.CurrentBet : this.SplitBet;
  133. }
  134. public void SetBet(long bet)
  135. {
  136. if (this.CurrentHand == this.splitHand)
  137. {
  138. this.SplitBet = bet;
  139. }
  140. else
  141. {
  142. this.CurrentBet = bet;
  143. }
  144. UIStates.Instance.OnStateChange();
  145. }
  146. public void ClearBet()
  147. {
  148. this.CurrentBet = BetSetUI.Instance.MoneySetting.MinValue;
  149. UIStates.Instance.OnStateChange();
  150. }
  151. public bool IsDoubleDown()
  152. {
  153. return this.CurrentHand.IsDoubleDown;
  154. }
  155. public bool IsStandardDoubleDown()
  156. {
  157. return this.standardHand.IsDoubleDown;
  158. }
  159. public bool IsSplitDoubleDown()
  160. {
  161. return this.splitHand.IsDoubleDown;
  162. }
  163. public void Surrender()
  164. {
  165. this.CurrentHand.IsSurrender = true;
  166. }
  167. public void DoubleDown()
  168. {
  169. this.SubtractDoubleDownBet();
  170. this.CurrentHand.IsDoubleDown = true;
  171. this.CurrentHand.Stand();
  172. }
  173. public GameObject DealCard(CardData card)
  174. {
  175. if (this.IsPlacingBet())
  176. {
  177. this.m_StartingBet = this.CurrentBet;
  178. }
  179. return this.CurrentHand.DealCard(card);
  180. }
  181. public void UpdateScore()
  182. {
  183. this.standardHand.UpdateScoreView();
  184. this.splitHand.UpdateScoreView();
  185. }
  186. public void ResetScore()
  187. {
  188. this.standardHand.ResetScore();
  189. this.splitHand.ResetScore();
  190. }
  191. public void ResetTable()
  192. {
  193. this.CurrentBet = this.m_StartingBet;
  194. this.OrijinCredit = GameMain.Instance.CharacterMgr.status.casinoCoin;
  195. this.TotalWinnings = 0L;
  196. this.m_DoubleDownBet = 0L;
  197. this.SplitBet = 0L;
  198. this.standardHand.ResetHand();
  199. this.splitHand.ResetHand();
  200. this.CurrentHand = this.standardHand;
  201. this.m_SplitGame = false;
  202. this.EndingGame = false;
  203. this.IsDecrease = false;
  204. this.IsturnEnd = false;
  205. UIStates.Instance.StateReset();
  206. }
  207. public bool IsSplitGame()
  208. {
  209. return this.m_SplitGame;
  210. }
  211. public bool IsIdle()
  212. {
  213. return this.CurrentHand.CurrentScore == 0 && this.splitHand.CurrentScore == 0 && !BetSetUI.Instance.IsDoBet;
  214. }
  215. public bool IsPlacingBet()
  216. {
  217. return this.CurrentHand.CurrentScore == 0 && this.splitHand.CurrentScore == 0 && BetSetUI.Instance.IsDoBet;
  218. }
  219. public bool CanHit()
  220. {
  221. return this.CurrentHand.CanHit();
  222. }
  223. public bool CanDoubleDown()
  224. {
  225. return this.CurrentHand == this.splitHand && this.splitHand.DoubleDownAvailable();
  226. }
  227. public bool HandIsEnded()
  228. {
  229. return this.CurrentHand.IsEnded();
  230. }
  231. public bool IsNatural21()
  232. {
  233. return this.standardHand.IsNatural21();
  234. }
  235. public bool IsEnded()
  236. {
  237. if (this.m_SplitGame)
  238. {
  239. return this.standardHand.IsEnded() && this.splitHand.IsEnded();
  240. }
  241. return this.CurrentHand.IsEnded();
  242. }
  243. public bool DoubleDownEnoughMoney()
  244. {
  245. if (this.CurrentHand == this.splitHand)
  246. {
  247. return GameMain.Instance.CharacterMgr.status.casinoCoin - this.SplitBet >= 0L;
  248. }
  249. return GameMain.Instance.CharacterMgr.status.casinoCoin - this.CurrentBet >= 0L;
  250. }
  251. public bool DoubleDownAvailable()
  252. {
  253. return !this.EndingGame && this.CurrentHand.DoubleDownAvailable() && this.DoubleDownEnoughMoney();
  254. }
  255. public bool SplitEnoughMoney()
  256. {
  257. return GameMain.Instance.CharacterMgr.status.casinoCoin - this.CurrentBet >= 0L;
  258. }
  259. public bool SplitAvailable()
  260. {
  261. return !this.m_SplitGame && this.CurrentHand.SplitAvailable() && this.SplitEnoughMoney();
  262. }
  263. public void StandOnCurrentHand()
  264. {
  265. this.CurrentHand.Stand();
  266. }
  267. private void SubtractDoubleDownBet()
  268. {
  269. this.m_DoubleDownBet = this.CurrentBet;
  270. GameMain.Instance.CharacterMgr.status.casinoCoin -= this.m_DoubleDownBet;
  271. if (this.CurrentHand == this.splitHand)
  272. {
  273. this.SplitBet += this.m_DoubleDownBet;
  274. }
  275. else
  276. {
  277. this.CurrentBet += this.m_DoubleDownBet;
  278. }
  279. }
  280. private void SubtractSplitBet()
  281. {
  282. this.SplitBet = this.CurrentBet;
  283. GameMain.Instance.CharacterMgr.status.casinoCoin -= this.SplitBet;
  284. }
  285. public void Split()
  286. {
  287. this.m_SplitGame = true;
  288. this.SubtractSplitBet();
  289. this.CurrentHand = this.splitHand;
  290. }
  291. public void NextHand()
  292. {
  293. if (this.m_SplitGame)
  294. {
  295. this.CurrentHand = this.standardHand;
  296. this.CurrentHand.ResetPositionForSplit();
  297. }
  298. }
  299. public bool CanSurrender()
  300. {
  301. return !this.IsSplitGame() && this.CurrentHand.CanSurrender() && !this.EndingGame && Dealer.Instance.HasFacedownCard();
  302. }
  303. private void ShowOutcomes(int dealerScore, bool dealerBlackjack)
  304. {
  305. foreach (PlayerHand playerHand in this.m_Playerhands)
  306. {
  307. playerHand.ShowOutcome(dealerScore, dealerBlackjack);
  308. }
  309. }
  310. public long GetCurrentBet()
  311. {
  312. if (this.CurrentHand == this.splitHand)
  313. {
  314. return this.SplitBet;
  315. }
  316. return this.CurrentBet;
  317. }
  318. public bool IsEven()
  319. {
  320. if (this.m_SplitGame)
  321. {
  322. return this.standardHand.IsEven && this.splitHand.IsEven;
  323. }
  324. return this.standardHand.IsEven;
  325. }
  326. public bool ExistDoubleDownwWin()
  327. {
  328. return this.standardHand.DoubleDownWin() || this.splitHand.DoubleDownWin();
  329. }
  330. public bool ExistWinHand()
  331. {
  332. return this.standardHand.IsWin || this.splitHand.IsWin;
  333. }
  334. public bool OnesideWin()
  335. {
  336. return (!this.standardHand.IsWin || !this.splitHand.IsWin) && (this.standardHand.IsWin || this.splitHand.IsWin);
  337. }
  338. public bool ExistSurrenderHand()
  339. {
  340. return this.standardHand.IsSurrender;
  341. }
  342. public bool ExistBlackJack()
  343. {
  344. return this.standardHand.IsNatural21() || this.splitHand.IsNatural21();
  345. }
  346. private long m_DoubleDownBet;
  347. [HideInInspector]
  348. public bool EndingGame;
  349. private long m_StartingBet;
  350. [SerializeField]
  351. private PlayerHand m_StandardHand;
  352. [SerializeField]
  353. private PlayerHand m_SplitHand;
  354. private PlayerHand[] m_Playerhands;
  355. private bool m_SplitGame;
  356. [HideInInspector]
  357. public bool IsturnEnd;
  358. }