Woolfrum knives

This commit is contained in:
IbanPlay authored and Cameron Ewell committed 2022-07-11 19:05:37 -04:00
1 parent bb5787f430
commit 40bfd1486b
7 files changed
+252 -48

No files matched your search

+5 -14
View File
@@ -1,24 +1,15 @@
using CalamityMod.Items.Materials;
using CalamityMod.Projectiles.Magic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Microsoft.Xna.Framework;
using System;
using System.IO;
using System;
using System.Linq;
using CalamityMod.Items.Materials;
using CalamityMod.Projectiles.Magic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using static CalamityMod.CalamityUtils;
using ReLogic.Content;
using Terraria;
using Terraria.Audio;
using Terraria.DataStructures;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ModLoader.IO;
using Terraria.GameContent;
using ReLogic.Content;
using System.Linq;
using static CalamityMod.CalamityUtils;
namespace CalamityMod.Items.Weapons.Magic
{
+101 -10
View File
@@ -5,58 +5,149 @@ using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.Audio;
using CalamityMod.Particles;
namespace CalamityMod.Items.Weapons.Rogue
{
public class WulfrumKnife : ModItem
{
public static readonly SoundStyle ThrowSound = new("CalamityMod/Sounds/Item/WulfrumKnifeThrow") { PitchVariance = 0.4f, Volume = 1f };
public static int missedShots = 0;
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Wulfrum Knife");
Tooltip.SetDefault("Stealth strikes make the knife fly further and hit several times at once");
Tooltip.SetDefault("Stealth strikes make the knife fly further and hit several times at once\n" +
"Hold right click to magnetize all nearby fallen knives back to you");
SacrificeTotal = 99;
}
public int shootCount = 0;
public bool stealthStrikeStarted = false;
public override void SetDefaults()
{
Item.width = 22;
Item.damage = 11;
Item.damage = 7;
Item.noMelee = true;
Item.consumable = true;
Item.noUseGraphic = true;
Item.useAnimation = 15;
Item.useStyle = ItemUseStyleID.Swing;
Item.useTime = 15;
//Clockwork burst
Item.useAnimation = 10;
Item.useTime = 4;
Item.reuseDelay = 24;
Item.knockBack = 1f;
Item.UseSound = SoundID.Item1;
Item.UseSound = ThrowSound;
Item.autoReuse = true;
Item.height = 38;
Item.maxStack = 999;
Item.value = Item.sellPrice(0, 0, 0, 5);
Item.rare = ItemRarityID.Blue;
Item.shoot = ModContent.ProjectileType<WulfrumKnifeProj>();
Item.shootSpeed = 12f;
Item.shootSpeed = 4f;
Item.DamageType = RogueDamageClass.Instance;
}
//Magnetization
public override void HoldItem(Player player)
{
player.Calamity().rightClickListener = true;
if (player.Calamity().mouseRight && Main.rand.NextBool(7))
{
Particle streak = new ManaDrainStreak(player, Main.rand.NextFloat(0.2f, 0.5f), Main.rand.NextVector2CircularEdge(1f, 1f) * Main.rand.NextFloat(170f, 670f), Main.rand.NextFloat(30f, 44f), Color.GreenYellow, Color.DeepSkyBlue, Main.rand.Next(15, 30));
GeneralParticleHandler.SpawnParticle(streak);
if (missedShots > 0)
{
CombatText.NewText(player.Hitbox, Color.Red, "Missed knives : " + missedShots.ToString());
missedShots = 0;
}
}
}
public override void GrabRange(Player player, ref int grabRange)
{
float rangeMult = 2f;
if (player.Distance(Item.Center) < 670 && player.HeldItem.type == ModContent.ItemType<WulfrumKnife>() && player.Calamity().mouseRight)
rangeMult = 20f;
grabRange = (int)(grabRange * rangeMult);
if (rangeMult > 2f && player.Distance(Item.Center) > 50f)
{
Item.velocity = (player.DirectionTo(Item.Center) * -20f);
if (Main.rand.NextBool(3))
{
Vector2 dustCenter = Item.Center + Main.rand.NextVector2Circular(4f, 4f);
Dust chust = Dust.NewDustPerfect(dustCenter, 15, -Item.velocity * Main.rand.NextFloat(0.2f, 0.1f), Scale: Main.rand.NextFloat(1.2f, 1.8f));
chust.noGravity = true;
}
}
}
//While this may look stupid, its necessary because ReuseDelay fucks up the consumption of the item otherwise.
public override bool ConsumeItem(Player player) => shootCount < 0;
public override bool? UseItem(Player player)
{
int placeholderStock = shootCount;
shootCount = -1;
if (ItemLoader.ConsumeItem(Item, player))
{
Item.stack--;
if (Item.stack <= 0)
Item.TurnToAir();
}
shootCount = placeholderStock;
shootCount++;
return base.UseItem(player);
}
//Random spread
public override void UseAnimation(Player player)
{
shootCount = 0;
stealthStrikeStarted = false;
}
public override void ModifyShootStats(Player player, ref Vector2 position, ref Vector2 velocity, ref int type, ref int damage, ref float knockback)
{
bool stealthStrike = player.Calamity().StealthStrikeAvailable() || stealthStrikeStarted;
float spread = stealthStrike ? MathHelper.PiOver4 * 0.04f : MathHelper.PiOver4 * 0.1f;
float speedBoost = stealthStrike ? 1.25f : 1f;
velocity = velocity.RotatedByRandom(shootCount / 2f * spread) * speedBoost;
}
public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback)
{
if (player.Calamity().StealthStrikeAvailable())
if (player.Calamity().StealthStrikeAvailable() || stealthStrikeStarted)
{
stealthStrikeStarted = true;
int p = Projectile.NewProjectile(source, position, velocity * 1.3f, ModContent.ProjectileType<WulfrumKnifeProj>(), damage, knockback, player.whoAmI);
Projectile proj = Main.projectile[p];
if (p.WithinBounds(Main.maxProjectiles))
{
proj.Calamity().stealthStrike = true;
proj.penetrate = 4;
proj.usesLocalNPCImmunity = true;
proj.localNPCHitCooldown = 1;
proj.penetrate = 2;
}
return false;
}
return true;
}
public override void AddRecipes()
{
CreateRecipe(100).
+1 -1
View File
@@ -40,7 +40,7 @@ namespace CalamityMod.Particles
Position = Owner.MountedCenter + Rotation.ToRotationVector2() * MathHelper.Lerp(StartDistanceFromPlayer, FinalDistanceFromPlayer, (float)Math.Pow(LifetimeCompletion, 2));
Color = Color.Lerp(StartColor, EndColor, LifetimeCompletion);
Lighting.AddLight(Position, Color.ToVector3());
Lighting.AddLight(Position, Color.ToVector3() * 0.2f);
}
public override void CustomDraw(SpriteBatch spriteBatch)
+5 -3
View File
@@ -15,8 +15,9 @@ namespace CalamityMod.Particles
internal Rectangle Frame;
public float Opacity;
public float OpacityMult;
public TechyHoloysquareParticle(Vector2 position, Vector2 speed, float scale, Color color, float opacity = 1f)
public TechyHoloysquareParticle(Vector2 position, Vector2 speed, float scale, Color color, int lifetime, float opacity = 1f)
{
Position = position;
Scale = scale;
@@ -24,8 +25,9 @@ namespace CalamityMod.Particles
Velocity = speed;
Rotation = Main.rand.NextFloat(MathHelper.TwoPi);
Opacity = opacity;
OpacityMult = opacity;
Variant = Main.rand.Next(6);
Lifetime = 25;
Lifetime = lifetime;
switch (Variant)
{
@@ -52,7 +54,7 @@ namespace CalamityMod.Particles
public override void Update()
{
Opacity = (float)Math.Pow(LifetimeCompletion, 0.5f);
Opacity = (float)Math.Pow(LifetimeCompletion, 0.5f) * OpacityMult;
Lighting.AddLight(Position, Color.ToVector3() * Opacity);
Rotation = Velocity.ToRotation();
-8
View File
@@ -131,14 +131,6 @@ namespace CalamityMod.Projectiles.Magic
float distanceFromTarget = (Target.Center - Projectile.Center).Length();
Projectile.rotation = Projectile.rotation.AngleTowards((Target.Center - Projectile.Center).ToRotation(), 0.07f * (float)Math.Pow(( 1 - distanceFromTarget / HomingRange), 2));
/*
float angleBetween = Projectile.rotation - ((Target.Center - Projectile.Center).ToRotation());
angleBetween += (angleBetween + 180).Modulo(360) - 180;
if (Math.Abs(angleBetween) > MaxDeviationAngle)
Projectile.rotation += MaxDeviationAngle * Math.Sign(angleBetween);
*/
}
Projectile.velocity *= 0.983f;
+140 -12
View File
@@ -4,42 +4,170 @@ using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using System;
using CalamityMod.Items.Weapons.Magic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.Audio;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;
using static Terraria.ModLoader.ModContent;
using CalamityMod.Particles;
namespace CalamityMod.Projectiles.Rogue
{
public class WulfrumKnifeProj : ModProjectile
{
internal PrimitiveTrail TrailDrawer;
internal Color PrimColorMult = Color.White;
public override string Texture => "CalamityMod/Items/Weapons/Rogue/WulfrumKnife";
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Knife");
ProjectileID.Sets.TrailCacheLength[Projectile.type] = 20;
ProjectileID.Sets.TrailingMode[Projectile.type] = 0;
}
public static int Lifetime = 950;
public float LifetimeCompletion => MathHelper.Clamp((Lifetime - Projectile.timeLeft) / (float)Lifetime, 0f, 1f);
public override void SetDefaults()
{
Projectile.width = 12;
Projectile.height = 12;
Projectile.friendly = true;
Projectile.penetrate = 2;
Projectile.aiStyle = 2;
Projectile.timeLeft = 600;
AIType = ProjectileID.ThrowingKnife;
Projectile.penetrate = 1;
Projectile.DamageType = RogueDamageClass.Instance;
Projectile.timeLeft = Lifetime;
Projectile.extraUpdates = 5;
Projectile.usesLocalNPCImmunity = true;
Projectile.localNPCHitCooldown = 1;
}
public override void AI()
{
Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver2;
Projectile.velocity *= 0.998f;
if (Projectile.timeLeft < Lifetime - 100)
Projectile.velocity.Y += 0.01f;
if (!Projectile.Calamity().stealthStrike)
{
if (Main.rand.NextBool(10))
{
Vector2 dustCenter = Projectile.Center + Projectile.velocity.RotatedBy(MathHelper.PiOver2).SafeNormalize(Vector2.Zero) * Main.rand.NextFloat(-3f, 3f);
Dust chust = Dust.NewDustPerfect(dustCenter, 15, -Projectile.velocity * Main.rand.NextFloat(0.6f, 1.5f), Scale: Main.rand.NextFloat(1f, 1.4f));
chust.noGravity = true;
if (!Main.rand.NextBool(5))
chust.noLightEmittence = true;
}
}
else
{
float effectOpacity = MathHelper.Clamp(1 - LifetimeCompletion * 5f, 0f, 1f);
Lighting.AddLight(Projectile.Center, (Main.rand.NextBool() ? Color.GreenYellow : Color.DeepSkyBlue).ToVector3() * effectOpacity);
if (Main.rand.NextBool(7))
{
Vector2 center = Projectile.Center + Projectile.velocity.RotatedBy(MathHelper.PiOver2).SafeNormalize(Vector2.Zero) * Main.rand.NextFloat(-3f, 3f);
Vector2 velocity = Projectile.velocity.SafeNormalize(Vector2.UnitY).RotatedByRandom(MathHelper.Pi / 6f) * Main.rand.NextFloat(4, 10);
GeneralParticleHandler.SpawnParticle(new TechyHoloysquareParticle(center, velocity, Main.rand.NextFloat(1f, 2f), Main.rand.NextBool() ? new Color(99, 255, 229) : new Color(25, 132, 247), 25, effectOpacity));
}
if (Main.rand.NextBool(8))
{
Vector2 dustCenter = Projectile.Center + Projectile.velocity.RotatedBy(MathHelper.PiOver2).SafeNormalize(Vector2.Zero) * Main.rand.NextFloat(-3f, 3f);
Dust chust = Dust.NewDustPerfect(dustCenter, 15, -Projectile.velocity * Main.rand.NextFloat(0.6f, 1.5f), Scale: Main.rand.NextFloat(1f, 1.4f));
chust.noGravity = true;
chust.noLightEmittence = true;
}
}
}
public override void Kill(int timeLeft)
{
if (Main.rand.NextBool(2) && false)
{
Item.NewItem(Projectile.GetSource_DropAsItem(), (int)Projectile.position.X, (int)Projectile.position.Y, Projectile.width, Projectile.height, ModContent.ItemType<WulfrumKnife>());
}
}
public override bool OnTileCollide(Vector2 oldVelocity)
{
Collision.HitTiles(Projectile.position, Projectile.velocity, Projectile.width, Projectile.height);
return base.OnTileCollide(oldVelocity);
}
internal Color ColorFunction(float completionRatio)
{
float fadeOpacity = (float)Math.Pow(1 - completionRatio, 2) * MathHelper.Clamp(1 - LifetimeCompletion * 5f, 0f, 1f);
return Color.GreenYellow.MultiplyRGB(PrimColorMult) * fadeOpacity;
}
internal float WidthFunction(float completionRatio)
{
return 9.4f;
}
public override bool PreDraw(ref Color lightColor)
{
Texture2D tex = ModContent.Request<Texture2D>(Texture).Value;
Main.EntitySpriteDraw(tex, Projectile.Center - Main.screenPosition, null, Projectile.GetAlpha(lightColor), Projectile.rotation, tex.Size() / 2f, Projectile.scale, SpriteEffects.None, 0);
float opacitey = MathHelper.Clamp(1 - LifetimeCompletion * 5f, 0f, 1f);
if (Projectile.Calamity().stealthStrike)
{
Main.spriteBatch.End();
Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix);
if (TrailDrawer is null)
TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]);
GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(Request<Texture2D>("CalamityMod/ExtraTextures/BasicTrail"));
CalamityUtils.DrawChromaticAberration(Vector2.UnitX, 1f, delegate (Vector2 offset, Color colorMod)
{
PrimColorMult = colorMod;
TrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition + offset, 30);
});
CalamityUtils.DrawChromaticAberration(Vector2.UnitX, 3f, delegate (Vector2 offset, Color colorMod)
{
Main.EntitySpriteDraw(tex, Projectile.Center - Main.screenPosition + offset, null, Color.GreenYellow.MultiplyRGB(colorMod) * opacitey, Projectile.rotation, tex.Size() / 2f, Projectile.scale, SpriteEffects.None, 0);
});
Main.spriteBatch.End();
Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix);
opacitey = MathHelper.Clamp(LifetimeCompletion * 8f, 0f, 1f);
Main.EntitySpriteDraw(tex, Projectile.Center - Main.screenPosition, null, Projectile.GetAlpha(lightColor) * opacitey, Projectile.rotation, tex.Size() / 2f, Projectile.scale, SpriteEffects.None, 0);
}
else
{
opacitey = MathHelper.Clamp(LifetimeCompletion * 15f, 0f, 1f);
Main.EntitySpriteDraw(tex, Projectile.Center - Main.screenPosition, null, Projectile.GetAlpha(lightColor) * opacitey, Projectile.rotation, tex.Size() / 2f, Projectile.scale, SpriteEffects.None, 0);
}
return false;
}
public override void Kill(int timeLeft)
{
if (Main.rand.NextBool(2))
{
Item.NewItem(Projectile.GetSource_DropAsItem(), (int)Projectile.position.X, (int)Projectile.position.Y, Projectile.width, Projectile.height, ModContent.ItemType<WulfrumKnife>());
}
}
}
}
Binary file not shown.