diff --git a/Buffs/Cooldowns/UniverseSplitterCooldown.cs b/Buffs/Cooldowns/UniverseSplitterCooldown.cs new file mode 100644 index 0000000000..03270a884e --- /dev/null +++ b/Buffs/Cooldowns/UniverseSplitterCooldown.cs @@ -0,0 +1,19 @@ +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Buffs.Cooldowns +{ + public class UniverseSplitterCooldown : ModBuff + { + public override void SetDefaults() + { + DisplayName.SetDefault("Universe Splitter Cooldown"); + Description.SetDefault("You cannot use the Universe Splitter"); + Main.debuff[Type] = true; + Main.pvpBuff[Type] = true; + Main.buffNoSave[Type] = true; + longerExpertDebuff = false; + canBeCleared = false; + } + } +} diff --git a/Buffs/Cooldowns/UniverseSplitterCooldown.png b/Buffs/Cooldowns/UniverseSplitterCooldown.png new file mode 100644 index 0000000000..f24e416ef2 Binary files /dev/null and b/Buffs/Cooldowns/UniverseSplitterCooldown.png differ diff --git a/Buffs/Cooldowns/Withered.cs b/Buffs/Cooldowns/Withered.cs new file mode 100644 index 0000000000..5a68168394 --- /dev/null +++ b/Buffs/Cooldowns/Withered.cs @@ -0,0 +1,21 @@ +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Buffs.Cooldowns +{ + public class Withered : ModBuff + { + public override void SetDefaults() + { + DisplayName.SetDefault("Withered"); + Description.SetDefault("Holding withered weapons causes you to suffer but makes your weapons strong"); + Main.debuff[Type] = true; + Main.pvpBuff[Type] = true; + Main.buffNoSave[Type] = true; + longerExpertDebuff = false; + canBeCleared = false; + } + + public override void Update(Player player, ref int buffIndex) => player.Calamity().witheredDebuff = true; + } +} diff --git a/Buffs/Cooldowns/Withered.png b/Buffs/Cooldowns/Withered.png new file mode 100644 index 0000000000..c51dae7b2a Binary files /dev/null and b/Buffs/Cooldowns/Withered.png differ diff --git a/Buffs/DamageOverTime/SagePoison.cs b/Buffs/DamageOverTime/SagePoison.cs new file mode 100644 index 0000000000..b1763d9e41 --- /dev/null +++ b/Buffs/DamageOverTime/SagePoison.cs @@ -0,0 +1,24 @@ +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Buffs.DamageOverTime +{ + public class SagePoison : ModBuff + { + public override void SetDefaults() + { + DisplayName.SetDefault("Sage Poison"); + Description.SetDefault("Poisoned"); + Main.debuff[Type] = true; + Main.pvpBuff[Type] = true; + Main.buffNoSave[Type] = true; + } + public override void Update(NPC npc, ref int buffIndex) + { + if (npc.Calamity().sagePoisonTime < npc.buffTime[buffIndex]) + npc.Calamity().sagePoisonTime = npc.buffTime[buffIndex]; + npc.DelBuff(buffIndex); + buffIndex--; + } + } +} diff --git a/Buffs/DamageOverTime/SagePoison.png b/Buffs/DamageOverTime/SagePoison.png new file mode 100644 index 0000000000..369f52e1ef Binary files /dev/null and b/Buffs/DamageOverTime/SagePoison.png differ diff --git a/Buffs/DamageOverTime/VulnerabilityHex.cs b/Buffs/DamageOverTime/VulnerabilityHex.cs index 17b1addd7e..dfc4a2c6e0 100644 --- a/Buffs/DamageOverTime/VulnerabilityHex.cs +++ b/Buffs/DamageOverTime/VulnerabilityHex.cs @@ -16,9 +16,14 @@ namespace CalamityMod.Buffs.DamageOverTime canBeCleared = false; } - public override void Update(Player player, ref int buffIndex) + public override void Update(Player player, ref int buffIndex) => player.Calamity().vHex = true; + + public override void Update(NPC npc, ref int buffIndex) { - player.Calamity().vHex = true; + if (npc.Calamity().vulnerabilityHex < npc.buffTime[buffIndex]) + npc.Calamity().vulnerabilityHex = npc.buffTime[buffIndex]; + npc.DelBuff(buffIndex); + buffIndex--; } } } diff --git a/Buffs/DamageOverTime/WeakBrimstoneFlames.cs b/Buffs/DamageOverTime/WeakBrimstoneFlames.cs new file mode 100644 index 0000000000..edf6f12830 --- /dev/null +++ b/Buffs/DamageOverTime/WeakBrimstoneFlames.cs @@ -0,0 +1,21 @@ +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Buffs.DamageOverTime +{ + public class WeakBrimstoneFlames : ModBuff + { + public override void SetDefaults() + { + DisplayName.SetDefault("Weak Brimstone Flames"); + Description.SetDefault("Health loss"); + Main.debuff[Type] = true; + Main.pvpBuff[Type] = true; + Main.buffNoSave[Type] = true; + Main.buffNoTimeDisplay[Type] = true; + longerExpertDebuff = false; + } + + public override void Update(Player player, ref int buffIndex) => player.Calamity().weakBrimstoneFlames = true; + } +} diff --git a/Buffs/DamageOverTime/WeakBrimstoneFlames.png b/Buffs/DamageOverTime/WeakBrimstoneFlames.png new file mode 100644 index 0000000000..e2be863c4b Binary files /dev/null and b/Buffs/DamageOverTime/WeakBrimstoneFlames.png differ diff --git a/Buffs/Summon/DaedalusGolemBuff.cs b/Buffs/Summon/DaedalusGolemBuff.cs new file mode 100644 index 0000000000..6c0972e123 --- /dev/null +++ b/Buffs/Summon/DaedalusGolemBuff.cs @@ -0,0 +1,36 @@ +using CalamityMod.CalPlayer; +using CalamityMod.Projectiles.Summon; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Buffs.Summon +{ + public class DaedalusGolemBuff : ModBuff + { + public override void SetDefaults() + { + DisplayName.SetDefault("Daedalus Golem"); + Description.SetDefault("A crystal golem is following you"); + Main.buffNoTimeDisplay[Type] = true; + Main.buffNoSave[Type] = true; + } + + public override void Update(Player player, ref int buffIndex) + { + CalamityPlayer modPlayer = player.Calamity(); + if (player.ownedProjectileCounts[ModContent.ProjectileType()] > 0) + { + modPlayer.daedalusGolem = true; + } + if (!modPlayer.daedalusGolem) + { + player.DelBuff(buffIndex); + buffIndex--; + } + else + { + player.buffTime[buffIndex] = 18000; + } + } + } +} diff --git a/Buffs/Summon/DaedalusGolemBuff.png b/Buffs/Summon/DaedalusGolemBuff.png new file mode 100644 index 0000000000..011938595e Binary files /dev/null and b/Buffs/Summon/DaedalusGolemBuff.png differ diff --git a/Buffs/Summon/DeathstareBuff.cs b/Buffs/Summon/DeathstareBuff.cs new file mode 100644 index 0000000000..8c3de83967 --- /dev/null +++ b/Buffs/Summon/DeathstareBuff.cs @@ -0,0 +1,36 @@ +using CalamityMod.CalPlayer; +using CalamityMod.Projectiles.Summon; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Buffs.Summon +{ + public class DeathstareBuff : ModBuff + { + public override void SetDefaults() + { + DisplayName.SetDefault("Miniature Eye of Cthulhu"); + Description.SetDefault("It's watching you"); + Main.buffNoTimeDisplay[Type] = true; + Main.buffNoSave[Type] = true; + } + + public override void Update(Player player, ref int buffIndex) + { + CalamityPlayer modPlayer = player.Calamity(); + if (player.ownedProjectileCounts[ModContent.ProjectileType()] > 0) + { + modPlayer.deathstareEyeball = true; + } + if (!modPlayer.deathstareEyeball) + { + player.DelBuff(buffIndex); + buffIndex--; + } + else + { + player.buffTime[buffIndex] = 18000; + } + } + } +} diff --git a/Buffs/Summon/DeathstareBuff.png b/Buffs/Summon/DeathstareBuff.png new file mode 100644 index 0000000000..eaf73dcf4e Binary files /dev/null and b/Buffs/Summon/DeathstareBuff.png differ diff --git a/Buffs/Summon/EyeOfNightBuff.cs b/Buffs/Summon/EyeOfNightBuff.cs new file mode 100644 index 0000000000..db3f86b42b --- /dev/null +++ b/Buffs/Summon/EyeOfNightBuff.cs @@ -0,0 +1,34 @@ +using CalamityMod.CalPlayer; +using CalamityMod.Projectiles.Summon; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Buffs.Summon +{ + public class EyeOfNightBuff : ModBuff + { + public override void SetDefaults() + { + DisplayName.SetDefault("Eye of Night"); + Description.SetDefault("It eerily watches"); + Main.buffNoTimeDisplay[Type] = true; + Main.buffNoSave[Type] = true; + //Main.persistentBuff[Type] = true; + } + + public override void Update(Player player, ref int buffIndex) + { + CalamityPlayer modPlayer = player.Calamity(); + if (player.ownedProjectileCounts[ModContent.ProjectileType()] > 0) + modPlayer.eyeOfNight = true; + + if (modPlayer.eyeOfNight) + player.buffTime[buffIndex] = 18000; + else + { + player.DelBuff(buffIndex); + buffIndex--; + } + } + } +} diff --git a/Buffs/Summon/EyeOfNightBuff.png b/Buffs/Summon/EyeOfNightBuff.png new file mode 100644 index 0000000000..e4f07e8ac0 Binary files /dev/null and b/Buffs/Summon/EyeOfNightBuff.png differ diff --git a/Buffs/Summon/FleshOfInfidelityBuff.cs b/Buffs/Summon/FleshOfInfidelityBuff.cs new file mode 100644 index 0000000000..fea7a77d87 --- /dev/null +++ b/Buffs/Summon/FleshOfInfidelityBuff.cs @@ -0,0 +1,34 @@ +using CalamityMod.CalPlayer; +using CalamityMod.Projectiles.Summon; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Buffs.Summon +{ + public class FleshOfInfidelityBuff : ModBuff + { + public override void SetDefaults() + { + DisplayName.SetDefault("Flesh Ball"); + Description.SetDefault("Why is it following you?"); + Main.buffNoTimeDisplay[Type] = true; + Main.buffNoSave[Type] = true; + //Main.persistentBuff[Type] = true; + } + + public override void Update(Player player, ref int buffIndex) + { + CalamityPlayer modPlayer = player.Calamity(); + if (player.ownedProjectileCounts[ModContent.ProjectileType()] > 0) + modPlayer.fleshBall = true; + + if (modPlayer.fleshBall) + player.buffTime[buffIndex] = 18000; + else + { + player.DelBuff(buffIndex); + buffIndex--; + } + } + } +} diff --git a/Buffs/Summon/FleshOfInfidelityBuff.png b/Buffs/Summon/FleshOfInfidelityBuff.png new file mode 100644 index 0000000000..5fadbf39f8 Binary files /dev/null and b/Buffs/Summon/FleshOfInfidelityBuff.png differ diff --git a/Buffs/Summon/FlowersOfMortalityBuff.cs b/Buffs/Summon/FlowersOfMortalityBuff.cs new file mode 100644 index 0000000000..a27ece7655 --- /dev/null +++ b/Buffs/Summon/FlowersOfMortalityBuff.cs @@ -0,0 +1,35 @@ +using CalamityMod.CalPlayer; +using CalamityMod.Projectiles.Summon; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Buffs.Summon +{ + public class FlowersOfMortalityBuff : ModBuff + { + public override void SetDefaults() + { + DisplayName.SetDefault("Flowers of Mortality"); + Description.SetDefault("Celestial blossoms surround you"); + Main.buffNoTimeDisplay[Type] = true; + Main.buffNoSave[Type] = true; + } + + public override void Update(Player player, ref int buffIndex) + { + CalamityPlayer modPlayer = player.Calamity(); + if (player.ownedProjectileCounts[ModContent.ProjectileType()] > 0) + modPlayer.flowersOfMortality = true; + + if (!modPlayer.flowersOfMortality) + { + player.DelBuff(buffIndex); + buffIndex--; + } + else + { + player.buffTime[buffIndex] = 18000; + } + } + } +} diff --git a/Buffs/Summon/FlowersOfMortalityBuff.png b/Buffs/Summon/FlowersOfMortalityBuff.png new file mode 100644 index 0000000000..dbba97dc87 Binary files /dev/null and b/Buffs/Summon/FlowersOfMortalityBuff.png differ diff --git a/Buffs/Summon/PerditionBuff.cs b/Buffs/Summon/PerditionBuff.cs new file mode 100644 index 0000000000..1773a82e3e --- /dev/null +++ b/Buffs/Summon/PerditionBuff.cs @@ -0,0 +1,36 @@ +using CalamityMod.CalPlayer; +using CalamityMod.Projectiles.Summon; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Buffs.Summon +{ + public class PerditionBuff : ModBuff + { + public override void SetDefaults() + { + DisplayName.SetDefault("Perdition"); + Description.SetDefault("How unfortunate"); + Main.buffNoTimeDisplay[Type] = true; + Main.buffNoSave[Type] = true; + //Main.persistentBuff[Type] = true; + } + + public override void Update(Player player, ref int buffIndex) + { + CalamityPlayer modPlayer = player.Calamity(); + if (player.ownedProjectileCounts[ModContent.ProjectileType()] > 0) + modPlayer.perditionBeacon = true; + + if (!modPlayer.perditionBeacon) + { + player.DelBuff(buffIndex); + buffIndex--; + } + else + { + player.buffTime[buffIndex] = 18000; + } + } + } +} diff --git a/Buffs/Summon/PerditionBuff.png b/Buffs/Summon/PerditionBuff.png new file mode 100644 index 0000000000..256653f0de Binary files /dev/null and b/Buffs/Summon/PerditionBuff.png differ diff --git a/Buffs/Summon/SageSpiritBuff.cs b/Buffs/Summon/SageSpiritBuff.cs new file mode 100644 index 0000000000..45034d0575 --- /dev/null +++ b/Buffs/Summon/SageSpiritBuff.cs @@ -0,0 +1,34 @@ +using CalamityMod.CalPlayer; +using CalamityMod.Projectiles.Summon; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Buffs.Summon +{ + public class SageSpiritBuff : ModBuff + { + public override void SetDefaults() + { + DisplayName.SetDefault("Sage Spirit"); + Description.SetDefault("It's uncomfortably close"); + Main.buffNoTimeDisplay[Type] = true; + Main.buffNoSave[Type] = true; + //Main.persistentBuff[Type] = true; + } + + public override void Update(Player player, ref int buffIndex) + { + CalamityPlayer modPlayer = player.Calamity(); + if (player.ownedProjectileCounts[ModContent.ProjectileType()] > 0) + modPlayer.sageSpirit = true; + + if (modPlayer.sageSpirit) + player.buffTime[buffIndex] = 18000; + else + { + player.DelBuff(buffIndex); + buffIndex--; + } + } + } +} diff --git a/Buffs/Summon/SageSpiritBuff.png b/Buffs/Summon/SageSpiritBuff.png new file mode 100644 index 0000000000..6f96cea427 Binary files /dev/null and b/Buffs/Summon/SageSpiritBuff.png differ diff --git a/Buffs/Summon/SepulcherMinionBuff.cs b/Buffs/Summon/SepulcherMinionBuff.cs new file mode 100644 index 0000000000..34910472ba --- /dev/null +++ b/Buffs/Summon/SepulcherMinionBuff.cs @@ -0,0 +1,36 @@ +using CalamityMod.CalPlayer; +using CalamityMod.Projectiles.Summon; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Buffs.Summon +{ + public class SepulcherMinionBuff : ModBuff + { + public override void SetDefaults() + { + DisplayName.SetDefault("Sepulcher"); + Description.SetDefault("It is not benevolent"); + Main.buffNoTimeDisplay[Type] = true; + Main.buffNoSave[Type] = true; + //Main.persistentBuff[Type] = true; + } + + public override void Update(Player player, ref int buffIndex) + { + CalamityPlayer modPlayer = player.Calamity(); + if (player.ownedProjectileCounts[ModContent.ProjectileType()] > 0) + modPlayer.sepulcher = true; + + if (!modPlayer.sepulcher) + { + player.DelBuff(buffIndex); + buffIndex--; + } + else + { + player.buffTime[buffIndex] = 18000; + } + } + } +} diff --git a/Buffs/Summon/SepulcherMinionBuff.png b/Buffs/Summon/SepulcherMinionBuff.png new file mode 100644 index 0000000000..5eeae4fa2b Binary files /dev/null and b/Buffs/Summon/SepulcherMinionBuff.png differ diff --git a/Buffs/Summon/SoulSeekerBuff.cs b/Buffs/Summon/SoulSeekerBuff.cs new file mode 100644 index 0000000000..e552084a4b --- /dev/null +++ b/Buffs/Summon/SoulSeekerBuff.cs @@ -0,0 +1,35 @@ +using CalamityMod.CalPlayer; +using CalamityMod.Projectiles.Summon; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Buffs.Summon +{ + public class SoulSeekerBuff : ModBuff + { + public override void SetDefaults() + { + DisplayName.SetDefault("Soul Seeker"); + Description.SetDefault("It definitely wants something from you"); + Main.buffNoTimeDisplay[Type] = true; + Main.buffNoSave[Type] = true; + } + + public override void Update(Player player, ref int buffIndex) + { + CalamityPlayer modPlayer = player.Calamity(); + if (player.ownedProjectileCounts[ModContent.ProjectileType()] > 0) + modPlayer.soulSeeker = true; + + if (!modPlayer.soulSeeker) + { + player.DelBuff(buffIndex); + buffIndex--; + } + else + { + player.buffTime[buffIndex] = 18000; + } + } + } +} diff --git a/Buffs/Summon/SoulSeekerBuff.png b/Buffs/Summon/SoulSeekerBuff.png new file mode 100644 index 0000000000..fe6b96bed3 Binary files /dev/null and b/Buffs/Summon/SoulSeekerBuff.png differ diff --git a/Buffs/Summon/ViridVanguardBuff.cs b/Buffs/Summon/ViridVanguardBuff.cs new file mode 100644 index 0000000000..ef7f387078 --- /dev/null +++ b/Buffs/Summon/ViridVanguardBuff.cs @@ -0,0 +1,36 @@ +using CalamityMod.CalPlayer; +using CalamityMod.Projectiles.Summon; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Buffs.Summon +{ + public class ViridVanguardBuff : ModBuff + { + public override void SetDefaults() + { + DisplayName.SetDefault("Virid Vanguard"); + Description.SetDefault("A perfect act of unity surrounds you"); + Main.buffNoTimeDisplay[Type] = true; + Main.buffNoSave[Type] = true; + } + + public override void Update(Player player, ref int buffIndex) + { + CalamityPlayer modPlayer = player.Calamity(); + if (player.ownedProjectileCounts[ModContent.ProjectileType()] > 0) + { + modPlayer.viridVanguard = true; + } + if (!modPlayer.viridVanguard) + { + player.DelBuff(buffIndex); + buffIndex--; + } + else + { + player.buffTime[buffIndex] = 18000; + } + } + } +} diff --git a/Buffs/Summon/ViridVanguardBuff.png b/Buffs/Summon/ViridVanguardBuff.png new file mode 100644 index 0000000000..5a824b9ddd Binary files /dev/null and b/Buffs/Summon/ViridVanguardBuff.png differ diff --git a/Buffs/Summon/WitherBlossomsBuff.cs b/Buffs/Summon/WitherBlossomsBuff.cs new file mode 100644 index 0000000000..2518bc18a0 --- /dev/null +++ b/Buffs/Summon/WitherBlossomsBuff.cs @@ -0,0 +1,35 @@ +using CalamityMod.CalPlayer; +using CalamityMod.Projectiles.Summon; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Buffs.Summon +{ + public class WitherBlossomsBuff : ModBuff + { + public override void SetDefaults() + { + DisplayName.SetDefault("Wither Blossoms"); + Description.SetDefault("Pestilence surrounds you"); + Main.buffNoTimeDisplay[Type] = true; + Main.buffNoSave[Type] = true; + } + + public override void Update(Player player, ref int buffIndex) + { + CalamityPlayer modPlayer = player.Calamity(); + if (player.ownedProjectileCounts[ModContent.ProjectileType()] > 0) + modPlayer.witherBlossom = true; + + if (!modPlayer.witherBlossom) + { + player.DelBuff(buffIndex); + buffIndex--; + } + else + { + player.buffTime[buffIndex] = 18000; + } + } + } +} diff --git a/Buffs/Summon/WitherBlossomsBuff.png b/Buffs/Summon/WitherBlossomsBuff.png new file mode 100644 index 0000000000..334f026255 Binary files /dev/null and b/Buffs/Summon/WitherBlossomsBuff.png differ diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index fa2574d6a7..280eac5611 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -31,6 +31,7 @@ using CalamityMod.NPCs.DevourerofGods; using CalamityMod.NPCs.GreatSandShark; using CalamityMod.NPCs.Leviathan; using CalamityMod.NPCs.NormalNPCs; +using CalamityMod.NPCs.Other; using CalamityMod.NPCs.PlaguebringerGoliath; using CalamityMod.NPCs.PlagueEnemies; using CalamityMod.NPCs.Polterghast; @@ -117,7 +118,11 @@ namespace CalamityMod.CalPlayer public int defenseDamage = 0; public float rangedAmmoCost = 1f; public bool heldGaelsLastFrame = false; + public bool blazingMouseDamageEffects = false; + public bool ableToDrawBlazingMouse = false; + public float blazingMouseAuraFade = 0f; public float GeneralScreenShakePower = 0f; + public bool GivenBrimstoneLocus = false; #endregion #region Tile Entity Trackers @@ -157,6 +162,7 @@ namespace CalamityMod.CalPlayer public bool newCirrusInventory = false; public bool newAmidiasInventory = false; public bool newBanditInventory = false; + public bool newCalamitasInventory = false; #endregion #region Stat Meter @@ -278,6 +284,7 @@ namespace CalamityMod.CalPlayer public float rogueStealthMax = 0f; public float stealthGenStandstill = 1f; public float stealthGenMoving = 1f; + public int flatStealthLossReduction = 0; public const float StealthAccelerationCap = 2f; public float stealthAcceleration = 1f; public bool stealthStrikeThisFrame = false; @@ -579,6 +586,7 @@ namespace CalamityMod.CalPlayer public int roverDriveTimer = 0; public int roverFrameCounter = 0; public int roverFrame = 0; + public bool rottenDogTooth = false; public bool angelicAlliance = false; public int angelicActivate = -1; #endregion @@ -718,6 +726,7 @@ namespace CalamityMod.CalPlayer public bool aCrunch = false; public bool irradiated = false; public bool bFlames = false; + public bool weakBrimstoneFlames = false; public bool aFlames = false; public bool gsInferno = false; public bool astralInfection = false; @@ -931,6 +940,18 @@ namespace CalamityMod.CalPlayer public bool plaguebringerPatronSummon = false; public bool howlTrio = false; public bool mountedScanner = false; + public bool sepulcher = false; + public bool daedalusGolem = false; + public bool deathstareEyeball = false; + public bool witherBlossom = false; + public bool flowersOfMortality = false; + public bool viridVanguard = false; + public bool sageSpirit = false; + public bool fleshBall = false; + public bool eyeOfNight = false; + public bool soulSeeker = false; + public bool perditionBeacon = false; + public List PendingProjectilesToRespawn = new List(); // Due to the way vanilla summons work, the buff must be applied manually for it to properly register, since @@ -1004,6 +1025,27 @@ namespace CalamityMod.CalPlayer public bool omegaBlueTransformationPower; #endregion + #region Calamitas Enchant Effects + public bool cursedSummonsEnchant = false; + public bool flamingItemEnchant = false; + public bool lifeManaEnchant = false; + public bool farProximityRewardEnchant = false; + public bool closeProximityRewardEnchant = false; + public bool dischargingItemEnchant = false; + public bool explosiveMinionsEnchant = false; + public bool bladeArmEnchant = false; + public bool manaMonsterEnchant = false; + + public bool witheringWeaponEnchant = false; + public bool witheredDebuff = false; + public int witheredWeaponHoldTime = 0; + + public bool persecutedEnchant = false; + public int persecutedEnchantSummonTimer = 0; + + public bool lecherousOrbEnchant = false; + #endregion Calamitas Enchant Effects + #endregion #region SavingAndLoading @@ -1051,6 +1093,7 @@ namespace CalamityMod.CalPlayer newCirrusInventory = false; newAmidiasInventory = false; newBanditInventory = false; + newCalamitasInventory = false; } public override TagCompound Save() @@ -1099,6 +1142,8 @@ namespace CalamityMod.CalPlayer boost.AddWithCondition("newCirrusInventory", newCirrusInventory); boost.AddWithCondition("newAmidiasInventory", newAmidiasInventory); boost.AddWithCondition("newBanditInventory", newBanditInventory); + boost.AddWithCondition("newCalamitasInventory", newCalamitasInventory); + boost.AddWithCondition("GivenBrimstoneLocus", GivenBrimstoneLocus); return new TagCompound { @@ -1174,6 +1219,8 @@ namespace CalamityMod.CalPlayer newCirrusInventory = boost.Contains("newCirrusInventory"); newAmidiasInventory = boost.Contains("newAmidiasInventory"); newBanditInventory = boost.Contains("newBanditInventory"); + newCalamitasInventory = boost.Contains("newCalamitasInventory"); + GivenBrimstoneLocus = boost.Contains("GivenBrimstoneLocus"); // Load rage from "stress" if this is an older save. Otherwise load it from "rage", its new name. if (tag.ContainsKey("stress")) @@ -1307,8 +1354,9 @@ namespace CalamityMod.CalPlayer BitsByte flags6 = reader.ReadByte(); newBanditInventory = flags6[0]; - finalTierAccessoryReforge = flags6[1]; - } + finalTierAccessoryReforge = flags6[1]; + newCalamitasInventory = flags6[2]; + } else { ModContent.GetInstance().Logger.Error("Unknown loadVersion: " + loadVersion); @@ -1493,6 +1541,8 @@ namespace CalamityMod.CalPlayer noWings = false; blockAllDashes = false; + blazingMouseDamageEffects = false; + ableToDrawBlazingMouse = false; luxorsGift = false; fungalSymbiote = false; @@ -1610,6 +1660,7 @@ namespace CalamityMod.CalPlayer noStupidNaturalARSpawns = false; burdenBreakerYeet = false; roverDrive = false; + rottenDogTooth = false; angelicAlliance = false; daedalusReflect = false; @@ -1735,6 +1786,7 @@ namespace CalamityMod.CalPlayer aCrunch = false; irradiated = false; bFlames = false; + weakBrimstoneFlames = false; aFlames = false; gsInferno = false; astralInfection = false; @@ -1953,6 +2005,17 @@ namespace CalamityMod.CalPlayer plaguebringerPatronSummon = false; howlTrio = false; mountedScanner = false; + sepulcher = false; + daedalusGolem = false; + deathstareEyeball = false; + witherBlossom = false; + flowersOfMortality = false; + viridVanguard = false; + sageSpirit = false; + fleshBall = false; + eyeOfNight = false; + soulSeeker = false; + perditionBeacon = false; abyssalDivingSuitPrevious = abyssalDivingSuit; abyssalDivingSuit = abyssalDivingSuitHide = abyssalDivingSuitForce = abyssalDivingSuitPower = false; @@ -1977,7 +2040,23 @@ namespace CalamityMod.CalPlayer RageDuration = DefaultRageDuration; RageDamageBoost = DefaultRageDamageBoost; + cursedSummonsEnchant = false; + flamingItemEnchant = false; + lifeManaEnchant = false; + farProximityRewardEnchant = false; + closeProximityRewardEnchant = false; + dischargingItemEnchant = false; + explosiveMinionsEnchant = false; + bladeArmEnchant = false; + manaMonsterEnchant = false; + witheringWeaponEnchant = false; + persecutedEnchant = false; + lecherousOrbEnchant = false; + flatStealthLossReduction = 0; + lastProjectileHit = null; + + CalamityPlayerMiscEffects.EnchantHeldItemEffects(player, player.Calamity(), player.ActiveItem()); } #endregion @@ -2087,6 +2166,7 @@ namespace CalamityMod.CalPlayer aCrunch = false; irradiated = false; bFlames = false; + weakBrimstoneFlames = false; aFlames = false; gsInferno = false; astralInfection = false; @@ -2381,6 +2461,7 @@ namespace CalamityMod.CalPlayer animusBoost = 1f; potionTimer = 0; bloodflareCoreLostDefense = 0; + persecutedEnchantSummonTimer = 0; if (BossRushEvent.BossRushActive) { @@ -4371,7 +4452,7 @@ namespace CalamityMod.CalPlayer else damageSource = PlayerDeathReason.ByCustomReason(player.name + "'s lungs collapsed."); } - if (bFlames || aFlames) + if (bFlames || aFlames || weakBrimstoneFlames) { damageSource = PlayerDeathReason.ByCustomReason(player.name + " was consumed by the black flames."); } @@ -4517,7 +4598,7 @@ namespace CalamityMod.CalPlayer else acidRoundMultiplier = 1D; - //Prismatic Breaker is a weird hybrid melee-ranged weapon so include it too. Why are you using desert prowler post-Yharon? don't ask me + // Prismatic Breaker is a weird hybrid melee-ranged weapon so include it too. Why are you using desert prowler post-Yharon? don't ask me if (desertProwler && (item.ranged || item.type == ModContent.ItemType()) && item.ammo == AmmoID.None) flat += 1f; } @@ -6832,6 +6913,12 @@ namespace CalamityMod.CalPlayer #region Shoot public override bool Shoot(Item item, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) { + if (bladeArmEnchant) + return false; + + if (rottenDogTooth && item.Calamity().rogue && item.type != ModContent.ItemType()) + damage = (int)(damage * (1f + RottenDogtooth.StealthStrikeDamageMultiplier)); + if (veneratedLocket) { if (item.Calamity().rogue && item.type != ModContent.ItemType()) @@ -7263,6 +7350,15 @@ namespace CalamityMod.CalPlayer if (player.whoAmI == Main.myPlayer) { + // Summon a portal if needed. + if (player.Calamity().persecutedEnchant && NPC.CountNPCS(ModContent.NPCType()) < 2) + { + Vector2 spawnPosition = player.Center + Main.rand.NextVector2Unit() * Main.rand.NextFloat(270f, 420f); + int portal = NPC.NewNPC((int)spawnPosition.X, (int)spawnPosition.Y, ModContent.NPCType()); + if (Main.npc.IndexInRange(portal)) + Main.npc[portal].target = player.whoAmI; + } + if (revivify) { int healAmt = (int)(damage / 15D); @@ -9479,20 +9575,21 @@ namespace CalamityMod.CalPlayer stealthStrikeThisFrame = true; stealthAcceleration = 1f; // Reset acceleration when you attack + float lossReductionRatio = flatStealthLossReduction / (rogueStealthMax * 100f); if (stealthStrikeHalfCost) { - rogueStealth -= 0.5f * rogueStealthMax; + rogueStealth -= 0.5f * rogueStealthMax - lossReductionRatio; if (rogueStealth <= 0f) rogueStealth = 0f; } else if (stealthStrike75Cost) - { - rogueStealth -= 0.75f * rogueStealthMax; + { + rogueStealth -= 0.75f * rogueStealthMax - lossReductionRatio; if (rogueStealth <= 0f) rogueStealth = 0f; } - else - rogueStealth = 0f; + else + rogueStealth = lossReductionRatio; } #endregion @@ -10623,5 +10720,32 @@ namespace CalamityMod.CalPlayer } #endregion + + #region Mana Consumption Effects + public override void OnConsumeMana(Item item, int manaConsumed) + { + CalamityPlayer modPlayer = player.Calamity(); + if (Main.rand.NextBool(4) && modPlayer.lifeManaEnchant) + { + if (Main.myPlayer == player.whoAmI) + { + player.HealEffect(-5); + player.statLife -= 5; + if (player.statLife <= 0) + player.KillMe(PlayerDeathReason.ByCustomReason($"{player.name} converted all of their life to mana."), 1000, -1); + } + + for (int i = 0; i < 8; i++) + { + Dust life = Dust.NewDustPerfect(player.Top + Main.rand.NextVector2Circular(player.width * 0.5f, 6f), 267); + life.color = Color.Red; + life.velocity = -Vector2.UnitY.RotatedByRandom(0.48f) * Main.rand.NextFloat(3f, 4.4f); + life.scale = Main.rand.NextFloat(1.5f, 1.72f); + life.fadeIn = 0.7f; + life.noGravity = true; + } + } + } + #endregion } } diff --git a/CalPlayer/CalamityPlayerLifeRegen.cs b/CalPlayer/CalamityPlayerLifeRegen.cs index 5eaaf80cc2..3dfb8137f3 100644 --- a/CalPlayer/CalamityPlayerLifeRegen.cs +++ b/CalPlayer/CalamityPlayerLifeRegen.cs @@ -2,10 +2,10 @@ using CalamityMod.Buffs.Alcohol; using CalamityMod.Buffs.DamageOverTime; using CalamityMod.Dusts; using CalamityMod.Events; -using CalamityMod.Projectiles.Healing; using CalamityMod.Projectiles.Ranged; using CalamityMod.World; using Microsoft.Xna.Framework; +using System; using Terraria; using Terraria.ModLoader; @@ -95,6 +95,15 @@ namespace CalamityMod.CalPlayer lifeRegenLost += 16; } + if (modPlayer.weakBrimstoneFlames) + { + if (player.lifeRegen > 0) + player.lifeRegen = 0; + + player.lifeRegenTime = 0; + lifeRegenLost += 5; + } + if (modPlayer.bFlames) { if (player.lifeRegen > 0) @@ -400,7 +409,23 @@ namespace CalamityMod.CalPlayer if (player.lifeRegen > 0) player.lifeRegen = 0; lifeRegenLost += 42; //the meaning of death - } + } + if (modPlayer.witheredDebuff) + { + modPlayer.witheredWeaponHoldTime += modPlayer.witheringWeaponEnchant.ToDirectionInt(); + if (modPlayer.witheredWeaponHoldTime < 0) + { + modPlayer.witheredWeaponHoldTime = 0; + } + else + { + lifeRegenLost += (int)(4D * Math.Pow(1.5D, modPlayer.witheredWeaponHoldTime / 87D)); + if (player.lifeRegen > 0) + player.lifeRegen = 0; + } + } + else + modPlayer.witheredWeaponHoldTime = 0; player.lifeRegen -= (int)(lifeRegenLost * lifeRegenMult); @@ -653,6 +678,11 @@ namespace CalamityMod.CalPlayer player.lifeRegenTime += 1; player.lifeRegen += 2; } + else if (modPlayer.rOoze) + { + if (!Main.dayTime) + player.lifeRegen += 4; + } if (modPlayer.ursaSergeant) { diff --git a/CalPlayer/CalamityPlayerMiscEffects.cs b/CalPlayer/CalamityPlayerMiscEffects.cs index e51794a7be..3527592c6a 100644 --- a/CalPlayer/CalamityPlayerMiscEffects.cs +++ b/CalPlayer/CalamityPlayerMiscEffects.cs @@ -8,6 +8,7 @@ using CalamityMod.Buffs.Summon; using CalamityMod.CustomRecipes; using CalamityMod.Dusts; using CalamityMod.Events; +using CalamityMod.Items; using CalamityMod.Items.Accessories; using CalamityMod.Items.Armor; using CalamityMod.Items.DraedonMisc; @@ -23,6 +24,7 @@ using CalamityMod.NPCs.AcidRain; using CalamityMod.NPCs.Astral; using CalamityMod.NPCs.Crags; using CalamityMod.NPCs.NormalNPCs; +using CalamityMod.NPCs.Other; using CalamityMod.NPCs.PlagueEnemies; using CalamityMod.NPCs.SupremeCalamitas; using CalamityMod.Projectiles.Boss; @@ -78,6 +80,10 @@ namespace CalamityMod.CalPlayer // Bool for any existing events, true if any event is active CalamityPlayer.areThereAnyDamnEvents = CalamityGlobalNPC.AnyEvents(player); + // Hurt the nearest NPC to the mouse if using the burning mouse. + if (modPlayer.blazingMouseDamageEffects) + HandleBlazingMouseEffects(player, modPlayer); + // Revengeance effects RevengeanceModeMiscEffects(player, modPlayer, mod); @@ -117,6 +123,11 @@ namespace CalamityMod.CalPlayer // Check if schematics are present on the mouse, for the sake of registering their recipes. CheckIfMouseItemIsSchematic(player); + // Update all particle sets for items. + // This must be done here instead of in the item logic because these sets are not properly instanced + // in the global classes. Attempting to update them there will cause multiple updates to one set for multiple items. + CalamityGlobalItem.UpdateAllParticleSets(); + // Regularly sync player stats during multiplayer if (player.whoAmI == Main.myPlayer && Main.netMode == NetmodeID.MultiplayerClient) { @@ -345,7 +356,7 @@ namespace CalamityMod.CalPlayer for (int i = 0; i < Main.maxNPCs; ++i) { NPC npc = Main.npc[i]; - if (npc is null || !npc.IsAnEnemy()) + if (npc is null || !npc.IsAnEnemy() || npc.Calamity().DoesNotGenerateRage) continue; // Take the longer of the two directions for the NPC's hitbox to be generous. @@ -480,8 +491,56 @@ namespace CalamityMod.CalPlayer #endregion #region Misc Effects + + private static void HandleBlazingMouseEffects(Player player, CalamityPlayer modPlayer) + { + Rectangle auraRectangle = Utils.CenteredRectangle(Main.MouseWorld, new Vector2(35f, 62f)); + modPlayer.blazingMouseAuraFade = MathHelper.Clamp(modPlayer.blazingMouseAuraFade - 0.025f, 0.25f, 1f); + for (int i = 0; i < Main.maxNPCs; i++) + { + if (!Main.npc[i].CanBeChasedBy() || !Main.npc[i].Hitbox.Intersects(auraRectangle) || !Main.rand.NextBool(2)) + continue; + + harmNPC(Main.npc[i]); + modPlayer.blazingMouseAuraFade = MathHelper.Clamp(modPlayer.blazingMouseAuraFade + 0.15f, 0.25f, 1f); + } + + void harmNPC(NPC npc) + { + int damage = (int)(player.AverageDamage() * Main.rand.Next(1950, 2050)); + npc.StrikeNPC(damage, 0f, 0); + + player.addDPS(damage); + npc.AddBuff(ModContent.BuffType(), 900); + + for (int i = 0; i < 4; i++) + { + Dust fire = Dust.NewDustDirect(npc.position, npc.width, npc.height, 267); + fire.velocity = Vector2.UnitY * -Main.rand.NextFloat(2f, 3.45f); + fire.scale = 1f + fire.velocity.Length() / 6f; + fire.color = Color.Lerp(Color.Orange, Color.Red, Main.rand.NextFloat(0.85f)); + fire.noGravity = true; + } + } + } + private static void MiscEffects(Player player, CalamityPlayer modPlayer, Mod mod) { + // Do a vanity/social slot check for SCal's expert drop since alternatives to get this working are a pain in the ass to create. + int blazingMouseItem = ModContent.ItemType(); + for (int i = 13; i < 18 + player.extraAccessorySlots; i++) + { + if (player.armor[i].type == blazingMouseItem) + { + modPlayer.ableToDrawBlazingMouse = true; + break; + } + } + + // Dust on hand when holding the phosphorescent gauntlet. + if (player.ActiveItem().type == ModContent.ItemType()) + PhosphorescentGauntletPunches.GenerateDustOnOwnerHand(player); + if (modPlayer.stealthUIAlpha > 0f && (modPlayer.rogueStealth <= 0f || modPlayer.rogueStealthMax <= 0f)) { modPlayer.stealthUIAlpha -= 0.035f; @@ -1184,6 +1243,19 @@ namespace CalamityMod.CalPlayer modPlayer.aBulwarkRareTimer--; if (modPlayer.hellbornBoost > 0) modPlayer.hellbornBoost--; + if (modPlayer.persecutedEnchantSummonTimer < 1800) + modPlayer.persecutedEnchantSummonTimer++; + else + { + modPlayer.persecutedEnchantSummonTimer = 0; + if (Main.myPlayer == player.whoAmI && player.Calamity().persecutedEnchant && NPC.CountNPCS(ModContent.NPCType()) < 2) + { + Vector2 spawnPosition = player.Center + Main.rand.NextVector2Unit() * Main.rand.NextFloat(270f, 420f); + int portal = NPC.NewNPC((int)spawnPosition.X, (int)spawnPosition.Y, ModContent.NPCType()); + if (Main.npc.IndexInRange(portal)) + Main.npc[portal].target = player.whoAmI; + } + } if (player.miscCounter % 20 == 0) modPlayer.canFireAtaxiaRangedProjectile = true; if (player.miscCounter % 100 == 0) @@ -1407,11 +1479,14 @@ namespace CalamityMod.CalPlayer // Ambrosial Ampoule bonus and other light-granting bonuses float[] light = new float[3]; - if (modPlayer.aAmpoule) + if ((modPlayer.rOoze && !Main.dayTime) || modPlayer.aAmpoule) { light[0] += 1f; light[1] += 1f; light[2] += 0.6f; + } + if (modPlayer.aAmpoule) + { player.endurance += 0.05f; player.pickSpeed -= 0.25f; player.buffImmune[BuffID.Venom] = true; @@ -2032,6 +2107,43 @@ namespace CalamityMod.CalPlayer } #endregion + #region Calamitas Enchantment Held Item Effects + public static void EnchantHeldItemEffects(Player player, CalamityPlayer modPlayer, Item heldItem) + { + if (heldItem.IsAir) + return; + + // Exhaustion recharge effects. + foreach (Item item in player.inventory) + { + if (item.IsAir) + continue; + + if (item.Calamity().AppliedEnchantment.HasValue && item.Calamity().AppliedEnchantment.Value.ID == 600) + { + // Initialize the exhaustion if it is currently not defined. + if (item.Calamity().DischargeEnchantExhaustion <= 0f) + item.Calamity().DischargeEnchantExhaustion = CalamityGlobalItem.DischargeEnchantExhaustionCap; + + // Slowly recharge the weapon over time. This is depleted when the item is actaully used. + else if (item.Calamity().DischargeEnchantExhaustion < CalamityGlobalItem.DischargeEnchantExhaustionCap) + item.Calamity().DischargeEnchantExhaustion++; + } + else + item.Calamity().DischargeEnchantExhaustion = 0f; + } + + if (!heldItem.Calamity().AppliedEnchantment.HasValue || heldItem.Calamity().AppliedEnchantment.Value.HoldEffect is null) + return; + + heldItem.Calamity().AppliedEnchantment.Value.HoldEffect(player); + + // Weak brimstone flame hold curse effect. + if (modPlayer.flamingItemEnchant) + player.AddBuff(ModContent.BuffType(), 10); + } + #endregion + #region Max Life And Mana Effects private static void MaxLifeAndManaEffects(Player player, CalamityPlayer modPlayer, Mod mod) { diff --git a/CalamityLists.cs b/CalamityLists.cs index 3ee41bc8d8..35c3d0dab9 100644 --- a/CalamityLists.cs +++ b/CalamityLists.cs @@ -358,7 +358,8 @@ namespace CalamityMod ProjectileType(), ProjectileType(), ProjectileType(), - ProjectileType() + ProjectileType(), + ProjectileType() }; rangedProjectileExceptionList = new List() @@ -423,13 +424,16 @@ namespace CalamityMod ProjectileType(), ProjectileType(), ProjectileType(), - // ProjectileType(), // TODO: ADD THE APOTHEOSIS WORM HERE LATER. IT IS IN A DIFFERENT BRANCH AS OF WRITING THIS. + ProjectileType(), ProjectileType(), ProjectileType(), ProjectileType(), ProjectileType(), ProjectileType(), + ProjectileType(), + ProjectileType(), + ProjectileType(), //Some hostile boss projectiles ProjectileType(), diff --git a/CalamityMod.cs b/CalamityMod.cs index f053c6b1b6..c5b74d0c99 100644 --- a/CalamityMod.cs +++ b/CalamityMod.cs @@ -42,6 +42,7 @@ using CalamityMod.Schematics; using CalamityMod.Skies; using CalamityMod.TileEntities; using CalamityMod.UI; +using CalamityMod.UI.CalamitasEnchants; using CalamityMod.World; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -187,6 +188,7 @@ namespace CalamityMod BossHealthBarManager.Load(this); DraedonStructures.Load(); CalamityLists.LoadLists(); + EnchantmentManager.LoadAllEnchantments(); SetupVanillaDR(); SetupBossKillTimes(); SetupBossVelocityScalingValues(); @@ -322,6 +324,7 @@ namespace CalamityMod bossVelocityDamageScaleValues?.Clear(); bossVelocityDamageScaleValues = null; + EnchantmentManager.UnloadAllEnchantments(); CalamityLists.UnloadLists(); NPCStats.Unload(); @@ -549,7 +552,7 @@ namespace CalamityMod { ModContent.NPCType(), 7200 }, { ModContent.NPCType(), 10800 }, { ModContent.NPCType(), 1200 }, - { ModContent.NPCType(), 11400 }, + { ModContent.NPCType(), 13200 }, { ModContent.NPCType(), 10800 }, { ModContent.NPCType(), 10800 }, { ModContent.NPCType(), 10800 }, @@ -901,11 +904,17 @@ namespace CalamityMod return true; }, InterfaceScaleType.None)); + // Calamitas Enchantment UI + layers.Insert(mouseIndex, new LegacyGameInterfaceLayer("Calamitas Enchantment", () => + { + CalamitasEnchantUI.Draw(Main.spriteBatch); + return true; + }, InterfaceScaleType.None)); + // Codebreaker UI. layers.Insert(mouseIndex, new LegacyGameInterfaceLayer("Codebreaker Decryption GUI", () => { DraedonDecryptUI.Draw(Main.spriteBatch); - return true; }, InterfaceScaleType.None)); // Popup GUIs. diff --git a/Effects/BordernadoFire.fx b/Effects/BordernadoFire.fx new file mode 100644 index 0000000000..f21b52ac0d --- /dev/null +++ b/Effects/BordernadoFire.fx @@ -0,0 +1,71 @@ +sampler uImage0 : register(s0); +sampler uImage1 : register(s1); +float3 uColor; +float3 uSecondaryColor; +float uOpacity; +float uSaturation; +float uRotation; +float uTime; +float4 uSourceRect; +float2 uWorldPosition; +float uDirection; +float3 uLightSource; +float2 uImageSize0; +float2 uImageSize1; +matrix uWorldViewProjection; + +struct VertexShaderInput +{ + float4 Position : POSITION0; + float4 Color : COLOR0; + float2 TextureCoordinates : TEXCOORD0; +}; + +struct VertexShaderOutput +{ + float4 Position : SV_POSITION; + float4 Color : COLOR0; + float2 TextureCoordinates : TEXCOORD0; +}; + +VertexShaderOutput VertexShaderFunction(in VertexShaderInput input) +{ + VertexShaderOutput output = (VertexShaderOutput) 0; + float4 pos = mul(input.Position, uWorldViewProjection); + output.Position = pos; + + output.Color = input.Color; + output.TextureCoordinates = input.TextureCoordinates; + + return output; +} + +// The X coordinate is the trail completion, the Y coordinate is the same as any other. +// This is simply how the primitive TextCoord is layed out in the C# code. +float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0 +{ + float4 color = input.Color; + float2 coords = input.TextureCoordinates; + + // Read the fade map as a streak. + float4 fadeMapColor = tex2D(uImage1, float2(frac(coords.y + cos(uTime) * 0.01), frac(coords.x - uTime * 1.4 * uSaturation))); + fadeMapColor.r *= pow(coords.x, 0.2); + + float opacity = lerp(1.45, 1.95, fadeMapColor.r) * color.a; + opacity *= pow(sin(coords.y * 3.141), lerp(1, 4, pow(coords.x, 2))); + opacity *= fadeMapColor.r * 1.5 + 1; + opacity *= lerp(0.4, 0.9, fadeMapColor.r); + + float3 transformColor = lerp(float3(1, 205 / 255.0, 119 / 255.0), float3(1, 76 / 255.0, 79 / 255.0), fadeMapColor.r); + color.rgb = lerp(color.rgb, transformColor, fadeMapColor.r); + return color * opacity * 1.6; +} + +technique Technique1 +{ + pass TrailPass + { + VertexShader = compile vs_2_0 VertexShaderFunction(); + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} diff --git a/Effects/BordernadoFire.xnb b/Effects/BordernadoFire.xnb new file mode 100644 index 0000000000..2d0ac3b0dc Binary files /dev/null and b/Effects/BordernadoFire.xnb differ diff --git a/Effects/CalamityShaders.cs b/Effects/CalamityShaders.cs index 08bbc7f6a6..6fc43d77dc 100644 --- a/Effects/CalamityShaders.cs +++ b/Effects/CalamityShaders.cs @@ -10,10 +10,16 @@ namespace CalamityMod.Effects { public static Effect AstralFogShader; public static Effect LightShader; + public static Effect SCalMouseShader; public static Effect TentacleShader; public static Effect LightDistortionShader; + public static Effect PhaseslayerRipShader; public static Effect FadedUVMapStreakShader; public static Effect FlameStreakShader; + public static Effect FadingSolidTrailShader; + public static Effect ScarletDevilShader; + public static Effect BordernadoFireShader; + public static Effect PrismCrystalShader; public static Effect SCalShieldShader; public static void LoadShaders() @@ -23,9 +29,15 @@ namespace CalamityMod.Effects AstralFogShader = CalamityMod.Instance.GetEffect("Effects/CustomShader"); LightShader = CalamityMod.Instance.GetEffect("Effects/LightBurstShader"); TentacleShader = CalamityMod.Instance.GetEffect("Effects/TentacleShader"); + SCalMouseShader = CalamityMod.Instance.GetEffect("Effects/SCalMouseShader"); LightDistortionShader = CalamityMod.Instance.GetEffect("Effects/DistortionShader"); + PhaseslayerRipShader = CalamityMod.Instance.GetEffect("Effects/PhaseslayerRipShader"); + ScarletDevilShader = CalamityMod.Instance.GetEffect("Effects/ScarletDevilStreak"); + BordernadoFireShader = CalamityMod.Instance.GetEffect("Effects/BordernadoFire"); + PrismCrystalShader = CalamityMod.Instance.GetEffect("Effects/PrismCrystalStreak"); FadedUVMapStreakShader = CalamityMod.Instance.GetEffect("Effects/FadedUVMapStreak"); FlameStreakShader = CalamityMod.Instance.GetEffect("Effects/Flame"); + FadingSolidTrailShader = CalamityMod.Instance.GetEffect("Effects/FadingSolidTrail"); SCalShieldShader = CalamityMod.Instance.GetEffect("Effects/SupremeShieldShader"); Filters.Scene["CalamityMod:Astral"] = new Filter(new AstralScreenShaderData(new Ref(AstralFogShader), "AstralPass").UseColor(0.18f, 0.08f, 0.24f), EffectPriority.VeryHigh); @@ -33,10 +45,16 @@ namespace CalamityMod.Effects Filters.Scene["CalamityMod:LightBurst"] = new Filter(new ScreenShaderData(new Ref(LightShader), "BurstPass"), EffectPriority.VeryHigh); Filters.Scene["CalamityMod:LightBurst"].Load(); + GameShaders.Misc["CalamityMod:FireMouse"] = new MiscShaderData(new Ref(SCalMouseShader), "DyePass"); GameShaders.Misc["CalamityMod:SubsumingTentacle"] = new MiscShaderData(new Ref(TentacleShader), "BurstPass"); GameShaders.Misc["CalamityMod:LightDistortion"] = new MiscShaderData(new Ref(LightDistortionShader), "DistortionPass"); + GameShaders.Misc["CalamityMod:PhaseslayerRipEffect"] = new MiscShaderData(new Ref(PhaseslayerRipShader), "TrailPass"); GameShaders.Misc["CalamityMod:TrailStreak"] = new MiscShaderData(new Ref(FadedUVMapStreakShader), "TrailPass"); GameShaders.Misc["CalamityMod:Flame"] = new MiscShaderData(new Ref(FlameStreakShader), "TrailPass"); + GameShaders.Misc["CalamityMod:FadingSolidTrail"] = new MiscShaderData(new Ref(FadingSolidTrailShader), "TrailPass"); + GameShaders.Misc["CalamityMod:OverpoweredTouhouSpearShader"] = new MiscShaderData(new Ref(ScarletDevilShader), "TrailPass"); + GameShaders.Misc["CalamityMod:Bordernado"] = new MiscShaderData(new Ref(BordernadoFireShader), "TrailPass"); + GameShaders.Misc["CalamityMod:PrismaticStreak"] = new MiscShaderData(new Ref(PrismCrystalShader), "TrailPass"); GameShaders.Misc["CalamityMod:SupremeShield"] = new MiscShaderData(new Ref(SCalShieldShader), "ShieldPass"); } } diff --git a/Effects/FabstaffStreak.fx b/Effects/FabstaffStreak.fx new file mode 100644 index 0000000000..497063c9da --- /dev/null +++ b/Effects/FabstaffStreak.fx @@ -0,0 +1,72 @@ +sampler uImage0 : register(s0); +sampler uImage1 : register(s1); +float3 uColor; +float3 uSecondaryColor; +float uOpacity; +float uSaturation; +float uRotation; +float uTime; +float4 uSourceRect; +float2 uWorldPosition; +float uDirection; +float3 uLightSource; +float2 uImageSize0; +float2 uImageSize1; +matrix uWorldViewProjection; + +struct VertexShaderInput +{ + float4 Position : POSITION0; + float4 Color : COLOR0; + float2 TextureCoordinates : TEXCOORD0; +}; + +struct VertexShaderOutput +{ + float4 Position : SV_POSITION; + float4 Color : COLOR0; + float2 TextureCoordinates : TEXCOORD0; +}; + +VertexShaderOutput VertexShaderFunction(in VertexShaderInput input) +{ + VertexShaderOutput output = (VertexShaderOutput)0; + float4 pos = mul(input.Position, uWorldViewProjection); + output.Position = pos; + + output.Color = input.Color; + output.TextureCoordinates = input.TextureCoordinates; + + return output; +} + +// The X coordinate is the trail completion, the Y coordinate is the same as any other. +// This is simply how the primitive TextCoord is layed out in the C# code. +float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0 +{ + float4 color = input.Color; + float2 coords = input.TextureCoordinates; + + // Read the fade map as a streak. + float4 fadeMapColor = tex2D(uImage1, float2(frac(coords.x - uTime * 2.5), coords.y)); + float opacity = fadeMapColor.r; + + // Fade out at the edges of the trail to give a blur effect. + // This is very important. + float power = lerp(3, 10, coords.x); + opacity = lerp(pow(sin(coords.y * 3.141), power), opacity, coords.x); + + // Fade out at the end of the streak. + if (coords.x > 0.7) + opacity *= pow(1 - (coords.x - 0.7) / 0.3, 6); + return color * opacity * 1.5; +} + +technique Technique1 +{ + pass TrailPass + { + VertexShader = compile vs_2_0 VertexShaderFunction(); + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} diff --git a/Effects/FabstaffStreak.xnb b/Effects/FabstaffStreak.xnb new file mode 100644 index 0000000000..45b95d5d3f Binary files /dev/null and b/Effects/FabstaffStreak.xnb differ diff --git a/Effects/FadedUVMapStreak.xnb b/Effects/FadedUVMapStreak.xnb index 45b95d5d3f..fbc7a110ec 100644 Binary files a/Effects/FadedUVMapStreak.xnb and b/Effects/FadedUVMapStreak.xnb differ diff --git a/Effects/FadingSolidTrail.fx b/Effects/FadingSolidTrail.fx new file mode 100644 index 0000000000..5b8427dcff --- /dev/null +++ b/Effects/FadingSolidTrail.fx @@ -0,0 +1,66 @@ +sampler uImage0 : register(s0); +sampler uImage1 : register(s1); +float3 uColor; +float3 uSecondaryColor; +float uOpacity; +float uSaturation; +float uRotation; +float uTime; +float4 uSourceRect; +float2 uWorldPosition; +float uDirection; +float3 uLightSource; +float2 uImageSize0; +float2 uImageSize1; +matrix uWorldViewProjection; +float shouldFlip; + +struct VertexShaderInput +{ + float4 Position : POSITION0; + float4 Color : COLOR0; + float2 TextureCoordinates : TEXCOORD0; +}; + +struct VertexShaderOutput +{ + float4 Position : SV_POSITION; + float4 Color : COLOR0; + float2 TextureCoordinates : TEXCOORD0; +}; + +VertexShaderOutput VertexShaderFunction(in VertexShaderInput input) +{ + VertexShaderOutput output = (VertexShaderOutput)0; + float4 pos = mul(input.Position, uWorldViewProjection); + output.Position = pos; + + output.Color = input.Color; + output.TextureCoordinates = input.TextureCoordinates; + + return output; +} + +// The X coordinate is the trail completion, the Y coordinate is the same as any other. +// This is simply how the primitive TextCoord is layed out in the C# code. +float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0 +{ + float4 color = input.Color; + float2 coords = input.TextureCoordinates; + if (shouldFlip == 1) + coords.y = 1 - coords.y; + + // Read the fade map as a streak. + float4 fadeMapColor = tex2D(uImage1, coords); + float opacity = fadeMapColor.r; + return color * opacity; +} + +technique Technique1 +{ + pass TrailPass + { + VertexShader = compile vs_2_0 VertexShaderFunction(); + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} diff --git a/Effects/FadingSolidTrail.xnb b/Effects/FadingSolidTrail.xnb new file mode 100644 index 0000000000..0d83a614e8 Binary files /dev/null and b/Effects/FadingSolidTrail.xnb differ diff --git a/Effects/PhaseslayerRipShader.fx b/Effects/PhaseslayerRipShader.fx new file mode 100644 index 0000000000..5f2870b13b --- /dev/null +++ b/Effects/PhaseslayerRipShader.fx @@ -0,0 +1,61 @@ +sampler uImage0 : register(s0); +sampler uImage1 : register(s1); +float3 uColor; +float3 uSecondaryColor; +float uOpacity; +float uSaturation; +float uRotation; +float uTime; +float4 uSourceRect; +float2 uWorldPosition; +float uDirection; +float3 uLightSource; +float2 uImageSize0; +float2 uImageSize1; +matrix uWorldViewProjection; + +struct VertexShaderInput +{ + float4 Position : POSITION0; + float4 Color : COLOR0; + float2 TextureCoordinates : TEXCOORD0; +}; + +struct VertexShaderOutput +{ + float4 Position : SV_POSITION; + float4 Color : COLOR0; + float2 TextureCoordinates : TEXCOORD0; +}; + +VertexShaderOutput VertexShaderFunction(in VertexShaderInput input) +{ + VertexShaderOutput output = (VertexShaderOutput)0; + float4 pos = mul(input.Position, uWorldViewProjection); + output.Position = pos; + + output.Color = input.Color; + output.TextureCoordinates = input.TextureCoordinates; + + return output; +} + +// The X coordinate is the trail completion, the Y coordinate is the same as any other. +// This is simply how the primitive TextCoord is layed out in the C# code. +float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0 +{ + float4 color = input.Color; + float2 coords = input.TextureCoordinates; + float slashMapColor = tex2D(uImage1, coords); + float opacity = 1 - slashMapColor.r; + return color * pow(opacity, 3); +} + +technique Technique1 +{ + pass TrailPass + { + VertexShader = compile vs_2_0 VertexShaderFunction(); + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} diff --git a/Effects/PhaseslayerRipShader.xnb b/Effects/PhaseslayerRipShader.xnb new file mode 100644 index 0000000000..02b74566ba Binary files /dev/null and b/Effects/PhaseslayerRipShader.xnb differ diff --git a/Effects/PrismCrystalStreak.fx b/Effects/PrismCrystalStreak.fx new file mode 100644 index 0000000000..8ec86f9cd3 --- /dev/null +++ b/Effects/PrismCrystalStreak.fx @@ -0,0 +1,70 @@ +sampler uImage0 : register(s0); +sampler uImage1 : register(s1); +float3 uColor; +float3 uSecondaryColor; +float uOpacity; +float uSaturation; +float uRotation; +float uTime; +float4 uSourceRect; +float2 uWorldPosition; +float uDirection; +float3 uLightSource; +float2 uImageSize0; +float2 uImageSize1; +matrix uWorldViewProjection; + +struct VertexShaderInput +{ + float4 Position : POSITION0; + float4 Color : COLOR0; + float2 TextureCoordinates : TEXCOORD0; +}; + +struct VertexShaderOutput +{ + float4 Position : SV_POSITION; + float4 Color : COLOR0; + float2 TextureCoordinates : TEXCOORD0; +}; + +VertexShaderOutput VertexShaderFunction(in VertexShaderInput input) +{ + VertexShaderOutput output = (VertexShaderOutput)0; + float4 pos = mul(input.Position, uWorldViewProjection); + output.Position = pos; + + output.Color = input.Color; + output.TextureCoordinates = input.TextureCoordinates; + + return output; +} + +// The X coordinate is the trail completion, the Y coordinate is the same as any other. +// This is simply how the primitive TextCoord is layed out in the C# code. +// Inputted images go into uImage1 sampler, in case you have a noise map or something similar. +float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0 +{ + float4 color = input.Color; + float2 coords = input.TextureCoordinates; + + float areaFadeGlow = lerp(1.2, 17, coords.x); + if (coords.x < 0.25) + areaFadeGlow = lerp(areaFadeGlow, 1.2, 1 - coords.x / 0.25); + float2 mapColor = tex2D(uImage1, float2(frac(coords.x - uTime * 4.2), coords.y)); + float opacity = pow(sin(coords.y * 3.141), areaFadeGlow) + 0.6 * lerp(1.1, 0.3, coords.x) * mapColor.r; + + if (coords.x > 0.66) + opacity = lerp(opacity, 0, (coords.x - 0.66) / 0.3); + + return color * opacity; +} + +technique Technique1 +{ + pass TrailPass + { + VertexShader = compile vs_2_0 VertexShaderFunction(); + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} diff --git a/Effects/PrismCrystalStreak.xnb b/Effects/PrismCrystalStreak.xnb new file mode 100644 index 0000000000..43f330f1f6 Binary files /dev/null and b/Effects/PrismCrystalStreak.xnb differ diff --git a/Effects/SCalMouseShader.fx b/Effects/SCalMouseShader.fx new file mode 100644 index 0000000000..07151bc3b6 --- /dev/null +++ b/Effects/SCalMouseShader.fx @@ -0,0 +1,31 @@ +sampler uImage0 : register(s0); +sampler uImage1 : register(s1); +float3 uColor; +float3 uSecondaryColor; +float uOpacity; +float uSaturation; +float uRotation; +float uTime; +float4 uSourceRect; +float2 uWorldPosition; +float uDirection; +float3 uLightSource; +float2 uImageSize0; +float2 uImageSize1; + +float4 PixelShaderFunction(float4 sampleColor : TEXCOORD, float2 coords : TEXCOORD0) : COLOR0 +{ + float fadeInterpolant = cos(coords.y * coords.x * 6.283 - uTime * 13.1) * 0.5 + 0.5; + + float4 fadeColor = float4(lerp(uColor, uSecondaryColor, fadeInterpolant), 1); + float4 color = tex2D(uImage0, coords) * fadeColor; + color *= 1 + fadeInterpolant * 0.5; + return color; +} +technique Technique1 +{ + pass DyePass + { + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} \ No newline at end of file diff --git a/Effects/SCalMouseShader.xnb b/Effects/SCalMouseShader.xnb new file mode 100644 index 0000000000..a6f0b32b7f Binary files /dev/null and b/Effects/SCalMouseShader.xnb differ diff --git a/Effects/ScarletDevilStreak.fx b/Effects/ScarletDevilStreak.fx new file mode 100644 index 0000000000..b79f4db97e --- /dev/null +++ b/Effects/ScarletDevilStreak.fx @@ -0,0 +1,70 @@ +sampler uImage0 : register(s0); +sampler uImage1 : register(s1); +float3 uColor; +float3 uSecondaryColor; +float uOpacity; +float uSaturation; +float uRotation; +float uTime; +float4 uSourceRect; +float2 uWorldPosition; +float uDirection; +float3 uLightSource; +float2 uImageSize0; +float2 uImageSize1; +matrix uWorldViewProjection; + +struct VertexShaderInput +{ + float4 Position : POSITION0; + float4 Color : COLOR0; + float2 TextureCoordinates : TEXCOORD0; +}; + +struct VertexShaderOutput +{ + float4 Position : SV_POSITION; + float4 Color : COLOR0; + float2 TextureCoordinates : TEXCOORD0; +}; + +VertexShaderOutput VertexShaderFunction(in VertexShaderInput input) +{ + VertexShaderOutput output = (VertexShaderOutput)0; + float4 pos = mul(input.Position, uWorldViewProjection); + output.Position = pos; + + output.Color = input.Color; + output.TextureCoordinates = input.TextureCoordinates; + + return output; +} + +// The X coordinate is the trail completion, the Y coordinate is the same as any other. +// This is simply how the primitive TextCoord is layed out in the C# code. +// Inputted images go into uImage1 sampler, in case you have a noise map or something similar. +float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0 +{ + float4 color = input.Color; + float2 coords = input.TextureCoordinates; + + float areaFadeGlow = lerp(1.2, 17, coords.x); + if (coords.x < 0.25) + areaFadeGlow = lerp(areaFadeGlow, 1.2, 1 - coords.x / 0.25); + float2 mapColor = tex2D(uImage1, float2(frac(coords.x - uTime * 2.5), coords.y)); + float opacity = pow(sin(coords.y * 3.141), areaFadeGlow) + 0.6 * lerp(1.1, 0.3, coords.x) * mapColor.r; + + if (coords.x > 0.66) + opacity = lerp(opacity, 0, (coords.x - 0.66) / 0.3); + + return color * opacity; +} + +technique Technique1 +{ + pass TrailPass + { + VertexShader = compile vs_2_0 VertexShaderFunction(); + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} diff --git a/Effects/ScarletDevilStreak.xnb b/Effects/ScarletDevilStreak.xnb new file mode 100644 index 0000000000..b68ab8631d Binary files /dev/null and b/Effects/ScarletDevilStreak.xnb differ diff --git a/ExtraTextures/BladeTrailUVMap.png b/ExtraTextures/BladeTrailUVMap.png new file mode 100644 index 0000000000..29e4cdac42 Binary files /dev/null and b/ExtraTextures/BladeTrailUVMap.png differ diff --git a/ExtraTextures/CalamityAura.png b/ExtraTextures/CalamityAura.png new file mode 100644 index 0000000000..fddcf00e77 Binary files /dev/null and b/ExtraTextures/CalamityAura.png differ diff --git a/ExtraTextures/EternityStreak.png b/ExtraTextures/EternityStreak.png new file mode 100644 index 0000000000..8b7fcd0246 Binary files /dev/null and b/ExtraTextures/EternityStreak.png differ diff --git a/ExtraTextures/FabstaffStreak.png b/ExtraTextures/FabstaffStreak.png new file mode 100644 index 0000000000..3a05118936 Binary files /dev/null and b/ExtraTextures/FabstaffStreak.png differ diff --git a/ExtraTextures/Lasers/FadeLaserEnd.png b/ExtraTextures/Lasers/FadeLaserEnd.png new file mode 100644 index 0000000000..899fa12378 Binary files /dev/null and b/ExtraTextures/Lasers/FadeLaserEnd.png differ diff --git a/ExtraTextures/Lasers/FadeLaserMid.png b/ExtraTextures/Lasers/FadeLaserMid.png new file mode 100644 index 0000000000..67af476cc0 Binary files /dev/null and b/ExtraTextures/Lasers/FadeLaserMid.png differ diff --git a/ExtraTextures/Lasers/FadeLaserStart.png b/ExtraTextures/Lasers/FadeLaserStart.png new file mode 100644 index 0000000000..0e661a1658 Binary files /dev/null and b/ExtraTextures/Lasers/FadeLaserStart.png differ diff --git a/ExtraTextures/Lasers/PrismLaserEnd.png b/ExtraTextures/Lasers/PrismLaserEnd.png new file mode 100644 index 0000000000..a8079f3418 Binary files /dev/null and b/ExtraTextures/Lasers/PrismLaserEnd.png differ diff --git a/ExtraTextures/Lasers/PrismLaserMid.png b/ExtraTextures/Lasers/PrismLaserMid.png new file mode 100644 index 0000000000..9f45394bd2 Binary files /dev/null and b/ExtraTextures/Lasers/PrismLaserMid.png differ diff --git a/ExtraTextures/Lasers/PrismLaserStart.png b/ExtraTextures/Lasers/PrismLaserStart.png new file mode 100644 index 0000000000..e8c3590839 Binary files /dev/null and b/ExtraTextures/Lasers/PrismLaserStart.png differ diff --git a/ExtraTextures/Lasers/UniverseSplitterHugeBeamEnd.png b/ExtraTextures/Lasers/UniverseSplitterHugeBeamEnd.png new file mode 100644 index 0000000000..4f303c2da1 Binary files /dev/null and b/ExtraTextures/Lasers/UniverseSplitterHugeBeamEnd.png differ diff --git a/ExtraTextures/Lasers/UniverseSplitterHugeBeamMid.png b/ExtraTextures/Lasers/UniverseSplitterHugeBeamMid.png new file mode 100644 index 0000000000..3fea77c900 Binary files /dev/null and b/ExtraTextures/Lasers/UniverseSplitterHugeBeamMid.png differ diff --git a/ExtraTextures/Lasers/UniverseSplitterSmallBeamBegin.png b/ExtraTextures/Lasers/UniverseSplitterSmallBeamBegin.png new file mode 100644 index 0000000000..1f385eb929 Binary files /dev/null and b/ExtraTextures/Lasers/UniverseSplitterSmallBeamBegin.png differ diff --git a/ExtraTextures/Lasers/UniverseSplitterSmallBeamEnd.png b/ExtraTextures/Lasers/UniverseSplitterSmallBeamEnd.png new file mode 100644 index 0000000000..2704d556d4 Binary files /dev/null and b/ExtraTextures/Lasers/UniverseSplitterSmallBeamEnd.png differ diff --git a/ExtraTextures/Lasers/UniverseSplitterSmallBeamMid.png b/ExtraTextures/Lasers/UniverseSplitterSmallBeamMid.png new file mode 100644 index 0000000000..ceb754745d Binary files /dev/null and b/ExtraTextures/Lasers/UniverseSplitterSmallBeamMid.png differ diff --git a/ExtraTextures/Particles/Fire.png b/ExtraTextures/Particles/Fire.png new file mode 100644 index 0000000000..cc76a599b3 Binary files /dev/null and b/ExtraTextures/Particles/Fire.png differ diff --git a/ExtraTextures/Particles/Light.png b/ExtraTextures/Particles/Light.png new file mode 100644 index 0000000000..8e2d2a871c Binary files /dev/null and b/ExtraTextures/Particles/Light.png differ diff --git a/ExtraTextures/ScarletDevilStreak.png b/ExtraTextures/ScarletDevilStreak.png new file mode 100644 index 0000000000..389379b370 Binary files /dev/null and b/ExtraTextures/ScarletDevilStreak.png differ diff --git a/ExtraTextures/SwordSlashTexture.png b/ExtraTextures/SwordSlashTexture.png new file mode 100644 index 0000000000..4bb428f196 Binary files /dev/null and b/ExtraTextures/SwordSlashTexture.png differ diff --git a/ExtraTextures/TaintedArm.png b/ExtraTextures/TaintedArm.png new file mode 100644 index 0000000000..f8796f05e7 Binary files /dev/null and b/ExtraTextures/TaintedArm.png differ diff --git a/ExtraTextures/TaintedForearm.png b/ExtraTextures/TaintedForearm.png new file mode 100644 index 0000000000..09355c363c Binary files /dev/null and b/ExtraTextures/TaintedForearm.png differ diff --git a/ExtraTextures/TaintedHand.png b/ExtraTextures/TaintedHand.png new file mode 100644 index 0000000000..89e494b14c Binary files /dev/null and b/ExtraTextures/TaintedHand.png differ diff --git a/ExtraTextures/TaintedHand2.png b/ExtraTextures/TaintedHand2.png new file mode 100644 index 0000000000..7050006ac8 Binary files /dev/null and b/ExtraTextures/TaintedHand2.png differ diff --git a/ExtraTextures/UI/CalamitasCurseBackground.png b/ExtraTextures/UI/CalamitasCurseBackground.png new file mode 100644 index 0000000000..29555271c1 Binary files /dev/null and b/ExtraTextures/UI/CalamitasCurseBackground.png differ diff --git a/ExtraTextures/UI/CalamitasCurseItemSlot.png b/ExtraTextures/UI/CalamitasCurseItemSlot.png new file mode 100644 index 0000000000..59e813980f Binary files /dev/null and b/ExtraTextures/UI/CalamitasCurseItemSlot.png differ diff --git a/ExtraTextures/UI/CalamitasCurseUI_ArrowDown.png b/ExtraTextures/UI/CalamitasCurseUI_ArrowDown.png new file mode 100644 index 0000000000..055426f728 Binary files /dev/null and b/ExtraTextures/UI/CalamitasCurseUI_ArrowDown.png differ diff --git a/ExtraTextures/UI/CalamitasCurseUI_ArrowDownClicked.png b/ExtraTextures/UI/CalamitasCurseUI_ArrowDownClicked.png new file mode 100644 index 0000000000..21aa985d34 Binary files /dev/null and b/ExtraTextures/UI/CalamitasCurseUI_ArrowDownClicked.png differ diff --git a/ExtraTextures/UI/CalamitasCurseUI_ArrowDownHovered.png b/ExtraTextures/UI/CalamitasCurseUI_ArrowDownHovered.png new file mode 100644 index 0000000000..56352fe81f Binary files /dev/null and b/ExtraTextures/UI/CalamitasCurseUI_ArrowDownHovered.png differ diff --git a/ExtraTextures/UI/CalamitasCurseUI_ArrowUp.png b/ExtraTextures/UI/CalamitasCurseUI_ArrowUp.png new file mode 100644 index 0000000000..7b06ca7dda Binary files /dev/null and b/ExtraTextures/UI/CalamitasCurseUI_ArrowUp.png differ diff --git a/ExtraTextures/UI/CalamitasCurseUI_ArrowUpClicked.png b/ExtraTextures/UI/CalamitasCurseUI_ArrowUpClicked.png new file mode 100644 index 0000000000..fc8bc6b539 Binary files /dev/null and b/ExtraTextures/UI/CalamitasCurseUI_ArrowUpClicked.png differ diff --git a/ExtraTextures/UI/CalamitasCurseUI_ArrowUpHovered.png b/ExtraTextures/UI/CalamitasCurseUI_ArrowUpHovered.png new file mode 100644 index 0000000000..6894e585fc Binary files /dev/null and b/ExtraTextures/UI/CalamitasCurseUI_ArrowUpHovered.png differ diff --git a/ExtraTextures/UI/CalamitasCurseUI_Button.png b/ExtraTextures/UI/CalamitasCurseUI_Button.png new file mode 100644 index 0000000000..42694b1b18 Binary files /dev/null and b/ExtraTextures/UI/CalamitasCurseUI_Button.png differ diff --git a/ExtraTextures/UI/CalamitasCurseUI_ButtonClicked.png b/ExtraTextures/UI/CalamitasCurseUI_ButtonClicked.png new file mode 100644 index 0000000000..c817343035 Binary files /dev/null and b/ExtraTextures/UI/CalamitasCurseUI_ButtonClicked.png differ diff --git a/ExtraTextures/UI/CalamitasCurseUI_ButtonHovered.png b/ExtraTextures/UI/CalamitasCurseUI_ButtonHovered.png new file mode 100644 index 0000000000..3b9ad755f1 Binary files /dev/null and b/ExtraTextures/UI/CalamitasCurseUI_ButtonHovered.png differ diff --git a/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Aflame.png b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Aflame.png new file mode 100644 index 0000000000..8d8c0b27ec Binary files /dev/null and b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Aflame.png differ diff --git a/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Bloodthirsty.png b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Bloodthirsty.png new file mode 100644 index 0000000000..583179b633 Binary files /dev/null and b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Bloodthirsty.png differ diff --git a/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Capricious.png b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Capricious.png new file mode 100644 index 0000000000..9c75e5ba01 Binary files /dev/null and b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Capricious.png differ diff --git a/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Ephemeral.png b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Ephemeral.png new file mode 100644 index 0000000000..5d8f8666be Binary files /dev/null and b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Ephemeral.png differ diff --git a/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Erratic.png b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Erratic.png new file mode 100644 index 0000000000..9d114ac4af Binary files /dev/null and b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Erratic.png differ diff --git a/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Evasive.png b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Evasive.png new file mode 100644 index 0000000000..3969952ddc Binary files /dev/null and b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Evasive.png differ diff --git a/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Evocative.png b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Evocative.png new file mode 100644 index 0000000000..588a10e3b0 Binary files /dev/null and b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Evocative.png differ diff --git a/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Exhumed.png b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Exhumed.png new file mode 100644 index 0000000000..584bd62881 Binary files /dev/null and b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Exhumed.png differ diff --git a/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Hellbound.png b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Hellbound.png new file mode 100644 index 0000000000..96b2a87a02 Binary files /dev/null and b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Hellbound.png differ diff --git a/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Incisive.png b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Incisive.png new file mode 100644 index 0000000000..fe9459ec61 Binary files /dev/null and b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Incisive.png differ diff --git a/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Indignant.png b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Indignant.png new file mode 100644 index 0000000000..526223131e Binary files /dev/null and b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Indignant.png differ diff --git a/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Lecherous.png b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Lecherous.png new file mode 100644 index 0000000000..fcbbe480bb Binary files /dev/null and b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Lecherous.png differ diff --git a/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Oblatory.png b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Oblatory.png new file mode 100644 index 0000000000..f4d86bb62f Binary files /dev/null and b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Oblatory.png differ diff --git a/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Obstinate.png b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Obstinate.png new file mode 100644 index 0000000000..41a740b387 Binary files /dev/null and b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Obstinate.png differ diff --git a/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Persecuted.png b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Persecuted.png new file mode 100644 index 0000000000..d4999cd4ad Binary files /dev/null and b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Persecuted.png differ diff --git a/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Polluted.png b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Polluted.png new file mode 100644 index 0000000000..4edccb5b2b Binary files /dev/null and b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Polluted.png differ diff --git a/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Relentless.png b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Relentless.png new file mode 100644 index 0000000000..df19b8d4c1 Binary files /dev/null and b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Relentless.png differ diff --git a/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Resentful.png b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Resentful.png new file mode 100644 index 0000000000..6259357bb1 Binary files /dev/null and b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Resentful.png differ diff --git a/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Splintered.png b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Splintered.png new file mode 100644 index 0000000000..0f75aff9d7 Binary files /dev/null and b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Splintered.png differ diff --git a/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Tainted.png b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Tainted.png new file mode 100644 index 0000000000..c3b9d97ec5 Binary files /dev/null and b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Tainted.png differ diff --git a/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Traitorous.png b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Traitorous.png new file mode 100644 index 0000000000..9a7f8c7cec Binary files /dev/null and b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Traitorous.png differ diff --git a/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Vindictive.png b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Vindictive.png new file mode 100644 index 0000000000..3a768a4e8e Binary files /dev/null and b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Vindictive.png differ diff --git a/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Withered.png b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Withered.png new file mode 100644 index 0000000000..fd20048613 Binary files /dev/null and b/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Withered.png differ diff --git a/ExtraTextures/UI/ModeIndicatorArea.png b/ExtraTextures/UI/ModeIndicatorArea.png index 701089c3cc..508fe00039 100644 Binary files a/ExtraTextures/UI/ModeIndicatorArea.png and b/ExtraTextures/UI/ModeIndicatorArea.png differ diff --git a/ExtraTextures/UI/ModeIndicatorArma.png b/ExtraTextures/UI/ModeIndicatorArma.png index d5e6ea594e..619f29b4a2 100644 Binary files a/ExtraTextures/UI/ModeIndicatorArma.png and b/ExtraTextures/UI/ModeIndicatorArma.png differ diff --git a/ExtraTextures/UI/ModeIndicatorDeath.png b/ExtraTextures/UI/ModeIndicatorDeath.png index 5cb843a4e0..cdf63aea54 100644 Binary files a/ExtraTextures/UI/ModeIndicatorDeath.png and b/ExtraTextures/UI/ModeIndicatorDeath.png differ diff --git a/ExtraTextures/UI/ModeIndicatorMalice.png b/ExtraTextures/UI/ModeIndicatorMalice.png new file mode 100644 index 0000000000..c19e5c029e Binary files /dev/null and b/ExtraTextures/UI/ModeIndicatorMalice.png differ diff --git a/ExtraTextures/UI/ModeIndicatorRev.png b/ExtraTextures/UI/ModeIndicatorRev.png index b1209d63f8..6086ff88b7 100644 Binary files a/ExtraTextures/UI/ModeIndicatorRev.png and b/ExtraTextures/UI/ModeIndicatorRev.png differ diff --git a/ExtraTextures/UI/ModeIndicatorRune.png b/ExtraTextures/UI/ModeIndicatorRune.png deleted file mode 100644 index 51a2ed08d5..0000000000 Binary files a/ExtraTextures/UI/ModeIndicatorRune.png and /dev/null differ diff --git a/Gores/PrismShurikenBlade.png b/Gores/PrismShurikenBlade.png new file mode 100644 index 0000000000..650f27e8c1 Binary files /dev/null and b/Gores/PrismShurikenBlade.png differ diff --git a/ILEditing/ILChanges.cs b/ILEditing/ILChanges.cs index a66460ba8c..adf8ec7167 100644 --- a/ILEditing/ILChanges.cs +++ b/ILEditing/ILChanges.cs @@ -1,16 +1,21 @@ using CalamityMod.CalPlayer; using CalamityMod.NPCs; +using CalamityMod.Projectiles; using CalamityMod.Tiles.DraedonStructures; using CalamityMod.World; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using Mono.Cecil.Cil; using MonoMod.Cil; using System; using System.Collections.Generic; using System.Reflection; using Terraria; +using Terraria.GameInput; +using Terraria.Graphics.Shaders; using Terraria.ID; using Terraria.ModLoader; +using Terraria.UI.Gamepad; using Terraria.Utilities; using Terraria.World.Generation; @@ -118,6 +123,8 @@ namespace CalamityMod.ILEditing DisableDemonAltarGeneration(); DisableTeleportersDuringBossFights(); FixSplittingWormBannerDrops(); + IncorporateMinionExplodingCountdown(); + UseCoolFireCursorEffect(); MakeMouseHoverItemsSupportAnimations(); } @@ -447,6 +454,25 @@ namespace CalamityMod.ILEditing }; } + private static void IncorporateMinionExplodingCountdown() + { + On.Terraria.Projectile.NewProjectile_float_float_float_float_int_int_float_int_float_float += (orig, x, y, xSpeed, ySpeed, type, damage, knockback, owner, ai0, ai1) => + { + // This is unfortunately not something that can be done via SetDefaults since owner is set + // after that method is called. Doing it directly when the projectile is spawned appears to be the only reasonable way. + int proj = orig(x, y, xSpeed, ySpeed, type, damage, knockback, owner, ai0, ai1); + Projectile projectile = Main.projectile[proj]; + if (projectile.minion) + { + Player player = Main.player[projectile.owner]; + CalamityPlayerMiscEffects.EnchantHeldItemEffects(player, player.Calamity(), player.ActiveItem()); + if (player.Calamity().explosiveMinionsEnchant) + projectile.Calamity().ExplosiveEnchantCountdown = CalamityGlobalProjectile.ExplosiveEnchantTime; + } + return proj; + }; + } + private static void MakeMouseHoverItemsSupportAnimations() { IL.Terraria.Main.DrawInterface_40_InteractItemIcon += (il) => @@ -476,8 +502,8 @@ namespace CalamityMod.ILEditing #endregion - #region IL Editing Injected/Hooked Functions - private static void BossRushLifeBytes(On.Terraria.Main.orig_InitLifeBytes orig) + #region IL Editing Injected/Hooked Functions + private static void BossRushLifeBytes(On.Terraria.Main.orig_InitLifeBytes orig) { orig(); foreach (int npcType in NeedsFourLifeBytes) @@ -524,7 +550,104 @@ namespace CalamityMod.ILEditing return orig(i, j, forced); } - private static void PreventSmashAltarCode(On.Terraria.WorldGen.orig_SmashAltar orig, int i, int j) + private static void UseCoolFireCursorEffect() + { + On.Terraria.Main.DrawCursor += (orig, bonus, smart) => + { + // Do nothing special if the player has a regular mouse or is on the menu. + if (Main.gameMenu || !Main.LocalPlayer.Calamity().ableToDrawBlazingMouse) + { + orig(bonus, smart); + return; + } + + if (Main.LocalPlayer.dead) + { + Main.SmartInteractShowingGenuine = false; + Main.SmartInteractShowingFake = false; + Main.SmartInteractNPC = -1; + Main.SmartInteractNPCsNearby.Clear(); + Main.SmartInteractTileCoords.Clear(); + Main.SmartInteractTileCoordsSelected.Clear(); + Main.TileInteractionLX = (Main.TileInteractionHX = (Main.TileInteractionLY = (Main.TileInteractionHY = -1))); + } + + Color flameColor = Color.Lerp(Color.DarkRed, Color.OrangeRed, (float)Math.Cos(Main.GlobalTime * 7.4f) * 0.5f + 0.5f); + Color cursorColor = flameColor * 1.9f; + Vector2 baseDrawPosition = Main.MouseScreen + bonus; + + // Draw the mouse as usual if the player isn't using the gamepad. + if (!PlayerInput.UsingGamepad) + { + int cursorIndex = smart.ToInt(); + + Color desaturatedCursorColor = cursorColor; + desaturatedCursorColor.R /= 5; + desaturatedCursorColor.G /= 5; + desaturatedCursorColor.B /= 5; + desaturatedCursorColor.A /= 2; + + Vector2 drawPosition = baseDrawPosition; + Vector2 desaturatedDrawPosition = drawPosition + Vector2.One; + + // If the blazing mouse is actually going to do damage, draw an indicator aura. + if (Main.LocalPlayer.Calamity().blazingMouseDamageEffects && !Main.mapFullscreen) + { + Texture2D auraTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/CalamityAura"); + Rectangle auraFrame = auraTexture.Frame(1, 6, 0, (int)(Main.GlobalTime * 12.3f) % 6); + float auraScale = MathHelper.Lerp(0.95f, 1f, (float)Math.Sin(Main.GlobalTime * 1.1f) * 0.5f + 0.5f); + + for (int i = 0; i < 12; i++) + { + Color auraColor = Color.Orange * Main.LocalPlayer.Calamity().blazingMouseAuraFade * 0.125f; + auraColor.A = 0; + Vector2 offsetDrawPosition = baseDrawPosition + (MathHelper.TwoPi * i / 12f + Main.GlobalTime * 5f).ToRotationVector2() * 2.5f; + offsetDrawPosition.Y -= 18f; + + Main.spriteBatch.Draw(auraTexture, offsetDrawPosition, auraFrame, auraColor, 0f, auraFrame.Size() * 0.5f, Main.cursorScale * auraScale, SpriteEffects.None, 0f); + } + } + + Main.spriteBatch.Draw(Main.cursorTextures[cursorIndex], drawPosition, null, desaturatedCursorColor, 0f, Vector2.Zero, Main.cursorScale, SpriteEffects.None, 0f); + + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.UIScaleMatrix); + GameShaders.Misc["CalamityMod:FireMouse"].UseColor(Color.Red); + GameShaders.Misc["CalamityMod:FireMouse"].UseSecondaryColor(Color.Lerp(Color.Red, Color.Orange, 0.75f)); + GameShaders.Misc["CalamityMod:FireMouse"].Apply(); + + Main.spriteBatch.Draw(Main.cursorTextures[cursorIndex], desaturatedDrawPosition, null, cursorColor, 0f, Vector2.Zero, Main.cursorScale * 1.075f, SpriteEffects.None, 0f); + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.GameViewMatrix.EffectMatrix); + return; + } + + // Don't bother doing any more drawing if the player is dead. + if (Main.LocalPlayer.dead && !Main.LocalPlayer.ghost && !Main.gameMenu) + return; + + if (PlayerInput.InvisibleGamepadInMenus) + return; + + // Draw a white circle instead if using the smart cursor. + if (smart && !(UILinkPointNavigator.Available && !PlayerInput.InBuildingMode)) + { + cursorColor = Color.White * Main.GamepadCursorAlpha; + int frameX = 0; + Texture2D smartCursorTexture = Main.cursorTextures[13]; + Rectangle frame = smartCursorTexture.Frame(2, 1, frameX, 0); + Main.spriteBatch.Draw(smartCursorTexture, baseDrawPosition, frame, cursorColor, 0f, frame.Size() * 0.5f, Main.cursorScale, SpriteEffects.None, 0f); + return; + } + + // Otherwise draw an ordinary crosshair at the mouse position. + cursorColor = Color.White; + Texture2D crosshairTexture = Main.cursorTextures[15]; + Main.spriteBatch.Draw(crosshairTexture, baseDrawPosition, null, cursorColor, 0f, crosshairTexture.Size() * 0.5f, Main.cursorScale, SpriteEffects.None, 0f); + }; + } + + private static void PreventSmashAltarCode(On.Terraria.WorldGen.orig_SmashAltar orig, int i, int j) { if (CalamityConfig.Instance.EarlyHardmodeProgressionRework) return; diff --git a/Items/Accessories/AmbrosialAmpoule.cs b/Items/Accessories/AmbrosialAmpoule.cs index 4286e66c63..ac477ff3f0 100644 --- a/Items/Accessories/AmbrosialAmpoule.cs +++ b/Items/Accessories/AmbrosialAmpoule.cs @@ -51,6 +51,7 @@ namespace CalamityMod.Items.Accessories CalamityPlayer modPlayer = player.Calamity(); modPlayer.beeResist = true; modPlayer.aAmpoule = true; + modPlayer.rOoze = true; } public override void AddRecipes() diff --git a/Items/Accessories/Calamity.cs b/Items/Accessories/Calamity.cs new file mode 100644 index 0000000000..d96bc93ed9 --- /dev/null +++ b/Items/Accessories/Calamity.cs @@ -0,0 +1,39 @@ +using Terraria; +using Terraria.DataStructures; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Accessories +{ + public class Calamity : ModItem + { + public const float MaxNPCSpeed = 5f; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Calamity"); + Tooltip.SetDefault("Lights your mouse ablaze with a brimstone fire and causes a flaming aura to appear around it\n" + + "Enemies near the aura take immense damage and are inflicted with Vulnerability Hex\n" + + "The mouse fire effect can be shown without the aura and damage effects by putting this item in a vanity slot"); + Main.RegisterItemAnimation(item.type, new DrawAnimationVertical(6, 4)); + } + + public override void SetDefaults() + { + item.width = 44; + item.height = 108; + item.rare = ItemRarityID.Purple; + item.value = CalamityGlobalItem.RarityVioletBuyPrice; + item.expert = true; + item.vanity = true; + item.accessory = true; + } + + public override void UpdateAccessory(Player player, bool hideVisual) + { + player.Calamity().blazingMouseDamageEffects = true; + player.Calamity().ableToDrawBlazingMouse = true; + } + + public override void UpdateEquip(Player player) => player.Calamity().ableToDrawBlazingMouse = true; + } +} diff --git a/Items/Accessories/Calamity.png b/Items/Accessories/Calamity.png new file mode 100644 index 0000000000..f4f939e40b Binary files /dev/null and b/Items/Accessories/Calamity.png differ diff --git a/Items/Accessories/RadiantOoze.cs b/Items/Accessories/RadiantOoze.cs index d25f436569..4828b840ba 100644 --- a/Items/Accessories/RadiantOoze.cs +++ b/Items/Accessories/RadiantOoze.cs @@ -25,11 +25,6 @@ namespace CalamityMod.Items.Accessories public override void UpdateAccessory(Player player, bool hideVisual) { player.Calamity().rOoze = true; - if (!Main.dayTime) - { - Lighting.AddLight((int)(player.position.X + (float)(player.width / 2)) / 16, (int)(player.position.Y + (float)(player.height / 2)) / 16, 1f, 1f, 0.6f); - player.lifeRegen += 4; - } } public override void AddRecipes() diff --git a/Items/Accessories/RottenDogtooth.cs b/Items/Accessories/RottenDogtooth.cs new file mode 100644 index 0000000000..fb51bb1b1f --- /dev/null +++ b/Items/Accessories/RottenDogtooth.cs @@ -0,0 +1,34 @@ +using CalamityMod.CalPlayer; +using System.Collections.Generic; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Accessories +{ + public class RottenDogtooth : ModItem + { + internal const int ArmorCrunchDebuffTime = 180; + internal const float StealthStrikeDamageMultiplier = 0.1f; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Rotten Dogtooth"); + Tooltip.SetDefault($"Makes Stealth strikes inflict Armor Crunch, deal {(int)(StealthStrikeDamageMultiplier * 100)}% more damage and cost 1 less unit of stealth."); + } + + public override void SetDefaults() + { + item.width = 14; + item.height = 22; + item.value = CalamityGlobalItem.Rarity1BuyPrice; + item.rare = ItemRarityID.Blue; + item.accessory = true; + } + + public override void UpdateAccessory(Player player, bool hideVisual) + { + player.Calamity().rottenDogTooth = true; + player.Calamity().flatStealthLossReduction++; + } + } +} diff --git a/Items/Accessories/RottenDogtooth.png b/Items/Accessories/RottenDogtooth.png new file mode 100644 index 0000000000..8a542b03b6 Binary files /dev/null and b/Items/Accessories/RottenDogtooth.png differ diff --git a/Items/Accessories/ShatteredCommunity.cs b/Items/Accessories/ShatteredCommunity.cs index f26df095ed..731ab8fe33 100644 --- a/Items/Accessories/ShatteredCommunity.cs +++ b/Items/Accessories/ShatteredCommunity.cs @@ -238,30 +238,5 @@ namespace CalamityMod.Items.Accessories level = reader.ReadInt32(); totalRageDamage = reader.ReadInt64(); } - - public override void AddRecipes() - { - ModRecipe r = new ShatteredCommunityRecipe(mod); - r.SetResult(this); - r.AddIngredient(ModContent.ItemType()); - r.AddIngredient(ModContent.ItemType()); - r.AddIngredient(ModContent.ItemType(), 120); - r.AddRecipe(); - } - - // The Shattered Community can only be crafted with a full-power Community. - // That is, in a world where all relevant bosses have been defeated. - private class ShatteredCommunityRecipe : ModRecipe - { - public ShatteredCommunityRecipe(Mod mod) : base(mod) { } - - public override bool RecipeAvailable() - { - bool vanillaBosses = NPC.downedSlimeKing && NPC.downedBoss1 && NPC.downedBoss2 && NPC.downedQueenBee && NPC.downedBoss3 && Main.hardMode; - vanillaBosses &= NPC.downedMechBossAny && NPC.downedPlantBoss && NPC.downedGolemBoss && NPC.downedFishron && NPC.downedAncientCultist && NPC.downedMoonlord; - bool calamityBosses = CalamityWorld.downedProvidence && CalamityWorld.downedDoG && CalamityWorld.downedYharon; - return vanillaBosses && calamityBosses; - } - } } } diff --git a/Items/Accessories/Sponge.cs b/Items/Accessories/Sponge.cs index 107bcab7ec..c5d984bb12 100644 --- a/Items/Accessories/Sponge.cs +++ b/Items/Accessories/Sponge.cs @@ -78,6 +78,7 @@ namespace CalamityMod.Items.Accessories modPlayer.seaShell = true; modPlayer.absorber = true; modPlayer.aAmpoule = true; + modPlayer.rOoze = true; player.statManaMax2 += 20; } diff --git a/Items/Armor/AuricTeslaSpaceHelmet.cs b/Items/Armor/AuricTeslaSpaceHelmet.cs index cf084dc02c..59c452eddd 100644 --- a/Items/Armor/AuricTeslaSpaceHelmet.cs +++ b/Items/Armor/AuricTeslaSpaceHelmet.cs @@ -45,7 +45,7 @@ namespace CalamityMod.Items.Armor player.setBonus = "Summoner Tarragon, Bloodflare and Silva armor effects\n" + "All projectiles spawn healing auric orbs on enemy hits\n" + "Max run speed and acceleration boosted by 10%\n" + - "+8 max minions and 120% increased minion damage"; + "+8 max minions and 90% increased minion damage"; CalamityPlayer modPlayer = player.Calamity(); modPlayer.tarraSet = true; modPlayer.tarraSummon = true; @@ -58,7 +58,7 @@ namespace CalamityMod.Items.Armor player.lavaMax += 240; player.ignoreWater = true; player.crimsonRegen = true; - player.minionDamage += 1.2f; + player.minionDamage += 0.9f; player.maxMinions += 8; if (player.lavaWet) { diff --git a/Items/BrimstoneLocus.cs b/Items/BrimstoneLocus.cs new file mode 100644 index 0000000000..d30495e93c --- /dev/null +++ b/Items/BrimstoneLocus.cs @@ -0,0 +1,35 @@ +using CalamityMod.Items.Materials; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items +{ + public class BrimstoneLocus : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Brimstone Locus"); + Tooltip.SetDefault("Not only can I enhance your equipment with potent magic, I can also draw out the true strength and ascend\n" + + "some of your weaponry to entirely new forms\n" + + "Such items are revealed while this item is in your inventory"); + } + + public override void SetDefaults() + { + item.width = 20; + item.height = 20; + item.rare = ItemRarityID.Purple; + item.Calamity().customRarity = CalamityRarity.Violet; + item.value = 0; + } + + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ModContent.ItemType()); + recipe.AddIngredient(ModContent.ItemType(), 3); + recipe.SetResult(this); + recipe.AddRecipe(); + } + } +} diff --git a/Items/BrimstoneLocus.png b/Items/BrimstoneLocus.png new file mode 100644 index 0000000000..4f08d4e2d2 Binary files /dev/null and b/Items/BrimstoneLocus.png differ diff --git a/Items/CalamityGlobalItem.cs b/Items/CalamityGlobalItem.cs index ce34cce89d..bee9bcfc03 100644 --- a/Items/CalamityGlobalItem.cs +++ b/Items/CalamityGlobalItem.cs @@ -6,8 +6,10 @@ using CalamityMod.Items.Accessories; using CalamityMod.Items.Potions; using CalamityMod.Items.Weapons.Melee; using CalamityMod.Items.Weapons.Summon; +using CalamityMod.NPCs.Other; using CalamityMod.NPCs.SupremeCalamitas; using CalamityMod.NPCs.TownNPCs; +using CalamityMod.Particles; using CalamityMod.Projectiles.Magic; using CalamityMod.Projectiles.Melee; using CalamityMod.Projectiles.Ranged; @@ -15,8 +17,10 @@ using CalamityMod.Projectiles.Rogue; using CalamityMod.Projectiles.Summon; using CalamityMod.Projectiles.Typeless; using CalamityMod.UI; +using CalamityMod.UI.CalamitasEnchants; using CalamityMod.World; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using System; using System.IO; using Terraria; @@ -50,19 +54,47 @@ namespace CalamityMod.Items return float.IsNaN(ratio) || float.IsInfinity(ratio) ? 0f : MathHelper.Clamp(ratio, 0f, 1f); } } - #endregion + #endregion - // Miscellaneous stuff - public CalamityRarity customRarity = CalamityRarity.NoEffect; + #region Enchantment Variables + public Enchantment? AppliedEnchantment = null; + public float DischargeEnchantExhaustion = 0; + public float DischargeExhaustionRatio + { + get + { + float ratio = DischargeEnchantExhaustion / DischargeEnchantExhaustionCap; + return float.IsNaN(ratio) || float.IsInfinity(ratio) ? 0f : MathHelper.Clamp(ratio, 0f, 1f); + } + } + public const float DischargeEnchantExhaustionCap = 1600f; + public const float DischargeEnchantMinDamageFactor = 0.77f; + public const float DischargeEnchantMaxDamageFactor = 1.26f; + #endregion + + // Miscellaneous stuff + public CalamityRarity customRarity = CalamityRarity.NoEffect; public int timesUsed = 0; public int reforgeTier = 0; public bool donorItem = false; public bool devItem = false; public bool challengeDrop = false; - // See RogueWeapon.cs for rogue modifier shit - #region Modifiers - public CalamityGlobalItem() + public static readonly Color[] ExoPalette = new Color[] + { + new Color(250, 255, 112), + new Color(211, 235, 108), + new Color(166, 240, 105), + new Color(105, 240, 220), + new Color(64, 130, 145), + new Color(145, 96, 145), + new Color(242, 112, 73), + new Color(199, 62, 62), + }; + + // See RogueWeapon.cs for rogue modifier shit + #region Modifiers + public CalamityGlobalItem() { StealthGenBonus = 1f; } @@ -71,6 +103,7 @@ namespace CalamityMod.Items { CalamityGlobalItem myClone = (CalamityGlobalItem)base.Clone(item, itemClone); myClone.StealthGenBonus = StealthGenBonus; + myClone.DischargeEnchantExhaustion = DischargeEnchantExhaustion; myClone.Charge = Charge; return myClone; } @@ -97,7 +130,10 @@ namespace CalamityMod.Items if (item.type == ItemID.PirateMap || item.type == ItemID.SnowGlobe) item.maxStack = 20; - if (item.type >= ItemID.GreenSolution && item.type <= ItemID.RedSolution) + if (item.type == ItemID.CelestialSigil) + item.maxStack = 1; + + if (item.type >= ItemID.GreenSolution && item.type <= ItemID.RedSolution) item.value = Item.buyPrice(0, 0, 5, 0); if (CalamityLists.useTurnList?.Contains(item.type) ?? false) @@ -224,6 +260,7 @@ namespace CalamityMod.Items public override bool Shoot(Item item, Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) { CalamityPlayer modPlayer = player.Calamity(); + if (rogue) { speedX *= modPlayer.throwingVelocity; @@ -464,10 +501,10 @@ namespace CalamityMod.Items } return true; } - #endregion + #endregion - #region SavingAndLoading - public override bool NeedsSaving(Item item) + #region SavingAndLoading + public override bool NeedsSaving(Item item) { return true; } @@ -480,8 +517,10 @@ namespace CalamityMod.Items ["timesUsed"] = timesUsed, ["rarity"] = (int)customRarity, ["charge"] = Charge, - ["reforgeTier"] = reforgeTier - }; + ["reforgeTier"] = reforgeTier, + ["enchantmentID"] = AppliedEnchantment.HasValue ? AppliedEnchantment.Value.ID : 0, + ["DischargeEnchantExhaustion"] = DischargeEnchantExhaustion + }; } public override void Load(Item item, TagCompound tag) @@ -496,8 +535,16 @@ namespace CalamityMod.Items else Charge = tag.GetFloat("charge"); + DischargeEnchantExhaustion = tag.GetFloat("DischargeEnchantExhaustion"); reforgeTier = tag.GetInt("reforgeTimer"); - } + Enchantment? savedEnchantment = EnchantmentManager.FindByID(tag.GetInt("enchantmentID")); + if (savedEnchantment.HasValue) + { + AppliedEnchantment = savedEnchantment.Value; + bool hasCreationEffect = AppliedEnchantment.Value.CreationEffect != null; + item.Calamity().AppliedEnchantment.Value.CreationEffect?.Invoke(item); + } + } public override void LoadLegacy(Item item, BinaryReader reader) { @@ -528,7 +575,9 @@ namespace CalamityMod.Items writer.Write(timesUsed); writer.Write(Charge); writer.Write(reforgeTier); - } + writer.Write(AppliedEnchantment.HasValue ? AppliedEnchantment.Value.ID : 0); + writer.Write(DischargeEnchantExhaustion); + } public override void NetReceive(Item item, BinaryReader reader) { @@ -539,7 +588,17 @@ namespace CalamityMod.Items timesUsed = reader.ReadInt32(); Charge = reader.ReadSingle(); reforgeTier = reader.ReadInt32(); - } + + Enchantment? savedEnchantment = EnchantmentManager.FindByID(reader.ReadInt32()); + if (savedEnchantment.HasValue) + { + AppliedEnchantment = savedEnchantment.Value; + bool hasCreationEffect = AppliedEnchantment.Value.CreationEffect != null; + if (hasCreationEffect) + item.Calamity().AppliedEnchantment.Value.CreationEffect(item); + } + DischargeEnchantExhaustion = reader.ReadSingle(); + } #endregion #region Pickup Item Changes @@ -585,7 +644,7 @@ namespace CalamityMod.Items NetMessage.SendData(MessageID.MoonlordCountdown, -1, -1, null, NPC.MoonLordCountdown); } - return base.UseItem(item, player); + return base.UseItem(item, player); } public override bool AltFunctionUse(Item item, Player player) @@ -694,7 +753,22 @@ namespace CalamityMod.Items if (PopupGUIManager.AnyGUIsActive) return false; - if (player.ownedProjectileCounts[ModContent.ProjectileType()] > 0 && + if (player.Calamity().cursedSummonsEnchant && NPC.CountNPCS(ModContent.NPCType()) < 2) + { + Point spawnPosition = Main.MouseWorld.ToPoint(); + NPC.NewNPC(spawnPosition.X, spawnPosition.Y, ModContent.NPCType(), Target: player.whoAmI); + Main.PlaySound(SoundID.DD2_DarkMageSummonSkeleton, Main.MouseWorld); + } + + bool belowHalfMana = player.statMana < player.statManaMax2 * 0.5f; + if (player.Calamity().manaMonsterEnchant && Main.rand.NextBool(12) && player.ownedProjectileCounts[ModContent.ProjectileType()] <= 0 && belowHalfMana) + { + int damage = (int)(165000 * player.MagicDamage()); + Vector2 shootVelocity = player.SafeDirectionTo(Main.MouseWorld, -Vector2.UnitY).RotatedByRandom(0.07f) * Main.rand.NextFloat(4f, 5f); + Projectile.NewProjectile(player.Center + shootVelocity, shootVelocity, ModContent.ProjectileType(), damage, 0f, player.whoAmI); + } + + if (player.ownedProjectileCounts[ModContent.ProjectileType()] > 0 && (item.damage > 0 || item.ammo != AmmoID.None)) { return false; // Don't use weapons if you're charging with a spear @@ -716,6 +790,15 @@ namespace CalamityMod.Items if (modPlayer.profanedCrystalBuffs && item.pick == 0 && item.axe == 0 && item.hammer == 0 && item.autoReuse && (modItem.rogue || item.magic || item.ranged || item.melee)) return player.altFunctionUse == 0 ? ProfanedSoulCrystal.TransformItemUsage(item, player) : AltFunctionUse(item, player); + // Exhaust the weapon if it has the necessary enchant. + if (!item.IsAir && modPlayer.dischargingItemEnchant) + { + float exhaustionCost = item.useTime * 2.25f; + if (exhaustionCost < 10f) + exhaustionCost = 10f; + DischargeEnchantExhaustion = MathHelper.Clamp(DischargeEnchantExhaustion - exhaustionCost, 0.001f, DischargeEnchantExhaustionCap); + } + // Check for sufficient charge if this item uses charge. if (item.type >= ItemID.Count && modItem.UsesCharge) { @@ -825,7 +908,11 @@ namespace CalamityMod.Items // Summon weapons specifically do not have their damage affected by charge. They still require charge to function however. CalamityGlobalItem modItem = item.Calamity(); - if (!item.summon && (modItem?.UsesCharge ?? false)) + + if (!item.summon && modItem.DischargeEnchantExhaustion > 0f) + mult *= DischargeEnchantmentDamageFormula(); + + if (!item.summon && (modItem?.UsesCharge ?? false)) { // At exactly zero charge, do not perform any multiplication. // This makes charge-using weapons show up at full damage when previewed in crafting, Recipe Browser, etc. @@ -835,9 +922,20 @@ namespace CalamityMod.Items } } - // This formula gives a slightly higher value than 1.0 above 85% charge, and a slightly lower value than 0.0 at 0% charge. - // Specifically, it gives 0.0 or less at 0.36% charge or lower. This is fine because the result is immediately clamped. - internal float ChargeDamageFormula() + internal float DischargeEnchantmentDamageFormula() + { + // This exponential has the properties of beginning at 0 and ending at 1, yet also has their signature rising curve. + // It is therefore perfect for a potential interpolant. + float interpolant = (float)Math.Pow(2D, DischargeExhaustionRatio) - 1f; + + // No further smoothening is required in the form of a Smoothstep remap. + // A linear interpolation works fine; the exponential already has the desired curve shape. + return MathHelper.Lerp(DischargeEnchantMinDamageFactor, DischargeEnchantMaxDamageFactor, interpolant); + } + + // This formula gives a slightly higher value than 1.0 above 85% charge, and a slightly lower value than 0.0 at 0% charge. + // Specifically, it gives 0.0 or less at 0.36% charge or lower. This is fine because the result is immediately clamped. + internal float ChargeDamageFormula() { float x = MathHelper.Clamp(ChargeRatio, 0f, 1f); float y = 1.087f - 0.08f / (x + 0.07f); @@ -1621,6 +1719,48 @@ namespace CalamityMod.Items } #endregion + #region Inventory Drawing + internal static ChargingEnergyParticleSet EnchantmentEnergyParticles = new ChargingEnergyParticleSet(-1, 2, Color.DarkViolet, Color.White, 0.04f, 24f); + + internal static void UpdateAllParticleSets() + { + EnchantmentEnergyParticles.Update(); + } + + public override bool PreDrawInInventory(Item item, SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale) + { + void drawItemManually(Color color, float generalScale) + { + Texture2D itemTexture = Main.itemTexture[item.type]; + Rectangle itemFrame = (Main.itemAnimations[item.type] == null) ? itemTexture.Frame() : Main.itemAnimations[item.type].GetFrame(itemTexture); + Vector2 itemOrigin = itemFrame.Size() * 0.5f; + spriteBatch.Draw(itemTexture, position, itemFrame, color, 0f, itemOrigin, scale * generalScale, SpriteEffects.None, 0f); + } + + if (!EnchantmentManager.ItemUpgradeRelationship.ContainsKey(item.type) || !Main.LocalPlayer.InventoryHas(ModContent.ItemType())) + return true; + + // Draw all particles. + float currentPower = 0f; + int calamitasNPCIndex = NPC.FindFirstNPC(ModContent.NPCType()); + if (calamitasNPCIndex != -1) + currentPower = Utils.InverseLerp(11750f, 1000f, Main.LocalPlayer.Distance(Main.npc[calamitasNPCIndex].Center), true); + + position += frame.Size() * 0.25f; + EnchantmentEnergyParticles.InterpolationSpeed = MathHelper.Lerp(0.035f, 0.1f, currentPower); + EnchantmentEnergyParticles.DrawSet(position + Main.screenPosition); + + float pulse = Main.GlobalTime * 0.79f % 1f; + float pulseFade = Utils.InverseLerp(0.87f, 0.27f, pulse, true); + float pulseScale = scale * MathHelper.Lerp(1.6f, 1f, pulseFade) / scale; + Color pulseColor = Color.Lerp(drawColor, Color.BlueViolet, pulseFade) * pulseFade; + drawItemManually(pulseColor, pulseScale); + drawItemManually(drawColor, 1f); + + return false; + } + #endregion + #region Reforging private int NewPrefixType(Item item) { diff --git a/Items/CalamityGlobalItemTooltip.cs b/Items/CalamityGlobalItemTooltip.cs index fe9dbd8078..2a727f3eda 100644 --- a/Items/CalamityGlobalItemTooltip.cs +++ b/Items/CalamityGlobalItemTooltip.cs @@ -11,6 +11,7 @@ using CalamityMod.Items.Weapons.Rogue; using CalamityMod.Items.Weapons.Summon; using CalamityMod.World; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using System; using System.Collections.Generic; using System.Linq; @@ -18,6 +19,7 @@ using System.Text; using Terraria; using Terraria.ID; using Terraria.ModLoader; +using Terraria.UI.Chat; namespace CalamityMod.Items { @@ -42,6 +44,10 @@ namespace CalamityMod.Items // This is placed between vanilla tooltip edits and mod mechanics because it can apply to vanilla items. StealthGenAccessoryTooltip(item, tooltips); + // If an item has an enchantment, show its prefix in the first tooltip line and append its description to the + // tooltip list. + EnchantmentTooltips(item, tooltips); + // Everything below this line can only apply to modded items. If the item is vanilla, stop here for efficiency. if (item.type < ItemID.Count) return; @@ -228,6 +234,19 @@ namespace CalamityMod.Items } #endregion + #region Enchantment Tooltips + private void EnchantmentTooltips(Item item, IList tooltips) + { + if (!item.IsAir && AppliedEnchantment.HasValue) + { + tooltips[0].text = $"{AppliedEnchantment.Value.Name} {tooltips[0].text}"; + + TooltipLine descriptionLine = new TooltipLine(mod, "Enchantment", CalamityUtils.ColorMessage(AppliedEnchantment.Value.Description, Color.DarkRed)); + tooltips.Add(descriptionLine); + } + } + #endregion + #region Vanilla Item Tooltip Modification private void ModifyVanillaTooltips(Item item, IList tooltips) { @@ -965,6 +984,39 @@ namespace CalamityMod.Items } #endregion + #region Enchanted Rarity Text Drawing + public override bool PreDrawTooltipLine(Item item, DrawableTooltipLine line, ref int yOffset) + { + // Special enchantment line color. + if (line.Name == "ItemName" && line.mod == "Terraria" && item.IsEnchanted()) + { + Color rarityColor = line.overrideColor ?? line.color; + Vector2 basePosition = new Vector2(line.X, line.Y); + + float backInterpolant = (float)Math.Pow(Main.GlobalTime * 0.81f % 1f, 1.5f); + Vector2 backScale = line.baseScale * MathHelper.Lerp(1f, 1.2f, backInterpolant); + Color backColor = Color.Lerp(rarityColor, Color.DarkRed, backInterpolant) * (float)Math.Pow(1f - backInterpolant, 0.46f); + Vector2 backPosition = basePosition - new Vector2(1f, 0.1f) * backInterpolant * 10f; + + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive); + + // Draw the back text as an ominous pulse. + for (int i = 0; i < 2; i++) + ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, line.font, line.text, backPosition, backColor, line.rotation, line.origin, backScale, line.maxWidth, line.spread); + + Main.spriteBatch.End(); + Main.spriteBatch.Begin(); + + // Draw the front text as usual. + ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, line.font, line.text, basePosition, rarityColor, line.rotation, line.origin, line.baseScale, line.maxWidth, line.spread); + + return false; + } + return true; + } + #endregion + #region Fargo Biome Fountain Tooltip private void FargoFountainTooltip(Item item, IList tooltips) { diff --git a/Items/DifficultyItems/Malice.cs b/Items/DifficultyItems/Malice.cs index 998250226f..874febecbf 100644 --- a/Items/DifficultyItems/Malice.cs +++ b/Items/DifficultyItems/Malice.cs @@ -3,6 +3,7 @@ using CalamityMod.Events; using CalamityMod.World; using Microsoft.Xna.Framework; using Terraria; +using Terraria.DataStructures; using Terraria.ID; using Terraria.ModLoader; @@ -16,6 +17,7 @@ namespace CalamityMod.Items.DifficultyItems Tooltip.SetDefault("Enrages every boss and allows them to drop special items.\n" + "Nurse no longer heals while a boss is alive.\n" + "Effect can be toggled on and off."); + Main.RegisterItemAnimation(item.type, new DrawAnimationVertical(6, 8)); } public override void SetDefaults() @@ -27,6 +29,7 @@ namespace CalamityMod.Items.DifficultyItems item.useTime = 45; item.useStyle = ItemUseStyleID.HoldingUp; item.UseSound = SoundID.Item119; + item.noUseGraphic = true; item.consumable = false; } diff --git a/Items/DifficultyItems/Malice.png b/Items/DifficultyItems/Malice.png index 493a9b001c..fa448647be 100644 Binary files a/Items/DifficultyItems/Malice.png and b/Items/DifficultyItems/Malice.png differ diff --git a/Items/TreasureBags/SlimeGodBag.cs b/Items/TreasureBags/SlimeGodBag.cs index 3df7456c7b..533e2d577c 100644 --- a/Items/TreasureBags/SlimeGodBag.cs +++ b/Items/TreasureBags/SlimeGodBag.cs @@ -51,7 +51,8 @@ namespace CalamityMod.Items.TreasureBags DropHelper.WeightStack(w), DropHelper.WeightStack(w), DropHelper.WeightStack(w), - DropHelper.WeightStack(w) + DropHelper.WeightStack(w), + DropHelper.WeightStack(w) ); // Equipment diff --git a/Items/Weapons/Magic/ApoctosisArray.cs b/Items/Weapons/Magic/ApoctosisArray.cs index 697bcfefef..12b0b3658a 100644 --- a/Items/Weapons/Magic/ApoctosisArray.cs +++ b/Items/Weapons/Magic/ApoctosisArray.cs @@ -45,8 +45,8 @@ namespace CalamityMod.Items.Weapons.Magic if (injectionNerf) manaRatio = MathHelper.Min(manaRatio, 0.65f); - // 20% to 220% damage. Astral Injection caps it at 124% damage. - float damageRatio = 0.2f + 1.6f * manaRatio; + // 20% to 160% damage. Astral Injection caps it at 111% damage. + float damageRatio = 0.2f + 1.4f * manaRatio; int finalDamage = (int)(damage * damageRatio); Projectile proj = Projectile.NewProjectileDirect(position, new Vector2(speedX, speedY), type, finalDamage, knockBack, player.whoAmI); diff --git a/Items/Weapons/Magic/Apotheosis.cs b/Items/Weapons/Magic/Apotheosis.cs index 4f9524d479..7066a7686c 100644 --- a/Items/Weapons/Magic/Apotheosis.cs +++ b/Items/Weapons/Magic/Apotheosis.cs @@ -22,13 +22,12 @@ namespace CalamityMod.Items.Weapons.Magic public override void SetDefaults() { - item.damage = 85; + item.damage = 77; item.magic = true; item.mana = 42; item.width = 30; item.height = 34; - item.useTime = 15; - item.useAnimation = 15; + item.useTime = item.useAnimation = 177; item.useStyle = ItemUseStyleID.HoldingOut; item.useTurn = false; item.noMelee = true; @@ -40,8 +39,8 @@ namespace CalamityMod.Items.Weapons.Magic item.UseSound = SoundID.Item92; item.autoReuse = true; - item.shoot = ModContent.ProjectileType(); - item.shootSpeed = 15.69f; + item.shoot = ModContent.ProjectileType(); + item.shootSpeed = 42.0f; } public override void PostDrawInWorld(SpriteBatch spriteBatch, Color lightColor, Color alphaColor, float rotation, float scale, int whoAmI) diff --git a/Items/Weapons/Magic/CarnageRay.cs b/Items/Weapons/Magic/CarnageRay.cs index c02ffe9401..5799ff4e61 100644 --- a/Items/Weapons/Magic/CarnageRay.cs +++ b/Items/Weapons/Magic/CarnageRay.cs @@ -12,7 +12,8 @@ namespace CalamityMod.Items.Weapons.Magic public override void SetStaticDefaults() { DisplayName.SetDefault("Carnage Ray"); - Tooltip.SetDefault("Fires a blood ray that splits if enemies are near it"); + Tooltip.SetDefault("Fires a blood ray\n" + + "The farther along the ray hit enemies are, the more damage they take"); Item.staff[item.type] = true; } diff --git a/Items/Weapons/Magic/Climax.cs b/Items/Weapons/Magic/Climax.cs index ff1244b646..15d9c50a84 100644 --- a/Items/Weapons/Magic/Climax.cs +++ b/Items/Weapons/Magic/Climax.cs @@ -20,13 +20,13 @@ namespace CalamityMod.Items.Weapons.Magic public override void SetDefaults() { - item.damage = 131; + item.damage = 105; item.magic = true; item.mana = 30; item.width = 78; item.height = 78; - item.useTime = 41; - item.useAnimation = 41; + item.useTime = 55; + item.useAnimation = 55; item.useStyle = ItemUseStyleID.HoldingOut; item.noMelee = true; item.knockBack = 5f; diff --git a/Items/Weapons/Magic/ElementalRay.cs b/Items/Weapons/Magic/ElementalRay.cs index 078d899a2a..2c6d165a4e 100644 --- a/Items/Weapons/Magic/ElementalRay.cs +++ b/Items/Weapons/Magic/ElementalRay.cs @@ -12,7 +12,11 @@ namespace CalamityMod.Items.Weapons.Magic public override void SetStaticDefaults() { DisplayName.SetDefault("Elemental Ray"); - Tooltip.SetDefault("Casts a rainbow ray that splits when enemies are near it"); + Tooltip.SetDefault("Casts four celestial beams near the player\n" + + "Solar beams explode into fire on enemy hits\n" + + "Nebula beams sweep a little bit over time\n" + + "Vortex beams act like fast lightning and electrify enemies on hit\n" + + "Stardust beams release small stars that home on enemy hits"); Item.staff[item.type] = true; } @@ -23,8 +27,8 @@ namespace CalamityMod.Items.Weapons.Magic item.mana = 18; item.width = 62; item.height = 62; - item.useTime = 20; - item.useAnimation = 20; + item.useTime = 4; + item.reuseDelay = item.useAnimation = 15; item.useStyle = ItemUseStyleID.HoldingOut; item.noMelee = true; item.knockBack = 7.5f; @@ -32,16 +36,51 @@ namespace CalamityMod.Items.Weapons.Magic item.rare = ItemRarityID.Purple; item.UseSound = SoundID.Item60; item.autoReuse = true; - item.shoot = ModContent.ProjectileType(); + item.shoot = 1; item.shootSpeed = 6f; } - public override Vector2? HoldoutOrigin() - { - return new Vector2(15, 15); - } + public override Vector2? HoldoutOrigin() => new Vector2(15); - public override void AddRecipes() + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + float offsetAngle = MathHelper.TwoPi * player.itemAnimation / player.itemAnimationMax; + offsetAngle += MathHelper.PiOver4 + Main.rand.NextFloat(0f, 1.3f); + float shootSpeed = 1f; + switch (player.itemAnimation) + { + case 14: + type = ModContent.ProjectileType(); + break; + case 10: + type = ModContent.ProjectileType(); + offsetAngle -= NebulaElementalBeam.UniversalAngularSpeed * 0.5f; + break; + case 6: + type = ModContent.ProjectileType(); + shootSpeed = 2f; + break; + case 2: + type = ModContent.ProjectileType(); + break; + default: + return false; + } + + Vector2 spawnOffset = player.SafeDirectionTo(Main.MouseWorld, Vector2.UnitY).RotatedBy(offsetAngle) * -Main.rand.NextFloat(40f, 96f); + Vector2 shootDirection = (Main.MouseWorld - (position + spawnOffset)).SafeNormalize(Vector2.UnitX * player.direction); + int beam = Projectile.NewProjectile(position + spawnOffset, shootDirection * shootSpeed, type, damage, knockBack, player.whoAmI); + + // Define specific values for fired lightning. + if (type == ModContent.ProjectileType()) + { + Main.projectile[beam].ai[0] = shootDirection.ToRotation(); + Main.projectile[beam].ai[1] = Main.rand.Next(100); + } + return false; + } + + public override void AddRecipes() { ModRecipe recipe = new ModRecipe(mod); recipe.AddIngredient(ModContent.ItemType(), 5); diff --git a/Items/Weapons/Magic/Eternity.cs b/Items/Weapons/Magic/Eternity.cs index 51b616b91c..ff5129e621 100644 --- a/Items/Weapons/Magic/Eternity.cs +++ b/Items/Weapons/Magic/Eternity.cs @@ -64,7 +64,7 @@ namespace CalamityMod.Items.Weapons.Magic recipe.AddIngredient(ModContent.ItemType()); recipe.AddIngredient(ModContent.ItemType()); recipe.AddIngredient(ModContent.ItemType()); - recipe.AddIngredient(ModContent.ItemType()); + recipe.AddIngredient(ModContent.ItemType()); recipe.AddIngredient(ModContent.ItemType(), 20); recipe.AddIngredient(ModContent.ItemType(), 10); recipe.AddIngredient(ItemID.UnicornHorn, 5); diff --git a/Items/Weapons/Magic/Fabstaff.cs b/Items/Weapons/Magic/Fabstaff.cs index 82994bd8f9..f581260826 100644 --- a/Items/Weapons/Magic/Fabstaff.cs +++ b/Items/Weapons/Magic/Fabstaff.cs @@ -37,7 +37,7 @@ namespace CalamityMod.Items.Weapons.Magic item.UseSound = SoundID.Item60; item.autoReuse = true; item.shoot = ModContent.ProjectileType(); - item.shootSpeed = 6f; + item.shootSpeed = 13.5f; } public override Vector2? HoldoutOrigin() diff --git a/Items/Weapons/Magic/Heresy.cs b/Items/Weapons/Magic/Heresy.cs new file mode 100644 index 0000000000..6d04804a89 --- /dev/null +++ b/Items/Weapons/Magic/Heresy.cs @@ -0,0 +1,44 @@ +using CalamityMod.Projectiles.Magic; +using Terraria; +using Terraria.DataStructures; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Weapons.Magic +{ + public class Heresy : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Heresy"); + Tooltip.SetDefault("Releases fire and souls upward from a held book\n" + + "As the book is held the power of both increases"); + Main.RegisterItemAnimation(item.type, new DrawAnimationVertical(6, 6)); + } + + public override void SetDefaults() + { + item.damage = 444; + item.magic = true; + item.mana = 10; + item.width = 38; + item.height = 40; + item.useTime = item.useAnimation = 120; + item.useStyle = ItemUseStyleID.HoldingOut; + item.noMelee = true; + item.UseSound = SoundID.DD2_EtherianPortalDryadTouch; + item.knockBack = 0f; + + item.value = CalamityGlobalItem.Rarity15BuyPrice; + item.Calamity().customRarity = CalamityRarity.Violet; + + item.autoReuse = true; + item.noUseGraphic = true; + item.shoot = ModContent.ProjectileType(); + item.channel = true; + item.shootSpeed = 0f; + } + + public override bool CanUseItem(Player player) => player.ownedProjectileCounts[item.shoot] <= 0; + } +} \ No newline at end of file diff --git a/Items/Weapons/Magic/Heresy.png b/Items/Weapons/Magic/Heresy.png new file mode 100644 index 0000000000..4c8e3e4f8b Binary files /dev/null and b/Items/Weapons/Magic/Heresy.png differ diff --git a/Items/Weapons/Magic/IonBlaster.cs b/Items/Weapons/Magic/IonBlaster.cs index fd77de50fa..e1cf2a27fc 100644 --- a/Items/Weapons/Magic/IonBlaster.cs +++ b/Items/Weapons/Magic/IonBlaster.cs @@ -46,8 +46,8 @@ namespace CalamityMod.Items.Weapons.Magic if (injectionNerf) manaRatio = MathHelper.Min(manaRatio, 0.65f); - // 20% to 180% damage. Astral Injection caps it at 124% damage. - float damageRatio = 0.2f + 1.6f * manaRatio; + // 20% to 160% damage. Astral Injection caps it at 111% damage. + float damageRatio = 0.2f + 1.4f * manaRatio; int finalDamage = (int)(damage * damageRatio); Projectile proj = Projectile.NewProjectileDirect(position, new Vector2(speedX, speedY), type, finalDamage, knockBack, player.whoAmI); diff --git a/Items/Weapons/Magic/NightsRay.cs b/Items/Weapons/Magic/NightsRay.cs index eff05e11fe..d30410c68c 100644 --- a/Items/Weapons/Magic/NightsRay.cs +++ b/Items/Weapons/Magic/NightsRay.cs @@ -12,7 +12,8 @@ namespace CalamityMod.Items.Weapons.Magic public override void SetStaticDefaults() { DisplayName.SetDefault("Night's Ray"); - Tooltip.SetDefault("Fires a dark ray that splits if enemies are near it"); + Tooltip.SetDefault("Fires a dark ray\n" + + "When hitting enemies, they are hit by several new beams from their sides"); Item.staff[item.type] = true; } diff --git a/Items/Weapons/Magic/RainbowPartyCannon.cs b/Items/Weapons/Magic/RainbowPartyCannon.cs new file mode 100644 index 0000000000..a346414cf1 --- /dev/null +++ b/Items/Weapons/Magic/RainbowPartyCannon.cs @@ -0,0 +1,79 @@ +using CalamityMod.Items.Materials; +using CalamityMod.Projectiles.Magic; +using CalamityMod.Tiles.Furniture.CraftingStations; +using Microsoft.Xna.Framework; +using System.Collections.Generic; +using System.Linq; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Weapons.Magic +{ + public class RainbowPartyCannon : ModItem + { + public static readonly Color[] ColorSet = new Color[] + { + new Color(188, 192, 193), // White + new Color(157, 100, 183), // Purple + new Color(249, 166, 77), // Honey-ish orange + new Color(255, 105, 234), // Pink + new Color(67, 204, 219), // Sky blue + new Color(249, 245, 99), // Bright yellow + new Color(236, 168, 247), // Purplish pink + }; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Rainbow Party Cannon"); + Tooltip.SetDefault("Let the rainbow remind you that together we will always shine..."); + } + + public override void SetDefaults() + { + item.damage = 225; + item.magic = true; + item.mana = 25; + item.width = 52; + item.height = 30; + item.crit += 4; + item.useTime = item.useAnimation = 24; + item.useStyle = ItemUseStyleID.HoldingOut; + item.noMelee = true; + item.knockBack = 3.5f; + item.value = CalamityGlobalItem.RarityHotPinkBuyPrice; + item.rare = 10; + item.Calamity().customRarity = CalamityRarity.HotPink; + item.UseSound = SoundID.Item11; + item.autoReuse = true; + item.noUseGraphic = true; + item.shoot = ModContent.ProjectileType(); + item.channel = true; + item.shootSpeed = 20f; + item.Calamity().devItem = true; + } + + public override void ModifyTooltips(List tooltips) + { + var tt2 = tooltips.FirstOrDefault(x => x.Name == "Tooltip0" && x.mod == "Terraria"); + tt2.overrideColor = new Color((int)MathHelper.Lerp(156f, 255f, Main.DiscoR / 256f), 108, 251); + } + + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ItemID.ConfettiCannon); + recipe.AddIngredient(ModContent.ItemType()); + + // This is the Celebration. The ItemID name is a bit unclear. + // TODO: Replace this with Celebration MK2 in 1.4. + recipe.AddIngredient(ItemID.FireworksLauncher); + recipe.AddIngredient(ItemID.FlaskofParty, 5); + recipe.AddIngredient(ItemID.SoulofLight, 25); + recipe.AddIngredient(ItemID.Confetti, 50); + recipe.AddIngredient(ModContent.ItemType(), 5); + recipe.AddTile(ModContent.TileType()); + recipe.SetResult(this); + recipe.AddRecipe(); + } + } +} diff --git a/Items/Weapons/Magic/RainbowPartyCannon.png b/Items/Weapons/Magic/RainbowPartyCannon.png new file mode 100644 index 0000000000..10b7ca96e9 Binary files /dev/null and b/Items/Weapons/Magic/RainbowPartyCannon.png differ diff --git a/Items/Weapons/Magic/SubsumingVortex.cs b/Items/Weapons/Magic/SubsumingVortex.cs index 561aa64ca2..01566b5b5f 100644 --- a/Items/Weapons/Magic/SubsumingVortex.cs +++ b/Items/Weapons/Magic/SubsumingVortex.cs @@ -21,7 +21,7 @@ namespace CalamityMod.Items.Weapons.Magic public override void SetDefaults() { - item.damage = 300; + item.damage = 175; item.magic = true; item.mana = 78; item.width = 38; diff --git a/Items/Weapons/Magic/TerraRay.cs b/Items/Weapons/Magic/TerraRay.cs index 0d17f2fc30..2eaacb9a7a 100644 --- a/Items/Weapons/Magic/TerraRay.cs +++ b/Items/Weapons/Magic/TerraRay.cs @@ -12,7 +12,8 @@ namespace CalamityMod.Items.Weapons.Magic public override void SetStaticDefaults() { DisplayName.SetDefault("Terra Ray"); - Tooltip.SetDefault("Casts an energy ray that splits if enemies are near it"); + Tooltip.SetDefault("Casts an energy ray that splits into energy on enemy hits\n" + + "More energy is created the farther along the ray the hit enemy is"); Item.staff[item.type] = true; } @@ -41,7 +42,15 @@ namespace CalamityMod.Items.Weapons.Magic return new Vector2(15, 15); } - public override void AddRecipes() + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + Vector2 shootVelocity = new Vector2(speedX, speedY); + Vector2 shootPosition = position + shootVelocity * 8f; + Projectile.NewProjectile(shootPosition, shootVelocity, type, damage, knockBack, player.whoAmI); + return false; + } + + public override void AddRecipes() { ModRecipe recipe = new ModRecipe(mod); recipe.AddIngredient(ModContent.ItemType()); diff --git a/Items/Weapons/Magic/Vehemenc.cs b/Items/Weapons/Magic/Vehemenc.cs index 6b4bf24fba..78ca7bb07f 100644 --- a/Items/Weapons/Magic/Vehemenc.cs +++ b/Items/Weapons/Magic/Vehemenc.cs @@ -8,14 +8,14 @@ namespace CalamityMod.Items.Weapons.Magic { public class Vehemenc : ModItem { + public const int VehemenceSkullDamage = 7000; public override void SetStaticDefaults() { DisplayName.SetDefault("Vehemence"); Tooltip.SetDefault("Casts an intense energy blast\n" + "Does far more damage the more HP an enemy has left\n" + "Max damage is capped at 200,000\n" + - "If an enemy has full HP it will inflict several long-lasting debuffs\n" + - "Revengeance drop"); + "If an enemy has full HP it will inflict Demon Flames for an extremely long time"); Item.staff[item.type] = true; } @@ -26,8 +26,9 @@ namespace CalamityMod.Items.Weapons.Magic item.mana = 590; item.width = 44; item.height = 44; - item.useTime = 50; - item.useAnimation = 50; + item.useTime = item.useAnimation = 50; + item.noUseGraphic = true; + item.channel = true; item.useStyle = ItemUseStyleID.HoldingOut; item.noMelee = true; item.knockBack = 5.75f; @@ -35,20 +36,19 @@ namespace CalamityMod.Items.Weapons.Magic item.rare = ItemRarityID.Red; item.UseSound = SoundID.Item73; item.autoReuse = true; - item.shoot = ModContent.ProjectileType(); + item.shoot = ModContent.ProjectileType(); item.shootSpeed = 16f; } - public override Vector2? HoldoutOrigin() - { - return new Vector2(25, 25); - } + public override Vector2? HoldoutOrigin() => new Vector2(25, 25); public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) { - Projectile.NewProjectile(position.X, position.Y, speedX, speedY, ModContent.ProjectileType(), damage, knockBack, player.whoAmI); + Projectile.NewProjectile(position, Vector2.Zero, type, damage, knockBack, player.whoAmI); player.AddBuff(BuffID.ManaSickness, 600, true); return false; } + + public override bool CanUseItem(Player player) => player.ownedProjectileCounts[item.shoot] <= 0; } } diff --git a/Items/Weapons/Magic/VoidVortex.cs b/Items/Weapons/Magic/VoidVortex.cs index d5c849419b..c199cf4eaf 100644 --- a/Items/Weapons/Magic/VoidVortex.cs +++ b/Items/Weapons/Magic/VoidVortex.cs @@ -18,13 +18,13 @@ namespace CalamityMod.Items.Weapons.Magic public override void SetDefaults() { - item.damage = 75; + item.damage = 82; item.magic = true; item.mana = 60; item.width = 130; item.height = 130; - item.useTime = 49; - item.useAnimation = 49; + item.useTime = 80; + item.useAnimation = 80; item.useStyle = ItemUseStyleID.HoldingOut; item.noMelee = true; item.knockBack = 0f; diff --git a/Items/Weapons/Melee/DragonRage.cs b/Items/Weapons/Melee/DragonRage.cs index e6670e844a..683d97d6be 100644 --- a/Items/Weapons/Melee/DragonRage.cs +++ b/Items/Weapons/Melee/DragonRage.cs @@ -17,7 +17,7 @@ namespace CalamityMod.Items.Weapons.Melee public override void SetDefaults() { - item.damage = 1350; + item.damage = 1275; item.knockBack = 7.5f; item.useAnimation = item.useTime = 25; item.melee = true; diff --git a/Items/Weapons/Melee/Murasama.cs b/Items/Weapons/Melee/Murasama.cs index 28ea5cf715..30c4f8561a 100644 --- a/Items/Weapons/Melee/Murasama.cs +++ b/Items/Weapons/Melee/Murasama.cs @@ -19,6 +19,7 @@ namespace CalamityMod.Items.Weapons.Melee Tooltip.SetDefault("There will be blood!\n" + "ID and power-level locked\n" + "Prove your strength or have the correct user ID to wield this sword"); + Main.RegisterItemAnimation(item.type, new DrawAnimationVertical(6, 13)); } public override void SetDefaults() diff --git a/Items/Weapons/Melee/Omniblade.cs b/Items/Weapons/Melee/Omniblade.cs index 77835d62e0..0ccd879f86 100644 --- a/Items/Weapons/Melee/Omniblade.cs +++ b/Items/Weapons/Melee/Omniblade.cs @@ -1,6 +1,5 @@ -using CalamityMod.Buffs.StatDebuffs; using CalamityMod.Items.Materials; -using Microsoft.Xna.Framework; +using CalamityMod.Projectiles.Melee; using Terraria; using Terraria.ID; using Terraria.ModLoader; @@ -29,28 +28,18 @@ namespace CalamityMod.Items.Weapons.Melee item.autoReuse = true; item.height = 146; item.value = Item.buyPrice(0, 80, 0, 0); + item.noMelee = true; + item.noUseGraphic = true; + item.channel = true; + item.shoot = ModContent.ProjectileType(); + item.shootSpeed = 24f; item.rare = ItemRarityID.Yellow; } // Terraria seems to really dislike high crit values in SetDefaults public override void GetWeaponCrit(Player player, ref int crit) => crit += 45; - public override void UseItemHitbox(Player player, ref Rectangle hitbox, ref bool noHitbox) - { - hitbox = CalamityUtils.FixSwingHitbox(102, 102); - } - - public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit) - { - if (Main.rand.NextBool(5)) - target.AddBuff(ModContent.BuffType(), 360); - } - - public override void OnHitPvp(Player player, Player target, int damage, bool crit) - { - if (Main.rand.NextBool(5)) - target.AddBuff(ModContent.BuffType(), 360); - } + public override bool CanUseItem(Player player) => player.ownedProjectileCounts[item.shoot] <= 0; public override void AddRecipes() { diff --git a/Items/Weapons/Melee/PhosphorescentGauntlet.cs b/Items/Weapons/Melee/PhosphorescentGauntlet.cs new file mode 100644 index 0000000000..4167740a72 --- /dev/null +++ b/Items/Weapons/Melee/PhosphorescentGauntlet.cs @@ -0,0 +1,50 @@ +using CalamityMod.Projectiles.Melee; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Weapons.Melee +{ + public class PhosphorescentGauntlet : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Phosphorescent Gauntlet"); + Tooltip.SetDefault("Releases rapid sulphurous punches\n" + + "On use, you lunge in the direction of the mouse.\n" + + "On collision, you are knocked back"); + } + + public override void SetDefaults() + { + item.width = item.height = 40; + item.damage = 750; + item.melee = true; + item.noMelee = true; + item.noUseGraphic = true; + item.channel = true; + item.useAnimation = item.useTime = 40; + item.useTurn = true; + item.useStyle = ItemUseStyleID.SwingThrow; + item.knockBack = 9f; + item.UseSound = SoundID.Item1; + item.autoReuse = true; + item.value = CalamityGlobalItem.RarityPureGreenBuyPrice; + item.shoot = ModContent.ProjectileType(); + item.shootSpeed = 1f; + item.Calamity().customRarity = CalamityRarity.PureGreen; + } + + // Terraria seems to really dislike high crit values in SetDefaults. + public override void GetWeaponCrit(Player player, ref int crit) => crit += 10; + + public override bool CanUseItem(Player player) => player.ownedProjectileCounts[item.shoot] <= 0; + + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + Projectile.NewProjectile(position, new Vector2(speedX, speedY), type, damage, knockBack, player.whoAmI); + return false; + } + } +} diff --git a/Items/Weapons/Melee/PhosphorescentGauntlet.png b/Items/Weapons/Melee/PhosphorescentGauntlet.png new file mode 100644 index 0000000000..a470c6a68d Binary files /dev/null and b/Items/Weapons/Melee/PhosphorescentGauntlet.png differ diff --git a/Items/Weapons/Melee/PhotonRipper.cs b/Items/Weapons/Melee/PhotonRipper.cs new file mode 100644 index 0000000000..aa3deafe46 --- /dev/null +++ b/Items/Weapons/Melee/PhotonRipper.cs @@ -0,0 +1,51 @@ +using CalamityMod.Projectiles.Melee; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Weapons.Melee +{ + public class PhotonRipper : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Photon Ripper"); + Tooltip.SetDefault("Unleashes a flurry of prismatic crystals at extremely fast speeds\n" + + "These crystals are capable of breaking trees"); + } + + public override void SetDefaults() + { + item.height = 134; + item.width = 54; + item.damage = 305; + item.axe = 3330; + item.axe /= 5; + item.melee = true; + item.noMelee = true; + item.noUseGraphic = true; + item.channel = true; + item.useStyle = ItemUseStyleID.HoldingOut; + item.useTime = 5; + item.useAnimation = 25; + item.knockBack = 12f; + item.autoReuse = false; + item.value = CalamityGlobalItem.RarityVioletBuyPrice; + item.rare = ItemRarityID.Red; + item.shoot = ModContent.ProjectileType(); + item.shootSpeed = 1f; + item.Calamity().customRarity = CalamityRarity.Violet; + } + + public override void GetWeaponCrit(Player player, ref int crit) => crit += 18; + + public override bool CanUseItem(Player player) => player.ownedProjectileCounts[item.shoot] <= 0; + + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + Projectile.NewProjectile(position, new Vector2(speedX, speedY), type, damage, knockBack, player.whoAmI, 0f, 0f); + return false; + } + } +} diff --git a/Items/Weapons/Melee/PhotonRipper.png b/Items/Weapons/Melee/PhotonRipper.png new file mode 100644 index 0000000000..7a425f4909 Binary files /dev/null and b/Items/Weapons/Melee/PhotonRipper.png differ diff --git a/Items/Weapons/Melee/SpineOfThanatos.cs b/Items/Weapons/Melee/SpineOfThanatos.cs new file mode 100644 index 0000000000..69b7b1c1df --- /dev/null +++ b/Items/Weapons/Melee/SpineOfThanatos.cs @@ -0,0 +1,51 @@ +using CalamityMod.Projectiles.Melee; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Weapons.Melee +{ + public class SpineOfThanatos : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Spine of Thanatos"); + Tooltip.SetDefault("Releases 3 fast metallic whips outward\n" + + "Once all three collide, a prism of light is shot outward\n" + + "If an enemy is within the line of sight of the whips on collision, the light will fire towards it"); + } + + public override void SetDefaults() + { + item.width = item.height = 28; + item.damage = 410; + item.rare = ItemRarityID.Red; + item.value = CalamityGlobalItem.RarityVioletBuyPrice; + item.Calamity().customRarity = CalamityRarity.Violet; + item.noMelee = true; + item.noUseGraphic = true; + item.channel = true; + item.autoReuse = true; + item.melee = true; + item.useAnimation = item.useTime = 24; + item.useStyle = ItemUseStyleID.HoldingOut; + item.knockBack = 8f; + item.UseSound = SoundID.Item68; + item.shootSpeed = 1f; + item.shoot = ModContent.ProjectileType(); + } + + public override bool CanUseItem(Player player) => player.ownedProjectileCounts[item.shoot] <= 0; + + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + for (int i = 0; i < 2; i++) + Projectile.NewProjectile(position.X, position.Y, speedX, speedY, type, damage, knockBack, player.whoAmI, 0f, (i == 0f).ToDirectionInt()); + + // Create a third, final whip that does not swing around at all and instead simply flies towards the mouse. + Projectile.NewProjectile(position.X, position.Y, speedX, speedY, type, damage, knockBack, player.whoAmI, 0f, 0f); + return false; + } + } +} diff --git a/Items/Weapons/Melee/SpineOfThanatos.png b/Items/Weapons/Melee/SpineOfThanatos.png new file mode 100644 index 0000000000..cbac11a060 Binary files /dev/null and b/Items/Weapons/Melee/SpineOfThanatos.png differ diff --git a/Items/Weapons/Melee/Violence.cs b/Items/Weapons/Melee/Violence.cs new file mode 100644 index 0000000000..306590f0c4 --- /dev/null +++ b/Items/Weapons/Melee/Violence.cs @@ -0,0 +1,49 @@ +using CalamityMod.Projectiles.Melee; +using CalamityMod.Projectiles.Melee.Spears; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Weapons.Melee +{ + public class Violence : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Violence"); + Tooltip.SetDefault("Releases a blazing fork which stays near the mouse and shreds enemies"); + } + + public override void SetDefaults() + { + item.height = item.width = 142; + item.damage = 204; + item.melee = true; + item.noMelee = true; + item.useTurn = true; + item.noUseGraphic = true; + item.useAnimation = 25; + item.useTime = 25; + item.useStyle = ItemUseStyleID.HoldingOut; + item.knockBack = 9f; + item.UseSound = SoundID.Item1; + item.autoReuse = true; + item.value = CalamityGlobalItem.RarityVioletBuyPrice; + item.rare = ItemRarityID.Purple; + item.Calamity().customRarity = CalamityRarity.Violet; + item.channel = true; + item.shoot = ModContent.ProjectileType(); + item.shootSpeed = 15f; + } + + public override bool CanUseItem(Player player) => player.altFunctionUse == 2 || player.ownedProjectileCounts[item.shoot] <= 0; + + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + Vector2 shootVelocity = new Vector2(speedX, speedY); + Projectile.NewProjectile(position, shootVelocity, type, damage, knockBack, player.whoAmI, 0f, shootVelocity.ToRotation()); + return false; + } + } +} diff --git a/Items/Weapons/Melee/Violence.png b/Items/Weapons/Melee/Violence.png new file mode 100644 index 0000000000..0946ba16ec Binary files /dev/null and b/Items/Weapons/Melee/Violence.png differ diff --git a/Items/Weapons/Ranged/AMR.cs b/Items/Weapons/Ranged/AMR.cs index 89e8b5111c..bb5728702a 100644 --- a/Items/Weapons/Ranged/AMR.cs +++ b/Items/Weapons/Ranged/AMR.cs @@ -18,7 +18,7 @@ namespace CalamityMod.Items.Weapons.Ranged public override void SetDefaults() { - item.damage = 3520; + item.damage = 3240; item.ranged = true; item.width = 76; item.height = 30; diff --git a/Items/Weapons/Ranged/AcesHigh.cs b/Items/Weapons/Ranged/AcesHigh.cs index 13b704a3e8..8884fcf40e 100644 --- a/Items/Weapons/Ranged/AcesHigh.cs +++ b/Items/Weapons/Ranged/AcesHigh.cs @@ -21,7 +21,7 @@ namespace CalamityMod.Items.Weapons.Ranged public override void SetDefaults() { - item.damage = 479; + item.damage = 230; item.ranged = true; item.width = 48; item.height = 30; diff --git a/Items/Weapons/Ranged/BulletFilledShotgun.cs b/Items/Weapons/Ranged/BulletFilledShotgun.cs new file mode 100644 index 0000000000..0dcb7bf48a --- /dev/null +++ b/Items/Weapons/Ranged/BulletFilledShotgun.cs @@ -0,0 +1,76 @@ +using CalamityMod.Items.Materials; +using CalamityMod.Projectiles.Ranged; +using Microsoft.Xna.Framework; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Weapons.Ranged +{ + public class BulletFilledShotgun : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Bullet-Filled Shotgun"); + Tooltip.SetDefault("Fires a massive spread of bouncing bullets\n" + + "Consumes five bullets per-use\n" + + "Aim? What's that?"); + } + public override void SetDefaults() + { + item.damage = 1; + item.knockBack = 0f; + item.useTime = item.useAnimation = 45; + item.ranged = true; + item.noMelee = true; + item.autoReuse = true; + item.useAmmo = AmmoID.Bullet; + item.shootSpeed = 9f; + item.shoot = ModContent.ProjectileType(); + + item.width = 64; + item.height = 24; + item.useStyle = ItemUseStyleID.HoldingOut; + item.UseSound = SoundID.Item38; + item.value = CalamityGlobalItem.Rarity3BuyPrice; + item.rare = ItemRarityID.Orange; + item.Calamity().donorItem = true; + } + + public override Vector2? HoldoutOffset() => new Vector2(-7, 0); + + public override bool CanUseItem(Player player) => CalamityGlobalItem.HasEnoughAmmo(player, item, 5); + + // Disable vanilla ammo consumption + public override bool ConsumeAmmo(Player player) => false; + + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + type = item.shoot; + int bulletAmt = Main.rand.Next(25,35); + for (int i = 0; i < bulletAmt; i++) + { + float newSpeedX = speedX + Main.rand.NextFloat(-15f, 15f); + float newSpeedY = speedY + Main.rand.NextFloat(-15f, 15f); + Projectile.NewProjectile(position.X, position.Y, newSpeedX, newSpeedY, type, damage, knockBack, player.whoAmI); + } + + // Consume 5 ammo per shot + CalamityGlobalItem.ConsumeAdditionalAmmo(player, item, 5); + return false; + } + + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ItemID.MusketBall, 100); + recipe.AddIngredient(ItemID.IronBar, 7); + recipe.anyIronBar = true; + recipe.AddIngredient(ModContent.ItemType(), 3); + recipe.AddTile(TileID.Anvils); + recipe.SetResult(this); + recipe.AddRecipe(); + } + } +} diff --git a/Items/Weapons/Ranged/BulletFilledShotgun.png b/Items/Weapons/Ranged/BulletFilledShotgun.png new file mode 100644 index 0000000000..2635f2a49c Binary files /dev/null and b/Items/Weapons/Ranged/BulletFilledShotgun.png differ diff --git a/Items/Weapons/Ranged/Condemnation.cs b/Items/Weapons/Ranged/Condemnation.cs new file mode 100644 index 0000000000..ae59eee27d --- /dev/null +++ b/Items/Weapons/Ranged/Condemnation.cs @@ -0,0 +1,79 @@ +using CalamityMod.Projectiles.Ranged; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Weapons.Ranged +{ + public class Condemnation : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Condemnation"); + Tooltip.SetDefault("Left clicks allows you to charge the repeater and release more arrows the longer the charge lasts\n" + + "Right clicks release fast moving arrows"); + } + + public override void SetDefaults() + { + item.damage = 566; + item.ranged = true; + item.width = 130; + item.height = 42; + item.useTime = item.useAnimation = 16; + item.useStyle = ItemUseStyleID.HoldingOut; + item.noMelee = true; + item.knockBack = 5f; + item.value = CalamityGlobalItem.RarityVioletBuyPrice; + item.rare = ItemRarityID.Purple; + item.Calamity().customRarity = CalamityRarity.Violet; + item.autoReuse = true; + item.shoot = ModContent.ProjectileType(); + item.shootSpeed = 14.5f; + item.useAmmo = AmmoID.Arrow; + } + + public override Vector2? HoldoutOffset() => new Vector2(-50f, 0f); + + public override bool AltFunctionUse(Player player) => true; + + public override bool CanUseItem(Player player) + { + if (player.altFunctionUse == 2) + { + item.noUseGraphic = false; + item.UseSound = SoundID.DD2_BallistaTowerShot; + item.channel = false; + } + else + { + item.noUseGraphic = true; + item.UseSound = SoundID.Item20; + item.channel = true; + return player.ownedProjectileCounts[ModContent.ProjectileType()] <= 0; + } + return base.CanUseItem(player); + } + + public override float UseTimeMultiplier(Player player) => player.altFunctionUse == 2 ? 0.7f : 1f; + + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + Vector2 shootVelocity = new Vector2(speedX, speedY); + Vector2 shootDirection = shootVelocity.SafeNormalize(Vector2.UnitX * player.direction); + + // Single arrow firing. + if (player.altFunctionUse == 2) + { + Vector2 tipPosition = position + shootDirection * 110f; + Projectile.NewProjectile(tipPosition, shootVelocity, item.shoot, damage, knockBack, player.whoAmI); + } + + // Charge-up. Done via a holdout projectile. + else + Projectile.NewProjectile(position, shootDirection, ModContent.ProjectileType(), 0, knockBack, player.whoAmI); + return false; + } + } +} diff --git a/Items/Weapons/Ranged/Condemnation.png b/Items/Weapons/Ranged/Condemnation.png new file mode 100644 index 0000000000..09d5d3c1fb Binary files /dev/null and b/Items/Weapons/Ranged/Condemnation.png differ diff --git a/Items/Weapons/Ranged/DragonsBreath.cs b/Items/Weapons/Ranged/DragonsBreath.cs index 7f23f120b5..daafd98c11 100644 --- a/Items/Weapons/Ranged/DragonsBreath.cs +++ b/Items/Weapons/Ranged/DragonsBreath.cs @@ -18,7 +18,7 @@ namespace CalamityMod.Items.Weapons.Ranged public override void SetDefaults() { - item.damage = 78; + item.damage = 200; item.ranged = true; item.width = 64; item.height = 28; diff --git a/Items/Weapons/Ranged/Drataliornus.cs b/Items/Weapons/Ranged/Drataliornus.cs index f1ced9fdd0..05c1402721 100644 --- a/Items/Weapons/Ranged/Drataliornus.cs +++ b/Items/Weapons/Ranged/Drataliornus.cs @@ -24,7 +24,7 @@ Right click to fire two devastating barrages of five empowered fireballs. public override void SetDefaults() { - item.damage = 231; + item.damage = 80; item.knockBack = 1f; item.shootSpeed = 18f; item.useStyle = ItemUseStyleID.HoldingOut; diff --git a/Items/Weapons/Ranged/HeavenlyGale.cs b/Items/Weapons/Ranged/HeavenlyGale.cs index cad26edbf9..232861159f 100644 --- a/Items/Weapons/Ranged/HeavenlyGale.cs +++ b/Items/Weapons/Ranged/HeavenlyGale.cs @@ -48,7 +48,6 @@ namespace CalamityMod.Items.Weapons.Ranged public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) { Vector2 source = player.RotatedRelativePoint(player.MountedCenter, true); - float dmgMult = 1f; float piOver10 = MathHelper.Pi * 0.1f; int arrowAmt = 5; Vector2 speed = new Vector2(speedX, speedY); @@ -98,6 +97,7 @@ namespace CalamityMod.Items.Weapons.Ranged break; } + float dmgMult = 1f; if (arrowTypes[i] == ProjectileType()) dmgMult = 0.5f; diff --git a/Items/Weapons/Ranged/MagnomalyCannon.cs b/Items/Weapons/Ranged/MagnomalyCannon.cs index 9c6f2c15cd..b56dc12554 100644 --- a/Items/Weapons/Ranged/MagnomalyCannon.cs +++ b/Items/Weapons/Ranged/MagnomalyCannon.cs @@ -21,7 +21,7 @@ namespace CalamityMod.Items.Weapons.Ranged public override void SetDefaults() { - item.damage = 435; + item.damage = 340; item.ranged = true; item.width = 84; item.height = 30; diff --git a/Items/Weapons/Ranged/Photoviscerator.cs b/Items/Weapons/Ranged/Photoviscerator.cs index da0b70c1b3..3193e384ae 100644 --- a/Items/Weapons/Ranged/Photoviscerator.cs +++ b/Items/Weapons/Ranged/Photoviscerator.cs @@ -11,7 +11,7 @@ namespace CalamityMod.Items.Weapons.Ranged public class Photoviscerator : ModItem { public const int CooldownTime = 60 * 7; // 7 second cooldown. - public const double AltFireDamageMult = 4.27; + public const double AltFireDamageMult = 2.5; public override void SetStaticDefaults() { diff --git a/Items/Weapons/Ranged/Skullmasher.cs b/Items/Weapons/Ranged/Skullmasher.cs index 518ec98cc7..bbf4b19e9e 100644 --- a/Items/Weapons/Ranged/Skullmasher.cs +++ b/Items/Weapons/Ranged/Skullmasher.cs @@ -16,7 +16,7 @@ namespace CalamityMod.Items.Weapons.Ranged public override void SetDefaults() { - item.damage = 924; + item.damage = 1100; item.ranged = true; item.width = 142; item.height = 40; diff --git a/Items/Weapons/Ranged/SurgeDriver.cs b/Items/Weapons/Ranged/SurgeDriver.cs new file mode 100644 index 0000000000..f3e8ed0a68 --- /dev/null +++ b/Items/Weapons/Ranged/SurgeDriver.cs @@ -0,0 +1,87 @@ +using CalamityMod.Projectiles.Ranged; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Weapons.Ranged +{ + public class SurgeDriver : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Surge Driver"); + Tooltip.SetDefault("Left clicks release a laser ray that explodes on collision\n" + + "Right clicks release a barrage of laser beams that release homing energy on enemy hits"); + } + + public override void SetDefaults() + { + item.damage = 156; + item.ranged = true; + item.width = 164; + item.height = 58; + item.useTime = item.useAnimation = 56; + item.useStyle = ItemUseStyleID.HoldingOut; + item.noMelee = true; + item.knockBack = 8f; + item.value = CalamityGlobalItem.RarityVioletBuyPrice; + item.rare = ItemRarityID.Purple; + item.Calamity().customRarity = CalamityRarity.Violet; + item.autoReuse = true; + item.shoot = ModContent.ProjectileType(); + item.shootSpeed = 11f; + item.useAmmo = AmmoID.Bullet; + } + + public override Vector2? HoldoutOffset() => new Vector2(-50f, -8f); + + public override bool AltFunctionUse(Player player) => true; + + public override bool CanUseItem(Player player) + { + if (player.altFunctionUse == 2) + { + item.noUseGraphic = false; + item.reuseDelay = 0; + item.UseSound = SoundID.Item14; + item.channel = false; + } + else + { + item.noUseGraphic = true; + item.reuseDelay = 28; + item.UseSound = mod.GetLegacySoundSlot(SoundType.Item, "Sounds/Item/LaserCannon"); + item.channel = true; + return player.ownedProjectileCounts[ModContent.ProjectileType()] <= 0; + } + return base.CanUseItem(player); + } + + public override float UseTimeMultiplier(Player player) => player.altFunctionUse == 2 ? 5f : 1f; + + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + Vector2 shootVelocity = new Vector2(speedX, speedY); + Vector2 shootDirection = shootVelocity.SafeNormalize(Vector2.UnitX * player.direction); + Vector2 gunTip = position + shootDirection * item.scale * 126f; + gunTip.Y -= 6f; + + // Large bullet/rocket releasing. + if (player.altFunctionUse == 2) + { + for (int i = 0; i < 2; i++) + { + Vector2 newShootVelocity = shootVelocity * Main.rand.NextFloat(1f, 1.45f); + newShootVelocity = newShootVelocity.RotatedByRandom(0.15f); + Projectile.NewProjectile(gunTip, newShootVelocity, item.shoot, damage, knockBack, player.whoAmI); + } + } + + // Snipe blast. Done via a held projectile. + else + Projectile.NewProjectile(gunTip, shootVelocity, ModContent.ProjectileType(), 0, knockBack, player.whoAmI); + return false; + } + } +} diff --git a/Items/Weapons/Ranged/SurgeDriver.png b/Items/Weapons/Ranged/SurgeDriver.png new file mode 100644 index 0000000000..12d9fe4928 Binary files /dev/null and b/Items/Weapons/Ranged/SurgeDriver.png differ diff --git a/Items/Weapons/Ranged/TheJailor.cs b/Items/Weapons/Ranged/TheJailor.cs new file mode 100644 index 0000000000..88451afad2 --- /dev/null +++ b/Items/Weapons/Ranged/TheJailor.cs @@ -0,0 +1,49 @@ +using CalamityMod.Projectiles.Ranged; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Weapons.Ranged +{ + public class TheJailor : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("The Jailor"); + Tooltip.SetDefault("Releases electric mines outward that connect to each-other via arcs"); + } + + public override void SetDefaults() + { + item.damage = 360; + item.ranged = true; + item.width = 102; + item.height = 70; + item.useTime = item.useAnimation = 28; + item.useStyle = ItemUseStyleID.HoldingOut; + item.noMelee = true; + item.knockBack = 8f; + item.value = CalamityGlobalItem.RarityVioletBuyPrice; + item.rare = ItemRarityID.Purple; + item.Calamity().customRarity = CalamityRarity.Violet; + item.UseSound = SoundID.Item14; + item.autoReuse = true; + item.shoot = ModContent.ProjectileType(); + item.shootSpeed = 11f; + item.useAmmo = AmmoID.Bullet; + } + + public override Vector2? HoldoutOffset() => new Vector2(-40f, -16f); + + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + Vector2 shootVelocity = new Vector2(speedX, speedY); + Vector2 shootDirection = shootVelocity.SafeNormalize(Vector2.UnitX * player.direction); + Vector2 gunTip = position + shootDirection * item.scale * 45f; + + Projectile.NewProjectile(gunTip, shootVelocity, item.shoot, damage, knockBack, player.whoAmI); + return false; + } + } +} diff --git a/Items/Weapons/Ranged/TheJailor.png b/Items/Weapons/Ranged/TheJailor.png new file mode 100644 index 0000000000..fe3c9379ec Binary files /dev/null and b/Items/Weapons/Ranged/TheJailor.png differ diff --git a/Items/Weapons/Ranged/TyrannysEnd.cs b/Items/Weapons/Ranged/TyrannysEnd.cs index f0fafacd23..2506f776bb 100644 --- a/Items/Weapons/Ranged/TyrannysEnd.cs +++ b/Items/Weapons/Ranged/TyrannysEnd.cs @@ -20,7 +20,7 @@ namespace CalamityMod.Items.Weapons.Ranged public override void SetDefaults() { - item.damage = 1260; + item.damage = 2250; item.knockBack = 9.5f; item.ranged = true; item.useTime = 55; diff --git a/Items/Weapons/Rogue/Celestus.cs b/Items/Weapons/Rogue/Celestus.cs index 11fd20a13e..af511ced9e 100644 --- a/Items/Weapons/Rogue/Celestus.cs +++ b/Items/Weapons/Rogue/Celestus.cs @@ -41,7 +41,7 @@ namespace CalamityMod.Items.Weapons.Rogue { if (player.Calamity().StealthStrikeAvailable()) //setting the stealth strike { - int stealth = Projectile.NewProjectile(position, new Vector2(speedX, speedY), type, damage, knockBack, player.whoAmI); + int stealth = Projectile.NewProjectile(position, new Vector2(speedX, speedY), type, (int)(damage * 0.65), knockBack, player.whoAmI); if (stealth.WithinBounds(Main.maxProjectiles)) Main.projectile[stealth].Calamity().stealthStrike = true; } diff --git a/Items/Weapons/Rogue/DukesDecapitator.cs b/Items/Weapons/Rogue/DukesDecapitator.cs index 43aff6047f..632515a33c 100644 --- a/Items/Weapons/Rogue/DukesDecapitator.cs +++ b/Items/Weapons/Rogue/DukesDecapitator.cs @@ -2,6 +2,7 @@ using Terraria; using Terraria.ID; using Terraria.ModLoader; using CalamityMod.Projectiles.Rogue; +using Microsoft.Xna.Framework; namespace CalamityMod.Items.Weapons.Rogue { @@ -34,5 +35,13 @@ namespace CalamityMod.Items.Weapons.Rogue item.shootSpeed = 15f; item.Calamity().rogue = true; } + + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + int proj = Projectile.NewProjectile(position, new Vector2(speedX, speedY), type, damage, knockBack, player.whoAmI); + if (Main.projectile.IndexInRange(proj)) + Main.projectile[proj].Calamity().stealthStrike = player.Calamity().StealthStrikeAvailable(); + return false; + } } } diff --git a/Items/Weapons/Rogue/Eradicator.cs b/Items/Weapons/Rogue/Eradicator.cs index 6f0dce3d0f..709098ebd9 100644 --- a/Items/Weapons/Rogue/Eradicator.cs +++ b/Items/Weapons/Rogue/Eradicator.cs @@ -40,7 +40,7 @@ namespace CalamityMod.Items.Weapons.Rogue public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) { if (player.Calamity().StealthStrikeAvailable()) - damage /= 2; + damage = (int)(damage * 0.4); int proj = Projectile.NewProjectile(position, new Vector2(speedX, speedY), type, damage, knockBack, player.whoAmI); if (player.Calamity().StealthStrikeAvailable() && proj.WithinBounds(Main.maxProjectiles)) diff --git a/Items/Weapons/Rogue/GodsParanoia.cs b/Items/Weapons/Rogue/GodsParanoia.cs index 4a27fc49f1..6314525c45 100644 --- a/Items/Weapons/Rogue/GodsParanoia.cs +++ b/Items/Weapons/Rogue/GodsParanoia.cs @@ -69,7 +69,7 @@ Right click to delete all existing spiky balls"); modPlayer.killSpikyBalls = false; if (modPlayer.StealthStrikeAvailable()) //setting the stealth strike { - damage = (int)(damage * 1.12); + damage = (int)(damage * 1.345); int stealth = Projectile.NewProjectile(position, new Vector2(speedX, speedY), type, damage, knockBack, player.whoAmI); if (stealth.WithinBounds(Main.maxProjectiles)) Main.projectile[stealth].Calamity().stealthStrike = true; diff --git a/Items/Weapons/Rogue/LuminousStriker.cs b/Items/Weapons/Rogue/LuminousStriker.cs index 6cb5770e69..c4e48f7c47 100644 --- a/Items/Weapons/Rogue/LuminousStriker.cs +++ b/Items/Weapons/Rogue/LuminousStriker.cs @@ -3,6 +3,7 @@ using Terraria.ID; using Terraria.ModLoader; using CalamityMod.Items.Materials; using CalamityMod.Projectiles.Rogue; +using Microsoft.Xna.Framework; namespace CalamityMod.Items.Weapons.Rogue { @@ -37,6 +38,14 @@ namespace CalamityMod.Items.Weapons.Rogue item.Calamity().rogue = true; } + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + int proj = Projectile.NewProjectile(position, new Vector2(speedX, speedY), type, damage, knockBack, player.whoAmI); + if (Main.projectile.IndexInRange(proj)) + Main.projectile[proj].Calamity().stealthStrike = player.Calamity().StealthStrikeAvailable(); + return false; + } + public override void AddRecipes() { ModRecipe recipe = new ModRecipe(mod); diff --git a/Items/Weapons/Rogue/RefractionRotor.cs b/Items/Weapons/Rogue/RefractionRotor.cs new file mode 100644 index 0000000000..16b39952a0 --- /dev/null +++ b/Items/Weapons/Rogue/RefractionRotor.cs @@ -0,0 +1,48 @@ +using CalamityMod.Projectiles.Rogue; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Weapons.Rogue +{ + public class RefractionRotor : RogueWeapon + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Refraction Rotor"); + Tooltip.SetDefault("Fires a large prismatic razorblade\n" + + "After hitting something, the blade dies moments later\n" + + "The blade explodes into rockets on death\n" + + "Stealth strikes explode into more rockets on death"); + } + + public override void SafeSetDefaults() + { + item.width = item.height = 120; + item.damage = 110; + item.knockBack = 8.5f; + item.useAnimation = item.useTime = 14; + item.Calamity().rogue = true; + item.autoReuse = true; + item.shootSpeed = 18f; + item.shoot = ModContent.ProjectileType(); + + item.useStyle = ItemUseStyleID.SwingThrow; + item.UseSound = SoundID.Item1; + item.noMelee = true; + item.noUseGraphic = true; + item.value = CalamityGlobalItem.RarityVioletBuyPrice; + item.rare = ItemRarityID.Red; + item.Calamity().customRarity = CalamityRarity.Violet; + } + + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + int shuriken = Projectile.NewProjectile(position, new Vector2(speedX, speedY), type, damage, knockBack, player.whoAmI); + if (player.Calamity().StealthStrikeAvailable() && Main.projectile.IndexInRange(shuriken)) + Main.projectile[shuriken].Calamity().stealthStrike = true; + return false; + } + } +} diff --git a/Items/Weapons/Rogue/RefractionRotor.png b/Items/Weapons/Rogue/RefractionRotor.png new file mode 100644 index 0000000000..9b945f0278 Binary files /dev/null and b/Items/Weapons/Rogue/RefractionRotor.png differ diff --git a/Items/Weapons/Rogue/Sacrifice.cs b/Items/Weapons/Rogue/Sacrifice.cs new file mode 100644 index 0000000000..c3665fa0c6 --- /dev/null +++ b/Items/Weapons/Rogue/Sacrifice.cs @@ -0,0 +1,69 @@ +using CalamityMod.NPCs.NormalNPCs; +using CalamityMod.Projectiles.Rogue; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Weapons.Rogue +{ + public class Sacrifice : RogueWeapon + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Sacrifice"); + Tooltip.SetDefault("Releases a dagger that sticks to enemies\n" + + "Right clicking causes all stuck daggers to fly back at you and give you life\n" + + "Daggers stuck to enemies release bloodsplosions over time"); + } + + public override void SafeSetDefaults() + { + item.damage = 266; + item.width = item.height = 68; + item.useAnimation = item.useTime = 6; + item.noMelee = true; + item.noUseGraphic = true; + item.useStyle = ItemUseStyleID.SwingThrow; + item.knockBack = 4f; + item.rare = ItemRarityID.Purple; + item.Calamity().customRarity = CalamityRarity.Violet; + item.UseSound = SoundID.Item1; + item.autoReuse = true; + item.value = CalamityGlobalItem.RarityVioletBuyPrice; + item.shoot = ModContent.ProjectileType(); + item.shootSpeed = 12f; + item.Calamity().rogue = true; + } + + public override bool AltFunctionUse(Player player) => true; + + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + if (player.altFunctionUse == 2) + { + for (int i = 0; i < Main.maxProjectiles; i++) + { + if (Main.projectile[i].type != type || !Main.projectile[i].active || Main.projectile[i].owner != player.whoAmI) + continue; + + if (Main.projectile[i].ai[0] != 1f) + continue; + + NPC attachedNPC = Main.npc[(int)Main.projectile[i].ai[1]]; + Main.projectile[i].ai[0] = 2f; + Main.projectile[i].ModProjectile().AbleToHealOwner = attachedNPC.type != NPCID.TargetDummy && attachedNPC.type != ModContent.NPCType(); + Main.projectile[i].netUpdate = true; + } + return false; + } + + Vector2 velocity = new Vector2(speedX, speedY); + position += velocity * 3f; + int proj = Projectile.NewProjectile(position, velocity, type, damage, knockBack, player.whoAmI); + if (player.Calamity().StealthStrikeAvailable() && Main.projectile.IndexInRange(proj)) + Main.projectile[proj].Calamity().stealthStrike = true; + return false; + } + } +} diff --git a/Items/Weapons/Rogue/Sacrifice.png b/Items/Weapons/Rogue/Sacrifice.png new file mode 100644 index 0000000000..4ad5c25480 Binary files /dev/null and b/Items/Weapons/Rogue/Sacrifice.png differ diff --git a/Items/Weapons/Rogue/ScarletDevil.cs b/Items/Weapons/Rogue/ScarletDevil.cs index 19e369a625..41d9c88861 100644 --- a/Items/Weapons/Rogue/ScarletDevil.cs +++ b/Items/Weapons/Rogue/ScarletDevil.cs @@ -1,6 +1,7 @@ using CalamityMod.Items.Materials; using CalamityMod.Projectiles.Rogue; using CalamityMod.Tiles.Furniture.CraftingStations; +using Microsoft.Xna.Framework; using Terraria; using Terraria.ID; using Terraria.ModLoader; @@ -25,9 +26,8 @@ namespace CalamityMod.Items.Weapons.Rogue item.damage = 8000; item.noMelee = true; item.noUseGraphic = true; - item.useAnimation = 60; + item.useAnimation = item.useTime = 81; item.useStyle = ItemUseStyleID.SwingThrow; - item.useTime = 60; item.knockBack = 8f; item.UseSound = SoundID.Item60; item.autoReuse = true; @@ -40,8 +40,16 @@ namespace CalamityMod.Items.Weapons.Rogue item.Calamity().devItem = true; } - // Terraria seems to really dislike high crit values in SetDefaults - public override void GetWeaponCrit(Player player, ref int crit) => crit += 20; + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + int proj = Projectile.NewProjectile(position, new Vector2(speedX, speedY), type, damage, knockBack, player.whoAmI); + if (Main.projectile.IndexInRange(proj)) + Main.projectile[proj].Calamity().stealthStrike = player.Calamity().StealthStrikeAvailable(); + return false; + } + + // Terraria seems to really dislike high crit values in SetDefaults + public override void GetWeaponCrit(Player player, ref int crit) => crit += 20; public override void AddRecipes() { diff --git a/Items/Weapons/Rogue/TheAtomSplitter.cs b/Items/Weapons/Rogue/TheAtomSplitter.cs new file mode 100644 index 0000000000..18635adb8b --- /dev/null +++ b/Items/Weapons/Rogue/TheAtomSplitter.cs @@ -0,0 +1,46 @@ +using CalamityMod.Projectiles.Rogue; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Weapons.Rogue +{ + public class TheAtomSplitter : RogueWeapon + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("The Atom Splitter"); + Tooltip.SetDefault("Fires a javelin that releases energy duplicates at enemies it hits\n" + + "Stealth strikes release duplicates much more quickly"); + } + + public override void SafeSetDefaults() + { + item.width = item.height = 128; + item.damage = 256; + item.knockBack = 7f; + item.useAnimation = item.useTime = 14; + item.Calamity().rogue = true; + item.autoReuse = true; + item.shootSpeed = 24f; + item.shoot = ModContent.ProjectileType(); + + item.useStyle = ItemUseStyleID.SwingThrow; + item.UseSound = SoundID.Item1; + item.noMelee = true; + item.noUseGraphic = true; + item.value = CalamityGlobalItem.RarityVioletBuyPrice; + item.rare = ItemRarityID.Red; + item.Calamity().customRarity = CalamityRarity.Violet; + } + + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + int javelin = Projectile.NewProjectile(position, new Vector2(speedX, speedY), type, damage, knockBack, player.whoAmI, -1f); + if (player.Calamity().StealthStrikeAvailable() && Main.projectile.IndexInRange(javelin)) + Main.projectile[javelin].Calamity().stealthStrike = true; + return false; + } + } +} diff --git a/Items/Weapons/Rogue/TheAtomSplitter.png b/Items/Weapons/Rogue/TheAtomSplitter.png new file mode 100644 index 0000000000..c1d0c0131b Binary files /dev/null and b/Items/Weapons/Rogue/TheAtomSplitter.png differ diff --git a/Items/Weapons/Summon/DaedalusGolemStaff.cs b/Items/Weapons/Summon/DaedalusGolemStaff.cs new file mode 100644 index 0000000000..8486a97ddf --- /dev/null +++ b/Items/Weapons/Summon/DaedalusGolemStaff.cs @@ -0,0 +1,54 @@ +using CalamityMod.Items.Materials; +using CalamityMod.Projectiles.Summon; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Weapons.Summon +{ + public class DaedalusGolemStaff : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Daedalus Golem Staff"); + Tooltip.SetDefault("Summons a Daedalus Golem soldier that fires pellets and electricity\n" + + "Shining god of greed"); // Funny Hollow Knight reference. + } + + public override void SetDefaults() + { + item.damage = 70; + item.mana = 12; + item.width = item.height = 32; + item.useTime = item.useAnimation = 25; + item.useStyle = ItemUseStyleID.SwingThrow; + item.noMelee = true; + item.knockBack = 3f; + item.UseSound = SoundID.Item67; + item.autoReuse = true; + item.shoot = ModContent.ProjectileType(); + item.shootSpeed = 10f; + item.summon = true; + + item.value = CalamityGlobalItem.Rarity5BuyPrice; + item.rare = ItemRarityID.Pink; + } + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + Point mouseTileCoords = Main.MouseWorld.ToTileCoordinates(); + if (!CalamityUtils.ParanoidTileRetrieval(mouseTileCoords.X, mouseTileCoords.Y).IsTileSolidGround()) + Projectile.NewProjectile(Main.MouseWorld, Vector2.UnitY * 4f, type, damage, knockBack, player.whoAmI, 0f, 0f); + return false; + } + + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ModContent.ItemType(), 12); + recipe.AddTile(TileID.MythrilAnvil); + recipe.SetResult(this); + recipe.AddRecipe(); + } + } +} diff --git a/Items/Weapons/Summon/DaedalusGolemStaff.png b/Items/Weapons/Summon/DaedalusGolemStaff.png new file mode 100644 index 0000000000..974e746cb9 Binary files /dev/null and b/Items/Weapons/Summon/DaedalusGolemStaff.png differ diff --git a/Items/Weapons/Summon/DeathstareRod.cs b/Items/Weapons/Summon/DeathstareRod.cs new file mode 100644 index 0000000000..d528e934b8 --- /dev/null +++ b/Items/Weapons/Summon/DeathstareRod.cs @@ -0,0 +1,42 @@ +using CalamityMod.Projectiles.Summon; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Weapons.Summon +{ + public class DeathstareRod : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Deathstare Rod"); + Tooltip.SetDefault("Summons an eye above your head that watches you and shoots at enemies"); + } + + public override void SetDefaults() + { + item.damage = 33; + item.mana = 10; + item.width = item.height = 42; + item.useTime = item.useAnimation = 35; + item.useStyle = ItemUseStyleID.SwingThrow; + item.noMelee = true; + item.knockBack = 2f; + item.value = CalamityGlobalItem.Rarity1BuyPrice; + item.rare = ItemRarityID.Blue; + item.UseSound = SoundID.NPCHit8; + item.autoReuse = true; + item.shoot = ModContent.ProjectileType(); + item.shootSpeed = 10f; + item.summon = true; + } + public override bool CanUseItem(Player player) => player.ownedProjectileCounts[item.shoot] <= 0; + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + CalamityUtils.KillShootProjectiles(true, type, player); + Projectile.NewProjectile(player.Center, Vector2.Zero, type, damage, knockBack, player.whoAmI, 0f, 0f); + return false; + } + } +} diff --git a/Items/Weapons/Summon/DeathstareRod.png b/Items/Weapons/Summon/DeathstareRod.png new file mode 100644 index 0000000000..fdabc4bd48 Binary files /dev/null and b/Items/Weapons/Summon/DeathstareRod.png differ diff --git a/Items/Weapons/Summon/ExhumedVigilance.cs b/Items/Weapons/Summon/ExhumedVigilance.cs new file mode 100644 index 0000000000..185a2ccd9d --- /dev/null +++ b/Items/Weapons/Summon/ExhumedVigilance.cs @@ -0,0 +1,50 @@ +using CalamityMod.Projectiles.Summon; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Weapons.Summon +{ + public class ExhumedVigilance : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Exhumed Vigilance"); + Tooltip.SetDefault("Summons either Cataclysm or Catastrophe at the mouse position\n" + + "They will look at you for a moment before charging at you\n" + + "They can do damage to both you and enemies"); + } + + public override void SetDefaults() + { + item.mana = 100; + item.damage = 1666; + item.useStyle = ItemUseStyleID.SwingThrow; + item.width = 58; + item.height = 64; + item.useTime = item.useAnimation = 30; + item.autoReuse = true; + item.noMelee = true; + item.knockBack = 0f; + item.value = CalamityGlobalItem.RarityVioletBuyPrice; + item.rare = ItemRarityID.Red; + item.Calamity().customRarity = CalamityRarity.Violet; + item.UseSound = SoundID.DD2_BetsySummon; + item.shoot = ModContent.ProjectileType(); + item.shootSpeed = 10f; + item.summon = true; + } + + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + if (player.altFunctionUse != 2) + { + if (Main.rand.NextBool(2)) + type = ModContent.ProjectileType(); + Projectile.NewProjectile(Main.MouseWorld, Vector2.Zero, type, damage, knockBack, player.whoAmI); + } + return false; + } + } +} diff --git a/Items/Weapons/Summon/ExhumedVigilance.png b/Items/Weapons/Summon/ExhumedVigilance.png new file mode 100644 index 0000000000..96d3b0caf3 Binary files /dev/null and b/Items/Weapons/Summon/ExhumedVigilance.png differ diff --git a/Items/Weapons/Summon/EyeOfNight.cs b/Items/Weapons/Summon/EyeOfNight.cs new file mode 100644 index 0000000000..5b6c81d1b7 --- /dev/null +++ b/Items/Weapons/Summon/EyeOfNight.cs @@ -0,0 +1,56 @@ +using Terraria.ModLoader; +using Terraria.ID; +using CalamityMod.Projectiles.Summon; +using CalamityMod.Items.Materials; +using Terraria; +using Microsoft.Xna.Framework; + +namespace CalamityMod.Items.Weapons.Summon +{ + public class EyeOfNight : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Eye of Night"); + Tooltip.SetDefault("Summons a diseased eyeball that attaches to enemies and explodes"); + } + + public override void SetDefaults() + { + item.damage = 35; + item.mana = 10; + item.width = item.height = 36; + item.useTime = item.useAnimation = 30; + item.useStyle = ItemUseStyleID.SwingThrow; + item.noMelee = true; + item.knockBack = 1f; + item.value = CalamityGlobalItem.Rarity3BuyPrice; + item.rare = ItemRarityID.Orange; + + item.UseSound = SoundID.NPCHit1; + item.autoReuse = true; + item.shoot = ModContent.ProjectileType(); + item.shootSpeed = 10f; + item.summon = true; + } + + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + if (player.altFunctionUse != 2) + Projectile.NewProjectile(Main.MouseWorld, Vector2.UnitY * -3f, type, damage, knockBack, player.whoAmI); + return false; + } + + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ModContent.ItemType()); + recipe.AddIngredient(ModContent.ItemType()); + recipe.AddIngredient(ModContent.ItemType()); + recipe.AddIngredient(ItemID.ImpStaff); + recipe.AddTile(TileID.Anvils); + recipe.SetResult(this); + recipe.AddRecipe(); + } + } +} diff --git a/Items/Weapons/Summon/EyeOfNight.png b/Items/Weapons/Summon/EyeOfNight.png new file mode 100644 index 0000000000..6e5a635902 Binary files /dev/null and b/Items/Weapons/Summon/EyeOfNight.png differ diff --git a/Items/Weapons/Summon/FleshOfInfidelity.cs b/Items/Weapons/Summon/FleshOfInfidelity.cs new file mode 100644 index 0000000000..3d0f142d8a --- /dev/null +++ b/Items/Weapons/Summon/FleshOfInfidelity.cs @@ -0,0 +1,49 @@ +using Terraria.ModLoader; +using Terraria.ID; +using TerrariaAudio = Terraria.Audio; +using CalamityMod.Projectiles.Summon; +using CalamityMod.Items.Materials; + +namespace CalamityMod.Items.Weapons.Summon +{ + public class FleshOfInfidelity : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Flesh of Infidelity"); + Tooltip.SetDefault("Summons a tentacled ball of flesh that splashes blood onto enemies"); + } + + public override void SetDefaults() + { + item.damage = 31; + item.mana = 10; + item.width = item.height = 48; + item.useTime = item.useAnimation = 30; + item.useStyle = ItemUseStyleID.SwingThrow; + item.noMelee = true; + item.knockBack = 1f; + item.value = CalamityGlobalItem.Rarity3BuyPrice; + item.rare = ItemRarityID.Orange; + + // SoundID has no Zombie24 sound instance, so we must create one ourselves. + item.UseSound = new TerrariaAudio.LegacySoundStyle(SoundID.Zombie, 24, TerrariaAudio.SoundType.Sound); + item.autoReuse = true; + item.shoot = ModContent.ProjectileType(); + item.shootSpeed = 10f; + item.summon = true; + } + + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ModContent.ItemType()); + recipe.AddIngredient(ModContent.ItemType()); + recipe.AddIngredient(ModContent.ItemType()); + recipe.AddIngredient(ItemID.ImpStaff); + recipe.AddTile(TileID.Anvils); + recipe.SetResult(this); + recipe.AddRecipe(); + } + } +} diff --git a/Items/Weapons/Summon/FleshOfInfidelity.png b/Items/Weapons/Summon/FleshOfInfidelity.png new file mode 100644 index 0000000000..cb2bb8757c Binary files /dev/null and b/Items/Weapons/Summon/FleshOfInfidelity.png differ diff --git a/Items/Weapons/Summon/FlowersOfMortality.cs b/Items/Weapons/Summon/FlowersOfMortality.cs new file mode 100644 index 0000000000..8020b91c54 --- /dev/null +++ b/Items/Weapons/Summon/FlowersOfMortality.cs @@ -0,0 +1,64 @@ +using CalamityMod.Items.Materials; +using CalamityMod.Projectiles.Summon; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Weapons.Summon +{ + public class FlowersOfMortality : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Flowers of Mortality"); + Tooltip.SetDefault("Summons five rainbow flowers over your head\n" + + "The combined flowers consume three minion slots"); + } + + public override void SetDefaults() + { + item.damage = 405; + item.summon = true; + item.mana = 10; + item.width = 36; + item.height = 36; + item.useTime = item.useAnimation = 15; + item.useStyle = ItemUseStyleID.SwingThrow; + item.noMelee = true; + item.knockBack = 5f; + item.value = CalamityGlobalItem.RarityTurquoiseBuyPrice; + item.rare = ItemRarityID.Red; + item.UseSound = SoundID.Item44; + item.autoReuse = true; + item.shoot = ModContent.ProjectileType(); + item.shootSpeed = 10f; + item.Calamity().customRarity = CalamityRarity.Turquoise; + } + + public override bool CanUseItem(Player player) => player.ownedProjectileCounts[item.shoot] < 3; //If you already have all 3, no need to resummon + + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + CalamityUtils.KillShootProjectiles(false, type, player); + for (int i = 0; i < 5; i++) + { + Projectile blossom = Projectile.NewProjectileDirect(player.Center, Vector2.Zero, type, damage, knockBack, player.whoAmI, 0f, 0f); + blossom.ai[0] = MathHelper.TwoPi * i / 5f; + blossom.rotation = blossom.ai[0]; + } + return false; + } + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ModContent.ItemType()); + recipe.AddIngredient(ItemID.LunarBar, 15); + recipe.AddIngredient(ModContent.ItemType(), 15); + recipe.AddIngredient(ModContent.ItemType(), 10); + recipe.AddTile(TileID.LunarCraftingStation); + recipe.SetResult(this); + recipe.AddRecipe(); + } + } +} diff --git a/Items/Weapons/Summon/FlowersOfMortality.png b/Items/Weapons/Summon/FlowersOfMortality.png new file mode 100644 index 0000000000..6a81cbc728 Binary files /dev/null and b/Items/Weapons/Summon/FlowersOfMortality.png differ diff --git a/Items/Weapons/Summon/Perdition.cs b/Items/Weapons/Summon/Perdition.cs new file mode 100644 index 0000000000..ed08789e23 --- /dev/null +++ b/Items/Weapons/Summon/Perdition.cs @@ -0,0 +1,58 @@ +using CalamityMod.Projectiles.Summon; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Weapons.Summon +{ + public class Perdition : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Perdition"); + Tooltip.SetDefault("Summons a beacon at the position of the mouse\n" + + "When a target is manually selected via right click it releases torrents of souls from below onto the target\n" + + "The beacon does not move"); + } + + public override void SetDefaults() + { + item.damage = 444; + item.mana = 25; + item.width = item.height = 56; + item.useTime = item.useAnimation = 42; + item.useStyle = ItemUseStyleID.SwingThrow; + item.noMelee = true; + item.knockBack = 4f; + item.UseSound = SoundID.DD2_EtherianPortalOpen; + item.autoReuse = true; + item.shoot = ModContent.ProjectileType(); + item.shootSpeed = 10f; + item.summon = true; + item.sentry = true; + + item.value = CalamityGlobalItem.RarityVioletBuyPrice; + item.rare = ItemRarityID.Purple; + item.Calamity().customRarity = CalamityRarity.Violet; + } + + public override bool AltFunctionUse(Player player) => true; + + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + if (player.altFunctionUse != 2) + { + Projectile.NewProjectile(Main.MouseWorld, Vector2.Zero, type, damage, knockBack, player.whoAmI); + player.UpdateMaxTurrets(); + } + else + { + // Play some demonic noises prior to a target being selected. + Main.PlaySound(SoundID.Zombie, player.Center, 93); + Main.PlaySound(SoundID.Item119, player.Center); + } + return false; + } + } +} diff --git a/Items/Weapons/Summon/Perdition.png b/Items/Weapons/Summon/Perdition.png new file mode 100644 index 0000000000..84db27a998 Binary files /dev/null and b/Items/Weapons/Summon/Perdition.png differ diff --git a/Items/Weapons/Summon/PolypLauncher.cs b/Items/Weapons/Summon/PolypLauncher.cs new file mode 100644 index 0000000000..faee489bb3 --- /dev/null +++ b/Items/Weapons/Summon/PolypLauncher.cs @@ -0,0 +1,44 @@ +using CalamityMod.Projectiles.Summon; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Weapons.Summon +{ + public class PolypLauncher : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Polyp Launcher"); + Tooltip.SetDefault("Summons a polyp bunch that launches coral chunks at nearby enemies"); + } + + public override void SetDefaults() + { + item.damage = 12; + item.mana = 10; + item.width = 10; + item.height = 32; + item.useTime = item.useAnimation = 35; + item.useStyle = ItemUseStyleID.SwingThrow; + item.noMelee = true; + item.knockBack = 0f; + item.value = Item.buyPrice(0, 2, 0, 0); + item.rare = 2; + item.UseSound = SoundID.Item44; + item.autoReuse = true; + item.shoot = ModContent.ProjectileType(); + item.shootSpeed = 10f; + item.summon = true; + } + + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + //CalamityUtils.OnlyOneSentry(player, type); + Projectile.NewProjectile(Main.MouseWorld, Vector2.Zero, type, damage, knockBack, player.whoAmI, 20f); + player.UpdateMaxTurrets(); + return false; + } + } +} diff --git a/Items/Weapons/Summon/PolypLauncher.png b/Items/Weapons/Summon/PolypLauncher.png new file mode 100644 index 0000000000..09678f9271 Binary files /dev/null and b/Items/Weapons/Summon/PolypLauncher.png differ diff --git a/Items/Weapons/Summon/SlimePuppetStaff.cs b/Items/Weapons/Summon/SlimePuppetStaff.cs new file mode 100644 index 0000000000..93bea9288a --- /dev/null +++ b/Items/Weapons/Summon/SlimePuppetStaff.cs @@ -0,0 +1,48 @@ +using CalamityMod.Projectiles.Summon; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Weapons.Summon +{ + public class SlimePuppetStaff : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Slime Puppet Staff"); + Tooltip.SetDefault("Summons a slime ball that follows you\n" + + "The ball flies toward nearby enemies and explodes into slime on enemy hits\n" + + "Does not consume minion slots"); // In other words, bootleg mage :TaxEvasion: + Item.staff[item.type] = true; + } + + public override void SetDefaults() + { + item.damage = 26; + item.mana = 13; + item.width = 48; + item.height = 56; + item.useTime = item.useAnimation = 24; + item.useStyle = ItemUseStyleID.HoldingOut; + item.noMelee = true; + item.knockBack = 3.6f; + item.value = CalamityGlobalItem.Rarity4BuyPrice; + item.rare = ItemRarityID.LightRed; + item.UseSound = mod.GetLegacySoundSlot(SoundType.Custom, "Sounds/Custom/SlimeGodPossession"); + item.shoot = ModContent.ProjectileType(); + item.shootSpeed = 10f; + item.summon = true; + } + + public override Vector2? HoldoutOrigin() => new Vector2(12f); + + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + if (player.altFunctionUse != 2) + Projectile.NewProjectile(Main.MouseWorld, Vector2.Zero, type, damage, knockBack, Main.myPlayer); + + return false; + } + } +} diff --git a/Items/Weapons/Summon/SlimePuppetStaff.png b/Items/Weapons/Summon/SlimePuppetStaff.png new file mode 100644 index 0000000000..119db86506 Binary files /dev/null and b/Items/Weapons/Summon/SlimePuppetStaff.png differ diff --git a/Items/Weapons/Summon/StaffoftheMechworm2.cs b/Items/Weapons/Summon/StaffoftheMechworm2.cs new file mode 100644 index 0000000000..54a05bfb70 --- /dev/null +++ b/Items/Weapons/Summon/StaffoftheMechworm2.cs @@ -0,0 +1,51 @@ +using CalamityMod.Projectiles.Summon; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Weapons.Summon +{ + public class StaffoftheMechworm2 : ModItem + { + // This is unfinished atm. + public override bool Autoload(ref string name) => false; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Staff of the Mechworm (But Exhumed!)"); + Tooltip.SetDefault("Summons a sepulcher to fight for you\n" + + "While the sepulcher is active brimstone hearts will begin to appear and orbit you\n" + + "The sepulcher will attempt to attack you more and more frequently depending on how many hearts are present\n" + + "The sepulcher takes up 4 minion slots"); + } + + public override void SetDefaults() + { + item.damage = 666; + item.mana = 15; + item.width = 58; + item.height = 58; + item.useTime = item.useAnimation = 12; + item.useStyle = ItemUseStyleID.SwingThrow; + item.noMelee = true; + item.knockBack = 2f; + item.value = CalamityGlobalItem.Rarity15BuyPrice; + item.rare = ItemRarityID.Purple; + item.Calamity().customRarity = CalamityRarity.Violet; + item.UseSound = SoundID.DD2_BetsySummon; + item.autoReuse = true; + item.shoot = ModContent.ProjectileType(); + item.shootSpeed = 10f; + item.summon = true; + } + + public override bool CanUseItem(Player player) => player.ownedProjectileCounts[item.shoot] <= 0; + + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + Projectile.NewProjectile(Main.MouseWorld, -Vector2.UnitY * 5f, type, damage, knockBack, player.whoAmI); + return false; + } + } +} diff --git a/Items/Weapons/Summon/StaffoftheMechworm2.png b/Items/Weapons/Summon/StaffoftheMechworm2.png new file mode 100644 index 0000000000..ffcc7066c0 Binary files /dev/null and b/Items/Weapons/Summon/StaffoftheMechworm2.png differ diff --git a/Items/Weapons/Summon/UniverseSplitter.cs b/Items/Weapons/Summon/UniverseSplitter.cs new file mode 100644 index 0000000000..10806aa174 --- /dev/null +++ b/Items/Weapons/Summon/UniverseSplitter.cs @@ -0,0 +1,91 @@ +using CalamityMod.Buffs.Cooldowns; +using CalamityMod.Items.Materials; +using CalamityMod.Items.SummonItems; +using CalamityMod.Projectiles.Summon; +using CalamityMod.Tiles.Furniture.CraftingStations; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.DataStructures; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Weapons.Summon +{ + public class UniverseSplitter : ModItem + { + public const float ItemUseDustMaxRadius = 36f; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Universe Splitter"); + Tooltip.SetDefault("Summons an energy field at the mouse cursor\n" + + "After the field has been deployed, it begins to summon multiple small beams\n" + + "After several seconds have passed, an enormous laser beam appears at the field's position\n" + + "This effect has a cooldown\n" + + "Attempting to use this item during the cooldown will cause it to short circuit and do damage to you.\n" + + "An ancient artifact from a previous age, it waits for your command...\n" + + "This is a terrible idea, but it isn't yours anyways... right?"); + Main.RegisterItemAnimation(item.type, new DrawAnimationVertical(6, 14)); + } + + public override void SetDefaults() + { + item.width = 54; + item.height = 76; + item.useStyle = ItemUseStyleID.SwingThrow; + item.noMelee = true; + item.UseSound = SoundID.Item122; + + item.summon = true; + item.mana = 300; + item.damage = 18000; + item.knockBack = 7f; + item.autoReuse = true; + item.useTime = item.useAnimation = 10; + item.shoot = ModContent.ProjectileType(); + item.shootSpeed = 10f; + item.noUseGraphic = true; + + item.value = CalamityGlobalItem.RarityHotPinkBuyPrice; + item.Calamity().customRarity = CalamityRarity.HotPink; + item.Calamity().devItem = true; + } + + public override bool CanUseItem(Player player) => player.ownedProjectileCounts[item.shoot] <= 0; + + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + if (player.altFunctionUse != 2) + { + if (!player.HasBuff(ModContent.BuffType())) + { + player.AddBuff(ModContent.BuffType(), 45 * 60); + Projectile.NewProjectile(Main.MouseWorld, Vector2.Zero, type, damage, knockBack, player.whoAmI); + for (int i = 0; i < 36; i++) + { + float angle = MathHelper.TwoPi / 36f * i + Main.rand.NextFloat(MathHelper.TwoPi / 36f); + Dust dust = Dust.NewDustPerfect(position + angle.ToRotationVector2() * ItemUseDustMaxRadius, 247); + dust.velocity = Vector2.Normalize(angle.ToRotationVector2()) * 2.5f; + dust.noGravity = true; + dust.scale = 0.8f; + } + } + else + { + Projectile.NewProjectile(position, Vector2.UnitY * 3f, ProjectileID.SaucerScrap, 5, 0f, player.whoAmI); + } + } + return false; + } + + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ModContent.ItemType(), 3); + recipe.AddIngredient(ModContent.ItemType(), 5); + recipe.AddIngredient(ModContent.ItemType(), 5); + recipe.AddTile(ModContent.TileType()); + recipe.SetResult(this); + recipe.AddRecipe(); + } + } +} diff --git a/Items/Weapons/Summon/UniverseSplitter.png b/Items/Weapons/Summon/UniverseSplitter.png new file mode 100644 index 0000000000..9397d8d05a Binary files /dev/null and b/Items/Weapons/Summon/UniverseSplitter.png differ diff --git a/Items/Weapons/Summon/Vigilance.cs b/Items/Weapons/Summon/Vigilance.cs new file mode 100644 index 0000000000..23b51e01f7 --- /dev/null +++ b/Items/Weapons/Summon/Vigilance.cs @@ -0,0 +1,66 @@ +using CalamityMod.Projectiles.Summon; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Weapons.Summon +{ + public class Vigilance : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Vigilance"); + Tooltip.SetDefault("Summons a soul seeker to fight for you"); + } + + public override void SetDefaults() + { + item.damage = 333; + item.mana = 12; + item.width = item.height = 32; + item.useTime = item.useAnimation = 10; + item.useStyle = ItemUseStyleID.SwingThrow; + item.noMelee = true; + item.knockBack = 4f; + item.UseSound = SoundID.DD2_BetsySummon; + item.autoReuse = true; + item.shoot = ModContent.ProjectileType(); + item.shootSpeed = 10f; + item.summon = true; + + item.value = CalamityGlobalItem.RarityVioletBuyPrice; + item.rare = ItemRarityID.Purple; + item.Calamity().customRarity = CalamityRarity.Violet; + } + + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + if (player.altFunctionUse != 2) + { + int seekerIndex = 0; + int totalSeekers = 0; + for (int i = 0; i < Main.maxProjectiles; i++) + { + if (Main.projectile[i].type != type || !Main.projectile[i].active || Main.projectile[i].owner != player.whoAmI) + continue; + + totalSeekers++; + } + + Projectile.NewProjectile(Main.MouseWorld, Vector2.Zero, type, damage, knockBack, player.whoAmI); + + for (int i = 0; i < Main.maxProjectiles; i++) + { + if (Main.projectile[i].type != type || !Main.projectile[i].active || Main.projectile[i].owner != player.whoAmI) + continue; + Main.projectile[i].ai[0] = seekerIndex / (float)totalSeekers; + Main.projectile[i].netUpdate = true; + + seekerIndex++; + } + } + return false; + } + } +} diff --git a/Items/Weapons/Summon/Vigilance.png b/Items/Weapons/Summon/Vigilance.png new file mode 100644 index 0000000000..cdc748ad35 Binary files /dev/null and b/Items/Weapons/Summon/Vigilance.png differ diff --git a/Items/Weapons/Summon/ViralSprout.cs b/Items/Weapons/Summon/ViralSprout.cs new file mode 100644 index 0000000000..77be9227c7 --- /dev/null +++ b/Items/Weapons/Summon/ViralSprout.cs @@ -0,0 +1,67 @@ +using CalamityMod.Items.Materials; +using CalamityMod.Projectiles.Summon; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Weapons.Summon +{ + public class ViralSprout : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Viral Sprout"); + Tooltip.SetDefault("Summons a sage spirit to fight for you\n" + + "Inflicts Sage Poison, a debuff that becomes stronger the more spirits you own"); + } + + public override void SetDefaults() + { + item.damage = 32; + item.mana = 10; + item.width = 48; + item.height = 56; + item.useTime = item.useAnimation = 20; + item.useStyle = ItemUseStyleID.HoldingUp; + item.noMelee = true; + item.knockBack = 2f; + item.value = CalamityGlobalItem.Rarity7BuyPrice; + item.rare = ItemRarityID.Lime; + item.UseSound = SoundID.Item44; + item.autoReuse = true; + item.shoot = ModContent.ProjectileType(); + item.shootSpeed = 10f; + item.summon = true; + } + + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + if (player.altFunctionUse != 2) + { + Projectile.NewProjectile(Main.MouseWorld, Vector2.Zero, type, damage, knockBack, player.whoAmI); + + int minionCount = 0; + for (int i = 0; i < Main.maxProjectiles; i++) + { + if (Main.projectile[i].type != type || !Main.projectile[i].active || Main.projectile[i].owner != player.whoAmI) + continue; + + Main.projectile[i].localAI[0] = minionCount; + Main.projectile[i].netUpdate = true; + minionCount++; + } + } + return false; + } + + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ModContent.ItemType(), 12); + recipe.AddTile(TileID.MythrilAnvil); + recipe.SetResult(this); + recipe.AddRecipe(); + } + } +} diff --git a/Items/Weapons/Summon/ViralSprout.png b/Items/Weapons/Summon/ViralSprout.png new file mode 100644 index 0000000000..062b3bc149 Binary files /dev/null and b/Items/Weapons/Summon/ViralSprout.png differ diff --git a/Items/Weapons/Summon/ViridVanguard.cs b/Items/Weapons/Summon/ViridVanguard.cs new file mode 100644 index 0000000000..1eb96eccdb --- /dev/null +++ b/Items/Weapons/Summon/ViridVanguard.cs @@ -0,0 +1,110 @@ +using CalamityMod.Items.Materials; +using CalamityMod.Projectiles.Summon; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +namespace CalamityMod.Items.Weapons.Summon +{ + public class ViridVanguard : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Virid Vanguard"); + Tooltip.SetDefault("Summons 2 blades that rotate around you\n" + + "Right clicking prompts all blades to fly upward and redirect towards the mouse"); + Item.staff[item.type] = true; + } + + public override void SetDefaults() + { + item.damage = 156; + item.summon = true; + item.sentry = true; + item.mana = 25; + item.width = 26; + item.height = 36; + item.useTime = item.useAnimation = 15; + item.useStyle = ItemUseStyleID.HoldingUp; + item.noMelee = true; + item.knockBack = 5f; + item.value = CalamityGlobalItem.RarityTurquoiseBuyPrice; + item.rare = 10; + item.autoReuse = true; + item.shoot = ModContent.ProjectileType(); + item.Calamity().customRarity = CalamityRarity.Turquoise; + } + + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + float totalMinionSlots = 0f; + for (int i = 0; i < Main.projectile.Length; i++) + { + if (Main.projectile[i].active && Main.projectile[i].minion && Main.projectile[i].owner == player.whoAmI) + { + totalMinionSlots += Main.projectile[i].minionSlots; + } + } + if (player.altFunctionUse != 2 && totalMinionSlots + 1.5f < player.maxMinions) + { + position = Main.MouseWorld; + int swordCount = 0; + for (int i = 0; i < Main.projectile.Length; i++) + { + if (Main.projectile[i].active && Main.projectile[i].type == type && Main.projectile[i].owner == player.whoAmI) + { + if ((Main.projectile[i].modProjectile as ViridVanguardBlade).FiringTime > 0f) + continue; + swordCount++; + for (int j = 0; j < 22; j++) + { + Dust dust = Dust.NewDustDirect(Main.projectile[i].position, Main.projectile[i].width, Main.projectile[i].height, 2); + dust.velocity = Vector2.UnitY * Main.rand.NextFloat(3f, 5.5f) * Main.rand.NextBool(2).ToDirectionInt(); + dust.noGravity = true; + } + } + } + + Projectile newBlade = Projectile.NewProjectileDirect(position, Vector2.Zero, type, damage, knockBack, player.whoAmI); + (newBlade.modProjectile as ViridVanguardBlade).AltTexture = swordCount % 2 == 1; + newBlade.netUpdate = true; + swordCount++; + + newBlade = Projectile.NewProjectileDirect(position, Vector2.Zero, type, damage, knockBack, player.whoAmI); + (newBlade.modProjectile as ViridVanguardBlade).AltTexture = swordCount % 2 == 1; + newBlade.netUpdate = true; + swordCount++; + + float angleVariance = MathHelper.TwoPi / swordCount; + float angle = 0f; + for (int i = 0; i < Main.projectile.Length; i++) + { + if (Main.projectile[i].active && Main.projectile[i].type == type && Main.projectile[i].owner == player.whoAmI) + { + if ((Main.projectile[i].modProjectile as ViridVanguardBlade).FiringTime > 0f) + continue; + Main.projectile[i].ai[0] = angle; + Main.projectile[i].localAI[1] = 80f; + angle += angleVariance; + for (int j = 0; j < 22; j++) + { + Dust dust = Dust.NewDustDirect(Main.projectile[i].position, Main.projectile[i].width, Main.projectile[i].height, 6); + dust.velocity = Vector2.UnitY * Main.rand.NextFloat(3f, 5.5f) * Main.rand.NextBool(2).ToDirectionInt(); + dust.noGravity = true; + } + } + } + } + return false; + } + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ModContent.ItemType()); + recipe.AddIngredient(ModContent.ItemType(), 8); + recipe.AddTile(TileID.LunarCraftingStation); + recipe.SetResult(this); + recipe.AddRecipe(); + } + } +} diff --git a/Items/Weapons/Summon/ViridVanguard.png b/Items/Weapons/Summon/ViridVanguard.png new file mode 100644 index 0000000000..6455e12c54 Binary files /dev/null and b/Items/Weapons/Summon/ViridVanguard.png differ diff --git a/Items/Weapons/Summon/WitherBlossomsStaff.cs b/Items/Weapons/Summon/WitherBlossomsStaff.cs new file mode 100644 index 0000000000..2e541f0170 --- /dev/null +++ b/Items/Weapons/Summon/WitherBlossomsStaff.cs @@ -0,0 +1,63 @@ +using CalamityMod.Items.Materials; +using CalamityMod.Projectiles.Summon; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Weapons.Summon +{ + public class WitherBlossomsStaff : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Wither Blossoms Staff"); + Tooltip.SetDefault("Summons four decaying flowers over your head\n" + + "The combined flowers consume two minion slots"); + } + + public override void SetDefaults() + { + item.damage = 61; + item.mana = 10; + item.width = 52; + item.height = 60; + item.useTime = item.useAnimation = 20; + item.useStyle = ItemUseStyleID.SwingThrow; + item.noMelee = true; + item.knockBack = 3f; + item.value = CalamityGlobalItem.Rarity8BuyPrice; + item.rare = ItemRarityID.Yellow; + item.UseSound = SoundID.Item46; + item.autoReuse = true; + item.shoot = ModContent.ProjectileType(); + item.shootSpeed = 10f; + item.summon = true; + } + + public override bool CanUseItem(Player player) => player.ownedProjectileCounts[item.shoot] < 3; //If you already have all 3, no need to resummon + + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + CalamityUtils.KillShootProjectiles(false, type, player); + for (int i = 0; i < 4; i++) + { + Projectile blossom = Projectile.NewProjectileDirect(player.Center, Vector2.Zero, type, damage, knockBack, player.whoAmI, 0f, 0f); + blossom.ai[0] = MathHelper.TwoPi * i / 4f; + blossom.rotation = blossom.ai[0]; + } + return false; + } + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ModContent.ItemType()); + recipe.AddIngredient(ModContent.ItemType(), 15); + recipe.AddIngredient(ModContent.ItemType(), 5); + recipe.AddIngredient(ModContent.ItemType(), 5); + recipe.AddTile(TileID.MythrilAnvil); + recipe.SetResult(this); + recipe.AddRecipe(); + } + } +} diff --git a/Items/Weapons/Summon/WitherBlossomsStaff.png b/Items/Weapons/Summon/WitherBlossomsStaff.png new file mode 100644 index 0000000000..c74966ede5 Binary files /dev/null and b/Items/Weapons/Summon/WitherBlossomsStaff.png differ diff --git a/ModSupport/ModCalls.cs b/ModSupport/ModCalls.cs index 96b6129f2f..16aee95c21 100644 --- a/ModSupport/ModCalls.cs +++ b/ModSupport/ModCalls.cs @@ -2,6 +2,7 @@ using CalamityMod.CalPlayer; using CalamityMod.Events; using CalamityMod.Items; using CalamityMod.Projectiles; +using CalamityMod.UI.CalamitasEnchants; using CalamityMod.World; using System; using System.Collections.Generic; @@ -1707,6 +1708,11 @@ namespace CalamityMod CalamityLists.MinionsToNotResurrectList.AddRange(secondaryArguments.Select(argument => Convert.ToInt32(argument))); return null; + case "CreateEnchantment": + case "RegisterEnchantment": + EnchantmentManager.ConstructFromModcall(args.Skip(1)); + return null; + default: return new ArgumentException("ERROR: Invalid method name."); } diff --git a/NPCs/Abyss/EidolonWyrmBodyAltHuge.cs b/NPCs/Abyss/EidolonWyrmBodyAltHuge.cs index bee2fbc7da..dab9292565 100644 --- a/NPCs/Abyss/EidolonWyrmBodyAltHuge.cs +++ b/NPCs/Abyss/EidolonWyrmBodyAltHuge.cs @@ -112,7 +112,7 @@ namespace CalamityMod.NPCs.Abyss { npc.localAI[0] += 1f; float shootShadowFireballGateValue = 90f; - float divisor = 5f; + float divisor = 2f; if (npc.ai[3] % divisor == 0f && npc.localAI[0] >= shootShadowFireballGateValue) { npc.localAI[0] = 0f; diff --git a/NPCs/Abyss/EidolonWyrmBodyHuge.cs b/NPCs/Abyss/EidolonWyrmBodyHuge.cs index c808772239..6b6f7a32b3 100644 --- a/NPCs/Abyss/EidolonWyrmBodyHuge.cs +++ b/NPCs/Abyss/EidolonWyrmBodyHuge.cs @@ -111,8 +111,8 @@ namespace CalamityMod.NPCs.Abyss if (Vector2.Distance(npc.Center, Main.player[Main.npc[(int)npc.ai[2]].target].Center) > 160f) { npc.localAI[0] += 1f; - float spawnAncientLightGateValue = 180f; - float divisor = 10f; + float spawnAncientLightGateValue = 120f; + float divisor = 4f; if (npc.ai[3] % divisor == 0f && npc.localAI[0] >= spawnAncientLightGateValue) { npc.localAI[0] = 0f; diff --git a/NPCs/Abyss/EidolonWyrmHeadHuge.cs b/NPCs/Abyss/EidolonWyrmHeadHuge.cs index 77075bb406..4ecf4c442c 100644 --- a/NPCs/Abyss/EidolonWyrmHeadHuge.cs +++ b/NPCs/Abyss/EidolonWyrmHeadHuge.cs @@ -207,7 +207,7 @@ namespace CalamityMod.NPCs.Abyss Main.npc[Previous].ai[0] = lol; NetMessage.SendData(MessageID.SyncNPC, -1, -1, null, lol, 0f, 0f, 0f, 0); Previous = lol; - Main.npc[Previous].ai[3] = i; + Main.npc[Previous].ai[3] = i / 2; } TailSpawned = true; } diff --git a/NPCs/AcidRain/NuclearTerror.cs b/NPCs/AcidRain/NuclearTerror.cs index a6f24d9caf..6bda0229b1 100644 --- a/NPCs/AcidRain/NuclearTerror.cs +++ b/NPCs/AcidRain/NuclearTerror.cs @@ -9,6 +9,7 @@ using Terraria; using Terraria.ID; using Terraria.ModLoader; using CalamityMod.Buffs.StatDebuffs; +using CalamityMod.Items.Weapons.Melee; namespace CalamityMod.NPCs.AcidRain { @@ -492,6 +493,7 @@ namespace CalamityMod.NPCs.AcidRain public override void NPCLoot() { DropHelper.DropItemChance(npc, ModContent.ItemType(), 3); + DropHelper.DropItemChance(npc, ModContent.ItemType(), 3); } } } diff --git a/NPCs/CalamityGlobalNPC.cs b/NPCs/CalamityGlobalNPC.cs index 6514732f5e..093719ee1f 100644 --- a/NPCs/CalamityGlobalNPC.cs +++ b/NPCs/CalamityGlobalNPC.cs @@ -5,6 +5,8 @@ using CalamityMod.Buffs.StatDebuffs; using CalamityMod.CalPlayer; using CalamityMod.Dusts; using CalamityMod.Events; +using CalamityMod.Items; +using CalamityMod.Items.Accessories; using CalamityMod.Items.Weapons.Melee; using CalamityMod.NPCs.Abyss; using CalamityMod.NPCs.AcidRain; @@ -27,6 +29,7 @@ using CalamityMod.NPCs.Leviathan; using CalamityMod.NPCs.NormalNPCs; using CalamityMod.NPCs.OldDuke; using CalamityMod.NPCs.Perforator; +using CalamityMod.NPCs.PlagueEnemies; using CalamityMod.NPCs.PlaguebringerGoliath; using CalamityMod.NPCs.Polterghast; using CalamityMod.NPCs.ProfanedGuardians; @@ -38,6 +41,7 @@ using CalamityMod.NPCs.StormWeaver; using CalamityMod.NPCs.SulphurousSea; using CalamityMod.NPCs.SupremeCalamitas; using CalamityMod.NPCs.Yharon; +using CalamityMod.Particles; using CalamityMod.Projectiles.DraedonsArsenal; using CalamityMod.Projectiles.Magic; using CalamityMod.Projectiles.Melee; @@ -58,7 +62,6 @@ using Terraria.Graphics.Effects; using Terraria.ID; using Terraria.ModLoader; using static Terraria.ModLoader.ModContent; -using CalamityMod.NPCs.PlagueEnemies; namespace CalamityMod.NPCs { @@ -111,6 +114,9 @@ namespace CalamityMod.NPCs public int shopAlertAnimTimer = 0; public int shopAlertAnimFrame = 0; + // Rage interactions + public bool DoesNotGenerateRage = false; + // NewAI internal const int maxAIMod = 4; public float[] newAI = new float[maxAIMod]; @@ -145,7 +151,7 @@ namespace CalamityMod.NPCs public int wCleave = 0; public int bBlood = 0; public int dFlames = 0; - public int marked = 0; + public int marked = 0; public int irradiated = 0; public int bFlames = 0; public int hFlames = 0; @@ -167,6 +173,9 @@ namespace CalamityMod.NPCs public int relicOfResilienceCooldown = 0; public int relicOfResilienceWeakness = 0; public int GaussFluxTimer = 0; + public int sagePoisonTime = 0; + public int sagePoisonDamage = 0; + public int vulnerabilityHex = 0; public int banishingFire = 0; // whoAmI Variables @@ -211,6 +220,9 @@ namespace CalamityMod.NPCs public static int draedonExoMechPrime = -1; public static int adultEidolonWyrmHead = -1; + // Drawing variables. + public FireParticleSet VulnerabilityHexFireDrawer = null; + // Boss Enrage variable for use with the boss health UI. // The logic behind this is as follows: // 1 - For special cases with super-enrages (specifically Yharon/SCal with their arenas), go solely based on whether that enrage is active. That information is most important to the player. @@ -964,11 +976,14 @@ namespace CalamityMod.NPCs ApplyDPSDebuff(pShred, 1500, 300, ref npc.lifeRegen, ref damage); ApplyDPSDebuff(nightwither, 200, 40, ref npc.lifeRegen, ref damage); ApplyDPSDebuff(dFlames, 2500, 500, ref npc.lifeRegen, ref damage); - ApplyDPSDebuff(bBlood, 50, 10, ref npc.lifeRegen, ref damage); + ApplyDPSDebuff(vulnerabilityHex, 44440, 4444, ref npc.lifeRegen, ref damage); + ApplyDPSDebuff(bBlood, 50, 10, ref npc.lifeRegen, ref damage); ApplyDPSDebuff(kamiFlu, 250, 25, ref npc.lifeRegen, ref damage); + ApplyDPSDebuff(vulnerabilityHex, 44440, 4444, ref npc.lifeRegen, ref damage); ApplyDPSDebuff(sulphurPoison, 180, 36, ref npc.lifeRegen, ref damage); + ApplyDPSDebuff(sagePoisonTime, 90, npc.Calamity().sagePoisonDamage, ref npc.lifeRegen, ref damage); - int electrifiedDamage = CalamityPlayer.areThereAnyDamnBosses ? 5 : 10; + int electrifiedDamage = CalamityPlayer.areThereAnyDamnBosses ? 5 : 10; int displayedValue = electrifiedDamage / 5; if (npc.velocity.X == 0) ApplyDPSDebuff(electrified, electrifiedDamage, displayedValue, ref npc.lifeRegen, ref damage); @@ -1022,6 +1037,7 @@ namespace CalamityMod.NPCs if (npc.type == NPCID.WallofFleshEye) npc.netAlways = true; + sagePoisonDamage = 0; if (npc.type == NPCID.Golem && (CalamityWorld.revenge || CalamityWorld.malice)) npc.noGravity = true; @@ -1085,9 +1101,9 @@ namespace CalamityMod.NPCs // Nothing should be immune to Enraged. npc.buffImmune[BuffType()] = false; - // Extra Notes: - // Shellfish minions set debuff immunity to Shellfish Claps on enemy hits, so most things are technically not immune. - // The Spiteful Candle sets the debuff immunity of Spite to all nearby enemies in the tile file for an enemy with less than 99% DR. + // Extra Notes: + // Shellfish minions set debuff immunity to Shellfish Claps on enemy hits, so most things are technically not immune. + // The Spiteful Candle sets the debuff immunity of Spite to all nearby enemies in the tile file for an enemy with less than 99% DR. } #endregion @@ -1985,7 +2001,9 @@ namespace CalamityMod.NPCs #region Pre AI public override bool PreAI(NPC npc) { - CalamityGlobalTownNPC.SetPatreonTownNPCName(npc, mod); + if (VulnerabilityHexFireDrawer != null) + VulnerabilityHexFireDrawer.Update(); + CalamityGlobalTownNPC.SetPatreonTownNPCName(npc, mod); // Decrement each immune timer if it's greater than 0. for (int i = 0; i < maxPlayerImmunities; i++) @@ -3505,6 +3523,8 @@ namespace CalamityMod.NPCs bBlood--; if (dFlames > 0) dFlames--; + if (vulnerabilityHex > 0) + vulnerabilityHex--; if (marked > 0) marked--; if (irradiated > 0) @@ -3539,14 +3559,20 @@ namespace CalamityMod.NPCs clamDebuff--; if (sulphurPoison > 0) sulphurPoison--; - if (relicOfResilienceCooldown > 0) - relicOfResilienceCooldown--; - if (relicOfResilienceWeakness > 0) - relicOfResilienceWeakness--; - if (GaussFluxTimer > 0) - GaussFluxTimer--; - if (ladHearts > 0) + if (sagePoisonTime > 0) + sagePoisonTime--; + if (kamiFlu > 0) + kamiFlu--; + if (relicOfResilienceCooldown > 0) + relicOfResilienceCooldown--; + if (relicOfResilienceWeakness > 0) + relicOfResilienceWeakness--; + if (GaussFluxTimer > 0) + GaussFluxTimer--; + if (ladHearts > 0) ladHearts--; + if (vulnerabilityHex > 0) + vulnerabilityHex--; if (banishingFire > 0) banishingFire--; @@ -3564,12 +3590,14 @@ namespace CalamityMod.NPCs npc.velocity *= 0.85f; else if (slowed > 0 || tesla > 0 || vaporfied > 0) npc.velocity *= 0.9f; + else if (vulnerabilityHex > 0) + npc.velocity = Vector2.Clamp(npc.velocity, new Vector2(-Calamity.MaxNPCSpeed), new Vector2(Calamity.MaxNPCSpeed, 10f)); else if (kamiFlu > 420) npc.velocity = Vector2.Clamp(npc.velocity, new Vector2(-KamiDebuff.MaxNPCSpeed), new Vector2(KamiDebuff.MaxNPCSpeed)); } } - if (!CalamityPlayer.areThereAnyDamnBosses && !CalamityLists.enemyImmunityList.Contains(npc.type)) + if (!CalamityPlayer.areThereAnyDamnBosses && !CalamityLists.enemyImmunityList.Contains(npc.type)) { if (pearlAura > 0) npc.velocity *= 0.9f; @@ -3919,16 +3947,9 @@ namespace CalamityMod.NPCs } else if (npc.type == NPCType()) { - if (projectile.type == ProjectileType() || projectile.type == ProjectileType() || projectile.type == ProjectileType() || - projectile.type == ProjectileType()) - { - damage = (int)(damage * 0.85); - } - if (projectile.type == ProjectileType() || projectile.type == ProjectileType() || projectile.type == ProjectileType()) - damage = (int)(damage * 0.8); - - if (projectile.type == ProjectileType() || projectile.type == ProjectileType() || projectile.type == ProjectileType()) - damage = (int)(damage * 0.81); + // For Onyxia. + if (projectile.type == ProjectileID.BlackBolt) + damage = (int)(damage * 0.9); } else if (npc.type == NPCType() || npc.type == NPCType()) { @@ -3942,6 +3963,10 @@ namespace CalamityMod.NPCs } else if (npc.type == NPCType()) { + if (projectile.type == ProjectileType()) + damage = (int)(damage * 0.7); + if (projectile.type == ProjectileType()) + damage = (int)(damage * 0.75); if (projectile.type == ProjectileType()) damage = (int)(damage * 0.9); } @@ -4738,7 +4763,9 @@ namespace CalamityMod.NPCs buffTextureList.Add(GetTexture("CalamityMod/Buffs/DamageOverTime/SnapClamDebuff")); if (sulphurPoison > 0) buffTextureList.Add(GetTexture("CalamityMod/Buffs/DamageOverTime/SulphuricPoisoning")); - if (vaporfied > 0) + if (sagePoisonTime > 0) + buffTextureList.Add(GetTexture("CalamityMod/Buffs/DamageOverTime/SagePoison")); + if (vaporfied > 0) buffTextureList.Add(GetTexture("CalamityMod/Buffs/DamageOverTime/Vaporfied")); // Stat debuffs @@ -4924,6 +4951,24 @@ namespace CalamityMod.NPCs Main.spriteBatch.Draw(Main.npcTexture[npc.type], new Vector2(position9.X - Main.screenPosition.X + npc.width / 2 - Main.npcTexture[npc.type].Width * npc.scale / 2f + vector11.X * npc.scale, position9.Y - Main.screenPosition.Y + npc.height - Main.npcTexture[npc.type].Height * npc.scale / Main.npcFrameCount[npc.type] + 4f + vector11.Y * npc.scale + num66 + npc.gfxOffY), new Microsoft.Xna.Framework.Rectangle?(npc.frame), alpha15, npc.rotation, vector11, npc.scale, spriteEffects, 0f); } } + else + { + if (npc.Calamity().vulnerabilityHex > 0) + { + float compactness = npc.width * 0.6f; + if (compactness < 10f) + compactness = 10f; + float power = npc.height / 100f; + if (power > 2.75f) + power = 2.75f; + if (VulnerabilityHexFireDrawer is null || VulnerabilityHexFireDrawer.LocalTimer >= VulnerabilityHexFireDrawer.SetLifetime) + VulnerabilityHexFireDrawer = new FireParticleSet(npc.Calamity().vulnerabilityHex, 1, Color.Red * 1.25f, Color.Red, compactness, power); + else + VulnerabilityHexFireDrawer.DrawSet(npc.Bottom - Vector2.UnitY * (12f - npc.gfxOffY)); + } + else + VulnerabilityHexFireDrawer = null; + } // Draw a pillar of light and fade the background as an animation when skipping things in the DD2 event. if (npc.type == NPCID.DD2EterniaCrystal) diff --git a/NPCs/ExoMechs/Thanatos/ThanatosHead.cs b/NPCs/ExoMechs/Thanatos/ThanatosHead.cs index 31ef75de3f..933b025751 100644 --- a/NPCs/ExoMechs/Thanatos/ThanatosHead.cs +++ b/NPCs/ExoMechs/Thanatos/ThanatosHead.cs @@ -158,10 +158,6 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos // Percent life remaining float lifeRatio = npc.life / (float)npc.lifeMax; - // Increase aggression if player is taking a long time to kill the boss - if (lifeRatio > calamityGlobalNPC.killTimeRatio_IncreasedAggression) - lifeRatio = calamityGlobalNPC.killTimeRatio_IncreasedAggression; - // Check if the other exo mechs are alive int otherExoMechsAlive = 0; bool exoPrimeAlive = false; @@ -551,7 +547,7 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos calamityGlobalNPC.newAI[3] += 1f; if (calamityGlobalNPC.newAI[3] >= velocityAdjustTime) { - npc.localAI[0] = 1f; + npc.localAI[0] = /*berserk ? 1f : 0f*/ 1f; AIState = (float)Phase.Charge; calamityGlobalNPC.newAI[2] = 0f; calamityGlobalNPC.newAI[3] = 0f; @@ -623,10 +619,13 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos { float squishedRatio = (float)Math.Pow((float)Math.Sin(MathHelper.Pi * b / 6f), 2D); float smoothenedRatio = MathHelper.SmoothStep(0f, 1f, squishedRatio); + Main.projectile[beam].ai[0] = npc.whoAmI; Main.projectile[beam].ai[1] = MathHelper.Lerp(-0.74f, 0.74f, smoothenedRatio); } } - Projectile.NewProjectile(npc.Center, Vector2.Zero, type, 0, 0f, 255, npc.whoAmI); + int beam2 = Projectile.NewProjectile(npc.Center, Vector2.Zero, type, 0, 0f, 255, npc.whoAmI); + if (Main.projectile.IndexInRange(beam2)) + Main.projectile[beam2].ai[0] = npc.whoAmI; } } } @@ -639,7 +638,9 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos { int type = ModContent.ProjectileType(); int damage = npc.GetProjectileDamage(type); - Projectile.NewProjectile(npc.Center, Vector2.Zero, type, damage, 0f, 255, npc.whoAmI); + int laser = Projectile.NewProjectile(npc.Center, Vector2.Zero, type, damage, 0f, 255, npc.whoAmI); + if (Main.projectile.IndexInRange(laser)) + Main.projectile[laser].ai[0] = npc.whoAmI; } } } diff --git a/NPCs/NormalNPCs/Pitbull.cs b/NPCs/NormalNPCs/Pitbull.cs index e5bf0f5e77..b23b78abea 100644 --- a/NPCs/NormalNPCs/Pitbull.cs +++ b/NPCs/NormalNPCs/Pitbull.cs @@ -1,3 +1,4 @@ +using CalamityMod.Items.Accessories; using CalamityMod.Items.Placeables.Banners; using CalamityMod.World; using Terraria; @@ -64,6 +65,7 @@ namespace CalamityMod.NPCs.NormalNPCs { float bandageDropRate = Main.expertMode ? 0.02f : 0.01f; DropHelper.DropItemChance(npc, ItemID.AdhesiveBandage, bandageDropRate); + DropHelper.DropItemChance(npc, ModContent.ItemType(), 8); } } } diff --git a/NPCs/Other/BrimstoneOrb.cs b/NPCs/Other/BrimstoneOrb.cs new file mode 100644 index 0000000000..8468cd95e5 --- /dev/null +++ b/NPCs/Other/BrimstoneOrb.cs @@ -0,0 +1,104 @@ +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.NPCs.Other +{ + public class BrimstoneOrb : ModNPC + { + public ref float Time => ref npc.ai[0]; + public Player Owner + { + get + { + if (npc.target >= 255 || npc.target < 0) + npc.TargetClosest(); + return Main.player[npc.target]; + } + } + public override void SetStaticDefaults() => DisplayName.SetDefault("Brimstone Orb"); + + public override void SetDefaults() + { + npc.width = npc.height = 28; + npc.damage = 0; + npc.defense = 0; + npc.lifeMax = 97444; + npc.noGravity = true; + npc.noTileCollide = true; + npc.value = 0f; + npc.HitSound = SoundID.NPCHit5; + npc.DeathSound = SoundID.NPCDeath7; + npc.knockBackResist = 0f; + npc.netAlways = true; + npc.aiStyle = -1; + npc.Calamity().DoesNotGenerateRage = true; + } + + public override void ScaleExpertStats(int numPlayers, float bossLifeScale) => npc.lifeMax = 97444; + + public override void AI() + { + npc.Opacity = Utils.InverseLerp(0f, 15f, Time, true); + npc.velocity = Vector2.Zero; + + if (Main.myPlayer == npc.target) + { + // Disappear if the player no longer has the enchanted weapon. + if (!Owner.Calamity().lecherousOrbEnchant) + { + npc.active = false; + npc.netUpdate = true; + } + + Vector2 destination = Vector2.Lerp(Owner.Center, Main.MouseWorld, 0.3f); + npc.Center = Vector2.Lerp(npc.Center, destination, 0.035f).MoveTowards(destination, 5f); + if (!npc.WithinRange(destination, 2000f)) + npc.Center = Owner.Center; + + if (npc.Center != destination) + { + npc.netSpam = 0; + npc.netUpdate = true; + } + } + + Time++; + } + + public override void HitEffect(int hitDirection, double damage) + { + for (int i = 0; i < 3; i++) + { + Dust magic = Dust.NewDustPerfect(npc.Center + Main.rand.NextVector2Circular(12f, 12f), 264); + magic.color = Color.Red; + magic.velocity = Main.rand.NextVector2Circular(3f, 3f); + magic.fadeIn = 0.9f; + magic.scale = 1.3f; + magic.noGravity = true; + } + + if (npc.life <= 0) + { + for (int i = 0; i < 15; i++) + { + Dust magic = Dust.NewDustPerfect(npc.Center + Main.rand.NextVector2Circular(12f, 12f), 264); + magic.color = Color.Red; + magic.velocity = Main.rand.NextVector2Circular(6f, 6f); + magic.fadeIn = 1.25f; + magic.scale = Main.rand.NextFloat(1.2f, 1.56f); + magic.noGravity = true; + } + } + } + + public override void NPCLoot() + { + for (int i = 0; i < 8; i++) + DropHelper.DropItem(npc, ItemID.Heart); + } + + public override Color? GetAlpha(Color drawColor) => Color.White * npc.Opacity; + } +} diff --git a/NPCs/Other/BrimstoneOrb.png b/NPCs/Other/BrimstoneOrb.png new file mode 100644 index 0000000000..680009c5da Binary files /dev/null and b/NPCs/Other/BrimstoneOrb.png differ diff --git a/NPCs/Other/CalamitasEnchantDemon.cs b/NPCs/Other/CalamitasEnchantDemon.cs new file mode 100644 index 0000000000..d4a60a001d --- /dev/null +++ b/NPCs/Other/CalamitasEnchantDemon.cs @@ -0,0 +1,163 @@ +using CalamityMod.Projectiles.Healing; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.NPCs.Other +{ + public class CalamitasEnchantDemon : ModNPC + { + public Player Target => Main.player[npc.target]; + public ref float AttackTimer => ref npc.ai[0]; + public ref float FadeAwayTimer => ref npc.ai[1]; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Demon"); + Main.npcFrameCount[npc.type] = 5; + } + + public override void SetDefaults() + { + npc.width = 68; + npc.height = 68; + npc.damage = 0; + npc.defense = 0; + + // This is meant to be created after SCal is defeated and should be at least a little challenging. + npc.lifeMax = 101010; + npc.HitSound = SoundID.NPCHit47; + npc.DeathSound = SoundID.NPCDeath18; + npc.noGravity = true; + npc.noTileCollide = true; + npc.value = 0f; + npc.knockBackResist = 0f; + npc.netAlways = true; + npc.aiStyle = 0; + } + + public override void ScaleExpertStats(int numPlayers, float bossLifeScale) => npc.lifeMax = 101010; + + public override void AI() + { + FadeAwayTimer++; + + // This npc should not attempt to locate other targets. The only one it will accept is the + // player who summoned it in the first place. + if (!Main.projectile.IndexInRange(npc.target) || Target.dead || !Target.active) + { + FadeAway(); + return; + } + + if (FadeAwayTimer < 15f) + { + DoInitializationAI(); + return; + } + + AttackTarget(); + } + + public void FadeAway() + { + npc.dontTakeDamage = true; + npc.Opacity = Utils.InverseLerp(50f, 0f, FadeAwayTimer, true); + + // Become inactive after fading away completely. + if (npc.Opacity <= 0f) + { + npc.active = false; + npc.netUpdate = true; + } + + // Slow down and fade away. + npc.velocity = Vector2.Lerp(npc.velocity, Vector2.UnitY * npc.Opacity * -2f, 0.125f); + + FadeAwayTimer++; + + if (Main.dedServ) + return; + + // Create some fade dust. + for (int i = 0; i < 3; i++) + { + Dust magic = Dust.NewDustDirect(npc.position, npc.width, npc.height, 223); + magic.velocity = -Vector2.UnitY * Main.rand.NextFloat(2.8f, 3.5f); + magic.scale = Main.rand.NextFloat(1f, 1.125f); + magic.fadeIn = 0.4f; + magic.noGravity = true; + magic.noLight = true; + } + } + + public void DoInitializationAI() + { + // Create a burst of magic on the first frame. + if (!Main.dedServ && FadeAwayTimer == 1f) + { + for (int i = 0; i < 50; i++) + { + Dust magic = Dust.NewDustDirect(npc.position, npc.width, npc.height, 223); + magic.velocity = -Vector2.UnitY * Main.rand.NextFloat(2.8f, 3.5f); + magic.scale = Main.rand.NextFloat(1f, 1.125f); + magic.fadeIn = 0.7f; + magic.noGravity = true; + magic.noLight = true; + } + } + + // Rise upward. + npc.velocity = Vector2.UnitX * MathHelper.Lerp(-0.1f, -3.5f, FadeAwayTimer / 15f); + } + + public void AttackTarget() + { + // Slow down prior to a charge. + if (AttackTimer % 120f > 90f) + npc.velocity *= 0.94f; + + // Otherwise attempt to move towards the player. + else if (!npc.WithinRange(Target.Center, 150f)) + { + Vector2 idealVelocity = npc.SafeDirectionTo(Target.Center) * 16f; + npc.velocity = (npc.velocity * 29f + idealVelocity) / 30f; + npc.velocity = Vector2.Lerp(npc.velocity, idealVelocity, 0.025f); + } + + // Charge. + if (AttackTimer % 120f == 119f) + npc.velocity = npc.SafeDirectionTo(Target.Center) * 23.5f; + + npc.spriteDirection = (npc.velocity.X < 0f).ToDirectionInt(); + } + + public override void FindFrame(int frameHeight) + { + npc.frameCounter++; + if (npc.frameCounter % 5f == 4f) + npc.frame.Y += frameHeight; + + if (npc.frame.Y >= frameHeight * Main.npcFrameCount[npc.type]) + npc.frame.Y = 0; + } + + public override void HitEffect(int hitDirection, double damage) + { + if (npc.life <= 0) + { + Utils.PoofOfSmoke(npc.Center); + + // Release 4 healing projectiles towards the target. + if (Main.netMode != NetmodeID.MultiplayerClient) + { + for (int i = 0; i < 4; i++) + { + Vector2 shootVelocity = npc.SafeDirectionTo(Target.Center).RotatedByRandom(0.6f) * Main.rand.NextFloat(12f, 14f); + Projectile.NewProjectile(npc.Center, shootVelocity, ModContent.ProjectileType(), 0, 0f, npc.target); + } + } + } + } + } +} diff --git a/NPCs/Other/CalamitasEnchantDemon.png b/NPCs/Other/CalamitasEnchantDemon.png new file mode 100644 index 0000000000..bd3a5924ca Binary files /dev/null and b/NPCs/Other/CalamitasEnchantDemon.png differ diff --git a/NPCs/Other/DemonPortal.cs b/NPCs/Other/DemonPortal.cs new file mode 100644 index 0000000000..092c7846ee --- /dev/null +++ b/NPCs/Other/DemonPortal.cs @@ -0,0 +1,123 @@ +using CalamityMod.Projectiles.Typeless; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.NPCs.Other +{ + public class DemonPortal : ModNPC + { + public ref float Time => ref npc.ai[0]; + public override void SetStaticDefaults() => DisplayName.SetDefault("Mysterious Portal"); + + public override void SetDefaults() + { + npc.width = npc.height = 60; + npc.damage = 0; + npc.defense = 0; + npc.lifeMax = 24660; + npc.noGravity = true; + npc.noTileCollide = true; + npc.value = 0f; + npc.knockBackResist = 0f; + npc.netAlways = true; + npc.aiStyle = -1; + } + + public override void ScaleExpertStats(int numPlayers, float bossLifeScale) => npc.lifeMax = 24660; + + public override void AI() + { + npc.rotation += 0.18f; + npc.Opacity = Utils.InverseLerp(0f, 30f, Time, true) * Utils.InverseLerp(420f, 390f, Time, true); + npc.velocity = Vector2.Zero; + npc.scale = npc.Opacity; + + if (Time == 300f) + { + if (Main.netMode != NetmodeID.MultiplayerClient) + ReleaseThings(); + Main.PlaySound(SoundID.DD2_EtherianPortalOpen, npc.Center); + } + + if (Main.netMode != NetmodeID.MultiplayerClient && Time >= 420f) + { + npc.active = false; + npc.netUpdate = true; + } + + Time++; + } + + public void ReleaseThings() + { + bool friendly = npc.life == 1; + for (int i = 0; i < 6; i++) + { + int demon = Projectile.NewProjectile(npc.Center, Main.rand.NextVector2CircularEdge(4f, 4f), ModContent.ProjectileType(), 17000, 0f, npc.target); + if (Main.projectile.IndexInRange(demon)) + { + Main.projectile[demon].friendly = friendly; + Main.projectile[demon].hostile = !friendly; + } + } + } + + public override bool StrikeNPC(ref double damage, int defense, ref float knockback, int hitDirection, ref bool crit) + { + bool wouldDie = npc.life - (damage * (crit ? 2D : 1D)) <= 0; + if (wouldDie) + { + npc.immortal = true; + + // Enrage demons if hit when already at 1 health. + if (npc.life == 1) + { + int demonType = ModContent.ProjectileType(); + for (int i = 0; i < Main.maxProjectiles; i++) + { + if (Main.projectile[i].type != demonType || !Main.projectile[i].active || Main.projectile[i].hostile) + continue; + + Main.projectile[i].hostile = true; + Main.projectile[i].friendly = false; + Main.projectile[i].netUpdate = true; + } + } + + npc.life = 1; + damage = 0D; + return false; + } + return true; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + spriteBatch.SetBlendState(BlendState.AlphaBlend); + + Texture2D portalTexture = Main.npcTexture[npc.type]; + Vector2 drawPosition = npc.Center - Main.screenPosition; + Vector2 origin = portalTexture.Size() * 0.5f; + Color baseColor = Color.White; + + // Purple-black portal. + Color color = Color.Lerp(baseColor, Color.Black, 0.55f) * npc.Opacity * 1.8f; + spriteBatch.Draw(portalTexture, drawPosition, null, color, npc.rotation, origin, npc.scale * 1.2f, SpriteEffects.None, 0f); + spriteBatch.Draw(portalTexture, drawPosition, null, color, -npc.rotation, origin, npc.scale * 1.2f, SpriteEffects.None, 0f); + + // Purple portal. + color = Color.Lerp(Color.Lerp(baseColor, Color.Purple, 0.55f), Color.Black, 0.66f) * npc.Opacity * 1.6f; + spriteBatch.Draw(portalTexture, drawPosition, null, color, npc.rotation * 0.6f, origin, npc.scale * 1.2f, SpriteEffects.None, 0f); + + // Red portal. + color = Color.Lerp(baseColor, Color.Red, 0.55f) * npc.Opacity * 1.6f; + spriteBatch.Draw(portalTexture, drawPosition, null, color, npc.rotation * -0.6f, origin, npc.scale * 1.2f, SpriteEffects.None, 0f); + + spriteBatch.SetBlendState(BlendState.AlphaBlend); + return false; + } + } +} diff --git a/NPCs/Other/DemonPortal.png b/NPCs/Other/DemonPortal.png new file mode 100644 index 0000000000..1fb1ceee5e Binary files /dev/null and b/NPCs/Other/DemonPortal.png differ diff --git a/NPCs/Other/ExhumedHeart.cs b/NPCs/Other/ExhumedHeart.cs new file mode 100644 index 0000000000..bfde229cb5 --- /dev/null +++ b/NPCs/Other/ExhumedHeart.cs @@ -0,0 +1,67 @@ +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.NPCs.Other +{ + public class ExhumedHeart : ModNPC + { + public ref float Time => ref npc.ai[0]; + public Player Owner + { + get + { + if (npc.target >= 255 || npc.target < 0) + npc.TargetClosest(); + return Main.player[npc.target]; + } + } + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Exhumed Brimstone Heart"); + Main.npcFrameCount[npc.type] = 6; + } + + public override void SetDefaults() + { + npc.width = npc.height = 38; + npc.damage = 0; + npc.defense = 0; + npc.lifeMax = 51740; + npc.noGravity = true; + npc.noTileCollide = true; + npc.value = 0f; + npc.HitSound = SoundID.NPCHit13; + npc.DeathSound = SoundID.NPCDeath1; + npc.knockBackResist = 0f; + npc.netAlways = true; + npc.aiStyle = -1; + npc.Calamity().DoesNotGenerateRage = true; + } + + public override void ScaleExpertStats(int numPlayers, float bossLifeScale) => npc.lifeMax = 51740; + + public override void AI() + { + npc.Opacity = Utils.InverseLerp(0f, 25f, Time, true); + npc.Center = Owner.Center + (MathHelper.TwoPi * Time / 540f).ToRotationVector2() * 350f; + npc.velocity = Vector2.Zero; + + Time++; + } + + public override void FindFrame(int frameHeight) + { + npc.frameCounter++; + npc.frame.Y = (int)(npc.frameCounter / 5) % Main.npcFrameCount[npc.type] * frameHeight; + } + + public override Color? GetAlpha(Color drawColor) + { + Color color = Color.Purple * npc.Opacity; + color.A = 127; + return color; + } + } +} diff --git a/NPCs/Other/ExhumedHeart.png b/NPCs/Other/ExhumedHeart.png new file mode 100644 index 0000000000..c597cfe505 Binary files /dev/null and b/NPCs/Other/ExhumedHeart.png differ diff --git a/NPCs/SlimeGod/SlimeGodCore.cs b/NPCs/SlimeGod/SlimeGodCore.cs index a08be74c81..d88d886bc5 100644 --- a/NPCs/SlimeGod/SlimeGodCore.cs +++ b/NPCs/SlimeGod/SlimeGodCore.cs @@ -679,7 +679,8 @@ namespace CalamityMod.NPCs.SlimeGod DropHelper.WeightStack(w), DropHelper.WeightStack(w), DropHelper.WeightStack(w), - DropHelper.WeightStack(w) + DropHelper.WeightStack(w), + DropHelper.WeightStack(w) ); // Vanity diff --git a/NPCs/SupremeCalamitas/SupremeCalamitas.cs b/NPCs/SupremeCalamitas/SupremeCalamitas.cs index 72ca0be300..8669ddac3f 100644 --- a/NPCs/SupremeCalamitas/SupremeCalamitas.cs +++ b/NPCs/SupremeCalamitas/SupremeCalamitas.cs @@ -13,6 +13,7 @@ using CalamityMod.Items.Weapons.Melee; using CalamityMod.Items.Weapons.Ranged; using CalamityMod.Items.Weapons.Rogue; using CalamityMod.Items.Weapons.Summon; +using CalamityMod.NPCs.TownNPCs; using CalamityMod.Projectiles.Boss; using CalamityMod.World; using Microsoft.Xna.Framework; @@ -568,7 +569,17 @@ namespace CalamityMod.NPCs.SupremeCalamitas forcefieldOpacity = Utils.InverseLerp(0.1f, 0.6f, npc.Opacity, true); if (npc.alpha >= 230) { - // TODO: Spawn the town NPC variant of SCal here when it's on the public branch. + if (CalamityWorld.downedSCal && !BossRushEvent.BossRushActive) + { + // Create a teleport line effect + Dust.QuickDustLine(npc.Center, initialRitualPosition, 500f, Color.Red); + npc.Center = initialRitualPosition; + + // Make the town NPC spawn. + if (Main.netMode != NetmodeID.MultiplayerClient) + NPC.NewNPC((int)npc.Center.X, (int)npc.Center.Y + 12, ModContent.NPCType()); + } + npc.active = false; npc.netUpdate = true; } @@ -995,7 +1006,6 @@ namespace CalamityMod.NPCs.SupremeCalamitas if (CalamityWorld.downedSCal && !BossRushEvent.BossRushActive) { - // TODO: Spawn the town NPC variant of SCal again here. if (giveUpCounter == 720) { for (int i = 0; i < 24; i++) @@ -2723,6 +2733,9 @@ namespace CalamityMod.NPCs.SupremeCalamitas Dust.QuickDustLine(npc.Center, initialRitualPosition, 500f, Color.Red); npc.Center = initialRitualPosition; + // Make the town NPC spawn. + NPC.NewNPC((int)npc.Center.X, (int)npc.Center.Y + 12, ModContent.NPCType()); + // Increase the player's SCal kill count if (Main.player[npc.target].Calamity().sCalKillCount < 5) Main.player[npc.target].Calamity().sCalKillCount++; diff --git a/NPCs/SupremeCalamitas/SupremeCataclysm.cs b/NPCs/SupremeCalamitas/SupremeCataclysm.cs index 2733c47632..af55c1e4bf 100644 --- a/NPCs/SupremeCalamitas/SupremeCataclysm.cs +++ b/NPCs/SupremeCalamitas/SupremeCataclysm.cs @@ -82,6 +82,7 @@ namespace CalamityMod.NPCs.SupremeCalamitas if (Main.npc[CalamityGlobalNPC.SCalCatastrophe].active) totalLifeRatio += Main.npc[CalamityGlobalNPC.SCalCatastrophe].life / (float)Main.npc[CalamityGlobalNPC.SCalCatastrophe].lifeMax; } + totalLifeRatio *= 0.5f; // Get a target if (npc.target < 0 || npc.target == Main.maxPlayers || Main.player[npc.target].dead || !Main.player[npc.target].active) @@ -101,7 +102,7 @@ namespace CalamityMod.NPCs.SupremeCalamitas num677 *= 0.5f; } - int scale = (int)Math.Round(MathHelper.Lerp(2f, 6.5f, totalLifeRatio * 0.5f)); + int scale = (int)Math.Round(MathHelper.Lerp(2f, 6.5f, 1f - totalLifeRatio)); if (npc.ai[3] < distanceX) { npc.ai[3] += scale; @@ -161,7 +162,7 @@ namespace CalamityMod.NPCs.SupremeCalamitas } if (npc.localAI[0] >= 120f) { - float fireRate = CalamityWorld.malice ? 2f : MathHelper.Lerp(1f, 2.5f, totalLifeRatio * 0.5f); + float fireRate = CalamityWorld.malice ? 2f : MathHelper.Lerp(1f, 2.5f, 1f - totalLifeRatio); npc.ai[1] += fireRate; if (npc.ai[1] >= 60f) { @@ -174,7 +175,7 @@ namespace CalamityMod.NPCs.SupremeCalamitas Projectile.NewProjectile(npc.Center, new Vector2(-8f, 0f), type, damage, 0f, Main.myPlayer); } } - fireRate = CalamityWorld.malice ? 3f : MathHelper.Lerp(1f, 4f, totalLifeRatio * 0.5f); + fireRate = CalamityWorld.malice ? 3f : MathHelper.Lerp(1f, 4f, 1f - totalLifeRatio); npc.ai[2] += fireRate; if (npc.ai[2] >= 300f) { diff --git a/NPCs/SupremeCalamitas/SupremeCatastrophe.cs b/NPCs/SupremeCalamitas/SupremeCatastrophe.cs index 03a6f65b55..3f626975e3 100644 --- a/NPCs/SupremeCalamitas/SupremeCatastrophe.cs +++ b/NPCs/SupremeCalamitas/SupremeCatastrophe.cs @@ -82,6 +82,7 @@ namespace CalamityMod.NPCs.SupremeCalamitas if (Main.npc[CalamityGlobalNPC.SCalCataclysm].active) totalLifeRatio += Main.npc[CalamityGlobalNPC.SCalCataclysm].life / (float)Main.npc[CalamityGlobalNPC.SCalCataclysm].lifeMax; } + totalLifeRatio *= 0.5f; // Get a target if (npc.target < 0 || npc.target == Main.maxPlayers || Main.player[npc.target].dead || !Main.player[npc.target].active) @@ -101,7 +102,7 @@ namespace CalamityMod.NPCs.SupremeCalamitas num677 *= 0.5f; } - int scale = (int)Math.Round(MathHelper.Lerp(2f, 6.5f, totalLifeRatio * 0.5f)); + int scale = (int)Math.Round(MathHelper.Lerp(2f, 6.5f, 1f - totalLifeRatio)); if (npc.ai[3] < distanceX) { npc.ai[3] += scale; @@ -161,7 +162,7 @@ namespace CalamityMod.NPCs.SupremeCalamitas } if (npc.localAI[0] >= 120f) { - float fireRate = CalamityWorld.malice ? 2f : MathHelper.Lerp(1f, 2.5f, totalLifeRatio * 0.5f); + float fireRate = CalamityWorld.malice ? 2f : MathHelper.Lerp(1f, 2.5f, 1f - totalLifeRatio); npc.ai[1] += fireRate; if (npc.ai[1] >= 45f) { @@ -174,7 +175,7 @@ namespace CalamityMod.NPCs.SupremeCalamitas Projectile.NewProjectile(npc.Center, new Vector2(4f, 0f), type, damage, 0f, Main.myPlayer); } } - fireRate = CalamityWorld.malice ? 3f : MathHelper.Lerp(1f, 4f, totalLifeRatio * 0.5f); + fireRate = CalamityWorld.malice ? 3f : MathHelper.Lerp(1f, 4f, 1f - totalLifeRatio); npc.ai[2] += fireRate; if (npc.ai[2] >= 300f) { diff --git a/NPCs/TownNPCs/FAP.cs b/NPCs/TownNPCs/FAP.cs index 9b24365075..355a5e0617 100644 --- a/NPCs/TownNPCs/FAP.cs +++ b/NPCs/TownNPCs/FAP.cs @@ -1,6 +1,7 @@ using CalamityMod.Events; using CalamityMod.Items.Placeables.Furniture; using CalamityMod.Items.Potions.Alcohol; +using CalamityMod.Projectiles.Magic; using CalamityMod.Projectiles.Typeless; using CalamityMod.World; using System.Collections.Generic; @@ -388,13 +389,13 @@ namespace CalamityMod.NPCs.TownNPCs public override void TownNPCAttackProj(ref int projType, ref int attackDelay) { - projType = ModContent.ProjectileType(); + projType = ModContent.ProjectileType(); attackDelay = 1; } public override void TownNPCAttackProjSpeed(ref float multiplier, ref float gravityCorrection, ref float randomOffset) { - multiplier = 2f; + multiplier = 11.5f; } } } diff --git a/NPCs/TownNPCs/SEAHOE.cs b/NPCs/TownNPCs/SEAHOE.cs index 8d37fcb1a2..31044def25 100644 --- a/NPCs/TownNPCs/SEAHOE.cs +++ b/NPCs/TownNPCs/SEAHOE.cs @@ -374,7 +374,9 @@ namespace CalamityMod.NPCs.TownNPCs nextSlot++; shop.item[nextSlot].SetDefaults(ModContent.ItemType()); nextSlot++; - shop.item[nextSlot].SetDefaults(ItemID.GillsPotion); + shop.item[nextSlot].SetDefaults(ModContent.ItemType()); + nextSlot++; + shop.item[nextSlot].SetDefaults(ItemID.GillsPotion); shop.item[nextSlot].shopCustomPrice = Item.buyPrice(0, 1, 0, 0); nextSlot++; shop.item[nextSlot].SetDefaults(ItemID.WaterWalkingPotion); @@ -383,7 +385,7 @@ namespace CalamityMod.NPCs.TownNPCs shop.item[nextSlot].SetDefaults(ItemID.FlipperPotion); shop.item[nextSlot].shopCustomPrice = Item.buyPrice(0, 1, 0, 0); nextSlot++; - if (CalamityWorld.downedDesertScourge) + if (CalamityWorld.downedDesertScourge) { shop.item[nextSlot].SetDefaults(ModContent.ItemType()); shop.item[nextSlot].shopCustomPrice = Item.buyPrice(0, 2, 0, 0); diff --git a/NPCs/TownNPCs/WITCH.cs b/NPCs/TownNPCs/WITCH.cs new file mode 100644 index 0000000000..0313ce6017 --- /dev/null +++ b/NPCs/TownNPCs/WITCH.cs @@ -0,0 +1,157 @@ +using CalamityMod.Dusts; +using CalamityMod.Events; +using CalamityMod.Items; +using CalamityMod.Projectiles.Magic; +using CalamityMod.UI.CalamitasEnchants; +using CalamityMod.World; +using Microsoft.Xna.Framework; +using System.Collections.Generic; +using Terraria; +using Terraria.GameContent.Events; +using Terraria.ID; +using Terraria.ModLoader; + +using static Terraria.ModLoader.ModContent; +using SCalBoss = CalamityMod.NPCs.SupremeCalamitas.SupremeCalamitas; + +namespace CalamityMod.NPCs.TownNPCs +{ + [AutoloadHead] + public class WITCH : ModNPC + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Brimstone Witch"); + + Main.npcFrameCount[npc.type] = 27; + NPCID.Sets.ExtraFramesCount[npc.type] = 9; + NPCID.Sets.AttackFrameCount[npc.type] = 4; + NPCID.Sets.DangerDetectRange[npc.type] = 700; + NPCID.Sets.AttackType[npc.type] = 1; + NPCID.Sets.AttackTime[npc.type] = 30; + NPCID.Sets.AttackAverageChance[npc.type] = 5; + } + + public override void SetDefaults() + { + npc.townNPC = true; + npc.friendly = true; + npc.lavaImmune = true; + npc.width = 18; + npc.height = 40; + npc.aiStyle = 7; + npc.damage = 10; + + // You should not be able to kill SCal under any typical circumstances. + npc.Calamity().DR = 0.999999f; + npc.Calamity().unbreakableDR = true; + npc.lifeMax = 1000000; + + npc.defense = 120; + npc.HitSound = SoundID.NPCHit1; + npc.DeathSound = SoundID.NPCDeath6; + npc.knockBackResist = 0.8f; + animationType = NPCID.Wizard; + } + + public override bool CanTownNPCSpawn(int numTownNPCs, int money) => CalamityWorld.downedSCal; + + public override string TownNPCName() => "Calamitas"; + + public override string GetChat() => "Mrrp is cringe."; + + public override void SetChatButtons(ref string button, ref string button2) => button = "Enchant"; + + public override void OnChatButtonClicked(bool firstButton, ref bool shop) + { + if (firstButton) + { + Main.playerInventory = true; + Main.LocalPlayer.Calamity().newCalamitasInventory = false; + CalamitasEnchantUI.NPCIndex = npc.whoAmI; + CalamitasEnchantUI.CurrentlyViewing = true; + + if (!Main.LocalPlayer.Calamity().GivenBrimstoneLocus) + { + DropHelper.DropItem(npc, ItemType()); + Main.LocalPlayer.Calamity().GivenBrimstoneLocus = true; + } + + shop = false; + } + } + + // Make this Town NPC teleport to the Queen statue when triggered. + public override bool CanGoToStatue(bool toKingStatue) => !toKingStatue; + + public override void TownNPCAttackStrength(ref int damage, ref float knockback) + { + damage = 50; + knockback = 10f; + } + + public override void TownNPCAttackCooldown(ref int cooldown, ref int randExtraCooldown) + { + cooldown = 10; + randExtraCooldown = 50; + } + + public override bool PreAI() + { + // Disappear if the SCal boss is active. She's supposed to be the boss. + // However, this doesn't happen in Boss Rush; the SCal there is a silent puppet created by Xeroc, not SCal herself. + if (NPC.AnyNPCs(NPCType()) && !BossRushEvent.BossRushActive) + { + npc.active = false; + npc.netUpdate = true; + return false; + } + return true; + } + + //public override void TownNPCAttackMagic(ref float auraLightMultiplier) + + public override void TownNPCAttackProj(ref int projType, ref int attackDelay) + { + projType = ProjectileType(); + attackDelay = 1; + } + + public override void TownNPCAttackProjSpeed(ref float multiplier, ref float gravityCorrection, ref float randomOffset) + { + multiplier = 2f; + } + + // Explode into red dust on death. + public override void HitEffect(int hitDirection, double damage) + { + if (npc.life <= 0) + { + npc.position = npc.Center; + npc.width = npc.height = 50; + npc.position.X -= npc.width / 2; + npc.position.Y -= npc.height / 2; + for (int i = 0; i < 5; i++) + { + int brimstone = Dust.NewDust(npc.position, npc.width, npc.height, (int)CalamityDusts.Brimstone, 0f, 0f, 100, default, 2f); + Main.dust[brimstone].velocity *= 3f; + if (Main.rand.NextBool(2)) + { + Main.dust[brimstone].scale = 0.5f; + Main.dust[brimstone].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f; + } + } + + for (int i = 0; i < 10; i++) + { + int fire = Dust.NewDust(npc.position, npc.width, npc.height, (int)CalamityDusts.Brimstone, 0f, 0f, 100, default, 3f); + Main.dust[fire].noGravity = true; + Main.dust[fire].velocity *= 5f; + + fire = Dust.NewDust(npc.position, npc.width, npc.height, (int)CalamityDusts.Brimstone, 0f, 0f, 100, default, 2f); + Main.dust[fire].velocity *= 2f; + } + } + } + } +} diff --git a/NPCs/TownNPCs/WITCH.png b/NPCs/TownNPCs/WITCH.png new file mode 100644 index 0000000000..7c02e35630 Binary files /dev/null and b/NPCs/TownNPCs/WITCH.png differ diff --git a/NPCs/TownNPCs/WITCH_Head.png b/NPCs/TownNPCs/WITCH_Head.png new file mode 100644 index 0000000000..8869c7a345 Binary files /dev/null and b/NPCs/TownNPCs/WITCH_Head.png differ diff --git a/Particles/EnchantedParticleSet.cs b/Particles/EnchantedParticleSet.cs new file mode 100644 index 0000000000..4feb625237 --- /dev/null +++ b/Particles/EnchantedParticleSet.cs @@ -0,0 +1,45 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Particles +{ + public class ChargingEnergyParticleSet : BaseParticleSet + { + public float InterpolationSpeed; + public float EdgeOffset; + public Color EdgeColor; + public Color CenterColor; + public override int ParticleLifetime => 50; + public override Texture2D ParticleTexture => ModContent.GetTexture("CalamityMod/ExtraTextures/Particles/Light"); + public ChargingEnergyParticleSet(int setLifetime, int particleSpawnRate, Color edgeColor, Color centerColor, float interpolationSpeed, float edgeOffset) : + base(setLifetime, particleSpawnRate) + { + EdgeColor = edgeColor; + CenterColor = centerColor; + InterpolationSpeed = interpolationSpeed; + EdgeOffset = edgeOffset; + } + + public override void UpdateBehavior(Particle particle) + { + float distanceToCenter = particle.RelativeOffset.Length(); + particle.Scale = MathHelper.SmoothStep(0.05f, 0.125f, Utils.InverseLerp(EdgeOffset, 6f, distanceToCenter, true)); + particle.Scale *= Utils.InverseLerp(ParticleLifetime, ParticleLifetime - 10f, particle.Time, true); + + if (distanceToCenter > 4.5f) + particle.RelativeOffset = Vector2.Lerp(particle.RelativeOffset, Vector2.Zero, InterpolationSpeed); + } + + public override Color DetermineParticleColor(float lifetimeCompletion) + { + Color particleColor = Color.Lerp(EdgeColor, CenterColor, Utils.InverseLerp(0f, 0.67f, lifetimeCompletion, true)); + particleColor.A = 50; + + return particleColor; + } + + public override Particle SpawnParticle() => new Particle(ParticleLifetime, Main.rand.NextVector2CircularEdge(1f, 1f) * EdgeOffset, 0.1f); + } +} \ No newline at end of file diff --git a/Particles/FireParticleSet.cs b/Particles/FireParticleSet.cs new file mode 100644 index 0000000000..fd362b1a76 --- /dev/null +++ b/Particles/FireParticleSet.cs @@ -0,0 +1,44 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Particles +{ + public class FireParticleSet : BaseParticleSet + { + public float SpawnAreaCompactness; + public float RelativePower; + public Color BrightColor; + public Color DarkColor; + public override int ParticleLifetime => 50; + public override Texture2D ParticleTexture => ModContent.GetTexture("CalamityMod/ExtraTextures/Particles/Fire"); + public FireParticleSet(int setLifetime, int particleSpawnRate, Color brightColor, Color darkColor, float spawnAreaCompactness, float relativePower) : + base(setLifetime, particleSpawnRate) + { + BrightColor = brightColor; + DarkColor = darkColor; + SpawnAreaCompactness = spawnAreaCompactness; + RelativePower = relativePower; + } + + public override void UpdateBehavior(Particle particle) + { + particle.Scale += RelativePower * 0.01f; + particle.RelativeOffset.Y -= RelativePower * 3f; + } + + public override Color DetermineParticleColor(float lifetimeCompletion) + { + Color particleColor = Color.Lerp(BrightColor, DarkColor, lifetimeCompletion); + particleColor = Color.Lerp(particleColor, Color.SaddleBrown, Utils.InverseLerp(0.95f, 0.7f, lifetimeCompletion, true)); + particleColor = Color.Lerp(particleColor, Color.White, Utils.InverseLerp(0.1f, 0.25f, lifetimeCompletion, true) * Utils.InverseLerp(0.4f, 0.25f, lifetimeCompletion, true) * 0.7f); + particleColor *= Utils.InverseLerp(0f, 0.15f, lifetimeCompletion, true) * Utils.InverseLerp(1f, 0.8f, lifetimeCompletion, true) * 0.6f; + particleColor.A = 50; + + return particleColor; + } + + public override Particle SpawnParticle() => new Particle(ParticleLifetime, Main.rand.NextVector2Circular(1f, 1f) * SpawnAreaCompactness, 0.06f); + } +} \ No newline at end of file diff --git a/Projectiles/BaseProjectiles/BaseLaserbeamProjectile.cs b/Projectiles/BaseProjectiles/BaseLaserbeamProjectile.cs index 3abf6c5637..78fe1d662a 100644 --- a/Projectiles/BaseProjectiles/BaseLaserbeamProjectile.cs +++ b/Projectiles/BaseProjectiles/BaseLaserbeamProjectile.cs @@ -38,7 +38,7 @@ namespace CalamityMod.Projectiles.BaseProjectiles // Attach to some arbitrary thing/position optionally. (The ai[1] value is a reserved for this in vanilla's Phantasmal Deathray) AttachToSomething(); - // Ensure the the velocity is a unit vector and is not a <0,0> vector. + // Ensure the the velocity is a unit vector. This has NaN safety in place with a fallback of <0, -1>. projectile.velocity = projectile.velocity.SafeNormalize(-Vector2.UnitY); Time++; @@ -79,11 +79,9 @@ namespace CalamityMod.Projectiles.BaseProjectiles /// public virtual void DetermineScale() { - projectile.scale = (float)Math.Sin(Time / Lifetime * MathHelper.Pi) * 6f * MaxScale; + projectile.scale = (float)Math.Sin(Time / Lifetime * MathHelper.Pi) * ScaleExpandRate * MaxScale; if (projectile.scale > MaxScale) - { projectile.scale = MaxScale; - } } /// @@ -92,7 +90,7 @@ namespace CalamityMod.Projectiles.BaseProjectiles public virtual void AttachToSomething() { } /// - /// Calculates the current laser's length. By default does not collide with tiles. is a generic laser collision method if you want to do that. + /// Calculates the current laser's length. By default does not collide with tiles. is a generic laser collision method if you want to use it. /// /// The laser length as a float. public virtual float DetermineLaserLength() => MaxLaserLength; @@ -115,6 +113,62 @@ namespace CalamityMod.Projectiles.BaseProjectiles Collision.LaserScan(projectile.Center, projectile.velocity, projectile.scale, MaxLaserLength, laserLengthSamplePoints); return laserLengthSamplePoints.Average(); } + + protected internal void DrawBeamWithColor(SpriteBatch spriteBatch, Color beamColor, float scale) + { + // Start texture drawing. + spriteBatch.Draw(LaserBeginTexture, + projectile.Center - Main.screenPosition, + null, + beamColor, + projectile.rotation, + LaserBeginTexture.Size() / 2f, + scale, + SpriteEffects.None, + 0f); + + // Prepare things for body drawing. + float laserBodyLength = LaserLength; + laserBodyLength -= (LaserBeginTexture.Height / 2 + LaserEndTexture.Height) * scale; + Vector2 centerOnLaser = projectile.Center; + centerOnLaser += projectile.velocity * scale * LaserBeginTexture.Height / 2f; + + // Body drawing. + if (laserBodyLength > 0f) + { + float laserOffset = LaserMiddleTexture.Height * scale; + float incrementalBodyLength = 0f; + while (incrementalBodyLength + 1f < laserBodyLength) + { + spriteBatch.Draw(LaserMiddleTexture, + centerOnLaser - Main.screenPosition, + null, + beamColor, + projectile.rotation, + LaserMiddleTexture.Width * 0.5f * Vector2.UnitX, + scale, + SpriteEffects.None, + 0f); + incrementalBodyLength += laserOffset; + centerOnLaser += projectile.velocity * laserOffset; + } + } + + // End texture drawing. + if (Math.Abs(LaserLength - DetermineLaserLength()) < 30f) + { + Vector2 laserEndCenter = centerOnLaser - Main.screenPosition; + spriteBatch.Draw(LaserEndTexture, + laserEndCenter, + null, + beamColor, + projectile.rotation, + LaserEndTexture.Frame(1, 1, 0, 0).Top(), + scale, + SpriteEffects.None, + 0f); + } + } #endregion #region Hook Overrides @@ -134,78 +188,30 @@ namespace CalamityMod.Projectiles.BaseProjectiles if (projectile.velocity == Vector2.Zero) return false; - // Start texture drawing. - spriteBatch.Draw(LaserBeginTexture, - projectile.Center - Main.screenPosition, - null, - LaserOverlayColor, - projectile.rotation, - LaserBeginTexture.Size() / 2f, - projectile.scale, - SpriteEffects.None, - 0f); - - // Prepare things for body drawing. - float laserBodyLength = LaserLength; - laserBodyLength -= (LaserBeginTexture.Height / 2 + LaserEndTexture.Height) * projectile.scale; - Vector2 centerOnLaser = projectile.Center; - centerOnLaser += projectile.velocity * projectile.scale * LaserBeginTexture.Height / 2f; - - // Body drawing. - if (laserBodyLength > 0f) - { - float laserOffset = LaserMiddleTexture.Height * projectile.scale; - float incrementalBodyLength = 0f; - while (incrementalBodyLength + 1f < laserBodyLength) - { - spriteBatch.Draw(LaserMiddleTexture, - centerOnLaser - Main.screenPosition, - null, - LaserOverlayColor, - projectile.rotation, - LaserMiddleTexture.Width * 0.5f * Vector2.UnitX, - projectile.scale, - SpriteEffects.None, - 0f); - incrementalBodyLength += laserOffset; - centerOnLaser += projectile.velocity * laserOffset; - } - } - - // End texture drawing. - if (Math.Abs(LaserLength - DetermineLaserLength()) < 30f) - { - Vector2 laserEndCenter = centerOnLaser - Main.screenPosition; - spriteBatch.Draw(LaserEndTexture, - laserEndCenter, - null, - LaserOverlayColor, - projectile.rotation, - LaserEndTexture.Frame(1, 1, 0, 0).Top(), - projectile.scale, - SpriteEffects.None, - 0f); - } + DrawBeamWithColor(spriteBatch, LaserOverlayColor, projectile.scale); return false; } public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) { if (projHitbox.Intersects(targetHitbox)) return true; - float unused = 69420f; - return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), projectile.Center, projectile.Center + projectile.velocity * LaserLength, projectile.Size.Length() * projectile.scale, ref unused); + float _ = 0f; + return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), projectile.Center, projectile.Center + projectile.velocity * LaserLength, projectile.Size.Length() * projectile.scale, ref _); } - #endregion - #region Virtual Properties - public virtual float Lifetime => 120f; - public virtual float MaxScale => 1f; - public virtual float MaxLaserLength => 2400f; // Be careful with this. Going too high will cause lag. + public override bool ShouldUpdatePosition() => false; + #endregion + + #region Overridable Properties + public abstract float Lifetime { get; } + public abstract float MaxScale { get; } + public abstract float MaxLaserLength { get; } // Be careful with this. Going too high will cause lag. + public abstract Texture2D LaserBeginTexture { get; } + public abstract Texture2D LaserMiddleTexture { get; } + public abstract Texture2D LaserEndTexture { get; } + public virtual float ScaleExpandRate => 4f; public virtual Color LightCastColor => Color.White; public virtual Color LaserOverlayColor => Color.White * 0.9f; - public virtual Texture2D LaserBeginTexture { get; } - public virtual Texture2D LaserMiddleTexture { get; } - public virtual Texture2D LaserEndTexture { get; } #endregion } } diff --git a/Projectiles/Boss/InfernadoRevenge.cs b/Projectiles/Boss/InfernadoRevenge.cs index 5f4ea978fc..d6c43e35ea 100644 --- a/Projectiles/Boss/InfernadoRevenge.cs +++ b/Projectiles/Boss/InfernadoRevenge.cs @@ -4,24 +4,25 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System.IO; using Terraria; +using Terraria.Graphics.Shaders; using Terraria.ModLoader; namespace CalamityMod.Projectiles.Boss { public class InfernadoRevenge : ModProjectile { - public override string Texture => "CalamityMod/Projectiles/Boss/Flarenado"; - + internal PrimitiveTrail TornadoDrawer; + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + public const int TornadoHeight = 8800; public override void SetStaticDefaults() { DisplayName.SetDefault("Infernado"); - Main.projFrames[projectile.type] = 12; } public override void SetDefaults() { projectile.width = 320; - projectile.height = 88; + projectile.height = 1020; projectile.hostile = true; projectile.tileCollide = false; projectile.ignoreWater = true; @@ -48,80 +49,56 @@ namespace CalamityMod.Projectiles.Boss projectile.active = false; projectile.netUpdate = true; return; - } - float scaleBase = 70f; - float scaleMult = 3.5f; - float baseWidth = 320f; - float baseHeight = 88f; - - projectile.frameCounter++; - if (projectile.frameCounter > 2) - { - projectile.frame++; - projectile.frameCounter = 0; - } - if (projectile.frame >= Main.projFrames[projectile.type]) - { - projectile.frame = 0; - } - if (projectile.localAI[0] == 0f) - { - projectile.localAI[0] = 1f; - projectile.scale = (scaleBase - projectile.ai[1]) * scaleMult / scaleBase; - CalamityGlobalProjectile.ExpandHitboxBy(projectile, (int)(baseWidth * projectile.scale), (int)(baseHeight * projectile.scale)); - projectile.netUpdate = true; - } - if (projectile.ai[1] != -1f) - { - projectile.scale = (scaleBase - projectile.ai[1]) * scaleMult / scaleBase; - projectile.width = (int)(baseWidth * projectile.scale); - projectile.height = (int)(baseHeight * projectile.scale); - } - - if (!Collision.SolidCollision(projectile.position, projectile.width, projectile.height)) - { - projectile.alpha -= 30; - if (projectile.alpha < 60) - { - projectile.alpha = 60; - } - } - else - { - projectile.alpha += 30; - if (projectile.alpha > 150) - { - projectile.alpha = 150; - } - } - if (projectile.ai[0] > 0f) - { - projectile.ai[0] -= 1f; - } - - if (projectile.ai[0] == 1f && projectile.ai[1] > 0f && projectile.owner == Main.myPlayer) - { - projectile.netUpdate = true; - Vector2 center = projectile.Center; - center.Y -= baseHeight * projectile.scale / 2f; - float num618 = (scaleBase - projectile.ai[1] + 1f) * scaleMult / scaleBase; - center.Y -= baseHeight * num618 / 2f; - center.Y += 2f; - Projectile.NewProjectile(center, projectile.velocity, projectile.type, projectile.damage, projectile.knockBack, projectile.owner, 11f, projectile.ai[1] - 1f); } } - public override Color? GetAlpha(Color lightColor) - { - return new Color(Main.DiscoR, Main.DiscoG, Main.DiscoB, projectile.alpha); + internal Color ColorFunction(float completionRatio) + { + return Color.Lerp(Color.Yellow, Color.Yellow, completionRatio); + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + float _ = 0f; + return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), + targetHitbox.Size(), + projectile.Bottom, + projectile.Bottom - Vector2.UnitY * TornadoHeight, + 72, + ref _); } - public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) { - Texture2D texture2D13 = Main.projectileTexture[projectile.type]; - int num214 = Main.projectileTexture[projectile.type].Height / Main.projFrames[projectile.type]; - int y6 = num214 * projectile.frame; - Main.spriteBatch.Draw(texture2D13, projectile.Center - Main.screenPosition + new Vector2(0f, projectile.gfxOffY), new Microsoft.Xna.Framework.Rectangle?(new Rectangle(0, y6, texture2D13.Width, num214)), projectile.GetAlpha(lightColor), projectile.rotation, new Vector2((float)texture2D13.Width / 2f, (float)num214 / 2f), projectile.scale, SpriteEffects.None, 0f); + if (TornadoDrawer is null) + TornadoDrawer = new PrimitiveTrail(_ => projectile.width * 0.5f + 16f, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:Bordernado"]); + + GameShaders.Misc["CalamityMod:Bordernado"].UseSaturation(-0.2f); + GameShaders.Misc["CalamityMod:Bordernado"].SetShaderTexture(ModContent.GetTexture("Terraria/Misc/Perlin")); + Vector2[] drawPoints = new Vector2[5]; + Vector2 upwardAscent = Vector2.UnitY * TornadoHeight; + Vector2 downwardOffset = Vector2.UnitY * projectile.height / (drawPoints.Length + 1); + + Vector2 bottom = projectile.Bottom + downwardOffset; + Vector2 top = bottom - upwardAscent; + for (int i = 0; i < drawPoints.Length - 1; i++) + drawPoints[i] = Vector2.Lerp(top, bottom, i / (float)(drawPoints.Length - 1)); + + drawPoints[drawPoints.Length - 1] = bottom; + TornadoDrawer.Draw(drawPoints, -Main.screenPosition, 85); + + Texture2D vortexTexture = ModContent.GetTexture("CalamityMod/Projectiles/Boss/OldDukeVortex"); + for (int i = 0; i < 110; i++) + { + float angle = MathHelper.TwoPi * i / 50f + Main.GlobalTime * MathHelper.TwoPi; + Color drawColor = Color.White * 0.04f; + drawColor.A = 0; + Vector2 drawPosition = bottom + angle.ToRotationVector2() * 4f - Main.screenPosition; + + drawPosition += (angle + Main.GlobalTime * i / 16f).ToRotationVector2() * 6f; + spriteBatch.Draw(vortexTexture, drawPosition, null, drawColor, angle + MathHelper.PiOver2, vortexTexture.Size() * 0.5f, 0.9f, SpriteEffects.None, 0f); + } + return false; } diff --git a/Projectiles/Boss/SkyFlareRevenge.cs b/Projectiles/Boss/SkyFlareRevenge.cs index 71d404d7e9..f39d157b8c 100644 --- a/Projectiles/Boss/SkyFlareRevenge.cs +++ b/Projectiles/Boss/SkyFlareRevenge.cs @@ -74,6 +74,7 @@ namespace CalamityMod.Projectiles.Boss int type = ModContent.ProjectileType(); int damage = projectile.GetProjectileDamage(ModContent.NPCType()); int nado = Projectile.NewProjectile(projectile.Center, Vector2.Zero, type, damage, 4f, Main.myPlayer, 16f, 50f); + Main.projectile[nado].Bottom = projectile.Center; Main.projectile[nado].netUpdate = true; } } diff --git a/Projectiles/CalamityGlobalProjectile.cs b/Projectiles/CalamityGlobalProjectile.cs index 46857355e2..e5b2eb1430 100644 --- a/Projectiles/CalamityGlobalProjectile.cs +++ b/Projectiles/CalamityGlobalProjectile.cs @@ -1,11 +1,15 @@ +using CalamityMod.Buffs.DamageOverTime; +using CalamityMod.Buffs.StatDebuffs; using CalamityMod.CalPlayer; using CalamityMod.Events; +using CalamityMod.Items.Accessories; using CalamityMod.NPCs; using CalamityMod.NPCs.NormalNPCs; using CalamityMod.Projectiles.Boss; using CalamityMod.Projectiles.Melee; using CalamityMod.Projectiles.Melee.Yoyos; using CalamityMod.Projectiles.Rogue; +using CalamityMod.Projectiles.Summon; using CalamityMod.Projectiles.Typeless; using CalamityMod.World; using Microsoft.Xna.Framework; @@ -18,6 +22,8 @@ using Terraria.ModLoader; using Terraria.Utilities; using static Terraria.ModLoader.ModContent; +using NanotechProjectile = CalamityMod.Projectiles.Typeless.Nanotech; + namespace CalamityMod.Projectiles { public class CalamityGlobalProjectile : GlobalProjectile @@ -108,8 +114,12 @@ namespace CalamityMod.Projectiles public const float MaliceModeProjectileVelocityMultiplier = 1.25f; public const float BossRushProjectileVelocityMultiplier = 1.35f; - #region SetDefaults - public override void SetDefaults(Projectile projectile) + // Enchantment variables. + public int ExplosiveEnchantCountdown = 0; + public const int ExplosiveEnchantTime = 2400; + + #region SetDefaults + public override void SetDefaults(Projectile projectile) { if (CalamityLists.trueMeleeProjectileList.Contains(projectile.type)) trueMelee = true; @@ -245,6 +255,47 @@ namespace CalamityMod.Projectiles #region PreAI public override bool PreAI(Projectile projectile) { + if (projectile.minion && ExplosiveEnchantCountdown > 0) + { + ExplosiveEnchantCountdown--; + if (defDamage == 0) + defDamage = projectile.damage; + projectile.damage = (int)(defDamage * MathHelper.SmoothStep(1f, 1.6f, 1f - ExplosiveEnchantCountdown / (float)ExplosiveEnchantTime)); + + // Make fizzle sounds and fire dust to indicate the impending explosion. + if (ExplosiveEnchantCountdown <= 300) + { + if (Main.rand.NextBool(24)) + Main.PlaySound(SoundID.DD2_BetsyFireballShot, projectile.Center); + + Dust fire = Dust.NewDustPerfect(projectile.Center + Main.rand.NextVector2Circular(projectile.width, projectile.height) * 0.42f, 267); + fire.color = Color.Lerp(Color.Orange, Color.Red, Main.rand.NextFloat(0.45f, 1f)); + fire.scale = Main.rand.NextFloat(1.4f, 1.65f); + fire.fadeIn = 0.5f; + fire.noGravity = true; + } + + if (ExplosiveEnchantCountdown % 40 == 39 && Main.rand.NextBool(12)) + { + int damage = (int)(Main.player[projectile.owner].MinionDamage() * 2000); + Projectile.NewProjectile(projectile.Center, Vector2.Zero, ProjectileType(), damage, 0f, projectile.owner); + } + + if (ExplosiveEnchantCountdown <= 0) + { + Main.PlaySound(SoundID.DD2_KoboldExplosion, projectile.Center); + if (Main.myPlayer == projectile.owner) + { + if (projectile.minionSlots > 0f) + { + int damage = (int)(Main.player[projectile.owner].MinionDamage() * 6000); + Projectile.NewProjectile(projectile.Center, Vector2.Zero, ProjectileType(), damage, 0f, projectile.owner); + } + projectile.Kill(); + } + } + } + if (RequiresManualResurrection) { // Reactivate the projectile the instant it's created. This is dirty as fuck, but @@ -1776,9 +1827,9 @@ namespace CalamityMod.Projectiles { if (Main.player[projectile.owner].miscCounter % 30 == 0 && projectile.FinalExtraUpdate()) { - if (projectile.owner == Main.myPlayer && player.ownedProjectileCounts[ProjectileType()] < 5) + if (projectile.owner == Main.myPlayer && player.ownedProjectileCounts[ProjectileType()] < 5) { - Projectile.NewProjectile(projectile.Center, Vector2.Zero, ProjectileType(), (int)(60 * player.RogueDamage()), 0f, projectile.owner); + Projectile.NewProjectile(projectile.Center, Vector2.Zero, ProjectileType(), (int)(60 * player.RogueDamage()), 0f, projectile.owner); } } } @@ -2025,6 +2076,9 @@ namespace CalamityMod.Projectiles Player player = Main.player[projectile.owner]; CalamityPlayer modPlayer = player.Calamity(); + if (modPlayer.rottenDogTooth && projectile.Calamity().stealthStrike) + target.AddBuff(BuffType(), RottenDogtooth.ArmorCrunchDebuffTime); + // Super dummies have nearly 10 million max HP (which is used in damage calculations). // This can very easily cause damage numbers that are unrealistic for the weapon. // As a result, they are omitted in this code. @@ -2048,6 +2102,23 @@ namespace CalamityMod.Projectiles organicEnemyHitEffect?.Invoke(target); } } + + if (modPlayer.flamingItemEnchant && !projectile.minion) + target.AddBuff(BuffType(), 420); + + if (modPlayer.farProximityRewardEnchant) + { + float proximityDamageInterpolant = Utils.InverseLerp(250f, 2400f, target.Distance(player.Center), true); + float proximityDamageFactor = MathHelper.SmoothStep(0.7f, 1.45f, proximityDamageInterpolant); + damage = (int)Math.Ceiling(damage * proximityDamageFactor); + } + + if (modPlayer.closeProximityRewardEnchant) + { + float proximityDamageInterpolant = Utils.InverseLerp(400f, 175f, target.Distance(player.Center), true); + float proximityDamageFactor = MathHelper.SmoothStep(0.75f, 1.75f, proximityDamageInterpolant); + damage = (int)Math.Ceiling(damage * proximityDamageFactor); + } if (!projectile.npcProj && !projectile.trap && rogue && stealthStrike && modPlayer.stealthStrikeAlwaysCrits) crit = true; diff --git a/Projectiles/DraedonsArsenal/GatlingLaserProj.cs b/Projectiles/DraedonsArsenal/GatlingLaserProj.cs index c6b5a6c1c5..e03bec6fec 100644 --- a/Projectiles/DraedonsArsenal/GatlingLaserProj.cs +++ b/Projectiles/DraedonsArsenal/GatlingLaserProj.cs @@ -74,7 +74,7 @@ namespace CalamityMod.Projectiles.DraedonsArsenal // This both checks if the player has sufficient mana and consumes it if they do. // If this is false, the Gatling Laser stops functioning. - bool hasMana = player.CheckMana(gatling.mana, true, false); + bool hasMana = player.CheckMana(gatling, -1, true, false); // Checks if the Gatling Laser has sufficient charge to fire. If this is false, it stops functioning. CalamityGlobalItem modItem = gatling.Calamity(); diff --git a/Projectiles/DraedonsArsenal/PhaseslayerProjectile.cs b/Projectiles/DraedonsArsenal/PhaseslayerProjectile.cs index b1be1d8490..165fcecad2 100644 --- a/Projectiles/DraedonsArsenal/PhaseslayerProjectile.cs +++ b/Projectiles/DraedonsArsenal/PhaseslayerProjectile.cs @@ -4,8 +4,11 @@ using CalamityMod.Items.Weapons.DraedonsArsenal; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; +using System.Collections.Generic; using System.IO; +using System.Linq; using Terraria; +using Terraria.Graphics.Shaders; using Terraria.ID; using Terraria.ModLoader; @@ -57,7 +60,7 @@ namespace CalamityMod.Projectiles.DraedonsArsenal { DisplayName.SetDefault("Phaseslayer"); ProjectileID.Sets.TrailingMode[projectile.type] = 2; - ProjectileID.Sets.TrailCacheLength[projectile.type] = 8; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 13; } public override void SetDefaults() @@ -167,7 +170,6 @@ namespace CalamityMod.Projectiles.DraedonsArsenal // These lines ensure the player and their arm are rotated the correct direction to hold the sword. projectile.direction = (Math.Cos(projectile.rotation) > 0).ToDirectionInt(); player.ChangeDir(projectile.direction); - player.heldProj = projectile.whoAmI; player.itemTime = 2; player.itemAnimation = 2; player.itemRotation = projectile.rotation * projectile.direction; @@ -271,6 +273,28 @@ namespace CalamityMod.Projectiles.DraedonsArsenal } } + internal PrimitiveTrail TrailDrawer; + internal Color ColorFunction(float completionRatio) + { + float averageRotation = projectile.oldRot.Take(20).Average(angle => MathHelper.WrapAngle(angle) + MathHelper.Pi); + float deltaAngle = Math.Abs(averageRotation - (MathHelper.WrapAngle(projectile.rotation) + MathHelper.Pi)); + float opacity = projectile.Opacity; + opacity *= Utils.InverseLerp(StandardSwingSpeed * 0.7f, StandardSwingSpeed, AngularDamageFactor, true); + opacity *= (float)Math.Pow(Utils.InverseLerp(1f, 0.45f, completionRatio, true), 4D); + opacity *= (float)Math.Pow(Utils.InverseLerp(0.9f, 1.1f, deltaAngle, true), 2D); + + float rotationAdjusted = MathHelper.WrapAngle(projectile.rotation) + MathHelper.Pi; + float oldRotationAdjusted = MathHelper.WrapAngle(projectile.oldRot[1]) + MathHelper.Pi; + deltaAngle = Math.Abs(rotationAdjusted - oldRotationAdjusted); + + if (deltaAngle < 0.04f) + opacity = 0f; + + return Color.Lerp(Color.Red, Color.PaleVioletRed * completionRatio, MathHelper.Clamp(completionRatio * 0.8f, 0f, 1f)) * opacity; + } + + internal float WidthFunction(float completionRatio) => (IsSmall ? 101f : 127f) * (1f - completionRatio); + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) { Texture2D bladeTexture = ModContent.GetTexture("CalamityMod/Projectiles/DraedonsArsenal/PhaseslayerBlade"); @@ -280,19 +304,35 @@ namespace CalamityMod.Projectiles.DraedonsArsenal Vector2 bladeOffset = projectile.rotation.ToRotationVector2() * (IsSmall ? 90f : 132f) * projectile.scale; Vector2 origin = bladeTexture.Size() * 0.5f; origin /= IsSmall ? new Vector2(1f, 3f) : new Vector2(3f, 7f); + Rectangle frame = IsSmall ? bladeTexture.Frame(1, 3, 0, BladeFrameY) : bladeTexture.Frame(3, 7, BladeFrameX, BladeFrameY); - // TODO: Update this afterimage drawcode to be more cool. - for (int i = 1; i < projectile.oldRot.Length; i++) - { - float angleDelta = MathHelper.Clamp(projectile.rotation - projectile.oldRot[i], -0.26f, 0.26f); - float angle = projectile.rotation + angleDelta; - angle += MathHelper.PiOver2; - Color color = Color.White * (float)Math.Pow(1f - i / (float)projectile.oldRot.Length, 3f); - Rectangle afterimageFrame = IsSmall ? bladeTexture.Frame(1, 3, 0, 2) : bladeTexture.Frame(3, 7, 2, 6); - spriteBatch.Draw(bladeTexture, projectile.Center + bladeOffset - Main.screenPosition, afterimageFrame, color, angle, origin, projectile.scale, SpriteEffects.None, 0f); - } + if (TrailDrawer is null) + TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:PhaseslayerRipEffect"]); + GameShaders.Misc["CalamityMod:PhaseslayerRipEffect"].SetShaderTexture(ModContent.GetTexture("CalamityMod/ExtraTextures/SwordSlashTexture")); + + Player player = Main.player[projectile.owner]; + List positions = new List(); + + float swingAngularDirection = Math.Sign(projectile.rotation - projectile.oldRot[1]); + projectile.oldRot[0] += swingAngularDirection * 0.1f; + for (int i = 0; i < projectile.oldPos.Length; i++) + { + if (projectile.oldPos[i] == Vector2.Zero) + continue; + + // Skip over any very points going in the wrong direction, to prevent "nets" from the primitive. + if (i > 1 && Math.Sign(projectile.oldRot[i - 1] - projectile.oldRot[i]) != swingAngularDirection) + continue; + + Vector2 position = projectile.position + projectile.oldRot[i].ToRotationVector2() * (IsSmall ? 90f : 132f) * projectile.scale; + + positions.Add(position); + } + projectile.oldRot[0] -= swingAngularDirection * 0.1f; + + TrailDrawer.Draw(positions, projectile.Size * 0.5f - Main.screenPosition, 50); spriteBatch.Draw(bladeTexture, projectile.Center + bladeOffset - Main.screenPosition, frame, Color.White, projectile.rotation + MathHelper.PiOver2, origin, projectile.scale, SpriteEffects.None, 0f); spriteBatch.Draw(hiltTexture, projectile.Center - Main.screenPosition, null, lightColor, projectile.rotation + MathHelper.PiOver2, hiltTexture.Size() * 0.5f, projectile.scale, SpriteEffects.None, 0f); diff --git a/Projectiles/Healing/DemonHeal.cs b/Projectiles/Healing/DemonHeal.cs new file mode 100644 index 0000000000..fcff05e107 --- /dev/null +++ b/Projectiles/Healing/DemonHeal.cs @@ -0,0 +1,33 @@ +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Healing +{ + public class DemonHeal : ModProjectile + { + public Player Owner => Main.player[projectile.owner]; + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + + public override void SetStaticDefaults() => DisplayName.SetDefault("Heal"); + + public override void SetDefaults() + { + projectile.width = 4; + projectile.height = 4; + projectile.friendly = true; + projectile.penetrate = 1; + projectile.timeLeft = 640; + } + + public override void AI() + { + projectile.HealingProjectile(10, projectile.owner, 20f, 20f, true, 640); + + Dust fire = Dust.NewDustPerfect(projectile.Center, 130); + fire.velocity = Microsoft.Xna.Framework.Vector2.Zero; + fire.scale = Main.rand.NextFloat(1f, 1.15f); + fire.fadeIn = 0.45f; + fire.noGravity = true; + } + } +} diff --git a/Projectiles/Magic/ApothChloro.cs b/Projectiles/Magic/ApothChloro.cs deleted file mode 100644 index 7a7a88882a..0000000000 --- a/Projectiles/Magic/ApothChloro.cs +++ /dev/null @@ -1,122 +0,0 @@ -using CalamityMod.Buffs.DamageOverTime; -using Microsoft.Xna.Framework; -using System; -using Terraria; -using Terraria.ModLoader; -namespace CalamityMod.Projectiles.Magic -{ - public class ApothChloro : ModProjectile - { - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Rays of Annihilation"); - } - - public override void SetDefaults() - { - projectile.width = 10; - projectile.height = 10; - projectile.alpha = 70; - projectile.timeLeft = 120; - projectile.penetrate = 1; - projectile.hostile = false; - projectile.friendly = true; - projectile.magic = true; - projectile.light = 0.5f; - projectile.extraUpdates = 1; - } - - public override void AI() - { - Lighting.AddLight(projectile.Center, 0.4f, 0.2f, 0.4f); - for (int i = 0; i < 5; i++) - { - Dust dust4 = Main.dust[Dust.NewDust(projectile.position, projectile.width, projectile.height, 242, projectile.velocity.X, projectile.velocity.Y, 100, default, 1f)]; - dust4.velocity = Vector2.Zero; - dust4.position -= projectile.velocity / 5f * (float)i; - dust4.noGravity = true; - dust4.scale = 0.8f; - dust4.noLight = true; - } - float num1 = (float)(projectile.position.X - projectile.velocity.X / 10.0 * 9.0); - float num2 = (float)(projectile.position.Y - projectile.velocity.Y / 10.0 * 9.0); - float num3 = (float)Math.Sqrt((double)(projectile.velocity.X * projectile.velocity.X + projectile.velocity.Y * projectile.velocity.Y)); - float num4 = projectile.localAI[0]; - if (num4 == 0f) - { - projectile.localAI[0] = num3; - num4 = num3; - } - if (projectile.alpha > 0) - projectile.alpha = projectile.alpha - 25; - if (projectile.alpha < 0) - projectile.alpha = 0; - float num5 = (float)projectile.position.X; - float num6 = (float)projectile.position.Y; - float num7 = 300f; - bool flag2 = false; - int num8 = 0; - float num9; - if (projectile.ai[1] == 0f) - { - for (int index = 0; index < Main.maxNPCs; ++index) - { - if (Main.npc[index].CanBeChasedBy((object)this, false) && ((double)projectile.ai[1] == 0.0 || (double)projectile.ai[1] == (double)(index + 1))) - { - num1 = (float)Main.npc[index].position.X + (float)(Main.npc[index].width / 2); - num2 = (float)Main.npc[index].position.Y + (float)(Main.npc[index].height / 2); - num9 = Math.Abs((float)projectile.position.X + (float)(projectile.width / 2) - num1) + Math.Abs((float)projectile.position.Y + (float)(projectile.height / 2) - num2); - if ((double)num9 < (double)num7 && Collision.CanHit(new Vector2((float)projectile.position.X + (float)(projectile.width / 2), (float)projectile.position.Y + (float)(projectile.height / 2)), 1, 1, Main.npc[index].position, Main.npc[index].width, Main.npc[index].height)) - { - num7 = num9; - num5 = num1; - num6 = num2; - flag2 = true; - num8 = index; - } - } - } - if (flag2) - projectile.ai[1] = (float)(num8 + 1); - flag2 = false; - } - if (projectile.ai[1] > 0f) - { - int index = (int)((double)projectile.ai[1] - 1.0); - if (Main.npc[index].active && Main.npc[index].CanBeChasedBy((object)this, true) && !Main.npc[index].dontTakeDamage) - { - if ((double)Math.Abs((float)projectile.position.X + (float)(projectile.width / 2) - ((float)Main.npc[index].position.X + (float)(Main.npc[index].width / 2))) + (double)Math.Abs((float)projectile.position.Y + (float)(projectile.height / 2) - ((float)Main.npc[index].position.Y + (float)(Main.npc[index].height / 2))) < 3000.0) - { - flag2 = true; - num5 = (float)Main.npc[index].position.X + (float)(Main.npc[index].width / 2); - num6 = (float)Main.npc[index].position.Y + (float)(Main.npc[index].height / 2); - } - } - else - projectile.ai[1] = 0.0f; - } - if (!projectile.friendly) - flag2 = false; - if (flag2) - { - double num15 = (double)num4; - Vector2 vector2 = new Vector2((float)(projectile.position.X + (double)projectile.width * 0.5), (float)(projectile.position.Y + (double)projectile.height * 0.5)); - num2 = num5 - (float)vector2.X; - num9 = num6 - (float)vector2.Y; - double num10 = Math.Sqrt((double)num2 * (double)num2 + (double)num9 * (double)num9); - float num11 = (float)(num15 / num10); - float num12 = num2 * num11; - float num13 = num9 * num11; - int num14 = 8; - projectile.velocity.X = (float)((projectile.velocity.X * (double)(num14 - 1) + (double)num12) / (double)num14); - projectile.velocity.Y = (float)((projectile.velocity.Y * (double)(num14 - 1) + (double)num13) / (double)num14); - } - } - - public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) - { - target.AddBuff(ModContent.BuffType(), 600, true); - target.AddBuff(ModContent.BuffType(), 600, true); - } - } -} diff --git a/Projectiles/Magic/ApothChloro.png b/Projectiles/Magic/ApothChloro.png deleted file mode 100644 index a17ddc8d5d..0000000000 Binary files a/Projectiles/Magic/ApothChloro.png and /dev/null differ diff --git a/Projectiles/Magic/ApothJaws.cs b/Projectiles/Magic/ApothJaws.cs deleted file mode 100644 index 99eb5a36c4..0000000000 --- a/Projectiles/Magic/ApothJaws.cs +++ /dev/null @@ -1,79 +0,0 @@ -using CalamityMod.Buffs.DamageOverTime; -using CalamityMod.Buffs.StatDebuffs; -using System; -using Terraria; -using Terraria.ModLoader; -namespace CalamityMod.Projectiles.Magic -{ - public class ApothJaws : ModProjectile - { - private const float degrees = (float)(Math.PI / 180) * 2; - - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Jaws of Annihilation"); - } - - public override void SetDefaults() - { - projectile.width = 144; - projectile.height = 72; - projectile.alpha = 70; - projectile.timeLeft = 240; - projectile.penetrate = -1; - projectile.usesLocalNPCImmunity = true; - projectile.localNPCHitCooldown = 10; - projectile.friendly = true; - projectile.magic = true; - projectile.tileCollide = false; - projectile.ignoreWater = true; - projectile.light = 1.5f; - } - - public override void AI() - { - if (projectile.timeLeft % 8 == 0) - { - double angle = (double)Main.rand.Next(360) * Math.PI / 180; - float offsetX = projectile.position.X + (float)Main.rand.Next((int)projectile.width); - float offsetY = projectile.position.Y + (float)Main.rand.Next((int)projectile.height); - if (projectile.owner == Main.myPlayer) - { - Projectile.NewProjectile(offsetX, offsetY, 14 * (float)Math.Cos(angle), 14 * (float)Math.Sin(angle), ModContent.ProjectileType(), projectile.damage, projectile.knockBack / 2, projectile.owner); - } - } - if (projectile.timeLeft < 30) - projectile.alpha = projectile.alpha + 6; - else if (projectile.timeLeft < 210) - { - projectile.velocity.X *= 0.9f; - projectile.velocity.Y *= 0.9f; - } - else if (projectile.timeLeft < 240) - { - if (projectile.ai[1] == 0) - projectile.rotation += 1.3f * degrees; - else - projectile.rotation -= 1.3f * degrees; - } - else if (projectile.timeLeft == 240) - { - if (projectile.ai[1] == 0) - projectile.rotation = projectile.ai[0] - 30 * degrees; - else - { - projectile.rotation = projectile.ai[0] + 30 * degrees + (float)Math.PI; - projectile.spriteDirection = -1; - } - } - } - - public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) - { - target.AddBuff(ModContent.BuffType(), 600, true); - target.AddBuff(ModContent.BuffType(), 600, true); - target.AddBuff(ModContent.BuffType(), 600, true); - target.AddBuff(ModContent.BuffType(), 30, true); - } - } -} diff --git a/Projectiles/Magic/ApothJaws.png b/Projectiles/Magic/ApothJaws.png deleted file mode 100644 index 84d2046947..0000000000 Binary files a/Projectiles/Magic/ApothJaws.png and /dev/null differ diff --git a/Projectiles/Magic/ApothMark.cs b/Projectiles/Magic/ApothMark.cs deleted file mode 100644 index f444c0fa88..0000000000 --- a/Projectiles/Magic/ApothMark.cs +++ /dev/null @@ -1,70 +0,0 @@ -using CalamityMod.Buffs.DamageOverTime; -using CalamityMod.Buffs.StatDebuffs; -using System; -using Terraria; -using Terraria.ModLoader; -namespace CalamityMod.Projectiles.Magic -{ - public class ApothMark : ModProjectile - { - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Jaws of Annihilation"); - } - - public override void SetDefaults() - { - projectile.width = 123; - projectile.height = 105; - projectile.alpha = 70; - projectile.timeLeft = 240; - projectile.penetrate = -1; - projectile.usesLocalNPCImmunity = true; - projectile.localNPCHitCooldown = 10; - projectile.friendly = true; - projectile.magic = true; - projectile.tileCollide = false; - projectile.ignoreWater = true; - projectile.light = 1.5f; - } - - public override void AI() - { - if (projectile.timeLeft < 30) - projectile.alpha = projectile.alpha + 6; - else if (projectile.timeLeft < 210) - { - projectile.velocity.X *= 0.9f; - projectile.velocity.Y *= 0.9f; - } - else if (projectile.timeLeft == 240) - { - projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X); - double offsetHyp = Math.Sqrt(48 * 48 + 38 * 38); - double offsetRotation = Math.Atan2(-38, 48) + (double)projectile.rotation; - double offsetX = offsetHyp * Math.Cos(offsetRotation); - double offsetY = offsetHyp * Math.Sin(offsetRotation); - if (projectile.owner == Main.myPlayer) - { - Projectile.NewProjectile(projectile.Center.X + (float)offsetX, projectile.Center.Y + (float)offsetY, projectile.velocity.X, projectile.velocity.Y, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner, projectile.rotation, 0f); - } - offsetRotation = Math.Atan2(38, 48) + (double)projectile.rotation; - offsetX = offsetHyp * Math.Cos(offsetRotation); - offsetY = offsetHyp * Math.Sin(offsetRotation); - - if (projectile.owner == Main.myPlayer) - { - Projectile.NewProjectile(projectile.position.X + projectile.width / 2 + (float)offsetX, projectile.position.Y + projectile.height / 2 + (float)offsetY, projectile.velocity.X, projectile.velocity.Y, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner, projectile.rotation, 1f); - } - } - } - - public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) - { - target.AddBuff(ModContent.BuffType(), 600, true); - target.AddBuff(ModContent.BuffType(), 600, true); - target.AddBuff(ModContent.BuffType(), 600, true); - target.AddBuff(ModContent.BuffType(), 30, true); - } - } -} diff --git a/Projectiles/Magic/ApothMark.png b/Projectiles/Magic/ApothMark.png deleted file mode 100644 index 41f8b01b7a..0000000000 Binary files a/Projectiles/Magic/ApothMark.png and /dev/null differ diff --git a/Projectiles/Magic/ApotheosisEnergy.cs b/Projectiles/Magic/ApotheosisEnergy.cs new file mode 100644 index 0000000000..0b27b1b7fe --- /dev/null +++ b/Projectiles/Magic/ApotheosisEnergy.cs @@ -0,0 +1,100 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Linq; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +namespace CalamityMod.Projectiles.Magic +{ + public class ApotheosisEnergy : ModProjectile + { + internal PrimitiveTrail TrailDrawer = null; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Apotheosis Energy"); + ProjectileID.Sets.TrailCacheLength[projectile.type] = 20; + ProjectileID.Sets.TrailingMode[projectile.type] = 2; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 20; + projectile.friendly = true; + projectile.ignoreWater = true; + projectile.tileCollide = false; + projectile.magic = true; + projectile.penetrate = -1; + projectile.timeLeft = 210; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 1; + } + + public override void AI() + { + Lighting.AddLight(projectile.Center, Color.Cyan.ToVector3() * projectile.Opacity); + + // Fade-effects. + if (projectile.timeLeft < 40f) + projectile.Opacity = Utils.InverseLerp(0f, 40f, projectile.timeLeft, true); + else + projectile.alpha = Utils.Clamp(projectile.alpha - 30, 0, 255); + + NPC potentialTarget = projectile.Center.ClosestNPCAt(5900f); + if (potentialTarget != null) + { + float squaredTargetDistance = projectile.DistanceSQ(potentialTarget.Center); + if (squaredTargetDistance > 120f * 120f && squaredTargetDistance < 1000f * 1000f) + projectile.velocity = projectile.velocity.ToRotation().AngleTowards(projectile.AngleTo(potentialTarget.Center), 0.1f).ToRotationVector2() * projectile.velocity.Length(); + } + } + + internal Color ColorFunction(float completionRatio) + { + Color baseColor = Color.Cyan; + if (completionRatio > 0.66f) + baseColor = Color.Lerp(baseColor, Color.Fuchsia, (completionRatio - 0.66f) / 0.33f); + else + { + float whiteFade = (float)Math.Sin(Utils.InverseLerp(0.0f, 0.2f, completionRatio, true) * MathHelper.Pi + Main.GlobalTime * 3f) * 0.45f; + baseColor = Color.Lerp(baseColor, Color.White, whiteFade); + } + + Color colorToUse = baseColor; + if (completionRatio > 0.5f) + colorToUse = Color.Lerp(baseColor, Color.Transparent, 1f - completionRatio / 0.5f); + return colorToUse * projectile.Opacity; + } + + internal float WidthFunction(float completionRatio) + { + float width; + float maxWidthOutwardness = 6f; + if (completionRatio < 0.2f) + width = (float)Math.Sin(completionRatio / 0.2f * MathHelper.PiOver2) * maxWidthOutwardness + 0.1f; + else + width = MathHelper.Lerp(maxWidthOutwardness, 0f, Utils.InverseLerp(0.2f, 1f, completionRatio, true)); + return width * projectile.Opacity; + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + for (int i = 0; i < projectile.oldPos.Length; i++) + { + if (Collision.CheckAABBvAABBCollision(projectile.oldPos[i], projHitbox.Size(), targetHitbox.TopLeft(), projHitbox.Size())) + return true; + } + return false; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + if (TrailDrawer is null) + TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction); + + TrailDrawer.Draw(projectile.oldPos, projectile.Size * 0.5f - Main.screenPosition, 85); + return false; + } + } +} diff --git a/Projectiles/Magic/ApotheosisEnergy.png b/Projectiles/Magic/ApotheosisEnergy.png new file mode 100644 index 0000000000..ead80128fa Binary files /dev/null and b/Projectiles/Magic/ApotheosisEnergy.png differ diff --git a/Projectiles/Magic/ApotheosisJaw.png b/Projectiles/Magic/ApotheosisJaw.png new file mode 100644 index 0000000000..ccf7b18279 Binary files /dev/null and b/Projectiles/Magic/ApotheosisJaw.png differ diff --git a/Projectiles/Magic/ApotheosisWorm.cs b/Projectiles/Magic/ApotheosisWorm.cs new file mode 100644 index 0000000000..dd7c1fa2ec --- /dev/null +++ b/Projectiles/Magic/ApotheosisWorm.cs @@ -0,0 +1,363 @@ +using CalamityMod.Buffs.DamageOverTime; +using CalamityMod.Buffs.StatDebuffs; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.IO; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Magic +{ + public class ApotheosisWorm : ModProjectile + { + internal class Segment + { + // Doing a typical byte seems to cause the thing to flicker when doing super fast fades. + // This is most likely due to under/overflows. + internal short Alpha; + internal float Rotation; + internal Vector2 Center; + internal void WriteTo(BinaryWriter writer) + { + writer.Write(Alpha); + writer.Write(Rotation); + writer.WritePackedVector2(Center); + } + + internal void ReadFrom(BinaryReader reader) + { + Alpha = reader.ReadInt16(); + Rotation = reader.ReadSingle(); + Center = reader.ReadPackedVector2(); + } + + internal Segment(byte alpha, float rotation, Vector2 center) + { + Alpha = alpha; + Rotation = rotation; + Center = center; + } + } + + internal Vector2 PortalPosition; + internal Segment[] Segments = new Segment[80]; + + internal Player Owner => Main.player[projectile.owner]; + internal ref float Time => ref projectile.ai[0]; + internal ref float FlyAcceleration => ref projectile.ai[1]; + internal ref float JawRotation => ref projectile.localAI[1]; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("The Devourer of Gods"); + } + + public override void SetDefaults() + { + projectile.width = 108; + projectile.height = 108; + projectile.alpha = 255; + projectile.timeLeft = 300; + projectile.penetrate = -1; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 9; + projectile.friendly = true; + projectile.magic = true; + projectile.tileCollide = false; + projectile.ignoreWater = true; + projectile.netImportant = true; + projectile.light = 1.5f; + } + + // Be VERY careful with the projectile's netcode, and use syncs very sparingly. + // Syncing will use a lot more bytes than usual. + + public override void SendExtraAI(BinaryWriter writer) + { + for (int i = 0; i < Segments.Length; i++) + { + Segments[i].WriteTo(writer); + } + } + + public override void ReceiveExtraAI(BinaryReader reader) + { + for (int i = 0; i < Segments.Length; i++) + { + Segments[i].ReadFrom(reader); + } + } + + public override void AI() + { + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2; + + // Initialization. + if (projectile.localAI[0] == 0f) + { + PortalPosition = projectile.Center + projectile.velocity * 7f; + if (Main.myPlayer == projectile.owner) + InitializeSegments(); + projectile.localAI[0] = 1f; + } + + // Head fade-in effects. + if (projectile.timeLeft <= 75) + projectile.alpha = Utils.Clamp(projectile.alpha + 40, 0, 255); + else if (Time > 15f) + projectile.alpha = Utils.Clamp(projectile.alpha - 40, 0, 255); + + // Update all segments of the devourer every frame. + for (int i = 0; i < Segments.Length; i++) + UpdateSegment(i); + + Time++; + + // Reset the jaw's rotation slowly over time. + JawRotation = MathHelper.Lerp(JawRotation, 0f, 0.08f); + + NPC potentialTarget = projectile.Center.ClosestNPCAt(4200f); + if (potentialTarget != null) + AttackTarget(potentialTarget); + } + + internal void InitializeSegments() + { + Vector2 directionToMouse = (Main.MouseWorld - projectile.Center).SafeNormalize(Vector2.UnitX * Owner.direction); + projectile.rotation = directionToMouse.ToRotation() + MathHelper.PiOver2; + for (int i = 0; i < Segments.Length; i++) + { + Segments[i] = new Segment(255, projectile.rotation, projectile.Center + directionToMouse / Segments.Length * i * 900f); + } + projectile.netUpdate = true; + } + + internal void UpdateSegment(int segmentIndex) + { + float aheadSegmentRotation = segmentIndex > 0 ? Segments[segmentIndex - 1].Rotation : projectile.rotation; + Vector2 aheadSegmentCenter = segmentIndex > 0 ? Segments[segmentIndex - 1].Center : projectile.Center; + Vector2 offsetToAheadSegment = aheadSegmentCenter - Segments[segmentIndex].Center; + + // Individual segment fade effects depending on time. + if (projectile.timeLeft <= 60) + { + int invisibleSegmentIndex = (int)MathHelper.Lerp(0f, Segments.Length, 1f - MathHelper.Clamp(projectile.timeLeft / 60f * 1.4f, 0f, 1f)); + if (segmentIndex < invisibleSegmentIndex) + { + Segments[segmentIndex].Alpha += 31; + if (Segments[segmentIndex].Alpha > 255) + Segments[segmentIndex].Alpha = 255; + } + } + + if (Time <= 90f) + { + int visibleSegmentIndex = (int)MathHelper.Lerp(0f, Segments.Length, Utils.InverseLerp(15f, 70f, Time, true)); + if (segmentIndex < visibleSegmentIndex) + { + Segments[segmentIndex].Alpha -= 17; + if (Segments[segmentIndex].Alpha < 0) + Segments[segmentIndex].Alpha = 0; + } + } + + // This variant of segment attachment incorporates rotation. + // Given the fact that all segments will execute this code is succession, the + // result across the entire worm will exponentially decay over each segment, + // allowing for smooth rotations. This code is what the stardust dragon and mechworm use for their segmenting. + if (aheadSegmentRotation != Segments[segmentIndex].Rotation) + { + float offsetAngle = MathHelper.WrapAngle(aheadSegmentRotation - Segments[segmentIndex].Rotation); + offsetToAheadSegment = offsetToAheadSegment.RotatedBy(offsetAngle * 0.075f); + } + Segments[segmentIndex].Rotation = offsetToAheadSegment.ToRotation() + MathHelper.PiOver2; + if (offsetToAheadSegment != Vector2.Zero) + Segments[segmentIndex].Center = aheadSegmentCenter - offsetToAheadSegment.SafeNormalize(Vector2.Zero) * 70f; + } + + internal void AttackTarget(NPC target) + { + if (Time >= 40f && projectile.alpha == 0 && Main.rand.NextBool(8)) + { + if (Main.myPlayer == projectile.owner) + { + Segment segmentToShootFrom = Segments[Main.rand.Next(Segments.Length)]; + Vector2 shootVelocity = (target.Center - segmentToShootFrom.Center).SafeNormalize(Vector2.UnitY).RotatedByRandom(0.25f) * 18f; + Projectile.NewProjectile(segmentToShootFrom.Center, shootVelocity, ModContent.ProjectileType(), projectile.damage / 2, 0f, projectile.owner); + } + + if (Main.rand.NextBool(10)) + Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Item, "Sounds/Item/LargeMechGaussRifle"), projectile.Center); + } + + float idealFlyAcceleration = 0.18f; + + Vector2 destination = target.Center; + float distanceFromDestination = projectile.Distance(destination); + + // Get a swerve effect if somewhat far from the target. + if (projectile.Distance(destination) > 725f) + { + destination += (Time % 30f / 30f * MathHelper.TwoPi).ToRotationVector2() * 145f; + distanceFromDestination = projectile.Distance(destination); + idealFlyAcceleration *= 2.5f; + } + + // Charge if the target is far away. + if (distanceFromDestination > 1500f && Time > 45f) + idealFlyAcceleration = MathHelper.Min(6f, FlyAcceleration + 1f); + + FlyAcceleration = MathHelper.Lerp(FlyAcceleration, idealFlyAcceleration, 0.3f); + + float directionToTargetOrthogonality = Vector2.Dot(projectile.velocity.SafeNormalize(Vector2.Zero), projectile.SafeDirectionTo(destination)); + + // Fly towards the target if it's far. + if (distanceFromDestination > 320f) + { + float speed = projectile.velocity.Length(); + if (speed < 23f) + speed += 0.08f; + + if (speed > 32f) + speed -= 0.08f; + + // Go faster if the line of sight is aiming closely at the target. + if (directionToTargetOrthogonality < 0.85f && directionToTargetOrthogonality > 0.5f) + speed += 6f; + + // And go slower otherwise so that the devourer can angle towards the target more accurately. + if (directionToTargetOrthogonality < 0.5f && directionToTargetOrthogonality > -0.7f) + speed -= 10f; + + speed = MathHelper.Clamp(speed, 16f, 34f); + + projectile.velocity = projectile.velocity.ToRotation().AngleTowards(projectile.AngleTo(destination), FlyAcceleration).ToRotationVector2() * speed; + } + + // Open jaws when near the target, and snap when really close. + if (distanceFromDestination < 200f) + JawRotation = MathHelper.Lerp(JawRotation, MathHelper.ToRadians(-34f), 0.4f); + else if (distanceFromDestination < 480f) + JawRotation = MathHelper.Lerp(JawRotation, MathHelper.ToRadians(15f), 0.24f); + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + target.AddBuff(ModContent.BuffType(), 600, true); + target.AddBuff(ModContent.BuffType(), 600, true); + target.AddBuff(ModContent.BuffType(), 600, true); + if (Main.rand.NextBool(30)) + { + target.AddBuff(ModContent.BuffType(), 120, true); + } + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + SpriteEffects spriteEffects = SpriteEffects.None; + if (projectile.spriteDirection == 1) + spriteEffects = SpriteEffects.FlipHorizontally; + + Texture2D headTexture = Main.projectileTexture[projectile.type]; + Vector2 drawPosition = projectile.Center - Main.screenPosition; + Vector2 headTextureOrigin = Main.projectileTexture[projectile.type].Size() * 0.5f; + drawPosition -= headTexture.Size() * projectile.scale * 0.5f; + drawPosition += headTextureOrigin * projectile.scale + new Vector2(0f, 4f + projectile.gfxOffY); + + Texture2D jawTexture = ModContent.GetTexture("CalamityMod/Projectiles/Magic/ApotheosisJaw"); + Vector2 jawOrigin = jawTexture.Size() * 0.5f; + + // Segment drawing. + Texture2D bodyTexture = ModContent.GetTexture("CalamityMod/NPCs/DevourerofGods/DevourerofGodsBodyS"); + Texture2D tailTexture = ModContent.GetTexture("CalamityMod/NPCs/DevourerofGods/DevourerofGodsTailS"); + + // Not white to differentiate itself slightly from regular DoG when fighting Boss Rush. + Color baseColor = Color.Lerp(Color.White, Color.Fuchsia, 0.15f); + + for (int i = 0; i < Segments.Length; i++) + { + bool isTail = i == Segments.Length - 1; + Texture2D segmentTexture = isTail ? tailTexture : bodyTexture; + Vector2 segmentOrigin = segmentTexture.Size() * 0.5f; + spriteBatch.Draw(segmentTexture, Segments[i].Center - Main.screenPosition, null, baseColor * ((255 - Segments[i].Alpha) / 255f), Segments[i].Rotation, segmentOrigin, projectile.scale, SpriteEffects.None, 0f); + } + + // Jaw drawing. + for (int i = -1; i <= 1; i += 2) + { + float jawBaseOffset = 42f; + SpriteEffects jawSpriteEffect = SpriteEffects.None; + if (i == 1) + jawSpriteEffect |= SpriteEffects.FlipHorizontally; + + // X/Y offsets for the jaws depending on the angle of the jaw. + // Has potential to act weird at unexpected angles, but that should never happen naturally. + Vector2 jawPosition = drawPosition; + jawPosition += Vector2.UnitX.RotatedBy(projectile.rotation + JawRotation * i) * i * (jawBaseOffset + (float)Math.Sin(JawRotation) * 24f); + jawPosition -= Vector2.UnitY.RotatedBy(projectile.rotation) * (38f + (float)Math.Sin(JawRotation) * 30f); + + spriteBatch.Draw(jawTexture, jawPosition, null, baseColor * projectile.Opacity, projectile.rotation + JawRotation * i, jawOrigin, projectile.scale, jawSpriteEffect, 0f); + } + + // Portal drawing at the start of the devourer's lifetime. + // This is extremely similar to the portal created when DoG teleports. + if (Time < 60f) + { + float currentFade = Utils.InverseLerp(0f, 8f, Time, true) * Utils.InverseLerp(60f, 52f, Time, true); + currentFade *= (1f + 0.2f * (float)Math.Cos(Main.GlobalTime % 30f * MathHelper.Pi * 3f)) * 0.8f; + + Texture2D texture = ModContent.GetTexture("CalamityMod/Projectiles/StarProj"); + Vector2 drawPos = PortalPosition - Main.screenPosition; + baseColor = new Color(150, 100, 255, 255) * projectile.Opacity; + baseColor *= 0.5f; + baseColor.A = 0; + Color colorA = baseColor; + Color colorB = baseColor * 0.5f; + colorA *= currentFade; + colorB *= currentFade; + Vector2 origin = texture.Size() / 2f; + Vector2 scale = new Vector2(4f, 10f) * projectile.Opacity * currentFade; + + spriteBatch.Draw(texture, drawPos, null, colorA, MathHelper.PiOver2, origin, scale, SpriteEffects.None, 0); + spriteBatch.Draw(texture, drawPos, null, colorA, 0f, origin, scale, SpriteEffects.None, 0); + spriteBatch.Draw(texture, drawPos, null, colorB, MathHelper.PiOver2, origin, scale * 0.8f, SpriteEffects.None, 0); + spriteBatch.Draw(texture, drawPos, null, colorB, 0f, origin, scale * 0.8f, SpriteEffects.None, 0); + + spriteBatch.Draw(texture, drawPos, null, colorA, MathHelper.PiOver2 + Main.GlobalTime * 3f * 0.25f, origin, scale, SpriteEffects.None, 0); + spriteBatch.Draw(texture, drawPos, null, colorA, Main.GlobalTime * 3f * 0.25f, origin, scale, SpriteEffects.None, 0); + spriteBatch.Draw(texture, drawPos, null, colorB, MathHelper.PiOver2 + Main.GlobalTime * 3f * 0.5f, origin, scale * 0.8f, SpriteEffects.None, 0); + spriteBatch.Draw(texture, drawPos, null, colorB, Main.GlobalTime * 3f * 0.5f, origin, scale * 0.8f, SpriteEffects.None, 0); + + spriteBatch.Draw(texture, drawPos, null, colorA, MathHelper.PiOver4, origin, scale * 0.6f, SpriteEffects.None, 0); + spriteBatch.Draw(texture, drawPos, null, colorA, MathHelper.PiOver4 * 3f, origin, scale * 0.6f, SpriteEffects.None, 0); + spriteBatch.Draw(texture, drawPos, null, colorB, MathHelper.PiOver4, origin, scale * 0.4f, SpriteEffects.None, 0); + spriteBatch.Draw(texture, drawPos, null, colorB, MathHelper.PiOver4 * 3f, origin, scale * 0.4f, SpriteEffects.None, 0); + + spriteBatch.Draw(texture, drawPos, null, colorA, MathHelper.PiOver4 + Main.GlobalTime * 3f * 0.75f, origin, scale * 0.6f, SpriteEffects.None, 0); + spriteBatch.Draw(texture, drawPos, null, colorA, MathHelper.PiOver4 * 3f + Main.GlobalTime * 3f * 0.75f, origin, scale * 0.6f, SpriteEffects.None, 0); + spriteBatch.Draw(texture, drawPos, null, colorB, MathHelper.PiOver4 + Main.GlobalTime * 3f, origin, scale * 0.4f, SpriteEffects.None, 0); + spriteBatch.Draw(texture, drawPos, null, colorB, MathHelper.PiOver4 * 3f + Main.GlobalTime * 3f, origin, scale * 0.4f, SpriteEffects.None, 0); + + } + + // Head drawing. + spriteBatch.Draw(headTexture, drawPosition, null, baseColor * projectile.Opacity, projectile.rotation, headTextureOrigin, projectile.scale, spriteEffects, 0f); + return false; + } + + // Manual collision detection that incorporates segments. + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + if (Collision.CheckAABBvAABBCollision(projectile.position, projHitbox.Size(), targetHitbox.TopLeft(), projHitbox.Size())) + return true; + + for (int i = 0; i < Segments.Length; i++) + { + if (Collision.CheckAABBvAABBCollision(Segments[i].Center - projHitbox.Size() * 0.5f, projHitbox.Size(), targetHitbox.TopLeft(), projHitbox.Size())) + return true; + } + return false; + } + } +} diff --git a/Projectiles/Magic/ApotheosisWorm.png b/Projectiles/Magic/ApotheosisWorm.png new file mode 100644 index 0000000000..31edfc75c7 Binary files /dev/null and b/Projectiles/Magic/ApotheosisWorm.png differ diff --git a/Projectiles/Magic/BeamStar.cs b/Projectiles/Magic/BeamStar.cs new file mode 100644 index 0000000000..08746a6162 --- /dev/null +++ b/Projectiles/Magic/BeamStar.cs @@ -0,0 +1,96 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Magic +{ + public class BeamStar : ModProjectile + { + public ref float Time => ref projectile.ai[0]; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Star"); + ProjectileID.Sets.TrailCacheLength[projectile.type] = 6; + ProjectileID.Sets.TrailingMode[projectile.type] = 0; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 12; + projectile.friendly = true; + projectile.alpha = 255; + projectile.penetrate = 1; + projectile.extraUpdates = 1; + projectile.timeLeft = 240; + projectile.tileCollide = true; + projectile.magic = true; + } + + public override void AI() + { + Time++; + + if (Time < 45f) + projectile.velocity = projectile.velocity.RotatedBy((projectile.identity % 4 - 2) / 2f * 0.016f) * 1.004f; + else + { + NPC potentialTarget = projectile.Center.ClosestNPCAt(800f, false); + if (potentialTarget != null) + { + float destinationDeltaAngle = MathHelper.WrapAngle(projectile.AngleTo(potentialTarget.Center) - projectile.velocity.ToRotation()); + + // If the angle is <0, meaning it's to the left, the sine will return a negative number, + // and a positive number if >0, because WrapAngle constricts to angle to a bound of + // -pi and pi, which are where a sine's wave restarts anew. + float angularHomeDirection = Math.Sign(Math.Sin(destinationDeltaAngle)); + projectile.velocity = projectile.velocity.RotatedBy(angularHomeDirection * 0.03f); + } + } + + if (Main.rand.NextBool(4)) + { + Dust stardust = Dust.NewDustDirect(projectile.position, projectile.width, projectile.height, 180, 0f, 0f, 100, default, 1f); + stardust.position = projectile.Center; + stardust.scale += Main.rand.NextFloat(0.5f); + stardust.noGravity = true; + stardust.velocity.Y -= 2f; + } + if (Main.rand.NextBool(6)) + { + Dust stardust = Dust.NewDustDirect(projectile.position, projectile.width, projectile.height, 176, 0f, 0f, 100, default, 1f); + stardust.position = projectile.Center; + stardust.scale += Main.rand.NextFloat(0.3f, 1.1f); + stardust.noGravity = true; + stardust.velocity *= 0.1f; + } + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Vector2 drawPosition; + Texture2D starTexture = Main.projectileTexture[projectile.type]; + for (int i = 1; i < projectile.oldPos.Length; i++) + { + float scale = projectile.scale * MathHelper.Lerp(0.9f, 0.6f, i / (float)projectile.oldPos.Length) * 0.56f; + drawPosition = projectile.oldPos[i] + projectile.Size * 0.5f - Main.screenPosition; + spriteBatch.Draw(starTexture, drawPosition, null, Color.White, 0f, starTexture.Size() * 0.5f, scale, SpriteEffects.None, 0f); + } + + drawPosition = projectile.Center - Main.screenPosition; + spriteBatch.Draw(starTexture, drawPosition, null, Color.White, 0f, starTexture.Size() * 0.5f, projectile.scale, SpriteEffects.None, 0f); + return false; + } + + public override void Kill(int timeLeft) + { + for (int k = 0; k < 10; k++) + { + Dust.NewDust(projectile.position + projectile.velocity, projectile.width, projectile.height, 176, projectile.oldVelocity.X * 0.5f, projectile.oldVelocity.Y * 0.5f); + Dust.NewDust(projectile.position + projectile.velocity, projectile.width, projectile.height, 180, projectile.oldVelocity.X * 0.5f, projectile.oldVelocity.Y * 0.5f); + } + } + } +} diff --git a/Projectiles/Magic/BeamStar.png b/Projectiles/Magic/BeamStar.png new file mode 100644 index 0000000000..741535f961 Binary files /dev/null and b/Projectiles/Magic/BeamStar.png differ diff --git a/Projectiles/Magic/BloodBolt.cs b/Projectiles/Magic/BloodBolt.cs deleted file mode 100644 index c7efb06d61..0000000000 --- a/Projectiles/Magic/BloodBolt.cs +++ /dev/null @@ -1,40 +0,0 @@ -using CalamityMod.Dusts; -using Microsoft.Xna.Framework; -using Terraria; -using Terraria.ModLoader; -namespace CalamityMod.Projectiles.Magic -{ - public class BloodBolt : ModProjectile - { - public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; - - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Blood Bolt"); - } - - public override void SetDefaults() - { - projectile.width = 4; - projectile.height = 4; - projectile.extraUpdates = 100; - projectile.friendly = true; - projectile.timeLeft = 30; - projectile.magic = true; - projectile.ignoreWater = true; - } - - public override void AI() - { - for (int num447 = 0; num447 < 2; num447++) - { - Vector2 vector33 = projectile.position; - vector33 -= projectile.velocity * ((float)num447 * 0.25f); - int num448 = Dust.NewDust(vector33, 1, 1, (int)CalamityDusts.Brimstone, 0f, 0f, 0, default, 1.25f); - Main.dust[num448].position = vector33; - Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; - Main.dust[num448].velocity *= 0.1f; - } - } - } -} diff --git a/Projectiles/Magic/BloodOrb.cs b/Projectiles/Magic/BloodOrb.cs deleted file mode 100644 index 63fefd6370..0000000000 --- a/Projectiles/Magic/BloodOrb.cs +++ /dev/null @@ -1,30 +0,0 @@ -using Terraria.ModLoader; -namespace CalamityMod.Projectiles.Magic -{ - public class BloodOrb : ModProjectile - { - public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; - - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Blood Orb"); - } - - public override void SetDefaults() - { - projectile.width = 14; - projectile.height = 14; - projectile.friendly = true; - projectile.ignoreWater = true; - projectile.alpha = 255; - projectile.penetrate = -1; - projectile.timeLeft = 30; - projectile.magic = true; - } - - public override void AI() - { - CalamityGlobalProjectile.MagnetSphereHitscan(projectile, 300f, 6f, 24f, 5, ModContent.ProjectileType()); - } - } -} diff --git a/Projectiles/Magic/BloodRay.cs b/Projectiles/Magic/BloodRay.cs index 43b0c0367a..e287b7f77c 100644 --- a/Projectiles/Magic/BloodRay.cs +++ b/Projectiles/Magic/BloodRay.cs @@ -1,13 +1,18 @@ using CalamityMod.Dusts; using Microsoft.Xna.Framework; +using System; using Terraria; using Terraria.ModLoader; namespace CalamityMod.Projectiles.Magic { public class BloodRay : ModProjectile { + public const int Lifetime = 150; + public const float MaxExponentialDamageBoost = 4f; + public static readonly float ExponentialDamageBoost = (float)Math.Pow(MaxExponentialDamageBoost, 1f / Lifetime); + public ref float Time => ref projectile.ai[0]; + public ref float InitialDamage => ref projectile.ai[1]; public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; - public override void SetStaticDefaults() { DisplayName.SetDefault("Blood Ray"); @@ -22,29 +27,33 @@ namespace CalamityMod.Projectiles.Magic projectile.ignoreWater = true; projectile.penetrate = 10; projectile.extraUpdates = 100; - projectile.timeLeft = 150; + projectile.timeLeft = Lifetime; } public override void AI() { - projectile.localAI[1] += 1f; - if (projectile.localAI[1] >= 29f && projectile.owner == Main.myPlayer) - { - projectile.localAI[1] = 0f; - Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, 0f, 0f, ModContent.ProjectileType(), (int)(projectile.damage * 0.6), projectile.knockBack, projectile.owner, 0f, 0f); - } + // Just doing damage = (int)(damage * scalar) wouldn't work here. + // The exponential base would be too small for a weapon like this, and the + // cast (which removes the fractional part) would overtake any increases before the damage can rise. + if (InitialDamage == 0f) + { + InitialDamage = projectile.damage; + projectile.netUpdate = true; + } - projectile.localAI[0] += 1f; - if (projectile.localAI[0] > 9f) + Time++; + projectile.damage = (int)(InitialDamage * Math.Pow(ExponentialDamageBoost, Time)); + + if (Time >= 12f) { - for (int num447 = 0; num447 < 2; num447++) + for (int i = 0; i < 2; i++) { - Vector2 vector33 = projectile.position; - vector33 -= projectile.velocity * ((float)num447 * 0.25f); - int num448 = Dust.NewDust(vector33, 1, 1, (int)CalamityDusts.Brimstone, 0f, 0f, 0, default, 1.5f); - Main.dust[num448].position = vector33; - Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; - Main.dust[num448].velocity *= 0.1f; + int dustType = Main.rand.NextBool(4) ? 182 : (int)CalamityDusts.Brimstone; + Vector2 dustSpawnPos = projectile.position - projectile.velocity * i / 2f; + Dust crimtameMagic = Dust.NewDustPerfect(dustSpawnPos, dustType); + crimtameMagic.scale = Main.rand.NextFloat(0.96f, 1.04f) * MathHelper.Lerp(1f, 1.7f, Time / Lifetime); + crimtameMagic.noGravity = true; + crimtameMagic.velocity *= 0.1f; } } } diff --git a/Projectiles/Magic/DarkSparkPrism.cs b/Projectiles/Magic/DarkSparkPrism.cs index 0fde8c1dfa..009b32ccca 100644 --- a/Projectiles/Magic/DarkSparkPrism.cs +++ b/Projectiles/Magic/DarkSparkPrism.cs @@ -125,7 +125,7 @@ namespace CalamityMod.Projectiles.Magic if (flag10 && Main.myPlayer == projectile.owner) { - bool flag11 = !flag9 || player.CheckMana(player.ActiveItem().mana, true, false); + bool flag11 = !flag9 || player.CheckMana(player.ActiveItem(), -1, true, false); bool flag12 = player.channel && flag11 && !player.noItems && !player.CCed; if (flag12) { diff --git a/Projectiles/Magic/EternityBook.cs b/Projectiles/Magic/EternityBook.cs index 61b77e0ceb..ab373b7042 100644 --- a/Projectiles/Magic/EternityBook.cs +++ b/Projectiles/Magic/EternityBook.cs @@ -44,7 +44,7 @@ namespace CalamityMod.Projectiles.Magic Time++; // Summon a bunch of cool things the moment the book is created, assuming an NPC is near the mouse position. - if (Time == 1f) + if (Main.myPlayer == projectile.owner && Time == 1f) { NPC target = Main.MouseWorld.ClosestNPCAt(4400f, true, true); diff --git a/Projectiles/Magic/EternityCircle.cs b/Projectiles/Magic/EternityCircle.cs index 7fbc1e6174..c88d994190 100644 --- a/Projectiles/Magic/EternityCircle.cs +++ b/Projectiles/Magic/EternityCircle.cs @@ -29,7 +29,7 @@ namespace CalamityMod.Projectiles.Magic get => (int)projectile.localAI[1]; set => projectile.localAI[1] = value; } - public const float TargetOffsetRadius = 595f; + public const float TargetOffsetRadius = 490f; public const float SinusoidalOffsetAngleIncrement = 0.54f; public static readonly float SinusoidalPositionAngleIncrement = MathHelper.ToRadians(3.5f); public override void SetStaticDefaults() diff --git a/Projectiles/Magic/EternityHex.cs b/Projectiles/Magic/EternityHex.cs index 79813a7cbb..91ca33bd9f 100644 --- a/Projectiles/Magic/EternityHex.cs +++ b/Projectiles/Magic/EternityHex.cs @@ -1,7 +1,10 @@ using CalamityMod.Items.Weapons.Magic; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using System; using Terraria; +using Terraria.Graphics.Shaders; +using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Projectiles.Magic @@ -10,6 +13,7 @@ namespace CalamityMod.Projectiles.Magic { public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + internal PrimitiveTrail LemniscateDrawer = null; public int TargetNPCIndex { get => (int)projectile.ai[0]; @@ -36,6 +40,8 @@ namespace CalamityMod.Projectiles.Magic public override void SetStaticDefaults() { DisplayName.SetDefault("Eternity"); + ProjectileID.Sets.TrailingMode[projectile.type] = 2; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 63; } public override void SetDefaults() @@ -46,6 +52,7 @@ namespace CalamityMod.Projectiles.Magic projectile.extraUpdates = 1; projectile.alpha = 255; } + public override void AI() { Player player = Main.player[projectile.owner]; @@ -99,13 +106,16 @@ namespace CalamityMod.Projectiles.Magic for (int i = 0; i < 3; i++) { LemniscateAngle += MathHelper.TwoPi / 200f; - DrawLemniscate(target); + DetermineLemniscatePosition(target); } + if (Time < Lifetime * projectile.MaxUpdates) { float effectRate = MathHelper.Lerp(0.4f, 1f, Time / (Lifetime * projectile.MaxUpdates - 40)); float random = Main.rand.NextFloat(); + projectile.Opacity = Utils.InverseLerp(Lifetime * projectile.MaxUpdates, (Lifetime - 60f) * projectile.MaxUpdates, Time, true); + // Spawn a bunch of swirling dust and do damage. if (random <= effectRate) SpawnSwirlingDust(target); @@ -142,6 +152,7 @@ namespace CalamityMod.Projectiles.Magic projectile.Kill(); } } + public void DeathDust() { for (int i = 0; i < 44; i++) @@ -151,7 +162,8 @@ namespace CalamityMod.Projectiles.Magic dust.noGravity = true; } } - public void DrawLemniscate(NPC target) + + public void DetermineLemniscatePosition(NPC target) { // This value causes the lemniscate to smoothen out and look better. float scale = 2f / (3f - (float)Math.Cos(2 * LemniscateAngle)); @@ -160,16 +172,8 @@ namespace CalamityMod.Projectiles.Magic Vector2 lemniscateOffset = scale * new Vector2((float)Math.Cos(LemniscateAngle), (float)Math.Sin(2f * LemniscateAngle) / 2f); projectile.Center = target.Center + lemniscateOffset * outwardMultiplier; - - // This part isn't actually throughout the projectile's lifetime because of extra updates. - float completionValue = Utils.InverseLerp(0f, Lifetime, Time, true); - Color dustColor = Color.Lerp(new Color(245, 112, 218), new Color(28, 13, 118), completionValue); - - Dust dust = Dust.NewDustDirect(projectile.Center, 0, 0, Eternity.DustID, newColor: dustColor); - dust.velocity = Vector2.Zero; - dust.scale = MathHelper.Lerp(0.8f, 1.5f, completionValue); - dust.noGravity = true; } + public void ChooseNewTarget(NPC newTarget) { TargetNPCIndex = newTarget.whoAmI; @@ -180,7 +184,7 @@ namespace CalamityMod.Projectiles.Magic Projectile proj = Main.projectile[i]; if (!proj.active) continue; - if (proj.whoAmI != projectile.whoAmI) + if (proj.owner != projectile.owner) continue; if (proj.type != ModContent.ProjectileType() && proj.type != ModContent.ProjectileType()) continue; @@ -189,24 +193,55 @@ namespace CalamityMod.Projectiles.Magic DeathDust(); } } + public void SpawnSwirlingDust(NPC target) { - for (int i = 0; i < 12; i++) + for (int i = 0; i < 3; i++) { float randomAngle = Main.rand.NextFloat() * MathHelper.TwoPi; float outwardnessFactor = Main.rand.NextFloat(); Vector2 spawnPosition = target.Center + randomAngle.ToRotationVector2() * MathHelper.Lerp(70f, EternityCircle.TargetOffsetRadius - 60f, outwardnessFactor); Vector2 velocity = (randomAngle - 3f * MathHelper.Pi / 8f).ToRotationVector2() * (10f + 9f * Main.rand.NextFloat() + 4f * outwardnessFactor); - Dust swirlingDust = Dust.NewDustPerfect(spawnPosition, Eternity.DustID, new Vector2?(velocity), 0, Main.rand.NextBool(3) ? Eternity.BlueColor : Eternity.PinkColor, 1.4f); - swirlingDust.scale = 0.8f; - swirlingDust.fadeIn = 0.95f + outwardnessFactor * 0.3f; + Dust swirlingDust = Dust.NewDustPerfect(spawnPosition, 267, new Vector2?(velocity), 0, Main.rand.NextBool(3) ? Eternity.BlueColor : Eternity.PinkColor, 1.4f); + swirlingDust.scale = 1.2f; + swirlingDust.fadeIn = 0.25f + outwardnessFactor * 0.1f; swirlingDust.noGravity = true; } } + // So that the player can gauge the DPS of this weapon effectively (StrikeNPC alone will not register the DPS to the player. I have to do this myself). public void RegisterDPS(int damage) { Main.player[projectile.owner].addDPS(damage); } - } -} \ No newline at end of file + + public Color PrimitiveColorFunction(float completionRatio) + { + float leftoverTimeScale = (float)Math.Sin(Main.GlobalTime * 4f) * 0.5f + 0.5f; + leftoverTimeScale *= 0.5f; + + Color headColor = Color.Lerp(Color.Black, Color.Magenta, 0.1f); + Color tailColor = Color.Lerp(Color.Magenta, Color.Cyan, completionRatio * 0.5f + leftoverTimeScale); + float opacity = (float)Math.Pow(Utils.InverseLerp(1f, 0.61f, completionRatio, true), 0.4) * projectile.Opacity; + float fadeToMagenta = MathHelper.SmoothStep(0f, 1f, (float)Math.Pow(completionRatio, 0.6D)); + + return Color.Lerp(headColor, tailColor, fadeToMagenta) * opacity; + } + + public float PrimitiveWidthFunction(float completionRatio) + { + float widthInterpolant = Utils.InverseLerp(0f, 0.12f, completionRatio, true); + return MathHelper.SmoothStep(1f, 10f, widthInterpolant); + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + if (LemniscateDrawer is null) + LemniscateDrawer = new PrimitiveTrail(PrimitiveWidthFunction, PrimitiveColorFunction, null, GameShaders.Misc["CalamityMod:TrailStreak"]); + + GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.GetTexture("CalamityMod/ExtraTextures/EternityStreak")); + LemniscateDrawer.Draw(projectile.oldPos, projectile.Size * 0.5f - Main.screenPosition, 84); + return false; + } + } +} diff --git a/Projectiles/Magic/EternityHoming.cs b/Projectiles/Magic/EternityHoming.cs index a208ef02a9..3863480df1 100644 --- a/Projectiles/Magic/EternityHoming.cs +++ b/Projectiles/Magic/EternityHoming.cs @@ -29,36 +29,26 @@ namespace CalamityMod.Projectiles.Magic public override void AI() { - NPC target = null; - float distance = 4400f; - for (int index = 0; index < Main.npc.Length; index++) - { - if (Main.npc[index].CanBeChasedBy(null, false)) - { - if (Main.npc[index].boss && Vector2.Distance(projectile.Center, Main.npc[index].Center) <= 4400f) - { - target = Main.npc[index]; - break; - } - if (Vector2.Distance(projectile.Center, Main.npc[index].Center) < distance) - { - distance = Vector2.Distance(projectile.Center, Main.npc[index].Center); - target = Main.npc[index]; - } - } - } + NPC target = projectile.Center.ClosestNPCAt(3000f); if (target != null) projectile.velocity = (projectile.velocity * 7f + projectile.SafeDirectionTo(target.Center) * 10f) / 8f; projectile.ai[0] += 0.18f; float angle = projectile.velocity.ToRotation() + MathHelper.PiOver2; float pulse = (float)Math.Sin(projectile.ai[0]); - float radius = 10f; + float radius = 4f; Vector2 offset = angle.ToRotationVector2() * pulse * radius; - Dust dust = Dust.NewDustPerfect(projectile.Center + offset, Eternity.DustID, Vector2.Zero, 0, Eternity.BlueColor); + + Dust dust = Dust.NewDustPerfect(projectile.Center + offset, 264, Vector2.Zero); + dust.color = Eternity.BlueColor; + dust.scale = 1.4f; + dust.noLight = true; dust.noGravity = true; - dust = Dust.NewDustPerfect(projectile.Center - offset, Eternity.DustID, Vector2.Zero, 0, Eternity.BlueColor); + dust = Dust.NewDustPerfect(projectile.Center - offset, 264, Vector2.Zero); + dust.color = Eternity.PinkColor; + dust.scale = 1.4f; + dust.noLight = true; dust.noGravity = true; } } diff --git a/Projectiles/Magic/FabBolt.cs b/Projectiles/Magic/FabBolt.cs index 0851b4b137..99420e8491 100644 --- a/Projectiles/Magic/FabBolt.cs +++ b/Projectiles/Magic/FabBolt.cs @@ -1,41 +1,114 @@ using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using System.Linq; using Terraria; +using Terraria.Graphics.Shaders; +using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Projectiles.Magic { public class FabBolt : ModProjectile { + internal PrimitiveTrail TrailDrawer; public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + public bool FadingOut + { + get => projectile.ai[0] == 1f; + set => projectile.ai[0] = value.ToInt(); + } + public override void SetStaticDefaults() { DisplayName.SetDefault("Bolt"); + ProjectileID.Sets.TrailingMode[projectile.type] = 2; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 23; } public override void SetDefaults() { projectile.width = 4; projectile.height = 4; - projectile.extraUpdates = 100; projectile.friendly = true; - projectile.timeLeft = 45; + projectile.extraUpdates = 2; + projectile.penetrate = 12; + projectile.timeLeft = 90 * projectile.extraUpdates; projectile.magic = true; - projectile.ignoreWater = true; - } + projectile.ignoreWater = true; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 0; + } public override void AI() { - if (projectile.timeLeft % 2f == 0f) + if (FadingOut) + { + projectile.Opacity = MathHelper.Lerp(projectile.Opacity, 0f, 0.27f); + if (projectile.Opacity <= 0.05f) + projectile.Kill(); + } + else + projectile.velocity *= 1.004f; + projectile.rotation = projectile.velocity.ToRotation(); + + // Emit light. + Lighting.AddLight(projectile.Center, Vector3.One * projectile.Opacity * 0.45f); + } + + internal Color ColorFunction(float completionRatio) + { + float fadeToEnd = MathHelper.Lerp(0.25f, 0.5f, (float)Math.Cos(-Main.GlobalTime * 3f) * 0.5f + 0.5f); + fadeToEnd *= 1f - Utils.InverseLerp(0.35f, 0f, completionRatio, true); + Color endColor = Color.Lerp(Color.Cyan, Color.HotPink, projectile.identity % 2); + return Color.Lerp(Color.White, endColor, fadeToEnd) * projectile.Opacity * 0.7f; + } + + internal float WidthFunction(float completionRatio) + { + float expansionCompletion = 1f - (float)Math.Pow(1f - Utils.InverseLerp(0f, 0.2f, completionRatio, true), 2D); + return MathHelper.Lerp(0f, 22f, expansionCompletion) * projectile.Opacity; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + if (TrailDrawer is null) + TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, PrimitiveTrail.RigidPointRetreivalFunction, GameShaders.Misc["CalamityMod:TrailStreak"]); + + GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.GetTexture("CalamityMod/ExtraTextures/FabstaffStreak")); + TrailDrawer.Draw(projectile.oldPos, projectile.Size * 0.5f - Main.screenPosition, 120, projectile.oldRot); + return false; + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + if (!FadingOut && projectile.penetrate < 2) { - Vector2 vector33 = projectile.position; - vector33 -= projectile.velocity * 0.25f; - int num448 = Dust.NewDust(vector33, 1, 1, 234, 0f, 0f, 0, default, 1.25f); - Main.dust[num448].position = vector33; - Main.dust[num448].noGravity = true; - Main.dust[num448].noLight = true; - Main.dust[num448].scale = Main.rand.Next(70, 110) * 0.013f; - Main.dust[num448].velocity *= 0.1f; - } + FadingOut = true; + projectile.velocity *= 0.1f; + projectile.extraUpdates = 0; + projectile.netUpdate = true; + } } - } + + public override bool OnTileCollide(Vector2 oldVelocity) + { + if (!FadingOut) + { + FadingOut = true; + projectile.velocity *= 0.1f; + projectile.extraUpdates = 0; + projectile.netUpdate = true; + } + return false; + } + + public override bool CanDamage() + { + if (FadingOut) + return false; + return base.CanDamage(); + } + } } diff --git a/Projectiles/Magic/FabOrb.cs b/Projectiles/Magic/FabOrb.cs deleted file mode 100644 index 780da25546..0000000000 --- a/Projectiles/Magic/FabOrb.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Terraria.ModLoader; -namespace CalamityMod.Projectiles.Magic -{ - public class FabOrb : ModProjectile - { - public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; - - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Orb"); - } - - public override void SetDefaults() - { - projectile.width = 14; - projectile.height = 14; - projectile.friendly = true; - projectile.ignoreWater = true; - projectile.alpha = 255; - projectile.penetrate = -1; - projectile.timeLeft = 30; - projectile.magic = true; - projectile.usesLocalNPCImmunity = true; - projectile.localNPCHitCooldown = 10; - } - - public override void AI() - { - CalamityGlobalProjectile.MagnetSphereHitscan(projectile, 150f, 6f, 6f, 2, ModContent.ProjectileType(), 1D, true); - } - } -} diff --git a/Projectiles/Magic/FabRay.cs b/Projectiles/Magic/FabRay.cs index c3f3b11e0c..137015fad6 100644 --- a/Projectiles/Magic/FabRay.cs +++ b/Projectiles/Magic/FabRay.cs @@ -1,15 +1,22 @@ using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; using Terraria; +using Terraria.Graphics.Shaders; +using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Projectiles.Magic { public class FabRay : ModProjectile { + internal PrimitiveTrail TrailDrawer; public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; public override void SetStaticDefaults() { DisplayName.SetDefault("Ray"); + ProjectileID.Sets.TrailCacheLength[projectile.type] = 54; + ProjectileID.Sets.TrailingMode[projectile.type] = 2; } public override void SetDefaults() @@ -18,10 +25,10 @@ namespace CalamityMod.Projectiles.Magic projectile.height = 4; projectile.friendly = true; projectile.magic = true; - projectile.ignoreWater = true; - projectile.penetrate = 20; - projectile.extraUpdates = 100; - projectile.timeLeft = 600; + projectile.ignoreWater = true; + projectile.penetrate = 70; + projectile.extraUpdates = 3; + projectile.timeLeft = 60 * projectile.extraUpdates; projectile.usesLocalNPCImmunity = true; projectile.localNPCHitCooldown = 10; } @@ -30,24 +37,59 @@ namespace CalamityMod.Projectiles.Magic { Lighting.AddLight(projectile.Center, 0.2f, 0.01f, 0.1f); projectile.ai[0] += 1f; - if (projectile.ai[0] % 6f == 0f && projectile.owner == Main.myPlayer) + projectile.Opacity = Utils.InverseLerp(0f, 10f * projectile.MaxUpdates, projectile.timeLeft, true); + + int shootRate = projectile.npcProj ? 40 : 12; + if (projectile.owner == Main.myPlayer && projectile.ai[0] % shootRate == 0f) { - Projectile.NewProjectile(projectile.Center, Vector2.Zero, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); + NPC potentialTarget = projectile.Center.ClosestNPCAt(180f, false); + if (potentialTarget != null) + { + Vector2 shootVelocity = projectile.SafeDirectionTo(potentialTarget.Center) * 13f; + Projectile.NewProjectile(projectile.Center - shootVelocity * 2.5f, shootVelocity, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner); + } + + for (int i = 0; i < projectile.oldPos.Length / 4; i += 3) + { + potentialTarget = projectile.oldPos[i].ClosestNPCAt(280f, false); + if (potentialTarget != null) + { + Vector2 shootVelocity = (potentialTarget.Center - projectile.oldPos[i]).SafeNormalize(Vector2.UnitY) * 13f; + Projectile.NewProjectile(projectile.oldPos[i] - shootVelocity * 2.5f, shootVelocity, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner); + break; + } + } } - if (projectile.ai[0] > 16f && projectile.ai[0] % 2f == 0f) - { - Vector2 source = projectile.position; - int pink = Dust.NewDust(source, 1, 1, 234, 0f, 0f, 0, default, 1.25f); - Main.dust[pink].noGravity = true; - Main.dust[pink].noLight = true; - Main.dust[pink].position = source; - Main.dust[pink].scale = Main.rand.Next(70, 110) * 0.013f; - Main.dust[pink].velocity *= 0.1f; - } + // Emit light. + Lighting.AddLight(projectile.Center, Vector3.One * projectile.Opacity * 0.7f); } - public override bool OnTileCollide(Vector2 oldVelocity) + internal Color ColorFunction(float completionRatio) + { + float fadeToEnd = MathHelper.Lerp(0.65f, 1f, (float)Math.Cos(-Main.GlobalTime * 3f) * 0.5f + 0.5f); + float fadeOpacity = Utils.InverseLerp(1f, 0.64f, completionRatio, true) * projectile.Opacity; + Color endColor = Color.Lerp(Color.Cyan, Color.HotPink, (float)Math.Sin(completionRatio * MathHelper.Pi * 1.6f - Main.GlobalTime * 4f) * 0.5f + 0.5f); + return Color.Lerp(Color.White, endColor, fadeToEnd) * fadeOpacity; + } + + internal float WidthFunction(float completionRatio) + { + float expansionCompletion = 1f - (float)Math.Pow(1f - Utils.InverseLerp(0f, 0.3f, completionRatio, true), 2D); + return MathHelper.Lerp(0f, 32f * projectile.Opacity, expansionCompletion); + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + if (TrailDrawer is null) + TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]); + + GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.GetTexture("CalamityMod/ExtraTextures/ScarletDevilStreak")); + TrailDrawer.Draw(projectile.oldPos, projectile.Size * 0.5f - Main.screenPosition, 76); + return false; + } + + public override bool OnTileCollide(Vector2 oldVelocity) { projectile.penetrate--; if (projectile.penetrate <= 0) diff --git a/Projectiles/Magic/HeresyProj.cs b/Projectiles/Magic/HeresyProj.cs new file mode 100644 index 0000000000..89a71ba3fd --- /dev/null +++ b/Projectiles/Magic/HeresyProj.cs @@ -0,0 +1,130 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.Utilities; + +namespace CalamityMod.Projectiles.Magic +{ + public class HeresyProj : ModProjectile + { + public Player Owner => Main.player[projectile.owner]; + public float ShootIntensity => MathHelper.SmoothStep(0f, 1f, Utils.InverseLerp(0f, 275f, Time, true)); + public ref float Time => ref projectile.ai[0]; + public ref float AttackTimer => ref projectile.ai[1]; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Heresy"); + Main.projFrames[projectile.type] = 8; + } + + public override void SetDefaults() + { + projectile.width = 26; + projectile.height = 32; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.tileCollide = false; + projectile.magic = true; + projectile.ignoreWater = true; + } + + public override void AI() + { + projectile.Center = Owner.Center + Vector2.UnitX * Owner.direction * 18f; + + // If the player is no longer able to hold the book, kill it. + if (!Owner.channel || Owner.noItems || Owner.CCed) + { + projectile.Kill(); + return; + } + + if (AttackTimer >= Main.rand.Next(20, 28) - (int)MathHelper.Lerp(0f, 16f, Utils.InverseLerp(0f, 120f, Time, true))) + ReleaseThings(); + + // Switch frames at a linearly increasing rate to make it look like the player is flipping pages quickly. + projectile.frameCounter++; + if (projectile.frameCounter >= (int)MathHelper.Lerp(10f, 2f, Utils.InverseLerp(0f, 180f, Time, true))) + { + projectile.frame = (projectile.frame + 1) % Main.projFrames[projectile.type]; + projectile.frameCounter = 0; + } + + AdjustPlayerValues(); + projectile.timeLeft = 2; + AttackTimer++; + Time++; + } + + public void ReleaseThings() + { + Main.PlaySound(SoundID.DD2_EtherianPortalSpawnEnemy); + if (Main.myPlayer != projectile.owner) + return; + + // If the owner has sufficient mana, consume it. + // Otherwise, delete the book and don't bother summoning anything. + if (!Owner.CheckMana(Owner.ActiveItem().mana, true, false)) + { + projectile.Kill(); + return; + } + WeightedRandom typeDecider = new WeightedRandom(); + + typeDecider.Add(ModContent.ProjectileType(), 1.5f); + + // Make souls appear more frequently (aka with a higher weight) the more "intense" the shots should be. + typeDecider.Add(ModContent.ProjectileType(), ShootIntensity * 0.75f); + typeDecider.Add(ModContent.ProjectileType(), ShootIntensity * 0.4f); + typeDecider.Add(ModContent.ProjectileType(), ShootIntensity * 0.2f); + + Vector2 spawnPosition = projectile.Top + Main.rand.NextVector2CircularEdge(4f, 4f); + Vector2 shootVelocity = -Vector2.UnitY.RotatedBy(Main.rand.NextFloat(-0.13f, 0.23f) * Owner.direction) * Owner.gravDir; + shootVelocity *= Main.rand.NextFloat(5f, 8); + + if (Owner.velocity.Y < 0f) + shootVelocity.Y += Owner.velocity.Y; + + Projectile.NewProjectile(spawnPosition, shootVelocity, typeDecider.Get(), projectile.damage, projectile.knockBack, projectile.owner, ShootIntensity); + + AttackTimer = 0f; + projectile.netUpdate = true; + } + + public void AdjustPlayerValues() + { + projectile.spriteDirection = projectile.direction = Owner.direction; + Owner.heldProj = projectile.whoAmI; + Owner.itemTime = 2; + Owner.itemAnimation = 2; + Owner.itemRotation = (projectile.direction * projectile.velocity).ToRotation(); + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + float glowOutwardness = MathHelper.SmoothStep(0f, 4f, Utils.InverseLerp(90f, 270f, Time, true)); + Texture2D bookTexture = Main.projectileTexture[projectile.type]; + Rectangle frame = bookTexture.Frame(1, Main.projFrames[projectile.type], 0, projectile.frame); + Vector2 drawPosition; + Vector2 origin = frame.Size() * 0.5f; + Color glowColor = Color.Lerp(Color.Pink, Color.Red, (float)Math.Cos(Main.GlobalTime * 5f) * 0.5f + 0.5f); + glowColor.A = 0; + + // Draw an ominous glowing version of the book after a bit of time. + for (int i = 0; i < 8; i++) + { + drawPosition = projectile.Center + (MathHelper.TwoPi * i / 8f + Main.GlobalTime * 4f).ToRotationVector2() * glowOutwardness - Main.screenPosition; + spriteBatch.Draw(bookTexture, drawPosition, frame, projectile.GetAlpha(glowColor), projectile.rotation, origin, projectile.scale, SpriteEffects.None, 0f); + } + + drawPosition = projectile.Center - Main.screenPosition; + spriteBatch.Draw(bookTexture, drawPosition, frame, projectile.GetAlpha(lightColor), projectile.rotation, origin, projectile.scale, SpriteEffects.None, 0f); + return false; + } + + public override bool CanDamage() => false; + } +} diff --git a/Projectiles/Magic/HeresyProj.png b/Projectiles/Magic/HeresyProj.png new file mode 100644 index 0000000000..ca66b0eb6f Binary files /dev/null and b/Projectiles/Magic/HeresyProj.png differ diff --git a/Projectiles/Magic/ManaMonster.cs b/Projectiles/Magic/ManaMonster.cs new file mode 100644 index 0000000000..934b90e21c --- /dev/null +++ b/Projectiles/Magic/ManaMonster.cs @@ -0,0 +1,106 @@ +using CalamityMod.Dusts; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Magic +{ + public class ManaMonster : ModProjectile + { + public ref float Time => ref projectile.ai[0]; + public Player Target => Main.player[projectile.owner]; + public const int NPCAttackTime = 50; + public const int PlayerAttackRedirectTime = 45; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Monster"); + ProjectileID.Sets.TrailCacheLength[projectile.type] = 3; + ProjectileID.Sets.TrailingMode[projectile.type] = 2; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 52; + projectile.friendly = true; + projectile.hostile = true; + projectile.tileCollide = false; + projectile.ignoreWater = true; + projectile.penetrate = -1; + projectile.timeLeft = 300; + projectile.Opacity = 0f; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 5; + projectile.magic = true; + } + + public override void AI() + { + if (Time < NPCAttackTime) + { + projectile.Opacity = Utils.InverseLerp(0f, 30f, Time, true); + if (projectile.velocity.Length() < 27f) + projectile.velocity *= 1.05f; + } + else + { + // Make an alert sound to indicate that the monster has become enraged and will now attack its caster. + if (Time == NPCAttackTime) + { + int ambientNoiseID = Main.rand.Next(39, 41 + 1); + Main.PlaySound(SoundID.Zombie, Target.Center, ambientNoiseID); + Main.PlaySound(SoundID.DD2_DrakinShot, Target.Center); + CreateTransitionBurstDust(); + } + + if (Time < NPCAttackTime + PlayerAttackRedirectTime) + { + float idealMovementDirection = projectile.AngleTo(Target.Center); + float angularTurnSpeed = 0.09f; + float newSpeed = MathHelper.Lerp(projectile.velocity.Length(), 22f, 0.1f); + projectile.velocity = projectile.velocity.ToRotation().AngleTowards(idealMovementDirection, angularTurnSpeed).ToRotationVector2() * newSpeed; + } + else if (projectile.velocity.Length() < 35f) + projectile.velocity *= 1.04f; + + // Fade out. + projectile.Opacity = Utils.InverseLerp(0f, 15f, projectile.timeLeft, true); + } + + projectile.rotation = projectile.velocity.ToRotation() - MathHelper.PiOver2; + Time++; + } + + public void CreateTransitionBurstDust() + { + if (Main.dedServ) + return; + + for (int i = 0; i < 75; i++) + { + Dust brimstone = Dust.NewDustPerfect(projectile.Center + Main.rand.NextVector2Square(-25f, 25f), (int)CalamityDusts.Brimstone); + brimstone.velocity = Main.rand.NextVector2Unit() * Main.rand.NextFloat(2f, 3.1f) * MathHelper.Lerp(1f, 2.175f, i / 75f); + brimstone.velocity = Vector2.Lerp(brimstone.velocity, -Vector2.UnitY * brimstone.velocity.Length(), 0.5f); + brimstone.scale = MathHelper.Lerp(1f, 1.875f, i / 75f) * Main.rand.NextFloat(0.8f, 1f); + brimstone.fadeIn = 0.4f; + brimstone.noGravity = true; + } + } + + public override void ModifyHitPlayer(Player target, ref int damage, ref bool crit) + { + // Ensure damage is not absolutely obscene when hitting players. + damage = Main.rand.Next(150, 225); + } + + public override bool CanDamage() => projectile.Opacity >= 1f; + + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + CalamityUtils.DrawAfterimagesCentered(projectile, ProjectileID.Sets.TrailingMode[projectile.type], lightColor, 1); + return false; + } + } +} diff --git a/Projectiles/Magic/ManaMonster.png b/Projectiles/Magic/ManaMonster.png new file mode 100644 index 0000000000..9b98b7bad0 Binary files /dev/null and b/Projectiles/Magic/ManaMonster.png differ diff --git a/Projectiles/Magic/NebulaElementalBeam.cs b/Projectiles/Magic/NebulaElementalBeam.cs new file mode 100644 index 0000000000..86b396809b --- /dev/null +++ b/Projectiles/Magic/NebulaElementalBeam.cs @@ -0,0 +1,66 @@ +using CalamityMod.Projectiles.BaseProjectiles; +using CalamityMod.Projectiles.Typeless; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Magic +{ + public class NebulaElementalBeam : BaseLaserbeamProjectile + { + public override float MaxScale => 1.4f; + public override float MaxLaserLength => 1000f; + public override float Lifetime => 30f; + public override Color LightCastColor => Color.White; + public override Texture2D LaserBeginTexture => ModContent.GetTexture("CalamityMod/ExtraTextures/Lasers/UltimaRayStart"); + public override Texture2D LaserMiddleTexture => ModContent.GetTexture("CalamityMod/ExtraTextures/Lasers/UltimaRayMid"); + public override Texture2D LaserEndTexture => ModContent.GetTexture("CalamityMod/ExtraTextures/Lasers/UltimaRayEnd"); + + public const float UniversalAngularSpeed = MathHelper.Pi / 400f; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Beam"); + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 20; + projectile.friendly = true; + projectile.magic = true; + projectile.penetrate = 10; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 13; + projectile.tileCollide = false; + projectile.timeLeft = (int)Lifetime; + } + + public override void ExtraBehavior() + { + RotationalSpeed = UniversalAngularSpeed; + // Generate a burst of bubble-like nebula dust. + if (!Main.dedServ && Time == 5f) + { + int totalBubbles = 24; + for (int i = 0; i < totalBubbles; i++) + { + Dust nebulaBubble = Dust.NewDustPerfect(projectile.Center, 242); + nebulaBubble.velocity = Main.rand.NextVector2Circular(6f, 6f); + nebulaBubble.scale = Main.rand.NextFloat(2f, 3f); + nebulaBubble.noGravity = true; + } + } + } + + public override void DetermineScale() => projectile.scale = projectile.timeLeft / Lifetime * MaxScale; + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + DrawBeamWithColor(spriteBatch, new Color(190, 29, 209), projectile.scale); + DrawBeamWithColor(spriteBatch, Color.Lerp(new Color(254, 126, 229), Color.Transparent, 0.35f), projectile.scale * 0.6f); + DrawBeamWithColor(spriteBatch, Color.Lerp(new Color(254, 190, 243), Color.Transparent, 0.35f), projectile.scale * 0.6f); + return false; + } + } +} diff --git a/Projectiles/Magic/NebulaElementalBeam.png b/Projectiles/Magic/NebulaElementalBeam.png new file mode 100644 index 0000000000..15e8775737 Binary files /dev/null and b/Projectiles/Magic/NebulaElementalBeam.png differ diff --git a/Projectiles/Magic/NightBolt.cs b/Projectiles/Magic/NightBolt.cs index f685be4ff5..b55dd36601 100644 --- a/Projectiles/Magic/NightBolt.cs +++ b/Projectiles/Magic/NightBolt.cs @@ -16,7 +16,7 @@ namespace CalamityMod.Projectiles.Magic { projectile.width = 4; projectile.height = 4; - projectile.extraUpdates = 100; + projectile.extraUpdates = 20; projectile.friendly = true; projectile.timeLeft = 30; projectile.magic = true; diff --git a/Projectiles/Magic/NightsRayBeam.cs b/Projectiles/Magic/NightsRayBeam.cs index 5e9eaa69cb..b9ca198c46 100644 --- a/Projectiles/Magic/NightsRayBeam.cs +++ b/Projectiles/Magic/NightsRayBeam.cs @@ -5,8 +5,13 @@ namespace CalamityMod.Projectiles.Magic { public class NightsRayBeam : ModProjectile { + public ref float Time => ref projectile.ai[0]; + public bool HasFiredSideBeams + { + get => projectile.ai[1] == 1f; + set => projectile.ai[1] = value.ToInt(); + } public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; - public override void SetStaticDefaults() { DisplayName.SetDefault("Ray"); @@ -26,24 +31,33 @@ namespace CalamityMod.Projectiles.Magic public override void AI() { - projectile.localAI[1] += 1f; - if (projectile.localAI[1] >= 29f && projectile.owner == Main.myPlayer) + if (!HasFiredSideBeams && projectile.owner == Main.myPlayer) { - projectile.localAI[1] = 0f; - Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, 0f, 0f, ModContent.ProjectileType(), (int)(projectile.damage * 0.6), projectile.knockBack, projectile.owner, 0f, 0f); + NPC potentialTarget = projectile.Center.ClosestNPCAt(5480f, false); + if (potentialTarget != null) + { + Vector2 baseSpawnPositionOffset = Main.rand.NextVector2CircularEdge(40f, 40f); + for (int i = 0; i < 4; i++) + { + Vector2 spawnPosition = potentialTarget.Center + baseSpawnPositionOffset.RotatedBy(MathHelper.TwoPi * i / 4f); + Projectile.NewProjectile(spawnPosition, Vector2.Zero, ModContent.ProjectileType(), (int)(projectile.damage * 0.8), projectile.knockBack, projectile.owner); + } + HasFiredSideBeams = true; + projectile.netUpdate = true; + } } - projectile.localAI[0] += 1f; - if (projectile.localAI[0] > 9f) + Time++; + if (Time >= 10f) { - for (int num447 = 0; num447 < 3; num447++) + for (int i = 0; i < 2; i++) { - Vector2 vector33 = projectile.position; - vector33 -= projectile.velocity * ((float)num447 * 0.25f); - int num448 = Dust.NewDust(vector33, 1, 1, 27, 0f, 0f, 0, default, 1.25f); - Main.dust[num448].position = vector33; - Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; - Main.dust[num448].velocity *= 0.1f; + Vector2 dustSpawnPos = projectile.position - projectile.velocity * i / 2f; + Dust corruptMagic = Dust.NewDustPerfect(dustSpawnPos, 27); + corruptMagic.color = Color.Lerp(Color.Fuchsia, Color.Magenta, Main.rand.NextFloat(0.6f)); + corruptMagic.scale = Main.rand.NextFloat(0.96f, 1.04f); + corruptMagic.noGravity = true; + corruptMagic.velocity *= 0.1f; } } } diff --git a/Projectiles/Magic/PartySparkle.cs b/Projectiles/Magic/PartySparkle.cs new file mode 100644 index 0000000000..58be299f5d --- /dev/null +++ b/Projectiles/Magic/PartySparkle.cs @@ -0,0 +1,120 @@ +using CalamityMod.Items.Weapons.Magic; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Magic +{ + public class PartySparkle : ModProjectile + { + public float Time + { + get => projectile.ai[0]; + set => projectile.ai[0] = value; + } + public float ColorSpectrumHue + { + get => projectile.ai[1]; + set => projectile.ai[1] = value; + } + public const int Lifetime = 90; + public const int FadeinTime = 18; + public const int FadeoutTime = 18; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Pretty Sparkle"); + } + + public override void SetDefaults() + { + projectile.width = 72; + projectile.height = 72; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.tileCollide = false; + projectile.magic = true; + projectile.timeLeft = Lifetime; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 10; + projectile.scale = 0.001f; + } + + public override void AI() + { + if (Time == 1f) + { + projectile.scale = Main.rand.NextFloat(0.4f, 1.1f); + CalamityGlobalProjectile.ExpandHitboxBy(projectile, (int)(72 * projectile.scale)); + ColorSpectrumHue = Main.rand.NextFloat(0f, 0.9999f); + projectile.netUpdate = true; + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2; + } + Time++; + + projectile.velocity *= 0.96f; + + projectile.rotation = projectile.rotation.AngleLerp(MathHelper.PiOver2, 0.085f); + + ColorSpectrumHue = (ColorSpectrumHue + 0.333f / Lifetime) % 0.999f; // Go 33% across the color spectrum throughout the sparkle's life instead of using a static sprite. + + projectile.Opacity = Utils.InverseLerp(0f, FadeinTime, Time, true) * Utils.InverseLerp(Lifetime, Lifetime - FadeoutTime, Time, true); + projectile.velocity = projectile.velocity.RotatedBy(Math.Sin(Time / 30f) * 0.0125f); + } + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D sparkleTexture = ModContent.GetTexture(Texture); + + Color sparkleColor = CalamityUtils.MulticolorLerp(ColorSpectrumHue, RainbowPartyCannon.ColorSet) * projectile.Opacity * 0.5f; + sparkleColor.A = 0; + + sparkleColor *= MathHelper.Lerp(1f, 1.5f, Utils.InverseLerp(Lifetime * 0.5f - 15f, Lifetime * 0.5f + 15f, Time, true)); + + Color orthogonalsparkleColor = Color.Lerp(sparkleColor, Color.White, 0.5f) * 0.5f; + + Vector2 origin = sparkleTexture.Size() / 2f; + + Vector2 sparkleScale = new Vector2(0.3f, 1f) * projectile.Opacity * projectile.scale; + Vector2 orthogonalsparkleScale = new Vector2(0.3f, 2f) * projectile.Opacity * projectile.scale; + + spriteBatch.Draw(sparkleTexture, + projectile.Center - Main.screenPosition + Vector2.UnitY * projectile.gfxOffY, + null, + sparkleColor, + MathHelper.PiOver2 + projectile.rotation, + origin, + orthogonalsparkleScale, + SpriteEffects.None, + 0f); + spriteBatch.Draw(sparkleTexture, + projectile.Center - Main.screenPosition + Vector2.UnitY * projectile.gfxOffY, + null, + sparkleColor, + projectile.rotation, + origin, + sparkleScale, + SpriteEffects.None, + 0f); + spriteBatch.Draw(sparkleTexture, + projectile.Center - Main.screenPosition + Vector2.UnitY * projectile.gfxOffY, + null, + orthogonalsparkleColor, + MathHelper.PiOver2 + projectile.rotation, + origin, + orthogonalsparkleScale * 0.6f, + SpriteEffects.None, + 0f); + spriteBatch.Draw(sparkleTexture, + projectile.Center - Main.screenPosition + Vector2.UnitY * projectile.gfxOffY, + null, + orthogonalsparkleColor, + projectile.rotation, + origin, + sparkleScale * 0.6f, + SpriteEffects.None, + 0f); + return false; + } + } +} diff --git a/Projectiles/Magic/PartySparkle.png b/Projectiles/Magic/PartySparkle.png new file mode 100644 index 0000000000..0968156e79 Binary files /dev/null and b/Projectiles/Magic/PartySparkle.png differ diff --git a/Projectiles/Magic/PurgeProj.cs b/Projectiles/Magic/PurgeProj.cs index f6357b097f..e0d68f4db5 100644 --- a/Projectiles/Magic/PurgeProj.cs +++ b/Projectiles/Magic/PurgeProj.cs @@ -79,7 +79,7 @@ namespace CalamityMod.Projectiles.Magic if (flag && Main.myPlayer == projectile.owner) { int weaponDamage2 = player.GetWeaponDamage(player.ActiveItem()); - bool flag2 = player.channel && player.CheckMana(player.ActiveItem().mana, true, false) && !player.noItems && !player.CCed; + bool flag2 = player.channel && player.CheckMana(player.ActiveItem(), -1, true, false) && !player.noItems && !player.CCed; if (flag2) { float speed = player.ActiveItem().shootSpeed * projectile.scale; diff --git a/Projectiles/Magic/RainbowComet.cs b/Projectiles/Magic/RainbowComet.cs new file mode 100644 index 0000000000..3e244cfc67 --- /dev/null +++ b/Projectiles/Magic/RainbowComet.cs @@ -0,0 +1,99 @@ +using CalamityMod.Items.Weapons.Magic; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Magic +{ + public class RainbowComet : ModProjectile + { + public ref float Time => ref projectile.ai[0]; + public const float FadeinTime = 40f; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Comet"); + ProjectileID.Sets.TrailingMode[projectile.type] = 0; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 12; + Main.projFrames[projectile.type] = 3; + } + + public override void SetDefaults() + { + projectile.width = 72; + projectile.height = 72; + projectile.friendly = true; + projectile.penetrate = 1; + projectile.magic = true; + projectile.timeLeft = 300; + projectile.usesLocalNPCImmunity = true; + projectile.alpha = 255; + projectile.localNPCHitCooldown = 16; + } + + public override void AI() + { + Time++; + projectile.Opacity = Utils.InverseLerp(0f, 20f, Time, true); + projectile.velocity = projectile.velocity.RotatedBy(Math.Sin(Time / 30f) * 0.0125f); + projectile.rotation = projectile.velocity.ToRotation() - MathHelper.PiOver2; + + projectile.frameCounter++; + if (projectile.frameCounter % 4 == 3) + projectile.frame = (projectile.frame + 1) % Main.projFrames[projectile.type]; + } + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D cometTexture = ModContent.GetTexture(Texture); + spriteBatch.Draw(cometTexture, + projectile.Center + Vector2.UnitY * projectile.gfxOffY - Main.screenPosition, + cometTexture.Frame(1, Main.projFrames[projectile.type], 0, projectile.frame), + Color.White * projectile.Opacity, + projectile.rotation, + cometTexture.Size() * 0.5f, + projectile.scale, + SpriteEffects.None, + 0f); + return false; + } + public override void Kill(int timeLeft) + { + if (projectile.owner == Main.myPlayer) + { + // Generate pretty sparkles. + for (int i = 0; i < 18; i++) + { + Vector2 velocity = Vector2.UnitY.RotatedByRandom(MathHelper.TwoPi) * Main.rand.NextFloat(9f, 20f); + Projectile.NewProjectile(projectile.Center, velocity, ModContent.ProjectileType(), projectile.damage, 1f, projectile.owner); + } + + // And release a bunch of rockets. + for (int i = 0; i < (int)RainbowRocket.PartyCannonExplosionType.Count; i++) + { + Vector2 velocity = -projectile.velocity.SafeNormalize(-Vector2.UnitY); + velocity = velocity.RotatedBy(MathHelper.Lerp(-1.1f, 1.1f, i / (float)(int)RainbowRocket.PartyCannonExplosionType.Count)); + velocity *= Main.rand.NextFloat(7f, 15f); + + Projectile rocket = Projectile.NewProjectileDirect(projectile.Center, velocity, ModContent.ProjectileType(), projectile.damage * 3, 1f, projectile.owner); + rocket.ai[1] = i; + } + } + + if (!Main.dedServ) + { + for (int i = 0; i < 80; i++) + { + Dust dust = Dust.NewDustPerfect(projectile.Center, 263); + dust.color = CalamityUtils.MulticolorLerp((Main.rand.NextFloat(0.4f) + Main.GlobalTime * 0.4f) % 0.999f, RainbowPartyCannon.ColorSet); + dust.scale = Main.rand.NextFloat(0.6f, 0.9f); + dust.velocity = Vector2.UnitY.RotatedByRandom(MathHelper.TwoPi) * Main.rand.NextFloat(12f, 16f); + dust.noGravity = true; + } + + Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Item, "Sounds/Item/LargeWeaponFire").WithVolume(0.45f), projectile.Center); + } + } + } +} diff --git a/Projectiles/Magic/RainbowComet.png b/Projectiles/Magic/RainbowComet.png new file mode 100644 index 0000000000..b713356be9 Binary files /dev/null and b/Projectiles/Magic/RainbowComet.png differ diff --git a/Projectiles/Magic/RainbowPartyCannonProjectile.cs b/Projectiles/Magic/RainbowPartyCannonProjectile.cs new file mode 100644 index 0000000000..da42c6a936 --- /dev/null +++ b/Projectiles/Magic/RainbowPartyCannonProjectile.cs @@ -0,0 +1,108 @@ +using Microsoft.Xna.Framework; +using System; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Magic +{ + public class RainbowPartyCannonProjectile : ModProjectile + { + public Player Owner => Main.player[projectile.owner]; + public ref float Time => ref projectile.ai[0]; + public const float ChargeDelay = 60f; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Party Cannon"); + } + + public override void SetDefaults() + { + projectile.width = 92; + projectile.height = 66; + projectile.penetrate = -1; + projectile.magic = true; + projectile.tileCollide = false; + projectile.ignoreWater = true; + } + + public override void AI() + { + Item heldItem = Owner.ActiveItem(); + projectile.damage = (int)((heldItem?.damage ?? 0) * Owner.MagicDamage()); + + UpdatePlayerVisuals(Owner.Center); + + bool stillUsingCannon = Owner.channel && !Owner.noItems && !Owner.CCed; + if (!stillUsingCannon) + { + projectile.Kill(); + return; + } + + if (Time > ChargeDelay && Time % heldItem.useTime == 0) + { + ConsumeManaAndFireProjectile(heldItem); + } + else if (Time <= ChargeDelay && !Main.dedServ) + { + if (Main.rand.NextBool(3)) + { + Vector2 velocityDirection = projectile.velocity.RotatedByRandom(0.1f); + Vector2 shotOffset = velocityDirection * projectile.Size * 0.5f; + Dust.NewDustPerfect(projectile.Center + shotOffset, Main.rand.Next(139, 143), velocityDirection * Main.rand.NextFloat(5f, 9f)); + } + } + + Time++; + + // Forces the cannon to disappear immediately if anything goes wrong. + projectile.timeLeft = 2; + } + + public void ConsumeManaAndFireProjectile(Item heldItem) + { + if (Owner.whoAmI != Main.myPlayer) + return; + + if (!Owner.CheckMana(heldItem.mana, true)) + { + projectile.Kill(); + return; + } + + Main.PlaySound(heldItem.UseSound, projectile.Center); + Vector2 spawnPosition = projectile.Center + projectile.velocity * 150f; + + // Shoot farther back if the cannon is shoved into a bunch of tiles. + if (!Collision.CanHitLine(Owner.MountedCenter, 16, 16, spawnPosition, 16, 16)) + spawnPosition = projectile.Center + projectile.velocity * 50f; + + Projectile.NewProjectile(spawnPosition, projectile.velocity.SafeNormalize(Vector2.Zero) * heldItem.shootSpeed, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, Owner.whoAmI); + } + + public void UpdatePlayerVisuals(Vector2 center) + { + // Place the cannon directly into the player's hand at all times. + projectile.Center = center; + + // Set the direction of the cannon if it hasn't been set yet. + if (projectile.velocity == Vector2.Zero || projectile.velocity.Length() != 1f) + projectile.velocity = (Main.MouseWorld - center).SafeNormalize(Vector2.UnitX * projectile.direction); + + projectile.rotation = projectile.velocity.ToRotation(); + projectile.direction = projectile.spriteDirection = (Math.Cos(projectile.rotation) > 0).ToDirectionInt(); + + // The cannon is a holdout projectile. Change the player's channel and direction values to reflect this. + Owner.ChangeDir(projectile.direction); + Owner.heldProj = projectile.whoAmI; + Owner.itemTime = 2; + Owner.itemAnimation = 2; + + Owner.itemRotation = (projectile.velocity * projectile.direction).ToRotation(); + if (projectile.spriteDirection == -1) + projectile.rotation += MathHelper.Pi; + } + + public override bool CanDamage() => false; + } +} diff --git a/Projectiles/Magic/RainbowPartyCannonProjectile.png b/Projectiles/Magic/RainbowPartyCannonProjectile.png new file mode 100644 index 0000000000..59c2f21ef9 Binary files /dev/null and b/Projectiles/Magic/RainbowPartyCannonProjectile.png differ diff --git a/Projectiles/Magic/RainbowRocket.cs b/Projectiles/Magic/RainbowRocket.cs new file mode 100644 index 0000000000..6b2b51ff60 --- /dev/null +++ b/Projectiles/Magic/RainbowRocket.cs @@ -0,0 +1,702 @@ +using CalamityMod.DataStructures; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Magic +{ + public class RainbowRocket : ModProjectile + { + public enum PartyCannonExplosionType + { + Pink = 0, + Orange = 1, + Yellow = 2, + White = 3, + SkyBlue = 4, + Purple = 5, + PalePink = 6, + Count = 7 + } + + internal PrimitiveTrail TrailDrawer = null; + public ref float Time => ref projectile.ai[0]; + public PartyCannonExplosionType RocketType + { + get => (PartyCannonExplosionType)(int)projectile.ai[1]; + set => projectile.ai[1] = (int)value; + } + public const float SwerveAngle = 0.02f; + public const float SwerveAngleOffsetMax = 0.04f; + public const float SwerveTime = 60f; + public const float HomingAcceleration = 0.4f; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Rainbow Rocket"); + Main.projFrames[projectile.type] = 3; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 20; + ProjectileID.Sets.TrailingMode[projectile.type] = 2; + } + + public override void SetDefaults() + { + projectile.width = 28; + projectile.height = 52; + + projectile.friendly = true; + projectile.penetrate = 1; + projectile.timeLeft = 180; + projectile.magic = true; + } + + #region AI + public override void AI() + { + Time++; + Lighting.AddLight(projectile.Center, Main.hslToRgb((float)Math.Sin(Time / 20f) * 0.5f + 0.5f, 0.9f, 0.9f).ToVector3()); + + projectile.tileCollide = Time > 60f; + + projectile.frameCounter++; + if (projectile.frameCounter % 4 == 3) + projectile.frame = (projectile.frame + 1) % Main.projFrames[projectile.type]; + + NPC potentialTarget = projectile.Center.ClosestNPCAt(2300f, true, true); + if (Time < SwerveTime) + DoMovement_IdleSwerveFly(); + else if (potentialTarget != null) + DoMovement_FlyToTarget(potentialTarget); + + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2; + } + + private void DoMovement_IdleSwerveFly() + { + float swerveAngleOffset = MathHelper.Lerp(-SwerveAngleOffsetMax, SwerveAngleOffsetMax, (float)RocketType / ((float)PartyCannonExplosionType.Count)); + projectile.velocity = projectile.velocity.RotatedBy(swerveAngleOffset + SwerveAngle); + } + + private void DoMovement_FlyToTarget(NPC target) + { + float angleToTarget = projectile.AngleTo(target.Center); + float angleOffset = MathHelper.WrapAngle(angleToTarget - projectile.velocity.ToRotation()); + projectile.velocity = projectile.velocity.RotatedBy(MathHelper.Clamp(angleOffset, -0.2f, 0.2f)); + projectile.velocity = projectile.velocity.SafeNormalize(-Vector2.UnitY) * (projectile.velocity.Length() + HomingAcceleration); + + if (Vector2.Dot(projectile.velocity.SafeNormalize(Vector2.Zero), projectile.SafeDirectionTo(target.Center)) < 0.75f) + projectile.velocity *= 0.75f; + } + #endregion + + #region Draw Effects + + internal Color GetRocketColor() + { + switch (RocketType) + { + case PartyCannonExplosionType.Pink: + return Color.Pink; + case PartyCannonExplosionType.Orange: + return Color.Orange; + case PartyCannonExplosionType.Yellow: + return Color.LightGoldenrodYellow * 0.8f; + case PartyCannonExplosionType.White: + return Color.LightGray; + case PartyCannonExplosionType.SkyBlue: + return Color.LightSkyBlue; + case PartyCannonExplosionType.Purple: + return Color.Magenta; + case PartyCannonExplosionType.PalePink: + return Color.Pink * 0.77f; + } + return Color.White; + } + + internal Color ColorFunction(float completionRatio) + { + Color baseColor = Main.hslToRgb((projectile.identity * 0.33f + completionRatio + Main.GlobalTime * 2f) % 1f, 1f, 0.54f); + return Color.Lerp(GetRocketColor(), baseColor, MathHelper.Clamp(completionRatio * 0.8f, 0f, 1f)) * projectile.Opacity; + } + + internal float WidthFunction(float completionRatio) + { + float width; + float maxWidthOutwardness = 8f; + if (completionRatio < 0.1f) + width = (float)Math.Sin(completionRatio / 0.1f * MathHelper.PiOver2) * maxWidthOutwardness + 0.1f; + else + width = MathHelper.Lerp(maxWidthOutwardness, 0f, Utils.InverseLerp(0.1f, 1f, completionRatio, true)); + return width * projectile.Opacity; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + if (TrailDrawer is null) + TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction); + + projectile.oldPos[0] = projectile.position + projectile.velocity.SafeNormalize(Vector2.Zero) * 50f; + TrailDrawer.Draw(projectile.oldPos, projectile.Size * 0.5f - Main.screenPosition + projectile.velocity, 80); + + Texture2D rocketTexture = ModContent.GetTexture(Texture); + spriteBatch.Draw(rocketTexture, + projectile.Center - Main.screenPosition, + rocketTexture.Frame(1, Main.projFrames[projectile.type], 0, projectile.frame), + GetRocketColor(), + projectile.rotation, + rocketTexture.Size() * 0.5f, + projectile.scale, + SpriteEffects.None, + 0f); + return false; + } + #endregion + + #region Kill Effects + public override void Kill(int timeLeft) + { + if (projectile.owner == Main.myPlayer) + { + for (int i = 1; i < projectile.oldPos.Length; i++) + { + if (Main.rand.NextBool(3)) + { + float offsetAngle = MathHelper.Lerp(-MathHelper.PiOver4, MathHelper.PiOver4, i / (float)projectile.oldPos.Length); + Vector2 spawnPosition = projectile.oldPos[i] + projectile.Size * 0.5f; + Vector2 spawnVelocity = (projectile.oldPos[i - 1] - projectile.oldPos[i]).SafeNormalize(Vector2.Zero); + spawnVelocity = spawnVelocity.RotatedBy(offsetAngle); + spawnVelocity *= Main.rand.NextFloat(12f, 18f); + Projectile.NewProjectile(spawnPosition, spawnVelocity, ModContent.ProjectileType(), projectile.damage, 2f, projectile.owner); + } + } + } + + CalamityGlobalProjectile.ExpandHitboxBy(projectile, 350); + projectile.Damage(); + + Main.PlaySound(SoundID.Item14, projectile.Center); + + // There's no need to spawn dust from the server. + if (Main.dedServ) + return; + + switch (RocketType) + { + case PartyCannonExplosionType.Pink: + PinkMarkExplosionDust(); + break; + case PartyCannonExplosionType.Orange: + OrangeMarkExplosionDust(); + break; + case PartyCannonExplosionType.Yellow: + YellowMarkExplosionDust(); + break; + case PartyCannonExplosionType.White: + WhiteMarkExplosionDust(); + break; + case PartyCannonExplosionType.SkyBlue: + SkyBlueMarkExplosionDust(); + break; + case PartyCannonExplosionType.Purple: + PurpleMarkExplosionDust(); + break; + case PartyCannonExplosionType.PalePink: + PalePinkMarkExplosionDust(); + break; + } + } + #endregion + + #region Pink Mark + public void PinkMarkExplosionDust() + { + // Spawn the main balloon. + BalloonExplosionDust(projectile.Center, Main.rand.NextFloat(8f, 15f), Color.Yellow); + + // Spawn the two smaller balloons. + float absoluteOffsetAngle = Main.rand.NextFloat(0.4f, 0.7f) * -1f; + Vector2 offset = Vector2.UnitY.RotatedBy(absoluteOffsetAngle) * 120f; + offset += Vector2.UnitX * 40f; + BalloonExplosionDust(projectile.Center + offset, Main.rand.NextFloat(6f, 11f), Color.DeepPink, absoluteOffsetAngle); + + absoluteOffsetAngle = Main.rand.NextFloat(0.4f, 0.7f); + offset = Vector2.UnitY.RotatedBy(absoluteOffsetAngle) * 120f; + offset -= Vector2.UnitX * 40f; + BalloonExplosionDust(projectile.Center + offset, Main.rand.NextFloat(6f, 11f), Color.DeepPink, absoluteOffsetAngle); + } + public void BalloonExplosionDust(Vector2 center, float petalBurstSpeed, Color balloonColor, float absoluteOffsetAngle = 0) + { + float explosionOffsetAngle = Main.rand.NextFloat(-0.3f, 0.3f) + absoluteOffsetAngle; + + // Draw the balloon as a petal. + for (float angle = 0f; angle <= MathHelper.TwoPi; angle += MathHelper.ToRadians(4f)) + { + Vector2 initialUnitVector = angle.ToRotationVector2(); + float unitMultiplier = 2f + (1f + (float)Math.Cos(MathHelper.Pi + angle)); // This value is used to "squash" the circle to make it into a petal shape. + Vector2 velocity = initialUnitVector * unitMultiplier; + velocity.X *= 0.5f; + velocity = velocity.SafeNormalize(Vector2.Zero); // Turn the petal velocity into a unit vector again to make future speed calculations easier. + velocity = velocity.RotatedBy(MathHelper.PiOver2); // Flip the petal velocity. It's tilted to the side normally. + velocity = velocity.RotatedBy(explosionOffsetAngle); // Account for the explosion offset angle that was determined at the start. + + Dust dust = Dust.NewDustPerfect(center, 261); + dust.velocity = velocity * petalBurstSpeed; + dust.noGravity = true; + dust.color = balloonColor; + dust.fadeIn = 1.5f; + } + + // Draw the string below the petal, giving it the appearance of a balloon. + StringExplosionDust(center, petalBurstSpeed, explosionOffsetAngle); + } + public void StringExplosionDust(Vector2 center, float petalBurstSpeed, float offsetAngle) + { + int evaluationPoints = 40; + + // When mapped out, these points give a rough string, which when used with a bezier curve, can be smoothened out to make it look like a real string. + Vector2[] bezierControlPoints = new Vector2[] + { + new Vector2(0f, 40f), + new Vector2(20f, 76f), + new Vector2(-16f, 108f), + new Vector2(-20f, 146f), + new Vector2(-14f, 180f), + new Vector2(10f, 214f) + }; + BezierCurve bezierCurve = new BezierCurve(bezierControlPoints); + for (int i = 0; i < evaluationPoints; i++) + { + Dust dust = Dust.NewDustPerfect(center, 261); + dust.position = center + bezierCurve.Evaluate(i / (float)evaluationPoints).RotatedBy(offsetAngle) + Vector2.UnitY * petalBurstSpeed * 2f; + dust.velocity = Vector2.Zero; + dust.noGravity = true; + dust.color = Color.White; + dust.fadeIn = 1.5f; + } + } + #endregion + + #region Orange Mark + public void OrangeMarkExplosionDust() + { + // Spawn the main apple. + AppleExplosionDust(projectile.Center, Main.rand.NextFloat(8f, 15f)); + + // Spawn two other apples to the side. + float absoluteOffsetAngle = Main.rand.NextFloat(0.4f, 0.7f) * -1f; + Vector2 offset = Vector2.UnitY.RotatedBy(absoluteOffsetAngle) * 120f; + offset += Vector2.UnitX * 70f; + AppleExplosionDust(projectile.Center + offset, Main.rand.NextFloat(6f, 11f), absoluteOffsetAngle); + + absoluteOffsetAngle = Main.rand.NextFloat(0.4f, 0.7f); + offset = Vector2.UnitY.RotatedBy(absoluteOffsetAngle) * 120f; + offset -= Vector2.UnitX * 70f; + AppleExplosionDust(projectile.Center + offset, Main.rand.NextFloat(6f, 11f), absoluteOffsetAngle); + } + public void AppleExplosionDust(Vector2 center, float appleBurstSpeed, float offsetAngle = 0f) + { + for (float angle = 0f; angle <= MathHelper.TwoPi; angle += MathHelper.ToRadians(4f)) + { + Vector2 initialUnitVector = angle.ToRotationVector2(); + float cosineValue = (float)Math.Cos(angle); + + Vector2 velocity = initialUnitVector; + + velocity = velocity.SafeNormalize(Vector2.Zero); // Turn the petal velocity into a unit vector again to make future speed calculations easier. + velocity.X *= 1.333f; + + // Squash the circle to the shape of an apple. + if (Math.Abs(cosineValue) < 0.35f) + { + velocity.Y *= MathHelper.Lerp(0.9f, 1f, Math.Abs(cosineValue) / 0.35f); + + // Squash the upper part slightly more than the lower part. + if (Math.Sign(cosineValue) == 1f) + { + velocity.Y *= 0.85f; + } + } + + velocity = velocity.RotatedBy(offsetAngle); // Account for the explosion offset angle that was determined at the start. + + Dust dust = Dust.NewDustPerfect(center, 261); + dust.velocity = velocity * appleBurstSpeed; + dust.noGravity = true; + dust.color = Color.Orange; + dust.fadeIn = 1.5f; + } + AppleLeafExplosionDust(center + new Vector2(0f, -54).RotatedBy(offsetAngle), offsetAngle); + } + public void AppleLeafExplosionDust(Vector2 center, float offsetAngle) + { + int evaluationPoints = 40; + + // When mapped out, these points give a rough apple stem shape. + Vector2[] bezierControlPoints = new Vector2[] + { + new Vector2(0f, 0f), + new Vector2(-20f, -26f), + new Vector2(-26f, -46f), + new Vector2(-30f, -60f), + new Vector2(-24f, -70f), + new Vector2(-10f, -40f), + new Vector2(0f, 0f), + }; + BezierCurve bezierCurve = new BezierCurve(bezierControlPoints); + for (int i = 0; i < evaluationPoints; i++) + { + Dust dust = Dust.NewDustPerfect(center, 261); + dust.position = center + bezierCurve.Evaluate(i / (float)evaluationPoints).RotatedBy(offsetAngle); + dust.velocity = Vector2.Zero; + dust.noGravity = true; + dust.color = Color.Brown; + dust.fadeIn = 1.5f; + } + } + #endregion + + #region Yellow Mark + public void YellowMarkExplosionDust() + { + // Spawn three butterflies. + ButterflyExplosionDust(projectile.Center, Main.rand.NextFloat(8f, 12f)); + + Vector2 offset = Vector2.UnitY.RotatedBy(Main.rand.NextFloat(0.4f, 0.7f) * -1f) * 120f; + offset += Vector2.UnitX * 84f; + ButterflyExplosionDust(projectile.Center + offset, Main.rand.NextFloat(6f, 11f)); + + offset = Vector2.UnitY.RotatedBy(Main.rand.NextFloat(0.4f, 0.7f)) * 120f; + offset -= Vector2.UnitX * 84f; + ButterflyExplosionDust(projectile.Center + offset, Main.rand.NextFloat(6f, 11f)); + } + public void ButterflyExplosionDust(Vector2 center, float butterflyBurstSpeed, float offsetAngle = 0f) + { + int petalCount = 4; + // Draw the butterfly as a petal with 4 sides. + for (float angle = 0f; angle <= MathHelper.TwoPi; angle += MathHelper.ToRadians(4f)) + { + Vector2 initialUnitVector = angle.ToRotationVector2(); + float unitMultiplier = 2f + (1f + (float)Math.Cos(angle * petalCount)); // This value is used to "squash" the circle to make it into a petal shape. + Vector2 velocity = initialUnitVector * unitMultiplier; + velocity = velocity.RotatedBy(MathHelper.PiOver4 + MathHelper.PiOver2); // Tilt the vector to make it look like an actual butterfly. + velocity = velocity.RotatedBy(offsetAngle); + velocity *= 0.25f; // Normalization removes the spaces that make the vector petal-like and not circular, so multiplication must be utilized instead. + + Dust dust = Dust.NewDustPerfect(center, 262); + dust.velocity = velocity * butterflyBurstSpeed; + dust.noGravity = true; + dust.color = Color.Pink; + dust.fadeIn = 1.5f; + } + ButterflyAntennaExplosionDust(center + new Vector2(0f, -74f).RotatedBy(offsetAngle), offsetAngle); + } + public void ButterflyAntennaExplosionDust(Vector2 center, float offsetAngle = 0f) + { + int evaluationPoints = 40; + + // When mapped out, these points give a rough apple stem shape. + Vector2[] bezierControlPoints = new Vector2[] + { + new Vector2(0f, 60f), + new Vector2(0f, 30f), + new Vector2(10f, -28f), + new Vector2(20f, -42f), + new Vector2(30f, -48f), + new Vector2(42f, -40f), + new Vector2(50f, -30f), + new Vector2(52f, -24f), + }; + BezierCurve bezierCurve = new BezierCurve(bezierControlPoints); + for (int i = 0; i < evaluationPoints; i++) + { + Dust dust = Dust.NewDustPerfect(center, 263); + dust.position = center + bezierCurve.Evaluate(i / (float)evaluationPoints).RotatedBy(offsetAngle); + dust.velocity = Vector2.Zero; + dust.noGravity = true; + dust.color = Color.SkyBlue; + dust.fadeIn = 1.5f; + + dust = Dust.CloneDust(dust); + dust.position = center + bezierCurve.Evaluate(i / (float)evaluationPoints).RotatedBy(offsetAngle) * new Vector2(-1f, 1f); + } + } + #endregion + + #region White Mark + public void WhiteMarkExplosionDust() + { + // Spawn three diamonds. + DiamondExplosionDust(projectile.Center, Main.rand.NextFloat(8f, 12f)); + + float absoluteOffsetAngle = Main.rand.NextFloat(0.4f, 0.7f); + Vector2 offset = Vector2.UnitY.RotatedBy(absoluteOffsetAngle * -1f) * 120f; + offset += Vector2.UnitX * 84f; + DiamondExplosionDust(projectile.Center + offset, Main.rand.NextFloat(6f, 11f)); + + absoluteOffsetAngle = Main.rand.NextFloat(0.4f, 0.7f); + offset = Vector2.UnitY.RotatedBy(absoluteOffsetAngle) * 120f; + offset -= Vector2.UnitX * 84f; + DiamondExplosionDust(projectile.Center + offset, Main.rand.NextFloat(6f, 11f)); + } + public void DiamondExplosionDust(Vector2 center, float diamondBurstSpeed, float offsetAngle = 0f) + { + int dustCount = 80; + for (int i = 0; i < dustCount; i++) + { + Vector2 startingVelocity = Vector2.Zero; + Vector2 endingVelocity = Vector2.Zero; + + switch (i / (dustCount / 4)) + { + case 0: + startingVelocity = Vector2.UnitY; + endingVelocity = Vector2.UnitX; + break; + case 1: + startingVelocity = Vector2.UnitX; + endingVelocity = -Vector2.UnitY; + break; + case 2: + startingVelocity = -Vector2.UnitY; + endingVelocity = -Vector2.UnitX; + break; + case 3: + startingVelocity = -Vector2.UnitX; + endingVelocity = Vector2.UnitY; + break; + } + Vector2 velocity = Vector2.Lerp(startingVelocity, endingVelocity, i / (dustCount / 4f) % 1f); + velocity = velocity.RotatedBy(offsetAngle); + velocity *= diamondBurstSpeed; + velocity.X *= 0.667f; + + Dust dust = Dust.NewDustPerfect(center, 263); + dust.position = center; + dust.velocity = velocity; + dust.noGravity = true; + dust.color = Color.LightSteelBlue; + dust.fadeIn = 1.5f; + } + } + #endregion + + #region Sky Blue Mark + public void SkyBlueMarkExplosionDust() + { + RainbowBoltExplosionDust(projectile.Center, Main.rand.NextFloat(-0.2f, 0.2f)); + } + public void RainbowBoltExplosionDust(Vector2 center, float offsetAngle = 0f) + { + // Spawn several clouds. + for (int i = 0; i < 5; i++) + { + CloudExplosionDust(center, offsetAngle); + } + LightningExplosionDust(center, offsetAngle); + } + public void CloudExplosionDust(Vector2 center, float offsetAngle = 0f) + { + center += Main.rand.NextVector2CircularEdge(40f, 40f); + Vector2 offset = Main.rand.NextVector2Square(0.9f, 1.15f); + for (float angle = 0f; angle <= MathHelper.TwoPi; angle += MathHelper.ToRadians(2f)) + { + Vector2 initialUnitVector = angle.ToRotationVector2(); + Vector2 spawnOffset = initialUnitVector.RotatedBy(offsetAngle); + spawnOffset = spawnOffset.RotatedByRandom(0.4f); + spawnOffset *= new Vector2(54f, 36f) * offset; + + spawnOffset -= Vector2.UnitY.RotatedBy(offsetAngle) * 90f; + + Dust dust = Dust.NewDustPerfect(center + spawnOffset, 263); + dust.velocity = Vector2.Zero; + dust.noGravity = true; + dust.scale = 2.7f; + dust.fadeIn = 1.5f; + } + } + public void LightningExplosionDust(Vector2 center, float offsetAngle = 0f) + { + int evaluationPoints = 65; + + // When mapped out, these points give a rough (but slightly weird) lightning bolt. + Vector2[] controlPoints = new Vector2[] + { + new Vector2(-38f, -64f), + new Vector2(-42f, -44f), + new Vector2(-26f, -28f), + new Vector2(-24f, -10f), + new Vector2(-34f, -4f), + new Vector2(-48f, -10f), + new Vector2(-40f, 12f), + new Vector2(-30f, 30f), + new Vector2(-20f, 48f), + new Vector2(-8f, 28f), + new Vector2(2f, 6f), + new Vector2(-8f, -4f), + new Vector2(4f, -16f), + new Vector2(8f, -36f), + new Vector2(12f, -56f), + new Vector2(-38f, -64f) + }; + for (int i = 0; i < evaluationPoints; i++) + { + int currentIndex = (int)(i / (float)evaluationPoints * controlPoints.Length); + Vector2 currentPosition = controlPoints[currentIndex]; + Vector2 nextPosition = controlPoints[(currentIndex + 1) % controlPoints.Length]; + + Dust dust = Dust.NewDustPerfect(center, 263); + dust.position = center + Vector2.Lerp(currentPosition, nextPosition, i / (float)evaluationPoints * controlPoints.Length % 0.999f).RotatedBy(offsetAngle) * 2f; + dust.position += Vector2.UnitY.RotatedBy(offsetAngle) * 138f; + dust.velocity = Vector2.Zero; + dust.noGravity = true; + dust.color = Main.hslToRgb(i / (float)evaluationPoints * 3f % 1f, 0.6f, 0.7f); + dust.scale = 1.4f; + dust.fadeIn = 1.5f; + } + + center += Main.rand.NextVector2CircularEdge(120f, 120f); + Vector2 offset = Main.rand.NextVector2Square(0.9f, 1.15f); + for (float angle = 0f; angle <= MathHelper.TwoPi; angle += MathHelper.ToRadians(2f)) + { + Vector2 initialUnitVector = angle.ToRotationVector2(); + Vector2 spawnOffset = initialUnitVector.RotatedBy(offsetAngle); + spawnOffset = spawnOffset.RotatedByRandom(0.4f); + spawnOffset *= new Vector2(130f, 84f) * offset; + + spawnOffset += Vector2.UnitY.RotatedBy(offsetAngle) * 30f; + + Dust dust = Dust.NewDustPerfect(center + spawnOffset, 263); + dust.velocity = Vector2.Zero; + dust.noGravity = true; + dust.scale = 4f; + dust.fadeIn = 1.5f; + } + } + #endregion + + #region Purple Mark + public void PurpleMarkExplosionDust() + { + TwilightStarExplosionDust(projectile.Center, 14f, Color.Magenta); + for (int i = 0; i < 6; i++) + { + float angle = MathHelper.TwoPi * i / 6f; + Vector2 offset = angle.ToRotationVector2() * Main.rand.NextFloat(140f, 180f); + TwilightStarExplosionDust(projectile.Center + offset, 4f, Color.White, Main.rand.NextFloat(-0.2f, 0.2f)); + } + } + public void TwilightStarExplosionDust(Vector2 center, float petalBurstSpeed, Color starColor, float absoluteOffsetAngle = 0f) + { + int pointsOnStar = 6; + for (int i = 0; i < pointsOnStar; i++) + { + float angle = MathHelper.Pi * 1.5f - i * MathHelper.TwoPi / pointsOnStar; + float nextAngle = MathHelper.Pi * 1.5f - (i + 2) * MathHelper.TwoPi / pointsOnStar; + Vector2 start = angle.ToRotationVector2(); + Vector2 end = nextAngle.ToRotationVector2(); + int pointsOnStarSegment = 35; + for (int j = 0; j < pointsOnStarSegment; j++) + { + Dust dust = Dust.NewDustPerfect(center, 263); + dust.scale = 1.8f; + dust.velocity = Vector2.Lerp(start, end, j / (float)pointsOnStarSegment) * petalBurstSpeed; + dust.velocity.X *= 0.7f; + dust.velocity = dust.velocity.RotatedBy(absoluteOffsetAngle); + dust.fadeIn = 1.5f; + dust.color = starColor; + dust.noGravity = true; + } + } + } + #endregion + + #region Pale Pink Mark + public void PalePinkMarkExplosionDust() + { + StarlightMarkExplosionDust(projectile.Center); + StarlightStarExplosionDust(projectile.Center + new Vector2(16f, 36f), 2f); + } + public void StarlightMarkExplosionDust(Vector2 center) + { + int evaluationPoints = 60; + + // When mapped out, these points give a rough swerving stream shape. + Vector2[] bezierControlPoints = new Vector2[] + { + new Vector2(-38f, -58f), + new Vector2(-22f, -34f), + new Vector2(-10f, -22f), + new Vector2(6f, -11f), + new Vector2(13f, 1f), + new Vector2(-20f, 11f), + new Vector2(16f, 11f), + new Vector2(26f, 6f), + new Vector2(24f, -11f), + new Vector2(8f, -28f), + new Vector2(-10f, -39f), + new Vector2(-38f, -58f) + }; + BezierCurve bezierCurve = new BezierCurve(bezierControlPoints); + + for (int i = 0; i < evaluationPoints; i++) + { + Dust dust = Dust.NewDustPerfect(center, 263); + dust.position = center + bezierCurve.Evaluate(i / (float)evaluationPoints) * new Vector2(3f, 1.7f); + dust.velocity = Vector2.Zero; + dust.color = i >= evaluationPoints / 2 ? Color.Cyan : Color.SkyBlue; + dust.fadeIn = 1.5f; + dust.scale = 1.4f; + dust.noGravity = true; + + dust = Dust.CloneDust(dust); + dust.position = center + bezierCurve.Evaluate(i / (float)evaluationPoints) * new Vector2(1f, -1f) + new Vector2(30f, -12f); + } + } + public void StarlightStarExplosionDust(Vector2 center, float starBurstSpeed) + { + int dustCount = 60; + for (int i = 0; i < dustCount; i++) + { + Vector2 startingVelocity = Vector2.Zero; + Vector2 endingVelocity = Vector2.Zero; + + switch (i / (dustCount / 4)) + { + case 0: + startingVelocity = Vector2.UnitY; + endingVelocity = Vector2.UnitX; + break; + case 1: + startingVelocity = Vector2.UnitX; + endingVelocity = -Vector2.UnitY; + break; + case 2: + startingVelocity = -Vector2.UnitY; + endingVelocity = -Vector2.UnitX; + break; + case 3: + startingVelocity = -Vector2.UnitX; + endingVelocity = Vector2.UnitY; + break; + } + Vector2 velocity = Vector2.Lerp(startingVelocity, endingVelocity, i / (dustCount / 4f) % 1f); + velocity *= starBurstSpeed; + velocity.X *= 0.75f; + + Dust dust = Dust.NewDustPerfect(center, 263); + dust.position = center; + dust.velocity = velocity; + dust.noGravity = true; + dust.color = Color.Purple; + dust.fadeIn = 1.5f; + + dust = Dust.CloneDust(dust); + dust.velocity = dust.velocity.RotatedBy(MathHelper.PiOver4); + dust.color = Color.White; + } + } + #endregion + } +} diff --git a/Projectiles/Magic/RainbowRocket.png b/Projectiles/Magic/RainbowRocket.png new file mode 100644 index 0000000000..7ff99fa614 Binary files /dev/null and b/Projectiles/Magic/RainbowRocket.png differ diff --git a/Projectiles/Magic/RedirectingFire.cs b/Projectiles/Magic/RedirectingFire.cs new file mode 100644 index 0000000000..d738f7a43a --- /dev/null +++ b/Projectiles/Magic/RedirectingFire.cs @@ -0,0 +1,101 @@ +using Microsoft.Xna.Framework; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.Utilities; + +namespace CalamityMod.Projectiles.Magic +{ + public class RedirectingFire : ModProjectile + { + public ref float BurstIntensity => ref projectile.ai[0]; + public ref float Time => ref projectile.ai[1]; + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + public override void SetStaticDefaults() => DisplayName.SetDefault("Fire"); + + public override void SetDefaults() + { + projectile.width = projectile.height = 18; + projectile.friendly = true; + projectile.penetrate = 1; + projectile.tileCollide = false; + projectile.magic = true; + projectile.ignoreWater = true; + } + + public override void AI() + { + if (Time >= 18f) + { + NPC potentialTarget = projectile.Center.ClosestNPCAt(1100f, false); + if (potentialTarget != null) + HomeInOnTarget(potentialTarget); + + float accelerationFactor = MathHelper.SmoothStep(1.025f, 1.015f, Utils.InverseLerp(6f, 24f, projectile.velocity.Length(), true)); + if (projectile.velocity.Length() < 24f) + projectile.velocity *= accelerationFactor; + } + EmitDust(); + Time++; + } + + public void HomeInOnTarget(NPC target) + { + float oldSpeed = projectile.velocity.Length(); + float delayFactor = Utils.InverseLerp(20f, 35f, Time, true); + float homeSpeed = MathHelper.Lerp(0f, 0.075f, delayFactor); + + projectile.velocity = Vector2.Lerp(projectile.velocity, projectile.SafeDirectionTo(target.Center) * 16f, homeSpeed); + projectile.velocity = projectile.velocity.SafeNormalize(Vector2.UnitY) * oldSpeed; + projectile.position += (target.Center - projectile.Center).SafeNormalize(Vector2.Zero) * MathHelper.Lerp(25f, 1f, Utils.InverseLerp(100f, 360f, projectile.Distance(target.Center), true)) * delayFactor; + } + + public Dust CreateDustInstance() + { + int dustType = 264; + + Color brimstoneColor = Color.Lerp(Color.Red, Color.DarkViolet, (float)Math.Sin(projectile.identity * 3f + Time / 12f) * 0.7f + 0.3f); + Color dustColor = Color.Lerp(Color.Orange, Color.Yellow, Main.rand.NextFloat()); + dustColor = Color.Lerp(dustColor, brimstoneColor, (float)Math.Pow(BurstIntensity, 2D)); + + Dust dust = Dust.NewDustPerfect(projectile.Center, dustType); + dust.color = dustColor; + dust.noGravity = true; + dust.noLight = true; + return dust; + } + + public void EmitDust() + { + if (Main.dedServ) + return; + + for (int i = 0; i < 5; i++) + { + Dust dust = CreateDustInstance(); + dust.velocity = (MathHelper.TwoPi * i / 5f).ToRotationVector2(); + dust.position += projectile.velocity; + dust.scale = MathHelper.Lerp(1f, 1.5f, BurstIntensity) * Main.rand.NextFloat(0.7f, 1.3f); + } + } + + public override void Kill(int timeLeft) + { + // Emit some fire sounds. + Main.PlaySound(SoundID.Item34, projectile.Center); + if (Main.dedServ) + return; + + for (int i = 0; i < 15; i++) + { + Dust ectoplasm = Dust.NewDustPerfect(projectile.Center + Main.rand.NextVector2Circular(30f, 30f) * BurstIntensity, 264); + ectoplasm.velocity = Main.rand.NextVector2Circular(2f, 2f); + ectoplasm.color = Color.Lerp(Color.Orange, Color.Yellow, Main.rand.NextFloat(0.67f)); + ectoplasm.scale = MathHelper.Lerp(1f, 1.6f, BurstIntensity); + ectoplasm.noGravity = true; + ectoplasm.noLight = true; + } + } + } +} diff --git a/Projectiles/Magic/RedirectingGildedSoul.cs b/Projectiles/Magic/RedirectingGildedSoul.cs new file mode 100644 index 0000000000..d54269ddb3 --- /dev/null +++ b/Projectiles/Magic/RedirectingGildedSoul.cs @@ -0,0 +1,87 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Magic +{ + public class RedirectingGildedSoul : ModProjectile + { + public ref float BurstIntensity => ref projectile.ai[0]; + public ref float Time => ref projectile.ai[1]; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Gilded Soul"); + Main.projFrames[projectile.type] = 4; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 10; + ProjectileID.Sets.TrailingMode[projectile.type] = 2; + } + + public override void SetDefaults() + { + projectile.scale = 0.6f; + projectile.width = projectile.height = 32; + projectile.friendly = true; + projectile.penetrate = 1; + projectile.tileCollide = false; + projectile.magic = true; + projectile.ignoreWater = true; + } + + public override void AI() => RedirectingVengefulSoul.DoSoulAI(projectile, ref Time, 5f); + + public override Color? GetAlpha(Color lightColor) + { + Color baseColor = Color.Lerp(Color.DarkGoldenrod, Color.Gold, projectile.identity % 5f / 5f); + Color color = Color.Lerp(baseColor, Color.White, BurstIntensity * 0.5f + (float)Math.Cos(Main.GlobalTime * 2.7f) * 0.04f); + color.A = 127; + return color * projectile.Opacity; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D texture = Main.projectileTexture[projectile.type]; + Rectangle frame = texture.Frame(1, Main.projFrames[projectile.type], 0, projectile.frame); + SpriteEffects direction = projectile.spriteDirection == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally; + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < projectile.oldPos.Length / 2; j++) + { + Color drawColor = projectile.GetAlpha(lightColor); + drawColor = Color.Lerp(drawColor, Color.White * projectile.Opacity, 2f * j / projectile.oldPos.Length) * (float)Math.Pow(1f - Utils.InverseLerp(0f, projectile.oldPos.Length / 2, j, true), 2D); + Vector2 drawPosition = projectile.oldPos[j] + projectile.Size * 0.5f + (MathHelper.TwoPi * i / 4f).ToRotationVector2() * 0.5f - Main.screenPosition; + float rotation = projectile.oldRot[j]; + + spriteBatch.Draw(texture, drawPosition, frame, drawColor, rotation, frame.Size() * 0.5f, projectile.scale, direction, 0f); + } + } + + return false; + } + + public override void Kill(int timeLeft) + { + // Play a wraith death sound at max intensity and a dungeon spirit hit sound otherwise. + Main.PlaySound(BurstIntensity >= 1f ? SoundID.NPCDeath52 : SoundID.NPCHit35, projectile.Center); + + // As well as an "extinguished" sound. + Main.PlaySound(SoundID.NPCDeath55, projectile.Center); + + // Make a ghost sound and explode into ectoplasmic energy. + if (Main.dedServ) + return; + + for (int i = 0; i < 45; i++) + { + Dust ectoplasm = Dust.NewDustPerfect(projectile.Center + Main.rand.NextVector2Circular(80f, 80f) * (float)Math.Pow(BurstIntensity, 2D), 264); + ectoplasm.velocity = Main.rand.NextVector2Circular(2f, 2f); + ectoplasm.color = projectile.GetAlpha(Color.White); + ectoplasm.scale = MathHelper.Lerp(1f, 1.6f, BurstIntensity); + ectoplasm.noGravity = true; + ectoplasm.noLight = true; + } + } + } +} diff --git a/Projectiles/Magic/RedirectingGildedSoul.png b/Projectiles/Magic/RedirectingGildedSoul.png new file mode 100644 index 0000000000..ecffa8c8a3 Binary files /dev/null and b/Projectiles/Magic/RedirectingGildedSoul.png differ diff --git a/Projectiles/Magic/RedirectingLostSoul.cs b/Projectiles/Magic/RedirectingLostSoul.cs new file mode 100644 index 0000000000..d11a8cf8a8 --- /dev/null +++ b/Projectiles/Magic/RedirectingLostSoul.cs @@ -0,0 +1,81 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Magic +{ + public class RedirectingLostSoul : ModProjectile + { + public ref float BurstIntensity => ref projectile.ai[0]; + public ref float Time => ref projectile.ai[1]; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Soul"); + Main.projFrames[projectile.type] = 4; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 10; + ProjectileID.Sets.TrailingMode[projectile.type] = 2; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 32; + projectile.friendly = true; + projectile.penetrate = 1; + projectile.tileCollide = false; + projectile.magic = true; + projectile.ignoreWater = true; + } + + public override void AI() => RedirectingVengefulSoul.DoSoulAI(projectile, ref Time, 1f); + + public override Color? GetAlpha(Color lightColor) + { + Color baseColor = Color.Lerp(Color.DarkRed, Color.DarkViolet, projectile.identity % 5f / 5f * 0.5f); + Color color = Color.Lerp(baseColor, Color.White, BurstIntensity * 0.5f + (float)Math.Cos(Main.GlobalTime * 2.7f) * 0.04f); + color.A = 0; + return color * projectile.Opacity; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + SpriteEffects direction = projectile.spriteDirection == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally; + Texture2D texture = Main.projectileTexture[projectile.type]; + Rectangle frame = texture.Frame(1, Main.projFrames[projectile.type], 0, projectile.frame); + + for (int j = 0; j < projectile.oldPos.Length / 2; j++) + { + float fade = (float)Math.Pow(1f - Utils.InverseLerp(0f, projectile.oldPos.Length / 2, j, true), 2D); + Color drawColor = projectile.GetAlpha(lightColor) * fade; + Vector2 drawPosition = projectile.oldPos[j] + projectile.Size * 0.5f - Main.screenPosition; + float rotation = projectile.oldRot[j]; + + spriteBatch.Draw(texture, drawPosition, frame, drawColor, rotation, frame.Size() * 0.5f, projectile.scale, direction, 0f); + } + + return false; + } + + public override void Kill(int timeLeft) + { + // Play a wraith death sound at max intensity and a dungeon spirit hit sound otherwise. + Main.PlaySound(BurstIntensity >= 1f ? SoundID.NPCDeath52 : SoundID.NPCHit35, projectile.Center); + + // Make a ghost sound and explode into ectoplasmic energy. + if (Main.dedServ) + return; + + for (int i = 0; i < 45; i++) + { + Dust ectoplasm = Dust.NewDustPerfect(projectile.Center + Main.rand.NextVector2Circular(50f, 50f) * BurstIntensity, 264); + ectoplasm.velocity = Main.rand.NextVector2Circular(2f, 2f); + ectoplasm.color = projectile.GetAlpha(Color.White); + ectoplasm.scale = MathHelper.Lerp(1f, 1.6f, BurstIntensity); + ectoplasm.noGravity = true; + ectoplasm.noLight = true; + } + } + } +} diff --git a/Projectiles/Magic/RedirectingLostSoul.png b/Projectiles/Magic/RedirectingLostSoul.png new file mode 100644 index 0000000000..f02bca1221 Binary files /dev/null and b/Projectiles/Magic/RedirectingLostSoul.png differ diff --git a/Projectiles/Magic/RedirectingVengefulSoul.cs b/Projectiles/Magic/RedirectingVengefulSoul.cs new file mode 100644 index 0000000000..fd9ce2250c --- /dev/null +++ b/Projectiles/Magic/RedirectingVengefulSoul.cs @@ -0,0 +1,126 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Magic +{ + public class RedirectingVengefulSoul : ModProjectile + { + public ref float BurstIntensity => ref projectile.ai[0]; + public ref float Time => ref projectile.ai[1]; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Soul"); + Main.projFrames[projectile.type] = 4; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 10; + ProjectileID.Sets.TrailingMode[projectile.type] = 2; + } + + public override void SetDefaults() + { + projectile.scale = 0.8f; + projectile.width = projectile.height = 46; + projectile.friendly = true; + projectile.penetrate = 1; + projectile.tileCollide = false; + projectile.magic = true; + projectile.ignoreWater = true; + } + + public override void AI() => DoSoulAI(projectile, ref Time, 2f); + + public static void DoSoulAI(Projectile projectile, ref float time, float soulPower) + { + if (time >= 20f) + { + NPC potentialTarget = projectile.Center.ClosestNPCAt(1250f, false); + if (potentialTarget != null) + HomeInOnTarget(projectile, potentialTarget, time); + + float accelerationFactor = MathHelper.SmoothStep(1.03f, 1.015f, Utils.InverseLerp(6f, 24f, projectile.velocity.Length(), true)); + if (projectile.velocity.Length() < 21f + soulPower * 2f) + projectile.velocity *= accelerationFactor; + } + projectile.Opacity = Utils.InverseLerp(0f, 15f, time, true); + projectile.frameCounter++; + if (projectile.frameCounter % 5f == 4f) + projectile.frame = (projectile.frame + 1) % Main.projFrames[projectile.type]; + + projectile.rotation = projectile.velocity.ToRotation(); + projectile.spriteDirection = (projectile.velocity.X > 0f).ToDirectionInt(); + if (projectile.spriteDirection == -1) + projectile.rotation += MathHelper.Pi; + + time++; + } + + public static void HomeInOnTarget(Projectile projectile, NPC target, float time) + { + float oldSpeed = projectile.velocity.Length(); + float delayFactor = Utils.InverseLerp(20f, 35f, time, true); + float homeSpeed = MathHelper.Lerp(0f, 0.075f, delayFactor); + + projectile.velocity = Vector2.Lerp(projectile.velocity, projectile.SafeDirectionTo(target.Center) * 16f, homeSpeed); + projectile.velocity = (projectile.velocity + projectile.SafeDirectionTo(target.Center) * 3f).SafeNormalize(Vector2.UnitY) * oldSpeed; + } + + public override Color? GetAlpha(Color lightColor) + { + Color baseColor = Color.Lerp(Color.IndianRed, Color.DarkViolet, projectile.identity % 5f / 5f * 0.5f); + Color color = Color.Lerp(baseColor * 1.5f, baseColor, BurstIntensity * 0.5f + (float)Math.Cos(Main.GlobalTime * 2.7f) * 0.04f); + color.A = 0; + return color * projectile.Opacity; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + SpriteEffects direction = projectile.spriteDirection == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally; + Texture2D texture = Main.projectileTexture[projectile.type]; + Rectangle frame = texture.Frame(1, Main.projFrames[projectile.type], 0, projectile.frame); + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < projectile.oldPos.Length / 2; j++) + { + float fade = (float)Math.Pow(1f - Utils.InverseLerp(0f, projectile.oldPos.Length / 2, j, true), 2D); + Color drawColor = Color.Lerp(projectile.GetAlpha(lightColor), Color.White * projectile.Opacity, j / projectile.oldPos.Length) * fade; + Vector2 drawPosition = projectile.oldPos[j] + projectile.Size * 0.5f + (MathHelper.TwoPi * i / 4f).ToRotationVector2() * 1.5f - Main.screenPosition; + float rotation = projectile.oldRot[j]; + + spriteBatch.Draw(texture, drawPosition, frame, drawColor, rotation, frame.Size() * 0.5f, projectile.scale, direction, 0f); + } + } + + return false; + } + + public override void Kill(int timeLeft) + { + // Play a wraith death sound at max intensity and a dungeon spirit hit sound otherwise. + Main.PlaySound(BurstIntensity >= 1f ? SoundID.NPCDeath52 : SoundID.NPCHit35, projectile.Center); + + // Make a ghost sound and explode into ectoplasmic energy. + if (Main.dedServ) + return; + + for (int i = 0; i < 45; i++) + { + Dust ectoplasm = Dust.NewDustPerfect(projectile.Center + Main.rand.NextVector2Circular(100f, 100f) * (float)Math.Pow(BurstIntensity, 2D), 264); + ectoplasm.velocity = Main.rand.NextVector2Circular(2f, 2f); + ectoplasm.color = projectile.GetAlpha(Color.White); + ectoplasm.scale = MathHelper.Lerp(1.2f, 1.9f, BurstIntensity); + ectoplasm.noGravity = true; + ectoplasm.noLight = true; + + ectoplasm = Dust.NewDustPerfect(projectile.Center, 264); + ectoplasm.velocity = (MathHelper.TwoPi * i / 45f).ToRotationVector2() * 6f; + ectoplasm.color = projectile.GetAlpha(Color.White); + ectoplasm.scale = MathHelper.Lerp(1.2f, 1.9f, BurstIntensity); + ectoplasm.noGravity = true; + ectoplasm.noLight = true; + } + } + } +} diff --git a/Projectiles/Magic/RedirectingVengefulSoul.png b/Projectiles/Magic/RedirectingVengefulSoul.png new file mode 100644 index 0000000000..3e0e4507b7 Binary files /dev/null and b/Projectiles/Magic/RedirectingVengefulSoul.png differ diff --git a/Projectiles/Magic/SeethingDischargeBrimstoneHellblast.cs b/Projectiles/Magic/SeethingDischargeBrimstoneHellblast.cs index 99f5ca7523..7fde79c1bc 100644 --- a/Projectiles/Magic/SeethingDischargeBrimstoneHellblast.cs +++ b/Projectiles/Magic/SeethingDischargeBrimstoneHellblast.cs @@ -10,6 +10,7 @@ namespace CalamityMod.Projectiles.Magic { public class SeethingDischargeBrimstoneHellblast : ModProjectile { + private bool initialized = false; public override string Texture => "CalamityMod/Projectiles/Boss/BrimstoneHellblast"; public override void SetStaticDefaults() @@ -35,6 +36,16 @@ namespace CalamityMod.Projectiles.Magic public override void AI() { + if (!initialized) + { + if (projectile.npcProj) + { + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 5; + projectile.penetrate = 10; + } + initialized = true; + } projectile.frameCounter++; if (projectile.frameCounter >= 10) { diff --git a/Projectiles/Magic/SolarElementalBeam.cs b/Projectiles/Magic/SolarElementalBeam.cs new file mode 100644 index 0000000000..bce85a1d74 --- /dev/null +++ b/Projectiles/Magic/SolarElementalBeam.cs @@ -0,0 +1,80 @@ +using CalamityMod.Projectiles.BaseProjectiles; +using CalamityMod.Projectiles.Typeless; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Magic +{ + public class SolarElementalBeam : BaseLaserbeamProjectile + { + public override float MaxScale => 1f; + public override float MaxLaserLength => 1000f; + public override float Lifetime => 30f; + public override Color LightCastColor => Color.White; + public override Texture2D LaserBeginTexture => ModContent.GetTexture("CalamityMod/ExtraTextures/Lasers/UltimaRayStart"); + public override Texture2D LaserMiddleTexture => ModContent.GetTexture("CalamityMod/ExtraTextures/Lasers/UltimaRayMid"); + public override Texture2D LaserEndTexture => ModContent.GetTexture("CalamityMod/ExtraTextures/Lasers/UltimaRayEnd"); + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Beam"); + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 20; + projectile.friendly = true; + projectile.magic = true; + projectile.penetrate = 10; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 13; + projectile.tileCollide = false; + projectile.timeLeft = (int)Lifetime; + } + + public override void ExtraBehavior() + { + // Generate a star-like burst of solar fire dust. + if (!Main.dedServ && Time == 5f) + { + int starPoints = 8; + for (int i = 0; i < starPoints; i++) + { + float angle = MathHelper.TwoPi * i / starPoints; + for (int j = 0; j < 12; j++) + { + float starSpeed = MathHelper.Lerp(2f, 10f, j / 12f); + Color dustColor = Color.Lerp(Color.White, Color.Yellow, j / 12f); + float dustScale = MathHelper.Lerp(1.6f, 0.85f, j / 12f); + + Dust fire = Dust.NewDustPerfect(projectile.Center, 6); + fire.velocity = angle.ToRotationVector2() * starSpeed; + fire.color = dustColor; + fire.scale = dustScale; + fire.noGravity = true; + } + } + } + } + + public override void DetermineScale() => projectile.scale = projectile.timeLeft / Lifetime * MaxScale; + + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + DrawBeamWithColor(spriteBatch, Color.Lerp(Color.OrangeRed, Color.Transparent, 0.25f), projectile.scale); + DrawBeamWithColor(spriteBatch, Color.Lerp(Color.Yellow * 1.1f, Color.Transparent, 0.25f), projectile.scale * 0.4f); + return false; + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + int type = ModContent.ProjectileType(); + int boomDamage = (int)(damage * 1.1); + int boom = Projectile.NewProjectile(target.Center, Vector2.Zero, type, boomDamage, knockback, projectile.owner, 0f, Main.rand.NextFloat(0.85f, 2f)); + Main.projectile[boom].Calamity().forceMagic = true; + } + } +} diff --git a/Projectiles/Magic/SolarElementalBeam.png b/Projectiles/Magic/SolarElementalBeam.png new file mode 100644 index 0000000000..15e8775737 Binary files /dev/null and b/Projectiles/Magic/SolarElementalBeam.png differ diff --git a/Projectiles/Magic/SparklingBeam.cs b/Projectiles/Magic/SparklingBeam.cs index 7c188ee5f6..0ed8ed8033 100644 --- a/Projectiles/Magic/SparklingBeam.cs +++ b/Projectiles/Magic/SparklingBeam.cs @@ -229,7 +229,7 @@ namespace CalamityMod.Projectiles.Magic } else { // Do we still have enough mana? If not, we kill the projectile because we cannot use it anymore - if (Main.player[projectile.owner].miscCounter % 10 == 0 && !player.CheckMana(player.ActiveItem().mana, true)) + if (Main.player[projectile.owner].miscCounter % 10 == 0 && !player.CheckMana(player.ActiveItem(), -1, true)) { projectile.Kill(); } diff --git a/Projectiles/Magic/StardustElementalBeam.cs b/Projectiles/Magic/StardustElementalBeam.cs new file mode 100644 index 0000000000..7fe2f9350d --- /dev/null +++ b/Projectiles/Magic/StardustElementalBeam.cs @@ -0,0 +1,85 @@ +using CalamityMod.Projectiles.BaseProjectiles; +using CalamityMod.Projectiles.Typeless; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Magic +{ + public class StardustElementalBeam : BaseLaserbeamProjectile + { + public override float MaxScale => 0.85f; + public override float MaxLaserLength => 1000f; + public override float Lifetime => 30f; + public override Color LightCastColor => Color.White; + public override Texture2D LaserBeginTexture => ModContent.GetTexture("CalamityMod/ExtraTextures/Lasers/UltimaRayStart"); + public override Texture2D LaserMiddleTexture => ModContent.GetTexture("CalamityMod/ExtraTextures/Lasers/UltimaRayMid"); + public override Texture2D LaserEndTexture => ModContent.GetTexture("CalamityMod/ExtraTextures/Lasers/UltimaRayEnd"); + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Beam"); + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 20; + projectile.friendly = true; + projectile.magic = true; + projectile.penetrate = 10; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 13; + projectile.tileCollide = false; + projectile.timeLeft = (int)Lifetime; + } + + public override void ExtraBehavior() + { + // Generate 2 stars from the side. + if (Main.myPlayer == projectile.owner && Time == 5f) + { + int type = ModContent.ProjectileType(); + + int damage = (int)(projectile.damage * 0.75); + for (int i = 0; i < 2; i++) + { + Vector2 starSpeed = projectile.velocity.RotatedBy(MathHelper.PiOver2 * i) * 5f; + Projectile.NewProjectile(projectile.Center, starSpeed, type, damage, projectile.knockBack, projectile.owner); + } + } + } + + public override void DetermineScale() => projectile.scale = projectile.timeLeft / Lifetime * MaxScale; + + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + DrawBeamWithColor(spriteBatch, Color.Lerp(Color.CornflowerBlue * 1.1f, Color.Transparent, 0.3f), projectile.scale); + DrawBeamWithColor(spriteBatch, Color.Lerp(Color.Cyan, Color.Transparent, 0.3f), projectile.scale * 0.5f); + DrawBeamWithColor(spriteBatch, Color.Lerp(Color.White, Color.Transparent, 0.3f), projectile.scale * 0.2f); + return false; + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + // Inflict the celled debuff for 3 seconds. + target.AddBuff(BuffID.StardustMinionBleed, 180); + + if (!Main.rand.NextBool(7)) + return; + + float spawnOffsetSpread = Main.rand.NextFloat(MathHelper.ToRadians(36f), MathHelper.ToRadians(64f)); + float baseOffsetAngle = Main.rand.NextFloat(-0.6f, 0.6f); + int type = ModContent.ProjectileType(); + damage = (int)(projectile.damage * 0.7); + for (int i = 0; i < 4; i++) + { + float spawnOffsetAngle = MathHelper.Lerp(spawnOffsetSpread * -0.5f, spawnOffsetSpread * 0.5f, i / 4f) + baseOffsetAngle; + Vector2 spawnPosition = target.Top - Vector2.UnitY.RotatedBy(spawnOffsetAngle) * 65f; + Projectile.NewProjectile(spawnPosition, -Vector2.UnitY.RotatedBy(spawnOffsetAngle) * 2f, type, damage, knockback, projectile.owner); + } + } + } +} diff --git a/Projectiles/Magic/StardustElementalBeam.png b/Projectiles/Magic/StardustElementalBeam.png new file mode 100644 index 0000000000..15e8775737 Binary files /dev/null and b/Projectiles/Magic/StardustElementalBeam.png differ diff --git a/Projectiles/Magic/T1000Proj.cs b/Projectiles/Magic/T1000Proj.cs index aec9a410c4..caebb2cf30 100644 --- a/Projectiles/Magic/T1000Proj.cs +++ b/Projectiles/Magic/T1000Proj.cs @@ -79,7 +79,7 @@ namespace CalamityMod.Projectiles.Magic if (flag && Main.myPlayer == projectile.owner) { int weaponDamage2 = player.GetWeaponDamage(player.ActiveItem()); - bool flag2 = player.channel && player.CheckMana(player.ActiveItem().mana, true, false) && !player.noItems && !player.CCed; + bool flag2 = player.channel && player.CheckMana(player.ActiveItem(), -1, true, false) && !player.noItems && !player.CCed; if (flag2) { float speed = player.ActiveItem().shootSpeed * projectile.scale; diff --git a/Projectiles/Magic/TerraBeam.cs b/Projectiles/Magic/TerraBeam.cs index 767731f012..6c3b4bbba7 100644 --- a/Projectiles/Magic/TerraBeam.cs +++ b/Projectiles/Magic/TerraBeam.cs @@ -1,56 +1,118 @@ +using CalamityMod.Projectiles.BaseProjectiles; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.ModLoader; + namespace CalamityMod.Projectiles.Magic { - public class TerraBeam : ModProjectile + public class TerraBeam : BaseLaserbeamProjectile { - public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + public override float MaxScale => 1f; + public override float MaxLaserLength => 1200f; + public override float Lifetime => 30f; + public override Color LightCastColor => Color.White; + public override Texture2D LaserBeginTexture => ModContent.GetTexture("CalamityMod/ExtraTextures/Lasers/UltimaRayStart"); + public override Texture2D LaserMiddleTexture => ModContent.GetTexture("CalamityMod/ExtraTextures/Lasers/UltimaRayMid"); + public override Texture2D LaserEndTexture => ModContent.GetTexture("CalamityMod/ExtraTextures/Lasers/UltimaRayEnd"); + public ref float ShardCooldown => ref projectile.ai[1]; + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; public override void SetStaticDefaults() { - DisplayName.SetDefault("Bolt"); + DisplayName.SetDefault("Beam"); } public override void SetDefaults() { - projectile.width = 4; - projectile.height = 4; + projectile.width = projectile.height = 20; projectile.friendly = true; projectile.magic = true; - projectile.ignoreWater = true; - projectile.penetrate = 10; - projectile.extraUpdates = 100; - projectile.timeLeft = 150; + projectile.ignoreWater = true; + projectile.penetrate = 10; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 8; + projectile.tileCollide = false; + projectile.timeLeft = (int)Lifetime; } - public override void AI() - { - projectile.localAI[1] += 1f; - if (projectile.localAI[1] >= 21f && projectile.owner == Main.myPlayer) - { - projectile.localAI[1] = 0f; - Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, 0f, 0f, ModContent.ProjectileType(), (int)(projectile.damage * 0.7), projectile.knockBack, projectile.owner, 0f, 0f); - } - - projectile.localAI[0] += 1f; - if (projectile.localAI[0] > 9f) - { - for (int num447 = 0; num447 < 3; num447++) + public override void ExtraBehavior() + { + // Generate a star-like and circular burst of terra dust. + if (!Main.dedServ && Time == 5f) + { + int starPoints = 6; + for (int i = 0; i < starPoints; i++) { - Vector2 vector33 = projectile.position; - vector33 -= projectile.velocity * ((float)num447 * 0.25f); - int num448 = Dust.NewDust(vector33, 1, 1, 107, 0f, 0f, 0, default, 1.25f); - Main.dust[num448].position = vector33; - Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; - Main.dust[num448].velocity *= 0.1f; - } + float angle = MathHelper.TwoPi * i / starPoints; + for (int j = 0; j < 12; j++) + { + float starSpeed = MathHelper.Lerp(1f, 7f, j / 12f); + Color dustColor = Color.Lerp(Color.White, Color.YellowGreen, j / 12f); + float dustScale = MathHelper.Lerp(1.6f, 0.85f, j / 12f); + + Dust terraMagic = Dust.NewDustPerfect(projectile.Center, 107); + terraMagic.velocity = angle.ToRotationVector2() * starSpeed; + terraMagic.color = dustColor; + terraMagic.scale = dustScale; + terraMagic.noGravity = true; + } + } + + int ovalPoints = 42; + for (int i = 0; i < ovalPoints; i++) + { + float angle = MathHelper.TwoPi * i / ovalPoints; + Dust terraMagic = Dust.NewDustPerfect(projectile.Center, 107); + terraMagic.velocity = angle.ToRotationVector2() * 6f; + terraMagic.scale = 1.1f; + terraMagic.noGravity = true; + } } + + if (ShardCooldown > 0f) + ShardCooldown--; } - public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) - { - target.immune[projectile.owner] = 8; + public override void DetermineScale() => projectile.scale = projectile.timeLeft / Lifetime * MaxScale; + + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + DrawBeamWithColor(spriteBatch, Color.Lime * 1.1f, projectile.scale); + DrawBeamWithColor(spriteBatch, Color.Yellow * 1.1f, projectile.scale * 0.5f); + return false; + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + if (ShardCooldown > 0f) + return; + + // The "Center" of the laser is actually the start of it in this context. + // Collision is done separately. This might have a slight offset due to collision + // boxes, but that should be negligible. + float lengthFromStart = projectile.Distance(target.Center); + + int totalShards = (int)MathHelper.Lerp(1, 4, MathHelper.Clamp(lengthFromStart / MaxLaserLength * 1.4f, 0f, 1f)); + int shardType = ModContent.ProjectileType(); + int shardDamage = (int)(damage * 0.6); + for (int i = 0; i < totalShards; i++) + { + int tries = 0; + Vector2 spawnOffset; + do + { + spawnOffset = Main.rand.NextVector2CircularEdge(target.width * 0.5f + 40f, target.height * 0.5f + 40f); + tries++; + } + while (Collision.SolidCollision((target.Center + spawnOffset).ToTileCoordinates().ToVector2(), 4, 4) && tries < 10); + + Projectile.NewProjectile(target.Center + spawnOffset, Main.rand.NextVector2CircularEdge(6f, 6f), shardType, shardDamage, knockback); + } + + ShardCooldown = 3f; + projectile.netUpdate = true; } - } + } } diff --git a/Projectiles/Magic/TerraBolt.cs b/Projectiles/Magic/TerraBolt.cs deleted file mode 100644 index 51b9d4aa78..0000000000 --- a/Projectiles/Magic/TerraBolt.cs +++ /dev/null @@ -1,51 +0,0 @@ -using Microsoft.Xna.Framework; -using Terraria; -using Terraria.ModLoader; -namespace CalamityMod.Projectiles.Magic -{ - public class TerraBolt : ModProjectile - { - public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; - - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Bolt"); - } - - public override void SetDefaults() - { - projectile.width = 4; - projectile.height = 4; - projectile.extraUpdates = 100; - projectile.friendly = true; - projectile.timeLeft = 30; - projectile.magic = true; - projectile.ignoreWater = true; - } - - public override void AI() - { - projectile.localAI[1] += 1f; - if (projectile.localAI[1] >= 29f && projectile.owner == Main.myPlayer) - { - projectile.localAI[1] = 0f; - Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, 0f, 0f, ModContent.ProjectileType(), (int)(projectile.damage * 0.7), projectile.knockBack, projectile.owner, 0f, 0f); - } - - for (int num447 = 0; num447 < 2; num447++) - { - Vector2 vector33 = projectile.position; - vector33 -= projectile.velocity * ((float)num447 * 0.25f); - int num448 = Dust.NewDust(vector33, 1, 1, 107, 0f, 0f, 0, default, 1.25f); - Main.dust[num448].position = vector33; - Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; - Main.dust[num448].velocity *= 0.1f; - } - } - - public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) - { - target.immune[projectile.owner] = 8; - } - } -} diff --git a/Projectiles/Magic/TerraBolt2.cs b/Projectiles/Magic/TerraBolt2.cs deleted file mode 100644 index 2ed2691579..0000000000 --- a/Projectiles/Magic/TerraBolt2.cs +++ /dev/null @@ -1,41 +0,0 @@ -using Microsoft.Xna.Framework; -using Terraria; -using Terraria.ModLoader; -namespace CalamityMod.Projectiles.Magic -{ - public class TerraBolt2 : ModProjectile - { - public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; - - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Bolt"); - } - - public override void SetDefaults() - { - projectile.width = 4; - projectile.height = 4; - projectile.extraUpdates = 100; - projectile.friendly = true; - projectile.timeLeft = 15; - projectile.magic = true; - projectile.ignoreWater = true; - } - - public override void AI() - { - Vector2 vector33 = projectile.position; - vector33 -= projectile.velocity * 0.25f; - int num448 = Dust.NewDust(vector33, 1, 1, 107, 0f, 0f, 0, default, 1.25f); - Main.dust[num448].position = vector33; - Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; - Main.dust[num448].velocity *= 0.1f; - } - - public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) - { - target.immune[projectile.owner] = 8; - } - } -} diff --git a/Projectiles/Magic/TerraOrb.cs b/Projectiles/Magic/TerraOrb.cs deleted file mode 100644 index ca2931dd8b..0000000000 --- a/Projectiles/Magic/TerraOrb.cs +++ /dev/null @@ -1,36 +0,0 @@ -using Terraria; -using Terraria.ModLoader; -namespace CalamityMod.Projectiles.Magic -{ - public class TerraOrb : ModProjectile - { - public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; - - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Bolt"); - } - - public override void SetDefaults() - { - projectile.width = 14; - projectile.height = 14; - projectile.friendly = true; - projectile.alpha = 255; - projectile.ignoreWater = true; - projectile.penetrate = -1; - projectile.timeLeft = 30; - projectile.magic = true; - } - - public override void AI() - { - CalamityGlobalProjectile.MagnetSphereHitscan(projectile, 300f, 6f, 24f, 5, ModContent.ProjectileType()); - } - - public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) - { - target.immune[projectile.owner] = 8; - } - } -} diff --git a/Projectiles/Magic/TerraOrb2.cs b/Projectiles/Magic/TerraOrb2.cs deleted file mode 100644 index 8513eda57c..0000000000 --- a/Projectiles/Magic/TerraOrb2.cs +++ /dev/null @@ -1,36 +0,0 @@ -using Terraria; -using Terraria.ModLoader; -namespace CalamityMod.Projectiles.Magic -{ - public class TerraOrb2 : ModProjectile - { - public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; - - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Bolt"); - } - - public override void SetDefaults() - { - projectile.width = 14; - projectile.height = 14; - projectile.friendly = true; - projectile.alpha = 255; - projectile.penetrate = -1; - projectile.timeLeft = 30; - projectile.magic = true; - projectile.ignoreWater = true; - } - - public override void AI() - { - CalamityGlobalProjectile.MagnetSphereHitscan(projectile, 300f, 6f, 18f, 5, ModContent.ProjectileType()); - } - - public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) - { - target.immune[projectile.owner] = 8; - } - } -} diff --git a/Projectiles/Magic/TerraShard.cs b/Projectiles/Magic/TerraShard.cs new file mode 100644 index 0000000000..cad86ae092 --- /dev/null +++ b/Projectiles/Magic/TerraShard.cs @@ -0,0 +1,35 @@ +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ModLoader; +namespace CalamityMod.Projectiles.Magic +{ + public class TerraShard : ModProjectile + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Shard"); + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 20; + projectile.friendly = true; + projectile.timeLeft = 60; + projectile.penetrate = 1; + projectile.magic = true; + projectile.tileCollide = true; + } + + public override void AI() + { + for (int i = 0; i < 4; i++) + { + Dust terraMagic = Dust.NewDustDirect(projectile.Center, 1, 1, 107, 0f, 0f, 0, default, 0.5f); + terraMagic.scale = 0.42f; + terraMagic.velocity *= 0.1f; + } + + CalamityGlobalProjectile.HomeInOnNPC(projectile, true, 500f, 15f, 20f); + } + } +} diff --git a/Projectiles/Magic/TerraShard.png b/Projectiles/Magic/TerraShard.png new file mode 100644 index 0000000000..15e8775737 Binary files /dev/null and b/Projectiles/Magic/TerraShard.png differ diff --git a/Projectiles/Magic/Vehemence.cs b/Projectiles/Magic/Vehemence.cs index f2e8ce99e3..875d18a6a5 100644 --- a/Projectiles/Magic/Vehemence.cs +++ b/Projectiles/Magic/Vehemence.cs @@ -1,3 +1,6 @@ +using CalamityMod.Buffs.DamageOverTime; +using CalamityMod.Dusts; +using CalamityMod.Items.Weapons.Magic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; @@ -9,6 +12,8 @@ namespace CalamityMod.Projectiles.Magic { public class Vehemence : ModProjectile { + public ref float Time => ref projectile.ai[0]; + public Player Owner => Main.player[projectile.owner]; public override void SetStaticDefaults() { DisplayName.SetDefault("Vehemence"); @@ -18,8 +23,7 @@ namespace CalamityMod.Projectiles.Magic public override void SetDefaults() { - projectile.width = 26; - projectile.height = 26; + projectile.width = projectile.height = 26; projectile.friendly = true; projectile.ignoreWater = true; projectile.penetrate = 1; @@ -31,24 +35,81 @@ namespace CalamityMod.Projectiles.Magic public override void AI() { projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2; - Lighting.AddLight(projectile.Center, 0.45f, 0f, 0.45f); - for (int num457 = 0; num457 < 2; num457++) + Lighting.AddLight(projectile.Center, Color.DarkRed.ToVector3()); + + if (Time == 0f) + GenerateInitialBurstDust(); + + GenerateHelicalDust(); + Time++; + } + + private void GenerateInitialBurstDust() + { + if (Main.dedServ) + return; + + for (int i = 0; i < 40; i++) { - int num458 = Dust.NewDust(projectile.position, projectile.width, projectile.height, 65, 0f, 0f, 100, default, 2f); - Main.dust[num458].noGravity = true; - Main.dust[num458].velocity *= 0.15f; - Main.dust[num458].velocity += projectile.velocity * 0.1f; + float angle = MathHelper.TwoPi * i / 40f; + + Dust brimstoneMagic = Dust.NewDustPerfect(projectile.Center + projectile.velocity * 7f, 27); + brimstoneMagic.velocity = angle.ToRotationVector2() * 15f; + brimstoneMagic.color = Color.Lerp(Color.Red, Color.MediumPurple, (float)Math.Sin(angle) * 0.5f + 0.5f); + brimstoneMagic.scale = 1.6f; + brimstoneMagic.noGravity = true; + } + } + + private void GenerateHelicalDust() + { + if (Main.dedServ) + return; + + // Helical brimstone dust from the back of the projectile. + for (int i = -1; i <= 1; i += 2) + { + float helixOffset = (float)Math.Sin(Time / 45f * MathHelper.TwoPi) * 11f * i; + Vector2 spawnOffset = new Vector2(helixOffset, -28f).RotatedBy(projectile.rotation); + + Dust brimstoneMagic = Dust.NewDustPerfect(projectile.Center + spawnOffset, (int)CalamityDusts.Brimstone); + brimstoneMagic.velocity = Vector2.Zero; + brimstoneMagic.scale = 1.1f; + brimstoneMagic.noGravity = true; } } public override void Kill(int timeLeft) { Main.PlaySound(SoundID.Item74, projectile.position); - for (int j = 0; j <= 25; j++) + if (Main.myPlayer == projectile.owner) { - int num459 = Dust.NewDust(projectile.position, projectile.width, projectile.height, 65, 0f, 0f, 100, default, 1f); - Main.dust[num459].noGravity = true; - Main.dust[num459].velocity *= 0.1f; + int damage = (int)(Vehemenc.VehemenceSkullDamage * Owner.MagicDamage()); + for (int i = 0; i < 18; i++) + Projectile.NewProjectile(projectile.Center, Main.rand.NextVector2Circular(12f, 12f), ModContent.ProjectileType(), damage, projectile.knockBack, projectile.owner); + } + + if (!Main.dedServ) + { + for (int i = 0; i < 20; i++) + { + for (int j = 0; j < 4; j++) + { + Vector2 shootVelocity = projectile.velocity.RotatedBy(MathHelper.Lerp(-0.35f, 0.35f, j / 4f)) * Main.rand.NextFloat(0.75f, 1.1f); + Vector2 spawnPosition = projectile.Center + shootVelocity.SafeNormalize(Vector2.Zero) * 10f; + + Dust blood = Dust.NewDustPerfect(spawnPosition, DustID.Blood); + blood.velocity = shootVelocity; + blood.scale = MathHelper.Lerp(1.7f, 0.85f, i / 20f); + } + } + for (int i = 0; i < 60; i++) + { + Dust brimstoneMagic = Dust.NewDustPerfect(projectile.Center, Main.rand.NextBool(2) ? (int)CalamityDusts.Brimstone : 27); + brimstoneMagic.velocity = Main.rand.NextVector2Circular(18f, 18f); + brimstoneMagic.scale = 1.7f; + brimstoneMagic.noGravity = true; + } } } @@ -56,8 +117,8 @@ namespace CalamityMod.Projectiles.Magic { double lifeAmount = target.life; double lifeMax = target.lifeMax; - double damageMult = lifeAmount / lifeMax * 7; - damage = (int)Math.Pow(damage, damageMult); + double damageExponent = lifeAmount / lifeMax * 7; + damage = (int)Math.Pow(damage, damageExponent); if (damage > 200000) damage = 200000; } @@ -65,13 +126,7 @@ namespace CalamityMod.Projectiles.Magic public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) { if (target.life == target.lifeMax) - { - target.AddBuff(BuffID.ShadowFlame, 12000); - target.AddBuff(BuffID.Ichor, 12000); - target.AddBuff(BuffID.Frostburn, 12000); - target.AddBuff(BuffID.OnFire, 12000); - target.AddBuff(BuffID.Poisoned, 12000); - } + target.AddBuff(ModContent.BuffType(), 18000); } public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) diff --git a/Projectiles/Magic/VehemenceHoldout.cs b/Projectiles/Magic/VehemenceHoldout.cs new file mode 100644 index 0000000000..9052a882ed --- /dev/null +++ b/Projectiles/Magic/VehemenceHoldout.cs @@ -0,0 +1,93 @@ +using CalamityMod.Dusts; +using Microsoft.Xna.Framework; +using System; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Magic +{ + public class VehemenceHoldout : ModProjectile + { + public Player Owner => Main.player[projectile.owner]; + public ref float Time => ref projectile.ai[0]; + + public const int ChargeTime = 90; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Vehemence"); + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 96; + projectile.friendly = false; + projectile.magic = false; + projectile.tileCollide = false; + projectile.ignoreWater = true; + projectile.timeLeft = ChargeTime + 1; + } + + public override void AI() + { + UpdatePlayerVisuals(); + if (Time == ChargeTime) + ShootBolt(); + else if (Time < ChargeTime) + CreateChargeDust(); + + Time++; + + if (Main.mouseLeftRelease && Time >= 5f && Time < ChargeTime) + projectile.Kill(); + } + + private void UpdatePlayerVisuals() + { + projectile.Center = Owner.RotatedRelativePoint(Owner.MountedCenter, true); + + projectile.rotation = projectile.AngleTo(Main.MouseWorld); + projectile.velocity = projectile.rotation.ToRotationVector2(); + + // Place the projectile directly into the player's hand with an offset at all times. + projectile.Center += projectile.rotation.ToRotationVector2() * 30f; + + projectile.direction = projectile.spriteDirection = (Math.Cos(projectile.rotation) > 0).ToDirectionInt(); + + // The staff is a holdout projectile; change the player's variables to reflect this. + Owner.ChangeDir(projectile.direction); + Owner.heldProj = projectile.whoAmI; + Owner.itemTime = 2; + Owner.itemAnimation = 2; + Owner.itemRotation = projectile.rotation * projectile.direction; + + projectile.rotation += MathHelper.PiOver4; + if (projectile.spriteDirection == -1) + projectile.rotation += MathHelper.PiOver2; + } + + private void ShootBolt() + { + if (Main.myPlayer != projectile.owner) + return; + + Item heldItem = Owner.ActiveItem(); + Vector2 shootVelocity = (Main.MouseWorld - projectile.Center).SafeNormalize(Vector2.UnitX * projectile.direction) * heldItem.shootSpeed; + Projectile.NewProjectile(projectile.Center, shootVelocity, ModContent.ProjectileType(), (int)(Owner.MagicDamage() * heldItem.damage), heldItem.knockBack, projectile.owner); + } + + private void CreateChargeDust() + { + if (Main.dedServ) + return; + + Vector2 spawnOffset = projectile.velocity * 70f; + for (int i = 0; i < 18; i++) + { + Dust brimstoneMagic = Dust.NewDustPerfect(projectile.Center + spawnOffset + Main.rand.NextVector2CircularEdge(30f, 30f), (int)CalamityDusts.Brimstone); + brimstoneMagic.velocity = (projectile.Center + spawnOffset - brimstoneMagic.position).SafeNormalize(Vector2.Zero) * 2f + Owner.velocity; + brimstoneMagic.scale = 1.2f; + brimstoneMagic.noGravity = true; + } + } + } +} diff --git a/Projectiles/Magic/VehemenceHoldout.png b/Projectiles/Magic/VehemenceHoldout.png new file mode 100644 index 0000000000..382701bacb Binary files /dev/null and b/Projectiles/Magic/VehemenceHoldout.png differ diff --git a/Projectiles/Magic/VehemenceSkull.cs b/Projectiles/Magic/VehemenceSkull.cs new file mode 100644 index 0000000000..a4abfd0030 --- /dev/null +++ b/Projectiles/Magic/VehemenceSkull.cs @@ -0,0 +1,63 @@ +using CalamityMod.Buffs.DamageOverTime; +using System; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Magic +{ + public class VehemenceSkull : ModProjectile + { + public ref float Time => ref projectile.ai[0]; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Brimstone Skull"); + Main.projFrames[projectile.type] = 10; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 45; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.alpha = 255; + projectile.tileCollide = false; + projectile.ignoreWater = true; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 6; + projectile.magic = true; + } + + public override void AI() + { + Time++; + projectile.frameCounter++; + if (projectile.frameCounter > 6) + { + projectile.frame++; + projectile.frameCounter = 0; + } + + if (projectile.ai[0] < 125) // 155 - frameCounter tick * number of disippation frames. + { + if (projectile.frame >= 4) + projectile.frame = 0; + } + + else if (projectile.owner == Main.myPlayer && projectile.frame >= Main.projFrames[projectile.type]) + projectile.Kill(); + + projectile.velocity *= 0.98f; + if (projectile.alpha > 110) + { + projectile.alpha -= 30; + if (projectile.alpha < 70) + projectile.alpha = 70; + } + + if (Math.Abs(projectile.velocity.X) > 0.1f) + projectile.spriteDirection = -projectile.direction; + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) => target.AddBuff(ModContent.BuffType(), 240); + } +} diff --git a/Projectiles/Magic/VehemenceSkull.png b/Projectiles/Magic/VehemenceSkull.png new file mode 100644 index 0000000000..249fa3f6fe Binary files /dev/null and b/Projectiles/Magic/VehemenceSkull.png differ diff --git a/Projectiles/Magic/VortexElementalBeam.cs b/Projectiles/Magic/VortexElementalBeam.cs new file mode 100644 index 0000000000..5a94a1d25a --- /dev/null +++ b/Projectiles/Magic/VortexElementalBeam.cs @@ -0,0 +1,182 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.IO; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.Utilities; + +namespace CalamityMod.Projectiles.Magic +{ + public class VortexElementalBeam : ModProjectile + { + public const int Lifetime = 30; + public const float LightningTurnRandomnessFactor = 1.7f; + public ref float InitialVelocityAngle => ref projectile.ai[0]; + // Technically not a ratio, and more of a seed, but it is used in a 0-2pi squash + // later in the code to get an arbitrary unit vector (which is then checked). + public ref float BaseTurnAngleRatio => ref projectile.ai[1]; + public ref float AccumulatedXMovementSpeeds => ref projectile.localAI[0]; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Lightning"); + ProjectileID.Sets.MinionShot[projectile.type] = true; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 30; + ProjectileID.Sets.TrailingMode[projectile.type] = 1; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 16; + projectile.friendly = true; + projectile.magic = true; + projectile.alpha = 255; + projectile.penetrate = 1; + projectile.ignoreWater = true; + projectile.tileCollide = false; + projectile.extraUpdates = 20; + projectile.timeLeft = 45 * projectile.extraUpdates; + + // Readjust the velocity magnitude the moment this projectile is created + // to make velocity setting outside the scope of this projectile less irritating + // to consider alongside extraUpdate multipliers. + // Also set the initial angle. + if (projectile.velocity != Vector2.Zero) + { + projectile.velocity /= projectile.extraUpdates; + } + } + + public override void SendExtraAI(BinaryWriter writer) => writer.Write(AccumulatedXMovementSpeeds); + + public override void ReceiveExtraAI(BinaryReader reader) => AccumulatedXMovementSpeeds = reader.ReadSingle(); + + public override void AI() + { + // frameCounter in this context is really just an arbitrary timer + // which allows random turning to occur. + projectile.frameCounter++; + + projectile.scale += 0.04f / projectile.MaxUpdates; + if (projectile.scale > 1f) + projectile.scale = 1f; + + Lighting.AddLight(projectile.Center, Color.Pink.ToVector3()); + if (projectile.frameCounter >= projectile.extraUpdates * 2) + { + projectile.frameCounter = 0; + + float originalSpeed = MathHelper.Min(6f, projectile.velocity.Length()); + UnifiedRandom unifiedRandom = new UnifiedRandom((int)BaseTurnAngleRatio); + int turnTries = 0; + Vector2 newBaseDirection = -Vector2.UnitY; + Vector2 potentialBaseDirection; + + do + { + BaseTurnAngleRatio = unifiedRandom.Next() % 100; + potentialBaseDirection = (BaseTurnAngleRatio / 100f * MathHelper.TwoPi).ToRotationVector2(); + + // Ensure that the new potential direction base is always moving upwards (this is supposed to be somewhat similar to a -UnitY + RotatedBy). + potentialBaseDirection.Y = -Math.Abs(potentialBaseDirection.Y); + + bool canChangeLightningDirection = true; + + // Potential directions with very little Y speed should not be considered, because this + // consequentially means that the X speed would be quite large. + if (potentialBaseDirection.Y > -0.02f) + canChangeLightningDirection = false; + + // This mess of math basically encourages movement at the ends of an extraUpdate cycle, + // discourages super frequenent randomness as the accumulated X speed changes get larger, + // or if the original speed is quite large. + if (Math.Abs(potentialBaseDirection.X * (projectile.extraUpdates + 1) * 2f * originalSpeed + AccumulatedXMovementSpeeds) > projectile.MaxUpdates * LightningTurnRandomnessFactor) + { + canChangeLightningDirection = false; + } + + // If the above checks were all passed, redefine the base direction of the lightning. + if (canChangeLightningDirection) + newBaseDirection = potentialBaseDirection; + + turnTries++; + } + while (turnTries < 100); + + if (projectile.velocity != Vector2.Zero) + { + AccumulatedXMovementSpeeds += newBaseDirection.X * (projectile.extraUpdates + 1) * 2f * originalSpeed; + projectile.velocity = newBaseDirection.RotatedBy(InitialVelocityAngle + MathHelper.PiOver2) * originalSpeed; + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2; + } + } + } + + #region Drawing + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D lightningSegmentTexture = Main.projectileTexture[projectile.type]; + projectile.GetAlpha(lightColor); + Vector2 lightningScale = new Vector2(projectile.scale) / 2f; + for (int i = 0; i < 3; i++) + { + // c_1 and f_1 are general fields that are used for drawing methods in here. + // c_1 is the color to be used, and f_1 is the opacity. + if (i == 0) + { + lightningScale = new Vector2(projectile.scale) * 0.6f; + DelegateMethods.c_1 = Color.DarkCyan * 0.85f; + } + else if (i == 1) + { + lightningScale = new Vector2(projectile.scale) * 0.4f; + DelegateMethods.c_1 = Color.Cyan * 0.85f; + } + else + { + lightningScale = new Vector2(projectile.scale) * 0.2f; + DelegateMethods.c_1 = Color.White; + } + + DelegateMethods.f_1 = 1f; + for (int j = projectile.oldPos.Length - 1; j > 0; j--) + { + if (projectile.oldPos[j] != Vector2.Zero) + { + Vector2 start = projectile.oldPos[j] + projectile.Size * 0.5f + Vector2.UnitY * projectile.gfxOffY - Main.screenPosition; + Vector2 end = projectile.oldPos[j - 1] + projectile.Size * 0.5f + Vector2.UnitY * projectile.gfxOffY - Main.screenPosition; + Utils.DrawLaser(spriteBatch, lightningSegmentTexture, start, end, lightningScale, DelegateMethods.LightningLaserDraw); + } + } + } + return false; + } + #endregion + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + target.AddBuff(BuffID.Electrified, 180); + + for (int i = 0; i < projectile.oldPos.Length - 1; i++) + { + // Skip zeroed old positions. They are almost certainly a + // result of incomplete indices. + if (projectile.oldPos[i + 1] == Vector2.Zero) + continue; + + for (int j = 0; j < 8; j++) + { + Vector2 dustSpawnPosition = Vector2.Lerp(projectile.oldPos[i], projectile.oldPos[i + 1], j / 8f); + dustSpawnPosition += projectile.Size * 0.5f; + + Dust electricity = Dust.NewDustPerfect(dustSpawnPosition, Main.rand.NextBool(2) ? 226 : 229); + electricity.velocity = Vector2.Zero; + electricity.scale = Main.rand.NextFloat(1.1f, 1.18f); + electricity.noGravity = true; + } + } + } + } +} diff --git a/Projectiles/Magic/VortexElementalBeam.png b/Projectiles/Magic/VortexElementalBeam.png new file mode 100644 index 0000000000..f99e9c57d5 Binary files /dev/null and b/Projectiles/Magic/VortexElementalBeam.png differ diff --git a/Projectiles/Magic/YharimsCrystalPrism.cs b/Projectiles/Magic/YharimsCrystalPrism.cs index 9f8a3703a5..7447510c99 100644 --- a/Projectiles/Magic/YharimsCrystalPrism.cs +++ b/Projectiles/Magic/YharimsCrystalPrism.cs @@ -82,7 +82,7 @@ namespace CalamityMod.Projectiles.Magic UpdateAim(rrp, speedTimesScale); // CheckMana returns true if the mana cost can be paid. If mana isn't consumed this frame, the CheckMana short-circuits out of being evaluated. - bool allowContinuedUse = !ShouldConsumeMana() || player.CheckMana(player.ActiveItem().mana, true, false); + bool allowContinuedUse = !ShouldConsumeMana() || player.CheckMana(player.ActiveItem(), -1, true, false); bool crystalStillInUse = player.channel && allowContinuedUse && !player.noItems && !player.CCed; // The beams are only projected once (on frame 1). diff --git a/Projectiles/Melee/AtaraxiaSplit.cs b/Projectiles/Melee/AtaraxiaSplit.cs index 033acb4421..0771c80dd0 100644 --- a/Projectiles/Melee/AtaraxiaSplit.cs +++ b/Projectiles/Melee/AtaraxiaSplit.cs @@ -18,7 +18,7 @@ namespace CalamityMod.Projectiles.Melee projectile.penetrate = -1; projectile.usesIDStaticNPCImmunity = true; projectile.idStaticNPCHitCooldown = 6; - projectile.timeLeft = 50; + projectile.timeLeft = 25; projectile.tileCollide = false; projectile.ignoreWater = true; projectile.alpha = 0; diff --git a/Projectiles/Melee/Blood.cs b/Projectiles/Melee/Blood.cs index 2973ab8a00..4e04f7104e 100644 --- a/Projectiles/Melee/Blood.cs +++ b/Projectiles/Melee/Blood.cs @@ -47,7 +47,7 @@ namespace CalamityMod.Projectiles.Melee if (player.moonLeech) return; - int healAmt = projectile.ai[0] == 1f ? 3 : 5; + int healAmt = 2; player.statLife += healAmt; player.HealEffect(healAmt); } diff --git a/Projectiles/Melee/BlueAura.cs b/Projectiles/Melee/BlueAura.cs index 8908e5b14f..51f745879f 100644 --- a/Projectiles/Melee/BlueAura.cs +++ b/Projectiles/Melee/BlueAura.cs @@ -21,6 +21,8 @@ namespace CalamityMod.Projectiles.Melee projectile.tileCollide = false; projectile.penetrate = -1; projectile.timeLeft = 300; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 10; } public override void AI() diff --git a/Projectiles/Melee/DragonPowFlail.cs b/Projectiles/Melee/DragonPowFlail.cs index e5b6761e92..b65387990b 100644 --- a/Projectiles/Melee/DragonPowFlail.cs +++ b/Projectiles/Melee/DragonPowFlail.cs @@ -138,8 +138,8 @@ namespace CalamityMod.Projectiles.Melee public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) { - // Only perform hit effects after reaching approximately 75% of the way out. - if (Main.player[projectile.owner].WithinRange(target.Center, 620f)) + // Only perform hit effects after reaching approximately 55% of the way out. + if (Main.player[projectile.owner].WithinRange(target.Center, 475f)) return; // Inflicts Daybroken, Abyssal Flames and Holy Flames for 8 seconds on-hit @@ -156,8 +156,8 @@ namespace CalamityMod.Projectiles.Melee public override void OnHitPvp(Player target, int damage, bool crit) { - // Only perform hit effects after reaching approximately 75% of the way out. - if (projectile.WithinRange(Main.player[projectile.owner].Center, 1100f)) + // Only perform hit effects after reaching approximately 55% of the way out. + if (projectile.WithinRange(Main.player[projectile.owner].Center, 475f)) return; // Inflicts Abyssal Flames and Holy Flames for 8 seconds on-hit diff --git a/Projectiles/Melee/Leech.cs b/Projectiles/Melee/Leech.cs index 9774c32ebe..6bd904b1b7 100644 --- a/Projectiles/Melee/Leech.cs +++ b/Projectiles/Melee/Leech.cs @@ -53,8 +53,8 @@ namespace CalamityMod.Projectiles.Melee return; Player player = Main.player[projectile.owner]; - player.statLife += 5; - player.HealEffect(5); + player.statLife += 2; + player.HealEffect(2); } } } diff --git a/Projectiles/Melee/OmnibladeSwing.cs b/Projectiles/Melee/OmnibladeSwing.cs new file mode 100644 index 0000000000..715455b7c9 --- /dev/null +++ b/Projectiles/Melee/OmnibladeSwing.cs @@ -0,0 +1,102 @@ +using CalamityMod.Buffs.StatDebuffs; +using Microsoft.Xna.Framework; +using System; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Melee +{ + public class OmnibladeSwing : ModProjectile + { + public Player Owner => Main.player[projectile.owner]; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Omniblade"); + Main.projFrames[projectile.type] = 6; + } + + public override void SetDefaults() + { + projectile.width = 246; + projectile.height = 184; + projectile.scale = 1.15f; + + projectile.friendly = true; + projectile.penetrate = -1; + projectile.tileCollide = false; + projectile.melee = true; + projectile.ownerHitCheck = true; + projectile.usesIDStaticNPCImmunity = true; + projectile.idStaticNPCHitCooldown = 3; + projectile.Calamity().trueMelee = true; + } + + public override void AI() + { + projectile.frameCounter++; + projectile.frame = projectile.frameCounter / 3; + if (projectile.frame >= Main.projFrames[projectile.type]) + projectile.Kill(); + + Vector2 playerRotatedPoint = Owner.RotatedRelativePoint(Owner.MountedCenter, true); + if (Main.myPlayer == projectile.owner) + { + if (Owner.channel && !Owner.noItems && !Owner.CCed) + HandleChannelMovement(playerRotatedPoint); + else + projectile.Kill(); + } + + // Rotation and directioning. + projectile.direction = (projectile.velocity.X > 0).ToDirectionInt(); + + // Sprite and player directioning. + projectile.spriteDirection = -projectile.direction; + if (projectile.direction == 1) + projectile.Left = Owner.Center; + else + projectile.Right = Owner.Center; + projectile.position.X += projectile.spriteDirection == -1 ? -116f : 88f; + projectile.position.Y -= projectile.scale * 66f; + Owner.ChangeDir(projectile.direction); + + // Prevents the projectile from dying + projectile.timeLeft = 2; + + // Player item-based field manipulation. + Owner.itemRotation = (projectile.velocity * projectile.direction).ToRotation(); + Owner.heldProj = projectile.whoAmI; + Owner.itemTime = 2; + Owner.itemAnimation = 2; + } + + public void HandleChannelMovement(Vector2 playerRotatedPoint) + { + Vector2 newVelocity = Vector2.UnitX * (Main.MouseWorld.X > playerRotatedPoint.X).ToDirectionInt(); + + // Sync if a velocity component changes. + if (projectile.velocity.X != newVelocity.X || projectile.velocity.Y != newVelocity.Y) + projectile.netUpdate = true; + + projectile.velocity = newVelocity; + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + if (Main.rand.NextBool(5)) + target.AddBuff(ModContent.BuffType(), 360); + } + + public override void OnHitPvp(Player target, int damage, bool crit) + { + if (Main.rand.NextBool(5)) + target.AddBuff(ModContent.BuffType(), 360); + } + + public override Color? GetAlpha(Color lightColor) => new Color(200, 200, 200, 170); + + // Don't suffer from the same issues Murasama did in the past; encouraging people to kill their wrists for some extra DPS is bad lmao + public override bool CanDamage() => projectile.frameCounter > 6; + } +} diff --git a/Projectiles/Melee/OmnibladeSwing.png b/Projectiles/Melee/OmnibladeSwing.png new file mode 100644 index 0000000000..bb0103db68 Binary files /dev/null and b/Projectiles/Melee/OmnibladeSwing.png differ diff --git a/Projectiles/Melee/PhosphorescentGauntletPunches.cs b/Projectiles/Melee/PhosphorescentGauntletPunches.cs new file mode 100644 index 0000000000..3bb90dba9c --- /dev/null +++ b/Projectiles/Melee/PhosphorescentGauntletPunches.cs @@ -0,0 +1,177 @@ +using CalamityMod.DataStructures; +using CalamityMod.Dusts; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Melee +{ + public class PhosphorescentGauntletPunches : ModProjectile + { + public Player Owner => Main.player[projectile.owner]; + public bool HasPerformedLunge + { + get => projectile.ai[0] == 1f; + set + { + int newValue = value.ToInt(); + if (projectile.ai[0] != newValue) + { + projectile.ai[0] = newValue; + projectile.netUpdate = true; + } + } + } + + public ref float Time => ref projectile.ai[1]; + + public const float LungeSpeed = 19f; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Punch"); + Main.projFrames[projectile.type] = 14; + } + + public override void SetDefaults() + { + projectile.scale = 1.6f; + projectile.width = projectile.height = (int)(projectile.scale * 60); + projectile.friendly = true; + projectile.penetrate = -1; + projectile.tileCollide = false; + projectile.melee = true; + projectile.ownerHitCheck = true; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 12; + projectile.frameCounter = 0; + projectile.Calamity().trueMelee = true; + } + + #region AI + public override void AI() + { + if (!HasPerformedLunge) + PerformLunge(); + + Vector2 topLeft = projectile.Center + projectile.velocity.RotatedBy(-MathHelper.PiOver2) * 40f; + Vector2 topRight = projectile.Center + projectile.velocity.RotatedBy(MathHelper.PiOver2) * 40f; + if (Time >= 8f && !Collision.CanHitLine(topLeft, 8, 8, topRight, 8, 8)) + ReelBack(); + HandleProjectileVisuals(); + HandlePositioning(); + Time++; + } + + internal void PerformLunge() + { + if (Main.myPlayer != projectile.owner) + return; + Owner.velocity = projectile.velocity.SafeNormalize(Vector2.UnitX * Owner.direction) * LungeSpeed; + HasPerformedLunge = true; + } + + internal void ReelBack() + { + Owner.immune = true; + Owner.immuneTime = 15; + + // Create some visual effects. + if (!Main.dedServ) + { + Vector2 topLeft = projectile.Center + projectile.velocity.RotatedBy(-MathHelper.PiOver2) * 40f; + Vector2 top = projectile.Center + projectile.velocity * 70f; + Vector2 topRight = projectile.Center + projectile.velocity.RotatedBy(MathHelper.PiOver2) * 40f; + foreach (Vector2 spawnPosition in new BezierCurve(topLeft, top, topRight).GetPoints(50)) + { + Dust sulphurousAcid = Dust.NewDustPerfect(spawnPosition + projectile.velocity * 16f, (int)CalamityDusts.SulfurousSeaAcid); + sulphurousAcid.velocity = projectile.velocity * 4f; + sulphurousAcid.noGravity = true; + sulphurousAcid.scale = 1.2f; + } + } + if (Main.myPlayer != projectile.owner) + return; + + // Reel back after collision. + Owner.velocity = Vector2.Reflect(Owner.velocity.SafeNormalize(Vector2.Zero), projectile.velocity.SafeNormalize(Vector2.Zero)) * Owner.velocity.Length(); + + // Create on-hit tile dust. + Collision.HitTiles(projectile.position, projectile.velocity, projectile.width + 16, projectile.height + 16); + projectile.Kill(); + } + + internal static void GenerateDustOnOwnerHand(Player player) + { + if (Main.dedServ) + return; + + Vector2 handOffset = Main.OffsetsPlayerOnhand[player.bodyFrame.Y / 56] * 2f; + if (player.direction != 1) + handOffset.X = player.bodyFrame.Width - handOffset.X; + if (player.gravDir != 1f) + handOffset.Y = player.bodyFrame.Height - handOffset.Y; + + handOffset -= new Vector2(player.bodyFrame.Width - player.width, player.bodyFrame.Height - player.height) / 2f; + Vector2 rotatedHandPosition = player.RotatedRelativePoint(player.position + handOffset, true); + for (int i = 0; i < 4; i++) + { + Dust dust = Dust.NewDustDirect(player.Center, 0, 0, (int)CalamityDusts.SulfurousSeaAcid, 0f, 0f, 150, default, 1.3f); + dust.position = rotatedHandPosition; + dust.velocity = Vector2.Zero; + dust.noGravity = true; + dust.fadeIn = 1f; + dust.velocity += player.velocity; + if (Main.rand.NextBool(2)) + { + dust.position += Utils.RandomVector2(Main.rand, -4f, 4f); + dust.scale += Main.rand.NextFloat(); + } + } + } + + internal void HandleProjectileVisuals() + { + float velocityAngle = projectile.velocity.ToRotation(); + projectile.rotation = velocityAngle + MathHelper.Pi; + projectile.frameCounter++; + if (projectile.frameCounter % 3 == 2) + { + projectile.frame++; + + // Die at the end of the final punch. + if (projectile.frame >= Main.projFrames[projectile.type]) + projectile.Kill(); + } + } + + internal void HandlePositioning() + { + projectile.Center = Owner.RotatedRelativePoint(Owner.MountedCenter); + projectile.Center += projectile.velocity.SafeNormalize(Vector2.UnitX * Owner.direction) * 30f; + } + #endregion + + #region Drawing + + // Manual drawing is used to correct the origin of the projectile when drawn. + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D punchTexture = ModContent.GetTexture(Texture); + Rectangle frame = punchTexture.Frame(1, Main.projFrames[projectile.type], 0, projectile.frame); + Vector2 origin = frame.Size() * 0.5f; + SpriteEffects directionEffect = projectile.spriteDirection == -1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None; + spriteBatch.Draw(punchTexture, projectile.Center - Main.screenPosition, frame, lightColor, projectile.rotation, origin, projectile.scale, directionEffect, 0f); + return false; + } + #endregion + + #region NPC Hit Collision Logic + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) => ReelBack(); + #endregion + } +} diff --git a/Projectiles/Melee/PhosphorescentGauntletPunches.png b/Projectiles/Melee/PhosphorescentGauntletPunches.png new file mode 100644 index 0000000000..ae775bc14a Binary files /dev/null and b/Projectiles/Melee/PhosphorescentGauntletPunches.png differ diff --git a/Projectiles/Melee/PhotonRipperGlowmask.png b/Projectiles/Melee/PhotonRipperGlowmask.png new file mode 100644 index 0000000000..3db63d70e2 Binary files /dev/null and b/Projectiles/Melee/PhotonRipperGlowmask.png differ diff --git a/Projectiles/Melee/PhotonRipperProjectile.cs b/Projectiles/Melee/PhotonRipperProjectile.cs new file mode 100644 index 0000000000..62588db1aa --- /dev/null +++ b/Projectiles/Melee/PhotonRipperProjectile.cs @@ -0,0 +1,220 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Melee +{ + public class PhotonRipperProjectile : ModProjectile + { + public Player Owner => Main.player[projectile.owner]; + public const int CrystalShootRate = 5; + public const int ChargeUpTime = 360; + public ref float Time => ref projectile.ai[0]; + public ref float OriginalDamage => ref projectile.ai[1]; + public float ChargeUpPower => MathHelper.Clamp((float)Math.Pow(Time / ChargeUpTime, 1.6D), 0f, 1f); + public override void SetStaticDefaults() => DisplayName.SetDefault("An extraordinarily cost inefficient chainsaw"); // Seriously though Draedon this seems a bit over the top lmfao. + + public override void SetDefaults() + { + projectile.width = 132; + projectile.height = 56; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.tileCollide = false; + projectile.melee = true; + projectile.ownerHitCheck = true; + projectile.usesIDStaticNPCImmunity = true; + projectile.idStaticNPCHitCooldown = 8; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D texture = Main.projectileTexture[projectile.type]; + Texture2D glowmaskTexture = ModContent.GetTexture("CalamityMod/Projectiles/Melee/PhotonRipperGlowmask"); + Rectangle glowmaskRectangle = glowmaskTexture.Frame(1, 6, 0, projectile.frame); + Vector2 origin = texture.Size() * 0.5f; + Vector2 drawPosition = projectile.Center - Main.screenPosition; + SpriteEffects direction = projectile.spriteDirection == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally; + + spriteBatch.Draw(texture, drawPosition, null, projectile.GetAlpha(lightColor), projectile.rotation, origin, projectile.scale, direction, 0f); + spriteBatch.Draw(glowmaskTexture, drawPosition, glowmaskRectangle, Color.White, projectile.rotation, origin, projectile.scale, direction, 0f); + return false; + } + + public override void AI() + { + PlayChainsawSounds(); + DetermineDamage(); + + // Determines the owner's position whilst incorporating their fullRotation field. + // It uses vector transformation on a Z rotation matrix based on said rotation under the hood. + // This is essentially just the pure mathematical definition of the RotatedBy method. + Vector2 playerRotatedPosition = Owner.RotatedRelativePoint(Owner.MountedCenter); + if (Main.myPlayer == projectile.owner) + { + if (Owner.channel && !Owner.noItems && !Owner.CCed) + HandleChannelMovement(playerRotatedPosition); + else + projectile.Kill(); + } + + DetermineVisuals(playerRotatedPosition); + ManipulatePlayerValues(); + EmitPrettyDust(); + + if (Time % CrystalShootRate == CrystalShootRate - 1f) + ReleasePrismTeeth(); + + // Prevent the projectile from dying normally. However, if anything for whatever reason + // goes wrong it will immediately be destroyed on the next frame. + projectile.timeLeft = 2; + + Time++; + } + + public void PlayChainsawSounds() + { + if (projectile.soundDelay <= 0) + { + Main.PlaySound(SoundID.Item22, projectile.Center); + projectile.soundDelay = (int)MathHelper.Lerp(30f, 12f, ChargeUpPower); + } + } + + public void DetermineDamage() + { + // Set the initial damage the moment it's created. + if (Main.myPlayer == projectile.owner && OriginalDamage == 0f) + { + OriginalDamage = projectile.damage; + projectile.netUpdate = true; + } + + // And then do time based damage calculations. This does not execute if the original damage is 0. + if (OriginalDamage != 0f) + projectile.damage = (int)MathHelper.SmoothStep(OriginalDamage * 0.36f, OriginalDamage, ChargeUpPower); + } + + public void DetermineVisuals(Vector2 playerRotatedPosition) + { + float directionAngle = projectile.velocity.ToRotation(); + projectile.rotation = directionAngle; + + int oldDirection = projectile.spriteDirection; + if (oldDirection == -1) + projectile.rotation += MathHelper.Pi; + + projectile.direction = projectile.spriteDirection = (Math.Cos(directionAngle) > 0).ToDirectionInt(); + + // If the direction differs from what it originaly was, undo the previous 180 degree turn. + // If this is not done, the chainsaw will have 1 frame of rotational "jitter" when the direction changes based on the + // original angle. This effect looks very strange in-game. + if (projectile.spriteDirection != oldDirection) + projectile.rotation -= MathHelper.Pi; + + // Positioning close to the player's arm. + projectile.position = playerRotatedPosition - projectile.Size * 0.5f + directionAngle.ToRotationVector2() * 30f; + + // Update the position a tiny bit every frame at random to make it look like the saw is vibrating. + // It is reset on the next frame. + projectile.position += Main.rand.NextVector2Circular(1.4f, 1.4f); + + // Update glowmask frames. + // Smoothstep is essentially like a linear interpolation but instead of being a straight line its + // curve is pseudo-logistic, with low increases at the ends of the curve. + projectile.frameCounter += (int)MathHelper.SmoothStep(12f, 33f, ChargeUpPower); + if (projectile.frameCounter >= 32) + { + projectile.frame = (projectile.frame + 1) % 6; + projectile.frameCounter = 0; + } + } + + public void HandleChannelMovement(Vector2 playerRotatedPosition) + { + Vector2 idealAimDirection = (Main.MouseWorld - playerRotatedPosition).SafeNormalize(Vector2.UnitX * Owner.direction); + + float angularAimVelocity = 0.15f; + float directionAngularDisparity = projectile.velocity.AngleBetween(idealAimDirection) / MathHelper.Pi; + + // Increase the turn speed if close to the ideal direction, since successive linear interpolations + // are asymptotic. + angularAimVelocity += MathHelper.Lerp(0f, 0.25f, Utils.InverseLerp(0.28f, 0.08f, directionAngularDisparity, true)); + + if (directionAngularDisparity > 0.02f) + projectile.velocity = Vector2.Lerp(projectile.velocity, idealAimDirection, angularAimVelocity); + else + projectile.velocity = idealAimDirection; + + projectile.velocity = projectile.velocity.SafeNormalize(Vector2.UnitX * Owner.direction); + } + + public void ManipulatePlayerValues() + { + Owner.itemRotation = (projectile.velocity * projectile.direction).ToRotation(); + Owner.itemTime = 2; + Owner.itemAnimation = 2; + Owner.ChangeDir(projectile.direction); + } + + public void EmitPrettyDust() + { + if (Main.dedServ) + return; + + for (int i = 0; i < 2; i++) + { + Vector2 spawnPosition = projectile.Center + projectile.velocity * 35f; + + // Spawn the dust a little bit on the chainsaw. X variance is less than Y variance to ensure that dust does not + // spawn too far from the blade. + spawnPosition += Main.rand.NextVector2CircularEdge(9f, 35f).RotatedBy(projectile.velocity.ToRotation() + MathHelper.PiOver2); + + Dust rainbowSpark = Dust.NewDustPerfect(spawnPosition, 261); + rainbowSpark.velocity = projectile.velocity * 3f + Main.rand.NextVector2CircularEdge(1.5f, 1.5f); + rainbowSpark.noGravity = true; + rainbowSpark.color = Main.hslToRgb((Time / 40f + Main.rand.NextFloat(-0.1f, 0.1f)) % 1f, 0.95f, 0.6f); + rainbowSpark.scale = Main.rand.NextFloat(0.9f, 1.25f); + } + } + + public void ReleasePrismTeeth() + { + // Play the sound that the crystal vile shard uses. + // Hopefully this isn't too cancerous to listen to, given the shoot rate of the crystals. + Main.PlaySound(SoundID.Item101, projectile.Center); + + if (Main.myPlayer != projectile.owner) + return; + + float shootReach = MathHelper.SmoothStep(projectile.width * 1.8f, projectile.width * 5.3f + 16f, ChargeUpPower); + + // Incorporate item shoot speed into the range of the crystals. + shootReach *= Owner.ActiveItem().shootSpeed; + + float distanceFromMouse = Owner.Distance(Main.MouseWorld); + + // If the distance to the mouse is less than the base reach, reach only to mouse. + // This way the player can more directly control the crystals if they want. + // This comes with a small constant offset to cancel out other factors. + if (distanceFromMouse < shootReach && distanceFromMouse > 40f) + shootReach = distanceFromMouse + 32f; + + Projectile.NewProjectile(Owner.Center, projectile.velocity, ModContent.ProjectileType(), projectile.damage / 2, 0f, projectile.owner, shootReach, projectile.whoAmI); + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + // Collision is done as a line to bypass the fact that hitboxes cannot rotate and that + // this projectile is notably flat in terms of sprite shape. + float _ = 0f; + float width = projectile.scale * 36f; + Vector2 start = projectile.Center; + Vector2 end = projectile.Center + projectile.velocity * 70f; + return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), start, end, width, ref _); + } + } +} diff --git a/Projectiles/Melee/PhotonRipperProjectile.png b/Projectiles/Melee/PhotonRipperProjectile.png new file mode 100644 index 0000000000..f0e5ea6ab4 Binary files /dev/null and b/Projectiles/Melee/PhotonRipperProjectile.png differ diff --git a/Projectiles/Melee/PrismRay.cs b/Projectiles/Melee/PrismRay.cs new file mode 100644 index 0000000000..7d3b81c3bd --- /dev/null +++ b/Projectiles/Melee/PrismRay.cs @@ -0,0 +1,209 @@ +using CalamityMod.Items; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +namespace CalamityMod.Projectiles.Melee +{ + public class PrismRay : ModProjectile + { + public Vector2 StartingPosition; + public Color RayColor => CalamityUtils.MulticolorLerp(RayHue, CalamityGlobalItem.ExoPalette); + public Color HueDownscaledRayColor => RayColor * 0.66f; + public ref float RayHue => ref projectile.ai[0]; + public ref float Time => ref projectile.localAI[1]; + public const int Lifetime = 30; + public override string Texture => "CalamityMod/Projectiles/StarProj"; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Prismatic Light"); + ProjectileID.Sets.MinionShot[projectile.type] = true; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 14; + projectile.alpha = 255; + projectile.penetrate = -1; + projectile.tileCollide = false; + projectile.ignoreWater = true; + projectile.timeLeft = 900; + projectile.friendly = true; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 10; + projectile.melee = true; + } + + public override void AI() + { + DelegateMethods.v3_1 = RayColor.ToVector3() * 0.5f; + Utils.PlotTileLine(StartingPosition, projectile.Center, 8f, DelegateMethods.CastLight); + if (projectile.localAI[0] == 0f) + { + projectile.direction = Main.rand.NextBool(2).ToDirectionInt(); + projectile.localAI[0] = 1f; + } + projectile.rotation = Time / 20f * MathHelper.TwoPi * projectile.direction; + projectile.alpha = Utils.Clamp(projectile.alpha - 18, 0, 255); + if (projectile.alpha == 0) + Lighting.AddLight(projectile.Center, RayColor.ToVector3() * 0.5f); + + for (int i = 0; i < 2; i++) + { + if (Main.rand.NextBool(10)) + { + Dust verticalMagic = Dust.NewDustDirect(projectile.Center, 0, 0, 267, 0f, 0f, 225, RayColor, 1.5f); + verticalMagic.noGravity = true; + verticalMagic.noLight = true; + verticalMagic.scale = projectile.Opacity; + verticalMagic.position = projectile.Center; + verticalMagic.velocity = Vector2.UnitY.RotatedBy(projectile.rotation + MathHelper.TwoPi * i / 2f) * 2.5f; + } + } + if (Main.rand.NextBool(10)) + { + Vector2 dustSpawnPosition = projectile.Center + Main.rand.NextVector2Unit() * Main.rand.NextFloat(20f, 120f); + Point dustTileCoords = dustSpawnPosition.ToTileCoordinates(); + bool canSpawnDust = true; + if (!WorldGen.InWorld(dustTileCoords.X, dustTileCoords.Y, 0)) + canSpawnDust = false; + + if (canSpawnDust && WorldGen.SolidTile(dustTileCoords.X, dustTileCoords.Y)) + canSpawnDust = false; + + if (canSpawnDust) + { + Dust risingMagic = Dust.NewDustDirect(dustSpawnPosition, 0, 0, 267, 0f, 0f, 127, RayColor, 1f); + risingMagic.noGravity = true; + risingMagic.position = dustSpawnPosition; + risingMagic.velocity = -Vector2.UnitY * Main.rand.NextFloat(1.6f, 7.5f); + risingMagic.fadeIn = Main.rand.NextFloat(1f, 2f); + risingMagic.scale = Main.rand.NextFloat(0.6f, 1.2f); + risingMagic.noLight = true; + + risingMagic = Dust.CloneDust(risingMagic); + risingMagic.scale *= 0.65f; + risingMagic.fadeIn *= 0.65f; + risingMagic.color = new Color(255, 255, 255, 255); + } + } + projectile.scale = projectile.Opacity * 0.5f; + projectile.velocity = Vector2.Zero; + + Time++; + if (Time >= Lifetime) + projectile.Kill(); + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + float _ = 0f; + return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), StartingPosition, projectile.Center, projectile.scale * 22f, ref _); + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Vector2 baseDrawPosition = projectile.Center + Vector2.UnitY * projectile.gfxOffY - Main.screenPosition; + Texture2D texture = Main.projectileTexture[projectile.type]; + Rectangle frame = texture.Frame(1, Main.projFrames[projectile.type], 0, projectile.frame); + Vector2 origin = frame.Size() / 2f; + Color fadedRayColor = projectile.GetAlpha(lightColor); + Color fullbrightRayColor = HueDownscaledRayColor.MultiplyRGBA(new Color(255, 255, 255, 0)); + + // Draw the stars at the end of the laser. + for (int i = 0; i < 6; i++) + { + Vector2 drawPosition = baseDrawPosition + (MathHelper.TwoPi * i / 6f + Main.GlobalTime * 3f).ToRotationVector2() * projectile.scale * 4f; + spriteBatch.Draw(texture, drawPosition, frame, fullbrightRayColor, projectile.rotation, origin, projectile.scale * 2f, SpriteEffects.None, 0f); + spriteBatch.Draw(texture, drawPosition, frame, fullbrightRayColor, 0f, origin, projectile.scale * 2f, SpriteEffects.None, 0f); + } + + // Draw the shimmering ray itself. + if (projectile.Opacity > 0.3f) + { + Vector2 drawOffset = (StartingPosition - projectile.Center) * 0.5f; + Vector2 scale = new Vector2(1f, drawOffset.Length() * 2f / texture.Height); + float rotation = drawOffset.ToRotation() + MathHelper.PiOver2; + + // This factor causes the opacity to flash rather quickly. + float drawFade = MathHelper.Clamp(MathHelper.Distance(Lifetime * 0.5f, Time) / (Lifetime * 0.667f), 0f, 1f); + + for (int i = 0; i < 3; i++) + { + Vector2 drawPosition = baseDrawPosition; + drawPosition += (MathHelper.TwoPi * i / 3f + Main.GlobalTime * 3f).ToRotationVector2() * projectile.scale * 2.5f; + drawPosition += drawOffset; + + spriteBatch.Draw(texture, drawPosition, frame, fullbrightRayColor * drawFade * 0.8f, rotation, origin, scale, SpriteEffects.None, 0f); + spriteBatch.Draw(texture, drawPosition, frame, fadedRayColor * drawFade * 0.8f, rotation, origin, scale * 0.5f, SpriteEffects.None, 0f); + } + } + return false; + } + + public override void Kill(int timeLeft) + { + CreateKillExplosionBurstDust(Main.rand.Next(7, 13)); + + // Adjust values and do damage before dying. + if (Main.myPlayer != projectile.owner) + return; + + Vector2 oldSize = projectile.Size; + projectile.position = projectile.Center; + projectile.width = projectile.height = 60; + projectile.Center = projectile.position; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 10; + projectile.Damage(); + projectile.position = projectile.Center; + projectile.Size = oldSize; + projectile.Center = projectile.position; + } + + public void CreateKillExplosionBurstDust(int dustCount) + { + if (Main.dedServ) + return; + + Vector2 baseExplosionDirection = -Vector2.UnitY.RotatedByRandom(MathHelper.Pi) * 3f; + Vector2 outwardFireSpeedFactor = new Vector2(2.1f, 2f); + Color brightenedRayColor = RayColor; + brightenedRayColor.A = 255; + + for (float i = 0f; i < dustCount; i++) + { + Dust explosionDust = Dust.NewDustDirect(projectile.Center, 0, 0, 267, 0f, 0f, 0, brightenedRayColor, 1f); + explosionDust.position = projectile.Center; + explosionDust.velocity = baseExplosionDirection.RotatedBy(MathHelper.TwoPi * i / dustCount) * outwardFireSpeedFactor * Main.rand.NextFloat(0.8f, 1.2f); + explosionDust.noGravity = true; + explosionDust.scale = 1.1f; + explosionDust.fadeIn = Main.rand.NextFloat(1.4f, 2.4f); + + explosionDust = Dust.CloneDust(explosionDust); + explosionDust.scale /= 2f; + explosionDust.fadeIn /= 2f; + explosionDust.color = new Color(255, 255, 255, 255); + } + for (float i = 0f; i < dustCount; i++) + { + Dust explosionDust = Dust.NewDustDirect(projectile.Center, 0, 0, 267, 0f, 0f, 0, brightenedRayColor, 1f); + explosionDust.position = projectile.Center; + explosionDust.velocity = baseExplosionDirection.RotatedBy(MathHelper.TwoPi * i / dustCount) * outwardFireSpeedFactor * Main.rand.NextFloat(0.8f, 1.2f); + explosionDust.velocity *= Main.rand.NextFloat() * 0.8f; + explosionDust.noGravity = true; + explosionDust.scale = Main.rand.NextFloat(); + explosionDust.fadeIn = Main.rand.NextFloat(1.4f, 2.4f); + + explosionDust = Dust.CloneDust(explosionDust); + explosionDust.scale /= 2f; + explosionDust.fadeIn /= 2f; + explosionDust.color = new Color(255, 255, 255, 255); + } + } + + public override Color? GetAlpha(Color lightColor) => new Color(projectile.Opacity, projectile.Opacity, projectile.Opacity, 0); + } +} diff --git a/Projectiles/Melee/PrismTooth.cs b/Projectiles/Melee/PrismTooth.cs new file mode 100644 index 0000000000..a7ac09c06d --- /dev/null +++ b/Projectiles/Melee/PrismTooth.cs @@ -0,0 +1,139 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.GameContent.Achievements; +using Terraria.Graphics.Shaders; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Melee +{ + public class PrismTooth : ModProjectile + { + internal PrimitiveTrail TrailDrawer; + public const int Lifetime = 80; + public Player Owner => Main.player[projectile.owner]; + public ref float ShootReach => ref projectile.ai[0]; + public ref float Time => ref projectile.ai[1]; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Prism Tooth"); + ProjectileID.Sets.TrailingMode[projectile.type] = 2; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 36; + } + + public override void SetDefaults() + { + projectile.scale = 0.6f; + projectile.width = projectile.height = 40; + projectile.friendly = true; + projectile.tileCollide = false; + projectile.penetrate = -1; + projectile.extraUpdates = 5; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 4 * projectile.MaxUpdates; + projectile.timeLeft = Lifetime; + projectile.melee = true; + } + + public override void AI() + { + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.Pi * Time / Lifetime; + + Vector2 baseDirection = (MathHelper.TwoPi * Time / Lifetime - MathHelper.PiOver2).ToRotationVector2(); + baseDirection.X *= 0.25f; + + // Constrain the Y offset into the bounds of 0-1 instead of -1-1. This prevents + // the crystal from flying behind the owner. In this context, the Y offset becomes how far away the + // crystal is from its own in terms of reach. + baseDirection.Y = baseDirection.Y * 0.5f + 0.5f; + Vector2 positionOffset = baseDirection * ShootReach; + + // Don't allow the X offset to go too far. + // This hard limit turns the squashed circle into bending, semi-rectangular shape. + if (Math.Abs(positionOffset.X) > 45f) + positionOffset.X = Math.Sign(baseDirection.X) * 45f; + + // In this context, the velocity is simply the initial direction as a unit vector- it does not + // actually influence movement in any way. + positionOffset = positionOffset.RotatedBy(projectile.velocity.ToRotation() - MathHelper.PiOver2); + + projectile.Center = Owner.RotatedRelativePoint(Owner.MountedCenter) + projectile.velocity * 42f + positionOffset; + projectile.Opacity = Utils.InverseLerp(0f, 12f, Time, true) * Utils.InverseLerp(Lifetime, Lifetime - 12f, Time, true); + + // Destroy trees within the range of the past 20 oldPos positions. + for (int i = 0; i < 20; i++) + { + Point pointToCheck = (projectile.oldPos[i] + projectile.Size * 0.5f).ToTileCoordinates(); + AbsolutelyFuckingAnnihilateTrees(pointToCheck.X, pointToCheck.Y); + } + + // Emit light. + Lighting.AddLight(projectile.Center, Vector3.One * 0.7f); + + Time++; + } + + public void AbsolutelyFuckingAnnihilateTrees(int x, int y) + { + Tile tileAtPosition = CalamityUtils.ParanoidTileRetrieval(x, y); + + // Ignore tiles that are not active and are not breakable by axes. + if (!tileAtPosition.active() || !Main.tileAxe[tileAtPosition.type]) + return; + + // Don't attempt to mine the tile if for whatever reason it's not supposed to be broken. + if (!WorldGen.CanKillTile(x, y)) + return; + + AchievementsHelper.CurrentlyMining = true; + + WorldGen.KillTile(x, y); + if (Main.netMode == NetmodeID.MultiplayerClient) + NetMessage.SendData(MessageID.TileChange, -1, -1, null, 0, x, y); + + AchievementsHelper.CurrentlyMining = false; + } + + public override Color? GetAlpha(Color lightColor) => Color.White; + + internal float WidthFunction(float completionRatio) => projectile.scale * 24f * (1f - Utils.InverseLerp(0.7f, 1f, completionRatio, true)) + 1f; + + internal Color ColorFunction(float completionRatio) + { + float hue = (projectile.identity % 9f / 9f + completionRatio * 0.7f) % 1f; + return Color.Lerp(Color.White, Main.hslToRgb(hue, 0.95f, 0.55f), 0.35f) * projectile.Opacity; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + if (Time <= 5f) + return true; + + if (TrailDrawer is null) + TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:PrismaticStreak"]); + + // Variable adjustment vector used to prevent the trail for starting somewhat that isn't behind + // the crystal. This may appear in small amounts, with offsets of a few pixels, but at the speed + // these crystals go, it's probably not something to worry too much about. + Vector2 generalOffset = projectile.rotation.ToRotationVector2().RotatedBy(MathHelper.PiOver2) * 15f; + generalOffset += projectile.rotation.ToRotationVector2() * -5f * (float)Math.Sin(projectile.rotation); + + // Mess with the oldPos array so that the trail always points towards the crystal. + Vector2 oldPosition = projectile.oldPos[1]; + projectile.oldPos[1] = projectile.oldPos[0] - projectile.rotation.ToRotationVector2() * Vector2.Distance(projectile.oldPos[0], projectile.oldPos[1]); + + // Revert back if the above calculations caused any NaNs. + if (projectile.oldPos[1].HasNaNs()) + projectile.oldPos[1] = oldPosition; + + GameShaders.Misc["CalamityMod:PrismaticStreak"].SetShaderTexture(ModContent.GetTexture("CalamityMod/ExtraTextures/ScarletDevilStreak")); + TrailDrawer.Draw(projectile.oldPos, projectile.Size * 0.5f + generalOffset - Main.screenPosition, 65); + return true; + } + + // Prevent the crystals from utilizing velocity. Their movement is entirely dependant on Center setting. + public override bool ShouldUpdatePosition() => false; + } +} diff --git a/Projectiles/Melee/PrismTooth.png b/Projectiles/Melee/PrismTooth.png new file mode 100644 index 0000000000..3201a55ae9 Binary files /dev/null and b/Projectiles/Melee/PrismTooth.png differ diff --git a/Projectiles/Melee/SpineOfThanatosBody1.png b/Projectiles/Melee/SpineOfThanatosBody1.png new file mode 100644 index 0000000000..4aae688469 Binary files /dev/null and b/Projectiles/Melee/SpineOfThanatosBody1.png differ diff --git a/Projectiles/Melee/SpineOfThanatosBody1Glowmask.png b/Projectiles/Melee/SpineOfThanatosBody1Glowmask.png new file mode 100644 index 0000000000..23eaaf6294 Binary files /dev/null and b/Projectiles/Melee/SpineOfThanatosBody1Glowmask.png differ diff --git a/Projectiles/Melee/SpineOfThanatosBody2.png b/Projectiles/Melee/SpineOfThanatosBody2.png new file mode 100644 index 0000000000..17382a5519 Binary files /dev/null and b/Projectiles/Melee/SpineOfThanatosBody2.png differ diff --git a/Projectiles/Melee/SpineOfThanatosBody2Glowmask.png b/Projectiles/Melee/SpineOfThanatosBody2Glowmask.png new file mode 100644 index 0000000000..d12dd42818 Binary files /dev/null and b/Projectiles/Melee/SpineOfThanatosBody2Glowmask.png differ diff --git a/Projectiles/Melee/SpineOfThanatosProjectile.cs b/Projectiles/Melee/SpineOfThanatosProjectile.cs new file mode 100644 index 0000000000..80a001416c --- /dev/null +++ b/Projectiles/Melee/SpineOfThanatosProjectile.cs @@ -0,0 +1,223 @@ +using CalamityMod.DataStructures; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Melee +{ + public class SpineOfThanatosProjectile : ModProjectile + { + public List WhipPoints = new List(); + public Player Owner => Main.player[projectile.owner]; + public float CurrentBendFactor => MaximumBendFactor * CalamityUtils.Convert01To010(Time / Lifetime); + public Vector2 WhipEnd => projectile.Center + WhipOutwardness; + + // This wrapper exists solely for clarity as to the definition of velocity in the context of this projectile. + // You may notice that the Center property of this projectile is constantly set to be near the player. However, since + // ShouldUpdatePosition is not overriden to false, it still gains its velocity as usual for 1 frame before being reset again. + public ref Vector2 WhipOutwardness => ref projectile.velocity; + public ref float Time => ref projectile.ai[0]; + public ref float SwingDirection => ref projectile.ai[1]; + public ref float InitialDirectionRotation => ref projectile.localAI[0]; + public const int Lifetime = 125; + public const int FlyBackTime = 40; + public const int FinalWhipRayShootRate = 10; + public const int LaserRayCount = 12; + public const float MaximumBendFactor = 42f; + public override void SetStaticDefaults() => DisplayName.SetDefault("Spine of Thanatos"); + + public override void SetDefaults() + { + projectile.width = 58; + projectile.height = 70; + projectile.scale = 0.75f; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.tileCollide = false; + projectile.melee = true; + projectile.extraUpdates = 2; + projectile.timeLeft = Lifetime; + projectile.ownerHitCheck = true; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 22; + } + + public void DetermineWhipPoints() + { + Vector2 startingPosition = Owner.RotatedRelativePoint(Owner.MountedCenter); + + List initialPoints = new List() + { + startingPosition + }; + for (int i = 0; i < 12; i++) + { + Vector2 bendOffset = Vector2.UnitX * -SwingDirection; + + // Make the bend factor depend on how far along the generated positions we are. + // The maximum bend should be halfway across the chain. + bendOffset *= CurrentBendFactor * CalamityUtils.Convert01To010(i / 12f); + + // Smoothly zero out the bending effects if the current position is near the owner. + bendOffset *= Utils.InverseLerp(0f, 300f, Owner.Distance(Vector2.Lerp(startingPosition, projectile.Center, i / 12f) + bendOffset), true); + initialPoints.Add(Vector2.Lerp(startingPosition, projectile.Center, i / 12f) + bendOffset); + } + initialPoints.Add(projectile.Center); + + BezierCurve bezierCurve = new BezierCurve(initialPoints.ToArray()); + int totalChains = (int)(projectile.Distance(startingPosition) / 24f / projectile.scale); + totalChains = (int)MathHelper.Clamp(totalChains, 40f, 440f); + + WhipPoints = bezierCurve.GetPoints(totalChains); + } + + public override void AI() + { + DetermineWhipPoints(); + + // Determines the owner's position whilst incorporating their fullRotation field. + // It uses vector transformation on a Z rotation matrix based on said rotation under the hood. + // This is essentially just the pure mathematical definition of the RotatedBy method. + Vector2 playerRotatedPosition = Owner.RotatedRelativePoint(Owner.MountedCenter); + if (Main.myPlayer == projectile.owner) + { + if (!Owner.noItems && !Owner.CCed) + HandleChannelMovement(playerRotatedPosition); + else + projectile.Kill(); + } + + ManipulatePlayerValues(); + + // Create a bunch of prismatic lasers outward from the non-arcing whip right before it comes back + // to its owner. + if (SwingDirection == 0f && projectile.timeLeft == FlyBackTime) + CreateBadassPrismExplosion(); + Time++; + } + + public void HandleChannelMovement(Vector2 playerRotatedPosition) + { + // Set the initial direction as a base for rotation. + if (InitialDirectionRotation == 0f) + InitialDirectionRotation = WhipOutwardness.ToRotation() - MathHelper.PiOver2; + + float attackCompletionRatio = Utils.InverseLerp(Lifetime, FlyBackTime, projectile.timeLeft, true); + + // Normally swing from a "cone" to a collision area that causes both whips to collide. + float baseSwingAngle = MathHelper.Lerp(-1.1f, 1.57f, 1f - attackCompletionRatio); + + Vector2 swingDirection = (SwingDirection * baseSwingAngle + MathHelper.PiOver2).ToRotationVector2(); + swingDirection = swingDirection.RotatedBy(InitialDirectionRotation); + + // If the whip is ready to return to its owner, have its outwardness approach the player again. + if (projectile.timeLeft < FlyBackTime) + WhipOutwardness = Vector2.Lerp(WhipOutwardness, InitialDirectionRotation.ToRotationVector2(), 0.1f); + else + { + // Have acceleration vary based on how much time has passed. + Vector2 swingSpeedIncrement = swingDirection * MathHelper.SmoothStep(3.8f, 13f, (float)Math.Pow(CalamityUtils.Convert01To010(Time / Lifetime), 8f)); + if (SwingDirection == 0f) + swingSpeedIncrement *= 0.84f; + WhipOutwardness += swingSpeedIncrement; + } + projectile.Center = playerRotatedPosition; + projectile.rotation = WhipOutwardness.ToRotation(); + } + + public void ManipulatePlayerValues() + { + Owner.itemTime = 2; + Owner.itemAnimation = 2; + if (SwingDirection == 0f) + { + Owner.itemRotation = WhipOutwardness.ToRotation() * projectile.direction; + Owner.ChangeDir(projectile.direction); + } + } + + public void CreateBadassPrismExplosion() + { + var sound = Main.PlaySound(SoundID.DD2_DarkMageHealImpact, Owner.Center); + if (sound != null) + sound.Pitch = MathHelper.Clamp(sound.Pitch + 0.15f, 0f, 1f); + + if (Main.myPlayer != projectile.owner) + return; + + Projectile.NewProjectile(WhipEnd, Vector2.Zero, ModContent.ProjectileType(), projectile.damage * 2, 0f, projectile.owner); + + // Fire a bunch of rays rays. + int rayDamage = (int)(projectile.damage * 1.5); + NPC potentialTarget = WhipEnd.ClosestNPCAt(700f); + for (int i = 0; i < LaserRayCount; i++) + { + float rayRotation = projectile.rotation + MathHelper.Lerp(-0.57f, 0.57f, i / (float)LaserRayCount); + float targetAimDisparity = 0f; + if (potentialTarget != null) + targetAimDisparity = projectile.rotation.ToRotationVector2().AngleBetween((potentialTarget.Center - WhipEnd).SafeNormalize(Vector2.Zero)); + + // By default, make the prism rays go outward a good amount based on their rotation + // to give a fan look. + Vector2 prismEndPosition = WhipEnd + rayRotation.ToRotationVector2() * 420f; + + // However, if a potential target is within the general line of sight of the whip, + // fire all lasers at it instead. This results in the entire laser spectrum appearing as one + // brilliant, blazing laser that does great damage. However, it does take some skill to do. + if (potentialTarget != null && targetAimDisparity < MathHelper.Pi * 0.27f) + prismEndPosition = potentialTarget.Center + potentialTarget.velocity * 4f; + + int prismRay = Projectile.NewProjectile(prismEndPosition, Vector2.Zero, ModContent.ProjectileType(), rayDamage, projectile.knockBack * 0.2f, projectile.owner); + if (Main.projectile.IndexInRange(prismRay)) + { + Main.projectile[prismRay].ModProjectile().RayHue = i / (float)LaserRayCount; + Main.projectile[prismRay].ModProjectile().StartingPosition = WhipEnd; + } + } + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + for (int i = 0; i < WhipPoints.Count - 1; i++) + { + string whipTexturePath; + if (i == WhipPoints.Count - 2) + whipTexturePath = Texture; + else if (i == 0) + whipTexturePath = "CalamityMod/Projectiles/Melee/SpineOfThanatosTail"; + else + whipTexturePath = $"CalamityMod/Projectiles/Melee/SpineOfThanatosBody{i % 2 + 1}"; + Texture2D whipSegmentTexture = ModContent.GetTexture(whipTexturePath); + Texture2D whipSegmentGlowmaskTexture = ModContent.GetTexture($"{whipTexturePath}Glowmask"); + + Vector2 origin = whipSegmentTexture.Size() * 0.5f; + float rotation = (WhipPoints[i + 1] - WhipPoints[i]).ToRotation() + MathHelper.PiOver2; + Vector2 drawPosition = WhipPoints[i] - Main.screenPosition; + Color color = projectile.GetAlpha(Lighting.GetColor((int)WhipPoints[i].X / 16, (int)WhipPoints[i].Y / 16)); + spriteBatch.Draw(whipSegmentTexture, drawPosition, null, color, rotation, origin, projectile.scale, SpriteEffects.None, 0f); + spriteBatch.Draw(whipSegmentGlowmaskTexture, drawPosition, null, Color.White, rotation, origin, projectile.scale, SpriteEffects.None, 0f); + } + + return false; + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + if (WhipPoints.Count <= 1) + return false; + + float width = projectile.scale * 38f; + for (int i = 0; i < WhipPoints.Count - 1; i++) + { + float _ = 0f; + if (Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), WhipPoints[i], WhipPoints[i + 1], width, ref _)) + return true; + } + return false; + } + } +} diff --git a/Projectiles/Melee/SpineOfThanatosProjectile.png b/Projectiles/Melee/SpineOfThanatosProjectile.png new file mode 100644 index 0000000000..749cc7be1b Binary files /dev/null and b/Projectiles/Melee/SpineOfThanatosProjectile.png differ diff --git a/Projectiles/Melee/SpineOfThanatosProjectileGlowmask.png b/Projectiles/Melee/SpineOfThanatosProjectileGlowmask.png new file mode 100644 index 0000000000..18a7157c07 Binary files /dev/null and b/Projectiles/Melee/SpineOfThanatosProjectileGlowmask.png differ diff --git a/Projectiles/Melee/SpineOfThanatosTail.png b/Projectiles/Melee/SpineOfThanatosTail.png new file mode 100644 index 0000000000..2f7adf9370 Binary files /dev/null and b/Projectiles/Melee/SpineOfThanatosTail.png differ diff --git a/Projectiles/Melee/SpineOfThanatosTailGlowmask.png b/Projectiles/Melee/SpineOfThanatosTailGlowmask.png new file mode 100644 index 0000000000..7d1ac8f4b8 Binary files /dev/null and b/Projectiles/Melee/SpineOfThanatosTailGlowmask.png differ diff --git a/Projectiles/Melee/TaintedBladeSlasher.cs b/Projectiles/Melee/TaintedBladeSlasher.cs new file mode 100644 index 0000000000..7d493cda46 --- /dev/null +++ b/Projectiles/Melee/TaintedBladeSlasher.cs @@ -0,0 +1,283 @@ +using CalamityMod.CalPlayer; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.IO; +using Terraria; +using Terraria.Graphics.Shaders; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Melee +{ + public class TaintedBladeSlasher : ModProjectile + { + internal PrimitiveTrail TrailDrawer = null; + public ref float SwordItemID => ref projectile.ai[1]; + public ref float VerticalOffset => ref projectile.localAI[0]; + public ref float Time => ref projectile.localAI[1]; + public float AttackCompletionRatio => 1f - Owner.itemAnimation / (float)Owner.itemAnimationMax; + public Player Owner => Main.player[projectile.owner]; + public int Variant => (int)projectile.ai[0] % 2; + + public const float ForearmLength = 80f; + public const float ArmLength = 108f; + + public Rectangle BladeFrame + { + get + { + Texture2D bladeTexture = Main.itemTexture[(int)SwordItemID]; + Rectangle bladeFrame = bladeTexture.Frame(1, 1, 0, 0); + bool hasMultipleFrames = Main.itemAnimations[(int)SwordItemID] != null; + if (hasMultipleFrames) + bladeFrame = Main.itemAnimations[(int)SwordItemID].GetFrame(bladeTexture); + return bladeFrame; + } + } + + public Vector2 BackArmAimPosition + { + get + { + Vector2 baseAimPosition = Owner.Top + new Vector2(-Owner.direction * (ForearmLength + Math.Abs(VerticalOffset) * 0.55f), -27f); + if (Variant == 1) + baseAimPosition.Y += 30f; + if (Owner.itemAnimation == 0) + return baseAimPosition; + + Vector2 endSwingPosition = Owner.Center + Vector2.UnitX * Owner.direction * 510f; + return Vector2.SmoothStep(baseAimPosition, endSwingPosition, Utils.InverseLerp(0f, 0.67f, AttackCompletionRatio, true) * Utils.InverseLerp(1f, 0.67f, AttackCompletionRatio, true)); + } + } + public Vector2 IdleMoveOffset + { + get + { + Vector2 offset = Owner.itemAnimation == 0 ? (Time / 27f).ToRotationVector2() * new Vector2(5f, 4f) : Vector2.Zero; + if (Variant == 1) + offset += Vector2.UnitX * Owner.direction * (1f - AttackCompletionRatio) * 40f; + return offset; + } + } + public Vector2 FrontArmEnd + { + get + { + float backArmRotation = Owner.AngleTo(BackArmAimPosition); + Vector2 fromArmDrawPosition = Owner.Center + backArmRotation.ToRotationVector2() * ForearmLength; + Vector2 backOffset = (projectile.Center - fromArmDrawPosition).SafeNormalize(Vector2.Zero) * ArmLength + IdleMoveOffset; + return fromArmDrawPosition + backOffset; + } + } + public Vector2 BladeOffsetDirection + { + get + { + float backArmRotation = Owner.AngleTo(BackArmAimPosition); + Vector2 fromArmDrawPosition = Owner.Center + backArmRotation.ToRotationVector2() * ForearmLength; + Vector2 backOffset = (projectile.Center - fromArmDrawPosition).SafeNormalize(Vector2.Zero) * ArmLength + IdleMoveOffset; + float bladeRotation = backOffset.ToRotation() - MathHelper.PiOver4 + MathHelper.Pi; + return -(bladeRotation + MathHelper.PiOver4 + BladeRotationOffset).ToRotationVector2(); + } + } + public Vector2 BladeCenterPosition + { + get + { + float offsetFactor = BladeFrame.Height / 4f + 31f; + return FrontArmEnd + BladeOffsetDirection * offsetFactor; + } + } + public float BladeRotationOffset => MathHelper.Lerp(MathHelper.PiOver2, 0f, Utils.InverseLerp(0f, 0.17f, 1f - AttackCompletionRatio, true)) * -Owner.direction; + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Blade"); + ProjectileID.Sets.TrailingMode[projectile.type] = 2; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 70; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 4; + projectile.friendly = true; + projectile.melee = true; + projectile.tileCollide = false; + projectile.penetrate = -1; + projectile.timeLeft = 90000; + projectile.usesLocalNPCImmunity = true; + projectile.noEnchantments = true; + } + + public override void SendExtraAI(BinaryWriter writer) => writer.Write(VerticalOffset); + + public override void ReceiveExtraAI(BinaryReader reader) => VerticalOffset = reader.ReadSingle(); + + public override void AI() + { + CalamityPlayerMiscEffects.EnchantHeldItemEffects(Owner, Owner.Calamity(), Owner.ActiveItem()); + if (!Owner.Calamity().bladeArmEnchant || Owner.ActiveItem().type != SwordItemID || Owner.CCed || !Owner.active || Owner.dead) + { + projectile.Kill(); + return; + } + + float swingOffsetAngle = MathHelper.SmoothStep(-1.87f, 3.79f, AttackCompletionRatio); + + // Offset a little bit angularly if the secondary variant to prevent complete overlap. + if (Variant == 1) + swingOffsetAngle -= 0.7f; + swingOffsetAngle *= Owner.direction; + swingOffsetAngle = MathHelper.Lerp(0f, swingOffsetAngle, Utils.InverseLerp(0f, 0.16f, AttackCompletionRatio, true)); + + if (Owner.itemAnimation == 0) + swingOffsetAngle = 0f; + + Vector2 destination = Owner.Center; + + if (Owner.itemAnimation == 0) + { + destination.X += Owner.direction * (VerticalOffset * 0.6f + 180f); + destination.Y += 330f + VerticalOffset; + if (Variant == 1) + destination.Y += 540f; + + // The blade can be kept in a static location when not being swung. + // This can result in insane damage coming from "poking" enemies. + // To accomodate for this, the hit countdown is increased when not attacking. + projectile.localNPCHitCooldown = 24; + } + else + { + // Swing around in an arc as needed. + // One arm extends a little bit further than the other. + destination -= Vector2.UnitY.RotatedBy(swingOffsetAngle) * 600f; + + // Make a fire/swing sound. + if (Owner.itemAnimation == 21) + Main.PlaySound(SoundID.DD2_FlameburstTowerShot, Owner.Center); + projectile.localNPCHitCooldown = 3; + } + + if (AttackCompletionRatio < 0.16f) + projectile.oldPos = new Vector2[projectile.oldPos.Length]; + + // Very, very quickly approach the swing destination while attacking. + // Also gain a temporary extra update. + if (Owner.itemAnimation > 0) + { + projectile.Center = Vector2.Lerp(projectile.Center, destination, 0.19f); + projectile.extraUpdates = 1; + } + + // Idly move towards the destination. + if (projectile.Center != destination) + projectile.Center += (destination - projectile.Center).SafeNormalize(Vector2.Zero) * MathHelper.Min(projectile.Distance(destination), 12f + Owner.velocity.Length()); + + // Ensure that the position is never too far from the destination. + CalamityUtils.DistanceClamp(ref projectile.position, ref destination, 50f); + + Time++; + } + + internal float PrimitiveWidthFunction(float completionRatio) => BladeFrame.Height * 0.47f; + + internal Color PrimitiveColorFunction(float completionRatio) + { + float opacity = Utils.InverseLerp(0.8f, 0.52f, completionRatio, true) * Utils.InverseLerp(1f, 0.81f, AttackCompletionRatio, true); + Color startingColor = Color.Lerp(Color.Red, Color.DarkRed, 0.4f); + Color endingColor = Color.Lerp(Color.DarkRed, Color.Purple, 0.77f); + return Color.Lerp(startingColor, endingColor, (float)Math.Pow(completionRatio, 0.37f)) * opacity; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + if (TrailDrawer is null) + TrailDrawer = new PrimitiveTrail(PrimitiveWidthFunction, PrimitiveColorFunction, specialShader: GameShaders.Misc["CalamityMod:FadingSolidTrail"]); + + Texture2D forearmTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/TaintedForearm"); + Texture2D armTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/TaintedArm"); + Texture2D handTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/TaintedHand"); + + // Reflect the 1st hand variant horizontally. + SpriteEffects handDirection = SpriteEffects.None; + if (Variant == (Owner.direction == -1).ToInt()) + { + handTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/TaintedHand2"); + handDirection = SpriteEffects.FlipHorizontally; + } + Texture2D bladeTexture = Main.itemTexture[(int)SwordItemID]; + + // Draw the arms. + float backArmRotation = Owner.AngleTo(BackArmAimPosition); + spriteBatch.Draw(forearmTexture, Owner.Center - Main.screenPosition, null, Color.White, backArmRotation - MathHelper.PiOver2, Vector2.UnitX * forearmTexture.Size() * 0.5f, projectile.scale, SpriteEffects.None, 0f); + + Vector2 frontArmDrawPosition = Owner.Center + backArmRotation.ToRotationVector2() * ForearmLength + IdleMoveOffset; + float frontArmRotation = projectile.AngleFrom(frontArmDrawPosition); + spriteBatch.Draw(armTexture, frontArmDrawPosition - Main.screenPosition, null, Color.White, frontArmRotation - MathHelper.PiOver2, Vector2.UnitX * armTexture.Size() * 0.5f, projectile.scale, SpriteEffects.None, 0f); + + float handRotation = frontArmRotation + MathHelper.PiOver2 + MathHelper.Pi; + float bladeRotation = handRotation - MathHelper.PiOver4 + MathHelper.Pi + BladeRotationOffset; + if (Owner.direction == -1) + bladeRotation += MathHelper.PiOver2; + + // Draw the trail behind the blade. + if (Owner.itemAnimation > 0) + { + GameShaders.Misc["CalamityMod:FadingSolidTrail"].SetShaderTexture(ModContent.GetTexture("CalamityMod/ExtraTextures/BladeTrailUVMap")); + GameShaders.Misc["CalamityMod:FadingSolidTrail"].Shader.Parameters["shouldFlip"].SetValue((float)(Owner.direction == -1).ToInt()); + + Vector2 bottom = BladeCenterPosition - BladeOffsetDirection * BladeFrame.Height * 0.5f - Main.screenPosition; + Vector2 top = BladeCenterPosition + BladeOffsetDirection * BladeFrame.Height * 0.5f - Main.screenPosition; + Vector2 offsetToBlade = (top - bottom).SafeNormalize(Vector2.Zero).RotatedBy(MathHelper.PiOver2) * 5f; + + TrailDrawer.OverridingStickPointStart = BladeCenterPosition - BladeOffsetDirection * BladeFrame.Height * 0.5f + offsetToBlade - Main.screenPosition; + TrailDrawer.OverridingStickPointEnd = BladeCenterPosition + BladeOffsetDirection * BladeFrame.Height * 0.5f + offsetToBlade - Main.screenPosition; + + // Swap the ends if needed so that the trail faces the right direction. + if (Owner.direction == -1) + Utils.Swap(ref TrailDrawer.OverridingStickPointStart, ref TrailDrawer.OverridingStickPointEnd); + + Vector2[] drawPoints = new Vector2[projectile.oldPos.Length]; + Vector2 perpendicularDirection = BladeOffsetDirection.SafeNormalize(Vector2.UnitY).RotatedBy(MathHelper.PiOver2); + for (int i = 1; i < drawPoints.Length; i++) + { + if (projectile.oldPos[i] == Vector2.Zero) + continue; + + drawPoints[i] = projectile.Center + perpendicularDirection.RotatedBy(i * -0.014f * Owner.direction) * i * -Owner.direction * 6f; + } + + TrailDrawer.Draw(drawPoints, BladeCenterPosition - projectile.position - Main.screenPosition, 67); + } + + // Draw the blade. + Vector2 bladeDrawPosition = BladeCenterPosition - Main.screenPosition; + SpriteEffects bladeDirection = Owner.direction == -1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None; + spriteBatch.Draw(bladeTexture, bladeDrawPosition, BladeFrame, Color.White, bladeRotation, BladeFrame.Size() * 0.5f, projectile.scale, bladeDirection, 0f); + + // Draw the hand. + spriteBatch.Draw(handTexture, FrontArmEnd - Main.screenPosition, null, projectile.GetAlpha(Color.White), handRotation, handTexture.Size() * 0.5f, projectile.scale, handDirection, 0f); + return false; + } + + // Register collision at the blade's position. + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + Vector2 start = BladeCenterPosition - BladeOffsetDirection * BladeFrame.Height * 0.5f; + Vector2 end = BladeCenterPosition + BladeOffsetDirection * BladeFrame.Height * 0.5f; + float width = 60f; + float _ = 0f; + return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), start, end, width, ref _); + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + ItemLoader.OnHitNPC(Owner.ActiveItem(), Owner, target, damage, knockback, crit); + NPCLoader.OnHitByItem(target, Owner, Owner.ActiveItem(), damage, knockback, crit); + PlayerHooks.OnHitNPC(Owner, Owner.ActiveItem(), target, damage, knockback, crit); + } + } +} diff --git a/Projectiles/Melee/ThanatosBoom.cs b/Projectiles/Melee/ThanatosBoom.cs new file mode 100644 index 0000000000..be0d35f9f8 --- /dev/null +++ b/Projectiles/Melee/ThanatosBoom.cs @@ -0,0 +1,55 @@ +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +namespace CalamityMod.Projectiles.Melee +{ + public class ThanatosBoom : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + + public override void SetStaticDefaults() => DisplayName.SetDefault("Boom"); + + public override void SetDefaults() + { + projectile.width = projectile.height = 54; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.ignoreWater = true; + projectile.tileCollide = false; + projectile.timeLeft = 45; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 4; + projectile.melee = true; + } + + public override void AI() + { + if (projectile.localAI[0] == 0f) + { + CreateExplosionDust(); + projectile.localAI[0] = 1f; + } + } + + public void CreateExplosionDust() + { + if (Main.dedServ) + return; + + for (float speed = 2f; speed <= 6f; speed += 0.7f) + { + float lifePersistance = Main.rand.NextFloat(0.8f, 1.7f); + for (int i = 0; i < 60; i++) + { + Dust energy = Dust.NewDustPerfect(projectile.Center, 267); + energy.velocity = (MathHelper.TwoPi * i / 60f).ToRotationVector2() * speed; + energy.noGravity = true; + energy.color = Main.hslToRgb(Main.rand.NextFloat(), 0.7f, 0.625f); + energy.fadeIn = lifePersistance; + energy.scale = 1.4f; + } + } + } + } +} diff --git a/Projectiles/Melee/ViolenceSlashProjectile.cs b/Projectiles/Melee/ViolenceSlashProjectile.cs new file mode 100644 index 0000000000..90f645103c --- /dev/null +++ b/Projectiles/Melee/ViolenceSlashProjectile.cs @@ -0,0 +1,121 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using System.Linq; +using Terraria; +using Terraria.Graphics.Shaders; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Melee +{ + public class ViolenceSlashProjectile : ModProjectile + { + internal PrimitiveTrail SliceAfterimageDrawer = null; + internal Player Owner => Main.player[projectile.owner]; + internal ref float Time => ref projectile.ai[0]; + internal float SwingSine => (float)Math.Sin(MathHelper.TwoPi * Time / 50f); + public override string Texture => "CalamityMod/Items/Weapons/Melee/Violence"; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Violence"); + ProjectileID.Sets.TrailingMode[projectile.type] = 2; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 36; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 142; + projectile.aiStyle = -1; + projectile.friendly = true; + projectile.melee = true; + projectile.penetrate = -1; + projectile.timeLeft = 90000; + projectile.ignoreWater = true; + projectile.extraUpdates = 1; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 6; + projectile.tileCollide = false; + } + + public override void AI() + { + // Fade in. + projectile.Opacity = Utils.InverseLerp(0f, 15f, Time, true); + + if (!Owner.channel) + { + projectile.Kill(); + return; + } + + ManipulatePlayerFields(); + DoMovement(); + + // Create some demonic light at the tip of the spear. + Lighting.AddLight(projectile.Center + (projectile.rotation + MathHelper.PiOver4).ToRotationVector2() * projectile.height * 0.45f, Color.Red.ToVector3() * 0.4f); + Time++; + } + + internal void DoMovement() + { + projectile.Center = Owner.RotatedRelativePoint(Owner.MountedCenter) + (projectile.rotation - MathHelper.PiOver4).ToRotationVector2() * projectile.height * 0.45f; + projectile.rotation = SwingSine * MathHelper.ToRadians(87f); + + if (Main.myPlayer == projectile.owner && !projectile.WithinRange(Main.MouseWorld, projectile.height + 15f)) + { + projectile.velocity = projectile.SafeDirectionTo(Main.MouseWorld); + projectile.netSpam = 0; + projectile.netUpdate = true; + } + + projectile.rotation += projectile.velocity.ToRotation() + MathHelper.PiOver4; + } + + internal void ManipulatePlayerFields() + { + Owner.itemTime = 2; + Owner.itemAnimation = 2; + Owner.ChangeDir((Math.Cos(projectile.rotation - MathHelper.PiOver4) > 0f).ToDirectionInt()); + } + + internal Color PrimitiveColorFunction(float completionRatio) + { + float averageRotation = projectile.oldRot.Average(angle => MathHelper.WrapAngle(angle) + MathHelper.Pi); + float opacity = projectile.Opacity * Utils.InverseLerp(0.75f, 0.45f, completionRatio, true) * 0.5f; + opacity *= Utils.InverseLerp(0.125f, 0.15f, Math.Abs(SwingSine), true); + + float rotationAdjusted = MathHelper.WrapAngle(projectile.rotation) + MathHelper.Pi; + float oldRotationAdjusted = MathHelper.WrapAngle(projectile.oldRot[1]) + MathHelper.Pi; + + return Color.Lerp(Color.Red * 1.1f, Color.DarkRed, Utils.InverseLerp(0f, 0.5f, completionRatio, true)) * opacity; + } + + internal float PrimitiveWidthFunction(float completionRatio) => projectile.height * 0.48f; + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + if (SliceAfterimageDrawer is null) + SliceAfterimageDrawer = new PrimitiveTrail(PrimitiveWidthFunction, PrimitiveColorFunction, specialShader: GameShaders.Misc["CalamityMod:PhaseslayerRipEffect"]); + + GameShaders.Misc["CalamityMod:PhaseslayerRipEffect"].SetShaderTexture(ModContent.GetTexture("CalamityMod/ExtraTextures/SwordSlashTexture")); + + Texture2D spearProjectile = Main.projectileTexture[projectile.type]; + + Player player = Main.player[projectile.owner]; + List positions = new List(); + + for (int i = 0; i < 16; i++) + { + Vector2 position = projectile.position + (projectile.rotation - MathHelper.PiOver4).ToRotationVector2() * (PrimitiveWidthFunction(0f) - 30f) * projectile.scale * 0.5f; + float angleOffset = MathHelper.Pi * 0.25f * -Math.Sign(SwingSine) * i / 16f; + position += (projectile.rotation - MathHelper.PiOver4 + MathHelper.PiOver2).ToRotationVector2().RotatedBy(angleOffset) * -SwingSine * i * 12f; + positions.Add(position); + } + + SliceAfterimageDrawer.Draw(positions, projectile.Size * 0.5f - Main.screenPosition, 50); + return true; + } + } +} diff --git a/Projectiles/Melee/ViolenceThrownProjectile.cs b/Projectiles/Melee/ViolenceThrownProjectile.cs new file mode 100644 index 0000000000..0fcf8ac827 --- /dev/null +++ b/Projectiles/Melee/ViolenceThrownProjectile.cs @@ -0,0 +1,161 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.Graphics.Shaders; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Melee +{ + public class ViolenceThrownProjectile : ModProjectile + { + internal PrimitiveTrail StreakDrawer = null; + internal Player Owner => Main.player[projectile.owner]; + internal ref float Time => ref projectile.ai[0]; + public override string Texture => "CalamityMod/Items/Weapons/Melee/Violence"; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Violence"); + ProjectileID.Sets.TrailingMode[projectile.type] = 2; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 36; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 142; + projectile.aiStyle = -1; + projectile.friendly = true; + projectile.melee = true; + projectile.penetrate = -1; + projectile.timeLeft = 90000; + projectile.ignoreWater = true; + projectile.extraUpdates = 1; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 6; + projectile.tileCollide = false; + } + + public override void AI() + { + // Fade in. + projectile.Opacity = Utils.InverseLerp(0f, 15f, Time, true); + + if (Owner.channel) + { + HomeTowardsMouse(); + projectile.rotation += 0.35f / projectile.MaxUpdates; + } + else + { + ReturnToOwner(); + + float idealAngle = projectile.AngleTo(Owner.Center) - MathHelper.PiOver4; + projectile.rotation = projectile.rotation.AngleLerp(idealAngle, 0.1f); + projectile.rotation = projectile.rotation.AngleTowards(idealAngle, 0.25f); + } + ManipulatePlayerFields(); + + // Create some demonic light at the tip of the spear. + Lighting.AddLight(projectile.Center + (projectile.rotation + MathHelper.PiOver4).ToRotationVector2() * projectile.height * 0.45f, Color.Red.ToVector3() * 0.4f); + Time++; + } + + internal void HomeTowardsMouse() + { + if (Main.myPlayer != projectile.owner) + return; + + if (projectile.WithinRange(Main.MouseWorld, projectile.velocity.Length() * 0.7f)) + projectile.Center = Main.MouseWorld; + else + projectile.velocity = (projectile.velocity * 3f + projectile.DirectionTo(Main.MouseWorld) * 19f) / 4f; + projectile.netSpam = 0; + projectile.netUpdate = true; + } + + internal void ReturnToOwner() + { + projectile.Center = Vector2.Lerp(projectile.Center, Owner.Center, 0.02f); + projectile.velocity = projectile.SafeDirectionTo(Owner.Center) * 22f; + if (projectile.Hitbox.Intersects(Owner.Hitbox)) + { + for (int i = 0; i < 75; i++) + { + Dust fire = Dust.NewDustPerfect(Owner.Center, DustID.Fire); + fire.velocity = (MathHelper.TwoPi * i / 75f).ToRotationVector2() * 4f - Vector2.UnitY * 3f; + fire.scale = 1.4f; + fire.noGravity = true; + } + projectile.Kill(); + } + } + + internal void ManipulatePlayerFields() + { + Owner.itemTime = 2; + Owner.itemAnimation = 2; + } + + internal float PrimitiveWidthFunction(float completionRatio) + { + float tipWidthFactor = MathHelper.SmoothStep(0f, 1f, Utils.InverseLerp(0.01f, 0.04f, completionRatio)); + float bodyWidthFactor = (float)Math.Pow(Utils.InverseLerp(1f, 0.04f, completionRatio), 0.9D); + return (float)Math.Pow(tipWidthFactor * bodyWidthFactor, 0.1D) * 30f; + } + + internal Color PrimitiveColorFunction(float completionRatio) + { + float fadeInterpolant = (float)Math.Cos(Main.GlobalTime * -9f + completionRatio * 6f + projectile.identity * 2f) * 0.5f + 0.5f; + + // Adjust the fade interpolant to be on a different scale via a linear interpolation. + fadeInterpolant = MathHelper.Lerp(0.15f, 0.75f, fadeInterpolant); + Color frontFade = Color.Lerp(new Color(255, 145, 115), new Color(113, 0, 159), fadeInterpolant); + + // Go halfway to a dark red color. + frontFade = Color.Lerp(frontFade, Color.DarkRed, 0.5f); + Color backFade = new Color(255, 145, 115); + + return Color.Lerp(frontFade, backFade, (float)Math.Pow(completionRatio, 1.2D)) * (float)Math.Pow(1f - completionRatio, 1.1D) * projectile.Opacity; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + if (StreakDrawer is null) + StreakDrawer = new PrimitiveTrail(PrimitiveWidthFunction, PrimitiveColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]); + + GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.GetTexture("CalamityMod/ExtraTextures/FabstaffStreak")); + + Texture2D spearProjectile = Main.projectileTexture[projectile.type]; + + // Not cloning the points causes the below operations to be applied to the original oldPos value by reference + // and thus causes it to be consistently added over and over, which is not intended behavior. + Vector2[] drawPoints = (Vector2[])projectile.oldPos.Clone(); + Vector2 aimAheadDirection = (projectile.rotation - MathHelper.PiOver2).ToRotationVector2(); + + if (Owner.channel) + { + drawPoints[0] += aimAheadDirection * -12f; + drawPoints[1] = drawPoints[0] - (projectile.rotation + MathHelper.PiOver4).ToRotationVector2() * Vector2.Distance(drawPoints[0], drawPoints[1]); + } + for (int i = 0; i < drawPoints.Length; i++) + drawPoints[i] -= (projectile.oldRot[i] + MathHelper.PiOver4).ToRotationVector2() * projectile.height * 0.5f; + + if (Time > projectile.oldPos.Length) + StreakDrawer.Draw(drawPoints, projectile.Size * 0.5f - Main.screenPosition, 88); + + Vector2 drawPosition = projectile.Center - Main.screenPosition; + for (int i = 0; i < 6; i++) + { + float rotation = projectile.oldRot[i] - MathHelper.PiOver2; + if (Owner.channel) + rotation += 0.2f; + + Color afterimageColor = Color.Lerp(lightColor, Color.Transparent, 1f - (float)Math.Pow(Utils.InverseLerp(0, 6, i), 1.4D)) * projectile.Opacity; + spriteBatch.Draw(spearProjectile, drawPosition, null, afterimageColor, rotation, spearProjectile.Size() * 0.5f, projectile.scale, SpriteEffects.None, 0f); + } + + return false; + } + } +} diff --git a/Projectiles/Ranged/BouncingShotgunPellet.cs b/Projectiles/Ranged/BouncingShotgunPellet.cs new file mode 100644 index 0000000000..75ab8ea2ff --- /dev/null +++ b/Projectiles/Ranged/BouncingShotgunPellet.cs @@ -0,0 +1,68 @@ +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +namespace CalamityMod.Projectiles.Ranged +{ + public class BouncingShotgunPellet : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Ranged/RealmRavagerBullet"; + private int bounce = 2; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Shotgun Pellet"); + } + + public override void SetDefaults() + { + projectile.width = 4; + projectile.height = 4; + projectile.light = 0.5f; + projectile.alpha = 255; + projectile.ranged = true; + projectile.friendly = true; + projectile.aiStyle = 1; + aiType = ProjectileID.BulletHighVelocity; + projectile.timeLeft = 180; + } + + public override bool OnTileCollide(Vector2 oldVelocity) + { + bounce--; + if (bounce <= 0) + projectile.Kill(); + else + { + if (projectile.velocity.X != oldVelocity.X) + projectile.velocity.X = -oldVelocity.X; + if (projectile.velocity.Y != oldVelocity.Y) + projectile.velocity.Y = -oldVelocity.Y; + Main.PlaySound(SoundID.Item10, projectile.Center); + projectile.damage /= 2; + } + return false; + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) => Main.PlaySound(SoundID.Item10, projectile.Center); + + public override void OnHitPvp(Player target, int damage, bool crit) => Main.PlaySound(SoundID.Item10, projectile.Center); + + public override void Kill(int timeLeft) + { + CalamityGlobalProjectile.ExpandHitboxBy(projectile, 32); + for (int d = 0; d < 2; d++) + { + Dust.NewDust(projectile.position, projectile.width, projectile.height, DustID.Smoke, 0f, 0f, 100, default, 1.5f); + } + for (int d = 0; d < 20; d++) + { + int idx = Dust.NewDust(projectile.position, projectile.width, projectile.height, DustID.Fire, 0f, 0f, 0, default, 2.5f); + Main.dust[idx].noGravity = true; + Main.dust[idx].velocity *= 3f; + idx = Dust.NewDust(projectile.position, projectile.width, projectile.height, DustID.Fire, 0f, 0f, 100, default, 1.5f); + Main.dust[idx].velocity *= 2f; + Main.dust[idx].noGravity = true; + } + } + } +} diff --git a/Projectiles/Ranged/CondemnationArrow.cs b/Projectiles/Ranged/CondemnationArrow.cs new file mode 100644 index 0000000000..ea57b89d1e --- /dev/null +++ b/Projectiles/Ranged/CondemnationArrow.cs @@ -0,0 +1,90 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Ranged +{ + public class CondemnationArrow : ModProjectile + { + public ref float Time => ref projectile.ai[0]; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Condemnation Arrow"); + ProjectileID.Sets.TrailingMode[projectile.type] = 1; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 9; + } + + public override void SetDefaults() + { + projectile.width = 26; + projectile.height = 90; + projectile.friendly = true; + projectile.ignoreWater = true; + projectile.tileCollide = false; + projectile.ranged = true; + projectile.arrow = true; + projectile.extraUpdates = 1; + projectile.timeLeft = 300; + } + + public override void AI() + { + Lighting.AddLight(projectile.Center, Color.Violet.ToVector3()); + projectile.Opacity = Utils.InverseLerp(0f, 20f, Time, true); + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2; + Time++; + + // Release side arrows every so often. + if (Main.netMode != NetmodeID.MultiplayerClient && Time % 90f == 89f) + { + for (int i = -1; i <= 1; i += 2) + { + Vector2 shootVelocity = projectile.velocity.RotatedBy(i * 0.036f); + Projectile.NewProjectile(projectile.Center, shootVelocity, ModContent.ProjectileType(), projectile.damage / 2, projectile.knockBack, projectile.owner); + } + } + } + + public override Color? GetAlpha(Color lightColor) + { + Color c1 = new Color(226, 40, 40, 0); + Color c2 = new Color(205, 0, 194, 0); + Color fadeColor = Color.Lerp(c1, c2, (float)Math.Cos(projectile.identity * 1.41f + Main.GlobalTime * 8f) * 0.5f + 0.5f); + return Color.Lerp(lightColor, fadeColor, 0.5f) * projectile.Opacity; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + CalamityUtils.DrawAfterimagesCentered(projectile, ProjectileID.Sets.TrailingMode[projectile.type], lightColor); + return false; + } + + public override void Kill(int timeLeft) + { + // Release a burst of magic dust on death. + if (Main.dedServ) + return; + + for (int i = 0; i < 30; i++) + { + Dust fire = Dust.NewDustPerfect(projectile.Center, 130); + fire.velocity = projectile.velocity.SafeNormalize(Vector2.UnitY).RotatedByRandom(0.8f) * new Vector2(4f, 1.25f) * Main.rand.NextFloat(0.9f, 1f); + fire.velocity = fire.velocity.RotatedBy(projectile.rotation - MathHelper.PiOver2); + fire.velocity += projectile.velocity * 0.7f; + + fire.noGravity = true; + fire.color = Color.Lerp(Color.White, Color.Purple, Main.rand.NextFloat()); + fire.scale = Main.rand.NextFloat(1f, 1.1f); + + fire = Dust.CloneDust(fire); + fire.velocity = Main.rand.NextVector2Circular(3f, 3f); + fire.velocity += projectile.velocity * 0.6f; + } + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) => projectile.RotatingHitboxCollision(targetHitbox.TopLeft(), targetHitbox.Size()); + } +} diff --git a/Projectiles/Ranged/CondemnationArrow.png b/Projectiles/Ranged/CondemnationArrow.png new file mode 100644 index 0000000000..3b2032bb20 Binary files /dev/null and b/Projectiles/Ranged/CondemnationArrow.png differ diff --git a/Projectiles/Ranged/CondemnationArrowHoming.cs b/Projectiles/Ranged/CondemnationArrowHoming.cs new file mode 100644 index 0000000000..14d7acf2b3 --- /dev/null +++ b/Projectiles/Ranged/CondemnationArrowHoming.cs @@ -0,0 +1,78 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Ranged +{ + public class CondemnationArrowHoming : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Ranged/CondemnationArrow"; + public ref float Time => ref projectile.ai[0]; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Condemnation Arrow"); + ProjectileID.Sets.TrailingMode[projectile.type] = 1; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 9; + } + + public override void SetDefaults() + { + projectile.width = 14; + projectile.height = 45; + projectile.scale = 0.5f; + projectile.friendly = true; + projectile.ignoreWater = true; + projectile.tileCollide = true; + projectile.ranged = true; + projectile.arrow = true; + projectile.extraUpdates = 1; + projectile.timeLeft = 300; + } + + public override void AI() + { + Lighting.AddLight(projectile.Center, Color.Violet.ToVector3()); + projectile.Opacity = Utils.InverseLerp(0f, 20f, Time, true) * Utils.InverseLerp(0f, 20f, projectile.timeLeft, true); + + NPC potentialTarget = projectile.Center.ClosestNPCAt(1500f, false); + if (potentialTarget != null) + projectile.velocity = (projectile.velocity * 29f + projectile.SafeDirectionTo(potentialTarget.Center) * 21f) / 30f; + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2; + Time++; + } + + public override Color? GetAlpha(Color lightColor) + { + Color c1 = new Color(226, 40, 40, 0); + Color c2 = new Color(205, 0, 194, 0); + return Color.Lerp(c1, c2, (float)Math.Cos(projectile.identity * 1.41f + Main.GlobalTime * 8f) * 0.5f + 0.5f) * projectile.Opacity; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + CalamityUtils.DrawAfterimagesCentered(projectile, ProjectileID.Sets.TrailingMode[projectile.type], lightColor); + return false; + } + + public override void Kill(int timeLeft) + { + // Release a burst of magic dust on death. + if (Main.dedServ) + return; + + for (int i = 0; i < 10; i++) + { + Dust fire = Dust.NewDustPerfect(projectile.Center, 267); + fire.velocity = Main.rand.NextVector2Circular(2f, 2f); + fire.color = Color.Lerp(Color.Red, Color.Purple, Main.rand.NextFloat()); + fire.scale = Main.rand.NextFloat(1f, 1.1f); + fire.noGravity = true; + } + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) => projectile.RotatingHitboxCollision(targetHitbox.TopLeft(), targetHitbox.Size()); + } +} diff --git a/Projectiles/Ranged/CondemnationHoldout.cs b/Projectiles/Ranged/CondemnationHoldout.cs new file mode 100644 index 0000000000..1ac21ab858 --- /dev/null +++ b/Projectiles/Ranged/CondemnationHoldout.cs @@ -0,0 +1,146 @@ +using Microsoft.Xna.Framework; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Ranged +{ + public class CondemnationHoldout : ModProjectile + { + public Player Owner => Main.player[projectile.owner]; + public bool OwnerCanShoot => Owner.channel && Owner.HasAmmo(Owner.ActiveItem(), true) && !Owner.noItems && !Owner.CCed; + public ref float ChargeUpTime => ref projectile.ai[0]; + public override string Texture => "CalamityMod/Items/Weapons/Ranged/Condemnation"; + public override void SetStaticDefaults() => DisplayName.SetDefault("Condemnation"); + + public override void SetDefaults() + { + projectile.width = 130; + projectile.height = 42; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.tileCollide = false; + projectile.ranged = true; + projectile.ignoreWater = true; + } + + public override void AI() + { + Vector2 armPosition = Owner.RotatedRelativePoint(Owner.MountedCenter, true); + + Vector2 tipPosition = armPosition + projectile.velocity * projectile.width * 0.5f; + if (ChargeUpTime < 20f) + ReleaseInitialChargeDust(tipPosition); + if (ChargeUpTime == 20f) + ReleaseInitialBurstDust(tipPosition); + + // Release projectiles after done charging. + if (!OwnerCanShoot) + { + projectile.Kill(); + + // If killed prior to the charge being complete, don't bother spawning anything. Just die. + if (ChargeUpTime < 20f) + return; + + int totalProjectilesToShoot = (int)Math.Pow(ChargeUpTime * 0.15f, 0.71) + 1; + if (totalProjectilesToShoot > 32) + totalProjectilesToShoot = 32; + + for (int i = 0; i < totalProjectilesToShoot; i++) + ShootProjectiles(tipPosition, MathHelper.Lerp(0.425f, 1f, i / (float)totalProjectilesToShoot)); + + Main.PlaySound(SoundID.DD2_BallistaTowerShot); + } + + UpdateProjectileHeldVariables(armPosition); + ManipulatePlayerVariables(); + ChargeUpTime++; + } + + public void ReleaseInitialBurstDust(Vector2 tipPosition) + { + if (Main.dedServ) + return; + + for (int i = 0; i < 36; i++) + { + Dust chargeMagic = Dust.NewDustPerfect(tipPosition, 267); + chargeMagic.velocity = (MathHelper.TwoPi * i / 36f).ToRotationVector2() * 5f + Owner.velocity; + chargeMagic.scale = Main.rand.NextFloat(1f, 1.5f); + chargeMagic.color = Color.Violet; + chargeMagic.noGravity = true; + } + } + + public void ReleaseInitialChargeDust(Vector2 tipPosition) + { + if (Main.dedServ) + return; + + for (int i = 0; i < 2; i++) + { + Dust chargeMagic = Dust.NewDustPerfect(tipPosition + Main.rand.NextVector2Circular(20f, 20f), 267); + chargeMagic.velocity = (tipPosition - chargeMagic.position) * 0.1f + Owner.velocity; + chargeMagic.scale = Main.rand.NextFloat(1f, 1.5f); + chargeMagic.color = projectile.GetAlpha(Color.White); + chargeMagic.noGravity = true; + } + } + + public void ShootProjectiles(Vector2 tipPosition, float speedFactor) + { + if (Main.myPlayer != projectile.owner) + return; + + Item heldItem = Owner.ActiveItem(); + int projectileType = ModContent.ProjectileType(); + float shootSpeed = heldItem.shootSpeed * speedFactor * 1.5f; + int damage = (int)(Owner.GetWeaponDamage(heldItem) * 1.45); + float knockback = heldItem.knockBack; + + bool uselessFuckYou = OwnerCanShoot; + Owner.PickAmmo(heldItem, ref projectileType, ref shootSpeed, ref uselessFuckYou, ref damage, ref knockback, false); + projectileType = ModContent.ProjectileType(); + + knockback = Owner.GetWeaponKnockback(heldItem, knockback); + Vector2 shootVelocity = projectile.velocity.SafeNormalize(Vector2.UnitY) * shootSpeed; + + Projectile.NewProjectile(tipPosition, shootVelocity, projectileType, damage, knockback, projectile.owner, 0f, 0f); + } + + public void UpdateProjectileHeldVariables(Vector2 armPosition) + { + if (Main.myPlayer == projectile.owner) + { + float interpolant = Utils.InverseLerp(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.position = armPosition - projectile.Size * 0.5f; + projectile.rotation = projectile.velocity.ToRotation(); + if (projectile.spriteDirection == -1) + projectile.rotation += MathHelper.Pi; + projectile.spriteDirection = projectile.direction; + projectile.timeLeft = 2; + } + + public 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 bool CanDamage() => false; + } +} diff --git a/Projectiles/Ranged/ContagionBow.cs b/Projectiles/Ranged/ContagionBow.cs index c7382b46ee..89ac2dd550 100644 --- a/Projectiles/Ranged/ContagionBow.cs +++ b/Projectiles/Ranged/ContagionBow.cs @@ -88,7 +88,7 @@ namespace CalamityMod.Projectiles.Ranged } if (flag && Main.myPlayer == projectile.owner) { - bool flag2 = player.channel && player.CheckMana(player.ActiveItem().mana, true, false) && !player.noItems && !player.CCed; + bool flag2 = player.channel && !player.noItems && !player.CCed; if (flag2) { float speed = player.ActiveItem().shootSpeed * projectile.scale; diff --git a/Projectiles/Ranged/ExoLight.cs b/Projectiles/Ranged/ExoLight.cs index 8978b339e7..9b76732b06 100644 --- a/Projectiles/Ranged/ExoLight.cs +++ b/Projectiles/Ranged/ExoLight.cs @@ -48,6 +48,14 @@ namespace CalamityMod.Projectiles.Ranged OffsetSpeed = Main.rand.NextFloat(MathHelper.ToRadians(2.5f), MathHelper.ToRadians(4f)) * Main.rand.NextBool(2).ToDirectionInt(); projectile.localAI[0] = 1f; } + + // Ensure that the owner projectile index is a valid one. + if (!Main.projectile.IndexInRange((int)projectile.localAI[1])) + { + projectile.Kill(); + return; + } + Projectile owner = Main.projectile[(int)projectile.localAI[1]]; // Ensure the owner is the correct projectile. diff --git a/Projectiles/Ranged/ExoLightBomb.cs b/Projectiles/Ranged/ExoLightBomb.cs index 5e4ddb8036..65c54e31ff 100644 --- a/Projectiles/Ranged/ExoLightBomb.cs +++ b/Projectiles/Ranged/ExoLightBomb.cs @@ -52,10 +52,12 @@ namespace CalamityMod.Projectiles.Ranged public override void SendExtraAI(BinaryWriter writer) { writer.Write(YDirection); + writer.WriteVector2(Destination); } public override void ReceiveExtraAI(BinaryReader reader) { YDirection = reader.ReadSingle(); + Destination = reader.ReadVector2(); } public override void AI() @@ -66,7 +68,11 @@ namespace CalamityMod.Projectiles.Ranged if (projectile.localAI[0] == 0f) { InitialCenter = projectile.Center; - Destination = Main.MouseWorld; + if (Main.myPlayer == projectile.owner) + { + Destination = Main.MouseWorld; + projectile.netUpdate = true; + } DustType = Main.rand.NextBool(2) ? 107 : 234; if (Main.rand.NextBool(4)) { @@ -74,6 +80,10 @@ namespace CalamityMod.Projectiles.Ranged } projectile.localAI[0] = 1f; } + + if (Destination == Vector2.Zero) + return; + if (Time <= 90f) { projectile.position = Vector2.Lerp(InitialCenter, Destination, Time / 90f); @@ -92,9 +102,8 @@ namespace CalamityMod.Projectiles.Ranged projectile.Center = Destination + ((Time - 90) / 90f * MathHelper.ToRadians(720f) + (YDirection == -1).ToInt() * MathHelper.Pi).ToRotationVector2() * radius; } else if (Time == 180f) - { projectile.Kill(); - } + projectile.rotation = projectile.velocity.ToRotation() - MathHelper.PiOver2; Time++; } diff --git a/Projectiles/Ranged/ExoLightBurst.cs b/Projectiles/Ranged/ExoLightBurst.cs index 8abad44ce5..02a59edf62 100644 --- a/Projectiles/Ranged/ExoLightBurst.cs +++ b/Projectiles/Ranged/ExoLightBurst.cs @@ -19,7 +19,7 @@ namespace CalamityMod.Projectiles.Ranged public override void SetDefaults() { - projectile.width = projectile.height = 190; + projectile.width = projectile.height = 50; projectile.friendly = true; projectile.ignoreWater = true; projectile.tileCollide = false; @@ -68,17 +68,15 @@ namespace CalamityMod.Projectiles.Ranged projectile.ModifyHitNPCSticky(4, false); } - public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) { - int width = (int)MathHelper.Min(targetHitbox.Width, 150); - int height = (int)MathHelper.Min(targetHitbox.Height, 150); - CalamityGlobalProjectile.ExpandHitboxBy(projectile, width, height); - return null; - } - - public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) - { - target.ExoDebuffs(2f); + if (projectile.width == 50) + { + int width = (int)MathHelper.Min(target.Hitbox.Width, 60); + int height = (int)MathHelper.Min(target.Hitbox.Height, 60); + CalamityGlobalProjectile.ExpandHitboxBy(projectile, width, height); + } + target.ExoDebuffs(2f); } public override void OnHitPvp(Player target, int damage, bool crit) diff --git a/Projectiles/Ranged/PrismComet.cs b/Projectiles/Ranged/PrismComet.cs new file mode 100644 index 0000000000..5fc4a36842 --- /dev/null +++ b/Projectiles/Ranged/PrismComet.cs @@ -0,0 +1,102 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Ranged +{ + public class PrismComet : ModProjectile + { + public ref float Time => ref projectile.ai[0]; + public override string Texture => "CalamityMod/Projectiles/Melee/Exocomet"; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Comet"); + Main.projFrames[projectile.type] = 5; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 10; + ProjectileID.Sets.TrailingMode[projectile.type] = 0; + } + + public override void SetDefaults() + { + projectile.scale = 0.86f; + projectile.width = projectile.height = 12; + projectile.friendly = true; + projectile.ignoreWater = true; + projectile.tileCollide = false; + projectile.melee = true; + projectile.penetrate = 1; + projectile.alpha = 50; + } + + public override void AI() + { + Lighting.AddLight(projectile.Center, Color.LightSeaGreen.ToVector3()); + projectile.frameCounter++; + if (projectile.frameCounter % 6 == 5) + projectile.frame = (projectile.frame + 1) % Main.projFrames[projectile.type]; + + projectile.alpha = Utils.Clamp(projectile.alpha - 25, 30, 255); + + if (projectile.alpha < 40) + ReleaseIdleDust(); + + // Home onto any targets after a short amount of time. + if (Time >= 25f) + { + NPC potentialTarget = projectile.Center.ClosestNPCAt(1050f); + if (potentialTarget != null) + projectile.velocity = (projectile.velocity * 12f + projectile.SafeDirectionTo(potentialTarget.Center) * 19f) / 13f; + } + else + projectile.velocity *= 1.05f; + + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2; + + Time++; + } + public void ReleaseIdleDust() + { + if (Main.dedServ) + return; + + Dust prismEnergy = Dust.NewDustDirect(projectile.position - projectile.velocity * 4f, 8, 8, 107, projectile.oldVelocity.X, projectile.oldVelocity.Y, 100, new Color(0, 255, 255), 0.5f); + prismEnergy.velocity *= -0.25f; + prismEnergy.velocity -= projectile.velocity * 0.3f; + + prismEnergy = Dust.NewDustDirect(projectile.position - projectile.velocity * 4f, 8, 8, 107, projectile.oldVelocity.X, projectile.oldVelocity.Y, 100, new Color(0, 255, 255), 0.5f); + prismEnergy.velocity *= -0.25f; + prismEnergy.position -= projectile.velocity * 0.5f; + prismEnergy.velocity -= projectile.velocity * 0.3f; + } + + public override bool CanDamage() => Time >= 20f; + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + CalamityUtils.DrawAfterimagesCentered(projectile, ProjectileID.Sets.TrailingMode[projectile.type], lightColor); + return false; + } + + public override Color? GetAlpha(Color lightColor) + { + Color color = Color.Honeydew * projectile.Opacity; + color.A = 0; + return color; + } + + public override void Kill(int timeLeft) + { + Main.PlaySound(SoundID.Zombie, (int)projectile.position.X, (int)projectile.position.Y, 103, 1f, 0f); + CalamityGlobalProjectile.ExpandHitboxBy(projectile, 80); + projectile.Damage(); + + if (Main.myPlayer != projectile.owner) + return; + + Projectile.NewProjectile(projectile.Center, Vector2.Zero, ModContent.ProjectileType(), projectile.damage, 0f, projectile.owner); + } + } +} diff --git a/Projectiles/Ranged/PrismEnergyBullet.cs b/Projectiles/Ranged/PrismEnergyBullet.cs new file mode 100644 index 0000000000..cf1920bd67 --- /dev/null +++ b/Projectiles/Ranged/PrismEnergyBullet.cs @@ -0,0 +1,69 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Ranged +{ + public class PrismEnergyBullet : ModProjectile + { + public ref float CurrentLaserLength => ref projectile.ai[0]; + public ref float Time => ref projectile.ai[1]; + public override string Texture => "CalamityMod/Projectiles/LaserProj"; + + public override void SetStaticDefaults() => DisplayName.SetDefault("Prism Rocket"); + + public override void SetDefaults() + { + projectile.scale = 1.7f; + projectile.width = projectile.height = 12; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.tileCollide = false; + projectile.timeLeft = 300; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 13; + projectile.extraUpdates = 1; + projectile.ranged = true; + } + + public override void AI() + { + CurrentLaserLength = (int)MathHelper.Lerp(1f, 70f, Utils.InverseLerp(0f, 15f, Time, true) * Utils.InverseLerp(0f, 15f, projectile.timeLeft, true)); + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2; + Time++; + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + if (Main.myPlayer != projectile.owner) + return; + + for (int i = 0; i < 3; i++) + { + Vector2 shootVelocity = projectile.velocity.RotatedBy(MathHelper.Lerp(-0.3f, 0.3f, i / 2f)) * 0.4f; + Projectile.NewProjectile(projectile.Center, shootVelocity, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner); + } + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D texture = Main.projectileTexture[projectile.type]; + Vector2 origin = texture.Size() * 0.5f; + Vector2 currentDirection = projectile.velocity.SafeNormalize(Vector2.Zero); + for (int i = 0; i < CurrentLaserLength; i++) + { + float scale = MathHelper.Lerp(1f, 0.2f, i / CurrentLaserLength) * projectile.scale; + Vector2 drawPosition = projectile.Center - currentDirection * i * 4f - Main.screenPosition; + Color drawColor = Color.Lerp(Color.Lime, Color.YellowGreen, (float)Math.Cos(i / CurrentLaserLength * 2.1f - Main.GlobalTime * 2.5f) * 0.5f + 0.5f); + drawColor = Color.Lerp(drawColor, Color.Yellow, 0.55f); + drawColor = Color.Lerp(drawColor, Color.White, (float)Math.Pow(i / CurrentLaserLength, 3D)); + drawColor.A = 0; + + spriteBatch.Draw(texture, drawPosition, null, drawColor, projectile.rotation, origin, scale, SpriteEffects.None, 0f); + } + return false; + } + } +} diff --git a/Projectiles/Ranged/PrismExplosionLarge.cs b/Projectiles/Ranged/PrismExplosionLarge.cs new file mode 100644 index 0000000000..6ed873f793 --- /dev/null +++ b/Projectiles/Ranged/PrismExplosionLarge.cs @@ -0,0 +1,60 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Ranged +{ + public class PrismExplosionLarge : ModProjectile + { + public override void SetStaticDefaults() => DisplayName.SetDefault("Explosion"); + + public override void SetDefaults() + { + projectile.width = projectile.height = 300; + projectile.friendly = true; + projectile.ignoreWater = false; + projectile.tileCollide = false; + projectile.ranged = true; + projectile.penetrate = -1; + projectile.timeLeft = 150; + projectile.extraUpdates = 2; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 11; + projectile.scale = 0.35f; + } + + public override void AI() + { + Lighting.AddLight(projectile.Center, Color.White.ToVector3() * 1.5f); + projectile.frameCounter++; + if (projectile.frameCounter % 8 == 7) + projectile.frame++; + + if (projectile.frame >= 18) + projectile.Kill(); + projectile.scale *= 1.0115f; + projectile.Opacity = Utils.InverseLerp(5f, 36f, projectile.timeLeft, true); + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D texture = Main.projectileTexture[projectile.type]; + Texture2D lightTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/PhotovisceratorLight"); + Rectangle frame = texture.Frame(3, 6, projectile.frame / 6, projectile.frame % 6); + Vector2 drawPosition = projectile.Center - Main.screenPosition; + Vector2 origin = frame.Size() * 0.5f; + + for (int i = 0; i < 36; i++) + { + Vector2 lightDrawPosition = drawPosition + (MathHelper.TwoPi * i / 36f + Main.GlobalTime * 5f).ToRotationVector2() * projectile.scale * 20f; + Color lightBurstColor = CalamityUtils.MulticolorLerp(projectile.timeLeft / 144f, Items.CalamityGlobalItem.ExoPalette); + lightBurstColor = Color.Lerp(lightBurstColor, Color.White, 0.4f) * projectile.Opacity * 0.04f; + lightBurstColor.A = 0; + spriteBatch.Draw(lightTexture, lightDrawPosition, null, lightBurstColor, 0f, lightTexture.Size() * 0.5f, projectile.scale * 2.5f, SpriteEffects.None, 0f); + } + spriteBatch.Draw(texture, drawPosition, frame, Color.White, 0f, origin, 1f, SpriteEffects.None, 0f); + return false; + } + } +} diff --git a/Projectiles/Ranged/PrismExplosionLarge.png b/Projectiles/Ranged/PrismExplosionLarge.png new file mode 100644 index 0000000000..3bbf34853c Binary files /dev/null and b/Projectiles/Ranged/PrismExplosionLarge.png differ diff --git a/Projectiles/Ranged/PrismExplosionSmall.cs b/Projectiles/Ranged/PrismExplosionSmall.cs new file mode 100644 index 0000000000..d1398625c0 --- /dev/null +++ b/Projectiles/Ranged/PrismExplosionSmall.cs @@ -0,0 +1,56 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Ranged +{ + public class PrismExplosionSmall : ModProjectile + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Explosion"); + Main.projFrames[projectile.type] = 7; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 130; + projectile.friendly = true; + projectile.ignoreWater = false; + projectile.tileCollide = false; + projectile.ranged = true; + projectile.penetrate = -1; + projectile.timeLeft = 150; + projectile.extraUpdates = 2; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 11; + projectile.scale = 0.5f; + } + + public override void AI() + { + Lighting.AddLight(projectile.Center, Color.White.ToVector3() * 1.15f); + projectile.frameCounter++; + if (projectile.frameCounter % 8 == 7) + projectile.frame++; + + if (projectile.frame >= Main.projFrames[projectile.type]) + projectile.Kill(); + projectile.scale *= 1.0115f; + projectile.Opacity = Utils.InverseLerp(5f, 36f, projectile.timeLeft, true); + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D texture = Main.projectileTexture[projectile.type]; + Texture2D lightTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/PhotovisceratorLight"); + Rectangle frame = texture.Frame(1, Main.projFrames[projectile.type], 0, projectile.frame); + Vector2 drawPosition = projectile.Center - Main.screenPosition; + Vector2 origin = frame.Size() * 0.5f; + + spriteBatch.Draw(texture, drawPosition, frame, Color.White, 0f, origin, 1f, SpriteEffects.None, 0f); + return false; + } + } +} diff --git a/Projectiles/Ranged/PrismExplosionSmall.png b/Projectiles/Ranged/PrismExplosionSmall.png new file mode 100644 index 0000000000..b4c5a29207 Binary files /dev/null and b/Projectiles/Ranged/PrismExplosionSmall.png differ diff --git a/Projectiles/Ranged/PrismMine.cs b/Projectiles/Ranged/PrismMine.cs new file mode 100644 index 0000000000..406e1be8af --- /dev/null +++ b/Projectiles/Ranged/PrismMine.cs @@ -0,0 +1,110 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Ranged +{ + public class PrismMine : ModProjectile + { + public List MinesToConnectTo = new List(); + public ref float Time => ref projectile.ai[0]; + public const float MineConnectDistanceMax = 850f; + public override void SetStaticDefaults() => DisplayName.SetDefault("Mine"); + + public override void SetDefaults() + { + projectile.width = projectile.height = 40; + projectile.friendly = true; + projectile.ignoreWater = true; + projectile.tileCollide = false; + projectile.ranged = true; + projectile.penetrate = -1; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 7; + projectile.timeLeft = 280; + } + + public override void AI() + { + projectile.velocity *= 0.94f; + Lighting.AddLight(projectile.Center, Color.Cyan.ToVector3()); + + float idealScale = MathHelper.Lerp(0.93f, 1.07f, (float)Math.Sin(MathHelper.TwoPi * projectile.timeLeft / 14f) * 0.5f + 0.5f); + projectile.scale = MathHelper.Lerp(0.15f, idealScale, Utils.InverseLerp(0f, 15f, Time, true) * Utils.InverseLerp(0f, 15f, projectile.timeLeft, true)); + Time++; + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + foreach (Projectile mine in LocateOtherMines()) + { + if (projectile.timeLeft <= 12) + break; + + float _ = 0f; + if (Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), projectile.Center, mine.Center, 20f, ref _)) + return true; + } + return base.Colliding(projHitbox, targetHitbox); + } + + public List LocateOtherMines() + { + List mines = new List(); + for (int i = 0; i < Main.maxProjectiles; i++) + { + Projectile proj = Main.projectile[i]; + if (proj.type != projectile.type || !proj.active || proj.timeLeft <= 12 || i == projectile.whoAmI) + continue; + if (!projectile.WithinRange(proj.Center, MineConnectDistanceMax)) + continue; + + mines.Add(proj); + } + + return mines; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D baseTexture = Main.projectileTexture[projectile.type]; + Texture2D glowTexture = ModContent.GetTexture($"{Texture}Glowmask"); + Texture2D laserTexture = ModContent.GetTexture($"CalamityMod/Projectiles/Ranged/PrismMineArc"); + + void drawLineTo(Vector2 destination, Color laserColor) + { + float rotation = projectile.AngleTo(destination); + float remainingDistance = projectile.Distance(destination) - 30f; + float laserScale = 0.5f; + Rectangle frame = laserTexture.Frame(1, 7, 0, (int)(Main.GlobalTime * 10f + projectile.identity * 3f) % 7); + Vector2 laserOrigin = frame.Size() * 0.5f; + while (remainingDistance > frame.Height * laserScale) + { + Vector2 laserDrawPosition = projectile.Center + projectile.SafeDirectionTo(destination, -Vector2.UnitY) * remainingDistance - Main.screenPosition; + spriteBatch.Draw(laserTexture, laserDrawPosition, frame, laserColor, rotation, laserOrigin, laserScale, SpriteEffects.None, 0f); + remainingDistance -= frame.Height * laserScale; + } + } + + Vector2 origin = baseTexture.Size() * 0.5f; + Vector2 drawPosition = projectile.Center - Main.screenPosition; + + foreach (Projectile mine in LocateOtherMines()) + { + float fade = Utils.InverseLerp(8f, 24f, projectile.timeLeft, true) * Utils.InverseLerp(8f, 24f, mine.timeLeft, true); + drawLineTo(mine.Center, Color.White * fade); + } + + spriteBatch.Draw(baseTexture, drawPosition, null, projectile.GetAlpha(lightColor), projectile.rotation, origin, projectile.scale, SpriteEffects.None, 0f); + + Rectangle glowFrame = glowTexture.Frame(1, 6, 0, (int)Time / 4 % 6); + Color glowColor = Color.White * 0.5f; + glowColor.A = 0; + spriteBatch.Draw(glowTexture, drawPosition, glowFrame, glowColor, projectile.rotation, origin, projectile.scale, SpriteEffects.None, 0f); + return false; + } + } +} \ No newline at end of file diff --git a/Projectiles/Ranged/PrismMine.png b/Projectiles/Ranged/PrismMine.png new file mode 100644 index 0000000000..f6e0b4a1e3 Binary files /dev/null and b/Projectiles/Ranged/PrismMine.png differ diff --git a/Projectiles/Ranged/PrismMineArc.png b/Projectiles/Ranged/PrismMineArc.png new file mode 100644 index 0000000000..5fa9c7b1b4 Binary files /dev/null and b/Projectiles/Ranged/PrismMineArc.png differ diff --git a/Projectiles/Ranged/PrismMineGlowmask.png b/Projectiles/Ranged/PrismMineGlowmask.png new file mode 100644 index 0000000000..bec3e59194 Binary files /dev/null and b/Projectiles/Ranged/PrismMineGlowmask.png differ diff --git a/Projectiles/Ranged/PrismaticEnergyBlast.cs b/Projectiles/Ranged/PrismaticEnergyBlast.cs new file mode 100644 index 0000000000..073240ffd1 --- /dev/null +++ b/Projectiles/Ranged/PrismaticEnergyBlast.cs @@ -0,0 +1,147 @@ +using CalamityMod.Projectiles.BaseProjectiles; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Ranged +{ + public class PrismaticEnergyBlast : BaseLaserbeamProjectile + { + public bool ExplodedYet + { + get => projectile.ai[1] == 1f; + set => projectile.ai[1] = value.ToInt(); + } + public override string Texture => "CalamityMod/ExtraTextures/Lasers/PrismLaserStart"; + public override float MaxScale => 1f; + public override float MaxLaserLength => 2700f; + public override float Lifetime => 50f; + public override Color LaserOverlayColor => Color.White; + public override Color LightCastColor => LaserOverlayColor; + public override Texture2D LaserBeginTexture => ModContent.GetTexture("CalamityMod/ExtraTextures/Lasers/PrismLaserStart"); + public override Texture2D LaserMiddleTexture => ModContent.GetTexture("CalamityMod/ExtraTextures/Lasers/PrismLaserMid"); + public override Texture2D LaserEndTexture => ModContent.GetTexture("CalamityMod/ExtraTextures/Lasers/PrismLaserEnd"); + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Energy Blast"); + Main.projFrames[projectile.type] = 5; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 14; + projectile.friendly = true; + projectile.ranged = true; + projectile.tileCollide = false; + projectile.penetrate = 100; + projectile.extraUpdates = 1; + projectile.timeLeft = 450; + } + + public override bool PreAI() + { + projectile.frameCounter++; + if (projectile.frameCounter % 5 == 4) + projectile.frame++; + + Vector2 laserEnd = projectile.position + projectile.velocity * LaserLength; + if (Collision.SolidCollision(laserEnd, 84, 84)) + CreateExplosion(laserEnd + projectile.Size * 0.5f); + return true; + } + + public void CreateExplosion(Vector2 laserEnd) + { + if (Main.myPlayer != projectile.owner || ExplodedYet || LaserLength <= 60f) + return; + + Projectile.NewProjectile(laserEnd, Vector2.Zero, ModContent.ProjectileType(), projectile.damage, 0f, projectile.owner); + + if (!ExplodedYet) + { + ExplodedYet = true; + projectile.netUpdate = true; + } + } + + public override float DetermineLaserLength() + { + if (projectile.penetrate == 100) + return DetermineLaserLength_CollideWithTiles(8); + return LaserLength; + } + + public override bool CanDamage() => projectile.penetrate == 100; + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + LaserLength = projectile.Distance(target.Center); + CreateExplosion(target.Center); + } + + public override void Kill(int timeLeft) + { + Vector2 laserEnd = projectile.Center + projectile.velocity * LaserLength; + CreateExplosion(laserEnd); + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + // Start texture drawing. + Rectangle beginFrame = LaserBeginTexture.Frame(1, Main.projFrames[projectile.type], 0, projectile.frame); + spriteBatch.Draw(LaserBeginTexture, + projectile.Center - Main.screenPosition, + beginFrame, + Color.White, + projectile.rotation, + beginFrame.Size() / 2f, + projectile.scale, + SpriteEffects.None, + 0f); + + // Prepare things for body drawing. + float laserBodyLength = LaserLength; + laserBodyLength -= (LaserBeginTexture.Height * 0.5f + LaserEndTexture.Height) * projectile.scale / Main.projFrames[projectile.type]; + Vector2 centerOnLaser = projectile.Center; + + // Body drawing. + Rectangle middleFrame = LaserMiddleTexture.Frame(1, Main.projFrames[projectile.type], 0, projectile.frame); + if (laserBodyLength > 30f) + { + float laserOffset = (LaserMiddleTexture.Height - 10f) * projectile.scale / Main.projFrames[projectile.type]; + float incrementalBodyLength = 0f; + while (incrementalBodyLength + 1f < laserBodyLength) + { + spriteBatch.Draw(LaserMiddleTexture, + centerOnLaser - Main.screenPosition, + middleFrame, + Color.White, + projectile.rotation, + middleFrame.Width * 0.5f * Vector2.UnitX, + projectile.scale, + SpriteEffects.None, + 0f); + incrementalBodyLength += laserOffset; + centerOnLaser += projectile.velocity * laserOffset; + } + } + + // End texture drawing. + Rectangle endFrame = LaserEndTexture.Frame(1, Main.projFrames[projectile.type], 0, projectile.frame); + Vector2 laserEndCenter = centerOnLaser - Main.screenPosition; + spriteBatch.Draw(LaserEndTexture, + laserEndCenter, + endFrame, + Color.White, + projectile.rotation, + endFrame.Size() * new Vector2(0.5f, 0f), + projectile.scale, + SpriteEffects.None, + 0f); + return false; + } + } +} diff --git a/Projectiles/Ranged/PrismaticEnergyBlast.png b/Projectiles/Ranged/PrismaticEnergyBlast.png new file mode 100644 index 0000000000..8e2d2a871c Binary files /dev/null and b/Projectiles/Ranged/PrismaticEnergyBlast.png differ diff --git a/Projectiles/Ranged/RealmRavagerBullet.cs b/Projectiles/Ranged/RealmRavagerBullet.cs index 8222e92154..6b93f23fdd 100644 --- a/Projectiles/Ranged/RealmRavagerBullet.cs +++ b/Projectiles/Ranged/RealmRavagerBullet.cs @@ -38,23 +38,20 @@ namespace CalamityMod.Projectiles.Ranged public override void Kill(int timeLeft) { - Main.PlaySound(SoundID.Item14, projectile.position); - projectile.position = projectile.Center; - projectile.width = projectile.height = 32; - projectile.position.X = projectile.position.X - (float)(projectile.width / 2); - projectile.position.Y = projectile.position.Y - (float)(projectile.height / 2); - for (int num193 = 0; num193 < 2; num193++) + Main.PlaySound(SoundID.Item14, projectile.Center); + CalamityGlobalProjectile.ExpandHitboxBy(projectile, 32); + for (int d = 0; d < 2; d++) { - Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 31, 0f, 0f, 100, default, 1.5f); + Dust.NewDust(projectile.position, projectile.width, projectile.height, DustID.Smoke, 0f, 0f, 100, default, 1.5f); } - for (int num194 = 0; num194 < 20; num194++) + for (int d = 0; d < 20; d++) { - int num195 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 0, default, 2.5f); - Main.dust[num195].noGravity = true; - Main.dust[num195].velocity *= 3f; - num195 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default, 1.5f); - Main.dust[num195].velocity *= 2f; - Main.dust[num195].noGravity = true; + int idx = Dust.NewDust(projectile.position, projectile.width, projectile.height, DustID.Fire, 0f, 0f, 0, default, 2.5f); + Main.dust[idx].noGravity = true; + Main.dust[idx].velocity *= 3f; + idx = Dust.NewDust(projectile.position, projectile.width, projectile.height, DustID.Fire, 0f, 0f, 100, default, 1.5f); + Main.dust[idx].velocity *= 2f; + Main.dust[idx].noGravity = true; } projectile.maxPenetrate = -1; projectile.penetrate = -1; diff --git a/Projectiles/Ranged/SurgeDriverHoldout.cs b/Projectiles/Ranged/SurgeDriverHoldout.cs new file mode 100644 index 0000000000..0031b41ef4 --- /dev/null +++ b/Projectiles/Ranged/SurgeDriverHoldout.cs @@ -0,0 +1,100 @@ +using Microsoft.Xna.Framework; +using System; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Ranged +{ + public class SurgeDriverHoldout : ModProjectile + { + public Player Owner => Main.player[projectile.owner]; + public bool OwnerCanShoot => Owner.channel && Owner.HasAmmo(Owner.ActiveItem(), true) && !Owner.noItems && !Owner.CCed; + public ref float ShootCountdown => ref projectile.ai[0]; + public override void SetStaticDefaults() => DisplayName.SetDefault("Storm Driver"); + + public override void SetDefaults() + { + projectile.width = 192; + projectile.height = 52; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.tileCollide = false; + projectile.ranged = true; + projectile.ignoreWater = true; + } + + public override void AI() + { + if (!OwnerCanShoot) + projectile.Kill(); + + Vector2 armPosition = Owner.RotatedRelativePoint(Owner.MountedCenter, true); + armPosition += projectile.velocity.SafeNormalize(Owner.direction * Vector2.UnitX) * 32f; + armPosition.Y -= 12f; + + UpdateProjectileHeldVariables(armPosition); + ManipulatePlayerVariables(); + + ShootCountdown--; + if (ShootCountdown <= 0f) + { + if (Main.myPlayer == projectile.owner) + { + ShootProjectiles(armPosition); + ShootCountdown = 28f; + projectile.netUpdate = true; + } + + Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Item, "Sounds/Item/LaserCannon"), projectile.Center); + } + } + + public void ShootProjectiles(Vector2 armPosition) + { + if (Main.myPlayer != projectile.owner) + return; + + Item heldItem = Owner.ActiveItem(); + int projectileType = ModContent.ProjectileType(); + float shootSpeed = heldItem.shootSpeed * projectile.scale * 0.64f; + int damage = (int)(Owner.GetWeaponDamage(heldItem) * 6.66); + float knockback = heldItem.knockBack; + + bool uselessFuckYou = OwnerCanShoot; + Owner.PickAmmo(heldItem, ref projectileType, ref shootSpeed, ref uselessFuckYou, ref damage, ref knockback, false); + projectileType = ModContent.ProjectileType(); + + knockback = Owner.GetWeaponKnockback(heldItem, knockback); + Vector2 shootDirection = (Main.MouseWorld - projectile.Center).SafeNormalize(-Vector2.UnitY); + Vector2 shootVelocity = shootDirection * shootSpeed; + + // Sync if the shoot direction changes. + if (shootDirection.X != projectile.velocity.X || shootDirection.Y != projectile.velocity.Y) + projectile.netUpdate = true; + + Vector2 gunTip = armPosition + shootDirection * heldItem.scale * 130f; + Projectile.NewProjectile(gunTip, shootVelocity, projectileType, damage, knockback, projectile.owner, 0f, 0f); + + projectile.velocity = shootDirection; + } + + public void UpdateProjectileHeldVariables(Vector2 armPosition) + { + projectile.position = armPosition - projectile.Size * 0.5f; + projectile.rotation = projectile.velocity.ToRotation(); + if (projectile.spriteDirection == -1) + projectile.rotation += MathHelper.Pi; + projectile.spriteDirection = projectile.direction; + projectile.timeLeft = 2; + } + + public void ManipulatePlayerVariables() + { + Owner.ChangeDir(projectile.direction); + Owner.heldProj = projectile.whoAmI; + Owner.itemTime = 2; + Owner.itemAnimation = 2; + Owner.itemRotation = (projectile.velocity * projectile.direction).ToRotation(); + } + } +} diff --git a/Projectiles/Ranged/SurgeDriverHoldout.png b/Projectiles/Ranged/SurgeDriverHoldout.png new file mode 100644 index 0000000000..1d943243d5 Binary files /dev/null and b/Projectiles/Ranged/SurgeDriverHoldout.png differ diff --git a/Projectiles/Rogue/DukesDecapitatorProj.cs b/Projectiles/Rogue/DukesDecapitatorProj.cs index 1ee9bd50e4..2162902ecd 100644 --- a/Projectiles/Rogue/DukesDecapitatorProj.cs +++ b/Projectiles/Rogue/DukesDecapitatorProj.cs @@ -8,12 +8,9 @@ using CalamityMod.CalPlayer; namespace CalamityMod.Projectiles.Rogue { public class DukesDecapitatorProj : ModProjectile - { - public override string Texture => "CalamityMod/Items/Weapons/Rogue/DukesDecapitator"; - - bool stealthBubbles = false; + { float rotationAmount = 1.5f; - + public override string Texture => "CalamityMod/Items/Weapons/Rogue/DukesDecapitator"; public override void SetStaticDefaults() { DisplayName.SetDefault("Decapitator"); @@ -43,18 +40,13 @@ namespace CalamityMod.Projectiles.Rogue projectile.velocity *= 0.99f; } projectile.ai[0] += 1f; - if (projectile.ai[0] == 1f && modPlayer.StealthStrikeAvailable()) - { - stealthBubbles = true; - projectile.Calamity().stealthStrike = true; - } if (projectile.ai[0] == 5f) projectile.tileCollide = true; if ((projectile.ai[0] % 15f) == 0f && rotationAmount > 0) { rotationAmount -= 0.05f; - if(stealthBubbles == true && projectile.owner == Main.myPlayer) + if (projectile.Calamity().stealthStrike && projectile.owner == Main.myPlayer) { float velocityX = Main.rand.NextFloat(-0.8f, 0.8f); float velocityY = Main.rand.NextFloat(-0.8f, -0.8f); diff --git a/Projectiles/Rogue/LuminousStrikerProj.cs b/Projectiles/Rogue/LuminousStrikerProj.cs index d5f0bedbc1..424654f468 100644 --- a/Projectiles/Rogue/LuminousStrikerProj.cs +++ b/Projectiles/Rogue/LuminousStrikerProj.cs @@ -32,10 +32,8 @@ namespace CalamityMod.Projectiles.Rogue public override void AI() { - CalamityPlayer modPlayer = Main.player[projectile.owner].Calamity(); - if (projectile.ai[0] == 0f && modPlayer.StealthStrikeAvailable()) + if (projectile.ai[0] == 0f && projectile.Calamity().stealthStrike) { - projectile.Calamity().stealthStrike = true; projectile.timeLeft = 600; projectile.ai[0] = 1f; } diff --git a/Projectiles/Rogue/PrismRocket.cs b/Projectiles/Rogue/PrismRocket.cs new file mode 100644 index 0000000000..25e8598ab3 --- /dev/null +++ b/Projectiles/Rogue/PrismRocket.cs @@ -0,0 +1,75 @@ +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Rogue +{ + public class PrismRocket : ModProjectile + { + public float ExponentialAccelerationFactor => projectile.Calamity().stealthStrike ? 1.027f : 1.015f; + public float MaxHomingSpeed => projectile.Calamity().stealthStrike ? 26f : 21f; + public const int Lifetime = 150; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Prism Rocket"); + ProjectileID.Sets.TrailingMode[projectile.type] = 2; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 20; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 16; + projectile.friendly = true; + projectile.melee = true; + projectile.penetrate = 1; + projectile.tileCollide = false; + projectile.timeLeft = Lifetime; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 9; + projectile.Calamity().rogue = true; + } + + public override void AI() + { + NPC potentialTarget = projectile.Center.ClosestNPCAt(800f, true); + if (potentialTarget != null) + AttackTarget(potentialTarget); + + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2; + EmitDust(); + } + + public void AttackTarget(NPC target) + { + float newSpeed = projectile.velocity.Length() * ExponentialAccelerationFactor; + if (newSpeed > MaxHomingSpeed) + newSpeed = MaxHomingSpeed; + + if (!projectile.WithinRange(target.Center, 30f)) + { + projectile.velocity = (projectile.velocity * 5f + projectile.SafeDirectionTo(target.Center) * newSpeed) / 6f; + projectile.velocity = projectile.velocity.ToRotation().AngleTowards(projectile.AngleTo(target.Center), 0.15f).ToRotationVector2() * newSpeed; + } + } + + public void EmitDust() + { + if (Main.dedServ) + return; + + for (int i = 0; i < 2; i++) + { + if (!Main.rand.NextBool(3)) + continue; + + Dust dust = Dust.NewDustPerfect(projectile.Center - (projectile.rotation - MathHelper.PiOver2).ToRotationVector2() * 10f, 261); + dust.color = Color.Cyan; + dust.velocity = Main.rand.NextVector2Unit(); + dust.scale = Main.rand.NextFloat(0.75f, 1.05f); + dust.noGravity = true; + } + } + } +} diff --git a/Projectiles/Rogue/PrismRocket.png b/Projectiles/Rogue/PrismRocket.png new file mode 100644 index 0000000000..dd035814fc Binary files /dev/null and b/Projectiles/Rogue/PrismRocket.png differ diff --git a/Projectiles/Rogue/PrismShurikenBlade.cs b/Projectiles/Rogue/PrismShurikenBlade.cs new file mode 100644 index 0000000000..31e90538bb --- /dev/null +++ b/Projectiles/Rogue/PrismShurikenBlade.cs @@ -0,0 +1,54 @@ +using Terraria; +using Terraria.ModLoader; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria.ID; + +namespace CalamityMod.Projectiles.Rogue +{ + public class PrismShurikenBlade : ModProjectile + { + public override void SetStaticDefaults() => DisplayName.SetDefault("Blade"); + + public override void SetDefaults() + { + projectile.width = projectile.height = 22; + projectile.friendly = true; + projectile.ignoreWater = true; + projectile.Calamity().rogue = true; + projectile.extraUpdates = 1; + projectile.timeLeft = 360; + } + + public override void AI() + { + CalamityGlobalProjectile.HomeInOnNPC(projectile, false, 850f, 14.5f, 35f); + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2; + } + + public override void Kill(int timeLeft) + { + if (Main.dedServ) + return; + + for (int i = 0; i < 15; i++) + { + Vector2 circularOffsetDirection = (MathHelper.TwoPi * i / 15f).ToRotationVector2().RotatedBy(projectile.velocity.ToRotation() - MathHelper.PiOver2); + Vector2 spawnPosition = projectile.Center - (projectile.rotation - MathHelper.PiOver2).ToRotationVector2() * projectile.height * 1.25f; + spawnPosition += circularOffsetDirection * new Vector2(12f, 7f); + + Dust energy = Dust.NewDustPerfect(spawnPosition, 261); + energy.velocity = circularOffsetDirection * new Vector2(3f, 2f); + energy.color = Color.Cyan; + energy.scale = 0.7f; + energy.noGravity = true; + } + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + CalamityUtils.DrawAfterimagesCentered(projectile, ProjectileID.Sets.TrailingMode[projectile.type], lightColor); + return false; + } + } +} diff --git a/Projectiles/Rogue/PrismShurikenBlade.png b/Projectiles/Rogue/PrismShurikenBlade.png new file mode 100644 index 0000000000..dd035814fc Binary files /dev/null and b/Projectiles/Rogue/PrismShurikenBlade.png differ diff --git a/Projectiles/Rogue/RefractionRotorGlowmask.png b/Projectiles/Rogue/RefractionRotorGlowmask.png new file mode 100644 index 0000000000..0cdffe82c6 Binary files /dev/null and b/Projectiles/Rogue/RefractionRotorGlowmask.png differ diff --git a/Projectiles/Rogue/RefractionRotorProjectile.cs b/Projectiles/Rogue/RefractionRotorProjectile.cs new file mode 100644 index 0000000000..24cdfaf854 --- /dev/null +++ b/Projectiles/Rogue/RefractionRotorProjectile.cs @@ -0,0 +1,115 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Rogue +{ + public class RefractionRotorProjectile : ModProjectile + { + public const int EnergyShotCount = 6; + public override string Texture => "CalamityMod/Items/Weapons/Rogue/RefractionRotor"; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Prism Shuriken"); + ProjectileID.Sets.TrailingMode[projectile.type] = 2; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 16; + } + + public override void SetDefaults() + { + projectile.width = 142; + projectile.height = 126; + projectile.friendly = true; + projectile.penetrate = 10; + projectile.timeLeft = 300; + projectile.alpha = 255; + projectile.tileCollide = false; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 10; + projectile.Calamity().rogue = true; + } + + public override void AI() + { + projectile.alpha = Utils.Clamp(projectile.alpha - 18, 0, 255); + projectile.rotation += projectile.velocity.Length() * Math.Sign(projectile.velocity.X) * 0.036f; + } + + public override bool CanDamage() => projectile.alpha <= 128; + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + if (projectile.timeLeft > 20) + projectile.timeLeft = 20; + } + + public override void Kill(int timeLeft) + { + // Release a puff of rainbow dust and some blades. + // If this projectile is a stealth strike, don't create the blades as a gore-- create them as a projectile instead. + if (!Main.dedServ) + { + for (int i = 0; i < 15; i++) + { + Dust rainbowBurst = Dust.NewDustPerfect(projectile.Center, 267); + rainbowBurst.color = Main.hslToRgb(i / 80f, 0.9f, 0.6f); + rainbowBurst.velocity = Main.rand.NextVector2Unit() * Main.rand.NextFloat(3f, 5.5f); + rainbowBurst.scale = Main.rand.NextFloat(1.4f, 2.4f); + rainbowBurst.fadeIn = Main.rand.NextFloat(0.8f, 1.6f); + rainbowBurst.noGravity = true; + } + + if (!projectile.Calamity().stealthStrike) + { + int goreType = mod.GetGoreSlot("Gores/PrismShurikenBlade"); + for (int i = 0; i < 6; i++) + { + Vector2 shootDirection = (MathHelper.TwoPi * i / 6f + projectile.rotation + MathHelper.PiOver2).ToRotationVector2(); + Vector2 spawnPosition = projectile.Center + projectile.Size * 0.5f * projectile.scale * shootDirection * 0.85f; + if (!WorldGen.SolidTile((int)spawnPosition.X / 16, (int)spawnPosition.Y / 16)) + Gore.NewGorePerfect(spawnPosition, projectile.velocity * 0.5f + shootDirection * 7f, goreType, projectile.scale); + } + } + } + + int shootType = ModContent.ProjectileType(); + if (Main.myPlayer != projectile.owner) + return; + + // Release a circle of damaging blades if this projectile is a stealth strike. + if (projectile.Calamity().stealthStrike) + { + int bladeType = ModContent.ProjectileType(); + for (int i = 0; i < 6; i++) + { + Vector2 shootDirection = (MathHelper.TwoPi * i / 6f + projectile.rotation + MathHelper.PiOver2).ToRotationVector2(); + Vector2 spawnPosition = projectile.Center + projectile.Size * 0.5f * projectile.scale * shootDirection * 0.85f; + Projectile.NewProjectile(spawnPosition, projectile.velocity * 0.5f + shootDirection * 7f, bladeType, projectile.damage, projectile.knockBack, projectile.owner); + } + } + + if (CalamityUtils.CountProjectiles(shootType) > 24) + return; + + int energyDamage = (int)(projectile.damage * 0.66); + float baseDirectionRotation = Main.rand.NextFloat(MathHelper.TwoPi); + for (int i = 0; i < EnergyShotCount; i++) + { + Vector2 shootVelocity = (MathHelper.TwoPi * i / EnergyShotCount + baseDirectionRotation).ToRotationVector2() * 9f; + Projectile.NewProjectile(projectile.Center + shootVelocity, shootVelocity, shootType, energyDamage, projectile.knockBack, projectile.owner); + } + } + + public override void PostDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D glowmask = ModContent.GetTexture("CalamityMod/Projectiles/Rogue/RefractionRotorGlowmask"); + Vector2 drawPosition = projectile.Center - Main.screenPosition + Vector2.UnitY * projectile.gfxOffY; + Vector2 origin = glowmask.Size() * 0.5f; + spriteBatch.Draw(glowmask, drawPosition, null, projectile.GetAlpha(Color.White), projectile.rotation, origin, projectile.scale, SpriteEffects.None, 0f); + } + } +} diff --git a/Projectiles/Rogue/SacrificeProjectile.cs b/Projectiles/Rogue/SacrificeProjectile.cs new file mode 100644 index 0000000000..e86e784981 --- /dev/null +++ b/Projectiles/Rogue/SacrificeProjectile.cs @@ -0,0 +1,113 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System.IO; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Rogue +{ + public class SacrificeProjectile : ModProjectile + { + public Player Owner => Main.player[projectile.owner]; + public bool StickingToAnything => projectile.ai[0] == 1f; + public bool ReturningToOwner => projectile.ai[0] == 2f; + public bool AbleToHealOwner = true; + public override string Texture => "CalamityMod/Items/Weapons/Rogue/Sacrifice"; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Sacrifice"); + ProjectileID.Sets.TrailingMode[projectile.type] = 1; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 8; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 68; + projectile.friendly = true; + projectile.ignoreWater = true; + projectile.penetrate = -1; + projectile.timeLeft = 600; + projectile.Calamity().rogue = true; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 6; + } + + public override void SendExtraAI(BinaryWriter writer) => writer.Write(AbleToHealOwner); + + public override void ReceiveExtraAI(BinaryReader reader) => AbleToHealOwner = reader.ReadBoolean(); + + + public override void AI() + { + if (ReturningToOwner) + { + projectile.timeLeft = 2; + projectile.velocity = projectile.SafeDirectionTo(Owner.Center) * 24f; + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.Pi + MathHelper.PiOver4; + + // Heal the player and disappear when touching them. + if (projectile.Hitbox.Intersects(Owner.Hitbox)) + { + if (!Owner.moonLeech && AbleToHealOwner) + { + int healAmount = projectile.Calamity().stealthStrike ? 50 : 4; + + Owner.HealEffect(healAmount); + Owner.statLife += healAmount; + if (Owner.statLife > Owner.statLifeMax2) + Owner.statLife = Owner.statLifeMax2; + } + + projectile.Kill(); + } + } + else if (!StickingToAnything) + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver4; + else if (!Main.dedServ && projectile.timeLeft % 40f == 39f) + { + for (int i = 0; i < 60; i++) + { + Dust blood = Dust.NewDustPerfect(projectile.Center + Main.rand.NextVector2Circular(50f, 50f), 267); + blood.velocity = Main.rand.NextVector2Circular(3f, 3f); + blood.noGravity = true; + blood.color = Color.Lerp(Color.Red, Color.DarkRed, Main.rand.NextFloat(0.25f, 1f)); + blood.scale = Main.rand.NextFloat(1f, 1.4f); + } + } + + if (StickingToAnything && projectile.timeLeft > 90) + projectile.timeLeft = 90; + projectile.StickyProjAI(50); + } + + public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection) + { + projectile.ModifyHitNPCSticky(15, true); + projectile.velocity *= 0.5f; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + CalamityUtils.DrawAfterimagesCentered(projectile, ProjectileID.Sets.TrailingMode[projectile.type], lightColor); + return false; + } + + public override bool OnTileCollide(Vector2 oldVelocity) + { + Collision.HitTiles(projectile.position + projectile.velocity, projectile.velocity, projectile.width, projectile.height); + Main.PlaySound(SoundID.Dig, projectile.position); + projectile.Kill(); + return false; + } + + public override void Kill(int timeLeft) + { + for (int i = 0; i < 5; i++) + { + int dust = Dust.NewDust(projectile.Center, 1, 1, 5, 0, 0, 0, default, 1.5f); + Main.dust[dust].noGravity = true; + } + } + } +} diff --git a/Projectiles/Rogue/ScarletDevilBullet.cs b/Projectiles/Rogue/ScarletDevilBullet.cs index 84663dc8f2..dd5420ca52 100644 --- a/Projectiles/Rogue/ScarletDevilBullet.cs +++ b/Projectiles/Rogue/ScarletDevilBullet.cs @@ -18,7 +18,6 @@ namespace CalamityMod.Projectiles.Rogue projectile.timeLeft = 140; projectile.tileCollide = false; projectile.ignoreWater = true; - projectile.Calamity().rogue = true; } public override void AI() @@ -67,5 +66,12 @@ namespace CalamityMod.Projectiles.Rogue { return new Color(250, 250, 250); } + + public override bool CanDamage() + { + if (projectile.Calamity().stealthStrike && projectile.ai[0] < 60f) + return false; + return base.CanDamage(); + } } } diff --git a/Projectiles/Rogue/ScarletDevilProjectile.cs b/Projectiles/Rogue/ScarletDevilProjectile.cs index 6950364395..12af7ff5c2 100644 --- a/Projectiles/Rogue/ScarletDevilProjectile.cs +++ b/Projectiles/Rogue/ScarletDevilProjectile.cs @@ -3,6 +3,7 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; using Terraria; +using Terraria.Graphics.Shaders; using Terraria.ID; using Terraria.ModLoader; @@ -10,19 +11,22 @@ namespace CalamityMod.Projectiles.Rogue { public class ScarletDevilProjectile : ModProjectile { + internal PrimitiveTrail TrailDrawer; + public ref float ShootTimer => ref projectile.ai[0]; public override string Texture => "CalamityMod/Items/Weapons/Rogue/ScarletDevil"; public override void SetStaticDefaults() { DisplayName.SetDefault("Spear the Gungnir"); - ProjectileID.Sets.TrailCacheLength[projectile.type] = 8; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 45; ProjectileID.Sets.TrailingMode[projectile.type] = 0; } public override void SetDefaults() { - projectile.width = 116; - projectile.height = 116; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 45; + projectile.width = 92; + projectile.height = 92; projectile.friendly = true; projectile.ignoreWater = true; projectile.penetrate = 1; @@ -34,29 +38,72 @@ namespace CalamityMod.Projectiles.Rogue public override void AI() { - CalamityPlayer modPlayer = Main.player[projectile.owner].Calamity(); Lighting.AddLight(projectile.Center, 0.55f, 0.25f, 0f); - projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 0.785f; - Dust.NewDust(projectile.position + projectile.velocity, projectile.width, projectile.height, 130, projectile.velocity.X * 0.25f, projectile.velocity.Y * 0.25f, 0, new Color(255, 255, 255), 0.85f); - projectile.ai[0] += 1f; - if (projectile.ai[0] == 1f && modPlayer.StealthStrikeAvailable()) + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver4; + + if (!Main.dedServ) { - projectile.Calamity().stealthStrike = true; + for (int i = 0; i < (projectile.Calamity().stealthStrike && Main.rand.NextBool(2) ? 2 : 1); i++) + Dust.NewDust(projectile.position + projectile.velocity, projectile.width, projectile.height, 130, projectile.velocity.X * 0.25f, projectile.velocity.Y * 0.25f, 0, new Color(255, 255, 255), 0.85f); } - if ((projectile.ai[0] %= 5f) == 0f) + + ShootTimer++; + + if (!projectile.Calamity().stealthStrike && projectile.oldPos.Length != 6) + projectile.oldPos = new Vector2[6]; + + if ((ShootTimer %= 5f) == 0f && !projectile.Calamity().stealthStrike) { - int numProj = 2; - float rotation = MathHelper.ToRadians(15); if (projectile.owner == Main.myPlayer) + GenerateSideBullets(2, MathHelper.ToRadians(15f)); + } + } + + internal void GenerateSideBullets(int totalBullets, float rotationalOffset) + { + for (int i = 0; i < totalBullets; i++) + { + Vector2 perturbedSpeed = new Vector2(-projectile.velocity.X / 3, -projectile.velocity.Y / 3).RotatedBy(MathHelper.Lerp(-rotationalOffset, rotationalOffset, i / (totalBullets - 1))); + for (int j = 0; j < 2; j++) { - for (int i = 0; i < numProj; i++) + Projectile.NewProjectile(projectile.Center, perturbedSpeed, ModContent.ProjectileType(), (int)(projectile.damage * 0.03), 0f, projectile.owner, 0f, 0f); + perturbedSpeed *= 1.05f; + } + } + } + + internal void SpawnOnStealthStrikeBullets() + { + float starSpeed = 25f; + + // Spawn a circle of fast bullets. + for (int i = 0; i < 40; i++) + { + Vector2 shootVelocity = (MathHelper.TwoPi * i / 40f).ToRotationVector2() * starSpeed; + int bullet = Projectile.NewProjectile(projectile.Center + shootVelocity, shootVelocity, ModContent.ProjectileType(), (int)(projectile.damage * 0.01), 0f, projectile.owner); + if (Main.projectile.IndexInRange(bullet)) + Main.projectile[bullet].Calamity().stealthStrike = true; + } + + // Spawn a pair of stars, one slow, one fast. + int pointsOnStar = 6; + for (int k = 0; k < 2; k++) + { + for (int i = 0; i < pointsOnStar; i++) + { + float angle = MathHelper.Pi * 1.5f - i * MathHelper.TwoPi / pointsOnStar; + float nextAngle = MathHelper.Pi * 1.5f - (i + 3) % pointsOnStar * MathHelper.TwoPi / pointsOnStar; + if (k == 1) + nextAngle = MathHelper.Pi * 1.5f - (i + 2) * MathHelper.TwoPi / pointsOnStar; + Vector2 start = angle.ToRotationVector2(); + Vector2 end = nextAngle.ToRotationVector2(); + int pointsOnStarSegment = 18; + for (int j = 0; j < pointsOnStarSegment; j++) { - Vector2 perturbedSpeed = new Vector2(-projectile.velocity.X / 3, -projectile.velocity.Y / 3).RotatedBy(MathHelper.Lerp(-rotation, rotation, i / (numProj - 1))); - for (int j = 0; j < 2; j++) - { - Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, perturbedSpeed.X, perturbedSpeed.Y, ModContent.ProjectileType(), (int)((double)projectile.damage * 0.03), 0f, projectile.owner, 0f, 0f); - perturbedSpeed *= 1.05f; - } + Vector2 shootVelocity = Vector2.Lerp(start, end, j / (float)pointsOnStarSegment) * starSpeed; + int bullet = Projectile.NewProjectile(projectile.Center + shootVelocity, shootVelocity, ModContent.ProjectileType(), (int)(projectile.damage * 0.01), 0f, projectile.owner); + if (Main.projectile.IndexInRange(bullet)) + Main.projectile[bullet].Calamity().stealthStrike = true; } } } @@ -74,38 +121,78 @@ namespace CalamityMod.Projectiles.Rogue public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) { - projectile.position = projectile.Center; - projectile.width = projectile.height = 150; - projectile.position.X = projectile.position.X - (float)(projectile.width / 2); - projectile.position.Y = projectile.position.Y - (float)(projectile.height / 2); - Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, 0f, 0f, ModContent.ProjectileType(), (int)((double)projectile.damage * 0.0075), 0f, projectile.owner, 0f, 0f); - - if (!projectile.Calamity().stealthStrike || Main.player[projectile.owner].moonLeech) + CalamityGlobalProjectile.ExpandHitboxBy(projectile, 150); + Projectile.NewProjectile(projectile.Center, Vector2.Zero, ModContent.ProjectileType(), (int)(projectile.damage * 0.0075), 0f, projectile.owner); + if (!projectile.Calamity().stealthStrike) return; - Main.player[projectile.owner].statLife += 50; - Main.player[projectile.owner].HealEffect(50); + if (!Main.player[projectile.owner].moonLeech) + { + // Give on-heal effects from stealth strikes. + Main.player[projectile.owner].statLife += 120; + Main.player[projectile.owner].HealEffect(120); + } + + // And spawn a bloom of bullets. + SpawnOnStealthStrikeBullets(); } public override void OnHitPvp(Player target, int damage, bool crit) { - projectile.position = projectile.Center; - projectile.width = projectile.height = 150; - projectile.position.X = projectile.position.X - (float)(projectile.width / 2); - projectile.position.Y = projectile.position.Y - (float)(projectile.height / 2); - Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, 0f, 0f, ModContent.ProjectileType(), (int)((double)projectile.damage * 0.0075), 0f, projectile.owner, 0f, 0f); - - if (!projectile.Calamity().stealthStrike) + CalamityGlobalProjectile.ExpandHitboxBy(projectile, 150); + Projectile.NewProjectile(projectile.Center, Vector2.Zero, ModContent.ProjectileType(), (int)(projectile.damage * 0.0075), 0f, projectile.owner); + if (!projectile.Calamity().stealthStrike) return; - Main.player[projectile.owner].statLife += 50; - Main.player[projectile.owner].HealEffect(50); + // Give on-heal effects from stealth strikes. + Main.player[projectile.owner].statLife += 120; + Main.player[projectile.owner].HealEffect(120); + + // And spawn a bloom of bullets. + SpawnOnStealthStrikeBullets(); + } + + internal float WidthFunction(float completionRatio) + { + float widthRatio = Utils.InverseLerp(0f, 0.1f, completionRatio, true); + float baseWidth = MathHelper.Lerp(0f, 110f, widthRatio) * MathHelper.Clamp(1f - (float)Math.Pow(completionRatio, 0.4D), 0.37f, 1f); + return baseWidth; + } + + internal Color ColorFunction(float completionRatio) + { + float colorFade = 1f - Utils.InverseLerp(0.6f, 0.98f, completionRatio, true); + Color baseColor = CalamityUtils.MulticolorLerp((float)Math.Pow(completionRatio, 1D / 2D), Color.White, Color.DarkRed, Color.Wheat, Color.IndianRed) * MathHelper.Lerp(0f, 1.4f, colorFade); + return Color.Lerp(baseColor, Color.DarkRed, (float)Math.Pow(completionRatio, 3D)); } public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) { - CalamityUtils.DrawAfterimagesCentered(projectile, ProjectileID.Sets.TrailingMode[projectile.type], new Color(100, 100, 100), 1); - return true; + if (!projectile.Calamity().stealthStrike) + { + CalamityUtils.DrawAfterimagesCentered(projectile, ProjectileID.Sets.TrailingMode[projectile.type], new Color(100, 100, 100)); + return true; + } + else + { + if (TrailDrawer is null) + TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, PrimitiveTrail.RigidPointRetreivalFunction, GameShaders.Misc["CalamityMod:OverpoweredTouhouSpearShader"]); + + GameShaders.Misc["CalamityMod:OverpoweredTouhouSpearShader"].SetShaderTexture(ModContent.GetTexture("CalamityMod/ExtraTextures/ScarletDevilStreak")); + TrailDrawer.Draw(projectile.oldPos, projectile.Size * 0.5f - Main.screenPosition + projectile.velocity.SafeNormalize(Vector2.Zero) * 86f, 60); + + Texture2D spearTexture = ModContent.GetTexture(Texture); + + for (int i = 0; i < 7; i++) + { + Color drawColor = Color.Lerp(lightColor, Color.White, 0.8f) * 0.2f; + drawColor.A = 0; + + Vector2 drawOffset = (i / 7f * MathHelper.TwoPi).ToRotationVector2() * 2f; + spriteBatch.Draw(spearTexture, projectile.Center - Main.screenPosition + drawOffset, null, drawColor, projectile.rotation, spearTexture.Size() * 0.5f, projectile.scale, SpriteEffects.None, 0f); + } + } + return false; } } } diff --git a/Projectiles/Rogue/TheAtomSplitterDuplicate.cs b/Projectiles/Rogue/TheAtomSplitterDuplicate.cs new file mode 100644 index 0000000000..0dfc874940 --- /dev/null +++ b/Projectiles/Rogue/TheAtomSplitterDuplicate.cs @@ -0,0 +1,61 @@ +using CalamityMod.Items; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Rogue +{ + public class TheAtomSplitterDuplicate : ModProjectile + { + public ref float Time => ref projectile.ai[0]; + public ref float Lifetime => ref projectile.ai[1]; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Atom Splitter"); + ProjectileID.Sets.TrailCacheLength[projectile.type] = 6; + ProjectileID.Sets.TrailingMode[projectile.type] = 2; + } + + public override void SetDefaults() + { + projectile.scale = 0.66f; + projectile.width = projectile.height = (int)(124f * projectile.scale); + projectile.friendly = true; + projectile.penetrate = 3; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 16; + projectile.timeLeft = 900; + projectile.extraUpdates = 1; + projectile.Calamity().rogue = true; + } + + public override void AI() + { + // Accelerate until at a certain speed. + if (projectile.velocity.Length() < 20f) + projectile.velocity *= 1.02f; + + projectile.Opacity = CalamityUtils.Convert01To010(Time / Lifetime) * 0.6f; + if (Time >= Lifetime) + projectile.Kill(); + + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver4; + Time++; + } + + public override bool CanDamage() => projectile.alpha < 180; + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + if (Time <= 1f) + return false; + + Color drawColor = CalamityUtils.MulticolorLerp((Time / 35f + projectile.identity / 4f) % 1f, CalamityGlobalItem.ExoPalette); + drawColor.A = 0; + CalamityUtils.DrawAfterimagesCentered(projectile, ProjectileID.Sets.TrailingMode[projectile.type], drawColor); + return false; + } + } +} diff --git a/Projectiles/Rogue/TheAtomSplitterDuplicate.png b/Projectiles/Rogue/TheAtomSplitterDuplicate.png new file mode 100644 index 0000000000..e6f4b2d8f3 Binary files /dev/null and b/Projectiles/Rogue/TheAtomSplitterDuplicate.png differ diff --git a/Projectiles/Rogue/TheAtomSplitterProjectile.cs b/Projectiles/Rogue/TheAtomSplitterProjectile.cs new file mode 100644 index 0000000000..abc384ed25 --- /dev/null +++ b/Projectiles/Rogue/TheAtomSplitterProjectile.cs @@ -0,0 +1,166 @@ +using CalamityMod.Items; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.IO; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Rogue +{ + public class TheAtomSplitterProjectile : ModProjectile + { + public ref float HitTargetIndex => ref projectile.ai[0]; + public ref float Time => ref projectile.ai[1]; + + public override string Texture => "CalamityMod/Items/Weapons/Rogue/TheAtomSplitter"; + + public override void SetStaticDefaults() => DisplayName.SetDefault("Atom Splitter"); + + public override void SetDefaults() + { + projectile.width = projectile.height = 124; + projectile.friendly = true; + projectile.tileCollide = false; + projectile.penetrate = 2; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 10; + projectile.timeLeft = 300; + projectile.Calamity().rogue = true; + } + + public override void SendExtraAI(BinaryWriter writer) + { + // timeLeft is not synced by default. However, it is changed during an operation that is only + // performed from one client's perspective, therefore it must be synced in this context. + writer.Write(projectile.timeLeft); + writer.Write((byte)projectile.alpha); + writer.Write(projectile.scale); + } + + public override void ReceiveExtraAI(BinaryReader reader) + { + projectile.timeLeft = reader.ReadInt32(); + projectile.alpha = reader.ReadByte(); + projectile.scale = reader.ReadSingle(); + } + + public override void AI() + { + // Accelerate until at a certain speed. + if (projectile.velocity.Length() < 20f) + projectile.velocity *= 1.02f; + + if (projectile.alpha < 10) + EmitDustFromTip(); + + // Stick to the target for a while and release a bunch of duplicates. + if (Main.npc.IndexInRange((int)HitTargetIndex) && Main.npc[(int)HitTargetIndex].active) + { + if (projectile.alpha < 255) + projectile.alpha = Utils.Clamp(projectile.alpha + 30, 0, 255); + + int shootRate = projectile.Calamity().stealthStrike ? 2 : 4; + if (projectile.timeLeft % shootRate == shootRate - 1) + { + FireDuplicateAtTarget(Main.npc[(int)HitTargetIndex], projectile.Calamity().stealthStrike ? 305f : 200f); + if (projectile.Calamity().stealthStrike) + FireExtraDuplicatesAtTarget(Main.npc[(int)HitTargetIndex]); + } + } + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver4; + Time++; + } + + public void EmitDustFromTip() + { + if (Main.dedServ) + return; + + float dustVelocityArcOffset = 1.5f + (float)Math.Sin(MathHelper.TwoPi * projectile.timeLeft / 35f) * 0.25f; + + float colorInterpolant = (float)Math.Cos(MathHelper.TwoPi * projectile.timeLeft / 75f) * 0.5f + 0.5f; + Color dustColor = CalamityUtils.MulticolorLerp(colorInterpolant, CalamityGlobalItem.ExoPalette); + Vector2 currentDirection = projectile.velocity.SafeNormalize(-Vector2.UnitY); + Vector2 tipPosition = projectile.Center + currentDirection * (projectile.height * 0.67f - 3f); + tipPosition += Main.rand.NextVector2CircularEdge(0.35f, 0.35f); + + for (float direction = -1f; direction <= 1f; direction += 2f) + { + Dust prismaticEnergy = Dust.NewDustPerfect(tipPosition, 267); + prismaticEnergy.velocity = currentDirection.RotatedBy(direction * dustVelocityArcOffset) * -7f + projectile.velocity; + prismaticEnergy.scale = 1.2f; + prismaticEnergy.color = dustColor; + prismaticEnergy.noGravity = true; + + prismaticEnergy = Dust.CloneDust(prismaticEnergy); + prismaticEnergy.scale *= 0.6f; + } + } + + public void FireDuplicateAtTarget(NPC target, float baseOutwardness) + { + if (Main.myPlayer != projectile.owner) + return; + + Vector2 spawnPosition = target.Center + Main.rand.NextVector2CircularEdge(baseOutwardness, baseOutwardness) * Main.rand.NextFloat(0.9f, 1.15f); + Vector2 shootVelocity = (target.Center - spawnPosition).SafeNormalize(Vector2.UnitY) * Main.rand.NextFloat(12f, 14f); + Projectile.NewProjectile(spawnPosition, shootVelocity, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner, 0f, baseOutwardness / 9f); + } + + public void FireExtraDuplicatesAtTarget(NPC target) + { + if (Main.myPlayer != projectile.owner) + return; + + Vector2 spawnPosition = target.Center + Vector2.UnitY * Main.rand.NextBool(2).ToDirectionInt() * Main.rand.NextFloat(200f, 270f); + spawnPosition.X += Main.rand.NextFloatDirection() * target.width * 0.45f; + + Vector2 shootVelocity = Vector2.UnitY * (target.Center.Y - spawnPosition.Y > 0f).ToDirectionInt() * Main.rand.NextFloat(14f, 16.5f); + Projectile.NewProjectile(spawnPosition, shootVelocity, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner, 0f, 24f); + } + + public void ReleaseHitDust(Vector2 spawnPosition) + { + if (Main.dedServ) + return; + + int dustCount = projectile.Calamity().stealthStrike ? 60 : 40; + Vector2 baseDustVelocity = -Vector2.UnitY.RotatedByRandom(MathHelper.Pi) * 1.4f; + Vector2 outwardFireSpeedFactor = new Vector2(2.1f, 2f); + + for (float i = 0f; i < dustCount; i++) + { + Color dustColor = CalamityUtils.MulticolorLerp(Main.rand.NextFloat(), CalamityGlobalItem.ExoPalette); + Dust explosionDust = Dust.NewDustDirect(spawnPosition, 0, 0, 267, 0f, 0f, 0, dustColor, 1f); + explosionDust.position = spawnPosition; + explosionDust.velocity = baseDustVelocity.RotatedBy(MathHelper.TwoPi * i / dustCount) * outwardFireSpeedFactor * Main.rand.NextFloat(0.8f, 1.2f); + explosionDust.velocity += projectile.velocity * Main.rand.NextFloat(0.6f, 0.85f); + if (projectile.Calamity().stealthStrike) + explosionDust.velocity *= 1.6f; + + explosionDust.noGravity = true; + explosionDust.scale = 1.1f; + explosionDust.fadeIn = Main.rand.NextFloat(1.4f, 2.4f); + + Dust.CloneDust(explosionDust).velocity *= Main.rand.NextFloat(0.8f); + + explosionDust = Dust.CloneDust(explosionDust); + explosionDust.scale /= 2f; + explosionDust.fadeIn /= 2f; + explosionDust.color = new Color(255, 255, 255, 255); + } + } + + public override bool CanDamage() => projectile.alpha < 80; + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + ReleaseHitDust(target.Center - projectile.velocity * 3f); + HitTargetIndex = target.whoAmI; + projectile.timeLeft = projectile.Calamity().stealthStrike ? 100 : 60; + projectile.netUpdate = true; + } + } +} diff --git a/Projectiles/Summon/BrimstoneDartMinion.cs b/Projectiles/Summon/BrimstoneDartMinion.cs new file mode 100644 index 0000000000..68f0f1acd4 --- /dev/null +++ b/Projectiles/Summon/BrimstoneDartMinion.cs @@ -0,0 +1,58 @@ +using CalamityMod.Buffs.DamageOverTime; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + public class BrimstoneDartMinion : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Boss/BrimstoneBarrage"; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Brimfire"); + Main.projFrames[projectile.type] = 4; + ProjectileID.Sets.MinionShot[projectile.type] = true; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 2; + ProjectileID.Sets.TrailingMode[projectile.type] = 0; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 18; + projectile.friendly = true; + projectile.ignoreWater = true; + projectile.timeLeft = 300; + projectile.penetrate = 1; + projectile.minion = true; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 10; + projectile.alpha = 255; + } + + public override void AI() + { + projectile.frameCounter++; + projectile.frame = projectile.frameCounter / 5 % Main.projFrames[projectile.type]; + projectile.Opacity = Utils.InverseLerp(300f, 285f, projectile.timeLeft, true) * Utils.InverseLerp(0f, 15f, projectile.timeLeft, true); + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2; + + if (projectile.velocity.Length() < 35f) + projectile.velocity *= 1.036f; + + Lighting.AddLight(projectile.Center, 0.75f, 0f, 0f); + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) => target.AddBuff(ModContent.BuffType(), 600); + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + lightColor.R = (byte)(255 * projectile.Opacity); + CalamityUtils.DrawAfterimagesCentered(projectile, ProjectileID.Sets.TrailingMode[projectile.type], lightColor, 1); + return false; + } + } +} diff --git a/Projectiles/Summon/BrimstoneDartSummon.cs b/Projectiles/Summon/BrimstoneDartSummon.cs new file mode 100644 index 0000000000..4c234ceeba --- /dev/null +++ b/Projectiles/Summon/BrimstoneDartSummon.cs @@ -0,0 +1,80 @@ +using CalamityMod.Buffs.DamageOverTime; +using CalamityMod.Dusts; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + public class BrimstoneDartSummon : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Boss/BrimstoneBarrage"; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Brimstone Dart"); + Main.projFrames[projectile.type] = 4; + ProjectileID.Sets.MinionShot[projectile.type] = true; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 2; + ProjectileID.Sets.TrailingMode[projectile.type] = 0; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 24; + projectile.friendly = true; + projectile.ignoreWater = true; + projectile.tileCollide = false; + projectile.minion = true; + projectile.minionSlots = 0f; + projectile.penetrate = 1; + projectile.timeLeft = 120; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 8; + } + + public override void AI() + { + if (projectile.velocity.Length() < 21f) + projectile.velocity *= 1.02f; + + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2; + + projectile.frameCounter++; + if (projectile.frameCounter % 5 == 4) + projectile.frame = (projectile.frame + 1) % Main.projFrames[projectile.type]; + + projectile.Opacity = Utils.InverseLerp(0f, 40f, projectile.timeLeft, true); + + Lighting.AddLight(projectile.Center, 0.75f, 0f, 0f); + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + target.AddBuff(ModContent.BuffType(), 180); + } + + public override void Kill(int timeLeft) + { + if (Main.dedServ) + return; + + for (int i = 0; i < 15; i++) + { + Dust brimstone = Dust.NewDustPerfect(projectile.Center, 267); + brimstone.velocity = projectile.velocity.RotatedByRandom(0.26f) * Main.rand.NextFloat(0.3f, 0.8f); + brimstone.scale = Main.rand.NextFloat(1.5f, 1.85f); + brimstone.color = Color.DarkRed; + brimstone.noGravity = true; + } + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + lightColor.R = (byte)(255 * projectile.Opacity); + CalamityUtils.DrawAfterimagesCentered(projectile, ProjectileID.Sets.TrailingMode[projectile.type], lightColor, 1); + return false; + } + } +} diff --git a/Projectiles/Summon/CataclysmSummon.cs b/Projectiles/Summon/CataclysmSummon.cs new file mode 100644 index 0000000000..36beeecad4 --- /dev/null +++ b/Projectiles/Summon/CataclysmSummon.cs @@ -0,0 +1,115 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + public class CataclysmSummon : ModProjectile + { + public ref float Time => ref projectile.ai[0]; + public bool LookingAtPlayer => Time < 45f; + public override string Texture => "CalamityMod/NPCs/SupremeCalamitas/SupremeCataclysm"; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Cataclysm"); + Main.projFrames[projectile.type] = 6; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 4; + ProjectileID.Sets.TrailingMode[projectile.type] = 2; + ProjectileID.Sets.MinionSacrificable[projectile.type] = false; + ProjectileID.Sets.MinionTargettingFeature[projectile.type] = false; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 100; + projectile.netImportant = true; + projectile.friendly = true; + projectile.hostile = true; + projectile.ignoreWater = true; + projectile.minionSlots = 0f; + projectile.timeLeft = 90000; + projectile.penetrate = -1; + projectile.Opacity = 0f; + projectile.tileCollide = false; + projectile.minion = true; + } + + public override void AI() => Behavior(projectile, Main.player[projectile.owner], ref Time); + + public static void Behavior(Projectile projectile, Player owner, ref float time) + { + DoFrameEffects(projectile); + + if (time < 40f) + FadeIn(projectile); + + else if (time > 95f) + { + projectile.Opacity -= 0.06f; + if (projectile.Opacity < 0f) + projectile.Kill(); + } + + if (time < 25f) + { + float idealRotation = projectile.AngleTo(owner.Center) - MathHelper.PiOver2; + projectile.rotation = projectile.rotation.AngleLerp(idealRotation, 0.08f); + projectile.rotation = projectile.rotation.AngleTowards(idealRotation, 0.2f); + } + else if (time < 40f) + { + projectile.rotation = projectile.AngleTo(owner.Center) - MathHelper.PiOver2; + projectile.velocity = projectile.SafeDirectionTo(owner.Center) * -5f; + } + else if (time == 40f) + { + projectile.rotation = projectile.AngleTo(owner.Center) - MathHelper.PiOver2; + projectile.velocity = projectile.SafeDirectionTo(owner.Center) * 31f; + projectile.damage = (int)(projectile.damage * 1.45); + + Main.PlaySound(SoundID.DD2_BetsyFlameBreath, owner.Center); + Main.PlaySound(SoundID.DD2_WyvernDiveDown, owner.Center); + } + + time++; + } + + public static void FadeIn(Projectile projectile) + { + if (projectile.localAI[0] == 0f) + { + for (int i = 0; i < 40; i++) + { + Dust brimstone = Dust.NewDustPerfect(projectile.Center + Main.rand.NextVector2Square(-65f, 65f), 267); + brimstone.velocity = -Vector2.UnitY * Main.rand.NextFloat(1.8f, 3.6f); + brimstone.scale = Main.rand.NextFloat(1.65f, 1.85f); + brimstone.fadeIn = Main.rand.NextFloat(0.7f, 0.9f); + brimstone.color = Color.Red; + brimstone.noGravity = true; + } + projectile.localAI[0] = 1f; + } + + projectile.Opacity = MathHelper.Clamp(projectile.Opacity + 0.075f, 0f, 1f); + } + + public static void DoFrameEffects(Projectile projectile) + { + projectile.frameCounter++; + if (projectile.frameCounter % 5f == 4f) + projectile.frame = (projectile.frame + 1) % Main.projFrames[projectile.type]; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + CalamityUtils.DrawAfterimagesCentered(projectile, ProjectileID.Sets.TrailingMode[projectile.type], Color.Red, 1); + return true; + } + + public override void ModifyHitPlayer(Player target, ref int damage, ref bool crit) => damage = 70; + + public override bool CanDamage() => projectile.Opacity >= 1f; + } +} diff --git a/Projectiles/Summon/CatastropheSummon.cs b/Projectiles/Summon/CatastropheSummon.cs new file mode 100644 index 0000000000..d60bdafa56 --- /dev/null +++ b/Projectiles/Summon/CatastropheSummon.cs @@ -0,0 +1,51 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + public class CatastropheSummon : ModProjectile + { + public ref float Time => ref projectile.ai[0]; + public bool LookingAtPlayer => Time < 45f; + public override string Texture => "CalamityMod/NPCs/SupremeCalamitas/SupremeCatastrophe"; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Catastrophe"); + Main.projFrames[projectile.type] = 6; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 4; + ProjectileID.Sets.TrailingMode[projectile.type] = 2; + ProjectileID.Sets.MinionSacrificable[projectile.type] = false; + ProjectileID.Sets.MinionTargettingFeature[projectile.type] = false; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 120; + projectile.netImportant = true; + projectile.friendly = true; + projectile.hostile = true; + projectile.ignoreWater = true; + projectile.minionSlots = 0f; + projectile.timeLeft = 90000; + projectile.penetrate = -1; + projectile.Opacity = 0f; + projectile.tileCollide = false; + projectile.minion = true; + } + + public override void AI() => CataclysmSummon.Behavior(projectile, Main.player[projectile.owner], ref Time); + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + CalamityUtils.DrawAfterimagesCentered(projectile, ProjectileID.Sets.TrailingMode[projectile.type], Color.Red, 1); + return true; + } + + public override void ModifyHitPlayer(Player target, ref int damage, ref bool crit) => damage = 70; + + public override bool CanDamage() => projectile.Opacity >= 1f; + } +} diff --git a/Projectiles/Summon/DaedalusGolem.cs b/Projectiles/Summon/DaedalusGolem.cs new file mode 100644 index 0000000000..ef481613a1 --- /dev/null +++ b/Projectiles/Summon/DaedalusGolem.cs @@ -0,0 +1,318 @@ +using CalamityMod.Buffs.Summon; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.IO; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.World.Generation; + +namespace CalamityMod.Projectiles.Summon +{ + public class DaedalusGolem : ModProjectile + { + public int AttackTimer; + public bool UsingChargedLaserAttack; + public const int ChargedPelletAttackTime = 30; + public const int ChargedLaserAttackTime = 120; + public const float Gravity = 0.35f; + public bool Stuck => StuckWalkThroughWallsTimer >= 40f || Collision.SolidCollision(projectile.Center, 2, 2); + public Vector2 ArmPosition => projectile.Center + new Vector2(projectile.spriteDirection == 1 ? -4f : 32f, 0f); + public Player Owner => Main.player[projectile.owner]; + public ref float StuckWalkThroughWallsTimer => ref projectile.ai[0]; + public ref float StuckJumpSpeed => ref projectile.ai[1]; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Daedalus Golem"); + Main.projFrames[projectile.type] = 18; + ProjectileID.Sets.MinionSacrificable[projectile.type] = true; + ProjectileID.Sets.MinionTargettingFeature[projectile.type] = true; + } + + public override void SetDefaults() + { + projectile.width = 28; + projectile.height = 58; + projectile.netImportant = true; + projectile.friendly = true; + projectile.minionSlots = 1; + projectile.timeLeft = 90000; + projectile.penetrate = -1; + projectile.minion = true; + projectile.tileCollide = true; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 10; + } + + public override void SendExtraAI(BinaryWriter writer) + { + writer.Write(AttackTimer); + writer.Write(UsingChargedLaserAttack); + } + + public override void ReceiveExtraAI(BinaryReader reader) + { + AttackTimer = reader.ReadInt32(); + UsingChargedLaserAttack = reader.ReadBoolean(); + } + + #region AI + public override void AI() + { + Main.projFrames[projectile.type] = 16; + bool isCorrectProjectile = projectile.type == ModContent.ProjectileType(); + Owner.AddBuff(ModContent.BuffType(), 3600); + if (isCorrectProjectile) + { + if (Owner.dead) + Owner.Calamity().daedalusGolem = false; + + if (Owner.Calamity().daedalusGolem) + projectile.timeLeft = 2; + } + + AdjustMinionDamage(); + + // Fall down. + if (projectile.velocity.Y < 15f) + projectile.velocity.Y += Gravity; + + Vector2 destination; + NPC potentialTarget = projectile.Center.MinionHoming(900f, Owner); + if (potentialTarget is null) + destination = Owner.Center + Vector2.UnitX * (80f + (projectile.identity * 28f) % 560f); + else + destination = potentialTarget.Center + Vector2.UnitX * (130f + (projectile.identity * 28f) % 560f); + + // Go upwards, and check down again to discover any height differences before deciding where to move. + // There's a chance that this will encounter a null tile. If it us, just skip this step. + try + { + Vector2 upwardCheck = destination - Vector2.UnitY * 2400f; + upwardCheck.Y = Utils.Clamp(upwardCheck.Y, 0f, Main.maxTilesY * 16f - 100f); + WorldUtils.Find(upwardCheck.ToTileCoordinates(), Searches.Chain(new Searches.Down(200), new Conditions.IsSolid()), out Point loweredPoint); + destination = loweredPoint.ToWorldCoordinates(); + } + catch (NullReferenceException) { } + + StuckWalkThroughWallsTimer = Utils.Clamp(StuckWalkThroughWallsTimer, 0, 160); + + if (projectile.Distance(Owner.Center) > 3500f) + { + projectile.Center = Owner.Center; + StuckWalkThroughWallsTimer = 0; + projectile.netImportant = true; + } + if ((MoveToDestination(destination) || AttackTimer > 0) && potentialTarget != null) + { + AttackTimer++; + if (AttackTimer == 1) + { + UsingChargedLaserAttack = Main.rand.NextBool(7); + projectile.netUpdate = true; + } + + if (AttackTimer >= (UsingChargedLaserAttack ? ChargedLaserAttackTime : ChargedPelletAttackTime)) + { + AttackTimer = 0; + projectile.netUpdate = true; + } + + if (MathHelper.Distance(potentialTarget.Center.X, projectile.Center.X) > 30f) + projectile.spriteDirection = (potentialTarget.Center.X - projectile.Center.X < 0).ToDirectionInt(); + + if (UsingChargedLaserAttack) + { + if (AttackTimer >= 45 && AttackTimer < ChargedLaserAttackTime / 2 && !Main.dedServ) + { + Vector2 drawOffset = Main.rand.NextVector2CircularEdge(12f, 12f); + Dust light = Dust.NewDustPerfect(ArmPosition + drawOffset, 261); + light.velocity = drawOffset.SafeNormalize(Vector2.Zero) * -2.5f; + light.color = Color.Lerp(Color.HotPink, Color.LightPink, Main.rand.NextFloat()); + light.scale = Main.rand.NextFloat(1.2f, 1.45f); + light.noGravity = true; + } + else if (AttackTimer >= ChargedLaserAttackTime / 2 && AttackTimer <= ChargedLaserAttackTime / 2 + 60 && AttackTimer % 10 == 9) + { + Main.PlaySound(SoundID.Item122, ArmPosition); + if (Main.myPlayer == projectile.owner) + { + Vector2 initialVelocity = projectile.SafeDirectionTo(potentialTarget.Center) * 2f; + if (Main.rand.NextBool(2)) + initialVelocity = initialVelocity.RotatedByRandom(0.4f); + float initialAngle = initialVelocity.ToRotation(); + Projectile.NewProjectile(ArmPosition, initialVelocity, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner, initialAngle, Main.rand.Next(100)); + } + } + } + else if (!UsingChargedLaserAttack && AttackTimer == ChargedPelletAttackTime / 2 && Main.myPlayer == projectile.owner) + { + Vector2 initialVelocity = projectile.SafeDirectionTo(potentialTarget.Center + potentialTarget.velocity * 15f) * 19f; + Projectile.NewProjectile(ArmPosition, initialVelocity, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner); + } + } + else if (potentialTarget is null && AttackTimer != 0) + { + AttackTimer = 0; + projectile.netUpdate = true; + } + } + + public void AdjustMinionDamage() + { + if (projectile.localAI[0] == 0f) + { + projectile.Calamity().spawnedPlayerMinionDamageValue = Owner.MinionDamage(); + projectile.Calamity().spawnedPlayerMinionProjectileDamageValue = projectile.damage; + projectile.localAI[0] += 1f; + } + if (Owner.MinionDamage() != projectile.Calamity().spawnedPlayerMinionDamageValue) + { + int newDamage = (int)(projectile.Calamity().spawnedPlayerMinionProjectileDamageValue / + projectile.Calamity().spawnedPlayerMinionDamageValue * + Owner.MinionDamage()); + projectile.damage = newDamage; + } + } + + public bool MoveToDestination(Vector2 destination) + { + Tile tileBelow = CalamityUtils.ParanoidTileRetrieval((int)(projectile.Bottom.X / 16), (int)(projectile.Bottom.Y / 16) + 1); + + // Float to the destination if stuck. + if (Stuck) + { + StuckJumpSpeed = 0f; + projectile.tileCollide = false; + + if (projectile.DistanceSQ(destination - Vector2.UnitY * 16f) > 10f * 10f) + projectile.velocity = projectile.SafeDirectionTo(destination - Vector2.UnitY * 16f) * 6f; + else + StuckWalkThroughWallsTimer = 0; + + StuckWalkThroughWallsTimer -= 4; + return false; + } + + projectile.tileCollide = true; + // Don't bother moving any more if super close to the destination. + // Just slow down and face the player. + if (Math.Abs(projectile.Center.X - destination.X) < 55 + Math.Abs(projectile.velocity.X)) + { + StuckJumpSpeed = 0f; + projectile.velocity.X *= 0.8f; + return true; + } + + int currentWalkDirection = Math.Sign(projectile.velocity.X); + int tilesSearchedAhead = 0; + + Tile tileBelowAhead; + + do + { + tileBelowAhead = CalamityUtils.ParanoidTileRetrieval((int)(projectile.Bottom.X / 16) + currentWalkDirection, (int)(projectile.Bottom.Y / 16) + 1); + + if (tileBelowAhead.IsTileSolidGround()) + break; + + tilesSearchedAhead++; + } + while (tilesSearchedAhead < 4); + + int directionToWalk = Math.Sign(destination.X - projectile.Center.X); + float idealWalkSpeed = 10f * directionToWalk; + float walkAcceleration = directionToWalk != currentWalkDirection ? 0.325f : 0.2f; + projectile.velocity.X = MathHelper.Lerp(projectile.velocity.X, idealWalkSpeed, walkAcceleration); + + // Jump if there's a gap or a wall. + if (tileBelow.IsTileSolidGround() || Collision.SolidCollision(projectile.Center, 10, 10)) + { + if (Math.Abs(projectile.oldPosition.X - projectile.position.X) < 2f || + Collision.SolidCollision(projectile.Center, 2, 2) || + !Collision.CanHitLine(projectile.position, projectile.width, projectile.height, Owner.position, Owner.width, Owner.height)) + { + projectile.velocity.Y = -12f - StuckJumpSpeed; + projectile.netSpam -= 10; + StuckJumpSpeed += 3.5f; + StuckJumpSpeed = Utils.Clamp(StuckJumpSpeed, 0f, 14f); + + StuckWalkThroughWallsTimer += 10f; + + projectile.netUpdate = true; + } + else if (tilesSearchedAhead > 0) + { + projectile.velocity.X = 7f; + + projectile.velocity.Y = -(5f + tilesSearchedAhead * 2f); + projectile.netSpam -= 10; + projectile.netUpdate = true; + } + else + { + StuckJumpSpeed = 0f; + StuckWalkThroughWallsTimer -= 5f; + } + } + + projectile.spriteDirection = (Owner.Center.X - projectile.Center.X < 0).ToDirectionInt(); + return false; + } + #endregion + + // Prevent on-tile collision death. + public override bool OnTileCollide(Vector2 oldVelocity) => false; + public override bool TileCollideStyle(ref int width, ref int height, ref bool fallThrough) + { + fallThrough = projectile.Bottom.Y < Owner.Top.Y; + return true; + } + + public override void PostDraw(SpriteBatch spriteBatch, Color lightColor) + { + int startingWalkFrame = 6; + int endingWalkFrame = 10; + + int startingPelletFrame = 1; + int endingPelletFrame = 4; + + int startingBeamFrame = 11; + int endingBeamFrame = 15; + + // Walking frames. Moves more quickly the faster the walk. + projectile.frameCounter++; + Tile tileBelow = CalamityUtils.ParanoidTileRetrieval((int)(projectile.Bottom.X / 16), (int)(projectile.Bottom.Y / 16) + 1); + + if (Stuck) + { + projectile.frame = 5; + } + else if (AttackTimer > 0) + { + if (UsingChargedLaserAttack) + projectile.frame = (int)MathHelper.Lerp(startingBeamFrame, endingBeamFrame + 1, Utils.InverseLerp(0f, ChargedLaserAttackTime, AttackTimer, true)); + else + projectile.frame = (int)MathHelper.Lerp(startingPelletFrame, endingPelletFrame + 1, Utils.InverseLerp(0f, ChargedPelletAttackTime, AttackTimer, true)); + } + else if (Math.Abs(projectile.velocity.X) > 5f && Math.Abs(projectile.velocity.Y) < 2f && tileBelow.IsTileSolidGround()) + { + if (projectile.frameCounter >= Utils.Clamp(2, 6, (int)Math.Abs(projectile.velocity.X * 0.8))) + { + projectile.frameCounter = 0; + projectile.frame++; + if (projectile.frame >= endingWalkFrame) + projectile.frame = startingWalkFrame; + } + projectile.frame = Utils.Clamp(projectile.frame, startingWalkFrame, endingWalkFrame); + } + else if (Math.Abs(projectile.velocity.X) <= 1f) + { + projectile.frame = 0; + } + } + + public override bool CanDamage() => false; + } +} diff --git a/Projectiles/Summon/DaedalusGolem.png b/Projectiles/Summon/DaedalusGolem.png new file mode 100644 index 0000000000..56ae471ca9 Binary files /dev/null and b/Projectiles/Summon/DaedalusGolem.png differ diff --git a/Projectiles/Summon/DaedalusLightning.cs b/Projectiles/Summon/DaedalusLightning.cs new file mode 100644 index 0000000000..056a522d17 --- /dev/null +++ b/Projectiles/Summon/DaedalusLightning.cs @@ -0,0 +1,150 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.IO; +using System.Linq; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.Utilities; +namespace CalamityMod.Projectiles.Summon +{ + public class DaedalusLightning : ModProjectile + { + internal PrimitiveTrail LightningDrawer; + + public const int MaximumBranchingIterations = 3; + public const float LightningTurnRandomnessFactor = 1.7f; + public ref float InitialVelocityAngle => ref projectile.ai[0]; + // Technically not a ratio, and more of a seed, but it is used in a 0-2pi squash + // later in the code to get an arbitrary unit vector (which is then checked). + public ref float BaseTurnAngleRatio => ref projectile.ai[1]; + public ref float AccumulatedXMovementSpeeds => ref projectile.localAI[0]; + public ref float BranchingIteration => ref projectile.localAI[1]; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Daedalus Lightning"); + ProjectileID.Sets.MinionShot[projectile.type] = true; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 100; + ProjectileID.Sets.TrailingMode[projectile.type] = 1; + } + + public override void SetDefaults() + { + projectile.width = 14; + projectile.height = 14; + projectile.friendly = true; + projectile.minion = true; + projectile.alpha = 255; + projectile.penetrate = 2; + projectile.ignoreWater = true; + projectile.tileCollide = false; + projectile.extraUpdates = 20; + projectile.timeLeft = 45 * projectile.extraUpdates; + + // Readjust the velocity magnitude the moment this projectile is created + // to make velocity setting outside the scope of this projectile less irritating + // to consider alongside extraUpdate multipliers. + // Also set the initial angle. + if (projectile.velocity != Vector2.Zero) + { + projectile.velocity /= projectile.extraUpdates; + } + } + + public override void SendExtraAI(BinaryWriter writer) + { + writer.Write(AccumulatedXMovementSpeeds); + writer.Write(BranchingIteration); + } + + public override void ReceiveExtraAI(BinaryReader reader) + { + AccumulatedXMovementSpeeds = reader.ReadSingle(); + BranchingIteration = reader.ReadSingle(); + } + + public override void AI() + { + // frameCounter in this context is really just an arbitrary timer + // which allows random turning to occur. + projectile.frameCounter++; + + projectile.scale = (float)Math.Sin(MathHelper.Pi * projectile.timeLeft / (45f * (projectile.MaxUpdates - 1))) * 4f; + if (projectile.scale > 1f) + projectile.scale = 1f; + + Lighting.AddLight(projectile.Center, Color.Pink.ToVector3()); + if (projectile.frameCounter >= projectile.extraUpdates * 2) + { + projectile.frameCounter = 0; + + float originalSpeed = MathHelper.Min(6f, projectile.velocity.Length()); + UnifiedRandom unifiedRandom = new UnifiedRandom((int)BaseTurnAngleRatio); + int turnTries = 0; + Vector2 newBaseDirection = -Vector2.UnitY; + Vector2 potentialBaseDirection; + + do + { + BaseTurnAngleRatio = unifiedRandom.Next() % 100; + potentialBaseDirection = (BaseTurnAngleRatio / 100f * MathHelper.TwoPi).ToRotationVector2(); + + // Ensure that the new potential direction base is always moving upwards (this is supposed to be somewhat similar to a -UnitY + RotatedBy). + potentialBaseDirection.Y = -Math.Abs(potentialBaseDirection.Y); + + bool canChangeLightningDirection = true; + + // Potential directions with very little Y speed should not be considered, because this + // consequentially means that the X speed would be quite large. + if (potentialBaseDirection.Y > -0.02f) + canChangeLightningDirection = false; + + // This mess of math basically encourages movement at the ends of an extraUpdate cycle, + // discourages super frequenent randomness as the accumulated X speed changes get larger, + // or if the original speed is quite large. + if (Math.Abs(potentialBaseDirection.X * (projectile.extraUpdates + 1) * 2f * originalSpeed + AccumulatedXMovementSpeeds) > projectile.MaxUpdates * LightningTurnRandomnessFactor) + { + canChangeLightningDirection = false; + } + + // If the above checks were all passed, redefine the base direction of the lightning. + if (canChangeLightningDirection) + newBaseDirection = potentialBaseDirection; + + turnTries++; + } + while (turnTries < 100); + + if (projectile.velocity != Vector2.Zero) + { + AccumulatedXMovementSpeeds += newBaseDirection.X * (projectile.extraUpdates + 1) * 2f * originalSpeed; + projectile.velocity = newBaseDirection.RotatedBy(InitialVelocityAngle + MathHelper.PiOver2) * originalSpeed; + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2; + } + } + } + + #region Drawing + internal float WidthFunction(float completionRatio) + { + float baseWidth = MathHelper.Lerp(2f, 6f, (float)Math.Sin(MathHelper.Pi * 4f * completionRatio) * 0.5f + 0.5f) * projectile.scale; + return baseWidth * (float)Math.Sin(MathHelper.Pi * completionRatio); + } + internal Color ColorFunction(float completionRatio) + { + Color baseColor = Color.Lerp(Color.Pink, Color.HotPink, (float)Math.Sin(MathHelper.TwoPi * completionRatio + Main.GlobalTime * 4f) * 0.5f + 0.5f); + return Color.Lerp(baseColor, Color.Red, ((float)Math.Sin(MathHelper.Pi * completionRatio + Main.GlobalTime * 4f) * 0.5f + 0.5f) * 0.8f); + } + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + if (LightningDrawer is null) + LightningDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, PrimitiveTrail.RigidPointRetreivalFunction); + + LightningDrawer.Draw(projectile.oldPos.Where(oldPos => oldPos != Vector2.Zero), projectile.Size * 0.5f - Main.screenPosition, 300); + return false; + } + #endregion + } +} diff --git a/Projectiles/Summon/DaedalusLightning.png b/Projectiles/Summon/DaedalusLightning.png new file mode 100644 index 0000000000..f99e9c57d5 Binary files /dev/null and b/Projectiles/Summon/DaedalusLightning.png differ diff --git a/Projectiles/Summon/DaedalusPellet.cs b/Projectiles/Summon/DaedalusPellet.cs new file mode 100644 index 0000000000..99d908f1dd --- /dev/null +++ b/Projectiles/Summon/DaedalusPellet.cs @@ -0,0 +1,65 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +namespace CalamityMod.Projectiles.Summon +{ + public class DaedalusPellet : ModProjectile + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Pellet"); + Main.projFrames[projectile.type] = 3; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 5; + ProjectileID.Sets.TrailingMode[projectile.type] = 0; + ProjectileID.Sets.MinionShot[projectile.type] = true; + } + + public override void SetDefaults() + { + projectile.width = 10; + projectile.height = 10; + projectile.friendly = true; + projectile.minion = true; + projectile.ignoreWater = true; + projectile.tileCollide = false; + projectile.alpha = 255; + projectile.penetrate = 1; + projectile.timeLeft = 600; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = -2; + } + + public override void AI() + { + projectile.frameCounter++; + if (projectile.frameCounter > 4) + { + projectile.frame++; + if (projectile.frame >= 3) + { + projectile.frame = 0; + } + projectile.frameCounter = 0; + } + if (projectile.ai[0] == 0f) + { + projectile.ai[0] = 1f; + Main.PlaySound(SoundID.DD2_SkyDragonsFuryShot, projectile.Center); + } + projectile.alpha = Utils.Clamp(projectile.alpha - 50, 0, 255); + } + + public override Color? GetAlpha(Color lightColor) + { + return new Color(255, 255, 255, projectile.alpha); + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + CalamityUtils.DrawAfterimagesCentered(projectile, ProjectileID.Sets.TrailingMode[projectile.type], lightColor); + return false; + } + } +} diff --git a/Projectiles/Summon/DaedalusPellet.png b/Projectiles/Summon/DaedalusPellet.png new file mode 100644 index 0000000000..b057abe312 Binary files /dev/null and b/Projectiles/Summon/DaedalusPellet.png differ diff --git a/Projectiles/Summon/DazzlingStabber.cs b/Projectiles/Summon/DazzlingStabber.cs index 62b6114e16..99c39730e1 100644 --- a/Projectiles/Summon/DazzlingStabber.cs +++ b/Projectiles/Summon/DazzlingStabber.cs @@ -100,18 +100,14 @@ namespace CalamityMod.Projectiles.Summon return; } - // Don't do anything if very close to the target. - if (projectile.WithinRange(target.Center, 60f)) - return; - // Reset the velocity to fly upward if there is very little motion to ensure // that the summon does not get stuck. - if (projectile.velocity.Length() < 1.6f) - projectile.velocity = Vector2.UnitY * 5f; + if (projectile.velocity.Length() < 3f) + projectile.velocity = Vector2.UnitY * -12f; // If close to the target, slow down dramatically. if (projectile.velocity.Length() > 5f && projectile.WithinRange(target.Center, 90f)) - projectile.velocity *= 0.8f; + projectile.velocity *= 0.93f; // Otherwise, if not close, speed up dramatically. else if (projectile.velocity.Length() < 40f) @@ -120,7 +116,8 @@ namespace CalamityMod.Projectiles.Summon float angularTurnSpeed = 0.35f; float angleToTargetCoords = projectile.AngleTo(target.Center); - projectile.velocity = projectile.velocity.ToRotation().AngleTowards(angleToTargetCoords, angularTurnSpeed).ToRotationVector2() * projectile.velocity.Length(); + if (!projectile.WithinRange(target.Center, 200f)) + projectile.velocity = projectile.velocity.ToRotation().AngleTowards(angleToTargetCoords, angularTurnSpeed).ToRotationVector2() * projectile.velocity.Length(); // If not super close to the target but the target is very much in the line of sight of the summon, charge. if (!projectile.WithinRange(target.Center, 75f) && Vector2.Dot(projectile.SafeDirectionTo(target.Center), projectile.velocity.SafeNormalize(Vector2.Zero)) > 0.85f) diff --git a/Projectiles/Summon/DeathstareBeam.cs b/Projectiles/Summon/DeathstareBeam.cs new file mode 100644 index 0000000000..e9804eb637 --- /dev/null +++ b/Projectiles/Summon/DeathstareBeam.cs @@ -0,0 +1,54 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + public class DeathstareBeam : ModProjectile + { + public ref float OwnerUUID => ref projectile.ai[0]; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Beam"); + ProjectileID.Sets.MinionShot[projectile.type] = true; + } + + public override void SetDefaults() + { + projectile.width = 10; + projectile.height = 10; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.tileCollide = false; + projectile.minion = true; + projectile.ignoreWater = true; + projectile.timeLeft = 10; + } + public override void AI() + { + if (!Main.projectile.IndexInRange((int)OwnerUUID)) + { + projectile.Kill(); + return; + } + + projectile.Opacity = Utils.InverseLerp(1f, 0f, 1f - projectile.timeLeft / 10f, true); + projectile.Center = Main.projectile[(int)OwnerUUID].Center - projectile.velocity; + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2; + } + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D beamTexture = Main.projectileTexture[projectile.type]; + Vector2 drawPosition = projectile.Center + Vector2.UnitY * projectile.gfxOffY - Main.screenPosition; + Vector2 drawScale = new Vector2(0.55f, projectile.velocity.Length() / beamTexture.Height * 20f); + Color color = Color.White * 2.1f * projectile.Opacity; + + if (Math.Abs(projectile.rotation - MathHelper.PiOver2) > 0.008f) + spriteBatch.Draw(beamTexture, drawPosition, null, color, projectile.rotation, beamTexture.Frame().Bottom(), drawScale, SpriteEffects.None, 0f); + return false; + } + } +} diff --git a/Projectiles/Summon/DeathstareBeam.png b/Projectiles/Summon/DeathstareBeam.png new file mode 100644 index 0000000000..a47f130bae Binary files /dev/null and b/Projectiles/Summon/DeathstareBeam.png differ diff --git a/Projectiles/Summon/DeathstareEyePupil.png b/Projectiles/Summon/DeathstareEyePupil.png new file mode 100644 index 0000000000..ea9db1fb5d Binary files /dev/null and b/Projectiles/Summon/DeathstareEyePupil.png differ diff --git a/Projectiles/Summon/DeathstareEyeball.cs b/Projectiles/Summon/DeathstareEyeball.cs new file mode 100644 index 0000000000..3845740cb1 --- /dev/null +++ b/Projectiles/Summon/DeathstareEyeball.cs @@ -0,0 +1,181 @@ +using CalamityMod.Buffs.Summon; +using CalamityMod.CalPlayer; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +namespace CalamityMod.Projectiles.Summon +{ + public class DeathstareEyeball : ModProjectile + { + // This does not need to be synced. It is used solely for drawcode/visuals and is intended to be local. + public float PupilScale = 1f; + public const int BeamFireRate = 60; + public Player Owner => Main.player[projectile.owner]; + public ref float Time => ref projectile.ai[1]; + public ref float PupilAngle => ref projectile.localAI[0]; + public ref float PupilOutwardness => ref projectile.localAI[1]; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Eyeball"); + Main.projFrames[projectile.type] = 4; + ProjectileID.Sets.NeedsUUID[projectile.type] = true; + ProjectileID.Sets.MinionSacrificable[projectile.type] = true; + ProjectileID.Sets.MinionTargettingFeature[projectile.type] = true; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 16; + projectile.netImportant = true; + projectile.friendly = true; + projectile.ignoreWater = true; + projectile.minionSlots = 1f; + projectile.timeLeft = 90000; + projectile.penetrate = -1; + projectile.tileCollide = false; + projectile.minion = true; + } + + #region AI + public override void AI() + { + Lighting.AddLight(projectile.Center, Color.Blue.ToVector3()); + + bool isCorrectMinion = projectile.type == ModContent.ProjectileType(); + CalamityPlayer modPlayer = Owner.Calamity(); + Owner.AddBuff(ModContent.BuffType(), 3600); + + // Ensure that the projectile executing this code is a valid one. + if (isCorrectMinion) + { + if (Owner.dead) + modPlayer.deathstareEyeball = false; + if (modPlayer.deathstareEyeball) + projectile.timeLeft = 2; + } + + Vector2 destination = Owner.Center + Vector2.UnitY * (Owner.gfxOffY - 110f); + if (Owner.gravDir == -1f) + destination.Y += 220f; + + // Very quickly fly towards above (or below if gravity is reversed) the player. + projectile.Center = Vector2.Lerp(projectile.Center, destination, 0.36f); + + projectile.position = projectile.position.Floor(); + projectile.rotation = (projectile.position.X - projectile.oldPosition.X) * 0.07f + Owner.velocity.X * 0.2f; + projectile.rotation = Utils.Clamp(projectile.rotation, -0.4f, 0.4f); + + if (projectile.localAI[0] == 0f) + { + Initialize(Owner); + projectile.localAI[0] = 1f; + } + if (Owner.MinionDamage() != projectile.Calamity().spawnedPlayerMinionDamageValue) + { + int trueDamage = (int)((float)projectile.Calamity().spawnedPlayerMinionProjectileDamageValue / + projectile.Calamity().spawnedPlayerMinionDamageValue * + Owner.MinionDamage()); + projectile.damage = trueDamage; + } + + NPC potentialTarget = projectile.Center.MinionHoming(720f, Owner); + + if (potentialTarget is null) + DoHoveringAI(); + else + DoAttackingAI(potentialTarget); + + projectile.frame = (int)(Time / 5) % 4; + + Time++; + } + + public void DoHoveringAI() + { + // Roll the pupil around if there's little movement from the eye and player. + if (Time % 180f > 120f && Math.Abs(projectile.rotation) < 0.03f) + { + float idealAngle = Utils.InverseLerp(120f, 180f, Time % 180f, true) * MathHelper.TwoPi; + + PupilAngle = PupilAngle.AngleTowards(idealAngle, MathHelper.ToRadians(12f)); + PupilOutwardness = MathHelper.Lerp(PupilOutwardness, 4f, 0.2f); + } + else + { + float idealOutwardness = MathHelper.Clamp(Owner.velocity.Length() * 0.5f, 0f, 5f); + float idealAngle = Owner.velocity.ToRotation(); + + PupilOutwardness = MathHelper.Lerp(PupilOutwardness, idealOutwardness, 0.2f); + PupilAngle = PupilAngle.AngleTowards(idealAngle, MathHelper.ToRadians(12f)); + } + } + + public void DoAttackingAI(NPC target) + { + PupilOutwardness = MathHelper.Lerp(PupilOutwardness, 4f, 0.25f); + + if (Time % BeamFireRate == BeamFireRate - 20) + { + if (Main.myPlayer == projectile.owner) + { + Vector2 velocity = (target.Center - projectile.Center) / 15f; + int beam = Projectile.NewProjectile(target.Center, velocity, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner); + Main.projectile[beam].ai[0] = Projectile.GetByUUID(projectile.owner, projectile.whoAmI); + Main.projectile[beam].Damage(); + } + PupilScale = 1.5f; + } + + // After firing, have the pupil retract a bit. + if (Time % BeamFireRate > BeamFireRate - 20) + { + PupilScale = MathHelper.Lerp(PupilScale, 0.7f, 0.15f); + } + // Otherwise, have it behave like normal. + else + { + PupilScale = MathHelper.Lerp(PupilScale, 1f, 0.175f); + PupilAngle = PupilAngle.AngleTowards(projectile.AngleTo(target.Center), MathHelper.ToRadians(15f)); + } + } + + public void Initialize(Player player) + { + projectile.Calamity().spawnedPlayerMinionDamageValue = player.MinionDamage(); + projectile.Calamity().spawnedPlayerMinionProjectileDamageValue = projectile.damage; + + if (!Main.dedServ) + return; + + for (int i = 0; i < 25; i++) + { + Dust dust = Dust.NewDustDirect(projectile.position, 52, 52, DustID.Blood); + dust.noGravity = true; + dust.scale = Main.rand.NextFloat(1.2f, 1.5f); + } + } + + #endregion + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D eyeTexture = Main.projectileTexture[projectile.type]; + Rectangle frame = eyeTexture.Frame(1, 4, 0, projectile.frame); + Vector2 origin = frame.Size() * 0.5f; + SpriteEffects spriteEffects = Owner.gravDir == 1 ? SpriteEffects.None : SpriteEffects.FlipVertically; + spriteBatch.Draw(eyeTexture, projectile.Center - Main.screenPosition, frame, projectile.GetAlpha(lightColor), projectile.rotation, origin, projectile.scale, spriteEffects, 0f); + + // Pupil drawing. + Texture2D pupilTexture = ModContent.GetTexture("CalamityMod/Projectiles/Summon/DeathstareEyePupil"); + Vector2 pupilDrawPosition = projectile.Center - Main.screenPosition + PupilAngle.ToRotationVector2() * PupilOutwardness; + pupilDrawPosition -= Vector2.UnitY * 4f; + spriteBatch.Draw(pupilTexture, pupilDrawPosition, null, projectile.GetAlpha(lightColor), PupilAngle, pupilTexture.Size() * 0.5f, PupilScale, spriteEffects, 0f); + return false; + } + + public override bool CanDamage() => false; + } +} diff --git a/Projectiles/Summon/DeathstareEyeball.png b/Projectiles/Summon/DeathstareEyeball.png new file mode 100644 index 0000000000..6825c3c664 Binary files /dev/null and b/Projectiles/Summon/DeathstareEyeball.png differ diff --git a/Projectiles/Summon/EyeOfNightCell.cs b/Projectiles/Summon/EyeOfNightCell.cs new file mode 100644 index 0000000000..9c67226c3c --- /dev/null +++ b/Projectiles/Summon/EyeOfNightCell.cs @@ -0,0 +1,54 @@ +using CalamityMod.Dusts; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + public class EyeOfNightCell : ModProjectile + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Cell"); + ProjectileID.Sets.MinionShot[projectile.type] = true; + } + + public override void SetDefaults() + { + projectile.friendly = true; + projectile.width = projectile.height = 10; + projectile.minion = true; + projectile.minionSlots = 0f; + projectile.ignoreWater = true; + projectile.tileCollide = false; + projectile.penetrate = -1; + projectile.timeLeft = 180; + projectile.extraUpdates = 1; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 19; + } + + public override void AI() + { + if (!Main.dedServ && projectile.velocity.Length() > 5f) + Dust.NewDustPerfect(projectile.Center, (int)CalamityDusts.SulfurousSeaAcid).noGravity = true; + + projectile.StickyProjAI(360); + } + public override void Kill(int timeLeft) + { + CalamityGlobalProjectile.ExpandHitboxBy(projectile, 60); + projectile.Damage(); + + if (!Main.dedServ) + for (int i = 0; i < 10; i++) + Dust.NewDustDirect(projectile.position, 36, 36, (int)CalamityDusts.SulfurousSeaAcid).noGravity = true; + } + + public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection) => projectile.ModifyHitNPCSticky(10, false); + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) => target.AddBuff(BuffID.CursedInferno, 120); + + public override void OnHitPvp(Player target, int damage, bool crit) => target.AddBuff(BuffID.CursedInferno, 120); + } +} diff --git a/Projectiles/Summon/EyeOfNightCell.png b/Projectiles/Summon/EyeOfNightCell.png new file mode 100644 index 0000000000..99bc8669bf Binary files /dev/null and b/Projectiles/Summon/EyeOfNightCell.png differ diff --git a/Projectiles/Summon/EyeOfNightSummon.cs b/Projectiles/Summon/EyeOfNightSummon.cs new file mode 100644 index 0000000000..6af7ff3d56 --- /dev/null +++ b/Projectiles/Summon/EyeOfNightSummon.cs @@ -0,0 +1,136 @@ +using CalamityMod.Buffs.Summon; +using CalamityMod.Dusts; +using Microsoft.Xna.Framework; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + public class EyeOfNightSummon : ModProjectile + { + public Player Owner => Main.player[projectile.owner]; + public ref float HoverTime => ref projectile.ai[0]; + + public const int ShootRate = 60; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Eye of Night"); + ProjectileID.Sets.MinionSacrificable[projectile.type] = true; + ProjectileID.Sets.MinionTargettingFeature[projectile.type] = true; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 16; + projectile.netImportant = true; + projectile.friendly = true; + projectile.ignoreWater = true; + projectile.minionSlots = 1f; + projectile.timeLeft = 90000; + projectile.penetrate = -1; + projectile.tileCollide = false; + projectile.minion = true; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 19; + } + + public override void AI() + { + ProvidePlayerMinionBuffs(); + DynamicallyUpdateDamage(); + GenerateVisuals(); + NPC potentialTarget = projectile.Center.MinionHoming(750f, Owner); + if (potentialTarget is null) + FlyNearOwner(); + else + AttackTarget(potentialTarget); + } + + internal void ProvidePlayerMinionBuffs() + { + Owner.AddBuff(ModContent.BuffType(), 3600); + + // Verify player/minion state integrity. The minion cannot stay alive if the + // owner is dead or if the caller of the AI is invalid. + if (projectile.type != ModContent.ProjectileType()) + return; + + if (Owner.dead) + Owner.Calamity().eyeOfNight = false; + if (Owner.Calamity().eyeOfNight) + projectile.timeLeft = 2; + } + + internal void DynamicallyUpdateDamage() + { + if (projectile.localAI[0] == 0f) + { + projectile.Calamity().spawnedPlayerMinionDamageValue = Owner.MinionDamage(); + projectile.Calamity().spawnedPlayerMinionProjectileDamageValue = projectile.damage; + projectile.localAI[0] = 1f; + } + if (Owner.MinionDamage() == projectile.Calamity().spawnedPlayerMinionDamageValue) + return; + int trueDamage = (int)(projectile.Calamity().spawnedPlayerMinionProjectileDamageValue / projectile.Calamity().spawnedPlayerMinionDamageValue * Owner.MinionDamage()); + projectile.damage = trueDamage; + } + + internal void GenerateVisuals() + { + // The code within this method is visual. There is no need to waste resources executing it on the server. + if (Main.dedServ) + return; + + projectile.rotation += projectile.velocity.X * 0.075f; + } + + internal void FlyNearOwner() + { + Vector2 destination = Owner.Top - Vector2.UnitY * 45f + (projectile.identity * 0.9f).ToRotationVector2() * 16f; + Vector2 idealVelocity = projectile.SafeDirectionTo(destination) * MathHelper.Lerp(2.3f, 8f, Utils.InverseLerp(16f, 160f, projectile.Distance(destination))); + if (projectile.velocity.Length() < 0.4f) + projectile.velocity = Vector2.UnitY.RotatedBy(Main.rand.NextFloat(0.5f, 1.1f) * Main.rand.NextBool(2).ToDirectionInt()) * -3.6f; + else if (!projectile.WithinRange(destination, 20f)) + projectile.velocity = projectile.velocity * 0.9f + idealVelocity * 0.1f; + + if (!projectile.WithinRange(Owner.Center, 1800f)) + { + projectile.Center = Owner.Center; + projectile.velocity = -Vector2.UnitY * 4f; + projectile.netUpdate = true; + } + + // Slow down a bit over time. + projectile.velocity *= 0.985f; + } + + internal void AttackTarget(NPC target) + { + if (Main.myPlayer == projectile.owner && HoverTime % 30 == 29) + { + Projectile.NewProjectile(projectile.Center, projectile.SafeDirectionTo(target.Center) * 8f, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner); + HoverTime++; + } + + Vector2 destination = target.Center; + Vector2 destinationOffset = Vector2.Max(target.Size * 1.2f, Vector2.One * 90f).RotatedBy(projectile.identity * 0.96f + HoverTime / 15f); + + // Make the offset pulsate over time. + destinationOffset *= MathHelper.Lerp(0.7f, 1.3f, (float)Math.Cos(projectile.identity * 1.11f + HoverTime / 14f) * 0.5f + 0.5f); + + destinationOffset.Y += (float)Math.Sin(projectile.identity * 1.16f + HoverTime / 15f + MathHelper.PiOver2) * MathHelper.Min(target.height * 0.8f, 70f); + + destination += destinationOffset; + + // Fly towards the destination faster the farther the eye already is to it. + float flySpeed = MathHelper.Lerp(5f, 15f, Utils.InverseLerp(40f, 250f, projectile.Distance(destination), true)); + + if (projectile.WithinRange(destination, 24f + target.velocity.Length() * 2f)) + HoverTime++; + + projectile.velocity = (destination - projectile.Center).SafeNormalize(Vector2.Zero) * flySpeed; + } + } +} \ No newline at end of file diff --git a/Projectiles/Summon/EyeOfNightSummon.png b/Projectiles/Summon/EyeOfNightSummon.png new file mode 100644 index 0000000000..7caaf49286 Binary files /dev/null and b/Projectiles/Summon/EyeOfNightSummon.png differ diff --git a/Projectiles/Summon/FleshBallMinion.cs b/Projectiles/Summon/FleshBallMinion.cs new file mode 100644 index 0000000000..57dab5bbee --- /dev/null +++ b/Projectiles/Summon/FleshBallMinion.cs @@ -0,0 +1,164 @@ +using CalamityMod.Buffs.Summon; +using CalamityMod.Projectiles.Melee; +using Microsoft.Xna.Framework; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + public class FleshBallMinion : ModProjectile + { + public Player Owner => Main.player[projectile.owner]; + public bool SittingOnGround => Math.Abs(projectile.velocity.X) < 1.55f && projectile.velocity.Y == 0f; + public ref float HopTimer => ref projectile.ai[0]; + public const float Gravity = 0.25f; + public const float MaxFallSpeed = 12f; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Flesh Ball"); + Main.projFrames[projectile.type] = 4; + ProjectileID.Sets.MinionSacrificable[projectile.type] = true; + ProjectileID.Sets.MinionTargettingFeature[projectile.type] = true; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 32; + projectile.netImportant = true; + projectile.friendly = true; + projectile.ignoreWater = true; + projectile.minionSlots = 1f; + projectile.timeLeft = 90000; + projectile.penetrate = -1; + projectile.tileCollide = false; + projectile.minion = true; + } + + public override void AI() + { + ProvidePlayerMinionBuffs(); + DetermineFrames(); + GenerateVisuals(); + + HopTimer++; + SufferFromSeparationAnxiety(); + NPC potentialTarget = projectile.Center.MinionHoming(950f, Owner); + if (potentialTarget is null) + GoNearOwner(); + else + AttackTarget(potentialTarget); + EnforceGravity(); + } + + internal void ProvidePlayerMinionBuffs() + { + Owner.AddBuff(ModContent.BuffType(), 3600); + + // Verify player/minion state integrity. The minion cannot stay alive if the + // owner is dead or if the caller of the AI is invalid. + if (projectile.type != ModContent.ProjectileType()) + return; + + if (Owner.dead) + Owner.Calamity().fleshBall = false; + if (Owner.Calamity().fleshBall) + projectile.timeLeft = 2; + } + + internal void DetermineFrames() + { + projectile.frameCounter++; + if (projectile.frameCounter % 5 == 4) + projectile.frame = (projectile.frame + 1) % Main.projFrames[projectile.type]; + } + + internal void EnforceGravity() + { + if (projectile.velocity.Y < MaxFallSpeed) + projectile.velocity.Y += Gravity; + } + + internal void GenerateVisuals() + { + // All code within this method is visual. There is no need to waste resources executing it on the server. + if (Main.dedServ) + return; + + projectile.rotation += projectile.velocity.X * 0.05f; + + Vector2 shootOffsetDirection = -Vector2.UnitY.RotatedBy(projectile.rotation + projectile.direction * 0.2f); + Dust blood = Dust.NewDustDirect(projectile.Center + shootOffsetDirection * 10f - new Vector2(4f), 0, 0, DustID.Blood, newColor: Color.Transparent); + blood.velocity = shootOffsetDirection.RotatedByRandom(MathHelper.PiOver4) * Main.rand.NextFloat(3f, 4f); + blood.noGravity = true; + } + + internal void SufferFromSeparationAnxiety() + { + float teleportPromptDistance = Collision.CanHitLine(projectile.Center, 1, 1, Owner.Center, 1, 1) ? 1900f : 805f; + if (Main.myPlayer == projectile.owner && !projectile.WithinRange(Owner.Center, teleportPromptDistance)) + { + projectile.Center = Owner.Center; + projectile.netUpdate = true; + } + } + + internal void GoNearOwner() + { + projectile.tileCollide = true; + + bool closeToPlayer = projectile.WithinRange(Owner.Center, 150f); + if (!closeToPlayer && SittingOnGround && HopTimer % 30f == 29f) + { + projectile.velocity = projectile.SafeDirectionTo(Owner.Center) * 9f + new Vector2(Math.Sign(projectile.velocity.X) * 2f, -9f); + + // Don't collide with tiles for 1 frame, to prevent slopes from being a nuisance. + projectile.tileCollide = false; + projectile.netUpdate = true; + } + } + + internal void AttackTarget(NPC target) + { + projectile.tileCollide = true; + + if (SittingOnGround && HopTimer % 20f == 19f) + { + projectile.velocity = projectile.SafeDirectionTo(target.Center) * 6f + new Vector2(Math.Sign(projectile.velocity.X) * 2f, -7f); + + // Release a bunch of blood. + if (Main.myPlayer == projectile.owner) + { + for (int i = 0; i < Main.rand.Next(1, 4 + 1); i++) + { + Vector2 shootVelocity = -Vector2.UnitY.RotatedByRandom(0.3f) * Main.rand.NextFloat(6f, 11f); + int blood = Projectile.NewProjectile(projectile.Top, shootVelocity, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner); + if (Main.projectile.IndexInRange(blood)) + { + Main.projectile[blood].Calamity().forceMinion = true; + Main.projectile[blood].penetrate = 1; + } + } + } + + // Don't collide with tiles for 1 frame, to prevent slopes from being a nuisance. + projectile.tileCollide = false; + projectile.netUpdate = true; + } + } + + // Prevent immediate death on tile collision, and slow down on tile collision. + public override bool OnTileCollide(Vector2 oldVelocity) + { + projectile.velocity.X *= 0.9f; + return false; + } + + public override bool TileCollideStyle(ref int width, ref int height, ref bool fallThrough) + { + fallThrough = projectile.Bottom.Y < Owner.Top.Y; + return true; + } + } +} diff --git a/Projectiles/Summon/FleshBallMinion.png b/Projectiles/Summon/FleshBallMinion.png new file mode 100644 index 0000000000..955f105050 Binary files /dev/null and b/Projectiles/Summon/FleshBallMinion.png differ diff --git a/Projectiles/Summon/FlowersOfMortalityCore.png b/Projectiles/Summon/FlowersOfMortalityCore.png new file mode 100644 index 0000000000..8e10fb5b09 Binary files /dev/null and b/Projectiles/Summon/FlowersOfMortalityCore.png differ diff --git a/Projectiles/Summon/FlowersOfMortalityPetal.cs b/Projectiles/Summon/FlowersOfMortalityPetal.cs new file mode 100644 index 0000000000..b743c1018e --- /dev/null +++ b/Projectiles/Summon/FlowersOfMortalityPetal.cs @@ -0,0 +1,106 @@ +using CalamityMod.Buffs.Summon; +using CalamityMod.CalPlayer; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +namespace CalamityMod.Projectiles.Summon +{ + public class FlowersOfMortalityPetal : ModProjectile + { + public Player Owner => Main.player[projectile.owner]; + public ref float OffsetAngle => ref projectile.ai[0]; + public ref float Time => ref projectile.ai[1]; + public float Hue => OffsetAngle % MathHelper.TwoPi / MathHelper.TwoPi % 1f; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Elemental Petal"); + ProjectileID.Sets.TrailingMode[projectile.type] = 2; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 8; + ProjectileID.Sets.MinionSacrificable[projectile.type] = true; + ProjectileID.Sets.MinionTargettingFeature[projectile.type] = true; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 30; + projectile.netImportant = true; + projectile.friendly = true; + projectile.ignoreWater = true; + projectile.minionSlots = 0.5f; + projectile.timeLeft = 90000; + projectile.penetrate = -1; + projectile.tileCollide = false; + projectile.minion = true; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 4; + } + + public override void AI() + { + bool isCorrectMinion = projectile.type == ModContent.ProjectileType(); + Player player = Main.player[projectile.owner]; + CalamityPlayer modPlayer = player.Calamity(); + player.AddBuff(ModContent.BuffType(), 3600); + if (isCorrectMinion) + { + if (player.dead) + modPlayer.flowersOfMortality = false; + if (modPlayer.flowersOfMortality) + projectile.timeLeft = 2; + } + + SetProjectileDamage(); + + Time++; + NPC potentialTarget = projectile.Center.MinionHoming(1050f, Owner, false); + if (Time % 25 == 24 && Main.myPlayer == projectile.owner && potentialTarget != null) + { + Vector2 shootVelocity = projectile.SafeDirectionTo(potentialTarget.Center) * 10f; + Projectile.NewProjectile(projectile.Center, shootVelocity, ModContent.ProjectileType(), projectile.damage / 3, projectile.knockBack, projectile.owner); + } + projectile.Center = player.Center + OffsetAngle.ToRotationVector2() * (150f + (float)Math.Sin(Time * 0.08f) * 15f); + projectile.rotation += MathHelper.ToRadians(7f); + OffsetAngle += MathHelper.ToRadians(6f); + } + + public void SetProjectileDamage() + { + if (projectile.localAI[0] == 0f) + { + projectile.Calamity().spawnedPlayerMinionDamageValue = Owner.MinionDamage(); + projectile.Calamity().spawnedPlayerMinionProjectileDamageValue = projectile.damage; + for (int i = 0; i < 36; i++) + { + Dust dust = Dust.NewDustPerfect(projectile.Center, 261); + dust.noGravity = true; + dust.color = Main.hslToRgb(Main.rand.NextFloat(), 1f, 0.5f); + dust.velocity = Main.rand.NextVector2Unit() * Main.rand.NextFloat(2f, 7f); + } + projectile.localAI[0] += 1f; + } + if (Owner.MinionDamage() != projectile.Calamity().spawnedPlayerMinionDamageValue) + { + int trueDamage = (int)(projectile.Calamity().spawnedPlayerMinionProjectileDamageValue / + projectile.Calamity().spawnedPlayerMinionDamageValue * + Owner.MinionDamage()); + projectile.damage = trueDamage; + } + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D petalTexture = Main.projectileTexture[projectile.type]; + Texture2D coreTexture = ModContent.GetTexture("CalamityMod/Projectiles/Summon/FlowersOfMortalityCore"); + Color drawColor = Main.hslToRgb(Hue, 0.95f, 0.5f) * 2.3f; + + Vector2 drawPosition = projectile.Center - Main.screenPosition; + spriteBatch.Draw(petalTexture, drawPosition, null, projectile.GetAlpha(drawColor), projectile.rotation, petalTexture.Size() * 0.5f, projectile.scale, SpriteEffects.None, 0f); + spriteBatch.Draw(coreTexture, drawPosition, null, projectile.GetAlpha(lightColor), 0f, coreTexture.Size() * 0.5f, projectile.scale, SpriteEffects.None, 0f); + + return false; + } + } +} diff --git a/Projectiles/Summon/FlowersOfMortalityPetal.png b/Projectiles/Summon/FlowersOfMortalityPetal.png new file mode 100644 index 0000000000..a32bdc4d1e Binary files /dev/null and b/Projectiles/Summon/FlowersOfMortalityPetal.png differ diff --git a/Projectiles/Summon/LostSoulGiant.cs b/Projectiles/Summon/LostSoulGiant.cs new file mode 100644 index 0000000000..b7caaff612 --- /dev/null +++ b/Projectiles/Summon/LostSoulGiant.cs @@ -0,0 +1,110 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + public class LostSoulGiant : ModProjectile + { + public ref float Time => ref projectile.ai[0]; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Soul"); + Main.projFrames[projectile.type] = 4; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 10; + ProjectileID.Sets.TrailingMode[projectile.type] = 2; + } + + public override void SetDefaults() + { + projectile.scale = 0.8f; + projectile.width = projectile.height = 52; + projectile.friendly = true; + projectile.penetrate = 1; + projectile.tileCollide = false; + projectile.magic = true; + projectile.ignoreWater = true; + } + + public override void AI() => DoSoulAI(projectile, ref Time); + + public static void DoSoulAI(Projectile projectile, ref float time) + { + if (time >= 15f) + { + NPC potentialTarget = projectile.Center.ClosestNPCAt(1800f, false); + if (potentialTarget != null) + HomeInOnTarget(projectile, potentialTarget); + } + + projectile.Opacity = Utils.InverseLerp(0f, 15f, time, true); + projectile.frameCounter++; + if (projectile.frameCounter % 5f == 4f) + projectile.frame = (projectile.frame + 1) % Main.projFrames[projectile.type]; + + projectile.rotation = projectile.velocity.ToRotation(); + projectile.spriteDirection = (projectile.velocity.X > 0f).ToDirectionInt(); + if (projectile.spriteDirection == -1) + projectile.rotation += MathHelper.Pi; + + time++; + } + + public static void HomeInOnTarget(Projectile projectile, NPC target) + { + float speed = MathHelper.Lerp(11f, 21f, (float)Math.Sin(projectile.identity % 7f / 7f * MathHelper.TwoPi) * 0.5f + 0.5f); + projectile.velocity = Vector2.Lerp(projectile.velocity, projectile.SafeDirectionTo(target.Center) * speed, 0.075f); + } + + public override Color? GetAlpha(Color lightColor) + { + Color baseColor = Color.Lerp(Color.IndianRed, Color.DarkViolet, projectile.identity % 5f / 5f * 0.5f); + Color color = Color.Lerp(baseColor * 1.5f, baseColor, (float)Math.Cos(Main.GlobalTime * 2.7f) * 0.04f + 0.45f); + color.A = 0; + return color * projectile.Opacity; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + SpriteEffects direction = projectile.spriteDirection == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally; + Texture2D texture = Main.projectileTexture[projectile.type]; + Rectangle frame = texture.Frame(1, Main.projFrames[projectile.type], 0, projectile.frame); + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < projectile.oldPos.Length / 2; j++) + { + float fade = (float)Math.Pow(1f - Utils.InverseLerp(0f, projectile.oldPos.Length / 2, j, true), 2D); + Color drawColor = Color.Lerp(projectile.GetAlpha(lightColor), Color.White * projectile.Opacity, j / projectile.oldPos.Length) * fade; + Vector2 drawPosition = projectile.oldPos[j] + projectile.Size * 0.5f + (MathHelper.TwoPi * i / 4f).ToRotationVector2() * 1.5f - Main.screenPosition; + float rotation = projectile.oldRot[j]; + + spriteBatch.Draw(texture, drawPosition, frame, drawColor, rotation, frame.Size() * 0.5f, projectile.scale, direction, 0f); + } + } + + return false; + } + + public override void Kill(int timeLeft) + { + // Play a wraith death sound. + Main.PlaySound(SoundID.NPCDeath52, projectile.Center); + + if (Main.dedServ) + return; + + for (int i = 0; i < 45; i++) + { + Dust ectoplasm = Dust.NewDustPerfect(projectile.Center + Main.rand.NextVector2Circular(60f, 60f), 264); + ectoplasm.velocity = Main.rand.NextVector2Circular(2f, 2f); + ectoplasm.color = projectile.GetAlpha(Color.White); + ectoplasm.scale = 1.45f; + ectoplasm.noGravity = true; + ectoplasm.noLight = true; + } + } + } +} diff --git a/Projectiles/Summon/LostSoulGiant.png b/Projectiles/Summon/LostSoulGiant.png new file mode 100644 index 0000000000..3e0e4507b7 Binary files /dev/null and b/Projectiles/Summon/LostSoulGiant.png differ diff --git a/Projectiles/Summon/LostSoulGold.cs b/Projectiles/Summon/LostSoulGold.cs new file mode 100644 index 0000000000..bd21a7662f --- /dev/null +++ b/Projectiles/Summon/LostSoulGold.cs @@ -0,0 +1,81 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + public class LostSoulGold : ModProjectile + { + public ref float Time => ref projectile.ai[0]; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Gold Soul"); + Main.projFrames[projectile.type] = 4; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 10; + ProjectileID.Sets.TrailingMode[projectile.type] = 2; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 38; + projectile.friendly = true; + projectile.penetrate = 1; + projectile.tileCollide = false; + projectile.magic = true; + projectile.ignoreWater = true; + } + + public override void AI() => LostSoulGiant.DoSoulAI(projectile, ref Time); + + public override Color? GetAlpha(Color lightColor) + { + Color baseColor = Color.Lerp(Color.DarkGoldenrod, Color.Gold, projectile.identity % 5f / 5f); + Color color = Color.Lerp(baseColor, Color.White, (float)Math.Cos(Main.GlobalTime * 2.7f) * 0.04f + 0.5f); + color.A = 127; + return color * projectile.Opacity; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + SpriteEffects direction = projectile.spriteDirection == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally; + Texture2D texture = Main.projectileTexture[projectile.type]; + Rectangle frame = texture.Frame(1, Main.projFrames[projectile.type], 0, projectile.frame); + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < projectile.oldPos.Length / 2; j++) + { + float fade = (float)Math.Pow(1f - Utils.InverseLerp(0f, projectile.oldPos.Length / 2, j, true), 2D); + Color drawColor = Color.Lerp(projectile.GetAlpha(lightColor), Color.White * projectile.Opacity, j / projectile.oldPos.Length) * fade; + Vector2 drawPosition = projectile.oldPos[j] + projectile.Size * 0.5f + (MathHelper.TwoPi * i / 4f).ToRotationVector2() * 0.8f - Main.screenPosition; + float rotation = projectile.oldRot[j]; + + spriteBatch.Draw(texture, drawPosition, frame, drawColor, rotation, frame.Size() * 0.5f, projectile.scale, direction, 0f); + } + } + + return false; + } + + public override void Kill(int timeLeft) + { + // Play a wraith death sound. + Main.PlaySound(SoundID.NPCDeath52, projectile.Center); + + if (Main.dedServ) + return; + + for (int i = 0; i < 45; i++) + { + Dust ectoplasm = Dust.NewDustPerfect(projectile.Center + Main.rand.NextVector2Circular(42f, 42f), 264); + ectoplasm.velocity = Main.rand.NextVector2Circular(1.75f, 1.75f); + ectoplasm.color = projectile.GetAlpha(Color.White); + ectoplasm.scale = 1.45f; + ectoplasm.noGravity = true; + ectoplasm.noLight = true; + } + } + } +} diff --git a/Projectiles/Summon/LostSoulGold.png b/Projectiles/Summon/LostSoulGold.png new file mode 100644 index 0000000000..ecffa8c8a3 Binary files /dev/null and b/Projectiles/Summon/LostSoulGold.png differ diff --git a/Projectiles/Summon/LostSoulLarge.cs b/Projectiles/Summon/LostSoulLarge.cs new file mode 100644 index 0000000000..204733a066 --- /dev/null +++ b/Projectiles/Summon/LostSoulLarge.cs @@ -0,0 +1,82 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + public class LostSoulLarge : ModProjectile + { + public ref float Time => ref projectile.ai[0]; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Soul"); + Main.projFrames[projectile.type] = 4; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 10; + ProjectileID.Sets.TrailingMode[projectile.type] = 2; + } + + public override void SetDefaults() + { + projectile.scale = 0.75f; + projectile.width = projectile.height = 46; + projectile.friendly = true; + projectile.penetrate = 1; + projectile.tileCollide = false; + projectile.magic = true; + projectile.ignoreWater = true; + } + + public override void AI() => LostSoulGiant.DoSoulAI(projectile, ref Time); + + public override Color? GetAlpha(Color lightColor) + { + Color baseColor = Color.Lerp(Color.Orange, Color.IndianRed, projectile.identity % 5f / 5f * 0.5f); + Color color = Color.Lerp(baseColor * 1.5f, baseColor, (float)Math.Cos(Main.GlobalTime * 2.7f) * 0.04f + 0.45f); + color.A = 0; + return color * projectile.Opacity; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + SpriteEffects direction = projectile.spriteDirection == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally; + Texture2D texture = Main.projectileTexture[projectile.type]; + Rectangle frame = texture.Frame(1, Main.projFrames[projectile.type], 0, projectile.frame); + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < projectile.oldPos.Length / 2; j++) + { + float fade = (float)Math.Pow(1f - Utils.InverseLerp(0f, projectile.oldPos.Length / 2, j, true), 2D); + Color drawColor = Color.Lerp(projectile.GetAlpha(lightColor), Color.White * projectile.Opacity, j / projectile.oldPos.Length) * fade; + Vector2 drawPosition = projectile.oldPos[j] + projectile.Size * 0.5f + (MathHelper.TwoPi * i / 4f).ToRotationVector2() * 1.25f - Main.screenPosition; + float rotation = projectile.oldRot[j]; + + spriteBatch.Draw(texture, drawPosition, frame, drawColor, rotation, frame.Size() * 0.5f, projectile.scale, direction, 0f); + } + } + + return false; + } + + public override void Kill(int timeLeft) + { + // Play a wraith death sound. + Main.PlaySound(SoundID.NPCDeath52, projectile.Center); + + if (Main.dedServ) + return; + + for (int i = 0; i < 45; i++) + { + Dust ectoplasm = Dust.NewDustPerfect(projectile.Center + Main.rand.NextVector2Circular(42f, 42f), 264); + ectoplasm.velocity = Main.rand.NextVector2Circular(1.75f, 1.75f); + ectoplasm.color = projectile.GetAlpha(Color.White); + ectoplasm.scale = 1.45f; + ectoplasm.noGravity = true; + ectoplasm.noLight = true; + } + } + } +} diff --git a/Projectiles/Summon/LostSoulLarge.png b/Projectiles/Summon/LostSoulLarge.png new file mode 100644 index 0000000000..06675010ab Binary files /dev/null and b/Projectiles/Summon/LostSoulLarge.png differ diff --git a/Projectiles/Summon/LostSoulSmall.cs b/Projectiles/Summon/LostSoulSmall.cs new file mode 100644 index 0000000000..0bc2e93403 --- /dev/null +++ b/Projectiles/Summon/LostSoulSmall.cs @@ -0,0 +1,81 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + public class LostSoulSmall : ModProjectile + { + public ref float Time => ref projectile.ai[0]; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Soul"); + Main.projFrames[projectile.type] = 4; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 10; + ProjectileID.Sets.TrailingMode[projectile.type] = 2; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 38; + projectile.friendly = true; + projectile.penetrate = 1; + projectile.tileCollide = false; + projectile.magic = true; + projectile.ignoreWater = true; + } + + public override void AI() => LostSoulGiant.DoSoulAI(projectile, ref Time); + + public override Color? GetAlpha(Color lightColor) + { + Color baseColor = Color.Lerp(Color.Orange, Color.IndianRed, projectile.identity % 5f / 5f * 0.425f); + Color color = Color.Lerp(baseColor * 1.5f, baseColor, (float)Math.Cos(Main.GlobalTime * 2.7f) * 0.04f + 0.45f); + color.A = 0; + return color * projectile.Opacity; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + SpriteEffects direction = projectile.spriteDirection == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally; + Texture2D texture = Main.projectileTexture[projectile.type]; + Rectangle frame = texture.Frame(1, Main.projFrames[projectile.type], 0, projectile.frame); + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < projectile.oldPos.Length / 2; j++) + { + float fade = (float)Math.Pow(1f - Utils.InverseLerp(0f, projectile.oldPos.Length / 2, j, true), 2D); + Color drawColor = Color.Lerp(projectile.GetAlpha(lightColor), Color.White * projectile.Opacity, j / projectile.oldPos.Length) * fade; + Vector2 drawPosition = projectile.oldPos[j] + projectile.Size * 0.5f + (MathHelper.TwoPi * i / 4f).ToRotationVector2() * 0.8f - Main.screenPosition; + float rotation = projectile.oldRot[j]; + + spriteBatch.Draw(texture, drawPosition, frame, drawColor, rotation, frame.Size() * 0.5f, projectile.scale, direction, 0f); + } + } + + return false; + } + + public override void Kill(int timeLeft) + { + // Play a wraith death sound. + Main.PlaySound(SoundID.NPCDeath52, projectile.Center); + + if (Main.dedServ) + return; + + for (int i = 0; i < 45; i++) + { + Dust ectoplasm = Dust.NewDustPerfect(projectile.Center + Main.rand.NextVector2Circular(42f, 42f), 264); + ectoplasm.velocity = Main.rand.NextVector2Circular(1.75f, 1.75f); + ectoplasm.color = projectile.GetAlpha(Color.White); + ectoplasm.scale = 1.45f; + ectoplasm.noGravity = true; + ectoplasm.noLight = true; + } + } + } +} diff --git a/Projectiles/Summon/LostSoulSmall.png b/Projectiles/Summon/LostSoulSmall.png new file mode 100644 index 0000000000..f02bca1221 Binary files /dev/null and b/Projectiles/Summon/LostSoulSmall.png differ diff --git a/Projectiles/Summon/MortalityBeam.cs b/Projectiles/Summon/MortalityBeam.cs new file mode 100644 index 0000000000..622f0b5b14 --- /dev/null +++ b/Projectiles/Summon/MortalityBeam.cs @@ -0,0 +1,79 @@ +using CalamityMod.Buffs.DamageOverTime; +using CalamityMod.Buffs.StatDebuffs; +using Microsoft.Xna.Framework; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + public class MortalityBeam : ModProjectile + { + public ref float Time => ref projectile.ai[0]; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Beam"); + ProjectileID.Sets.TrailCacheLength[projectile.type] = 10; + ProjectileID.Sets.TrailingMode[projectile.type] = 0; + ProjectileID.Sets.MinionShot[projectile.type] = true; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 20; + projectile.friendly = true; + projectile.ignoreWater = true; + projectile.tileCollide = true; + projectile.minionSlots = 0f; + projectile.minion = true; + projectile.penetrate = 1; + projectile.timeLeft = 180; + } + + public override void AI() + { + Lighting.AddLight(projectile.Center, Color.White.ToVector3()); + if (!Main.dedServ) + { + for (int i = -1; i <= 1; i += 2) + { + float offset = (float)Math.Sin(Time / 45f * MathHelper.TwoPi) * 10f * i; + Vector2 rotatedOffset = new Vector2(offset, 2f).RotatedBy(projectile.velocity.ToRotation() + MathHelper.PiOver2); + + Dust rainbowDust = Dust.NewDustPerfect(projectile.Center + rotatedOffset, 261); + rainbowDust.color = Main.hslToRgb(Main.rand.NextFloat(), 0.9f, 0.5f); + rainbowDust.velocity = Vector2.Zero; + rainbowDust.scale = 1.5f; + rainbowDust.noGravity = true; + } + } + + Time++; + NPC potentialTarget = projectile.Center.MinionHoming(1000f, Main.player[projectile.owner], false); + if (potentialTarget != null) + projectile.velocity = (projectile.velocity * 5f + projectile.SafeDirectionTo(potentialTarget.Center) * 13f) / 6f; + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + target.AddBuff(ModContent.BuffType(), 180); + target.AddBuff(ModContent.BuffType(), 180); + target.AddBuff(ModContent.BuffType(), 180); + target.AddBuff(ModContent.BuffType(), 180); + } + + public override void Kill(int timeLeft) + { + if (Main.myPlayer == projectile.owner) + { + float redHue = Main.rgbToHsl(Color.Red).X; + float greenHue = Main.rgbToHsl(Color.SeaGreen).X; + float blueHue = Main.rgbToHsl(Color.Blue).X; + Vector2 spawnPosition = projectile.Center + Main.rand.NextVector2CircularEdge(10f, 10f); + Projectile bolt = Projectile.NewProjectileDirect(spawnPosition, Main.rand.NextVector2CircularEdge(9f, 9f), ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner); + bolt.localAI[0] = Utils.SelectRandom(Main.rand, redHue, greenHue, blueHue); + } + } + } +} diff --git a/Projectiles/Summon/MortalityBeam.png b/Projectiles/Summon/MortalityBeam.png new file mode 100644 index 0000000000..3c8f498e7b Binary files /dev/null and b/Projectiles/Summon/MortalityBeam.png differ diff --git a/Projectiles/Summon/MortalityBolt.cs b/Projectiles/Summon/MortalityBolt.cs new file mode 100644 index 0000000000..d0083cbc4e --- /dev/null +++ b/Projectiles/Summon/MortalityBolt.cs @@ -0,0 +1,66 @@ +using CalamityMod.Buffs.DamageOverTime; +using CalamityMod.Buffs.StatDebuffs; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +namespace CalamityMod.Projectiles.Summon +{ + public class MortalityBolt : ModProjectile + { + public Color ProjectileColor => Main.hslToRgb(projectile.localAI[0], 1f, 0.5f); + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Bolt"); + ProjectileID.Sets.MinionShot[projectile.type] = true; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 20; + projectile.friendly = true; + projectile.ignoreWater = true; + projectile.tileCollide = false; + projectile.minionSlots = 0f; + projectile.minion = true; + projectile.penetrate = 1; + projectile.timeLeft = 180; + } + + public override void AI() + { + Lighting.AddLight(projectile.Center, Color.White.ToVector3()); + if (!Main.dedServ) + { + for (int i = 0; i < 4; i++) + { + Dust rainbowDust = Dust.NewDustPerfect(projectile.Center + Main.rand.NextVector2Circular(5f, 5f), 261); + rainbowDust.color = ProjectileColor; + rainbowDust.velocity += projectile.velocity; + rainbowDust.noGravity = true; + } + } + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + target.AddBuff(ModContent.BuffType(), 180); + target.AddBuff(ModContent.BuffType(), 180); + target.AddBuff(ModContent.BuffType(), 180); + target.AddBuff(ModContent.BuffType(), 180); + } + + public override void Kill(int timeLeft) + { + if (!Main.dedServ) + { + for (int i = 0; i < 15; i++) + { + Dust rainbowDust = Dust.NewDustDirect(projectile.Center + Main.rand.NextVector2Circular(5f, 5f), 40, 40, 261); + rainbowDust.color = ProjectileColor; + rainbowDust.noGravity = true; + } + } + } + } +} diff --git a/Projectiles/Summon/MortalityBolt.png b/Projectiles/Summon/MortalityBolt.png new file mode 100644 index 0000000000..3c8f498e7b Binary files /dev/null and b/Projectiles/Summon/MortalityBolt.png differ diff --git a/Projectiles/Summon/PerditionBeacon.cs b/Projectiles/Summon/PerditionBeacon.cs new file mode 100644 index 0000000000..fdd5ec89b8 --- /dev/null +++ b/Projectiles/Summon/PerditionBeacon.cs @@ -0,0 +1,173 @@ +using CalamityMod.Buffs.Summon; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.Utilities; + +namespace CalamityMod.Projectiles.Summon +{ + public class PerditionBeacon : ModProjectile + { + public ref float AttackTime => ref projectile.ai[0]; + public ref float AttackTimer => ref projectile.ai[1]; + public ref float DownwardCrossFade => ref projectile.localAI[1]; + public Player Owner => Main.player[projectile.owner]; + + // Only attack targets if one is explicitly defined. Don't default to a closest target. + public NPC Target => Owner.HasMinionAttackTargetNPC ? Main.npc[Owner.MinionAttackTargetNPC] : null; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Perdition Beacon"); + Main.projFrames[projectile.type] = 16; + ProjectileID.Sets.MinionTargettingFeature[projectile.type] = true; + } + + public override void SetDefaults() + { + projectile.width = 48; + projectile.height = 90; + projectile.ignoreWater = true; + projectile.tileCollide = false; + projectile.sentry = true; + projectile.light = 1f; + projectile.timeLeft = Projectile.SentryLifeTime; + projectile.penetrate = -1; + projectile.alpha = 255; + } + + public override void AI() + { + Player player = Main.player[projectile.owner]; + + if (projectile.localAI[0] == 0f) + { + DoInitializationEffects(); + projectile.localAI[0] = 1f; + } + + // Dynamically adjust damage of the minion. + if (player.MinionDamage() != projectile.Calamity().spawnedPlayerMinionDamageValue) + { + int newDamage = (int)(projectile.Calamity().spawnedPlayerMinionProjectileDamageValue / projectile.Calamity().spawnedPlayerMinionDamageValue * player.MinionDamage()); + projectile.damage = newDamage; + } + + // Fade in. + projectile.alpha = Utils.Clamp(projectile.alpha - 8, 0, 255); + + HandleFrames(); + FollowOwner(); + ProvidePlayerMinionBuffs(); + if (Target != null && projectile.WithinRange(Target.Center, 2200f)) + { + AttackTarget(); + DownwardCrossFade = MathHelper.Clamp(DownwardCrossFade + 0.025f, 0f, 1f); + AttackTime++; + } + else + { + DownwardCrossFade = MathHelper.Clamp(DownwardCrossFade - 0.025f, 0f, 1f); + AttackTime = 0f; + } + + AttackTime++; + } + + internal void DoInitializationEffects() + { + projectile.Calamity().spawnedPlayerMinionDamageValue = Owner.MinionDamage(); + projectile.Calamity().spawnedPlayerMinionProjectileDamageValue = projectile.damage; + + // Release a burst of fire dust on spawn. + if (Main.dedServ) + return; + + for (int i = 0; i < 55; i++) + { + Dust fire = Dust.NewDustPerfect(projectile.Center + Main.rand.NextVector2Circular(35f, 35f), 267); + fire.velocity = Vector2.Lerp(fire.velocity, Vector2.UnitY * -Main.rand.NextFloat(3.5f, 6f), 0.5f); + fire.color = Color.Lerp(Color.Orange, Color.Red, Main.rand.NextFloat(0f, 0.67f)); + fire.scale = Main.rand.NextFloat(1.2f, 1.5f); + fire.noGravity = true; + } + } + + internal void ProvidePlayerMinionBuffs() + { + Owner.AddBuff(ModContent.BuffType(), 3600); + + // Verify player/minion state integrity. The minion cannot stay alive if the + // owner is dead or if the caller of the AI is invalid. + if (projectile.type != ModContent.ProjectileType()) + return; + + if (Owner.dead) + Owner.Calamity().perditionBeacon = false; + if (Owner.Calamity().perditionBeacon) + projectile.timeLeft = 2; + } + + internal void HandleFrames() + { + projectile.frameCounter++; + if (projectile.frameCounter % 5 == 4) + projectile.frame = (projectile.frame + 1) % Main.projFrames[projectile.type]; + } + + internal void FollowOwner() + { + Vector2 destination = Owner.Top - Vector2.UnitY * MathHelper.Lerp(20f, 40f, (float)Math.Cos(projectile.timeLeft / 24f) * 0.5f + 0.5f); + projectile.Center = Vector2.Lerp(projectile.Center, destination, 0.025f); + projectile.Center += (destination - projectile.Center).SafeNormalize(Vector2.Zero) * 3f; + + if (projectile.WithinRange(destination, 5f) || !projectile.WithinRange(destination, 2200f)) + projectile.Center = destination; + } + + internal void AttackTarget() + { + // Release cinders around the target. + Dust cinder = Dust.NewDustPerfect(Target.Center + Main.rand.NextVector2Circular(800f, 800f), DustID.Fire); + cinder.velocity = Vector2.UnitY * -Main.rand.NextFloat(3f, 7f); + cinder.scale = 1f + cinder.velocity.Length() * 0.17f; + cinder.noGravity = true; + + int shootRate = (int)MathHelper.Lerp(24f, 3f, Utils.InverseLerp(0f, 300f, AttackTime, true)); + AttackTimer++; + + if (AttackTimer < shootRate || Main.myPlayer != projectile.owner) + return; + + AttackTimer = 0f; + projectile.netUpdate = true; + + WeightedRandom rng = new WeightedRandom(projectile.identity * 2167 + (int)(Main.GlobalTime * 20)); + rng.Add(ModContent.ProjectileType(), 0.5f); + rng.Add(ModContent.ProjectileType(), 0.6f); + rng.Add(ModContent.ProjectileType(), 0.8f); + rng.Add(ModContent.ProjectileType(), 1f); + + Vector2 spawnPosition = Target.Center + Vector2.UnitY.RotatedByRandom(0.27f) * 1150f; + Vector2 shootVelocity = (Target.Center - spawnPosition).SafeNormalize(-Vector2.UnitY).RotatedByRandom(0.09f) * Main.rand.NextFloat(19f, 31f); + Projectile.NewProjectile(spawnPosition, shootVelocity, rng.Get(), projectile.damage, projectile.knockBack, projectile.owner); + } + + public override void PostDraw(SpriteBatch spriteBatch, Color lightColor) + { + if (Target is null) + return; + + Texture2D crossTexture = ModContent.GetTexture("CalamityMod/Projectiles/Summon/PerditionCross"); + + Vector2 drawPosition = Target.Bottom - Main.screenPosition; + drawPosition.Y -= 12f; + Color drawColor = Color.White * DownwardCrossFade; + spriteBatch.Draw(crossTexture, drawPosition, null, drawColor, projectile.rotation, crossTexture.Size() * 0.5f, projectile.scale * 0.85f, SpriteEffects.None, 0f); + } + + public override bool CanDamage() => false; + } +} diff --git a/Projectiles/Summon/PerditionBeacon.png b/Projectiles/Summon/PerditionBeacon.png new file mode 100644 index 0000000000..daa5e3f58f Binary files /dev/null and b/Projectiles/Summon/PerditionBeacon.png differ diff --git a/Projectiles/Summon/PerditionCross.png b/Projectiles/Summon/PerditionCross.png new file mode 100644 index 0000000000..e7441f8d10 Binary files /dev/null and b/Projectiles/Summon/PerditionCross.png differ diff --git a/Projectiles/Summon/PolypLauncherProjectile.cs b/Projectiles/Summon/PolypLauncherProjectile.cs new file mode 100644 index 0000000000..fc0eeee785 --- /dev/null +++ b/Projectiles/Summon/PolypLauncherProjectile.cs @@ -0,0 +1,80 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + public class PolypLauncherProjectile : ModProjectile + { + public const float Gravity = 0.4f; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Polyp Chunk"); + ProjectileID.Sets.SentryShot[projectile.type] = true; + } + + public override void SetDefaults() + { + projectile.width = 18; + projectile.height = 18; + projectile.friendly = true; + projectile.tileCollide = true; + projectile.ignoreWater = true; + projectile.timeLeft = 300; + projectile.alpha = 255; + projectile.minion = true; + projectile.minionSlots = 0f; + } + + public override void AI() + { + if (projectile.velocity.Y <= 10f) + { + projectile.velocity.Y += Gravity; + } + projectile.ai[0]++; + if (projectile.ai[0] < 10) + { + projectile.alpha = (int)MathHelper.Lerp(255, 0, projectile.ai[0] / 10f); + } + projectile.rotation += (Math.Abs(projectile.velocity.X) + Math.Abs(projectile.velocity.Y)) * 0.1f * projectile.direction; + } + + public override void Kill(int timeLeft) + { + Main.PlaySound(SoundID.Item10, projectile.Center); + //Dust on impact + int dust_splash = 0; + while (dust_splash < 9) + { + Dust.NewDust(projectile.position, projectile.width, projectile.height, 225, -projectile.velocity.X * 0.15f, -projectile.velocity.Y * 0.15f, 120, default, 1f); + dust_splash += 1; + } + int split = 0; + int shardAmt = Main.rand.Next(1,5); + while (split < shardAmt) + { + //Calculate the velocity of the projectile + float shardspeedX = -projectile.velocity.X * Main.rand.NextFloat(.5f, .7f) + Main.rand.NextFloat(-3f, 3f); + float shardspeedY = -projectile.velocity.Y * Main.rand.Next(50, 70) * 0.01f + Main.rand.Next(-8, 9) * 0.2f; + //Prevents the projectile speed from being too low + if (shardspeedX < 2f && shardspeedX > -2f) + { + shardspeedX += -projectile.velocity.X; + } + if (shardspeedY > 2f && shardspeedY < 2f) + { + shardspeedY += -projectile.velocity.Y; + } + Vector2 shardSpeed = new Vector2(shardspeedX, shardspeedY); + + //Spawn the projectile + int shard = Projectile.NewProjectile(projectile.Center + shardSpeed, shardSpeed, ModContent.ProjectileType(), (int)(projectile.damage * 0.5), projectile.knockBack / 2f, projectile.owner, Main.rand.Next(3)); + split += 1; + } + } + } +} diff --git a/Projectiles/Summon/PolypLauncherProjectile.png b/Projectiles/Summon/PolypLauncherProjectile.png new file mode 100644 index 0000000000..d4fb7e3171 Binary files /dev/null and b/Projectiles/Summon/PolypLauncherProjectile.png differ diff --git a/Projectiles/Summon/PolypLauncherSentry.cs b/Projectiles/Summon/PolypLauncherSentry.cs new file mode 100644 index 0000000000..88b104c1c1 --- /dev/null +++ b/Projectiles/Summon/PolypLauncherSentry.cs @@ -0,0 +1,99 @@ +using Microsoft.Xna.Framework; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +namespace CalamityMod.Projectiles.Summon +{ + public class PolypLauncherSentry : ModProjectile + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Polyp Launcher"); + Main.projFrames[projectile.type] = 4; + ProjectileID.Sets.MinionTargettingFeature[projectile.type] = true; + } + + public override void SetDefaults() + { + projectile.width = 42; + projectile.height = 25; + projectile.ignoreWater = true; + projectile.tileCollide = true; + projectile.sentry = true; + projectile.timeLeft = Projectile.SentryLifeTime; + projectile.penetrate = -1; + } + + public override void AI() + { + Player player = Main.player[projectile.owner]; + + if (projectile.localAI[0] == 0f) + { + projectile.Calamity().spawnedPlayerMinionDamageValue = player.MinionDamage(); + projectile.Calamity().spawnedPlayerMinionProjectileDamageValue = projectile.damage; + projectile.localAI[0] += 1f; + } + if (player.MinionDamage() != projectile.Calamity().spawnedPlayerMinionDamageValue) + { + int damage2 = (int)(projectile.Calamity().spawnedPlayerMinionProjectileDamageValue / + projectile.Calamity().spawnedPlayerMinionDamageValue * + player.MinionDamage()); + projectile.damage = damage2; + } + + projectile.frameCounter++; + if (projectile.frameCounter > 4) + { + projectile.frame++; + projectile.frameCounter = 0; + } + if (projectile.frame >= Main.projFrames[projectile.type]) + { + projectile.frame = 0; + } + + projectile.velocity.Y += 0.5f; + if (projectile.velocity.Y > 10f) + { + projectile.velocity.Y = 10f; + } + + projectile.StickToTiles(false, false); + + if (projectile.ai[0] > 0f) + { + projectile.ai[0] -= 1f; + return; + } + projectile.ai[1] += Main.rand.Next(1,3); + + NPC potentialTarget = projectile.Center.MinionHoming(800f, player, false); + + if (projectile.owner == Main.myPlayer && potentialTarget != null) + { + if (projectile.ai[1] > 40f) + { + Vector2 spawnPosition = new Vector2(projectile.oldPosition.X + (projectile.width / 2), projectile.oldPosition.Y + (projectile.height / 2)); + + float shootSpeed = 16f; + float gravity = -PolypLauncherProjectile.Gravity; + float distance = Vector2.Distance(spawnPosition, potentialTarget.Center); + float angle = 0.25f * (float)Math.Asin(MathHelper.Clamp(gravity * distance * 1.5f / (float)Math.Pow(shootSpeed, 2), -1f, 1f)); + + Vector2 velocity = new Vector2(0f, -shootSpeed).RotatedBy(angle).RotatedByRandom(0.1f); + velocity.X *= (potentialTarget.Center.X - projectile.Center.X < 0).ToDirectionInt(); + + Projectile.NewProjectile(spawnPosition, velocity, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner); + projectile.ai[1] = 0f; + projectile.netUpdate = true; + } + } + } + + public override bool OnTileCollide(Vector2 oldVelocity) => false; + + public override bool CanDamage() => false; + } +} diff --git a/Projectiles/Summon/PolypLauncherSentry.png b/Projectiles/Summon/PolypLauncherSentry.png new file mode 100644 index 0000000000..605f9b0719 Binary files /dev/null and b/Projectiles/Summon/PolypLauncherSentry.png differ diff --git a/Projectiles/Summon/PolypLauncherShrapnel.cs b/Projectiles/Summon/PolypLauncherShrapnel.cs new file mode 100644 index 0000000000..69dff708fe --- /dev/null +++ b/Projectiles/Summon/PolypLauncherShrapnel.cs @@ -0,0 +1,65 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +namespace CalamityMod.Projectiles.Summon +{ + public class PolypLauncherShrapnel : ModProjectile + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Polyp Shrapnel"); + ProjectileID.Sets.SentryShot[projectile.type] = true; + } + + public override void SetDefaults() + { + projectile.friendly = true; + projectile.width = 13; + projectile.height = 13; + projectile.ignoreWater = true; + projectile.timeLeft = 120; + projectile.minion = true; + projectile.minionSlots = 0f; + } + + public override void AI() + { + //Rotation and gravity + projectile.rotation += 0.6f * projectile.direction; + projectile.velocity.Y += 0.27f; + if (projectile.velocity.Y > 16f) + { + projectile.velocity.Y = 16f; + } + } + + public override void Kill(int timeLeft) + { + //Dust effect + int splash = 0; + while (splash < 4) + { + Dust.NewDust(projectile.position, projectile.width, projectile.height, 225, -projectile.velocity.X * 0.15f, -projectile.velocity.Y * 0.10f, 150, default, 0.7f); + splash += 1; + } + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + //Changes the texture of the projectile + Texture2D texture = Main.projectileTexture[projectile.type]; + if (projectile.ai[0] == 1f) + { + texture = ModContent.GetTexture("CalamityMod/Projectiles/Summon/PolypLauncherShrapnel2"); + } + if (projectile.ai[0] == 2f) + { + texture = ModContent.GetTexture("CalamityMod/Projectiles/Summon/PolypLauncherShrapnel3"); + } + Main.spriteBatch.Draw(texture, projectile.Center - Main.screenPosition, new Rectangle?(new Rectangle(0, 0, texture.Width, texture.Height)), projectile.GetAlpha(lightColor), projectile.rotation, texture.Size() / 2f, projectile.scale, SpriteEffects.None, 0f); + return false; + } + } +} diff --git a/Projectiles/Summon/PolypLauncherShrapnel.png b/Projectiles/Summon/PolypLauncherShrapnel.png new file mode 100644 index 0000000000..94fe76c650 Binary files /dev/null and b/Projectiles/Summon/PolypLauncherShrapnel.png differ diff --git a/Projectiles/Summon/PolypLauncherShrapnel2.png b/Projectiles/Summon/PolypLauncherShrapnel2.png new file mode 100644 index 0000000000..08c20fef73 Binary files /dev/null and b/Projectiles/Summon/PolypLauncherShrapnel2.png differ diff --git a/Projectiles/Summon/PolypLauncherShrapnel3.png b/Projectiles/Summon/PolypLauncherShrapnel3.png new file mode 100644 index 0000000000..b4ca87e39c Binary files /dev/null and b/Projectiles/Summon/PolypLauncherShrapnel3.png differ diff --git a/Projectiles/Summon/SageNeedle.cs b/Projectiles/Summon/SageNeedle.cs new file mode 100644 index 0000000000..76f51d3629 --- /dev/null +++ b/Projectiles/Summon/SageNeedle.cs @@ -0,0 +1,75 @@ +using CalamityMod.Buffs.DamageOverTime; +using Microsoft.Xna.Framework; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +namespace CalamityMod.Projectiles.Summon +{ + public class SageNeedle : ModProjectile + { + public const int OnDeathHealValue = 1; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Sage Needle"); + ProjectileID.Sets.MinionShot[projectile.type] = true; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 16; + projectile.friendly = true; + projectile.ignoreWater = true; + projectile.minion = true; + projectile.minionSlots = 0f; + projectile.timeLeft = 150; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 6; + } + + public override void AI() + { + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.ToRadians(48f); + + // Don't collide with tiles unless the needle is falling. + projectile.tileCollide = projectile.velocity.Y > 0f; + if (projectile.velocity.Y < 12f) + projectile.velocity.Y += 0.16f; + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + int totalSageSpirits = Main.player[projectile.owner].ownedProjectileCounts[ModContent.ProjectileType()]; + + // A slightly-smoothened curve that's a little less potent than a linear curve. + // Has the potential to eventually surpass a linear curve, but this is infeasible, only happening + // at around 344 allocated slots. + float averageDamageMultiplier = (float)(Math.Pow(totalSageSpirits, 0.73D) + Math.Pow(totalSageSpirits, 1.1D)) * 0.5f; + + // 1 slot provides 40 DoT. + // 2 slots provide 76 DoT. + // 3 slots provide 111 DoT. + // 4 slots provide 146 DoT. + // 5 slots provide 182 DoT. + int sagePoisonDamage = (int)(40 * averageDamageMultiplier); + sagePoisonDamage = CalamityUtils.DamageSoftCap(sagePoisonDamage, 270); + + target.AddBuff(ModContent.BuffType(), 300); + target.Calamity().sagePoisonDamage = sagePoisonDamage; + } + + public override void Kill(int timeLeft) + { + if (Main.dedServ) + return; + + for (int i = 0; i < 6; i++) + { + Dust redGrass = Dust.NewDustDirect(projectile.position + projectile.velocity, projectile.width, projectile.height, DustID.Grass, projectile.velocity.X * 0.1f, projectile.velocity.Y * 0.1f); + redGrass.velocity = Utils.NextVector2Unit(Main.rand) * Main.rand.NextFloat(1f, 3f); + redGrass.noGravity = true; + redGrass.color = Color.Lerp(Color.IndianRed, Color.MediumVioletRed, Main.rand.NextFloat()); + } + } + } +} diff --git a/Projectiles/Summon/SageNeedle.png b/Projectiles/Summon/SageNeedle.png new file mode 100644 index 0000000000..539aaa7384 Binary files /dev/null and b/Projectiles/Summon/SageNeedle.png differ diff --git a/Projectiles/Summon/SageSpirit.cs b/Projectiles/Summon/SageSpirit.cs new file mode 100644 index 0000000000..105c02e434 --- /dev/null +++ b/Projectiles/Summon/SageSpirit.cs @@ -0,0 +1,197 @@ +using CalamityMod.Buffs.Summon; +using Microsoft.Xna.Framework; +using System; +using System.IO; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + public class SageSpirit : ModProjectile + { + internal Player Owner => Main.player[projectile.owner]; + internal ref float AttackTimer => ref projectile.ai[0]; + internal ref float PlayerFlyTime => ref projectile.ai[1]; + internal ref float SageSpiritIndex => ref projectile.localAI[0]; + internal ref float GeneralTime => ref projectile.localAI[1]; + internal bool Initialized = false; + internal Vector2 PlayerFlyStart; + internal Vector2 PlayerFlyOffsetAtEnds; + internal Vector2 PlayerFlyDestination; + + internal const int ShootRate = 40; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Sage Spirit"); + Main.projFrames[projectile.type] = 4; + ProjectileID.Sets.MinionSacrificable[projectile.type] = true; + ProjectileID.Sets.MinionTargettingFeature[projectile.type] = true; + } + + public override void SetDefaults() + { + projectile.width = 48; + projectile.height = 72; + projectile.netImportant = true; + projectile.friendly = true; + projectile.ignoreWater = true; + projectile.minionSlots = 1f; + projectile.timeLeft = 90000; + projectile.penetrate = -1; + projectile.tileCollide = false; + projectile.minion = true; + } + + public override void SendExtraAI(BinaryWriter writer) + { + writer.Write(Initialized); + writer.Write(SageSpiritIndex); + writer.Write(GeneralTime); + writer.WritePackedVector2(PlayerFlyStart); + writer.WritePackedVector2(PlayerFlyOffsetAtEnds); + writer.WritePackedVector2(PlayerFlyDestination); + } + + public override void ReceiveExtraAI(BinaryReader reader) + { + Initialized = reader.ReadBoolean(); + SageSpiritIndex = reader.ReadSingle(); + GeneralTime = reader.ReadSingle(); + PlayerFlyStart = reader.ReadPackedVector2(); + PlayerFlyOffsetAtEnds = reader.ReadPackedVector2(); + PlayerFlyDestination = reader.ReadPackedVector2(); + } + + public override void AI() + { + GeneralTime++; + ProvidePlayerMinionBuffs(); + Initialize(); + DetermineFrames(); + NPC potentialTarget = projectile.Center.MinionHoming(750f, Owner); + if (potentialTarget is null) + FlyNearOwner(); + else + { + ResetOwnerFlyValues(); + AttackTarget(potentialTarget); + } + } + + internal void ProvidePlayerMinionBuffs() + { + Owner.AddBuff(ModContent.BuffType(), 3600); + + // Verify player/minion state integrity. The minion cannot stay alive if the + // owner is dead or if the caller of the AI is invalid. + if (projectile.type != ModContent.ProjectileType()) + return; + + if (Owner.dead) + Owner.Calamity().sageSpirit = false; + if (Owner.Calamity().sageSpirit) + projectile.timeLeft = 2; + } + + internal void Initialize() + { + if (Initialized) + return; + + Initialized = true; + PlayerFlyTime = 1f; + PlayerFlyOffsetAtEnds = Vector2.UnitY; + PlayerFlyStart = projectile.Center; + PlayerFlyDestination = projectile.Center - Vector2.UnitY * 10f; + projectile.netUpdate = true; + } + + internal void DetermineFrames() + { + projectile.frameCounter++; + if (projectile.frameCounter % 5 == 4) + projectile.frame = (projectile.frame + 1) % Main.projFrames[projectile.type]; + } + + internal void ResetOwnerFlyValues() + { + PlayerFlyTime = 0f; + PlayerFlyOffsetAtEnds = Vector2.Zero; + PlayerFlyStart = PlayerFlyDestination = -Vector2.One; + projectile.netUpdate = true; + } + + internal void FlyNearOwner() + { + Vector2 destination = Owner.Center + Vector2.UnitX * Owner.width * 1.6f * Owner.direction; + + int totalSageSpirits = Owner.ownedProjectileCounts[projectile.type]; + destination += (SageSpiritIndex * MathHelper.TwoPi / totalSageSpirits).ToRotationVector2() * 70f; + if (PlayerFlyTime >= 1f) + { + projectile.Center = PlayerFlyDestination; + ResetOwnerFlyValues(); + return; + } + + float distanceFromDestination = projectile.Distance(destination); + if (float.IsNaN(distanceFromDestination)) + distanceFromDestination = 0f; + + // Determine owner values if they are still in the air. + if (PlayerFlyTime <= 0f) + { + PlayerFlyStart = projectile.Center; + PlayerFlyOffsetAtEnds = Vector2.UnitY * distanceFromDestination; + PlayerFlyDestination = destination; + projectile.netUpdate = true; + PlayerFlyTime = 0.01f; + return; + } + + projectile.position.Y += (float)Math.Cos(GeneralTime / 60f * MathHelper.TwoPi + projectile.identity * 1.1f) * 0.5f; + + if (distanceFromDestination < 160f && PlayerFlyTime <= 0f) + return; + + // A catmull-rom spline attempts to find a smooth arc of two points based on a 0-1 interpolant. + // Its results are always within the bounds of the second and third term. They are intended to be the "middle" of the spline. + // The other 2 points at the ends are intended to be used to determine how the resulting curve should arc. + // In this context, since the offset at the start is down, it'll actually go up because it's starting at the bottom + // and then going up, bending between the 2 middle points. + projectile.Center = Vector2.CatmullRom( + PlayerFlyStart + PlayerFlyOffsetAtEnds, + PlayerFlyStart, + PlayerFlyDestination, + PlayerFlyDestination + PlayerFlyOffsetAtEnds, + PlayerFlyTime); + + PlayerFlyTime = MathHelper.Clamp(PlayerFlyTime + 0.03f, 0f, 1f); + } + + internal void AttackTarget(NPC target) + { + AttackTimer++; + + int totalSageSpirits = Owner.ownedProjectileCounts[projectile.type]; + Vector2 destinationOffsetFactor = Vector2.Max(target.Size, new Vector2(160f)) * new Vector2(0.6f, 0.37f); + Vector2 destination = target.Center + (AttackTimer / 12f).ToRotationVector2() * destinationOffsetFactor; + destination += (SageSpiritIndex * MathHelper.TwoPi / totalSageSpirits).ToRotationVector2() * 130f; + projectile.Center = Vector2.Lerp(projectile.Center, destination, 0.1f); + + // Frequently release a bunch of spikes. + if (projectile.owner == Main.myPlayer && AttackTimer % ShootRate == ShootRate - 1) + { + for (int i = 0; i < 3; i++) + { + Vector2 spikeVelocity = -Vector2.UnitY.RotatedBy(MathHelper.Lerp(-0.56f, 0.56f, i / 3f)) * 6f; + Projectile.NewProjectile(projectile.Top, spikeVelocity, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner); + } + } + } + + // The spirit itself should not do direct damage. + public override bool CanDamage() => false; + } +} diff --git a/Projectiles/Summon/SageSpirit.png b/Projectiles/Summon/SageSpirit.png new file mode 100644 index 0000000000..6bd3337fd9 Binary files /dev/null and b/Projectiles/Summon/SageSpirit.png differ diff --git a/Projectiles/Summon/SeekerSummonProj.cs b/Projectiles/Summon/SeekerSummonProj.cs new file mode 100644 index 0000000000..7805fd543a --- /dev/null +++ b/Projectiles/Summon/SeekerSummonProj.cs @@ -0,0 +1,150 @@ +using CalamityMod.Buffs.Summon; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + public class SeekerSummonProj : ModProjectile + { + public Player Owner => Main.player[projectile.owner]; + public ref float CircleAngleRatio => ref projectile.ai[0]; + public ref float Time => ref projectile.ai[1]; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Soul Seeker"); + Main.projFrames[projectile.type] = 5; + ProjectileID.Sets.MinionTargettingFeature[projectile.type] = true; + ProjectileID.Sets.MinionSacrificable[projectile.type] = true; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 84; + projectile.netImportant = true; + projectile.friendly = true; + projectile.ignoreWater = true; + projectile.minionSlots = 1f; + projectile.timeLeft = 90000; + projectile.penetrate = -1; + projectile.tileCollide = false; + projectile.minion = true; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 8; + projectile.alpha = 255; + } + + + public override void AI() + { + if (projectile.localAI[0] == 0f) + { + DoInitializationEffects(); + projectile.localAI[0] = 1f; + } + + ProvidePlayerMinionBuffs(); + DetermineFrames(); + + projectile.alpha = Utils.Clamp(projectile.alpha - 15, 0, 255); + NPC potentialTarget = projectile.Center.MinionHoming(2050f, Owner); + if (potentialTarget is null) + FlyNearOwner(); + else + AttackTarget(potentialTarget); + Time++; + } + + internal void DoInitializationEffects() + { + if (Main.dedServ) + return; + + for (int i = 0; i < 40; i++) + { + Dust brimstoneFire = Dust.NewDustPerfect(projectile.Center + Main.rand.NextVector2Circular(50f, 50f), DustID.Fireworks); + brimstoneFire.velocity = Vector2.UnitY * -Main.rand.NextFloat(2f, 5f); + brimstoneFire.scale = 1f + brimstoneFire.velocity.Length() * 0.1f; + brimstoneFire.color = Color.Lerp(Color.White, Color.OrangeRed, Main.rand.NextFloat()); + brimstoneFire.noGravity = true; + } + } + + internal void ProvidePlayerMinionBuffs() + { + Owner.AddBuff(ModContent.BuffType(), 3600); + + // Verify player/minion state integrity. The minion cannot stay alive if the + // owner is dead or if the caller of the AI is invalid. + if (projectile.type != ModContent.ProjectileType()) + return; + + if (Owner.dead) + Owner.Calamity().soulSeeker = false; + if (Owner.Calamity().soulSeeker) + projectile.timeLeft = 2; + } + + internal void DetermineFrames() + { + projectile.frameCounter++; + if (projectile.frameCounter % 5 == 4) + projectile.frame = (projectile.frame + 1) % Main.projFrames[projectile.type]; + } + + internal void FlyNearOwner() + { + // Make an imp laugh sound every so often. + if (Main.rand.NextBool(1600)) + Main.PlaySound(SoundID.DD2_KoboldFlyerHurt); + + Vector2 destination = Owner.Center + (MathHelper.TwoPi * CircleAngleRatio - MathHelper.PiOver2).ToRotationVector2() * 310f; + projectile.Center = Vector2.Lerp(projectile.Center, destination, 0.03f); + + if (!projectile.WithinRange(destination, 20f)) + projectile.velocity = (projectile.velocity * 20f + projectile.SafeDirectionTo(destination) * 16f) / 21f; + + if (!projectile.WithinRange(Owner.Center, 1800f)) + { + projectile.Center = Owner.Center; + projectile.velocity = -Vector2.UnitY * 4f; + projectile.netUpdate = true; + } + + projectile.spriteDirection = (destination.X - projectile.Center.X > 0f).ToDirectionInt(); + } + + internal void AttackTarget(NPC target) + { + // Slow down and release a bunch of darts at the enemy for a short interval. + if (Time % 90f > 45f) + { + // Make an imp scream sound every so often. + if (Main.rand.NextBool(400)) + Main.PlaySound(SoundID.DD2_KoboldFlyerChargeScream); + + projectile.velocity *= 0.9f; + if (Time % 16f == 15f) + { + float shootSpeed = 14f; + Vector2 eyePosition = projectile.Center + new Vector2(projectile.spriteDirection * 22f, -12f); + Vector2 aheadAim = (target.Center - eyePosition) / target.velocity.Length() / shootSpeed; + Vector2 shootVelocity = (target.Center + aheadAim - eyePosition).SafeNormalize(Vector2.UnitX * projectile.spriteDirection) * shootSpeed; + projectile.spriteDirection = (shootVelocity.X > 0f).ToDirectionInt(); + if (Main.netMode != NetmodeID.MultiplayerClient) + { + Projectile.NewProjectile(eyePosition, shootVelocity, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner); + } + } + return; + } + + projectile.spriteDirection = (projectile.velocity.X > 0f).ToDirectionInt(); + if (!projectile.WithinRange(target.Center, 400f)) + projectile.velocity = (projectile.velocity * 10f + projectile.SafeDirectionTo(target.Center) * 22f) / 11f; + else if (projectile.velocity.Length() < 28f) + projectile.velocity = projectile.SafeDirectionTo(target.Center) * 29f; + } + } +} diff --git a/Projectiles/Summon/SeekerSummonProj.png b/Projectiles/Summon/SeekerSummonProj.png new file mode 100644 index 0000000000..bd3a5924ca Binary files /dev/null and b/Projectiles/Summon/SeekerSummonProj.png differ diff --git a/Projectiles/Summon/SepulcherArm.png b/Projectiles/Summon/SepulcherArm.png new file mode 100644 index 0000000000..b45111f206 Binary files /dev/null and b/Projectiles/Summon/SepulcherArm.png differ diff --git a/Projectiles/Summon/SepulcherForeArm.png b/Projectiles/Summon/SepulcherForeArm.png new file mode 100644 index 0000000000..da24ee8a4f Binary files /dev/null and b/Projectiles/Summon/SepulcherForeArm.png differ diff --git a/Projectiles/Summon/SepulcherHand.png b/Projectiles/Summon/SepulcherHand.png new file mode 100644 index 0000000000..c28935e9f2 Binary files /dev/null and b/Projectiles/Summon/SepulcherHand.png differ diff --git a/Projectiles/Summon/SepulcherMinion.cs b/Projectiles/Summon/SepulcherMinion.cs new file mode 100644 index 0000000000..7635085c33 --- /dev/null +++ b/Projectiles/Summon/SepulcherMinion.cs @@ -0,0 +1,690 @@ +using CalamityMod.Buffs.Summon; +using CalamityMod.NPCs.Other; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + public class SepulcherMinion : ModProjectile + { + public struct SepulcherSegment + { + public Vector2 CurrentPosition; + public float Rotation; + public SepulcherSegment(Vector2 position, float rotation) + { + CurrentPosition = position; + Rotation = rotation; + } + } + + public class SepulcherArm + { + public class SepulcherArmLimb + { + public Vector2 Center; + public float Rotation; + + public SepulcherArmLimb(Vector2 center, float rotation) + { + Center = center; + Rotation = rotation; + } + + public void SendData(BinaryWriter writer) + { + writer.WritePackedVector2(Center); + writer.Write(Rotation); + } + + public static SepulcherArmLimb ReceiveData(BinaryReader reader) => new SepulcherArmLimb(reader.ReadPackedVector2(), reader.ReadSingle()); + } + + public SepulcherArmLimb[] Limbs = new SepulcherArmLimb[2]; + public byte SegmentIndexToAttachTo; + public Vector2 Center; + public float Rotation; + public bool ReelingBack = false; + public bool Direction; + public SepulcherArm(Vector2 center, byte segmentIndexToAttachTo, float rotation, bool reelingBack, bool direction) + { + Center = center; + SegmentIndexToAttachTo = segmentIndexToAttachTo; + Rotation = rotation; + ReelingBack = reelingBack; + Direction = direction; + Limbs = new SepulcherArmLimb[2] + { + new SepulcherArmLimb(center, rotation), + new SepulcherArmLimb(center, rotation) + }; + } + } + + public enum AIState + { + HoverNearOwner, + AttackEnemy_Charge, + AttackEnemy_ReleaseDartBurst, + AttackOwner + } + + public int IdleTimer; + public int AttackTimer; + public int PlayerAttackCountdown; + public SepulcherSegment[] Segments = new SepulcherSegment[24]; + public List Arms = new List(); + public Player Owner => Main.player[projectile.owner]; + public AIState CurrentAIState + { + get => (AIState)(int)projectile.ai[0]; + set + { + // Don't do anything unless the caller is the owner of this projectile- changes will be synced to other clients in MP. + if (Main.myPlayer != projectile.owner) + return; + + projectile.ai[0] = (int)value; + projectile.netUpdate = true; + } + } + public ref float JawRotation => ref projectile.localAI[0]; + public ref float JawSnapTimer => ref projectile.localAI[1]; + + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Sepulcher"); + ProjectileID.Sets.TrailingMode[projectile.type] = 2; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 5; + ProjectileID.Sets.MinionSacrificable[projectile.type] = true; + ProjectileID.Sets.MinionTargettingFeature[projectile.type] = true; + } + + public override void SetDefaults() + { + projectile.width = 54; + projectile.height = 54; + projectile.friendly = true; + projectile.ignoreWater = true; + projectile.netImportant = true; + projectile.penetrate = -1; + projectile.minionSlots = 4f; + projectile.timeLeft = 90000; + projectile.Opacity = 0f; + projectile.tileCollide = false; + projectile.minion = true; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 4; + projectile.hide = true; + } + + #region Syncing + public override void SendExtraAI(BinaryWriter writer) + { + writer.Write(IdleTimer); + writer.Write(PlayerAttackCountdown); + writer.Write(Arms.Count); + for (int i = 0; i < Arms.Count; i++) + { + writer.WritePackedVector2(Arms[i].Center); + writer.Write(Arms[i].SegmentIndexToAttachTo); + writer.Write(Arms[i].Rotation); + writer.Write(Arms[i].ReelingBack); + writer.Write(Arms[i].Direction); + Arms[0].Limbs[0].SendData(writer); + Arms[0].Limbs[1].SendData(writer); + } + } + + public override void ReceiveExtraAI(BinaryReader reader) + { + IdleTimer = reader.ReadInt32(); + PlayerAttackCountdown = reader.ReadInt32(); + Arms.Clear(); + for (int i = 0; i < reader.ReadInt32(); i++) + { + Arms.Add(new SepulcherArm(reader.ReadPackedVector2(), reader.ReadByte(), reader.ReadSingle(), reader.ReadBoolean(), reader.ReadBoolean())); + Arms.Last().Limbs[0] = SepulcherArm.SepulcherArmLimb.ReceiveData(reader); + Arms.Last().Limbs[1] = SepulcherArm.SepulcherArmLimb.ReceiveData(reader); + } + } + #endregion + + #region AI + public override void AI() + { + Initialize(); + HandleBuffs(); + HandleFlexibleDamage(); + UpdateSegments(); + + // Fade in rapidly. + projectile.Opacity = MathHelper.Clamp(projectile.Opacity + 0.2f, 0f, 1f); + + NPC potentialTarget = AttemptToFindTarget(1450f); + + // Enter the attack state if a valid enemy is found and go back to hovering otherwise. + // This will be overriden if attacking the owner. + if (CurrentAIState != AIState.AttackEnemy_ReleaseDartBurst && CurrentAIState != AIState.AttackEnemy_Charge) + { + if (potentialTarget != null) + CurrentAIState = AIState.AttackEnemy_ReleaseDartBurst; + } + else if (potentialTarget is null) + { + CurrentAIState = AIState.HoverNearOwner; + AttackTimer = 0; + } + + // Reset the AI to player attack mode if the countdown is going on. + if (PlayerAttackCountdown > 0) + { + if (CurrentAIState != AIState.AttackOwner) + CurrentAIState = AIState.AttackOwner; + + PlayerAttackCountdown--; + + // If it's finished, go back to idle owner hover movement. + if (PlayerAttackCountdown <= 0) + CurrentAIState = AIState.HoverNearOwner; + } + + + // Determine whether the projectile can attack its owner based on the attakc countdown. + projectile.hostile = PlayerAttackCountdown > 0; + + switch (CurrentAIState) + { + case AIState.HoverNearOwner: + HoverNearOwner(); + break; + case AIState.AttackEnemy_ReleaseDartBurst: + AttackEnemyWithDarts(potentialTarget); + AttackTimer++; + break; + case AIState.AttackEnemy_Charge: + AttackEnemyByCharging(potentialTarget); + AttackTimer++; + break; + case AIState.AttackOwner: + AttackOwner(); + break; + } + + // Check if ready to enrage every so often. + IdleTimer++; + if (IdleTimer % 600 == 599) + { + int heartsAttachedToOwner = 0; + int heartType = ModContent.NPCType(); + for (int i = 0; i < Main.maxNPCs; i++) + { + if (Main.npc[i].type != heartType || !Main.npc[i].active || Main.npc[i].target != projectile.owner) + continue; + heartsAttachedToOwner++; + } + + float chanceToBecomeAngry = 0f; + if (heartsAttachedToOwner >= 2) + chanceToBecomeAngry = Utils.InverseLerp(2f, 6f, heartsAttachedToOwner, true); + if (Main.rand.NextFloat() < chanceToBecomeAngry) + { + PlayerAttackCountdown = 300; + projectile.netUpdate = true; + } + else if (Main.netMode != NetmodeID.MultiplayerClient) + NPC.NewNPC((int)Owner.Center.X, (int)Owner.Center.Y, heartType); + } + + if (JawSnapTimer > 0f) + { + JawRotation = JawRotation.AngleTowards(-0.44f, 0.064f); + JawSnapTimer--; + } + else + JawRotation = JawRotation.AngleTowards(0f, 0.03f); + } + + public void Initialize() + { + if (projectile.ai[1] != 0f) + return; + + for (int i = 0; i < Segments.Length; i++) + Segments[i].CurrentPosition = projectile.Center - projectile.velocity.SafeNormalize(Vector2.UnitY) * i * 0.2f; + + projectile.Calamity().spawnedPlayerMinionDamageValue = Owner.MinionDamage(); + projectile.Calamity().spawnedPlayerMinionProjectileDamageValue = projectile.damage; + projectile.ai[1] = 1f; + if (Main.myPlayer == projectile.owner) + { + float rotationalOffset = 0f; + for (byte i = 3; i < Segments.Length - 2; i += 2) + { + Arms.Add(new SepulcherArm(Segments[i].CurrentPosition, i, rotationalOffset, false, false)); + rotationalOffset = MathHelper.WrapAngle(rotationalOffset + MathHelper.Pi / 6f); + + Arms.Add(new SepulcherArm(Segments[i].CurrentPosition, i, rotationalOffset + MathHelper.Pi, false, true)); + rotationalOffset = MathHelper.WrapAngle(rotationalOffset + MathHelper.Pi / 6f); + } + projectile.netUpdate = true; + } + } + + public void HandleBuffs() + { + // Maintain or remove the Mechworm buff from the owner. + Owner.AddBuff(ModContent.BuffType(), 3600); + if (Owner.dead) + Owner.Calamity().sepulcher = false; + if (Owner.Calamity().sepulcher) + projectile.timeLeft = 2; + } + + public void HandleFlexibleDamage() + { + // Adjust the damage of this projectile if the owner's current minion damage factor has changed for any reason. + if (Owner.MinionDamage() != projectile.Calamity().spawnedPlayerMinionDamageValue) + { + int trueDamage = (int)(projectile.Calamity().spawnedPlayerMinionProjectileDamageValue / projectile.Calamity().spawnedPlayerMinionDamageValue * Owner.MinionDamage()); + projectile.damage = trueDamage; + } + } + + public void UpdateSegments() + { + float aheadRotation = projectile.rotation; + Vector2 aheadPosition = projectile.Center; + + // Connect all segments to each-other and calculate their rotations. + for (int i = 0; i < Segments.Length; i++) + { + Vector2 offsetToDestination = aheadPosition - Segments[i].CurrentPosition; + // This variant of segment attachment incorporates rotation. + // Given the fact that all segments will execute this code is succession, the + // result across the entire worm will exponentially decay over each segment, + // allowing for smooth rotations. This code is what the stardust dragon uses for its segmenting. + if (aheadRotation != Segments[i].Rotation) + { + float angleOffset = MathHelper.WrapAngle(aheadRotation - Segments[i].Rotation.AngleLerp(aheadRotation, 0.08f)); + offsetToDestination = offsetToDestination.RotatedBy(angleOffset * 0.08f); + } + + Segments[i].Rotation = (aheadPosition - Segments[i].CurrentPosition).ToRotation() + MathHelper.PiOver2; + Segments[i].CurrentPosition = aheadPosition - offsetToDestination.SafeNormalize(Vector2.Zero) * 48f; + + // Adjust the ahead positions before interating further. + aheadPosition = Segments[i].CurrentPosition; + aheadRotation = Segments[i].Rotation; + } + + // Adjust the arms. + for (int i = 0; i < Arms.Count; i++) + { + SepulcherSegment segmentToAttachTo = Segments[Arms[i].SegmentIndexToAttachTo]; + Vector2 idealMovePosition = segmentToAttachTo.CurrentPosition; + float sideFactor = MathHelper.Lerp(200f, 18f, Utils.InverseLerp(-0.51f, -0.06f, Arms[i].Rotation, true)); + float aheadFactor = MathHelper.Lerp(284f, 680f, Utils.InverseLerp(-0.51f, -0.06f, Arms[i].Rotation, true)); + int direction = Arms[i].Direction.ToDirectionInt(); + idealMovePosition += (segmentToAttachTo.Rotation + Arms[i].Rotation * direction - MathHelper.PiOver2).ToRotationVector2() * projectile.scale * aheadFactor; + idealMovePosition += (segmentToAttachTo.Rotation + Arms[i].Rotation * direction - MathHelper.PiOver2 + MathHelper.PiOver2 * direction).ToRotationVector2() * projectile.scale * sideFactor; + Arms[i].Center = idealMovePosition; + + Vector2 offsetFromSegment = Vector2.Zero; + + offsetFromSegment += new Vector2(direction * 35f, 28f).RotatedBy(segmentToAttachTo.Rotation - (MathHelper.PiOver2 - Arms[i].Rotation * 1.7f - 0.77f) * direction).SafeNormalize(Vector2.UnitY) * 62f; + Arms[i].Limbs[0].Center = segmentToAttachTo.CurrentPosition + offsetFromSegment; + Arms[i].Limbs[0].Rotation = offsetFromSegment.ToRotation(); + + Arms[i].Limbs[1].Rotation = (Arms[i].Center - Arms[i].Limbs[0].Center).ToRotation(); + Arms[i].Limbs[1].Center = Arms[i].Limbs[0].Center + offsetFromSegment * 0.5f + (Arms[i].Center - Arms[i].Limbs[0].Center).SafeNormalize(Vector2.UnitY) * 64f; + + float rotationalVelocityFactor = Utils.InverseLerp(0f, 6f, projectile.velocity.Length(), true); + if (CurrentAIState == AIState.AttackEnemy_Charge) + rotationalVelocityFactor *= 0.85f; + if (CurrentAIState == AIState.AttackOwner) + rotationalVelocityFactor *= 1.2f; + + if (Arms[i].ReelingBack) + { + Arms[i].Rotation -= rotationalVelocityFactor * 0.066f; + if (Arms[i].Rotation < -0.55f) + Arms[i].ReelingBack = false; + } + else + { + Arms[i].Rotation += rotationalVelocityFactor * 0.029f; + if (Arms[i].Rotation > 0.77f) + Arms[i].ReelingBack = true; + } + } + } + + public void HoverNearOwner() + { + // Teleport to the owner if it's very far away. + if (!projectile.WithinRange(Owner.Center, 3200f)) + { + projectile.Center = Owner.Center; + projectile.velocity = Main.rand.NextVector2CircularEdge(4f, 4f); + projectile.netUpdate = true; + } + + // Attempt to move towards the owner. + if (!projectile.WithinRange(Owner.Center, 540f)) + { + Vector2 destination = Owner.Center + (IdleTimer / 31f).ToRotationVector2() * 240f; + projectile.velocity = Vector2.Lerp(projectile.velocity, projectile.SafeDirectionTo(destination) * 18f, 0.03f); + + float updatedDirectionRotation = projectile.velocity.ToRotation().AngleTowards(projectile.AngleTo(destination), 0.04f); + projectile.velocity = updatedDirectionRotation.ToRotationVector2() * projectile.velocity.Length(); + } + else if (projectile.velocity.Length() < 16f) + projectile.velocity *= 1.03f; + + // Determine the head rotation. + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2; + } + + public void AttackEnemyWithDarts(NPC target) + { + Vector2 destination = target.Center + ((AttackTimer / 20f).ToRotationVector2() * 320f); + + // Step towards the ideal velocity with an acceleration of 1 pixel/second^2. + projectile.velocity = projectile.velocity.MoveTowards(projectile.SafeDirectionTo(destination) * 24f, 1f); + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2; + + // Release a burst of darts from all segments at the target. + if (Main.myPlayer == projectile.owner && AttackTimer % 60 > 60 - Segments.Length) + { + int segmentToFireFrom = 60 - AttackTimer % 60; + Vector2 spawnPosition = Segments[segmentToFireFrom].CurrentPosition; + Vector2 shootVelocity = (target.Center - spawnPosition).SafeNormalize(Vector2.UnitY) * 8f; + Projectile.NewProjectile(spawnPosition, shootVelocity, ModContent.ProjectileType(), projectile.damage / 2, projectile.knockBack, projectile.owner); + } + + if (Main.myPlayer == projectile.owner && AttackTimer > 430) + { + CurrentAIState = AIState.AttackEnemy_Charge; + AttackTimer = 0; + } + } + + public void AttackEnemyByCharging(NPC target) + { + if (!projectile.WithinRange(target.Center, 350f)) + { + Vector2 destination = target.Center + (AttackTimer / 25f).ToRotationVector2() * MathHelper.Min(target.width * 0.35f, 150f); + projectile.velocity = Vector2.Lerp(projectile.velocity, projectile.SafeDirectionTo(destination) * 34f, 0.08f); + + float updatedDirectionRotation = projectile.velocity.ToRotation().AngleTowards(projectile.AngleTo(destination), 0.12f); + projectile.velocity = updatedDirectionRotation.ToRotationVector2() * projectile.velocity.Length(); + } + else if (projectile.velocity.Length() < 29f) + { + projectile.velocity *= 1.035f; + if (JawSnapTimer <= 0f) + { + // Open the mouth of the jaw if close but not super close to the target. + if (projectile.WithinRange(target.Center, 270f)) + JawRotation = JawRotation.AngleLerp(0.87f, 0.12f); + + // If really close, snap. + if (projectile.WithinRange(target.Center, 165f)) + { + Main.PlaySound(SoundID.DD2_SkeletonHurt, projectile.Center); + JawSnapTimer = 45f; + } + } + } + + // Determine the head rotation. + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2; + + if (Main.myPlayer == projectile.owner && AttackTimer > 480) + { + CurrentAIState = AIState.AttackEnemy_ReleaseDartBurst; + AttackTimer = 0; + } + } + + public void AttackOwner() + { + // Attempt to angle towards the owner. + float newSpeed = MathHelper.Lerp(projectile.velocity.Length(), 21f, 0.025f); + + if (!projectile.WithinRange(Owner.Center, 370f)) + { + Vector2 idealVelocity = projectile.SafeDirectionTo(Owner.Center) * newSpeed; + projectile.velocity = projectile.velocity.MoveTowards(idealVelocity, 2f); + + float idealAimDirection = idealVelocity.ToRotation(); + projectile.velocity = projectile.velocity.ToRotation().AngleLerp(idealAimDirection, 0.05f).ToRotationVector2() * projectile.velocity.Length(); + } + else if (projectile.velocity.Length() < 36f) + { + projectile.velocity *= 1.03f; + if (JawSnapTimer <= 0f) + { + // Open the mouth of the jaw if close but not super close to the owner. + if (projectile.WithinRange(Owner.Center, 300f)) + JawRotation = JawRotation.AngleLerp(0.87f, 0.12f); + + // If really close, snap. + if (projectile.WithinRange(Owner.Center, 180f)) + { + Main.PlaySound(SoundID.DD2_SkeletonHurt, projectile.Center); + JawSnapTimer = 45f; + } + } + } + + // Determine the head rotation. + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2; + } + + public NPC AttemptToFindTarget(float searchDistance) + { + NPC closestTarget = null; + + int heartType = ModContent.NPCType(); + if (Owner.HasMinionAttackTargetNPC) + { + NPC targetedNPC = Main.npc[Owner.MinionAttackTargetNPC]; + if (targetedNPC.WithinRange(projectile.Center, searchDistance) && targetedNPC.CanBeChasedBy() && targetedNPC.type != heartType) + return targetedNPC; + } + + float distance = searchDistance * searchDistance; + for (int i = 0; i < Main.maxNPCs; i++) + { + if (Main.npc[i].CanBeChasedBy() && Main.npc[i].type != heartType) + { + float extraDistance = (Main.npc[i].width / 2) + (Main.npc[i].height / 2); + + if (Main.npc[i].WithinRange(projectile.Center, distance + extraDistance)) + { + distance = Main.npc[i].DistanceSQ(projectile.Center); + closestTarget = Main.npc[i]; + } + } + } + + return closestTarget; + } + + #endregion + + #region Drawing + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + float angerFactor = Utils.InverseLerp(300f, 280f, PlayerAttackCountdown, true) * Utils.InverseLerp(0f, 30f, PlayerAttackCountdown, true); + float afterimageOutwardness = MathHelper.Lerp(6f, 8f, (float)Math.Cos(Main.GlobalTime * 2.3f) * 0.5f + 0.5f) * angerFactor; + Color backAfterimageColor = Color.Red * angerFactor; + backAfterimageColor.A = 0; + + Texture2D eyesTexture = ModContent.GetTexture("CalamityMod/Projectiles/Summon/SepulcherMinionEyes"); + Texture2D jawTexture = ModContent.GetTexture("CalamityMod/Projectiles/Summon/SepulcherMinionJaw"); + Texture2D headTexture = ModContent.GetTexture("CalamityMod/Projectiles/Summon/SepulcherMinionHead"); + Texture2D bodyTexture = ModContent.GetTexture("CalamityMod/Projectiles/Summon/SepulcherMinionBody"); + Texture2D bodyTexture2 = ModContent.GetTexture("CalamityMod/Projectiles/Summon/SepulcherMinionBodyAlt"); + Texture2D tailTexture = ModContent.GetTexture("CalamityMod/Projectiles/Summon/SepulcherMinionTail"); + Texture2D armTexture = ModContent.GetTexture("CalamityMod/Projectiles/Summon/SepulcherArm"); + Texture2D foreArmTexture = ModContent.GetTexture("CalamityMod/Projectiles/Summon/SepulcherForeArm"); + Texture2D handTexture = ModContent.GetTexture("CalamityMod/Projectiles/Summon/SepulcherHand"); + + Vector2 drawPosition; + + // Draw the arms. + for (int i = 0; i < Arms.Count; i++) + { + Vector2 forearmDrawPosition = Arms[i].Limbs[0].Center - Main.screenPosition; + Color drawColor = Lighting.GetColor((int)(Arms[i].Limbs[0].Center.X / 16), (int)(Arms[i].Limbs[0].Center.Y / 16)); + + if (afterimageOutwardness > 0f) + { + for (int j = 0; j < 4; j++) + { + Vector2 drawOffset = (MathHelper.TwoPi * j / 4f).ToRotationVector2() * afterimageOutwardness; + spriteBatch.Draw(foreArmTexture, forearmDrawPosition + drawOffset, null, backAfterimageColor, Arms[i].Limbs[0].Rotation + MathHelper.PiOver2, foreArmTexture.Size() * 0.5f, projectile.scale, SpriteEffects.None, 0f); + } + } + spriteBatch.Draw(foreArmTexture, forearmDrawPosition, null, drawColor, Arms[i].Limbs[0].Rotation + MathHelper.PiOver2, foreArmTexture.Size() * 0.5f, projectile.scale, SpriteEffects.None, 0f); + + Vector2 armDrawPosition = Arms[i].Limbs[1].Center - Main.screenPosition; + drawColor = Lighting.GetColor((int)(Arms[i].Limbs[1].Center.X / 16), (int)(Arms[i].Limbs[1].Center.Y / 16)); + + if (afterimageOutwardness > 0f) + { + for (int j = 0; j < 4; j++) + { + Vector2 drawOffset = (MathHelper.TwoPi * j / 4f).ToRotationVector2() * afterimageOutwardness; + spriteBatch.Draw(armTexture, armDrawPosition + drawOffset, null, backAfterimageColor, Arms[i].Limbs[1].Rotation + MathHelper.PiOver2, armTexture.Size() * new Vector2(0.5f, 0f), projectile.scale, SpriteEffects.FlipVertically, 0f); + } + } + spriteBatch.Draw(armTexture, armDrawPosition, null, drawColor, Arms[i].Limbs[1].Rotation + MathHelper.PiOver2, armTexture.Size() * new Vector2(0.5f, 0f), projectile.scale, SpriteEffects.FlipVertically, 0f); + + Vector2 handDrawPosition = armDrawPosition; + SpriteEffects handDirection = Arms[i].Direction ? SpriteEffects.None : SpriteEffects.FlipHorizontally; + + if (afterimageOutwardness > 0f) + { + for (int j = 0; j < 4; j++) + { + Vector2 drawOffset = (MathHelper.TwoPi * j / 4f).ToRotationVector2() * afterimageOutwardness; + spriteBatch.Draw(handTexture, handDrawPosition + drawOffset, null, backAfterimageColor, Arms[i].Limbs[1].Rotation - MathHelper.PiOver2, handTexture.Size() * new Vector2(0.5f, 0f), projectile.scale, handDirection, 0f); + } + } + spriteBatch.Draw(handTexture, handDrawPosition, null, drawColor, Arms[i].Limbs[1].Rotation - MathHelper.PiOver2, handTexture.Size() * new Vector2(0.5f, 0f), projectile.scale, handDirection, 0f); + } + + // Draw the segments. + for (int i = 0; i < Segments.Length; i++) + { + Texture2D textureToUse = i % 2 == 1 ? bodyTexture2 : bodyTexture; + + // Use the tail texture for the last segment. + if (i == Segments.Length - 1) + textureToUse = tailTexture; + + drawPosition = Segments[i].CurrentPosition - Main.screenPosition; + lightColor = Lighting.GetColor((int)(drawPosition.X + Main.screenPosition.X) / 16, (int)(drawPosition.Y + Main.screenPosition.Y) / 16); + + if (afterimageOutwardness > 0f) + { + for (int j = 0; j < 4; j++) + { + Vector2 drawOffset = (MathHelper.TwoPi * j / 4f).ToRotationVector2() * afterimageOutwardness; + spriteBatch.Draw(textureToUse, drawPosition + drawOffset, null, backAfterimageColor, Segments[i].Rotation, textureToUse.Size() * 0.5f, projectile.scale, SpriteEffects.None, 0f); + } + } + spriteBatch.Draw(textureToUse, drawPosition, null, projectile.GetAlpha(lightColor), Segments[i].Rotation, textureToUse.Size() * 0.5f, projectile.scale, SpriteEffects.None, 0f); + } + + drawPosition = projectile.Center - Main.screenPosition; + lightColor = Lighting.GetColor((int)(drawPosition.X + Main.screenPosition.X) / 16, (int)(drawPosition.Y + Main.screenPosition.Y) / 16); + + // Draw the jaws. + for (int i = -1; i <= 1; i += 2) + { + float jawBaseOffset = 24f; + SpriteEffects jawSpriteEffect = i == 1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None; + Vector2 jawPosition = projectile.Center - Main.screenPosition; + jawPosition += Vector2.UnitX.RotatedBy(projectile.rotation + JawRotation * i) * i * (jawBaseOffset + (float)Math.Sin(JawRotation) * 14f); + jawPosition -= Vector2.UnitY.RotatedBy(projectile.rotation) * (26f + (float)Math.Sin(JawRotation) * 8f); + spriteBatch.Draw(jawTexture, jawPosition, null, projectile.GetAlpha(lightColor), projectile.rotation + JawRotation * i, jawTexture.Size() * 0.5f, projectile.scale * 1.25f, jawSpriteEffect, 0f); + } + + // Draw the head. + if (afterimageOutwardness > 0f) + { + for (int i = 0; i < 4; i++) + { + Vector2 drawOffset = (MathHelper.TwoPi * i / 4f).ToRotationVector2() * afterimageOutwardness; + spriteBatch.Draw(headTexture, drawPosition + drawOffset, null, backAfterimageColor, projectile.rotation, headTexture.Size() * 0.5f, projectile.scale * 1.25f, SpriteEffects.None, 0f); + } + } + spriteBatch.Draw(headTexture, drawPosition, null, projectile.GetAlpha(lightColor), projectile.rotation, headTexture.Size() * 0.5f, projectile.scale * 1.25f, SpriteEffects.None, 0f); + + // Draw demonic eyes if enraged. + if (afterimageOutwardness > 0f) + { + for (int i = 0; i < (int)(projectile.oldPos.Length * angerFactor); i++) + { + drawPosition = projectile.Center - Main.screenPosition - projectile.velocity.SafeNormalize(Vector2.Zero) * 3f * i; + Color fadeColor = Color.White * (1f - i / (float)projectile.oldPos.Length); + spriteBatch.Draw(eyesTexture, drawPosition, null, projectile.GetAlpha(fadeColor), projectile.oldRot[i], eyesTexture.Size() * 0.5f, projectile.scale * 1.25f, SpriteEffects.None, 0f); + } + } + + return false; + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + // If default collision is possible return true immediately. + if (projHitbox.Intersects(targetHitbox)) + return true; + + // Check based on segments. + for (int i = 0; i < Segments.Length; i++) + { + if (Utils.CenteredRectangle(Segments[i].CurrentPosition, Vector2.One * 52f).Intersects(targetHitbox)) + return true; + } + + return false; + } + + public override void DrawBehind(int index, List drawCacheProjsBehindNPCsAndTiles, List drawCacheProjsBehindNPCs, List drawCacheProjsBehindProjectiles, List drawCacheProjsOverWiresUI) + { + drawCacheProjsBehindProjectiles.Add(index); + } + + #endregion + + #region Damage Stuff + public override void ModifyHitPlayer(Player target, ref int damage, ref bool crit) + { + damage = Main.rand.Next(80, 90); + } + + public override bool? CanHitNPC(NPC target) + { + if (target.type == ModContent.NPCType()) + return false; + return null; + } + #endregion + } +} diff --git a/Projectiles/Summon/SepulcherMinionBody.png b/Projectiles/Summon/SepulcherMinionBody.png new file mode 100644 index 0000000000..5e8b75333e Binary files /dev/null and b/Projectiles/Summon/SepulcherMinionBody.png differ diff --git a/Projectiles/Summon/SepulcherMinionBodyAlt.png b/Projectiles/Summon/SepulcherMinionBodyAlt.png new file mode 100644 index 0000000000..7bddb6f35e Binary files /dev/null and b/Projectiles/Summon/SepulcherMinionBodyAlt.png differ diff --git a/Projectiles/Summon/SepulcherMinionEyes.png b/Projectiles/Summon/SepulcherMinionEyes.png new file mode 100644 index 0000000000..29f5267031 Binary files /dev/null and b/Projectiles/Summon/SepulcherMinionEyes.png differ diff --git a/Projectiles/Summon/SepulcherMinionHead.png b/Projectiles/Summon/SepulcherMinionHead.png new file mode 100644 index 0000000000..e1fb445359 Binary files /dev/null and b/Projectiles/Summon/SepulcherMinionHead.png differ diff --git a/Projectiles/Summon/SepulcherMinionJaw.png b/Projectiles/Summon/SepulcherMinionJaw.png new file mode 100644 index 0000000000..11df3bb5ae Binary files /dev/null and b/Projectiles/Summon/SepulcherMinionJaw.png differ diff --git a/Projectiles/Summon/SepulcherMinionTail.png b/Projectiles/Summon/SepulcherMinionTail.png new file mode 100644 index 0000000000..283e094283 Binary files /dev/null and b/Projectiles/Summon/SepulcherMinionTail.png differ diff --git a/Projectiles/Summon/SlimePuppet.cs b/Projectiles/Summon/SlimePuppet.cs new file mode 100644 index 0000000000..2141fdc467 --- /dev/null +++ b/Projectiles/Summon/SlimePuppet.cs @@ -0,0 +1,118 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + public class SlimePuppet : ModProjectile + { + public Player Owner => Main.player[projectile.owner]; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Slime Puppet"); + ProjectileID.Sets.MinionSacrificable[projectile.type] = true; + ProjectileID.Sets.MinionTargettingFeature[projectile.type] = true; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 1; + ProjectileID.Sets.TrailingMode[projectile.type] = 0; + } + + public override void SetDefaults() + { + projectile.width = 60; + projectile.height = 60; + projectile.netImportant = true; + projectile.friendly = true; + projectile.minionSlots = 0; + projectile.timeLeft = 300; + projectile.penetrate = 1; + projectile.minion = true; + projectile.tileCollide = false; + } + + public override void AI() + { + ResetDamage(); + + // Prevent clumping of other slime puppets near this one. + projectile.MinionAntiClump(); + + NPC potentialTarget = projectile.Center.MinionHoming(800f, Owner); + + if (potentialTarget is null) + { + // Movement above the player, depending on the index of the projectile in the Main.projectile array. + float destinationAngularOffset = (float)Math.Sin(projectile.identity / 6f % 6f * MathHelper.Pi) * MathHelper.Pi / 10f; + Vector2 destination = Owner.Center - Vector2.UnitY.RotatedBy(destinationAngularOffset) * 160f; + + if (projectile.DistanceSQ(destination) > 18f * 18f) + projectile.velocity = (projectile.velocity * 20f + projectile.SafeDirectionTo(destination) * 9f) / 21f; + } + else + { + float nudgedVelocityDirection = projectile.velocity.ToRotation().AngleTowards(projectile.AngleTo(potentialTarget.Center), 0.078f); + projectile.velocity = nudgedVelocityDirection.ToRotationVector2() * MathHelper.Lerp(projectile.velocity.Length(), 16f, 0.25f); + if (projectile.WithinRange(potentialTarget.Center, 120f)) + projectile.Center += projectile.SafeDirectionTo(potentialTarget.Center) * 3f; + } + if (projectile.ai[0] > 0f) + { + projectile.rotation += MathHelper.ToRadians(projectile.velocity.Length() / 4f) * Math.Sign(projectile.velocity.X); + projectile.ai[0]--; + } + else if (potentialTarget != null) + projectile.rotation = projectile.velocity.ToRotation(); + + if (Vector2.Dot(projectile.oldVelocity.SafeNormalize(Vector2.Zero), projectile.velocity.SafeNormalize(Vector2.Zero)) < 0.87) + projectile.ai[0] = 50f; + } + + public void ResetDamage() + { + // Initialize minion damage values the moment the projectile is spawned. + if (projectile.localAI[0] == 0f) + { + projectile.Calamity().spawnedPlayerMinionDamageValue = Owner.MinionDamage(); + projectile.Calamity().spawnedPlayerMinionProjectileDamageValue = projectile.damage; + projectile.localAI[0] = 1f; + } + if (Owner.MinionDamage() != projectile.Calamity().spawnedPlayerMinionDamageValue) + { + int trueDamage = (int)(projectile.Calamity().spawnedPlayerMinionProjectileDamageValue / projectile.Calamity().spawnedPlayerMinionDamageValue * Owner.MinionDamage()); + projectile.damage = trueDamage; + } + } + + public override void Kill(int timeLeft) + { + CalamityGlobalProjectile.ExpandHitboxBy(projectile, 100); + projectile.maxPenetrate = -1; + projectile.penetrate = -1; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 10; + projectile.Damage(); + Main.PlaySound(SoundID.NPCDeath1, projectile.Center); + + if (!Main.dedServ) + { + for (int i = 0; i < 20; i++) + { + Vector2 spawnOffset = Main.rand.NextVector2Unit() * Main.rand.NextFloat(4f, 36f); + Dust slime = Dust.NewDustPerfect(projectile.Center + spawnOffset, 243); + slime.velocity = spawnOffset.RotatedBy(MathHelper.PiOver2 * Main.rand.NextBool(2).ToDirectionInt()) * 0.16f; + slime.scale = 1.2f; + } + } + } + + public override bool OnTileCollide(Vector2 oldVelocity) => false; + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + CalamityUtils.DrawAfterimagesCentered(projectile, ProjectileID.Sets.TrailingMode[projectile.type], lightColor); + return false; + } + } +} diff --git a/Projectiles/Summon/SlimePuppet.png b/Projectiles/Summon/SlimePuppet.png new file mode 100644 index 0000000000..25eb7cc27f Binary files /dev/null and b/Projectiles/Summon/SlimePuppet.png differ diff --git a/Projectiles/Summon/SummonBrimstoneExplosion.cs b/Projectiles/Summon/SummonBrimstoneExplosion.cs new file mode 100644 index 0000000000..0c4eb00e90 --- /dev/null +++ b/Projectiles/Summon/SummonBrimstoneExplosion.cs @@ -0,0 +1,72 @@ +using CalamityMod.Dusts; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + public class SummonBrimstoneExplosion : ModProjectile + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Explosion"); + ProjectileID.Sets.MinionShot[projectile.type] = true; + Main.projFrames[projectile.type] = 6; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 160; + projectile.friendly = true; + projectile.hostile = true; + projectile.minion = true; + projectile.penetrate = -1; + projectile.timeLeft = Main.projFrames[projectile.type] * 5; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 10; + } + + public override void AI() + { + if (projectile.localAI[0] == 0f) + { + CreateInitialDust(); + projectile.localAI[0] = 1f; + } + + // Emit crimson light. + Lighting.AddLight(projectile.Center, Color.Red.ToVector3() * 1.1f); + if (projectile.timeLeft % 5f == 4f) + projectile.frame++; + } + + public void CreateInitialDust() + { + float randomnessSmoothness = 3f; + for (int i = 0; i < 10; i++) + { + randomnessSmoothness += i; + + int offsetVariance = (int)(randomnessSmoothness * 4f); + for (int j = 0; j < 30; j++) + { + Vector2 velocity = Main.rand.NextVector2Square(-randomnessSmoothness, randomnessSmoothness).SafeNormalize(Vector2.UnitY) * randomnessSmoothness * 0.48f; + Dust dust = Dust.NewDustDirect(projectile.Center, offsetVariance, offsetVariance, (int)CalamityDusts.Brimstone, 0f, 0f, 100, default, 1.6f); + dust.position += Main.rand.NextVector2Square(-10f, 10f); + dust.velocity = velocity; + dust.noGravity = true; + } + } + + projectile.Damage(); + CalamityGlobalProjectile.ExpandHitboxBy(projectile, 48); + } + + public override void ModifyHitPlayer(Player target, ref int damage, ref bool crit) + { + // Prevent absurd quantities of damage to the player. + damage = (int)(damage * 0.018); + } + } +} diff --git a/Projectiles/Summon/SummonBrimstoneExplosion.png b/Projectiles/Summon/SummonBrimstoneExplosion.png new file mode 100644 index 0000000000..b53b2fea88 Binary files /dev/null and b/Projectiles/Summon/SummonBrimstoneExplosion.png differ diff --git a/Projectiles/Summon/SummonBrimstoneExplosionSmall.cs b/Projectiles/Summon/SummonBrimstoneExplosionSmall.cs new file mode 100644 index 0000000000..24b4b6de0e --- /dev/null +++ b/Projectiles/Summon/SummonBrimstoneExplosionSmall.cs @@ -0,0 +1,64 @@ +using CalamityMod.Dusts; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + public class SummonBrimstoneExplosionSmall : ModProjectile + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Explosion"); + ProjectileID.Sets.MinionShot[projectile.type] = true; + Main.projFrames[projectile.type] = 6; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 108; + projectile.friendly = true; + projectile.hostile = false; + projectile.minion = true; + projectile.penetrate = -1; + projectile.timeLeft = Main.projFrames[projectile.type] * 5; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 10; + } + + public override void AI() + { + if (projectile.localAI[0] == 0f) + { + CreateInitialDust(); + projectile.localAI[0] = 1f; + } + + // Emit crimson light. + Lighting.AddLight(projectile.Center, Color.Red.ToVector3() * 1.1f); + if (projectile.timeLeft % 5f == 4f) + projectile.frame++; + } + + public void CreateInitialDust() + { + float randomnessSmoothness = 3f; + for (int i = 0; i < 6; i++) + { + randomnessSmoothness += i * 0.36f; + + for (int j = 0; j < 30; j++) + { + Vector2 velocity = Main.rand.NextVector2Square(-randomnessSmoothness, randomnessSmoothness).SafeNormalize(Vector2.UnitY) * randomnessSmoothness * 0.48f; + Dust dust = Dust.NewDustDirect(projectile.position + Vector2.One * 22f, 1, 1, (int)CalamityDusts.Brimstone, 0f, 0f, 100, default, 1.6f); + dust.position += Main.rand.NextVector2Square(-10f, 10f); + dust.velocity = velocity; + dust.noGravity = true; + } + } + + projectile.Damage(); + } + } +} diff --git a/Projectiles/Summon/SummonBrimstoneExplosionSmall.png b/Projectiles/Summon/SummonBrimstoneExplosionSmall.png new file mode 100644 index 0000000000..b53b2fea88 Binary files /dev/null and b/Projectiles/Summon/SummonBrimstoneExplosionSmall.png differ diff --git a/Projectiles/Summon/UniverseSplitterField.cs b/Projectiles/Summon/UniverseSplitterField.cs new file mode 100644 index 0000000000..56fc408f48 --- /dev/null +++ b/Projectiles/Summon/UniverseSplitterField.cs @@ -0,0 +1,159 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Audio; +using System; +using System.IO; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +namespace CalamityMod.Projectiles.Summon +{ + public class UniverseSplitterField : ModProjectile + { + public float Timer + { + get => projectile.ai[0]; + set => projectile.ai[0] = value; + } + public float DustRadius = 0f; + public const float DustChargeTime = 30f; + public const float DustMinRadius = 0f; + public const float DustMaxRadius = 90f; + public const int SpiralPrecision = 25; + public const int SpiralRings = 5; + public const int TimeLeft = 720; + + public const float SmallBeamAngleMax = MathHelper.TwoPi / 15f; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Field"); + ProjectileID.Sets.MinionShot[projectile.type] = true; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 200; + projectile.alpha = 255; + projectile.friendly = true; + projectile.minion = true; + projectile.minionSlots = 0f; + projectile.ignoreWater = true; + projectile.timeLeft = TimeLeft; + } + + public override void SendExtraAI(BinaryWriter writer) + { + writer.Write(DustRadius); + } + + public override void ReceiveExtraAI(BinaryReader reader) + { + DustRadius = reader.ReadSingle(); + } + + public override void AI() + { + Timer++; + if (Timer < DustChargeTime) + { + DustRadius = MathHelper.Lerp(DustMinRadius, DustMaxRadius, Timer / DustChargeTime); + } + else + { + DustRadius = DustMaxRadius + (float)Math.Sin(Timer / 50f) * 16f; + } + if (!Main.dedServ) + { + GenerateIdleDust(); + } + SpawnLasers(); + } + + public void GenerateIdleDust() + { + // Generate a dust ring that pulsates + for (int i = 0; i < 80; i++) + { + Dust dust = Dust.NewDustPerfect(projectile.Center + (i / 80f * MathHelper.TwoPi).ToRotationVector2() * DustRadius, 247); + dust.velocity = Vector2.Zero; + dust.scale = 1.2f; + dust.noGravity = true; + } + + // Spirals that spin around + for (int i = 0; i < SpiralPrecision; i++) + { + for (int direction = -1; direction <= 1; direction += 2) + { + for (int j = 0; j < SpiralRings; j++) + { + Dust dust = Dust.NewDustPerfect(projectile.Center + + Vector2.UnitY.RotatedBy(Timer / SpiralPrecision * direction).RotatedBy(j / (float)SpiralRings * MathHelper.TwoPi).RotatedBy(i / (float)SpiralPrecision * MathHelper.TwoPi / SpiralRings * direction) * + DustRadius * i / SpiralPrecision, 261); + dust.velocity = Vector2.Zero; + dust.scale = 0.7f; + dust.noGravity = true; + } + } + } + + // Outward expansion of dust + bool firingGiantLaserBeam = Timer > TimeLeft - UniverseSplitterHugeBeam.TimeLeft; + for (int i = 0; i < (firingGiantLaserBeam ? 30 : 16); i++) + { + Dust dust = Dust.NewDustPerfect(projectile.Center, 247); + dust.velocity = Main.rand.NextVector2Circular(8f, 8f) * (firingGiantLaserBeam ? 1.6f : 1f); + dust.noGravity = true; + dust.scale = 1.25f; + } + + // Energy dust that appears before the giant beam does and remains + if (Timer > TimeLeft - UniverseSplitterHugeBeam.TimeLeft - 120f) + { + float outwardCircleRadius = MathHelper.Lerp(0f, DustRadius * 1.2f, MathHelper.Clamp((Timer - (TimeLeft - UniverseSplitterHugeBeam.TimeLeft - 120f)) / 40f, 0f, 1f)); + for (int i = 0; i < 95; i++) + { + Dust dust = Dust.NewDustPerfect(projectile.Center + (i / 95f * MathHelper.TwoPi).ToRotationVector2() * outwardCircleRadius, 247); + dust.scale = 1.2f; + dust.noGravity = true; + dust.velocity = Main.rand.NextBool(7) ? projectile.DirectionFrom(dust.position) * 6f : Vector2.Zero; + } + } + } + + public void SpawnLasers() + { + // Create small beams sometimes + if (Timer > 120f && + Timer < TimeLeft - UniverseSplitterHugeBeam.TimeLeft && + Timer % 60f == 0f) + { + Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Item, "Sounds/Item/PlasmaBolt"), projectile.Center); + if (Main.myPlayer == projectile.owner) + { + Vector2 offset = new Vector2(Main.rand.NextFloat(-800f, 800f), -1460f); + Projectile.NewProjectile(projectile.Center + offset, + -Vector2.Normalize(offset), + ModContent.ProjectileType(), + projectile.damage, + projectile.knockBack, + projectile.owner, + (-Vector2.Normalize(offset)).ToRotation()); + } + } + // Summon a giant beam + if (Timer == TimeLeft - UniverseSplitterHugeBeam.TimeLeft && Main.myPlayer == projectile.owner) + { + Main.PlaySound(SoundID.Zombie, projectile.Center, 104); + Projectile.NewProjectile(projectile.Center + Vector2.UnitY * -UniverseSplitterHugeBeam.MaximumLength / 2f, + Vector2.UnitY, + ModContent.ProjectileType(), + projectile.damage, + projectile.knockBack, + projectile.owner, + 0f); + } + } + + public override bool CanDamage() => false; + } +} diff --git a/Projectiles/Summon/UniverseSplitterField.png b/Projectiles/Summon/UniverseSplitterField.png new file mode 100644 index 0000000000..c8fba012d0 Binary files /dev/null and b/Projectiles/Summon/UniverseSplitterField.png differ diff --git a/Projectiles/Summon/UniverseSplitterHugeBeam.cs b/Projectiles/Summon/UniverseSplitterHugeBeam.cs new file mode 100644 index 0000000000..5a211b41f3 --- /dev/null +++ b/Projectiles/Summon/UniverseSplitterHugeBeam.cs @@ -0,0 +1,201 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System.IO; +using Terraria; +using Terraria.ID; +using Terraria.Enums; +using Terraria.ModLoader; +using CalamityMod.Buffs.DamageOverTime; +using Terraria.GameContent.Events; + +namespace CalamityMod.Projectiles.Summon +{ + public class UniverseSplitterHugeBeam : ModProjectile + { + // Pretty self explanatory + public const int TotalFadeoutTime = 25; + public const int TimeLeft = 180; + public const float MaximumLength = 3000f; + // How fat the laser is + public const float LaserSize = 1.45f; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Universe Splitter Ray"); + } + + public override void SetDefaults() + { + projectile.width = 14; + projectile.height = 14; + projectile.friendly = true; + projectile.magic = true; + projectile.penetrate = -1; + projectile.tileCollide = false; + projectile.timeLeft = TimeLeft; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 6; + } + + // Netcode for sending and receiving shit + // localAI[0] is the timer, localAI[1] is the laser length + + public override void SendExtraAI(BinaryWriter writer) + { + writer.Write(projectile.localAI[0]); + writer.Write(projectile.localAI[1]); + } + + public override void ReceiveExtraAI(BinaryReader reader) + { + projectile.localAI[0] = reader.ReadSingle(); + projectile.localAI[1] = reader.ReadSingle(); + } + + public override void AI() + { + projectile.velocity = (projectile.velocity.ToRotation() + projectile.ai[0]).ToRotationVector2(); + projectile.rotation = projectile.velocity.ToRotation() - MathHelper.PiOver2; + + projectile.localAI[0]++; + + // Fadein/out. The timeleft varies, so this must be done manually. + if (projectile.localAI[0] < TotalFadeoutTime) + { + projectile.scale = MathHelper.Lerp(0.01f, LaserSize, projectile.localAI[0] / TotalFadeoutTime); + } + + if (projectile.timeLeft < TotalFadeoutTime) + { + projectile.scale = MathHelper.Lerp(LaserSize, 0f, 1f - (projectile.timeLeft / (float)TotalFadeoutTime)); + } + + Vector2 samplingPoint = projectile.Center; + + float[] samples = new float[3]; + + float determinedLength = 0f; + Collision.LaserScan(samplingPoint, projectile.velocity, projectile.width * projectile.scale, MaximumLength + 72f, samples); + for (int i = 0; i < samples.Length; i++) + { + determinedLength += samples[i]; + } + determinedLength /= samples.Length; + + determinedLength = MathHelper.Clamp(determinedLength, MaximumLength * 0.3f, MaximumLength); + + float lerpDelta = 0.5f; + projectile.localAI[1] = MathHelper.Lerp(projectile.localAI[1], determinedLength, lerpDelta); + if (projectile.localAI[0] < 30f) + { + projectile.localAI[1] = MathHelper.Lerp(72f, projectile.localAI[1], projectile.localAI[0] / 30f); + } + Vector2 beamEndPosition = projectile.Center + projectile.velocity * (projectile.localAI[1] - 6f); + if (projectile.localAI[0] >= 30f && + projectile.localAI[0] <= 35f) + { + if (projectile.localAI[0] == 30f) + Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Item, "Sounds/Item/TeslaCannonFire"), projectile.Center); + for (int i = 0; i < 75; i++) + { + Dust dust = Dust.NewDustPerfect(beamEndPosition, 269); + dust.velocity = Main.rand.NextVector2Circular(16f, 11f); + dust.velocity = dust.velocity.SafeNormalize(Vector2.UnitY) * new Vector2(5f, 3.5f); + dust.scale = Main.rand.NextFloat(1.2f, 1.5f); + dust.noGravity = true; + + dust = Dust.NewDustPerfect(beamEndPosition, 269); + dust.velocity = (i / 75f * MathHelper.TwoPi).ToRotationVector2().RotatedByRandom(0.2f) * new Vector2(16f, 11f) * 1.3f; + dust.scale = Main.rand.NextFloat(1.4f, 1.75f); + dust.noGravity = true; + } + } + + if (projectile.localAI[0] > TimeLeft - 50f) + { + float light = 1f; + if (projectile.localAI[0] < TimeLeft - 30f) + { + light = MathHelper.Lerp(0f, 1f, (projectile.localAI[0] - (TimeLeft - 30f)) / 30f); + } + MoonlordDeathDrama.RequestLight(light, beamEndPosition); + } + + // Draw acid green light across the laser + DelegateMethods.v3_1 = new Vector3(0.62f, 0.94f, 0.38f); + Utils.PlotTileLine(projectile.Center, projectile.Center + projectile.velocity * projectile.localAI[1], projectile.width * projectile.scale, new Utils.PerLinePoint(DelegateMethods.CastLight)); + } + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + if (projectile.velocity == Vector2.Zero) + { + return false; + } + Texture2D laserTailTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/Lasers/UniverseSplitterHugeBeamEnd"); + Texture2D laserBodyTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/Lasers/UniverseSplitterHugeBeamMid"); + float laserLength = projectile.localAI[1]; + Color drawColor = new Color(1f, 1f, 1f) * 0.9f; + + // Laser body logic + + laserLength -= laserTailTexture.Height / 2 * projectile.scale; + Vector2 centerDelta = projectile.Center - 76f * projectile.velocity * projectile.scale; + centerDelta += projectile.velocity * projectile.scale * laserTailTexture.Height / 2f; + if (laserLength > 0f) + { + float laserLengthDelta = 0f; + Rectangle sourceRectangle = new Rectangle(0, 76 * (projectile.timeLeft / 3 % 5), laserBodyTexture.Width, 76); + while (laserLengthDelta + 1f < laserLength) + { + if (laserLength - laserLengthDelta < sourceRectangle.Height) + { + sourceRectangle.Height = (int)(laserLength - laserLengthDelta); + } + Main.spriteBatch.Draw(laserBodyTexture, centerDelta - Main.screenPosition, new Rectangle?(sourceRectangle), drawColor, projectile.rotation, new Vector2(sourceRectangle.Width / 2f, 0f), projectile.scale, SpriteEffects.None, 0f); + laserLengthDelta += sourceRectangle.Height * projectile.scale; + centerDelta += projectile.velocity * sourceRectangle.Height * projectile.scale; + sourceRectangle.Y += (int)(76 * projectile.scale); + if (sourceRectangle.Y + sourceRectangle.Height > laserBodyTexture.Height) + { + sourceRectangle.Y = 0; + } + } + } + + // Laser tail logic + centerDelta += projectile.velocity * projectile.scale * 38f; + Rectangle tailFrameRectangle = new Rectangle(0, 76 * (projectile.timeLeft / 3 % 5), laserTailTexture.Width, 76); + Main.spriteBatch.Draw(laserTailTexture, centerDelta - Main.screenPosition, tailFrameRectangle, drawColor, projectile.rotation, new Vector2(148f, 76f) / 2f, projectile.scale, SpriteEffects.None, 0f); + + return false; + } + + public override bool ShouldUpdatePosition() => false; + + public override void CutTiles() + { + DelegateMethods.tilecut_0 = TileCuttingContext.AttackProjectile; + Vector2 unit = projectile.velocity; + Utils.PlotTileLine(projectile.Center, projectile.Center + unit * projectile.localAI[1], (float)projectile.width * projectile.scale, new Utils.PerLinePoint(DelegateMethods.CutTiles)); + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + if (projHitbox.Intersects(targetHitbox)) + { + return true; + } + float value = 0f; + if (Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), projectile.Center, projectile.Center + projectile.velocity * (projectile.localAI[1] + 76f), 22f * projectile.scale, ref value)) + { + return true; + } + return false; + } + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + target.AddBuff(BuffID.Electrified, 300); + target.AddBuff(ModContent.BuffType(), 45 * 60); + } + } +} diff --git a/Projectiles/Summon/UniverseSplitterHugeBeam.png b/Projectiles/Summon/UniverseSplitterHugeBeam.png new file mode 100644 index 0000000000..58ba72804a Binary files /dev/null and b/Projectiles/Summon/UniverseSplitterHugeBeam.png differ diff --git a/Projectiles/Summon/UniverseSplitterSmallBeam.cs b/Projectiles/Summon/UniverseSplitterSmallBeam.cs new file mode 100644 index 0000000000..02d9aad775 --- /dev/null +++ b/Projectiles/Summon/UniverseSplitterSmallBeam.cs @@ -0,0 +1,185 @@ +using CalamityMod.Dusts; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.IO; +using Terraria; +using Terraria.ID; +using Terraria.Enums; +using Terraria.ModLoader; +namespace CalamityMod.Projectiles.Summon +{ + public class UniverseSplitterSmallBeam : ModProjectile + { + // Pretty self explanatory + public const int FadeinTime = 25; + public const int MovementTime = 60; + public const int TimeLeft = 120; + public const float TotalSweeps = 4f; + public const float MaximumLength = 3000f; + // How fat the laser is + public const float LaserSize = 1.2f; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Universe Splitter Ray"); + } + + public override void SetDefaults() + { + projectile.width = 14; + projectile.height = 14; + projectile.friendly = true; + projectile.magic = true; + projectile.penetrate = -1; + projectile.tileCollide = false; + projectile.timeLeft = TimeLeft; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 6; + } + + // Netcode for sending and receiving shit + // localAI[0] is the timer, localAI[1] is the laser length + + public override void SendExtraAI(BinaryWriter writer) + { + writer.Write(projectile.localAI[0]); + writer.Write(projectile.localAI[1]); + } + + public override void ReceiveExtraAI(BinaryReader reader) + { + projectile.localAI[0] = reader.ReadSingle(); + projectile.localAI[1] = reader.ReadSingle(); + } + + public static float CosineInterpolation(float start, float end, float time) + { + float cosineTime = (1f - (float)Math.Cos(MathHelper.Pi * time)) * 0.5f; + return start * (1 - cosineTime) + end * cosineTime; + } + + public override bool ShouldUpdatePosition() => false; + + public override void AI() + { + if (projectile.localAI[0] <= MovementTime) + { + projectile.velocity = (projectile.ai[0] + (float)Math.Cos(projectile.localAI[0] / MovementTime * TotalSweeps) * + CosineInterpolation(1f, 0f, projectile.localAI[0] / MovementTime) * UniverseSplitterField.SmallBeamAngleMax).ToRotationVector2(); + } + projectile.rotation = projectile.velocity.ToRotation() - MathHelper.PiOver2; + + projectile.localAI[0] += 1f; + + // Fadein/out. The timeleft varies, so this must be done manually. + if (projectile.localAI[0] < FadeinTime) + { + projectile.scale = MathHelper.Lerp(0.01f, LaserSize, projectile.localAI[0] / FadeinTime); + } + if (projectile.localAI[0] > MovementTime && + projectile.localAI[0] <= MovementTime + 10f) + { + projectile.scale = MathHelper.Lerp(LaserSize, 3.25f, (projectile.localAI[0] - MovementTime) / 10f); + } + if (projectile.localAI[0] > TimeLeft - 15f) + { + projectile.scale = MathHelper.Lerp(3.25f, 0.01f, (projectile.localAI[0] - (TimeLeft - 15f)) / 15f); + } + + Vector2 samplingPoint = projectile.Center; + + float[] samples = new float[3]; + + float determinedLength = 0f; + Collision.LaserScan(samplingPoint, projectile.velocity, projectile.width * projectile.scale, MaximumLength, samples); + for (int i = 0; i < samples.Length; i++) + { + determinedLength += samples[i]; + } + determinedLength /= samples.Length; + + determinedLength = MathHelper.Clamp(determinedLength, MaximumLength * 0.5f, MaximumLength); + + float lerpDelta = 0.5f; + projectile.localAI[1] = MathHelper.Lerp(projectile.localAI[1], determinedLength, lerpDelta); + Vector2 beamEndPosiiton = projectile.Center + projectile.velocity * (projectile.localAI[1] - 6f); + + // Draw white light across the laser + DelegateMethods.v3_1 = Color.White.ToVector3(); + Utils.PlotTileLine(projectile.Center, projectile.Center + projectile.velocity * projectile.localAI[1], projectile.width * projectile.scale, new Utils.PerLinePoint(DelegateMethods.CastLight)); + } + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + if (projectile.velocity == Vector2.Zero) + { + return false; + } + Texture2D laserTailTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/Lasers/UniverseSplitterSmallBeamBegin"); + Texture2D laserBodyTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/Lasers/UniverseSplitterSmallBeamMid"); + Texture2D laserHeadTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/Lasers/UniverseSplitterSmallBeamEnd"); + float laserLength = projectile.localAI[1]; + Color drawColor = new Color(1f, 1f, 1f) * 0.9f; + + // Laser tail logic + + Main.spriteBatch.Draw(laserTailTexture, projectile.Center - Main.screenPosition, null, drawColor, projectile.rotation, laserTailTexture.Size() / 2f, projectile.scale, SpriteEffects.None, 0f); + + // Laser body logic + + laserLength -= (laserTailTexture.Height / 2 + laserHeadTexture.Height) * projectile.scale; + Vector2 centerDelta = projectile.Center; + centerDelta += projectile.velocity * projectile.scale * (float)laserTailTexture.Height / 2f; + if (laserLength > 0f) + { + float laserLengthDelta = 0f; + Rectangle sourceRectangle = new Rectangle(0, 14 * (projectile.timeLeft / 3 % 5), laserBodyTexture.Width, 16); + while (laserLengthDelta + 1f < laserLength) + { + if (laserLength - laserLengthDelta < sourceRectangle.Height) + { + sourceRectangle.Height = (int)(laserLength - laserLengthDelta); + } + Main.spriteBatch.Draw(laserBodyTexture, centerDelta - Main.screenPosition, new Rectangle?(sourceRectangle), drawColor, projectile.rotation, new Vector2(sourceRectangle.Width / 2f, 0f), projectile.scale, SpriteEffects.None, 0f); + laserLengthDelta += sourceRectangle.Height * projectile.scale; + centerDelta += projectile.velocity * sourceRectangle.Height * projectile.scale; + sourceRectangle.Y += 14; + if (sourceRectangle.Y + sourceRectangle.Height > laserBodyTexture.Height) + { + sourceRectangle.Y = 0; + } + } + } + + // Laser head logic + + Main.spriteBatch.Draw(laserHeadTexture, centerDelta - Main.screenPosition, null, drawColor, projectile.rotation, laserHeadTexture.Frame(1, 1, 0, 0).Top(), projectile.scale, SpriteEffects.None, 0f); + return false; + } + + public override void CutTiles() + { + DelegateMethods.tilecut_0 = TileCuttingContext.AttackProjectile; + Vector2 unit = projectile.velocity; + Utils.PlotTileLine(projectile.Center, projectile.Center + unit * projectile.localAI[1], (float)projectile.width * projectile.scale, new Utils.PerLinePoint(DelegateMethods.CutTiles)); + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + if (projHitbox.Intersects(targetHitbox)) + { + return true; + } + float value = 0f; + if (Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), projectile.Center, projectile.Center + projectile.velocity * projectile.localAI[1], 22f * projectile.scale, ref value)) + { + return true; + } + return false; + } + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + target.AddBuff(BuffID.Electrified, 300); + } + } +} diff --git a/Projectiles/Summon/UniverseSplitterSmallBeam.png b/Projectiles/Summon/UniverseSplitterSmallBeam.png new file mode 100644 index 0000000000..50902dedaf Binary files /dev/null and b/Projectiles/Summon/UniverseSplitterSmallBeam.png differ diff --git a/Projectiles/Summon/ViridVanguardBlade.cs b/Projectiles/Summon/ViridVanguardBlade.cs new file mode 100644 index 0000000000..df19971af4 --- /dev/null +++ b/Projectiles/Summon/ViridVanguardBlade.cs @@ -0,0 +1,198 @@ +using CalamityMod.Buffs.Summon; +using CalamityMod.CalPlayer; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.IO; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + public class ViridVanguardBlade : ModProjectile + { + public bool AltTexture = false; + + public int RemainingSlices = 0; + public int PostSliceDeathTimer; + public float RedirectAngle; + public float FiringTime = 0f; + public Vector2 IdealPosition; + public float Angle + { + get => projectile.ai[0]; + set => projectile.ai[0] = value; + } + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Vanguard Blade"); + ProjectileID.Sets.TrailingMode[projectile.type] = 0; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 7; + } + + public override void SetDefaults() + { + projectile.width = 60; + projectile.height = 156; + projectile.netImportant = true; + projectile.friendly = true; + projectile.ignoreWater = true; + projectile.minionSlots = 1.5f; + projectile.timeLeft = 18000; + projectile.penetrate = -1; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 14; + projectile.tileCollide = false; + projectile.timeLeft *= 5; + projectile.minion = true; + } + public override void SendExtraAI(BinaryWriter writer) + { + writer.Write(RedirectAngle); + writer.Write(FiringTime); + writer.Write(AltTexture); + } + public override void ReceiveExtraAI(BinaryReader reader) + { + RedirectAngle = reader.ReadSingle(); + FiringTime = reader.ReadSingle(); + AltTexture = reader.ReadBoolean(); + } + public override void AI() + { + Player player = Main.player[projectile.owner]; + CalamityPlayer modPlayer = player.Calamity(); + projectile.spriteDirection = AltTexture.ToDirectionInt(); + if (projectile.localAI[0] == 0f) + { + projectile.Calamity().spawnedPlayerMinionDamageValue = player.MinionDamage(); + projectile.Calamity().spawnedPlayerMinionProjectileDamageValue = projectile.damage; + projectile.localAI[0] = 1f; + } + if (player.MinionDamage() != projectile.Calamity().spawnedPlayerMinionDamageValue) + { + int trueDamage = (int)(projectile.Calamity().spawnedPlayerMinionProjectileDamageValue / + projectile.Calamity().spawnedPlayerMinionDamageValue * + player.MinionDamage()); + projectile.damage = trueDamage; + } + bool isProperProjectile = projectile.type == ModContent.ProjectileType(); + player.AddBuff(ModContent.BuffType(), 3600); + if (isProperProjectile) + { + if (player.dead) + { + modPlayer.viridVanguard = false; + } + if (modPlayer.viridVanguard) + { + projectile.timeLeft = 2; + } + } + + if (FiringTime <= 0f) + { + projectile.ai[1]++; + float outwardPosition = 320f; + outwardPosition += (float)Math.Sin(Angle) * 200f; + projectile.Center = player.Center + Angle.ToRotationVector2().RotatedBy((float)Math.Cos(Angle) * MathHelper.PiOver4 + AltTexture.ToInt() * MathHelper.Pi) * outwardPosition; + projectile.rotation = player.AngleTo(projectile.Center) + MathHelper.PiOver4; + Angle += MathHelper.ToRadians(4f); + } + else + { + projectile.spriteDirection = 1; + if (FiringTime >= 239f) + { + RemainingSlices = projectile.penetrate = 3; + IdealPosition = player.Center - Vector2.UnitY.RotatedBy(RedirectAngle) * 550f; + } + else if (FiringTime > 120f) + { + projectile.Center = Vector2.Lerp(projectile.Center, IdealPosition, 1f / 40f); + projectile.rotation = projectile.rotation.AngleLerp(RedirectAngle + MathHelper.ToRadians(82f), 1f / 60f); + } + else if (FiringTime > 80f) + { + projectile.Center = IdealPosition; + projectile.rotation = projectile.rotation.AngleLerp(projectile.AngleTo(Main.MouseWorld) + MathHelper.ToRadians(82f), 1f / 20f); + } + else if (FiringTime == 80f) + { + PostSliceDeathTimer = 80; + projectile.velocity = projectile.SafeDirectionTo(Main.MouseWorld) * 30f; + } + else if (FiringTime == 1f) + { + if (RemainingSlices <= 0) + { + projectile.Kill(); + } + else if (RemainingSlices <= 2) + { + projectile.velocity *= -1; + FiringTime = 20f; + } + } + FiringTime--; + } + + if (RemainingSlices > 0) + PostSliceDeathTimer--; + if (PostSliceDeathTimer == 1) + projectile.Kill(); + + if (projectile.localAI[1] > 0) + { + projectile.alpha = (int)MathHelper.Lerp(255, 0, 1f - projectile.localAI[1] / 80f); + projectile.localAI[1]--; + } + } + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + if (RemainingSlices > 0) + { + FiringTime = 10f; + RemainingSlices--; + } + } + public override void Kill(int timeLeft) + { + for (int j = 0; j < 40; j++) + { + Dust dust = Dust.NewDustDirect(projectile.position, projectile.width, projectile.height, 66); + dust.velocity = Vector2.UnitY * Main.rand.NextFloat(3f, 5.5f) * Main.rand.NextBool(2).ToDirectionInt(); + dust.noGravity = true; + } + } + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D texture = ModContent.GetTexture("CalamityMod/Projectiles/Summon/ViridVanguardBlade" + (AltTexture ? "" : "Alt")); + + Rectangle rectangle = new Rectangle(0, 0, texture.Width, texture.Height); + + SpriteEffects spriteEffects = SpriteEffects.None; + if (projectile.spriteDirection == -1) + spriteEffects = SpriteEffects.FlipHorizontally; + + if (CalamityConfig.Instance.Afterimages && FiringTime > 0f && FiringTime < 80f) + { + for (int i = 0; i < projectile.oldPos.Length; i++) + { + Vector2 drawPos = projectile.oldPos[i] + projectile.Size / 2f - Main.screenPosition + new Vector2(0f, projectile.gfxOffY); + Color color = Color.Lerp(Color.White, Color.DarkOliveGreen, i / (float)projectile.oldPos.Length) * + ((projectile.oldPos.Length - i) / (float)projectile.oldPos.Length); + float scale = MathHelper.Lerp(projectile.scale * 1f, projectile.scale * 0.5f, i / (float)projectile.oldPos.Length); + Main.spriteBatch.Draw(texture, drawPos, new Rectangle?(rectangle), color, + projectile.rotation, + rectangle.Size() / 2f, scale, spriteEffects, 0f); + } + } + Main.spriteBatch.Draw(texture, projectile.Center - Main.screenPosition + new Vector2(0f, projectile.gfxOffY), new Rectangle?(rectangle), Color.White, + projectile.rotation, + rectangle.Size() / 2f, 1f, spriteEffects, 0f); + return false; + } + } +} diff --git a/Projectiles/Summon/ViridVanguardBlade.png b/Projectiles/Summon/ViridVanguardBlade.png new file mode 100644 index 0000000000..400382aa1c Binary files /dev/null and b/Projectiles/Summon/ViridVanguardBlade.png differ diff --git a/Projectiles/Summon/ViridVanguardBladeAlt.png b/Projectiles/Summon/ViridVanguardBladeAlt.png new file mode 100644 index 0000000000..127ec26b1c Binary files /dev/null and b/Projectiles/Summon/ViridVanguardBladeAlt.png differ diff --git a/Projectiles/Summon/WitherBlossom.cs b/Projectiles/Summon/WitherBlossom.cs new file mode 100644 index 0000000000..94bf3ee576 --- /dev/null +++ b/Projectiles/Summon/WitherBlossom.cs @@ -0,0 +1,87 @@ +using CalamityMod.Buffs.Summon; +using CalamityMod.CalPlayer; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +namespace CalamityMod.Projectiles.Summon +{ + public class WitherBlossom : ModProjectile + { + public Player Owner => Main.player[projectile.owner]; + public ref float OffsetAngle => ref projectile.ai[0]; + public ref float Time => ref projectile.ai[1]; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Wither Blossom"); + ProjectileID.Sets.MinionSacrificable[projectile.type] = true; + ProjectileID.Sets.MinionTargettingFeature[projectile.type] = true; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 30; + projectile.netImportant = true; + projectile.friendly = true; + projectile.ignoreWater = true; + projectile.minionSlots = 0.5f; + projectile.timeLeft = 90000; + projectile.penetrate = -1; + projectile.tileCollide = false; + projectile.minion = true; + } + + public override void AI() + { + bool isCorrectMinion = projectile.type == ModContent.ProjectileType(); + Player player = Main.player[projectile.owner]; + CalamityPlayer modPlayer = player.Calamity(); + player.AddBuff(ModContent.BuffType(), 3600); + if (isCorrectMinion) + { + if (player.dead) + modPlayer.witherBlossom = false; + if (modPlayer.witherBlossom) + projectile.timeLeft = 2; + } + + SetProjectileDamage(); + + Time++; + NPC potentialTarget = projectile.Center.MinionHoming(950f, Owner); + if (Time % 50 == 49 && Main.myPlayer == projectile.owner && potentialTarget != null) + { + Vector2 shootVelocity = projectile.SafeDirectionTo(potentialTarget.Center).RotatedByRandom(0.25f) * 8f; + Projectile.NewProjectile(projectile.Center, shootVelocity, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner); + } + projectile.Center = player.Center + OffsetAngle.ToRotationVector2() * 150f; + projectile.rotation += MathHelper.ToRadians(5f); + OffsetAngle += MathHelper.ToRadians(4f); + } + + public void SetProjectileDamage() + { + if (projectile.localAI[0] == 0f) + { + projectile.Calamity().spawnedPlayerMinionDamageValue = Owner.MinionDamage(); + projectile.Calamity().spawnedPlayerMinionProjectileDamageValue = projectile.damage; + for (int i = 0; i < 36; i++) + { + Dust dust = Dust.NewDustPerfect(projectile.Center, 179); + dust.noGravity = true; + dust.velocity = Main.rand.NextVector2Unit() * Main.rand.NextFloat(2f, 7f); + } + projectile.localAI[0] += 1f; + } + if (Owner.MinionDamage() != projectile.Calamity().spawnedPlayerMinionDamageValue) + { + int trueDamage = (int)(projectile.Calamity().spawnedPlayerMinionProjectileDamageValue / + projectile.Calamity().spawnedPlayerMinionDamageValue * + Owner.MinionDamage()); + projectile.damage = trueDamage; + } + } + + public override bool CanDamage() => false; + } +} diff --git a/Projectiles/Summon/WitherBlossom.png b/Projectiles/Summon/WitherBlossom.png new file mode 100644 index 0000000000..a0ba831dd4 Binary files /dev/null and b/Projectiles/Summon/WitherBlossom.png differ diff --git a/Projectiles/Summon/WitherBolt.cs b/Projectiles/Summon/WitherBolt.cs new file mode 100644 index 0000000000..fed98e329a --- /dev/null +++ b/Projectiles/Summon/WitherBolt.cs @@ -0,0 +1,97 @@ +using CalamityMod.Buffs.DamageOverTime; +using CalamityMod.Dusts; +using CalamityMod.Projectiles.Melee; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +namespace CalamityMod.Projectiles.Summon +{ + public class WitherBolt : ModProjectile + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Wither Bolt"); + ProjectileID.Sets.TrailingMode[projectile.type] = 2; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 25; + ProjectileID.Sets.MinionShot[projectile.type] = true; + } + + public override void SetDefaults() + { + projectile.scale = 0.8f; + projectile.width = projectile.height = (int)(72 * projectile.scale); + projectile.friendly = true; + projectile.minion = true; + projectile.minionSlots = 0f; + projectile.timeLeft = 180; + projectile.tileCollide = false; + projectile.ignoreWater = true; + projectile.penetrate = 2; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 10; + } + public override void AI() + { + Lighting.AddLight(projectile.Center, Color.DarkGreen.ToVector3() * 1.25f); + float oldSpeed = projectile.velocity.Length(); + + NPC potentialTarget = projectile.Center.MinionHoming(800f, Main.player[projectile.owner]); + if (potentialTarget != null) + projectile.velocity = (projectile.velocity * 3f + projectile.SafeDirectionTo(potentialTarget.Center) * oldSpeed) / 4f; + projectile.velocity = projectile.velocity.SafeNormalize(Vector2.UnitY) * oldSpeed * 1.01f; + + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2; + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + target.AddBuff(ModContent.BuffType(), 180); + projectile.Opacity = MathHelper.Lerp(projectile.Opacity, 0f, 0.25f); + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D boltTexture = Main.projectileTexture[projectile.type]; + for (int i = 0; i < projectile.oldPos.Length; i++) + { + float completionRatio = i / (float)projectile.oldPos.Length; + Color drawColor = Color.Lerp(lightColor, Color.Olive, 0.6f); + drawColor = Color.Lerp(drawColor, Color.Black, completionRatio); + drawColor = Color.Lerp(drawColor, Color.Transparent, completionRatio); + + Vector2 drawPosition = projectile.oldPos[i] + projectile.Size * 0.5f - Main.screenPosition; + spriteBatch.Draw(boltTexture, drawPosition, null, projectile.GetAlpha(drawColor), projectile.oldRot[i], boltTexture.Size() * 0.5f, projectile.scale, SpriteEffects.None, 0f); + } + return false; + } + + public override void Kill(int timeLeft) + { + if (!Main.dedServ) + { + for (int i = 0; i < projectile.oldPos.Length / 2; i++) + { + for (int j = 0; j < 2; j++) + { + Dust plague = Dust.NewDustDirect(projectile.oldPos[i], projectile.width / 2, projectile.height / 2, 107); + plague.velocity = (projectile.oldRot[i] - MathHelper.PiOver2).ToRotationVector2() * 4.5f + Main.rand.NextVector2Circular(2f, 2f); + plague.color = Color.Olive; + plague.noGravity = true; + } + } + } + + if (Main.myPlayer == projectile.owner) + { + for (int i = 0; i < 2; i++) + { + Vector2 spawnPosition = projectile.Center + Main.rand.NextVector2CircularEdge(8f, 8f); + int seeker = Projectile.NewProjectile(spawnPosition, Main.rand.NextVector2Circular(12f, 12f), ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner); + Main.projectile[seeker].Calamity().forceMinion = true; + } + } + } + } +} diff --git a/Projectiles/Summon/WitherBolt.png b/Projectiles/Summon/WitherBolt.png new file mode 100644 index 0000000000..0968156e79 Binary files /dev/null and b/Projectiles/Summon/WitherBolt.png differ diff --git a/Projectiles/Typeless/CirrusBolt.cs b/Projectiles/Typeless/CirrusBolt.cs deleted file mode 100644 index a5480db6c2..0000000000 --- a/Projectiles/Typeless/CirrusBolt.cs +++ /dev/null @@ -1,41 +0,0 @@ -using Microsoft.Xna.Framework; -using Terraria; -using Terraria.ModLoader; -namespace CalamityMod.Projectiles.Typeless -{ - public class CirrusBolt : ModProjectile - { - public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; - - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Bolt"); - } - - public override void SetDefaults() - { - projectile.width = 4; - projectile.height = 4; - projectile.extraUpdates = 100; - projectile.friendly = true; - projectile.timeLeft = 45; - projectile.magic = true; - projectile.npcProj = true; - } - - public override void AI() - { - if (projectile.timeLeft % 2f == 0f) - { - Vector2 vector33 = projectile.position; - vector33 -= projectile.velocity * 0.25f; - int num448 = Dust.NewDust(vector33, 1, 1, 234, 0f, 0f, 0, default, 1.25f); - Main.dust[num448].position = vector33; - Main.dust[num448].noGravity = true; - Main.dust[num448].noLight = true; - Main.dust[num448].scale = Main.rand.Next(70, 110) * 0.013f; - Main.dust[num448].velocity *= 0.1f; - } - } - } -} diff --git a/Projectiles/Typeless/CirrusOrb.cs b/Projectiles/Typeless/CirrusOrb.cs deleted file mode 100644 index 13bcddbfdc..0000000000 --- a/Projectiles/Typeless/CirrusOrb.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Terraria.ModLoader; -namespace CalamityMod.Projectiles.Typeless -{ - public class CirrusOrb : ModProjectile - { - public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; - - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Orb"); - } - - public override void SetDefaults() - { - projectile.width = 14; - projectile.height = 14; - projectile.friendly = true; - projectile.alpha = 255; - projectile.penetrate = -1; - projectile.timeLeft = 30; - projectile.magic = true; - projectile.usesLocalNPCImmunity = true; - projectile.localNPCHitCooldown = 10; - projectile.npcProj = true; - } - - public override void AI() - { - CalamityGlobalProjectile.MagnetSphereHitscan(projectile, 150f, 6f, 6f, 2, ModContent.ProjectileType()); - } - } -} diff --git a/Projectiles/Typeless/CirrusRay.cs b/Projectiles/Typeless/CirrusRay.cs deleted file mode 100644 index 9ade156435..0000000000 --- a/Projectiles/Typeless/CirrusRay.cs +++ /dev/null @@ -1,71 +0,0 @@ -using Microsoft.Xna.Framework; -using Terraria; -using Terraria.ModLoader; -namespace CalamityMod.Projectiles.Typeless -{ - public class CirrusRay : ModProjectile - { - public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; - - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Ray"); - } - - public override void SetDefaults() - { - projectile.width = 4; - projectile.height = 4; - projectile.friendly = true; - projectile.magic = true; - projectile.penetrate = 5; - projectile.extraUpdates = 100; - projectile.timeLeft = 300; - projectile.usesLocalNPCImmunity = true; - projectile.localNPCHitCooldown = 10; - projectile.npcProj = true; - } - - public override void AI() - { - Lighting.AddLight(projectile.Center, 0.2f, 0.01f, 0.1f); - projectile.ai[0] += 1f; - if (projectile.ai[0] % 6f == 0f && projectile.owner == Main.myPlayer) - { - Projectile.NewProjectile(projectile.Center, Vector2.Zero, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); - } - - if (projectile.ai[0] > 16f && projectile.ai[0] % 2f == 0f) - { - Vector2 source = projectile.position; - int pink = Dust.NewDust(source, 1, 1, 234, 0f, 0f, 0, default, 1.25f); - Main.dust[pink].noGravity = true; - Main.dust[pink].noLight = true; - Main.dust[pink].position = source; - Main.dust[pink].scale = Main.rand.Next(70, 110) * 0.013f; - Main.dust[pink].velocity *= 0.1f; - } - } - - public override bool OnTileCollide(Vector2 oldVelocity) - { - projectile.penetrate--; - if (projectile.penetrate <= 0) - { - projectile.Kill(); - } - else - { - if (projectile.velocity.X != oldVelocity.X) - { - projectile.velocity.X = -oldVelocity.X; - } - if (projectile.velocity.Y != oldVelocity.Y) - { - projectile.velocity.Y = -oldVelocity.Y; - } - } - return false; - } - } -} diff --git a/Projectiles/Typeless/SuicideBomberDemon.cs b/Projectiles/Typeless/SuicideBomberDemon.cs new file mode 100644 index 0000000000..a712fd1b16 --- /dev/null +++ b/Projectiles/Typeless/SuicideBomberDemon.cs @@ -0,0 +1,117 @@ +using Microsoft.Xna.Framework; +using System.IO; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Typeless +{ + public class SuicideBomberDemon : ModProjectile + { + public Player Owner => Main.player[projectile.owner]; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Demon"); + Main.projFrames[projectile.type] = 5; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 32; + projectile.tileCollide = false; + projectile.ignoreWater = true; + projectile.penetrate = -1; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 5; + projectile.Opacity = 0f; + projectile.timeLeft = 300; + } + + public override void SendExtraAI(BinaryWriter writer) + { + writer.Write(projectile.friendly); + writer.Write(projectile.hostile); + } + + public override void ReceiveExtraAI(BinaryReader reader) + { + projectile.friendly = reader.ReadBoolean(); + projectile.hostile = reader.ReadBoolean(); + } + + public override void AI() + { + if (projectile.owner == 255) + projectile.owner = Player.FindClosest(projectile.Center, 1, 1); + projectile.Opacity = MathHelper.Clamp(projectile.Opacity + 0.025f, 0f, 1f); + + projectile.frame = projectile.frameCounter++ / 5 % Main.projFrames[projectile.type]; + + // Anti-clumping behavior. + float pushForce = 0.08f; + for (int k = 0; k < Main.maxProjectiles; k++) + { + Projectile otherProj = Main.projectile[k]; + // Short circuits to make the loop as fast as possible + if (!otherProj.active || otherProj.type != projectile.type || k == projectile.whoAmI) + continue; + + // If the other projectile is indeed the same owned by the same player and they're too close, nudge them away. + bool sameProjType = otherProj.type == projectile.type; + float taxicabDist = MathHelper.Distance(projectile.position.X, otherProj.position.X) + MathHelper.Distance(projectile.position.Y, otherProj.position.Y); + if (sameProjType && taxicabDist < 60f) + { + if (projectile.position.X < otherProj.position.X) + projectile.velocity.X -= pushForce; + else + projectile.velocity.X += pushForce; + + if (projectile.position.Y < otherProj.position.Y) + projectile.velocity.Y -= pushForce; + else + projectile.velocity.Y += pushForce; + } + } + + if (projectile.hostile) + { + projectile.velocity = projectile.velocity.MoveTowards(projectile.SafeDirectionTo(Owner.Center) * 16f, 1.4f); + projectile.spriteDirection = (Owner.Center.X > projectile.Center.X).ToDirectionInt(); + if (projectile.Hitbox.Intersects(Owner.Hitbox)) + projectile.Kill(); + } + else if (projectile.friendly) + { + NPC potentialTarget = projectile.Center.ClosestNPCAt(1360f); + if (potentialTarget is null) + projectile.velocity = Vector2.Lerp(projectile.velocity, -Vector2.UnitY * 10f, 0.06f); + else + { + projectile.spriteDirection = (potentialTarget.Center.X > projectile.Center.X).ToDirectionInt(); + projectile.velocity = projectile.velocity.MoveTowards(projectile.SafeDirectionTo(potentialTarget.Center) * 18.5f, 3f); + if (projectile.Hitbox.Intersects(potentialTarget.Hitbox)) + { + projectile.Damage(); + projectile.Kill(); + } + } + } + } + + public override void Kill(int timeLeft) + { + for (int i = 0; i < 40; i++) + { + Dust explosion = Dust.NewDustDirect(projectile.position, projectile.width, projectile.height, 267); + explosion.velocity = Main.rand.NextVector2Circular(4f, 4f); + explosion.color = Color.Red; + explosion.scale = 1.35f; + explosion.fadeIn = 0.45f; + explosion.noGravity = true; + } + } + + public override bool CanDamage() => projectile.Opacity >= 1f; + + public override void ModifyHitPlayer(Player target, ref int damage, ref bool crit) => damage = Main.rand.Next(60, 70); + } +} diff --git a/Projectiles/Typeless/SuicideBomberDemon.png b/Projectiles/Typeless/SuicideBomberDemon.png new file mode 100644 index 0000000000..bd3a5924ca Binary files /dev/null and b/Projectiles/Typeless/SuicideBomberDemon.png differ diff --git a/TrailGeneration/PrimitiveTrail.cs b/TrailGeneration/PrimitiveTrail.cs index 789f726bf6..44754a9700 100644 --- a/TrailGeneration/PrimitiveTrail.cs +++ b/TrailGeneration/PrimitiveTrail.cs @@ -42,6 +42,9 @@ namespace CalamityMod public MiscShaderData SpecialShader; public TrailPointRetrievalFunction TrailPointFunction; + public Vector2 OverridingStickPointStart = Vector2.Zero; + public Vector2 OverridingStickPointEnd = Vector2.Zero; + public delegate List TrailPointRetrievalFunction(IEnumerable originalPositions, Vector2 generalOffset, int totalTrailPoints, IEnumerable originalRotations = null); public PrimitiveTrail(VertexWidthFunction widthFunction, VertexColorFunction colorFunction, TrailPointRetrievalFunction pointFunction = null, MiscShaderData specialShader = null) @@ -93,7 +96,7 @@ namespace CalamityMod BaseEffect.Projection = effectProjection; } - public static List RigidPointRetreivalFunction(IEnumerable originalPositions, Vector2 generalOffset, int totalTrailPoints, IEnumerable originalRotations = null) + public static List RigidPointRetreivalFunction(IEnumerable originalPositions, Vector2 generalOffset, int totalTrailPoints, IEnumerable _ = null) { List basePoints = originalPositions.Where(originalPosition => originalPosition != Vector2.Zero).ToList(); List endPoints = new List(); @@ -191,11 +194,19 @@ namespace CalamityMod // This doesn't use RotatedBy for the sake of performance (there can potentially be a lot of trail points). Vector2 sideDirection = new Vector2(-directionToAhead.Y, directionToAhead.X); + Vector2 left = currentPosition - sideDirection * widthAtVertex; + Vector2 right = currentPosition + sideDirection * widthAtVertex; + if (i == 0 && OverridingStickPointStart != Vector2.Zero) + { + left = OverridingStickPointStart; + right = OverridingStickPointEnd; + } + // What this is doing, at its core, is defining a rectangle based on two triangles. // These triangles are defined based on the width of the strip at that point. // The resulting rectangles combined are what make the trail itself. - vertices[i * 2] = new VertexPosition2DColor(currentPosition - sideDirection * widthAtVertex, vertexColor, leftCurrentTextureCoord); - vertices[i * 2 + 1] = new VertexPosition2DColor(currentPosition + sideDirection * widthAtVertex, vertexColor, rightCurrentTextureCoord); + vertices[i * 2] = new VertexPosition2DColor(left, vertexColor, leftCurrentTextureCoord); + vertices[i * 2 + 1] = new VertexPosition2DColor(right, vertexColor, rightCurrentTextureCoord); } return vertices.ToArray(); diff --git a/UI/CalamitasEnchantments/CalamitasEnchantUI.cs b/UI/CalamitasEnchantments/CalamitasEnchantUI.cs new file mode 100644 index 0000000000..39ade9da0c --- /dev/null +++ b/UI/CalamitasEnchantments/CalamitasEnchantUI.cs @@ -0,0 +1,406 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System.Collections.Generic; +using System.Linq; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.UI; +using Terraria.UI.Chat; + +namespace CalamityMod.UI.CalamitasEnchants +{ + public class CalamitasEnchantUI + { + public static int NPCIndex = -1; + public static int EnchantIndex = 0; + public static Enchantment? SelectedEnchantment = null; + public static Item CurrentlyHeldItem = new Item(); + public static float TopButtonClickCountdown = 0f; + public static float BottomButtonClickCountdown = 0f; + public static float ReforgeButtonClickCountdown = 0f; + + public static bool CurrentlyViewing = false; + + public static readonly Vector2 ReforgeUITopLeft = new Vector2(68f, 320f); + public static readonly float ResolutionRatio = Main.screenHeight / 1440f; + + public static Rectangle MouseScreenArea => Utils.CenteredRectangle(Main.MouseScreen, Vector2.One * 2f); + + public static bool InRangeOfNPC() + { + // Don't bother trying if no valid NPC has been selected yet. + if (!Main.npc.IndexInRange(NPCIndex) || !Main.npc[NPCIndex].active) + return false; + + Rectangle validTalkArea = Utils.CenteredRectangle(Main.LocalPlayer.Center, new Vector2(Player.tileRangeX * 2f, Player.tileRangeY) * 16f); + return validTalkArea.Intersects(Main.npc[NPCIndex].Hitbox); + } + + public static void Draw(SpriteBatch spriteBatch) + { + // Decrement click cooldowns. + // This is done so that click textures do not instantly disappear. + if (TopButtonClickCountdown > 0f) + TopButtonClickCountdown--; + if (BottomButtonClickCountdown > 0f) + BottomButtonClickCountdown--; + if (ReforgeButtonClickCountdown > 0f) + ReforgeButtonClickCountdown--; + + // Don't bother doing anything except resetting if not looking at the UI. + if (!CurrentlyViewing) + { + // If an item was stored, release it back into the world. + if (!CurrentlyHeldItem.IsAir) + { + Main.LocalPlayer.QuickSpawnClonedItem(CurrentlyHeldItem, CurrentlyHeldItem.stack); + CurrentlyHeldItem.TurnToAir(); + } + + EnchantIndex = 0; + NPCIndex = -1; + return; + } + + // Check if the player can still be in the UI. + if (Main.LocalPlayer.chest != -1 || Main.LocalPlayer.sign != -1 || Main.LocalPlayer.talkNPC == -1 || !Main.playerInventory || !InRangeOfNPC() || Main.InGuideCraftMenu) + { + CurrentlyViewing = false; + + // Check if the player has any items being held. + // If they do, drop it onto the ground. + Main.LocalPlayer.dropItemCheck(); + + // Reload visible recipes in case the dropped item was an ingredient. + Recipe.FindRecipes(); + return; + } + + // Open the inventory and stop talking to any NPCs by default while the UI is open, similar to the goblin tinkerer. + Main.playerInventory = true; + Main.npcChatText = string.Empty; + + Texture2D backgroundTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/UI/CalamitasCurseBackground"); + Vector2 backgroundScale = Vector2.One * Main.UIScale; + + // Draw the background. + spriteBatch.Draw(backgroundTexture, ReforgeUITopLeft, null, Color.White, 0f, Vector2.Zero, backgroundScale, SpriteEffects.None, 0f); + + // Prevent the player from say, firing a weapon while the mouse is hovering over the UI. + DisableMouseWhenOverUI(backgroundTexture, backgroundScale); + + // Select the enchantment to use. + IEnumerable possibleEnchantments = SelectEnchantment(); + + // Draw the cost and description. + int cost = 0; + if (SelectedEnchantment.HasValue) + { + Point costDrawPositionTopLeft = (ReforgeUITopLeft + new Vector2(50f, 78f) * backgroundScale).ToPoint(); + cost = DrawEnchantmentCost(spriteBatch, costDrawPositionTopLeft); + Point descriptionDrawPositionTopLeft = costDrawPositionTopLeft; + descriptionDrawPositionTopLeft.Y += (int)(Main.UIScale * 70f); + Vector2 iconDrawPositionTopLeft = costDrawPositionTopLeft.ToVector2() + new Vector2(270f, -24f) * Main.UIScale; + + DrawEnchantmentDescription(spriteBatch, descriptionDrawPositionTopLeft); + if (!string.IsNullOrEmpty(SelectedEnchantment.Value.IconTexturePath)) + { + Texture2D iconTexture = ModContent.GetTexture(SelectedEnchantment.Value.IconTexturePath); + DrawIcon(spriteBatch, iconDrawPositionTopLeft, iconTexture); + } + } + + // Draw the item icon. + Vector2 itemSlotDrawPosition = ReforgeUITopLeft + new Vector2(30f, 50f) * backgroundScale; + Vector2 reforgeIconDrawPosition = ReforgeUITopLeft + new Vector2(84f, 60f) * backgroundScale; + DrawItemIcon(spriteBatch, itemSlotDrawPosition, reforgeIconDrawPosition, backgroundScale, out bool isHoveringOverItemIcon, out bool isHoveringOverReforgeIcon); + if (isHoveringOverItemIcon) + InteractWithItemSlot(); + + // Draw the buttons. + DrawAndInteractWithButtons(spriteBatch, possibleEnchantments, ReforgeUITopLeft + new Vector2(210f, 50f) * backgroundScale, ReforgeUITopLeft + new Vector2(210f, 90f) * backgroundScale, backgroundScale); + + // Draw the enchantment name. + if (SelectedEnchantment.HasValue) + DrawEnchantmentName(spriteBatch, ReforgeUITopLeft + new Vector2(216f, 66f) * backgroundScale); + + // Handle spending logic. + if (isHoveringOverReforgeIcon) + { + if (Main.mouseLeft && Main.mouseLeftRelease) + { + InteractWithEnchantIcon(cost); + ReforgeButtonClickCountdown = 15f; + } + } + } + + public static void DisableMouseWhenOverUI(Texture2D backgroundTexture, Vector2 backgroundScale) + { + Rectangle backgroundArea = new Rectangle((int)ReforgeUITopLeft.X, (int)ReforgeUITopLeft.Y, (int)(backgroundTexture.Width * backgroundScale.X), (int)(backgroundTexture.Width * backgroundScale.Y)); + + if (MouseScreenArea.Intersects(backgroundArea)) + { + Main.LocalPlayer.mouseInterface = false; + Main.blockMouse = true; + } + } + + public static IEnumerable SelectEnchantment() + { + IEnumerable possibleEnchantments = EnchantmentManager.GetValidEnchantmentsForItem(CurrentlyHeldItem); + + // Select the enchantment based on an index in the possible enchantments. + // If no possible enchantments were found, default to null. + SelectedEnchantment = null; + + if (possibleEnchantments.Count() > 0) + SelectedEnchantment = possibleEnchantments.ElementAt(EnchantIndex); + + return possibleEnchantments; + } + + public static int DrawEnchantmentCost(SpriteBatch spriteBatch, Point costDrawPositionTopLeft) + { + if (CurrentlyHeldItem.IsAir) + return 0; + + int cost = CurrentlyHeldItem.value * 4; + + // Increase the cost of enchanting significantly if doing so would upgrade the item directly. + if (SelectedEnchantment.HasValue && SelectedEnchantment.Value.Name == EnchantmentManager.UpgradeEnchantName) + cost = (int)MathHelper.Min(cost, Item.buyPrice(5)) * 5; + + // Draw the coin costs. + string costText = "Cost: "; + Utils.DrawBorderStringFourWay(spriteBatch, Main.fontMouseText, costText, costDrawPositionTopLeft.X, costDrawPositionTopLeft.Y + 45f * Main.UIScale, Color.White * (Main.mouseTextColor / 255f), Color.Black, Vector2.Zero, Main.UIScale); + costDrawPositionTopLeft.X += (int)((Main.fontMouseText.MeasureString(costText).X * 0.5f + 12f) * Main.UIScale); + + int[] coinsArray = Utils.CoinsSplit(cost); + for (int i = 0; i < 4; i++) + { + Vector2 drawPosition = new Vector2(costDrawPositionTopLeft.X + (ChatManager.GetStringSize(Main.fontMouseText, costText, Vector2.One, -1f).X + ((24 * i) - 24f)) * Main.UIScale, costDrawPositionTopLeft.Y + 54f * Main.UIScale); + spriteBatch.Draw(Main.itemTexture[ItemID.PlatinumCoin - i], drawPosition, null, Color.White, 0f, Main.itemTexture[ItemID.PlatinumCoin - i].Size() * 0.5f, Main.UIScale, SpriteEffects.None, 0f); + Utils.DrawBorderStringFourWay(spriteBatch, Main.fontItemStack, coinsArray[3 - i].ToString(), drawPosition.X - 11f, drawPosition.Y, Color.White, Color.Black, new Vector2(0.3f), 0.75f * Main.UIScale); + } + + return cost; + } + + public static void DrawEnchantmentDescription(SpriteBatch spriteBatch, Point descriptionDrawPositionTopLeft) + { + Vector2 vectorDrawPosition = descriptionDrawPositionTopLeft.ToVector2(); + Vector2 scale = new Vector2(0.67f, 0.7f) * MathHelper.Clamp(ResolutionRatio, 0.825f, 1f) * Main.UIScale; + foreach (string line in Utils.WordwrapString(SelectedEnchantment.Value.Description, Main.fontMouseText, 465, 10, out _)) + { + if (string.IsNullOrEmpty(line)) + continue; + + ChatManager.DrawColorCodedStringWithShadow(spriteBatch, Main.fontMouseText, line, vectorDrawPosition, Color.Orange, 0f, Vector2.Zero, scale); + vectorDrawPosition.Y += Main.UIScale * 16f; + } + } + + public static void DrawIcon(SpriteBatch spriteBatch, Vector2 drawPositionTopLeft, Texture2D texture) + { + spriteBatch.Draw(texture, drawPositionTopLeft, null, Color.White, 0f, Vector2.Zero, Main.UIScale, SpriteEffects.None, 0f); + } + + public static void DrawItemIcon(SpriteBatch spriteBatch, Vector2 itemSlotDrawPosition, Vector2 reforgeIconDrawPosition, Vector2 scale, out bool isHoveringOverItemIcon, out bool isHoveringOverReforgeIcon) + { + isHoveringOverReforgeIcon = false; + Texture2D itemSlotTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/UI/CalamitasCurseItemSlot"); + + Texture2D reforgeIconTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/UI/CalamitasCurseUI_Button"); + Rectangle reforgeIconArea = new Rectangle((int)reforgeIconDrawPosition.X, (int)reforgeIconDrawPosition.Y, (int)(reforgeIconTexture.Width * scale.X), (int)(reforgeIconTexture.Height * scale.Y)); + + // Have the reforge icon light up if the mouse is hovering over it. + if (MouseScreenArea.Intersects(reforgeIconArea)) + { + reforgeIconTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/UI/CalamitasCurseUI_ButtonHovered"); + isHoveringOverReforgeIcon = true; + } + + if (ReforgeButtonClickCountdown > 0f) + reforgeIconTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/UI/CalamitasCurseUI_ButtonClicked"); + + // This will be used for item deposit/withdrawal logic. + isHoveringOverItemIcon = MouseScreenArea.Intersects(new Rectangle((int)itemSlotDrawPosition.X, (int)itemSlotDrawPosition.Y, (int)(itemSlotTexture.Width * scale.X), (int)(itemSlotTexture.Height * scale.Y))); + + spriteBatch.Draw(itemSlotTexture, itemSlotDrawPosition, null, Color.White, 0f, Vector2.Zero, scale, SpriteEffects.None, 0f); + + // Draw the draw the item within the slot, if it exists. + if (!CurrentlyHeldItem.IsAir) + AttemptToDrawItemInIcon(spriteBatch, itemSlotDrawPosition); + + spriteBatch.Draw(reforgeIconTexture, reforgeIconDrawPosition, null, Color.White, 0f, Vector2.Zero, scale, SpriteEffects.None, 0f); + } + + public static void AttemptToDrawItemInIcon(SpriteBatch spriteBatch, Vector2 drawPosition) + { + float inventoryScale = Main.inventoryScale; + Texture2D itemTexture = Main.itemTexture[CurrentlyHeldItem.type]; + Rectangle itemFrame = itemTexture.Frame(1, 1, 0, 0); + bool hasMultipleFrames = Main.itemAnimations[CurrentlyHeldItem.type] != null; + if (hasMultipleFrames) + itemFrame = Main.itemAnimations[CurrentlyHeldItem.type].GetFrame(itemTexture); + + float baseScale = Main.UIScale; + Color _ = Color.White; + ItemSlot.GetItemLight(ref _, ref baseScale, CurrentlyHeldItem, false); + + float itemScale = 1f; + + // Ensure that the item being drawn does not exceed a certain size. + // If it does, constrict its scale to prevent it from going beyond the maximum. + if (itemFrame.Width > 36 || itemFrame.Height > 36) + itemScale = 36f / MathHelper.Max(itemFrame.Width, itemFrame.Height); + + itemScale *= inventoryScale * baseScale; + drawPosition += Vector2.One * 23f * baseScale; + + // Draw the item. + if (hasMultipleFrames || ItemLoader.PreDrawInInventory(CurrentlyHeldItem, spriteBatch, drawPosition, itemFrame, CurrentlyHeldItem.GetAlpha(Color.White), CurrentlyHeldItem.GetColor(Color.White), itemTexture.Size() * 0.5f, itemScale)) + { + spriteBatch.Draw(itemTexture, drawPosition, itemFrame, CurrentlyHeldItem.GetAlpha(Color.White), 0f, itemFrame.Size() * 0.5f, itemScale, SpriteEffects.None, 0f); + spriteBatch.Draw(itemTexture, drawPosition, itemFrame, CurrentlyHeldItem.GetColor(Color.White), 0f, itemFrame.Size() * 0.5f, itemScale, SpriteEffects.None, 0f); + } + } + + public static void InteractWithItemSlot() + { + if (!CurrentlyHeldItem.IsAir) + { + // Display item stats. + Main.HoverItem = CurrentlyHeldItem.Clone(); + + // Force the HoverItem to be displayed. + Main.instance.MouseTextHackZoom(string.Empty); + } + + // Attempt to exchange if the slot is clicked. + if (Main.mouseLeftRelease && Main.mouseLeft && (Main.mouseItem.CanBeEnchantedBySomething() || Main.mouseItem.IsAir)) + { + EnchantIndex = 0; + Utils.Swap(ref Main.mouseItem, ref CurrentlyHeldItem); + Main.PlaySound(SoundID.Grab); + } + } + + public static void DrawAndInteractWithButtons(SpriteBatch spriteBatch, IEnumerable possibleEnchantments, Vector2 topButtonTopLeft, Vector2 bottomButtonTopLeft, Vector2 scale) + { + // Leave the arrows blank if no possible enchants exist. + if (possibleEnchantments.Count() == 0) + return; + + // Decide textures. + Texture2D topArrowTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/UI/CalamitasCurseUI_ArrowUp"); + Texture2D bottomArrowTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/UI/CalamitasCurseUI_ArrowDown"); + if (TopButtonClickCountdown > 0f) + topArrowTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/UI/CalamitasCurseUI_ArrowUpClicked"); + if (BottomButtonClickCountdown > 0f) + bottomArrowTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/UI/CalamitasCurseUI_ArrowDownClicked"); + + Rectangle topButtonArea = new Rectangle((int)topButtonTopLeft.X, (int)topButtonTopLeft.Y, (int)(topArrowTexture.Width * scale.X), (int)(topArrowTexture.Height * scale.Y)); + Rectangle bottomButtonArea = new Rectangle((int)bottomButtonTopLeft.X, (int)bottomButtonTopLeft.Y, (int)(bottomArrowTexture.Width * scale.X), (int)(bottomArrowTexture.Height * scale.Y)); + bool hoveringOverTopArrow = MouseScreenArea.Intersects(topButtonArea); + bool hoveringOverBottomArrow = MouseScreenArea.Intersects(bottomButtonArea); + if (hoveringOverTopArrow) + topArrowTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/UI/CalamitasCurseUI_ArrowUpHovered"); + + if (hoveringOverBottomArrow) + bottomArrowTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/UI/CalamitasCurseUI_ArrowDownHovered"); + + // Draw the arrows. + if (EnchantIndex > 0) + spriteBatch.Draw(topArrowTexture, topButtonTopLeft, null, Color.White, 0f, Vector2.Zero, scale, SpriteEffects.None, 0f); + if (EnchantIndex < possibleEnchantments.Count() - 1) + spriteBatch.Draw(bottomArrowTexture, bottomButtonTopLeft, null, Color.White, 0f, Vector2.Zero, scale, SpriteEffects.None, 0f); + + if (Main.mouseLeft && Main.mouseLeftRelease) + { + // Decement the enchantment index if the top button is pressed. + if (hoveringOverTopArrow && EnchantIndex > 0) + { + EnchantIndex--; + TopButtonClickCountdown = 15f; + Main.PlaySound(SoundID.MenuTick); + } + + // Increment the enchantment index if the bottom button is pressed. + if (hoveringOverBottomArrow && EnchantIndex < possibleEnchantments.Count() - 1) + { + EnchantIndex++; + BottomButtonClickCountdown = 15f; + Main.PlaySound(SoundID.MenuTick); + } + } + } + + public static void DrawEnchantmentName(SpriteBatch spriteBatch, Vector2 nameDrawCenter) + { + Vector2 scale = new Vector2(0.8f, 0.745f) * Main.UIScale; + float textWidth = Main.fontMouseText.MeasureString(SelectedEnchantment.Value.Name).X * scale.X; + Color drawColor = SelectedEnchantment.Value.Equals(EnchantmentManager.ClearEnchantment) ? Color.White : Color.Orange; + nameDrawCenter.X -= textWidth * 0.5f; + ChatManager.DrawColorCodedStringWithShadow(spriteBatch, Main.fontMouseText, SelectedEnchantment.Value.Name, nameDrawCenter, drawColor, 0f, Vector2.Zero, scale); + } + + public static void InteractWithEnchantIcon(int cost) + { + // If there's no valid item in the slot, do nothing. + if (CurrentlyHeldItem.IsAir) + return; + + // If no enchantment has been selected, do nothing. + if (!SelectedEnchantment.HasValue) + return; + + // If there is no cost or the player cannot afford it, do nothing. + if (cost <= 0 || !Main.LocalPlayer.CanBuyItem(cost)) + return; + + Item originalItem = CurrentlyHeldItem.Clone(); + byte oldPrefix = CurrentlyHeldItem.prefix; + CurrentlyHeldItem.SetDefaults(CurrentlyHeldItem.type); + CurrentlyHeldItem.Prefix(oldPrefix); + CurrentlyHeldItem = CurrentlyHeldItem.CloneWithModdedDataFrom(originalItem); + + if (SelectedEnchantment.Value.Name == EnchantmentManager.UpgradeEnchantName) + { + CurrentlyHeldItem.SetDefaults(EnchantmentManager.ItemUpgradeRelationship[CurrentlyHeldItem.type]); + CurrentlyHeldItem.Prefix(oldPrefix); + } + else + { + CurrentlyHeldItem.Calamity().AppliedEnchantment = SelectedEnchantment.Value; + SelectedEnchantment.Value.CreationEffect?.Invoke(CurrentlyHeldItem); + } + + // Update the compare item. This is used check comparisons when showing reforge tooltip bonuses. + // Updating it with the same bonuses as what was applied to the real item will negate the incorrect numbers, + // such as absurd damage boosts. + if (Main.cpItem is null) + Main.cpItem = new Item(); + Main.cpItem.SetDefaults(Main.cpItem.type); + + if (SelectedEnchantment.Value.Name != EnchantmentManager.UpgradeEnchantName) + { + Main.cpItem.Calamity().AppliedEnchantment = SelectedEnchantment.Value; + SelectedEnchantment.Value.CreationEffect?.Invoke(Main.cpItem); + } + + // Take away the money for the cost. + Main.LocalPlayer.BuyItem(cost); + + // Reset the enchantment index to prevent index problems on a different item. + EnchantIndex = 0; + + Main.PlaySound(SoundID.DD2_BetsyFlameBreath, Main.LocalPlayer.Center); + + if (SelectedEnchantment.Value.Name == EnchantmentManager.UpgradeEnchantName) + Main.PlaySound(SoundID.DD2_DarkMageHealImpact, Main.LocalPlayer.Center); + } + } +} diff --git a/UI/CalamitasEnchantments/Enchantment.cs b/UI/CalamitasEnchantments/Enchantment.cs new file mode 100644 index 0000000000..e24f411e0e --- /dev/null +++ b/UI/CalamitasEnchantments/Enchantment.cs @@ -0,0 +1,64 @@ +using System; +using Terraria; + +namespace CalamityMod.UI.CalamitasEnchants +{ + public struct Enchantment + { + public string Name; + public string Description; + public string IconTexturePath; + public Action CreationEffect; + public Action HoldEffect; + + public int ID { get; internal set; } + + // This is internal because CanBeAppliedTo should be used over this field directly. + // Using that has the benefit of null checks and is objectively superior to using the raw delegate. + internal Predicate ApplyRequirement; + public Enchantment(string name, string description, int id, string iconTexturePath, Action creationEffect, Action holdEffect, Predicate requirement) + { + Name = name; + Description = description; + CreationEffect = creationEffect; + HoldEffect = holdEffect; + ApplyRequirement = requirement; + ID = id; + IconTexturePath = iconTexturePath; + } + public Enchantment(string name, string description, int id, string iconTexturePath, Action holdEffect, Predicate requirement) + { + Name = name; + Description = description; + CreationEffect = null; + HoldEffect = holdEffect; + ApplyRequirement = requirement; + ID = id; + IconTexturePath = iconTexturePath; + } + public Enchantment(string name, string description, int id, string iconTexturePath, Action creationEffect, Predicate requirement) + { + Name = name; + Description = description; + CreationEffect = creationEffect; + HoldEffect = null; + ApplyRequirement = requirement; + ID = id; + IconTexturePath = iconTexturePath; + } + + public bool CanBeAppliedTo(Item item) + { + // "Empty" items can never be enchanted. + if (item is null || item.IsAir) + return false; + + // If there is no requirement, always return true, bar the above requirement. + if (ApplyRequirement is null) + return true; + + // Otherwise return what the defined requirement says is needed. + return ApplyRequirement(item); + } + } +} diff --git a/UI/CalamitasEnchantments/EnchantmentManager.cs b/UI/CalamitasEnchantments/EnchantmentManager.cs new file mode 100644 index 0000000000..e30094da53 --- /dev/null +++ b/UI/CalamitasEnchantments/EnchantmentManager.cs @@ -0,0 +1,316 @@ +using CalamityMod.Items.Accessories; +using CalamityMod.Items.Weapons.Summon; +using CalamityMod.NPCs.Other; +using CalamityMod.Projectiles.Melee; +using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.UI.CalamitasEnchants +{ + public static class EnchantmentManager + { + internal const int ClearEnchantmentID = -18591774; + internal const string UpgradeEnchantName = "Exhume"; + public static List EnchantmentList { get; internal set; } = new List(); + public static Dictionary ItemUpgradeRelationship { get; internal set; } = new Dictionary(); + public static Enchantment ClearEnchantment { get; internal set; } + public static IEnumerable GetValidEnchantmentsForItem(Item item) + { + // Do nothing if the item cannot be enchanted. + if (item is null || item.IsAir || !item.CanBeEnchantedBySomething()) + yield break; + + // Don't allow any enchantments if the item is an upgrade item. + if (ItemUpgradeRelationship.ContainsValue(item.type)) + yield break; + + // Only give the option to clear if the item already has an enchantment. + if (item.Calamity().AppliedEnchantment.HasValue) + { + yield return ClearEnchantment; + yield break; + } + + // Check based on all the requirements for all enchantments. + foreach (Enchantment enchantment in EnchantmentList) + { + // Don't incorporate an enchantment in the list if the item already has it. + if (item.Calamity().AppliedEnchantment.HasValue && item.Calamity().AppliedEnchantment.Value.Equals(enchantment)) + continue; + + if (enchantment.ApplyRequirement(item)) + yield return enchantment; + } + } + + public static Enchantment? FindByID(int id) + { + Enchantment? enchantment = EnchantmentList.FirstOrDefault(enchant => enchant.ID == id); + if (enchantment.HasValue && !enchantment.Value.Equals(default(Enchantment))) + return enchantment; + return null; + } + + public static void ConstructFromModcall(IEnumerable parameters) + { + int secondaryArgumentCount = parameters.Count(); + if (secondaryArgumentCount < 5) + throw new ArgumentNullException("ERROR: A minimum of 4 arguments must be supplied to this command; a name, a description, an id, and a requirement predicate."); + if (secondaryArgumentCount > 7) + throw new ArgumentNullException("ERROR: A maximum of 6 arguments can be supplied to this command."); + + string name = string.Empty; + string description = string.Empty; + int id = -1; + string iconTexturePath = null; + Predicate requirement = null; + Action creationEffect = null; + Action holdEffect = null; + + // First element - the name. + if (parameters.ElementAt(0) is string nameElement) + name = nameElement; + else + throw new ArgumentException("The first argument to this command must be a string."); + + // Second element - the description. + if (parameters.ElementAt(1) is string descriptionElement) + description = descriptionElement; + else + throw new ArgumentException("The second argument to this command must be a string."); + + // Third element - the ID. + if (parameters.ElementAt(2) is int idElement) + id = idElement; + else + throw new ArgumentException("The third argument to this command must be an int."); + + // Fourth element - the requirement predicate. This determines if an item can be enchanted by said enchant or not. + if (parameters.ElementAt(3) is Predicate requirementElement) + requirement = requirementElement; + else + throw new ArgumentException("The fourth argument to this command must be an Item Predicate."); + + // Fifth element - the texture path. This determines what icon is drawn on the UI when selected. It may be null to specify that none should be drawn. + if (parameters.ElementAt(4) is string iconTexturePathElement) + iconTexturePath = iconTexturePathElement; + else + throw new ArgumentException("The fifth argument to this command must be a string."); + + // Optional elements - creation and hold effects. + switch (secondaryArgumentCount) + { + case 6: + object sixthElement = parameters.ElementAt(4); + if (sixthElement is Action creationElement) + creationEffect = creationElement; + else if (sixthElement is Action holdElement) + holdEffect = holdElement; + else + throw new ArgumentException("The sixth argument to this command must be an Item or Player Action."); + break; + case 7: + sixthElement = parameters.ElementAt(4); + object seventhElement = parameters.ElementAt(5); + if (sixthElement is Action creationElement2) + { + creationEffect = creationElement2; + holdEffect = seventhElement as Action; + } + else if (sixthElement is Action holdElement2) + { + creationEffect = seventhElement as Action; + holdEffect = holdElement2; + } + else + throw new ArgumentException("The sixth argument to this command must be an Item or Player Action and the sixth must be the other action type."); + break; + } + + // Ensure the enchantment's ID is not already claimed. + if (EnchantmentList.Any(enchant => enchant.ID == id) || id == ClearEnchantmentID) + throw new ArgumentException("An enchantment with this ID already exists. Another one must be specified."); + + EnchantmentList.Add(new Enchantment(name, description, id, iconTexturePathElement, creationEffect, holdEffect, requirement)); + } + + internal static void LoadAllEnchantments() + { + EnchantmentList = new List + { + new Enchantment(UpgradeEnchantName, "Transforms this item into something significantly stronger.", + 1, + "CalamityMod/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Exhumed", + null, + null, + item => ItemUpgradeRelationship.ContainsKey(item.type)), + + new Enchantment("Indignant", "Summons demons that harm you but drop healing items on death on item usage.", + 100, + "CalamityMod/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Indignant", + null, + player => player.Calamity().cursedSummonsEnchant = true, + item => item.damage > 0 && item.maxStack == 1 && item.summon), + + new Enchantment("Aflame", "Lights enemies ablaze on hit but also causes the user to take damage over time when holding this item.", + 200, + "CalamityMod/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Aflame", + null, + player => player.Calamity().flamingItemEnchant = true, + item => item.damage > 0 && item.maxStack == 1 && !item.summon), + + new Enchantment("Oblatory", "Reduces mana cost and greatly increases damage but sometimes causes this item to use your life.", + 300, + "CalamityMod/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Oblatory", + item => + { + item.damage = (int)(item.damage * 1.5); + item.mana = (int)Math.Ceiling(item.mana * 0.6); + }, + player => player.Calamity().lifeManaEnchant = true, + item => item.damage > 0 && item.maxStack == 1 && item.magic && item.mana > 0), + + new Enchantment("Resentful", "Makes the damage of projectiles vary based on how far the hit target is from you. The farther, the more damage, and vice versa.", + 400, + "CalamityMod/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Resentful", + null, + player => player.Calamity().farProximityRewardEnchant = true, + item => item.damage > 0 && item.maxStack == 1 && item.shoot > ProjectileID.None), + + new Enchantment("Bloodthirsty", "Makes the damage of projectiles vary based on how far the hit target is from you. The closer, the more damage, and vice versa.", + 500, + "CalamityMod/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Bloodthirsty", + null, + player => player.Calamity().closeProximityRewardEnchant = true, + item => item.damage > 0 && item.maxStack == 1 && item.shoot > ProjectileID.None), + + new Enchantment("Ephemeral", "Causes the damage output of this item to discharge from exhaustive use. Its damage returns naturally when not being used.", + 600, + "CalamityMod/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Ephemeral", + null, + player => player.Calamity().dischargingItemEnchant = true, + item => item.damage > 0 && item.maxStack == 1 && !item.summon), + + new Enchantment("Hellbound", "Causes minions to be created with a 40 second timer. Once it runs out, they explode violently. Minions do more damage the longer they live and idly explode as well.", + 700, + "CalamityMod/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Hellbound", + null, + player => player.Calamity().explosiveMinionsEnchant = true, + item => item.damage > 0 && item.maxStack == 1 && item.summon), + + new Enchantment("Tainted", "Removes projectile shooting capabilities of this item. In exchange, two skeletal arms are released on use that slice at the mouse position.", + 800, + "CalamityMod/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Tainted", + item => item.useTime = item.useAnimation = 25, + player => + { + if (Main.gameMenu) + return; + + player.Calamity().bladeArmEnchant = true; + bool armsArePresent = false; + int armType = ModContent.ProjectileType(); + for (int i = 0; i < Main.maxProjectiles; i++) + { + if (Main.projectile[i].type != armType || Main.projectile[i].owner != player.whoAmI || !Main.projectile[i].active) + continue; + + armsArePresent = true; + break; + } + + if (Main.myPlayer == player.whoAmI && !armsArePresent) + { + // Yes, this is a LOT of damage but given the limited range of this thing it needs to be extremely powerful when it does actually hit. + int damage = (int)(player.ActiveItem().damage * player.MeleeDamage() * 5); + int blade = Projectile.NewProjectile(player.Center, Vector2.Zero, ModContent.ProjectileType(), damage, 0f, player.whoAmI, 0f, player.ActiveItem().type); + if (Main.projectile.IndexInRange(blade)) + Main.projectile[blade].localAI[0] = 0f; + + blade = Projectile.NewProjectile(player.Center, Vector2.Zero, ModContent.ProjectileType(), damage, 0f, player.whoAmI, 1f, player.ActiveItem().type); + if (Main.projectile.IndexInRange(blade)) + Main.projectile[blade].localAI[0] = -80f; + } + }, + item => item.damage > 0 && item.maxStack == 1 && item.melee && !item.noUseGraphic && item.shoot > ProjectileID.None), + + new Enchantment("Traitorous", "Causes this item to sometimes release a monster that hurts both you and enemies when you have less than 50% mana.", + 900, + "CalamityMod/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Traitorous", + null, + player => player.Calamity().manaMonsterEnchant = true, + item => item.damage > 0 && item.maxStack == 1 && item.magic && item.mana > 0), + + new Enchantment("Withering", "You heal when hurt based on damage dealt. After being hurt, the weapon rapidly drains your life to deal massive damage.", + 1000, + "CalamityMod/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Withered", + null, + player => player.Calamity().witheringWeaponEnchant = true, + item => item.damage > 0 && item.maxStack == 1 && !item.summon), + + new Enchantment("Persecuted", "When attacked, or over time, demon portals appear near you. If sufficiently damaged they are friendly; otherwise they attack you.", + 1100, + "CalamityMod/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Persecuted", + null, + player => player.Calamity().persecutedEnchant = true, + item => item.damage > 0 && item.maxStack == 1 && item.shoot > ProjectileID.None), + + new Enchantment("Lecherous", "Spawns a resiliant brimstone orb that stays between you and your mouse that interferes with your homing weapons. It releases a bunch of hearts on death.", + 1200, + "CalamityMod/ExtraTextures/UI/EnchantmentSymbols/CurseIcon_Lecherous", + null, + player => + { + if (Main.gameMenu) + return; + + player.Calamity().lecherousOrbEnchant = true; + + bool orbIsPresent = false; + int orbType = ModContent.NPCType(); + for (int i = 0; i < Main.maxNPCs; i++) + { + if (Main.npc[i].type != orbType || Main.npc[i].target != player.whoAmI || !Main.npc[i].active) + continue; + + orbIsPresent = true; + break; + } + + if (Main.myPlayer == player.whoAmI && !orbIsPresent) + { + int orb = NPC.NewNPC((int)player.Center.X, (int)player.Center.Y - 5, orbType); + if (Main.npc.IndexInRange(orb)) + Main.npc[orb].TargetClosest(); + } + }, + item => item.damage > 0 && item.maxStack == 1 && item.shoot > ProjectileID.None), + }; + + // Special disenchantment thing. This is separated from the list on purpose. + ClearEnchantment = new Enchantment("Disenchant", + string.Empty, + ClearEnchantmentID, + null, + item => item.Calamity().AppliedEnchantment = null, + item => item.maxStack == 1 && item.shoot >= ProjectileID.None); + + ItemUpgradeRelationship = new Dictionary() + { + [ModContent.ItemType()] = ModContent.ItemType(), + [ModContent.ItemType()] = ModContent.ItemType(), + }; + } + + internal static void UnloadAllEnchantments() + { + EnchantmentList = null; + ItemUpgradeRelationship = null; + } + } +} diff --git a/UI/ModeIndicatorUI.cs b/UI/ModeIndicatorUI.cs index 93e9f8b1e2..5967268016 100644 --- a/UI/ModeIndicatorUI.cs +++ b/UI/ModeIndicatorUI.cs @@ -9,9 +9,9 @@ namespace CalamityMod.UI public class ModeIndicatorUI { public static readonly Vector2 OffsetToAreaCenter = new Vector2(0f, 4f); - public static Vector2 DifficultyIconOffset => new Vector2(0f, -16f); - public static Vector2 ArmageddonIconOffset => new Vector2(11.5f, 7f); - public static Vector2 DefiledRuneIconOffset => new Vector2(-12f, 7); + public static Vector2 DifficultyIconOffset => new Vector2(0f, -13f); + public static Vector2 ArmageddonIconOffset => new Vector2(12f, 7f); + public static Vector2 MaliceIconOffset => new Vector2(-12f, 7f); public static void Draw(SpriteBatch spriteBatch) { // The mode indicator should only be displayed when the inventory is open, to prevent obstruction. @@ -22,25 +22,51 @@ namespace CalamityMod.UI Texture2D revengeanceIconTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/UI/ModeIndicatorRev"); Texture2D deathIconTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/UI/ModeIndicatorDeath"); Texture2D armageddonIconTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/UI/ModeIndicatorArma"); + Texture2D maliceIconTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/UI/ModeIndicatorMalice"); - // TODO -- When Malice is added, replace this with Malice's indicator. - Texture2D defiledRuneIconTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/UI/ModeIndicatorRune"); + Rectangle mouseRectangle = Utils.CenteredRectangle(Main.MouseScreen, Vector2.One * 2f); Vector2 drawCenter = new Vector2(Main.screenWidth - 400f, 72f) + outerAreaTexture.Size() * 0.5f; spriteBatch.Draw(outerAreaTexture, drawCenter, null, Color.White, 0f, outerAreaTexture.Size() * 0.5f, 1f, SpriteEffects.None, 0f); + Texture2D difficultyIconToUse = CalamityWorld.death ? deathIconTexture : revengeanceIconTexture; + bool modeIsActive = CalamityWorld.revenge; + bool renderingText = false; if (CalamityWorld.revenge) + spriteBatch.Draw(difficultyIconToUse, drawCenter + DifficultyIconOffset, null, Color.White, 0f, difficultyIconToUse.Size() * 0.5f, 1f, SpriteEffects.None, 0f); + + // Rev/Death active text. + if (mouseRectangle.Intersects(Utils.CenteredRectangle(drawCenter + DifficultyIconOffset, difficultyIconToUse.Size()))) { - Texture2D difficultyIconToUse = CalamityWorld.death ? deathIconTexture : revengeanceIconTexture; - spriteBatch.Draw(difficultyIconToUse, drawCenter + DifficultyIconOffset, null, Color.White, 0f, revengeanceIconTexture.Size() * 0.5f, 0.9f, SpriteEffects.None, 0f); + Main.instance.MouseText($"{(CalamityWorld.death ? "Death" : "Revengeance")} Mode is {(modeIsActive ? "active" : "not active")}."); + renderingText = true; } if (CalamityWorld.armageddon) - spriteBatch.Draw(armageddonIconTexture, drawCenter + ArmageddonIconOffset, null, Color.White, 0f, revengeanceIconTexture.Size() * 0.5f, 0.9f, SpriteEffects.None, 0f); + { + spriteBatch.Draw(armageddonIconTexture, drawCenter + ArmageddonIconOffset, null, Color.White, 0f, armageddonIconTexture.Size() * 0.5f, 1f, SpriteEffects.None, 0f); + } - /*if (false) - spriteBatch.Draw(defiledRuneIconTexture, drawCenter + DefiledRuneIconOffset, null, Color.White, 0f, revengeanceIconTexture.Size() * 0.5f, 0.9f, SpriteEffects.None, 0f);*/ + // Armageddon active text. + if (!renderingText && mouseRectangle.Intersects(Utils.CenteredRectangle(drawCenter + ArmageddonIconOffset, armageddonIconTexture.Size()))) + { + Main.instance.MouseText($"Armageddon is {(CalamityWorld.armageddon ? "active" : "not active")}."); + renderingText = true; + } + + if (CalamityWorld.malice) + spriteBatch.Draw(maliceIconTexture, drawCenter + MaliceIconOffset, null, Color.White, 0f, maliceIconTexture.Size() * 0.5f, 1f, SpriteEffects.None, 0f); + + // Malice active text. + if (!renderingText && mouseRectangle.Intersects(Utils.CenteredRectangle(drawCenter + MaliceIconOffset, armageddonIconTexture.Size()))) + { + Main.instance.MouseText($"Malice Mode is {(CalamityWorld.malice ? "active" : "not active")}."); + renderingText = true; + } + + if (renderingText) + Main.instance.MouseTextHackZoom(string.Empty); } } } diff --git a/Utilities/CollisionUtils.cs b/Utilities/CollisionUtils.cs new file mode 100644 index 0000000000..2ba78d6163 --- /dev/null +++ b/Utilities/CollisionUtils.cs @@ -0,0 +1,28 @@ +using Microsoft.Xna.Framework; +using Terraria; + +namespace CalamityMod +{ + public static partial class CalamityUtils + { + /// + /// Performs collision based a rotating hitbox for an entity by treating the hitbox as a line. By default uses the velocity of the entity as a direction. This can be overriden. + /// + /// The entity. + /// The top left coordinates of the target to check. + /// The hitbox size of the target to check. + /// An optional direction override + public static bool RotatingHitboxCollision(this Entity entity, Vector2 targetTopLeft, Vector2 targetHitboxDimensions, Vector2? directionOverride = null) + { + Vector2 lineDirection = directionOverride ?? entity.velocity; + + // Ensure that the line direction is a unit vector. + lineDirection = lineDirection.SafeNormalize(Vector2.UnitY); + Vector2 start = entity.Center - lineDirection * entity.height * 0.5f; + Vector2 end = entity.Center + lineDirection * entity.height * 0.5f; + + float _ = 0f; + return Collision.CheckAABBvLineCollision(targetTopLeft, targetHitboxDimensions, start, end, entity.width, ref _); + } + } +} diff --git a/Utilities/DrawingUtils.cs b/Utilities/DrawingUtils.cs index 697e5f7931..a3eefd6d7e 100644 --- a/Utilities/DrawingUtils.cs +++ b/Utilities/DrawingUtils.cs @@ -112,6 +112,17 @@ namespace CalamityMod } } + /// + /// Sets a 's arbitrarily. + /// + /// The sprite batch. + /// The blend state to use. + public static void SetBlendState(this SpriteBatch spriteBatch, BlendState blendState) + { + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Immediate, blendState, Main.DefaultSamplerState, DepthStencilState.None, RasterizerState.CullCounterClockwise, null, Main.GameViewMatrix.TransformationMatrix); + } + // Used for bullets. This lets you draw afterimages while keeping the hitbox at the front of the projectile. // This supports type 0 and type 2 afterimages. Vanilla bullets never have type 2 afterimages. public static void DrawAfterimagesFromEdge(Projectile proj, int mode, Color lightColor, Texture2D texture = null) diff --git a/Utilities/ItemUtils.cs b/Utilities/ItemUtils.cs index d743b3f451..00b12acb8e 100644 --- a/Utilities/ItemUtils.cs +++ b/Utilities/ItemUtils.cs @@ -1,6 +1,8 @@ +using CalamityMod.UI.CalamitasEnchants; using CalamityMod.World; using Microsoft.Xna.Framework; using System.Collections.Generic; +using System.Linq; using System.Text; using Terraria; using Terraria.ID; @@ -196,6 +198,25 @@ namespace CalamityMod return moved; } + /// + /// Determines if a given item is enchanted based on Calamitas' special system. + /// + /// The item to check. + public static bool IsEnchanted(this Item item) + { + // If the item is air just immediately return false. + // It will not have a CalamityGlobalItem instance to use and attempting to do anything with it + // would just result in errors. + if (item.IsAir) + return false; + + // If the item is contained in the enchant upgrade result relationship, return true. + if (EnchantmentManager.ItemUpgradeRelationship.ContainsValue(item.type)) + return true; + + return item.Calamity().AppliedEnchantment.HasValue; + } + public static Rectangle FixSwingHitbox(float hitboxWidth, float hitboxHeight) { Player player = Main.player[Main.myPlayer]; @@ -363,6 +384,12 @@ namespace CalamityMod } #endregion + /// + /// Determines if an item can be enchanted by any item at all via Calamitas' enchantment system. + /// + /// The item to check. + public static bool CanBeEnchantedBySomething(this Item item) => EnchantmentManager.EnchantmentList.Any(enchantment => enchantment.ApplyRequirement(item)); + public static void ConsumeItemViaQuickBuff(Player player, Item item, int buffType, int buffTime, bool reducedPotionSickness) { bool showsOver = false; diff --git a/Utilities/MathematicalUtils.cs b/Utilities/MathematicalUtils.cs index 27508a4aa5..797a623508 100644 --- a/Utilities/MathematicalUtils.cs +++ b/Utilities/MathematicalUtils.cs @@ -20,6 +20,14 @@ namespace CalamityMod /// The second vector. public static float AngleBetween(this Vector2 v1, Vector2 v2) => (float)Math.Acos(Vector2.Dot(v1.SafeNormalize(Vector2.Zero), v2.SafeNormalize(Vector2.Zero))); + // NOTE: A similar function to this one exists in 1.4, but it is not the same underlying function. Check Turn01ToCyclic010 in Utils.cs to see the effect. + + /// + /// Converts a 0-1 bound to a 0-1-0 bump. This function automatically clamps the value to the necessary 0-1 range. + /// + /// The value to convert. + public static float Convert01To010(float value) => (float)Math.Sin(MathHelper.Pi * MathHelper.Clamp(value, 0f, 1f)); + /// /// Uses a rewritten horizontal range formula to determine the direction to fire a projectile in order for it to hit a destination. Falls back on a certain value if no such direction can exist. If no fallback is provided, a clamp is used. /// diff --git a/Utilities/ProjectileUtils.cs b/Utilities/ProjectileUtils.cs index b1fb0e3b10..b13a4c3b1a 100644 --- a/Utilities/ProjectileUtils.cs +++ b/Utilities/ProjectileUtils.cs @@ -21,6 +21,11 @@ namespace CalamityMod public static bool IsSummon(this Projectile proj) => proj.minion || proj.sentry || CalamityLists.projectileMinionList.Contains(proj.type) || ProjectileID.Sets.MinionShot[proj.type] || ProjectileID.Sets.SentryShot[proj.type]; + public static T ModProjectile(this Projectile projectile) where T : ModProjectile + { + return projectile.modProjectile as T; + } + public static void KillAllHostileProjectiles() { for (int x = 0; x < Main.maxProjectiles; x++) diff --git a/Utilities/TileUtils.cs b/Utilities/TileUtils.cs index e499f8d696..a383821d66 100644 --- a/Utilities/TileUtils.cs +++ b/Utilities/TileUtils.cs @@ -458,5 +458,11 @@ namespace CalamityMod SetMerge(type, TileType()); SetMerge(type, TileType()); } + + /// + /// Determines if a tile is solid ground based on whether it's active and not actuated or if the tile is solid in any way, including just the top. + /// + /// The tile to check. + public static bool IsTileSolidGround(this Tile tile) => tile != null && tile.nactive() && (Main.tileSolid[tile.type] || Main.tileSolidTop[tile.type]); } }