示例#1
0
        public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
            StarfireLampPlayer starfireLampPlayer = player.GetModPlayer <StarfireLampPlayer>();

            starfireLampPlayer.TwinkleTime = StarfireLampPlayer.MaxTwinkleTime;

            //Done here to be on use rather than on animation start
            if (!Main.dedServ)
            {
                Main.PlaySound(SoundID.Item45.WithPitchVariance(0.2f).WithVolume(0.5f), player.Center);
            }

            if (player.altFunctionUse == 2)
            {
                NPC mousehovernpc = null;

                foreach (NPC npc in Main.npc.Where(x => x.active && x.CanBeChasedBy(player) && x != null))                 //iterate through npcs and filter out ones that shouldnt be targetted
                {
                    Rectangle hitbox = npc.Hitbox;
                    hitbox.Inflate(40, 40);
                    if (hitbox.Contains(Main.MouseWorld.ToPoint()))
                    {
                        mousehovernpc = npc;
                    }
                }

                if (mousehovernpc == null)
                {
                    return(false);
                }

                starfireLampPlayer.LampTargetNPC  = mousehovernpc;
                starfireLampPlayer.LampTargetTime = StarfireLampPlayer.MaxTargetTime;
                return(false);
            }

            starfireLampPlayer.GlowmaskOpacity = 1;

            //Adjust position to account for hold style
            position.Y += 26;
            position.X += 18 * player.direction;

            Vector2 vel = Vector2.Normalize(Main.MouseWorld - position).RotatedByRandom(MathHelper.Pi / 20) * item.shootSpeed;

            speedX = vel.X;
            speedY = vel.Y;
            return(true);
        }
示例#2
0
        public override void AI()
        {
            Lighting.AddLight(projectile.Center, SpiritMod.StarjinxColor(Main.GlobalTime - 1).ToVector3() / 3);
            projectile.tileCollide = Timer > 15;
            void TargetCheck()
            {
                int maxDist = 1000;

                foreach (NPC npc in Main.npc.Where(x => x.Distance(projectile.Center) < maxDist && x.active && x.CanBeChasedBy(this) && x != null))
                {
                    StarfireLampPlayer player = Main.player[projectile.owner].GetModPlayer <StarfireLampPlayer>();
                    if (player.LampTargetNPC == npc && npc.active && npc != null && npc.CanBeChasedBy(this))
                    {
                        AiState = HomingAim;
                        Target  = npc;
                        projectile.netUpdate = true;
                        Timer = 0;
                    }
                }
            }

            switch (AiState)
            {
            case JustSpawned:
                Direction = Main.rand.NextBool() ? -1 : 1;
                OrigVel   = projectile.velocity;
                AiState   = Main.rand.NextBool(3) ? Circling : CosWave;
                break;

            case CosWave:
                ++Timer;
                projectile.velocity = OrigVel.RotatedBy(Math.Cos((Timer / 45) * MathHelper.TwoPi) * Direction * MathHelper.Pi / 8);
                if (Timer > 10)
                {
                    TargetCheck();
                }
                break;

            case Circling:
                ++Timer;
                projectile.velocity = (OrigVel.RotatedBy(MathHelper.ToRadians(Timer * Direction * 9) + MathHelper.PiOver2 * Direction) * 0.5f) + (OrigVel * 0.33f);
                if (Timer > 10)
                {
                    TargetCheck();
                }
                break;

            case HomingAim:
                ++Timer;
                if (Timer > 8 || Target == null || !Target.active || !Target.CanBeChasedBy(this))
                {
                    AiState = HomingAccelerate;
                    break;
                }
                projectile.velocity = Vector2.Lerp(projectile.velocity, projectile.DirectionTo(Target.Center) * 2, 0.22f);
                break;

            case HomingAccelerate:
                if (projectile.velocity.Length() < 24)
                {
                    projectile.velocity *= 1.05f;
                }

                if (Target != null && Target.active && Target.CanBeChasedBy(this))
                {
                    projectile.velocity = projectile.velocity.Length() *
                                          Vector2.Normalize(Vector2.Lerp(projectile.velocity, projectile.DirectionTo(Target.Center) * projectile.velocity.Length(), 0.1f));
                }
                break;
            }

            projectile.rotation = projectile.velocity.ToRotation() - MathHelper.PiOver2;
            projectile.alpha    = Math.Max(projectile.alpha - 15, 0);

            if (projectile.frameCounter++ % 5 == 0)
            {
                projectile.frame = (projectile.frame + 1) % Main.projFrames[projectile.type];
            }

            if (!Main.dedServ)
            {
                if (Main.rand.NextBool(12))
                {
                    ParticleHandler.SpawnParticle(new FireParticle(projectile.Center, projectile.velocity * Main.rand.NextFloat(0.75f),
                                                                   Yellow, Orange, Main.rand.NextFloat(0.25f, 0.3f), 25, delegate(Particle p)
                    {
                        p.Velocity *= 0.93f;
                    }));
                }

                if (Main.rand.NextBool(8))
                {
                    ParticleHandler.SpawnParticle(new StarParticle(projectile.Center, projectile.velocity * Main.rand.NextFloat(0.75f),
                                                                   Main.rand.NextBool(3) ? Orange : Yellow, Main.rand.NextFloat(0.15f, 0.2f), 20));
                }
            }
        }