Esempio n. 1
0
        protected void UpdateMovement()
        {
            CharacterInfo obj = GetOwner();

            if (null != obj && !obj.IsDead() && null != ObjectInfo)
            {
                if (obj.IsNpc && !obj.CastNpcInfo().CanMove)
                {
                    return;
                }
                MovementStateInfo msi = obj.GetMovementStateInfo();
                ObjectInfo.FaceDir     = msi.GetFaceDir();
                ObjectInfo.WantFaceDir = msi.GetWantFaceDir();
                if (msi.IsMoving)
                {
                    Vector3 pos = msi.GetPosition3D();
                    ObjectInfo.MoveCos   = (float)msi.MoveDirCosAngle;
                    ObjectInfo.MoveSin   = (float)msi.MoveDirSinAngle;
                    ObjectInfo.MoveSpeed = (float)obj.GetActualProperty().MoveSpeed *(float)obj.VelocityCoefficient;

                    if (obj is UserInfo)
                    {
                        if (msi.TargetPosition.LengthSquared() < Geometry.c_FloatPrecision)
                        {
                            ObjectInfo.MoveTargetDistanceSqr = 100.0f;
                        }
                        else
                        {
                            ObjectInfo.MoveTargetDistanceSqr = msi.CalcDistancSquareToTarget();
                        }
                    }
                    else
                    {
                        ObjectInfo.MoveTargetDistanceSqr = msi.CalcDistancSquareToTarget();
                    }

                    ObjectInfo.IsLogicMoving = true;
                }
                else
                {
                    ObjectInfo.IsLogicMoving = false;
                }
            }
            else
            {
                ObjectInfo.IsLogicMoving = false;
            }
        }
Esempio n. 2
0
        private void MoveUser(UserInfo obj, long deltaTime)
        {
            MovementStateInfo msi = obj.GetMovementStateInfo();

            if (null != obj.ControlledObject)
            {
                MovementStateInfo ctrlMsi = obj.ControlledObject.GetMovementStateInfo();
                ctrlMsi.IsMoving = msi.IsMoving;
                ctrlMsi.SetFaceDir(msi.GetFaceDir());
                ctrlMsi.SetMoveDir(msi.GetMoveDir());
            }
            if (obj.IsHaveStateFlag(CharacterState_Type.CST_Sleep) || obj.IsHaveStateFlag(CharacterState_Type.CST_FixedPosition))
            {
                return;
            }
            //玩家移动中忽略阻挡,由客户端与AI来规划路径。
            if (!obj.IsDead() && msi.IsMoving && !msi.IsSkillMoving && !msi.IsMoveMeetObstacle)
            {
                Vector3 pos      = msi.GetPosition3D();
                float   speed    = (float)obj.GetRealControlledObject().GetActualProperty().MoveSpeed *(float)obj.VelocityCoefficient;
                float   distance = (speed * (float)(int)deltaTime) / 1000.0f;

                //LogSystem.Debug("MovementSystem user:{0} speed:{1} deltaTime:{2} distance:{3}", obj.GetId(), speed, deltaTime, distance);

                float   x = 0, y = 0;
                Vector2 newPos = new Vector2();
                if (obj.GetAiStateInfo().CurState != (int)AiStateId.Invalid && msi.CalcDistancSquareToTarget() < distance * distance)
                {
                    x = msi.TargetPosition.X;
                    y = msi.TargetPosition.Z;
                    AdjustPosition(obj.SpatialSystem, ref x, ref y);
                    newPos = new Vector2(x, y);
                    msi.SetPosition2D(newPos);
                }
                else
                {
                    float cosV = (float)msi.MoveDirCosAngle;
                    float sinV = (float)msi.MoveDirSinAngle;
                    y = pos.Z + distance * cosV;
                    x = pos.X + distance * sinV;
                    AdjustPosition(obj.SpatialSystem, ref x, ref y);
                    newPos = new Vector2(x, y);
                    msi.SetPosition2D(newPos);
                }
                if (null != obj.ControlledObject)
                {
                    obj.ControlledObject.GetMovementStateInfo().SetPosition2D(newPos);
                }
            }
        }
Esempio n. 3
0
        private void MoveNpc(NpcInfo obj, long deltaTime)
        {
            if (obj.IsHaveStateFlag(CharacterState_Type.CST_Sleep) ||
                obj.IsHaveStateFlag(CharacterState_Type.CST_FixedPosition) ||
                null != obj.ControllerObject)
            {
                return;
            }
            MovementStateInfo msi = obj.GetMovementStateInfo();

            //npc执行移动时忽略阻挡与避让,这些行为由ai模块在规划其路径时执行。
            if (!obj.IsDead() && obj.CanMove && msi.IsMoving && !msi.IsSkillMoving)
            {
                Vector3 pos       = msi.GetPosition3D();
                float   cos_angle = (float)msi.MoveDirCosAngle;
                float   sin_angle = (float)msi.MoveDirSinAngle;
                float   speed     = (float)obj.GetActualProperty().MoveSpeed *(float)obj.VelocityCoefficient;
                float   distance  = (speed * (float)(int)deltaTime) / 1000.0f;

                //LogSystem.Debug("MovementSystem npc:{0} speed:{1} deltaTime:{2} distance:{3}", obj.GetId(), speed, deltaTime, distance);

                float x = 0, y = 0;
                if (msi.CalcDistancSquareToTarget() < distance * distance)
                {
                    x = msi.TargetPosition.X;
                    y = msi.TargetPosition.Z;
                    AdjustPosition(obj.SpatialSystem, ref x, ref y);
                    Vector2 newPos = new Vector2(x, y);
                    msi.SetPosition2D(newPos);
                }
                else
                {
                    float len = pos.Length();
                    y = pos.Z + distance * cos_angle;
                    x = pos.X + distance * sin_angle;
                    AdjustPosition(obj.SpatialSystem, ref x, ref y);
                    Vector2 newPos = new Vector2(x, y);
                    msi.SetPosition2D(newPos);
                }
            }
        }