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

◆ ChooseAmmo()

Item Terraria.Player.ChooseAmmo ( Item weapon)
inline

Attempts to select an ammo item stack from this player's inventory to shoot with the given weapon.

Parameters
weaponThe weapon for which this call should try to find ammo.
Returns
Null if no suitable ammo is found; otherwise, returns the first ammo item found.

Definition at line 54039 of file Player.cs.

54040 {
54041 Item item = null;
54042 bool flag = false;
54043 if (weapon.useAmmo == AmmoID.Coin)
54044 {
54045 for (int i = 0; i < 4; i++)
54046 {
54047 int num = 50 + i;
54048 if (inventory[num].stack > 0 && ItemLoader.CanChooseAmmo(weapon, inventory[i], this))
54049 {
54050 item = inventory[num];
54051 flag = true;
54052 break;
54053 }
54054 }
54055 }
54056 for (int j = 54; j < 58; j++)
54057 {
54058 if (inventory[j].stack > 0 && ItemLoader.CanChooseAmmo(weapon, inventory[j], this))
54059 {
54060 item = inventory[j];
54061 flag = true;
54062 break;
54063 }
54064 }
54065 if (!flag)
54066 {
54067 for (int k = 0; k < 54; k++)
54068 {
54069 if (inventory[k].stack > 0 && ItemLoader.CanChooseAmmo(weapon, inventory[k], this))
54070 {
54071 item = inventory[k];
54072 break;
54073 }
54074 }
54075 }
54076 return item;
54077 }
static int Coin
Definition AmmoID.cs:139
AmmoID entries represent ammo types. Ammo items that share the same AmmoID value assigned to F:Terrar...
Definition AmmoID.cs:11
static bool CanChooseAmmo(Item weapon, Item ammo, Player player)
Calls each M:Terraria.ModLoader.GlobalItem.CanChooseAmmo(Terraria.Item,Terraria.Item,...
This serves as the central class from which item-related functions are carried out....
Definition ItemLoader.cs:26
Item[] inventory
The player's normal inventory. Indexes 0-9 hold the hotbar items, 10-49 the rest of the main inventor...
Definition Player.cs:1767

References Terraria.ModLoader.ItemLoader.CanChooseAmmo(), Terraria.ID.AmmoID.Coin, and Terraria.Player.inventory.

Referenced by Terraria.Player.HasAmmo(), and Terraria.Player.PickAmmo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: