diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index 9a7f318f0b..2b65d89652 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -191,6 +191,7 @@ namespace CalamityMod.CalPlayer public int armorPenetrationStat = 0; public float wingFlightTimeStat = 0f; public float jumpSpeedStat = 0f; + public int rageDamageStat = 0; public int adrenalineDamageStat = 0; public int adrenalineDRStat = 0; public int moveSpeedStat = 0; @@ -349,9 +350,8 @@ namespace CalamityMod.CalPlayer public int rageCombatFrames = 0; public static readonly int RageCombatDelayTime = CalamityUtils.SecondsToFrames(10); public static readonly int RageFadeTime = CalamityUtils.SecondsToFrames(30); - public static readonly double RageDamageBoost = 0.5D; // +50% - public static readonly float MinRageDR = 0.1f; // 10% DR - public static readonly float MaxRageDR = 0.2f; // 20% DR + public static readonly double DefaultRageDamageBoost = 0.5D; // +50% + public double RageDamageBoost = DefaultRageDamageBoost; #endregion #region Adrenaline @@ -481,6 +481,7 @@ namespace CalamityMod.CalPlayer public bool reducedPlagueDmg = false; public bool abaddon = false; public bool community = false; + public bool shatteredCommunity = false; public bool fleshTotem = false; public bool fleshTotemCooldown = false; public bool bloodPact = false; @@ -1338,6 +1339,9 @@ namespace CalamityMod.CalPlayer int integerTypeBoost = (int)(floatTypeBoost * 50f); player.statLifeMax2 += player.statLifeMax / 5 / 20 * integerTypeBoost; } + // Shattered Community gives the same max health boost as normal full-power Community (10%) + if (shatteredCommunity) + player.statLifeMax2 += (player.statLifeMax / 5 / 10) * 5; // Max health reductions if (crimEffigy) @@ -1539,6 +1543,7 @@ namespace CalamityMod.CalPlayer reducedPlagueDmg = false; abaddon = false; community = false; + shatteredCommunity = false; stressPills = false; laudanum = false; fleshTotem = false; @@ -1964,6 +1969,7 @@ namespace CalamityMod.CalPlayer rageModeActive = false; adrenalineModeActive = false; RageDuration = DefaultRageDuration; + RageDamageBoost = DefaultRageDamageBoost; lastProjectileHit = null; } @@ -4699,6 +4705,12 @@ namespace CalamityMod.CalPlayer CalamityPlayerOnHit.ItemLifesteal(player, mod, target, item, damage); CalamityPlayerOnHit.ItemOnHit(player, mod, item, damage, target.Center, crit, (target.damage > 5 || target.boss) && !target.SpawnedFromStatue); CalamityPlayerOnHit.NPCDebuffs(player, mod, target, item.melee, item.ranged, item.magic, item.summon, item.Calamity().rogue, false); + + // Shattered Community tracks all damage dealt with Rage Mode (ignoring dummies). + if (target.type == NPCID.TargetDummy || target.type == ModContent.NPCType()) + return; + if (rageModeActive && shatteredCommunity) + ShatteredCommunity.AccumulateRageDamage(player, this, damage); } #endregion @@ -4835,6 +4847,12 @@ namespace CalamityMod.CalPlayer CalamityPlayerOnHit.ProjLifesteal(player, mod, target, proj, damage, crit); CalamityPlayerOnHit.ProjOnHit(player, mod, proj, target.Center, crit, (target.damage > 5 || target.boss) && !target.SpawnedFromStatue); CalamityPlayerOnHit.NPCDebuffs(player, mod, target, proj.melee, proj.ranged, proj.magic, proj.IsSummon(), proj.Calamity().rogue, true); + + // Shattered Community tracks all damage dealt with Rage Mode (ignoring dummies). + if (target.type == NPCID.TargetDummy || target.type == ModContent.NPCType()) + return; + if (rageModeActive && shatteredCommunity) + ShatteredCommunity.AccumulateRageDamage(player, this, damage); } } #endregion @@ -7094,11 +7112,14 @@ namespace CalamityMod.CalPlayer if ((godSlayerDamage && damage <= 80) || damage < 1) damage = 1; - // Gain rage based on the amount of damage taken. Also set the Rage gain cooldown to prevent bizarre abuse cases. - if (CalamityWorld.revenge && CalamityConfig.Instance.Rippers && rageGainCooldown == 0) + // Shattered Community makes the player gain rage based on the amount of damage taken. + // Also set the Rage gain cooldown to prevent bizarre abuse cases. + if (CalamityWorld.revenge && CalamityConfig.Instance.Rippers && shatteredCommunity && rageGainCooldown == 0) { float HPRatio = (float)damage / player.statLifeMax2; - rage += rageMax * HPRatio; + // Damage to rage conversion is half as effective while Rage Mode is active. + float rageConversionRatio = rageModeActive ? 0.4f : 0.8f; + rage += rageMax * HPRatio * rageConversionRatio; rageGainCooldown = DefaultRageGainCooldown; // Rage capping is handled in MiscEffects } diff --git a/CalPlayer/CalamityPlayerMiscEffects.cs b/CalPlayer/CalamityPlayerMiscEffects.cs index 7f547cf76c..ba59b54fb8 100644 --- a/CalPlayer/CalamityPlayerMiscEffects.cs +++ b/CalPlayer/CalamityPlayerMiscEffects.cs @@ -294,27 +294,49 @@ namespace CalamityMod.CalPlayer // This is how much Rage will be changed by this frame. float rageDiff = 0; - // Draedon's Heart provides constant rage generation that scales with missing health. - if (modPlayer.draedonsHeart) + // If the player equips multiple rage generation accessories they get the max possible effect without stacking any of them. { - float percentMissingHealth = 1f - player.statLife / player.statLifeMax2; - float rageGainLerp = MathHelper.Lerp(DraedonsHeart.MinRagePerSecond, DraedonsHeart.MaxRagePerSecond, percentMissingHealth); - rageDiff += modPlayer.rageMax * rageGainLerp / 60f; + float rageGen = 0f; + + // Draedon's Heart provides constant rage generation that scales with missing health. + if (modPlayer.draedonsHeart) + { + float percentMissingHealth = 1f - player.statLife / player.statLifeMax2; + float rageGainLerp = MathHelper.Lerp(DraedonsHeart.MinRagePerSecond, DraedonsHeart.MaxRagePerSecond, percentMissingHealth); + float dhRageGen = modPlayer.rageMax * rageGainLerp / 60f; + if (rageGen < dhRageGen) + rageGen = dhRageGen; + } + // Shattered Community provides constant rage generation (stronger than Heart of Darkness). + if (modPlayer.shatteredCommunity) + { + float scRageGen = modPlayer.rageMax * ShatteredCommunity.RagePerSecond / 60f; + if (rageGen < scRageGen) + rageGen = scRageGen; + } + // Heart of Darkness grants constant rage generation. + else if (modPlayer.heartOfDarkness) + { + float hodRageGen = modPlayer.rageMax * HeartofDarkness.RagePerSecond / 60f; + if (rageGen < hodRageGen) + rageGen = hodRageGen; + } + + rageDiff += rageGen; } - // Heart of Darkness grants constant rage generation. - else if (modPlayer.heartOfDarkness) - rageDiff += modPlayer.rageMax * HeartofDarkness.RagePerSecond / 60f; // Holding Gael's Greatsword grants constant rage generation. if (modPlayer.heldGaelsLastFrame) rageDiff += modPlayer.rageMax * GaelsGreatsword.RagePerSecond / 60f; + bool rageFading = modPlayer.rageCombatFrames <= 0 && !modPlayer.heartOfDarkness && !modPlayer.shatteredCommunity; + // If Rage Mode is currently active, you smoothly lose all rage over the duration. if (modPlayer.rageModeActive) rageDiff -= modPlayer.rageMax / modPlayer.RageDuration; - // If out of combat and NOT using Heart of Darkness, Rage fades away. - else if (!modPlayer.rageModeActive && modPlayer.rageCombatFrames <= 0 && !modPlayer.heartOfDarkness) + // If out of combat and NOT using Heart of Darkness or Shattered Community, Rage fades away. + else if (!modPlayer.rageModeActive && rageFading) rageDiff -= modPlayer.rageMax / CalamityPlayer.RageFadeTime; // Apply the rage change and cap rage in both directions. @@ -2653,6 +2675,9 @@ namespace CalamityMod.CalPlayer player.moveSpeed += floatTypeBoost; flightTimeMult += floatTypeBoost; } + // Shattered Community gives the same wing time boost as normal Community + if (modPlayer.shatteredCommunity) + flightTimeMult += 0.15f; if (modPlayer.profanedCrystalBuffs && modPlayer.gOffense && modPlayer.gDefense) { @@ -3922,6 +3947,7 @@ namespace CalamityMod.CalPlayer (player.wereWolf ? 0.2f : 0f) + (player.jumpBoost ? 1.5f : 0f); modPlayer.jumpSpeedStat = trueJumpSpeedBoost * 20f; + modPlayer.rageDamageStat = (int)(100D * modPlayer.RageDamageBoost); modPlayer.adrenalineDamageStat = (int)(100D * modPlayer.GetAdrenalineDamage()); int extraAdrenalineDR = 0 + (modPlayer.adrenalineBoostOne ? 5 : 0) + diff --git a/Items/Accessories/ShatteredCommunity.cs b/Items/Accessories/ShatteredCommunity.cs new file mode 100644 index 0000000000..f697de0501 --- /dev/null +++ b/Items/Accessories/ShatteredCommunity.cs @@ -0,0 +1,237 @@ +using CalamityMod.CalPlayer; +using CalamityMod.Items.Materials; +using CalamityMod.World; +using Microsoft.Xna.Framework; +using System.Collections.Generic; +using System.Text; +using Terraria; +using Terraria.DataStructures; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.ModLoader.IO; + +namespace CalamityMod.Items.Accessories +{ + public class ShatteredCommunity : ModItem + { + // The percentage of a full Rage bar that is gained every second with the Shattered Community equipped. + public const float RagePerSecond = 0.02f; + private static readonly Color rarityColorOne = new Color(128, 62, 128); + private static readonly Color rarityColorTwo = new Color(245, 105, 245); + + private bool everInInventory = false; + + // Base level cost is 400,000 damage dealt while Rage is active. + // Each successive level costs (400,000 * level) MORE damage, so the total required goes up quadratically. + // Total required to reach level 60 is 732,000,000 damage dealt. + // This is within one order of magnitude of the integer limit, so relevant values are stored as longs. + private const long BaseLevelCost = 400000L; + private static long LevelCost(int level) => BaseLevelCost * level; + private static long CumulativeLevelCost(int level) => (BaseLevelCost / 2L) * level * (level + 1); + private const int MaxLevel = 60; + + internal int rageLevel = 0; + internal long totalRageDamage = 0L; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Shattered Community"); + Tooltip.SetDefault("Ruined by unknowable hatred, it still contains (most of) the power of The Community...\n" + + "Legendary Accessory\n" + + "You generate rage over time and rage does not fade away out of combat\n" + + "Taking damage gives rage, this effect is not hindered by your defensive stats\n" + + "While Rage Mode is active, taking damage gives only half as much rage\n" + + "Deal damage with Rage Mode to further empower your wrath\n"); + Main.RegisterItemAnimation(item.type, new DrawAnimationVertical(5, 5)); + } + + public override void SetDefaults() + { + item.width = 20; + item.height = 20; + item.accessory = true; + item.value = CalamityGlobalItem.RarityHotPinkBuyPrice; + item.rare = ItemRarityID.Red; + item.Calamity().customRarity = CalamityRarity.ItemSpecific; + } + + // Not overriding these Clones makes tooltips fail to function correctly due to HoverItem spaghetti. + public override ModItem Clone() + { + var clone = (ShatteredCommunity)base.Clone(); + clone.everInInventory = everInInventory; + clone.rageLevel = rageLevel; + clone.totalRageDamage = totalRageDamage; + return clone; + } + public override ModItem Clone(Item item) + { + var clone = (ShatteredCommunity)base.Clone(); + clone.everInInventory = everInInventory; + clone.rageLevel = rageLevel; + clone.totalRageDamage = totalRageDamage; + return clone; + } + + internal static Color GetRarityColor() => CalamityUtils.ColorSwap(rarityColorOne, rarityColorTwo, 3f); + + public override void UpdateAccessory(Player player, bool hideVisual) + { + CalamityPlayer modPlayer = player.Calamity(); + modPlayer.shatteredCommunity = true; + + // Shattered Community gives (mostly) the same boosts as normal Community + // It does not give melee speed or minion knockback, but always gives life regen (instead of only conditionally) + player.allDamage += 0.1f; + modPlayer.AllCritBoost(5); + player.statDefense += 10; + player.endurance += 0.05f; + player.lifeRegen += 2; + player.moveSpeed += 0.2f; + + // Shattered Community provides a stacking +1% Rage Mode damage per level. + modPlayer.RageDamageBoost += rageLevel * 0.01; + } + + // Community and Shattered Community are mutually exclusive + public override bool CanEquipAccessory(Player player, int slot) => !player.Calamity().community; + public override bool CanUseItem(Player player) => false; + + public override void UpdateInventory(Player player) + { + everInInventory = true; + } + + // Produces purple light while in the world. + public override void PostUpdate() + { + Vector3 lightColor = Main.essScale * new Vector3(0.1f, 0f, 0.6f); + Lighting.AddLight(item.Center, lightColor); + } + + internal static void AccumulateRageDamage(Player player, CalamityPlayer mp, long damage) + { + if (!mp.shatteredCommunity) + return; + // Static context, so the item ID has to be retrieved from TML. + int thisItemID = ModContent.ItemType(); + ShatteredCommunity sc = null; + + // First, find the Shattered Community in the player's inventory. + // slots 3, 4, 5, 6, 7, 8, 9 are valid non-vanity accessories + for (int i = 3; i <= 9; ++i) + { + Item acc = player.armor[i]; + if (acc.type == thisItemID) + sc = acc.modItem as ShatteredCommunity; + } + + // Safety check in case for some reason the equipped Shattered Community isn't found. + if (sc is null) + return; + + // Actually accumulate the damage. + sc.totalRageDamage += damage; + + // Level up if applicable. + if (sc.totalRageDamage > CumulativeLevelCost(sc.rageLevel + 1)) + { + ++sc.rageLevel; + sc.LevelUpEffects(player); + } + } + + private void LevelUpEffects(Player player) + { + // TODO -- it should probably do something fancy involving dust or whatever + } + + public override void ModifyTooltips(List tooltips) + { + // Shattered Community hides its full tooltip when viewed via Recipe Browser or similar. + // Instead, it notifies the player that it must be crafted with a full-power Community. + // Once it has entered a player's inventory, it permanently behaves normally. + if (!everInInventory) + { + tooltips.RemoveAll(line => line.Name != "Tooltip0" && line.Name != "Tooltip1" && line.Name != "Tooltip2" && line.Name.StartsWith("Tooltip")); + tooltips.Find(line => line.Name == "Tooltip2").text = "Must be crafted with a fully powered Community"; + return; + } + + // Stat tooltips are added dynamically. + StringBuilder sb = new StringBuilder(256); + + // Line 6: Current level + sb.Append("Current level: "); + sb.Append(rageLevel); + sb.Append(" (+"); + sb.Append(rageLevel); + sb.Append("% Rage Mode damage)"); + tooltips.Add(new TooltipLine(mod, "Tooltip6", sb.ToString())); + sb.Clear(); + + if (rageLevel < MaxLevel) + { + long progressToNextLevel = totalRageDamage - CumulativeLevelCost(rageLevel); + long totalToNextLevel = LevelCost(rageLevel + 1); + double ratio = (double)progressToNextLevel / totalToNextLevel; + string percent = (100D * ratio).ToString("0.00"); + + // Line 7: Progress to next level + sb.Append("Progress to next level: "); + sb.Append(percent); + sb.Append('%'); + tooltips.Add(new TooltipLine(mod, "Tooltip7", sb.ToString())); + sb.Clear(); + } + + // Line 8: Total damage dealt + sb.Append("Total Rage Mode damage: "); + sb.Append(totalRageDamage); + tooltips.Add(new TooltipLine(mod, "Tooltip8", sb.ToString())); + } + + public override TagCompound Save() + { + TagCompound tag = new TagCompound + { + { "real", everInInventory }, + { "level", rageLevel }, + { "totalDamage", totalRageDamage } + }; + return tag; + } + + public override void Load(TagCompound tag) + { + everInInventory = tag.GetBool("real"); + rageLevel = tag.GetInt("level"); + totalRageDamage = tag.GetLong("totalDamage"); + } + + 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/ShatteredCommunity.png b/Items/Accessories/ShatteredCommunity.png new file mode 100644 index 0000000000..3d24764cc2 Binary files /dev/null and b/Items/Accessories/ShatteredCommunity.png differ diff --git a/Items/Accessories/StatMeter.cs b/Items/Accessories/StatMeter.cs index 240d9e2c1a..1687a441a6 100644 --- a/Items/Accessories/StatMeter.cs +++ b/Items/Accessories/StatMeter.cs @@ -77,6 +77,7 @@ namespace CalamityMod.Items.Accessories // Only append rippers stats in Rev+, if rippers are enabled. if (CalamityWorld.revenge && CalamityConfig.Instance.Rippers) { + sb.Append("Rage Damage Boost: ").Append(modPlayer.rageDamageStat).Append("%\n"); sb.Append("Adrenaline Damage Boost: ").Append(modPlayer.adrenalineDamageStat) .Append("% | Adrenaline DR Boost: ").Append(modPlayer.adrenalineDRStat) .Append("%\n\n"); diff --git a/Items/Accessories/TheCommunity.cs b/Items/Accessories/TheCommunity.cs index aaf8fde348..cf6b34a0c4 100644 --- a/Items/Accessories/TheCommunity.cs +++ b/Items/Accessories/TheCommunity.cs @@ -1,6 +1,7 @@ using CalamityMod.CalPlayer; using Terraria; using Terraria.DataStructures; +using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Items.Accessories @@ -26,7 +27,7 @@ namespace CalamityMod.Items.Accessories item.width = 20; item.height = 20; item.value = CalamityGlobalItem.Rarity7BuyPrice; - item.rare = 7; + item.rare = ItemRarityID.Lime; item.accessory = true; item.Calamity().customRarity = CalamityRarity.Rainbow; } @@ -36,5 +37,8 @@ namespace CalamityMod.Items.Accessories CalamityPlayer modPlayer = player.Calamity(); modPlayer.community = true; } - } + + // Community and Shattered Community are mutually exclusive + public override bool CanEquipAccessory(Player player, int slot) => !player.Calamity().shatteredCommunity; + } } diff --git a/Items/CalamityGlobalItem.cs b/Items/CalamityGlobalItem.cs index fec4382501..99bdf57e1a 100644 --- a/Items/CalamityGlobalItem.cs +++ b/Items/CalamityGlobalItem.cs @@ -1147,6 +1147,8 @@ namespace CalamityMod.Items tt2.overrideColor = Judgement.GetSyncedLightColor(); if (item.type == ModContent.ItemType()) tt2.overrideColor = new Color(0.34f, 0.34f + 0.66f * Main.DiscoG / 255f, 0.34f + 0.5f * Main.DiscoG / 255f); + if (item.type == ModContent.ItemType()) + tt2.overrideColor = ShatteredCommunity.GetRarityColor(); if (item.type == ModContent.ItemType()) tt2.overrideColor = CalamityUtils.ColorSwap(new Color(255, 166, 0), new Color(25, 250, 25), 4f); //alternates between emerald green and amber (BanditHueh) if (item.type == ModContent.ItemType()) diff --git a/Utilities/CalamityUtils.cs b/Utilities/CalamityUtils.cs index 140298da2d..167f8793a6 100644 --- a/Utilities/CalamityUtils.cs +++ b/Utilities/CalamityUtils.cs @@ -173,8 +173,7 @@ namespace CalamityMod } else if (mp.rageModeActive) { - double rageBoost = CalamityPlayer.RageDamageBoost; // other effects forthcoming - damageMult += rageBoost; + damageMult += mp.RageDamageBoost; } else if (mp.adrenalineModeActive) damageMult += mp.GetAdrenalineDamage();