Files
ForgottenWawiTech/Content/Items/Weapons/Magic/BeamAttackWand.cs
T

88 lines
3.6 KiB
C#

using ForgottenWawiTech.Content.Projectiles;
using ForgottenWawiTech.Content.Players;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using ForgottenWawiTech.Content.Rarities;
namespace ForgottenWawiTech.Content.Items.Weapons.Magic
{
public class BeamAttackWand : ModItem
{
public override void SetDefaults()
{
Item.width = 32;
Item.height = 32;
Item.useStyle = ItemUseStyleID.Swing;
Item.useAnimation = 40; // frames the swing lasts
Item.useTime = 40; // one use per full animation
Item.autoReuse = true;
Item.UseSound = SoundID.Item1;
Item.damage = 10;
Item.knockBack = 4.5f;
Item.DamageType = DamageClass.Magic; // treat beams as melee for synergy
Item.rare = ModContent.RarityType<FWTDeveloperItem>();
Item.value = Item.buyPrice(silver: 50);
Item.shoot = ModContent.ProjectileType<BeamAttackWandBeam>();
Item.shootSpeed = 12f; // base speed of beams
Item.noMelee = false;
Item.mana = 3;
}
// No recipe: obtained from Eye of Cthulhu treasure bag (see GlobalItem loot class)
public override void HoldItem(Player player)
{
// Emit beams only while the item is mid-swing
if (player.itemAnimation > 0 && player.HeldItem.type == Item.type && player.whoAmI == Main.myPlayer)
{
var modPlayer = player.GetModPlayer<BeamAttackWandPlayer>();
modPlayer.BeamEmissionTimer--;
if (modPlayer.BeamEmissionTimer <= 0)
{
// Kirby-style beam: a sweeping whip that leaves a multi-beam arc.
// We'll spawn several beams at once in a tight angular spread around a smoothed central swing rotation.
float targetRot = player.itemRotation + (player.direction == -1 ? MathHelper.Pi : 0f);
if (modPlayer.LastBeamRot == 0f)
modPlayer.LastBeamRot = targetRot;
// Smooth aggressively so the arc persists briefly (lower factor = larger persistence)
float smoothedRot = modPlayer.LastBeamRot + MathHelper.WrapAngle(targetRot - modPlayer.LastBeamRot) * 0.25f;
modPlayer.LastBeamRot = smoothedRot;
// Determine swing progress (0..1) to slightly widen arc near middle of swing
float swingProgress = 1f - (player.itemAnimation / (float)player.itemAnimationMax);
// Arc width scales up mid-swing then back down
float baseArc = 0.30f; // radians total small arc
float arcWidth = baseArc * (float)(1.0 - System.Math.Pow(2 * swingProgress - 1, 2)); // bell curve widen
int beamsThisBurst = 4; // number of simultaneous beams
int beamDamage = (int)(Item.damage * 0.45f); // slight reduction since multiple per tick
for (int i = 0; i < beamsThisBurst; i++)
{
// Evenly distribute within arc centered on smoothedRot
float lerp = beamsThisBurst == 1 ? 0f : i / (float)(beamsThisBurst - 1);
float offset = MathHelper.Lerp(-arcWidth * 0.5f, arcWidth * 0.5f, lerp);
float beamRot = smoothedRot + offset;
Vector2 dir = beamRot.ToRotationVector2();
if (dir.HasNaNs()) dir = new Vector2(player.direction, 0f);
dir = dir.SafeNormalize(new Vector2(player.direction, 0f));
// Stagger spawn distance to create a whip chain illusion (front beams slightly further)
float distance = 14f + 3f * i;
Vector2 spawnPos = player.Center + dir * distance + new Vector2(0f, -4f);
Vector2 velocity = dir * Item.shootSpeed * (1f + i * 0.05f); // slight incremental speed
Projectile.NewProjectile(player.GetSource_ItemUse(Item), spawnPos, velocity,
Item.shoot, beamDamage, Item.knockBack, player.whoAmI);
}
// Emit burst every 3 ticks to keep DPS reasonable while visually dense
modPlayer.BeamEmissionTimer = 3;
}
}
}
}
}