public BagInstance(int Id, ItemBag Bag) { InitializeDefaults(); this.InstanceId = Id; if (Bag is BoundedBag BoundedBag) { if (BoundedBag is BundleBag BundleBag) { this.TypeId = BundleBag.BundleBagTypeId; } else { this.TypeId = BoundedBag.TypeInfo.Id; this.ExcludedAutofillItems = BoundedBag.ExcludedAutofillItems.Select(x => new KeyValuePair <string, HashSet <ObjectQuality> >(x.Key, x.Value)).ToList(); } this.Autofill = BoundedBag.Autofill; } else if (Bag is Rucksack Rucksack) { this.TypeId = Rucksack.RucksackTypeId; this.Autofill = Rucksack.Autofill; this.AutofillPriority = Rucksack.AutofillPriority; this.SortProperty = Rucksack.SortProperty; this.SortOrder = Rucksack.SortOrder; } else if (Bag is OmniBag OmniBag) { this.TypeId = OmniBag.OmniBagTypeId; this.NestedBags = OmniBag.NestedBags.Select(x => new BagInstance(-1, x)).ToArray(); } else { throw new NotImplementedException(string.Format("Logic for encoding Bag Type '{0}' is not implemented", Bag.GetType().ToString())); } this.Size = Bag.Size; if (Bag.Contents != null) { this.Contents = Bag.Contents.Where(x => x != null).Select(x => new BagItem(x)).ToArray(); } if (!Bag.IsUsingCustomIcon) { this.IsCustomIcon = false; this.OverriddenIcon = new Rectangle(); } else { this.IsCustomIcon = true; this.OverriddenIcon = Bag.CustomIconTexturePosition.Value; } }