private void Fire(Player player)
        {
            var baseVel = player.DirectionTo(Main.MouseWorld).RotatedByRandom(0.02f) * player.HeldItem.shootSpeed;

            Vector2 pos          = player.Center - new Vector2(0, 8);
            Vector2 muzzleOffset = Vector2.Normalize(baseVel) * (player.HeldItem.width / 2f);

            if (Collision.CanHit(pos, 0, 0, pos + muzzleOffset, 0, 0))
            {
                pos += muzzleOffset;
            }

            var p = Projectile.NewProjectileDirect(pos, baseVel, ModContent.ProjectileType <GranitechGunBullet>(), player.HeldItem.damage, 0f, player.whoAmI);

            if (p.modProjectile is GranitechGunBullet bullet)
            {
                bullet.spawnRings = true;
            }

            //Main.PlaySound(Terraria.ID.SoundID.Item11, projectile.Center);
            if (!Main.dedServ)
            {
                Main.PlaySound(SpiritMod.Instance.GetLegacySoundSlot(SoundType.Custom, "Sounds/EnergyShoot").WithPitchVariance(0.1f).WithVolume(0.25f), pos);
            }

            VFX(pos + muzzleOffset, baseVel * 0.2f);

            GItem.UseAmmo(player, AmmoID.Bullet);
        }
        private void Fire(Player p)
        {
            Main.PlaySound(SoundID.NPCDeath13, projectile.Center);

            Vector2 vel = Vector2.Normalize(Main.MouseWorld - p.Center) * 10f * (ScalingCapped * 0.8f);
            int     inc = 3 + (int)ScalingCapped;

            for (int i = 0; i < inc; i++)             //Projectiles
            {
                Vector2 velocity = vel.RotatedBy((i - (inc / 2f)) * 0.16f) * Main.rand.NextFloat(0.85f, 1.15f);
                Projectile.NewProjectile(p.Center, velocity, ModContent.ProjectileType <GastricAcid>(), (int)(p.HeldItem.damage * ScalingCapped), 1f, projectile.owner);
            }

            GItem.UseAmmo(p, AmmoID.Gel);
        }
예제 #3
0
        public override void AI()
        {
            Player player = Main.player[projectile.owner];

            player.ChangeDir(Main.MouseWorld.X > player.position.X ? 1 : -1);

            player.itemTime      = 5;        // Set item time to 2 frames while we are used
            player.itemAnimation = 5;        // Set item animation time to 2 frames while we are used
            direction            = Main.MouseWorld - (player.Center);
            direction.Normalize();
            direction          *= 70f;
            projectile.position = player.Center + direction;
            projectile.velocity = Vector2.Zero;
            player.itemRotation = direction.ToRotation();
            player.heldProj     = projectile.whoAmI;

            if (player.direction != 1)
            {
                player.itemRotation -= 3.14f;
            }

            if (player.channel)
            {
                if (projectile.soundDelay <= 0 && targets.Count > 0)                 //Create sound & use ammo
                {
                    projectile.soundDelay = 20;
                    Main.PlaySound(SoundID.Item, (int)projectile.position.X, (int)projectile.position.Y, 15);
                    GItem.UseAmmo(player, AmmoID.Gel);
                }

                projectile.timeLeft = 2;
                counter++;
                projectile.frame = (counter / 5) % 4;
                for (int i = 0; i < Main.npc.Length; i++)
                {
                    NPC     npc   = Main.npc[i];
                    Vector2 toNPC = npc.Center - player.Center;
                    if (toNPC.Length() < RANGE && npc.active && AnglesWithinCone(toNPC.ToRotation(), direction.ToRotation()) && (!npc.townNPC || !npc.friendly))
                    {
                        bool targetted = false;
                        foreach (var npc2 in targets)
                        {
                            if (npc2.active)
                            {
                                if (npc2 == npc)
                                {
                                    targetted = true;
                                }
                            }
                        }
                        if (!targetted)
                        {
                            SpiritMod.primitives.CreateTrail(new RailgunPrimTrail(projectile, npc));
                            targets.Add(npc);
                            npc.GetGlobalNPC <TeslaCannonGNPC>().charging = true;
                        }
                    }
                    else
                    {
                        if (npc.active)
                        {
                            npc.GetGlobalNPC <TeslaCannonGNPC>().charging = false;
                        }
                        targets.Remove(npc);
                    }
                }
                foreach (var npc2 in targets.ToArray())
                {
                    if (!npc2.active)
                    {
                        targets.Remove(npc2);
                    }
                }
            }
            else
            {
                projectile.active = false;
            }
        }