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

◆ FillAmmoFromInventory()

static void Terraria.UI.ItemSorting.FillAmmoFromInventory ( )
inlinestatic

Definition at line 1227 of file ItemSorting.cs.

1228 {
1229 List<int> list = new List<int>();
1230 List<int> list2 = new List<int>();
1231 Item[] inventory = Main.player[Main.myPlayer].inventory;
1232 for (int i = 54; i < 58; i++)
1233 {
1234 ItemSlot.SetGlow(i, 0.31f, chest: false);
1235 Item item = inventory[i];
1236 if (item.IsAir)
1237 {
1238 list2.Add(i);
1239 }
1240 else if (item.ammo != AmmoID.None)
1241 {
1242 if (!list.Contains(item.type))
1243 {
1244 list.Add(item.type);
1245 }
1246 RefillItemStack(inventory, inventory[i], 0, 50);
1247 }
1248 }
1249 if (list2.Count < 1)
1250 {
1251 return;
1252 }
1253 for (int j = 0; j < 50; j++)
1254 {
1255 Item item2 = inventory[j];
1256 if (item2.stack >= 1 && item2.CanFillEmptyAmmoSlot() && list.Contains(item2.type))
1257 {
1258 int num = list2[0];
1259 list2.Remove(num);
1260 Utils.Swap(ref inventory[j], ref inventory[num]);
1261 RefillItemStack(inventory, inventory[num], 0, 50);
1262 if (list2.Count == 0)
1263 {
1264 break;
1265 }
1266 }
1267 }
1268 if (list2.Count < 1)
1269 {
1270 return;
1271 }
1272 for (int k = 0; k < 50; k++)
1273 {
1274 Item item3 = inventory[k];
1275 if (item3.stack >= 1 && item3.CanFillEmptyAmmoSlot() && item3.FitsAmmoSlot())
1276 {
1277 int num2 = list2[0];
1278 list2.Remove(num2);
1279 Utils.Swap(ref inventory[k], ref inventory[num2]);
1280 RefillItemStack(inventory, inventory[num2], 0, 50);
1281 if (list2.Count == 0)
1282 {
1283 break;
1284 }
1285 }
1286 }
1287 }
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
bool ICollection< KeyValuePair< TKey, TValue > >. Contains(KeyValuePair< TKey, TValue > keyValuePair)
void Add(TKey key, TValue value)
static int None
Definition AmmoID.cs:104
static void RefillItemStack(Item[] inv, Item itemToRefill, int loopStartIndex, int loopEndIndex)

References System.Collections.Generic.Dictionary< TKey, TValue >.Add(), System.Collections.Generic.Dictionary< TKey, TValue >.Contains(), System.Collections.Generic.Dictionary< TKey, TValue >.Count, System.item, System.list, Terraria.Main.myPlayer, Terraria.ID.AmmoID.None, Terraria.Main.player, Terraria.UI.ItemSorting.RefillItemStack(), System.Collections.Generic.Dictionary< TKey, TValue >.Remove(), and Terraria.UI.ItemSlot.SetGlow().

Referenced by Terraria.UI.ItemSorting.SortAmmo().