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

◆ StrikeNPC() [1/2]

int Terraria.NPC.StrikeNPC ( HitInfo hit,
bool fromNet = false,
bool noPlayerInteraction = false )
inline

Directly deals damage to the NPC, spawns combat text, plays hit sound, deals knockback based on the provided T:Terraria.NPC.HitInfo
Calls M:Terraria.NPC.HitEffect(Terraria.NPC.HitInfo) and associated hooks after dealing damage.
Calls M:Terraria.NPC.checkDead
Does not automatically send packets. Use M:Terraria.NetMessage.SendStrikeNPC(Terraria.NPC,Terraria.NPC.HitInfo@,System.Int32) to synchronize hits.

Parameters
hitThe parameters of the hit. Normally obtained via T:Terraria.NPC.HitModifiers or M:Terraria.NPC.CalculateHitInfo(System.Int32,System.Int32,System.Boolean,System.Single,Terraria.ModLoader.DamageClass,System.Boolean,System.Single)
fromNettrue if this strike came from another client over the network. Just changes the combat text to be darker in color.
noPlayerInteractionPrevents M:Terraria.NPC.PlayerInteraction(System.Int32) from being called in single player. In multiplayer, player interaction is handled by the server.
Returns
The actual health lost by the NPC. Normally this is P:Terraria.NPC.HitInfo.Damage but it is capped at the current health of the NPC, and represents the actual damage dealt in the case of F:Terraria.NPC.HitInfo.InstantKill

Definition at line 91814 of file NPC.cs.

91815 {
91816 //IL_00ed: Unknown result type (might be due to invalid IL or missing references)
91817 //IL_00e6: Unknown result type (might be due to invalid IL or missing references)
91818 //IL_00a5: Unknown result type (might be due to invalid IL or missing references)
91819 //IL_009e: Unknown result type (might be due to invalid IL or missing references)
91820 //IL_00f2: Unknown result type (might be due to invalid IL or missing references)
91821 //IL_00aa: Unknown result type (might be due to invalid IL or missing references)
91822 //IL_00d0: Unknown result type (might be due to invalid IL or missing references)
91823 //IL_00d5: Unknown result type (might be due to invalid IL or missing references)
91824 //IL_012c: Unknown result type (might be due to invalid IL or missing references)
91825 //IL_0131: Unknown result type (might be due to invalid IL or missing references)
91826 //IL_0101: Unknown result type (might be due to invalid IL or missing references)
91827 //IL_00fa: Unknown result type (might be due to invalid IL or missing references)
91828 //IL_0106: Unknown result type (might be due to invalid IL or missing references)
91829 //IL_0438: Unknown result type (might be due to invalid IL or missing references)
91830 //IL_043e: Unknown result type (might be due to invalid IL or missing references)
91831 //IL_0846: Unknown result type (might be due to invalid IL or missing references)
91832 bool flag = Main.netMode == 0;
91834 if (!active || life <= 0)
91835 {
91836 return 0;
91837 }
91838 double num = hit.Damage;
91839 bool crit = hit.Crit;
91840 int hitDirection = hit.HitDirection;
91841 if (hit.InstantKill)
91842 {
91843 num = ((realLife > 0) ? Main.npc[realLife].life : life);
91844 }
91845 if (!hit.HideCombatText && !hit.InstantKill && lifeMax > 1 && !HideStrikeDamage)
91846 {
91847 if (friendly)
91848 {
91849 Color color = (crit ? CombatText.DamagedFriendlyCrit : CombatText.DamagedFriendly);
91850 CombatText.NewText(new Rectangle((int)position.X, (int)position.Y, width, height), color, (int)num, crit);
91851 }
91852 else
91853 {
91854 Color color2 = (crit ? CombatText.DamagedHostileCrit : CombatText.DamagedHostile);
91855 if (fromNet)
91856 {
91857 color2 = (crit ? CombatText.OthersDamagedHostileCrit : CombatText.OthersDamagedHostile);
91858 }
91859 CombatText.NewText(new Rectangle((int)position.X, (int)position.Y, width, height), color2, (int)num, crit);
91860 }
91861 }
91862 if (num >= 1.0)
91863 {
91864 if (flag)
91865 {
91866 PlayerInteraction(Main.myPlayer);
91867 }
91868 justHit = true;
91869 if ((type == 438 || type == 379) && Main.netMode != 1)
91870 {
91871 int num2 = (int)(0f - ai[3] - 1f);
91872 if (num2 > -1 && Main.npc[num2].localAI[0] == 0f)
91873 {
91874 Main.npc[num2].localAI[0] = 1f;
91875 }
91876 }
91877 if (townNPC)
91878 {
91879 if (aiStyle == 7 && (ai[0] == 3f || ai[0] == 4f || ai[0] == 16f || ai[0] == 17f))
91880 {
91881 NPC nPC = Main.npc[(int)ai[2]];
91882 if (nPC.active)
91883 {
91884 nPC.ai[0] = 1f;
91885 nPC.ai[1] = 300 + Main.rand.Next(300);
91886 nPC.ai[2] = 0f;
91887 nPC.localAI[3] = 0f;
91888 nPC.direction = hitDirection;
91889 nPC.netUpdate = true;
91890 }
91891 }
91892 ai[0] = 1f;
91893 ai[1] = 300 + Main.rand.Next(300);
91894 ai[2] = 0f;
91895 localAI[3] = 0f;
91897 netUpdate = true;
91898 }
91899 if (aiStyle == 8 && Main.netMode != 1)
91900 {
91901 if (type == 172)
91902 {
91903 ai[0] = 450f;
91904 }
91905 else if (type == 283 || type == 284)
91906 {
91907 if (Main.rand.Next(2) == 0)
91908 {
91909 ai[0] = 390f;
91910 netUpdate = true;
91911 }
91912 }
91913 else if (type == 533)
91914 {
91915 if (Main.rand.Next(3) != 0)
91916 {
91917 ai[0] = 181f;
91918 netUpdate = true;
91919 }
91920 }
91921 else
91922 {
91923 ai[0] = 400f;
91924 }
91925 TargetClosest();
91926 }
91927 if (aiStyle == 97 && Main.netMode != 1)
91928 {
91929 localAI[1] = 1f;
91930 TargetClosest();
91931 }
91932 if (type == 371)
91933 {
91934 num = 0.0;
91935 ai[0] = 1f;
91936 ai[1] = 4f;
91937 dontTakeDamage = true;
91938 }
91939 if (type == 346 && (double)life >= (double)lifeMax * 0.5 && (double)life - num < (double)lifeMax * 0.5)
91940 {
91941 Gore.NewGore(position, velocity, 517);
91942 }
91943 if (type == 184)
91944 {
91945 localAI[0] = 60f;
91946 }
91947 if (type == 535)
91948 {
91949 localAI[0] = 60f;
91950 }
91951 if (type == 185)
91952 {
91953 localAI[0] = 1f;
91954 }
91955 if (!immortal)
91956 {
91957 if (realLife >= 0)
91958 {
91959 Main.npc[realLife].life -= (int)num;
91960 life = Main.npc[realLife].life;
91961 lifeMax = Main.npc[realLife].lifeMax;
91962 }
91963 else
91964 {
91965 life -= (int)num;
91966 }
91967 }
91968 if (hit.Knockback > 0f)
91969 {
91970 float num3 = hit.Knockback;
91971 if (num3 > 8f)
91972 {
91973 float num4 = num3 - 8f;
91974 num4 *= 0.9f;
91975 num3 = 8f + num4;
91976 }
91977 if (num3 > 10f)
91978 {
91979 float num5 = num3 - 10f;
91980 num5 *= 0.8f;
91981 num3 = 10f + num5;
91982 }
91983 if (num3 > 12f)
91984 {
91985 float num6 = num3 - 12f;
91986 num6 *= 0.7f;
91987 num3 = 12f + num6;
91988 }
91989 if (num3 > 14f)
91990 {
91991 float num7 = num3 - 14f;
91992 num7 *= 0.6f;
91993 num3 = 14f + num7;
91994 }
91995 if (num3 > 16f)
91996 {
91997 num3 = 16f;
91998 }
91999 if (crit)
92000 {
92001 num3 *= 1.4f;
92002 }
92003 int num8 = (int)num * 10;
92004 if (Main.expertMode)
92005 {
92006 num8 = (int)num * 15;
92007 }
92008 if (num8 > lifeMax)
92009 {
92011 {
92012 if (velocity.X > 0f)
92013 {
92014 velocity.X -= num3;
92015 }
92016 velocity.X -= num3;
92017 if (velocity.X < 0f - num3)
92018 {
92019 velocity.X = 0f - num3;
92020 }
92021 }
92022 else if (hitDirection > 0 && velocity.X < num3)
92023 {
92024 if (velocity.X < 0f)
92025 {
92026 velocity.X += num3;
92027 }
92028 velocity.X += num3;
92029 if (velocity.X > num3)
92030 {
92031 velocity.X = num3;
92032 }
92033 }
92034 if (type == 185)
92035 {
92036 num3 *= 1.5f;
92037 }
92038 num3 = (noGravity ? (num3 * -0.5f) : (num3 * -0.75f));
92039 if (velocity.Y > num3)
92040 {
92041 velocity.Y += num3;
92042 if (velocity.Y < num3)
92043 {
92044 velocity.Y = num3;
92045 }
92046 }
92047 }
92048 else
92049 {
92050 if (!noGravity)
92051 {
92052 velocity.Y = (0f - num3) * 0.75f * knockBackResist;
92053 }
92054 else
92055 {
92056 velocity.Y = (0f - num3) * 0.5f * knockBackResist;
92057 }
92058 velocity.X = num3 * (float)hitDirection * knockBackResist;
92059 }
92060 }
92061 if ((type == 113 || type == 114) && life <= 0)
92062 {
92063 for (int i = 0; i < 200; i++)
92064 {
92065 if (Main.npc[i].active && (Main.npc[i].type == 113 || Main.npc[i].type == 114))
92066 {
92067 Main.npc[i].HitEffect(hitDirection, num, hit.InstantKill);
92068 }
92069 }
92070 }
92071 else
92072 {
92073 HitEffect(hit);
92074 }
92075 if (HitSound.HasValue)
92076 {
92078 }
92079 if (realLife >= 0)
92080 {
92081 Main.npc[realLife].checkDead();
92082 }
92083 else
92084 {
92085 checkDead();
92086 }
92087 return (int)num;
92088 }
92089 return 0;
92090 }
static SlotId PlaySound(in SoundStyle? style, Vector2? position=null, SoundUpdateCallback? updateCallback=null)
Attempts to play a sound style with the provided sound style (if it's not null), and returns a valid ...
Vector2 velocity
The velocity of this Entity in world coordinates per tick.
Definition Entity.cs:33
Vector2 position
The position of this Entity in world coordinates.
Definition Entity.cs:28
int width
The width of this Entity's hitbox, in pixels.
Definition Entity.cs:46
bool active
If true, the Entity actually exists within the game world. Within the specific entity array,...
Definition Entity.cs:21
int height
The height of this Entity's hitbox, in pixels.
Definition Entity.cs:51
bool immortal
Definition NPC.cs:700
float[] localAI
Acts like F:Terraria.NPC.ai, but does not sync to the server. Many vanilla T:Terraria....
Definition NPC.cs:1003
int lifeMax
The maximum life of this NPC.
Definition NPC.cs:1077
void TargetClosest(bool faceTarget=true)
Definition NPC.cs:83247
int aiStyle
Selects which vanilla code to use for the AI method. Vanilla NPC AI styles are enumerated in the T:Te...
Definition NPC.cs:1013
bool noGravity
If true, the npc will not be affected by gravity. Demon Eyes and other floating npc use this....
Definition NPC.cs:1122
float[] ai
An array with 4 slots used for any sort of data storage, which is occasionally synced from the server...
Definition NPC.cs:997
float knockBackResist
How much of the knockback it receives will actually apply. 1f: full knockback; 0f: no knockback....
Definition NPC.cs:1110
bool dontTakeDamage
Definition NPC.cs:1160
bool friendly
Indicates that an NPC is friendly to players. If true, a player won't damage the NPC and the NPC won'...
Definition NPC.cs:1197
int type
The NPC ID of this NPC. The NPC ID is a unique number assigned to each NPC loaded into the game....
Definition NPC.cs:990
Color color
Definition NPC.cs:1085
SoundStyle? HitSound
The sound that plays when this npc is hit. Set this to an existing T:Terraria.ID.SoundID entry or ass...
Definition NPC.cs:1059
bool HideStrikeDamage
If true, damage combat text will not be shown by M:Terraria.NPC.StrikeNPC(Terraria....
Definition NPC.cs:1605
void checkDead()
Definition NPC.cs:83653
bool justHit
Definition NPC.cs:1015
void PlayerInteraction(int player)
Definition NPC.cs:85611
int life
The current life of the NPC. Automatically set to the value of F:Terraria.NPC.lifeMax at the end of S...
Definition NPC.cs:1072
int realLife
Stores the index (the F:Terraria.Entity.whoAmI) of a single NPC. This NPC will then share a health po...
Definition NPC.cs:604
bool netUpdate
Definition NPC.cs:1130
bool townNPC
Definition NPC.cs:1174
void HitEffect(int hitDirection=0, double dmg=10.0, bool? instantKill=null)
Definition NPC.cs:92191

References Terraria.CombatText.DamagedFriendly, Terraria.CombatText.DamagedHostile, Terraria.Main.expertMode, Terraria.Main.myPlayer, Terraria.Main.netMode, Terraria.Gore.NewGore(), Terraria.CombatText.NewText(), Terraria.Main.npc, Terraria.CombatText.OthersDamagedHostile, Terraria.Audio.SoundEngine.PlaySound(), and Terraria.Main.rand.

+ Here is the call graph for this function: