Ejemplo n.º 1
0
        public override void Handle(GameSession session, PacketReader packet)
        {
            byte function = packet.ReadByte(); // Unknown what this is for

            packet.ReadInt();                  // ServerTicks
            packet.ReadInt();                  // ClientTicks
            byte segments = packet.ReadByte();

            if (segments < 1)
            {
                return;
            }

            SyncState[] syncStates = new SyncState[segments];
            for (int i = 0; i < segments; i++)
            {
                syncStates[i] = packet.ReadSyncState();

                packet.ReadInt(); // ClientTicks
                packet.ReadInt(); // ServerTicks
            }

            Packet syncPacket = SyncStatePacket.UserSync(session.FieldPlayer, syncStates);

            session.FieldManager.BroadcastPacket(syncPacket, session);
            session.FieldPlayer.Coord = syncStates[0].Coord.ToFloat();
            // not sure if this needs to be synced here
            session.Player.Animation = syncStates[0].Animation1;
        }
Ejemplo n.º 2
0
    public override void Handle(GameSession session, PacketReader packet)
    {
        byte function = packet.ReadByte(); // Unknown what this is for

        session.ServerTick = packet.ReadInt();
        session.ClientTick = packet.ReadInt();

        byte segments = packet.ReadByte();

        if (segments < 1)
        {
            return;
        }

        SyncState[] syncStates = new SyncState[segments];
        for (int i = 0; i < segments; i++)
        {
            syncStates[i] = packet.ReadSyncState();

            packet.ReadInt(); // ClientTicks
            packet.ReadInt(); // ServerTicks
        }

        PacketWriter syncPacket = SyncStatePacket.UserSync(session.Player.FieldPlayer, syncStates);

        session.FieldManager.BroadcastPacket(syncPacket, session);
        UpdatePlayer(session, syncStates);
    }
Ejemplo n.º 3
0
        public override void Handle(GameSession session, PacketReader packet)
        {
            byte function = packet.ReadByte(); // Unknown what this is for

            session.ServerTick = packet.ReadInt();
            session.ClientTick = packet.ReadInt();

            byte segments = packet.ReadByte();

            if (segments < 1)
            {
                return;
            }

            SyncState[] syncStates = new SyncState[segments];
            for (int i = 0; i < segments; i++)
            {
                syncStates[i] = packet.ReadSyncState();

                packet.ReadInt(); // ClientTicks
                packet.ReadInt(); // ServerTicks
            }

            Packet syncPacket = SyncStatePacket.UserSync(session.FieldPlayer, syncStates);

            session.FieldManager.BroadcastPacket(syncPacket, session);

            CoordF coord        = syncStates[0].Coord.ToFloat();
            CoordF closestBlock = Block.ClosestBlock(coord);

            closestBlock.Z -= Block.BLOCK_SIZE; // Get block under player

            if (IsCoordSafe(session, syncStates[0].Coord, closestBlock))
            {
                session.Player.SafeBlock = closestBlock;
            }

            session.FieldPlayer.Coord = syncStates[0].Coord.ToFloat();
            CoordF rotation = new CoordF();

            rotation.Z = syncStates[0].Rotation / 10;
            session.FieldPlayer.Rotation = rotation;

            if (IsOutOfBounds(session.FieldPlayer.Coord, session.FieldManager.BoundingBox))
            {
                int    currentHp  = session.Player.Stats[PlayerStatId.Hp].Current;
                int    fallDamage = currentHp * Math.Clamp(currentHp * 4 / 100 - 1, 0, 25) / 100; // TODO: Create accurate damage model
                CoordF safeBlock  = session.Player.SafeBlock;
                safeBlock.Z += Block.BLOCK_SIZE + 1;                                              // Without this player will spawn inside the block
                session.Player.ConsumeHp(fallDamage);

                session.Send(UserMoveByPortalPacket.Move(session, safeBlock, session.Player.Rotation));
                session.Send(StatPacket.UpdateStats(session.FieldPlayer, PlayerStatId.Hp));
                session.Send(FallDamagePacket.FallDamage(session, fallDamage));
            }
            // not sure if this needs to be synced here
            session.Player.Animation = syncStates[0].Animation1;
        }
Ejemplo n.º 4
0
        public override void Handle(GameSession session, PacketReader packet)
        {
            byte function = packet.ReadByte();     // Unknown what this is for

            session.ClientTick = packet.ReadInt(); //ClientTicks
            packet.ReadInt();                      // ServerTicks

            byte segments = packet.ReadByte();

            if (segments < 1)
            {
                return;
            }

            SyncState[] syncStates = new SyncState[segments];
            for (int i = 0; i < segments; i++)
            {
                syncStates[i] = packet.ReadSyncState();

                packet.ReadInt(); // ClientTicks
                packet.ReadInt(); // ServerTicks
            }

            Packet syncPacket = SyncStatePacket.UserSync(session.FieldPlayer, syncStates);

            session.FieldManager.BroadcastPacket(syncPacket, session);

            CoordF coord        = syncStates[0].Coord.ToFloat();
            CoordF closestBlock = Block.ClosestBlock(coord);

            closestBlock.Z -= Block.BLOCK_SIZE; // Get block under player

            if (IsCoordSafe(session, syncStates[0].Coord, closestBlock))
            {
                session.Player.SafeBlock = closestBlock;
            }

            session.FieldPlayer.Coord = syncStates[0].Coord.ToFloat();

            if (IsOutOfBounds(session.FieldPlayer.Coord, session.FieldManager.BoundingBox))
            {
                CoordF safeBlock = session.Player.SafeBlock;
                safeBlock.Z += Block.BLOCK_SIZE + 1; // Without this player will spawn inside the block
                // for some reason if coord is negative player is teleported one block over, which can result player being stuck inside a block
                if (session.FieldPlayer.Coord.X < 0)
                {
                    safeBlock.X -= Block.BLOCK_SIZE;
                }
                if (session.FieldPlayer.Coord.Y < 0)
                {
                    safeBlock.Y -= Block.BLOCK_SIZE;
                }
                session.Send(UserMoveByPortalPacket.Move(session, safeBlock));
                session.Send(FallDamagePacket.FallDamage(session, 150)); // TODO: create a formula to determine HP loss
            }
            // not sure if this needs to be synced here
            session.Player.Animation = syncStates[0].Animation1;
        }