Beispiel #1
0
 static public int get_IsFinish(IntPtr l)
 {
     try {
         GameFramework.AiData_ForMoveCommand self = (GameFramework.AiData_ForMoveCommand)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.IsFinish);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
        private static bool WayPointArrived(EntityInfo charObj, AiData_ForMoveCommand data)
        {
            bool  ret         = false;
            var   move_info   = charObj.GetMovementStateInfo();
            float powDistDest = move_info.CalcDistancSquareToTarget();

            if (powDistDest <= 1f)
            {
                ret = true;
            }
            return(ret);
        }
        private static void MoveToNext(EntityInfo charObj, AiData_ForMoveCommand data, ref ScriptRuntime.Vector3 targetPos)
        {
            if (++data.Index >= data.WayPoints.Count)
            {
                data.IsFinish = true;
                return;
            }

            var move_info = charObj.GetMovementStateInfo();

            targetPos = data.WayPoints[data.Index];
            move_info.TargetPosition = targetPos;
        }
Beispiel #4
0
 static public int set_IsFinish(IntPtr l)
 {
     try {
         GameFramework.AiData_ForMoveCommand self = (GameFramework.AiData_ForMoveCommand)checkSelf(l);
         bool v;
         checkType(l, 2, out v);
         self.IsFinish = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Beispiel #5
0
 static public int set_WayPoints(IntPtr l)
 {
     try {
         GameFramework.AiData_ForMoveCommand self = (GameFramework.AiData_ForMoveCommand)checkSelf(l);
         List <ScriptRuntime.Vector3>        v;
         checkType(l, 2, out v);
         self.WayPoints = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Beispiel #6
0
 static public int constructor(IntPtr l)
 {
     try {
         GameFramework.AiData_ForMoveCommand o;
         System.Collections.Generic.List <ScriptRuntime.Vector3> a1;
         checkType(l, 2, out a1);
         o = new GameFramework.AiData_ForMoveCommand(a1);
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
        internal static void DoMoveCommandState(EntityInfo entity, long deltaTime, AbstractAiStateLogic logic)
        {
            //执行状态处理
            AiData_ForMoveCommand data = GetAiDataForMoveCommand(entity);

            if (null == data)
            {
                return;
            }

            if (!data.IsFinish)
            {
                if (WayPointArrived(entity, data))
                {
                    Vector3 targetPos = new Vector3();
                    MoveToNext(entity, data, ref targetPos);
                    if (!data.IsFinish)
                    {
                        logic.NotifyAiPursue(entity, targetPos);
                    }
                }
                else
                {
                    AiStateInfo info = entity.GetAiStateInfo();
                    info.Time += deltaTime;
                    if (info.Time > 500)
                    {
                        info.Time = 0;
                        Vector3 targetPos = data.WayPoints[data.Index];
                        logic.NotifyAiPursue(entity, targetPos);
                    }
                }
            }

            //判断是否状态结束并执行相应处理
            if (data.IsFinish)
            {
                logic.AiSendStoryMessage(entity, "npc_arrived:" + entity.GetUnitId(), entity.GetId());
                logic.AiSendStoryMessage(entity, "obj_arrived", entity.GetId());
                logic.NotifyAiStopPursue(entity);
                logic.ChangeToState(entity, (int)AiStateId.Idle);
            }
        }
        private static void DoMoveCommandState(EntityInfo npc, long deltaTime)
        {
            //执行状态处理
            AiData_ForMoveCommand data = GetAiDataForMoveCommand(npc);

            if (null == data)
            {
                return;
            }

            if (!data.IsFinish)
            {
                if (WayPointArrived(npc, data))
                {
                    ScriptRuntime.Vector3 targetPos = new ScriptRuntime.Vector3();
                    MoveToNext(npc, data, ref targetPos);
                    if (!data.IsFinish)
                    {
                        AiPursue(npc, targetPos);
                    }
                }
                else
                {
                    ScriptRuntime.Vector3 targetPos = data.WayPoints[data.Index];
                    AiPursue(npc, targetPos);
                }
            }

            //判断是否状态结束并执行相应处理
            if (data.IsFinish)
            {
                Scene scene = npc.SceneContext.CustomData as Scene;
                if (null != scene)
                {
                    scene.StorySystem.SendMessage("npcarrived:" + npc.GetUnitId(), npc.GetId());
                    scene.StorySystem.SendMessage("objarrived", npc.GetId());
                }
                AiStopPursue(npc);
                npc.GetAiStateInfo().ChangeToState((int)PredefinedAiStateId.Idle);
            }
        }
        private static void DoMoveCommandState(EntityInfo npc, long deltaTime)
        {
            //执行状态处理
            AiData_ForMoveCommand data = GetAiDataForMoveCommand(npc);

            if (null == data)
            {
                return;
            }

            if (!data.IsFinish)
            {
                if (WayPointArrived(npc, data))
                {
                    ScriptRuntime.Vector3 targetPos = new ScriptRuntime.Vector3();
                    MoveToNext(npc, data, ref targetPos);
                    if (!data.IsFinish)
                    {
                        AiPursue(npc, targetPos);
                    }
                }
                else
                {
                    ScriptRuntime.Vector3 targetPos = data.WayPoints[data.Index];
                    AiPursue(npc, targetPos);
                }
            }

            //判断是否状态结束并执行相应处理
            if (data.IsFinish)
            {
                if (!string.IsNullOrEmpty(data.Event))
                {
                    GfxStorySystem.Instance.SendMessage(data.Event, npc.GetId(), npc.GetUnitId());
                }
                AiStopPursue(npc);
                npc.GetAiStateInfo().ChangeToState((int)PredefinedAiStateId.Idle);
            }
        }
        private static AiData_ForMoveCommand GetAiDataForMoveCommand(EntityInfo npc)
        {
            AiData_ForMoveCommand data = npc.GetAiStateInfo().AiDatas.GetData <AiData_ForMoveCommand>();

            return(data);
        }
 private static bool WayPointArrived(EntityInfo charObj, AiData_ForMoveCommand data)
 {
     bool ret = false;
     var move_info = charObj.GetMovementStateInfo();
     float powDistDest = move_info.CalcDistancSquareToTarget();
     if (powDistDest <= 1f) {
         ret = true;
     }
     return ret;
 }
        private static void MoveToNext(EntityInfo charObj, AiData_ForMoveCommand data, ref Vector3 targetPos)
        {
            if (++data.Index >= data.WayPoints.Count) {
                data.IsFinish = true;
                return;
            }

            var move_info = charObj.GetMovementStateInfo();
            targetPos = data.WayPoints[data.Index];
            move_info.TargetPosition = targetPos;
        }
 protected override bool ExecCommand(StoryInstance instance, long delta)
 {
     Scene scene = instance.Context as Scene;
     if (null != scene) {
         int unitId = m_UnitId.Value;
         List<object> poses = m_WayPoints.Value;
         EntityInfo entity = scene.SceneContext.GetEntityByUnitId(unitId);
         if (null != entity && null != poses && poses.Count > 0) {
             List<Vector3> waypoints = new List<Vector3>();
             waypoints.Add(entity.GetMovementStateInfo().GetPosition3D());
             for (int i = 0; i < poses.Count; ++i) {
                 Vector3 pt = (Vector3)poses[i];
                 waypoints.Add(pt);
             }
             AiStateInfo aiInfo = entity.GetAiStateInfo();
             AiData_ForMoveCommand data = aiInfo.AiDatas.GetData<AiData_ForMoveCommand>();
             if (null == data) {
                 data = new AiData_ForMoveCommand(waypoints);
                 aiInfo.AiDatas.AddData(data);
             }
             data.WayPoints = waypoints;
             data.Index = 0;
             data.IsFinish = false;
             entity.GetMovementStateInfo().TargetPosition = waypoints[0];
             aiInfo.Time = 1000;//下一帧即触发移动
             aiInfo.ChangeToState((int)AiStateId.MoveCommand);
         }
     }
     return false;
 }
 protected override bool ExecCommand(StoryInstance instance, long delta)
 {
     Scene scene = instance.Context as Scene;
     if (null != scene) {
         int unitId = m_UnitId.Value;
         Vector3 pos = m_Pos.Value;
         EntityInfo entity = scene.SceneContext.GetEntityByUnitId(unitId);
         if (null != entity) {
             List<Vector3> waypoints = new List<Vector3>();
             waypoints.Add(pos);
             AiStateInfo aiInfo = entity.GetAiStateInfo();
             AiData_ForMoveCommand data = aiInfo.AiDatas.GetData<AiData_ForMoveCommand>();
             if (null == data) {
                 data = new AiData_ForMoveCommand(waypoints);
                 aiInfo.AiDatas.AddData(data);
             }
             data.WayPoints = waypoints;
             data.Index = 0;
             data.IsFinish = false;
             entity.GetMovementStateInfo().TargetPosition = pos;
             aiInfo.Time = 1000;//下一帧即触发移动
             aiInfo.ChangeToState((int)AiStateId.MoveCommand);
         }
     }
     return false;
 }
 protected override bool ExecCommand(StoryInstance instance, long delta)
 {
     int objId = m_ObjId.Value;
     Vector3 pos = m_Pos.Value;
     EntityInfo obj = ClientModule.Instance.GetEntityById(objId);
     if (null != obj) {
         List<Vector3> waypoints = new List<Vector3>();
         waypoints.Add(pos);
         AiStateInfo aiInfo = obj.GetAiStateInfo();
         AiData_ForMoveCommand data = aiInfo.AiDatas.GetData<AiData_ForMoveCommand>();
         if (null == data) {
             data = new AiData_ForMoveCommand(waypoints);
             aiInfo.AiDatas.AddData(data);
         }
         data.WayPoints = waypoints;
         data.Index = 0;
         data.IsFinish = false;
         obj.GetMovementStateInfo().TargetPosition = pos;
         aiInfo.Time = 1000;//下一帧即触发移动
         aiInfo.ChangeToState((int)AiStateId.MoveCommand);
     }
     return false;
 }