Terraria.UI.ChestUI.QuickStack C# (CSharp) Method

QuickStack() public static method

public static QuickStack ( ) : void
return void
        public static void QuickStack()
        {
            Player player = Main.player[Main.myPlayer];
            if (player.chest == -3)
                ChestUI.MoveCoins(player.inventory, player.bank2.item);
            else if (player.chest == -2)
                ChestUI.MoveCoins(player.inventory, player.bank.item);
            Item[] objArray1 = player.inventory;
            Item[] objArray2 = player.bank.item;
            if (player.chest > -1)
                objArray2 = Main.chest[player.chest].item;
            else if (player.chest == -2)
                objArray2 = player.bank.item;
            else if (player.chest == -3)
                objArray2 = player.bank2.item;
            List<int> list1 = new List<int>();
            List<int> list2 = new List<int>();
            List<int> list3 = new List<int>();
            Dictionary<int, int> dictionary = new Dictionary<int, int>();
            List<int> list4 = new List<int>();
            bool[] flagArray = new bool[objArray2.Length];
            for (int index = 0; index < 40; ++index)
            {
                if (objArray2[index].itemId > 0 && objArray2[index].stack > 0 && objArray2[index].maxStack > 1 && (objArray2[index].itemId < 71 || objArray2[index].itemId > 74))
                {
                    list2.Add(index);
                    list1.Add(objArray2[index].netID);
                }
                if (objArray2[index].itemId == 0 || objArray2[index].stack <= 0)
                    list3.Add(index);
            }
            int num1 = 50;
            if (player.chest <= -2)
                num1 += 4;
            for (int key = 0; key < num1; ++key)
            {
                if (list1.Contains(objArray1[key].netID) && !objArray1[key].favorited)
                    dictionary.Add(key, objArray1[key].netID);
            }
            for (int index1 = 0; index1 < list2.Count; ++index1)
            {
                int index2 = list2[index1];
                int num2 = objArray2[index2].netID;
                foreach (KeyValuePair<int, int> keyValuePair in dictionary)
                {
                    if (keyValuePair.Value == num2 && objArray1[keyValuePair.Key].netID == num2)
                    {
                        int num3 = objArray1[keyValuePair.Key].stack;
                        int num4 = objArray2[index2].maxStack - objArray2[index2].stack;
                        if (num4 != 0)
                        {
                            if (num3 > num4)
                                num3 = num4;
                            Main.PlaySound(7, -1, -1, 1);
                            objArray2[index2].stack += num3;
                            objArray1[keyValuePair.Key].stack -= num3;
                            if (objArray1[keyValuePair.Key].stack == 0)
                                objArray1[keyValuePair.Key].SetDefaults(0, false);
                            flagArray[index2] = true;
                        }
                        else
                            break;
                    }
                }
            }
            foreach (KeyValuePair<int, int> keyValuePair in dictionary)
            {
                if (objArray1[keyValuePair.Key].stack == 0)
                    list4.Add(keyValuePair.Key);
            }
            foreach (int key in list4)
                dictionary.Remove(key);
            for (int index1 = 0; index1 < list3.Count; ++index1)
            {
                int index2 = list3[index1];
                bool flag = true;
                int num2 = objArray2[index2].netID;
                foreach (KeyValuePair<int, int> keyValuePair in dictionary)
                {
                    if (keyValuePair.Value == num2 && objArray1[keyValuePair.Key].netID == num2 || flag && objArray1[keyValuePair.Key].stack > 0)
                    {
                        Main.PlaySound(7, -1, -1, 1);
                        if (flag)
                        {
                            num2 = keyValuePair.Value;
                            objArray2[index2] = objArray1[keyValuePair.Key];
                            objArray1[keyValuePair.Key] = new Item();
                        }
                        else
                        {
                            int num3 = objArray1[keyValuePair.Key].stack;
                            int num4 = objArray2[index2].maxStack - objArray2[index2].stack;
                            if (num4 != 0)
                            {
                                if (num3 > num4)
                                    num3 = num4;
                                objArray2[index2].stack += num3;
                                objArray1[keyValuePair.Key].stack -= num3;
                                if (objArray1[keyValuePair.Key].stack == 0)
                                    objArray1[keyValuePair.Key] = new Item();
                            }
                            else
                                break;
                        }
                        flagArray[index2] = true;
                        flag = false;
                    }
                }
            }
            if (Main.netMode == 1 && player.chest >= 0)
            {
                for (int index = 0; index < flagArray.Length; ++index)
                    NetMessage.SendData(32, -1, -1, "", player.chest, (float)index, 0.0f, 0.0f, 0, 0, 0);
            }
            list1.Clear();
            list2.Clear();
            list3.Clear();
            dictionary.Clear();
            list4.Clear();
        }

Usage Example

Ejemplo n.º 1
0
        private static void DrawButton(SpriteBatch spriteBatch, int ID, int X, int Y)
        {
            Player player = Main.player[Main.myPlayer];

            if (ID == 4 && player.chest < -1 || ID == 5 && !Main.editChest)
            {
                ChestUI.UpdateHover(ID, false);
            }
            else
            {
                Y += ID * 26;
                float  num  = ChestUI.ButtonScale[ID];
                string text = "";
                switch (ID)
                {
                case 0:
                    text = Lang.inter[29];
                    break;

                case 1:
                    text = Lang.inter[30];
                    break;

                case 2:
                    text = Lang.inter[31];
                    break;

                case 3:
                    text = Lang.inter[82];
                    break;

                case 4:
                    text = Lang.inter[Main.editChest ? 47 : 61];
                    break;

                case 5:
                    text = Lang.inter[63];
                    break;
                }
                Vector2 vector2   = Main.fontMouseText.MeasureString(text);
                Color   color     = new Color((int)Main.mouseTextColor, (int)Main.mouseTextColor, (int)Main.mouseTextColor, (int)Main.mouseTextColor) * num;
                Color   baseColor = Color.White * 0.97f * (float)(1.0 - ((double)byte.MaxValue - (double)Main.mouseTextColor) / (double)byte.MaxValue * 0.5);
                baseColor.A = byte.MaxValue;
                X          += (int)((double)vector2.X * (double)num / 2.0);
                ChatManager.DrawColorCodedStringWithShadow(spriteBatch, Main.fontMouseText, text, new Vector2((float)X, (float)Y), baseColor, 0.0f, vector2 / 2f, new Vector2(num), -1f, 1.5f);
                vector2 *= num;
                if (!Utils.FloatIntersect((float)Main.mouseX, (float)Main.mouseY, 0.0f, 0.0f, (float)X - vector2.X / 2f, (float)Y - vector2.Y / 2f, vector2.X, vector2.Y))
                {
                    ChestUI.UpdateHover(ID, false);
                }
                else
                {
                    ChestUI.UpdateHover(ID, true);
                    player.mouseInterface = true;
                    if (!Main.mouseLeft || !Main.mouseLeftRelease)
                    {
                        return;
                    }
                    switch (ID)
                    {
                    case 0:
                        ChestUI.LootAll();
                        break;

                    case 1:
                        ChestUI.DepositAll();
                        break;

                    case 2:
                        ChestUI.QuickStack();
                        break;

                    case 3:
                        ChestUI.Restock();
                        break;

                    case 4:
                        ChestUI.RenameChest();
                        break;

                    case 5:
                        ChestUI.RenameChestCancel();
                        break;
                    }
                    Recipe.FindRecipes();
                }
            }
        }