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

◆ PickAmmo() [1/2]

void Terraria.Player.PickAmmo ( Item sItem,
ref int projToShoot,
ref float speed,
ref bool canShoot,
ref int totalDamage,
ref float KnockBack,
out int usedAmmoItemId,
bool dontConsume = false )
inlinepackage

Definition at line 54079 of file Player.cs.

54080 {
54081 usedAmmoItemId = 0;
54082 Item item = ChooseAmmo(sItem);
54083 canShoot = item != null;
54084 bool shootWithNoAmmo = false;
54085 if (!canShoot && !ItemLoader.NeedsAmmo(sItem, this))
54086 {
54087 item = ContentSamples.ItemsByType[sItem.useAmmo];
54088 if (item.ammo == sItem.useAmmo)
54089 {
54090 shootWithNoAmmo = (canShoot = true);
54091 }
54092 }
54093 if (!canShoot)
54094 {
54095 return;
54096 }
54097 usedAmmoItemId = item.type;
54098 StatModifier ammoDamage = GetTotalDamage(item.DamageType);
54099 if (AmmoID.Sets.IsArrow[item.ammo])
54100 {
54101 ammoDamage = ammoDamage.CombineWith(arrowDamage);
54102 }
54103 if (AmmoID.Sets.IsBullet[item.ammo])
54104 {
54105 ammoDamage = ammoDamage.CombineWith(bulletDamage);
54106 }
54107 if (AmmoID.Sets.IsSpecialist[item.ammo])
54108 {
54109 ammoDamage = ammoDamage.CombineWith(specialistDamage);
54110 }
54111 ammoDamage.Base = 0f;
54112 ammoDamage.Flat = totalDamage;
54113 ref float Damage = ref ammoDamage.Flat;
54114 int pickedProjectileId = -1;
54116 {
54118 }
54119 else if (sItem.type == 1946)
54120 {
54121 projToShoot = 338 + item.type - 771;
54122 }
54123 else if (sItem.type == 3930)
54124 {
54125 projToShoot = 715 + item.type - AmmoID.Rocket;
54126 }
54127 else if (sItem.useAmmo == AmmoID.Rocket)
54128 {
54129 projToShoot += item.shoot;
54130 }
54131 else if (sItem.useAmmo == AmmoID.Solution)
54132 {
54133 projToShoot += item.shoot;
54134 }
54135 else if (item.shoot > 0)
54136 {
54137 projToShoot = item.shoot;
54138 }
54139 if (sItem.type == 3019 && projToShoot == 1)
54140 {
54141 projToShoot = 485;
54142 }
54143 if (sItem.type == 3052)
54144 {
54145 projToShoot = 495;
54146 }
54147 if (sItem.type == 4953 && projToShoot == 1)
54148 {
54149 projToShoot = 932;
54150 }
54151 if (sItem.type == 4381)
54152 {
54153 projToShoot = 819;
54154 }
54155 if (sItem.type == 4058 && projToShoot == 474)
54156 {
54157 projToShoot = 117;
54158 }
54159 if (projToShoot == 42)
54160 {
54161 if (item.type == 370)
54162 {
54163 projToShoot = 65;
54164 Damage += 5f;
54165 }
54166 else if (item.type == 408)
54167 {
54168 projToShoot = 68;
54169 Damage += 5f;
54170 }
54171 else if (item.type == 1246)
54172 {
54173 projToShoot = 354;
54174 Damage += 5f;
54175 }
54176 }
54177 if (inventory[selectedItem].type == 2888 && projToShoot == 1)
54178 {
54179 projToShoot = 469;
54180 }
54181 if (hasMoltenQuiver && projToShoot == 1)
54182 {
54183 projToShoot = 2;
54184 Damage += 2f;
54185 }
54186 speed += item.shootSpeed;
54187 if (magicQuiver && (sItem.useAmmo == AmmoID.Arrow || sItem.useAmmo == AmmoID.Stake))
54188 {
54189 KnockBack *= 1.1f;
54190 speed *= 1.1f;
54191 }
54192 if ((sItem.useAmmo == AmmoID.Arrow || sItem.useAmmo == AmmoID.Stake) && archery && speed < 20f)
54193 {
54194 speed *= 1.2f;
54195 if (speed > 20f)
54196 {
54197 speed = 20f;
54198 }
54199 }
54200 KnockBack += item.knockBack;
54202 totalDamage = (int)(ammoDamage.ApplyTo(item.damage) + 5E-06f);
54203 if (!dontConsume && !shootWithNoAmmo && item.consumable && !IsAmmoFreeThisShot(sItem, item, projToShoot))
54204 {
54205 CombinedHooks.OnConsumeAmmo(this, sItem, item);
54206 item.stack--;
54207 if (item.stack <= 0)
54208 {
54209 item.active = false;
54210 item.TurnToAir();
54211 }
54212 }
54213 }
static bool[] IsArrow
If true for a given item type (F:Terraria.Item.type), then items of that type are counted as arrows f...
Definition AmmoID.cs:118
static bool[] IsSpecialist
If true for a given item type (F:Terraria.Item.type), then items of that type are counted as speciali...
Definition AmmoID.cs:130
static bool[] IsBullet
If true for a given item type (F:Terraria.Item.type), then items of that type are counted as bullets ...
Definition AmmoID.cs:124
static int Arrow
Definition AmmoID.cs:137
static int Rocket
Definition AmmoID.cs:149
static int Stake
Definition AmmoID.cs:163
static int Solution
Definition AmmoID.cs:151
AmmoID entries represent ammo types. Ammo items that share the same AmmoID value assigned to F:Terrar...
Definition AmmoID.cs:11
static Dictionary< int, Item > ItemsByType
The default T:Terraria.Item for a given item type (F:Terraria.Item.type).
This class stores instances of various content types in a number of dictionaries. These instances ser...
static void OnConsumeAmmo(Player player, Item weapon, Item ammo)
static void PickAmmo(Item weapon, Item ammo, Player player, ref int type, ref float speed, ref StatModifier damage, ref float knockback)
Calls ModItem.PickAmmo, then all GlobalItem.PickAmmo hooks.
static bool NeedsAmmo(Item weapon, Player player)
Calls ModItem.NeedsAmmo, then all GlobalItem.NeedsAmmo hooks, until any of them returns false.
This serves as the central class from which item-related functions are carried out....
Definition ItemLoader.cs:26
bool hasMoltenQuiver
Definition Player.cs:2180
StatModifier GetTotalDamage(DamageClass damageClass)
Calculates a total damage modifier for the player for the provided T:Terraria.ModLoader....
Definition Player.cs:58396
bool PickAmmo_TryFindingSpecificMatches(int launcher, int ammo, out int pickedProjectileId)
Definition Player.cs:53992
StatModifier arrowDamage
Definition Player.cs:2605
StatModifier bulletDamage
Definition Player.cs:2607
StatModifier specialistDamage
Definition Player.cs:2609
bool IsAmmoFreeThisShot(Item weapon, Item ammo, int projToShoot)
Determines whether or not the given ammunition should be conserved, based on the given weapon as wiel...
Definition Player.cs:54222
Item ChooseAmmo(Item weapon)
Attempts to select an ammo item stack from this player's inventory to shoot with the given weapon.
Definition Player.cs:54039
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.Item.ammo, Terraria.Player.archery, Terraria.ID.AmmoID.Arrow, Terraria.Player.arrowDamage, Terraria.Player.bulletDamage, Terraria.Player.ChooseAmmo(), Terraria.Item.consumable, Terraria.GameContent.Damage, Terraria.Item.damage, Terraria.Item.DamageType, Terraria.Player.GetTotalDamage(), Terraria.Player.hasMoltenQuiver, Terraria.Player.inventory, Terraria.Player.IsAmmoFreeThisShot(), Terraria.ID.AmmoID.Sets.IsArrow, Terraria.ID.AmmoID.Sets.IsBullet, Terraria.ID.AmmoID.Sets.IsSpecialist, Terraria.ID.ContentSamples.ItemsByType, Terraria.Item.knockBack, Terraria.Player.magicQuiver, Terraria.ModLoader.ItemLoader.NeedsAmmo(), Terraria.ModLoader.CombinedHooks.OnConsumeAmmo(), Terraria.ModLoader.ItemLoader.PickAmmo(), Terraria.Player.PickAmmo_TryFindingSpecificMatches(), Terraria.ID.AmmoID.Rocket, Terraria.Player.selectedItem, Terraria.Item.shoot, Terraria.Item.shootSpeed, Terraria.ID.AmmoID.Solution, Terraria.Player.specialistDamage, Terraria.Item.stack, Terraria.ID.AmmoID.Stake, Terraria.Item.TurnToAir(), and Terraria.Item.type.

+ Here is the call graph for this function: