Terraria.Projectile.Damage C# (CSharp) Method

Damage() public method

public Damage ( ) : void
return void
        public void Damage()
        {
            if (type == 18 || type == 72 || (type == 86 || type == 87) || (aiStyle == 31 || aiStyle == 32 || (type == 226 || type == 378)) || (type == 613 || type == 650 || type == 434 && localAI[0] != 0.0 || (type == 439 || type == 444)) || (type == 451 && ((int)(ai[0] - 1.0) / penetrate == 0 || ai[1] < 5.0) && ai[0] != 0.0 || (type == 500 || type == 460 || (type == 633 || type == 600) || (type == 601 || type == 602 || type == 535))) || (type == 631 && localAI[1] == 0.0 || aiStyle == 93 && ai[0] != 0.0 && ai[0] != 2.0 || aiStyle == 10 && localAI[1] == -1.0) || Main.projPet[type] && type != 266 && (type != 407 && type != 317) && ((type != 388 || ai[0] != 2.0) && (type < 390 || type > 392)) && ((type < 393 || type > 395) && (type != 533 || ai[0] < 6.0 || ai[0] > 8.0)) && (type < 625 || type > 628))
                return;
            Rectangle myRect = new Rectangle((int)position.X, (int)position.Y, width, height);
            if (type == 85 || type == 101)
            {
                int num = 30;
                myRect.X -= num;
                myRect.Y -= num;
                myRect.Width += num * 2;
                myRect.Height += num * 2;
            }
            if (type == 188)
            {
                int num = 20;
                myRect.X -= num;
                myRect.Y -= num;
                myRect.Width += num * 2;
                myRect.Height += num * 2;
            }
            if (aiStyle == 29)
            {
                int num = 4;
                myRect.X -= num;
                myRect.Y -= num;
                myRect.Width += num * 2;
                myRect.Height += num * 2;
            }
            if (friendly && owner == Main.myPlayer && !npcProj)
            {
                if (aiStyle == 16 && type != 338 && (type != 339 && type != 340) && type != 341 && (timeLeft <= 1 || type == 108 || type == 164) || type == 286 && localAI[1] == -1.0)
                {
                    int index = Main.myPlayer;
                    if (Main.player[index].active && !Main.player[index].dead && !Main.player[index].immune && (!ownerHitCheck || Collision.CanHit(Main.player[owner].position, Main.player[owner].width, Main.player[owner].height, Main.player[index].position, Main.player[index].width, Main.player[index].height)))
                    {
                        Rectangle rectangle = new Rectangle((int)Main.player[index].position.X, (int)Main.player[index].position.Y, Main.player[index].width, Main.player[index].height);
                        if (myRect.Intersects(rectangle))
                        {
                            if (Main.player[index].position.X + (Main.player[index].width / 2) < position.X + (width / 2))
                                direction = -1;
                            else
                                direction = 1;
                            int Damage = Main.DamageVar(damage);
                            StatusPlayer(index);
                            Main.player[index].Hurt(Damage, direction, true, false, Lang.deathMsg(owner, -1, whoAmI, -1), false);
                            if (trap)
                            {
                                Main.player[index].trapDebuffSource = true;
                                if (Main.player[index].dead)
                                    AchievementsHelper.HandleSpecialEvent(Main.player[index], 4);
                            }
                            if (Main.netMode != 0)
                                NetMessage.SendData(26, -1, -1, Lang.deathMsg(owner, -1, whoAmI, -1), index, direction, Damage, 1f, 0, 0, 0);
                        }
                    }
                }
                if (aiStyle != 45 && aiStyle != 92 && (aiStyle != 105 && aiStyle != 106) && (type != 463 && type != 69 && (type != 70 && type != 621)) && (type != 10 && type != 11 && (type != 379 && type != 407) && (type != 476 && type != 623 && (type < 625 || type > 628))))
                {
                    int num1 = (int)(position.X / 16.0);
                    int num2 = (int)((position.X + width) / 16.0) + 1;
                    int num3 = (int)(position.Y / 16.0);
                    int num4 = (int)((position.Y + height) / 16.0) + 1;
                    if (num1 < 0)
                        num1 = 0;
                    if (num2 > Main.maxTilesX)
                        num2 = Main.maxTilesX;
                    if (num3 < 0)
                        num3 = 0;
                    if (num4 > Main.maxTilesY)
                        num4 = Main.maxTilesY;
                    AchievementsHelper.CurrentlyMining = true;
                    for (int i = num1; i < num2; ++i)
                    {
                        for (int j = num3; j < num4; ++j)
                        {
                            if (Main.tile[i, j] != null && Main.tileCut[Main.tile[i, j].type] && (Main.tile[i, j + 1] != null && Main.tile[i, j + 1].type != 78) && Main.tile[i, j + 1].type != 380)
                            {
                                WorldGen.KillTile(i, j, false, false, false);
                                if (Main.netMode != 0)
                                    NetMessage.SendData(17, -1, -1, "", 0, i, j, 0.0f, 0, 0, 0);
                            }
                        }
                    }
                    if (type == 461 || type == 632 || type == 642)
                        Utils.PlotTileLine(Center, Center + velocity * localAI[1], width * scale, new Utils.PerLinePoint(DelegateMethods.CutTiles));
                    else if (type == 611)
                        Utils.PlotTileLine(Center, Center + velocity, width * scale, new Utils.PerLinePoint(DelegateMethods.CutTiles));
                    AchievementsHelper.CurrentlyMining = false;
                }
            }
            if (owner == Main.myPlayer)
            {
                if (damage > 0)
                {
                    for (int index1 = 0; index1 < 200; ++index1)
                    {
                        bool flag1 = !updatedNPCImmunity || npcImmune[index1] == 0;
                        if (Main.npc[index1].active && !Main.npc[index1].dontTakeDamage && flag1 && (friendly && (!Main.npc[index1].friendly || type == 318 || Main.npc[index1].type == 22 && owner < 255 && Main.player[owner].killGuide || Main.npc[index1].type == 54 && owner < 255 && Main.player[owner].killClothier) || hostile && Main.npc[index1].friendly) && (owner < 0 || Main.npc[index1].immune[owner] == 0 || maxPenetrate == 1))
                        {
                            bool flag2 = false;
                            if (type == 11 && (Main.npc[index1].type == 47 || Main.npc[index1].type == 57))
                                flag2 = true;
                            else if (type == 31 && Main.npc[index1].type == 69)
                                flag2 = true;
                            else if (Main.npc[index1].trapImmune && trap)
                                flag2 = true;
                            else if (Main.npc[index1].immortal && npcProj)
                                flag2 = true;
                            if (!flag2 && (Main.npc[index1].noTileCollide || !ownerHitCheck || Collision.CanHit(Main.player[owner].position, Main.player[owner].width, Main.player[owner].height, Main.npc[index1].position, Main.npc[index1].width, Main.npc[index1].height)))
                            {
                                bool flag3;
                                if (Main.npc[index1].type == 414)
                                {
                                    Rectangle rect = Main.npc[index1].getRect();
                                    int num = 8;
                                    rect.X -= num;
                                    rect.Y -= num;
                                    rect.Width += num * 2;
                                    rect.Height += num * 2;
                                    flag3 = Colliding(myRect, rect);
                                }
                                else
                                    flag3 = Colliding(myRect, Main.npc[index1].getRect());
                                if (flag3)
                                {
                                    if (type == 604)
                                        Main.player[owner].Counterweight(Main.npc[index1].Center, damage, knockBack);
                                    if (Main.npc[index1].reflectingProjectiles && CanReflect())
                                    {
                                        Main.npc[index1].ReflectProjectile(whoAmI);
                                        return;
                                    }
                                    int Damage1 = Main.DamageVar(damage);
                                    if (type == 604)
                                    {
                                        friendly = false;
                                        ai[1] = 1000f;
                                    }
                                    if ((type == 400 || type == 401 || type == 402) && (Main.npc[index1].type >= 13 && Main.npc[index1].type <= 15))
                                    {
                                        Damage1 = (int)(Damage1 * 0.65);
                                        if (penetrate > 1)
                                            --penetrate;
                                    }
                                    if (type == 504)
                                        ai[0] += (float)((60.0 - ai[0]) / 2.0);
                                    if (aiStyle == 3 && type != 301)
                                    {
                                        if (ai[0] == 0.0)
                                        {
                                            velocity.X = -velocity.X;
                                            velocity.Y = -velocity.Y;
                                            netUpdate = true;
                                        }
                                        ai[0] = 1f;
                                    }
                                    else if (type == 582)
                                    {
                                        if (ai[0] != 0.0)
                                            direction *= -1;
                                    }
                                    else if (type == 612)
                                        direction = Main.player[owner].direction;
                                    else if (type == 624)
                                    {
                                        float num = 1f;
                                        if (Main.npc[index1].knockBackResist > 0.0)
                                            num = 1f / Main.npc[index1].knockBackResist;
                                        knockBack = 4f * num;
                                        if (Main.npc[index1].Center.X < Center.X)
                                            direction = 1;
                                        else
                                            direction = -1;
                                    }
                                    else if (aiStyle == 16)
                                    {
                                        if (timeLeft > 3)
                                            timeLeft = 3;
                                        if (Main.npc[index1].position.X + (Main.npc[index1].width / 2) < position.X + (width / 2))
                                            direction = -1;
                                        else
                                            direction = 1;
                                    }
                                    else if (aiStyle == 68)
                                    {
                                        if (timeLeft > 3)
                                            timeLeft = 3;
                                        if (Main.npc[index1].position.X + (Main.npc[index1].width / 2) < position.X + (width / 2))
                                            direction = -1;
                                        else
                                            direction = 1;
                                    }
                                    else if (aiStyle == 50)
                                    {
                                        if (Main.npc[index1].position.X + (Main.npc[index1].width / 2) < position.X + (width / 2))
                                            direction = -1;
                                        else
                                            direction = 1;
                                    }
                                    if (type == 509)
                                    {
                                        int num = Main.rand.Next(2, 6);
                                        for (int index2 = 0; index2 < num; ++index2)
                                        {
                                            Vector2 vector2 = new Vector2(Main.rand.Next(-100, 101), Main.rand.Next(-100, 101));
                                            vector2 += velocity * 3f;
                                            vector2.Normalize();
                                            vector2 *= Main.rand.Next(35, 81) * 0.1f;
                                            int Damage2 = (int)(damage * 0.5);
                                            NewProjectile(Center.X, Center.Y, vector2.X, vector2.Y, 504, Damage2, knockBack * 0.2f, owner, 0.0f, 0.0f);
                                        }
                                    }
                                    if (type == 598 || type == 636 || type == 614)
                                    {
                                        ai[0] = 1f;
                                        ai[1] = index1;
                                        velocity = (Main.npc[index1].Center - Center) * 0.75f;
                                        netUpdate = true;
                                    }
                                    if (type >= 511 && type <= 513)
                                        timeLeft = 0;
                                    if (type == 524)
                                    {
                                        netUpdate = true;
                                        ai[0] += 50f;
                                    }
                                    if (aiStyle == 39)
                                    {
                                        if (ai[1] == 0.0)
                                        {
                                            ai[1] = (index1 + 1);
                                            netUpdate = true;
                                        }
                                        if (Main.player[owner].position.X + (Main.player[owner].width / 2) < position.X + (width / 2))
                                            direction = 1;
                                        else
                                            direction = -1;
                                    }
                                    if (type == 41 && timeLeft > 1)
                                        timeLeft = 1;
                                    bool crit = false;
                                    if (!npcProj && !trap)
                                    {
                                        if (melee && Main.rand.Next(1, 101) <= Main.player[owner].meleeCrit)
                                            crit = true;
                                        if (ranged && Main.rand.Next(1, 101) <= Main.player[owner].rangedCrit)
                                            crit = true;
                                        if (magic && Main.rand.Next(1, 101) <= Main.player[owner].magicCrit)
                                            crit = true;
                                        if (thrown && Main.rand.Next(1, 101) <= Main.player[owner].thrownCrit)
                                            crit = true;
                                    }
                                    if (aiStyle == 99)
                                    {
                                        Main.player[owner].Counterweight(Main.npc[index1].Center, damage, knockBack);
                                        if (Main.npc[index1].Center.X < Main.player[owner].Center.X)
                                            direction = -1;
                                        else
                                            direction = 1;
                                        if (ai[0] >= 0.0)
                                        {
                                            Vector2 vector2_1 = Center - Main.npc[index1].Center;
                                            vector2_1.Normalize();
                                            float num = 16f;
                                            Projectile projectile1 = this;
                                            Vector2 vector2_2 = projectile1.velocity * -0.5f;
                                            projectile1.velocity = vector2_2;
                                            Projectile projectile2 = this;
                                            Vector2 vector2_3 = projectile2.velocity + vector2_1 * num;
                                            projectile2.velocity = vector2_3;
                                            netUpdate = true;
                                            localAI[0] += 20f;
                                            if (!Collision.CanHit(position, width, height, Main.player[owner].position, Main.player[owner].width, Main.player[owner].height))
                                            {
                                                localAI[0] += 40f;
                                                Damage1 = (int)(Damage1 * 0.75);
                                            }
                                        }
                                    }
                                    if (aiStyle == 93)
                                    {
                                        if (ai[0] == 0.0)
                                        {
                                            ai[1] = 0.0f;
                                            ai[0] = (-index1 - 1);
                                            velocity = Main.npc[index1].Center - Center;
                                        }
                                        Damage1 = ai[0] != 2.0 ? (int)(Damage1 * 0.15) : (int)(Damage1 * 1.35);
                                    }
                                    if (!npcProj)
                                    {
                                        int num = Item.NPCtoBanner(Main.npc[index1].BannerID());
                                        if (num >= 0)
                                            Main.player[Main.myPlayer].lastCreatureHit = num;
                                    }
                                    if (Main.netMode != 2)
                                    {
                                        int index2 = Item.NPCtoBanner(Main.npc[index1].BannerID());
                                        if (index2 > 0 && Main.player[owner].NPCBannerBuff[index2])
                                        {
                                            if (Main.expertMode)
                                                Damage1 *= 2;
                                            else
                                                Damage1 = (int)(Damage1 * 1.5);
                                        }
                                    }
                                    if (Main.expertMode)
                                    {
                                        if ((type == 30 || type == 28 || (type == 29 || type == 470) || (type == 517 || type == 588 || type == 637)) && (Main.npc[index1].type >= 13 && Main.npc[index1].type <= 15))
                                            Damage1 /= 5;
                                        if (type == 280 && (Main.npc[index1].type >= 134 && Main.npc[index1].type <= 136 || Main.npc[index1].type == 139))
                                            Damage1 = (int)(Damage1 * 0.75);
                                    }
                                    if (Main.netMode != 2 && Main.npc[index1].type == 439 && (type >= 0 && type <= 651) && ProjectileID.Sets.Homing[type])
                                        Damage1 = (int)(Damage1 * 0.75);
                                    if (type == 497 && penetrate != 1)
                                    {
                                        ai[0] = 25f;
                                        float num = velocity.Length();
                                        Vector2 vector2 = Main.npc[index1].Center - Center;
                                        vector2.Normalize();
                                        velocity = -(vector2 * num) * 0.9f;
                                        netUpdate = true;
                                    }
                                    if (type == 323 && (Main.npc[index1].type == 158 || Main.npc[index1].type == 159))
                                        Damage1 *= 10;
                                    if (type == 294)
                                        damage = (int)(damage * 0.8);
                                    if (type == 477 && penetrate > 1)
                                    {
                                        int[] numArray = new int[10];
                                        int maxValue = 0;
                                        int num1 = 700;
                                        int num2 = 20;
                                        for (int index2 = 0; index2 < 200; ++index2)
                                        {
                                            if (index2 != index1 && Main.npc[index2].CanBeChasedBy(this, false))
                                            {
                                                float num3 = (Center - Main.npc[index2].Center).Length();
                                                if (num3 > num2 && num3 < num1 && Collision.CanHitLine(Center, 1, 1, Main.npc[index2].Center, 1, 1))
                                                {
                                                    numArray[maxValue] = index2;
                                                    ++maxValue;
                                                    if (maxValue >= 9)
                                                        break;
                                                }
                                            }
                                        }
                                        if (maxValue > 0)
                                        {
                                            int index2 = Main.rand.Next(maxValue);
                                            Vector2 vector2 = Main.npc[numArray[index2]].Center - Center;
                                            float num3 = velocity.Length();
                                            vector2.Normalize();
                                            velocity = vector2 * num3;
                                            netUpdate = true;
                                        }
                                    }
                                    if (type == 261)
                                    {
                                        float num = (float)Math.Sqrt(velocity.X * velocity.X + velocity.Y * velocity.Y);
                                        if (num < 1.0)
                                            num = 1f;
                                        Damage1 = (int)(Damage1 * num / 8.0);
                                    }
                                    StatusNPC(index1);
                                    if (type != 221 && type != 227 && type != 614)
                                        Main.player[owner].OnHit(Main.npc[index1].Center.X, Main.npc[index1].Center.Y, Main.npc[index1]);
                                    if (type == 317)
                                    {
                                        ai[1] = -1f;
                                        netUpdate = true;
                                    }
                                    if (!npcProj && !hostile && Main.player[owner].armorPenetration > 0)
                                        Damage1 += Main.npc[index1].checkArmorPenetration(Main.player[owner].armorPenetration);
                                    int dmg = npcProj ? (int)Main.npc[index1].StrikeNPCNoInteraction(Damage1, knockBack, direction, crit, false, false) : (int)Main.npc[index1].StrikeNPC(Damage1, knockBack, direction, crit, false, false);
                                    if (!npcProj && Main.player[owner].accDreamCatcher)
                                        Main.player[owner].addDPS(dmg);
                                    if (!npcProj && !Main.npc[index1].immortal)
                                    {
                                        if (type == 304 && dmg > 0 && (Main.npc[index1].lifeMax > 5 && !Main.player[owner].moonLeech))
                                            vampireHeal(dmg, new Vector2(Main.npc[index1].Center.X, Main.npc[index1].Center.Y));
                                        if (Main.npc[index1].value > 0.0 && Main.player[owner].coins && Main.rand.Next(5) == 0)
                                        {
                                            int Type = 71;
                                            if (Main.rand.Next(10) == 0)
                                                Type = 72;
                                            if (Main.rand.Next(100) == 0)
                                                Type = 73;
                                            int number = Item.NewItem((int)Main.npc[index1].position.X, (int)Main.npc[index1].position.Y, Main.npc[index1].width, Main.npc[index1].height, Type, 1, false, 0, false);
                                            Main.item[number].stack = Main.rand.Next(1, 11);
                                            Main.item[number].velocity.Y = Main.rand.Next(-20, 1) * 0.2f;
                                            Main.item[number].velocity.X = Main.rand.Next(10, 31) * 0.2f * direction;
                                            if (Main.netMode == 1)
                                                NetMessage.SendData(21, -1, -1, "", number, 0.0f, 0.0f, 0.0f, 0, 0, 0);
                                        }
                                        if (dmg > 0 && Main.npc[index1].lifeMax > 5 && (friendly && !hostile) && aiStyle != 59)
                                        {
                                            if (Main.npc[index1].canGhostHeal)
                                            {
                                                if (Main.player[owner].ghostHeal && !Main.player[owner].moonLeech)
                                                    ghostHeal(dmg, new Vector2(Main.npc[index1].Center.X, Main.npc[index1].Center.Y));
                                                if (Main.player[owner].ghostHurt)
                                                    ghostHurt(dmg, new Vector2(Main.npc[index1].Center.X, Main.npc[index1].Center.Y));
                                                if (Main.player[owner].setNebula && Main.player[owner].nebulaCD == 0 && Main.rand.Next(3) == 0)
                                                {
                                                    Main.player[owner].nebulaCD = 30;
                                                    int Type = Utils.SelectRandom(Main.rand, 3453, 3454, 3455);
                                                    int number = Item.NewItem((int)Main.npc[index1].position.X, (int)Main.npc[index1].position.Y, Main.npc[index1].width, Main.npc[index1].height, Type, 1, false, 0, false);
                                                    Main.item[number].velocity.Y = Main.rand.Next(-20, 1) * 0.2f;
                                                    Main.item[number].velocity.X = Main.rand.Next(10, 31) * 0.2f * direction;
                                                    if (Main.netMode == 1)
                                                        NetMessage.SendData(21, -1, -1, "", number, 0.0f, 0.0f, 0.0f, 0, 0, 0);
                                                }
                                            }
                                            if (melee && Main.player[owner].beetleOffense)
                                            {
                                                if (Main.player[owner].beetleOrbs == 0)
                                                    Main.player[owner].beetleCounter += (dmg * 3);
                                                else if (Main.player[owner].beetleOrbs == 1)
                                                    Main.player[owner].beetleCounter += (dmg * 2);
                                                else
                                                    Main.player[owner].beetleCounter += dmg;
                                                Main.player[owner].beetleCountdown = 0;
                                            }
                                            if (arrow && type != 631 && Main.player[owner].phantasmTime > 0)
                                            {
                                                Vector2 Source = Main.player[owner].position + Main.player[owner].Size * Utils.RandomVector2(Main.rand, 0.0f, 1f);
                                                Vector2 vector2 = Main.npc[index1].DirectionFrom(Source) * 6f;
                                                NewProjectile(Source.X, Source.Y, vector2.X, vector2.Y, 631, damage, 0.0f, owner, index1, 0.0f);
                                                NewProjectile(Source.X, Source.Y, vector2.X, vector2.Y, 631, damage, 0.0f, owner, index1, 15f);
                                                NewProjectile(Source.X, Source.Y, vector2.X, vector2.Y, 631, damage, 0.0f, owner, index1, 30f);
                                            }
                                        }
                                    }
                                    if (!npcProj && melee && Main.player[owner].meleeEnchant == 7)
                                        NewProjectile(Main.npc[index1].Center.X, Main.npc[index1].Center.Y, Main.npc[index1].velocity.X, Main.npc[index1].velocity.Y, 289, 0, 0.0f, owner, 0.0f, 0.0f);
                                    if (Main.netMode != 0)
                                    {
                                        if (crit)
                                            NetMessage.SendData(28, -1, -1, "", index1, Damage1, knockBack, direction, 1, 0, 0);
                                        else
                                            NetMessage.SendData(28, -1, -1, "", index1, Damage1, knockBack, direction, 0, 0, 0);
                                    }
                                    if (type >= 390 && type <= 392)
                                        localAI[1] = 20f;
                                    if (type == 434)
                                        numUpdates = 0;
                                    else if (type == 598 || type == 636 || type == 614)
                                    {
                                        damage = 0;
                                        int length = 6;
                                        if (type == 614)
                                            length = 10;
                                        if (type == 636)
                                            length = 8;
                                        Point[] pointArray = new Point[length];
                                        int num = 0;
                                        for (int x = 0; x < 1000; ++x)
                                        {
                                            if (x != whoAmI && Main.projectile[x].active && (Main.projectile[x].owner == Main.myPlayer && Main.projectile[x].type == type) && (Main.projectile[x].ai[0] == 1.0 && Main.projectile[x].ai[1] == index1))
                                            {
                                                pointArray[num++] = new Point(x, Main.projectile[x].timeLeft);
                                                if (num >= pointArray.Length)
                                                    break;
                                            }
                                        }
                                        if (num >= pointArray.Length)
                                        {
                                            int index2 = 0;
                                            for (int index3 = 1; index3 < pointArray.Length; ++index3)
                                            {
                                                if (pointArray[index3].Y < pointArray[index2].Y)
                                                    index2 = index3;
                                            }
                                            Main.projectile[pointArray[index2].X].Kill();
                                        }
                                    }
                                    else if (type == 632)
                                        Main.npc[index1].immune[owner] = 5;
                                    else if (type == 514)
                                        Main.npc[index1].immune[owner] = 1;
                                    else if (type == 617)
                                        Main.npc[index1].immune[owner] = 4;
                                    else if (type == 611)
                                    {
                                        if (localAI[1] <= 0.0)
                                            NewProjectile(Main.npc[index1].Center.X, Main.npc[index1].Center.Y, 0.0f, 0.0f, 612, damage, 10f, owner, 0.0f, (float)(0.850000023841858 + Utils.NextFloat(Main.rand) * 1.14999997615814));
                                        localAI[1] = 4f;
                                    }
                                    else if (type == 595)
                                        Main.npc[index1].immune[owner] = 5;
                                    else if (type >= 625 && type <= 628)
                                        Main.npc[index1].immune[owner] = 6;
                                    else if (type == 286)
                                        Main.npc[index1].immune[owner] = 5;
                                    else if (type == 514)
                                        Main.npc[index1].immune[owner] = 3;
                                    else if (type == 443)
                                        Main.npc[index1].immune[owner] = 8;
                                    else if (type >= 424 && type <= 426)
                                        Main.npc[index1].immune[owner] = 5;
                                    else if (type == 634 || type == 635)
                                        Main.npc[index1].immune[owner] = 5;
                                    else if (type == 246)
                                        Main.npc[index1].immune[owner] = 7;
                                    else if (type == 249)
                                        Main.npc[index1].immune[owner] = 7;
                                    else if (type == 190)
                                        Main.npc[index1].immune[owner] = 8;
                                    else if (type == 409)
                                        Main.npc[index1].immune[owner] = 6;
                                    else if (type == 407)
                                        Main.npc[index1].immune[owner] = 20;
                                    else if (type == 311)
                                        Main.npc[index1].immune[owner] = 7;
                                    else if (type == 582)
                                    {
                                        Main.npc[index1].immune[owner] = 7;
                                        if (ai[0] != 1.0)
                                        {
                                            ai[0] = 1f;
                                            netUpdate = true;
                                        }
                                    }
                                    else
                                    {
                                        if (type == 451)
                                        {
                                            if (ai[0] == 0.0)
                                                ai[0] += penetrate;
                                            else
                                                ai[0] -= (penetrate + 1);
                                            ai[1] = 0.0f;
                                            netUpdate = true;
                                            break;
                                        }
                                        if (penetrate != 1)
                                            Main.npc[index1].immune[owner] = 10;
                                    }
                                    if (penetrate > 0 && type != 317)
                                    {
                                        if (type == 357)
                                            damage = (int)(damage * 0.9);
                                        --penetrate;
                                        if (penetrate == 0)
                                            break;
                                    }
                                    if (aiStyle == 7)
                                    {
                                        ai[0] = 1f;
                                        damage = 0;
                                        netUpdate = true;
                                    }
                                    else if (aiStyle == 13)
                                    {
                                        ai[0] = 1f;
                                        netUpdate = true;
                                    }
                                    else if (aiStyle == 69)
                                    {
                                        ai[0] = 1f;
                                        netUpdate = true;
                                    }
                                    else if (type == 607)
                                    {
                                        ai[0] = 1f;
                                        netUpdate = true;
                                        friendly = false;
                                    }
                                    else if (type == 638 || type == 639 || type == 640)
                                    {
                                        npcImmune[index1] = -1;
                                        Main.npc[index1].immune[owner] = 0;
                                        damage = (int)(damage * 0.96);
                                    }
                                    else if (type == 642)
                                    {
                                        npcImmune[index1] = 10;
                                        Main.npc[index1].immune[owner] = 0;
                                    }
                                    else if (type == 611 || type == 612)
                                    {
                                        npcImmune[index1] = 6;
                                        Main.npc[index1].immune[owner] = 4;
                                    }
                                    else if (type == 645)
                                    {
                                        npcImmune[index1] = -1;
                                        Main.npc[index1].immune[owner] = 0;
                                        if (ai[1] != -1.0)
                                        {
                                            ai[0] = 0.0f;
                                            ai[1] = -1f;
                                            netUpdate = true;
                                        }
                                    }
                                    ++numHits;
                                }
                            }
                        }
                    }
                }
                if (damage > 0 && Main.player[Main.myPlayer].hostile)
                {
                    for (int index = 0; index < 255; ++index)
                    {
                        if (index != owner && Main.player[index].active && (!Main.player[index].dead && !Main.player[index].immune) && (Main.player[index].hostile && playerImmune[index] <= 0 && (Main.player[Main.myPlayer].team == 0 || Main.player[Main.myPlayer].team != Main.player[index].team)) && ((!ownerHitCheck || Collision.CanHit(Main.player[owner].position, Main.player[owner].width, Main.player[owner].height, Main.player[index].position, Main.player[index].width, Main.player[index].height)) && Colliding(myRect, Main.player[index].getRect())))
                        {
                            if (aiStyle == 3)
                            {
                                if (ai[0] == 0.0)
                                {
                                    velocity.X = -velocity.X;
                                    velocity.Y = -velocity.Y;
                                    netUpdate = true;
                                }
                                ai[0] = 1f;
                            }
                            else if (aiStyle == 16)
                            {
                                if (timeLeft > 3)
                                    timeLeft = 3;
                                if (Main.player[index].position.X + (Main.player[index].width / 2) < position.X + (width / 2))
                                    direction = -1;
                                else
                                    direction = 1;
                            }
                            else if (aiStyle == 68)
                            {
                                if (timeLeft > 3)
                                    timeLeft = 3;
                                if (Main.player[index].position.X + (Main.player[index].width / 2) < position.X + (width / 2))
                                    direction = -1;
                                else
                                    direction = 1;
                            }
                            if (type == 41 && timeLeft > 1)
                                timeLeft = 1;
                            bool Crit = false;
                            if (melee && Main.rand.Next(1, 101) <= Main.player[owner].meleeCrit)
                                Crit = true;
                            int Damage = Main.DamageVar(damage);
                            if (!Main.player[index].immune)
                                StatusPvP(index);
                            if (type != 221 && type != 227 && type != 614)
                                Main.player[owner].OnHit(Main.player[index].Center.X, Main.player[index].Center.Y, Main.player[index]);
                            int dmg = (int)Main.player[index].Hurt(Damage, direction, true, false, Lang.deathMsg(owner, -1, whoAmI, -1), Crit);
                            if (dmg > 0 && Main.player[owner].ghostHeal && (friendly && !hostile))
                                ghostHeal(dmg, new Vector2(Main.player[index].Center.X, Main.player[index].Center.Y));
                            if (type == 304 && dmg > 0)
                                vampireHeal(dmg, new Vector2(Main.player[index].Center.X, Main.player[index].Center.Y));
                            if (melee && Main.player[owner].meleeEnchant == 7)
                                NewProjectile(Main.player[index].Center.X, Main.player[index].Center.Y, Main.player[index].velocity.X, Main.player[index].velocity.Y, 289, 0, 0.0f, owner, 0.0f, 0.0f);
                            if (Main.netMode != 0)
                            {
                                if (Crit)
                                    NetMessage.SendData(26, -1, -1, Lang.deathMsg(owner, -1, whoAmI, -1), index, direction, Damage, 1f, 1, 0, 0);
                                else
                                    NetMessage.SendData(26, -1, -1, Lang.deathMsg(owner, -1, whoAmI, -1), index, direction, Damage, 1f, 0, 0, 0);
                            }
                            playerImmune[index] = 40;
                            if (penetrate > 0)
                            {
                                --penetrate;
                                if (penetrate == 0)
                                    break;
                            }
                            if (aiStyle == 7)
                            {
                                ai[0] = 1f;
                                damage = 0;
                                netUpdate = true;
                            }
                            else if (aiStyle == 13)
                            {
                                ai[0] = 1f;
                                netUpdate = true;
                            }
                            else if (aiStyle == 69)
                            {
                                ai[0] = 1f;
                                netUpdate = true;
                            }
                        }
                    }
                }
            }
            if (type == 10 && Main.netMode != 1)
            {
                for (int index = 0; index < 200; ++index)
                {
                    if (Main.npc[index].active && Main.npc[index].type == 534)
                    {
                        Rectangle rectangle = new Rectangle((int)Main.npc[index].position.X, (int)Main.npc[index].position.Y, Main.npc[index].width, Main.npc[index].height);
                        if (myRect.Intersects(rectangle))
                            Main.npc[index].Transform(441);
                    }
                }
            }
            if (type == 11 && Main.netMode != 1)
            {
                for (int index = 0; index < 200; ++index)
                {
                    if (Main.npc[index].active)
                    {
                        if (Main.npc[index].type == 46 || Main.npc[index].type == 303)
                        {
                            Rectangle rectangle = new Rectangle((int)Main.npc[index].position.X, (int)Main.npc[index].position.Y, Main.npc[index].width, Main.npc[index].height);
                            if (myRect.Intersects(rectangle))
                                Main.npc[index].Transform(47);
                        }
                        else if (Main.npc[index].type == 55)
                        {
                            Rectangle rectangle = new Rectangle((int)Main.npc[index].position.X, (int)Main.npc[index].position.Y, Main.npc[index].width, Main.npc[index].height);
                            if (myRect.Intersects(rectangle))
                                Main.npc[index].Transform(57);
                        }
                        else if (Main.npc[index].type == 148 || Main.npc[index].type == 149)
                        {
                            Rectangle rectangle = new Rectangle((int)Main.npc[index].position.X, (int)Main.npc[index].position.Y, Main.npc[index].width, Main.npc[index].height);
                            if (myRect.Intersects(rectangle))
                                Main.npc[index].Transform(168);
                        }
                    }
                }
            }
            if (type == 463 && Main.netMode != 1)
            {
                for (int index = 0; index < 200; ++index)
                {
                    if (Main.npc[index].active)
                    {
                        if (Main.npc[index].type == 46 || Main.npc[index].type == 303)
                        {
                            Rectangle rectangle = new Rectangle((int)Main.npc[index].position.X, (int)Main.npc[index].position.Y, Main.npc[index].width, Main.npc[index].height);
                            if (myRect.Intersects(rectangle))
                                Main.npc[index].Transform(464);
                        }
                        else if (Main.npc[index].type == 55)
                        {
                            Rectangle rectangle = new Rectangle((int)Main.npc[index].position.X, (int)Main.npc[index].position.Y, Main.npc[index].width, Main.npc[index].height);
                            if (myRect.Intersects(rectangle))
                                Main.npc[index].Transform(465);
                        }
                        else if (Main.npc[index].type == 148 || Main.npc[index].type == 149)
                        {
                            Rectangle rectangle = new Rectangle((int)Main.npc[index].position.X, (int)Main.npc[index].position.Y, Main.npc[index].width, Main.npc[index].height);
                            if (myRect.Intersects(rectangle))
                                Main.npc[index].Transform(470);
                        }
                    }
                }
            }
            if (Main.netMode == 2 || !hostile || (Main.myPlayer >= 255 || damage <= 0))
                return;
            int i1 = Main.myPlayer;
            if (!Main.player[i1].active || Main.player[i1].dead || (Main.player[i1].immune || !Colliding(myRect, Main.player[i1].getRect())))
                return;
            int num5 = direction;
            int hitDirection = Main.player[i1].position.X + (Main.player[i1].width / 2) >= position.X + (width / 2) ? 1 : -1;
            int num6 = Main.DamageVar(damage);
            if (!Main.player[i1].immune)
                StatusPlayer(i1);
            if (Main.player[i1].resistCold && coldDamage)
                num6 = (int)(num6 * 0.699999988079071);
            if (Main.expertMode)
                num6 = (int)(num6 * Main.expertDamage);
            Main.player[i1].Hurt(num6 * 2, hitDirection, false, false, Lang.deathMsg(-1, -1, whoAmI, -1), false);
            if (trap)
            {
                Main.player[i1].trapDebuffSource = true;
                if (Main.player[i1].dead)
                    AchievementsHelper.HandleSpecialEvent(Main.player[i1], 4);
            }
            if (type == 435)
                --penetrate;
            if (type == 436)
                --penetrate;
            if (type != 437)
                return;
            --penetrate;
        }

Usage Example

 public static void ExplosionEffect(Projectile p)
 {
     Main.PlaySound(2, (int)p.position.X, (int)p.position.Y, 14);
     for (int num500 = 0; num500 < 10; num500++)
     {
         Dust.NewDust(new Vector2(p.position.X, p.position.Y), p.width, p.height, 31, 0f, 0f, 100, default(Color), 1.5f);
     }
     for (int num501 = 0; num501 < 5; num501++)
     {
         int num502 = Dust.NewDust(new Vector2(p.position.X, p.position.Y), p.width, p.height, 6, 0f, 0f, 100, default(Color), 2.5f);
         Main.dust[num502].noGravity = true;
         Main.dust[num502].velocity *= 3f;
         num502 = Dust.NewDust(new Vector2(p.position.X, p.position.Y), p.width, p.height, 6, 0f, 0f, 100, default(Color), 1.5f);
         Main.dust[num502].velocity *= 2f;
     }
     int num503 = Gore.NewGore(new Vector2(p.position.X, p.position.Y), default(Vector2), Main.rand.Next(61, 64), 1f);
     Main.gore[num503].velocity *= 0.4f;
     Gore expr_105D2_cp_0 = Main.gore[num503];
     expr_105D2_cp_0.velocity.X = expr_105D2_cp_0.velocity.X + (float)Main.rand.Next(-10, 11) * 0.1f;
     Gore expr_10602_cp_0 = Main.gore[num503];
     expr_10602_cp_0.velocity.Y = expr_10602_cp_0.velocity.Y + (float)Main.rand.Next(-10, 11) * 0.1f;
     num503 = Gore.NewGore(new Vector2(p.position.X, p.position.Y), default(Vector2), Main.rand.Next(61, 64), 1f);
     Main.gore[num503].velocity *= 0.4f;
     Gore expr_10696_cp_0 = Main.gore[num503];
     expr_10696_cp_0.velocity.X = expr_10696_cp_0.velocity.X + (float)Main.rand.Next(-10, 11) * 0.1f;
     Gore expr_106C6_cp_0 = Main.gore[num503];
     expr_106C6_cp_0.velocity.Y = expr_106C6_cp_0.velocity.Y + (float)Main.rand.Next(-10, 11) * 0.1f;
     if (p.owner == Main.myPlayer)
     {
         p.penetrate = -1;
         p.position.X = p.position.X + (float)(p.width / 2);
         p.position.Y = p.position.Y + (float)(p.height / 2);
         p.width = 48;
         p.height = 48;
         p.position.X = p.position.X - (float)(p.width / 2);
         p.position.Y = p.position.Y - (float)(p.height / 2);
         p.Damage();
     }
 }
All Usage Examples Of Terraria.Projectile::Damage