1using Microsoft.Xna.Framework;
2using Microsoft.Xna.Framework.Graphics;
4using System.Collections.Generic;
7using System.Linq.Expressions;
8using System.Reflection;
9using Terraria.GameContent.UI;
11using Terraria.Localization;
21 internal static bool loaded =
false;
23 internal static readonly IList<ModNPC> npcs =
new List<ModNPC>();
24 internal static readonly IList<GlobalNPC> globalNPCs =
new List<GlobalNPC>();
26 internal static readonly IDictionary<string, int> globalIndexes =
new Dictionary<string, int>();
27 internal static readonly IDictionary<Type, int> globalIndexesByType =
new Dictionary<Type, int>();
28 internal static readonly IDictionary<int, int> bannerToItem =
new Dictionary<int, int>();
30 private static readonly
int[]
shopToNPC =
new int[Main.MaxShopIDs - 1];
34 public static readonly IList<int>
blockLoot =
new List<int>();
46 private static List<HookList>
hooks =
new List<HookList>();
78 internal static int ReserveNPCID() {
94 return type >= NPCID.Count && type <
NPCCount ? npcs[type - NPCID.Count] :
null;
101 internal static void ResizeArrays(
bool unloading) {
102 Array.Resize(ref Main.NPCLoaded,
nextNPC);
103 Array.Resize(ref Main.townNPCCanSpawn,
nextNPC);
104 Array.Resize(ref Main.slimeRainNPC,
nextNPC);
105 Array.Resize(ref Main.npcTexture,
nextNPC);
106 Array.Resize(ref Main.npcAltTextures,
nextNPC);
107 Array.Resize(ref Main.npcCatchable,
nextNPC);
108 Array.Resize(ref Main.npcFrameCount,
nextNPC);
109 Array.Resize(ref NPC.killCount,
nextNPC);
110 Array.Resize(ref NPC.npcsFoundForCheckActive,
nextNPC);
111 Array.Resize(ref Lang._npcNameCache,
nextNPC);
112 Array.Resize(ref EmoteBubble.CountNPCs,
nextNPC);
113 Array.Resize(ref WorldGen.TownManager._hasRoom,
nextNPC);
114 Array.Resize(ref NPCID.Sets.TrailingMode,
nextNPC);
115 Array.Resize(ref NPCID.Sets.BelongsToInvasionOldOnesArmy,
nextNPC);
116 Array.Resize(ref NPCID.Sets.TeleportationImmune,
nextNPC);
117 Array.Resize(ref NPCID.Sets.UsesNewTargetting,
nextNPC);
118 Array.Resize(ref NPCID.Sets.FighterUsesDD2PortalAppearEffect,
nextNPC);
119 Array.Resize(ref NPCID.Sets.StatueSpawnedDropRarity,
nextNPC);
120 Array.Resize(ref NPCID.Sets.NoEarlymodeLootWhenSpawnedFromStatue,
nextNPC);
121 Array.Resize(ref NPCID.Sets.NeedsExpertScaling,
nextNPC);
122 Array.Resize(ref NPCID.Sets.ProjectileNPC,
nextNPC);
123 Array.Resize(ref NPCID.Sets.SavesAndLoads,
nextNPC);
124 Array.Resize(ref NPCID.Sets.TrailCacheLength,
nextNPC);
125 Array.Resize(ref NPCID.Sets.MPAllowedEnemies,
nextNPC);
126 Array.Resize(ref NPCID.Sets.TownCritter,
nextNPC);
127 Array.Resize(ref NPCID.Sets.HatOffsetY,
nextNPC);
128 Array.Resize(ref NPCID.Sets.FaceEmote,
nextNPC);
129 Array.Resize(ref NPCID.Sets.ExtraFramesCount,
nextNPC);
130 Array.Resize(ref NPCID.Sets.AttackFrameCount,
nextNPC);
131 Array.Resize(ref NPCID.Sets.DangerDetectRange,
nextNPC);
132 Array.Resize(ref NPCID.Sets.AttackTime,
nextNPC);
133 Array.Resize(ref NPCID.Sets.AttackAverageChance,
nextNPC);
134 Array.Resize(ref NPCID.Sets.AttackType,
nextNPC);
135 Array.Resize(ref NPCID.Sets.PrettySafe,
nextNPC);
136 Array.Resize(ref NPCID.Sets.MagicAuraColor,
nextNPC);
137 Array.Resize(ref NPCID.Sets.BossHeadTextures,
nextNPC);
138 Array.Resize(ref NPCID.Sets.ExcludedFromDeathTally,
nextNPC);
139 Array.Resize(ref NPCID.Sets.TechnicallyABoss,
nextNPC);
140 Array.Resize(ref NPCID.Sets.MustAlwaysDraw,
nextNPC);
141 Array.Resize(ref NPCID.Sets.ExtraTextureCount,
nextNPC);
142 Array.Resize(ref NPCID.Sets.NPCFramingGroup,
nextNPC);
143 Array.Resize(ref NPCID.Sets.TownNPCsFramingGroups,
nextNPC);
144 for (
int k = NPCID.Count; k <
nextNPC; k++) {
145 Main.NPCLoaded[k] =
true;
146 Main.npcFrameCount[k] = 1;
147 Lang._npcNameCache[k] = LocalizedText.Empty;
148 NPCID.Sets.TrailingMode[k] = -1;
149 NPCID.Sets.StatueSpawnedDropRarity[k] = -1f;
150 NPCID.Sets.TrailCacheLength[k] = 10;
151 NPCID.Sets.DangerDetectRange[k] = -1;
152 NPCID.Sets.AttackTime[k] = -1;
153 NPCID.Sets.AttackAverageChance[k] = 1;
154 NPCID.Sets.AttackType[k] = -1;
155 NPCID.Sets.PrettySafe[k] = -1;
156 NPCID.Sets.MagicAuraColor[k] = Color.White;
157 NPCID.Sets.BossHeadTextures[k] = -1;
160 InstancedGlobals = globalNPCs.Where(g => g.InstancePerEntity).ToArray();
161 for (
int i = 0; i < InstancedGlobals.Length; i++) {
162 InstancedGlobals[i].instanceIndex = i;
164 foreach (var hook
in hooks) {
165 hook.arr = ModLoader.BuildGlobalHook(globalNPCs, hook.method);
173 internal static void Unload() {
178 globalIndexes.Clear();
179 globalIndexesByType.Clear();
180 bannerToItem.Clear();
182 NPCID.Sets.Skeletons.RemoveAt(NPCID.Sets.Skeletons.Count - 1);
186 internal static bool IsModNPC(NPC npc) {
187 return npc.type >= NPCID.Count;
192 internal static void SetDefaults(NPC npc,
bool createModNPC =
true) {
202 npc.globalNPCs = InstancedGlobals.Select(g => g.NewInstance(npc)).ToArray();
209 internal static GlobalNPC GetGlobalNPC(NPC npc,
Mod mod,
string name) {
211 return globalIndexes.TryGetValue(mod.
Name +
':' + name, out index) ? globalNPCs[index].
Instance(npc) :
null;
214 internal static GlobalNPC GetGlobalNPC(NPC npc, Type type) {
216 return globalIndexesByType.TryGetValue(type, out index) ? (index > -1 ? globalNPCs[index].Instance(npc) :
null) :
null;
222 npc.modNPC?.ScaleExpertStats(numPlayers, bossLifeScale);
232 npc.modNPC?.ResetEffects();
242 bool useAiType = npc.modNPC !=
null && npc.modNPC.aiType > 0;
244 npc.type = npc.modNPC.aiType;
262 if (result && npc.modNPC !=
null) {
263 return npc.modNPC.PreAI();
270 public static void AI(NPC npc) {
281 npc.modNPC?.PostAI();
289 if (npc.modNPC !=
null) {
291 using (MemoryStream stream =
new MemoryStream()) {
293 npc.modNPC.SendExtraAI(modWriter);
295 data = stream.ToArray();
298 writer.Write((
byte)data.Length);
299 if (data.Length > 0) {
306 if (npc.modNPC !=
null) {
307 byte[] extraAI = reader.ReadBytes(reader.ReadByte());
308 if (extraAI.Length > 0) {
309 using (MemoryStream stream =
new MemoryStream(extraAI)) {
311 npc.modNPC.ReceiveExtraAI(modReader);
320 public static void FindFrame(NPC npc,
int frameHeight) {
322 if (npc.modNPC !=
null && npc.modNPC.animationType > 0) {
323 npc.type = npc.modNPC.animationType;
325 npc.VanillaFindFrame(frameHeight);
327 npc.modNPC?.FindFrame(frameHeight);
336 public static void HitEffect(NPC npc,
int hitDirection,
double damage) {
337 npc.VanillaHitEffect(hitDirection, damage);
338 npc.modNPC?.HitEffect(hitDirection, damage);
349 npc.modNPC?.UpdateLifeRegen(ref damage);
359 if (npc.modNPC !=
null && !npc.modNPC.CheckActive()) {
375 if (npc.modNPC !=
null) {
376 result = npc.modNPC.CheckDead();
394 if (npc.modNPC !=
null) {
395 return npc.modNPC.SpecialNPCLoot();
408 if (result && npc.modNPC !=
null) {
409 result = npc.modNPC.PreNPCLoot();
423 npc.modNPC?.NPCLoot();
431 public static void BossLoot(NPC npc, ref
string name, ref
int potionType) {
432 npc.modNPC?.BossLoot(ref name, ref potionType);
435 public static void BossBag(NPC npc, ref
int bagType) {
436 if (npc.modNPC !=
null) {
437 bagType = npc.modNPC.bossBag;
443 public static void OnCatchNPC(NPC npc, Player player, Item item) {
444 npc.modNPC?.OnCatchNPC(player, item);
454 public static bool CanHitPlayer(NPC npc, Player target, ref
int cooldownSlot) {
460 if (npc.modNPC !=
null) {
461 return npc.modNPC.CanHitPlayer(target, ref cooldownSlot);
469 public static void ModifyHitPlayer(NPC npc, Player target, ref
int damage, ref
bool crit) {
470 npc.modNPC?.ModifyHitPlayer(target, ref damage, ref crit);
479 public static void OnHitPlayer(NPC npc, Player target,
int damage,
bool crit) {
480 npc.modNPC?.OnHitPlayer(target, damage, crit);
493 if (canHit.HasValue && !canHit.Value) {
496 if (canHit.HasValue) {
500 if (npc.modNPC !=
null) {
501 bool? canHit = npc.modNPC.CanHitNPC(target);
502 if (canHit.HasValue && !canHit.Value) {
505 if (canHit.HasValue) {
512 private delegate
void DelegateModifyHitNPC(NPC npc, NPC target, ref
int damage, ref
float knockback, ref
bool crit);
515 public static void ModifyHitNPC(NPC npc, NPC target, ref
int damage, ref
float knockback, ref
bool crit) {
516 npc.modNPC?.ModifyHitNPC(target, ref damage, ref knockback, ref crit);
525 public static void OnHitNPC(NPC npc, NPC target,
int damage,
float knockback,
bool crit) {
526 npc.modNPC?.OnHitNPC(target, damage, knockback, crit);
538 if (canHit.HasValue && !canHit.Value) {
541 if (canHit.HasValue) {
545 if (npc.modNPC !=
null) {
546 bool? canHit = npc.modNPC.CanBeHitByItem(player, item);
547 if (canHit.HasValue && !canHit.Value) {
550 if (canHit.HasValue) {
557 private delegate
void DelegateModifyHitByItem(NPC npc, Player player, Item item, ref
int damage, ref
float knockback, ref
bool crit);
560 public static void ModifyHitByItem(NPC npc, Player player, Item item, ref
int damage, ref
float knockback, ref
bool crit) {
561 npc.modNPC?.ModifyHitByItem(player, item, ref damage, ref knockback, ref crit);
570 public static void OnHitByItem(NPC npc, Player player, Item item,
int damage,
float knockback,
bool crit) {
571 npc.modNPC?.OnHitByItem(player, item, damage, knockback, crit);
584 if (canHit.HasValue && !canHit.Value) {
587 if (canHit.HasValue) {
591 if (npc.modNPC !=
null) {
592 bool? canHit = npc.modNPC.CanBeHitByProjectile(projectile);
593 if (canHit.HasValue && !canHit.Value) {
596 if (canHit.HasValue) {
603 private delegate
void DelegateModifyHitByProjectile(NPC npc, Projectile projectile, ref
int damage, ref
float knockback, ref
bool crit, ref
int hitDirection);
606 public static void ModifyHitByProjectile(NPC npc, Projectile projectile, ref
int damage, ref
float knockback, ref
bool crit, ref
int hitDirection) {
607 npc.modNPC?.ModifyHitByProjectile(projectile, ref damage, ref knockback, ref crit, ref hitDirection);
616 public static void OnHitByProjectile(NPC npc, Projectile projectile,
int damage,
float knockback,
bool crit) {
617 npc.modNPC?.OnHitByProjectile(projectile, damage, knockback, crit);
624 private delegate
bool DelegateStrikeNPC(NPC npc, ref
double damage,
int defense, ref
float knockback,
int hitDirection, ref
bool crit);
627 public static bool StrikeNPC(NPC npc, ref
double damage,
int defense, ref
float knockback,
int hitDirection, ref
bool crit) {
629 if (npc.modNPC !=
null) {
630 flag = npc.modNPC.StrikeNPC(ref damage, defense, ref knockback, hitDirection, ref crit);
633 if (!g.
Instance(npc).
StrikeNPC(npc, ref damage, defense, ref knockback, hitDirection, ref crit)) {
644 npc.modNPC?.BossHeadSlot(ref index);
655 npc.modNPC?.BossHeadRotation(ref rotation);
666 npc.modNPC?.BossHeadSpriteEffects(ref spriteEffects);
675 public static Color?
GetAlpha(NPC npc, Color lightColor) {
678 if (color.HasValue) {
682 return npc.modNPC?.GetAlpha(lightColor);
689 npc.modNPC?.DrawEffects(ref drawColor);
698 public static bool PreDraw(NPC npc, SpriteBatch spriteBatch, Color drawColor) {
703 if (result && npc.modNPC !=
null) {
704 return npc.modNPC.PreDraw(spriteBatch, drawColor);
711 public static void PostDraw(NPC npc, SpriteBatch spriteBatch, Color drawColor) {
712 npc.modNPC?.PostDraw(spriteBatch, drawColor);
721 internal static void DrawBehind(NPC npc,
int index)
723 npc.modNPC?.DrawBehind(index);
734 Vector2 position =
new Vector2(npc.position.X + npc.width / 2, npc.position.Y + npc.gfxOffY);
735 if (Main.HealthBarDrawSettings == 1) {
736 position.Y += npc.height + 10f + Main.NPCAddHeight(npc.whoAmI);
738 else if (Main.HealthBarDrawSettings == 2) {
739 position.Y -= 24f + Main.NPCAddHeight(npc.whoAmI) / 2f;
742 bool? result = g.
Instance(npc).
DrawHealthBar(npc, Main.HealthBarDrawSettings, ref scale, ref position);
743 if (result.HasValue) {
751 bool? result = npc.modNPC.DrawHealthBar(Main.HealthBarDrawSettings, ref scale, ref position);
752 if (result.HasValue) {
763 float alpha = Lighting.Brightness((
int)(npc.Center.X / 16f), (
int)(npc.Center.Y / 16f));
764 Main.instance.DrawHealthBar(position.X, position.Y, npc.life, npc.lifeMax, alpha, scale);
770 public static void EditSpawnRate(Player player, ref
int spawnRate, ref
int maxSpawns) {
777 ref
int safeRangeX, ref
int safeRangeY);
780 public static void EditSpawnRange(Player player, ref
int spawnRangeX, ref
int spawnRangeY,
781 ref
int safeRangeX, ref
int safeRangeY) {
783 g.
EditSpawnRange(player, ref spawnRangeX, ref spawnRangeY, ref safeRangeX, ref safeRangeY);
792 IDictionary<int, float> pool =
new Dictionary<int, float>();
794 foreach (
ModNPC npc
in npcs) {
797 pool[npc.
npc.type] = weight;
803 float totalWeight = 0f;
804 foreach (
int type
in pool.Keys) {
805 if (pool[type] < 0f) {
808 totalWeight += pool[type];
810 float choice = (float)Main.rand.NextDouble() * totalWeight;
811 foreach (
int type
in pool.Keys) {
812 float weight = pool[type];
813 if (choice < weight) {
823 public static int SpawnNPC(
int type,
int tileX,
int tileY) {
824 var npc = type >= NPCID.Count ?
826 NPC.NewNPC(tileX * 16 + 8, tileY * 16, type);
836 foreach (
ModNPC npc
in npcs) {
837 if (npc.
npc.townNPC && NPC.TypeToHeadIndex(npc.
npc.type) >= 0 && !NPC.AnyNPCs(npc.
npc.type) &&
839 Main.townNPCCanSpawn[npc.
npc.type] =
true;
840 if (WorldGen.prioritizedTownNPC == 0) {
841 WorldGen.prioritizedTownNPC = npc.
npc.type;
848 return GetNPC(type)?.
CheckConditions(WorldGen.roomX1, WorldGen.roomX2, WorldGen.roomY1, WorldGen.roomY2) ??
true;
856 return npc.modNPC?.UsesPartyHat() ??
true;
861 public static bool CanChat(NPC npc,
bool vanillaCanChat) {
862 bool defaultCanChat = npc.modNPC?.CanChat() ?? vanillaCanChat;
866 if (canChat.HasValue) {
867 if (!canChat.Value) {
870 defaultCanChat =
true;
874 return defaultCanChat;
880 public static void GetChat(NPC npc, ref
string chat) {
881 if (npc.modNPC !=
null) {
882 chat = npc.modNPC.GetChat();
884 else if (chat.Equals(
"")) {
885 chat = Language.GetTextValue(
"tModLoader.DefaultTownNPCChat");
893 if (Main.player[Main.myPlayer].talkNPC >= 0) {
894 NPC npc = Main.
npc[Main.player[Main.myPlayer].talkNPC];
895 npc.modNPC?.SetChatButtons(ref button, ref button2);
902 NPC npc = Main.
npc[Main.LocalPlayer.talkNPC];
910 Main.PlaySound(SoundID.MenuTick);
921 NPC npc = Main.
npc[Main.LocalPlayer.talkNPC];
924 if (npc.modNPC !=
null) {
925 npc.modNPC.OnChatButtonClicked(firstButton, ref shop);
926 Main.PlaySound(SoundID.MenuTick);
928 Main.playerInventory =
true;
929 Main.npcChatText =
"";
930 Main.npcShop = Main.MaxShopIDs - 1;
931 Main.instance.shop[Main.npcShop].SetupShop(npc.type);
942 public static void SetupShop(
int type, Chest shop, ref
int nextSlot) {
965 public static bool CanGoToStatue(NPC npc,
bool toKingStatue,
bool vanillaCanGo) {
966 bool defaultCanGo = npc.modNPC?.CanGoToStatue(toKingStatue) ?? vanillaCanGo;
970 if (canGo.HasValue) {
984 npc.modNPC?.OnGoToStatue(toKingStatue);
994 public static void BuffTownNPC(ref
float damageMult, ref
int defense) {
1019 npc.modNPC?.TownNPCAttackStrength(ref damage, ref knockback);
1030 npc.modNPC?.TownNPCAttackCooldown(ref cooldown, ref randExtraCooldown);
1041 npc.modNPC?.TownNPCAttackProj(ref projType, ref attackDelay);
1049 ref
float randomOffset);
1053 ref
float randomOffset) {
1054 npc.modNPC?.TownNPCAttackProjSpeed(ref multiplier, ref gravityCorrection, ref randomOffset);
1065 npc.modNPC?.TownNPCAttackShoot(ref inBetweenShots);
1076 npc.modNPC?.TownNPCAttackMagic(ref auraLightMultiplier);
1087 npc.modNPC?.TownNPCAttackSwing(ref itemWidth, ref itemHeight);
1098 npc.modNPC?.DrawTownAttackGun(ref scale, ref item, ref closeness);
1108 public static void DrawTownAttackSwing(NPC npc, ref Texture2D item, ref
int itemSize, ref
float scale, ref Vector2 offset) {
1109 npc.modNPC?.DrawTownAttackSwing(ref item, ref itemSize, ref scale, ref offset);
1116 private static bool HasMethod(Type t,
string method, params Type[] args) {
1117 return t.GetMethod(method, args).DeclaringType != typeof(
GlobalNPC);
1120 internal static void VerifyGlobalNPC(
GlobalNPC npc) {
1121 var type = npc.GetType();
1123 bool hasInstanceFields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
1124 .Any(f => f.DeclaringType != typeof(
GlobalNPC));
1125 if (hasInstanceFields) {
1127 throw new Exception(type +
" has instance fields but does not set InstancePerEntity to true. Either use static fields, or per instance globals");
This serves as the central class from which buff-related functions are supported and carried out.
This class allows you to modify and use hooks for all NPCs, including vanilla mobs....
virtual void TownNPCAttackMagic(NPC npc, ref float auraLightMultiplier)
Allows you to control the brightness of the light emitted by a town NPC's aura when it performs a mag...
virtual bool CanHitPlayer(NPC npc, Player target, ref int cooldownSlot)
Allows you to determine whether an NPC can hit the given player. Return false to block the NPC from h...
virtual ? bool CanBeHitByItem(NPC npc, Player player, Item item)
Allows you to determine whether an NPC can be hit by the given melee weapon when swung....
virtual void DrawBehind(NPC npc, int index)
When used in conjunction with "npc.hide = true", allows you to specify that this npc should be drawn ...
virtual ? bool DrawHealthBar(NPC npc, byte hbPosition, ref float scale, ref Vector2 position)
Allows you to control how the health bar for the given NPC is drawn. The hbPosition parameter is the ...
virtual void BossHeadRotation(NPC npc, ref float rotation)
Allows you to customize the rotation of an NPC's boss head icon on the map.
virtual void OnHitByItem(NPC npc, Player player, Item item, int damage, float knockback, bool crit)
Allows you to create special effects when an NPC is hit by a melee weapon.
virtual ? Color GetAlpha(NPC npc, Color drawColor)
Allows you to determine the color and transparency in which an NPC is drawn. Return null to use the d...
virtual void BossHeadSlot(NPC npc, ref int index)
Allows you to customize the boss head texture used by an NPC based on its state. Set index to -1 to s...
virtual void TownNPCAttackStrength(NPC npc, ref int damage, ref float knockback)
Allows you to determine the damage and knockback of a town NPC's attack before the damage is scaled....
virtual void SetupTravelShop(int[] shop, ref int nextSlot)
Allows you to add items to the traveling merchant's shop. Add an item by setting shop[nextSlot] to th...
virtual bool StrikeNPC(NPC npc, ref double damage, int defense, ref float knockback, int hitDirection, ref bool crit)
Allows you to use a custom damage formula for when an NPC takes damage from any source....
virtual ? bool CanChat(NPC npc)
Allows you to determine whether this NPC can talk with the player. Return true to allow talking with ...
virtual void OnHitPlayer(NPC npc, Player target, int damage, bool crit)
Allows you to create special effects when an NPC hits a player (for example, inflicting debuffs).
virtual void TownNPCAttackSwing(NPC npc, ref int itemWidth, ref int itemHeight)
Allows you to determine the width and height of the item a town NPC swings when it attacks,...
virtual void SetupShop(int type, Chest shop, ref int nextSlot)
Allows you to add items to an NPC's shop. The type parameter is the type of the NPC that this shop be...
virtual bool PreDraw(NPC npc, SpriteBatch spriteBatch, Color drawColor)
Allows you to draw things behind an NPC, or to modify the way the NPC is drawn. Return false to stop ...
virtual void EditSpawnRate(Player player, ref int spawnRate, ref int maxSpawns)
Allows you to modify the chance of NPCs spawning around the given player and the maximum number of NP...
virtual bool CheckActive(NPC npc)
Whether or not to run the code for checking whether an NPC will remain active. Return false to stop t...
virtual void GetChat(NPC npc, ref string chat)
Allows you to modify the chat message of any NPC that the player can talk to.
virtual void UpdateLifeRegen(NPC npc, ref int damage)
Allows you to make the NPC either regenerate health or take damage over time by setting npc....
virtual void PostAI(NPC npc)
Allows you to determine how any NPC behaves. This will be called regardless of what PreAI returns.
virtual void ResetEffects(NPC npc)
This is where you reset any fields you add to your subclass to their default states....
virtual void OnChatButtonClicked(NPC npc, bool firstButton)
Allows you to make something happen whenever a button is clicked on this NPC's chat window....
virtual bool InstancePerEntity
Whether to create a new GlobalNPC instance for every NPC that exists. Useful for storing information ...
virtual void TownNPCAttackProjSpeed(NPC npc, ref float multiplier, ref float gravityCorrection, ref float randomOffset)
Allows you to determine the speed at which a town NPC throws a projectile when it attacks....
GlobalNPC Instance(NPC npc)
virtual void SpawnNPC(int npc, int tileX, int tileY)
Allows you to customize an NPC (for example, its position or ai array) after it naturally spawns and ...
virtual void ModifyHitPlayer(NPC npc, Player target, ref int damage, ref bool crit)
Allows you to modify the damage, etc., that an NPC does to a player.
virtual void ModifyHitByItem(NPC npc, Player player, Item item, ref int damage, ref float knockback, ref bool crit)
Allows you to modify the damage, knockback, etc., that an NPC takes from a melee weapon.
virtual ? bool CanHitNPC(NPC npc, NPC target)
Allows you to determine whether an NPC can hit the given friendly NPC. Return true to allow hitting t...
virtual bool PreNPCLoot(NPC npc)
Allows you to determine whether or not the NPC will drop anything at all. Return false to stop the NP...
virtual void PostDraw(NPC npc, 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 TownNPCAttackShoot(NPC npc, ref bool inBetweenShots)
Allows you to tell the game that a town NPC has already created a projectile and will still create mo...
virtual void EditSpawnRange(Player player, ref int spawnRangeX, ref int spawnRangeY, ref int safeRangeX, ref int safeRangeY)
Allows you to modify the range at which NPCs can spawn around the given player. The spawnRanges deter...
virtual bool PreChatButtonClicked(NPC npc, bool firstButton)
Allows you to determine if something can happen whenever a button is clicked on this NPC's chat windo...
virtual void BossHeadSpriteEffects(NPC npc, ref SpriteEffects spriteEffects)
Allows you to flip an NPC's boss head icon on the map.
virtual void OnHitByProjectile(NPC npc, Projectile projectile, int damage, float knockback, bool crit)
Allows you to create special effects when an NPC is hit by a projectile.
virtual void ScaleExpertStats(NPC npc, int numPlayers, float bossLifeScale)
Allows you to customize an NPC's stats in expert mode.
virtual void DrawTownAttackSwing(NPC npc, ref Texture2D item, ref int itemSize, ref float scale, ref Vector2 offset)
Allows you to customize how a town NPC's weapon is drawn when the NPC is swinging it (the NPC must ha...
virtual void AI(NPC npc)
Allows you to determine how any NPC behaves. This will only be called if PreAI returns true.
virtual void OnCatchNPC(NPC npc, Player player, Item item)
Allows you to make things happen when an NPC is caught. Ran Serverside.
virtual void ModifyHitByProjectile(NPC npc, Projectile projectile, ref int damage, ref float knockback, ref bool crit, ref int hitDirection)
Allows you to modify the damage, knockback, etc., that an NPC takes from a projectile.
virtual void DrawEffects(NPC npc, ref Color drawColor)
Allows you to add special visual effects to an NPC (such as creating dust), and modify the color in w...
virtual ? bool CanBeHitByProjectile(NPC npc, Projectile projectile)
Allows you to determine whether an NPC can be hit by the given projectile. Return true to allow hitti...
virtual void ModifyHitNPC(NPC npc, NPC target, ref int damage, ref float knockback, ref bool crit)
Allows you to modify the damage, knockback, etc., that an NPC does to a friendly NPC.
virtual void BuffTownNPC(ref float damageMult, ref int defense)
Allows you to modify the stats of town NPCs. Useful for buffing town NPCs when certain bosses are def...
virtual void SetDefaults(NPC npc)
Allows you to set the properties of any and every NPC that gets created.
virtual void DrawTownAttackGun(NPC npc, ref float scale, ref int item, ref int closeness)
Allows you to customize how a town NPC's weapon is drawn when the NPC is shooting (the NPC must have ...
virtual void OnGoToStatue(NPC npc, bool toKingStatue)
Allows you to make things happen when this NPC teleports to a King or Queen statue....
virtual bool PreAI(NPC npc)
Allows you to determine how any NPC behaves. Return false to stop the vanilla AI and the AI hook from...
virtual void NPCLoot(NPC npc)
Allows you to make things happen when an NPC dies (for example, dropping items and setting ModWorld f...
virtual void EditSpawnPool(IDictionary< int, float > pool, NPCSpawnInfo spawnInfo)
Allows you to control which NPCs can spawn and how likely each one is to spawn. The pool parameter ma...
virtual bool SpecialNPCLoot(NPC npc)
Allows you to call NPCLoot on your own when the NPC dies, rather then letting vanilla call it on its ...
virtual void TownNPCAttackCooldown(NPC npc, ref int cooldown, ref int randExtraCooldown)
Allows you to determine the cooldown between each of a town NPC's attack. The cooldown will be a numb...
virtual ? bool CanGoToStatue(NPC npc, bool toKingStatue)
Whether this NPC can be telported a King or Queen statue. Return true to allow the NPC to teleport to...
virtual void FindFrame(NPC npc, int frameHeight)
Allows you to modify the frame from an NPC's texture that is drawn, which is necessary in order to an...
virtual void HitEffect(NPC npc, int hitDirection, double damage)
Allows you to make things happen whenever an NPC is hit, such as creating dust or gores....
virtual void TownNPCAttackProj(NPC npc, ref int projType, ref int attackDelay)
Allows you to determine the projectile type of a town NPC's attack, and how long it takes for the pro...
virtual bool CheckDead(NPC npc)
Whether or not an NPC should be killed when it reaches 0 health. You may program extra effects in thi...
virtual void OnHitNPC(NPC npc, NPC target, int damage, float knockback, bool crit)
Allows you to create special effects when an NPC hits a friendly NPC.
Mod is an abstract class that you will override. It serves as a central place from which the mod's co...
virtual string Name
Stores the name of the mod. This name serves as the mod's identification, and also helps with saving ...
This serves as the central class which loads mods. It contains many static fields and methods related...
This class serves as a place for you to place all your properties and hooks for each NPC....
virtual string TownNPCName()
Allows you to give this town NPC any name when it spawns. By default returns something embarrassing.
NPC npc
The NPC object that this ModNPC controls.
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 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....
virtual ModNPC NewInstance(NPC npcClone)
Create a new instance of this ModNPC for an NPC instance. Called at the end of NPC....
virtual int SpawnNPC(int tileX, int tileY)
Allows you to customize how this NPC is created when it naturally spawns (for example,...
virtual float SpawnChance(NPCSpawnInfo spawnInfo)
Whether or not this NPC can spawn with the given spawning conditions. Return the weight for the chanc...
static bool AllowVanillaClients
readonly MethodInfo method
HookList(MethodInfo method)
This serves as the central class from which NPC-related functions are carried out....
static void DrawHealthBar(NPC npc, Vector2 position, float scale)
static void OnHitByItem(NPC npc, Player player, Item item, int damage, float knockback, bool crit)
static void BossBag(NPC npc, ref int bagType)
delegate void DelegateTownNPCAttackProj(NPC npc, ref int projType, ref int attackDelay)
static bool CheckConditions(int type)
static HookList HookModifyHitNPC
static int SpawnNPC(int type, int tileX, int tileY)
static HookList HookUpdateLifeRegen
delegate void DelegateTownNPCAttackSwing(NPC npc, ref int itemWidth, ref int itemHeight)
delegate void DelegateTownNPCAttackShoot(NPC npc, ref bool inBetweenShots)
static HookList HookTownNPCAttackShoot
static HookList HookCanBeHitByProjectile
static string TownNPCName(int type)
static void GetChat(NPC npc, ref string chat)
static void UpdateLifeRegen(NPC npc, ref int damage)
static void TownNPCAttackStrength(NPC npc, ref int damage, ref float knockback)
static HookList HookTownNPCAttackCooldown
static ModNPC GetNPC(int type)
Gets the ModNPC instance corresponding to the specified type.
static void HitEffect(NPC npc, int hitDirection, double damage)
static bool CanChat(NPC npc, bool vanillaCanChat)
static HookList HookGetAlpha
delegate void DelegateSetupTravelShop(int[] shop, ref int nextSlot)
delegate void DelegateBossHeadSlot(NPC npc, ref int index)
static HookList HookSetupShop
static void DrawTownAttackGun(NPC npc, ref float scale, ref int item, ref int closeness)
static bool SpecialNPCLoot(NPC npc)
static HookList HookBossHeadSlot
static HookList HookPreDraw
static HookList HookTownNPCAttackStrength
delegate void DelegateGetChat(NPC npc, ref string chat)
static HookList HookHitEffect
delegate? bool DelegateDrawHealthBar(NPC npc, byte bhPosition, ref float scale, ref Vector2 position)
static HookList HookSpawnNPC
static void ResetEffects(NPC npc)
delegate void DelegateDrawEffects(NPC npc, ref Color drawColor)
static HookList HookSpecialNPCLoot
static void SendExtraAI(NPC npc, BinaryWriter writer)
static HookList HookStrikeNPC
static HookList HookEditSpawnPool
static bool CheckDead(NPC npc)
static void DrawTownAttackSwing(NPC npc, ref Texture2D item, ref int itemSize, ref float scale, ref Vector2 offset)
static readonly IList< int > blockLoot
Allows you to stop an NPC from dropping loot by adding item IDs to this list. This list will be clear...
static List< HookList > hooks
static void NPCAI(NPC npc)
delegate void DelegateDrawTownAttackGun(NPC npc, ref float scale, ref int item, ref int closeness)
static HookList HookEditSpawnRate
static bool CheckActive(NPC npc)
delegate void DelegateTownNPCAttackMagic(NPC npc, ref float auraLightMultiplier)
static HookList HookCanHitPlayer
static HookList AddHook< F >(Expression< Func< GlobalNPC, F > > func)
static HookList HookOnGoToStatue
static void SetupTravelShop(int[] shop, ref int nextSlot)
static HookList HookDrawBehind
static ? int ChooseSpawn(NPCSpawnInfo spawnInfo)
static HookList HookGetChat
delegate bool DelegateCanHitPlayer(NPC npc, Player target, ref int cooldownSlot)
delegate void DelegateEditSpawnRange(Player player, ref int spawnRangeX, ref int spawnRangeY, ref int safeRangeX, ref int safeRangeY)
static void OnHitByProjectile(NPC npc, Projectile projectile, int damage, float knockback, bool crit)
static void TownNPCAttackMagic(NPC npc, ref float auraLightMultiplier)
static bool CanHitPlayer(NPC npc, Player target, ref int cooldownSlot)
static HookList HookDrawTownAttackSwing
delegate void DelegateDrawTownAttackSwing(NPC npc, ref Texture2D item, ref int itemSize, ref float scale, ref Vector2 offset)
static HookList HookDrawTownAttackGun
static void ModifyHitByProjectile(NPC npc, Projectile projectile, ref int damage, ref float knockback, ref bool crit, ref int hitDirection)
static void TownNPCAttackProj(NPC npc, ref int projType, ref int attackDelay)
static void PostDraw(NPC npc, SpriteBatch spriteBatch, Color drawColor)
static void PostAI(NPC npc)
static HookList HookNPCLoot
static HookList HookScaleExpertStats
static HookList HookCanChat
static HookList HookBuffTownNPC
static HookList HookOnHitByItem
static ? bool CanBeHitByItem(NPC npc, Player player, Item item)
static HookList HookOnHitNPC
static HookList HookModifyHitByProjectile
static HookList HookCanBeHitByItem
static void DrawEffects(NPC npc, ref Color drawColor)
static void TownNPCAttackShoot(NPC npc, ref bool inBetweenShots)
delegate void DelegateTownNPCAttackStrength(NPC npc, ref int damage, ref float knockback)
delegate void DelegateEditSpawnRate(Player player, ref int spawnRate, ref int maxSpawns)
static void OnHitNPC(NPC npc, NPC target, int damage, float knockback, bool crit)
delegate void DelegateModifyHitByItem(NPC npc, Player player, Item item, ref int damage, ref float knockback, ref bool crit)
static void ReceiveExtraAI(NPC npc, BinaryReader reader)
static HookList HookPreChatButtonClicked
static HookList HookPreAI
static bool PreChatButtonClicked(bool firstButton)
static void FindFrame(NPC npc, int frameHeight)
static void OnChatButtonClicked(bool firstButton)
delegate void DelegateBuffTownNPC(ref float damageMult, ref int defense)
static void TownNPCAttackSwing(NPC npc, ref int itemWidth, ref int itemHeight)
static void TownNPCAttackProjSpeed(NPC npc, ref float multiplier, ref float gravityCorrection, ref float randomOffset)
static void SetChatButtons(ref string button, ref string button2)
static HookList HookBossHeadRotation
static HookList HookTownNPCAttackSwing
delegate void DelegateBossHeadRotation(NPC npc, ref float rotation)
static HookList HookCanGoToStatue
static HookList HookCheckDead
delegate void DelegateModifyHitNPC(NPC npc, NPC target, ref int damage, ref float knockback, ref bool crit)
static HookList HookDrawEffects
delegate void DelegateUpdateLifeRegen(NPC npc, ref int damage)
static HookList HookCheckActive
static bool StrikeNPC(NPC npc, ref double damage, int defense, ref float knockback, int hitDirection, ref bool crit)
delegate void DelegateOnChatButtonClicked(NPC npc, bool firstButton)
delegate void DelegateBossHeadSpriteEffects(NPC npc, ref SpriteEffects spriteEffects)
static HookList HookEditSpawnRange
static HookList HookTownNPCAttackProjSpeed
static void TownNPCAttackCooldown(NPC npc, ref int cooldown, ref int randExtraCooldown)
static void BossHeadSlot(NPC npc, ref int index)
static void BossHeadRotation(NPC npc, ref float rotation)
static void EditSpawnRate(Player player, ref int spawnRate, ref int maxSpawns)
static bool DrawHealthBar(NPC npc, ref float scale)
static HookList HookPreNPCLoot
static void ModifyHitByItem(NPC npc, Player player, Item item, ref int damage, ref float knockback, ref bool crit)
static HookList HookOnCatchNPC
static void ModifyHitNPC(NPC npc, NPC target, ref int damage, ref float knockback, ref bool crit)
static HookList HookTownNPCAttackProj
static HookList HookPostAI
static void OnHitPlayer(NPC npc, Player target, int damage, bool crit)
static ? bool CanHitNPC(NPC npc, NPC target)
static bool PreDraw(NPC npc, SpriteBatch spriteBatch, Color drawColor)
static HookList HookOnChatButtonClicked
static bool PreAI(NPC npc)
delegate void DelegateTownNPCAttackProjSpeed(NPC npc, ref float multiplier, ref float gravityCorrection, ref float randomOffset)
static int vanillaSkeletonCount
static void BossLoot(NPC npc, ref string name, ref int potionType)
delegate void DelegateSetupShop(int type, Chest shop, ref int nextSlot)
static HookList HookOnHitPlayer
static bool HasMethod(Type t, string method, params Type[] args)
static HookList HookSetupTravelShop
delegate bool DelegateStrikeNPC(NPC npc, ref double damage, int defense, ref float knockback, int hitDirection, ref bool crit)
static HookList HookResetEffects
delegate void DelegateModifyHitByProjectile(NPC npc, Projectile projectile, ref int damage, ref float knockback, ref bool crit, ref int hitDirection)
static void ScaleExpertStats(NPC npc, int numPlayers, float bossLifeScale)
static HookList HookFindFrame
static void SetupShop(int type, Chest shop, ref int nextSlot)
static HookList HookTownNPCAttackMagic
static void NPCLoot(NPC npc)
delegate void DelegateModifyHitPlayer(NPC npc, Player target, ref int damage, ref bool crit)
static bool CanGoToStatue(NPC npc, bool toKingStatue, bool vanillaCanGo)
static bool UsesPartyHat(NPC npc)
static readonly int[] shopToNPC
static ? Color GetAlpha(NPC npc, Color lightColor)
static HookList HookDrawHealthBar
static HookList HookModifyHitByItem
static HookList HookOnHitByProjectile
static void BuffTownNPC(ref float damageMult, ref int defense)
static bool PreNPCLoot(NPC npc)
static void OnCatchNPC(NPC npc, Player player, Item item)
static HookList HookCanHitNPC
static void EditSpawnRange(Player player, ref int spawnRangeX, ref int spawnRangeY, ref int safeRangeX, ref int safeRangeY)
static HookList HookSetDefaults
delegate void DelegateTownNPCAttackCooldown(NPC npc, ref int cooldown, ref int randExtraCooldown)
static HookList HookBossHeadSpriteEffects
static void OnGoToStatue(NPC npc, bool toKingStatue)
static void BossHeadSpriteEffects(NPC npc, ref SpriteEffects spriteEffects)
static void ModifyHitPlayer(NPC npc, Player target, ref int damage, ref bool crit)
static ? bool CanBeHitByProjectile(NPC npc, Projectile projectile)
static HookList HookModifyHitPlayer
static void CanTownNPCSpawn(int numTownNPCs, int money)
static HookList HookPostDraw
This server as a central class to help modders spawn their npcs. It's basically the vanilla spawn cod...
A struct that stores information regarding where an NPC is naturally spawning and the player it is sp...