Rijam_RijamsMod/Items/Weapons/Magic/Cresceptre.cs
using RijamsMod.Projectiles.Magic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Microsoft.Xna.Framework;
using Terraria.DataStructures;
using Microsoft.Xna.Framework.Graphics;
using ReLogic.Content;

namespace RijamsMod.Items.Weapons.Magic
{
	public class Cresceptre : ModItem
	{
		public override void SetDefaults()
		{
			Item.damage = 45;
			Item.crit = 4;
			Item.noMelee = true;
			Item.DamageType = DamageClass.Magic;
			Item.mana = 15;
			Item.rare = ItemRarityID.Pink; //5
			Item.width = 64;
			Item.height = 64;
			Item.useTime = 13;
			Item.knockBack = 1;
			Item.UseSound = new(Mod.Name + "/Sounds/Item/Cresceptre") { PitchVariance = 0.05f, MaxInstances = 5 };
			if (!Main.dedServ) //Need to check if a server is running, otherwise it will break multiplayer
			{
				Item.GetGlobalItem<ItemUseGlow>().glowTexture = ModContent.Request<Texture2D>(Mod.Name + "/Items/GlowMasks/" + Name + "_Glow");

				var flash = Item.GetGlobalItem<WeaponAttackFlash>();
				flash.flashTexture = ModContent.Request<Texture2D>(Mod.Name + "/Items/GlowMasks/" + Name + "_Flash");
				flash.posOffsetXLeft = 12;
				flash.posOffsetXRight = -24;
				flash.posOffsetY = -12;
				flash.frameCount = 3;
				flash.frameRate = 3;
				flash.forceFirstFrame = true;
				flash.animationLoop = false;
			}
			Item.useStyle = ItemUseStyleID.Shoot;
			Item.shootSpeed = 12f;
			Item.useAnimation = 13;
			Item.autoReuse = true;
			Item.shoot = ModContent.ProjectileType<CresceptreSphere>();
			Item.value = Item.sellPrice(gold: 6);
		}
		public override Vector2? HoldoutOffset()
		{
			return new Vector2(-16, 0);
		}
		public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback)
		{
			Vector2 muzzleOffset = Vector2.Normalize(velocity) * 20f;
			float numberProjectiles = 2;// 2 shots
			float rotation = MathHelper.ToRadians(20);
			position += Vector2.Normalize(velocity) * 20f;

			for (int i = 0; i < numberProjectiles; i++)
			{
				Vector2 perturbedSpeed = velocity.RotatedBy(MathHelper.Lerp(-rotation, rotation, i / (numberProjectiles - 1))); // Watch out for dividing by 0 if there is only 1 projectile.
				if (Collision.CanHit(position, 0, 0, position + muzzleOffset, 0, 0))
				{
					position += muzzleOffset;
				}
				Projectile.NewProjectile(source, position, perturbedSpeed, type, damage, knockback, player.whoAmI);
			}
			return false;
		}

		public override void AddRecipes()
		{
			CreateRecipe()
				.AddRecipeGroup(RijamsModRecipes.GoldBars, 10)
				.AddIngredient(ItemID.CrystalShard, 5)
				.AddIngredient(ItemID.GoldDust, 5)
				.AddIngredient(ItemID.SoulofNight, 3)
				.AddTile(TileID.MythrilAnvil)
				.Register();
		}
	}
}
