Exemplo n.º 1
0
        public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
        {
            Vector2 mouse  = new Vector2(Main.mouseX, Main.mouseY) + Main.screenPosition;
            int     amount = Main.rand.Next(1, 3);

            for (int i = 0; i < amount; ++i)
            {
                Vector2 pos = new Vector2(mouse.X + target.width * 0.5f + Main.rand.Next(-35, 36), mouse.Y - 220f);
                pos.X  = (pos.X * 10f + mouse.X) / 11f - 350;
                pos.Y -= Main.rand.Next(-20, 20);
                float spX = mouse.X + target.width * 0.5f + Main.rand.Next(-100, 101) - mouse.X;
                float spY = mouse.Y - pos.Y;
                if (spY < 0f)
                {
                    spY *= -1f;
                }
                if (spY < 20f)
                {
                    spY = 20f;
                }

                float length = (float)Math.Sqrt((double)(spX * spX + spY * spY));
                length = 12 / length;
                spX   *= length;
                spY   *= length;
                spX    = spX + (float)Main.rand.Next(-40, 41) * 0.02f;
                spY    = spY + (float)Main.rand.Next(-40, 41) * 0.12f;
                spX   *= (float)Main.rand.Next(75, 150) * 0.006f;
                pos.X += (float)Main.rand.Next(-20, 21);
                DustHelper.DrawCircle(new Vector2(pos.X, pos.Y), 222, 1, 1f, 1.35f, .85f, .85f);

                Projectile.NewProjectile(pos.X, pos.Y, spX * projectile.direction, spY, ModContent.ProjectileType <MorningtideProjectile2>(), projectile.damage / 3 * 2, 2, Main.player[projectile.owner].whoAmI);
            }
        }
        public override void AI()
        {
            alphaCounter += 0.03f;
            Player player = Main.player[projectile.owner];

            if (player.HasAccessory <CimmerianScepter>())
            {
                projectile.timeLeft = 2;
            }

            for (int num526 = 0; num526 < 1000; num526++)
            {
                if (num526 != projectile.whoAmI && Main.projectile[num526].active && Main.projectile[num526].owner == projectile.owner && Main.projectile[num526].type == projectile.type && Math.Abs(projectile.position.X - Main.projectile[num526].position.X) + Math.Abs(projectile.position.Y - Main.projectile[num526].position.Y) < (float)projectile.width)
                {
                    if (projectile.position.X < Main.projectile[num526].position.X)
                    {
                        projectile.velocity.X = projectile.velocity.X - 0.05f;
                    }
                    else
                    {
                        projectile.velocity.X = projectile.velocity.X + 0.05f;
                    }

                    if (projectile.position.Y < Main.projectile[num526].position.Y)
                    {
                        projectile.velocity.Y = projectile.velocity.Y - 0.05f;
                    }
                    else
                    {
                        projectile.velocity.Y = projectile.velocity.Y + 0.05f;
                    }
                }
            }

            float num529 = 900f;
            bool  flag19 = false;

            if (projectile.ai[0] == 0f)
            {
                for (int num531 = 0; num531 < 200; num531++)
                {
                    if (Main.npc[num531].CanBeChasedBy(projectile, false))
                    {
                        float num532 = Main.npc[num531].position.X + 40 + (float)(Main.npc[num531].width / 2);
                        float num533 = Main.npc[num531].position.Y - 90 + (float)(Main.npc[num531].height / 2);
                        float num534 = Math.Abs(projectile.position.X + (float)(projectile.width / 2) - num532) + Math.Abs(projectile.position.Y + (float)(projectile.height / 2) - num533);
                        if (num534 < num529 && Collision.CanHit(projectile.position, projectile.width, projectile.height, Main.npc[num531].position, Main.npc[num531].width, Main.npc[num531].height))
                        {
                            num529 = num534;
                            flag19 = true;
                        }
                    }
                }
            }
            else
            {
                projectile.tileCollide = false;
            }

            if (!flag19)
            {
                projectile.friendly = true;
                float num535 = 8f;
                if (projectile.ai[0] == 1f)
                {
                    num535 = 12f;
                }

                Vector2 vector38 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f);
                float   num536   = Main.player[projectile.owner].Center.X - vector38.X;
                float   num537   = Main.player[projectile.owner].Center.Y - vector38.Y - 60f;
                float   num538   = (float)Math.Sqrt((double)(num536 * num536 + num537 * num537));
                if (num538 < 100f && projectile.ai[0] == 1f && !Collision.SolidCollision(projectile.position, projectile.width, projectile.height))
                {
                    projectile.ai[0] = 0f;
                }
                if (num538 > 2000f)
                {
                    projectile.position.X = Main.player[projectile.owner].Center.X - (projectile.width * .5f);
                    projectile.position.Y = Main.player[projectile.owner].Center.Y - (projectile.width * .5f);
                }

                if (num538 > 70f)
                {
                    num538  = num535 / num538;
                    num536 *= num538;
                    num537 *= num538;
                    projectile.velocity.X = (projectile.velocity.X * 20f + num536) * (1f / 21f);
                    projectile.velocity.Y = (projectile.velocity.Y * 20f + num537) * (1f / 21f);
                }
                else
                {
                    if (projectile.velocity.X == 0f && projectile.velocity.Y == 0f)
                    {
                        projectile.velocity.X = -0.05f;
                        projectile.velocity.Y = -0.025f;
                    }
                    projectile.velocity *= 1.0035f;
                }
                projectile.friendly = false;
                projectile.rotation = projectile.velocity.X * 0.15f;

                if (Math.Abs(projectile.velocity.X) > 0.05)
                {
                    projectile.spriteDirection = -projectile.direction;
                    return;
                }
            }

            else
            {
                timer++;
                if (timer > 130 && timer < 170)
                {
                    projectile.rotation += .3f;
                }
                else
                {
                    for (int num531 = 0; num531 < 200; num531++)
                    {
                        if (Main.npc[num531].CanBeChasedBy(projectile, false))
                        {
                            projectile.rotation = projectile.DirectionTo(Main.npc[num531].Center).ToRotation() + 1.57f;
                        }
                    }
                }
                if (timer >= Main.rand.Next(180, 210))
                {
                    int   range         = 100;             //How many tiles away the projectile targets NPCs
                    float shootVelocity = 9.5f;            //magnitude of the shoot vector (speed of arrows shot)

                    //TARGET NEAREST NPC WITHIN RANGE
                    float lowestDist = float.MaxValue;
                    for (int i = 0; i < 200; ++i)
                    {
                        NPC npc = Main.npc[i];
                        //if npc is a valid target (active, not friendly, and not a critter)
                        if (npc.active && npc.CanBeChasedBy(projectile) && !npc.friendly)
                        {
                            //if npc is within 50 blocks
                            float dist = projectile.Distance(npc.Center);
                            if (dist / 16 < range)
                            {
                                //if npc is closer than closest found npc
                                if (dist < lowestDist)
                                {
                                    lowestDist = dist;

                                    //target this npc
                                    projectile.ai[1]     = npc.whoAmI;
                                    projectile.netUpdate = true;
                                }
                            }
                        }
                    }
                    NPC target = (Main.npc[(int)projectile.ai[1]] ?? new NPC());
                    timer = 0;
                    Vector2 ShootArea = new Vector2(projectile.Center.X, projectile.Center.Y - 13);
                    Vector2 direction = Vector2.Normalize(target.Center - ShootArea) * shootVelocity;
                    switch (Main.rand.Next(3))
                    {
                    case 0:                             //star attack
                        colorVer = new Color(126, 61, 255);
                        Main.PlaySound(SoundID.Item, projectile.Center, 9);
                        for (int z = 0; z < 4; z++)
                        {
                            Vector2 pos = new Vector2(projectile.Center.X + Main.rand.Next(-30, 30), projectile.Center.Y + Main.rand.Next(-30, 30));
                            DustHelper.DrawStar(pos, 272, pointAmount: 5, mainSize: 1.425f, dustDensity: 2, dustSize: .5f, pointDepthMult: 0.3f, noGravity: true);
                            int proj2 = Projectile.NewProjectile(pos.X, pos.Y, direction.X + Main.rand.Next(-2, 2), direction.Y + Main.rand.Next(-2, 2), mod.ProjectileType("CimmerianStaffStar"), projectile.damage, 0, Main.myPlayer);
                        }

                        break;

                    case 1:                             //explosion attack
                        colorVer = new Color(255, 20, 52);
                        Main.PlaySound(SoundID.DD2_GhastlyGlaiveImpactGhost, projectile.Center);
                        DustHelper.DrawCircle(projectile.Center, 130, 1, 1f, 1f, .85f, .85f);
                        int proj23 = Projectile.NewProjectile(target.Center.X, target.Center.Y, 0f, 0f, mod.ProjectileType("CimmerianRedGlyph"), projectile.damage, 0, Main.myPlayer);

                        break;

                    case 2:                             //lightning attack
                        colorVer = new Color(61, 184, 255);
                        Main.PlaySound(SoundID.Item, projectile.Center, 12);
                        for (int k = 0; k < 15; k++)
                        {
                            Dust d = Dust.NewDustPerfect(projectile.Center, 226, Vector2.One.RotatedByRandom(6.28f) * Main.rand.NextFloat(3), 0, default, Main.rand.NextFloat(.4f, .8f));
                            d.noGravity = true;
                        }
                        for (int i = 0; i < 3; i++)
                        {
                            DustHelper.DrawElectricity(projectile.Center, target.Center, 226, 0.3f);
                        }
                        target.StrikeNPC((int)(projectile.damage * 1.5f), 1f, 0, false);
                        for (int k = 0; k < 10; k++)
                        {
                            Dust d = Dust.NewDustPerfect(target.Center, 226, Vector2.One.RotatedByRandom(6.28f) * Main.rand.NextFloat(2), 0, default, Main.rand.NextFloat(.2f, .4f));