Exemplo n.º 1
0
        public static Packet ConvertToPacket(this byte[] buffer, SocketReceivedResult socketReceiveResult)
        {
            Packet receivedPacket = null;
            var    eventType      = buffer.GetSocketEventType();

            switch (eventType)
            {
            case PacketTypeEnum.Connection:
                receivedPacket = new ConnectionPacket();
                break;

            case PacketTypeEnum.Ping:
                receivedPacket = new PingPacket();
                break;

            case PacketTypeEnum.Disconnect:
                receivedPacket = new DisconnectPacket();
                break;

            case PacketTypeEnum.Movement:
                receivedPacket = new MovementPacket();
                break;

            default:
                Log.Error("Unknown packet type, cannot handle them");
                break;
            }

            receivedPacket.Deserialize(buffer);
            receivedPacket.SetHeader(eventType, socketReceiveResult.RemoteEndPoint);

            return(receivedPacket);
        }
Exemplo n.º 2
0
        public virtual void SetLocationOnSmooth(Point3D newLocation)
        {
            Point3D oldLocation = Location;
            int     rx          = newLocation.X - oldLocation.X;
            int     ry          = newLocation.Y - oldLocation.Y;
            int     rz          = newLocation.Z - oldLocation.Z;

            NoMoveHS = true;
            _containedObjects.ForEachObject(
                item => item.NoMoveHS = true,
                mob => mob.NoMoveHS   = true);

            Location = newLocation;

            _containedObjects.ForEachMobile(
                mob =>
            {
                NotifyLocationChangeOnSmooth(mob, new Point3D(mob.Location.X - rx, mob.Location.Y - ry, mob.Location.Z - rz));
            });

            NoMoveHS = false;
            _containedObjects.ForEachObject(
                item => item.NoMoveHS = false,
                mob => mob.NoMoveHS   = false);

            IPooledEnumerable eable = Map.GetClientsInRange(Location, GetMaxUpdateRange());

            foreach (NetState state in eable)
            {
                Mobile m = state.Mobile;

                if (!m.CanSee(this))
                {
                    continue;
                }

                if (m.InRange(Location, GetUpdateRange(m)))
                {
                    state.Send(GetMovementPacketFor(state));

                    if (!m.InRange(oldLocation, GetUpdateRange(m)))
                    {
                        SendInfoTo(state);
                    }
                }

                if (Utility.InUpdateRange(Location, m.Location) && !Utility.InUpdateRange(oldLocation, m.Location))
                {
                    SendInfoTo(state);
                }
            }

            eable.Free();

            if (MovementPacket != null)
            {
                MovementPacket.Release();
                MovementPacket = null;
            }
        }
Exemplo n.º 3
0
    private void OnMove(SocketIOEvent obj)
    {
        MovementPacket packet = JsonUtility.FromJson <MovementPacket>(obj.data);

        string id = packet.id;

        if (!players.ContainsKey(id))
        {
            return;
        }

        if (players[id].isDead)
        {
            return;
        }

        Vector3    position = new Vector3(packet.x, packet.y, packet.z);
        Quaternion rotation = new Quaternion(packet.rx, packet.ry, packet.rz, packet.rw);

        if (!players.ContainsKey(id))
        {
            return;
        }

        players[id].transform.position = position;
        players[id].transform.rotation = rotation;
        AI ai = players[id].GetComponent <AI>();

        if (ai == null)
        {
            players[id].anim.SetFloat("InputHorizontal", packet.horizontal);
            players[id].anim.SetFloat("InputVertical", packet.vertical);
            players[id].anim.SetFloat("InputMagnitude", packet.inputMagnitude);
            players[id].anim.SetFloat("MoveSet_ID", packet.moveSetID);
            players[id].anim.SetBool("IsGrounded", packet.isGrounded);
            players[id].anim.SetBool("IsCrouching", packet.isCrouching);
            players[id].anim.SetBool("IsStrafing", packet.isStrafing);
            players[id].anim.SetFloat("VerticalVelocity", packet.verticalVelocity);

            if (packet.horizontal != 0.0f || packet.vertical != 0.0f)
            {
                if (players[id].GetComponent <vThirdPersonController>().isGrounded)
                {
                    players[id].PlaySound(Player.AudioType.Movement);
                }
            }
        }
        else
        {
            if (packet.horizontal != 0.0f || packet.vertical != 0.0f)
            {
                players[id].anim.SetTrigger("isWalking");
            }
            else
            {
                players[id].anim.ResetTrigger("isWalking");
            }
        }
    }
Exemplo n.º 4
0
        public void SendMoveLeft(Vector3 o, Quaternion i)
        {
            var Orientation = -(ConvertToRadians(i.eulerAngles.y)) - 4.6f;

            var startMoving = new MovementPacket(WorldCommand.MSG_MOVE_START_TURN_LEFT)
            {
                GUID   = Exchange.gameClient.Player.GUID,
                flags  = (MovementFlags)Flags.MoveFlags,
                flags2 = (MovementFlags2)Flags.MoveFlags2,
                X      = o.x,
                Y      = o.z,
                Z      = o.y,
                O      = Orientation
            };

            Exchange.gameClient.SendPacket(startMoving);

            Flags.Clear();
            Flags.Clear2();
        }
Exemplo n.º 5
0
        public void MoveForward(Vector3 o, UnityEngine.Quaternion h)
        {
            var Orientation = -(ConvertToRadians(h.eulerAngles.y)) - 4.6f;

            var startMoving = new MovementPacket(WorldCommand.MSG_MOVE_START_FORWARD)
            {
                GUID   = Exchange.gameClient.Player.GUID,
                flags  = (MovementFlags)Flags.MoveFlags,
                flags2 = (MovementFlags2)Flags.MoveFlags2,
                X      = o.x,
                Y      = o.z,
                Z      = o.y,
                O      = Orientation
            };

            Exchange.gameClient.SendPacket(startMoving);

            Flags.Clear();
            Flags.Clear2();
        }
Exemplo n.º 6
0
        public void SendFallLand(Vector3 o, Quaternion i, uint time)
        {
            var Orientation = -(ConvertToRadians(i.eulerAngles.y)) - 4.6f;

            var startMoving = new MovementPacket(WorldCommand.MSG_MOVE_FALL_LAND)
            {
                GUID     = Exchange.gameClient.Player.GUID,
                flags    = (MovementFlags)Flags.MoveFlags,
                flags2   = (MovementFlags2)Flags.MoveFlags2,
                fallTime = time,
                X        = o.x,
                Y        = o.z,
                Z        = o.y,
                O        = Orientation
            };

            Exchange.gameClient.SendPacket(startMoving);

            Flags.Clear();
            Flags.Clear2();
        }
Exemplo n.º 7
0
    public void Move(Transform p, float horizontal, float vertical, bool isGrounded, bool isCrouching, bool isStrafing, float inputMagnitude, float moveSetID, float verticalVelocity)
    {
        MovementPacket packet = new MovementPacket();

        packet.x                = p.position.x;
        packet.y                = p.position.y;
        packet.z                = p.position.z;
        packet.rx               = p.rotation.x;
        packet.ry               = p.rotation.y;
        packet.rz               = p.rotation.z;
        packet.rw               = p.rotation.w;
        packet.horizontal       = horizontal;
        packet.vertical         = vertical;
        packet.isGrounded       = isGrounded;
        packet.isCrouching      = isCrouching;
        packet.isStrafing       = isStrafing;
        packet.inputMagnitude   = inputMagnitude;
        packet.moveSetID        = moveSetID;
        packet.verticalVelocity = verticalVelocity;

        socket.Emit("move", JsonUtility.ToJson(packet));
    }
Exemplo n.º 8
0
        public void MoveTo(Position destination)
        {
            const float MovementEpsilon = 1.0f;

            if (destination.MapID != Player.MapID)
            {
                Log("Trying to move to another map", Client.UI.LogLevel.Warning);
                return;
            }

            Path path = null;

            using (var detour = new DetourCLI.Detour())
            {
                List <DetourCLI.Point> resultPath;
                bool successful = detour.FindPath(Player.X, Player.Y, Player.Z,
                                                  destination.X, destination.Y, destination.Z,
                                                  Player.MapID, out resultPath);
                if (!successful)
                {
                    return;
                }

                path = new Path(resultPath, Player.Speed);
                var destinationPoint = path.Destination;
                destination.SetPosition(destinationPoint.X, destinationPoint.Y, destinationPoint.Z);
            }

            var remaining = destination - Player.GetPosition();

            // check if we even need to move
            if (remaining.Length < MovementEpsilon)
            {
                return;
            }

            var direction = remaining.Direction;

            var facing = new MovementPacket(WorldCommand.MSG_MOVE_SET_FACING)
            {
                GUID  = Player.GUID,
                flags = MovementFlags.MOVEMENTFLAG_FORWARD,
                X     = Player.X,
                Y     = Player.Y,
                Z     = Player.Z,
                O     = direction.O
            };

            SendPacket(facing);
            Player.SetPosition(facing.GetPosition());

            var startMoving = new MovementPacket(WorldCommand.MSG_MOVE_START_FORWARD)
            {
                GUID  = Player.GUID,
                flags = MovementFlags.MOVEMENTFLAG_FORWARD,
                X     = Player.X,
                Y     = Player.Y,
                Z     = Player.Z,
                O     = Player.O
            };

            SendPacket(startMoving);

            var previousMovingTime = DateTime.Now;

            var oldRemaining = remaining;

            ScheduleAction(() =>
            {
                Point progressPosition = path.MoveAlongPath((float)(DateTime.Now - previousMovingTime).TotalSeconds);
                Player.SetPosition(progressPosition.X, progressPosition.Y, progressPosition.Z);
                previousMovingTime = DateTime.Now;

                remaining = destination - Player.GetPosition();
                if (remaining.Length > MovementEpsilon && oldRemaining.Length >= remaining.Length)
                {
                    oldRemaining = remaining;

                    var heartbeat = new MovementPacket(WorldCommand.MSG_MOVE_HEARTBEAT)
                    {
                        GUID  = Player.GUID,
                        flags = MovementFlags.MOVEMENTFLAG_FORWARD,
                        X     = Player.X,
                        Y     = Player.Y,
                        Z     = Player.Z,
                        O     = Player.O
                    };
                    SendPacket(heartbeat);
                }
                else
                {
                    var stopMoving = new MovementPacket(WorldCommand.MSG_MOVE_STOP)
                    {
                        GUID = Player.GUID,
                        X    = destination.X,
                        Y    = destination.Y,
                        Z    = destination.Z,
                        O    = Player.O
                    };
                    SendPacket(stopMoving);
                    Player.SetPosition(stopMoving.GetPosition());

                    CancelActionsByFlag(ActionFlag.Movement);
                }
            }, new TimeSpan(0, 0, 0, 0, 100), flags: ActionFlag.Movement);
        }
Exemplo n.º 9
0
        public void MoveTo(Position destination)
        {
            CancelActionsByFlag(ActionFlag.Movement, false);

            if (destination.MapID != Player.MapID)
            {
                Log("Trying to move to another map", Client.UI.LogLevel.Warning);
                HandleTriggerInput(TriggerActionType.DestinationReached, false);
                return;
            }

            Path path = null;

            using (var detour = new DetourCLI.Detour())
            {
                List <MapCLI.Point> resultPath;
                var pathResult = detour.FindPath(Player.X, Player.Y, Player.Z,
                                                 destination.X, destination.Y, destination.Z,
                                                 Player.MapID, out resultPath);
                if (pathResult != PathType.Complete)
                {
                    Log($"Cannot reach destination, FindPath() returned {pathResult} : {destination.ToString()}", Client.UI.LogLevel.Warning);
                    HandleTriggerInput(TriggerActionType.DestinationReached, false);
                    return;
                }

                path = new Path(resultPath, Player.Speed, Player.MapID);
                var destinationPoint = path.Destination;
                destination.SetPosition(destinationPoint.X, destinationPoint.Y, destinationPoint.Z);
            }

            var remaining = destination - Player.GetPosition();

            // check if we even need to move
            if (remaining.Length < MovementEpsilon)
            {
                HandleTriggerInput(TriggerActionType.DestinationReached, true);
                return;
            }

            var direction = remaining.Direction;

            var facing = new MovementPacket(NetworkOperationCode.MSG_MOVE_SET_FACING)
            {
                GUID  = Player.GUID,
                flags = MovementFlags.MOVEMENTFLAG_FORWARD,
                X     = Player.X,
                Y     = Player.Y,
                Z     = Player.Z,
                O     = path.CurrentOrientation
            };

            SendPacket(facing);
            Player.SetPosition(facing.GetPosition());

            var startMoving = new MovementPacket(NetworkOperationCode.MSG_MOVE_START_FORWARD)
            {
                GUID  = Player.GUID,
                flags = MovementFlags.MOVEMENTFLAG_FORWARD,
                X     = Player.X,
                Y     = Player.Y,
                Z     = Player.Z,
                O     = path.CurrentOrientation
            };

            SendPacket(startMoving);

            var previousMovingTime = DateTime.Now;

            var oldRemaining = remaining;

            ScheduleAction(() =>
            {
                Point progressPosition = path.MoveAlongPath((float)(DateTime.Now - previousMovingTime).TotalSeconds);
                Player.SetPosition(progressPosition.X, progressPosition.Y, progressPosition.Z);
                previousMovingTime = DateTime.Now;

                remaining = destination - Player.GetPosition();
                if (remaining.Length > MovementEpsilon)
                {
                    oldRemaining = remaining;

                    var heartbeat = new MovementPacket(NetworkOperationCode.MSG_MOVE_HEARTBEAT)
                    {
                        GUID  = Player.GUID,
                        flags = MovementFlags.MOVEMENTFLAG_FORWARD,
                        X     = Player.X,
                        Y     = Player.Y,
                        Z     = Player.Z,
                        O     = path.CurrentOrientation
                    };
                    SendPacket(heartbeat);
                }
                else
                {
                    var stopMoving = new MovementPacket(NetworkOperationCode.MSG_MOVE_STOP)
                    {
                        GUID = Player.GUID,
                        X    = Player.X,
                        Y    = Player.Y,
                        Z    = Player.Z,
                        O    = path.CurrentOrientation
                    };
                    SendPacket(stopMoving);
                    Player.SetPosition(stopMoving.GetPosition());

                    CancelActionsByFlag(ActionFlag.Movement, false);

                    HandleTriggerInput(TriggerActionType.DestinationReached, true);
                }
            }, new TimeSpan(0, 0, 0, 0, 100), ActionFlag.Movement,
                           () =>
            {
                var stopMoving = new MovementPacket(NetworkOperationCode.MSG_MOVE_STOP)
                {
                    GUID = Player.GUID,
                    X    = Player.X,
                    Y    = Player.Y,
                    Z    = Player.Z,
                    O    = path.CurrentOrientation
                };
                SendPacket(stopMoving);
            });
        }
Exemplo n.º 10
0
        public void MoveTo(Position destination)
        {
            const float MovementEpsilon = 1.0f;

            if (destination.MapID != Player.MapID)
            {
                Log("Trying to move to another map", Client.UI.LogLevel.Warning);
                return;
            }

            var remaining = destination - Player.GetPosition();

            // check if we even need to move
            if (remaining.Length < MovementEpsilon)
            {
                return;
            }

            var direction = remaining.Direction;

            var facing = new MovementPacket(WorldCommand.MSG_MOVE_SET_FACING)
            {
                GUID  = Player.GUID,
                flags = MovementFlags.MOVEMENTFLAG_FORWARD,
                X     = Player.X,
                Y     = Player.Y,
                Z     = Player.Z,
                O     = direction.O
            };

            SendPacket(facing);
            Player.SetPosition(facing.GetPosition());

            var startMoving = new MovementPacket(WorldCommand.MSG_MOVE_START_FORWARD)
            {
                GUID  = Player.GUID,
                flags = MovementFlags.MOVEMENTFLAG_FORWARD,
                X     = Player.X,
                Y     = Player.Y,
                Z     = Player.Z,
                O     = Player.O
            };

            SendPacket(startMoving);

            var previousMovingTime = DateTime.Now;

            var oldRemaining = remaining;

            ScheduleAction(() =>
            {
                Player.SetPosition(Player.GetPosition() + direction * 7 * (DateTime.Now - previousMovingTime).TotalSeconds);
                previousMovingTime = DateTime.Now;

                remaining = destination - Player.GetPosition();
                if (remaining.Length > MovementEpsilon && oldRemaining.Length > remaining.Length)
                {
                    oldRemaining = remaining;

                    var heartbeat = new MovementPacket(WorldCommand.MSG_MOVE_HEARTBEAT)
                    {
                        GUID  = Player.GUID,
                        flags = MovementFlags.MOVEMENTFLAG_FORWARD,
                        X     = Player.X,
                        Y     = Player.Y,
                        Z     = Player.Z,
                        O     = Player.O
                    };
                    SendPacket(heartbeat);
                }
                else
                {
                    var stopMoving = new MovementPacket(WorldCommand.MSG_MOVE_STOP)
                    {
                        GUID = Player.GUID,
                        X    = destination.X,
                        Y    = destination.Y,
                        Z    = destination.Z,
                        O    = Player.O
                    };
                    SendPacket(stopMoving);
                    Player.SetPosition(stopMoving.GetPosition());

                    CancelActionsByFlag(ActionFlag.Movement);
                }
            }, new TimeSpan(0, 0, 0, 0, 100), flags: ActionFlag.Movement);
        }
Exemplo n.º 11
0
        public void Follow(WorldObject target)
        {
            if (target == null)
            {
                return;
            }

            Path     path               = null;
            bool     moving             = false;
            Position pathEndPosition    = target.GetPosition();
            DateTime previousMovingTime = DateTime.MinValue;

            ScheduleAction(() =>
            {
                if (!target.IsValid)
                {
                    return;
                }

                if (target.MapID != Player.MapID)
                {
                    Log("Trying to follow a target on another map", Client.UI.LogLevel.Warning);
                    CancelActionsByFlag(ActionFlag.Movement, false);
                    return;
                }

                var distance = target - Player.GetPosition();
                // check if we even need to move
                if (distance.Length < FollowMovementEpsilon)
                {
                    if (path != null)
                    {
                        var stopMoving = new MovementPacket(NetworkOperationCode.MSG_MOVE_STOP)
                        {
                            GUID = Player.GUID,
                            X    = Player.X,
                            Y    = Player.Y,
                            Z    = Player.Z,
                            O    = Player.O
                        };
                        SendPacket(stopMoving);
                        Player.SetPosition(stopMoving.GetPosition());
                        moving = false;
                        path   = null;
                        HandleTriggerInput(TriggerActionType.DestinationReached, true);
                    }

                    return;
                }

                float targetMovement = (target - pathEndPosition).Length;
                if (targetMovement > FollowTargetRecalculatePathEpsilon)
                {
                    path = null;
                }
                else if (distance.Length >= FollowMovementEpsilon && distance.Length <= FollowTargetRecalculatePathEpsilon)
                {
                    path = null;
                }

                if (path == null)
                {
                    using (var detour = new DetourCLI.Detour())
                    {
                        List <MapCLI.Point> resultPath;
                        var findPathResult = detour.FindPath(Player.X, Player.Y, Player.Z,
                                                             target.X, target.Y, target.Z,
                                                             Player.MapID, out resultPath);
                        if (findPathResult != PathType.Complete)
                        {
                            HandleTriggerInput(TriggerActionType.DestinationReached, false);
                            CancelActionsByFlag(ActionFlag.Movement);
                            return;
                        }

                        path            = new Path(resultPath, Player.Speed, Player.MapID);
                        pathEndPosition = target.GetPosition();
                    }
                }

                if (!moving)
                {
                    moving     = true;
                    var facing = new MovementPacket(NetworkOperationCode.MSG_MOVE_SET_FACING)
                    {
                        GUID  = Player.GUID,
                        flags = MovementFlags.MOVEMENTFLAG_FORWARD,
                        X     = Player.X,
                        Y     = Player.Y,
                        Z     = Player.Z,
                        O     = path.CurrentOrientation
                    };

                    SendPacket(facing);
                    Player.SetPosition(facing.GetPosition());

                    var startMoving = new MovementPacket(NetworkOperationCode.MSG_MOVE_START_FORWARD)
                    {
                        GUID  = Player.GUID,
                        flags = MovementFlags.MOVEMENTFLAG_FORWARD,
                        X     = Player.X,
                        Y     = Player.Y,
                        Z     = Player.Z,
                        O     = path.CurrentOrientation
                    };
                    SendPacket(startMoving);

                    previousMovingTime = DateTime.Now;
                    return;
                }

                Point progressPosition = path.MoveAlongPath((float)(DateTime.Now - previousMovingTime).TotalSeconds);
                Player.SetPosition(progressPosition.X, progressPosition.Y, progressPosition.Z);
                previousMovingTime = DateTime.Now;

                var heartbeat = new MovementPacket(NetworkOperationCode.MSG_MOVE_HEARTBEAT)
                {
                    GUID  = Player.GUID,
                    flags = MovementFlags.MOVEMENTFLAG_FORWARD,
                    X     = Player.X,
                    Y     = Player.Y,
                    Z     = Player.Z,
                    O     = path.CurrentOrientation
                };
                SendPacket(heartbeat);
            }, new TimeSpan(0, 0, 0, 0, 100), flags: ActionFlag.Movement);
        }