Beispiel #1
0
        public static OptionResult Perform(Sims3.Gameplay.Inventory inventory, Item sort)
        {
            if (inventory == null)
            {
                return(OptionResult.Failure);
            }

            if (sort == null)
            {
                return(OptionResult.Failure);
            }

            Dictionary <Type, int> counts = new Dictionary <Type, int>();

            foreach (InventoryStack stack in inventory.mItems.Values)
            {
                foreach (InventoryItem item in stack.List)
                {
                    if (item.mObject == null)
                    {
                        continue;
                    }

                    counts[item.mObject.GetType()] = stack.List.Count;

                    if (!item.mObject.InUse)
                    {
                        item.mInUse = false;
                    }
                }
            }

            List <SortObject> objs = new List <SortObject>();

            foreach (GameObject obj in Inventories.QuickFind <GameObject>(inventory))
            {
                if (obj is Hoverboard)
                {
                    Hoverboard obj2 = obj as Hoverboard;
                    if (obj2 != null)
                    {
                        bool usingHoverboardAlways = obj2.UsingHoverboardAlways;
                        if (inventory.TryToRemove(obj))
                        {
                            objs.Add(new SortObject(obj, counts[obj.GetType()], usingHoverboardAlways));
                        }
                    }
                    continue;
                }

                if (inventory.TryToRemove(obj))
                {
                    objs.Add(new SortObject(obj, counts[obj.GetType()]));
                }
            }

            try
            {
                objs.Sort(sort);
            }
            catch (Exception e)
            {
                Common.Exception(inventory.Owner, e);
            }

            try
            {
                inventory.IgnoreInventoryValidation = true;

                foreach (SortObject obj in objs)
                {
                    if (obj.mObj is Hoverboard)
                    {
                        Hoverboard obj2 = obj.mObj as Hoverboard;
                        if (obj2 != null)
                        {
                            obj2.UsingHoverboardAlways = obj.mUsingHoverboardAlways;

                            if (!Inventories.TryToMove(obj2, inventory))
                            {
                                obj2.Destroy();
                            }
                        }

                        continue;
                    }

                    if (!Inventories.TryToMove(obj.mObj, inventory))
                    {
                        obj.mObj.Destroy();
                    }
                }
            }
            finally
            {
                inventory.IgnoreInventoryValidation = false;
            }

            return(OptionResult.SuccessClose);
        }