From eaca2fab491f06ab0ec1f672a64995a46b6b3550 Mon Sep 17 00:00:00 2001 From: Memes <114233643+Mr-Memes@users.noreply.github.com> Date: Mon, 13 Feb 2023 20:31:45 +0100 Subject: [PATCH] Improved Sirius. --- Items/Weapons/Summon/Sirius.cs | 52 +++------- Projectiles/Summon/SiriusBeam.cs | 36 +++---- Projectiles/Summon/SiriusMinion.cs | 160 +++++++++++++---------------- 3 files changed, 102 insertions(+), 146 deletions(-) diff --git a/Items/Weapons/Summon/Sirius.cs b/Items/Weapons/Summon/Sirius.cs index 7f9ad8fddf..5ad2044140 100644 --- a/Items/Weapons/Summon/Sirius.cs +++ b/Items/Weapons/Summon/Sirius.cs @@ -12,60 +12,40 @@ namespace CalamityMod.Items.Weapons.Summon { public class Sirius : ModItem { - int siriusSlots; public override void SetStaticDefaults() { DisplayName.SetDefault("Sirius"); Tooltip.SetDefault("Summons the brightest star in the night sky to shine upon your foes\n" + - "Consumes all of the remaining minion slots on use\n" + - "Must be used from the hotbar\n" + - "Increased power based on the number of minion slots used"); + "Can only be summoned once\n" + + "Uses 8 minion slots"); SacrificeTotal = 1; } public override void SetDefaults() { - Item.width = 62; - Item.height = 62; - Item.useStyle = ItemUseStyleID.Swing; - Item.noMelee = true; - Item.UseSound = SoundID.Item44; + Item.width = Item.height = 62; + + Item.damage = 750; + Item.useTime = Item.useAnimation = 10; + Item.mana = 10; + Item.knockBack = 10f; + + Item.shoot = ModContent.ProjectileType(); Item.DamageType = DamageClass.Summon; - Item.mana = 10; - Item.damage = 175; - Item.knockBack = 3f; - Item.useTime = Item.useAnimation = 10; - Item.shoot = ModContent.ProjectileType(); - Item.shootSpeed = 10f; - - Item.value = CalamityGlobalItem.Rarity13BuyPrice; + Item.useStyle = ItemUseStyleID.Swing; + Item.UseSound = SoundID.Item44; Item.rare = ModContent.RarityType(); + Item.value = CalamityGlobalItem.Rarity13BuyPrice; + Item.noMelee = true; } - public override void HoldItem(Player player) - { - double minionCount = 0; - for (int j = 0; j < Main.projectile.Length; j++) - { - Projectile proj = Main.projectile[j]; - if (proj.active && proj.owner == player.whoAmI && proj.minion && proj.type != Item.shoot) - { - minionCount += proj.minionSlots; - } - } - siriusSlots = (int)(player.maxMinions - minionCount); - } - - public override bool CanUseItem(Player player) - { - return siriusSlots >= 1; - } + public override bool CanUseItem(Player player) => player.ownedProjectileCounts[Item.shoot] <= 0; public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) { CalamityUtils.KillShootProjectiles(true, type, player); - int p = Projectile.NewProjectile(source, position, Vector2.Zero, type, damage, knockback, player.whoAmI, siriusSlots, 30f); + int p = Projectile.NewProjectile(source, position, Vector2.Zero, type, damage, knockback, player.whoAmI); if (Main.projectile.IndexInRange(p)) Main.projectile[p].originalDamage = Item.damage; return false; diff --git a/Projectiles/Summon/SiriusBeam.cs b/Projectiles/Summon/SiriusBeam.cs index 4e8669e2d0..9345c1254f 100644 --- a/Projectiles/Summon/SiriusBeam.cs +++ b/Projectiles/Summon/SiriusBeam.cs @@ -18,35 +18,33 @@ namespace CalamityMod.Projectiles.Summon public override void SetDefaults() { - Projectile.width = 4; - Projectile.height = 4; + Projectile.width = Projectile.height = 4; + + Projectile.minionSlots = 0f; + Projectile.penetrate = -1; + Projectile.extraUpdates = 220; // Random number to make it go fast. + Projectile.localNPCHitCooldown = 110; // Random number so it doesn't multi-hit. + Projectile.timeLeft = 1000; // Random number so it doesn't die too fast. + Projectile.friendly = true; Projectile.minion = true; - Projectile.minionSlots = 0f; - Projectile.extraUpdates = 220; - Projectile.timeLeft = 1000; Projectile.usesLocalNPCImmunity = true; - Projectile.localNPCHitCooldown = 110; Projectile.tileCollide = false; Projectile.DamageType = DamageClass.Summon; } public override void AI() { - Projectile.localAI[0] += 1f; - if (Projectile.localAI[0] > 3f) + for (int d = 0; d < 4; d++) { - for (int num447 = 0; num447 < 4; num447++) - { - Vector2 vector33 = Projectile.position; - vector33 -= Projectile.velocity * ((float)num447 * 0.25f); - Projectile.alpha = 255; - int num448 = Dust.NewDust(vector33, 1, 1, 20, 0f, 0f, 0, default, 1f); - Main.dust[num448].position = vector33; - Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; - Main.dust[num448].velocity *= 0.2f; - Main.dust[num448].noGravity = true; - } + Vector2 vector33 = Projectile.position; + vector33 -= Projectile.velocity * (d * 0.25f); + Projectile.alpha = 255; + int trailDust = Dust.NewDust(vector33, 1, 1, 20, 0f, 0f, 0, default, 1f); + Main.dust[trailDust].position = vector33; + Main.dust[trailDust].scale = Main.rand.Next(70, 110) * 0.013f; + Main.dust[trailDust].velocity *= 0.2f; + Main.dust[trailDust].noGravity = true; } } diff --git a/Projectiles/Summon/SiriusMinion.cs b/Projectiles/Summon/SiriusMinion.cs index 34f7deca5e..0406baca0d 100644 --- a/Projectiles/Summon/SiriusMinion.cs +++ b/Projectiles/Summon/SiriusMinion.cs @@ -1,14 +1,24 @@ -using CalamityMod.Buffs.Summon; +using System; +using CalamityMod.Buffs.Summon; using CalamityMod.CalPlayer; using Microsoft.Xna.Framework; -using System; +using rail; using Terraria; using Terraria.ID; using Terraria.ModLoader; + namespace CalamityMod.Projectiles.Summon { public class SiriusMinion : ModProjectile { + public Player Owner => Main.player[Projectile.owner]; + + public CalamityPlayer moddedOwner => Owner.Calamity(); + + public ref float TimerForShooting => ref Projectile.ai[0]; + + public bool CheckForSpawning = false; + public override void SetStaticDefaults() { DisplayName.SetDefault("Sirius"); @@ -20,125 +30,91 @@ namespace CalamityMod.Projectiles.Summon { Projectile.width = 38; Projectile.height = 48; + + Projectile.minionSlots = 8f; + Projectile.penetrate = -1; + Projectile.netImportant = true; Projectile.friendly = true; Projectile.ignoreWater = true; - Projectile.minionSlots = 1f; - Projectile.timeLeft = 18000; - Projectile.penetrate = -1; Projectile.tileCollide = false; - Projectile.timeLeft *= 5; Projectile.minion = true; Projectile.DamageType = DamageClass.Summon; } public override void AI() { - Player player = Main.player[Projectile.owner]; - CalamityPlayer modPlayer = player.Calamity(); + NPC target = Projectile.Center.MinionHoming(5000f, Owner); // Constantly tries to find a target. - bool correctMinion = Projectile.type == ModContent.ProjectileType(); - if (correctMinion) - { - if (player.dead) - { - modPlayer.sirius = false; - } - if (modPlayer.sirius) - { - Projectile.timeLeft = 2; - } - } - player.AddBuff(ModContent.BuffType(), 3600); + CheckMinionExistince(); // Checks if the minion can still exist. + SpawnEffect(); // Does a dust spawn effect. + ShootTarget(target); // If there's a target, shoot at the target. - Projectile.minionSlots = Projectile.ai[0]; - Lighting.AddLight(Projectile.Center, 0.5f, 0.5f, 1f); + Projectile.Center = Owner.Center - Vector2.UnitY * 60f; // Stays above the player. - Projectile.Center = player.Center + Vector2.UnitY * (player.gfxOffY - 60f); - if (player.gravDir == -1f) - { - Projectile.position.Y += 120f; - Projectile.rotation = MathHelper.Pi; - } + Lighting.AddLight(Projectile.Center, 0.5f, 0.5f, 1f); // Passively makes blue light. + + // The timer for the minion shooting. + if (TimerForShooting < 60f) + TimerForShooting++; else + TimerForShooting = 0f; + + // Makes the star oscillate. + Projectile.scale = 0.8f + MathF.Abs(MathF.Cos(MathHelper.Pi * (TimerForShooting / 50f))) / 5f; + } + + #region Methods + + public void CheckMinionExistince() + { + Owner.AddBuff(ModContent.BuffType(), 3600); + if (Projectile.type == ModContent.ProjectileType()) { - Projectile.rotation = 0f; + if (Owner.dead) + moddedOwner.sirius = false; + if (moddedOwner.sirius) + Projectile.timeLeft = 2; } - Projectile.position.X = (int)Projectile.position.X; - Projectile.position.Y = (int)Projectile.position.Y; + } - float scalar = (float)Main.mouseTextColor / 200f - 0.35f; - scalar *= 0.2f; - Projectile.scale = scalar + 0.95f; - - if (Projectile.localAI[0] == 0f) + public void SpawnEffect() + { + if (CheckForSpawning == false) { int dustAmt = 50; for (int d = 0; d < dustAmt; d++) { - int sirius = Dust.NewDust(new Vector2(Projectile.position.X, Projectile.position.Y + 16f), Projectile.width, Projectile.height - 16, 20, 0f, 0f, 0, default, 1f); - Main.dust[sirius].velocity *= 2f; - Main.dust[sirius].scale *= 1.15f; + float angle = MathHelper.TwoPi / dustAmt * d; + Vector2 dustVelocity = angle.ToRotationVector2() * 20f; + Dust spawnDust = Dust.NewDustPerfect(Owner.Center - Vector2.UnitY * 60f, 20, dustVelocity); + spawnDust.noGravity = true; } - Projectile.localAI[0] += 1f; + CheckForSpawning = true; } + } - if (Projectile.owner == Main.myPlayer) + public void ShootTarget(NPC target) + { + if (target is not null) { - if (Projectile.ai[1] != 0f) + if (TimerForShooting >= 60f && Projectile.owner == Main.myPlayer) { - Projectile.ai[1] -= 1f; - return; - } - Vector2 targetVec = Projectile.position; - float maxDistance = 7000f; - bool hasTarget = false; - if (player.HasMinionAttackTargetNPC) - { - NPC npc = Main.npc[player.MinionAttackTargetNPC]; - if (npc.CanBeChasedBy(Projectile, false)) + // Makes a dust effect on the minion, to make a better effect of it shooting. + int dustAmt = 50; + for (int d = 0; d < dustAmt; d++) { - float extraDistance = (npc.width / 2) + (npc.height / 2); - - if (Vector2.Distance(npc.Center, Projectile.Center) < (maxDistance + extraDistance)) - { - targetVec = npc.Center; - hasTarget = true; - } + float angle = MathHelper.TwoPi / dustAmt * d; + Vector2 dustVelocity = angle.ToRotationVector2() * 20f; + Dust spawnDust = Dust.NewDustPerfect(Projectile.Center, 20, dustVelocity); + spawnDust.noGravity = true; } - } - if (!hasTarget) - { - for (int i = 0; i < Main.maxNPCs; i++) - { - NPC npc = Main.npc[i]; - if (npc.CanBeChasedBy(Projectile, false)) - { - float extraDistance = (npc.width / 2) + (npc.height / 2); - if (Vector2.Distance(npc.Center, Projectile.Center) < (maxDistance + extraDistance)) - { - targetVec = npc.Center; - hasTarget = true; - } - } - } - } - if (hasTarget) - { - float projSpeed = 15f; - Vector2 source = new Vector2(Projectile.Center.X - 4f, Projectile.Center.Y); - Vector2 velocity = targetVec - Projectile.Center; - float targetDist = velocity.Length(); - targetDist = projSpeed / targetDist; - velocity.X *= targetDist; - velocity.Y *= targetDist; - float damageMult = ((float)Math.Log(Projectile.ai[0], MathHelper.E)) + 1f; - int beam = Projectile.NewProjectile(Projectile.GetSource_FromThis(), source, velocity, ModContent.ProjectileType(), (int)(Projectile.damage * damageMult), Projectile.knockBack, Projectile.owner); + // Shoots the beam. + Vector2 velocity = (target.Center - Projectile.Center).SafeNormalize(Vector2.Zero) * 3f; + int beam = Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, velocity, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner); if (Main.projectile.IndexInRange(beam)) - Main.projectile[beam].originalDamage = (int)(Projectile.originalDamage * damageMult); - Main.projectile[beam].penetrate = (int)Projectile.ai[0]; - Projectile.ai[1] = 30f; + Main.projectile[beam].originalDamage = Projectile.originalDamage; } } } @@ -146,5 +122,7 @@ namespace CalamityMod.Projectiles.Summon public override Color? GetAlpha(Color lightColor) => new Color(200, 200, 200, 200); public override bool? CanDamage() => false; + + #endregion } }