示例#1
0
        public static void QuickStack(IContainerItem container, Func <Item, bool> selector = null)
        {
            if (Main.LocalPlayer.IsStackingItems())
            {
                return;
            }

            IList <Item> Items = container.GetItems();

            bool stacked = false;

            for (int i = 0; i < Items.Count; i++)
            {
                if (Items[i].type > 0 && Items[i].stack > 0 && !Items[i].favorited && (selector?.Invoke(Items[i]) ?? true))
                {
                    int type  = Items[i].type;
                    int stack = Items[i].stack;
                    Items[i] = Chest.PutItemInNearbyChest(Items[i], Main.LocalPlayer.Center);
                    if (Items[i].type != type || Items[i].stack != stack)
                    {
                        stacked = true;
                    }
                }
            }

            if (stacked)
            {
                Main.PlaySound(7);
            }

            NetUtility.SyncItem(container.GetItem().item);
        }
示例#2
0
        public static void QuickRestack(IContainerItem container)
        {
            if (Main.LocalPlayer.IsStackingItems())
            {
                return;
            }
            IList <Item> Items = container.GetItems();

            bool stacked = false;

            for (int i = 0; i < Items.Count; i++)
            {
                if (Items[i].type > 0 && Items[i].stack > 0)
                {
                    int type  = Items[i].type;
                    int stack = Items[i].stack;
                    Items[i] = TakeItemFromNearbyChest(Items[i], Main.LocalPlayer.Center);
                    if (Items[i].type != type || Items[i].stack != stack)
                    {
                        stacked = true;
                    }
                }
            }

            if (stacked)
            {
                Main.PlaySound(7);
            }

            NetUtility.SyncItem(container.GetItem().item);
        }
示例#3
0
        public static void DepositAll(IContainerItem container, Func <Item, bool> selector = null)
        {
            Player       player = Main.LocalPlayer;
            IList <Item> Items  = container.GetItems();

            MoveCoins(player.inventory, container);

            for (int pIndex = 49; pIndex >= 10; pIndex--)
            {
                if (player.inventory[pIndex].stack > 0 && player.inventory[pIndex].type > 0 && !player.inventory[pIndex].favorited && (selector?.Invoke(player.inventory[pIndex]) ?? true))
                {
                    if (player.inventory[pIndex].maxStack > 1)
                    {
                        for (int bIndex = 0; bIndex < Items.Count; bIndex++)
                        {
                            if (Items[bIndex].stack < Items[bIndex].maxStack && player.inventory[pIndex].IsTheSameAs(Items[bIndex]))
                            {
                                int stack = player.inventory[pIndex].stack;
                                if (player.inventory[pIndex].stack + Items[bIndex].stack > Items[bIndex].maxStack)
                                {
                                    stack = Items[bIndex].maxStack - Items[bIndex].stack;
                                }

                                player.inventory[pIndex].stack -= stack;
                                Items[bIndex].stack            += stack;
                                Main.PlaySound(7);

                                if (player.inventory[pIndex].stack <= 0)
                                {
                                    player.inventory[pIndex].SetDefaults();
                                    break;
                                }
                                if (Items[bIndex].type == 0)
                                {
                                    Items[bIndex] = player.inventory[pIndex].Clone();
                                    player.inventory[pIndex].SetDefaults();
                                }
                            }
                        }
                    }
                    if (player.inventory[pIndex].stack > 0)
                    {
                        for (int bIndex = 0; bIndex < Items.Count; bIndex++)
                        {
                            if (Items[bIndex].stack == 0)
                            {
                                Main.PlaySound(7);
                                Items[bIndex] = player.inventory[pIndex].Clone();
                                player.inventory[pIndex].SetDefaults();
                                break;
                            }
                        }
                    }
                }
            }

            NetUtility.SyncItem(container.GetItem().item);
        }
示例#4
0
        public static void LootAll(IContainerItem container, Func <Item, bool> selector = null)
        {
            Player       player = Main.LocalPlayer;
            IList <Item> Items  = container.GetItems();

            for (int i = 0; i < Items.Count; i++)
            {
                if (Items[i].type > 0 && (selector?.Invoke(Items[i]) ?? true))
                {
                    Items[i].position = player.Center;
                    Items[i]          = player.GetItem(Main.myPlayer, Items[i]);
                }
            }

            NetUtility.SyncItem(container.GetItem().item);
        }
示例#5
0
        public static void Restock(IContainerItem container)
        {
            Player player = Main.LocalPlayer;

            Item[]       inventory = player.inventory;
            IList <Item> item      = container.GetItems();

            HashSet <int> restackableItems = new HashSet <int>();
            List <int>    canRestackIndex  = new List <int>();
            List <int>    list2            = new List <int>();

            for (int i = 57; i >= 0; i--)
            {
                if ((i < 50 || i >= 54) && (inventory[i].type < 71 || inventory[i].type > 74))
                {
                    if (inventory[i].stack > 0 && inventory[i].maxStack > 1 && inventory[i].prefix == 0)
                    {
                        restackableItems.Add(inventory[i].netID);
                        if (inventory[i].stack < inventory[i].maxStack)
                        {
                            canRestackIndex.Add(i);
                        }
                    }
                    else if (inventory[i].stack == 0 || inventory[i].netID == 0 || inventory[i].type == 0)
                    {
                        list2.Add(i);
                    }
                }
            }
            bool restocked = false;

            for (int j = 0; j < item.Count; j++)
            {
                if (item[j].stack >= 1 && item[j].prefix == 0 && restackableItems.Contains(item[j].netID))
                {
                    bool flag2 = false;
                    for (int k = 0; k < canRestackIndex.Count; k++)
                    {
                        int num     = canRestackIndex[k];
                        int context = 0;
                        if (num >= 50)
                        {
                            context = 2;
                        }
                        if (inventory[num].netID == item[j].netID && ItemSlot.PickItemMovementAction(inventory, context, num, item[j]) != -1)
                        {
                            int num2 = item[j].stack;
                            if (inventory[num].maxStack - inventory[num].stack < num2)
                            {
                                num2 = inventory[num].maxStack - inventory[num].stack;
                            }
                            inventory[num].stack += num2;
                            item[j].stack        -= num2;
                            restocked             = true;
                            if (inventory[num].stack == inventory[num].maxStack)
                            {
                                canRestackIndex.RemoveAt(k);
                                k--;
                            }
                            if (item[j].stack == 0)
                            {
                                item[j] = new Item();
                                flag2   = true;
                                break;
                            }
                        }
                    }
                    if (!flag2 && list2.Count > 0 && item[j].ammo != 0)
                    {
                        for (int l = 0; l < list2.Count; l++)
                        {
                            int context2 = 0;
                            if (list2[l] >= 50)
                            {
                                context2 = 2;
                            }
                            if (ItemSlot.PickItemMovementAction(inventory, context2, list2[l], item[j]) != -1)
                            {
                                Item temp = inventory[list2[l]];
                                inventory[list2[l]] = item[j];
                                item[j]             = temp;

                                canRestackIndex.Add(list2[l]);
                                list2.RemoveAt(l);
                                restocked = true;
                                break;
                            }
                        }
                    }
                }
            }
            if (restocked)
            {
                Main.PlaySound(7);
            }

            NetUtility.SyncItem(container.GetItem().item);
        }