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); } } }
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()); }