示例#1
0
        /// <summary>
        /// Parses the binary sack data to internal data
        /// </summary>
        /// <param name="reader">BinaryReader instance</param>
        public void Parse(SackCollection sc, BinaryReader reader)
        {
            try
            {
                sc.isModified = false;

                if (sc.sackType == SackType.Stash)
                {
                    // IL decided to use a different format for the stash files.
                    TQData.ValidateNextString("numItems", reader);
                    sc.size = reader.ReadInt32();
                }
                else if (sc.sackType == SackType.Equipment)
                {
                    if (sc.isImmortalThrone)
                    {
                        sc.size  = 12;
                        sc.slots = 12;
                    }
                    else
                    {
                        sc.size  = 11;
                        sc.slots = 11;
                    }
                }
                else
                {
                    // sc is just a regular sack.
                    TQData.ValidateNextString("begin_block", reader);                     // make sure we just read a new block
                    sc.beginBlockCrap = reader.ReadInt32();

                    TQData.ValidateNextString("tempBool", reader);
                    sc.tempBool = reader.ReadInt32();

                    TQData.ValidateNextString("size", reader);
                    sc.size = reader.ReadInt32();
                }

                sc.items = new List <Item>(sc.size);

                Item prevItem = null;
                for (int i = 0; i < sc.size; ++i)
                {
                    // Additional logic to decode the weapon slots in the equipment section
                    if (sc.sackType == SackType.Equipment && (i == 7 || i == 9))
                    {
                        TQData.ValidateNextString("begin_block", reader);
                        sc.beginBlockCrap = reader.ReadInt32();

                        // Eat the alternate tag and flag
                        TQData.ValidateNextString("alternate", reader);

                        // Skip over the alternateCrap
                        reader.ReadInt32();
                    }

                    Item item = new Item();
                    item.ContainerType = sc.sackType;
                    ItemProvider.Parse(item, reader);

                    // Stack sc item with the previous item if necessary
                    if ((prevItem != null) && item.DoesStack && (item.PositionX == -1) && (item.PositionY == -1))
                    {
                        prevItem.StackSize++;
                    }
                    else
                    {
                        prevItem = item;
                        sc.items.Add(item);
                        if (sc.sackType == SackType.Equipment)
                        {
                            // Get the item location from the table
                            item.PositionX = SackCollection.GetEquipmentLocationOffset(i).X;
                            item.PositionY = SackCollection.GetEquipmentLocationOffset(i).Y;

                            // Eat the itemAttached tag and flag
                            TQData.ValidateNextString("itemAttached", reader);

                            // Skip over the itemAttachedCrap
                            reader.ReadInt32();
                        }
                    }

                    // Additional logic to decode the weapon slots in the equipment section
                    if (sc.sackType == SackType.Equipment && (i == 8 || i == 10))
                    {
                        TQData.ValidateNextString("end_block", reader);
                        sc.endBlockCrap = reader.ReadInt32();
                    }
                }

                TQData.ValidateNextString("end_block", reader);
                sc.endBlockCrap = reader.ReadInt32();
            }
            catch (ArgumentException ex)
            {
                // The ValidateNextString Method can throw an ArgumentException.
                // We just pass it along at sc point.
                Log.LogDebug(ex, "ValidateNextString fail !");
                throw;
            }
        }