internal static void AdjustCharacterPosition(int id, float x, float z, double time, float dir)
        {
            CharacterInfo info = WorldSystem.Instance.GetCharacterById(id);

            if (null != info)
            {
                MovementStateInfo msi = info.GetMovementStateInfo();
                if (time < 1000)
                {
                    Vector3 pos      = msi.GetPosition3D();
                    double  speed    = info.GetActualProperty().MoveSpeed;
                    double  distance = (speed * time) / 1000;
                    double  len      = pos.Length();
                    float   nz       = (float)(z + distance * Math.Cos(dir));
                    float   nx       = (float)(x + distance * Math.Sin(dir));
                    float   dx       = nx - pos.X;
                    float   dz       = nz - pos.Z;
                    float   distSqr  = dx * dx + dz * dz;
                    if (distSqr > 0)
                    {
                        msi.SetPosition2D(x, z);

                        CharacterView view = EntityManager.Instance.GetCharacterViewById(info.GetId());
                        if (null != view)
                        {
                            GfxSystem.UpdateGameObjectLocalPosition2D(view.Actor, x, z);
                        }

                        //LogSystem.Debug("PositionController start, id:{0} dx:{1} dz:{2} time:{3}, just move to pos", id, dx, dz, time);
                    }
                    else
                    {
                        CharacterView view = EntityManager.Instance.GetCharacterViewById(info.GetId());
                        if (null != view)
                        {
                            lock (GfxSystem.SyncLock)
                            {
                                view.ObjectInfo.AdjustDx  = dx;
                                view.ObjectInfo.AdjustDz  = dz;
                                view.ObjectInfo.CurTime   = 0.0f;
                                view.ObjectInfo.TotalTime = 0.5f;
                            }
                        }
                        //LogSystem.Debug("PositionController start, id:{0} dx:{1} dz:{2} time:{3}", id, dx, dz, time);
                    }
                }
                else
                {
                    msi.SetPosition2D(x, z);

                    CharacterView view = EntityManager.Instance.GetCharacterViewById(info.GetId());
                    if (null != view)
                    {
                        GfxSystem.UpdateGameObjectLocalPosition2D(view.Actor, x, z);
                    }

                    //LogSystem.Debug("PositionController just move to pos, id:{0} x:{1} z:{2}", id, x, z);
                }
            }
        }
Beispiel #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);
                }
            }
        }
Beispiel #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);
                }
            }
        }