Esempio n. 1
0
        public override bool TryRemoveInvalidItems(IList <Item> Target, int ActualTargetCapacity)
        {
            bool ChangesMade = base.TryRemoveInvalidItems(Target, ActualTargetCapacity);

            //  Group the Nested Bags by their type
            //  and only keep the largest size of each unique type id
            foreach (IGrouping <string, ItemBag> Group in NestedBags.GroupBy(x => x.GetTypeId() ?? "Invalid"))
            {
                string         TypeId    = Group.Key;
                List <ItemBag> Instances = Group.ToList();

                int RemovedCount = 0;
                if (TypeId == OmniBagTypeId)
                {
                    RemovedCount = NestedBags.RemoveAll(x => Instances.Contains(x));
                }
                else if (Instances.Count > 1)
                {
                    ItemBag ToKeep = Instances.OrderByDescending(x => x.Size).FirstOrDefault(x => x.Size <= this.Size);
                    RemovedCount = NestedBags.RemoveAll(x => Instances.Contains(x) && x != ToKeep);
                }

                if (RemovedCount > 0)
                {
                    ChangesMade = true;
                    Resync();
                }
            }

            return(ChangesMade);
        }
Esempio n. 2
0
        public bool MoveToBag(ItemBag Bag, bool PlaySoundEffect, IList <Item> Source, bool NotifyIfContentsChanged)
        {
            if (!IsValidBag(Bag) || NestedBags.Any(x => x.GetTypeId() == Bag.GetTypeId()) || !Source.Contains(Bag))
            {
                if (PlaySoundEffect)
                {
                    Game1.playSound(MoveContentsFailedSound);
                }
                return(false);
            }
            else
            {
                NestedBags.Add(Bag);
                Source[Source.IndexOf(Bag)] = null;

                if (NotifyIfContentsChanged)
                {
                    OnContentsChanged?.Invoke(this, EventArgs.Empty);
                }
                Resync();
                if (PlaySoundEffect)
                {
                    Game1.playSound(MoveContentsSuccessSound);
                }
                return(true);
            }
        }
Esempio n. 3
0
        public bool MoveFromBag(ItemBag Bag, bool PlaySoundEffect, IList <Item> Target, int ActualTargetCapacity, bool NotifyIfContentsChanged)
        {
            if (Bag == null || !NestedBags.Contains(Bag))
            {
                if (PlaySoundEffect)
                {
                    Game1.playSound(MoveContentsFailedSound);
                }
                return(false);
            }
            else
            {
                //  Find index to place this bag at in the target list
                int TargetCapacity = Math.Max(ActualTargetCapacity, Target.Count);
                int ItemIndex      = -1;
                for (int i = 0; i < TargetCapacity; i++)
                {
                    if (i >= Target.Count || Target[i] == null)
                    {
                        ItemIndex = i;
                        break;
                    }
                }

                if (ItemIndex >= 0)
                {
                    //  Put bag in target, remove from source
                    if (ItemIndex >= Target.Count)
                    {
                        Target.Add(Bag);
                    }
                    else
                    {
                        Target[ItemIndex] = Bag;
                    }
                    NestedBags.Remove(Bag);

                    if (NotifyIfContentsChanged)
                    {
                        OnContentsChanged?.Invoke(this, EventArgs.Empty);
                    }
                    Resync();
                    if (PlaySoundEffect)
                    {
                        Game1.playSound(MoveContentsSuccessSound);
                    }
                    return(true);
                }
                else
                {
                    if (PlaySoundEffect)
                    {
                        Game1.playSound(MoveContentsFailedSound);
                    }
                    return(false);
                }
            }
        }