1using Microsoft.Xna.Framework;
2using Microsoft.Xna.Framework.Graphics;
5using System.Text.RegularExpressions;
7using Terraria.Localization;
53 public virtual string Texture => (GetType().Namespace +
"." +
Name).Replace(
'.',
'/');
125 internal void SetupNPC(NPC
npc) {
156 clone.npc = npcClone;
160 ModNPC copy = (
ModNPC)Activator.CreateInstance(GetType());
197 if (
npc.lifeMax > 32767 ||
npc.boss) {
198 Main.npcLifeBytes[
npc.type] = 4;
200 else if (
npc.lifeMax > 127) {
201 Main.npcLifeBytes[
npc.type] = 2;
204 Main.npcLifeBytes[
npc.type] = 1;
208 int altTextureCount = altTextures.Length;
209 NPCID.Sets.ExtraTextureCount[
npc.type] = altTextureCount;
210 Main.npcAltTextures[
npc.type] =
new Texture2D[altTextureCount + 1];
211 if (altTextureCount > 0) {
212 Main.npcAltTextures[
npc.type][0] = Main.npcTexture[
npc.type];
214 for (
int k = 1; k <= altTextureCount; k++) {
247 public virtual void AI() {
280 public virtual void HitEffect(
int hitDirection,
double damage) {
341 public virtual void BossLoot(ref
string name, ref
int potionType) {
350 public virtual bool CanHitPlayer(Player target, ref
int cooldownSlot) {
369 public virtual void OnHitPlayer(Player target,
int damage,
bool crit) {
388 public virtual void ModifyHitNPC(NPC target, ref
int damage, ref
float knockback, ref
bool crit) {
398 public virtual void OnHitNPC(NPC target,
int damage,
float knockback,
bool crit) {
419 public virtual void ModifyHitByItem(Player player, Item item, ref
int damage, ref
float knockback, ref
bool crit) {
430 public virtual void OnHitByItem(Player player, Item item,
int damage,
float knockback,
bool crit) {
450 public virtual void ModifyHitByProjectile(Projectile projectile, ref
int damage, ref
float knockback, ref
bool crit, ref
int hitDirection) {
460 public virtual void OnHitByProjectile(Projectile projectile,
int damage,
float knockback,
bool crit) {
472 public virtual bool StrikeNPC(ref
double damage,
int defense, ref
float knockback,
int hitDirection, ref
bool crit) {
519 public virtual bool PreDraw(SpriteBatch spriteBatch, Color drawColor) {
528 public virtual void PostDraw(SpriteBatch spriteBatch, Color drawColor) {
547 public virtual bool?
DrawHealthBar(
byte hbPosition, ref
float scale, ref Vector2 position) {
566 public virtual int SpawnNPC(
int tileX,
int tileY) {
567 return NPC.NewNPC(tileX * 16 + 8, tileY * 16,
npc.type);
597 return Language.GetTextValue(
"tModLoader.DefaultTownNPCName");
621 return Language.GetTextValue(
"tModLoader.DefaultTownNPCChat");
645 public virtual void SetupShop(Chest shop, ref
int nextSlot) {
735 public virtual void DrawTownAttackSwing(ref Texture2D item, ref
int itemSize, ref
float scale, ref Vector2 offset) {
Manages content added by mods. Liasons between mod content and Terraria's arrays and oversees the Loa...
static Texture2D GetTexture(string name)
Gets the texture with the specified name. The name is in the format of "ModFolder/OtherFolders/FileNa...
Mod is an abstract class that you will override. It serves as a central place from which the mod's co...
string DisplayName
The display name of this mod in the Mods menu.
This class serves as a place for you to place all your properties and hooks for each NPC....
virtual ? Color GetAlpha(Color drawColor)
Allows you to determine the color and transparency in which this NPC is drawn. Return null to use the...
virtual void PostDraw(SpriteBatch spriteBatch, Color drawColor)
Allows you to draw things in front of this NPC. This method is called even if PreDraw returns false.
virtual void NPCLoot()
Allows you to make things happen when this NPC dies (for example, dropping items and setting ModWorld...
virtual void DrawTownAttackSwing(ref Texture2D item, ref int itemSize, ref float scale, ref Vector2 offset)
Allows you to customize how this town NPC's weapon is drawn when this NPC is swinging it (this NPC mu...
virtual void BossHeadSlot(ref int index)
Allows you to customize the boss head texture used by this NPC based on its state....
virtual void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit)
Allows you to modify the damage, knockback, etc., that this NPC does to a friendly NPC.
virtual bool UsesPartyHat()
Allows you to determine whether this town NPC wears a party hat during a party. Returns true by defau...
virtual string TownNPCName()
Allows you to give this town NPC any name when it spawns. By default returns something embarrassing.
virtual void OnChatButtonClicked(bool firstButton, ref bool shop)
Allows you to make something happen whenever a button is clicked on this NPC's chat window....
virtual void TownNPCAttackStrength(ref int damage, ref float knockback)
Allows you to determine the damage and knockback of this town NPC's attack before the damage is scale...
virtual void DrawBehind(int index)
When used in conjunction with "npc.hide = true", allows you to specify that this npc should be drawn ...
virtual void HitEffect(int hitDirection, double damage)
Allows you to make things happen whenever this NPC is hit, such as creating dust or gores....
virtual void TownNPCAttackCooldown(ref int cooldown, ref int randExtraCooldown)
Allows you to determine the cooldown between each of this town NPC's attack. The cooldown will be a n...
virtual void OnHitNPC(NPC target, int damage, float knockback, bool crit)
Allows you to create special effects when this NPC hits a friendly NPC.
NPC npc
The NPC object that this ModNPC controls.
virtual void FindFrame(int frameHeight)
Allows you to modify the frame from this NPC's texture that is drawn, which is necessary in order to ...
virtual bool CanHitPlayer(Player target, ref int cooldownSlot)
Allows you to determine whether this NPC can hit the given player. Return false to block this NPC fro...
virtual ModNPC Clone()
Returns a clone of this ModNPC. Allows you to decide which fields of your ModNPC class are copied ove...
virtual void TownNPCAttackProjSpeed(ref float multiplier, ref float gravityCorrection, ref float randomOffset)
Allows you to determine the speed at which this town NPC throws a projectile when it attacks....
virtual void ReceiveExtraAI(BinaryReader reader)
Use this to receive information that was sent in SendExtraAI.
MusicPriority musicPriority
The priority of the music that plays when this NPC is on or near the screen.
virtual void OnHitPlayer(Player target, int damage, bool crit)
Allows you to create special effects when this NPC hits a player (for example, inflicting debuffs).
virtual ? bool CanBeHitByProjectile(Projectile projectile)
Allows you to determine whether this NPC can be hit by the given projectile. Return true to allow hit...
int banner
The type of NPC that this NPC will be considered as when determining banner drops and banner bonuses....
virtual void DrawEffects(ref Color drawColor)
Allows you to add special visual effects to this NPC (such as creating dust), and modify the color in...
virtual string HeadTexture
The file name of this NPC's head texture file, to be used in autoloading.
virtual bool PreAI()
Allows you to determine how this NPC behaves. Return false to stop the vanilla AI and the AI hook fro...
virtual string Texture
The file name of this NPC's texture file in the mod loader's file space.
virtual void DrawTownAttackGun(ref float scale, ref int item, ref int closeness)
Allows you to customize how this town NPC's weapon is drawn when this NPC is shooting (this NPC must ...
virtual bool CloneNewInstances
Whether instances of this ModNPC are created through a memberwise clone or its constructor....
virtual void TownNPCAttackSwing(ref int itemWidth, ref int itemHeight)
Allows you to determine the width and height of the item this town NPC swings when it attacks,...
virtual bool StrikeNPC(ref double damage, int defense, ref float knockback, int hitDirection, ref bool crit)
Allows you to use a custom damage formula for when this NPC takes damage from any source....
int animationType
Determines which type of vanilla NPC this ModNPC will copy the animation (FindFrame) of....
virtual void ResetEffects()
This is where you reset any fields you add to your subclass to their default states....
virtual bool CheckConditions(int left, int right, int top, int bottom)
Allows you to define special conditions required for this town NPC's house. For example,...
virtual bool SpecialNPCLoot()
Allows you to call NPCLoot on your own when the NPC dies, rather then letting vanilla call it on its ...
int bannerItem
The type of the item this NPC drops for every 50 times it is defeated. For any ModNPC whose banner fi...
virtual void BossHeadSpriteEffects(ref SpriteEffects spriteEffects)
Allows you to flip this NPC's boss head icon on the map.
virtual void TownNPCAttackShoot(ref bool inBetweenShots)
Allows you to tell the game that this town NPC has already created a projectile and will still create...
virtual void ModifyHitPlayer(Player target, ref int damage, ref bool crit)
Allows you to modify the damage, etc., that this NPC does to a player.
virtual bool CanTownNPCSpawn(int numTownNPCs, int money)
Whether or not the conditions have been met for this town NPC to be able to move into town....
virtual void SetupShop(Chest shop, ref int nextSlot)
Allows you to add items to this NPC's shop. Add an item by setting the defaults of shop....
float drawOffsetY
The vertical offset used for drawing this NPC. Defaults to 0.
virtual bool CanChat()
Allows you to determine whether this NPC can talk with the player. By default, returns if the NPC is ...
virtual void AutoStaticDefaults()
Automatically sets certain static defaults. Override this if you do not want the properties to be set...
string Name
The internal name of this NPC.
int aiType
Determines which type of vanilla NPC this ModNPC will copy the behavior (AI) of. Leave as 0 to not co...
virtual void UpdateLifeRegen(ref int damage)
Allows you to make the NPC either regenerate health or take damage over time by setting npc....
ModNPC()
ModNPC constructor.
virtual void SetDefaults()
Allows you to set all your NPC's properties, such as width, damage, aiStyle, lifeMax,...
virtual void AI()
Allows you to determine how this NPC behaves. This will only be called if PreAI returns true.
virtual void ModifyHitByProjectile(Projectile projectile, ref int damage, ref float knockback, ref bool crit, ref int hitDirection)
Allows you to modify the damage, knockback, etc., that this NPC takes from a projectile....
virtual bool PreDraw(SpriteBatch spriteBatch, Color drawColor)
Allows you to draw things behind this NPC, or to modify the way this NPC is drawn....
virtual bool PreNPCLoot()
Allows you to determine whether or not this NPC will drop anything at all. Return false to stop the N...
virtual void OnHitByProjectile(Projectile projectile, int damage, float knockback, bool crit)
Allows you to create special effects when this NPC is hit by a projectile.
Mod mod
The mod that added this ModNPC.
virtual ? bool CanHitNPC(NPC target)
Allows you to determine whether this NPC can hit the given friendly NPC. Return true to allow hitting...
virtual bool Autoload(ref string name)
Allows you to automatically load an NPC instead of using Mod.AddNPC. Return true to allow autoloading...
virtual string GetChat()
Allows you to give this NPC a chat message when a player talks to it. By default returns something em...
virtual void SetChatButtons(ref string button, ref string button2)
Allows you to set the text for the buttons that appear on this NPC's chat window. A parameter left as...
int music
The ID of the music that plays when this NPC is on or near the screen. Defaults to -1,...
virtual void ModifyHitByItem(Player player, Item item, ref int damage, ref float knockback, ref bool crit)
Allows you to modify the damage, knockback, etc., that this NPC takes from a melee weapon.
virtual ModNPC NewInstance(NPC npcClone)
Create a new instance of this ModNPC for an NPC instance. Called at the end of NPC....
ModTranslation DisplayName
The translations for the display name of this NPC.
int bossBag
The item type of the boss bag that is dropped when DropBossBags is called for this NPC.
virtual ? bool DrawHealthBar(byte hbPosition, ref float scale, ref Vector2 position)
Allows you to control how the health bar for this NPC is drawn. The hbPosition parameter is the same ...
virtual string BossHeadTexture
This file name of this NPC's boss head texture file, to be used in autoloading.
virtual void BossHeadRotation(ref float rotation)
Allows you to customize the rotation of this NPC's boss head icon on the map.
virtual void TownNPCAttackProj(ref int projType, ref int attackDelay)
Allows you to determine the projectile type of this town NPC's attack, and how long it takes for the ...
virtual int SpawnNPC(int tileX, int tileY)
Allows you to customize how this NPC is created when it naturally spawns (for example,...
virtual void TownNPCAttackMagic(ref float auraLightMultiplier)
Allows you to control the brightness of the light emitted by this town NPC's aura when it performs a ...
virtual void OnCatchNPC(Player player, Item item)
Allows you to make things happen when this NPC is caught. Ran Serverside
virtual ? bool CanBeHitByItem(Player player, Item item)
Allows you to determine whether this NPC can be hit by the given melee weapon when swung....
virtual void SendExtraAI(BinaryWriter writer)
If you are storing AI information outside of the npc.ai array, use this to send that AI information b...
virtual bool CheckDead()
Whether or not this NPC should be killed when it reaches 0 health. You may program extra effects in t...
virtual float SpawnChance(NPCSpawnInfo spawnInfo)
Whether or not this NPC can spawn with the given spawning conditions. Return the weight for the chanc...
virtual string[] AltTextures
The file names of this NPC's alternate texture files, if any. This will be used in the given AutoStat...
virtual void BossLoot(ref string name, ref int potionType)
Allows you to customize what happens when this boss dies, such as which name is displayed in the defe...
virtual bool CanGoToStatue(bool toKingStatue)
Whether this NPC can be telported to a King or Queen statue. Returns false by default.
virtual void OnHitByItem(Player player, Item item, int damage, float knockback, bool crit)
Allows you to create special effects when this NPC is hit by a melee weapon.
virtual void OnGoToStatue(bool toKingStatue)
Allows you to make things happen when this NPC teleports to a King or Queen statue....
virtual bool CheckActive()
Whether or not to run the code for checking whether this NPC will remain active. Return false to stop...
virtual void SetStaticDefaults()
Allows you to set all your NPC's static properties, such as names/translations and the arrays in NPCI...
virtual void ScaleExpertStats(int numPlayers, float bossLifeScale)
Allows you to customize this NPC's stats in expert mode. This is useful because expert mode's doublin...
void SetDefault(string value)
This serves as the central class from which NPC-related functions are carried out....
MusicPriority
This enum dictates from low to high which music selections take priority. Setting appropriate MusicPr...
bool Autoload
Whether or not this mod will autoload content by default. Autoloading content means you do not need t...
A struct that stores information regarding where an NPC is naturally spawning and the player it is sp...