Start on prism chainsaw
This commit is contained in:
1 parent
a81e7665e1
commit
d9a86e1873
7 files changed
+340
No files matched your search
@@ -0,0 +1,47 @@
|
||||
using CalamityMod.Projectiles.Melee;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Terraria;
|
||||
using Terraria.ID;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Items.Weapons.Melee
|
||||
{
|
||||
public class PrismSaw : ModItem
|
||||
{
|
||||
public override void SetStaticDefaults()
|
||||
{
|
||||
DisplayName.SetDefault("Prism Saw");
|
||||
}
|
||||
|
||||
public override void SetDefaults()
|
||||
{
|
||||
item.height = 134;
|
||||
item.width = 54;
|
||||
item.damage = 3781;
|
||||
item.melee = true;
|
||||
item.noMelee = true;
|
||||
item.noUseGraphic = true;
|
||||
item.channel = true;
|
||||
item.useStyle = ItemUseStyleID.HoldingOut;
|
||||
item.useTime = 5;
|
||||
item.useAnimation = 25;
|
||||
item.knockBack = 12f;
|
||||
item.autoReuse = false;
|
||||
item.value = CalamityGlobalItem.RarityVioletBuyPrice;
|
||||
item.rare = ItemRarityID.Red;
|
||||
item.shoot = ModContent.ProjectileType<PrismSawProjectile>();
|
||||
item.shootSpeed = 1f;
|
||||
item.Calamity().customRarity = CalamityRarity.Violet;
|
||||
}
|
||||
|
||||
public override void GetWeaponCrit(Player player, ref int crit) => crit += 18;
|
||||
|
||||
public override bool CanUseItem(Player player) => player.ownedProjectileCounts[item.shoot] <= 0;
|
||||
|
||||
public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
|
||||
{
|
||||
Projectile.NewProjectile(position, new Vector2(speedX, speedY), type, damage, knockBack, player.whoAmI, 0f, 0f);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.0 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 5.0 KiB |
@@ -0,0 +1,196 @@
|
||||
using CalamityMod.Dusts;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using Terraria;
|
||||
using Terraria.ID;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Projectiles.Melee
|
||||
{
|
||||
public class PrismSawProjectile : ModProjectile
|
||||
{
|
||||
public Player Owner => Main.player[projectile.owner];
|
||||
public ref float Time => ref projectile.ai[0];
|
||||
public ref float OriginalDamage => ref projectile.ai[1];
|
||||
public float ChargeUpPower => MathHelper.Clamp((float)Math.Pow(Time / 240f, 1.6D), 0f, 1f);
|
||||
public override void SetStaticDefaults() => DisplayName.SetDefault("Verrrrrrrry over the top chainsaw thing");
|
||||
|
||||
public override void SetDefaults()
|
||||
{
|
||||
projectile.width = 132;
|
||||
projectile.height = 56;
|
||||
projectile.friendly = true;
|
||||
projectile.penetrate = -1;
|
||||
projectile.tileCollide = false;
|
||||
projectile.melee = true;
|
||||
projectile.ownerHitCheck = true;
|
||||
projectile.usesIDStaticNPCImmunity = true;
|
||||
projectile.idStaticNPCHitCooldown = 2;
|
||||
}
|
||||
|
||||
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
|
||||
{
|
||||
Texture2D texture = Main.projectileTexture[projectile.type];
|
||||
Texture2D glowmaskTexture = ModContent.GetTexture("CalamityMod/Projectiles/Melee/PrismSawGlowmask");
|
||||
Rectangle glowmaskRectangle = glowmaskTexture.Frame(1, 6, 0, projectile.frame);
|
||||
Vector2 origin = texture.Size() * 0.5f;
|
||||
Vector2 drawPosition = projectile.Center - Main.screenPosition;
|
||||
SpriteEffects direction = projectile.spriteDirection == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally;
|
||||
spriteBatch.Draw(texture, drawPosition, null, projectile.GetAlpha(lightColor), projectile.rotation, origin, projectile.scale, direction, 0f);
|
||||
spriteBatch.Draw(glowmaskTexture, drawPosition, glowmaskRectangle, Color.White, projectile.rotation, origin, projectile.scale, direction, 0f);
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void AI()
|
||||
{
|
||||
PlayChainsawSounds();
|
||||
DetermineDamage();
|
||||
|
||||
Vector2 playerRotatedPoint = Owner.RotatedRelativePoint(Owner.MountedCenter);
|
||||
if (Main.myPlayer == projectile.owner)
|
||||
{
|
||||
if (Owner.channel && !Owner.noItems && !Owner.CCed)
|
||||
HandleChannelMovement(playerRotatedPoint);
|
||||
else
|
||||
projectile.Kill();
|
||||
}
|
||||
|
||||
DetermineVisuals(playerRotatedPoint);
|
||||
ManipulatePlayerValues();
|
||||
EmitPrettyDust();
|
||||
|
||||
if (Time > 90f && Time % 36f == 35f)
|
||||
ReleasePrismTeeth();
|
||||
|
||||
// Prevent the projectile from dying normally. However, if anything for whatever reason
|
||||
// goes wrong it will immediately be destroyed on the next frame.
|
||||
projectile.timeLeft = 2;
|
||||
|
||||
Time++;
|
||||
}
|
||||
|
||||
public void PlayChainsawSounds()
|
||||
{
|
||||
if (projectile.soundDelay <= 0)
|
||||
{
|
||||
Main.PlaySound(SoundID.Item22, projectile.position);
|
||||
projectile.soundDelay = (int)MathHelper.Lerp(30f, 12f, ChargeUpPower);
|
||||
}
|
||||
}
|
||||
|
||||
public void DetermineDamage()
|
||||
{
|
||||
// Set the initial damage the moment it's created.
|
||||
if (Main.myPlayer == projectile.owner && OriginalDamage == 0f)
|
||||
{
|
||||
OriginalDamage = projectile.damage;
|
||||
projectile.netUpdate = true;
|
||||
}
|
||||
|
||||
// And then do time based calculations. This does not execute if the original damage is 0.
|
||||
if (OriginalDamage != 0f)
|
||||
projectile.damage = (int)MathHelper.SmoothStep(OriginalDamage * 0.36f, OriginalDamage, ChargeUpPower);
|
||||
}
|
||||
|
||||
public void DetermineVisuals(Vector2 playerRotatedPoint)
|
||||
{
|
||||
float velocityAngle = projectile.velocity.ToRotation();
|
||||
projectile.rotation = velocityAngle;
|
||||
|
||||
int oldDirection = projectile.spriteDirection;
|
||||
if (oldDirection == -1)
|
||||
projectile.rotation += MathHelper.Pi;
|
||||
|
||||
projectile.direction = projectile.spriteDirection = (Math.Cos(velocityAngle) > 0).ToDirectionInt();
|
||||
|
||||
if (projectile.spriteDirection != oldDirection)
|
||||
projectile.rotation -= MathHelper.Pi;
|
||||
|
||||
// Positioning close to the end of the player's arm.
|
||||
projectile.position = playerRotatedPoint - projectile.Size * 0.5f + velocityAngle.ToRotationVector2() * 30f;
|
||||
|
||||
// Update the position a tiny bit every frame at random to make it look like the saw is vibrating.
|
||||
projectile.position += Main.rand.NextVector2Circular(1.4f, 1.4f);
|
||||
|
||||
// Update glowmask frames.
|
||||
projectile.frameCounter += (int)MathHelper.SmoothStep(12f, 33f, ChargeUpPower);
|
||||
if (projectile.frameCounter >= 32)
|
||||
{
|
||||
projectile.frame = (projectile.frame + 1) % 6;
|
||||
projectile.frameCounter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void HandleChannelMovement(Vector2 playerRotatedPoint)
|
||||
{
|
||||
float speed = 1f;
|
||||
if (Owner.ActiveItem().shoot == projectile.type)
|
||||
speed = Owner.ActiveItem().shootSpeed * projectile.scale;
|
||||
|
||||
Vector2 currentAimDirection = projectile.velocity.SafeNormalize(Vector2.UnitX * Owner.direction);
|
||||
Vector2 idealAimDirection = (Main.MouseWorld - playerRotatedPoint).SafeNormalize(Vector2.UnitX * Owner.direction);
|
||||
|
||||
float angularAimVelocity = 0.16f;
|
||||
float directionAngularDisparity = projectile.velocity.AngleBetween(idealAimDirection) / MathHelper.Pi;
|
||||
|
||||
// Increase the turn speed if close to the ideal direction, since successive linear interpolations
|
||||
// are asymptotic.
|
||||
angularAimVelocity += MathHelper.Lerp(0f, 0.25f, Utils.InverseLerp(0.28f, 0.08f, directionAngularDisparity, true));
|
||||
|
||||
if (directionAngularDisparity < 0.02f)
|
||||
projectile.velocity = Vector2.Lerp(currentAimDirection, idealAimDirection, angularAimVelocity);
|
||||
else
|
||||
projectile.velocity = idealAimDirection;
|
||||
|
||||
projectile.velocity = projectile.velocity.SafeNormalize(Vector2.UnitX * Owner.direction) * speed;
|
||||
}
|
||||
|
||||
public void ManipulatePlayerValues()
|
||||
{
|
||||
Owner.itemRotation = (projectile.velocity * projectile.direction).ToRotation();
|
||||
Owner.heldProj = projectile.whoAmI;
|
||||
Owner.itemTime = 2;
|
||||
Owner.itemAnimation = 2;
|
||||
Owner.ChangeDir(projectile.direction);
|
||||
}
|
||||
|
||||
public void EmitPrettyDust()
|
||||
{
|
||||
if (Main.dedServ)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
Vector2 spawnPosition = projectile.Center + projectile.velocity * 35f;
|
||||
spawnPosition += Main.rand.NextVector2CircularEdge(9f, 35f).RotatedBy(projectile.velocity.ToRotation() + MathHelper.PiOver2);
|
||||
|
||||
Dust rainbowSpark = Dust.NewDustPerfect(spawnPosition, 261);
|
||||
rainbowSpark.velocity = projectile.velocity * 3f + Main.rand.NextVector2CircularEdge(1.5f, 1.5f);
|
||||
rainbowSpark.noGravity = true;
|
||||
rainbowSpark.color = Main.hslToRgb((Time / 40f + Main.rand.NextFloat(-0.1f, 0.1f)) % 1f, 0.95f, 0.6f);
|
||||
rainbowSpark.scale = Main.rand.NextFloat(0.9f, 1.25f);
|
||||
}
|
||||
}
|
||||
|
||||
public void ReleasePrismTeeth()
|
||||
{
|
||||
if (Main.myPlayer != projectile.owner)
|
||||
return;
|
||||
|
||||
float shootReach = MathHelper.SmoothStep(projectile.width * 1.2f, projectile.width * 2.25f + 20f, ChargeUpPower);
|
||||
Projectile.NewProjectile(Owner.Center, projectile.velocity, ModContent.ProjectileType<PrismTooth>(), projectile.damage / 2, 0f, projectile.owner, 0f, shootReach);
|
||||
}
|
||||
|
||||
public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox)
|
||||
{
|
||||
// Collision is done as a line to bypass the fact that hitboxes cannot rotate and that
|
||||
// this projectile is notably flat in terms of sprite shape.
|
||||
float _ = 0f;
|
||||
float width = projectile.scale * 36f;
|
||||
Vector2 start = projectile.Center;
|
||||
Vector2 end = projectile.Center + projectile.velocity * 70f;
|
||||
return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), start, end, width, ref _);
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 715 B |
@@ -0,0 +1,97 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.IO;
|
||||
using Terraria;
|
||||
using Terraria.Graphics.Shaders;
|
||||
using Terraria.ID;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Projectiles.Melee
|
||||
{
|
||||
public class PrismTooth : ModProjectile
|
||||
{
|
||||
internal PrimitiveTrail TrailDrawer;
|
||||
public const int Lifetime = 30;
|
||||
public Player Owner => Main.player[projectile.owner];
|
||||
public ref float Time => ref projectile.ai[0];
|
||||
public ref float ShootReach => ref projectile.ai[1];
|
||||
public override void SetStaticDefaults()
|
||||
{
|
||||
DisplayName.SetDefault("Prism Tooth");
|
||||
ProjectileID.Sets.TrailingMode[projectile.type] = 2;
|
||||
ProjectileID.Sets.TrailCacheLength[projectile.type] = 36;
|
||||
}
|
||||
|
||||
public override void SetDefaults()
|
||||
{
|
||||
projectile.width = projectile.height = 35;
|
||||
projectile.friendly = true;
|
||||
projectile.penetrate = 1;
|
||||
projectile.timeLeft = Lifetime;
|
||||
projectile.melee = true;
|
||||
}
|
||||
|
||||
public override void SendExtraAI(BinaryWriter writer) => writer.Write((byte)projectile.direction);
|
||||
|
||||
public override void ReceiveExtraAI(BinaryReader reader) => projectile.direction = reader.ReadByte();
|
||||
|
||||
public override void AI()
|
||||
{
|
||||
// Determine the initial direction of the tooth in terms of its orbit.
|
||||
if (Main.myPlayer == projectile.owner && projectile.spriteDirection == 0)
|
||||
{
|
||||
projectile.spriteDirection = Main.rand.NextBool(2).ToDirectionInt();
|
||||
projectile.netUpdate = true;
|
||||
}
|
||||
|
||||
projectile.rotation = MathHelper.Pi * Time / Lifetime;
|
||||
if (projectile.spriteDirection == -1)
|
||||
projectile.rotation = MathHelper.Pi - projectile.rotation;
|
||||
projectile.rotation += projectile.velocity.ToRotation();
|
||||
|
||||
// In this context, the velocity is simply the initial direction as a unit vector- it does not
|
||||
// actually influence movement in any way.
|
||||
float angle = MathHelper.TwoPi * Time / Lifetime - MathHelper.PiOver2;
|
||||
if (projectile.spriteDirection == -1)
|
||||
angle += MathHelper.Pi;
|
||||
|
||||
Vector2 baseDirection = angle.ToRotationVector2();
|
||||
baseDirection.X *= 0.25f;
|
||||
baseDirection.Y = baseDirection.Y * 0.5f + 0.5f;
|
||||
baseDirection = baseDirection.RotatedBy(projectile.velocity.ToRotation() - MathHelper.PiOver2);
|
||||
|
||||
projectile.Center = Owner.RotatedRelativePoint(Owner.MountedCenter) + baseDirection * ShootReach;
|
||||
projectile.Opacity = Utils.InverseLerp(0f, 12f, Time, true) * Utils.InverseLerp(Lifetime, Lifetime - 12f, Time, true);
|
||||
|
||||
Time++;
|
||||
}
|
||||
|
||||
public override Color? GetAlpha(Color lightColor)
|
||||
{
|
||||
float hue = (projectile.identity % 9f / 9f + projectile.timeLeft / (float)Lifetime) % 1f;
|
||||
return Color.Lerp(lightColor, Main.hslToRgb(hue, 0.95f, 0.55f), 0.35f) * projectile.Opacity;
|
||||
}
|
||||
|
||||
internal float WidthFunction(float completionRatio) => 54f;
|
||||
|
||||
internal Color ColorFunction(float completionRatio)
|
||||
{
|
||||
Color color = Color.Lerp(Color.White, Color.Violet, Utils.InverseLerp(0f, 0.7f, completionRatio, true)) * (1f - Utils.InverseLerp(0f, 0.98f, completionRatio, true));
|
||||
color.A /= 2;
|
||||
return color;
|
||||
}
|
||||
|
||||
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
|
||||
{
|
||||
if (TrailDrawer is null)
|
||||
TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, false, GameShaders.Misc["CalamityMod:OverpoweredTouhouSpearShader"]);
|
||||
|
||||
GameShaders.Misc["CalamityMod:OverpoweredTouhouSpearShader"].SetShaderTexture(ModContent.GetTexture("CalamityMod/ExtraTextures/ScarletDevilStreak"));
|
||||
TrailDrawer.Draw(projectile.oldPos, projectile.Size * 0.5f - Main.screenPosition + projectile.velocity.SafeNormalize(Vector2.Zero) * 86f, 60);
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool ShouldUpdatePosition() => false;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 338 B |
Reference in new issue
Block a user