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

◆ StrikeNPC()

double Terraria.NPC.StrikeNPC ( int Damage,
float knockBack,
int hitDirection,
bool crit = false,
bool noEffect = false,
bool fromNet = false )
inline

Definition at line 78024 of file NPC.cs.

78025 {
78026 bool flag = Main.netMode == 0;
78027 if (flag && ignorePlayerInteractions > 0)
78028 {
78030 flag = false;
78031 }
78032 if (!active || life <= 0)
78033 {
78034 return 0.0;
78035 }
78036 double num = Damage;
78037 num = Main.CalculateDamageNPCsTake((int)num, defense);
78038 if (crit)
78039 {
78040 num *= 2.0;
78041 }
78042 if (takenDamageMultiplier > 1f)
78043 {
78044 num *= (double)takenDamageMultiplier;
78045 }
78046 if ((takenDamageMultiplier > 1f || Damage != 9999) && lifeMax > 1)
78047 {
78048 if (friendly)
78049 {
78050 Color color = (crit ? CombatText.DamagedFriendlyCrit : CombatText.DamagedFriendly);
78051 CombatText.NewText(new Rectangle((int)position.X, (int)position.Y, width, height), color, (int)num, crit);
78052 }
78053 else
78054 {
78055 Color color2 = (crit ? CombatText.DamagedHostileCrit : CombatText.DamagedHostile);
78056 if (fromNet)
78057 {
78058 color2 = (crit ? CombatText.OthersDamagedHostileCrit : CombatText.OthersDamagedHostile);
78059 }
78060 CombatText.NewText(new Rectangle((int)position.X, (int)position.Y, width, height), color2, (int)num, crit);
78061 }
78062 }
78063 if (num >= 1.0)
78064 {
78065 if (flag)
78066 {
78067 PlayerInteraction(Main.myPlayer);
78068 }
78069 justHit = true;
78070 if ((type == 438 || type == 379) && Main.netMode != 1)
78071 {
78072 int num2 = (int)(0f - ai[3] - 1f);
78073 if (num2 > -1 && Main.npc[num2].localAI[0] == 0f)
78074 {
78075 Main.npc[num2].localAI[0] = 1f;
78076 }
78077 }
78078 if (townNPC)
78079 {
78080 if (aiStyle == 7 && (ai[0] == 3f || ai[0] == 4f || ai[0] == 16f || ai[0] == 17f))
78081 {
78082 NPC nPC = Main.npc[(int)ai[2]];
78083 if (nPC.active)
78084 {
78085 nPC.ai[0] = 1f;
78086 nPC.ai[1] = 300 + Main.rand.Next(300);
78087 nPC.ai[2] = 0f;
78088 nPC.localAI[3] = 0f;
78089 nPC.direction = hitDirection;
78090 nPC.netUpdate = true;
78091 }
78092 }
78093 ai[0] = 1f;
78094 ai[1] = 300 + Main.rand.Next(300);
78095 ai[2] = 0f;
78096 localAI[3] = 0f;
78098 netUpdate = true;
78099 }
78100 if (aiStyle == 8 && Main.netMode != 1)
78101 {
78102 if (type == 172)
78103 {
78104 ai[0] = 450f;
78105 }
78106 else if (type == 283 || type == 284)
78107 {
78108 if (Main.rand.Next(2) == 0)
78109 {
78110 ai[0] = 390f;
78111 netUpdate = true;
78112 }
78113 }
78114 else if (type == 533)
78115 {
78116 if (Main.rand.Next(3) != 0)
78117 {
78118 ai[0] = 181f;
78119 netUpdate = true;
78120 }
78121 }
78122 else
78123 {
78124 ai[0] = 400f;
78125 }
78126 TargetClosest();
78127 }
78128 if (aiStyle == 97 && Main.netMode != 1)
78129 {
78130 localAI[1] = 1f;
78131 TargetClosest();
78132 }
78133 if (type == 371)
78134 {
78135 num = 0.0;
78136 ai[0] = 1f;
78137 ai[1] = 4f;
78138 dontTakeDamage = true;
78139 }
78140 if (type == 346 && (double)life >= (double)lifeMax * 0.5 && (double)life - num < (double)lifeMax * 0.5)
78141 {
78142 Gore.NewGore(position, velocity, 517);
78143 }
78144 if (type == 184)
78145 {
78146 localAI[0] = 60f;
78147 }
78148 if (type == 535)
78149 {
78150 localAI[0] = 60f;
78151 }
78152 if (type == 185)
78153 {
78154 localAI[0] = 1f;
78155 }
78156 if (!immortal)
78157 {
78158 if (realLife >= 0)
78159 {
78160 Main.npc[realLife].life -= (int)num;
78161 life = Main.npc[realLife].life;
78162 lifeMax = Main.npc[realLife].lifeMax;
78163 }
78164 else
78165 {
78166 life -= (int)num;
78167 }
78168 }
78169 if (knockBack > 0f && knockBackResist > 0f)
78170 {
78171 float num3 = knockBack * knockBackResist;
78172 if (onFire2)
78173 {
78174 num3 *= 1.1f;
78175 }
78176 if (num3 > 8f)
78177 {
78178 float num4 = num3 - 8f;
78179 num4 *= 0.9f;
78180 num3 = 8f + num4;
78181 }
78182 if (num3 > 10f)
78183 {
78184 float num5 = num3 - 10f;
78185 num5 *= 0.8f;
78186 num3 = 10f + num5;
78187 }
78188 if (num3 > 12f)
78189 {
78190 float num6 = num3 - 12f;
78191 num6 *= 0.7f;
78192 num3 = 12f + num6;
78193 }
78194 if (num3 > 14f)
78195 {
78196 float num7 = num3 - 14f;
78197 num7 *= 0.6f;
78198 num3 = 14f + num7;
78199 }
78200 if (num3 > 16f)
78201 {
78202 num3 = 16f;
78203 }
78204 if (crit)
78205 {
78206 num3 *= 1.4f;
78207 }
78208 int num8 = (int)num * 10;
78209 if (Main.expertMode)
78210 {
78211 num8 = (int)num * 15;
78212 }
78213 if (num8 > lifeMax)
78214 {
78216 {
78217 if (velocity.X > 0f)
78218 {
78219 velocity.X -= num3;
78220 }
78221 velocity.X -= num3;
78222 if (velocity.X < 0f - num3)
78223 {
78224 velocity.X = 0f - num3;
78225 }
78226 }
78227 else if (hitDirection > 0 && velocity.X < num3)
78228 {
78229 if (velocity.X < 0f)
78230 {
78231 velocity.X += num3;
78232 }
78233 velocity.X += num3;
78234 if (velocity.X > num3)
78235 {
78236 velocity.X = num3;
78237 }
78238 }
78239 if (type == 185)
78240 {
78241 num3 *= 1.5f;
78242 }
78243 num3 = (noGravity ? (num3 * -0.5f) : (num3 * -0.75f));
78244 if (velocity.Y > num3)
78245 {
78246 velocity.Y += num3;
78247 if (velocity.Y < num3)
78248 {
78249 velocity.Y = num3;
78250 }
78251 }
78252 }
78253 else
78254 {
78255 if (!noGravity)
78256 {
78257 velocity.Y = (0f - num3) * 0.75f * knockBackResist;
78258 }
78259 else
78260 {
78261 velocity.Y = (0f - num3) * 0.5f * knockBackResist;
78262 }
78263 velocity.X = num3 * (float)hitDirection * knockBackResist;
78264 }
78265 }
78266 if ((type == 113 || type == 114) && life <= 0)
78267 {
78268 for (int i = 0; i < 200; i++)
78269 {
78270 if (Main.npc[i].active && (Main.npc[i].type == 113 || Main.npc[i].type == 114))
78271 {
78272 Main.npc[i].HitEffect(hitDirection, num);
78273 }
78274 }
78275 }
78276 else
78277 {
78278 HitEffect(hitDirection, num);
78279 }
78280 if (HitSound != null)
78281 {
78283 }
78284 if (realLife >= 0)
78285 {
78286 Main.npc[realLife].checkDead();
78287 }
78288 else
78289 {
78290 checkDead();
78291 }
78292 return num;
78293 }
78294 return 0.0;
78295 }
static void PlaySound(int type, Vector2 position, int style=1)
Vector2 velocity
Definition Entity.cs:16
Vector2 position
Definition Entity.cs:14
int defense
Definition NPC.cs:463
bool immortal
Definition NPC.cs:261
float[] localAI
Definition NPC.cs:449
bool onFire2
Definition NPC.cs:227
int lifeMax
Definition NPC.cs:479
static int ignorePlayerInteractions
Definition NPC.cs:624
void TargetClosest(bool faceTarget=true)
Definition NPC.cs:69934
int aiStyle
Definition NPC.cs:453
float takenDamageMultiplier
Definition NPC.cs:117
bool noGravity
Definition NPC.cs:503
float[] ai
Definition NPC.cs:447
float knockBackResist
Definition NPC.cs:495
bool dontTakeDamage
Definition NPC.cs:527
bool friendly
Definition NPC.cs:555
int type
Definition NPC.cs:445
Color color
Definition NPC.cs:487
void checkDead()
Definition NPC.cs:70326
void HitEffect(int hitDirection=0, double dmg=10.0)
Definition NPC.cs:78386
bool justHit
Definition NPC.cs:455
void PlayerInteraction(int player)
Definition NPC.cs:72193
int life
Definition NPC.cs:477
int realLife
Definition NPC.cs:173
bool netUpdate
Definition NPC.cs:507
bool townNPC
Definition NPC.cs:537
LegacySoundStyle HitSound
Definition NPC.cs:473

References Terraria.Main.CalculateDamageNPCsTake(), Terraria.GameContent.Damage, 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(), Terraria.Main.rand, and System.type.

Referenced by Terraria.Player.ApplyDamageToNPC().