protected override bool ExecCommand(StoryInstance instance, StoryValueParam <int, float, float> _params, long delta)
        {
            BoxedValue us;

            if (instance.GlobalVariables.TryGetValue("EntityInfo", out us))
            {
                EntityInfo user = us.ObjectVal as EntityInfo;
                if (null != user)
                {
                    int        objId   = _params.Param1Value;
                    float      x       = _params.Param2Value;
                    float      z       = _params.Param3Value;
                    EntityInfo charObj = user.SceneContext.GetEntityById(objId);
                    if (null != charObj)
                    {
                        MovementStateInfo msi = charObj.GetMovementStateInfo();
                        msi.SetPosition2D(x, z);

                        Scene scene = user.SceneContext.CustomData as Scene;
                        if (null != scene)
                        {
                            GameFrameworkMessage.Msg_RC_AdjustPosition adjustPos = new GameFrameworkMessage.Msg_RC_AdjustPosition();
                            adjustPos.role_id  = objId;
                            adjustPos.face_dir = msi.GetFaceDir();
                            adjustPos.x        = x;
                            adjustPos.z        = z;

                            scene.NotifyAllUser(RoomMessageDefine.Msg_RC_AdjustPosition, adjustPos);
                        }
                    }
                }
            }
            return(false);
        }
Exemplo n.º 2
0
    internal static void Execute(object msg, NetConnection conn)
    {
        Msg_RC_AdjustPosition _msg = msg as Msg_RC_AdjustPosition;

        if (null == _msg)
        {
            return;
        }
        EntityInfo npc = PluginFramework.Instance.GetEntityById(_msg.role_id);

        if (null != npc)
        {
            float x       = ProtoHelper.DecodeFloat(_msg.x);
            float z       = ProtoHelper.DecodeFloat(_msg.z);
            float faceDir = ProtoHelper.DecodeFloat(_msg.face_dir);

            MovementStateInfo msi = npc.GetMovementStateInfo();
            msi.SetPosition2D(x, z);
            msi.SetFaceDir(faceDir);

            UnityEngine.GameObject actor = EntityController.Instance.GetGameObject(npc.GetId());
            GameFramework.Skill.Trigers.TriggerUtil.MoveObjTo(actor, new UnityEngine.Vector3(x, 0, z));
            actor.transform.localRotation = UnityEngine.Quaternion.Euler(0, Utility.RadianToDegree(faceDir), 0);
        }
    }
Exemplo n.º 3
0
    internal static void Execute(object msg, NetConnection conn)
    {
        Msg_RC_NpcSkill targetmsg = msg as Msg_RC_NpcSkill;

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

        if (null == npc)
        {
            return;
        }
        float x = 0.0f;
        float z = 0.0f;

        ProtoHelper.DecodePosition2D(targetmsg.stand_pos, out x, out z);
        float faceDir = ProtoHelper.DecodeFloat(targetmsg.face_direction);
        int   skillId = targetmsg.skill_id;

        LogSystem.Info("Receive Msg_RC_NpcSkill, EntityId={0}, SkillId={1}", targetmsg.npc_id, skillId);

        MovementStateInfo msi = npc.GetMovementStateInfo();

        if (targetmsg.target_id <= 0)
        {
            msi.SetPosition2D(x, z);
            msi.SetFaceDir(faceDir);
            npc.GetAiStateInfo().Target  = 0;
            UnityEngine.GameObject actor = EntityController.Instance.GetGameObject(npc.GetId());
            GameFramework.Skill.Trigers.TriggerUtil.MoveObjTo(actor, new UnityEngine.Vector3(x, actor.transform.position.y, z));
            actor.transform.localRotation = UnityEngine.Quaternion.Euler(0, Utility.RadianToDegree(faceDir), 0);
        }
        else
        {
            npc.GetAiStateInfo().Target = targetmsg.target_id;
        }

        SkillInfo skillInfo = npc.GetSkillStateInfo().GetSkillInfoById(skillId);

        if (null != skillInfo)
        {
            if (skillInfo.ConfigData.skillData.canmove == 0)
            {
                EntityViewModel viewModel = EntityViewModelManager.Instance.GetEntityViewById(targetmsg.npc_id);
                if (null != viewModel)
                {
                    viewModel.StopMove();
                }
            }
            if (GfxSkillSystem.Instance.StartSkill(npc.GetId(), skillInfo.ConfigData, 0))
            {
                Utility.EventSystem.Publish("ui_skill_cooldown", "ui", npc.GetId(), skillId, skillInfo.ConfigData.skillData.cooldown / 1000.0f);
            }
        }
    }
        internal void SyncPlayerMoveToPos(ScriptRuntime.Vector3 target_pos)
        {
            EntityInfo userInfo = ClientModule.Instance.GetEntityById(ClientModule.Instance.LeaderID);

            if (null != userInfo)
            {
                MovementStateInfo msi = userInfo.GetMovementStateInfo();

                Msg_CR_UserMoveToPos builder = new Msg_CR_UserMoveToPos();
                builder.target_pos = ProtoHelper.EncodePosition2D(target_pos.X, target_pos.Z);
                SendMessage(RoomMessageDefine.Msg_CR_UserMoveToPos, builder);
            }
        }
        internal void SyncPlayerMoveToPos(ScriptRuntime.Vector3 target_pos)
        {
            EntityInfo userInfo = PluginFramework.Instance.GetEntityById(PluginFramework.Instance.RoomObjId);

            if (null != userInfo)
            {
                MovementStateInfo msi = userInfo.GetMovementStateInfo();

                Msg_CR_UserMoveToPos builder = new Msg_CR_UserMoveToPos();
                builder.target_pos = ToPosition(target_pos.X, target_pos.Z);
                SendMessage(RoomMessageDefine.Msg_CR_UserMoveToPos, builder);
            }
        }
        internal void SyncPlayerStopMove()
        {
            EntityInfo userInfo = PluginFramework.Instance.GetEntityById(PluginFramework.Instance.RoomObjId);

            if (null != userInfo)
            {
                MovementStateInfo msi = userInfo.GetMovementStateInfo();

                Msg_CR_UserMoveToPos builder = new Msg_CR_UserMoveToPos();
                builder.target_pos = ToPosition(msi.PositionX, msi.PositionZ);
                builder.is_stop    = true;
                SendMessage(RoomMessageDefine.Msg_CR_UserMoveToPos, builder);
            }
        }
        internal void SyncPlayerStopMove()
        {
            EntityInfo userInfo = ClientModule.Instance.GetEntityById(ClientModule.Instance.LeaderID);

            if (null != userInfo)
            {
                MovementStateInfo msi = userInfo.GetMovementStateInfo();

                Msg_CR_UserMoveToPos builder = new Msg_CR_UserMoveToPos();
                builder.target_pos = ProtoHelper.EncodePosition2D(msi.PositionX, msi.PositionZ);
                builder.is_stop    = true;
                SendMessage(RoomMessageDefine.Msg_CR_UserMoveToPos, builder);
            }
        }
Exemplo n.º 8
0
        internal void SyncGfxMoveControlStart(CharacterInfo obj, int id, bool isSkill)
        {
            MovementStateInfo           msi = obj.GetMovementStateInfo();
            Msg_CRC_GfxControlMoveStart msg = new Msg_CRC_GfxControlMoveStart();

            msg.obj_id             = obj.GetId();
            msg.skill_or_impact_id = id;
            msg.is_skill           = isSkill;
            msg.cur_pos            = new ArkCrossEngineMessage.Position();
            msg.cur_pos.x          = msi.PositionX;
            msg.cur_pos.z          = msi.PositionZ;
            msg.send_time          = TimeUtility.GetServerMilliseconds();

            SendMessage(msg);
        }
Exemplo n.º 9
0
        internal void SyncPlayerMoveStop()
        {
            UserInfo userInfo = WorldSystem.Instance.GetPlayerSelf();

            if (null != userInfo)
            {
                MovementStateInfo msi = userInfo.GetMovementStateInfo();
                ArkCrossEngineMessage.Msg_CRC_MoveStop builder = new ArkCrossEngineMessage.Msg_CRC_MoveStop();
                builder.send_time = TimeUtility.GetServerMilliseconds();
                Position pos = new Position();
                pos.x            = msi.PositionX;
                pos.z            = msi.PositionZ;
                builder.position = pos;
                SendMessage(builder);
            }
        }
Exemplo n.º 10
0
        internal void SyncPlayerMoveToAttack(int targetId, float attackRange)
        {
            WorldSystem.Instance.IsAlreadyNotifyMeetObstacle = false;

            UserInfo userInfo = WorldSystem.Instance.GetPlayerSelf();

            if (null != userInfo)
            {
                MovementStateInfo       msi     = userInfo.GetMovementStateInfo();
                Msg_CR_UserMoveToAttack builder = new Msg_CR_UserMoveToAttack();
                builder.target_id    = targetId;
                builder.attack_range = attackRange;
                builder.cur_pos_x    = msi.PositionX;
                builder.cur_pos_z    = msi.PositionZ;
                SendMessage(builder);
            }
        }
Exemplo n.º 11
0
        internal void SyncPlayerMoveToPos(Vector3 target_pos)
        {
            WorldSystem.Instance.IsAlreadyNotifyMeetObstacle = false;

            UserInfo userInfo = WorldSystem.Instance.GetPlayerSelf();

            if (null != userInfo)
            {
                MovementStateInfo    msi     = userInfo.GetMovementStateInfo();
                Msg_CR_UserMoveToPos builder = new Msg_CR_UserMoveToPos();
                builder.target_pos_x = target_pos.X;
                builder.target_pos_z = target_pos.Z;
                builder.cur_pos_x    = msi.PositionX;
                builder.cur_pos_z    = msi.PositionZ;
                SendMessage(builder);
            }
        }
Exemplo n.º 12
0
        protected override bool ExecCommand(StoryInstance instance, long delta)
        {
            Scene scene = instance.Context as Scene;

            if (null != scene)
            {
                if (0 == m_ParamNum)
                {
                    for (LinkedListNode <UserInfo> linkNode = scene.UserManager.Users.FirstValue; null != linkNode; linkNode = linkNode.Next)
                    {
                        UserInfo info = linkNode.Value;
                        User     user = info.CustomData as User;

                        if (null != info && null != user)
                        {
                            MovementStateInfo msi = info.GetMovementStateInfo();

                            LogSystem.Info("CameraFollowImmediately:{0}", info.GetId());

                            ArkCrossEngineMessage.Msg_RC_CameraFollow msg = new ArkCrossEngineMessage.Msg_RC_CameraFollow();
                            msg.obj_id         = info.GetId();
                            msg.is_immediately = true;

                            user.SendMessage(msg);
                        }
                    }
                }
                else
                {
                    int     unitId = m_UnitId.Value;
                    NpcInfo npc    = scene.SceneContext.GetCharacterInfoByUnitId(unitId) as NpcInfo;
                    if (null != npc)
                    {
                        LogSystem.Info("CameraFollowImmediately:{0}", npc.GetId());

                        ArkCrossEngineMessage.Msg_RC_CameraFollow msg = new ArkCrossEngineMessage.Msg_RC_CameraFollow();
                        msg.obj_id         = npc.GetId();
                        msg.is_immediately = true;
                        scene.NotifyAllUser(msg);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 13
0
        internal void SyncPlayerMoveStart(float dir)
        {
            WorldSystem.Instance.IsAlreadyNotifyMeetObstacle = false;

            UserInfo userInfo = WorldSystem.Instance.GetPlayerSelf();

            if (null != userInfo)
            {
                MovementStateInfo msi = userInfo.GetMovementStateInfo();
                ArkCrossEngineMessage.Msg_CRC_MoveStart builder = new ArkCrossEngineMessage.Msg_CRC_MoveStart();
                builder.send_time = TimeUtility.GetServerMilliseconds();
                builder.dir       = dir;
                Position pos = new Position();
                pos.x                   = msi.PositionX;
                pos.z                   = msi.PositionZ;
                builder.position        = pos;
                builder.is_skill_moving = msi.IsSkillMoving;
                SendMessage(builder);
            }
        }
Exemplo n.º 14
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);
            }
        }
    }
Exemplo n.º 15
0
        internal void SyncPlayerStopSkill(CharacterInfo entity, int skillId)
        {
            if (entity.IsHaveStateFlag(CharacterState_Type.CST_Sleep))
            {
                return;
            }
            //LogSystem.Debug("SyncStopSkill {0}, entity {1}", skillId, entity.GetId());
            int id = entity.GetId();
            MovementStateInfo msi = entity.GetMovementStateInfo();

            if (id == WorldSystem.Instance.PlayerSelfId)
            {
                ArkCrossEngineMessage.Msg_CRC_StopSkill msg = new ArkCrossEngineMessage.Msg_CRC_StopSkill();
                msg.skill_id = skillId;
                SendMessage(msg);
            }
            else if (entity.OwnerId == WorldSystem.Instance.PlayerSelfId)
            {
                ArkCrossEngineMessage.Msg_CRC_NpcStopSkill msg = new ArkCrossEngineMessage.Msg_CRC_NpcStopSkill();
                msg.npc_id   = entity.GetId();
                msg.skill_id = skillId;
                SendMessage(msg);
            }
        }
Exemplo n.º 16
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);
                }
            }
        }
    }
Exemplo n.º 17
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                var chunkVelocities            = chunk.GetNativeArray(VelocityType);
                var chunkTranslations          = chunk.GetNativeArray(TranslationType);
                var chunkRotations             = chunk.GetNativeArray(RotationType);
                var chunkMovementData          = chunk.GetNativeArray(MovementType);
                var chunkEnemyData             = chunk.GetNativeArray(EnemyStateType);
                int index                      = chunk.GetSharedComponentIndex(MovementStateInfoType);
                MovementStateInfo movementInfo = MovementInfo[index / 2];
                quaternion        rot90        = quaternion.Euler(0, math.PI / 2, 0);

                for (int i = 0; i < chunk.Count; i++)
                {
                    var enemyState = chunkEnemyData[i];
                    if (enemyState.CurrAIState != EnemyAIState.Dead)
                    {
                        var    movementState = chunkMovementData[i];
                        var    translation   = chunkTranslations[i];
                        var    velocity      = chunkVelocities[i];
                        var    rotation      = chunkRotations[i];
                        float3 toTarget      = movementState.Target - translation.Value;
                        float3 toPlayer      = enemyState.PlayerPosition - translation.Value;
                        toPlayer.y = 0;
                        toTarget.y = 0;
                        float3 fromTargetToPlayer = movementState.Target - enemyState.PlayerPosition;
                        fromTargetToPlayer.y = 0;
                        if (enemyState.LookAtPlayer)
                        {
                            //rotation = new Rotation()
                            //{
                            //    Value = quaternion.identity
                            //};
                            rotation = new Rotation()
                            {
                                Value = quaternion.LookRotationSafe(toPlayer, new float3(0, 1, 0))
                            };
                        }

                        if (enemyState.CurrAIState != EnemyAIState.Idle)
                        {
                            float maxDist = enemyState.DesiredDistance + enemyState.DesiredDistanceLeeway;
                            float minDist = enemyState.DesiredDistance - enemyState.DesiredDistanceLeeway;
                            float currDistFromTargetToPlayer = math.lengthsq(fromTargetToPlayer);
                            if (currDistFromTargetToPlayer > maxDist * maxDist || currDistFromTargetToPlayer < minDist * minDist)
                            {
                                SetNewTarget(ref movementState, ref enemyState, ref translation, out toTarget, out fromTargetToPlayer, ref Random);
                            }
                            float3 fTTPNorm = math.normalizesafe(fromTargetToPlayer);
                            float3 tPNorm   = math.normalizesafe(toPlayer);
                            float3 tTNorm   = math.normalizesafe(toTarget);
                            //chunkTranslations[i] = new Translation()
                            //{
                            //    Value = translation.Value + tTNorm * movementInfo.Speed * DeltaTime
                            //};

                            if (math.dot(fTTPNorm, tPNorm) > 0)
                            {
                                velocity.Linear = tTNorm * movementInfo.Speed;// * math.min(1, math.length(toTarget));
                            }
                            else
                            {
                                bool tooFar   = math.lengthsq(toPlayer) > maxDist * maxDist;
                                bool tooClose = math.lengthsq(toPlayer) < minDist * minDist;
                                if (tooFar || tooClose)
                                {
                                    velocity.Linear = math.normalizesafe(toPlayer * math.select(1, -1, tooClose)) * movementInfo.Speed;
                                }
                                else
                                {
                                    velocity.Linear = math.normalizesafe(math.mul(rot90, tPNorm *
                                                                                  math.select(-1, 1,
                                                                                              math.dot(math.mul(rot90, -tPNorm), fTTPNorm) < math.dot(math.mul(rot90, tPNorm), fTTPNorm))))
                                                      * movementInfo.Speed;
                                }
                            }
                        }
                        velocity.Linear.y    = -1;
                        chunkMovementData[i] = movementState;
                        chunkEnemyData[i]    = enemyState;
                        chunkVelocities[i]   = velocity;
                        chunkRotations[i]    = rotation;
                    }
                    //chunkVelocities[i].Linear =
                    //    chunkTranslations[i] = new Translation()
                    //    {
                    //        Value = chunkTranslations[i].Value + math.mul(chunkRotations[i].Value, new float3(0, 0, DeltaTime * MovementInfo[chunkIndex + 1].Speed))
                    //    };
                }
            }
Exemplo n.º 18
0
        protected override bool ExecCommand(StoryInstance instance, long delta)
        {
            Scene scene = instance.Context as Scene;

            if (null != scene)
            {
                if (m_ParamNum >= 3)
                {
                    float x = m_X.Value;
                    float y = m_Y.Value;
                    float z = m_Z.Value;

                    LogSystem.Info("CameraLookat:{0} {1} {2}", x, y, z);

                    ArkCrossEngineMessage.Msg_RC_CameraLookat msg = new ArkCrossEngineMessage.Msg_RC_CameraLookat();
                    msg.x = x;
                    msg.y = y;
                    msg.z = z;
                    msg.is_immediately = false;
                    scene.NotifyAllUser(msg);
                }
                else if (m_ParamNum >= 1)
                {
                    int     unitId = m_UnitId.Value;
                    NpcInfo npc    = scene.SceneContext.GetCharacterInfoByUnitId(unitId) as NpcInfo;
                    if (null != npc)
                    {
                        MovementStateInfo msi = npc.GetMovementStateInfo();

                        LogSystem.Info("CameraLookat:{0}({1} {2} {3})", unitId, msi.PositionX, msi.PositionY, msi.PositionZ);

                        ArkCrossEngineMessage.Msg_RC_CameraLookat msg = new ArkCrossEngineMessage.Msg_RC_CameraLookat();
                        msg.x = msi.PositionX;
                        msg.y = msi.PositionY;
                        msg.z = msi.PositionZ;
                        msg.is_immediately = false;
                        scene.NotifyAllUser(msg);
                    }
                }
                else
                {
                    for (LinkedListNode <UserInfo> linkNode = scene.UserManager.Users.FirstValue; null != linkNode; linkNode = linkNode.Next)
                    {
                        UserInfo info = linkNode.Value;
                        User     user = info.CustomData as User;

                        if (null != info && null != user)
                        {
                            MovementStateInfo msi = info.GetMovementStateInfo();

                            LogSystem.Info("CameraLookat:{0}({1} {2} {3})", info.GetId(), msi.PositionX, msi.PositionY, msi.PositionZ);

                            ArkCrossEngineMessage.Msg_RC_CameraLookat msg = new ArkCrossEngineMessage.Msg_RC_CameraLookat();
                            msg.x = msi.PositionX;
                            msg.y = msi.PositionY;
                            msg.z = msi.PositionZ;
                            msg.is_immediately = false;

                            user.SendMessage(msg);
                        }
                    }
                }
            }
            return(false);
        }