From 9cd32d9952e29b6cf96eb5137ae65df876cf1626 Mon Sep 17 00:00:00 2001 From: Doze-Zoze Date: Sat, 24 May 2025 15:13:26 -0500 Subject: [PATCH] Ported summon tag refactor to main --- Buffs/CalamityGlobalBuff.cs | 36 ++++ CalPlayer/CalamityPlayer.cs | 17 ++ DataStructures/SummonTag.cs | 184 ++++++++++++++++++ Items/Accessories/ProfanedSoulCrystal.cs | 25 +++ Items/CalamityGlobalItemTooltip.cs | 73 ++++++- .../en-US/Mods.CalamityMod.Common.hjson | 3 + NPCs/CalamityGlobalNPC.cs | 183 +++++++++++------ Systems/Collections/SummonTagBuffList.cs | 35 ++++ Systems/Collections/SummonTagDebuffDict.cs | 63 ++++++ 9 files changed, 558 insertions(+), 61 deletions(-) create mode 100644 DataStructures/SummonTag.cs create mode 100644 Systems/Collections/SummonTagBuffList.cs create mode 100644 Systems/Collections/SummonTagDebuffDict.cs diff --git a/Buffs/CalamityGlobalBuff.cs b/Buffs/CalamityGlobalBuff.cs index f2ef8dfbb5..f893df6689 100644 --- a/Buffs/CalamityGlobalBuff.cs +++ b/Buffs/CalamityGlobalBuff.cs @@ -14,6 +14,24 @@ namespace CalamityMod.Buffs public override void Update(int type, Player player, ref int buffIndex) { + // Globally remove summon tag buff stacking + // Other mods need to add to this list because we genuinely don't have any way to tell this + if (SummonTagBuffList.Includes(type) && buffIndex > 0) + { + for (int i = buffIndex; i >= 0; i--) + { + if (player.buffTime[i] > 0) + { + int buffID = player.buffType[i]; + if (SummonTagBuffList.Includes(buffID) && buffID != type) + { + player.DelBuff(i); + break; + } + } + } + } + if (type == BuffID.Archery) { player.arrowDamage *= 0.955f; @@ -106,6 +124,24 @@ namespace CalamityMod.Buffs public override void Update(int type, NPC npc, ref int buffIndex) { + // Globally remove summon tag debuff stacking, unless allowed in the SummonTag + // Other mods need to add to this list because otherwise we can't tell which IsATag buff is actually for whips + if (SummonTagDebuffDict.TryGet(type, out var tag1) && !tag1.AllowsWhipStacking && buffIndex > 0) + { + for (int i = buffIndex; i >= 0; i--) + { + if (npc.buffTime[i] > 0) + { + int buffID = npc.buffType[i]; + if (SummonTagDebuffDict.TryGet(buffID, out var tag2) && !tag2.AllowsWhipStacking && buffID != type) + { + npc.DelBuff(i); + break; + } + } + } + } + if (type == BuffID.Webbed) { if (npc.Calamity().webbed < npc.buffTime[buffIndex]) diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index 56b57b152b..e515c98499 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -1540,6 +1540,16 @@ namespace CalamityMod.CalPlayer public bool AmphibiansGuitarBool = false; #endregion + #region Whip + public bool forceSummonTagCrit = false; //Forces whip multiplicative effects to function as crit chance + public bool forceSummonTagMultiplicative = false; //Forces whip multiplicative effects to function as multiplicative damage + + //Allows providing flat, crit, and multiplicative tag values on gear. These will apply on *any* minion or sentry hit, not just if the target is tagged. + public int bonusFlatTag = 0; + public float bonusCritTag = 0; + public float bonusMultTag = 0; + #endregion + #region Biome public bool ZoneSunkenSea => ZoneTimelessShores || ZoneRadiantReefs || ZonePolypForest || ZoneGleamingBurrows || ZoneClamDen || ZoneBasaltGully; public bool ZoneTimelessShores => Player.InModBiome(); @@ -2708,6 +2718,13 @@ namespace CalamityMod.CalPlayer AmphibiansGuitarBool = false; #endregion + //On GFB both are enabled to cause the game to pick between multiplicative and crit at random + forceSummonTagMultiplicative = (Main.zenithWorld ? true : false); + forceSummonTagCrit = (Main.zenithWorld ? true : false); + bonusFlatTag = 0; + bonusCritTag = 0; + bonusMultTag = 0; + /* Spawn blockers from back when they used to work by being favorited and not a toggleable item noStupidNaturalARSpawns = false disableVoodooSpawns = false; diff --git a/DataStructures/SummonTag.cs b/DataStructures/SummonTag.cs new file mode 100644 index 0000000000..61c2540ab0 --- /dev/null +++ b/DataStructures/SummonTag.cs @@ -0,0 +1,184 @@ +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; +using Terraria; +using Terraria.GameContent; +using Terraria.ID; + +namespace CalamityMod.DataStructures +{ + /// + /// This is used to store summon tag stats so they can be applied automatically. + /// + public class SummonTag + { + #region SummonTag data + /// + /// Flat tag damage from this summon tag + /// + public int FlatTagDamage = 0; + + /// + /// This is tag damage that isn't added to the tooltip. Used for removing Vanilla whip tag damage. + /// + public int UnlistedTagDamage = 0; + + /// + /// Multiplicative tag damage from this summon tag. Stacks additively with other tags. + /// + public float MultiplicativeTagDamage = 0; + + /// + /// This is tag damage that isn't added to the tooltip. Used for removing Firecracker whip damage. + /// + public float UnlistedMultiplicativeTagDamage = 0; + + /// + /// Tag critical strike chance from this stummon tag. Stacks additively with other tags. + /// + public float TagCritChance = 0; + + /// + /// How much the Critical Strike damage multiplier should be adjusted with this tag. Stacks additively with other tags. + /// + public float TagCritDamage = 0; + + /// + /// UNIMPLEMENTED. Need to add animation frame support before using. + /// What the texture for the tag effect should be. + /// + public Asset TagTexture; + + /// + /// What item inflicted this tag + /// + public int TagItem = -1; + + /// + /// The ModifyHitByProjectileTag code to run. Defaults to just applying the tag effects. + /// + public ModifyHitByProjectileTag TagModifyHitEffects; + + /// + /// Disable to stop tooltips from drawing automatically, for things that change TagModifyHitEffects + /// + public bool AutoDrawTooltip = true; + + /// + /// Setting to true allows this tag to be used alongside other tag effects. + /// + public bool AllowsWhipStacking = false; + + /// + /// The OnHitByProjectile code to run when this tag is applied. Defaults to nothing. + /// + public OnHitByProjectile TagOnHit = BlankOnHit; + public SummonTag() + { + TagModifyHitEffects = ApplyTagModifyHit; + } + + public SummonTag(int itemType) + { + TagItem = itemType; + TagModifyHitEffects = ApplyTagModifyHit; + } + + /// + /// A modified version of ModifyHitByProjectile that incorporates tag damage multipliers and tag critical chance. + /// This delegate is used for TagModifyHitEffects + /// + /// + /// + /// + /// + /// + public delegate void ModifyHitByProjectileTag(Projectile proj, NPC npc, ref NPC.HitModifiers modifiers, ref float tagDamageMult, ref float critChance); + + /// + /// This delegate is used for TagOnHit + /// + /// + /// + /// + /// + public delegate void OnHitByProjectile(NPC npc, Projectile projectile, NPC.HitInfo hit, int damageDone); + + /// + /// The default tag damage functionality + /// + public void ApplyTagModifyHit(Projectile proj, NPC npc, ref NPC.HitModifiers modifiers, ref float tagDamageMult, ref float critChance) + { + modifiers.FlatBonusDamage += (FlatTagDamage + UnlistedTagDamage) * tagDamageMult; + modifiers.ScalingBonusDamage += (MultiplicativeTagDamage + UnlistedMultiplicativeTagDamage) * tagDamageMult; + critChance += TagCritChance; + modifiers.CritDamage += TagCritDamage; + } + /// + /// Due to how Firecracker works, this allows it to work with crit accessories. + /// + public static void FirecrackerModifyHit(Projectile proj, NPC npc, ref NPC.HitModifiers modifiers, ref float tagDamageMult, ref float critChance) + { + modifiers.ScalingBonusDamage += (Firecracker.MultiplicativeTagDamage + Firecracker.UnlistedMultiplicativeTagDamage) * tagDamageMult; + modifiers.CritDamage += Firecracker.TagCritDamage; + } + /// + /// This is replaced by custom tag on hit effects. Does nothing. + /// + public static void BlankOnHit(NPC npc, Projectile projectile, NPC.HitInfo hit, int damagedone) { } + #endregion + + #region Vanilla whip stats + public static SummonTag LeatherWhip = new SummonTag(ItemID.BlandWhip) + { + FlatTagDamage = 4, + UnlistedTagDamage = -4 //Negative value cancels out vanilla tag damage + }; + public static SummonTag Snapthorn = new SummonTag(ItemID.ThornWhip) + { + FlatTagDamage = 4, + UnlistedTagDamage = -6 //Negative value cancels out vanilla tag damage + }; + public static SummonTag SpinalTap = new SummonTag(ItemID.BoneWhip) + { + FlatTagDamage = 5, + UnlistedTagDamage = -7 //Negative value cancels out vanilla tag damage + }; + public static SummonTag Firecracker = new SummonTag(ItemID.FireWhip) + { + MultiplicativeTagDamage = 1f, + TagCritDamage = -1f, + TagModifyHitEffects = FirecrackerModifyHit, + UnlistedMultiplicativeTagDamage = -1.75f, //Cancels out the vanilla firecracker tag damage + AutoDrawTooltip = false + }; + public static SummonTag CoolWhip = new SummonTag(ItemID.CoolWhip) + { + FlatTagDamage = 8, + UnlistedTagDamage = -6 //Negative value cancels out vanilla tag damage + }; + public static SummonTag Durendal = new SummonTag(ItemID.SwordWhip) + { + FlatTagDamage = 5, + TagCritChance = 0.05f, + UnlistedTagDamage = -9 //Negative value cancels out vanilla tag damage + }; + public static SummonTag MorningStar = new SummonTag(ItemID.MaceWhip) + { + TagCritChance = 0.13f, + UnlistedTagDamage = -8 //Negative value cancels out vanilla tag damage + }; + public static SummonTag DarkHarvest = new SummonTag(ItemID.ScytheWhip) + { + FlatTagDamage = 14, + UnlistedTagDamage = -10, //Negative value cancels out vanilla tag damage + //This has a unique on hit effect from vanilla. + }; + public static SummonTag Kaleidoscope = new SummonTag(ItemID.RainbowWhip) + { + FlatTagDamage = 10, + TagCritChance = 0.10f, + UnlistedTagDamage = -20 //Negative value cancels out vanilla tag damage + }; + #endregion + } +} diff --git a/Items/Accessories/ProfanedSoulCrystal.cs b/Items/Accessories/ProfanedSoulCrystal.cs index 546e685553..a62a6fa4f7 100644 --- a/Items/Accessories/ProfanedSoulCrystal.cs +++ b/Items/Accessories/ProfanedSoulCrystal.cs @@ -6,6 +6,8 @@ using CalamityMod.Buffs.Summon.Whips; using CalamityMod.CalPlayer; using CalamityMod.DataStructures; using CalamityMod.Items.Materials; +using CalamityMod.NPCs.Providence; +using CalamityMod.Particles; using CalamityMod.Projectiles.Summon; using CalamityMod.Rarities; using CalamityMod.Tiles.Furniture.CraftingStations; @@ -14,6 +16,7 @@ using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.Audio; using Terraria.DataStructures; +using Terraria.GameContent; using Terraria.ID; using Terraria.ModLoader; @@ -31,6 +34,26 @@ namespace CalamityMod.Items.Accessories public const int maxMinionRequirement = 10; public const int maxPscAnimTime = 120; + public static SummonTag SummonTag = new() { MultiplicativeTagDamage = 0.2f, TagModifyHitEffects = ApplyTagModifyHit, AutoDrawTooltip = false }; + + public static void ApplyTagModifyHit(Projectile proj, NPC npc, ref NPC.HitModifiers modifiers, ref float tagDamageMult, ref float critChance) + { + if (Main.player[proj.owner].Calamity().pscState >= (int)ProfanedSoulCrystalState.Buffs) + { + var empowered = Main.player[proj.owner].Calamity().pscState == (int)ProfanedSoulCrystalState.Empowered; + //20% is balanced for non empowered, while 40% helps ensure psc remains balanced at empowered tier + //Some PSC projectiles receive a reduced amount of benefit from this, for balancing purposes + modifiers.ScalingBonusDamage += (empowered ? 0.4f : SummonTag.MultiplicativeTagDamage) * tagDamageMult; + if (!Main.dedServ) + { + var color = ProvUtils.GetColorBasedOnEnrage(!Main.dayTime, 0); + float power = Math.Min(npc.height / 100f, 3f); + var position = new Vector2(Main.rand.NextFloat(npc.Left.X, npc.Right.X), Main.rand.NextFloat(npc.Top.Y, npc.Bottom.Y)); + var particle = new FlameParticle(position, 50, 0.25f, power, color * (Main.dayTime ? 1f : 1.25f), color * (Main.dayTime ? 1.25f : 1f)); + GeneralParticleHandler.SpawnParticle(particle); + } + } + } // Interface stuff. public int OwnerPlayer { get; set; } @@ -192,6 +215,8 @@ namespace CalamityMod.Items.Accessories public override void SetDefaults() { + SummonTag.TagItem = Item.type; + SummonTag.TagTexture = TextureAssets.Item[Type]; Item.width = 50; Item.height = 50; Item.accessory = true; diff --git a/Items/CalamityGlobalItemTooltip.cs b/Items/CalamityGlobalItemTooltip.cs index bbe4afbd13..c621856826 100644 --- a/Items/CalamityGlobalItemTooltip.cs +++ b/Items/CalamityGlobalItemTooltip.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using CalamityMod.Balancing; using CalamityMod.CustomRecipes; +using CalamityMod.DataStructures; using CalamityMod.Items.Accessories; using CalamityMod.Items.Armor.Demonshade; using CalamityMod.Items.PermanentBoosters; @@ -15,6 +16,7 @@ using CalamityMod.Items.Weapons.Ranged; using CalamityMod.Items.Weapons.Rogue; using CalamityMod.Items.Weapons.Summon; using CalamityMod.Prefixes; +using CalamityMod.Systems.Collections; using CalamityMod.World; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -154,6 +156,7 @@ namespace CalamityMod.Items // 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); + WhipAutomaticTooltips(item, tooltips, ref lastTooltipIndex); // In GFB, replace all instances of "rogue" with "rouge". string[] rogueKey = new string[] { CalamityUtils.GetTextValue($"Misc.GFBRogueUppercase"), CalamityUtils.GetTextValue($"Misc.GFBRogueLowercase") }; string[] rougeKey = new string[] { CalamityUtils.GetTextValue($"Misc.GFBRougeUppercase"), CalamityUtils.GetTextValue($"Misc.GFBRougeLowercase") }; @@ -411,6 +414,47 @@ namespace CalamityMod.Items } #endregion + #region Whip Tooltips + private void WhipAutomaticTooltips(Item item, IList tooltips, ref int lastTooltipIndex) + { + // Multiplicative tag changes + string FlatTagTooltip(int dmg) => (CalamityUtils.GetText($"Common.SummonTagDamageFlat").Format(dmg.ToString())); + string MultTagTooltip(float mult) => (CalamityUtils.GetText($"Common.SummonTagDamageMult").Format((mult + 1).ToString("0.##"))); + string CritTagTooltip(float crit) => (CalamityUtils.GetText($"Common.SummonTagCrit").Format((crit * 100).ToString("0.#"))); + + Dictionary TagByItem = new(); + foreach (SummonTag tag1 in SummonTagDebuffDict.Dict.Values) + { + if (tag1.TagItem > -1) TagByItem.Add(tag1.TagItem, tag1); + } + if (TagByItem.TryGetValue(item.type, out SummonTag tag)) + { + if (!tag.AutoDrawTooltip) return; + var modPlayer = Main.LocalPlayer.Calamity(); + if (tag.FlatTagDamage != 0) + { + TooltipLine line = new TooltipLine(Mod, "CalamityMod:FlatSummonTag", FlatTagTooltip(tag.FlatTagDamage)); + tooltips.Insert(++lastTooltipIndex, line); + } + if (!modPlayer.forceSummonTagCrit && (tag.MultiplicativeTagDamage != 0 || (modPlayer.forceSummonTagMultiplicative && tag.TagCritChance != 0))) + { + TooltipLine line = new TooltipLine(Mod, "CalamityMod:MultiplicativeSummonTag", MultTagTooltip(tag.MultiplicativeTagDamage + (modPlayer.forceSummonTagMultiplicative ? tag.TagCritChance : 0))); + tooltips.Insert(++lastTooltipIndex, line); + } + if (!modPlayer.forceSummonTagMultiplicative && (tag.TagCritChance != 0 || (modPlayer.forceSummonTagCrit && tag.MultiplicativeTagDamage != 0))) + { + TooltipLine line = new TooltipLine(Mod, "CalamityMod:CritSummonTag", CritTagTooltip(tag.TagCritChance + (modPlayer.forceSummonTagCrit ? tag.MultiplicativeTagDamage : 0))); + tooltips.Insert(++lastTooltipIndex, line); + } + if (modPlayer.forceSummonTagMultiplicative && modPlayer.forceSummonTagCrit) //when both tag and crit are forced, swaps between the two + { + TooltipLine line = new TooltipLine(Mod, "CalamityMod:CritSummonTag", ((int)(Main.GlobalTimeWrappedHourly / 5) % 2 == 0 ? CritTagTooltip(tag.MultiplicativeTagDamage + tag.TagCritChance) : MultTagTooltip(tag.MultiplicativeTagDamage + tag.TagCritChance))); + tooltips.Insert(++lastTooltipIndex, line); + } + } + } + #endregion + #region Vanilla Item Tooltip Modification private static void ModifyVanillaTooltips(Item item, IList tooltips) { @@ -636,8 +680,33 @@ namespace CalamityMod.Items EditTooltipByNum(0, (line) => line.Text = CalamityUtils.GetText("Vanilla.DodgeInfo").Format(BalancingConstants.BrainDodgeCooldownMin / 60, BalancingConstants.BrainDodgeCooldownMax / 60)); #endregion - // Weapon changes - #region Weapon changes + // Whip tag is dynamically generated for all whips based on the SummonTagDebuffDict, so we'll remove the vanilla tag tootlips. + #region Whip Tag removal + // Additive tag changes + if (item.type == ItemID.BlandWhip) + EditTooltipByNum(0, (line) => line.Text = string.Empty); + if (item.type == ItemID.ThornWhip) + EditTooltipByNum(0, (line) => line.Text = string.Empty); + if (item.type == ItemID.BoneWhip) + EditTooltipByNum(0, (line) => line.Text = string.Empty); + if (item.type == ItemID.CoolWhip) + EditTooltipByNum(0, (line) => line.Text = string.Empty); + if (item.type == ItemID.SwordWhip) + EditTooltipByNum(0, (line) => line.Text = string.Empty); + if (item.type == ItemID.MaceWhip) + { + EditTooltipByNum(0, (line) => line.Text = string.Empty); + EditTooltipByNum(1, (line) => line.Text = string.Empty); + } + if (item.type == ItemID.RainbowWhip) + { + EditTooltipByNum(0, (line) => line.Text = string.Empty); + EditTooltipByNum(1, (line) => line.Text = string.Empty); + } + #endregion + + // Other weapon changes + #region Other weapon changes // Aerial Bane is no longer the real bane of aerial enemies (50% dmg bonus removed) if (item.type == ItemID.DD2BetsyBow) EditTooltipByNum(0, (line) => line.Text = EditedTooltip("DD2BetsyBow")); diff --git a/Localization/en-US/Mods.CalamityMod.Common.hjson b/Localization/en-US/Mods.CalamityMod.Common.hjson index c083073773..413fa82e21 100644 --- a/Localization/en-US/Mods.CalamityMod.Common.hjson +++ b/Localization/en-US/Mods.CalamityMod.Common.hjson @@ -11,6 +11,9 @@ NotConsumable: Not consumable RogueDamage: "{0}% increased rogue damage" RogueCrit: "{0}% increased rogue critical strike chance" RogueVelocity: "{0}% increased rogue velocity" +SummonTagDamageFlat: "{0} summon tag damage" +SummonTagDamageMult: "{0}x summon tag damage" +SummonTagCrit: "{0}% summon tag critcal strike chance" DodgeInformation: ''' Attacks that deal less than 5% of your max life in damage will not be dodged diff --git a/NPCs/CalamityGlobalNPC.cs b/NPCs/CalamityGlobalNPC.cs index 8e81031fe3..f4642fd26a 100644 --- a/NPCs/CalamityGlobalNPC.cs +++ b/NPCs/CalamityGlobalNPC.cs @@ -10,6 +10,7 @@ using CalamityMod.Buffs.StatBuffs; using CalamityMod.Buffs.StatDebuffs; using CalamityMod.Buffs.Summon.Whips; using CalamityMod.CalPlayer; +using CalamityMod.DataStructures; using CalamityMod.Dusts; using CalamityMod.Events; using CalamityMod.ExtraTextures; @@ -20,6 +21,7 @@ using CalamityMod.Items.Accessories; using CalamityMod.Items.Potions.Alcohol; using CalamityMod.Items.Tools; using CalamityMod.Items.Weapons.Melee; +using CalamityMod.Items.Weapons.Summon.Whips; using CalamityMod.Items.Weapons.Typeless; using CalamityMod.NPCs.Abyss; using CalamityMod.NPCs.AcidRain; @@ -63,6 +65,7 @@ using CalamityMod.Projectiles.Melee; using CalamityMod.Projectiles.Ranged; using CalamityMod.Projectiles.Rogue; using CalamityMod.Projectiles.Summon; +using CalamityMod.Projectiles.Summon.Whips; using CalamityMod.Projectiles.Typeless; using CalamityMod.Systems; using CalamityMod.Systems.Collections; @@ -6494,8 +6497,9 @@ namespace CalamityMod.NPCs #region Modify Hit By Projectile public static bool DisableMultWhipTag = false; - //this bool does nothing on this branch, its just here so that CalTestHelpers doesn't crash searching for it - //if you want to mess with this, please do so in the summoner branch - Shade + //this bool does nothing on the main branch, its just here so that CalTestHelpers doesn't crash searching for it + //if you want to mess with this to test whips, please do so in the summoner branch - Shade + public override void ModifyHitByProjectile(NPC npc, Projectile projectile, ref NPC.HitModifiers modifiers) { Player player = Main.player[projectile.owner]; @@ -6673,14 +6677,36 @@ namespace CalamityMod.NPCs if ((projectile.minion || ProjectileID.Sets.MinionShot[projectile.type] || projectile.sentry || ProjectileID.Sets.SentryShot[projectile.type]) && (player.ownedProjectileCounts[ProjectileType()] > 0 || player.ownedProjectileCounts[ProjectileType()] > 0 || (player.Calamity().rOfResilienceCooldown == 0 && player.HeldItem.type == ItemType()))) modifiers.SourceDamage *= 0.1f; + //Doze apr-6-2025: with the summon tag system we now have this is unnececcessary and very likely causes issues on MP, so i'm commenting it out for the time being. Once further testing is done, delete it entirely. + //Delete ardor blososm sparks and buff if hit by something that isnt a minion or sentry while not having Ardor Blossom Star in hand + /*if (npc.HasBuff() && player.HeldItem.type != ModContent.ItemType() && !projectile.minion && !ProjectileID.Sets.MinionShot[projectile.type] && !projectile.sentry) + { + npc.RequestBuffRemoval(ModContent.BuffType()); + //Remove all embers from this enemy + for (int k = 0; k < Main.maxProjectiles; k++) + { + if (Main.projectile[k].active && Main.projectile[k].type == ModContent.ProjectileType() && Main.projectile[k].ai[0] == 1f && Main.projectile[k].ai[1] == npc.whoAmI && Main.projectile[k].owner == player.whoAmI) + Main.projectile[k].Kill(); + } + }*/ + //Handle summon tag effects if (projectile.minion || ProjectileID.Sets.MinionShot[projectile.type] || projectile.sentry || ProjectileID.Sets.SentryShot[projectile.type]) - EditWhipTagDamage(projectile, npc, ref modifiers); + { + EditSummonTagDamage(projectile, npc, ref modifiers); + } + + } - #endregion + #endregion #region OnHitBy overrides public override void OnHitByProjectile(NPC npc, Projectile projectile, NPC.HitInfo hit, int damagedone) { + if (projectile.minion || ProjectileID.Sets.MinionShot[projectile.type] || projectile.sentry || ProjectileID.Sets.SentryShot[projectile.type]) + { + SummonTagOnHitEffects(npc, projectile, hit, damagedone); + } + if (IsArmored()) { CombatText.NewText(npc.Hitbox, Color.Gray, damagedone, hit.Crit); @@ -6705,75 +6731,89 @@ namespace CalamityMod.NPCs } } + #endregion - #region Whip Tag - // Make whip tags multiplicative, by effectively reversing the process done to it - private void EditWhipTagDamage(Projectile proj, NPC npc, ref NPC.HitModifiers modifiers) + + #region Summon Tag + //doze 03-15-2025: A full refactor of the summon tag system to make it easier to use and more flexible. Ping me with any questions. + private void EditSummonTagDamage(Projectile proj, NPC npc, ref NPC.HitModifiers modifiers) { - // Don't make it run through the index if it's a trap - if (proj.npcProj || proj.trap) + if (proj.npcProj || proj.trap || proj.owner == -1) // don't run on non-player-owned projectiles. return; + var player = Main.player[proj.owner]; + var modPlayer = player.Calamity(); + + float critChance = modPlayer.bonusCritTag; float TagDamageMult = ProjectileID.Sets.SummonTagDamageMultiplier[proj.type]; + + TagDamageMult += modPlayer.bonusMultTag; + modifiers.FlatBonusDamage += modPlayer.bonusFlatTag; + for (int i = 0; i < NPC.maxBuffs; i++) { if (npc.buffTime[i] >= 1) { - switch (npc.buffType[i]) + int type = npc.buffType[i]; + if (SummonTagDebuffDict.TryGet(type, out SummonTag tag)) { - case BuffID.BlandWhipEnemyDebuff: // Leather Whip - modifiers.FlatBonusDamage += -4f * TagDamageMult; - modifiers.ScalingBonusDamage += (BalancingConstants.DurendalTagDamageMultiplier - 1f) * TagDamageMult; - break; - case BuffID.ThornWhipNPCDebuff: // Snapthorn - modifiers.FlatBonusDamage += -6f * TagDamageMult; - modifiers.ScalingBonusDamage += (BalancingConstants.SnapthornTagDamageMultiplier - 1f) * TagDamageMult; - break; - case BuffID.BoneWhipNPCDebuff: // Spinal Tap - modifiers.FlatBonusDamage += -7f * TagDamageMult; - modifiers.ScalingBonusDamage += (BalancingConstants.SpinalTapTagDamageMultiplier - 1f) * TagDamageMult; - break; - case BuffID.FlameWhipEnemyDebuff: // Firecracker - modifiers.ScalingBonusDamage += (BalancingConstants.FirecrackerExplosionDamageMultiplier - 2.75f) * TagDamageMult; - break; - case BuffID.CoolWhipNPCDebuff: // Cool Whip - modifiers.FlatBonusDamage += -6f * TagDamageMult; - modifiers.ScalingBonusDamage += (BalancingConstants.CoolWhipTagDamageMultiplier - 1f) * TagDamageMult; - break; - case BuffID.SwordWhipNPCDebuff: // Durendal - modifiers.FlatBonusDamage += -9f * TagDamageMult; - modifiers.ScalingBonusDamage += (BalancingConstants.DurendalTagDamageMultiplier - 1f) * TagDamageMult; - break; - case BuffID.ScytheWhipEnemyDebuff: // Dark Harvest - modifiers.FlatBonusDamage += -10f * TagDamageMult; - break; - case BuffID.MaceWhipNPCDebuff: // Morning Star - modifiers.FlatBonusDamage += -8f * TagDamageMult; - modifiers.ScalingBonusDamage += (BalancingConstants.MorningStarTagDamageMultiplier - 1f) * TagDamageMult; - break; - case BuffID.RainbowWhipNPCDebuff: // Kaleidoscope - modifiers.FlatBonusDamage += -20f * TagDamageMult; - modifiers.ScalingBonusDamage += (BalancingConstants.KaleidoscopeTagDamageMultiplier - 1f) * TagDamageMult; - break; + tag.TagModifyHitEffects(proj, npc, ref modifiers, ref TagDamageMult, ref critChance); } } } - //BuffType cannot be used in switch case, so that has to be handled outside of it - //Verify that the owner of the proj has psc state higher or equal to psc buffs - if (npc.HasBuff() && Main.player[proj.owner].Calamity().pscState >= (int)ProfanedSoulCrystal.ProfanedSoulCrystalState.Buffs) + + //For the vanilla Monk/Shinobi armor critting with Lightning Auras. In vanilla it doesn't stack additively but frankly I do not care. It's not like aura is that good anyway. + if (proj.type == ProjectileID.DD2LightningAuraT1 || proj.type == ProjectileID.DD2LightningAuraT2 || proj.type == ProjectileID.DD2LightningAuraT3) { - var empowered = Main.player[proj.owner].Calamity().pscState == (int)ProfanedSoulCrystal.ProfanedSoulCrystalState.Empowered; - //20% is balanced for non empowered, while 40% helps ensure psc remains balanced at empowered tier - //Some PSC projectiles receive a reduced amount of benefit from this, for balancing purposes - modifiers.ScalingBonusDamage += (empowered ? 0.4f : 0.2f) * TagDamageMult; - if (!Main.dedServ) + if (player.setMonkT3) { - var color = ProvUtils.GetColorBasedOnEnrage(!Main.dayTime, 0); - float power = Math.Min(npc.height / 100f, 3f); - var position = new Vector2(Main.rand.NextFloat(npc.Left.X, npc.Right.X), Main.rand.NextFloat(npc.Top.Y, npc.Bottom.Y)); - var particle = new FlameParticle(position, 50, 0.25f, power, color * (Main.dayTime ? 1f : 1.25f), color * (Main.dayTime ? 1.25f : 1f)); - GeneralParticleHandler.SpawnParticle(particle); + critChance += 0.25f; // 1/4 chance to crit with Shinobi + } + else if (player.setMonkT2) + { + critChance += 0.166f; // 1/6 chance to crit with Monk + } + } + + //Used to convert all multiplicative tag into crit chance and vice-versa. If both force tag crit and multiplicative are applied, chooses one at random. + if (modPlayer.forceSummonTagCrit && !(modPlayer.forceSummonTagMultiplicative && Main.rand.NextBool())) + { + critChance += modifiers.ScalingBonusDamage.Value; + modifiers.ScalingBonusDamage += -modifiers.ScalingBonusDamage.Value; + + } + else if (modPlayer.forceSummonTagMultiplicative) + { + + modifiers.ScalingBonusDamage += critChance; + critChance = 0; + } + + //currently doesn't support more than 100% crit chance, todo if something does more than +100% tag damage + if (Main.rand.NextFloat() < critChance) + modifiers.SetCrit(); + else + modifiers.DisableCrit(); //This is to prevent Morning Star and Kalei from critting with their vanilla tag effect. If you want a minion/sentry to crit, you *must* make sure to change critChance in this function. + } + + //This is for whip tag effects that run on hit and don't modify the damage of the hit. + private void SummonTagOnHitEffects(NPC npc, Projectile projectile, NPC.HitInfo hit, int damagedone) + { + if (projectile.npcProj || projectile.trap || projectile.owner == -1) // don't run on non-player-owned projectiles. + return; + + Player player = Main.player[projectile.owner]; + + for (int i = 0; i < NPC.maxBuffs; i++) + { + if (npc.buffTime[i] >= 1) + { + int type = npc.buffType[i]; + if (SummonTagDebuffDict.TryGet(type, out SummonTag tag)) + { + tag.TagOnHit(npc, projectile, hit, damagedone); + } } } } @@ -7930,8 +7970,6 @@ namespace CalamityMod.NPCs currentDebuffs.Add(TextureAssets.Buff[BuffID.Slimed].Value); if (npc.drippingSparkleSlime) currentDebuffs.Add(TextureAssets.Buff[BuffID.GelBalloonBuff].Value); - if (npc.markedByScytheWhip) // Dark Harvest whip, the only Whip debuff that has an NPC bool - currentDebuffs.Add(TextureAssets.Buff[BuffID.ScytheWhipEnemyDebuff].Value); // Total amount of elements in the buff list int buffTextureListLength = currentDebuffs.Count(); @@ -7975,6 +8013,33 @@ namespace CalamityMod.NPCs if (currentDebuffs[i] == TextureAssets.Buff[BuffType()].Value) ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, FontAssets.MouseText.Value, somaShredStacks.ToString(), npc.Center - screenPos - new Vector2(drawPosX, drawPosY + additionalYOffset) + Vector2.One * 4f, Color.Gold, 0f, Vector2.Zero, Vector2.One * Main.UIScale * 0.8f); } + + + // Draw summon tag display. TODO: make it use custom textures provided by SummonTag. + int yOffset = 0; + for (int i = NPC.maxBuffs - 1; i >= 0; i--) + { + if (npc.buffTime[i] > 0) + { + if (SummonTagDebuffDict.TryGet(npc.buffType[i], out SummonTag tag)) + { + // Fetch the item and its frames + var tex = TextureAssets.Item[tag.TagItem].Value; + Rectangle frame = (Main.itemAnimations[tag.TagItem] == null) ? tex.Frame() : Main.itemAnimations[tag.TagItem].GetFrame(tex); + if (tag.TagTexture != null) + { + tex = tag.TagTexture.Value; + frame = tex.Frame(); + } + + // Draw it accordingly + // This is drawn below the NPC as opposed to above to differentiate from regular debuffs + Vector2 drawPos = npc.Center - screenPos + Vector2.UnitY * (drawPosY + frame.Height * 0.5f + yOffset); + spriteBatch.Draw(tex, drawPos, frame, Color.White, 0f, frame.Size() * 0.5f, 0.75f, SpriteEffects.None, 0f); + yOffset += frame.Height + 4; + } + } + } } } diff --git a/Systems/Collections/SummonTagBuffList.cs b/Systems/Collections/SummonTagBuffList.cs new file mode 100644 index 0000000000..c37383d0bd --- /dev/null +++ b/Systems/Collections/SummonTagBuffList.cs @@ -0,0 +1,35 @@ +using System.Collections.Generic; +using CalamityMod.Buffs.Summon.Whips; +using Terraria.ID; +using Terraria.ModLoader; +using static Terraria.ModLoader.ModContent; + +namespace CalamityMod.Systems.Collections +{ + /// + /// A that contains a of all summon tag buff's IDs. + /// + public sealed class SummonTagBuffList : ModSystem + { + public static IList List { get; private set; } + + public override void OnModLoad() + { + List = + [ + BuffID.CoolWhipPlayerBuff, + BuffID.ScytheWhipPlayerBuff, + BuffID.SwordWhipPlayerBuff, + BuffID.ThornWhipPlayerBuff, + BuffType() + ]; + } + + public override void Unload() => List = null; + + /// + /// A shorthand method to check whether or not a buff ID is a summon tag buff. + /// + public static bool Includes(int buffID) => List.Contains(buffID); + } +} diff --git a/Systems/Collections/SummonTagDebuffDict.cs b/Systems/Collections/SummonTagDebuffDict.cs new file mode 100644 index 0000000000..df41613bcc --- /dev/null +++ b/Systems/Collections/SummonTagDebuffDict.cs @@ -0,0 +1,63 @@ +using System.Collections.Generic; +using CalamityMod.Buffs.Summon.Whips; +using CalamityMod.DataStructures; +using CalamityMod.Items.Accessories; +using CalamityMod.Items.Weapons.Summon; +using CalamityMod.Items.Weapons.Summon.Whips; +using Terraria.ID; +using Terraria.ModLoader; +using static Terraria.ModLoader.ModContent; + +namespace CalamityMod.Systems.Collections +{ + /// + /// A that contains a of all summon tag debuff's IDs and their associated SummonTag. + /// + public sealed class SummonTagDebuffDict : ModSystem + { + public static IDictionary Dict { get; private set; } + + public override void OnModLoad() + { + Dict = new Dictionary + { + { BuffID.BlandWhipEnemyDebuff, SummonTag.LeatherWhip }, + { BuffID.BoneWhipNPCDebuff, SummonTag.SpinalTap }, + { BuffID.CoolWhipNPCDebuff, SummonTag.CoolWhip }, + { BuffID.FlameWhipEnemyDebuff, SummonTag.Firecracker }, + { BuffID.MaceWhipNPCDebuff, SummonTag.MorningStar }, + { BuffID.RainbowWhipNPCDebuff, SummonTag.Kaleidoscope }, + { BuffID.ScytheWhipEnemyDebuff, SummonTag.DarkHarvest }, + { BuffID.SwordWhipNPCDebuff, SummonTag.Durendal }, + { BuffID.ThornWhipNPCDebuff, SummonTag.Snapthorn }, + { BuffType(), ArdorBlossomStar.SummonTag }, + { BuffType(), Cnidarian.SummonTag }, + { BuffType(), ProfanedSoulCrystal.SummonTag }, + { BuffType(), RottenMaw.SummonTag }, + { BuffType(), UnderBite.SummonTag }, + { BuffType(), AtlasMunitionsBeacon.SummonTag }, + { BuffType(), AberrantHorror.SummonTag } + }; + + } + + public override void Unload() + { + Dict?.Clear(); + Dict = null; + } + + /// + /// A shorthand method to obtain a SummonTag from its debuff. + /// + public static bool TryGet(int buffType, out SummonTag tag) + { + return Dict.TryGetValue(buffType, out tag); + } + + public static bool Add(int buffType, SummonTag tag) + { + return Dict.TryAdd(buffType, tag); + } + } +}