예제 #1
0
        internal NetworkedGameObjectClient GetObjectFromPacket(IIdentifiable p)
        {
            int id = p.GetId();

            NetworkedGameObjects.TryGetValue(id, out NetworkedGameObjectClient packetObject);
            return(packetObject);
        }
예제 #2
0
        /// <inheritdoc/>
        /// <remarks>
        /// This Packet is sent to the Server when an Object does an animation, including attacking other players.
        /// It will create the animation at the client side.
        /// </remarks>
        public void ShowAnimation(IIdentifiable animatingObj, byte animation, IIdentifiable targetObj, byte direction)
        {
            var animatingId = animatingObj.GetId(this.player);

            if (targetObj == null)
            {
                using (var writer = this.connection.StartSafeWrite(0xC1, 7))
                {
                    var packet = writer.Span;
                    packet[2] = 0x18;
                    packet[3] = animatingId.GetHighByte();
                    packet[4] = animatingId.GetLowByte();
                    packet[5] = direction;
                    packet[6] = animation;
                    writer.Commit();
                }
            }
            else
            {
                var targetId = targetObj.GetId(this.player);
                using (var writer = this.connection.StartSafeWrite(0xC1, 9))
                {
                    var packet = writer.Span;
                    packet[2] = 0x18;
                    packet[3] = animatingId.GetHighByte();
                    packet[4] = animatingId.GetLowByte();
                    packet[5] = direction;
                    packet[6] = animation;
                    packet[7] = targetId.GetHighByte();
                    packet[8] = targetId.GetLowByte();
                    writer.Commit();
                }
            }
        }
예제 #3
0
        /// <inheritdoc/>
        public void AddExperience(int exp, IIdentifiable obj)
        {
            ushort id = obj.GetId(this.player);

            while (exp > 0)
            {
                // We send multiple exp packets if the value is bigger than ushort.MaxValue, because that's all what the packet can carry.
                // On a normal exp server this should never be an issue, but with higher settings, it fixes the problem that the exp bar
                // shows less exp than the player actually gained.
                ushort sendExp;
                if (exp > ushort.MaxValue)
                {
                    sendExp = ushort.MaxValue;
                }
                else
                {
                    sendExp = (ushort)exp;
                }

                using (var writer = this.connection.StartSafeWrite(0xC3, 0x09))
                {
                    var packet = writer.Span;
                    packet[2] = 0x16;
                    packet.Slice(3).SetShortSmallEndian(id);
                    packet.Slice(5).SetShortSmallEndian(sendExp);

                    // last 2 bytes = last hit dmg
                    writer.Commit();
                }

                exp -= sendExp;
            }
        }
예제 #4
0
        /// <inheritdoc/>
        /// <remarks>
        /// This Packet is sent to the Server when an Object does an animation, including attacking other players.
        /// It will create the animation at the client side.
        /// </remarks>
        public void ShowAnimation(IIdentifiable animatingObj, byte animation, IIdentifiable targetObj, byte direction)
        {
            var animatingId = animatingObj.GetId(this.player);

            if (targetObj == null)
            {
                this.connection.Send(new byte[] { 0xC1, 0x07, 0x18, animatingId.GetHighByte(), animatingId.GetLowByte(), direction, animation });
            }
            else
            {
                var targetId = targetObj.GetId(this.player);
                this.connection.Send(new byte[] { 0xC1, 0x09, 0x18, animatingId.GetHighByte(), animatingId.GetLowByte(), direction, animation, targetId.GetHighByte(), targetId.GetLowByte() });
            }
        }
예제 #5
0
        /// <inheritdoc/>
        public void AddExperience(int exp, IIdentifiable obj)
        {
            var    remainingExperience = exp;
            ushort id = obj.GetId(this.player);

            while (remainingExperience > 0)
            {
                // We send multiple exp packets if the value is bigger than ushort.MaxValue, because that's all what the packet can carry.
                // On a normal exp server this should never be an issue, but with higher settings, it fixes the problem that the exp bar
                // shows less exp than the player actually gained.
                ushort sendExp = remainingExperience > ushort.MaxValue ? ushort.MaxValue : (ushort)remainingExperience;
                using (var writer = this.connection.StartSafeWrite(0xC3, 0x09))
                {
                    var packet = writer.Span;
                    packet[2] = 0x16;
                    packet.Slice(3).SetShortSmallEndian(id);
                    packet.Slice(5).SetShortSmallEndian(sendExp);
                    packet.Slice(7).SetShortSmallEndian((ushort)((obj as IAttackable)?.LastReceivedDamage ?? 0));
                    writer.Commit();
                }

                remainingExperience -= sendExp;
            }
        }
예제 #6
0
        /// <inheritdoc/>
        public void AddExperience(int exp, IIdentifiable obj)
        {
            ushort id = obj.GetId(this.player);

            while (exp > 0)
            {
                // We send multiple exp packets if the value is bigger than ushort.MaxValue, because that's all what the packet can carry.
                // On a normal exp server this should never be an issue, but with higher settings, it fixes the problem that the exp bar
                // shows less exp than the player actually gained.
                ushort sendExp;
                if (exp > ushort.MaxValue)
                {
                    sendExp = ushort.MaxValue;
                }
                else
                {
                    sendExp = (ushort)exp;
                }

                byte[] packet = { 0xC3, 0x09, 0x16, id.GetHighByte(), id.GetLowByte(), sendExp.GetHighByte(), sendExp.GetLowByte(), 0, 0 }; // last 2 bytes = last hit dmg
                this.connection.Send(packet);
                exp -= sendExp;
            }
        }