Example #1
0
        /// <summary>
        /// Add a <see cref="ICreature"/>'s description to the message.
        /// </summary>
        /// <param name="message">The message to add the creature description to.</param>
        /// <param name="creature">The creature to describe and add.</param>
        /// <param name="asKnown">A value indicating whether this creature is known.</param>
        /// <param name="creatureToRemoveId">The id of another creature to replace if the client buffer is known to be full.</param>
        public static void AddCreature(this INetworkMessage message, ICreature creature, bool asKnown, uint creatureToRemoveId)
        {
            if (asKnown)
            {
                message.AddByte((byte)OutgoingGamePacketType.AddKnownCreature); // known
                message.AddByte(0x00);
                message.AddUInt32(creature.Id);
            }
            else
            {
                message.AddByte((byte)OutgoingGamePacketType.AddUnknownCreature); // unknown
                message.AddByte(0x00);
                message.AddUInt32(creatureToRemoveId);
                message.AddUInt32(creature.Id);
                message.AddString(creature.Name);
            }

            message.AddByte(Convert.ToByte(Math.Min(100, creature.Hitpoints * 100 / creature.MaxHitpoints))); // health bar, needs a percentage.
            message.AddByte(Convert.ToByte(creature.Direction.GetClientSafeDirection()));

            if (creature.IsInvisible)
            {
                message.AddUInt16(0x00);
                message.AddUInt16(0x00);
            }
            else
            {
                message.AddOutfit(creature.Outfit);
            }

            message.AddByte(creature.EmittedLightLevel);
            message.AddByte(creature.EmittedLightColor);
            message.AddUInt16(creature.Speed);

            message.AddByte(creature.Skull);
            message.AddByte(creature.Shield);
        }