Terraria.Player.OnHit C# (CSharp) Method

OnHit() public method

public OnHit ( float x, float y, Entity victim ) : void
x float
y float
victim Entity
return void
        public void OnHit(float x, float y, Entity victim)
        {
            if (Main.myPlayer != this.whoAmI)
                return;
            if (this.onHitDodge && this.shadowDodgeTimer == 0 && Main.rand.Next(4) == 0)
            {
                if (!this.shadowDodge)
                    this.shadowDodgeTimer = 1800;
                this.AddBuff(59, 1800, true);
            }
            if (this.onHitRegen)
                this.AddBuff(58, 300, true);
            if (this.stardustMinion && victim is NPC)
            {
                for (int index = 0; index < 1000; ++index)
                {
                    Projectile projectile = Main.projectile[index];
                    if (projectile.active && projectile.owner == this.whoAmI && (projectile.type == 613 && (double)projectile.localAI[1] <= 0.0) && Main.rand.Next(2) == 0)
                    {
                        Vector2 vector2 = new Vector2(x, y) - projectile.Center;
                        if ((double)vector2.Length() > 0.0)
                            vector2.Normalize();
                        vector2 *= 20f;
                        Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, vector2.X, vector2.Y, 614, projectile.damage / 3, 0.0f, projectile.owner, 0.0f, (float)victim.whoAmI);
                        projectile.localAI[1] = (float)(30 + Main.rand.Next(4) * 10);
                    }
                }
            }
            if (this.onHitPetal && this.petalTimer == 0)
            {
                this.petalTimer = 20;
                int num1 = 1;
                if ((double)x < (double)this.position.X + (double)(this.width / 2))
                    num1 = -1;
                int num2 = this.direction;
                float num3 = Main.screenPosition.X;
                if (num2 < 0)
                    num3 += (float)Main.screenWidth;
                float num4 = Main.screenPosition.Y + (float)Main.rand.Next(Main.screenHeight);
                Vector2 vector2 = new Vector2(num3, num4);
                float num5 = x - vector2.X;
                float num6 = y - vector2.Y;
                float num7 = num5 + (float)Main.rand.Next(-50, 51) * 0.1f;
                float num8 = num6 + (float)Main.rand.Next(-50, 51) * 0.1f;
                float num9 = 24f / (float)Math.Sqrt((double)num7 * (double)num7 + (double)num8 * (double)num8);
                float SpeedX = num7 * num9;
                float SpeedY = num8 * num9;
                Projectile.NewProjectile(num3, num4, SpeedX, SpeedY, 221, 36, 0.0f, this.whoAmI, 0.0f, 0.0f);
            }
            if (!this.crystalLeaf || this.petalTimer != 0)
                return;
            int num10 = this.inventory[this.selectedItem].itemId;
            for (int index = 0; index < 1000; ++index)
            {
                if (Main.projectile[index].owner == this.whoAmI && Main.projectile[index].type == 226)
                {
                    this.petalTimer = 50;
                    float num1 = 12f;
                    Vector2 vector2 = new Vector2(Main.projectile[index].position.X + (float)this.width * 0.5f, Main.projectile[index].position.Y + (float)this.height * 0.5f);
                    float num2 = x - vector2.X;
                    float num3 = y - vector2.Y;
                    float num4 = (float)Math.Sqrt((double)num2 * (double)num2 + (double)num3 * (double)num3);
                    float num5 = num1 / num4;
                    float SpeedX = num2 * num5;
                    float SpeedY = num3 * num5;
                    Projectile.NewProjectile(Main.projectile[index].Center.X - 4f, Main.projectile[index].Center.Y, SpeedX, SpeedY, 227, Player.crystalLeafDamage, (float)Player.crystalLeafKB, this.whoAmI, 0.0f, 0.0f);
                    break;
                }
            }
        }
Player