Beispiel #1
0
        /// <summary>
        /// Overrides equality operators to compare by Id.
        /// </summary>
        public override bool Equals(Object obj)
        {
            if (!(obj is ExtraDropItem))
            {
                return(false);
            }

            ExtraDropItem other = (ExtraDropItem)obj;

            return(Id == other.Id);
        }
Beispiel #2
0
        /// <summary>
        /// Adds a drop item to the entry and returns it.
        /// </summary>
        /// <param name="id">The id of the item to drop.</param>
        /// <param name="probability">The probability of dropping the item.</param>
        /// <returns>The added item.</returns>
        public ExtraDropItem AddItem(uint id, float probability)
        {
            // Based on the EXTRADROPTABLE.h struct that Teemo Cell extracted, there can only be 256 items.
            if (DropItems.Count >= 256)
            {
                throw new System.OverflowException("Too many items in entry");
            }

            ExtraDropItem item = new ExtraDropItem(id, probability);
            DropItems.Add(item);

            return item;
        }
Beispiel #3
0
        /// <summary>
        /// Returns the index of the item with the given item id. If such an item does not exist, -1 is returned. 
        /// Includes an offsets to begin the search at.
        /// </summary>
        /// <param name="itemId">The item id to search for.</param>
        /// <param name="offset">Only search items with index >= this offset.</param>
        /// <returns>Index of the item with an id of itemId or -1 if such an item does not exist.</returns>
        public int FindItem(uint itemId, int offset)
        {
            // Since Items are considered equivalent if the Id matches, we will create a template item with only the id.
            ExtraDropItem search = new ExtraDropItem(itemId, 0.0f);

            List<ExtraDropItem> offsetItems = DropItems.Skip(offset).ToList();
            int index = offsetItems.IndexOf(search);

            if (index == -1)
            {
                return -1;
            }

            return index + offset;
        }
Beispiel #4
0
        /// <summary>
        /// Serialize to an output stream.
        /// </summary>
        /// <param name="output">The output stream to serialize to.</param>
        public void Serialize(Stream output)
        {
            BinaryWriter writer = new BinaryWriter(output);

            // Serialize monsters.
            writer.Write(Monsters.Count);
            for (int i = 0; i < Monsters.Count; ++i)
            {
                writer.Write(Monsters[i]);
            }

            // Serialize items. There must always be exactly 256 items according to the EXTRADROPTABLE.h struct that 
            // Teemo Cell extracted from the gs, so we'll pad it with 0s to 256 items if there are less than 256 items.
            for (int i = 0; i < 256; ++i)
            {
                if (i < DropItems.Count)
                {
                    ExtraDropItem item = DropItems[i];
                    item.Serialize(output);
                }
                else
                {
                    // Pad with 0s.
                    ExtraDropItem padding = new ExtraDropItem(0, 0.0f);
                    padding.Serialize(output);
                }
            }

            // Serialize name by first converting it to bytes, so the encoding will be correct. We must also pad it up
            // to 128 bytes if it isn't already.
            byte[] nameBytes = Encoding.GetEncoding("GB18030").GetBytes(Name);
            byte[] namePadded = new byte[128];
            Array.Copy(nameBytes, namePadded, Math.Min(nameBytes.Length, 128));
            writer.Write(namePadded);
            
            // Serialize the type as an integer.
            writer.Write((int) Type);

            // Serialize the drop probabilities. There must always be exactly 8 probabilities, according to the 
            // EXTRADROPTABLE.h struct that Teemo Cell extracted from the gs.
            for (int i = 0; i < 8; ++i)
            {
                writer.Write(_dropNumProbabilities[i]);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Construct the entry by deserializing from a stream.
        /// </summary>
        /// <param name="input">The input stream to deserialize from.</param>
        public ExtraDropEntry(Stream input)
        {
            BinaryReader reader = new BinaryReader(input);

            // Deserialize monsters.
            int numMonsters = reader.ReadInt32();
            for (int i = 0; i < numMonsters; ++i)
            {
                int monsterId = reader.ReadInt32();
                Monsters.Add(monsterId);
            }

            // Deserialize items. There must always be exactly 256 items based on the EXTRADROPTABLE.h struct that 
            // Teemo Cell extracted from the gs.
            for (int i = 0; i < 256; ++i)
            {
                ExtraDropItem item = new ExtraDropItem(input);

                // We'll only populate if the item id is non-zero, because an item id of zero actually represents no
                // item. This makes it easier for us to add or remove items later. We simply pad up to 256 items 
                // when we save.
                if (item.Id > 0)
                {
                    DropItems.Add(item);
                }
            }

            // Deserialize name. This is always 128 bytes based on the EXTRADROPTABLE.h struct that Teemo Cell extracted
            // from the gs.
            byte[] nameBytes = reader.ReadBytes(128);
            SetName(nameBytes);

            // Deserialize type.
            int type = reader.ReadInt32();
            SetType(type);

            // Deserialize the drop num probabilities. There are always 8 probabilities based on the EXTRADROPTABLE.h 
            // struct that Teemo Cell extracted from the gs.
            for (int i = 0; i < 8; ++i)
            {
                float probability = reader.ReadSingle();
                _dropNumProbabilities[i] = probability;
            }
        }
Beispiel #6
0
 /// <summary>
 /// Constructs a new item by cloning an existing item.
 /// </summary>
 /// <param name="item">The item to clone.</param>
 public ExtraDropItem(ExtraDropItem item)
 {
     Id          = item.Id;
     Probability = item.Probability;
 }