private void MoveNpc(EntityInfo obj, long deltaTime) { if (obj.HaveState(CharacterPropertyEnum.x3002_昏睡) || obj.HaveState(CharacterPropertyEnum.x3001_眩晕)) { return; } MovementStateInfo msi = obj.GetMovementStateInfo(); //npc执行移动时忽略阻挡与避让,这些行为由ai模块在规划其路径时执行。 if (!obj.IsDead() && obj.CanMove && msi.IsMoving) { ScriptRuntime.Vector3 pos = msi.GetPosition3D(); float speed = (float)obj.ActualProperty.GetFloat(CharacterPropertyEnum.x2011_最终速度); float distance = (speed * (float)(int)deltaTime) / 1000.0f; ScriptRuntime.Vector3 dir = msi.TargetDir; //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; ScriptRuntime.Vector2 newPos = new ScriptRuntime.Vector2(x, y); msi.SetPosition2D(newPos); msi.IsMoving = false; } else { ScriptRuntime.Vector3 tpos = pos + dir * distance; msi.SetPosition(tpos); } } }
private void MoveNpc(EntityInfo obj, long deltaTime) { if (obj.HaveState(CharacterPropertyEnum.x3002_昏睡) || obj.HaveState(CharacterPropertyEnum.x3001_眩晕)) { return; } MovementStateInfo msi = obj.GetMovementStateInfo(); //npc执行移动时忽略阻挡与避让,这些行为由ai模块在规划其路径时执行。 if (!obj.IsDead() && obj.CanMove && msi.IsMoving && !msi.IsSkillMoving) { ScriptRuntime.Vector3 pos = msi.GetPosition3D(); float speed = (float)obj.ActualProperty.GetFloat(CharacterPropertyEnum.x2011_最终速度); float distance = (speed * (float)(int)deltaTime) / 1000.0f; ScriptRuntime.Vector3 dir = msi.TargetDir; //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; ScriptRuntime.Vector2 newPos = new ScriptRuntime.Vector2(x, y); msi.SetPosition2D(newPos); msi.IsMoving = false; Scene scene = obj.SceneContext.CustomData as Scene; if (null != scene) { Msg_RC_NpcMove npcMoveBuilder = DataSyncUtility.BuildNpcMoveMessage(obj); if (null != npcMoveBuilder) { scene.NotifyAllUser(RoomMessageDefine.Msg_RC_NpcMove, npcMoveBuilder); } } } else { ScriptRuntime.Vector3 tpos = pos + dir * distance; msi.SetPosition(tpos); } } }
public bool HaveState(int objId, string state) { EntityInfo entity = m_Scene.EntityManager.GetEntityInfo(objId); if (null != entity) { return(entity.HaveState((CharacterPropertyEnum)CharacterStateUtility.NameToState(state))); } return(false); }
public bool HaveState(int objId, string state) { EntityViewModel view = GetEntityViewById(objId); if (null != view && null != view.Entity) { EntityInfo npc = view.Entity; return(npc.HaveState((CharacterPropertyEnum)CharacterStateUtility.NameToState(state))); } return(false); }