From 9bfa76cd5d8ec52117a8badba759300e2a52a0cc Mon Sep 17 00:00:00 2001 From: Ozzatron Date: Fri, 24 Feb 2023 21:12:06 -0500 Subject: [PATCH] 1) Completely rewrote everything about ULTRAKILL-style ricoshots under the hood. 2) Crackshot Colt damage 13 -> 18, can throw 4 copper coins, multiplier reduced heavily, ricoshots always crit 3) Midas Prime 52 -> 81, throws coins slightly slower, multipliers reduced heavily, ricoshots always crit 4) CalamityGlobalItem now supports arbitrary grab range multipliers. 5) Slightly reduced ricochet coin grab range but made it always work even if you're not holding Midas Prime. 6) Crackshot Colt and Midas Prime use the same projectiles internally (so Crackshot Colt inflicts Midas now) 7) Improved Marksman Round tooltip to indicate that it works with Crackshot Colt now 8) Added generic damage multiplier and a crit-forcing bool to CalamityGlobalProjectile 9) Moved almost all ricoshot related code to a new RicoshotUtils. 10) Ricoshots search 1000 pixels for other coins, 2000 pixels for enemies and 2800 pixels for DSO bullseyes. --- Enums/RicoshotTargetType.cs | 10 + Items/Accessories/DaawnlightSpiritOrigin.cs | 3 + Items/Ammo/MarksmanRound.cs | 5 +- Items/CalamityGlobalItem.cs | 12 +- Items/Weapons/Ranged/CrackshotColt.cs | 86 ++--- Items/Weapons/Ranged/MidasPrime.cs | 192 ++++-------- Projectiles/CalamityGlobalProjectile.cs | 19 +- Projectiles/Ranged/CrackshotBlast.cs | 132 -------- Projectiles/Ranged/CrackshotCoin.cs | 104 ------- Projectiles/Ranged/CrackshotCoin.png | Bin 1035 -> 0 bytes Projectiles/Ranged/MarksmanShot.cs | 219 +++++++++++++ Projectiles/Ranged/MidasBlast.cs | 327 -------------------- Projectiles/Ranged/MidasCoin.cs | 141 --------- Projectiles/Ranged/MidasCoin.png | Bin 1949 -> 0 bytes Projectiles/Ranged/RicoshotCoin.cs | 289 +++++++++++++++++ Projectiles/Ranged/RicoshotCoin.png | Bin 0 -> 1588 bytes Utilities/ProjectileUtils.cs | 9 +- Utilities/RicoshotUtils.cs | 204 ++++++++++++ 18 files changed, 872 insertions(+), 880 deletions(-) create mode 100644 Enums/RicoshotTargetType.cs delete mode 100644 Projectiles/Ranged/CrackshotBlast.cs delete mode 100644 Projectiles/Ranged/CrackshotCoin.cs delete mode 100644 Projectiles/Ranged/CrackshotCoin.png create mode 100644 Projectiles/Ranged/MarksmanShot.cs delete mode 100644 Projectiles/Ranged/MidasBlast.cs delete mode 100644 Projectiles/Ranged/MidasCoin.cs delete mode 100644 Projectiles/Ranged/MidasCoin.png create mode 100644 Projectiles/Ranged/RicoshotCoin.cs create mode 100644 Projectiles/Ranged/RicoshotCoin.png create mode 100644 Utilities/RicoshotUtils.cs diff --git a/Enums/RicoshotTargetType.cs b/Enums/RicoshotTargetType.cs new file mode 100644 index 0000000000..e5c763204c --- /dev/null +++ b/Enums/RicoshotTargetType.cs @@ -0,0 +1,10 @@ +namespace CalamityMod +{ + public enum RicoshotTargetType : byte + { + None = 0, + Coin = 1, + Bullseye = 2, + NPC = 3 + } +} diff --git a/Items/Accessories/DaawnlightSpiritOrigin.cs b/Items/Accessories/DaawnlightSpiritOrigin.cs index d0213c1ee6..91a387f25f 100644 --- a/Items/Accessories/DaawnlightSpiritOrigin.cs +++ b/Items/Accessories/DaawnlightSpiritOrigin.cs @@ -24,6 +24,9 @@ namespace CalamityMod.Items.Accessories internal const float RegularEnemyBullseyeRadius = 8f; internal const float BossBullseyeRadius = 18f; + // Special search radius for coin ricoshots that only applies to DSO targets. + public static readonly float RicoshotSearchDistance = 2800f; + internal static float GetDamageMultiplier(Player p, CalamityPlayer mp, bool hitBullseye) { float baseCritMult = 2f; // In vanilla Terraria, crits do +100% damage. diff --git a/Items/Ammo/MarksmanRound.cs b/Items/Ammo/MarksmanRound.cs index 8938576984..36227b2c09 100644 --- a/Items/Ammo/MarksmanRound.cs +++ b/Items/Ammo/MarksmanRound.cs @@ -11,7 +11,8 @@ namespace CalamityMod.Items.Ammo { SacrificeTotal = 99; DisplayName.SetDefault("Marksman Round"); - Tooltip.SetDefault("A carefully crafted round which can be ricocheted off of midair coins\nAny gun firing this bullet can perform Ricoshots with coins tossed using Midas Prime"); + Tooltip.SetDefault("A carefully crafted round which can be ricocheted off of midair coins\n" + + "This allows other guns to utilize the coins tossed by Crackshot Colt and Midas Prime"); } public override void SetDefaults() @@ -25,7 +26,7 @@ namespace CalamityMod.Items.Ammo Item.knockBack = 2.25f; Item.value = Item.sellPrice(copper: 10); Item.rare = ItemRarityID.LightRed; - Item.shoot = ModContent.ProjectileType(); + Item.shoot = ModContent.ProjectileType(); Item.shootSpeed = 1f; Item.ammo = AmmoID.Bullet; } diff --git a/Items/CalamityGlobalItem.cs b/Items/CalamityGlobalItem.cs index c748dcb305..26ef6834ff 100644 --- a/Items/CalamityGlobalItem.cs +++ b/Items/CalamityGlobalItem.cs @@ -83,6 +83,7 @@ namespace CalamityMod.Items public bool donorItem = false; public bool devItem = false; public bool canFirePointBlankShots = false; + public float grabRangeMultiplier = 1f; public static readonly Color ExhumedTooltipColor = new Color(198, 27, 64); @@ -123,6 +124,7 @@ namespace CalamityMod.Items myClone.donorItem = donorItem; myClone.devItem = devItem; myClone.canFirePointBlankShots = canFirePointBlankShots; + myClone.grabRangeMultiplier = grabRangeMultiplier; return myClone; } @@ -1524,11 +1526,13 @@ namespace CalamityMod.Items #region GrabChanges public override void GrabRange(Item item, Player player, ref int grabRange) { - CalamityPlayer modPlayer = player.Calamity(); - int itemGrabRangeBoost = 0 + - (modPlayer.reaverExplore ? 20 : 0); + // First, apply the grab range multiplier. + if (grabRangeMultiplier > 1f) + grabRange = (int)(grabRangeMultiplier * grabRange); - grabRange += itemGrabRangeBoost; + // Then, if wearing the appropriate Reaver armor, add 20 flat item grab range. + if (player.Calamity().reaverExplore) + grabRange += 20; } #endregion diff --git a/Items/Weapons/Ranged/CrackshotColt.cs b/Items/Weapons/Ranged/CrackshotColt.cs index 21c33ff01c..32a1fd746e 100644 --- a/Items/Weapons/Ranged/CrackshotColt.cs +++ b/Items/Weapons/Ranged/CrackshotColt.cs @@ -1,35 +1,32 @@ using System; using CalamityMod.Items.Materials; +using CalamityMod.Projectiles.Ranged; using Microsoft.Xna.Framework; using Terraria; using Terraria.Audio; using Terraria.ID; using Terraria.ModLoader; -using CalamityMod.Projectiles.Ranged; namespace CalamityMod.Items.Weapons.Ranged { public class CrackshotColt : ModItem { - public static readonly SoundStyle ShootSound = new("CalamityMod/Sounds/Item/CrackshotColtShot") { PitchVariance = 0.1f }; - - public static readonly SoundStyle BlingSound = new("CalamityMod/Sounds/Custom/Ultrabling") { PitchVariance = 0.5f }; - public static readonly SoundStyle BlingHitSound = new("CalamityMod/Sounds/Custom/UltrablingHit") { PitchVariance = 0.5f }; - - public static float MaxDownwardsAngle4Coin = MathHelper.PiOver4; - public static float RicochetDamageMult = 2.5f; + // Crackshot Colt uses the same sound as Midas Prime, just quieter. + private static SoundStyle ShootSound => MidasPrime.ShootSound with { Volume = 0.6f }; public override void SetStaticDefaults() { DisplayName.SetDefault("Crackshot Colt"); - Tooltip.SetDefault("Right click to throw a coin in the air. Hitting the coin with a bullet redirects the shot into the nearest enemy\n" + - "Coin throws consume copper coins"); + Tooltip.SetDefault("Right click to toss a Copper Coin in the air\n" + + "Striking a coin with a bullet causes it to ricochet into the nearest enemy\n" + + "Up to 4 coins can be tossed simultaneously, and shots will ricochet off multiple coins if possible\n" + + "Ricocheted bullets always critically strike and do bonus damage based on the coins used"); SacrificeTotal = 1; } public override void SetDefaults() { - Item.damage = 13; + Item.damage = 18; Item.DamageType = DamageClass.Ranged; Item.width = 23; Item.height = 8; @@ -40,73 +37,90 @@ namespace CalamityMod.Items.Weapons.Ranged Item.knockBack = 2.25f; Item.value = CalamityGlobalItem.Rarity1BuyPrice; Item.rare = ItemRarityID.Blue; - Item.UseSound = ShootSound with { Volume = 0.6f}; + Item.UseSound = ShootSound; Item.autoReuse = true; - Item.shoot = ModContent.ProjectileType(); + Item.shoot = ModContent.ProjectileType(); Item.useAmmo = AmmoID.Bullet; Item.shootSpeed = 14f; Item.Calamity().canFirePointBlankShots = true; } + // This item has a right click. public override bool AltFunctionUse(Player player) => true; + + // This item enables the automatic syncing of player mouse coordinates while held. public override void HoldItem(Player player) => player.Calamity().mouseWorldListener = true; + + // This item never uses ammo when right clicking. public override bool CanConsumeAmmo(Item ammo, Player player) => player.altFunctionUse != 2; public override bool CanUseItem(Player player) { + // Two things are checked for right click: + // 1) The player has at least 1 copper coin to toss + // 2) The player doesn't have 4 ricoshot coins (of any type) in the air already if (player.altFunctionUse == 2) - return player.CanBuyItem(1); //Breaks if the player has > 999 plat. Ask tml people to fix that? + { + // player.CanBuyItem() breaks if the player has more than 2,147 platinum coins and was never fixed + // This alternative method works no matter how much money the player has + long cashAvailable = Utils.CoinsCount(out bool overflow, player.inventory); + if (cashAvailable < 1 && !overflow) + return false; + + return player.GetActiveRicoshotCoinCount() < 4; + } return true; } public override bool? UseItem(Player player) { + // Remove 1 copper from the player's inventory when using right click if (player.altFunctionUse == 2) - { player.BuyItem(1); - } return base.UseItem(player); } + // This hook is a convenient location to change the use sound. public override void UseAnimation(Player player) { - Item.UseSound = ShootSound with { Volume = 0.6f}; + Item.UseSound = ShootSound; if (player.altFunctionUse == 2) - Item.UseSound = BlingSound; + Item.UseSound = RicoshotCoin.BlingSound; } + // Coins can be tossed much faster than bullets can be fired. public override float UseSpeedMultiplier(Player player) { if (player.altFunctionUse == 2) - return 1.3f; + return 3f; return 1f; } public override void ModifyShootStats(Player player, ref Vector2 position, ref Vector2 velocity, ref int type, ref int damage, ref float knockback) { + // Move all fired projectiles 12 pixels upwards so they don't come out of the player's groin + position -= Vector2.UnitY * 12f; - //Override every projectile - type = ModContent.ProjectileType(); + // No matter what type of ammo is used, left click will fire a Marksman Round + type = ModContent.ProjectileType(); + // Right clicks toss coins instead if (player.altFunctionUse == 2) { damage = 0; - type = ModContent.ProjectileType() ; - - //Ok the velocity is flipped because the in world coordinates have 0 at the top, so to do the typical trigo stuff we flip it, you get me. - float shootAngle = (player.Calamity().mouseWorld - player.MountedCenter).ToRotation() * -1; - - if (shootAngle > -MathHelper.Pi + MaxDownwardsAngle4Coin && shootAngle < -MathHelper.PiOver2) - shootAngle = -MathHelper.Pi + MaxDownwardsAngle4Coin; - - else if (shootAngle < -MaxDownwardsAngle4Coin && shootAngle >= -MathHelper.PiOver2) - shootAngle = -MaxDownwardsAngle4Coin; - - velocity = (shootAngle * -1).ToRotationVector2() * 1.3f - Vector2.UnitY * 1.12f + player.velocity / 4f; + type = ModContent.ProjectileType(); + velocity = player.GetCoinTossVelocity(); } } + // + // Crackshot Colt has no Shoot override because it can only toss copper coins. + // Copper coins have ai[0] = 0f, so no override is needed. + // + + // Make the gun have visible recoil when fired for extra cool factor. + #region Firing Animation public override void UseStyle(Player player, Rectangle heldItemFrame) { player.direction = Math.Sign((player.Calamity().mouseWorld - player.Center).X); @@ -132,13 +146,15 @@ namespace CalamityMod.Items.Weapons.Ranged player.SetCompositeArmFront(true, Player.CompositeArmStretchAmount.Full, rotation); } + #endregion public override void AddRecipes() { CreateRecipe(). + AddRecipeGroup("AnyGoldBar", 8). AddIngredient(ModContent.ItemType()). - AddRecipeGroup("AnyGoldBar", 3). - AddIngredient(ItemID.CopperCoin, 5). + AddIngredient(ModContent.ItemType()). + AddIngredient(ItemID.CopperCoin, 4). AddTile(TileID.Anvils). Register(); } diff --git a/Items/Weapons/Ranged/MidasPrime.cs b/Items/Weapons/Ranged/MidasPrime.cs index c80412aef5..12373598ad 100644 --- a/Items/Weapons/Ranged/MidasPrime.cs +++ b/Items/Weapons/Ranged/MidasPrime.cs @@ -1,45 +1,35 @@ using System; -using System.IO; -using CalamityMod.Items.Materials; +using System.Collections.Generic; +using CalamityMod.Projectiles.Ranged; 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.ModLoader; -using Terraria.ModLoader.IO; -using static CalamityMod.CalamityUtils; -using CalamityMod.Projectiles.Ranged; -using System.Collections.Generic; -using static Microsoft.Xna.Framework.Input.Keys; namespace CalamityMod.Items.Weapons.Ranged { public class MidasPrime : ModItem { - public static float MaxDownwardsAngle4Coin = MathHelper.PiOver4; + internal static readonly SoundStyle ShootSound = new("CalamityMod/Sounds/Item/CrackshotColtShot") { PitchVariance = 0.1f }; - public static int ShotCoin = 0; - public static float SilverRicochetDamageMult = 1.5f; - public static float GoldRicochetDamageMult = 1.75f; - public static int RipeningTime = 100; + // Internal storage used to keep track between UseItem and Shoot hooks whether a gold coin was queued up + private bool nextShotGoldCoin = false; public override void SetStaticDefaults() { DisplayName.SetDefault("Midas Prime"); - Tooltip.SetDefault("Struck enemies drop extra coins\n" + - "Right click to throw a coin in the air. Hitting the coin with a bullet redirects the shot into the nearest enemy\n" + - "If you have multiple coins up in the air, bullets will first redirect towards other coins up to a maximum of 4\n" + - "Coin ricochets will increase the damage of the bullet, provided the coins have been in the air for long enough\n" + - "Coin throws consume gold and silver coins"); + Tooltip.SetDefault("Right click to coss a Gold Coin or Silver Coin in the air\n" + + "Striking a coin with a bullet causes it to ricochet into the nearest enemy\n" + + "Up to 4 coins can be tossed simultaneously, and shots will ricochet off multiple coins if possible\n" + + "Ricocheted bullets always critically strike and do bonus damage based on the coins used"); SacrificeTotal = 1; } public override void SetDefaults() { - Item.damage = 52; + Item.damage = 81; Item.DamageType = DamageClass.Ranged; Item.width = 23; Item.height = 8; @@ -50,155 +40,126 @@ namespace CalamityMod.Items.Weapons.Ranged Item.knockBack = 2.25f; Item.value = CalamityGlobalItem.Rarity5BuyPrice; Item.rare = ItemRarityID.Pink; - Item.UseSound = CrackshotColt.ShootSound; + Item.UseSound = ShootSound; Item.autoReuse = true; - Item.shoot = ModContent.ProjectileType(); + Item.shoot = ModContent.ProjectileType(); Item.useAmmo = AmmoID.Bullet; Item.shootSpeed = 14f; Item.Calamity().canFirePointBlankShots = true; } + // This item has a right click. public override bool AltFunctionUse(Player player) => true; + + // This item enables the automatic syncing of player mouse coordinates while held. public override void HoldItem(Player player) => player.Calamity().mouseWorldListener = true; - - public override bool CanConsumeAmmo(Item ammo, Player player) => player.altFunctionUse == 2 ? false : true; + + // This item never uses ammo when right clicking. + public override bool CanConsumeAmmo(Item ammo, Player player) => player.altFunctionUse != 2; public override bool CanUseItem(Player player) { + // Two things are checked for right click: + // 1) The player has at least 1 silver coin to toss + // 2) The player doesn't have 4 ricoshot coins (of any type) in the air already if (player.altFunctionUse == 2) { - //Using player.CanBuyItem() breaks if the player has too many platinum coins - long coinCount = Utils.CoinsCount(out bool overflow, player.inventory); - return overflow || coinCount >= 100; + // player.CanBuyItem() breaks if the player has more than 2,147 platinum coins and was never fixed + // This alternative method works no matter how much money the player has + long cashAvailable = Utils.CoinsCount(out bool overflow, player.inventory); + if (cashAvailable < 100 && !overflow) + return false; + + return player.GetActiveRicoshotCoinCount() < 4; } return true; } public override bool? UseItem(Player player) { + // Remove either 1 gold (if possible) or 1 silver (otherwise) when using right click if (player.altFunctionUse == 2) { - long coinCount = Utils.CoinsCount(out bool overflow, player.inventory); + long cashAvailable = Utils.CoinsCount(out bool overflow, player.inventory); - if (overflow || coinCount > 10000) + // If the player has at least 1 gold in their inventory, spend it and use a gold coin + if (overflow || cashAvailable > 10000) { player.BuyItem(10000); - ShotCoin = 1; + nextShotGoldCoin = true; } + // Otherwise, spend 1 silver and use a silver coin else { player.BuyItem(100); - ShotCoin = 0; + nextShotGoldCoin = false; } - - //Clear prev coins - int ownedCoins = 0; - int oldestCoinIndex = -1; - int oldestCoinTime = 10000; - for (int i = 0; i < Main.maxProjectiles; i++) - { - Projectile proj = Main.projectile[i]; - - if (proj.active && proj.owner == player.whoAmI && proj.type == ModContent.ProjectileType()) - { - ownedCoins++; - if (proj.timeLeft < oldestCoinTime) - { - oldestCoinIndex = proj.whoAmI; - oldestCoinTime = proj.timeLeft; - } - } - } - - if (ownedCoins >= 4) - Main.projectile[oldestCoinIndex].Kill(); - } return base.UseItem(player); } + // This hook is a convenient location to change the use sound. public override void UseAnimation(Player player) { - Item.UseSound = CrackshotColt.ShootSound; + Item.UseSound = ShootSound; if (player.altFunctionUse == 2) - Item.UseSound = CrackshotColt.BlingSound; + Item.UseSound = RicoshotCoin.BlingSound; } + // Coins can be tossed much faster than bullets can be fired. public override float UseSpeedMultiplier(Player player) { if (player.altFunctionUse == 2) - return 5f; + return 3f; return 1f; } public override void ModifyShootStats(Player player, ref Vector2 position, ref Vector2 velocity, ref int type, ref int damage, ref float knockback) { - position -= Vector2.UnitY * 13f; + // Move all fired projectiles 15 pixels upwards so they don't come out of the player's groin + position -= Vector2.UnitY * 15f; - //Override every projectile - type = ModContent.ProjectileType(); + // No matter what type of ammo is used, left click will fire a Marksman Round + type = ModContent.ProjectileType(); + // Right clicks toss coins instead if (player.altFunctionUse == 2) { damage = 0; - type = ModContent.ProjectileType(); - - //Ok the velocity is flipped because the in world coordinates have 0 at the top, so to do the typical trigo stuff we flip it, you get me. - float shootAngle = (player.Calamity().mouseWorld - player.MountedCenter).ToRotation() * -1; - - if (shootAngle > -MathHelper.Pi + MaxDownwardsAngle4Coin && shootAngle < -MathHelper.PiOver2) - shootAngle = -MathHelper.Pi + MaxDownwardsAngle4Coin; - - else if (shootAngle < -MaxDownwardsAngle4Coin && shootAngle >= -MathHelper.PiOver2) - shootAngle = -MaxDownwardsAngle4Coin; - - velocity = (shootAngle * -1).ToRotationVector2() * 1.3f - Vector2.UnitY * 1.12f + player.velocity / 4f; + type = ModContent.ProjectileType(); + velocity = player.GetCoinTossVelocity(); } } + // This shoot override is only needed to set ai[0] to be either 1f or 2f for silver and gold coins. public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) { if (player.altFunctionUse == 2) { - Projectile.NewProjectile(source, position, velocity, type, damage, knockback, player.whoAmI, ShotCoin); + float coinAIVariable = nextShotGoldCoin ? 2f : 1f; + Projectile.NewProjectile(source, position, velocity, type, damage, knockback, player.whoAmI, coinAIVariable); return false; } + // Otherwise use default behavior (which is just to return true). return base.Shoot(player, source, position, velocity, type, damage, knockback); } - + #region Hidden ULTRAKILL Reference Tooltip public override void ModifyTooltips(List tooltips) { - if (Main.keyState.IsKeyDown(LeftShift)) - { - int tooltipIndex = -1; - int tooltipCount = 0; - - for (int i = 0; i < tooltips.Count; i++) - { - if (tooltips[i].Name.StartsWith("Tooltip")) - { - if (tooltipIndex == -1) - tooltipIndex = i; - - tooltipCount++; - } - } - - if (tooltipIndex != -1) - { - tooltips.RemoveRange(tooltipIndex, tooltipCount); - - TooltipLine bloodIsFuel = new TooltipLine(Mod, "CalamityMod:HiddenTooltip", "MANKIND IS DEAD.\nBLOOD IS FUEL.\nHELL IS FULL."); - bloodIsFuel.OverrideColor = Color.Red; - tooltips.Insert(tooltipIndex, bloodIsFuel); - } - } + TooltipLine ultrakillIntro = new TooltipLine(Mod, + "CalamityMod:UltrakillIntroReference", + "MANKIND IS DEAD.\nBLOOD IS FUEL.\nHELL IS FULL.") + { OverrideColor = Color.Red }; + CalamityUtils.HoldShiftTooltip(tooltips, new TooltipLine[] { ultrakillIntro }); } + #endregion + // Make the gun have visible recoil when fired for extra cool factor. + #region Firing Animation public override void UseStyle(Player player, Rectangle heldItemFrame) { player.direction = Math.Sign((player.Calamity().mouseWorld - player.Center).X); @@ -207,7 +168,9 @@ namespace CalamityMod.Items.Weapons.Ranged Vector2 itemPosition = player.MountedCenter + itemRotation.ToRotationVector2() * 7f; Vector2 itemSize = new Vector2(50, 24); Vector2 itemOrigin = new Vector2(-17, 3); + CalamityUtils.CleanHoldStyle(player, itemRotation, itemPosition, itemSize, itemOrigin); + base.UseStyle(player, heldItemFrame); } @@ -222,35 +185,6 @@ namespace CalamityMod.Items.Weapons.Ranged player.SetCompositeArmFront(true, Player.CompositeArmStretchAmount.Full, rotation); } + #endregion } - - public class MidasPrimeItem : GlobalItem - { - public override bool InstancePerEntity => true; - public bool magnetMode = false; - - public override void GrabRange(Item item, Player player, ref int grabRange) - { - if (player.HeldItem.type == ModContent.ItemType() && magnetMode && item.timeSinceItemSpawned > 60) - grabRange *= 8; - } - - public override bool GrabStyle(Item item, Player player) - { - if (player.HeldItem.type == ModContent.ItemType() && magnetMode && item.timeSinceItemSpawned > 60) - { - //This is just Player.PullItemPickup() but not private - - Vector2 towardsPlayer = player.Center - item.Center; - float movementSpeed = towardsPlayer.Length(); - movementSpeed = 12 / movementSpeed; - towardsPlayer *= movementSpeed; - item.velocity = (item.velocity * 4f + towardsPlayer) / 5f; - return true; - } - - return false; - } - } - } diff --git a/Projectiles/CalamityGlobalProjectile.cs b/Projectiles/CalamityGlobalProjectile.cs index 9e360b7cb5..560fd397c6 100644 --- a/Projectiles/CalamityGlobalProjectile.cs +++ b/Projectiles/CalamityGlobalProjectile.cs @@ -57,9 +57,16 @@ namespace CalamityMod.Projectiles // They then take the remainder (e.g. the remaining 16%) and roll against that for a final +100% (like normal crits). // For example if you have 716% critical strike chance, you are guaranteed +700% damage and then have a 16% chance for +800% damage instead. // These are currently only enabled for Soma Prime, but any bullet fired from that gun can supercrit. - //Set this to -1 if you want the projectile to supercrit forever, and to any positive value to make it supercrit only x times + // Set this to -1 if you want the projectile to supercrit forever, and to any positive value to make it supercrit only x times public int supercritHits = 0; + // Without adjusting underlying crit calculations, set this to true to force a projectile as a crit. + // TODO -- In the TML 1.4.4 port, there is a much better way to set NPC strike events to be forced crits. + public bool forcedCrit = false; + + // The total bonus damage (as a ratio of the projectile's own damage) applied to this projectile as a result of a ricoshot combo. + public float totalRicoshotDamageBonus = 0f; + // If true, this projectile can apply the infinitely-stacking Shred debuff iconic to Soma Prime. public bool appliesSomaShred = false; @@ -2014,7 +2021,7 @@ namespace CalamityMod.Projectiles { if (modPlayer.deadshotBrooch && projectile.CountsAsClass() && player.heldProj != projectile.whoAmI) { - if (projectile.type != ProjectileType()) + if (projectile.type != ProjectileType()) projectile.extraUpdates += 1; } @@ -2441,6 +2448,10 @@ namespace CalamityMod.Projectiles float calamityVelocityDamageMultiplier = 100f * (1f - (1f / (1f + baseVelocityDamageMultiplier))); damageScale = calamityVelocityDamageMultiplier; } + + // If applicable, use ricoshot bonus damage. + if (totalRicoshotDamageBonus > 0f) + damageScale += totalRicoshotDamageBonus; } #endregion @@ -2450,6 +2461,10 @@ namespace CalamityMod.Projectiles Player player = Main.player[projectile.owner]; CalamityPlayer modPlayer = player.Calamity(); + // If this projectile is forced to crit, simply set the crit bool. + if (forcedCrit) + crit = true; + if (modPlayer.rottenDogTooth && projectile.Calamity().stealthStrike) target.AddBuff(BuffType(), RottenDogtooth.ArmorCrunchDebuffTime); diff --git a/Projectiles/Ranged/CrackshotBlast.cs b/Projectiles/Ranged/CrackshotBlast.cs deleted file mode 100644 index 811767179f..0000000000 --- a/Projectiles/Ranged/CrackshotBlast.cs +++ /dev/null @@ -1,132 +0,0 @@ -using System; -using CalamityMod.Items.Weapons.Ranged; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using Terraria; -using Terraria.Audio; -using Terraria.Graphics.Shaders; -using Terraria.ID; -using Terraria.ModLoader; -using static Terraria.ModLoader.ModContent; - -namespace CalamityMod.Projectiles.Ranged -{ - public class CrackshotBlast : ModProjectile - { - internal PrimitiveTrail TrailDrawer; - - public ref float Boosted => ref Projectile.ai[0]; - public ref float DieSoon => ref Projectile.ai[1]; - - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Crack Shot"); - ProjectileID.Sets.TrailCacheLength[Projectile.type] = TrailLenght; - ProjectileID.Sets.TrailingMode[Projectile.type] = 0; - ProjectileID.Sets.DrawScreenCheckFluff[Projectile.type] = 4000; - } - - public static int Lifetime = 600; - public static int TrailLenght = 35; - - public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; - - public override void SetDefaults() - { - Projectile.width = 16; - Projectile.height = 16; - Projectile.DamageType = DamageClass.Ranged; - Projectile.friendly = true; - Projectile.penetrate = -1; - Projectile.timeLeft = Lifetime; - Projectile.extraUpdates = 7; - Projectile.alpha = 255; - } - - public override bool? CanDamage() => Projectile.numHits == 0; - - public override void AI() - { - Lighting.AddLight(Projectile.Center, (Color.Gold * 0.8f).ToVector3() * 0.5f); - - if (Boosted == 0) - { - //Check for coins - for (int i = 0; i < Main.maxProjectiles; i++) - { - Projectile proj = Main.projectile[i]; - if (proj.ModProjectile != null && proj.type == ModContent.ProjectileType() && proj.active) - { - if (Collision.CheckAABBvAABBCollision(proj.Hitbox.TopLeft(), proj.Hitbox.Size(), Projectile.Hitbox.TopLeft(), Projectile.Hitbox.Size())) - { - NPC target = Projectile.Center.ClosestNPCAt(900, false, true); - if (target != null) - { - Projectile.velocity = (Projectile.DirectionTo(target.Center) * 16f); - Boosted = 1; - Main.player[Projectile.owner].Calamity().GeneralScreenShakePower = 2; - Projectile.damage = (int)(Projectile.damage * CrackshotColt.RicochetDamageMult); - } - - proj.active = false; - if (proj.owner == Main.myPlayer) - { - int coin = Item.NewItem(proj.GetSource_DropAsItem(), proj.Center, Vector2.One, ItemID.CopperCoin, noBroadcast: false); - - if (Main.netMode == NetmodeID.MultiplayerClient) - NetMessage.SendData(MessageID.SyncItem, -1, -1, null, coin, 1f); - } - - SoundEngine.PlaySound(CrackshotColt.BlingHitSound, proj.Center); - return; - } - } - } - } - - if (DieSoon == 1) - Projectile.velocity = Vector2.Zero; - - } - - public override bool OnTileCollide(Vector2 oldVelocity) - { - //sfx - Projectile.velocity = Vector2.Zero; - Collision.HitTiles(Projectile.position, Projectile.velocity, Projectile.width, Projectile.height); - DieSoon = 1f; - Projectile.timeLeft = Math.Min((Lifetime - Projectile.timeLeft), TrailLenght); - return false; - } - - public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) - { - //sfx - DieSoon = 1f; - Projectile.timeLeft = Math.Min((Lifetime - Projectile.timeLeft), TrailLenght); - } - - internal Color ColorFunction(float completionRatio) - { - float fadeOpacity = Math.Min(Projectile.timeLeft / (float)TrailLenght, 1f); - return Color.PaleGoldenrod * fadeOpacity; - } - - internal float WidthFunction(float completionRatio) - { - float width = Math.Min(Projectile.timeLeft / (float)TrailLenght, 1f); - return (1 - completionRatio) * 6.4f * width; - } - - public override bool PreDraw(ref Color lightColor) - { - if (TrailDrawer is null) - TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, PrimitiveTrail.RigidPointRetreivalFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]); - - GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(Request("CalamityMod/ExtraTextures/Trails/BasicTrail")); - TrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition, TrailLenght); - - return false; - } - } -} diff --git a/Projectiles/Ranged/CrackshotCoin.cs b/Projectiles/Ranged/CrackshotCoin.cs deleted file mode 100644 index b70035513a..0000000000 --- a/Projectiles/Ranged/CrackshotCoin.cs +++ /dev/null @@ -1,104 +0,0 @@ -using System; -using CalamityMod.Items.Weapons.Melee; -using CalamityMod.Items.Weapons.Rogue; -using CalamityMod.Sounds; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using ReLogic.Content; -using Terraria; -using Terraria.Audio; -using Terraria.Graphics.Effects; -using Terraria.Graphics.Shaders; -using Terraria.ID; -using Terraria.ModLoader; -using static Terraria.ModLoader.ModContent; - -namespace CalamityMod.Projectiles.Ranged -{ - public class CrackshotCoin : ModProjectile - { - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Coin"); - ProjectileID.Sets.TrailCacheLength[Projectile.type] = 60; - ProjectileID.Sets.TrailingMode[Projectile.type] = 0; - Main.projFrames[Projectile.type] = 8; - } - - public static int Lifetime = 950; - public float LifetimeCompletion => MathHelper.Clamp((Lifetime - Projectile.timeLeft) / (float)Lifetime, 0f, 1f); - public float FadePercent => Math.Clamp(Projectile.timeLeft / FadeTime, 0f, 1f); - public static float FadeTime => 30f; - public Player Owner => Main.player[Projectile.owner]; - - public override void SetDefaults() - { - Projectile.width = 22; - Projectile.height = 22; - Projectile.friendly = true; - Projectile.penetrate = -1; - Projectile.DamageType = DamageClass.Ranged; - - Projectile.timeLeft = Lifetime; - Projectile.extraUpdates = 3; - Projectile.usesLocalNPCImmunity = true; - Projectile.localNPCHitCooldown = 1; - Projectile.scale = 1.1f; - } - - public override void AI() - { - Projectile.frameCounter++; - if (Projectile.frameCounter > 8) - { - Projectile.frame++; - Projectile.frameCounter = 0; - } - if (Projectile.frame >= Main.projFrames[Projectile.type]) - { - Projectile.frame = 0; - } - - Lighting.AddLight(Projectile.Center, Color.Goldenrod.ToVector3() * 0.2f); - - - Projectile.rotation = Projectile.velocity.X * 0.5f; - Projectile.velocity *= 0.998f; - - if (Projectile.timeLeft < Lifetime - 100) - Projectile.velocity.Y += 0.01f; - - if (Projectile.Center.Distance(Owner.MountedCenter) > 1300 && Projectile.timeLeft > FadeTime) - Projectile.timeLeft = (int)FadeTime; - - if (Main.rand.NextBool(10)) - { - int schyste = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, 246); - Main.dust[schyste].noGravity = true; - } - } - - public override bool OnTileCollide(Vector2 oldVelocity) - { - Collision.HitTiles(Projectile.position, Projectile.velocity, Projectile.width, Projectile.height); - - return base.OnTileCollide(oldVelocity); - } - - public override bool PreDraw(ref Color lightColor) - { - Texture2D tex = ModContent.Request(Texture).Value; - Rectangle frame = new Rectangle(0, Projectile.frame * tex.Height / Main.projFrames[Projectile.type], tex.Width, tex.Height / Main.projFrames[Projectile.type]); - - Main.EntitySpriteDraw(tex, Projectile.Center - Main.screenPosition, frame, Projectile.GetAlpha(lightColor) * FadePercent, Projectile.rotation, frame.Size() / 2f, Projectile.scale, SpriteEffects.None, 0); - - return false; - } - - public override void Kill(int timeLeft) - { - if (Projectile.owner == Main.myPlayer && Main.rand.NextBool(4)) - Item.NewItem(Projectile.GetSource_DropAsItem(), Projectile.Center, Vector2.One, ItemID.CopperCoin); - } - } -} diff --git a/Projectiles/Ranged/CrackshotCoin.png b/Projectiles/Ranged/CrackshotCoin.png deleted file mode 100644 index 38bbfa904cdf86f360d0b2200604d01da7d48124..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1035 zcmV+m1oZofP)Px&#Ysd#R9J=8m`!Xm3zw^v%U1wUcd!X9hRpZ}ZNb6l^&S8_;>PtEHf-D< zy*p!LibwLhbYlBT03HTj+x*ZScmzPhr8WS(?$MflkXWj!T5Mwy$jZ-yAJAivn|j|^ z0Qv`P1bi7#*Ou~FG-J7>7;|FaIX8Pfm45F3shI0VG}K-9z948!Wdougvu?faja z400n(iJ+|q%Z3Hs$p8eqzo*s)%MY^h@m)RuI(i-h(Cp8NGNwuok`E+m9eX;V;u66* zgX~WF7$o!fykh`p?{Uar#ZvAB^&n#ArAZHx9}?kw+khT}l^;AFrHB5|N1F}PrxzFi zQzm`XWGI@Z-g)$VFsg^uwh5R0_e_BNS@Tm|FA1b>I(A#vhWH0Vs~Cx1k3$CeR#{P) zH?Bw7;*nFIV-H`hgg1A*ZBUSEvP#7kaCw6gK|ZYOGT|HPNG+k z=Q1=IX;ZZF-nDN@+URm0OB5`JuAJ0BHEurO6;SpWnPN0ghFxdP!pGUnicu)2YW` z>7ioPd?1!h1#>+`20-zg8JY~GW#s@odEhr8cCI0~aQ&_cFmsAaQxEOW0=AXo|9HE% zs6U}7PhW8orHSe#frbrH&8Dwj8tHlKiUni-)$`W$;}=*KkW&%trY8UZ002ovPDHLk FV1j9Z^wIzT diff --git a/Projectiles/Ranged/MarksmanShot.cs b/Projectiles/Ranged/MarksmanShot.cs new file mode 100644 index 0000000000..10766ea0a9 --- /dev/null +++ b/Projectiles/Ranged/MarksmanShot.cs @@ -0,0 +1,219 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using CalamityMod.Systems; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.Audio; +using Terraria.Graphics.Shaders; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Ranged +{ + public class MarksmanShot : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + private static readonly int trailLength = 35; + private PrimitiveTrail trailDrawer; + internal List trailPositions; + + // Lifetime of a bullet. Defined in terms of updates because Terraria's engine is trash. + internal static readonly int UpdateCount = 8; + internal static readonly int Lifetime = UpdateCount * CalamityUtils.SecondsToFrames(2); + + // Number of ricochets this coin has performed. This is tracked to enforce ricochet caps (if enabled). + internal ref float NumRicochets => ref Projectile.ai[0]; + public static readonly int RicochetCap = 999; // 4 + + // A counter for how long the shot remains frozen in place when ricocheting off a coin. + internal ref float RicochetFreezeTimer => ref Projectile.ai[1]; + // The default length of the above freeze timer. + internal static int RicochetPause = UpdateCount * 3; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Marksman Shot"); + ProjectileID.Sets.DrawScreenCheckFluff[Projectile.type] = 4000; + } + + public override void SetDefaults() + { + Projectile.width = 16; + Projectile.height = 16; + Projectile.DamageType = DamageClass.Ranged; + Projectile.friendly = true; + Projectile.penetrate = -1; + Projectile.timeLeft = Lifetime; + Projectile.MaxUpdates = UpdateCount; + Projectile.alpha = 255; + } + + // Marksman Shots are not immediately deleted on collision (due to their trail streak) and are not allowed to deal damage more than once. + public override bool? CanDamage() => Projectile.numHits == 0 ? null : false; + + // Bullets stop moving when ricocheting for a certain number of frames. + public override bool ShouldUpdatePosition() => RicochetFreezeTimer <= 0; + + public override void AI() + { + Lighting.AddLight(Projectile.Center, (Color.Gold * 0.8f).ToVector3() * 0.5f); + + // Do not update the custom old position array if the shot is not currently moving. + if (ShouldUpdatePosition()) + { + // If the trail positions array isn't initialized yet, set everything equal to the projectile's current center + if (trailPositions == null) + { + trailPositions = new List(trailLength); + for (int i = 0; i < trailLength; ++i) + trailPositions.Add(Projectile.Center); + } + + // Insert the projectile's current center + trailPositions.Insert(0, Projectile.Center); + + // Trim excess old position data + while (trailPositions.Count > trailLength) + trailPositions.RemoveAt(trailPositions.Count - 1); + } + + // If the shot is currently not moving due to being frozen from a ricochet, decrement that timer. + if (RicochetFreezeTimer > 0f) + --RicochetFreezeTimer; + + // Otherwise, if the ricochet cap has not been reached, check for collisions with any coins that have not been struck. + else if (NumRicochets < RicochetCap) + { + Projectile[] validCoins = Projectile.GetAvailableCoins(); + Projectile struckCoin = null; + + // Check for collisions with valid coins + for (int i = 0; i < validCoins.Length; ++i) + { + Projectile coin = validCoins[i]; + bool hitThisCoin = Collision.CheckAABBvAABBCollision( + coin.Hitbox.TopLeft(), coin.Hitbox.Size(), Projectile.Hitbox.TopLeft(), Projectile.Hitbox.Size() + ); + if (hitThisCoin) + { + struckCoin = coin; + break; + } + } + + // If a coin was struck, set up the potential multi-ricoshot. + if (struckCoin is not null) + { + // Assemble an array of the remaining coins. + Projectile[] otherCoins = validCoins.Where((proj) => proj.whoAmI != struckCoin.whoAmI).ToArray(); + + // Ricochet off of this coin to the next target. + // This coin (and potential further coins) may have already been recursively frozen. + // As long as those coins have not yet been struck, they are valid targets. + RicoshotTarget nextTarget = Projectile.FindRicochetTarget(Projectile.Center, otherCoins, true); + RicochetOffCoin(nextTarget, struckCoin); + + // If the next target is another coin, freeze it to (almost) guarantee it will be hit. + if (nextTarget.type == RicoshotTargetType.Coin) + { + Projectile nextCoin = Main.projectile[nextTarget.entityID]; + nextCoin.ai[1] = RicoshotCoin.RicochetPause; + } + } + } + } + + public void RicochetOffCoin(RicoshotTarget target, Projectile struckCoin) + { + // Mechanically perform the ricochet (redirect towards the given target) + float speed = Projectile.velocity.Length(); + Projectile.velocity = Projectile.DirectionTo(target.pos) * speed; + + // Force the projectile as a crit. This is done without editing underlying crit chance. + CalamityGlobalProjectile cgp = Projectile.Calamity(); + cgp.forcedCrit = true; + + // Apply bonus damage to the projectile. This is an additive multiplier between multiple coins. + float bonusDamageRatio = struckCoin.ai[0] switch + { + 1f => NumRicochets > 0 ? RicoshotCoin.SilverMulticoinBonus : RicoshotCoin.SilverBonus, + 2f => NumRicochets > 0 ? RicoshotCoin.GoldMulticoinBonus : RicoshotCoin.GoldBonus, + _ => NumRicochets > 0 ? RicoshotCoin.CopperMulticoinBonus : RicoshotCoin.CopperBonus, + }; + cgp.totalRicoshotDamageBonus += bonusDamageRatio; + + // Increment the ricochet count, relegating further coins to only give the multicoin bonus damage. + NumRicochets++; + + // If the target was valid, freeze the shot in place for a brief moment. + if (target.IsValid) + RicochetFreezeTimer = RicochetPause; + + // Play coin ricochet sound ("Ultrabling") + SoundEngine.PlaySound(RicoshotCoin.BlingHitSound, struckCoin.Center); + + // Apply a little screenshake + Main.player[Projectile.owner].Calamity().GeneralScreenShakePower = 5; + + // Kill the struck coin immediately after marking it as having been struck. + struckCoin.localAI[0] = NumRicochets; + struckCoin.Kill(); + + // ORDER easter egg fades in every time a Ricoshot is performed + if (struckCoin.owner == Main.myPlayer) + { + Player coinOwner = Main.player[struckCoin.owner]; + if (coinOwner.name.ToLower() == "v1" || coinOwner.name.ToLower() == "v2" || coinOwner.name.ToLower() == "mirage") + ORDERSystem.ORDER(); + } + } + + public override bool OnTileCollide(Vector2 oldVelocity) + { + Projectile.velocity = Vector2.Zero; + Collision.HitTiles(Projectile.position, Projectile.velocity, Projectile.width, Projectile.height); + + // Instead of immediately killing the projectile, simply set the time left so the trail can fade out. + Projectile.timeLeft = Math.Min(Lifetime - Projectile.timeLeft, trailLength); + return false; + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + target.AddBuff(BuffID.Midas, 60); + + // Instead of immediately killing the projectile, simply set the time left so the trail can fade out. + Projectile.velocity = Vector2.Zero; + Projectile.timeLeft = Math.Min((Lifetime - Projectile.timeLeft), trailLength); + } + + internal Color ColorFunction(float completionRatio) + { + float fadeOpacity = Math.Min(Projectile.timeLeft / (float)trailLength, 1f); + return Color.PaleGoldenrod * fadeOpacity; + } + + internal float WidthFunction(float completionRatio) + { + float width = Math.Min(Projectile.timeLeft / (float)trailLength, 1f); + return (1 - completionRatio) * 6.4f * width; + } + + // Marksman Shots render entirely as a shader based on previous positions and do not draw a sprite. + public override bool PreDraw(ref Color lightColor) + { + if (trailPositions is null) + return false; + + if (trailDrawer is null) + trailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, PrimitiveTrail.RigidPointRetreivalFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]); + + GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/BasicTrail")); + trailDrawer.Draw(trailPositions, Projectile.Size * 0.5f - Main.screenPosition, trailLength); + + return false; + } + } +} diff --git a/Projectiles/Ranged/MidasBlast.cs b/Projectiles/Ranged/MidasBlast.cs deleted file mode 100644 index 079a41756f..0000000000 --- a/Projectiles/Ranged/MidasBlast.cs +++ /dev/null @@ -1,327 +0,0 @@ -using System; -using CalamityMod.Items.Weapons.Ranged; -using CalamityMod.Systems; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using Terraria; -using Terraria.Audio; -using Terraria.Graphics.Shaders; -using Terraria.ID; -using Terraria.ModLoader; -using static Terraria.ModLoader.ModContent; -using System.Collections.Generic; -using System.IO; -using CalamityMod.Projectiles.Typeless; - -namespace CalamityMod.Projectiles.Ranged -{ - public class MidasBlast : ModProjectile - { - internal PrimitiveTrail TrailDrawer; - - public static int Pause = 6 * 6; - public static int CoinPause = 3 * 30; - - public ref float Ricochets => ref Projectile.ai[0]; - public ref float PauseTime => ref Projectile.ai[1]; - - internal List cachedPos; - public Vector2 StoredDirection = Vector2.Zero; - - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Marksman Shot"); - ProjectileID.Sets.DrawScreenCheckFluff[Projectile.type] = 4000; - } - - public static int Lifetime = 600; - public static int TrailLenght = 35; - - public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; - - public override void SetDefaults() - { - Projectile.width = 16; - Projectile.height = 16; - Projectile.DamageType = DamageClass.Ranged; - Projectile.friendly = true; - Projectile.penetrate = -1; - Projectile.timeLeft = Lifetime; - Projectile.extraUpdates = 7; - Projectile.alpha = 255; - - - - Pause = 4 * 6; - } - - public override bool? CanDamage() => Projectile.numHits == 0; - public override bool ShouldUpdatePosition() => PauseTime <= 0; - - public override void AI() - { - Lighting.AddLight(Projectile.Center, (Color.Gold * 0.8f).ToVector3() * 0.5f); - if (ShouldUpdatePosition()) - UpdateCache(); - - if (Ricochets < 4) - { - int[] flyingCoins = new int[4]; - int coinIndex = 0; - int struckCoinIndex = -1; - - //Check for coins - for (int i = 0; i < Main.maxProjectiles; i++) - { - Projectile proj = Main.projectile[i]; - if (proj.ModProjectile != null && proj.type == ModContent.ProjectileType() && proj.active && proj.owner == Projectile.owner) - { - flyingCoins[coinIndex] = proj.whoAmI; - coinIndex++; - - if (Collision.CheckAABBvAABBCollision(proj.Hitbox.TopLeft(), proj.Hitbox.Size(), Projectile.Hitbox.TopLeft(), Projectile.Hitbox.Size())) - { - struckCoinIndex = proj.whoAmI; - coinIndex--; // We don't care about this coin, don't redirect it to itself - } - - if (coinIndex == 4) - break; - } - } - - if (struckCoinIndex >= 0) - { - Projectile struckCoin = Main.projectile[struckCoinIndex]; - - if (Ricochets == 0) - PlanFullRicochet(flyingCoins, coinIndex, struckCoin); - else - SimpleRicochet(flyingCoins, coinIndex, struckCoin); - } - } - - PauseTime--; - } - - public void RicochetEffect(Vector2 target, Projectile struckCoin, bool shouldPause = true) - { - //Play sound - SoundEngine.PlaySound(CrackshotColt.BlingHitSound, struckCoin.Center); - Projectile.velocity = Projectile.DirectionTo(target) * 16f; - Ricochets++; - Main.player[Projectile.owner].Calamity().GeneralScreenShakePower = 5; - - float ripening = MathHelper.Clamp((MidasCoin.Lifetime - struckCoin.timeLeft) / (float)MidasPrime.RipeningTime, 0f, 1f); //Coins take a specific amount of time to "ripen" and give the full damage mult - float damageMult = MathHelper.Lerp(1f, (struckCoin.ai[0] == 0 ? MidasPrime.SilverRicochetDamageMult : MidasPrime.GoldRicochetDamageMult), Math.Min((float)Math.Pow(ripening, 3f), 1f)); - Projectile.damage = (int)(Projectile.damage * damageMult); - - struckCoin.active = false; - if (struckCoin.owner == Main.myPlayer) - { - int coin = Item.NewItem(struckCoin.GetSource_DropAsItem(), struckCoin.Center, Vector2.One, struckCoin.ai[0] == 0 ? ItemID.SilverCoin : ItemID.GoldCoin, noBroadcast:false); - - if (Main.netMode == NetmodeID.MultiplayerClient) - NetMessage.SendData(MessageID.SyncItem, -1, -1, null, coin, 1f); - - Main.item[coin].GetGlobalItem().magnetMode = true; - - //Play the funny - Player coinOwner = Main.player[struckCoin.owner]; - if (coinOwner.name.ToLower() == "v1" || coinOwner.name.ToLower() == "v2" || coinOwner.name.ToLower() == "mirage") - ORDERSystem.ORDER(); - } - - if (shouldPause) - PauseTime = Pause; - } - - public void SimpleRicochet(int[] flyingCoins, int flyingCoinCount, Projectile struckCoin) - { - //If we find a redirection target, do the ricochet and a bunch of cool effects. - if (FindRicochetTarget(Projectile.Center, flyingCoins, flyingCoinCount, out Vector2 redirectionTarget, out int coinIndex)) - RicochetEffect(redirectionTarget, struckCoin, coinIndex >= 0); - - //If no target is found, just ricochet the shot forward - else - RicochetEffect(Projectile.Center + Projectile.velocity, struckCoin, false); - } - - public void PlanFullRicochet(int[] flyingCoins, int flyingCoinCount, Projectile struckCoin) - { - Vector2 ricochetPosition = Projectile.Center; - Vector2 firstRicochetTarget = Vector2.Zero; - - - for (int i = 0; i <= flyingCoinCount; i++) - { - //Check for a potential ricochet target that isnt paused already (aka we already hit. - if (FindRicochetTarget(ricochetPosition, flyingCoins, flyingCoinCount, out Vector2 redirectionTarget, out int redirectedCoinIndex, false)) - { - if (redirectedCoinIndex >= 0) - { - if (firstRicochetTarget == Vector2.Zero) - firstRicochetTarget = redirectionTarget; - - Main.projectile[redirectedCoinIndex].ai[1] = CoinPause; - ricochetPosition = redirectionTarget; - } - - - else - { - //If we can't ricochet to any coins from the start but we still found a valid npc target, go to them. - if (i == 0) - { - RicochetEffect(redirectionTarget, struckCoin, false); - return; - } - - else - break; - } - } - - else - { - if (i == 0) - { - //If no target at all was found, just propel the coin forward - RicochetEffect(Projectile.Center + Projectile.velocity, struckCoin, false); - return; - } - else - { - break; - } - } - } - - RicochetEffect(firstRicochetTarget, struckCoin); - return; - } - - public bool FindRicochetTarget(Vector2 ricochetStart, int[] flyingCoins, int flyingCoinCount, out Vector2 redirectionTarget, out int redirectedCoinIndex, bool ignorePausedCoins = true) - { - bool targetFound = false; - float closestCoinDistance = 1000; - redirectionTarget = ricochetStart; - redirectedCoinIndex = -1; - - //Search for a coin to ricochet off of. - if (Ricochets < 3) - { - for (int i = 0; i < flyingCoinCount; i++) - { - Projectile coin = Main.projectile[flyingCoins[i]]; - if ((ignorePausedCoins || coin.ai[1] <= 0) && Collision.CanHitLine(ricochetStart - Projectile.Size / 2f, Projectile.width, Projectile.height, coin.position, coin.width, coin.height)) - { - float coinDistance = (ricochetStart - coin.Center).Length(); - if (closestCoinDistance > coinDistance) - { - targetFound = true; - closestCoinDistance = coinDistance; - redirectionTarget = coin.Center; - redirectedCoinIndex = coin.whoAmI; - } - } - } - } - - //If no coin was found, search for a npc to hit. - if (!targetFound) - { - NPC target = ricochetStart.ClosestNPCAt(900, false, true); - if (target != null) - { - targetFound = true; - redirectionTarget = target.Center; - - if (Main.player[Projectile.owner].Calamity().spiritOrigin) - { - for (int i = 0; i < Main.maxProjectiles; i++) - { - Projectile checkedProj = Main.projectile[i]; - if (checkedProj.type == ProjectileType() && checkedProj.active && checkedProj.owner == Projectile.owner && (int)checkedProj.ai[0] == target.whoAmI) - { - redirectionTarget = checkedProj.Center; - break; - } - - } - } - } - } - - if (redirectionTarget != ricochetStart) - return true; - - return false; - } - - - - public override bool OnTileCollide(Vector2 oldVelocity) - { - Projectile.velocity = Vector2.Zero; - Collision.HitTiles(Projectile.position, Projectile.velocity, Projectile.width, Projectile.height); - Projectile.timeLeft = Math.Min((Lifetime - Projectile.timeLeft), TrailLenght); - return false; - } - - public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) - { - Projectile.numHits++; - target.AddBuff(BuffID.Midas, 60); - Projectile.velocity = Vector2.Zero; - Projectile.timeLeft = Math.Min((Lifetime - Projectile.timeLeft), TrailLenght); - } - - internal Color ColorFunction(float completionRatio) - { - float fadeOpacity = Math.Min(Projectile.timeLeft / (float)TrailLenght, 1f); - return Color.PaleGoldenrod * fadeOpacity; - } - - internal float WidthFunction(float completionRatio) - { - float width = Math.Min(Projectile.timeLeft / (float)TrailLenght, 1f); - return (1 - completionRatio) * 6.4f * width; - } - - public override bool PreDraw(ref Color lightColor) - { - if (cachedPos is null) - return false; - - if (TrailDrawer is null) - TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, PrimitiveTrail.RigidPointRetreivalFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]); - - GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(Request("CalamityMod/ExtraTextures/Trails/BasicTrail")); - TrailDrawer.Draw(cachedPos, Projectile.Size * 0.5f - Main.screenPosition, TrailLenght); - - return false; - } - - //Done like that for better control instead of relying on Projectile.OldPos() - private void UpdateCache() - { - if (cachedPos == null) - { - cachedPos = new List(); - - for (int i = 0; i < TrailLenght; i++) - { - cachedPos.Add(Projectile.Center); - } - } - - cachedPos.Insert(0, Projectile.Center); - - while (cachedPos.Count > TrailLenght) - { - cachedPos.RemoveAt(cachedPos.Count - 1); - } - } - } -} diff --git a/Projectiles/Ranged/MidasCoin.cs b/Projectiles/Ranged/MidasCoin.cs deleted file mode 100644 index 7e213fe6ac..0000000000 --- a/Projectiles/Ranged/MidasCoin.cs +++ /dev/null @@ -1,141 +0,0 @@ -using System; -using CalamityMod.Items.Weapons.Ranged; -using CalamityMod.Systems; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using Terraria; -using Terraria.Audio; -using Terraria.Graphics.Shaders; -using Terraria.ID; -using Terraria.ModLoader; -using static Terraria.ModLoader.ModContent; -using ReLogic.Content; - -namespace CalamityMod.Projectiles.Ranged -{ - public class MidasCoin : ModProjectile - { - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Coin"); - ProjectileID.Sets.TrailCacheLength[Projectile.type] = 60; - ProjectileID.Sets.TrailingMode[Projectile.type] = 0; - Main.projFrames[Projectile.type] = 8; - } - - public ref float BlingType => ref Projectile.ai[0]; - public ref float PauseTime => ref Projectile.ai[1]; - - public static int Lifetime = 950; - public float LifetimeCompletion => MathHelper.Clamp((Lifetime - Projectile.timeLeft) / (float)Lifetime, 0f, 1f); - public float FadePercent => Math.Clamp(Projectile.timeLeft / FadeTime, 0f, 1f); - public static float FadeTime => 30f; - public Player Owner => Main.player[Projectile.owner]; - public static Asset SheenTex; - public static Asset BloomTex; - - public override void SetDefaults() - { - Projectile.width = 22; - Projectile.height = 22; - Projectile.friendly = true; - Projectile.penetrate = -1; - Projectile.DamageType = DamageClass.Ranged; - - Projectile.timeLeft = Lifetime; - Projectile.extraUpdates = 3; - Projectile.usesLocalNPCImmunity = true; - Projectile.localNPCHitCooldown = 1; - Projectile.scale = 1.1f; - } - - public override bool ShouldUpdatePosition() => PauseTime <= 0; - - public override void AI() - { - PauseTime--; - - Projectile.frameCounter++; - if (Projectile.frameCounter > 8) - { - Projectile.frame++; - Projectile.frameCounter = 0; - } - if (Projectile.frame >= Main.projFrames[Projectile.type]) - { - Projectile.frame = 0; - } - - Lighting.AddLight(Projectile.Center, Color.Goldenrod.ToVector3() * 0.2f); - - - Projectile.rotation = Projectile.velocity.X * 0.5f; - Projectile.velocity *= 0.998f; - - if (Projectile.timeLeft < Lifetime - 100) - Projectile.velocity.Y += 0.01f; - - if (Projectile.Center.Distance(Owner.MountedCenter) > 1300 && Projectile.timeLeft > FadeTime) - Projectile.timeLeft = (int)FadeTime; - - if (Main.rand.NextBool(10)) - { - int schyste = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, 246); - Main.dust[schyste].noGravity = true; - } - } - - public override bool OnTileCollide(Vector2 oldVelocity) - { - Collision.HitTiles(Projectile.position, Projectile.velocity, Projectile.width, Projectile.height); - - return base.OnTileCollide(oldVelocity); - } - - public override bool PreDraw(ref Color lightColor) - { - Texture2D tex = ModContent.Request(Texture).Value; - Rectangle frame = new Rectangle((int)BlingType * tex.Width / 2, Projectile.frame * tex.Height / Main.projFrames[Projectile.type], tex.Width / 2 - 2, tex.Height / Main.projFrames[Projectile.type] - 2); - - Main.EntitySpriteDraw(tex, Projectile.Center - Main.screenPosition, frame, Projectile.GetAlpha(lightColor) * FadePercent, Projectile.rotation, frame.Size() / 2f, Projectile.scale, SpriteEffects.None, 0); - - - float sheenOpacity = (float)Math.Sin(Math.Clamp((Lifetime - Projectile.timeLeft) / (MidasPrime.RipeningTime * 2f), 0f, 1f) * MathHelper.Pi); - - if (sheenOpacity > 0f) - { - Main.spriteBatch.End(); - Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); - - if (SheenTex == null) - SheenTex = Request("CalamityMod/Particles/HalfStar"); - Texture2D shineTex = SheenTex.Value; - - if (BloomTex == null) - BloomTex = Request("CalamityMod/Particles/BloomCircle"); - Texture2D bloomTex = BloomTex.Value; - - Vector2 shineScale = new Vector2(1f, 3f - sheenOpacity * 2f); - Color shineColor = BlingType == 0 ? Color.Silver : Color.Goldenrod; - - - Main.EntitySpriteDraw(bloomTex, Projectile.Center - Main.screenPosition, null, shineColor * sheenOpacity * 0.3f, MathHelper.PiOver2, bloomTex.Size() / 2f, shineScale * Projectile.scale, SpriteEffects.None, 0); - Main.EntitySpriteDraw(shineTex, Projectile.Center - Main.screenPosition, null, shineColor * sheenOpacity * 0.7f, MathHelper.PiOver2, shineTex.Size() / 2f, shineScale * Projectile.scale, SpriteEffects.None, 0); - - Main.spriteBatch.End(); - Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); - } - - return false; - } - - public override void Kill(int timeLeft) - { - if (Projectile.owner == Main.myPlayer && Main.rand.NextBool(4)) - { - int coin = Item.NewItem(Projectile.GetSource_DropAsItem(), Projectile.Center, Vector2.One, BlingType == 0 ? ItemID.SilverCoin : ItemID.GoldCoin); - Main.item[coin].GetGlobalItem().magnetMode = true; - } - } - } -} diff --git a/Projectiles/Ranged/MidasCoin.png b/Projectiles/Ranged/MidasCoin.png deleted file mode 100644 index fad5268dd524ea776fa4f52a7134fd80b24694b0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1949 zcmV;O2V(e%P)Px+S4l)cRA_lAsM2D=Du(sp?AP^7ce;x) zI~&6HGCQZ|%+A;Ung92{%sS<^VJt`4WJwJ3axRvLFqB zIddlgaOU(;Yu)&Qi4MT=#-jkdw)F}Cy+|^gd5_Eiprz&KFu+Hj*I5&)o;J+Kj4O5k zzW8tx0D0LL0SGl;3j^%lx6WF(eCZ+ph7L1K_wKF-{9ssKS{Md+_~FN`Ka`cv1|YB4 z*!ZCt#Q^lV+UfwLUHvr-F#owUYu%{4$pG9l@i74A&R*E{UEl-5TipW<4K>zr;i44@ zT_{-pSLFCbkMsOv`23Qk0Bl%g&c!euo|yM$mllpdCp%><%)7z&*SVDR7}4nTRSSs^iYs$+>t%j0SKNN0HjjAR8ZYiOgk?$I{=-np_uhjL3PvB?{%3r#pSJyZv6UdE8uwx@TZxgFc8z~+SE!P|OJ97!)I;5Iso?b-jvQn>hdVA6v^z)V znBDnf$c(36ZZUa^={=omISF+4rCzzk#Ik$`p!v5I(Cd=9hG;<4X@OoZ1V(y;E}mIDPi_Fu>xf`PRDmOHB4vIKp(rFP=RC_+i8L&_MtKIkOyq zs;4XCyo>QY0J%9?01Oy3!U34SWT&;Rq|oG*MK}M&8)4hHRc6Ij=Rs&!(qKmOcTg3 zzO=n9RqCZrJ@G(~6P3Zbp>=(nHfubsmvKRFZ~NXFPreOxhq<}q0XTW`c+8ka5YuH( zr2}wBwy|yS)BtPUlnDbJfMvIw27IiScI{Fz(>oaQrP{S^Z5=UP%f+)NOkDcRbRgZri9n8n1uowvGA}H~WYF>ER3WN_(2eyW0=P9ItwGRFCV{ ze(;lZ?w=k`o;d}GRx^a*`O_VMu_KHpTJrkmKvWO!DIE($s~N)R+#CmBol9HD@=YEsdBvdFSrwcZw?;_L-f5iVfETACW_0x-6((L zKazZg4M)T*_8WW8M=DcN{=hBhw=fnncf`H8%0%K)ethpAN+rDNr9x-KMF#qrqg2AH zUg}2j87gK;v|jr6-)5m=mK7@#tCtF?`+Ey@*-izUfy94rF}3_I2cYAUiO^H8*4FL! j775ncQs(y-H$MIWfo+2@!myXZ00000NkvXXu0mjfkW$Ms diff --git a/Projectiles/Ranged/RicoshotCoin.cs b/Projectiles/Ranged/RicoshotCoin.cs new file mode 100644 index 0000000000..bd745863fa --- /dev/null +++ b/Projectiles/Ranged/RicoshotCoin.cs @@ -0,0 +1,289 @@ +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; +using Terraria; +using Terraria.Audio; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Ranged +{ + public class RicoshotCoin : ModProjectile + { + internal static readonly SoundStyle BlingSound = new("CalamityMod/Sounds/Custom/Ultrabling") { PitchVariance = 0.5f }; + internal static readonly SoundStyle BlingHitSound = new("CalamityMod/Sounds/Custom/UltrablingHit") { PitchVariance = 0.5f }; + private static Asset sheenAsset; + private static Asset bloomAsset; + + public static readonly float UsedCoinGrabRangeMultiplier = 5f; + public static readonly float CoinTossForce = 7.33f; + + // This variable controls how far shots are allowed to ricochet from one coin to another. + // This creates a circle around the first coin hit to check for other coins for multi-ricoshots. + public static readonly float MaxIntraCoinRicoshotDistance = 1000f; + + // This variable controls how far shots are allowed to ricochet into NPCs. + // This is intentionally higher than the intra-coin distance to make it easier to land successful ricoshots. + public static readonly float RicoshotSearchDistance = 2000f; + + // The first copper coin struck adds +50% damage. Copper coins beyond the first add +15% damage. + // Maximum: 4 copper coins = +95% + internal static float CopperBonus = 0.5f; + internal static float CopperMulticoinBonus = 0.15f; + + // The first silver coin struck adds +100% damage. Silver coins beyond the first add +25% damage. + // Maximum: 4 silver coins = +175% + internal static float SilverBonus = 1f; + internal static float SilverMulticoinBonus = 0.25f; + + // The first gold coin struck adds +150% damage. Gold coins beyond the first add +50% damage. + // Maximum: 4 gold coins = +300% + internal static float GoldBonus = 1.5f; + internal static float GoldMulticoinBonus = 0.5f; + + // Lifetime of a coin. Defined in terms of updates because Terraria's engine is trash. + internal static readonly int UpdateCount = 4; + internal static readonly int CoinLifetime = UpdateCount * CalamityUtils.SecondsToFrames(7); + + // Coins fade out for the last 30 frames of their existence. + // This fading begins immediately if they are an extreme distance from the player. + private static readonly int FadeoutTime = UpdateCount * 30; + private static readonly float ForceFadeDistance = 2000f; + + // Number of frames over which coin damage increases to its full value. + private static readonly int DamageWindupFrames = 40; + internal static int DamageScaleUpTime => UpdateCount * DamageWindupFrames; + + // 0f = copper + // 1f = silver + // 2f = gold + // 3f = platinum (not currently implemented) + internal ref float CoinType => ref Projectile.ai[0]; + + // A counter for how long the coin remains frozen in place when struck. + internal ref float ShotFreezeTimer => ref Projectile.ai[1]; + // The default length of the above freeze timer. + internal static int RicochetPause = UpdateCount * 22; + + // Marker for whether the coin has been shot. + // localAI is set to the number of the coin in a chain; i.e. the first coin gets 1, the second coin gets 2... + public bool HasBeenShot => Projectile.localAI[0] > 0f; + + public Player Owner => Main.player[Projectile.owner]; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Ricoshot Coin"); + ProjectileID.Sets.TrailCacheLength[Projectile.type] = 60; + ProjectileID.Sets.TrailingMode[Projectile.type] = 0; + Main.projFrames[Projectile.type] = 8; + } + + public override void SetDefaults() + { + Projectile.width = 22; + Projectile.height = 22; + Projectile.friendly = true; + Projectile.penetrate = -1; + Projectile.DamageType = DamageClass.Ranged; + + // 7 seconds should be more than enough to hit any coin. + Projectile.MaxUpdates = UpdateCount; + Projectile.timeLeft = CoinLifetime; + + Projectile.scale = 1.1f; + } + + // Coins cannot damage anything. + public override bool? CanDamage() => false; + + // Coins stop moving when shot for a certain number of frames. + public override bool ShouldUpdatePosition() => ShotFreezeTimer <= 0; + + public override void AI() + { + // Decrement the timer for how long the coin should remain frozen, if it is currently frozen. + if (ShotFreezeTimer > 0f) + { + --ShotFreezeTimer; + + // On the frame the coin stops being frozen, destroy it immediately. + if (ShotFreezeTimer <= 0) + { + Projectile.Kill(); + return; + } + } + + // Update the coin animation so it spins. + Projectile.frameCounter++; + if (Projectile.frameCounter > 8) + { + Projectile.frame++; + Projectile.frameCounter = 0; + } + if (Projectile.frame >= Main.projFrames[Projectile.type]) + Projectile.frame = 0; + + // Produce a tiny amount of light based on coin type. + // Dropped coins typically do not produce light, but do emit dust which is rendered fullbright. + // Ricoshot coins do both. + int dustID = DustID.CopperCoin; + switch (CoinType) + { + case 1f: + Lighting.AddLight(Projectile.Center, Color.White.ToVector3() * 0.14f); + dustID = DustID.SilverCoin; + break; + case 2f: + Lighting.AddLight(Projectile.Center, Color.Goldenrod.ToVector3() * 0.2f); + dustID = DustID.GoldCoin; + break; + default: + Lighting.AddLight(Projectile.Center, Color.DarkOrange.ToVector3() * 0.11f); + break; + } + + // Randomly spawn dust like standard coins would. + if (Main.rand.NextBool(10)) + { + Dust d = Dust.NewDustDirect(Projectile.position, Projectile.width, Projectile.height, dustID); + d.noGravity = true; + } + + // The coin spins in midair based on how fast it is traveling horizontally. + Projectile.rotation = Projectile.velocity.X * 0.5f; + + // The coin experiences a gravity calculated to enable similar movement to the player. + // No other modifications are made to its velocity, and it is updated only once per frame to match player physics. + // This enables perfect parabolic arcs like in ULTRAKILL. + if (Projectile.FinalExtraUpdate()) + { + float coinGravity = Player.defaultGravity / Projectile.MaxUpdates; + Projectile.velocity.Y += coinGravity; + + // Max coin fall speed commented out because it seems unnecessary. + // It would also mess with the perfect parabolas. + // Max coin fall speed is the same as the player's max default fall speed (10f). + /* + float maxCoinFallSpeed = 10f / Projectile.MaxUpdates; + if (Projectile.velocity.Y > maxCoinFallSpeed) + Projectile.velocity.Y = maxCoinFallSpeed; + */ + } + + // Coins that are extremely far away from the player begin fading immediately. + if (Projectile.timeLeft > FadeoutTime && Projectile.Center.Distance(Owner.MountedCenter) > ForceFadeDistance) + Projectile.timeLeft = FadeoutTime; + } + + public override bool OnTileCollide(Vector2 oldVelocity) + { + Collision.HitTiles(Projectile.position, Projectile.velocity, Projectile.width, Projectile.height); + return base.OnTileCollide(oldVelocity); + } + + // Coins are occasionally refunded when these projectiles are destroyed. The exact refund rules are described below. + public override void Kill(int timeLeft) + { + // Do nothing except on the client who owns this Ricoshot Coin. + if (Projectile.owner != Main.myPlayer) + return; + + // Potentially spawn the coin that was tossed when the Ricoshot Coin is destroyed. + // If the coin wasn't shot, it is always refunded. + bool spawnRefundCoin = !HasBeenShot; + + // If the coin WAS shot, then there is only a certain chance to refund it based on coin type. + if (!spawnRefundCoin) + { + spawnRefundCoin = CoinType switch + { + // Copper coins are never refunded. + 0f => false, + + // Silver coins are refunded half of the time if they are the first coin, + // and are never refunded if they are a subsequent coin in a chain. + 1f => Projectile.localAI[0] == 1f ? Main.rand.NextFloat() < 0.5f : false, + + // Gold coins are always refunded if they are the first coin, + // and are never refunded if they are a subsequent coin in a chain. + 2f => Projectile.localAI[0] == 1f, + + // If you don't know what's going on, don't refund a coin. + _ => false + }; + } + + // Actually grant the coin refund. All refunded coins are given an incredibly high pickup range for convenience. + if (spawnRefundCoin) + { + int itemID = CoinType switch + { + 1f => ItemID.SilverCoin, + 2f => ItemID.GoldCoin, + _ => ItemID.CopperCoin, + }; + int coin = Item.NewItem(Projectile.GetSource_DropAsItem(), Projectile.Center, Vector2.One, itemID, noBroadcast: false); + Main.item[coin].Calamity().grabRangeMultiplier = UsedCoinGrabRangeMultiplier; + + // Sync this dropped coin in multiplayer. + if (Main.netMode == NetmodeID.MultiplayerClient) + NetMessage.SendData(MessageID.SyncItem, -1, -1, null, coin, 1f); + } + } + + public override bool PreDraw(ref Color lightColor) + { + Texture2D tex = ModContent.Request(Texture).Value; + int numFrames = Main.projFrames[Projectile.type]; + Rectangle frame = new Rectangle( + /* X */ (int)CoinType * tex.Width / 3, + /* Y */ Projectile.frame * tex.Height / numFrames, + /* W */ tex.Width / 3 - 2, + /* H */ tex.Height / numFrames - 2 + ); + + float fadingOpacity = Math.Clamp(Projectile.timeLeft / (float)FadeoutTime, 0f, 1f); + Color alphaColor = Projectile.GetAlpha(lightColor) * fadingOpacity; + Main.EntitySpriteDraw(tex, Projectile.Center - Main.screenPosition, frame, alphaColor, Projectile.rotation, frame.Size() / 2f, Projectile.scale, SpriteEffects.None, 0); + + // As this value goes from 0 to 1, the below sine goes from 0, to 1, to 0. + // This means the coin begins shining, then loses its shine afterwards. + // Shooting the coin too quickly deals reduced damage. + int numUpdatesPassed = CoinLifetime - Projectile.timeLeft; + float coinSheenLerp = Math.Clamp(numUpdatesPassed / (DamageScaleUpTime * 2f), 0f, 1f); + float sheenOpacity = MathF.Sin(MathHelper.Pi * coinSheenLerp); + + // oh BOY another end begin boy + if (sheenOpacity > 0f) + { + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + sheenAsset ??= ModContent.Request("CalamityMod/Particles/HalfStar"); + Texture2D shineTex = sheenAsset.Value; + + bloomAsset ??= ModContent.Request("CalamityMod/Particles/BloomCircle"); + Texture2D bloomTex = bloomAsset.Value; + + Vector2 shineScale = new Vector2(1f, 3f - sheenOpacity * 2f); + Color shineColor = CoinType switch + { + 1f => Color.Silver, + 2f => Color.Goldenrod, + _ => Color.DarkOrange, + }; + + Main.EntitySpriteDraw(bloomTex, Projectile.Center - Main.screenPosition, null, shineColor * sheenOpacity * 0.3f, MathHelper.PiOver2, bloomTex.Size() / 2f, shineScale * Projectile.scale, SpriteEffects.None, 0); + Main.EntitySpriteDraw(shineTex, Projectile.Center - Main.screenPosition, null, shineColor * sheenOpacity * 0.7f, MathHelper.PiOver2, shineTex.Size() / 2f, shineScale * Projectile.scale, SpriteEffects.None, 0); + + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + } + + return false; + } + } +} diff --git a/Projectiles/Ranged/RicoshotCoin.png b/Projectiles/Ranged/RicoshotCoin.png new file mode 100644 index 0000000000000000000000000000000000000000..fecf2cb14334aa718f3f79e13569f05402e69daf GIT binary patch literal 1588 zcmV-42Fv-0P)Px))Ja4^RCt{2oKJ{VRUF4ZFGZw9s}?elE(8^_o~B?BrVK$6rXprI&4i6a8)s5e zM#jx-MjXbPG&d3{r4^}!OcF*hG(G}FXY~08$A!UA41%s&h_vXnIPd$e_uPBlyEm>d z=XF1udGFkN?tOeYf4=wk``syE(cAiT<{CcS0$x}Zi>et(D-S1@l z{hms4vFX4}eOR|>P6eQ6*9X=qgB5TqyK+Ub0`S>a=d2@ZE8tdk?F+Lj0R01pts~v$ zewMP{C|Zz`@3cM&9eBQF1pv=2c^QC?-A4f!p14P@ed^`nLo?Tfz%ny;=(W z-QL}ws9$-!dcW}tbX zQM9&JY4)EuXx7m`u3ZG6_hcCeX1k4M|M2J)0Pb8d=kNJw8xYKP8_oV7&L06_?AjRs z`u6?`1hZZEr>Ky!!lk5*loc)|ZKSNQl@#76nv*q=@gP5XbLtr&`52WSot(S}Bp;*l zqu0y-08KDPoqqKEkB6#9OnaksRDSf>(0~qApz%5?KYHprvqN#*^z(KdjkqW6NZR|q z9yyxmLfVnE_n$p`I#ECENZR{P9N!*$p1+EIGm_4SiX(^j0m*%+`2O4aK2&(4X#PX9 zCNf5QcI^QkUq@%#r^FJojwT|qjymv0(cF*bOn34znl%wWy1(5-;ciV`svb$^M+ZOt z0)XF2=XEHNAMHD^8i2cZjB9H?KdN}BTvXDXN%2s*sH7+!+Q>!utEe1)TIBH4B8T4y ze-#a8dpaJQ?Ww5E_6GQ?s3Oh9MY907IhE`}iZm}>x)OlN$z)HViZmBrGWWY)eiVD2 zH;U$aea>{p86OpSzCI-pKibw>v`#4{%GbxloD${hH*R^=I&z^&^Yub``@Wwa0B~k> ztZu$uC~q%+DrH^ydZE1ir(ae={k&1sxz`8CP0g=+p`=;m$o(Q&Wx1&pp;rGC)mW5* zQdaG!Z#{^;fX1SbvTAoJt+6NtrEIPJVrY5wN6|>WUeEQyp6xdFbG@)&ui8NPH-oE+jM*~bwba9JmAD)Q6knNIG{Wx#l8~{p};^U`LKWcKKFBXl4=Wdu* ze-vHZ@)r=q?u%3LepD5@LP{xiuP9z4KPsgZyVn@C{it1`>y4tdwQA`7RTY5F^{YcC zY#TIrc$Xg?+H3l4?fWIv-u3QU!0kuXZ%0>0sJ&z7>DYe$DJnLtS{B-ST}s;g*Vt3i ze%>gWlQp>?&6-GjRDLvV{iytC+WJxX(f?2VXnA4~aJwd9*NLRyMe$p z3I7z8i;}~an`(qylpMa?R3qe~PI!(o40;c zessZ%+rX30g{t4&S!Uh!J{OvkHTg4B*3{NfRX((}J_`hU{el^{>*njFi1PKpUSI$H zdR0Db++q%Eub(@soGo5@7~#XqiFs^ zv!*siH5SuW_ZE^Mr_u2W3aZ&d)~^ zjWuOCYW)sm+s~UZ8u6oco{4Il)1|EZ=+-{_|2@5C`Z*MmAGPyLwfkB9{83a&M&GbC zbgnm%llylshn&8YbiHBQSTF0000 type != RicoshotTargetType.None; + } + + public static partial class CalamityUtils + { + public static int GetActiveRicoshotCoinCount(this Player player) + { + int count = 0; + int id = ModContent.ProjectileType(); + + for (int i = 0; i < Main.maxProjectiles; ++i) + { + Projectile p = Main.projectile[i]; + if (p is null || !p.active || p.owner != player.whoAmI) + continue; + if (p.type == id) + ++count; + } + return count; + } + + /// + /// Gets the velocity that the player will toss a Ricoshot Coin at based on their current mouse position and velocity. + /// + /// The player who would (or will) toss a coin. + /// The appropriate velocity to toss the coin at. + public static Vector2 GetCoinTossVelocity(this Player player) + { + // As 0,0 in world coordinates is the top left of the world (+Y = down instead of up), + // we have to flip the Y here to do valid trigonometry. + Vector2 vectorToMouse = player.Calamity().mouseWorld - player.MountedCenter; + vectorToMouse.Y *= -1f; + + // All coin tosses are guaranteed to have a baseline gentle upwards velocity. + // This can be canceled out by pointing your mouse cursor straight down. + // Again, normally in Terraria +Y is straight down. However we are inverting it here for the math. + Vector2 tossVelocity = new Vector2(0f, RicoshotCoin.CoinTossForce); + + // Normalize the direction to the mouse. + Vector2 mouseDirNormalized = vectorToMouse.SafeNormalize(Vector2.UnitY); + // Add extra coin toss velocity directly towards the mouse. + tossVelocity += RicoshotCoin.CoinTossForce * mouseDirNormalized; + + // Re-invert the Y coordinates for the game world. + tossVelocity.Y *= -1f; + + // All coin tosses inherit the player's full velocity. + Vector2 finalVelocity = player.velocity + tossVelocity; + + // Coins have extra updates, so account for those. + return finalVelocity / RicoshotCoin.UpdateCount; + } + + /// + /// Gets a list of all coin projectiles that are within valid range of this projectile to set up a multi-ricoshot. + /// + /// The projectile to search around. + /// An array of Projectiles. This array may be empty, but it will never be null. + public static Projectile[] GetAvailableCoins(this Projectile searchingShot) + { + IList coins = new List(); + + // Search for all nearby coins. + // Coins do not necessarily have to be owned by the same player as the searching projectile! + int coinID = ModContent.ProjectileType(); + for (int i = 0; i < Main.maxProjectiles; ++i) + { + Projectile proj = Main.projectile[i]; + if (!proj.active || proj.ModProjectile is null || proj.type != coinID) + continue; + + // Coins that have already been struck are ignored. + if (proj.localAI[0] > 0f) + continue; + + // Finally, do a distance check + float dist = searchingShot.DistanceSQ(proj.Center); + if (dist <= RicoshotCoin.MaxIntraCoinRicoshotDistance * RicoshotCoin.MaxIntraCoinRicoshotDistance) + coins.Add(proj); + } + + return coins.ToArray(); + } + + /// + /// Given an array of available Ricoshot Coins, finds the next target of the given projectile's ricoshot.
+ ///
+ /// Ricoshots prioritize the following targets, in order:
+ /// 1) Other coins which are not already part of a ricoshot, including those owned by other players
+ /// 2) Daawnlight Spirit Origin bullseyes owned by the shot's owner
+ /// 3) Bosses, determined by
+ /// 4) Any other hostile NPC + ///
+ /// The projectile which is starting (or continuing) a ricoshot. + /// The position to consider for this ricochet. This may not necessarily be the shot's current position. + /// An array of available coins for the current stage of the ricoshot. + /// Whether or not already-frozen coins are considered valid targets.
+ /// This is true when actually redirecting a shot, as it is expected to strike frozen coins.
+ /// This is false when recursively freezing coins (setting up ricoshots) to prevent infinite recursion. + /// The next ricochet target. This may not be a valid target. + public static RicoshotTarget FindRicochetTarget(this Projectile theShot, Vector2 startPos, Projectile[] availableCoins, bool considerFrozenCoins = false) + { + RicoshotTarget ret = default; + + // The first thing coins attempt to ricochet to is other coins. + // If any coins are available, they will ricochet to the closest possible coin that has line of sight. + bool foundAnyCoin = false; + float closestCoinDistance = RicoshotCoin.MaxIntraCoinRicoshotDistance; + foreach (Projectile coin in availableCoins) + { + // Skip coins which are already frozen (part of an ongoing ricoshot), unless considering them + if (!considerFrozenCoins && coin.ai[1] > 0f) + continue; + + // Check line of sight. + Vector2 wouldBeShotCorner = startPos - theShot.Size / 2f; + bool los = Collision.CanHitLine(wouldBeShotCorner, theShot.width, theShot.height, coin.position, coin.width, coin.height); + if (los) + { + // If this coin is closer than the current closest coin, choose it as the target. + float coinDistance = coin.Distance(startPos); + if (coinDistance < closestCoinDistance) + { + foundAnyCoin = true; + closestCoinDistance = coinDistance; + ret.type = RicoshotTargetType.Coin; + ret.pos = coin.Center; + ret.entityID = coin.whoAmI; + } + } + } + + // If a coin was found, that is the target. Return it. + if (foundAnyCoin) + return ret; + + // The second thing coins attempt to ricochet to is Daawnlight Spirit Origin bullseyes. + bool foundAnyBullseye = false; + float closestBullseyeDistance = DaawnlightSpiritOrigin.RicoshotSearchDistance; + int bullseyeID = ModContent.ProjectileType(); + for (int i = 0; i < Main.maxProjectiles; ++i) + { + Projectile proj = Main.projectile[i]; + if (proj is null || !proj.active || proj.ModProjectile is null || proj.type != bullseyeID || proj.owner != theShot.owner) + continue; + + // Do a distance check. + float bullseyeDistance = proj.Distance(startPos); + if (bullseyeDistance < closestBullseyeDistance) + { + foundAnyBullseye = true; + closestBullseyeDistance = bullseyeDistance; + ret.type = RicoshotTargetType.Bullseye; + ret.pos = proj.Center; + ret.entityID = proj.whoAmI; + } + } + + // If a Daawnlight Spirit Origin bullseye was found, that is the target. Return it. + if (foundAnyBullseye) + return ret; + + // The third thing coins attempt to ricochet to is hostile NPCs. + // Bosses are preferred over other possible targets. + NPC targetNPC = startPos.ClosestNPCAt(RicoshotCoin.RicoshotSearchDistance, false, true); + if (targetNPC != null) + { + ret.type = RicoshotTargetType.NPC; + ret.pos = targetNPC.Center; + ret.entityID = targetNPC.whoAmI; + return ret; + } + + // If absolutely nothing was found, leave the type at None but give a random destination. + ret.type = RicoshotTargetType.None; + ret.pos = startPos + Main.rand.NextVector2Unit() * 32f; + return ret; + } + } +}