using System; using System.Linq; using CalamityMod.Items.Materials; using CalamityMod.Projectiles.Magic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; using Terraria; using Terraria.Audio; using Terraria.ID; using Terraria.ModLoader; using static CalamityMod.CalamityUtils; namespace CalamityMod.Items.Weapons.Magic { [LegacyName("WulfrumStaff")] public class WulfrumProsthesis : ModItem, IHideFrontArm, ILocalizedModType { public new string LocalizationCategory => "Items.Weapons.Magic"; public static readonly SoundStyle ShootSound = new("CalamityMod/Sounds/Item/WulfrumProsthesisShoot") { PitchVariance = 0.1f, Volume = 0.55f }; public static readonly SoundStyle HitSound = new("CalamityMod/Sounds/Item/WulfrumProsthesisHit") { PitchVariance = 0.1f, Volume = 0.75f , MaxInstances = 3}; public static readonly SoundStyle SuckSound = new("CalamityMod/Sounds/Item/WulfrumProsthesisSucc") { Volume = 0.5f }; public static readonly SoundStyle SuckStopSound = new("CalamityMod/Sounds/Item/WulfrumProsthesisSuccStop") { Volume = 0.5f }; internal static Asset RealSprite; public override string Texture => "CalamityMod/Items/Weapons/Magic/WulfrumProsthesis_Arm"; public override void SetDefaults() { Item.damage = 18; Item.DamageType = DamageClass.Magic; Item.mana = 5; Item.width = 34; Item.height = 42; Item.useTime = 24; Item.useAnimation = 24; Item.useStyle = ItemUseStyleID.Shoot; Item.noMelee = true; Item.knockBack = 3; Item.value = CalamityGlobalItem.Rarity1BuyPrice; Item.rare = ItemRarityID.Blue; Item.UseSound = ShootSound; Item.autoReuse = true; Item.shoot = ModContent.ProjectileType(); Item.shootSpeed = 18f; Item.holdStyle = 16; //Custom hold style } public override void HoldItem(Player player) { player.Calamity().mouseWorldListener = true; player.Calamity().rightClickListener = true; } public override bool CanUseItem(Player player) => !Main.projectile.Any(n => n.active && n.owner == player.whoAmI && n.type == ModContent.ProjectileType()); public override bool AltFunctionUse(Player player) => true; public override void ModifyShootStats(Player player, ref Vector2 position, ref Vector2 velocity, ref int type, ref int damage, ref float knockback) { if (player.altFunctionUse == 2) type = ModContent.ProjectileType(); } public override void ModifyManaCost(Player player, ref float reduce, ref float mult) { if (player.altFunctionUse == 2) mult = 0f; } public override void UseAnimation(Player player) { Item.UseSound = ShootSound; if (player.altFunctionUse == 2) Item.UseSound = null; } public void SetItemInHand(Player player, Rectangle heldItemFrame) { //Make the player face where they're aiming. if (player.Calamity().mouseWorld.X > player.Center.X) { player.ChangeDir(1); } else { player.ChangeDir(-1); } float animProgress = 1 - player.itemTime / (float)player.itemTimeMax; //Default Vector2 itemPosition = player.MountedCenter + new Vector2(-2f * player.direction, -1f * player.gravDir); float itemRotation = (player.Calamity().mouseWorld - itemPosition).ToRotation(); //Adjust for animation if (animProgress < 0.7f) itemPosition -= itemRotation.ToRotationVector2() * (1 - (float)Math.Pow(1 - (0.7f - animProgress) / 0.7f, 4)) * 4f; if (animProgress < 0.4f) itemRotation += -0.45f * (float)Math.Pow((0.4f - animProgress) / 0.4f, 2) * player.direction * player.gravDir; //Shakezzz if (player.itemTime == 1 && Main.projectile.Any(n => n.active && n.owner == player.whoAmI && n.type == ModContent.ProjectileType())) { itemPosition += Main.rand.NextVector2Circular(2f, 2f); } Vector2 itemSize = new Vector2(28, 14); Vector2 itemOrigin = new Vector2(-8, 0); CleanHoldStyle(player, itemRotation, itemPosition, itemSize, itemOrigin, true); } public override void HoldStyle(Player player, Rectangle heldItemFrame) => SetItemInHand(player, heldItemFrame); public override void UseStyle(Player player, Rectangle heldItemFrame) => SetItemInHand(player, heldItemFrame); public override bool PreDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale) { if (RealSprite == null) RealSprite = ModContent.Request("CalamityMod/Items/Weapons/Magic/WulfrumProsthesis"); Texture2D properSprite = RealSprite.Value; spriteBatch.DrawNewInventorySprite(properSprite, new Vector2(28f, 14f), position, drawColor, origin, scale, new Vector2(0, -6f)); return false; } public override bool PreDrawInWorld(SpriteBatch spriteBatch, Color lightColor, Color alphaColor, ref float rotation, ref float scale, int whoAmI) { if (RealSprite == null) RealSprite = ModContent.Request("CalamityMod/Items/Weapons/Magic/WulfrumProsthesis"); Texture2D properSprite = RealSprite.Value; spriteBatch.Draw(properSprite, Item.position - Main.screenPosition, null, lightColor, rotation, properSprite.Size() / 2f, scale, 0, 0); return false; } public override void AddRecipes() { CreateRecipe(). AddIngredient(10). AddIngredient(). AddTile(TileID.Anvils). Register(); } } public class WulfrumProsthesisPlayer : ModPlayer { public bool ManaDrainActive = false; public override void UpdateDead() { ManaDrainActive = false; } public override void PostUpdateMiscEffects() { if (ManaDrainActive) { Player.manaRegenBonus = 35; Player.manaRegenDelay = 0; Player.manaRegenBuff = true; } ManaDrainActive = false; } } }