123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422 |
- using System;
- using UnityEngine;
- public class BjPlayer : MonoBehaviour
- {
- public static BjPlayer Instance { get; private set; }
- public long CurrentBet { get; private set; }
- public long SplitBet { get; private set; }
- public long TotalWinnings { get; private set; }
- public PlayerHand standardHand
- {
- get
- {
- return this.m_StandardHand;
- }
- }
- public PlayerHand splitHand
- {
- get
- {
- return this.m_SplitHand;
- }
- }
- public PlayerHand CurrentHand { get; private set; }
- public long OrijinCredit { get; private set; }
- public bool IsDecrease { get; private set; }
- public long MoneyDifference
- {
- get
- {
- return this.OrijinCredit - GameMain.Instance.CharacterMgr.status.casinoCoin;
- }
- }
- public long FactMoneyDifference { get; private set; }
- public bool NotEnoughCredit
- {
- get
- {
- return GameMain.Instance.CharacterMgr.status.casinoCoin < BetSetUI.Instance.MoneySetting.MinValue;
- }
- }
- public bool IsNowSplitHand
- {
- get
- {
- return this.CurrentHand == this.splitHand;
- }
- }
- private void Awake()
- {
- BjPlayer.Instance = this;
- this.m_Playerhands = new PlayerHand[]
- {
- this.standardHand,
- this.splitHand
- };
- }
- private void Start()
- {
- this.m_StartingBet = BetSetUI.Instance.MoneySetting.MinValue;
- }
- public void SubtractBet()
- {
- this.OrijinCredit = GameMain.Instance.CharacterMgr.status.casinoCoin;
- GameMain.Instance.CharacterMgr.status.casinoCoin -= this.CurrentBet;
- UIStates.Instance.OnStateChange();
- }
- public void AwardWinnings(int dealerScore)
- {
- this.TotalWinnings = 0L;
- this.ShowOutcomes(dealerScore, Dealer.Instance.IsNatural21());
- foreach (PlayerHand playerHand in this.m_Playerhands)
- {
- long num = 0L;
- if (playerHand.IsEnded() && !playerHand.IsBust())
- {
- if (playerHand.IsSurrender)
- {
- num = this.GetPushWinnings(playerHand) / 2L;
- }
- else if (playerHand.IsEven)
- {
- num = this.GetPushWinnings(playerHand);
- }
- else if (playerHand.IsWin)
- {
- num = this.GetWinnings(playerHand);
- }
- }
- this.TotalWinnings += num;
- foreach (ChipStack chipStack in ChipManager.Instance.ChipStacks)
- {
- if ((chipStack.IsSplitBetStack && playerHand == this.splitHand) || (!chipStack.IsSplitBetStack && playerHand != this.splitHand))
- {
- chipStack.IsSurrender = playerHand.IsSurrender;
- chipStack.IsWinningStack = (num > 0L);
- chipStack.IsEven = playerHand.IsEven;
- chipStack.IsBlackJack = playerHand.IsNatural21();
- }
- }
- }
- bool flag = GameMain.Instance.CharacterMgr.status.casinoCoin + this.TotalWinnings > 999999L;
- GameMain.Instance.CharacterMgr.status.casinoCoin += this.TotalWinnings;
- if (flag)
- {
- this.FactMoneyDifference = this.TotalWinnings - (this.SplitBet + this.CurrentBet);
- }
- else
- {
- this.FactMoneyDifference = -this.MoneyDifference;
- }
- this.IsDecrease = (GameMain.Instance.CharacterMgr.status.casinoCoin < this.OrijinCredit);
- UIStates.Instance.OnStateChange();
- UIStates.Instance.ShowOutcomeText();
- ChipManager.Instance.UpdateStacks();
- }
- private long GetWinnings(PlayerHand hand)
- {
- long num = this.CurrentBet;
- if (hand == this.splitHand)
- {
- num = this.SplitBet;
- }
- long result = num * 2L;
- if (hand.IsNatural21())
- {
- result = (long)Mathf.FloorToInt((float)num * 2.5f);
- }
- return result;
- }
- private long GetPushWinnings(PlayerHand hand)
- {
- return (!(hand == this.splitHand)) ? this.CurrentBet : this.SplitBet;
- }
- public void SetBet(long bet)
- {
- if (this.CurrentHand == this.splitHand)
- {
- this.SplitBet = bet;
- }
- else
- {
- this.CurrentBet = bet;
- }
- UIStates.Instance.OnStateChange();
- }
- public void ClearBet()
- {
- this.CurrentBet = BetSetUI.Instance.MoneySetting.MinValue;
- UIStates.Instance.OnStateChange();
- }
- public bool IsDoubleDown()
- {
- return this.CurrentHand.IsDoubleDown;
- }
- public bool IsStandardDoubleDown()
- {
- return this.standardHand.IsDoubleDown;
- }
- public bool IsSplitDoubleDown()
- {
- return this.splitHand.IsDoubleDown;
- }
- public void Surrender()
- {
- this.CurrentHand.IsSurrender = true;
- }
- public void DoubleDown()
- {
- this.SubtractDoubleDownBet();
- this.CurrentHand.IsDoubleDown = true;
- this.CurrentHand.Stand();
- }
- public GameObject DealCard(CardData card)
- {
- if (this.IsPlacingBet())
- {
- this.m_StartingBet = this.CurrentBet;
- }
- return this.CurrentHand.DealCard(card);
- }
- public void UpdateScore()
- {
- this.standardHand.UpdateScoreView();
- this.splitHand.UpdateScoreView();
- }
- public void ResetScore()
- {
- this.standardHand.ResetScore();
- this.splitHand.ResetScore();
- }
- public void ResetTable()
- {
- this.CurrentBet = this.m_StartingBet;
- this.OrijinCredit = GameMain.Instance.CharacterMgr.status.casinoCoin;
- this.TotalWinnings = 0L;
- this.m_DoubleDownBet = 0L;
- this.SplitBet = 0L;
- this.standardHand.ResetHand();
- this.splitHand.ResetHand();
- this.CurrentHand = this.standardHand;
- this.m_SplitGame = false;
- this.EndingGame = false;
- this.IsDecrease = false;
- this.IsturnEnd = false;
- UIStates.Instance.StateReset();
- }
- public bool IsSplitGame()
- {
- return this.m_SplitGame;
- }
- public bool IsIdle()
- {
- return this.CurrentHand.CurrentScore == 0 && this.splitHand.CurrentScore == 0 && !BetSetUI.Instance.IsDoBet;
- }
- public bool IsPlacingBet()
- {
- return this.CurrentHand.CurrentScore == 0 && this.splitHand.CurrentScore == 0 && BetSetUI.Instance.IsDoBet;
- }
- public bool CanHit()
- {
- return this.CurrentHand.CanHit();
- }
- public bool CanDoubleDown()
- {
- return this.CurrentHand == this.splitHand && this.splitHand.DoubleDownAvailable();
- }
- public bool HandIsEnded()
- {
- return this.CurrentHand.IsEnded();
- }
- public bool IsNatural21()
- {
- return this.standardHand.IsNatural21();
- }
- public bool IsEnded()
- {
- if (this.m_SplitGame)
- {
- return this.standardHand.IsEnded() && this.splitHand.IsEnded();
- }
- return this.CurrentHand.IsEnded();
- }
- public bool DoubleDownEnoughMoney()
- {
- if (this.CurrentHand == this.splitHand)
- {
- return GameMain.Instance.CharacterMgr.status.casinoCoin - this.SplitBet >= 0L;
- }
- return GameMain.Instance.CharacterMgr.status.casinoCoin - this.CurrentBet >= 0L;
- }
- public bool DoubleDownAvailable()
- {
- return !this.EndingGame && this.CurrentHand.DoubleDownAvailable() && this.DoubleDownEnoughMoney();
- }
- public bool SplitEnoughMoney()
- {
- return GameMain.Instance.CharacterMgr.status.casinoCoin - this.CurrentBet >= 0L;
- }
- public bool SplitAvailable()
- {
- return !this.m_SplitGame && this.CurrentHand.SplitAvailable() && this.SplitEnoughMoney();
- }
- public void StandOnCurrentHand()
- {
- this.CurrentHand.Stand();
- }
- private void SubtractDoubleDownBet()
- {
- this.m_DoubleDownBet = this.CurrentBet;
- GameMain.Instance.CharacterMgr.status.casinoCoin -= this.m_DoubleDownBet;
- if (this.CurrentHand == this.splitHand)
- {
- this.SplitBet += this.m_DoubleDownBet;
- }
- else
- {
- this.CurrentBet += this.m_DoubleDownBet;
- }
- }
- private void SubtractSplitBet()
- {
- this.SplitBet = this.CurrentBet;
- GameMain.Instance.CharacterMgr.status.casinoCoin -= this.SplitBet;
- }
- public void Split()
- {
- this.m_SplitGame = true;
- this.SubtractSplitBet();
- this.CurrentHand = this.splitHand;
- }
- public void NextHand()
- {
- if (this.m_SplitGame)
- {
- this.CurrentHand = this.standardHand;
- this.CurrentHand.ResetPositionForSplit();
- }
- }
- public bool CanSurrender()
- {
- return !this.IsSplitGame() && this.CurrentHand.CanSurrender() && !this.EndingGame && Dealer.Instance.HasFacedownCard();
- }
- private void ShowOutcomes(int dealerScore, bool dealerBlackjack)
- {
- foreach (PlayerHand playerHand in this.m_Playerhands)
- {
- playerHand.ShowOutcome(dealerScore, dealerBlackjack);
- }
- }
- public long GetCurrentBet()
- {
- if (this.CurrentHand == this.splitHand)
- {
- return this.SplitBet;
- }
- return this.CurrentBet;
- }
- public bool IsEven()
- {
- if (this.m_SplitGame)
- {
- return this.standardHand.IsEven && this.splitHand.IsEven;
- }
- return this.standardHand.IsEven;
- }
- public bool ExistDoubleDownwWin()
- {
- return this.standardHand.DoubleDownWin() || this.splitHand.DoubleDownWin();
- }
- public bool ExistWinHand()
- {
- return this.standardHand.IsWin || this.splitHand.IsWin;
- }
- public bool OnesideWin()
- {
- return (!this.standardHand.IsWin || !this.splitHand.IsWin) && (this.standardHand.IsWin || this.splitHand.IsWin);
- }
- public bool ExistSurrenderHand()
- {
- return this.standardHand.IsSurrender;
- }
- public bool ExistBlackJack()
- {
- return this.standardHand.IsNatural21() || this.splitHand.IsNatural21();
- }
- private long m_DoubleDownBet;
- [HideInInspector]
- public bool EndingGame;
- private long m_StartingBet;
- [SerializeField]
- private PlayerHand m_StandardHand;
- [SerializeField]
- private PlayerHand m_SplitHand;
- private PlayerHand[] m_Playerhands;
- private bool m_SplitGame;
- [HideInInspector]
- public bool IsturnEnd;
- }
|