예제 #1
0
        // Returns the number of chips and coins placed.
        public int PlaceEarnings(float value)
        {
            int cents        = (int)Math.Round(value * 100);
            int wholeDollars = cents / 100;
            int centsOnly    = cents % 100;

            int itemsPlaced = PlaceEarnings(wholeDollars);

            var position   = Vector3.up * (ChipThickness * itemsPlaced - ChipInlayDepth) + Vector3.left * ChipSidestepDistance;
            var coinOffset = Vector2.zero;

            while (centsOnly >= 25)
            {
                var quarter = BaccaratScript.Instantiate(Owner.Quarter, ChipStack.transform);
                quarter.SetActive(true);
                quarter.transform.localScale      *= 0.375f;
                quarter.transform.localPosition    = position + new Vector3(coinOffset.x, 0, coinOffset.y);
                quarter.transform.localEulerAngles = new Vector3(0, UnityEngine.Random.Range(0f, 360f), 0);

                // Flip with 50% chance
                if (UnityEngine.Random.Range(0, 2) == 0)
                {
                    quarter.transform.Rotate(Vector3.forward, 180);
                    quarter.transform.localPosition += Vector3.up * 0.00175f * 0.375f;
                }

                centsOnly -= 25;
                coinOffset = 0.0001f * UnityEngine.Random.insideUnitCircle;
                position  += Vector3.up * 0.00175f * 0.375f;

                itemsPlaced++;
            }

            while (centsOnly >= 5)
            {
                var nickel = BaccaratScript.Instantiate(Owner.Nickel, ChipStack.transform);
                nickel.SetActive(true);
                nickel.transform.localScale      *= 0.375f;
                nickel.transform.localPosition    = position + new Vector3(coinOffset.x, 0, coinOffset.y);
                nickel.transform.localEulerAngles = new Vector3(0, UnityEngine.Random.Range(0f, 360f), 0);

                // Flip with 50% chance
                if (UnityEngine.Random.Range(0, 2) == 0)
                {
                    nickel.transform.Rotate(Vector3.forward, 180);
                    nickel.transform.localPosition += Vector3.up * 0.00195f * 0.375f;
                }

                centsOnly -= 5;
                coinOffset = 0.0001f * UnityEngine.Random.insideUnitCircle;
                position  += Vector3.up * 0.00195f * 0.375f;

                itemsPlaced++;
            }

            return(itemsPlaced);
        }
예제 #2
0
        public Bet(BaccaratScript owner, KMSelectable selectable, GameObject chipStack)
        {
            Owner      = owner;
            Selectable = selectable;
            ChipStack  = chipStack;

            Chips       = new List <GameObject>();
            ChipIndices = new List <int>();

            Selectable.OnInteract += delegate()
            {
                if (Owner.AcceptsInput)
                {
                    if (ActiveCoroutine != null)
                    {
                        Owner.StopCoroutine(ActiveCoroutine);
                    }
                    ActiveCoroutine = Owner.StartCoroutine(CheckForLongPress());
                }
                return(false);
            };
            Selectable.OnInteractEnded += delegate()
            {
                if (Owner.AcceptsInput)
                {
                    if (ActiveCoroutine != null)
                    {
                        Owner.StopCoroutine(ActiveCoroutine);
                        ActiveCoroutine = null;

                        // Short press, add a new chip
                        float chipRotation = UnityEngine.Random.Range(0f, 360f);

                        // The new chip will keep the textures of the active chip
                        var newChip = BaccaratScript.Instantiate(Owner.CurrentChip.gameObject, ChipStack.transform);
                        newChip.transform.localScale      *= 0.5f;
                        newChip.transform.localPosition    = Vector3.up * ChipThickness * ChipIndices.Count;
                        newChip.transform.localEulerAngles = new Vector3(-90, 0, chipRotation);

                        newChip.transform.GetChild(0).Rotate(Vector3.forward, chipRotation);

                        Chips.Add(newChip);
                        ChipIndices.Add(Owner.CurrentChipIndex);

                        Owner.Audio.PlaySoundAtTransform("chip", Owner.transform);
                    }
                }
            };
        }
예제 #3
0
        public void Clear()
        {
            bool hadValue = Value > 0;

            // Long press, remove all chips
            for (int i = 0; i < ChipStack.transform.childCount; i++)
            {
                BaccaratScript.Destroy(ChipStack.transform.GetChild(i).gameObject);
            }

            Chips.Clear();
            ChipIndices.Clear();

            if (hadValue)
            {
                Owner.Audio.PlaySoundAtTransform("chipclear", Owner.transform);
            }
        }
예제 #4
0
        // Returns the number of chips placed.
        public int PlaceEarnings(int value)
        {
            var chipIndices = BaccaratScript.ToChipIndices(value);

            for (int i = 0; i < chipIndices.Count; i++)
            {
                float chipRotation = UnityEngine.Random.Range(0f, 360f);

                // The new chip will keep the textures of the active chip, so rewrite them
                var newChip = BaccaratScript.Instantiate(Owner.CurrentChip.gameObject, ChipStack.transform);
                newChip.GetComponent <Renderer>().material = Owner.ChipMaterials[chipIndices[i]];
                newChip.transform.localScale      *= 0.5f;
                newChip.transform.localPosition    = Vector3.up * ChipThickness * i + Vector3.left * ChipSidestepDistance;
                newChip.transform.localEulerAngles = new Vector3(-90, 0, chipRotation);

                var inlayTransform = newChip.transform.GetChild(0);
                inlayTransform.gameObject.GetComponent <Renderer>().material = Owner.InlayMaterials[chipIndices[i]];
                inlayTransform.Rotate(Vector3.forward, chipRotation);
            }

            return(chipIndices.Count);
        }