Пример #1
0
 private void OnFall(bool isFalling)
 {
     if (isFalling)
     {
         this.mMesh.JumpLoop();
         GravitySpeed.Reset();
     }
     else
     {
         if (GravitySpeed.GetTimeSinceFall() >= 600)
         {
             this.Hit(GravitySpeed.GetSpeed() / GravitySpeed.SPEED_TMAX * VanillaPlayer.DEFAULT_PLAYER_LIFE * 0.8f);
         }
         if (this.mCharInfo.IsPlayer)
         {
             ((Sinbad)this.mMesh).EndJump();
         }
     }
 }
Пример #2
0
        public void Update(float frameTime)
        {
            Vector3 translation = Vector3.ZERO;

            if (this.mCharInfo.Life > 0)
            {
                if (this.mFollow != null && this.mFollow.IsOnFloor() && this.mForcedDestination.Count == 0 &&
                    (this.mFollow.FeetPosition - this.mDestination).SquaredLength > this.mStaySqrDistToGoal)
                {
                    this.FindPathTo(this.mFollow.FeetPosition);
                }

                if (this.mPathFinder != null)
                {
                    this.mForcedDestination = this.mPathFinder.ContinuePathFinding();
                    if (this.mForcedDestination.Count > 0)
                    {
                        this.mPathFinder = null;
                        this.ComputeNextYaw();
                        this.mLastSquaredDist = -1;
                        this.MovementInfo.IsMovementForced = true;
                        this.mWasAllowedToMove             = this.MovementInfo.IsAllowedToMove;
                        this.MovementInfo.IsAllowedToMove  = false;
                    }
                    else if (this.mPathFinder.HaveGiveUp)
                    {
                        this.mPathFinder  = null;
                        this.mDestination = Vector3.ZERO;
                        Console.WriteLine("forget path");
                    }
                }

                Degree distToYawGoal = this.mYawGoal - this.GetYaw();
                float  absDiffYaw    = System.Math.Abs((((int)distToYawGoal.ValueAngleUnits) + 360) % 360);

                if (this.MovementInfo.IsMovementForced && this.mForcedDestination.Count == 0 && absDiffYaw < 1)
                {
                    this.MovementInfo.IsAllowedToMove  = this.mWasAllowedToMove;
                    this.MovementInfo.IsMovementForced = false;
                }

                if (this.MovementInfo.IsMovementForced)
                {
                    this.MovementInfo.YawValue = YAW_SPEED * YawFactor.GetFactor(distToYawGoal);

                    if (this.mForcedDestination.Count > 0)
                    {
                        Vector3 diff            = this.mForcedDestination.Peek() - this.FeetPosition;
                        float   squaredDistance = diff.x * diff.x + diff.z * diff.z;
                        if ((this.mDestination - this.FeetPosition).SquaredLength < this.mStaySqrDistToGoal)
                        {
                            while (this.mForcedDestination.Count > 0)
                            {
                                this.PopForcedDest(false);
                            }
                        }
                        else if (this.mLastSquaredDist == -1 || squaredDistance > SQUARED_DIST_PRECISION)
                        {
                            if (absDiffYaw < 20)
                            {
                                float factor = 6 / absDiffYaw;
                                this.MovementInfo.MoveDirection = this.mMesh.MoveForwardDir * (factor <= 1 ? factor : 1);

                                if (this.mForcedDestination.Peek().y > this.FeetPosition.y || this.mIsBlocked)
                                {
                                    this.MovementInfo.MoveDirection += Vector3.UNIT_Y;
                                }
                            }
                            this.mLastSquaredDist = squaredDistance;
                        }
                        else
                        {
                            this.PopForcedDest();
                        }
                    }
                }
                if (this.mCharInfo.IsPlayer)
                {
                    ((VanillaPlayer)this).Update(frameTime);
                }
                else
                {
                    ((VanillaNonPlayer)this).Update(frameTime);
                }

                if (this.MovementInfo.IsPushedByArcaneLevitator)
                {
                    translation.y = ArcaneLevitatorSpeed.GetSpeed();
                }
                else if (this.MovementInfo.IsJumping)
                {
                    translation.y = JumpSpeed.GetSpeed();
                }
                else
                {
                    translation.y = GravitySpeed.GetSpeed();
                }

                translation += WALK_SPEED * this.MovementInfo.MoveDirection * new Vector3(1, 0, 1)
                               * (this.MovementInfo.Sprint ? SPRINT_FACTOR : 1); // Ignores the y axis translation here
                this.mNode.Yaw(this.MovementInfo.YawValue * frameTime);

                this.Translate(translation * frameTime);    // Apply the translation

                if (this.MovementInfo.IsAllowedToMove)
                {
                    this.mYawGoal = this.GetYaw();
                }

                if (!this.MovementInfo.IsJumping && !this.MovementInfo.IsFalling && !this.MovementInfo.IsPushedByArcaneLevitator)
                {
                    int zDirSign     = this.mMesh.Zdir(this.MovementInfo.MoveDirection);
                    int prevZDirSign = this.mMesh.Zdir(this.mPreviousDirection);

                    if (zDirSign != 0 && zDirSign != prevZDirSign)
                    {
                        this.mMesh.Walk(true, zDirSign);
                    }
                    else if (zDirSign == 0 && prevZDirSign != 0)
                    {
                        this.mMesh.Walk(false);
                    }
                }
                this.mPreviousDirection = this.MovementInfo.MoveDirection;
                if (this.mMesh.AnimMgr.CurrentAnims.Count == 0) // By default apply idle anim
                {
                    this.mMesh.Idle();
                    this.mPreviousDirection = Vector3.ZERO;
                }
            }
            else
            {
                this.mTimeSinceDead += frameTime;
                if (this.mTimeSinceDead >= 2)
                {
                    this.WaitForRemove = true;
                }
            }

            this.mMesh.Update(frameTime);
            this.MovementInfo.ClearInfo();

            if (this.FeetPosition.y < 0)
            {
                this.WaitForRemove = true;
            }
        }