diff --git a/Items/Placeables/Furniture/Monoliths/BossRushMonolith.png b/Items/Placeables/Furniture/Monoliths/BossRushMonolith.png index d00e2fd304..700f5dca6d 100644 Binary files a/Items/Placeables/Furniture/Monoliths/BossRushMonolith.png and b/Items/Placeables/Furniture/Monoliths/BossRushMonolith.png differ diff --git a/Items/Weapons/Magic/AetherfluxCannon.cs b/Items/Weapons/Magic/AetherfluxCannon.cs index 11d3ad3d29..782fffeba9 100644 --- a/Items/Weapons/Magic/AetherfluxCannon.cs +++ b/Items/Weapons/Magic/AetherfluxCannon.cs @@ -39,11 +39,12 @@ namespace CalamityMod.Items.Weapons.Magic public override bool CanUseItem(Player player) => player.ownedProjectileCounts[Item.shoot] <= 0; + public override void HoldItem(Player player) => player.Calamity().mouseRotationListener = true; + public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) { - Vector2 shootVelocity = velocity; - Vector2 shootDirection = shootVelocity.SafeNormalize(Vector2.UnitX * player.direction); - Projectile.NewProjectile(source, position, shootDirection, type, damage, knockback, player.whoAmI); + Vector2 spawnPosition = player.RotatedRelativePoint(player.MountedCenter, true); + Projectile.NewProjectileDirect(source, spawnPosition, player.Calamity().mouseWorld - spawnPosition, ModContent.ProjectileType(), damage, knockback, player.whoAmI); return false; } diff --git a/Items/Weapons/Magic/GloriousEnd.cs b/Items/Weapons/Magic/GloriousEnd.cs index 29c4d96f19..59db80cd1d 100644 --- a/Items/Weapons/Magic/GloriousEnd.cs +++ b/Items/Weapons/Magic/GloriousEnd.cs @@ -31,5 +31,7 @@ namespace CalamityMod.Items.Weapons.Magic } public override bool CanUseItem(Player player) => player.ownedProjectileCounts[Item.shoot] <= 0; + + public override void HoldItem(Player player) => player.Calamity().mouseWorldListener = true; } } diff --git a/Items/Weapons/Magic/NanoPurge.cs b/Items/Weapons/Magic/NanoPurge.cs index 558c24ab99..a0522394b9 100644 --- a/Items/Weapons/Magic/NanoPurge.cs +++ b/Items/Weapons/Magic/NanoPurge.cs @@ -10,8 +10,9 @@ namespace CalamityMod.Items.Weapons.Magic [LegacyName("Purge")] public class NanoPurge : ModItem, ILocalizedModType { + public static int UseTime = 20; + public new string LocalizationCategory => "Items.Weapons.Magic"; - public const int UseTime = 20; public override void SetDefaults() { @@ -35,11 +36,12 @@ namespace CalamityMod.Items.Weapons.Magic public override bool CanUseItem(Player player) => player.ownedProjectileCounts[Item.shoot] <= 0; + public override void HoldItem(Player player) => player.Calamity().mouseRotationListener = true; + public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) { - Vector2 shootVelocity = velocity; - Vector2 shootDirection = shootVelocity.SafeNormalize(Vector2.UnitX * player.direction); - Projectile.NewProjectile(source, position, shootDirection, type, damage, knockback, player.whoAmI); + Vector2 spawnPosition = player.RotatedRelativePoint(player.MountedCenter, true); + Projectile.NewProjectileDirect(source, spawnPosition, player.Calamity().mouseWorld - spawnPosition, ModContent.ProjectileType(), damage, knockback, player.whoAmI); return false; } diff --git a/Items/Weapons/Magic/Omicron.cs b/Items/Weapons/Magic/Omicron.cs index 010a7b2f7e..2f5274a96d 100644 --- a/Items/Weapons/Magic/Omicron.cs +++ b/Items/Weapons/Magic/Omicron.cs @@ -1,4 +1,6 @@ -using CalamityMod.Items.Materials; +using CalamityMod.CalPlayer; +using CalamityMod.DataStructures; +using CalamityMod.Items.Materials; using CalamityMod.Projectiles.Magic; using CalamityMod.Rarities; using CalamityMod.Tiles.Furniture.CraftingStations; @@ -14,6 +16,7 @@ namespace CalamityMod.Items.Weapons.Magic { public static float FireRate = 15f; public static float StarterWinup = 60f; + public static float WingmanFireRate = 10f; public new string LocalizationCategory => "Items.Weapons.Magic"; @@ -40,7 +43,14 @@ namespace CalamityMod.Items.Weapons.Magic public override bool CanUseItem(Player player) => player.ownedProjectileCounts[Item.shoot] <= 0 && player.ownedProjectileCounts[ModContent.ProjectileType()] < 2; // Makes the rotation of the mouse around the player sync in multiplayer. - public override void HoldItem(Player player) => player.Calamity().mouseRotationListener = true; + public override void HoldItem(Player player) + { + CalamityPlayer calPlayer = player.Calamity(); + calPlayer.mouseWorldListener = true; + calPlayer.mouseRotationListener = true; + calPlayer.rightClickListener = true; + } + public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) { for (int i = 0; i < 2; i++) diff --git a/Items/Weapons/Magic/Wingman.cs b/Items/Weapons/Magic/Wingman.cs index 1526be5dd7..b4960be3d1 100644 --- a/Items/Weapons/Magic/Wingman.cs +++ b/Items/Weapons/Magic/Wingman.cs @@ -35,7 +35,12 @@ namespace CalamityMod.Items.Weapons.Magic public override bool CanUseItem(Player player) => player.ownedProjectileCounts[Item.shoot] < 2; // Makes the rotation of the mouse around the player sync in multiplayer. - public override void HoldItem(Player player) => player.Calamity().mouseRotationListener = true; + public override void HoldItem(Player player) + { + var modPlayer = player.Calamity(); + modPlayer.mouseRotationListener = true; + modPlayer.rightClickListener = true; + } public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) { diff --git a/Items/Weapons/Melee/DepthCrusher.cs b/Items/Weapons/Melee/DepthCrusher.cs index 1714581a67..86f994eb02 100644 --- a/Items/Weapons/Melee/DepthCrusher.cs +++ b/Items/Weapons/Melee/DepthCrusher.cs @@ -16,12 +16,12 @@ namespace CalamityMod.Items.Weapons.Melee { Item.width = 56; Item.height = 50; - Item.damage = 35; + Item.damage = 48; Item.knockBack = 7.25f; Item.useTime = 65; Item.useAnimation = 65; Item.shoot = ModContent.ProjectileType(); - Item.shootSpeed = 3f; + Item.shootSpeed = 6f; Item.noMelee = true; Item.noUseGraphic = true; diff --git a/Items/Weapons/Ranged/ArcNovaDiffuser.cs b/Items/Weapons/Ranged/ArcNovaDiffuser.cs index c47d25ca28..2ce192c482 100644 --- a/Items/Weapons/Ranged/ArcNovaDiffuser.cs +++ b/Items/Weapons/Ranged/ArcNovaDiffuser.cs @@ -26,10 +26,8 @@ namespace CalamityMod.Items.Weapons.Ranged public new string LocalizationCategory => "Items.Weapons.Ranged"; - public override void SetStaticDefaults() - { - ItemID.Sets.IsRangedSpecialistWeapon[Item.type] = true; - } + public override void SetStaticDefaults() => ItemID.Sets.IsRangedSpecialistWeapon[Type] = true; + public override void SetDefaults() { Item.width = 58; @@ -53,6 +51,15 @@ namespace CalamityMod.Items.Weapons.Ranged public override bool CanUseItem(Player player) => player.ownedProjectileCounts[Item.shoot] <= 0; + public override void HoldItem(Player player) => player.Calamity().mouseWorldListener = true; + + public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) + { + Projectile holdout = Projectile.NewProjectileDirect(source, player.MountedCenter, Vector2.Zero, ModContent.ProjectileType(), damage, knockback, player.whoAmI, 0, 1); + holdout.velocity = player.Calamity().mouseWorld - player.RotatedRelativePoint(player.MountedCenter); + return false; + } + public override void AddRecipes() { CreateRecipe(). diff --git a/Items/Weapons/Ranged/ElementalEruption.cs b/Items/Weapons/Ranged/ElementalEruption.cs index 8c8449aafd..e282838825 100644 --- a/Items/Weapons/Ranged/ElementalEruption.cs +++ b/Items/Weapons/Ranged/ElementalEruption.cs @@ -14,10 +14,7 @@ namespace CalamityMod.Items.Weapons.Ranged public int FlareCounter = 0; - public override void SetStaticDefaults() - { - ItemID.Sets.ItemsThatAllowRepeatedRightClick[Item.type] = true; - } + public override void SetStaticDefaults() => ItemID.Sets.ItemsThatAllowRepeatedRightClick[Type] = true; public override void SetDefaults() { @@ -41,13 +38,18 @@ namespace CalamityMod.Items.Weapons.Ranged } public override Vector2? HoldoutOffset() => new Vector2(-10, 0); + public override bool CanUseItem(Player player) => player.ownedProjectileCounts[Item.shoot] <= 0; + public override void HoldItem(Player player) => player.Calamity().mouseWorldListener = true; + // Spawning the holdout cannot consume ammo public override bool CanConsumeAmmo(Item ammo, 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) { - Projectile.NewProjectile(source, position, Vector2.Zero, type, 0, 0f, player.whoAmI); + Projectile holdout = Projectile.NewProjectileDirect(source, player.MountedCenter, Vector2.Zero, ModContent.ProjectileType(), damage, knockback, player.whoAmI, 0, 1); + holdout.velocity = player.Calamity().mouseWorld - player.RotatedRelativePoint(player.MountedCenter); return false; } diff --git a/Items/Weapons/Ranged/MagnaCannon.cs b/Items/Weapons/Ranged/MagnaCannon.cs index 4a320fba08..88422994c3 100644 --- a/Items/Weapons/Ranged/MagnaCannon.cs +++ b/Items/Weapons/Ranged/MagnaCannon.cs @@ -22,10 +22,8 @@ namespace CalamityMod.Items.Weapons.Ranged public new string LocalizationCategory => "Items.Weapons.Ranged"; - public override void SetStaticDefaults() - { - ItemID.Sets.IsRangedSpecialistWeapon[Item.type] = true; - } + public override void SetStaticDefaults() => ItemID.Sets.IsRangedSpecialistWeapon[Item.type] = true; + public override void SetDefaults() { Item.width = 56; @@ -49,6 +47,15 @@ namespace CalamityMod.Items.Weapons.Ranged public override bool CanUseItem(Player player) => player.ownedProjectileCounts[Item.shoot] <= 0; + public override void HoldItem(Player player) => player.Calamity().mouseRotationListener = true; + + public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) + { + Vector2 spawnPosition = player.RotatedRelativePoint(player.MountedCenter); + Projectile.NewProjectileDirect(source, spawnPosition, player.Calamity().mouseWorld - player.RotatedRelativePoint(player.MountedCenter), ModContent.ProjectileType(), 0, 0f, player.whoAmI); + return false; + } + public override void AddRecipes() { CreateRecipe(). diff --git a/Items/Weapons/Ranged/OpalStriker.cs b/Items/Weapons/Ranged/OpalStriker.cs index b7add585c2..35158cca97 100644 --- a/Items/Weapons/Ranged/OpalStriker.cs +++ b/Items/Weapons/Ranged/OpalStriker.cs @@ -21,10 +21,8 @@ namespace CalamityMod.Items.Weapons.Ranged public static int AftershotCooldownFrames = 17; public static int FullChargeFrames = 88; - public override void SetStaticDefaults() - { - ItemID.Sets.IsRangedSpecialistWeapon[Item.type] = true; - } + public override void SetStaticDefaults() => ItemID.Sets.IsRangedSpecialistWeapon[Type] = true; + public override void SetDefaults() { Item.width = 48; @@ -48,6 +46,15 @@ namespace CalamityMod.Items.Weapons.Ranged public override bool CanUseItem(Player player) => player.ownedProjectileCounts[Item.shoot] <= 0; + public override void HoldItem(Player player) => player.Calamity().mouseRotationListener = true; + + public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) + { + Vector2 spawnPosition = player.RotatedRelativePoint(player.MountedCenter, true); + Projectile.NewProjectileDirect(source, spawnPosition, player.Calamity().mouseWorld - spawnPosition, ModContent.ProjectileType(), 0, 0f, player.whoAmI); + return false; + } + public override void AddRecipes() { CreateRecipe(). diff --git a/Items/Weapons/Ranged/WildfireBloom.cs b/Items/Weapons/Ranged/WildfireBloom.cs index b6c2286b1a..d821089aeb 100644 --- a/Items/Weapons/Ranged/WildfireBloom.cs +++ b/Items/Weapons/Ranged/WildfireBloom.cs @@ -39,13 +39,21 @@ namespace CalamityMod.Items.Weapons.Ranged } public override Vector2? HoldoutOffset() => new Vector2(-10, 0); + public override bool CanUseItem(Player player) => player.ownedProjectileCounts[Item.shoot] <= 0; + public override void HoldItem(Player player) => player.Calamity().mouseWorldListener = true; + // Spawning the holdout cannot consume ammo public override bool CanConsumeAmmo(Item ammo, 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) { - Projectile.NewProjectile(source, position, Vector2.Zero, type, 0, 0f, player.whoAmI); + Projectile holdout = Projectile.NewProjectileDirect(source, position, Vector2.Zero, ModContent.ProjectileType(), 0, 0f, player.whoAmI); + + // We set the rotation to the direction to the mouse so the first frame doesn't appear bugged out. + holdout.velocity = (player.Calamity().mouseWorld - player.MountedCenter).SafeNormalize(Vector2.Zero); + return false; } diff --git a/Localization/en-US/Mods.CalamityMod.Projectiles.Melee.hjson b/Localization/en-US/Mods.CalamityMod.Projectiles.Melee.hjson index 6f5c733c72..f49ed13e17 100644 --- a/Localization/en-US/Mods.CalamityMod.Projectiles.Melee.hjson +++ b/Localization/en-US/Mods.CalamityMod.Projectiles.Melee.hjson @@ -268,8 +268,8 @@ TaintedBladeSlasher.DisplayName: Tainted Blade TenebreusTidesWaterProjectile.DisplayName: Water Spear TenebreusTidesWaterSpear.DisplayName: Tenebreus Tides Water Spear TenebreusTidesWaterSword.DisplayName: Tenebreus Tides Water Sword -TerratomereBeam.DisplayName: Terra Slash Beam -TerratomereBigSlash.DisplayName: Terratomere Slash +TerratomereMeleeSlash.DisplayName: Terratomere Slash +TerratomereSwordBeam.DisplayName: Terra Slash Beam TerratomereExplosion.DisplayName: Terratomere Explosion TerratomereHoldoutProj.DisplayName: Terratomere TerratomereSlash.DisplayName: Terratomere Slash diff --git a/Localization/en-US/Mods.CalamityMod.UI.hjson b/Localization/en-US/Mods.CalamityMod.UI.hjson index 7fbda27580..4037840c25 100644 --- a/Localization/en-US/Mods.CalamityMod.UI.hjson +++ b/Localization/en-US/Mods.CalamityMod.UI.hjson @@ -260,7 +260,7 @@ Communication: { The final to begin construction was Artemis. Rather than being founded on raw power, it was made to be the apex of speed and accuracy. There is elegance in simplicity, for all of Artemis' combat efficacy comes from an onboard predictive AI and a battery of hard-light bolt emitters.\n - It was the perfect partner to its twin and required no revisions. Organic beings are naturally inclined to fixate their senses on fire, presenting Artemis with the perfect opportunity to strike with unparalleled precision. + It was the perfect partner to its twin and required only a single revision. Organic beings are naturally inclined to fixate their senses on fire, presenting Artemis with the perfect opportunity to strike with unparalleled precision. ''' } diff --git a/Projectiles/Magic/AetherfluxCannonHoldout.cs b/Projectiles/Magic/AetherfluxCannonHoldout.cs index 94e57a3010..f516b8a025 100644 --- a/Projectiles/Magic/AetherfluxCannonHoldout.cs +++ b/Projectiles/Magic/AetherfluxCannonHoldout.cs @@ -1,65 +1,54 @@ using CalamityMod.Items.Weapons.Magic; +using CalamityMod.Projectiles.BaseProjectiles; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.Audio; +using Terraria.GameContent; using Terraria.ID; -using Terraria.Localization; using Terraria.ModLoader; namespace CalamityMod.Projectiles.Magic { - public class AetherfluxCannonHoldout : ModProjectile + public class AetherfluxCannonHoldout : BaseGunHoldoutProjectile { - public override LocalizedText DisplayName => CalamityUtils.GetItemName(); - private const int FramesPerFireRateIncrease = 36; - - private Player Owner => Main.player[Projectile.owner]; + public override int AssociatedItemID => ModContent.ItemType(); + public override float MaxOffsetLengthFromArm => 10f; + public override float OffsetXUpwards => -15f; + public override float OffsetXDownwards => 10f; + public override float BaseOffsetY => -15f; + public override float OffsetYUpwards => 8f; + public override float OffsetYDownwards => 15f; + public override string Texture => "CalamityMod/Projectiles/Magic/AetherfluxCannonHoldout"; private ref float DeployedFrames => ref Projectile.ai[0]; private ref float AnimationRate => ref Projectile.ai[1]; private ref float LastShootAttemptTime => ref Projectile.localAI[0]; private ref float LastAnimationTime => ref Projectile.localAI[1]; - public override void SetStaticDefaults() - { - Main.projFrames[Projectile.type] = 8; - } + public override void SetStaticDefaults() => Main.projFrames[Type] = 8; - public override void SetDefaults() + public override void KillHoldoutLogic() { - Projectile.width = 58; - Projectile.height = 94; - Projectile.friendly = true; - Projectile.penetrate = -1; - Projectile.tileCollide = false; - Projectile.ignoreWater = true; - Projectile.DamageType = DamageClass.Magic; - } + base.KillHoldoutLogic(); - public override void AI() - { - Vector2 armPosition = Owner.RotatedRelativePoint(Owner.MountedCenter, true); - Vector2 gunBarrelPos = armPosition + Projectile.velocity * Projectile.height * 0.4f; - - // If the player is unable to continue using the holdout, delete it. - if (Owner.CantUseHoldout() || !Owner.HasAmmo(Owner.ActiveItem())) - { + bool actuallyShoot = DeployedFrames >= (HeldItem?.useAnimation ?? AetherfluxCannon.UseTime); + bool manaOK = !actuallyShoot || Owner.CheckMana(Owner.ActiveItem(), -1, true, false); + if (!manaOK) Projectile.Kill(); - return; - } + } + public override void HoldoutAI() + { // Play a sound frame 1. if (DeployedFrames <= 0f) - { SoundEngine.PlaySound(SoundID.DD2_DarkMageCastHeal with { Volume = SoundID.DD2_DarkMageCastHeal.Volume * 1.5f }, Projectile.Center); - } // Update damage based on curent magic damage stat (so Mana Sickness affects it) - Item weaponItem = Owner.ActiveItem(); - Projectile.damage = weaponItem is null ? 0 : Owner.GetWeaponDamage(weaponItem); + Projectile.damage = HeldItem is null ? 0 : Owner.GetWeaponDamage(HeldItem); // Get the original weapon's use time. - int itemUseTime = weaponItem?.useAnimation ?? AetherfluxCannon.UseTime; + int itemUseTime = HeldItem?.useAnimation ?? AetherfluxCannon.UseTime; // 36, base use time, will result in 5. Speed increasing reforges push it to 4. int framesPerShot = itemUseTime / 7; @@ -73,7 +62,7 @@ namespace CalamityMod.Projectiles.Magic if (DeployedFrames - LastAnimationTime >= AnimationRate) { LastAnimationTime = DeployedFrames; - Projectile.frame = (Projectile.frame + 1) % Main.projFrames[Projectile.type]; + Projectile.frame = (Projectile.frame + 1) % Main.projFrames[Type]; } // Once past the initial spin-up time, fire constantly as long as mana is available. @@ -89,7 +78,7 @@ namespace CalamityMod.Projectiles.Magic SoundEngine.PlaySound(SoundID.Item91, Projectile.Center); int projID = ModContent.ProjectileType(); - float shootSpeed = weaponItem.shootSpeed; + float shootSpeed = HeldItem.shootSpeed; Vector2 shootDirection = Projectile.velocity.SafeNormalize(Vector2.UnitY); Vector2 shootVelocity = shootDirection * shootSpeed; @@ -102,67 +91,24 @@ namespace CalamityMod.Projectiles.Magic for (int i = -1; i <= 1; i += 2) { - Vector2 laserStartPos = gunBarrelPos + i * perp + Main.rand.NextVector2CircularEdge(6f, 6f); + Vector2 laserStartPos = GunTipPosition + i * perp + Main.rand.NextVector2CircularEdge(6f, 6f); Vector2 dustOnlySpread = Main.rand.NextVector2Circular(shootSpeed, shootSpeed); Vector2 dustVelocity = shootVelocity + dustInaccuracy * dustOnlySpread; - if (actuallyShoot) - { - Projectile godRay = Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), laserStartPos, shootVelocity, projID, Projectile.damage, Projectile.knockBack, Projectile.owner, 0f, 0f); - // Tell this Phased God Ray exactly which way it should be waving. - godRay.localAI[1] = i * 0.5f; - } - SpawnFiringDust(gunBarrelPos, dustVelocity); + if (actuallyShoot && Main.myPlayer == Projectile.owner) + Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), laserStartPos, shootVelocity, projID, Projectile.damage, Projectile.knockBack, Projectile.owner, i * 0.5f); + SpawnFiringDust(GunTipPosition, dustVelocity); } } - - // Delete the laser gun if a mana cost cannot be paid. - else - { - Projectile.Kill(); - return; - } } - - UpdateProjectileHeldVariables(armPosition); - ManipulatePlayerVariables(); } - private void UpdateProjectileHeldVariables(Vector2 armPosition) - { - if (Main.myPlayer == Projectile.owner) - { - float interpolant = Utils.GetLerpValue(5f, 25f, Projectile.Distance(Main.MouseWorld), true); - Vector2 oldVelocity = Projectile.velocity; - Projectile.velocity = Vector2.Lerp(Projectile.velocity, Projectile.SafeDirectionTo(Main.MouseWorld), interpolant); - if (Projectile.velocity != oldVelocity) - { - Projectile.netSpam = 0; - Projectile.netUpdate = true; - } - } - - Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver2; - Projectile.Center = armPosition + Projectile.velocity.SafeNormalize(Vector2.UnitX * Owner.direction) * 8f; - Projectile.spriteDirection = Projectile.direction; - Projectile.timeLeft = 2; - } - - private void ManipulatePlayerVariables() - { - Owner.ChangeDir(Projectile.direction); - Owner.heldProj = Projectile.whoAmI; - Owner.itemTime = 2; - Owner.itemAnimation = 2; - Owner.itemRotation = (Projectile.velocity * Projectile.direction).ToRotation(); - } - - private void SpawnFiringDust(Vector2 gunBarrelPos, Vector2 laserVelocity) + private void SpawnFiringDust(Vector2 GunTipPosition, Vector2 laserVelocity) { int dustID = 133; int dustRadius = 12; float dustRandomness = 11f; int dustDiameter = 2 * dustRadius; - Vector2 dustCorner = gunBarrelPos - Vector2.One * dustRadius; + Vector2 dustCorner = GunTipPosition - Vector2.One * dustRadius; for (int i = 0; i < 2; i++) { Vector2 dustVel = laserVelocity + Main.rand.NextVector2Circular(dustRandomness, dustRandomness); @@ -173,9 +119,18 @@ namespace CalamityMod.Projectiles.Magic } } - public override bool? CanDamage() => false; + public override bool PreDraw(ref Color lightColor) + { + Texture2D texture = TextureAssets.Projectile[Type].Value; + Vector2 drawPosition = Projectile.Center - Main.screenPosition; + Rectangle frame = texture.Frame(verticalFrames: Main.projFrames[Type], frameY: Projectile.frame); + float drawRotation = Projectile.rotation + (Projectile.spriteDirection == -1 ? MathHelper.Pi : 0f) + MathHelper.PiOver2; + Vector2 rotationPoint = frame.Size() * 0.5f; + SpriteEffects flipSprite = (Projectile.spriteDirection * Owner.gravDir == -1) ? SpriteEffects.FlipVertically : SpriteEffects.None; - // prevents the item from appearing backwards frame 1 - public override bool PreDraw(ref Color lightColor) => FramesPerFireRateIncrease > 0f; + Main.EntitySpriteDraw(texture, drawPosition, frame, Projectile.GetAlpha(lightColor), drawRotation, rotationPoint, Projectile.scale * Owner.gravDir, flipSprite); + + return false; + } } } diff --git a/Projectiles/Magic/GenesisBeam.cs b/Projectiles/Magic/GenesisBeam.cs index 1a6f1196e0..1290158ebd 100644 --- a/Projectiles/Magic/GenesisBeam.cs +++ b/Projectiles/Magic/GenesisBeam.cs @@ -3,6 +3,7 @@ using Microsoft.Xna.Framework; using Terraria; using Terraria.Audio; using Terraria.ModLoader; +using Terraria.WorldBuilding; namespace CalamityMod.Projectiles.Magic { @@ -31,7 +32,7 @@ namespace CalamityMod.Projectiles.Magic Projectile.usesIDStaticNPCImmunity = true; Projectile.idStaticNPCHitCooldown = 31; Projectile.penetrate = -1; - Projectile.extraUpdates = 75; + Projectile.extraUpdates = 10; Projectile.timeLeft = 20; } @@ -48,7 +49,7 @@ namespace CalamityMod.Projectiles.Magic Projectile.timeLeft = 50; } - if (Projectile.timeLeft % 2 == 0 && (!SplitShot && Time > 2 || (SplitShot && Time > 3 && Projectile.timeLeft > 2))) + if (Projectile.timeLeft < (SplitShot ? 20 : 50)) { Particle spark = new GlowSparkParticle(Projectile.Center, -Projectile.velocity * 0.05f, false, 17, 0.06f, MainColor, new Vector2(0.5f, 1.3f)); GeneralParticleHandler.SpawnParticle(spark); @@ -74,14 +75,14 @@ namespace CalamityMod.Projectiles.Magic if (Main.myPlayer == Projectile.owner) Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, perturbedSpeed, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner, 0f, 1f); + } - for (int k = 0; k < 3; k++) - { - Particle blastRing = new CustomPulse(Projectile.Center, Vector2.Zero, MainColor, "CalamityMod/Particles/BloomCircle", Vector2.One, Main.rand.NextFloat(-10, 10), 0.5f, 0.4f, 35); - GeneralParticleHandler.SpawnParticle(blastRing); - Particle blastRing2 = new CustomPulse(Projectile.Center, Vector2.Zero, Color.White, "CalamityMod/Particles/BloomCircle", Vector2.One, Main.rand.NextFloat(-10, 10), 0.4f, 0.3f, 35); - GeneralParticleHandler.SpawnParticle(blastRing2); - } + for (int k = 0; k < 3; k++) + { + Particle blastRing = new CustomPulse(Projectile.Center, Vector2.Zero, MainColor, "CalamityMod/Particles/BloomCircle", Vector2.One, Main.rand.NextFloat(-10, 10), 0.5f, 0.4f, 35); + GeneralParticleHandler.SpawnParticle(blastRing); + Particle blastRing2 = new CustomPulse(Projectile.Center, Vector2.Zero, Color.White, "CalamityMod/Particles/BloomCircle", Vector2.One, Main.rand.NextFloat(-10, 10), 0.4f, 0.3f, 35); + GeneralParticleHandler.SpawnParticle(blastRing2); } for (int i = 0; i < 20; i++) @@ -107,12 +108,10 @@ namespace CalamityMod.Projectiles.Magic Projectile.netUpdate = true; } - public override void ModifyHitNPC(NPC target, ref NPC.HitModifiers modifiers) + public void OnHitEffects() { if (SplitShot) // This is the sweet spot { - modifiers.SourceDamage *= 1.5f; - int points = 10; float radians = MathHelper.TwoPi / points; Vector2 spinningPoint = Vector2.Normalize(new Vector2(-1f, -1f)); @@ -127,6 +126,17 @@ namespace CalamityMod.Projectiles.Magic SoundStyle fire = new("CalamityMod/Sounds/Item/ArcNovaDiffuserChargeImpact"); SoundEngine.PlaySound(fire with { Volume = 1.25f, Pitch = 0.4f, PitchVariance = 0.15f }, Projectile.Center); } + } + + public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) => OnHitEffects(); + + public override void OnHitPlayer(Player target, Player.HurtInfo info) => OnHitEffects(); + + public override void ModifyHitNPC(NPC target, ref NPC.HitModifiers modifiers) + { + if (SplitShot) + modifiers.SourceDamage *= 1.5f; + if (Projectile.numHits > 0) Projectile.damage = (int)(Projectile.damage * 0.95f); if (Projectile.damage < 1) diff --git a/Projectiles/Magic/MeteorStar.cs b/Projectiles/Magic/MeteorStar.cs index e123f24b7b..c2292cb1bb 100644 --- a/Projectiles/Magic/MeteorStar.cs +++ b/Projectiles/Magic/MeteorStar.cs @@ -1,5 +1,6 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using System; using Terraria; using Terraria.Audio; using Terraria.ID; @@ -10,6 +11,8 @@ namespace CalamityMod.Projectiles.Magic public class MeteorStar : ModProjectile, ILocalizedModType { public new string LocalizationCategory => "Projectiles.Magic"; + public Player Owner => Main.player[Projectile.owner]; + public override void SetStaticDefaults() { ProjectileID.Sets.TrailCacheLength[Projectile.type] = 5; @@ -22,128 +25,80 @@ namespace CalamityMod.Projectiles.Magic Projectile.width = 42; Projectile.height = 34; Projectile.friendly = true; + Projectile.tileCollide = false; Projectile.DamageType = DamageClass.Magic; Projectile.timeLeft = 361; } public override void AI() { - Player player = Main.player[Projectile.owner]; - bool flippedGravity = player.gravDir == -1f; - Projectile.frameCounter++; - if (Projectile.frameCounter > 6) - { - Projectile.frame++; - Projectile.frameCounter = 0; - } - if (Projectile.frame >= Main.projFrames[Projectile.type]) - { - Projectile.frame = 0; - } - - Lighting.AddLight(Projectile.Center, (255 - Projectile.alpha) * 0.5f / 255f, (255 - Projectile.alpha) * 0.5f / 255f, (255 - Projectile.alpha) * 0.15f / 255f); + Projectile.frame = Projectile.frameCounter / 6 % Main.projFrames[Projectile.type]; + Color LightYellow = new Color(255, 255, 76); + Lighting.AddLight(Projectile.Center, LightYellow.ToVector3() * Projectile.Opacity * 0.5f); bool explodingSoon = Projectile.timeLeft <= 120; if (Projectile.soundDelay <= 0) { - Projectile.soundDelay = 30 + Main.rand.Next(40); - if (explodingSoon) - Projectile.soundDelay -= 30; - if (Main.rand.NextBool(10) || explodingSoon) - { + Projectile.soundDelay = 30 + Main.rand.Next(explodingSoon ? 10 : 40); + if (Main.rand.NextBool(4) || explodingSoon) SoundEngine.PlaySound(SoundID.Item9, Projectile.Center); - } } - if ((Main.rand.NextBool(20) || explodingSoon) && Main.rand.NextBool(3) && Main.netMode != NetmodeID.Server) + if ((Main.rand.NextBool(12) || (explodingSoon && Main.rand.NextBool(3))) && Main.netMode != NetmodeID.Server) { - int idx = Gore.NewGore(Projectile.GetSource_FromAI(), Projectile.Center, Projectile.velocity * 0.2f, Main.rand.Next(16, 18), 1f); - Main.gore[idx].velocity *= 0.66f; - Main.gore[idx].velocity += Projectile.velocity * 0.3f; + Gore star = Gore.NewGoreDirect(Projectile.GetSource_FromAI(), Projectile.Center, Projectile.velocity * 0.2f, Main.rand.Next(16, 18), 1f); + star.velocity *= 0.66f; + star.velocity += Projectile.velocity * 0.3f; } if (explodingSoon) { for (int i = 0; i < 3; i++) { - int smoke = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, DustID.Smoke, 0f, 0f, 100, default, 2f); - Dust dust = Main.dust[smoke]; - dust.velocity *= 0.3f; - dust.position.X = Projectile.Center.X + 4f + Main.rand.NextFloat(-6f, 6f); - dust.position.Y = Projectile.Center.Y + Main.rand.NextFloat(-6f, 6f); - dust.noGravity = true; + Dust smoke = Dust.NewDustDirect(Projectile.position, Projectile.width, Projectile.height, DustID.Smoke, 0f, 0f, 100, default, 2f); + smoke.velocity *= 0.3f; + smoke.position.X = Projectile.Center.X + 4f + Main.rand.NextFloat(-6f, 6f); + smoke.position.Y = Projectile.Center.Y + Main.rand.NextFloat(-6f, 6f); + smoke.noGravity = true; } } if (Main.myPlayer == Projectile.owner) { - if (player.channel) + // Initialize position + if (Projectile.ai[2] != 1f) { - float speed = 14f; - float mouseDistX = (float)Main.mouseX + Main.screenPosition.X - Projectile.Center.X; - float mouseDistY = (float)Main.mouseY + Main.screenPosition.Y - Projectile.Center.Y; - if (player.gravDir == -1f) - { - mouseDistY = Main.screenPosition.Y + (float)Main.screenHeight - (float)Main.mouseY - Projectile.Center.Y; - } - Vector2 mouseVec = new Vector2(mouseDistX, mouseDistY); - float mouseDist = mouseVec.Length(); - if (mouseDist > speed) - { - mouseDist = speed / mouseDist; - mouseVec.X *= mouseDist; - mouseVec.Y *= mouseDist; - int mouseSpeedX = (int)(mouseVec.X * 1000f); - int projSpeedX = (int)(Projectile.velocity.X * 1000f); - int mouseSpeedY = (int)(mouseVec.Y * 1000f); - int projSpeedY = (int)(Projectile.velocity.Y * 1000f); - if (mouseSpeedX != projSpeedX || mouseSpeedY != projSpeedY) - { - Projectile.netUpdate = true; - } - Projectile.velocity.X = mouseVec.X; - Projectile.velocity.Y = mouseVec.Y; - } + if (Owner.gravDir == -1f) + Projectile.Center = Owner.Top; else - { - int mouseSpeedX = (int)(mouseVec.X * 1000f); - int projSpeedX = (int)(Projectile.velocity.X * 1000f); - int mouseSpeedY = (int)(mouseVec.Y * 1000f); - int projSpeedY = (int)(Projectile.velocity.Y * 1000f); - if (mouseSpeedX != projSpeedX || mouseSpeedY != projSpeedY) - { - Projectile.netUpdate = true; - } - Projectile.velocity.X = mouseVec.X; - Projectile.velocity.Y = mouseVec.Y; - } - player.ChangeDir((int)Projectile.velocity.X); - player.velocity = Projectile.velocity; - if (Projectile.velocity.Y > 16f) - { - Projectile.velocity.Y = 16f; - player.velocity.Y = 16f; - } - if (player.mount != null) - { - player.mount.Dismount(player); - } - if (!flippedGravity) - player.Bottom = Projectile.Center; + Projectile.Center = Owner.Bottom; + + Projectile.ai[2] = 1f; + Projectile.netUpdate = true; + Projectile.netSpam = 0; + } + if (Owner.channel) + { + Owner.mount?.Dismount(Owner); + Owner.RemoveAllGrapplingHooks(); + + Projectile.velocity = Owner.SafeDirectionTo(Owner.Calamity().mouseWorld) * 14f; + Owner.velocity = Projectile.velocity; + Owner.ChangeDir(Math.Sign(Projectile.velocity.X) <= 0 ? -1 : 1); + + // Move the player to the projectile, allowing them to bypass platforms + if (Owner.gravDir == -1f) + Owner.Top = Projectile.Center; else - player.Top = Projectile.Center; + Owner.Bottom = Projectile.Center; } else - { Explode(true); - } } - Projectile.tileCollide = Projectile.velocity != Vector2.Zero && ++Projectile.ai[0] >= 5f; - // Die immediately if the owner of this projectile is clipping into tiles because of its movement. - if (Collision.SolidCollision(player.position, player.width, player.height) && Projectile.velocity != Vector2.Zero) + if (Collision.SolidCollision(Owner.position, Owner.width, Owner.height) && Projectile.velocity != Vector2.Zero) { - player.velocity.Y = 0f; + Owner.velocity.Y = 0f; Explode(); } @@ -155,27 +110,14 @@ namespace CalamityMod.Projectiles.Magic public override void OnHitPlayer(Player target, Player.HurtInfo info) => Explode(); - public override bool OnTileCollide(Vector2 oldVelocity) - { - Explode(); - return base.OnTileCollide(oldVelocity); - } - public override bool PreDraw(ref Color lightColor) { CalamityUtils.DrawAfterimagesCentered(Projectile, ProjectileID.Sets.TrailingMode[Projectile.type], lightColor, 1); // Draw the main texture in fullbright Texture2D texture = Terraria.GameContent.TextureAssets.Projectile[Projectile.type].Value; - - int frameHeight = texture.Height / Main.projFrames[Projectile.type]; - int frameY = frameHeight * Projectile.frame; - float scale = Projectile.scale; - float rotation = Projectile.rotation; - - Rectangle rectangle = new Rectangle(0, frameY, texture.Width, frameHeight); - Vector2 origin = rectangle.Size() / 2f; - Main.spriteBatch.Draw(texture, Projectile.Center - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY), rectangle, Color.White, rotation, origin, scale, SpriteEffects.None, 0); + Rectangle frame = texture.Frame(1, Main.projFrames[Type], 0, Projectile.frame); + Main.EntitySpriteDraw(texture, Projectile.Center - Main.screenPosition, frame, Color.White, Projectile.rotation, frame.Size() * 0.5f, Projectile.scale, SpriteEffects.None); return false; } @@ -191,12 +133,12 @@ namespace CalamityMod.Projectiles.Magic for (int i = 0; i < 10; i++) { - int idx = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, DustID.Smoke, 0f, 0f, 100, default, 1.2f); - Main.dust[idx].velocity *= 3f; + Dust smoke = Dust.NewDustDirect(Projectile.position, Projectile.width, Projectile.height, DustID.Smoke, 0f, 0f, 100, default, 1.2f); + smoke.velocity *= 3f; if (Main.rand.NextBool()) { - Main.dust[idx].scale = 0.5f; - Main.dust[idx].fadeIn = 1f + Main.rand.Next(10) * 0.1f; + smoke.scale = 0.5f; + smoke.fadeIn = 1f + Main.rand.Next(10) * 0.1f; } } if (Main.netMode != NetmodeID.Server) @@ -208,5 +150,11 @@ namespace CalamityMod.Projectiles.Magic } Projectile.Kill(); } + + public override void OnKill(int timeLeft) + { + Owner.velocity *= 0.8f; + Owner.fullRotation = 0f; + } } } diff --git a/Projectiles/Magic/NanoPurgeHoldout.cs b/Projectiles/Magic/NanoPurgeHoldout.cs index b68d0f826f..54a6a8e99a 100644 --- a/Projectiles/Magic/NanoPurgeHoldout.cs +++ b/Projectiles/Magic/NanoPurgeHoldout.cs @@ -1,57 +1,53 @@ -using CalamityMod.Items.Weapons.Magic; +using System; +using CalamityMod.Items.Weapons.Magic; +using CalamityMod.Projectiles.BaseProjectiles; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.Audio; +using Terraria.DataStructures; +using Terraria.GameContent; using Terraria.ID; -using Terraria.Localization; using Terraria.ModLoader; namespace CalamityMod.Projectiles.Magic { - public class NanoPurgeHoldout : ModProjectile + public class NanoPurgeHoldout : BaseGunHoldoutProjectile { - public override LocalizedText DisplayName => CalamityUtils.GetItemName(); + public override int AssociatedItemID => ModContent.ItemType(); + public override string Texture => "CalamityMod/Projectiles/Magic/NanoPurgeHoldout"; + public override float MaxOffsetLengthFromArm => 10f; + public override float OffsetXUpwards => -15f; + public override float OffsetXDownwards => 5f; + public override float BaseOffsetY => -10f; + public override float OffsetYUpwards => 5f; + public override float OffsetYDownwards => 10f; + private const int FramesPerFireRateIncrease = 36; private static int[] LaserOffsetByAnimationFrame = { 4, 3, 0, 3 }; - private Player Owner => Main.player[Projectile.owner]; private ref float DeployedFrames => ref Projectile.ai[0]; private ref float ChargeTowardsNextShot => ref Projectile.ai[1]; - public override void SetStaticDefaults() - { - Main.projFrames[Projectile.type] = 4; - } + public override void SetStaticDefaults() => Main.projFrames[Type] = 4; - public override void SetDefaults() + public override void KillHoldoutLogic() { - Projectile.width = 34; - Projectile.height = 62; - Projectile.friendly = true; - Projectile.penetrate = -1; - Projectile.tileCollide = false; - Projectile.ignoreWater = true; - Projectile.DamageType = DamageClass.Magic; - } + base.KillHoldoutLogic(); - public override void AI() - { - Vector2 armPosition = Owner.RotatedRelativePoint(Owner.MountedCenter, true); - Vector2 gunBarrelPos = armPosition + Projectile.velocity * Projectile.height * 0.5f; - - // If the player is unable to continue using the holdout, delete it. - if (Owner.CantUseHoldout() || !Owner.HasAmmo(Owner.ActiveItem())) - { + bool actuallyShoot = DeployedFrames >= (HeldItem?.useAnimation ?? NanoPurge.UseTime); + bool manaOK = !actuallyShoot || Owner.CheckMana(Owner.ActiveItem(), -1, true, false); + if (!manaOK) Projectile.Kill(); - return; - } + } + public override void HoldoutAI() + { // Update damage based on curent magic damage stat (so Mana Sickness affects it) - Item weaponItem = Owner.ActiveItem(); - Projectile.damage = weaponItem is null ? 0 : Owner.GetWeaponDamage(weaponItem); + Projectile.damage = HeldItem is null ? 0 : Owner.GetWeaponDamage(HeldItem); // Get the original weapon's use time. - int itemUseTime = weaponItem?.useAnimation ?? NanoPurge.UseTime; + int itemUseTime = HeldItem?.useAnimation ?? NanoPurge.UseTime; // Update time. DeployedFrames += 1f; @@ -76,7 +72,7 @@ namespace CalamityMod.Projectiles.Magic SoundEngine.PlaySound(SoundID.Item91, Projectile.Center); int projID = ModContent.ProjectileType(); - float shootSpeed = weaponItem.shootSpeed; + float shootSpeed = HeldItem.shootSpeed; float inaccuracyRatio = 0.045f; Vector2 shootDirection = Projectile.velocity.SafeNormalize(Vector2.UnitY); Vector2 perp = shootDirection.RotatedBy(MathHelper.PiOver2); @@ -86,59 +82,22 @@ namespace CalamityMod.Projectiles.Magic { Vector2 spread = Main.rand.NextVector2CircularEdge(shootSpeed, shootSpeed); Vector2 shootVelocity = shootDirection * shootSpeed + inaccuracyRatio * spread; - Vector2 splitBarrelPos = gunBarrelPos + i * LaserOffsetByAnimationFrame[Projectile.frame] * perp; - Projectile.NewProjectile(Projectile.GetSource_FromThis(), splitBarrelPos, shootVelocity, projID, Projectile.damage, Projectile.knockBack, Projectile.owner, 0f, 0f); + Vector2 splitBarrelPos = GunTipPosition + i * LaserOffsetByAnimationFrame[Projectile.frame] * perp; + Projectile.NewProjectile(Projectile.GetSource_FromThis(), splitBarrelPos, shootVelocity, projID, Projectile.damage, Projectile.knockBack, Projectile.owner); SpawnFiringDust(splitBarrelPos, shootVelocity); } } - - // Delete the laser gun if a mana cost cannot be paid. - else - { - Projectile.Kill(); - return; - } } - UpdateProjectileHeldVariables(armPosition); - ManipulatePlayerVariables(); + ExtraBackArmRotation = Utils.Remap(Vector2.Dot(-Vector2.UnitY, Projectile.velocity.SafeNormalize(-Vector2.UnitY)), 0f, 1f, MathHelper.PiOver4, 0f); } - private void UpdateProjectileHeldVariables(Vector2 armPosition) - { - if (Main.myPlayer == Projectile.owner) - { - float interpolant = Utils.GetLerpValue(5f, 25f, Projectile.Distance(Main.MouseWorld), true); - Vector2 oldVelocity = Projectile.velocity; - Projectile.velocity = Vector2.Lerp(Projectile.velocity, Projectile.SafeDirectionTo(Main.MouseWorld), interpolant); - if (Projectile.velocity != oldVelocity) - { - Projectile.netSpam = 0; - Projectile.netUpdate = true; - } - } - - Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver2; - Projectile.Center = armPosition + Projectile.velocity.SafeNormalize(Vector2.UnitX * Owner.direction) * 8f; - Projectile.spriteDirection = Projectile.direction; - Projectile.timeLeft = 2; - } - - private void ManipulatePlayerVariables() - { - Owner.ChangeDir(Projectile.direction); - Owner.heldProj = Projectile.whoAmI; - Owner.itemTime = 2; - Owner.itemAnimation = 2; - Owner.itemRotation = (Projectile.velocity * Projectile.direction).ToRotation(); - } - - private void SpawnFiringDust(Vector2 gunBarrelPos, Vector2 laserVelocity) + private void SpawnFiringDust(Vector2 GunTipPosition, Vector2 laserVelocity) { int dustID = 107; int dustRadius = 5; int dustDiameter = 2 * dustRadius; - Vector2 dustCorner = gunBarrelPos - Vector2.One * dustRadius; + Vector2 dustCorner = GunTipPosition - Vector2.One * dustRadius; for (int i = 0; i < 2; i++) { Vector2 dustVel = laserVelocity + Main.rand.NextVector2Circular(7f, 7f); @@ -149,9 +108,24 @@ namespace CalamityMod.Projectiles.Magic } } - public override bool? CanDamage() => false; + public override void OnSpawn(IEntitySource source) + { + base.OnSpawn(source); + FrontArmStretch = Player.CompositeArmStretchAmount.Quarter; + } - // prevents the item from appearing backwards frame 1 - public override bool PreDraw(ref Color lightColor) => DeployedFrames > 0f; + public override bool PreDraw(ref Color lightColor) + { + Texture2D texture = TextureAssets.Projectile[Type].Value; + Vector2 drawPosition = Projectile.Center - Main.screenPosition; + Rectangle frame = texture.Frame(verticalFrames: Main.projFrames[Type], frameY: Projectile.frame); + float drawRotation = Projectile.rotation + (Projectile.spriteDirection == -1 ? MathHelper.Pi : 0f) + MathHelper.PiOver2; + Vector2 rotationPoint = frame.Size() * 0.5f; + SpriteEffects flipSprite = (Projectile.spriteDirection * Owner.gravDir == -1) ? SpriteEffects.FlipVertically : SpriteEffects.None; + + Main.EntitySpriteDraw(texture, drawPosition, frame, Projectile.GetAlpha(lightColor), drawRotation, rotationPoint, Projectile.scale * Owner.gravDir, flipSprite); + + return false; + } } } diff --git a/Projectiles/Magic/OmicronBeam.cs b/Projectiles/Magic/OmicronBeam.cs index e281affc55..2c12781212 100644 --- a/Projectiles/Magic/OmicronBeam.cs +++ b/Projectiles/Magic/OmicronBeam.cs @@ -1,8 +1,8 @@ -using CalamityMod.Particles; +using System.IO; +using CalamityMod.Particles; using Microsoft.Xna.Framework; using Terraria; using Terraria.Audio; -using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Projectiles.Magic @@ -11,13 +11,17 @@ namespace CalamityMod.Projectiles.Magic { public new string LocalizationCategory => "Projectiles.Magic"; public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + public ref float time => ref Projectile.ai[0]; - - public Color mainColor = Color.MediumVioletRed; - public bool HitDirect = false; - public ref float isSplit => ref Projectile.ai[1]; - public bool splitShot = false; + public bool splitShot + { + get => Projectile.ai[2] == 1f; + set => Projectile.ai[2] = value == true ? 1f : 0f; + } + public bool HitDirect { get; set; } + public Color mainColor { get; set; } = Color.MediumVioletRed; + public override void SetDefaults() { Projectile.width = 50; @@ -31,21 +35,25 @@ namespace CalamityMod.Projectiles.Magic Projectile.usesIDStaticNPCImmunity = true; Projectile.idStaticNPCHitCooldown = 91; } + public override void AI() { if (isSplit == 0) { + Projectile.netSpam = 0; Projectile.netUpdate = true; splitShot = true; } Player Owner = Main.player[Projectile.owner]; float targetDist = Vector2.Distance(Owner.Center, Projectile.Center); + if (Projectile.timeLeft % 2 == 0 && time > 2 && targetDist < 1400f) { Particle spark = new GlowSparkParticle(Projectile.Center, -Projectile.velocity * 0.05f, false, 25, MathHelper.Clamp(0.34f - time * 0.07f, 0.085f, 0.34f), mainColor, new Vector2(0.5f, 1.3f)); GeneralParticleHandler.SpawnParticle(spark); } + if (Main.rand.NextBool()) { Vector2 trailPos = Projectile.Center; @@ -53,13 +61,21 @@ namespace CalamityMod.Projectiles.Magic Particle Trail = new SparkParticle(trailPos, Projectile.velocity * Main.rand.NextFloat(0.2f, 0.9f), false, Main.rand.Next(40, 50 + 1), trailScale, mainColor); GeneralParticleHandler.SpawnParticle(Trail); } + Vector2 dustVel = new Vector2(2, 2).RotatedByRandom(100) * Main.rand.NextFloat(0.1f, 0.8f); Dust dust = Dust.NewDustPerfect(Projectile.Center + dustVel, Main.rand.NextBool(4) ? 264 : 66, dustVel, 0, default, Main.rand.NextFloat(0.9f, 1.2f)); dust.noGravity = true; dust.color = Main.rand.NextBool() ? Color.Lerp(mainColor, Color.White, 0.5f) : mainColor; time++; + + if (Projectile.numUpdates == 1) + { + Projectile.netSpam = 0; + Projectile.netUpdate = true; + } } + public override void OnKill(int timeLeft) { int numProj = 2; @@ -98,18 +114,21 @@ namespace CalamityMod.Projectiles.Magic dust.color = Main.rand.NextBool() ? Color.Lerp(mainColor, Color.White, 0.5f) : mainColor; } } + public override void ModifyHitNPC(NPC target, ref NPC.HitModifiers modifiers) { if (splitShot && time > 7 && !HitDirect) Projectile.Kill(); Player Owner = Main.player[Projectile.owner]; + for (int i = 0; i <= 8; i++) { Dust dust = Dust.NewDustPerfect(Projectile.Center, Main.rand.NextBool(4) ? 264 : 66, (Projectile.velocity.SafeNormalize(Vector2.UnitY) * 15f).RotatedByRandom(MathHelper.ToRadians(15f)) * Main.rand.NextFloat(0.1f, 0.8f), 0, default, Main.rand.NextFloat(1.2f, 1.6f)); dust.noGravity = true; dust.color = Main.rand.NextBool() ? Color.Lerp(mainColor, Color.White, 0.5f) : mainColor; } + if (time <= 7 && splitShot) // This is the sweet spot { modifiers.SourceDamage *= 5; @@ -144,6 +163,11 @@ namespace CalamityMod.Projectiles.Magic HitDirect = true; } } + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) => CalamityUtils.CircularHitboxCollision(Projectile.Center, time <= 7 ? 90 : 20, targetHitbox); + + public override void SendExtraAI(BinaryWriter writer) => writer.Write(HitDirect); + + public override void ReceiveExtraAI(BinaryReader reader) => HitDirect = reader.ReadBoolean(); } } diff --git a/Projectiles/Magic/OmicronHoldout.cs b/Projectiles/Magic/OmicronHoldout.cs index 9a73374df0..9d3aef3fb7 100644 --- a/Projectiles/Magic/OmicronHoldout.cs +++ b/Projectiles/Magic/OmicronHoldout.cs @@ -1,4 +1,5 @@ -using CalamityMod.Items.Weapons.Magic; +using System.IO; +using CalamityMod.Items.Weapons.Magic; using CalamityMod.Particles; using CalamityMod.Projectiles.BaseProjectiles; using Microsoft.Xna.Framework; @@ -90,9 +91,6 @@ namespace CalamityMod.Projectiles.Magic public void Shoot(bool yBeam) { Vector2 shootDirection = Projectile.velocity.SafeNormalize(Vector2.Zero); - - // Spawns the projectile. - Vector2 firingVelocity1 = (shootDirection * 8).RotatedBy(0.1f * Utils.GetLerpValue(10, 55, Windup, true)); Vector2 firingVelocity2 = (shootDirection * 8).RotatedBy(-0.1f * Utils.GetLerpValue(10, 55, Windup, true)); Vector2 firingVelocity3 = (shootDirection * 10); @@ -175,5 +173,9 @@ namespace CalamityMod.Projectiles.Magic ShootingTimer = 0; PostFireCooldown--; } + + public override void SendExtraAIHoldout(BinaryWriter writer) => writer.Write(Windup); + + public override void ReceiveExtraAIHoldout(BinaryReader reader) => Windup = reader.ReadSingle(); } } diff --git a/Projectiles/Magic/OmicronWingman.cs b/Projectiles/Magic/OmicronWingman.cs index a932b15d32..9b830bea2a 100644 --- a/Projectiles/Magic/OmicronWingman.cs +++ b/Projectiles/Magic/OmicronWingman.cs @@ -1,19 +1,16 @@ using System; +using System.Collections.Generic; +using System.IO; using CalamityMod.Items.Weapons.Magic; using CalamityMod.Particles; -using Humanizer; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -using ReLogic.Utilities; using Terraria; using Terraria.Audio; using Terraria.DataStructures; using Terraria.ID; using Terraria.Localization; using Terraria.ModLoader; -using System.Collections.Generic; -using System.IO; -using CalamityMod.Graphics.Renderers; namespace CalamityMod.Projectiles.Magic { @@ -26,7 +23,6 @@ namespace CalamityMod.Projectiles.Magic private ref float ShootingTimer => ref Projectile.ai[0]; private float FiringTime = 10; private float PostFireCooldown = 0; - private Vector2 MovementOffset; public bool MovingUp = true; public float xOffset = 1; public float yOffset = 0; @@ -42,45 +38,48 @@ namespace CalamityMod.Projectiles.Magic public bool recharging = false; + public override void SetStaticDefaults() + { + ProjectileID.Sets.TrailCacheLength[Type] = 9; + ProjectileID.Sets.TrailingMode[Type] = 2; + } + public override void SetDefaults() { Projectile.width = Projectile.height = 142; Projectile.tileCollide = false; Projectile.ignoreWater = true; Projectile.netImportant = true; - ProjectileID.Sets.TrailCacheLength[Projectile.type] = 9; - ProjectileID.Sets.TrailingMode[Projectile.type] = 2; Projectile.hide = true; } public override void AI() { + Owner ??= Main.player[Projectile.owner]; + if (time > 1 && Owner.ownedProjectileCounts[ModContent.ProjectileType()] < 1 && PostFireCooldown <= 0) Projectile.Kill(); + Lighting.AddLight(Projectile.Center, StaticEffectsColor.ToVector3() * 0.2f); + if (time == 0) - { - MovingUp = Projectile.ai[2] == 1 ? true : false; - } + MovingUp = Projectile.ai[2] == 1; + firingDelay--; Item heldItem = Owner.ActiveItem(); // Update damage based on curent magic damage stat (so Mana Sickness affects it) Projectile.damage = heldItem is null ? 0 : Owner.GetWeaponDamage(heldItem); - Vector2 tipPosition = Projectile.Center + Projectile.velocity.SafeNormalize(Vector2.Zero).RotatedBy(-0.05f * Projectile.direction) * 12f; // If there's no player, or the player is the server, or the owner's stunned, there'll be no holdout. if (PostFireCooldown == 0 && launchDelay == 0 && Owner.CantUseHoldout() || heldItem.type != ModContent.ItemType()) { - NetUpdate(); if (PostFireCooldown <= 0) Projectile.Kill(); } if (PostFireCooldown > 0) - { PostFiringCooldown(); - } if (launchDelay > 0 || (PostFireCooldown <= 0 && (Owner.Calamity().mouseRight || (firingDelay <= 0 && Projectile.ai[2] == 1 || Projectile.ai[2] == -1)))) { @@ -89,10 +88,10 @@ namespace CalamityMod.Projectiles.Magic { if (launchDelay < 50) launchDelay++; - + if (launchDelay >= 50 && (Owner.CheckMana(Owner.ActiveItem(), (int)(heldItem.mana * Owner.manaCost) * 2, true, false))) { - Shoot(heldItem, true); + Shoot(true); PostFireCooldown = 50; ShootingTimer = 0; launchDelay = 0; @@ -102,13 +101,11 @@ namespace CalamityMod.Projectiles.Magic { if (Owner.CheckMana(Owner.ActiveItem(), -1, false, false)) { - Shoot(heldItem, false); + Shoot(false); ShootingTimer = 0; } else if (PostFireCooldown <= 0) - { Projectile.Kill(); - } } } @@ -119,7 +116,7 @@ namespace CalamityMod.Projectiles.Magic Vector2 ownerToMouse = Owner.Calamity().mouseWorld - ownerPosition; // Deals with the holdout's rotation and direction, the owner's arms, etc. - ManageHoldout(ownerPosition, ownerToMouse); + ManagePlayerProjectileMembers(ownerToMouse); // When we change the distance of the gun from the arms for the recoil, // recover to the original position smoothly. @@ -127,82 +124,66 @@ namespace CalamityMod.Projectiles.Magic OffsetLength = MathHelper.Lerp(OffsetLength, MaxOffsetLength, 0.1f); ShootingTimer++; - - // Inside here go all the things that dedicated servers shouldn't spend resources on. - // Like visuals and sounds. - if (Main.dedServ) - return; - - Vector2 shootDirection = Projectile.velocity.SafeNormalize(Vector2.Zero) * 20; time++; Projectile.soundDelay--; + + Projectile.netSpam = 0; + Projectile.netUpdate = true; } - private void ManageHoldout(Vector2 mountedCenter, Vector2 ownerToMouse) + private void ManagePlayerProjectileMembers(Vector2 ownerToMouse) { Vector2 rotationVector = Projectile.rotation.ToRotationVector2(); float velocityRotation = Projectile.velocity.ToRotation(); - float proximityLookingUpwards = Vector2.Dot(ownerToMouse.SafeNormalize(Vector2.Zero), -Vector2.UnitY); int direction = MathF.Sign(ownerToMouse.X); - - Vector2 armPosition = Owner.RotatedRelativePoint(mountedCenter, true); Vector2 lengthOffset = rotationVector * OffsetLength; - Vector2 armOffset = new Vector2(Utils.Remap(proximityLookingUpwards, -1f, 1f, 0f, -12f) * direction, -10f + Utils.Remap(MathF.Abs(proximityLookingUpwards), 0f, 1f, 0f, proximityLookingUpwards > 0f ? 15f : 0f)); if (time % 30 == 0) - { MovingUp = !MovingUp; - } //xOffset = MathHelper.Lerp(xOffset, placementOffset.X, 0.01f); yOffset = MathHelper.Lerp(yOffset, 150 * (MovingUp ? -1 : 1), (0.085f - (FiringTime * 0.0012f))); Vector2 placementOffset = Projectile.velocity.SafeNormalize(Vector2.UnitX).RotatedBy(MathHelper.PiOver2) * (yOffset); - Vector2 location = Owner.MountedCenter + placementOffset; Projectile.Center = lengthOffset + location; - - Projectile.velocity = velocityRotation.AngleTowards(ownerToMouse.ToRotation(), 0.2f).ToRotationVector2(); - Projectile.rotation = (Main.MouseWorld - Projectile.Center).SafeNormalize(Vector2.UnitX).ToRotation(); + Projectile.rotation = (Owner.Calamity().mouseWorld - Projectile.Center).SafeNormalize(Vector2.UnitX).ToRotation(); Projectile.timeLeft = 2; - - Owner.heldProj = Projectile.whoAmI; - Owner.itemTime = Owner.itemAnimation = 2; - Owner.itemRotation = (Projectile.velocity * Projectile.direction).ToRotation(); - Projectile.spriteDirection = Projectile.direction = direction; } - private void Shoot(Item item, bool isGrenade) + private void Shoot(bool isGrenade) { - Vector2 shootDirection = (Main.MouseWorld - Projectile.Center).SafeNormalize(Vector2.UnitX); + Vector2 shootDirection = (Owner.Calamity().mouseWorld - Projectile.Center).SafeNormalize(Vector2.UnitX); // The position of the tip of the gun. Vector2 tipPosition = Projectile.Center + Projectile.velocity.SafeNormalize(Vector2.Zero).RotatedBy(-0.05f * Projectile.direction) * 12f; - // Spawns the projectile. - Vector2 firingVelocity = shootDirection * 10; if (isGrenade) { SoundStyle fire = new("CalamityMod/Sounds/Item/DeadSunExplosion"); SoundEngine.PlaySound(fire with { Volume = 0.2f, Pitch = -0.4f, PitchVariance = 0.2f }, Projectile.Center); - Projectile bomb = Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), tipPosition, firingVelocity, ModContent.ProjectileType(), Projectile.damage * 14, Projectile.knockBack * 5, Projectile.owner, 0, 2); - bomb.timeLeft = 530; - Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), tipPosition, firingVelocity * 1.2f, ModContent.ProjectileType(), Projectile.damage * 14, Projectile.knockBack * 5, Projectile.owner, 0, 2); + if (Main.myPlayer == Projectile.owner) + { + Projectile bomb = Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), tipPosition, firingVelocity, ModContent.ProjectileType(), Projectile.damage * 14, Projectile.knockBack * 5, Projectile.owner, 0, 2); + bomb.timeLeft = 530; + Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), tipPosition, firingVelocity * 1.2f, ModContent.ProjectileType(), Projectile.damage * 14, Projectile.knockBack * 5, Projectile.owner, 0, 2); + } } else { SoundStyle fire = new("CalamityMod/Sounds/Item/MagnaCannonShot"); SoundEngine.PlaySound(fire with { Volume = 0.25f, Pitch = 1f, PitchVariance = 0.35f }, Projectile.Center); - - Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), tipPosition, firingVelocity, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner, 0, 2); - Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), tipPosition, firingVelocity.RotatedBy(-0.05) * 0.85f, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner, 0, 2); - Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), tipPosition, firingVelocity.RotatedBy(0.05) * 0.85f, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner, 0, 2); - } - NetUpdate(); + if (Main.myPlayer == Projectile.owner) + { + Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), tipPosition, firingVelocity, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner, 0, 2); + Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), tipPosition, firingVelocity.RotatedBy(-0.05) * 0.85f, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner, 0, 2); + Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), tipPosition, firingVelocity.RotatedBy(0.05) * 0.85f, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner, 0, 2); + } + } // Inside here go all the things that dedicated servers shouldn't spend resources on. // Like visuals and sounds. @@ -218,6 +199,7 @@ namespace CalamityMod.Projectiles.Magic dust2.noGravity = true; dust2.color = Main.rand.NextBool() ? Color.Lerp(StaticEffectsColor, Color.White, 0.5f) : StaticEffectsColor; } + Particle pulse = new GlowSparkParticle((tipPosition - shootDirection * 14), shootDirection * 20, false, Main.rand.Next(7, 11 + 1), 0.035f, StaticEffectsColor, new Vector2(1.5f, 0.9f), true); GeneralParticleHandler.SpawnParticle(pulse); @@ -227,6 +209,7 @@ namespace CalamityMod.Projectiles.Magic else OffsetLength -= 5f; } + private void PostFiringCooldown() { Owner.channel = true; @@ -242,23 +225,13 @@ namespace CalamityMod.Projectiles.Magic dust.noGravity = false; dust.color = StaticEffectsColor; } + ShootingTimer = 0; firingDelay = 15; PostFireCooldown--; } - private void NetUpdate() - { - Projectile.netUpdate = true; - if (Projectile.netSpam >= 10) - Projectile.netSpam = 9; - } - - public override void OnSpawn(IEntitySource source) - { - Owner = Main.player[Projectile.owner]; - OffsetLength = MaxOffsetLength; - } + public override void OnSpawn(IEntitySource source) => OffsetLength = MaxOffsetLength; // Because we use the velocity as a direction, we don't need it to change its position. public override bool ShouldUpdatePosition() => false; @@ -270,8 +243,7 @@ namespace CalamityMod.Projectiles.Magic if (time <= 0) return false; - Texture2D texture = ModContent.Request("CalamityMod/Items/Weapons/Magic/Wingman").Value; - + Texture2D texture; if (Projectile.ai[2] == 1) texture = ModContent.Request("CalamityMod/Projectiles/Magic/OmicronWingman").Value; else @@ -291,9 +263,29 @@ namespace CalamityMod.Projectiles.Magic return false; } - public override void DrawBehind(int index, List behindNPCsAndTiles, List behindNPCs, List behindProjectiles, List overPlayers, List overWiresUI) + + public override void DrawBehind(int index, List behindNPCsAndTiles, List behindNPCs, List behindProjectiles, List overPlayers, List overWiresUI) => behindNPCs.Add(index); + + public override void SendExtraAI(BinaryWriter writer) { - behindNPCs.Add(index); + writer.Write(Projectile.rotation); + writer.Write(Projectile.spriteDirection); + writer.Write(OffsetLength); + writer.Write(time); + writer.Write(firingDelay); + writer.Write(launchDelay); + writer.Write(MovingUp); + } + + public override void ReceiveExtraAI(BinaryReader reader) + { + Projectile.rotation = reader.ReadSingle(); + Projectile.spriteDirection = reader.ReadInt32(); + OffsetLength = reader.ReadSingle(); + time = reader.ReadInt32(); + firingDelay = reader.ReadInt32(); + launchDelay = reader.ReadInt32(); + MovingUp = reader.ReadBoolean(); } } } diff --git a/Projectiles/Magic/PhasedGodRay.cs b/Projectiles/Magic/PhasedGodRay.cs index 97b300715c..633e74c335 100644 --- a/Projectiles/Magic/PhasedGodRay.cs +++ b/Projectiles/Magic/PhasedGodRay.cs @@ -17,7 +17,7 @@ namespace CalamityMod.Projectiles.Magic // They are extremely carefully chosen and barely work as is! private const float WaveTheta = 0.09f; private const int WaveTwistFrames = 9; - private ref float WaveFrameState => ref Projectile.localAI[1]; + private ref float WaveFrameState => ref Projectile.ai[0]; public override string Texture => "CalamityMod/Projectiles/LaserProj"; @@ -53,7 +53,7 @@ namespace CalamityMod.Projectiles.Magic float waveSign = WaveFrameState < 0f ? -1f : 1f; - // Initialize waving. Setting localAI[1] to a number between -1 and 1 tells it which way to wave. + // Initialize waving. Setting ai[0] to a number between -1 and 1 tells it which way to wave. // Exactly 0 is a coinflip. if (Math.Abs(WaveFrameState) < 1f) { diff --git a/Projectiles/Magic/WingmanGrenade.cs b/Projectiles/Magic/WingmanGrenade.cs index fe6b7fb52a..d25fad5311 100644 --- a/Projectiles/Magic/WingmanGrenade.cs +++ b/Projectiles/Magic/WingmanGrenade.cs @@ -1,25 +1,31 @@ -using CalamityMod.Particles; -using CalamityMod.Projectiles.Summon; +using System.IO; +using CalamityMod.Particles; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.Audio; using Terraria.ID; using Terraria.ModLoader; + namespace CalamityMod.Projectiles.Magic { public class WingmanGrenade : ModProjectile, ILocalizedModType { public new string LocalizationCategory => "Projectiles.Magic"; public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; - public int BounceHits = 0; - public Color mainColor = Color.White; - public bool exploding = false; - public float sizeBonus = 1; + + public bool exploding + { + get => Projectile.ai[0] == 1f; + set => Projectile.ai[0] = value == true ? 1f : 0f; + } + public float sizeBonus { get; set; } = 1f; + public Color mainColor { get; set; } = Color.White; + public override void SetStaticDefaults() { - ProjectileID.Sets.TrailCacheLength[Projectile.type] = 14; - ProjectileID.Sets.TrailingMode[Projectile.type] = 2; + ProjectileID.Sets.TrailCacheLength[Type] = 14; + ProjectileID.Sets.TrailingMode[Type] = 2; } public override void SetDefaults() @@ -35,6 +41,8 @@ namespace CalamityMod.Projectiles.Magic Projectile.localNPCHitCooldown = -1; } + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) => CalamityUtils.CircularHitboxCollision(Projectile.Center, exploding ? 120 * sizeBonus : 20 * sizeBonus, targetHitbox); + public override void AI() { if (mainColor == Color.White) @@ -60,8 +68,10 @@ namespace CalamityMod.Projectiles.Magic if (exploding) { Projectile.velocity = Vector2.Zero; + if (Projectile.timeLeft > 65) Projectile.timeLeft = 65; + if (Projectile.timeLeft == 65) { Particle blastRing2 = new CustomPulse(Projectile.Center, Vector2.Zero, mainColor, "CalamityMod/Particles/HighResHollowCircleHardEdge", Vector2.One, Main.rand.NextFloat(-10, 10), 0f, 0.12f * sizeBonus, 15); @@ -71,6 +81,7 @@ namespace CalamityMod.Projectiles.Magic SoundStyle fire = new("CalamityMod/Sounds/Item/ArcNovaDiffuserChargeImpact"); SoundEngine.PlaySound(fire with { Volume = 1.25f, Pitch = -0.2f, PitchVariance = 0.15f }, Projectile.Center); } + if (Projectile.timeLeft == 65) { Particle blastRing2 = new CustomPulse(Projectile.Center, Vector2.Zero, mainColor, "CalamityMod/Particles/HighResHollowCircleHardEdge", Vector2.One, Main.rand.NextFloat(-10, 10), 0.12f * sizeBonus, 0.135f * sizeBonus, 50); @@ -83,10 +94,11 @@ namespace CalamityMod.Projectiles.Magic GeneralParticleHandler.SpawnParticle(blastRing2); } } - Lighting.AddLight(Projectile.Center, mainColor.ToVector3() * 0.7f); - Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver2; - + Projectile.velocity *= 0.988f; + Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver2; + Lighting.AddLight(Projectile.Center, mainColor.ToVector3() * 0.7f); + if (Projectile.timeLeft % 2 == 0) { if (!exploding && Main.rand.NextBool() || exploding) @@ -97,51 +109,49 @@ namespace CalamityMod.Projectiles.Magic dust.color = Main.rand.NextBool() ? Color.Lerp(mainColor, Color.White, 0.5f) : mainColor; } } - } - public override bool PreDraw(ref Color lightColor) - { - Texture2D texture = ModContent.Request("CalamityMod/Particles/Light").Value; - Vector2 drawPosition = Projectile.Center - Main.screenPosition; - Color drawColor = Projectile.GetAlpha(lightColor); - float drawRotation = Projectile.rotation; - Vector2 rotationPoint = texture.Size() * 0.5f; - if (!exploding) - { - CalamityUtils.DrawAfterimagesCentered(Projectile, ProjectileID.Sets.TrailingMode[Projectile.type], Color.Lerp(mainColor, Color.White, 0.5f) * 0.6f, 1); - Main.EntitySpriteDraw(texture, drawPosition, null, mainColor with { A = 0 }, drawRotation, rotationPoint, Projectile.scale, SpriteEffects.None); - Main.EntitySpriteDraw(texture, drawPosition, null, Color.White with { A = 0 }, drawRotation, rotationPoint, Projectile.scale, SpriteEffects.None); - - } - return false; + Projectile.netSpam = 0; + Projectile.netUpdate = true; } + public override void ModifyHitNPC(NPC target, ref NPC.HitModifiers modifiers) { if (!exploding) - { exploding = true; - } + if (Projectile.numHits > 0) Projectile.damage = (int)(Projectile.damage * 0.80f); if (Projectile.damage < 1) Projectile.damage = 1; } - public override void OnKill(int timeLeft) - { - for (int i = 0; i <= 5; i++) - { - //Dust dust = Dust.NewDustPerfect(Projectile.Center, Main.rand.NextBool(4) ? 264 : 66, (Projectile.velocity.SafeNormalize(Vector2.UnitY) * 15f).RotatedByRandom(MathHelper.ToRadians(15f)) * Main.rand.NextFloat(0.1f, 0.8f), 0, default, Main.rand.NextFloat(1.2f, 1.6f)); - //dust.noGravity = true; - //dust.color = Main.rand.NextBool() ? Color.Lerp(mainColor, Color.White, 0.5f) : mainColor; - } - } + public override bool OnTileCollide(Vector2 oldVelocity) { Projectile.tileCollide = false; exploding = true; return false; } - public override bool? CanDamage() => null; - public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) => CalamityUtils.CircularHitboxCollision(Projectile.Center, exploding ? 120 * sizeBonus : 20 * sizeBonus, targetHitbox); + + public override bool PreDraw(ref Color lightColor) + { + Texture2D texture = ModContent.Request("CalamityMod/Particles/Light").Value; + Vector2 drawPosition = Projectile.Center - Main.screenPosition; + float drawRotation = Projectile.rotation; + Vector2 rotationPoint = texture.Size() * 0.5f; + + if (!exploding) + { + CalamityUtils.DrawAfterimagesCentered(Projectile, ProjectileID.Sets.TrailingMode[Type], Color.Lerp(mainColor, Color.White, 0.5f) * 0.6f, 1); + Main.EntitySpriteDraw(texture, drawPosition, null, mainColor with { A = 0 }, drawRotation, rotationPoint, Projectile.scale, SpriteEffects.None); + Main.EntitySpriteDraw(texture, drawPosition, null, Color.White with { A = 0 }, drawRotation, rotationPoint, Projectile.scale, SpriteEffects.None); + + } + + return false; + } + + public override void SendExtraAI(BinaryWriter writer) => writer.Write(sizeBonus); + + public override void ReceiveExtraAI(BinaryReader reader) => sizeBonus = reader.ReadSingle(); } } diff --git a/Projectiles/Magic/WingmanHoldout.cs b/Projectiles/Magic/WingmanHoldout.cs index bca2231d0b..7a7d41eec1 100644 --- a/Projectiles/Magic/WingmanHoldout.cs +++ b/Projectiles/Magic/WingmanHoldout.cs @@ -1,19 +1,16 @@ using System; +using System.Collections.Generic; +using System.IO; using CalamityMod.Items.Weapons.Magic; using CalamityMod.Particles; -using Humanizer; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -using ReLogic.Utilities; using Terraria; using Terraria.Audio; using Terraria.DataStructures; using Terraria.ID; using Terraria.Localization; using Terraria.ModLoader; -using System.Collections.Generic; -using System.IO; -using CalamityMod.Graphics.Renderers; namespace CalamityMod.Projectiles.Magic { @@ -24,22 +21,22 @@ namespace CalamityMod.Projectiles.Magic public Color StaticEffectsColor = Color.HotPink; private ref float ShootingTimer => ref Projectile.ai[0]; + private ref float PostFireCooldown => ref Projectile.ai[1]; + public float yOffset; + private float OffsetLength; private float FiringTime = 40; - private float PostFireCooldown = 0; - private Vector2 MovementOffset; - public bool MovingUp = true; - public float xOffset = 1; - public float yOffset = 0; - public int time = 0; + public int time; public int firingDelay = 45; - - private ref float OffsetLength => ref Projectile.localAI[0]; - + public bool MovingUp = true; private Player Owner; - private float MaxOffsetLength = 5f; + private static readonly float MaxOffsetLength = 5f; - public bool recharging = false; + public override void SetStaticDefaults() + { + ProjectileID.Sets.TrailCacheLength[Type] = 9; + ProjectileID.Sets.TrailingMode[Type] = 2; + } public override void SetDefaults() { @@ -47,19 +44,21 @@ namespace CalamityMod.Projectiles.Magic Projectile.tileCollide = false; Projectile.ignoreWater = true; Projectile.netImportant = true; - ProjectileID.Sets.TrailCacheLength[Projectile.type] = 9; - ProjectileID.Sets.TrailingMode[Projectile.type] = 2; Projectile.hide = true; } public override void AI() { + Owner ??= Main.player[Projectile.owner]; + Lighting.AddLight(Projectile.Center, StaticEffectsColor.ToVector3() * 0.2f); + if (time == 0) { MovingUp = Projectile.ai[2] == 1 ? true : false; } firingDelay--; + Item heldItem = Owner.ActiveItem(); // Update damage based on curent magic damage stat (so Mana Sickness affects it) @@ -72,9 +71,8 @@ namespace CalamityMod.Projectiles.Magic Vector2 tipPosition = Projectile.Center + Projectile.velocity.SafeNormalize(Vector2.Zero).RotatedBy(-0.05f * Projectile.direction) * 12f; // If there's no player, or the player is the server, or the owner's stunned, there'll be no holdout. - if (Owner.CantUseHoldout() || heldItem.type != ModContent.ItemType() ) + if (Owner.CantUseHoldout() || heldItem.type != ModContent.ItemType()) { - NetUpdate(); if (PostFireCooldown <= 0) Projectile.Kill(); } @@ -85,7 +83,7 @@ namespace CalamityMod.Projectiles.Magic { if ((Owner.CheckMana(Owner.ActiveItem(), (int)(heldItem.mana * Owner.manaCost) * 5, true, false))) { - Shoot(heldItem, true); + Shoot(true); PostFireCooldown = 35 + 55 * Utils.GetLerpValue(10, 40, FiringTime, true); ShootingTimer = 0; FiringTime = 40; @@ -102,9 +100,9 @@ namespace CalamityMod.Projectiles.Magic } else if (ShootingTimer >= FiringTime) { - if (Owner.CheckMana(Owner.ActiveItem(), -1, true, false)) + if (Owner.CheckMana(Owner.ActiveItem(), (int)(heldItem.mana * Owner.manaCost), true, false)) { - Shoot(heldItem, false); + Shoot(false); ShootingTimer = 0; if (FiringTime > 10) @@ -132,7 +130,7 @@ namespace CalamityMod.Projectiles.Magic Vector2 ownerToMouse = Owner.Calamity().mouseWorld - ownerPosition; // Deals with the holdout's rotation and direction, the owner's arms, etc. - ManageHoldout(ownerPosition, ownerToMouse); + ManageHoldout(ownerToMouse); // When we change the distance of the gun from the arms for the recoil, // recover to the original position smoothly. @@ -140,73 +138,54 @@ namespace CalamityMod.Projectiles.Magic OffsetLength = MathHelper.Lerp(OffsetLength, MaxOffsetLength, 0.1f); ShootingTimer++; - - // Inside here go all the things that dedicated servers shouldn't spend resources on. - // Like visuals and sounds. - if (Main.dedServ) - return; - - Vector2 shootDirection = Projectile.velocity.SafeNormalize(Vector2.Zero) * 20; time++; Projectile.soundDelay--; + + Projectile.netSpam = 0; + Projectile.netUpdate = true; } - private void ManageHoldout(Vector2 mountedCenter, Vector2 ownerToMouse) + private void ManageHoldout(Vector2 ownerToMouse) { Vector2 rotationVector = Projectile.rotation.ToRotationVector2(); float velocityRotation = Projectile.velocity.ToRotation(); - float proximityLookingUpwards = Vector2.Dot(ownerToMouse.SafeNormalize(Vector2.Zero), -Vector2.UnitY); int direction = MathF.Sign(ownerToMouse.X); - - Vector2 armPosition = Owner.RotatedRelativePoint(mountedCenter, true); Vector2 lengthOffset = rotationVector * OffsetLength; - Vector2 armOffset = new Vector2(Utils.Remap(proximityLookingUpwards, -1f, 1f, 0f, -12f) * direction, -10f + Utils.Remap(MathF.Abs(proximityLookingUpwards), 0f, 1f, 0f, proximityLookingUpwards > 0f ? 15f : 0f)); if (time % 40 == 0) - { MovingUp = !MovingUp; - } //xOffset = MathHelper.Lerp(xOffset, placementOffset.X, 0.01f); yOffset = MathHelper.Lerp(yOffset, 150 * (MovingUp ? -1 : 1), (0.085f - (FiringTime * 0.0012f))); Vector2 placementOffset = Projectile.velocity.SafeNormalize(Vector2.UnitX).RotatedBy(MathHelper.PiOver2) * (yOffset); - Vector2 location = Owner.MountedCenter + placementOffset; Projectile.Center = lengthOffset + location; - - Projectile.velocity = velocityRotation.AngleTowards(ownerToMouse.ToRotation(), 0.2f).ToRotationVector2(); - Projectile.rotation = (Main.MouseWorld - Projectile.Center).SafeNormalize(Vector2.UnitX).ToRotation(); + Projectile.rotation = (Owner.Calamity().mouseWorld - Projectile.Center).SafeNormalize(Vector2.UnitX).ToRotation(); Projectile.timeLeft = 2; + Projectile.spriteDirection = Projectile.direction = direction; + Owner.ChangeDir(direction); + Owner.heldProj = Projectile.whoAmI; Owner.itemTime = Owner.itemAnimation = 2; Owner.itemRotation = (Projectile.velocity * Projectile.direction).ToRotation(); - Projectile.spriteDirection = Projectile.direction = direction; - Owner.ChangeDir(direction); - float armRotation = (Projectile.rotation - MathHelper.PiOver2); // -Pi/2 because the arms rotation starts with arms pointing down. if (Projectile.ai[2] == 1) - { - Owner.SetCompositeArmFront(true, Player.CompositeArmStretchAmount.Quarter, armRotation); - } + Owner.SetCompositeArmFront(true, Player.CompositeArmStretchAmount.Full, armRotation); else - { Owner.SetCompositeArmBack(true, Player.CompositeArmStretchAmount.Full, armRotation); - } } - private void Shoot(Item item, bool isGrenade) + private void Shoot(bool isGrenade) { - Vector2 shootDirection = (Main.MouseWorld - Projectile.Center).SafeNormalize(Vector2.UnitX); + Vector2 shootDirection = (Owner.Calamity().mouseWorld - Projectile.Center).SafeNormalize(Vector2.UnitX); // The position of the tip of the gun. Vector2 tipPosition = Projectile.Center + Projectile.velocity.SafeNormalize(Vector2.Zero).RotatedBy(-0.05f * Projectile.direction) * 12f; - // Spawns the projectile. - Vector2 firingVelocity = shootDirection * 10; if (isGrenade) { @@ -221,8 +200,6 @@ namespace CalamityMod.Projectiles.Magic Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), tipPosition, firingVelocity * Utils.GetLerpValue(80, 10, FiringTime, true), ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner, 0); } - NetUpdate(); - // Inside here go all the things that dedicated servers shouldn't spend resources on. // Like visuals and sounds. if (Main.dedServ) @@ -246,6 +223,7 @@ namespace CalamityMod.Projectiles.Magic else OffsetLength -= 5f; } + private void PostFiringCooldown() { Owner.channel = true; @@ -266,18 +244,7 @@ namespace CalamityMod.Projectiles.Magic PostFireCooldown--; } - private void NetUpdate() - { - Projectile.netUpdate = true; - if (Projectile.netSpam >= 10) - Projectile.netSpam = 9; - } - - public override void OnSpawn(IEntitySource source) - { - Owner = Main.player[Projectile.owner]; - OffsetLength = MaxOffsetLength; - } + public override void OnSpawn(IEntitySource source) => OffsetLength = MaxOffsetLength; // Because we use the velocity as a direction, we don't need it to change its position. public override bool ShouldUpdatePosition() => false; @@ -289,8 +256,7 @@ namespace CalamityMod.Projectiles.Magic if (time <= 0 && !Main.dedServ) return false; - Texture2D texture = ModContent.Request("CalamityMod/Items/Weapons/Magic/Wingman").Value; - + Texture2D texture; if (Projectile.ai[2] == 1) texture = ModContent.Request("CalamityMod/Items/Weapons/Magic/Wingman").Value; else @@ -309,9 +275,31 @@ namespace CalamityMod.Projectiles.Magic return false; } - public override void DrawBehind(int index, List behindNPCsAndTiles, List behindNPCs, List behindProjectiles, List overPlayers, List overWiresUI) + + public override void DrawBehind(int index, List behindNPCsAndTiles, List behindNPCs, List behindProjectiles, List overPlayers, List overWiresUI) => behindNPCs.Add(index); + + public override void SendExtraAI(BinaryWriter writer) { - behindNPCs.Add(index); + writer.Write(Projectile.rotation); + writer.Write(Projectile.spriteDirection); + writer.Write(OffsetLength); + writer.Write(FiringTime); + writer.Write(time); + writer.Write(firingDelay); + writer.Write(MovingUp); + writer.Write(yOffset); + } + + public override void ReceiveExtraAI(BinaryReader reader) + { + Projectile.rotation = reader.ReadSingle(); + Projectile.spriteDirection = reader.ReadInt32(); + OffsetLength = reader.ReadSingle(); + FiringTime = reader.ReadSingle(); + time = reader.ReadInt32(); + firingDelay = reader.ReadInt32(); + MovingUp = reader.ReadBoolean(); + yOffset = reader.ReadSingle(); } } } diff --git a/Projectiles/Melee/DepthCrusherProjectile.cs b/Projectiles/Melee/DepthCrusherProjectile.cs index 8e65dbcd00..d0b0e7f55d 100644 --- a/Projectiles/Melee/DepthCrusherProjectile.cs +++ b/Projectiles/Melee/DepthCrusherProjectile.cs @@ -105,7 +105,7 @@ namespace CalamityMod.Projectiles.Melee } Projectile.rotation += (0.4f * (MathF.Abs(Projectile.velocity.Y) * 0.2f + 0.6f)) * Projectile.direction; - if (Projectile.velocity.Y < 20) + if (Projectile.velocity.Y < 16) Projectile.velocity.Y += Projectile.numHits >= 3 ? 0.7f : 0.4f; if (Projectile.numHits >= 3) { @@ -119,7 +119,7 @@ namespace CalamityMod.Projectiles.Melee if (Projectile.velocity.Y > 0) Projectile.velocity.X *= 0.975f; - if (Collision.SolidCollision(Projectile.Center, 15, 15)) + if (Collision.SolidCollision(Projectile.Center, 25, 25)) { Projectile.tileCollide = true; } @@ -133,9 +133,9 @@ namespace CalamityMod.Projectiles.Melee if (!setDamage) { if (Projectile.velocity.Y > 0) - Projectile.velocity.Y = -9; + Projectile.velocity.Y -= 6; else - Projectile.velocity.Y = -7; + Projectile.velocity.Y = -6; } for (int i = 0; i < 15; i++) @@ -195,7 +195,7 @@ namespace CalamityMod.Projectiles.Melee SoundEngine.PlaySound(HitSound, Projectile.Center); for (int i = 0; i < 3; i++) { - Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, new Vector2(0, -5).RotatedByRandom(0.6f) * Main.rand.NextFloat(0.9f, 1.1f), ModContent.ProjectileType(), startDamage / 4, Projectile.knockBack / 4, Projectile.owner); + Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Bottom, new Vector2(0, -5).RotatedByRandom(0.6f) * Main.rand.NextFloat(0.9f, 1.1f), ModContent.ProjectileType(), (int)(startDamage * 0.3f), Projectile.knockBack / 4, Projectile.owner); } Projectile.Kill(); } diff --git a/Projectiles/Melee/DepthCrusherSplitProjectile.cs b/Projectiles/Melee/DepthCrusherSplitProjectile.cs index 5c2b6ef338..4da528c2f8 100644 --- a/Projectiles/Melee/DepthCrusherSplitProjectile.cs +++ b/Projectiles/Melee/DepthCrusherSplitProjectile.cs @@ -42,7 +42,7 @@ namespace CalamityMod.Projectiles.Melee } if (Time > 20 && Time < (randTimer - 70)) { - CalamityUtils.HomeInOnNPC(Projectile, true, 280f, MathHelper.Clamp(1f + Time * 0.06f, 1, 10), 20f); + CalamityUtils.HomeInOnNPC(Projectile, true, 384f, MathHelper.Clamp(1f + Time * 0.12f, 1, 11), 20f); } else if (Time >= (randTimer - 70)) { diff --git a/Projectiles/Melee/TerratomereHoldoutProj.cs b/Projectiles/Melee/TerratomereHoldoutProj.cs index 9861f0ab15..95ff843ca5 100644 --- a/Projectiles/Melee/TerratomereHoldoutProj.cs +++ b/Projectiles/Melee/TerratomereHoldoutProj.cs @@ -169,21 +169,21 @@ namespace CalamityMod.Projectiles.Melee for (int i = 0; i < totalBeams; i++) { Vector2 randomVelocity = Main.rand.NextVector2CircularEdge(randomVelocityLimit, randomVelocityLimit); - Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center - bigSlashVelocity * 0.4f, bigSlashVelocity + randomVelocity, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner); + Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center - bigSlashVelocity * 0.4f, bigSlashVelocity + randomVelocity, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner); } } - // This is a slash, not a beam. + // Close range slash effect if (Main.myPlayer == Projectile.owner && Time == (int)(Terratomere.SwingTime * RecoveryCompletionRatio) + 5f) { Vector2 bigSlashVelocity = InitialRotation.ToRotationVector2() * Owner.ActiveItem().shootSpeed / 6f; Vector2 bigSlashSpawnPosition = Projectile.Center + bigSlashVelocity.SafeNormalize(Vector2.UnitY) * 64f; - int slash = Projectile.NewProjectile(Projectile.GetSource_FromThis(), bigSlashSpawnPosition, bigSlashVelocity, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner); + int slash = Projectile.NewProjectile(Projectile.GetSource_FromThis(), bigSlashSpawnPosition, bigSlashVelocity, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner); if (Main.projectile.IndexInRange(slash)) { Main.projectile[slash].ai[0] = (Direction == 1f).ToInt(); - Main.projectile[slash].ModProjectile().ControlPoints = GenerateSlashPoints().ToArray(); + Main.projectile[slash].ModProjectile().ControlPoints = GenerateSlashPoints().ToArray(); } } } diff --git a/Projectiles/Melee/TerratomereBeam.cs b/Projectiles/Melee/TerratomereMeleeSlash.cs similarity index 86% rename from Projectiles/Melee/TerratomereBeam.cs rename to Projectiles/Melee/TerratomereMeleeSlash.cs index e25ce01dd4..1f95774c5f 100644 --- a/Projectiles/Melee/TerratomereBeam.cs +++ b/Projectiles/Melee/TerratomereMeleeSlash.cs @@ -8,7 +8,7 @@ using Terraria.ModLoader; namespace CalamityMod.Projectiles.Melee { - public class TerratomereBeam : ModProjectile, ILocalizedModType + public class TerratomereMeleeSlash : ModProjectile, ILocalizedModType { public new string LocalizationCategory => "Projectiles.Melee"; public Vector2[] ControlPoints; @@ -54,8 +54,8 @@ namespace CalamityMod.Projectiles.Melee for (int i = 0; i < ControlPoints.Length; i++) points.Add(ControlPoints[i] + ControlPoints[i].SafeNormalize(Vector2.Zero) * (Projectile.scale - 1f) * 40f); - for (int i = 0; i < 3; i++) - PrimitiveRenderer.RenderTrail(points, new(SlashWidthFunction, SlashColorFunction, (_) => Projectile.Center, shader: GameShaders.Misc["CalamityMod:ExobladeSlash"]), 65); + // 17MAY2024: Ozzatron: remove Terratomere rendering its trails multiple times + PrimitiveRenderer.RenderTrail(points, new(SlashWidthFunction, SlashColorFunction, (_) => Projectile.Center, shader: GameShaders.Misc["CalamityMod:ExobladeSlash"]), 65); Main.spriteBatch.ExitShaderRegion(); return false; diff --git a/Projectiles/Melee/TerratomereBeam.png b/Projectiles/Melee/TerratomereMeleeSlash.png similarity index 100% rename from Projectiles/Melee/TerratomereBeam.png rename to Projectiles/Melee/TerratomereMeleeSlash.png diff --git a/Projectiles/Melee/TerratomereBigSlash.cs b/Projectiles/Melee/TerratomereSwordBeam.cs similarity index 90% rename from Projectiles/Melee/TerratomereBigSlash.cs rename to Projectiles/Melee/TerratomereSwordBeam.cs index 0e339a35e8..b31f77baca 100644 --- a/Projectiles/Melee/TerratomereBigSlash.cs +++ b/Projectiles/Melee/TerratomereSwordBeam.cs @@ -9,7 +9,7 @@ using Terraria.ModLoader; namespace CalamityMod.Projectiles.Melee { - public class TerratomereBigSlash : ModProjectile, ILocalizedModType + public class TerratomereSwordBeam : ModProjectile, ILocalizedModType { public new string LocalizationCategory => "Projectiles.Melee"; public int TargetIndex = -1; @@ -72,8 +72,8 @@ namespace CalamityMod.Projectiles.Melee GameShaders.Misc["CalamityMod:ExobladePierce"].UseColor(Terratomere.TerraColor1); GameShaders.Misc["CalamityMod:ExobladePierce"].UseSecondaryColor(Terratomere.TerraColor2); - for (int i = 0; i < 4; i++) - PrimitiveRenderer.RenderTrail(Projectile.oldPos, new(SlashWidthFunction, SlashColorFunction, (_) => Projectile.Size * 0.5f, shader: GameShaders.Misc["CalamityMod:ExobladePierce"]), 30); + // 17MAY2024: Ozzatron: remove Terratomere rendering its trails multiple times + PrimitiveRenderer.RenderTrail(Projectile.oldPos, new(SlashWidthFunction, SlashColorFunction, (_) => Projectile.Size * 0.5f, shader: GameShaders.Misc["CalamityMod:ExobladePierce"]), 30); return false; } diff --git a/Projectiles/Ranged/ArcNovaDiffuserHoldout.cs b/Projectiles/Ranged/ArcNovaDiffuserHoldout.cs index e042721fbb..bfda144189 100644 --- a/Projectiles/Ranged/ArcNovaDiffuserHoldout.cs +++ b/Projectiles/Ranged/ArcNovaDiffuserHoldout.cs @@ -32,7 +32,7 @@ namespace CalamityMod.Projectiles.Ranged public override void KillHoldoutLogic() { - if (HeldItem.type != Owner.ActiveItem().type || Owner is null || !Owner.active || Owner.CCed || Owner.dead || Owner.noItems) + if (Owner.CantUseHoldout(false) || HeldItem.type != Owner.ActiveItem().type) Projectile.Kill(); } diff --git a/Projectiles/Ranged/FlakKrakenProjectile.cs b/Projectiles/Ranged/FlakKrakenProjectile.cs index 962a9ba3c5..98db63bb3b 100644 --- a/Projectiles/Ranged/FlakKrakenProjectile.cs +++ b/Projectiles/Ranged/FlakKrakenProjectile.cs @@ -61,6 +61,8 @@ namespace CalamityMod.Projectiles.Ranged public override void AI() { + Owner ??= Main.player[Projectile.owner]; + // Enforces the gravity. if (IsShrapnel) { @@ -124,15 +126,9 @@ namespace CalamityMod.Projectiles.Ranged trailDust.noGravity = true; trailDust.noLight = true; trailDust.alpha = (int)Utils.Remap(Projectile.timeLeft, 30f, 0f, 127f, 0f); - - Lighting.AddLight(Projectile.Center, Color.White.ToVector3() * (IsShrapnel ? 0.3f : 1f)); } - public override void OnSpawn(IEntitySource source) - { - Owner = Main.player[Projectile.owner]; - Projectile.scale = 1.5f; - } + public override void OnSpawn(IEntitySource source) => Projectile.scale = 1.5f; public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) { @@ -169,7 +165,7 @@ namespace CalamityMod.Projectiles.Ranged { bool usedClusterRockets = RocketID == ItemID.ClusterRocketI || RocketID == ItemID.ClusterRocketII; int flakAmount = usedClusterRockets ? ClusterShrapnelAmount : ShrapnelAmount; - for (int i = 0; i < flakAmount; i++) + for (int i = 0; i < flakAmount && Main.myPlayer == Projectile.owner; i++) { Projectile shrapnel = Projectile.NewProjectileDirect( Projectile.GetSource_FromThis(), diff --git a/Projectiles/Ranged/FlakToxicannonProjectile.cs b/Projectiles/Ranged/FlakToxicannonProjectile.cs index 01b0f9336b..a01cdd3535 100644 --- a/Projectiles/Ranged/FlakToxicannonProjectile.cs +++ b/Projectiles/Ranged/FlakToxicannonProjectile.cs @@ -59,6 +59,8 @@ namespace CalamityMod.Projectiles.Ranged public override void AI() { + Owner ??= Main.player[Projectile.owner]; + // Enforces the gravity. if (IsShrapnel) { @@ -119,11 +121,7 @@ namespace CalamityMod.Projectiles.Ranged Lighting.AddLight(Projectile.Center, Color.GreenYellow.ToVector3() * (IsShrapnel ? 1.5f : 2.5f)); } - public override void OnSpawn(IEntitySource source) - { - Owner = Main.player[Projectile.owner]; - Projectile.scale = 1.5f; - } + public override void OnSpawn(IEntitySource source) => Projectile.scale = 1.5f; public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) { @@ -160,7 +158,7 @@ namespace CalamityMod.Projectiles.Ranged { bool usedClusterRockets = RocketID == ItemID.ClusterRocketI || RocketID == ItemID.ClusterRocketII; int flakAmount = usedClusterRockets ? ClusterShrapnelAmount : ShrapnelAmount; - for (int i = 0; i < flakAmount; i++) + for (int i = 0; i < flakAmount && Main.myPlayer == Projectile.owner; i++) { Projectile shrapnel = Projectile.NewProjectileDirect( Projectile.GetSource_FromThis(), diff --git a/Projectiles/Ranged/MagnaCannonHoldout.cs b/Projectiles/Ranged/MagnaCannonHoldout.cs index 46cd0b8502..ef4ea8c38e 100644 --- a/Projectiles/Ranged/MagnaCannonHoldout.cs +++ b/Projectiles/Ranged/MagnaCannonHoldout.cs @@ -1,67 +1,48 @@ -using System; -using CalamityMod.Items.Weapons.Ranged; +using CalamityMod.Items.Weapons.Ranged; using CalamityMod.Particles; +using CalamityMod.Projectiles.BaseProjectiles; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using ReLogic.Utilities; using Terraria; using Terraria.Audio; -using Terraria.Localization; +using Terraria.GameContent; using Terraria.ModLoader; namespace CalamityMod.Projectiles.Ranged { - public class MagnaCannonHoldout : ModProjectile + public class MagnaCannonHoldout : BaseGunHoldoutProjectile { - // Take the name and texture from the weapon - public override LocalizedText DisplayName => CalamityUtils.GetItemName(); - public override string Texture => "CalamityMod/Items/Weapons/Ranged/MagnaCannon"; - - public static int FramesPerLoad = 9; - public static int MaxLoadableShots = 20; - public static float BulletSpeed = 12f; - - private Player Owner => Main.player[Projectile.owner]; - public SlotId MagnaChargeSlot; + public override int AssociatedItemID => ModContent.ItemType(); + public override float MaxOffsetLengthFromArm => 20f; + public override float OffsetXUpwards => -5f; + public override float BaseOffsetY => -5f; private ref float CurrentChargingFrames => ref Projectile.ai[0]; private ref float ShotsLoaded => ref Projectile.ai[1]; private ref float ShootTimer => ref Projectile.ai[2]; private bool FullyCharged => CurrentChargingFrames >= MagnaCannon.FullChargeFrames; - public int Time = 0; + public SlotId MagnaChargeSlot; + public static int FramesPerLoad = 9; + public static int MaxLoadableShots = 20; + public static float BulletSpeed = 12f; - public override void SetDefaults() + public override void KillHoldoutLogic() { - Projectile.width = 58; - Projectile.height = 30; - Projectile.friendly = true; - Projectile.tileCollide = false; - Projectile.DamageType = DamageClass.Ranged; - Projectile.ignoreWater = true; + if (Owner.CantUseHoldout(false) || HeldItem.type != Owner.ActiveItem().type) + Projectile.Kill(); } - public override void AI() + public override void HoldoutAI() { - Time++; - if (Time == 1) - Projectile.alpha = 255; - else - Projectile.alpha = 0; - - if (Owner.dead) // destroy the holdout if the player dies - { - Projectile.Kill(); - return; - } - - Vector2 armPosition = Owner.RotatedRelativePoint(Owner.MountedCenter, true); - Vector2 tipPosition = armPosition + Projectile.velocity * Projectile.width * 0.9f; - if (SoundEngine.TryGetActiveSound(MagnaChargeSlot, out var ChargeSound) && ChargeSound.IsPlaying) ChargeSound.Position = Projectile.Center; // Fire if the owner stops channeling or otherwise cannot use the weapon. if (Owner.CantUseHoldout()) { + KeepRefreshingLifetime = false; + if (ShotsLoaded > 0) { // While bullets are remaining, refresh the lifespan; it will not refresh again after bullets run out @@ -75,24 +56,19 @@ namespace CalamityMod.Projectiles.Ranged SoundEngine.PlaySound(MagnaCannon.Fire, Projectile.position); Vector2 shootVelocity = Projectile.velocity.SafeNormalize(Vector2.UnitY) * BulletSpeed; - Projectile.NewProjectile(Projectile.GetSource_FromThis(), tipPosition, shootVelocity.RotatedByRandom(MathHelper.ToRadians(9f)), ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack * (FullyCharged ? 3 : 1), Projectile.owner); + Projectile.NewProjectile(Projectile.GetSource_FromThis(), GunTipPosition, shootVelocity.RotatedByRandom(MathHelper.ToRadians(9f)), ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack * (FullyCharged ? 3 : 1), Projectile.owner); for (int i = 0; i <= 3; i++) { - Dust dust = Dust.NewDustPerfect(tipPosition, 187, shootVelocity.RotatedByRandom(MathHelper.ToRadians(15f)) * Main.rand.NextFloat(0.9f, 1.2f), 0, default, Main.rand.NextFloat(1.5f, 2.3f)); + Dust dust = Dust.NewDustPerfect(GunTipPosition, 187, shootVelocity.RotatedByRandom(MathHelper.ToRadians(15f)) * Main.rand.NextFloat(0.9f, 1.2f), 0, default, Main.rand.NextFloat(1.5f, 2.3f)); dust.noGravity = true; } ShotsLoaded--; - ShootTimer = (FullyCharged ? 4f : 5f); - Projectile.netSpam = 0; - Projectile.netUpdate = true; + ShootTimer = FullyCharged ? 4f : 5f; } } else { - // While channeled, keep refreshing the projectile lifespan - Projectile.timeLeft = 2; - // Loads shots until maxed out if (ShotsLoaded < MaxLoadableShots && CurrentChargingFrames % FramesPerLoad == 0) ShotsLoaded++; @@ -116,13 +92,13 @@ namespace CalamityMod.Projectiles.Ranged { if (!FullyCharged) { - Particle streak = new ManaDrainStreak(Owner, Main.rand.NextFloat(0.06f + (CurrentChargingFrames / 180), 0.08f + (CurrentChargingFrames / 180)), Main.rand.NextVector2CircularEdge(2f, 2f) * Main.rand.NextFloat(0.3f * CurrentChargingFrames, 0.3f * CurrentChargingFrames), 0f, Color.White, Color.Aqua, 7, tipPosition); + Particle streak = new ManaDrainStreak(Owner, Main.rand.NextFloat(0.06f + (CurrentChargingFrames / 180), 0.08f + (CurrentChargingFrames / 180)), Main.rand.NextVector2CircularEdge(2f, 2f) * Main.rand.NextFloat(0.3f * CurrentChargingFrames, 0.3f * CurrentChargingFrames), 0f, Color.White, Color.Aqua, 7, GunTipPosition); GeneralParticleHandler.SpawnParticle(streak); } float orbScale = MathHelper.Clamp(CurrentChargingFrames, 0f, MagnaCannon.FullChargeFrames); - Particle orb = new GenericBloom(tipPosition, Projectile.velocity, Color.DarkBlue, orbScale / 135f, 2); + Particle orb = new GenericBloom(GunTipPosition, Projectile.velocity, Color.DarkBlue, orbScale / 135f, 2); GeneralParticleHandler.SpawnParticle(orb); - Particle orb2 = new GenericBloom(tipPosition, Projectile.velocity, Color.Aqua, orbScale / 200f, 2); + Particle orb2 = new GenericBloom(GunTipPosition, Projectile.velocity, Color.Aqua, orbScale / 200f, 2); GeneralParticleHandler.SpawnParticle(orb2); } @@ -131,49 +107,38 @@ namespace CalamityMod.Projectiles.Ranged { for (int i = 0; i < 36; i++) { - Dust chargefull = Dust.NewDustPerfect(tipPosition, 160); + Dust chargefull = Dust.NewDustPerfect(GunTipPosition, 160); chargefull.velocity = (MathHelper.TwoPi * i / 36f).ToRotationVector2() * 18f + Owner.velocity; chargefull.scale = Main.rand.NextFloat(1f, 1.5f); chargefull.noGravity = true; } } } - UpdateProjectileHeldVariables(armPosition); - ManipulatePlayerVariables(); } - private void UpdateProjectileHeldVariables(Vector2 armPosition) - { - if (Main.myPlayer == Projectile.owner) - { - float interpolant = Utils.GetLerpValue(5f, 40f, Projectile.Distance(Main.MouseWorld), true); - Vector2 oldVelocity = Projectile.velocity; - Projectile.velocity = Vector2.Lerp(Projectile.velocity, Projectile.SafeDirectionTo(Main.MouseWorld), interpolant); - } - Projectile.Center = armPosition + Projectile.velocity * 20; - Projectile.rotation = Projectile.velocity.ToRotation() + (Projectile.spriteDirection == -1 ? MathHelper.Pi : 0f); - Projectile.spriteDirection = Projectile.direction; - - // Rumble (only while channeling) - float rumble = MathHelper.Clamp(CurrentChargingFrames, 0f, MagnaCannon.FullChargeFrames); - if (!Owner.CantUseHoldout()) - Projectile.position += Main.rand.NextVector2Circular(rumble / 43f, rumble / 43f); - } - - private void ManipulatePlayerVariables() - { - Owner.ChangeDir(Projectile.direction); - Owner.heldProj = Projectile.whoAmI; - Owner.itemTime = 2; - Owner.itemAnimation = 2; - Owner.itemRotation = (Projectile.velocity * Projectile.direction).ToRotation(); - } public override void OnKill(int timeLeft) { if (SoundEngine.TryGetActiveSound(MagnaChargeSlot, out var ChargeSound)) ChargeSound?.Stop(); } - public override bool? CanDamage() => false; + public override bool PreDraw(ref Color lightColor) + { + Texture2D texture = TextureAssets.Projectile[Type].Value; + Vector2 drawPosition = Projectile.Center - Main.screenPosition; + float drawRotation = Projectile.rotation + (Projectile.spriteDirection == -1 ? MathHelper.Pi : 0f); + Vector2 rotationPoint = texture.Size() * 0.5f; + SpriteEffects flipSprite = (Projectile.spriteDirection * Owner.gravDir == -1) ? SpriteEffects.FlipHorizontally : SpriteEffects.None; + + if (!Owner.CantUseHoldout()) + { + float rumble = MathHelper.Clamp(CurrentChargingFrames, 0f, MagnaCannon.FullChargeFrames); + drawPosition += Main.rand.NextVector2Circular(rumble / 43f, rumble / 43f); + } + + Main.EntitySpriteDraw(texture, drawPosition, null, Projectile.GetAlpha(lightColor), drawRotation, rotationPoint, Projectile.scale * Owner.gravDir, flipSprite); + + return false; + } } } diff --git a/Projectiles/Ranged/NullShot.cs b/Projectiles/Ranged/NullShot.cs index e7b444bcb3..2ec483b36b 100644 --- a/Projectiles/Ranged/NullShot.cs +++ b/Projectiles/Ranged/NullShot.cs @@ -45,44 +45,44 @@ namespace CalamityMod.Projectiles.Ranged public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) { - if (target.type == NPCID.TargetDummy || CalamityPlayer.areThereAnyDamnBosses || CalamityLists.AquaticScourgeIDs.Contains(target.type)) + if (target.type == NPCID.TargetDummy) { return; } - int nullBuff = Main.rand.Next(7); + + int randAmt = (CalamityPlayer.areThereAnyDamnBosses || CalamityLists.AquaticScourgeIDs.Contains(target.type)) ? 6 : 8; + int nullBuff = Main.rand.Next(randAmt); if (!target.boss) { - if (nullBuff == 0) + switch (nullBuff) { - target.scale *= 2f; - } - else if (nullBuff == 1) - { - target.scale *= 0.5f; - } - else if (nullBuff == 2 && target.type != ModContent.NPCType()) - { - target.damage += 10; - } - else if (nullBuff == 3) - { - target.damage -= 10; - } - else if (nullBuff == 4) - { - target.knockBackResist = 0f; - } - else if (nullBuff == 5) - { - target.knockBackResist = 1f; - } - else if (nullBuff == 6) - { - target.defense += 5; - } - else - { - target.defense -= 5; + case 0: + if (target.type != ModContent.NPCType()) + target.damage += 10; + break; + case 1: + target.damage -= 10; + break; + case 2: + target.knockBackResist = 0f; + break; + case 3: + target.knockBackResist = 1f; + break; + case 4: + target.defense += 5; + break; + case 5: + target.defense -= 5; + break; + case 6: + target.scale *= 2f; + break; + case 7: + target.scale *= 0.5f; + break; + default: + break; } } } diff --git a/Projectiles/Ranged/NullShot2.cs b/Projectiles/Ranged/NullShot2.cs index dfcc271c29..d24185b9d0 100644 --- a/Projectiles/Ranged/NullShot2.cs +++ b/Projectiles/Ranged/NullShot2.cs @@ -45,52 +45,50 @@ namespace CalamityMod.Projectiles.Ranged public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) { - if (target.type == NPCID.TargetDummy || CalamityPlayer.areThereAnyDamnBosses || CalamityLists.AquaticScourgeIDs.Contains(target.type)) + if (target.type == NPCID.TargetDummy) { return; } - int nullBuff = Main.rand.Next(10); + + int randAmt = (CalamityPlayer.areThereAnyDamnBosses || CalamityLists.AquaticScourgeIDs.Contains(target.type)) ? 8 : 10; + int nullBuff = Main.rand.Next(randAmt); if (!target.boss) { - if (nullBuff == 0) + switch (nullBuff) { - target.scale *= 5f; - } - else if (nullBuff == 1) - { - target.scale *= 0.1f; - } - else if (nullBuff == 2 && target.type != ModContent.NPCType()) - { - target.damage += 20; - } - else if (nullBuff == 3) - { - target.damage -= 20; - } - else if (nullBuff == 4) - { - target.knockBackResist = 0f; - } - else if (nullBuff == 5) - { - target.knockBackResist = 1f; - } - else if (nullBuff == 6) - { - target.defense += 10; - } - else if (nullBuff == 7) - { - target.defense -= 10; - } - else if (nullBuff == 8) - { - target.velocity.Y = Main.rand.NextBool() ? 30f : -30f; - } - else - { - target.velocity.X = Main.rand.NextBool() ? 30f : -30f; + case 0: + if (target.type != ModContent.NPCType()) + target.damage += 20; + break; + case 1: + target.damage -= 20; + break; + case 2: + target.knockBackResist = 0f; + break; + case 3: + target.knockBackResist = 1f; + break; + case 4: + target.defense += 10; + break; + case 5: + target.defense -= 10; + break; + case 6: + target.velocity.Y = Main.rand.NextBool() ? 30f : -30f; + break; + case 7: + target.velocity.X = Main.rand.NextBool() ? 30f : -30f; + break; + case 8: + target.scale *= 5f; + break; + case 9: + target.scale *= 0.1f; + break; + default: + break; } } } diff --git a/Projectiles/Ranged/OpalStrikerHoldout.cs b/Projectiles/Ranged/OpalStrikerHoldout.cs index afc3cb7b6d..7a42eabdbf 100644 --- a/Projectiles/Ranged/OpalStrikerHoldout.cs +++ b/Projectiles/Ranged/OpalStrikerHoldout.cs @@ -1,92 +1,71 @@ -using System; -using CalamityMod.Items.Weapons.Ranged; +using CalamityMod.Items.Weapons.Ranged; using CalamityMod.Particles; +using CalamityMod.Projectiles.BaseProjectiles; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using ReLogic.Utilities; using Terraria; using Terraria.Audio; -using Terraria.Localization; +using Terraria.GameContent; using Terraria.ModLoader; namespace CalamityMod.Projectiles.Ranged { - public class OpalStrikerHoldout : ModProjectile + public class OpalStrikerHoldout : BaseGunHoldoutProjectile { - // Take the name and texture from the weapon - public override LocalizedText DisplayName => CalamityUtils.GetItemName(); - public override string Texture => "CalamityMod/Items/Weapons/Ranged/OpalStriker"; + public override int AssociatedItemID => ModContent.ItemType(); + public override float MaxOffsetLengthFromArm => 15f; + public override float OffsetXUpwards => -5f; + public override float BaseOffsetY => -5f; + private ref float CurrentChargingFrames => ref Projectile.ai[0]; + private bool FullyCharged => CurrentChargingFrames >= OpalStriker.FullChargeFrames; + public SlotId OpalChargeSlot; public static float ChargedDamageMult = 5f; public static float ChargedKBMult = 3f; public static float BulletSpeed = 12f; - private Player Owner => Main.player[Projectile.owner]; - public SlotId OpalChargeSlot; - - private ref float CurrentChargingFrames => ref Projectile.ai[0]; - private bool FullyCharged => CurrentChargingFrames >= OpalStriker.FullChargeFrames; - public int Time = 0; - - public override void SetDefaults() + public override void KillHoldoutLogic() { - Projectile.width = 46; - Projectile.height = 30; - Projectile.friendly = true; - Projectile.tileCollide = false; - Projectile.DamageType = DamageClass.Ranged; - Projectile.ignoreWater = true; + if (Owner.CantUseHoldout(false) || HeldItem.type != Owner.ActiveItem().type) + Projectile.Kill(); } - public override void AI() + public override void HoldoutAI() { - Time++; - if (Time == 1) - Projectile.alpha = 255; - else - Projectile.alpha = 0; - - if (Owner.dead) // destroy the holdout if the player dies - { - Projectile.Kill(); - return; - } - - Vector2 armPosition = Owner.RotatedRelativePoint(Owner.MountedCenter, true); - Vector2 tipPosition = (armPosition + Projectile.velocity * Projectile.width * 0.85f) + (Projectile.velocity * 4).RotatedBy(-0.3f * Projectile.direction); - if (SoundEngine.TryGetActiveSound(OpalChargeSlot, out var ChargeSound) && ChargeSound.IsPlaying) ChargeSound.Position = Projectile.Center; // Fire if the owner stops channeling or otherwise cannot use the weapon. if (Owner.CantUseHoldout()) { + KeepRefreshingLifetime = false; + if (Projectile.ai[1] != 1f) { + Projectile.timeLeft = OpalStriker.AftershotCooldownFrames; + ChargeSound?.Stop(); SoundEngine.PlaySound(FullyCharged ? OpalStriker.ChargedFire : OpalStriker.Fire, Projectile.Center); Vector2 shootVelocity = Projectile.velocity.SafeNormalize(Vector2.UnitY) * BulletSpeed; if (FullyCharged) { - Projectile.NewProjectile(Projectile.GetSource_FromThis(), tipPosition, shootVelocity, ModContent.ProjectileType(), (int)(Projectile.damage * ChargedDamageMult), Projectile.knockBack * ChargedKBMult, Projectile.owner); + Projectile.NewProjectile(Projectile.GetSource_FromThis(), GunTipPosition, shootVelocity, ModContent.ProjectileType(), (int)(Projectile.damage * ChargedDamageMult), Projectile.knockBack * ChargedKBMult, Projectile.owner); for (int i = 0; i <= 10; i++) { - Dust dust = Dust.NewDustPerfect(tipPosition, 162, shootVelocity.RotatedByRandom(MathHelper.ToRadians(20f)) * Main.rand.NextFloat(0.8f, 1.4f), 0, default, Main.rand.NextFloat(1.5f, 2.3f)); + Dust dust = Dust.NewDustPerfect(GunTipPosition, 162, shootVelocity.RotatedByRandom(MathHelper.ToRadians(20f)) * Main.rand.NextFloat(0.8f, 1.4f), 0, default, Main.rand.NextFloat(1.5f, 2.3f)); dust.noGravity = true; } } else - Projectile.NewProjectile(Projectile.GetSource_FromThis(), tipPosition, shootVelocity, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner); + Projectile.NewProjectile(Projectile.GetSource_FromThis(), GunTipPosition, shootVelocity, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner); Projectile.ai[1] = 1f; - Projectile.netSpam = 0; - Projectile.netUpdate = true; } } else { - // While channeled, keep refreshing the projectile lifespan to the amount when attacking - Projectile.timeLeft = OpalStriker.AftershotCooldownFrames; CurrentChargingFrames++; // Sounds @@ -103,14 +82,14 @@ namespace CalamityMod.Projectiles.Ranged { if (!FullyCharged) { - Particle streak = new ManaDrainStreak(Owner, Main.rand.NextFloat(0.06f + (CurrentChargingFrames / 180), 0.08f + (CurrentChargingFrames / 180)), Main.rand.NextVector2CircularEdge(2f, 2f) * Main.rand.NextFloat(0.3f * CurrentChargingFrames, 0.3f * CurrentChargingFrames), 0f, Color.Gold, Color.Orange, 7, tipPosition); + Particle streak = new ManaDrainStreak(Owner, Main.rand.NextFloat(0.06f + (CurrentChargingFrames / 180), 0.08f + (CurrentChargingFrames / 180)), Main.rand.NextVector2CircularEdge(2f, 2f) * Main.rand.NextFloat(0.3f * CurrentChargingFrames, 0.3f * CurrentChargingFrames), 0f, Color.Gold, Color.Orange, 7, GunTipPosition); GeneralParticleHandler.SpawnParticle(streak); } float orbScale = MathHelper.Clamp(CurrentChargingFrames, 0f, OpalStriker.FullChargeFrames); - Particle orb = new GenericBloom(tipPosition, Projectile.velocity, Color.OrangeRed, orbScale / 135f, 2); + Particle orb = new GenericBloom(GunTipPosition, Projectile.velocity, Color.OrangeRed, orbScale / 135f, 2); GeneralParticleHandler.SpawnParticle(orb); - Particle orb2 = new GenericBloom(tipPosition, Projectile.velocity, Color.Coral, orbScale / 200f, 2); + Particle orb2 = new GenericBloom(GunTipPosition, Projectile.velocity, Color.Coral, orbScale / 200f, 2); GeneralParticleHandler.SpawnParticle(orb2); } @@ -119,50 +98,38 @@ namespace CalamityMod.Projectiles.Ranged { for (int i = 0; i < 36; i++) { - Dust chargefull = Dust.NewDustPerfect(tipPosition, 162); + Dust chargefull = Dust.NewDustPerfect(GunTipPosition, 162); chargefull.velocity = (MathHelper.TwoPi * i / 36f).ToRotationVector2() * 13f + Owner.velocity; chargefull.scale = Main.rand.NextFloat(2f, 2.5f); chargefull.noGravity = true; } } } - - UpdateProjectileHeldVariables(armPosition); - ManipulatePlayerVariables(); } - private void UpdateProjectileHeldVariables(Vector2 armPosition) - { - if (Main.myPlayer == Projectile.owner) - { - float interpolant = Utils.GetLerpValue(5f, 35f, Projectile.Distance(Main.MouseWorld), true); - Vector2 oldVelocity = Projectile.velocity; - Projectile.velocity = Vector2.Lerp(Projectile.velocity, Projectile.SafeDirectionTo(Main.MouseWorld), interpolant); - } - Projectile.Center = armPosition + Projectile.velocity * 15 + new Vector2(0, 3); - Projectile.rotation = Projectile.velocity.ToRotation() + (Projectile.spriteDirection == -1 ? MathHelper.Pi : 0f); - Projectile.spriteDirection = Projectile.direction; - - // Rumble (only while channeling) - float rumble = MathHelper.Clamp(CurrentChargingFrames, 0f, OpalStriker.FullChargeFrames); - if (!Owner.CantUseHoldout()) - Projectile.position += Main.rand.NextVector2Circular(rumble / 30f, rumble / 30f); - } - - private void ManipulatePlayerVariables() - { - Owner.ChangeDir(Projectile.direction); - Owner.heldProj = Projectile.whoAmI; - Owner.itemTime = 2; - Owner.itemAnimation = 2; - Owner.itemRotation = (Projectile.velocity * Projectile.direction).ToRotation(); - } public override void OnKill(int timeLeft) { if (SoundEngine.TryGetActiveSound(OpalChargeSlot, out var ChargeSound)) ChargeSound?.Stop(); } - public override bool? CanDamage() => false; + public override bool PreDraw(ref Color lightColor) + { + Texture2D texture = TextureAssets.Projectile[Type].Value; + Vector2 drawPosition = Projectile.Center - Main.screenPosition; + float drawRotation = Projectile.rotation + (Projectile.spriteDirection == -1 ? MathHelper.Pi : 0f); + Vector2 rotationPoint = texture.Size() * 0.5f; + SpriteEffects flipSprite = (Projectile.spriteDirection * Owner.gravDir == -1) ? SpriteEffects.FlipHorizontally : SpriteEffects.None; + + if (!Owner.CantUseHoldout()) + { + float rumble = MathHelper.Clamp(CurrentChargingFrames, 0f, OpalStriker.FullChargeFrames); + drawPosition += Main.rand.NextVector2Circular(rumble / 30f, rumble / 30f); + } + + Main.EntitySpriteDraw(texture, drawPosition, null, Projectile.GetAlpha(lightColor), drawRotation, rotationPoint, Projectile.scale * Owner.gravDir, flipSprite); + + return false; + } } } diff --git a/Projectiles/Summon/HarvestStaffMinion.cs b/Projectiles/Summon/HarvestStaffMinion.cs index c00e7bf69b..c2b19b285f 100644 --- a/Projectiles/Summon/HarvestStaffMinion.cs +++ b/Projectiles/Summon/HarvestStaffMinion.cs @@ -46,8 +46,6 @@ namespace CalamityMod.Projectiles.Summon } else if (value == AIState.Idle) Animation = AnimationState.Idle; - - NetUpdate(); } } @@ -127,8 +125,6 @@ namespace CalamityMod.Projectiles.Summon FramesUntilNextAnimationFrame = 5; break; } - - NetUpdate(); } } @@ -138,9 +134,10 @@ namespace CalamityMod.Projectiles.Summon public int AnimationFrames { get; set; } /// - /// The amount of time, in frames, that it'll take to go to the next frame of animation. + /// The amount of time, in frames, that it'll take to go to the next frame of animation.
+ /// Defaults to 1 so it doesn't divide by 0. ///
- public int FramesUntilNextAnimationFrame { get; set; } + public int FramesUntilNextAnimationFrame { get; set; } = 1; /// /// A convienent bool for when the animation has been completed.
@@ -214,7 +211,7 @@ namespace CalamityMod.Projectiles.Summon } } - public int NetUpdateTimer { get; set; } + public bool KILLYOURSELF { get; set; } #endregion @@ -222,11 +219,11 @@ namespace CalamityMod.Projectiles.Summon public override void AI() { + Owner ??= Main.player[Projectile.owner]; + Projectile.width = Projectile.height = Variant == 0 ? 28 : (Variant == 1 ? 22 : 20); + if (Animation == AnimationState.Grow && (MySentry is null || Projectile.Distance(MySentry.Center) > 600f)) - { Projectile.Kill(); - NetUpdate(); - } Target = Projectile.Center.MinionHoming(State == AIState.Still ? PlantedEnemyDistanceDetection : NormalEnemyDistanceDetection, Owner, false); @@ -246,16 +243,13 @@ namespace CalamityMod.Projectiles.Summon if (IdleJumpCooldown > 0) IdleJumpCooldown--; + if (KILLYOURSELF) + Projectile.Kill(); + Projectile.timeLeft = 2; DoGravity(); DoAnimation(); - - NetUpdateTimer++; - if (NetUpdateTimer > 60) - { - NetUpdateTimer = 0; - NetUpdate(); - } + NetUpdate(); } public override bool OnTileCollide(Vector2 oldVelocity) @@ -300,7 +294,7 @@ namespace CalamityMod.Projectiles.Summon { if (State != AIState.Attack) return; - + Projectile.ExpandHitboxBy(4f); Projectile.Damage(); @@ -312,7 +306,7 @@ namespace CalamityMod.Projectiles.Summon gore.timeLeft = 15; } - NetUpdate(); + KILLYOURSELF = true; if (Main.dedServ) return; @@ -374,7 +368,6 @@ namespace CalamityMod.Projectiles.Summon { IdleWalkingTime = IdleWalkingTimer = Main.rand.Next(60, 180); IdleWalkingDirection = MySentry == null || Projectile.WithinRange(MySentry.Center, 960f) ? (Main.rand.NextBool() ? -1 : 1) : MathF.Sign(MySentry.Center.X - Projectile.Center.X); - NetUpdate(); } else if (IdleWalkingTimer != 0f) @@ -447,8 +440,6 @@ namespace CalamityMod.Projectiles.Summon Animation = AnimationState.Jump; SoundEngine.PlaySound(_jumpSound with { Pitch = Utils.Remap(Variant, 0f, 2f, -0.3f, 0.3f) }, Projectile.Center); - - NetUpdate(); } /// @@ -478,7 +469,6 @@ namespace CalamityMod.Projectiles.Summon Projectile.velocity.Y = -MathF.Sqrt(-2f * PumpkinGravityStrength * (destination.Y - Projectile.Bottom.Y)); Animation = AnimationState.Jump; SoundEngine.PlaySound(_jumpSound with { Pitch = Utils.Remap(Variant, 0f, 2f, -0.3f, 0.3f) }, Projectile.Center); - NetUpdate(); } /// @@ -524,9 +514,10 @@ namespace CalamityMod.Projectiles.Summon return; Projectile.frameCounter++; - if (Projectile.frameCounter % FramesUntilNextAnimationFrame == 0) + if (Projectile.frameCounter >= FramesUntilNextAnimationFrame) { Projectile.frame = Math.Min(Projectile.frame + 1, AnimationFrames - 1); + Projectile.frameCounter = 0; // If it's the run animation, loop it. if (Animation == AnimationState.Run && CompletedAnimation) @@ -539,9 +530,8 @@ namespace CalamityMod.Projectiles.Summon /// public void NetUpdate() { + Projectile.netSpam = 0; Projectile.netUpdate = true; - if (Projectile.netSpam >= 10) - Projectile.netSpam = 9; } #endregion @@ -566,34 +556,36 @@ namespace CalamityMod.Projectiles.Summon public override void SendExtraAI(BinaryWriter writer) { + writer.Write(Direction); writer.Write(IdleWalkingTime); writer.Write(IdleWalkingTimer); writer.Write(IdleJumpCount); writer.Write(IdleJumpCooldown); writer.Write(IdleWalkingDirection); - writer.Write(NetUpdateTimer); + writer.Write(AnimationFrames); + writer.Write(FramesUntilNextAnimationFrame); + writer.Write(KILLYOURSELF); } public override void ReceiveExtraAI(BinaryReader reader) { + Direction = reader.ReadInt32(); IdleWalkingTime = reader.ReadInt32(); IdleWalkingTimer = reader.ReadInt32(); IdleJumpCount = reader.ReadInt32(); IdleJumpCooldown = reader.ReadInt32(); IdleWalkingDirection = reader.ReadInt32(); - NetUpdateTimer = reader.ReadInt32(); + AnimationFrames = reader.ReadInt32(); + FramesUntilNextAnimationFrame = reader.ReadInt32(); + KILLYOURSELF = reader.ReadBoolean(); } public override bool? CanDamage() => State == AIState.Attack ? null : false; - public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) => NetUpdate(); - public override void ModifyHitNPC(NPC target, ref NPC.HitModifiers modifiers) => modifiers.SourceDamage *= Utils.Remap(Variant, 0f, 2f, 1.5f, 0.5f); public override void OnSpawn(IEntitySource source) { - Owner = Main.player[Projectile.owner]; - Projectile.width = Projectile.height = Variant == 0 ? 28 : (Variant == 1 ? 22 : 20); Direction = Main.rand.NextBool() ? -1 : 1; Animation = AnimationState.None; } diff --git a/Projectiles/Typeless/RelicOfDeliveranceSpear.cs b/Projectiles/Typeless/RelicOfDeliveranceSpear.cs index d8d5974075..1c2161af35 100644 --- a/Projectiles/Typeless/RelicOfDeliveranceSpear.cs +++ b/Projectiles/Typeless/RelicOfDeliveranceSpear.cs @@ -176,11 +176,8 @@ namespace CalamityMod.Projectiles.Typeless // Adjust the player's held projectile type. if (player.heldProj == -1) player.heldProj = Projectile.whoAmI; - if (player.mount != null) - { - player.mount.Dismount(player); - } - player.ChangeDir((int)Projectile.velocity.X); + player.mount?.Dismount(player); + player.ChangeDir(Math.Sign(Projectile.velocity.X) <= 0 ? -1 : 1); // Generate dust if (Projectile.ai[0] % DustSpawnInterval == DustSpawnInterval - 1f) { diff --git a/Utilities/PlayerUtils.cs b/Utilities/PlayerUtils.cs index eab0501756..faf8ed2d66 100644 --- a/Utilities/PlayerUtils.cs +++ b/Utilities/PlayerUtils.cs @@ -887,7 +887,7 @@ namespace CalamityMod /// /// The player using the holdout. /// Returns if the player CAN'T use the item. - public static bool CantUseHoldout(this Player player) => player == null || !player.active || player.dead || !player.channel || player.CCed || player.noItems; + public static bool CantUseHoldout(this Player player, bool needsToHold = true) => player == null || !player.active || player.dead || (!player.channel && needsToHold) || player.CCed || player.noItems; /// /// Makes the given player send the given packet to all appropriate receivers.