shart cannon

This commit is contained in:
Altixal committed 2023-10-21 03:21:40 +07:00
1 parent b364e50f4f
commit daa334f79c
5 files changed
+84 -74

No files matched your search

+1 -1
View File
@@ -17,7 +17,7 @@ namespace CalamityMod.Items.Weapons.Ranged
// Left-click stats
public static float AmmoNotConsumeChance = 0.95f;
public static int LightBombCooldown = 10;
public static int LightBombCooldown = 15;
// Right-click stats
public static float RightClickVelocityMult = 2.5f;
+6 -6
View File
@@ -33,11 +33,11 @@ namespace CalamityMod.Projectiles.Ranged
}
public override void AI()
{
Particle explosion = new DetailedExplosion(Projectile.Center, Vector2.Zero, color1, new Vector2(1f, 1f), Main.rand.NextFloat(-5, 5), 0f, ExplosionRadius * 0.0065f + 0.1f, Main.rand.Next(15, 22));
Particle explosion = new DetailedExplosion(Projectile.Center, Vector2.Zero, color1, Vector2.One, Main.rand.NextFloat(-5, 5), 0f, ExplosionRadius * 0.0065f + 0.1f, Main.rand.Next(15, 22));
GeneralParticleHandler.SpawnParticle(explosion);
Particle explosion2 = new DetailedExplosion(Projectile.Center, Vector2.Zero, Color.Black, new Vector2(1f, 1f), Main.rand.NextFloat(-5, 5), 0f, ExplosionRadius * 0.0045f + 0.1f, Main.rand.Next(15, 22), false);
Particle explosion2 = new DetailedExplosion(Projectile.Center, Vector2.Zero, Color.Black, Vector2.One, Main.rand.NextFloat(-5, 5), 0f, ExplosionRadius * 0.0045f + 0.1f, Main.rand.Next(15, 22), false);
GeneralParticleHandler.SpawnParticle(explosion2);
Particle explosion3 = new DetailedExplosion(Projectile.Center, Vector2.Zero, Color.Black, new Vector2(1f, 1f), Main.rand.NextFloat(-5, 5), 0f, ExplosionRadius * 0.0030f + 0.1f, Main.rand.Next(15, 22), false);
Particle explosion3 = new DetailedExplosion(Projectile.Center, Vector2.Zero, Color.Black, Vector2.One, Main.rand.NextFloat(-5, 5), 0f, ExplosionRadius * 0.0030f + 0.1f, Main.rand.Next(15, 22), false);
GeneralParticleHandler.SpawnParticle(explosion3);
Particle orb = new GenericBloom(Projectile.Center, Projectile.velocity, color1, ExplosionRadius * 0.0085f + 0.05f, 10, true);
GeneralParticleHandler.SpawnParticle(orb);
@@ -48,9 +48,9 @@ namespace CalamityMod.Projectiles.Ranged
for (int i = 0; i < numberOfDusts; i++)
{
float rot = MathHelper.ToRadians(i * rotFactor);
Vector2 offset = new Vector2(Main.rand.NextFloat(ExplosionRadius * 0.2f, 3.1f), 0).RotatedBy(rot * Main.rand.NextFloat(1.1f, 9.1f));
Vector2 velOffset = new Vector2(Main.rand.NextFloat(ExplosionRadius * 0.2f, 3.1f), 0).RotatedBy(rot * Main.rand.NextFloat(1.1f, 9.1f));
Dust dust = Dust.NewDustPerfect(Projectile.Center + offset, Main.rand.NextBool(4) ? 229 : Projectile.ai[1] == 5 ? 226 : 156, new Vector2(velOffset.X, velOffset.Y));
Vector2 offset = (Vector2.UnitX * Main.rand.NextFloat(ExplosionRadius * 0.2f, 3.1f)).RotatedBy(rot * Main.rand.NextFloat(1.1f, 9.1f));
Vector2 velOffset = (Vector2.UnitX * Main.rand.NextFloat(ExplosionRadius * 0.2f, 3.1f)).RotatedBy(rot * Main.rand.NextFloat(1.1f, 9.1f));
Dust dust = Dust.NewDustPerfect(Projectile.Center + offset, Main.rand.NextBool(4) ? 229 : Projectile.ai[1] == 5 ? 226 : 156, velOffset);
dust.noGravity = dust.type == 226? false : true;
dust.color = dust.type == 226 ? color1 : default;
dust.velocity = velOffset;
+4 -4
View File
@@ -27,7 +27,7 @@ namespace CalamityMod.Projectiles.Ranged
public override void SetStaticDefaults()
{
ProjectileID.Sets.TrailingMode[Projectile.type] = 0;
ProjectileID.Sets.TrailCacheLength[Projectile.type] = 20;
ProjectileID.Sets.TrailCacheLength[Projectile.type] = 24;
}
public override void SetDefaults()
@@ -65,7 +65,7 @@ namespace CalamityMod.Projectiles.Ranged
Projectile.Kill();
// Movement around the owner.
Projectile.Center = owner.Center + OffsetRotation.ToRotationVector2() * (float)Math.Cos(OffsetRotation * 0.3f) * owner.Size * 0.5f;
Projectile.Center = owner.Center + OffsetRotation.ToRotationVector2() * MathF.Cos(OffsetRotation * 0.3f) * owner.Size * 0.5f;
Projectile.rotation = (Projectile.position - Projectile.oldPos[1]).ToRotation();
OffsetRotation += OffsetSpeed;
}
@@ -75,13 +75,13 @@ namespace CalamityMod.Projectiles.Ranged
Texture2D lightTexture = ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/SmallGreyscaleCircle").Value;
for (int i = 0; i < Projectile.oldPos.Length; i++)
{
float colorInterpolation = (float)Math.Cos(Projectile.timeLeft / 16f + Main.GlobalTimeWrappedHourly / 20f + i / (float)Projectile.oldPos.Length * MathHelper.Pi) * 0.5f + 0.5f;
float colorInterpolation = MathF.Cos(Projectile.timeLeft / 16f + Main.GlobalTimeWrappedHourly / 20f + i / (float)Projectile.oldPos.Length * MathHelper.Pi) * 0.5f + 0.5f;
Color color = Color.Lerp(Color.LightGreen, Color.LightPink, colorInterpolation) * 0.4f;
color.A = 0;
Vector2 drawPosition = Projectile.oldPos[i] + lightTexture.Size() * 0.5f - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY) + new Vector2(-25f, -25f);
Color outerColor = color;
Color innerColor = color * 0.5f;
float intensity = 0.9f + 0.15f * (float)Math.Cos(Main.GlobalTimeWrappedHourly % 60f * MathHelper.TwoPi);
float intensity = 0.9f + 0.15f * MathF.Cos(Main.GlobalTimeWrappedHourly % 60f * MathHelper.TwoPi);
// Become smaller the futher along the old positions we are.
intensity *= MathHelper.Lerp(0.15f, 1f, 1f - i / (float)Projectile.oldPos.Length);
+39 -50
View File
@@ -1,4 +1,6 @@
using Microsoft.Xna.Framework;
using CalamityMod.Buffs.DamageOverTime;
using CalamityMod.Particles;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.IO;
@@ -6,7 +8,6 @@ using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.Audio;
using CalamityMod.Buffs.DamageOverTime;
namespace CalamityMod.Projectiles.Ranged
{
@@ -19,25 +20,13 @@ namespace CalamityMod.Projectiles.Ranged
public Vector2 InitialCenter;
public Vector2 Destination;
public const float MaxRadius = 90f;
public float Time
{
get => Projectile.ai[0];
set => Projectile.ai[0] = value;
}
public int DustType
{
get => (int)Projectile.ai[1];
set => Projectile.ai[1] = value;
}
public float YDirection
{
get => Projectile.localAI[1];
set => Projectile.localAI[1] = value;
}
public ref float YDirection => ref Projectile.ai[0];
public ref float Time => ref Projectile.ai[1];
public override void SetStaticDefaults()
{
ProjectileID.Sets.TrailingMode[Projectile.type] = 0;
ProjectileID.Sets.TrailCacheLength[Projectile.type] = 15;
ProjectileID.Sets.TrailCacheLength[Projectile.type] = 36;
}
public override void SetDefaults()
@@ -53,12 +42,11 @@ namespace CalamityMod.Projectiles.Ranged
public override void SendExtraAI(BinaryWriter writer)
{
writer.Write(YDirection);
writer.WriteVector2(Destination);
}
public override void ReceiveExtraAI(BinaryReader reader)
{
YDirection = reader.ReadSingle();
Destination = reader.ReadVector2();
}
@@ -70,60 +58,41 @@ namespace CalamityMod.Projectiles.Ranged
if (Projectile.localAI[0] == 0f)
{
InitialCenter = Projectile.Center;
Projectile.localAI[0] = 1f;
if (Main.myPlayer == Projectile.owner)
{
Destination = Main.MouseWorld;
Projectile.netUpdate = true;
}
DustType = Main.rand.NextBool() ? 107 : 234;
if (Main.rand.NextBool(4))
{
DustType = 269;
}
Projectile.localAI[0] = 1f;
}
if (Destination == Vector2.Zero)
return;
if (Time <= 90f)
if (Time <= 60f)
{
Projectile.position = Vector2.Lerp(InitialCenter, Destination, Time / 90f);
Projectile.position.Y += (float)Math.Sin(Time / 90f * MathHelper.TwoPi) * 75f;
Projectile.Center = Vector2.Lerp(InitialCenter, Destination, Time / 60f);
Projectile.Center += (Vector2.UnitY * MathF.Sin(Time / 60f * MathHelper.TwoPi) * 75f * YDirection).RotatedBy(Projectile.velocity.ToRotation());
}
else if (Time < 180f)
else if (Time < 120f)
{
// For those who haven't seen this yet (namely in the 1.4 source), this allows you to achieve a
// fade-in and fade-out effect with relative ease. At 90, multiply by 0, and somewhere in-between until 115, where you multiply by 1.
// And then do the same for the fade-out effect of 180f-165. These inverse linear interpolations cannot overlap by definition because
// their ranges do not overlap. Overall a really cool trick.
float radius = MaxRadius * Utils.GetLerpValue(90f, 115f, Time, true) * Utils.GetLerpValue(180f, 165f, Time, true);
radius *= 1f + (float)Math.Cos(Main.GlobalTimeWrappedHourly / 24f) * 0.25f;
float radius = MaxRadius * Utils.GetLerpValue(60f, 75f, Time, true) * Utils.GetLerpValue(120f, 105f, Time, true);
radius *= 1f + MathF.Cos(Main.GlobalTimeWrappedHourly / 24f) * 0.25f;
if (radius < 5f)
radius = 5f;
Projectile.Center = Destination + ((Time - 90) / 90f * MathHelper.ToRadians(720f) + (YDirection == -1).ToInt() * MathHelper.Pi).ToRotationVector2() * radius;
Projectile.Center = Destination + ((Time - 60) / 60f * MathHelper.ToRadians(720f) + (YDirection == -1).ToInt() * MathHelper.Pi).ToRotationVector2() * radius;
}
else if (Time == 180f)
else if (Time == 120f)
Projectile.Kill();
Projectile.rotation = Projectile.velocity.ToRotation() - MathHelper.PiOver2;
Time++;
}
public void GenerateRotationalDust()
{
for (int i = 0; i < 9; i++)
{
float angle = Time / 45f + i / 9f * MathHelper.TwoPi;
Vector2 offsetSpan = angle.ToRotationVector2() * Projectile.Size * 0.65f * Projectile.scale;
Vector2 edgePosition = Projectile.Center + offsetSpan.RotatedBy(Projectile.rotation);
Dust dust = Dust.NewDustPerfect(edgePosition + Main.rand.NextVector2Circular(4f, 4f), DustType);
dust.velocity = Vector2.Zero;
dust.noGravity = true;
dust.scale = 0.65f;
}
}
public override Color? GetAlpha(Color lightColor)
{
return CalamityUtils.MulticolorLerp(Time / 60f % 1f, new Color[]
@@ -138,7 +107,7 @@ namespace CalamityMod.Projectiles.Ranged
Texture2D lightTexture = ModContent.Request<Texture2D>(Texture).Value;
for (int i = 0; i < Projectile.oldPos.Length; i++)
{
float colorInterpolation = (float)Math.Cos(Projectile.timeLeft / 16f + Main.GlobalTimeWrappedHourly / 20f + i / (float)Projectile.oldPos.Length * MathHelper.Pi) * 0.5f + 0.5f;
float colorInterpolation = MathF.Cos(Projectile.timeLeft / 16f + Main.GlobalTimeWrappedHourly / 20f + i / (float)Projectile.oldPos.Length * MathHelper.Pi) * 0.5f + 0.5f;
Color color = CalamityUtils.MulticolorLerp(MathHelper.Clamp(colorInterpolation, 0f, 0.99f), new Color[]
{
Color.PaleGreen,
@@ -149,7 +118,7 @@ namespace CalamityMod.Projectiles.Ranged
Vector2 drawPosition = Projectile.oldPos[i] + lightTexture.Size() * 0.5f - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY) + new Vector2(-15f, -15f);
Color outerColor = color;
Color innerColor = color * 0.5f;
float intensity = 0.9f + 0.15f * (float)Math.Cos(Main.GlobalTimeWrappedHourly % 60f * MathHelper.TwoPi);
float intensity = 0.9f + 0.15f * MathF.Cos(Main.GlobalTimeWrappedHourly % 60f * MathHelper.TwoPi);
// Become smaller the futher along the old positions we are.
intensity *= MathHelper.Lerp(0.15f, 1f, 1f - i / (float)Projectile.oldPos.Length);
@@ -175,9 +144,29 @@ namespace CalamityMod.Projectiles.Ranged
Vector2 vel = Vector2.UnitY.RotatedByRandom(MathHelper.TwoPi) * 16f;
Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), Projectile.Center, vel, projID, Projectile.damage, Projectile.knockBack * 0.3f, Projectile.owner);
}
// If the explosion happens naturally, there's instead only 1 giant explosion instead of 2 separate ones
if (Time >= 120f && YDirection == 1)
return;
float scaleBonus = Time >= 120f ? Main.rand.NextFloat(2.4f, 3.2f) : Main.rand.NextFloat(0.8f, 1.6f);
Projectile.scale = 4.5f * scaleBonus;
Particle pinkBoom = new DetailedExplosion(Projectile.Center, Vector2.Zero, Color.Violet, Vector2.One, Main.rand.NextFloat(0f, MathHelper.TwoPi), 0f, 0.5f * scaleBonus, 12);
GeneralParticleHandler.SpawnParticle(pinkBoom);
Particle greenBoom = new DetailedExplosion(Projectile.Center, Vector2.Zero, Color.PaleGreen, Vector2.One, Main.rand.NextFloat(0f, MathHelper.TwoPi), 0f, 0.4f * scaleBonus, 12);
GeneralParticleHandler.SpawnParticle(greenBoom);
// we should probably have a generic util to do this whole thing
Projectile.maxPenetrate = -1;
Projectile.penetrate = -1;
Projectile.usesLocalNPCImmunity = true;
Projectile.localNPCHitCooldown = 10;
Projectile.Damage();
}
}
public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) => CalamityUtils.CircularHitboxCollision(Projectile.Center, Projectile.width * Projectile.scale * 0.5f, targetHitbox);
public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) => target.AddBuff(ModContent.BuffType<MiracleBlight>(), 360);
public override void OnHitPlayer(Player target, Player.HurtInfo info) => target.AddBuff(ModContent.BuffType<MiracleBlight>(), 360);
+34 -13
View File
@@ -1,5 +1,7 @@
using CalamityMod.Items.Weapons.Ranged;
using CalamityMod.Particles;
using Microsoft.Xna.Framework;
using System;
using Terraria;
using Terraria.Audio;
using Terraria.ID;
@@ -30,9 +32,30 @@ namespace CalamityMod.Projectiles.Ranged
public override void AI()
{
UpdateProjectileHeldVariables();
Vector2 armPosition = Owner.RotatedRelativePoint(Owner.MountedCenter, true);
UpdateProjectileHeldVariables(armPosition);
ManipulatePlayerVariables();
// Orange exo energy as the back "flames"
Color energyColor = Color.Orange;
Vector2 flamePosition = armPosition + Projectile.velocity * Projectile.width * 0.12f;
Vector2 verticalOffset = Vector2.UnitY.RotatedBy(Projectile.rotation);
if (Math.Cos(Projectile.rotation) < 0f)
verticalOffset *= -1f;
if (Main.rand.NextBool(4))
{
Vector2 flameAngle = -Vector2.UnitY.RotatedBy(Projectile.rotation + MathHelper.ToRadians(Main.rand.NextFloat(270f, 300f) * Projectile.spriteDirection));
SquishyLightParticle exoEnergy = new(flamePosition - verticalOffset * 26f, flameAngle * Main.rand.NextFloat(0.4f, 1.6f), 0.25f, energyColor, 20);
GeneralParticleHandler.SpawnParticle(exoEnergy);
SquishyLightParticle exoEnergy2 = new(armPosition - verticalOffset * 22f, flameAngle * Main.rand.NextFloat(0.3f, 1.2f), 0.2f, energyColor, 12);
GeneralParticleHandler.SpawnParticle(exoEnergy2);
}
// Create light around the crystal
Lighting.AddLight(armPosition + Projectile.velocity * 42f - verticalOffset * 10f, 0.8f, 0.8f, 0.8f);
Lighting.AddLight(armPosition + Projectile.velocity * 96f + verticalOffset * 6f, 0.4f, 0.4f, 0.4f);
// Despawn the projectile if the player can't shoot
// Any forced lifespan (triggered by attacking right click to prevent click spamming) will have priority
if (!OwnerCanShoot)
@@ -59,24 +82,24 @@ namespace CalamityMod.Projectiles.Ranged
{
// Can't shoot on frame 1 as it can't use ammo yet
if (ShootTimer < 0f)
RightClickAttack();
RightClickAttack(armPosition, verticalOffset);
ShootTimer--;
}
else if (!Owner.Calamity().mouseRight && Owner.channel)
{
ShootTimer++;
LeftClickAttack();
LeftClickAttack(armPosition, verticalOffset);
}
}
public void LeftClickAttack()
public void LeftClickAttack(Vector2 armPosition, Vector2 verticalOffset)
{
// Consume ammo and retrieve projectile stats; has a chance to not consume ammo
Owner.PickAmmo(Owner.ActiveItem(), out _, out float shootSpeed, out int damage, out float knockback, out _, Main.rand.NextFloat() <= AmmoNotConsumeChance);
var source = Projectile.GetSource_FromThis();
Vector2 position = Projectile.Center + Projectile.velocity * 40f;
Vector2 position = armPosition + Projectile.velocity * 48f - verticalOffset * 10f;
Vector2 velocity = Projectile.velocity * shootSpeed;
// Main fire stream
@@ -90,18 +113,16 @@ namespace CalamityMod.Projectiles.Ranged
for (int i = 0; i < 2; i++)
{
position += Projectile.velocity * 64f;
Vector2 bombPos = armPosition + Projectile.velocity * 108f + verticalOffset * 6f;
int yDirection = (i == 0).ToDirectionInt();
Vector2 bombVel = velocity.RotatedBy(0.2f * yDirection);
Projectile lightBomb = Projectile.NewProjectileDirect(source, position, bombVel, ProjectileType<ExoLight>(), damage, knockback, Projectile.owner);
lightBomb.localAI[1] = yDirection;
lightBomb.netUpdate = true;
Projectile.NewProjectile(source, bombPos, bombVel, ProjectileType<ExoLight>(), damage, knockback, Projectile.owner, yDirection);
}
}
}
public void RightClickAttack()
public void RightClickAttack(Vector2 armPosition, Vector2 verticalOffset)
{
// Multiplied by the ratio of attack speed gained from modifiers
ShootTimer = (RightClickCooldown * Owner.ActiveItem().useTime / (float)LightBombCooldown) - 1f;
@@ -111,14 +132,14 @@ namespace CalamityMod.Projectiles.Ranged
Owner.PickAmmo(Owner.ActiveItem(), out _, out float shootSpeed, out int damage, out float knockback, out _);
var source = Projectile.GetSource_FromThis();
Vector2 position = Projectile.Center + Projectile.velocity * 120f;
Vector2 position = armPosition + Projectile.velocity * 140f + verticalOffset * 6f;
Vector2 velocity = Projectile.velocity * shootSpeed * RightClickVelocityMult;
SoundEngine.PlaySound(SoundID.Item34, Owner.MountedCenter);
Projectile.NewProjectile(source, position, velocity, ProjectileType<ExoFlareCluster>(), damage, knockback, Projectile.owner);
}
public void UpdateProjectileHeldVariables()
public void UpdateProjectileHeldVariables(Vector2 armPosition)
{
if (Main.myPlayer == Projectile.owner)
{
@@ -132,7 +153,7 @@ namespace CalamityMod.Projectiles.Ranged
}
}
Projectile.position = Owner.RotatedRelativePoint(Owner.MountedCenter, true) - Projectile.Size * 0.5f;
Projectile.position = armPosition - Projectile.Size * 0.5f + Projectile.velocity.SafeNormalize(Vector2.UnitY) * 28f;
Projectile.rotation = Projectile.velocity.ToRotation();
if (Projectile.spriteDirection == -1)
Projectile.rotation += MathHelper.Pi;