Ejemplo n.º 1
0
        internal static Msg_RC_NpcMove BuildNpcMoveMessage(NpcInfo npc)
        {
            Msg_RC_NpcMove npcMoveBuilder = new Msg_RC_NpcMove();

            if (npc.GetMovementStateInfo().IsMoving)
            {
                npcMoveBuilder.npc_id         = npc.GetId();
                npcMoveBuilder.is_moving      = true;
                npcMoveBuilder.move_direction = (float)npc.GetMovementStateInfo().GetMoveDir();
                npcMoveBuilder.face_direction = (float)npc.GetMovementStateInfo().GetFaceDir();
                npcMoveBuilder.cur_pos_x      = npc.GetMovementStateInfo().GetPosition3D().X;
                npcMoveBuilder.cur_pos_z      = npc.GetMovementStateInfo().GetPosition3D().Z;
                NpcAiStateInfo data = npc.GetAiStateInfo();
                npcMoveBuilder.target_pos_x         = npc.GetMovementStateInfo().TargetPosition.X;
                npcMoveBuilder.target_pos_z         = npc.GetMovementStateInfo().TargetPosition.Z;
                npcMoveBuilder.velocity_coefficient = (float)npc.VelocityCoefficient;
                npcMoveBuilder.velocity             = npc.GetActualProperty().MoveSpeed;
                npcMoveBuilder.move_mode            = (int)npc.GetMovementStateInfo().MovementMode;
            }
            else
            {
                npcMoveBuilder.npc_id    = npc.GetId();
                npcMoveBuilder.is_moving = false;
                npcMoveBuilder.cur_pos_x = npc.GetMovementStateInfo().GetPosition3D().X;
                npcMoveBuilder.cur_pos_z = npc.GetMovementStateInfo().GetPosition3D().Z;
            }
            return(npcMoveBuilder);
        }
Ejemplo n.º 2
0
    internal static void Execute(object msg, NetConnection conn, NetworkSystem networkSystem)
    {
        Msg_RC_NpcMove targetmsg = msg as Msg_RC_NpcMove;

        if (null == targetmsg)
        {
            return;
        }
    }
Ejemplo n.º 3
0
        private void OnNpcMove(NpcInfo npc)
        {
            Scene scene = npc.SceneContext.CustomData as Scene;

            if (null != scene && !npc.GetMovementStateInfo().IsSkillMoving)
            {
                Msg_RC_NpcMove npcMoveBuilder = DataSyncUtility.BuildNpcMoveMessage(npc);
                if (null != npcMoveBuilder)
                {
                    scene.NotifyAreaUser(npc, npcMoveBuilder);
                }
            }
        }
Ejemplo n.º 4
0
        internal static void SyncNpcAiStateToUser(NpcInfo npc, User user)
        {
            Msg_RC_NpcMove   npcMoveBuilder       = BuildNpcMoveMessage(npc);
            Msg_RC_NpcTarget npcFaceTargetBuilder = BuildNpcTargetMessage(npc);

            if (null != npcMoveBuilder)
            {
                user.SendMessage(npcMoveBuilder);
            }
            if (null != npcFaceTargetBuilder)
            {
                user.SendMessage(npcFaceTargetBuilder);
            }
        }
        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);
                }
            }
        }
Ejemplo n.º 6
0
        private void NpcEnterCampSight(NpcInfo npc, int campid)
        {
            Msg_RC_NpcEnter bder = DataSyncUtility.BuildNpcEnterMessage(npc);

            NotifyCampUsers(campid, bder);
            Msg_RC_SyncProperty propBuilder = DataSyncUtility.BuildSyncPropertyMessage(npc);

            NotifyCampUsers(campid, propBuilder);
            Msg_RC_NpcMove npcMoveBuilder = DataSyncUtility.BuildNpcMoveMessage(npc);

            NotifyCampUsers(campid, npcMoveBuilder);
            Msg_RC_NpcTarget npcFaceTargetBuilder = DataSyncUtility.BuildNpcTargetMessage(npc);

            if (npcFaceTargetBuilder != null)
            {
                NotifyCampUsers(campid, npcFaceTargetBuilder);
            }
        }
Ejemplo n.º 7
0
        internal static void SyncNpcAiStateToCaredUsers(NpcInfo npc)
        {
            Scene scene = npc.SceneContext.CustomData as Scene;

            if (null != scene)
            {
                Msg_RC_NpcMove   npcMoveBuilder       = BuildNpcMoveMessage(npc);
                Msg_RC_NpcTarget npcFaceTargetBuilder = BuildNpcTargetMessage(npc);

                if (null != npcMoveBuilder)
                {
                    scene.NotifyAreaUser(npc, npcMoveBuilder, false);
                }
                if (null != npcFaceTargetBuilder)
                {
                    scene.NotifyAreaUser(npc, npcFaceTargetBuilder, false);
                }
            }
        }
        public static Msg_RC_NpcMove BuildNpcMoveMessage(EntityInfo npc)
        {
            ScriptRuntime.Vector3 srcPos         = npc.GetMovementStateInfo().GetPosition3D();
            Msg_RC_NpcMove        npcMoveBuilder = new Msg_RC_NpcMove();

            if (npc.GetMovementStateInfo().IsMoving)
            {
                npcMoveBuilder.npc_id   = npc.GetId();
                npcMoveBuilder.velocity = npc.ActualProperty.GetFloat(CharacterPropertyEnum.x2011_最终速度);
                ScriptRuntime.Vector3 targetPos = npc.GetMovementStateInfo().TargetPosition;
                npcMoveBuilder.target_pos = ToPosition(targetPos.X, targetPos.Z);
                npcMoveBuilder.cur_pos    = ToPosition(srcPos.X, srcPos.Z);
            }
            else
            {
                npcMoveBuilder.npc_id  = npc.GetId();
                npcMoveBuilder.cur_pos = ToPosition(srcPos.X, srcPos.Z);
            }
            return(npcMoveBuilder);
        }
Ejemplo n.º 9
0
        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);
                    }
                }
            }
        }
Ejemplo n.º 10
0
        internal static Msg_RC_NpcMove BuildNpcMoveMessage(EntityInfo npc)
        {
            ScriptRuntime.Vector3 srcPos         = npc.GetMovementStateInfo().GetPosition3D();
            Msg_RC_NpcMove        npcMoveBuilder = new Msg_RC_NpcMove();

            if (npc.GetMovementStateInfo().IsMoving)
            {
                npcMoveBuilder.npc_id   = npc.GetId();
                npcMoveBuilder.velocity = ProtoHelper.EncodeFloat(npc.GetActualProperty().MoveSpeed);
                ScriptRuntime.Vector3 targetPos = npc.GetMovementStateInfo().TargetPosition;
                npcMoveBuilder.target_pos = ProtoHelper.EncodePosition2D(targetPos.X, targetPos.Z);
                npcMoveBuilder.cur_pos    = ProtoHelper.EncodePosition2D(srcPos.X, srcPos.Z);
            }
            else
            {
                npcMoveBuilder.npc_id  = npc.GetId();
                npcMoveBuilder.cur_pos = ProtoHelper.EncodePosition2D(srcPos.X, srcPos.Z);
            }
            return(npcMoveBuilder);
        }
Ejemplo n.º 11
0
    public static void AiPursue(EntityInfo npc, ScriptRuntime.Vector3 target)
    {
        MovementStateInfo msi = npc.GetMovementStateInfo();

        msi.IsMoving       = true;
        msi.TargetPosition = target;
        float dir = Geometry.GetYRadian(msi.GetPosition3D(), target);

        msi.SetFaceDir(dir);

        Msg_RC_NpcMove npcMoveBuilder = DataSyncUtility.BuildNpcMoveMessage(npc);

        if (null != npcMoveBuilder)
        {
            Scene scene = npc.SceneContext.CustomData as Scene;
            if (null != scene)
            {
                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);
                    }
                }
            }
        }
Ejemplo n.º 13
0
        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);
                    }
                }
            }
        }
Ejemplo n.º 14
0
    internal static void Execute(object msg, NetConnection conn)
    {
        Msg_RC_NpcMove targetmsg = msg as Msg_RC_NpcMove;

        if (null == targetmsg)
        {
            return;
        }
        EntityInfo npc = PluginFramework.Instance.GetEntityById(targetmsg.npc_id);

        if (null == npc)
        {
            return;
        }
        if (targetmsg.velocity > 0)
        {
            float x, y;
            float tx, ty;
            ProtoHelper.DecodePosition2D(targetmsg.cur_pos, out x, out y);
            ProtoHelper.DecodePosition2D(targetmsg.target_pos, out tx, out ty);
            Vector2 curPos    = new Vector2(x, y);
            Vector2 targetPos = new Vector2(tx, ty);

            MovementStateInfo msi      = npc.GetMovementStateInfo();
            float             velocity = ProtoHelper.DecodeFloat(targetmsg.velocity);
            npc.ActualProperty.SetFloat(CharacterPropertyEnum.x2011_最终速度, velocity);
            if (Geometry.DistanceSquare(msi.GetPosition2D(), curPos) > c_MaxPosDeltaSqr)
            {
                msi.SetPosition2D(curPos);
                UnityEngine.GameObject actor = EntityController.Instance.GetGameObject(npc.GetId());
                GameFramework.Skill.Trigers.TriggerUtil.MoveObjTo(actor, new UnityEngine.Vector3(x, actor.transform.position.y, y));
            }

            EntityViewModel viewModel = EntityViewModelManager.Instance.GetEntityViewById(targetmsg.npc_id);
            if (null != viewModel)
            {
                viewModel.MoveTo(targetPos.X, 0, targetPos.Y);
            }
        }
        else
        {
            float x, y;
            ProtoHelper.DecodePosition2D(targetmsg.cur_pos, out x, out y);
            Vector2           curPos = new Vector2(x, y);
            MovementStateInfo msi    = npc.GetMovementStateInfo();
            if (Geometry.DistanceSquare(msi.GetPosition2D(), curPos) > c_MaxPosDeltaSqr)
            {
                msi.SetPosition2D(curPos);
                UnityEngine.GameObject actor = EntityController.Instance.GetGameObject(npc.GetId());
                GameFramework.Skill.Trigers.TriggerUtil.MoveObjTo(actor, new UnityEngine.Vector3(x, actor.transform.position.y, y));
            }
            else
            {
                EntityViewModel viewModel = EntityViewModelManager.Instance.GetEntityViewById(targetmsg.npc_id);
                if (null != viewModel)
                {
                    viewModel.MoveTo(curPos.X, 0, curPos.Y);
                }
            }
        }
    }