コード例 #1
0
 private void OnUpdateListViewItem(ItemPocketEventArgs e)
 {
     if (UpdateListViewItem != null)
     {
         UpdateListViewItem(this, e);
     }
 }
コード例 #2
0
 private void OnMoveListViewItem(ItemPocketEventArgs e)
 {
     if (MoveListViewItem != null)
     {
         MoveListViewItem(this, e);
     }
 }
コード例 #3
0
 private void OnAddListViewItem(ItemPocketEventArgs e)
 {
     if (AddListViewItem != null)
     {
         AddListViewItem(this, e);
     }
 }
コード例 #4
0
        public void TossItemAt(int index)
        {
            inventory.GameSave.IsChanged = true;
            items.RemoveAt(index);
            ItemPocketEventArgs args = new ItemPocketEventArgs();

            args.Index      = index;
            args.PocketType = pocketType;
            OnRemoveListViewItem(args);
        }
コード例 #5
0
 public void RepopulateListView()
 {
     listViewItems.Clear();
     for (int i = 0; i < items.Count; i++)
     {
         ItemPocketEventArgs args = new ItemPocketEventArgs();
         args.Index      = i;
         args.Item       = items[i];
         args.PocketType = pocketType;
         OnAddListViewItem(args);
     }
 }
コード例 #6
0
        public void MoveItem(int oldIndex, int newIndex)
        {
            if (!ordered)
            {
                inventory.GameSave.IsChanged = true;
                Item item = items[oldIndex];
                items.RemoveAt(oldIndex);
                items.Insert(newIndex, item);

                ItemPocketEventArgs args = new ItemPocketEventArgs();
                args.OldIndex   = oldIndex;
                args.NewIndex   = newIndex;
                args.PocketType = pocketType;
                OnMoveListViewItem(args);
            }
        }
コード例 #7
0
 public void TossItemAt(int index, uint count)
 {
     if (count > 0)
     {
         inventory.GameSave.IsChanged = true;
         if (count < items[index].Count)
         {
             items[index].Count -= count;
             ItemPocketEventArgs args = new ItemPocketEventArgs();
             args.Index      = index;
             args.Item       = items[index];
             args.PocketType = pocketType;
             OnUpdateListViewItem(args);
         }
         else
         {
             items.RemoveAt(index);
             ItemPocketEventArgs args = new ItemPocketEventArgs();
             args.Index      = index;
             args.PocketType = pocketType;
             OnRemoveListViewItem(args);
         }
     }
 }
コード例 #8
0
        public bool AddItem(ushort id, uint count)
        {
            ItemData itemData = ItemDatabase.GetItemFromID(id);

            if (pocketType != ItemTypes.PC && itemData.SubPocketType != pocketType && inventory.ContainsPocket(itemData.SubPocketType))
            {
                return(inventory[itemData.SubPocketType].AddItem(id, count));
            }
            if (HasRoomForItem(id, count))
            {
                int  countLeft       = (int)count;
                bool hasStackAlready = false;
                for (int i = 0; i < items.Count && countLeft > 0; i++)
                {
                    if (items[i].ID == id)
                    {
                        hasStackAlready = true;
                        if (items[i].Count < maxStackSize)
                        {
                            int itemCount = (int)items[i].Count;
                            if (countLeft - Math.Min(countLeft, (int)maxStackSize - itemCount) <= 0 || allowDuplicateStacks)
                            {
                                inventory.GameSave.IsChanged = true;
                                items[i].Count += (uint)Math.Min(countLeft, (int)maxStackSize - itemCount);
                                countLeft      -= Math.Min(countLeft, (int)maxStackSize - itemCount);
                                ItemPocketEventArgs args = new ItemPocketEventArgs();
                                args.Index      = i;
                                args.Item       = items[i];
                                args.PocketType = pocketType;
                                OnUpdateListViewItem(args);
                            }
                        }
                        else if (maxStackSize == 0)
                        {
                            inventory.GameSave.IsChanged = true;
                            items[i].Count += (uint)countLeft;
                            countLeft       = 0;
                            ItemPocketEventArgs args = new ItemPocketEventArgs();
                            args.Index      = i;
                            args.Item       = items[i];
                            args.PocketType = pocketType;
                            OnUpdateListViewItem(args);
                        }
                    }
                }
                if (ordered)
                {
                    for (int i = 0; (i < (int)pocketSize || pocketSize == 0) && countLeft > 0 && (allowDuplicateStacks || !hasStackAlready); i++)
                    {
                        if (i >= items.Count || GetOrder(items[i].ItemData) > GetOrder(itemData))
                        {
                            hasStackAlready = true;
                            if (maxStackSize == 0)
                            {
                                inventory.GameSave.IsChanged = true;
                                items.Insert(i, new Item(id, (uint)countLeft, this));
                                ItemPocketEventArgs args = new ItemPocketEventArgs();
                                args.Index      = i;
                                args.Item       = items[i];
                                args.PocketType = pocketType;
                                OnAddListViewItem(args);
                                countLeft = 0;
                            }
                            else
                            {
                                inventory.GameSave.IsChanged = true;
                                items.Insert(i, new Item(id, (uint)Math.Min(countLeft, maxStackSize), this));
                                ItemPocketEventArgs args = new ItemPocketEventArgs();
                                args.Index      = i;
                                args.Item       = items[i];
                                args.PocketType = pocketType;
                                OnAddListViewItem(args);
                                countLeft -= Math.Min(countLeft, (int)maxStackSize);
                            }
                        }
                    }
                }
                else
                {
                    for (int i = items.Count; (i < (int)pocketSize || pocketSize == 0) && countLeft > 0 && (allowDuplicateStacks || !hasStackAlready); i++)
                    {
                        hasStackAlready = true;
                        if (maxStackSize == 0)
                        {
                            inventory.GameSave.IsChanged = true;
                            items.Add(new Item(id, (uint)countLeft, this));
                            ItemPocketEventArgs args = new ItemPocketEventArgs();
                            args.Index      = i;
                            args.Item       = items[i];
                            args.PocketType = pocketType;
                            OnAddListViewItem(args);
                            countLeft = 0;
                        }
                        else
                        {
                            inventory.GameSave.IsChanged = true;
                            items.Add(new Item(id, (uint)Math.Min(countLeft, (int)maxStackSize), this));
                            ItemPocketEventArgs args = new ItemPocketEventArgs();
                            args.Index      = i;
                            args.Item       = items[i];
                            args.PocketType = pocketType;
                            OnAddListViewItem(args);
                            countLeft -= Math.Min(countLeft, (int)maxStackSize);
                        }
                    }
                }
                return(true);
            }
            return(false);
        }