private object StopMove(object param) { if (m_Owner == null) { return(null); } Client.IMapSystem mapSys = EntitySystem.m_ClientGlobal.GetMapSystem(); if (mapSys == null) { return(null); } if (param != null) { Vector3 pos = (Vector3)param; if (m_bMoving) { m_param.m_speed = m_Owner.GetProp((int)WorldObjProp.MoveSpeed) * EntityConst.MOVE_SPEED_RATE; m_vSpeed = (m_param.m_speed * m_fSpeedFact * m_fSpeedTerrainFact) * m_dir; long nCurTime = Engine.Utility.TimeHelper.GetTickCount(); Vector3 ds = m_vSpeed * ((nCurTime - m_LastTime) * 0.001f); pos = m_vLastPos + ds; m_fDistance += ds.magnitude; m_LastTime = nCurTime; if (EntitySystem.m_ClientGlobal.IsMainPlayer(m_Owner)) { m_uServerTime = EntityConfig.serverTime; } } // 停止时如果是阻挡点客户端做一下修正 目前的同步方案可能会和服务器之间不同步 测试再看效果 if (!mapSys.CanWalk(pos)) { pos = m_lastWalkPos; } m_Owner.SendMessage(EntityMessage.EntityCommand_SetPos, pos); m_LastTime = Engine.Utility.TimeHelper.GetTickCount(); //Engine.Utility.Log.Error("Move stop: ({0},{1}) {2} {3} speed:{4}", pos.x, pos.z, m_LastTime, m_fDistance, m_fDistance / (m_LastTime - m_BeginTime)); // 切换到Normal状态 Creature owner = m_Owner as Creature; if (owner != null) { if (!m_bIgnoreMoveAction && !owner.IsDead()) { if (m_param != null) { owner.ChangeState(CreatureState.Normal, (object)(m_param.m_ignoreStand?1:0)); } else { owner.ChangeState(CreatureState.Normal); } } } else { m_Owner.PlayAction(EntityAction.Stand, 0, m_fSpeedFact); } } m_LastTime = 0; // 强制同步 SyncPos(true); // 停止同步 Client.stEntityStopMove stopEntity = new Client.stEntityStopMove(); stopEntity.uid = m_Owner.GetUID(); stopEntity.bExternal = m_bExternalStop; m_vSpeed = Vector3.zero; m_nPathIndex = -1; if (m_param != null) { m_param.m_speed = 0; } m_bMoving = false; m_hasTarget = false; //Engine.Utility.TimerAxis.Instance().KillTimer(0, this); if (m_Owner.GetEntityCallback() != null && m_param != null) { m_Owner.GetEntityCallback().OnMoveEnd(m_Owner, m_param.param); } Engine.Utility.EventEngine.Instance().DispatchEvent((int)GameEventID.ENTITYSYSTEM_ENTITYSTOPMOVE, stopEntity); return(null); }
//public virtual void OnTimer(uint uTimerID) //{ // MoveUpdate(); //} public override void Update() { if (m_Owner == null) { return; } if (m_curScene == null) { return; } if (!m_bMoving) { return; } // 实时取对象身上的速度值 m_param.m_speed = m_Owner.GetProp((int)WorldObjProp.MoveSpeed) * EntityConst.MOVE_SPEED_RATE; m_vSpeed = (m_param.m_speed * m_fSpeedFact * m_fSpeedTerrainFact) * m_dir; long nCurTime = Engine.Utility.TimeHelper.GetTickCount(); Vector3 ds = m_vSpeed * ((nCurTime - m_LastTime) * 0.001f); Vector3 pos = m_vLastPos + ds; m_LastTime = nCurTime; // 获取服务器时间 if (EntitySystem.m_ClientGlobal.IsMainPlayer(m_Owner)) { m_uServerTime = EntityConfig.serverTime; } if (pos.Equals(m_vLastPos)) { return; } Client.IMapSystem mapSys = EntitySystem.m_ClientGlobal.GetMapSystem(); if (mapSys == null) { return; } m_fDistance += ds.magnitude; // 检测是否到达目标点 if (ChkMove(pos) && !m_bMoveDir) // pos 已经超过目标点 { m_nPathIndex++; if (m_nPathIndex < m_param.path.Count) // 路径上的点还没有走完 { // 处理路径上点切换 SwitchTarget(m_param.path[m_nPathIndex], ref pos); // 贴地处理 CloseTerrainPos(ref pos); if (mapSys.CanWalk(pos)) { m_lastWalkPos = pos; } // 设置当前位置 m_Owner.SetPos(ref pos); // 同步玩家位置 发送实体移动事件 SyncPos(); m_vLastPos = pos; } else { Vector3 pp = m_target; // 贴地处理 CloseTerrainPos(ref pp); if (mapSys.CanWalk(pp)) { m_lastWalkPos = pp; } //pp.y = pos.y; m_bMoving = false; // 停止移动 m_bExternalStop = false; // 非外部因素 StopMove(pp); m_bExternalStop = true; } } else { // 设置新位置 //if (mapSys.CanWalk(pos)) { // 贴地处理 CloseTerrainPos(ref pos); if (mapSys.CanWalk(pos)) { m_lastWalkPos = pos; } //Engine.Utility.Log.Error("SetPos:{0},{1}", pos.x, pos.z); m_Owner.SetPos(ref pos); SyncPos(); m_vLastPos = pos; } //else //{ // // 遇到障碍就停止 // m_Owner.SetPos(ref m_vLastPos); // StopMove(m_vLastPos); //} } // 设置场景草扰动 if (m_Owner.GetEntityType() == EntityType.EntityType_Player) { mapSys.AddGrassWaveForce(pos, 0.8f, 1.2f); } }