static private BuildNpcMoveMessage ( |
||
npc | ||
리턴 |
private void MoveNpc(EntityInfo obj, long deltaTime) { if (obj.IsHaveStateFlag(CharacterState_Type.CST_Sleep) || obj.IsHaveStateFlag(CharacterState_Type.CST_FixedPosition)) { 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.GetActualProperty().MoveSpeed; 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; User user = obj.CustomData as User; if (null != user) { Msg_RC_NpcMove npcMoveBuilder = DataSyncUtility.BuildNpcMoveMessage(obj); if (null != npcMoveBuilder) { Scene scene = user.OwnRoom.ActiveScene; if (null != scene) { scene.NotifyAllUser(RoomMessageDefine.Msg_RC_NpcMove, npcMoveBuilder); } } } } else { ScriptRuntime.Vector3 tpos = pos + dir * distance; msi.SetPosition(tpos); } } }
private void OnAiStopPursue(EntityInfo npc) { Scene scene = npc.SceneContext.CustomData as Scene; if (null != scene) { npc.GetMovementStateInfo().IsMoving = false; if (npc.GetMovementStateInfo().IsMoveStatusChanged) { npc.GetMovementStateInfo().IsMoveStatusChanged = false; Msg_RC_NpcMove npcMoveBuilder = DataSyncUtility.BuildNpcMoveMessage(npc); if (null != npcMoveBuilder) { scene.NotifyAllUser(RoomMessageDefine.Msg_RC_NpcMove, npcMoveBuilder); } } } }
internal static void Execute(object msg, User user) { Msg_CR_UserMoveToPos move_msg = msg as Msg_CR_UserMoveToPos; if (move_msg == null) { return; } EntityInfo charactor = user.Info; if (charactor == null) { LogSys.Log(LOG_TYPE.DEBUG, "charactor {0}({1},{2},{3}) not exist", user.RoleId, user.GetKey(), user.Guid, user.Name); return; } /// if (charactor.GetAIEnable()) { float tx, tz; ProtoHelper.DecodePosition2D(move_msg.target_pos, out tx, out tz); ScriptRuntime.Vector3 pos = new ScriptRuntime.Vector3(tx, 0, tz); MovementStateInfo msi = charactor.GetMovementStateInfo(); msi.IsMoving = true; msi.TargetPosition = pos; float dir = Geometry.GetYRadian(msi.GetPosition3D(), pos); msi.SetFaceDir(dir); msi.SetMoveDir(dir); Msg_RC_NpcMove npcMoveBuilder = DataSyncUtility.BuildNpcMoveMessage(charactor); if (null != npcMoveBuilder) { Scene scene = user.OwnRoom.ActiveScene; if (null != scene) { scene.NotifyAllUser(RoomMessageDefine.Msg_RC_NpcMove, npcMoveBuilder); } } } }
private void OnAiPursue(EntityInfo npc, ScriptRuntime.Vector3 target) { Scene scene = npc.SceneContext.CustomData as Scene; if (null != scene) { npc.GetMovementStateInfo().TargetPosition = target; float dir = Geometry.GetYRadian(npc.GetMovementStateInfo().GetPosition3D(), target); npc.GetMovementStateInfo().SetFaceDir(dir); npc.GetMovementStateInfo().SetMoveDir(dir); npc.GetMovementStateInfo().IsMoving = true; if (npc.GetMovementStateInfo().IsMoveStatusChanged) { npc.GetMovementStateInfo().IsMoveStatusChanged = false; Msg_RC_NpcMove npcMoveBuilder = DataSyncUtility.BuildNpcMoveMessage(npc); if (null != npcMoveBuilder) { scene.NotifyAllUser(RoomMessageDefine.Msg_RC_NpcMove, npcMoveBuilder); } } } }