Esempio n. 1
0
    private void ShakeOnce()
    {
        if (_state != PokeballState.Shaking)
        {
            return;
        }

        _shakeLeft--;

        if (_shakeLeft > 0)
        {
            // For now Pokéballs are Masterballs.

            float escapeChance = 0.045f; // We should get this value from the Pokemon stats. // 0.045 escape chance makes a capture probability between 75% to 83% after 4 to 6 shakes.

            if (Random.value < escapeChance)
            {
                Explode();
            }
            else
            {
                Vector3 force = Random.onUnitSphere * 0.3f;
                force.y = 0;

                Freeze(false);
                StopMove();
                _rigid.AddForce(force, ForceMode.VelocityChange);
                PlaySound("Shake");

                float delay = Random.Range(1.3f, 2f) + (_shakeLeft == 1 ? 1.2f : 0f);

                //if (_editorTest)
                {
                    delay *= 0.75f;
                }

                //object[] parms = new object[2] { -force, delay / 2f };
                object[] parms = new object[2] { -force, 0.25f };

                StartCoroutine("BalanceShakeForce", parms);
                Invoke("ShakeOnce", delay);
            }
        }
        else
        {
            // The capture is a success!

            _state = PokeballState.Lying;
            _isPokemonInside = true;

            _shakeLeft = -1;

            _content = _temporaryContent;
            _content.StoreInPokeball();
            _content.SetCaptureResult(true);
            _pkmnName.text = _content._name;

            _temporaryContent = null;
            StopMove();
            _animator.SetBool("RedLightOn", false);
            PlaySound("Caught");

            Instantiate(Resources.Load("Particles/CaptureParticle"), _tr.position, Quaternion.identity);

            //StartBacking();
            StartCoroutine(StartBackingWithDelayCoroutine(2.25f));
        }
    }