Beispiel #1
0
        public static void SortChest()
        {
            int chest = Main.player[Main.myPlayer].chest;

            if (chest == -1)
            {
                return;
            }
            Item[] inv = Main.player[Main.myPlayer].bank.item;
            if (chest == -3)
            {
                inv = Main.player[Main.myPlayer].bank2.item;
            }
            if (chest == -4)
            {
                inv = Main.player[Main.myPlayer].bank3.item;
            }
            if (chest > -1)
            {
                inv = Main.chest[chest].item;
            }
            Tuple <int, int, int>[] tupleArray1 = new Tuple <int, int, int> [40];
            for (int index = 0; index < 40; ++index)
            {
                tupleArray1[index] = Tuple.Create <int, int, int>(inv[index].netID, inv[index].stack, (int)inv[index].prefix);
            }
            ItemSorting.Sort(inv);
            Tuple <int, int, int>[] tupleArray2 = new Tuple <int, int, int> [40];
            for (int index = 0; index < 40; ++index)
            {
                tupleArray2[index] = Tuple.Create <int, int, int>(inv[index].netID, inv[index].stack, (int)inv[index].prefix);
            }
            if (Main.netMode != 1 || Main.player[Main.myPlayer].chest <= -1)
            {
                return;
            }
            for (int index = 0; index < 40; ++index)
            {
                if (tupleArray2[index] != tupleArray1[index])
                {
                    NetMessage.SendData(32, -1, -1, (NetworkText)null, Main.player[Main.myPlayer].chest, (float)index, 0.0f, 0.0f, 0, 0, 0);
                }
            }
        }
Beispiel #2
0
 public static void SortInventory()
 {
     ItemSorting.Sort(Main.player[Main.myPlayer].inventory, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 50, 51, 52, 53, 54, 55, 56, 57, 58);
 }
Beispiel #3
0
        private static void Sort(Item[] inv, params int[] ignoreSlots)
        {
            ItemSorting.SetupSortingPriorities();
            List <int> intList1 = new List <int>();

            for (int index = 0; index < inv.Length; ++index)
            {
                if (!((IEnumerable <int>)ignoreSlots).Contains <int>(index))
                {
                    Item obj = inv[index];
                    if (obj != null && obj.stack != 0 && (obj.type != 0 && !obj.favorited))
                    {
                        intList1.Add(index);
                    }
                }
            }
            for (int index1 = 0; index1 < intList1.Count; ++index1)
            {
                Item obj1 = inv[intList1[index1]];
                if (obj1.stack < obj1.maxStack)
                {
                    int num1 = obj1.maxStack - obj1.stack;
                    for (int index2 = index1; index2 < intList1.Count; ++index2)
                    {
                        if (index1 != index2)
                        {
                            Item obj2 = inv[intList1[index2]];
                            if (obj1.type == obj2.type && obj2.stack != obj2.maxStack)
                            {
                                int num2 = obj2.stack;
                                if (num1 < num2)
                                {
                                    num2 = num1;
                                }
                                obj1.stack += num2;
                                obj2.stack -= num2;
                                num1       -= num2;
                                if (obj2.stack == 0)
                                {
                                    inv[intList1[index2]] = new Item();
                                    intList1.Remove(intList1[index2]);
                                    --index1;
                                    int num3 = index2 - 1;
                                    break;
                                }
                                if (num1 == 0)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            List <int> intList2 = new List <int>((IEnumerable <int>)intList1);

            for (int index = 0; index < inv.Length; ++index)
            {
                if (!((IEnumerable <int>)ignoreSlots).Contains <int>(index) && !intList2.Contains(index))
                {
                    Item obj = inv[index];
                    if (obj == null || obj.stack == 0 || obj.type == 0)
                    {
                        intList2.Add(index);
                    }
                }
            }
            intList2.Sort();
            List <int> intList3 = new List <int>();
            List <int> intList4 = new List <int>();

            foreach (ItemSorting.ItemSortingLayer layer in ItemSorting._layerList)
            {
                List <int> intList5 = layer.SortingMethod(layer, inv, intList1);
                if (intList5.Count > 0)
                {
                    intList4.Add(intList5.Count);
                }
                intList3.AddRange((IEnumerable <int>)intList5);
            }
            intList3.AddRange((IEnumerable <int>)intList1);
            List <Item> objList = new List <Item>();

            foreach (int index in intList3)
            {
                objList.Add(inv[index]);
                inv[index] = new Item();
            }
            float num4 = 1f / (float)intList4.Count;
            float hue  = num4 / 2f;

            for (int index1 = 0; index1 < objList.Count; ++index1)
            {
                int index2 = intList2[0];
                ItemSlot.SetGlow(index2, hue, Main.player[Main.myPlayer].chest != -1);
                List <int> intList5 = intList4;
                int        index3   = 0;
                int        num1     = intList5[index3];
                int        index4   = 0;
                int        num2     = num1 - 1;
                intList5[index4] = num2;
                if (intList4[0] == 0)
                {
                    intList4.RemoveAt(0);
                    hue += num4;
                }
                inv[index2] = objList[index1];
                intList2.Remove(index2);
            }
        }