internal int Remove(object item, bool returnLeafIndex)
        {
            int index      = -1;
            int localIndex = ProtectedItems.IndexOf(item);

            if (localIndex >= 0)
            {
                if (returnLeafIndex)
                {
                    index = LeafIndexFromItem(null, localIndex);
                }

                CollectionViewGroupInternal subGroup = item as CollectionViewGroupInternal;
                if (subGroup != null)
                {
                    subGroup.Clear();

                    // Remove from the name to group map.
                    RemoveSubgroupFromMap(subGroup);
                }

                ChangeCounts(item, -1);

                // ChangeCounts may clear this group, if it is now empty.
                // In that case, don't use localIndex - it's now out of range.
                if (ProtectedItems.Count > 0)
                {
                    ProtectedItems.RemoveAt(localIndex);
                }
            }

            return(index);
        }
        internal void Clear()
        {
            // reset the counts before delving into subgroups.   The subgroup
            // changes can incur re-entrant calls to LeafAt(index) which will
            // get out-of-range exceptions (DDVSO 656948), unless we fend them
            // off by ensuring that count<=index.
            FullCount          = 1;
            ProtectedItemCount = 0;

            if (_groupBy != null)
            {
                // This group has subgroups.  Disconnect from GroupDescription events
                PropertyChangedEventManager.RemoveHandler(_groupBy, OnGroupByChanged, String.Empty);
                _groupBy = null;

                // recursively clear subgroups
                for (int i = 0, n = ProtectedItems.Count; i < n; ++i)
                {
                    CollectionViewGroupInternal subGroup = ProtectedItems[i] as CollectionViewGroupInternal;
                    if (subGroup != null)
                    {
                        subGroup.Clear();
                    }
                }
            }

            ProtectedItems.Clear();
            if (_nameToGroupMap != null)
            {
                _nameToGroupMap.Clear();
            }
        }
Ejemplo n.º 3
0
        internal void Clear()
        {
            if (_groupBy != null)
            {
                // This group has subgroups.  Disconnect from GroupDescription events
                PropertyChangedEventManager.RemoveHandler(_groupBy, OnGroupByChanged, String.Empty);
                _groupBy = null;

                // recursively clear subgroups
                for (int i = 0, n = ProtectedItems.Count; i < n; ++i)
                {
                    CollectionViewGroupInternal subGroup = ProtectedItems[i] as CollectionViewGroupInternal;
                    if (subGroup != null)
                    {
                        subGroup.Clear();
                    }
                }
            }

            FullCount          = 1;
            ProtectedItemCount = 0;
            ProtectedItems.Clear();
            if (_nameToGroupMap != null)
            {
                _nameToGroupMap.Clear();
            }
        }
Ejemplo n.º 4
0
        internal void AddItem(object item, bool allowSorting, IList wrappedList)
        {
            int index = ProtectedItems.Count;

            if (allowSorting && !(item is CollectionViewGroup))
            {
                var comparer = Sorters.Count > 0 ? new PropertyComparer(Sorters) : null;

                for (int i = 0; i < ProtectedItems.Count; i++)
                {
                    int comparison;
                    if (comparer != null)
                    {
                        comparison = comparer.Compare(item, ProtectedItems [i]);
                    }
                    else
                    {
                        comparison = wrappedList.IndexOf(item).CompareTo(wrappedList.IndexOf(ProtectedItems [i]));
                    }

                    if (comparison < 0)
                    {
                        index = i;
                        break;
                    }
                }
            }

            ProtectedItems.Insert(index, item);
            if (!(item is StandardCollectionViewGroup))
            {
                IncrementCount();
            }
        }
Ejemplo n.º 5
0
 internal void Clear()
 {
     FullCount          = 1;
     ProtectedItemCount = 0;
     ProtectedItems.Clear();
     if (_nameToGroupMap != null)
     {
         _nameToGroupMap.Clear();
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Internal use only.
        /// </summary>
        /// <param name="items"></param>
        /// <returns></returns>
        public ReadOnlyObservableCollection <Object> BuildGroupsFromList(IList items)
        {
            ProtectedItems.Clear();

            foreach (var item in items)
            {
                AddItemToGroup(item, 0, this);
            }
            return(this.Items);
        }
Ejemplo n.º 7
0
        internal void InsertSpecialItem(int index, object item, bool loading)
        {
            ChangeCounts(item, +1);
            ProtectedItems.Insert(index, item);

            if (!loading)
            {
                int globalIndex = this.LeafIndexFromItem(item, index);
                OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, globalIndex));
            }
        }
        //------------------------------------------------------
        //
        //  Internal methods
        //
        //------------------------------------------------------

        internal void Add(object item)
        {
            if (_groupComparer == null)
            {
                ChangeCounts(item, +1);
                ProtectedItems.Add(item);
            }
            else
            {
                Insert(item, null, null);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Insert a new item or subgroup and return its index.  Seed is a
        /// representative from the subgroup (or the item itself) that
        /// is used to position the new item/subgroup w.r.t. the order given
        /// by the comparer. (If comparer is null, just add at the end).
        /// </summary>
        /// <param name="item">Item we are looking for</param>
        /// <param name="seed">Seed of the item we are looking for</param>
        /// <param name="comparer">Comparer used to find the item</param>
        /// <returns>The index where the item was inserted</returns>
        internal int Insert(object item, object seed, IComparer comparer)
        {
            // never insert the new item/group before the explicit subgroups
            int low   = (GroupBy == null) ? 0 : GroupBy.GroupNames.Count;
            int index = FindIndex(item, seed, comparer, low, ProtectedItems.Count);

            // now insert the item
            ChangeCounts(item, +1);
            ProtectedItems.Insert(index, item);

            return(index);
        }
Ejemplo n.º 10
0
        internal void ClearSubtree()
        {
            ProtectedItems.Clear();
            CollectionChanged.Raise(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
            return;
//			if (IsBottomLevel) {
//				ClearItems ();
//			} else {
//				foreach (StandardCollectionViewGroup g in Items)
//					g.ClearSubtree ();
//			}
        }
Ejemplo n.º 11
0
        internal bool RemoveItem(object item)
        {
            if (ProtectedItems.Remove(item))
            {
                if (!(item is StandardCollectionViewGroup))
                {
                    DecrementCount();
                }
                return(true);
            }

            return(false);
        }
        private void CollectionViewGroupProxy_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            var copy = _wrapped.Group.ToList();

            _dispatcher.Invoke(() =>
            {
                ProtectedItems.Clear();
                foreach (var item in copy)
                {
                    ProtectedItems.Add(item);
                }
                ProtectedItemCount = copy.Count;
            });
        }
        public CollectionViewGroupProxy(PersonAgeGroup group, Dispatcher dispatcher) : base(group.Key)
        {
            _wrapped    = group;
            _dispatcher = dispatcher;

            ((INotifyCollectionChanged)_wrapped.Group).CollectionChanged += CollectionViewGroupProxy_CollectionChanged;
            {
                foreach (var item in _wrapped.Group)
                {
                    ProtectedItems.Add(item);
                }
                ProtectedItemCount = group.Group.Count;
            }
        }
Ejemplo n.º 14
0
        internal void RemoveSpecialItem(int index, object item, bool loading)
        {
            Debug.Assert(Object.Equals(item, ProtectedItems[index]), "RemoveSpecialItem finds inconsistent data");
            int globalIndex = -1;

            if (!loading)
            {
                globalIndex = this.LeafIndexFromItem(item, index);
            }

            ChangeCounts(item, -1);
            ProtectedItems.RemoveAt(index);

            if (!loading)
            {
                OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item, globalIndex));
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Removes the specified item from the collection
        /// </summary>
        /// <param name="item">Item to remove</param>
        /// <param name="returnLeafIndex">Whether we want to return the leaf index</param>
        /// <returns>Leaf index where item was removed, if value was specified. Otherwise '-1'</returns>
        internal int Remove(object item, bool returnLeafIndex)
        {
            int index      = -1;
            int localIndex = ProtectedItems.IndexOf(item);

            if (localIndex >= 0)
            {
                if (returnLeafIndex)
                {
                    index = LeafIndexFromItem(null, localIndex);
                }

                ChangeCounts(item, -1);
                ProtectedItems.RemoveAt(localIndex);
            }

            return(index);
        }
        // insert a new item or subgroup and return its index.  Seed is a
        // representative from the subgroup (or the item itself) that
        // is used to position the new item/subgroup w.r.t. the order given
        // by the comparer.  (If comparer is null, just add at the end).
        internal int Insert(object item, object seed, IComparer comparer)
        {
            // when group sorting is not declared,
            // never insert the new item/group before the explicit subgroups
            int low = 0;

            if (_groupComparer == null && GroupBy != null)
            {
                low = GroupBy.GroupNames.Count;
            }

            int index = FindIndex(item, seed, comparer, low, ProtectedItems.Count);

            // now insert the item
            ChangeCounts(item, +1);
            ProtectedItems.Insert(index, item);

            return(index);
        }
Ejemplo n.º 17
0
        internal void AddItem(object item, bool allowSorting)
        {
            int index = ProtectedItems.Count;

            if (allowSorting && Sorters.Count > 0 && !(item is CollectionViewGroup))
            {
                var comparer = new PropertyComparer(Sorters);
                for (int i = 0; i < ProtectedItems.Count; i++)
                {
                    if (comparer.Compare(item, ProtectedItems [i]) < 0)
                    {
                        index = i;
                        break;
                    }
                }
            }

            ProtectedItems.Insert(index, item);
            if (!(item is StandardCollectionViewGroup))
            {
                IncrementCount();
            }
        }
Ejemplo n.º 18
0
        internal int Remove(object item, bool returnLeafIndex)
        {
            int index      = -1;
            int localIndex = ProtectedItems.IndexOf(item);

            if (localIndex >= 0)
            {
                if (returnLeafIndex)
                {
                    index = LeafIndexFromItem(null, localIndex);
                }

                CollectionViewGroupInternal subGroup = item as CollectionViewGroupInternal;
                if (subGroup != null)
                {
                    // Remove from the name to group map.
                    RemoveSubgroupFromMap(subGroup);
                }
                ChangeCounts(item, -1);
                ProtectedItems.RemoveAt(localIndex);
            }

            return(index);
        }
Ejemplo n.º 19
0
        public override void dropLoot()
        {
            Entity whoKiller = this.getKiller();

            /*
             * Replaced if killer is [Npc] to [this] (this player).
             * Also I couldn't do it in 1 line of coding because
             * this.getKiller() may change while being casted to Player
             * even if it was Npc (then it would be based on luck timing).
             */
            Player killer = whoKiller is Npc ? this : (Player)(whoKiller);

            int amountToKeep = isSkulled() ? 0 : 3;

            if (prayers.isProtectItem())
            {
                amountToKeep = isSkulled() ? 1 : 4;
            }

            int[]  protectedItems = new int[amountToKeep];
            bool[] saved          = new bool[amountToKeep];
            if (protectedItems.Length > 0)
            {
                protectedItems[0] = ProtectedItems.getProtectedItem1(this)[0];
            }
            if (protectedItems.Length > 1)
            {
                protectedItems[1] = ProtectedItems.getProtectedItem2(this)[0];
            }
            if (protectedItems.Length > 2)
            {
                protectedItems[2] = ProtectedItems.getProtectedItem3(this)[0];
            }
            if (protectedItems.Length > 3)
            {
                protectedItems[3] = ProtectedItems.getProtectedItem4(this)[0];
            }
            bool save = false;

            foreach (Item item in getInventory().getItems())
            {
                save = false;

                if (item.getItemId() > 0)
                {
                    for (int j = 0; j < protectedItems.Length; j++)
                    {
                        if (amountToKeep > 0 && protectedItems[j] > 0)
                        {
                            if (!saved[j] && !save)
                            {
                                if (item.getItemId() == protectedItems[j] && item.getItemAmount() == 1)
                                {
                                    saved[j] = true;
                                    save     = true;
                                }
                                if (item.getItemId() == protectedItems[j] && item.getItemAmount() > 1)
                                {
                                    item.setItemAmount(item.getItemAmount() - 1);
                                    saved[j] = true;
                                    save     = true;
                                }
                            }
                        }
                    }
                    if (!save)
                    {
                        int itemId = item.getItemId();
                        //If inventory items have to break on dropped death, this is where they go
                        if (itemId >= 4708 && itemId <= 4759)
                        {
                            itemId = BrokenBarrows.getBrokenId(itemId);
                        }
                        Server.getGroundItems().newEntityDrop(new GroundItem(itemId, item.getItemAmount(), this.getLocation(), item.getDefinition().isPlayerBound() ? this : killer));
                    }
                }
            }
            inventory.clearAll();
            saved = new bool[amountToKeep];
            foreach (ItemData.EQUIP equip in Enum.GetValues(typeof(ItemData.EQUIP)))
            {
                if (equip == ItemData.EQUIP.NOTHING)
                {
                    continue;
                }
                save = false;
                Item item = this.getEquipment().getSlot(equip);
                if (item.getItemId() > 0)
                {
                    for (int j = 0; j < protectedItems.Length; j++)
                    {
                        if (amountToKeep > 0 && protectedItems[j] > -1)
                        {
                            if (!saved[j] && !save)
                            {
                                if (item.getItemId() == protectedItems[j] && item.getItemAmount() == 1)
                                {
                                    saved[j] = true;
                                    save     = true;
                                }
                                if (item.getItemId() == protectedItems[j] && item.getItemAmount() > 1)
                                {
                                    item.setItemAmount(item.getItemAmount() - 1);
                                    saved[j] = true;
                                    save     = true;
                                }
                            }
                        }
                    }
                    if (!save)
                    {
                        //If equipped items have to break on dropped death, this is where they go
                        int itemId = item.getItemId();
                        if (itemId >= 4708 && itemId <= 4759)
                        {
                            itemId = BrokenBarrows.getBrokenId(itemId);
                        }
                        Server.getGroundItems().newEntityDrop(new GroundItem(itemId, item.getItemAmount(), this.getLocation(), item.getDefinition().isPlayerBound() ? this : killer));
                    }
                }
            }
            equipment.clearAll();
            GroundItem bones = new GroundItem(526, 1, this.getLocation(), killer);

            Server.getGroundItems().newEntityDrop(bones);
            inventory.setProtectedItems(protectedItems);
        }
Ejemplo n.º 20
0
 internal void ClearItems()
 {
     ProtectedItems.Clear();
     ProtectedItemCount = 0;
 }
Ejemplo n.º 21
0
 internal int IndexOf(object item)
 {
     return(ProtectedItems.IndexOf(item));
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Clears the collection of items
 /// </summary>
 internal void Clear()
 {
     ProtectedItems.Clear();
     FullCount          = 1;
     ProtectedItemCount = 0;
 }
Ejemplo n.º 23
0
        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------

        /// <summary>
        /// Adds the specified item to the collection
        /// </summary>
        /// <param name="item">Item to add</param>
        internal void Add(object item)
        {
            ChangeCounts(item, +1);
            ProtectedItems.Add(item);
        }
Ejemplo n.º 24
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="item"></param>
 protected void AddItem(object item)
 {
     ProtectedItems.Add(item);
     ProtectedItemCount++;
 }
 /// <summary>
 /// Insert a new item or subgroup.
 /// </summary>
 /// <param name="item">The item being inserted.</param>
 /// <param name="index">The index at which to insert the item.</param>
 internal void Insert(object item, int index)
 {
     this.ChangeCounts(item, +1);
     ProtectedItems.Insert(index, item);
 }
        // move an item and return true if it really moved.
        // Also translate the indices to "leaf" coordinates
        internal bool Move(object item, IList list, ref int oldIndex, ref int newIndex)
        {
            int oldIndexLocal = -1, newIndexLocal = -1;
            int localIndex = 0;
            int n          = ProtectedItems.Count;

            // the input is in "full" coordinates.  Find the corresponding local coordinates
            for (int fullIndex = 0; ; ++fullIndex)
            {
                if (fullIndex == oldIndex)
                {
                    oldIndexLocal = localIndex;
                    if (newIndexLocal >= 0)
                    {
                        break;
                    }
                    ++localIndex;
                }

                if (fullIndex == newIndex)
                {
                    newIndexLocal = localIndex;
                    if (oldIndexLocal >= 0)
                    {
                        --newIndexLocal;
                        break;
                    }
                    ++fullIndex;
                    ++oldIndex;
                }

                if (localIndex < n && ItemsControl.EqualsEx(ProtectedItems[localIndex], list[fullIndex]))
                {
                    ++localIndex;
                }
            }

            // the move may be a no-op w.r.t. this group
            if (oldIndexLocal == newIndexLocal)
            {
                return(false);
            }

            // translate to "leaf" coordinates
            int low, high, lowLeafIndex, delta = 0;

            if (oldIndexLocal < newIndexLocal)
            {
                low          = oldIndexLocal + 1;
                high         = newIndexLocal + 1;
                lowLeafIndex = LeafIndexFromItem(null, oldIndexLocal);
            }
            else
            {
                low          = newIndexLocal;
                high         = oldIndexLocal;
                lowLeafIndex = LeafIndexFromItem(null, newIndexLocal);
            }

            for (int i = low; i < high; ++i)
            {
                CollectionViewGroupInternal subgroup = Items[i] as CollectionViewGroupInternal;
                delta += (subgroup == null) ? 1 : subgroup.ItemCount;
            }

            if (oldIndexLocal < newIndexLocal)
            {
                oldIndex = lowLeafIndex;
                newIndex = oldIndex + delta;
            }
            else
            {
                newIndex = lowLeafIndex;
                oldIndex = newIndex + delta;
            }

            // do the actual move
            ProtectedItems.Move(oldIndexLocal, newIndexLocal);
            return(true);
        }
Ejemplo n.º 27
0
        public override void dropLoot()
        {
            Entity killer = this.getKiller();
            Player klr    = killer is Npc ? null : (Player)killer;

            if (klr == null)
            {
                klr = this;
            }
            int amountToKeep = isSkulled() ? 0 : 3;

            if (prayers.isProtectItem())
            {
                amountToKeep = isSkulled() ? 1 : 4;
            }

            /*
             * Meh wanted to make a much more effient system.
             * //price of item, [item, object[]=(inventory/euqipment)]
             * //Inventory Items
             * SortedDictionary<int, object[]> valueSortedItems = new SortedDictionary<int, object[]>();
             * Item item;
             * int price = 0;
             * for(int i = 0; i < Inventory.MAX_INVENTORY_SLOTS; i++) {
             *  item = inventory.getSlot(i);
             *  if(item.getItemId() != -1 && item.getItemAmount() > 0) { //is real item.
             *      //price of item stacked
             *      price = item.getItemAmount() * item.getDefinition().getPrice().getMaximumPrice();
             *      valueSortedItems.Add(price, new object[] {item, 0});
             *  }
             * }
             * //Equipment Items
             * for(int i = 0; i < 14; i++) {
             *  item = equipment.getSlot(i);
             *  if(item.getItemId() != -1 && item.getItemAmount() > 0) { //is real item.
             *      //price of item stacked
             *      price = item.getItemAmount() * item.getDefinition().getPrice().getMaximumPrice();
             *      valueSortedItems.Add(price, new object[] {item, 1});
             *  }
             * }*/

            int[]  protectedItems = new int[amountToKeep];
            bool[] saved          = new bool[amountToKeep];
            if (protectedItems.Length > 0)
            {
                protectedItems[0] = ProtectedItems.getProtectedItem1(this)[0];
            }
            if (protectedItems.Length > 1)
            {
                protectedItems[1] = ProtectedItems.getProtectedItem2(this)[0];
            }
            if (protectedItems.Length > 2)
            {
                protectedItems[2] = ProtectedItems.getProtectedItem3(this)[0];
            }
            if (protectedItems.Length > 3)
            {
                protectedItems[3] = ProtectedItems.getProtectedItem4(this)[0];
            }
            bool save = false;

            for (int i = 0; i < 28; i++)
            {
                save = false;
                Item item = inventory.getSlot(i);
                if (item.getItemId() > 0)
                {
                    for (int j = 0; j < protectedItems.Length; j++)
                    {
                        if (amountToKeep > 0 && protectedItems[j] > 0)
                        {
                            if (!saved[j] && !save)
                            {
                                if (item.getItemId() == protectedItems[j] && item.getItemAmount() == 1)
                                {
                                    saved[j] = true;
                                    save     = true;
                                }
                                if (item.getItemId() == protectedItems[j] && item.getItemAmount() > 1)
                                {
                                    item.setItemAmount(item.getItemAmount() - 1);
                                    saved[j] = true;
                                    save     = true;
                                }
                            }
                        }
                    }
                    if (!save)
                    {
                        int itemId = item.getItemId();
                        if (itemId >= 4708 && itemId <= 4759)
                        {
                            itemId = BrokenBarrows.getBrokenId(itemId);
                        }
                        GroundItem gi = new GroundItem(itemId, item.getItemAmount(), this.getLocation(), item.getDefinition().isPlayerBound() ? this : klr);
                        Server.getGroundItems().newEntityDrop(gi);
                    }
                }
            }
            inventory.clearAll();
            saved = new bool[amountToKeep];
            foreach (ItemData.EQUIP equip in Enum.GetValues(typeof(ItemData.EQUIP)))
            {
                if (equip == ItemData.EQUIP.NOTHING)
                {
                    continue;
                }
                save = false;
                Item item = this.getEquipment().getSlot(equip);
                if (item.getItemId() > 0)
                {
                    for (int j = 0; j < protectedItems.Length; j++)
                    {
                        if (amountToKeep > 0 && protectedItems[j] > -1)
                        {
                            if (!saved[j] && !save)
                            {
                                if (item.getItemId() == protectedItems[j] && item.getItemAmount() == 1)
                                {
                                    saved[j] = true;
                                    save     = true;
                                }
                                if (item.getItemId() == protectedItems[j] && item.getItemAmount() > 1)
                                {
                                    item.setItemAmount(item.getItemAmount() - 1);
                                    saved[j] = true;
                                    save     = true;
                                }
                            }
                        }
                    }
                    if (!save)
                    {
                        int itemId = item.getItemId();
                        if (itemId >= 4708 && itemId <= 4759)
                        {
                            itemId = BrokenBarrows.getBrokenId(itemId);
                        }
                        GroundItem gi = new GroundItem(itemId, item.getItemAmount(), this.getLocation(), item.getDefinition().isPlayerBound() ? this : klr);
                        Server.getGroundItems().newEntityDrop(gi);
                    }
                }
            }
            equipment.clearAll();
            GroundItem bones = new GroundItem(526, 1, this.getLocation(), klr);

            Server.getGroundItems().newEntityDrop(bones);
            inventory.setProtectedItems(protectedItems);
        }
Ejemplo n.º 28
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="item"></param>
 protected void RemoveItem(object item)
 {
     ProtectedItems.Remove(item);
     ProtectedItemCount--;
 }