using CalamityMod.Buffs.DamageOverTime; using CalamityMod.CalPlayer; using CalamityMod.Items.Materials; using CalamityMod.NPCs; using CalamityMod.Projectiles.Melee; using Microsoft.Xna.Framework; using Terraria; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Items.Weapons.Melee { public class AnarchyBlade : ModItem { private static int BaseDamage = 110; public override void SetStaticDefaults() { DisplayName.SetDefault("Anarchy Blade"); Tooltip.SetDefault("The lower your life the more damage this blade does\n" + "Your hits will generate a large explosion\n" + "If you're below 50% life your hits have a chance to instantly kill regular enemies"); } public override void SetDefaults() { item.width = 94; item.damage = BaseDamage; item.melee = true; item.useAnimation = 19; item.useTime = 19; item.useTurn = true; item.useStyle = 1; item.knockBack = 7.5f; item.UseSound = SoundID.Item1; item.autoReuse = true; item.height = 100; item.value = Item.buyPrice(0, 80, 0, 0); item.rare = 8; } public override void AddRecipes() { ModRecipe recipe = new ModRecipe(mod); recipe.AddIngredient(ModContent.ItemType(), 5); recipe.AddIngredient(ModContent.ItemType(), 3); recipe.AddIngredient(ItemID.BrokenHeroSword); recipe.AddTile(TileID.MythrilAnvil); recipe.SetResult(this); recipe.AddRecipe(); } public override void MeleeEffects(Player player, Rectangle hitbox) { if (Main.rand.NextBool(3)) { int dust = Dust.NewDust(new Vector2(hitbox.X, hitbox.Y), hitbox.Width, hitbox.Height, 235); } } // Gains 10% of missing health as base damage. public override void ModifyWeaponDamage(Player player, ref float add, ref float mult, ref float flat) { int lifeAmount = player.statLifeMax2 - player.statLife; flat += lifeAmount * 0.1f * player.meleeDamage; } public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit) { Projectile.NewProjectile(target.Center.X, target.Center.Y, 0f, 0f, ModContent.ProjectileType(), (int)((float)item.damage * player.meleeDamage), knockback, Main.myPlayer); target.AddBuff(ModContent.BuffType(), 300); if (player.statLife < (player.statLifeMax2 * 0.5f) && Main.rand.NextBool(5)) { if (!CalamityPlayer.areThereAnyDamnBosses && CalamityGlobalNPC.ShouldAffectNPC(target)) { target.life = 0; target.HitEffect(0, 10.0); target.active = false; target.NPCLoot(); } } } } }