Пример #1
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);
                }
            }
        }
Пример #2
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;
            }
        }
Пример #3
0
 internal void Create(NpcInfo npc)
 {
     Init();
     if (null != npc)
     {
         m_Npc             = npc;
         ObjectInfo.UnitId = m_Npc.GetUnitId();
         ObjectInfo.CampId = m_Npc.GetCampId();
         ObjectInfo.LinkId = m_Npc.GetLinkId();
         MovementStateInfo msi = m_Npc.GetMovementStateInfo();
         Vector3           pos = msi.GetPosition3D();
         float             dir = msi.GetFaceDir();
         CreateActor(m_Npc.GetId(), m_Npc.GetModel(), pos, dir, m_Npc.Scale);
         npc.ActorId      = Actor;
         ObjectInfo.IsNpc = true;
         CreateBornEffect(Actor, npc.GetBornEffect(), npc.ParticleScale, npc.GetBornEffectTime());
         InitAnimationSets();
     }
 }
Пример #4
0
        protected void SimulateMove()
        {
            if (!m_Npc.IsSimulateMove)
            {
                return;
            }
            if (m_Npc.SummonOwnerId < 0)
            {
                return;
            }
            CharacterInfo owner = WorldSystem.Instance.GetCharacterById(m_Npc.SummonOwnerId);

            if (owner == null)
            {
                return;
            }
            CharacterView owner_view = EntityManager.Instance.GetCharacterViewById(m_Npc.SummonOwnerId);

            if (owner_view == null)
            {
                return;
            }
            MovementStateInfo msi     = m_Npc.GetMovementStateInfo();
            MovementStateInfo sim_msi = owner.GetMovementStateInfo();

            m_Npc.GetActualProperty().SetMoveSpeed(Operate_Type.OT_Absolute, owner.GetActualProperty().MoveSpeed);
            m_Npc.VelocityCoefficient = owner.VelocityCoefficient;
            if (owner_view.ObjectInfo.IsGfxMoveControl)
            {
                msi.IsMoving = false;
            }
            else
            {
                msi.IsMoving = sim_msi.IsMoving;
            }
            msi.SetFaceDir(sim_msi.GetFaceDir());
            msi.SetWantFaceDir(sim_msi.GetWantFaceDir());
            msi.SetMoveDir(sim_msi.GetMoveDir());
        }
Пример #5
0
 internal void Create(UserInfo user)
 {
     Init();
     if (null != user)
     {
         m_User            = user;
         ObjectInfo.UnitId = m_User.GetUnitId();
         ObjectInfo.CampId = m_User.GetCampId();
         ObjectInfo.LinkId = m_User.GetLinkId();
         MovementStateInfo msi = m_User.GetMovementStateInfo();
         Vector3           pos = msi.GetPosition3D();
         float             dir = msi.GetFaceDir();
         CreateActor(m_User.GetId(), m_User.GetModel(), pos, dir, m_User.Scale);
         user.ActorId = Actor;
         UpdateXSoulEquip();
         InitAnimationSets();
         ObjectInfo.IsPlayer = true;
         if (user.GetId() == WorldSystem.Instance.PlayerSelfId)
         {
             GfxSystem.MarkPlayerSelf(Actor);
         }
     }
 }