Esempio n. 1
0
        private static void MoveToNext(NpcInfo npc, AiData_ForMoveCommand data)
        {
            if (++data.Index >= data.WayPoints.Count)
            {
                data.IsFinish = true;
                return;
            }

            var     move_info = npc.GetMovementStateInfo();
            Vector3 from      = move_info.GetPosition3D();
            Vector3 to        = data.WayPoints[data.Index];
            float   move_dir  = MoveDirection(from, to);

            float now      = TimeUtility.GetServerMilliseconds();
            float distance = Geometry.Distance(from, to);
            float speed    = npc.GetActualProperty().MoveSpeed;

            data.EstimateFinishTime = now + 1000 * (distance / speed);
            DLog._("ai_move", "[{0}]: now({1}), from({2}), to({3}), distance({4}), speed({5}), move_time({6}), estimate({7})",
                   npc.GetId(), now, from.ToString(), to.ToString(), distance, speed, 1000 * (distance / speed), data.EstimateFinishTime);

            move_info.IsMoving = true;
            move_info.SetMoveDir(move_dir);
            move_info.SetFaceDir(move_dir);
        }
Esempio n. 2
0
        public static void DoMoveCommandState(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            //执行状态处理
            AiData_ForMoveCommand data = GetAiDataForMoveCommand(npc);

            if (null == data)
            {
                return;
            }

            if (!data.IsFinish)
            {
                if (WayPointArrived(npc, data))
                {
                    MoveToNext(npc, data);
                }
            }

            //判断是否状态结束并执行相应处理
            if (null != data && data.IsFinish)
            {
                npc.GetMovementStateInfo().IsMoving = false;
                npc.GetAiStateInfo().PopState();
            }
        }
Esempio n. 3
0
 private static bool WayPointArrived(NpcInfo npc, AiData_ForMoveCommand data)
 {
     if (TimeUtility.GetServerMilliseconds() >= data.EstimateFinishTime)
     {
         var     move_info = npc.GetMovementStateInfo();
         Vector3 to        = data.WayPoints[data.Index];
         Vector3 now       = move_info.GetPosition3D();
         float   distance  = Geometry.Distance(now, to);
         DLog._("ai_move", "[{0}]: closest distance({1}) ", npc.GetId(), distance);
         return(true);
     }
     return(false);
 }
Esempio n. 4
0
        private static AiData_ForMoveCommand GetAiDataForMoveCommand(NpcInfo npc)
        {
            AiData_ForMoveCommand data = npc.GetAiStateInfo().AiDatas.GetData <AiData_ForMoveCommand>();

            return(data);
        }