Files
CalamityModPublic/Projectiles/Melee/PhosphorescentGauntletPunches.cs
T
Ozzatron 72bb69852a 1 - There is now a Utility function to give players immunity frames. Immunity frames should not be given to players any other way.
2 - Gael's Greatsword right click parry removed.
3 - Removed Determination Breaker.
4 - Shield slam iframes normalized. Ornate Shield and Plaguebringer set give 4. Asgard's Valor line gives 6.
5 - Shield of Cthulhu gives 6 iframes and 6 no-collide frames instead of 10 no-collide frames.
6 - Shield of Cthulhu can't cause you to get double-hit anymore.
7 - Calamity-granted iframes will never cause the player to get double-hit.
8 - Solar Flare Armor set bonus now has a base damage of 400. Its spawned explosion now has the same damage and scales with melee stats.
9 - Solar Flare Armor set bonus now gives 12 iframes.
10 - Solar Flare Armor set bonus can't cause you to get double-hit anymore.
11 - Exo Gladius on-hit gives 3 iframes.
12 - Lucrecia (and its projectiles) on-hit give 5 iframes.
13 - Phosphorescent Gauntlet on-hit gives 15 iframes.
14 - Cosmic Plushie explicitly removes all your iframes immediately upon stabbing you.
2021-11-11 18:50:12 -05:00

175 lines
5.6 KiB
C#

using CalamityMod.DataStructures;
using CalamityMod.Dusts;
using CalamityMod.Items.Weapons.Melee;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Melee
{
public class PhosphorescentGauntletPunches : ModProjectile
{
public Player Owner => Main.player[projectile.owner];
public bool HasPerformedLunge
{
get => projectile.ai[0] == 1f;
set
{
int newValue = value.ToInt();
if (projectile.ai[0] != newValue)
{
projectile.ai[0] = newValue;
projectile.netUpdate = true;
}
}
}
public ref float Time => ref projectile.ai[1];
public const float LungeSpeed = 19f;
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Punch");
Main.projFrames[projectile.type] = 14;
}
public override void SetDefaults()
{
projectile.scale = 1.6f;
projectile.width = projectile.height = (int)(projectile.scale * 60);
projectile.friendly = true;
projectile.penetrate = -1;
projectile.tileCollide = false;
projectile.melee = true;
projectile.ownerHitCheck = true;
projectile.usesLocalNPCImmunity = true;
projectile.localNPCHitCooldown = 12;
projectile.frameCounter = 0;
projectile.Calamity().trueMelee = true;
}
#region AI
public override void AI()
{
if (!HasPerformedLunge)
PerformLunge();
Vector2 topLeft = projectile.Center + projectile.velocity.RotatedBy(-MathHelper.PiOver2) * 40f;
Vector2 topRight = projectile.Center + projectile.velocity.RotatedBy(MathHelper.PiOver2) * 40f;
if (Time >= 8f && !Collision.CanHitLine(topLeft, 8, 8, topRight, 8, 8))
ReelBack();
HandleProjectileVisuals();
HandlePositioning();
Time++;
}
internal void PerformLunge()
{
if (Main.myPlayer != projectile.owner)
return;
Owner.velocity = projectile.velocity.SafeNormalize(Vector2.UnitX * Owner.direction) * LungeSpeed;
HasPerformedLunge = true;
}
internal void ReelBack()
{
Owner.GiveIFrames(PhosphorescentGauntlet.OnHitIFrames);
// Create some visual effects.
if (!Main.dedServ)
{
Vector2 topLeft = projectile.Center + projectile.velocity.RotatedBy(-MathHelper.PiOver2) * 40f;
Vector2 top = projectile.Center + projectile.velocity * 70f;
Vector2 topRight = projectile.Center + projectile.velocity.RotatedBy(MathHelper.PiOver2) * 40f;
foreach (Vector2 spawnPosition in new BezierCurve(topLeft, top, topRight).GetPoints(50))
{
Dust sulphurousAcid = Dust.NewDustPerfect(spawnPosition + projectile.velocity * 16f, (int)CalamityDusts.SulfurousSeaAcid);
sulphurousAcid.velocity = projectile.velocity * 4f;
sulphurousAcid.noGravity = true;
sulphurousAcid.scale = 1.2f;
}
}
if (Main.myPlayer != projectile.owner)
return;
// Reel back after collision.
Owner.velocity = Vector2.Reflect(Owner.velocity.SafeNormalize(Vector2.Zero), projectile.velocity.SafeNormalize(Vector2.Zero)) * Owner.velocity.Length();
// Create on-hit tile dust.
Collision.HitTiles(projectile.position, projectile.velocity, projectile.width + 16, projectile.height + 16);
projectile.Kill();
}
internal static void GenerateDustOnOwnerHand(Player player)
{
if (Main.dedServ)
return;
Vector2 handOffset = Main.OffsetsPlayerOnhand[player.bodyFrame.Y / 56] * 2f;
if (player.direction != 1)
handOffset.X = player.bodyFrame.Width - handOffset.X;
if (player.gravDir != 1f)
handOffset.Y = player.bodyFrame.Height - handOffset.Y;
handOffset -= new Vector2(player.bodyFrame.Width - player.width, player.bodyFrame.Height - player.height) / 2f;
Vector2 rotatedHandPosition = player.RotatedRelativePoint(player.position + handOffset, true);
for (int i = 0; i < 4; i++)
{
Dust dust = Dust.NewDustDirect(player.Center, 0, 0, (int)CalamityDusts.SulfurousSeaAcid, 0f, 0f, 150, default, 1.3f);
dust.position = rotatedHandPosition;
dust.velocity = Vector2.Zero;
dust.noGravity = true;
dust.fadeIn = 1f;
dust.velocity += player.velocity;
if (Main.rand.NextBool(2))
{
dust.position += Utils.RandomVector2(Main.rand, -4f, 4f);
dust.scale += Main.rand.NextFloat();
}
}
}
internal void HandleProjectileVisuals()
{
float velocityAngle = projectile.velocity.ToRotation();
projectile.rotation = velocityAngle + MathHelper.Pi;
projectile.frameCounter++;
if (projectile.frameCounter % 3 == 2)
{
projectile.frame++;
// Die at the end of the final punch.
if (projectile.frame >= Main.projFrames[projectile.type])
projectile.Kill();
}
}
internal void HandlePositioning()
{
projectile.Center = Owner.RotatedRelativePoint(Owner.MountedCenter);
projectile.Center += projectile.velocity.SafeNormalize(Vector2.UnitX * Owner.direction) * 30f;
}
#endregion
#region Drawing
// Manual drawing is used to correct the origin of the projectile when drawn.
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
{
Texture2D punchTexture = ModContent.GetTexture(Texture);
Rectangle frame = punchTexture.Frame(1, Main.projFrames[projectile.type], 0, projectile.frame);
Vector2 origin = frame.Size() * 0.5f;
SpriteEffects directionEffect = projectile.spriteDirection == -1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
spriteBatch.Draw(punchTexture, projectile.Center - Main.screenPosition, frame, lightColor, projectile.rotation, origin, projectile.scale, directionEffect, 0f);
return false;
}
#endregion
#region NPC Hit Collision Logic
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) => ReelBack();
#endregion
}
}