Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ Restock()

static void Terraria.UI.ChestUI.Restock ( )
inlinestatic

Definition at line 941 of file ChestUI.cs.

942 {
943 Player player = Main.player[Main.myPlayer];
944 Item[] inventory = player.inventory;
945 Item[] item = player.bank.item;
946 if (player.chest > -1)
947 {
948 item = Main.chest[player.chest].item;
949 }
950 else if (player.chest == -2)
951 {
952 item = player.bank.item;
953 }
954 else if (player.chest == -3)
955 {
956 item = player.bank2.item;
957 }
958 else if (player.chest == -4)
959 {
960 item = player.bank3.item;
961 }
962 else if (player.chest == -5)
963 {
964 item = player.bank4.item;
965 }
967 List<int> list = new List<int>();
968 List<int> list2 = new List<int>();
969 for (int num = 57; num >= 0; num--)
970 {
971 if ((num < 50 || num >= 54) && (inventory[num].type < 71 || inventory[num].type > 74))
972 {
973 if (inventory[num].stack > 0 && inventory[num].maxStack > 1 && inventory[num].prefix == 0)
974 {
975 hashSet.Add(inventory[num].netID);
976 if (inventory[num].stack < inventory[num].maxStack)
977 {
978 list.Add(num);
979 }
980 }
981 else if (inventory[num].stack == 0 || inventory[num].netID == 0 || inventory[num].type == 0)
982 {
983 list2.Add(num);
984 }
985 }
986 }
987 bool flag = false;
988 for (int i = 0; i < item.Length; i++)
989 {
990 if (item[i].stack < 1 || item[i].prefix != 0 || !hashSet.Contains(item[i].netID))
991 {
992 continue;
993 }
994 bool flag2 = false;
995 for (int j = 0; j < list.Count; j++)
996 {
997 int num2 = list[j];
998 int context = 0;
999 if (num2 >= 50)
1000 {
1001 context = 2;
1002 }
1003 if (inventory[num2].netID != item[i].netID || ItemSlot.PickItemMovementAction(inventory, context, num2, item[i]) == -1)
1004 {
1005 continue;
1006 }
1007 int num3 = item[i].stack;
1008 if (inventory[num2].maxStack - inventory[num2].stack < num3)
1009 {
1010 num3 = inventory[num2].maxStack - inventory[num2].stack;
1011 }
1012 inventory[num2].stack += num3;
1013 item[i].stack -= num3;
1014 flag = true;
1015 if (inventory[num2].stack == inventory[num2].maxStack)
1016 {
1017 if (Main.netMode == 1 && Main.player[Main.myPlayer].chest > -1)
1018 {
1019 NetMessage.SendData(32, -1, -1, null, Main.player[Main.myPlayer].chest, i);
1020 }
1021 list.RemoveAt(j);
1022 j--;
1023 }
1024 if (item[i].stack == 0)
1025 {
1026 item[i] = new Item();
1027 flag2 = true;
1028 if (Main.netMode == 1 && Main.player[Main.myPlayer].chest > -1)
1029 {
1030 NetMessage.SendData(32, -1, -1, null, Main.player[Main.myPlayer].chest, i);
1031 }
1032 break;
1033 }
1034 }
1035 if (flag2 || list2.Count <= 0 || item[i].ammo == 0)
1036 {
1037 continue;
1038 }
1039 for (int k = 0; k < list2.Count; k++)
1040 {
1041 int context2 = 0;
1042 if (list2[k] >= 50)
1043 {
1044 context2 = 2;
1045 }
1046 if (ItemSlot.PickItemMovementAction(inventory, context2, list2[k], item[i]) != -1)
1047 {
1048 Utils.Swap(ref inventory[list2[k]], ref item[i]);
1049 if (Main.netMode == 1 && Main.player[Main.myPlayer].chest > -1)
1050 {
1051 NetMessage.SendData(32, -1, -1, null, Main.player[Main.myPlayer].chest, i);
1052 }
1053 list.Add(list2[k]);
1054 list2.RemoveAt(k);
1055 flag = true;
1056 break;
1057 }
1058 }
1059 }
1060 if (flag)
1061 {
1063 }
1064 }
bool ICollection< KeyValuePair< TKey, TValue > >. Contains(KeyValuePair< TKey, TValue > keyValuePair)
void Add(TKey key, TValue value)
static void PlaySound(int type, Vector2 position, int style=1)

References System.Collections.Generic.Dictionary< TKey, TValue >.Add(), Terraria.Player.bank, Terraria.Player.bank2, Terraria.Player.bank3, Terraria.Player.bank4, Terraria.Main.chest, Terraria.Player.chest, System.Collections.Generic.Dictionary< TKey, TValue >.Contains(), System.Collections.Generic.Dictionary< TKey, TValue >.Count, Terraria.Player.inventory, Terraria.Chest.item, Terraria.Item.maxStack, Terraria.Main.myPlayer, Terraria.Main.netMode, Terraria.UI.ItemSlot.PickItemMovementAction(), Terraria.Main.player, Terraria.Audio.SoundEngine.PlaySound(), Terraria.NetMessage.SendData(), and Terraria.Item.stack.

Referenced by Terraria.UI.ChestUI.DrawButton().