Skip to content

Commit

Permalink
add loot-related hooks for ModNPC
Browse files Browse the repository at this point in the history
  • Loading branch information
blushiemagic committed Aug 15, 2015
1 parent 4b5a3be commit a94620e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
14 changes: 14 additions & 0 deletions patches/tModLoader/Terraria.ModLoader/ModNPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public Mod mod
internal string texture;
public int aiType = 0;
public int animationType = 0;
public int bossBag = -1;

public ModNPC()
{
Expand Down Expand Up @@ -68,5 +69,18 @@ public virtual void FindFrame(int frameHeight)
public virtual void HitEffect(int hitDirection, double damage)
{
}

public virtual bool PreNPCLoot()
{
return true;
}

public virtual void NPCLoot()
{
}

public virtual void BossLoot(ref string name, ref int potionType)
{
}
}
}
26 changes: 26 additions & 0 deletions patches/tModLoader/Terraria.ModLoader/NPCLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,41 @@ internal static bool PreNPCLoot(NPC npc)
return false;
}
}
if (IsModNPC(npc))
{
return npc.modNPC.PreNPCLoot();
}
return true;
}
//in Terraria.NPC.NPCLoot before heart and star drops add NPCLoader.NPCLoot(this);
internal static void NPCLoot(NPC npc)
{
if (IsModNPC(npc))
{
npc.modNPC.NPCLoot();
}
foreach (GlobalNPC globalNPC in globalNPCs)
{
globalNPC.NPCLoot(npc);
}
}
//in Terraria.NPC.NPCLoot after determing potion type call
// NPCLoader.BossLoot(this, ref name, ref num70);
internal static void BossLoot(NPC npc, ref string name, ref int potionType)
{
if (IsModNPC(npc))
{
npc.modNPC.BossLoot(ref name, ref potionType);
}
}
//in Terraria.NPC.DropBossBags after if statements setting bag type call
// NPCLoader.BossBag(this, ref num);
internal static void BossBag(NPC npc, ref int bagType)
{
if (IsModNPC(npc))
{
bagType = npc.modNPC.bossBag;
}
}
}
}
20 changes: 18 additions & 2 deletions patches/tModLoader/Terraria/NPC.cs.patch
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,31 @@
{
return;
}
@@ -57135,6 +57158,7 @@
@@ -57065,6 +57088,7 @@
{
num70 = 499;
}
+ NPCLoader.BossLoot(this, ref name, ref num70);
Item.NewItem((int)this.position.X, (int)this.position.Y, this.width, this.height, num70, stack5, false, 0, false, false);
int num71 = Main.rand.Next(5) + 5;
for (int num72 = 0; num72 < num71; num72++)
@@ -57135,6 +57159,7 @@
NetMessage.SendData(25, -1, -1, Lang.misc[32], 255, 50f, 255f, 130f, 0, 0, 0);
}
}
+ NPCLoader.NPCLoot(this);
if (this.type != 16 && this.type != 81 && this.type != 121 && Main.rand.Next(6) == 0 && this.lifeMax > 1 && this.damage > 0)
{
int num73 = (int)Player.FindClosest(this.position, this.width, this.height);
@@ -62274,6 +62298,11 @@
@@ -57329,6 +57354,7 @@
{
num = 3332;
}
+ NPCLoader.BossBag(this, ref num);
if (num > 0)
{
if (Main.netMode == 2)
@@ -62274,6 +62300,11 @@

public void HitEffect(int hitDirection = 0, double dmg = 10.0)
{
Expand Down

0 comments on commit a94620e

Please sign in to comment.