Added Trident of the Sunken
This commit is contained in:
@@ -0,0 +1,181 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Terraria;
|
||||
using Terraria.Audio;
|
||||
using Terraria.DataStructures;
|
||||
using Terraria.ID;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace ForgottenWawiTech.Content.Projectiles.TridentOfTheSunken
|
||||
{
|
||||
public class TridentOfTheSunkenHoldout : ModProjectile
|
||||
{
|
||||
private const int MaxChargeTime = 60;
|
||||
private const int RequiredChargeTime = 60;
|
||||
// Slight offsets so the player grips the center of the sprite instead of the trident hovering ahead.
|
||||
private const float HoldoutForwardOffset = 12f;
|
||||
private const float HoldoutVerticalOffset = -6f;
|
||||
|
||||
private ref float Charge => ref Projectile.ai[0];
|
||||
private ref float HasFired => ref Projectile.ai[1];
|
||||
|
||||
public override string Texture => "ForgottenWawiTech/Content/Items/Weapons/Magic/TridentOfTheSunken";
|
||||
|
||||
public override void SetDefaults()
|
||||
{
|
||||
Projectile.width = 30;
|
||||
Projectile.height = 256;
|
||||
Projectile.friendly = false;
|
||||
Projectile.hostile = false;
|
||||
Projectile.penetrate = -1;
|
||||
Projectile.tileCollide = false;
|
||||
Projectile.ignoreWater = true;
|
||||
}
|
||||
|
||||
public override void AI()
|
||||
{
|
||||
Player player = Main.player[Projectile.owner];
|
||||
int tridentType = ModContent.ItemType<Items.Weapons.Magic.TridentOfTheSunken>();
|
||||
if (player.dead || player.HeldItem.type != tridentType)
|
||||
{
|
||||
Projectile.Kill();
|
||||
return;
|
||||
}
|
||||
|
||||
Vector2 handPosition = player.RotatedRelativePoint(player.MountedCenter, true);
|
||||
player.heldProj = Projectile.whoAmI;
|
||||
player.itemAnimation = player.itemTime = 2;
|
||||
|
||||
Vector2 aim = Projectile.velocity;
|
||||
if (Main.myPlayer == player.whoAmI)
|
||||
{
|
||||
aim = Main.MouseWorld - handPosition;
|
||||
if (aim.LengthSquared() < 0.01f)
|
||||
{
|
||||
aim = new Vector2(player.direction, 0f);
|
||||
}
|
||||
aim.Normalize();
|
||||
|
||||
player.ChangeDir(aim.X >= 0f ? 1 : -1);
|
||||
Projectile.velocity = aim;
|
||||
}
|
||||
|
||||
Vector2 anchorOffset = new Vector2(player.direction * HoldoutForwardOffset, HoldoutVerticalOffset * player.gravDir);
|
||||
Projectile.Center = handPosition + anchorOffset;
|
||||
|
||||
Projectile.direction = player.direction;
|
||||
Projectile.spriteDirection = player.direction;
|
||||
Projectile.rotation = 0f;
|
||||
|
||||
if (player.channel)
|
||||
{
|
||||
Charge = MathHelper.Clamp(Charge + 1f, 0f, MaxChargeTime);
|
||||
if (Charge == RequiredChargeTime)
|
||||
{
|
||||
ReadyFeedback(player);
|
||||
}
|
||||
else if (Charge % 15f == 0f)
|
||||
{
|
||||
SoundEngine.PlaySound(SoundID.Item15 with { Volume = 0.3f }, player.Center);
|
||||
}
|
||||
}
|
||||
else if (HasFired == 0f)
|
||||
{
|
||||
if (Main.myPlayer == player.whoAmI && Charge >= RequiredChargeTime)
|
||||
{
|
||||
FireProjectile(player, handPosition);
|
||||
}
|
||||
else
|
||||
{
|
||||
CancelCharge(player);
|
||||
}
|
||||
}
|
||||
|
||||
Projectile.timeLeft = 2;
|
||||
}
|
||||
|
||||
public override void Kill(int timeLeft)
|
||||
{
|
||||
if (HasFired == 0f && Main.player[Projectile.owner] is Player player && player.active && !player.dead)
|
||||
{
|
||||
Vector2 handPosition = player.RotatedRelativePoint(player.MountedCenter, true);
|
||||
if (Main.myPlayer == player.whoAmI && Charge >= RequiredChargeTime)
|
||||
{
|
||||
FireProjectile(player, handPosition);
|
||||
}
|
||||
else if (Charge < RequiredChargeTime)
|
||||
{
|
||||
CancelCharge(player, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void FireProjectile(Player player, Vector2 spawnPosition)
|
||||
{
|
||||
if (Charge < RequiredChargeTime)
|
||||
{
|
||||
CancelCharge(player);
|
||||
return;
|
||||
}
|
||||
|
||||
Vector2 aim = Projectile.velocity;
|
||||
if (aim.LengthSquared() < 0.01f)
|
||||
{
|
||||
aim = new Vector2(player.direction, 0f);
|
||||
}
|
||||
aim.Normalize();
|
||||
|
||||
float chargeProgress = MathHelper.Clamp(Charge / MaxChargeTime, 0f, 1f);
|
||||
float speed = MathHelper.Lerp(7f, 12f, chargeProgress);
|
||||
|
||||
int baseDamage = player.GetWeaponDamage(player.HeldItem);
|
||||
int damage = (int)(baseDamage * MathHelper.Lerp(1f, 1.6f, chargeProgress));
|
||||
float knockBack = player.GetWeaponKnockback(player.HeldItem, player.HeldItem.knockBack) * MathHelper.Lerp(1f, 1.2f, chargeProgress);
|
||||
|
||||
IEntitySource source = player.GetSource_ItemUse(player.HeldItem);
|
||||
int proj = Projectile.NewProjectile(source, spawnPosition, aim * speed, ModContent.ProjectileType<TridentOfTheSunkenShot>(), damage, knockBack, player.whoAmI, chargeProgress);
|
||||
|
||||
if (Main.projectile.IndexInRange(proj))
|
||||
{
|
||||
Main.projectile[proj].localAI[0] = chargeProgress;
|
||||
}
|
||||
|
||||
SoundEngine.PlaySound(SoundID.Item72 with { Volume = 0.8f }, spawnPosition);
|
||||
HasFired = 1f;
|
||||
Projectile.netUpdate = true;
|
||||
Projectile.Kill();
|
||||
}
|
||||
|
||||
private void ReadyFeedback(Player player)
|
||||
{
|
||||
if (Main.dedServ)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SoundEngine.PlaySound(SoundID.Item33 with { Volume = 0.6f, Pitch = -0.1f }, Projectile.Center);
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
Vector2 velocity = Main.rand.NextVector2Circular(1.2f, 1.2f) * Main.rand.NextFloat(0.8f, 1.4f);
|
||||
Dust dust = Dust.NewDustDirect(Projectile.Center - new Vector2(5f, 85f), 16, 16, DustID.BlueFairy, velocity.X, velocity.Y, 100, default, 1.1f);
|
||||
dust.noGravity = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void CancelCharge(Player player, bool killProjectile = true)
|
||||
{
|
||||
if (HasFired != 0f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
HasFired = -1f;
|
||||
Projectile.netUpdate = true;
|
||||
SoundEngine.PlaySound(SoundID.MenuClose with { Volume = 0.6f }, player.Center);
|
||||
if (killProjectile && Projectile.active)
|
||||
{
|
||||
Projectile.Kill();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user