Example #1
0
    private void LateUpdate()
    {
        if (Owner == null && BasePV.IsMine)
        {
            PhotonNetwork.Destroy(gameObject);
            return;
        }

        switch (State)
        {
        case HorseState.Mounted:
        {
            if (this.Owner == null)
            {
                this.Unmounted();
                return;
            }

            Owner.baseT.position = baseT.position + heroOffsetVector;
            Owner.baseT.rotation = baseR.rotation;
            Owner.baseR.velocity = baseR.velocity;

            if (controller.targetDirection == -874f)
            {
                this.ToIdleAnimation();
                if (baseR.velocity.magnitude > 15f)
                {
                    if (!Owner.baseA.IsPlaying("horse_run"))
                    {
                        Owner.CrossFade("horse_run", 0.1f);
                    }
                }
                else if (!Owner.baseA.IsPlaying("horse_idle"))
                {
                    Owner.CrossFade("horse_idle", 0.1f);
                }
            }
            else
            {
                base.gameObject.transform.rotation = Quaternion.Lerp(base.gameObject.transform.rotation, Quaternion.Euler(0f, this.controller.targetDirection, 0f), 100f * Time.deltaTime / (base.rigidbody.velocity.magnitude + 20f));
                if (this.controller.isWALKDown)
                {
                    baseR.AddForce(baseT.Forward() * this.speed * 0.6f, ForceMode.Acceleration);
                    if (baseR.velocity.magnitude >= this.speed * 0.6f)
                    {
                        baseR.AddForce(-this.speed * 0.6f * baseR.velocity.normalized, ForceMode.Acceleration);
                    }
                }
                else
                {
                    baseR.AddForce(baseT.Forward() * this.speed, ForceMode.Acceleration);
                    if (baseR.velocity.magnitude >= this.speed)
                    {
                        baseR.AddForce(-this.speed * baseR.velocity.normalized, ForceMode.Acceleration);
                    }
                }
                if (baseR.velocity.magnitude > 8f)
                {
                    if (!baseA.IsPlaying("horse_Run"))
                    {
                        this.CrossFade("horse_Run", 0.1f);
                    }
                    if (!this.Owner.baseA.IsPlaying("horse_run"))
                    {
                        this.Owner.CrossFade("horse_run", 0.1f);
                    }
                    if (!this.dustParticle.enableEmission)
                    {
                        this.dustParticle.enableEmission = true;
                        BasePV.RPC("setDust", PhotonTargets.Others, new object[]
                            {
                                true
                            });
                    }
                }
                else
                {
                    if (!baseA.IsPlaying("horse_WALK"))
                    {
                        this.CrossFade("horse_WALK", 0.1f);
                    }
                    if (!this.Owner.baseA.IsPlaying("horse_idle"))
                    {
                        this.Owner.baseA.CrossFade("horse_idle", 0.1f);
                    }
                    if (this.dustParticle.enableEmission)
                    {
                        this.dustParticle.enableEmission = false;
                        BasePV.RPC("setDust", PhotonTargets.Others, new object[]
                            {
                                false
                            });
                    }
                }
            }

            if ((this.controller.isAttackDown || this.controller.isAttackIIDown) && this.IsGrounded())
            {
                baseR.AddForce(Vectors.up * 25f, ForceMode.VelocityChange);
            }
        }
        break;

        case HorseState.Follow:
        {
            if (this.Owner == null)
            {
                this.Unmounted();
                return;
            }

            if (baseR.velocity.magnitude > 8f)
            {
                if (!baseA.IsPlaying("horse_Run"))
                {
                    this.CrossFade("horse_Run", 0.1f);
                }
                if (!this.dustParticle.enableEmission)
                {
                    this.dustParticle.enableEmission = true;
                    BasePV.RPC("setDust", PhotonTargets.Others, new object[]
                        {
                            true
                        });
                }
            }
            else
            {
                if (!baseA.IsPlaying("horse_WALK"))
                {
                    this.CrossFade("horse_WALK", 0.1f);
                }
                if (this.dustParticle.enableEmission)
                {
                    this.dustParticle.enableEmission = false;
                    BasePV.RPC("setDust", PhotonTargets.Others, new object[]
                        {
                            false
                        });
                }
            }

            float num = -Mathf.DeltaAngle(FengMath.GetHorizontalAngle(baseT.position, this.setPoint), base.gameObject.transform.rotation.eulerAngles.y - 90f);
            base.gameObject.transform.rotation = Quaternion.Lerp(base.gameObject.transform.rotation, Quaternion.Euler(0f, base.gameObject.transform.rotation.eulerAngles.y + num, 0f), 200f * Time.deltaTime / (baseR.velocity.magnitude + 20f));
            if (Vector3.Distance(this.setPoint, baseT.position) < 20f)
            {
                baseR.AddForce(baseT.Forward() * this.speed * 0.7f, ForceMode.Acceleration);
                if (baseR.velocity.magnitude >= this.speed)
                {
                    baseR.AddForce(-this.speed * 0.7f * baseR.velocity.normalized, ForceMode.Acceleration);
                }
            }
            else
            {
                baseR.AddForce(base.transform.Forward() * this.speed, ForceMode.Acceleration);
                if (baseR.velocity.magnitude >= this.speed)
                {
                    baseR.AddForce(-this.speed * baseR.velocity.normalized, ForceMode.Acceleration);
                }
            }
            this.timeElapsed += Time.deltaTime;
            if (this.timeElapsed > 0.6f)
            {
                this.timeElapsed = 0f;
                if (Vector3.Distance(this.Owner.baseT.position, this.setPoint) > 20f)
                {
                    this.Followed();
                }
            }
            if (Vector3.Distance(this.Owner.baseT.position, baseT.position) < 5f)
            {
                this.Unmounted();
            }
            if (Vector3.Distance(this.setPoint, baseT.position) < 5f)
            {
                this.Unmounted();
            }
            this.awayTimer += Time.deltaTime;
            if (this.awayTimer > 6f)
            {
                this.awayTimer = 0f;
                if (Physics.Linecast(baseT.position + Vectors.up, this.Owner.baseT.position + Vectors.up, Layers.Ground.value))
                {
                    baseT.position = new Vector3(this.Owner.baseT.position.x, this.GetHeight(this.Owner.baseT.position + Vectors.up * 5f), this.Owner.baseT.position.z);
                }
            }
        }
        break;

        case HorseState.Idle:
        {
            this.ToIdleAnimation();
            if (this.Owner != null && Vector3.Distance(this.Owner.baseT.position, baseT.position) > 20f)
            {
                this.Followed();
            }
        }
        break;
        }
        baseR.AddForce(new Vector3(0f, -50f * baseR.mass, 0f));
    }