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

◆ ProcessHitAgainstNPC()

void Terraria.Player.ProcessHitAgainstNPC ( Item sItem,
Rectangle itemRectangle,
int originalDamage,
float knockBack,
int npcIndex )
inlineprivate

Definition at line 42076 of file Player.cs.

42077 {
42078 NPC nPC = Main.npc[npcIndex];
42079 if (nPC.dontTakeDamage || !CanNPCBeHitByPlayerOrPlayerProjectile(nPC))
42080 {
42081 if (NPCID.Sets.ZappingJellyfish[nPC.type] && itemRectangle.Intersects(nPC.Hitbox) && (nPC.noTileCollide || CanHit(nPC)))
42082 {
42084 }
42085 }
42086 else
42087 {
42088 if (nPC.friendly && (nPC.type != 22 || !killGuide) && (nPC.type != 54 || !killClothier) && (!nPC.isLikeATownNPC || sItem.type != 5129))
42089 {
42090 return;
42091 }
42092 Rectangle rectangle = new Rectangle((int)nPC.position.X, (int)nPC.position.Y, nPC.width, nPC.height);
42093 bool flag = itemRectangle.Intersects(rectangle);
42094 int type = sItem.type;
42095 if (type == 121)
42096 {
42099 bool flag2 = Utils.LineRectangleDistance(rectangle, location, location2) <= 16f;
42100 flag = ((!_spawnVolcanoExplosion) ? (flag || flag2) : flag2);
42101 }
42102 if (!flag || (!nPC.noTileCollide && !CanHit(nPC)))
42103 {
42104 return;
42105 }
42106 int num = originalDamage;
42107 bool flag3 = false;
42109 if (Main.rand.Next(1, 101) <= weaponCrit)
42110 {
42111 flag3 = true;
42112 }
42113 int num2 = Item.NPCtoBanner(nPC.BannerID());
42114 if (num2 > 0 && HasNPCBannerBuff(num2))
42115 {
42116 num = ((!Main.expertMode) ? ((int)((float)num * ItemID.Sets.BannerStrength[Item.BannerToItem(num2)].NormalDamageDealt)) : ((int)((float)num * ItemID.Sets.BannerStrength[Item.BannerToItem(num2)].ExpertDamageDealt)));
42117 }
42118 if (parryDamageBuff && sItem.melee)
42119 {
42120 num *= 5;
42121 parryDamageBuff = false;
42122 ClearBuff(198);
42123 }
42124 if (sItem.type == 426 && (float)nPC.life >= (float)nPC.lifeMax * 0.9f)
42125 {
42126 num = (int)((float)num * 2.5f);
42127 }
42128 if (sItem.type == 5096)
42129 {
42130 int num3 = 0;
42131 if (FindBuffIndex(26) != -1)
42132 {
42133 num3 = 1;
42134 }
42135 if (FindBuffIndex(206) != -1)
42136 {
42137 num3 = 2;
42138 }
42139 if (FindBuffIndex(207) != -1)
42140 {
42141 num3 = 3;
42142 }
42143 float num4 = 1f + 0.05f * (float)num3;
42144 num = (int)((float)num * num4);
42145 }
42146 if (sItem.type == 671)
42147 {
42148 float t = (float)nPC.life / (float)nPC.lifeMax;
42149 float lerpValue = Utils.GetLerpValue(1f, 0.1f, t, clamped: true);
42150 float num5 = 1f * lerpValue;
42151 num = (int)((float)num * (1f + num5));
42152 Vector2 point = itemRectangle.Center.ToVector2();
42153 Vector2 positionInWorld = nPC.Hitbox.ClosestPointInRect(point);
42155 {
42156 PositionInWorld = positionInWorld
42157 }, whoAmI);
42158 }
42159 int num6 = Main.DamageVar(num, luck);
42160 float armorPenetrationPercent = 0f;
42161 if (sItem.type == 5129 && nPC.isLikeATownNPC)
42162 {
42164 if (nPC.type == 18)
42165 {
42166 num6 *= 2;
42167 }
42168 }
42169 if (sItem.type == 3258)
42170 {
42172 particleOrchestraSettings.PositionInWorld = nPC.Center;
42175 }
42176 if (sItem.type == 5382)
42177 {
42179 particleOrchestraSettings.PositionInWorld = nPC.Center;
42182 }
42183 if (sItem.type == 5129)
42184 {
42186 particleOrchestraSettings.PositionInWorld = nPC.Center;
42189 }
42190 StatusToNPC(sItem.type, npcIndex);
42191 if (nPC.life > 5)
42192 {
42193 OnHit(nPC.Center.X, nPC.Center.Y, nPC);
42194 }
42195 num6 += nPC.checkArmorPenetration(armorPenetration, armorPenetrationPercent);
42197 int dmgDone = (int)nPC.StrikeNPC(num6, knockBack, direction, flag3);
42199 int num7 = Item.NPCtoBanner(nPC.BannerID());
42200 if (num7 >= 0)
42201 {
42203 }
42204 if (Main.netMode != 0)
42205 {
42206 if (flag3)
42207 {
42208 NetMessage.SendData(28, -1, -1, null, npcIndex, num6, knockBack, direction, 1);
42209 }
42210 else
42211 {
42212 NetMessage.SendData(28, -1, -1, null, npcIndex, num6, knockBack, direction);
42213 }
42214 }
42215 if (accDreamCatcher)
42216 {
42217 addDPS(num6);
42218 }
42220 if (attempt.DidNPCDie())
42221 {
42223 }
42225 }
42226 }
static void RequestParticleSpawn(bool clientOnly, ParticleOrchestraType type, ParticleOrchestraSettings settings, int? overrideInvokingPlayerIndex=null)
static BannerEffect[] BannerStrength
Definition ItemID.cs:1018
static bool[] ZappingJellyfish
Definition NPCID.cs:4111
bool HasNPCBannerBuff(int bannerType)
Definition Player.cs:42017
void TakeDamageFromJellyfish(int npcIndex)
Definition Player.cs:42068
bool parryDamageBuff
Definition Player.cs:2011
void SetMeleeHitCooldown(int npcIndex, int timeInFrames)
Definition Player.cs:42049
void addDPS(int dmg)
Definition Player.cs:50700
void ApplyAttackCooldown()
Definition Player.cs:42228
void StatusToNPC(int type, int i)
Definition Player.cs:5468
bool CanNPCBeHitByPlayerOrPlayerProjectile(NPC npc, Projectile projectile=null)
Definition Player.cs:19902
int FindBuffIndex(int type)
Definition Player.cs:4425
bool CanHit(Entity ent)
Definition Player.cs:40596
bool killClothier
Definition Player.cs:2337
void GetPointOnSwungItemPath(float spriteWidth, float spriteHeight, float normalizedPointOnPath, float itemScale, out Vector2 location, out Vector2 outwardDirection)
Definition Player.cs:42553
int GetWeaponCrit(Item sItem)
Definition Player.cs:49892
int lastCreatureHit
Definition Player.cs:2169
float GetAdjustedItemScale(Item item)
Definition Player.cs:40623
void OnKillNPC(ref NPCKillAttempt attempt, object externalKillingBlowSource)
Definition Player.cs:19875
int armorPenetration
Definition Player.cs:1551
void ApplyNPCOnHitEffects(Item sItem, Rectangle itemRectangle, int damage, float knockBack, int npcIndex, int dmgRandomized, int dmgDone)
Definition Player.cs:42241
void OnHit(float x, float y, Entity victim)
Definition Player.cs:5855
bool _spawnVolcanoExplosion
Definition Player.cs:2455
bool accDreamCatcher
Definition Player.cs:2187
void ClearBuff(int type)
Definition Player.cs:4623

References Terraria.ID.ItemID.Sets.BannerStrength, Terraria.Item.BannerToItem(), Terraria.Main.DamageVar(), Terraria.Main.expertMode, Terraria.Utils.GetLerpValue(), Terraria.Utils.LineRectangleDistance(), Terraria.Main.netMode, Terraria.Main.npc, Terraria.Item.NPCtoBanner(), Terraria.Main.rand, Terraria.GameContent.Drawing.ParticleOrchestrator.RequestParticleSpawn(), Terraria.NetMessage.SendData(), System.type, and Terraria.ID.NPCID.Sets.ZappingJellyfish.