Terraria v1.4.4.9
Terraria source code documentation
All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros

◆ DropItemFromNPC()

static void Terraria.GameContent.ItemDropRules.CommonCode.DropItemFromNPC ( NPC npc,
int itemId,
int stack,
bool scattered = false )
inlinestatic

Definition at line 9 of file CommonCode.cs.

10 {
11 if (itemId > 0 && itemId < ItemID.Count)
12 {
13 int x = (int)npc.position.X + npc.width / 2;
14 int y = (int)npc.position.Y + npc.height / 2;
15 if (scattered)
16 {
17 x = (int)npc.position.X + Main.rand.Next(npc.width + 1);
18 y = (int)npc.position.Y + Main.rand.Next(npc.height + 1);
19 }
20 int itemIndex = Item.NewItem(npc.GetItemSource_Loot(), x, y, 0, 0, itemId, stack, noBroadcast: false, -1);
21 ModifyItemDropFromNPC(npc, itemIndex);
22 }
23 }
static void ModifyItemDropFromNPC(NPC npc, int itemIndex)
Definition CommonCode.cs:76
static readonly short Count
Definition ItemID.cs:12138

References Terraria.ID.ItemID.Count, Terraria.NPC.GetItemSource_Loot(), Terraria.Entity.height, Terraria.GameContent.ItemDropRules.CommonCode.ModifyItemDropFromNPC(), Terraria.Item.NewItem(), Terraria.Entity.position, Terraria.Main.rand, Terraria.Entity.width, Microsoft.Xna.Framework.Vector2.X, and Microsoft.Xna.Framework.Vector2.Y.

Referenced by Terraria.GameContent.ItemDropRules.CommonCode.DropItemForEachInteractingPlayerOnThePlayer(), Terraria.GameContent.ItemDropRules.CommonCode.DropItemLocalPerClientAndSetNPCMoneyTo0(), Terraria.GameContent.ItemDropRules.CommonDrop.TryDroppingItem(), Terraria.GameContent.ItemDropRules.CommonDropNotScalingWithLuck.TryDroppingItem(), Terraria.GameContent.ItemDropRules.CommonDropWithRerolls.TryDroppingItem(), Terraria.GameContent.ItemDropRules.DropOneByOne.TryDroppingItem(), Terraria.GameContent.ItemDropRules.FromOptionsWithoutRepeatsDropRule.TryDroppingItem(), Terraria.GameContent.ItemDropRules.MechBossSpawnersDropRule.TryDroppingItem(), Terraria.GameContent.ItemDropRules.OneFromOptionsDropRule.TryDroppingItem(), Terraria.GameContent.ItemDropRules.OneFromOptionsNotScaledWithLuckDropRule.TryDroppingItem(), and Terraria.GameContent.ItemDropRules.SlimeBodyItemDropRule.TryDroppingItem().