-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModPlayer.cs
More file actions
43 lines (40 loc) · 2.01 KB
/
ModPlayer.cs
File metadata and controls
43 lines (40 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using MechThrowverhaul.Items;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ModLoader.IO;
namespace MechThrowverhaul
{
public class ThrowPlayer : ModPlayer
{
public Vector2 ManufacturingTable;
public bool UIOpen;
public int Restock(int stock, int type)
{
for (int i = 0; i < Main.maxInventory; i++) // loops through the player's inventory
{
Item currentItem = player.inventory[i];
// determines if the item:
if (currentItem.active && currentItem.type != ItemID.None && (currentItem.type == type || type == 0)) // Exists and matches the item type or is universal,
{
ThrowingWeapons thrownItem = currentItem.GetGlobalItem<ThrowingWeapons>();
if (thrownItem.throwverhauled == true && // has been throwverhauled,
thrownItem.throwStack < thrownItem.maxStack) // and hasn't already met the max ammo count
{
thrownItem.throwStack += stock; // increases the current stack by the value of "stock"
stock -= stock; // reduces the stock to 0 because it should be empty
if (thrownItem.throwStack > thrownItem.maxStack) // if the ammo count is increased above the maximum
{
stock += thrownItem.throwStack - thrownItem.maxStack; // stock is increased by the remainder / the extra change
// this extra change is used to restock more throwing weapons in the inventory
thrownItem.throwStack = thrownItem.maxStack; // set ammo count back to max
}
if (stock <= 0) break; // if there is no stock left, no point in continuing
}
}
}
return stock;
}
}
}