mirror blade rework

This commit is contained in:
Doze-Zoze committed 2025-05-03 19:14:28 -05:00
1 parent 48521bc7c7
commit 0c8bcb7b5f
11 files changed
+378 -48

No files matched your search

+91 -15
View File
@@ -1,24 +1,40 @@
using CalamityMod.Projectiles.Melee;
using CalamityMod.Projectiles.BaseProjectiles;
using CalamityMod.Rarities;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.DataStructures;
using Microsoft.Xna.Framework;
using CalamityMod.Systems.Collections;
using System;
using Terraria.Localization;
namespace CalamityMod.Items.Weapons.Melee
{
public class MirrorBlade : ModItem, ILocalizedModType
public class MirrorBlade : BaseSwordHoldoutItem, ILocalizedModType
{
public new string LocalizationCategory => "Items.Weapons.Melee";
private int baseDamage = 100;
public override int ProjectileType => ModContent.ProjectileType<MirrorBladeProjectile>();
public float damageMultiplier = 1f;
public int reflectTimer = 0;
public override void SetStaticDefaults()
{
Main.RegisterItemAnimation(Item.type, new DrawAnimationVertical(5, 5));
ItemID.Sets.AnimatesAsSoul[Type] = true;
ItemID.Sets.ItemsThatAllowRepeatedRightClick[Type] = true;
base.SetStaticDefaults();
}
public override void SetDefaults()
{
Item.width = 72;
Item.height = 72;
Item.damage = baseDamage;
Item.DamageType = DamageClass.Melee;
Item.useAnimation = 12;
Item.useTime = 12;
Item.width = 114;
Item.height = 128;
Item.damage = 1000;
Item.DamageType = TrueMeleeDamageClass.Instance;
Item.useAnimation = 40;
Item.useTime = 40;
Item.useTurn = true;
Item.useStyle = ItemUseStyleID.Swing;
Item.knockBack = 7f;
@@ -28,20 +44,80 @@ namespace CalamityMod.Items.Weapons.Melee
Item.rare = ModContent.RarityType<Turquoise>();
Item.shootSpeed = 9f;
Item.shoot = ModContent.ProjectileType<MirrorBlast>();
base.SetDefaults();
}
public override void OnHitNPC(Player player, NPC target, NPC.HitInfo hit, int damageDone)
public override void UpdateInventory(Player player)
{
int conDamage = target.damage + baseDamage;
if (conDamage < baseDamage)
if (reflectTimer > 0)
{
conDamage = baseDamage;
if (reflectTimer <= 50)
{
float coneLength = 80f;
float maximumAngle = 0.8f;
float coneRotation = player.DirectionTo(Main.MouseWorld).ToRotation();
var shardCount = 0;
foreach (var proj in Main.projectile)
{
if (proj.active && proj.type == ModContent.ProjectileType<MirrorBlast>() && proj.owner == player.whoAmI && (proj.ModProjectile as MirrorBlast).isShard)
{
shardCount++;
}
}
foreach (var proj in Main.ActiveProjectiles)
{
if (proj.hostile && proj.damage > 0 && proj.Hitbox.IntersectsConeSlowMoreAccurate(player.Center, coneLength, coneRotation, maximumAngle))
{
if (shardCount >= 10)
{
player.SetImmuneTimeForAllTypes(player.longInvince ? 60 : 30);
}
proj.Calamity().multiplicativeDR += shardCount / 10f;
proj.Calamity().multiplicativeDRTimer = 60;
foreach (var proj2 in Main.projectile)
{
if (proj2.active && proj2.type == ModContent.ProjectileType<MirrorBlast>() && proj2.owner == player.whoAmI && (proj2.ModProjectile as MirrorBlast).isShard)
{
proj2.damage = (int)(proj2.damage * (shardCount >= 10 ? 3f : 2f));
(proj2.ModProjectile as MirrorBlast).shardShield = 0;
(proj2.ModProjectile as MirrorBlast).shardNum = 11;
}
}
reflectTimer = 0;
return;
}
}
}
reflectTimer--;
}
if (conDamage > 400)
}
public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback)
{
if (player.altFunctionUse == 2)
{
conDamage = 400;
reflectTimer = 60;
foreach (var proj in Main.projectile)
{
if (proj.active && proj.type == ModContent.ProjectileType<MirrorBlast>() && proj.owner == player.whoAmI && (proj.ModProjectile as MirrorBlast).isShard)
{
(proj.ModProjectile as MirrorBlast).shardShield = 60;
}
}
return false;
}
Item.damage = conDamage;
return base.Shoot(player, source, position, velocity, type, damage, knockback);
}
public override bool AltFunctionUse(Player player)
{
return true;
}
public override void ModifyWeaponDamage(Player player, ref StatModifier damage)
{
//damage *= damageMultiplier;
}
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

@@ -858,8 +858,12 @@ MirrorBlade: {
DisplayName: Mirror Blade
Tooltip:
'''
The amount of contact damage an enemy does is added to this weapons' damage
You must hit an enemy with the blade to trigger this effect
Striking an enemy or a hostile projectile spawns mirror shards
You can have up to 10 mirror shards at once, and excess shards are launched at enemies
<right> to form your shards into a mirror shield
Each shard redues the damage of a projectile that hit the shield by 10%
The shield breaks after one projectile, launching the shards at enemies with increasd damage
With all 10 shards, you gain a brief period of invulnerability when shattering the shield
'''
}
@@ -307,3 +307,4 @@ WulfrumScrewdriverProj.DisplayName: Wulfrum Screwdriver
YinYoDark.DisplayName: Dark Shard
YinYoLight.DisplayName: Light Shard
MutilatorSwordProj.DisplayName: The Mutilator
MirrorBladeProjectile.DisplayName: Mirror Blade
@@ -301,8 +301,15 @@ namespace CalamityMod.Projectiles.BaseProjectiles
player.direction = -1;
Projectile.spriteDirection = -1 * (int)player.gravDir;
}
if (AlternateSwings && player.GetModPlayer<BaseSwordHoldoutPlayer>().swingNum % 2 == 0)
{
Projectile.spriteDirection *= -1;
}
swingTime = Main.player[Projectile.owner].HeldItem.useTime;
Spawn(source);
StartupTime *= Projectile.MaxUpdates;
CooldownTime *= Projectile.MaxUpdates;
swingTime *= Projectile.MaxUpdates;
if (useMeleeSpeed)
{
var speed = Main.player[Projectile.owner].GetAttackSpeed<MeleeDamageClass>();
@@ -339,7 +346,7 @@ namespace CalamityMod.Projectiles.BaseProjectiles
{
var player = Main.player[Projectile.owner];
var modplayer = player.GetModPlayer<BaseSwordHoldoutPlayer>();
float adust = MathHelper.ToRadians(45 + 180);
float adust = MathHelper.ToRadians(225);
if (timer < StartupTime || timer > StartupTime + swingTime)
{
angle = Vector2.Lerp(angle, (player.Center - Main.MouseWorld).SafeNormalize(Vector2.One), RotateInStartup);
@@ -369,16 +376,18 @@ namespace CalamityMod.Projectiles.BaseProjectiles
oldProjectilePos.RemoveAt(0);
}
}
var angle2 = (AlternateSwings && (modplayer.swingNum % 2 == 1 ? false : true) ? SwingFunction() : -SwingFunction());
var angle2 = (AlternateSwings && (modplayer.swingNum % 2 == 1 ? false : true) ? SwingFunction() : SwingFunction());
Projectile.Center = armCenter - (angle * OffsetDistance * (1 + (Projectile.scale - 1) * 0.75f)).RotatedBy(Projectile.spriteDirection * angle2);
Projectile.rotation = angle.RotatedBy(Projectile.spriteDirection * angle2).ToRotation() + adust;
AdditionalAI();
player.itemTime = ExistsTime + 1 - timer;
player.itemTime = ExistsTime + 2 - timer;
player.itemAnimation = ExistsTime + 2 - timer;
if (timer > ExistsTime)
{
Projectile.Kill();
player.itemTime = 0;
player.itemAnimation = 0;
Projectile.Kill();
}
timer++;
if (timer >= StartupTime && timer < StartupTime + swingTime)
@@ -427,7 +436,7 @@ namespace CalamityMod.Projectiles.BaseProjectiles
GameShaders.Misc["CalamityMod:ExobladeSlash"].Shader.Parameters["fireColor"].SetValue(trailColors[2].ToVector3());
GameShaders.Misc["CalamityMod:ExobladeSlash"].Shader.Parameters["flipped"].SetValue((AlternateSwings && modplayer.swingNum % 2 == 1) ^ Projectile.spriteDirection == -1 ? false : true);
GameShaders.Misc["CalamityMod:ExobladeSlash"].Shader.Parameters["flipped"].SetValue(Projectile.spriteDirection == -1 ? false : true);
GameShaders.Misc["CalamityMod:ExobladeSlash"].Apply();
var positionsToUse = Projectile.oldPos.Take((int)MathHelper.Min(trailLength,swingTimer)).ToArray();
@@ -485,7 +494,7 @@ namespace CalamityMod.Projectiles.BaseProjectiles
return;
}
amount += 1;
if (timer % (swingTime / amount) == 0 && timer > 0 && timer < swingTime - swingTime / amount / 2)
if (swingTimer % (swingTime / amount) == 0 && swingTimer > 0 && swingTimer < swingTime - swingTime / amount / 2)
{
Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, (Projectile.rotation + negate * MathHelper.ToRadians(45 - negate * 90)).ToRotationVector2() * velocity, type, (int)(Projectile.damage * damagemod), Projectile.knockBack, Projectile.owner, ai0);
}
+12
View File
@@ -219,6 +219,11 @@ namespace CalamityMod.Projectiles
/// <summary> A temporary flat amount subtracted from the projectile's damage when hitting the player. Resets to 0 if <see cref="flatDRTimer"/> drops to 0. </summary>
public int flatDR = 0;
/// <summary> Timer for how long a projectile's damage is reduced by the value in <see cref="multiplicativeDR"/>. </summary>
public int multiplicativeDRTimer = 0;
/// <summary> A temporary multiplicative amount of damage reduction when hitting the player. Resets to 0 if <see cref="multiplicativeDRTimer"/> drops to 0. </summary>
public float multiplicativeDR = 0;
/// <summary> If true, allows hostile projectiles to deal defense damage to the player. Used mostly for hard-hitting bosses. </summary>
public bool DealsDefenseDamage = false;
@@ -4006,6 +4011,12 @@ namespace CalamityMod.Projectiles
if (flatDRTimer <= 0)
flatDR = 0;
}
if (projectile.FinalExtraUpdate() && multiplicativeDRTimer > 0)
{
multiplicativeDRTimer--;
if (multiplicativeDRTimer <= 0)
multiplicativeDR = 0;
}
if (projectile.FinalExtraUpdate() && TransformerTimer > 0)
{
TransformerTimer--;
@@ -4219,6 +4230,7 @@ namespace CalamityMod.Projectiles
public override void ModifyHitPlayer(Projectile projectile, Player target, ref Player.HurtModifiers modifiers)
{
modifiers.FinalDamage.Flat -= flatDR;
modifiers.FinalDamage *= 1f - multiplicativeDR;
}
#endregion
+109
View File
@@ -0,0 +1,109 @@
using Terraria.ModLoader;
using CalamityMod.Projectiles.BaseProjectiles;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using CalamityMod.Items.Weapons.Melee;
using Terraria.DataStructures;
using System;
using System.Collections.Generic;
namespace CalamityMod.Projectiles.Melee
{
public class MirrorBladeProjectile : BaseSwordHoldoutProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Melee";
public override int swingWidth => 200;
public override Item BaseItem => ModContent.GetModItem(ModContent.ItemType<MirrorBlade>()).Item;
public override int AfterImageLength => 10;
public override int OffsetDistance => 80;
public override bool drawSwordTrail => false;
public override Color[] trailColors => new Color[] { Color.Red, Color.MediumPurple, Color.Purple }; public override int StartupTime { get; set; }
public override int CooldownTime { get; set; }
public override bool AlternateSwings => true;
public override bool useMeleeSpeed => true;
public override int swingTime { get; set; } = 8;
public List<int> reflectedProjectiles = new List<int>() { };
public override void Defaults()
{
Projectile.extraUpdates = 3;
}
public override void Spawn(IEntitySource source)
{
var player = Main.player[Projectile.owner];
var modplayer = player.GetModPlayer<BaseSwordHoldoutPlayer>();
StartupTime = 15;
CooldownTime = 15;
swingTime -= StartupTime + CooldownTime;
modplayer.swingNum = (modplayer.swingNum + 1) % 2;
Projectile.timeLeft = 600;
}
public override void AdditionalAI()
{
if (inStartup)
{
Projectile.scale = baseScale * MathHelper.Lerp(0.75f, 1f, StartupCompletion);
if (timer >= StartupTime - 1)
{
//Projectile.extraUpdates = 3;
}
}
else if (inCooldown)
{
//Projectile.extraUpdates = 1;
Projectile.Opacity = 1;
Projectile.scale = baseScale * MathHelper.Lerp(1, 0.75f, CooldownCompletion);
}
else
{
//Projectile.extraUpdates = 1;
Projectile.Opacity = 1;
}
if (!inStartup && !inCooldown)
foreach (var proj in Main.ActiveProjectiles)
{
if (proj.Hitbox.Intersects(Projectile.Hitbox) && proj.hostile && !reflectedProjectiles.Contains(proj.whoAmI))
{
reflectedProjectiles.Add(proj.whoAmI);
Projectile.NewProjectile(Projectile.GetSource_FromThis(), proj.Center, proj.velocity * -1, ModContent.ProjectileType<MirrorBlast>(), (int)(Projectile.damage * 0.5f), Projectile.knockBack, Projectile.owner);
}
}
Lighting.AddLight(Main.player[Projectile.owner].Center, 0.96f, 0.91f, 1f);
}
public override float SwingFunction()
{
if (inStartup)
return MathHelper.ToRadians(MathHelper.SmoothStep(-swingWidth * 0.7f, -swingWidth * 0.4f, 1 - MathF.Pow(StartupCompletion, 0.5f)));
if (inCooldown)
return MathHelper.ToRadians(MathHelper.SmoothStep(swingWidth * 0.5f, (360 - swingWidth * 0.4f), MathF.Pow(CooldownCompletion, 0.5f)));
return MathHelper.ToRadians(MathHelper.SmoothStep(-swingWidth * .5f, (swingWidth * 0.5f), SwingCompletion));
}
public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone)
{
Projectile.NewProjectile(Projectile.GetSource_FromThis(), target.Center, Vector2.Zero, ModContent.ProjectileType<MirrorBlast>(), (int)(Projectile.damage * 0.5f), Projectile.knockBack, Projectile.owner);
}
public override float trailOffset => 28;
public override float trailWidth(float completion)
{
return 60;//base.trailWidth(completion)*2;
}
public override int trailLength => 40;
public override bool PreDraw(ref Color lightColor)
{
lightColor = Color.White;
return base.PreDraw(ref lightColor);
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

+144 -25
View File
@@ -3,61 +3,180 @@ using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;
namespace CalamityMod.Projectiles.Melee
{
public class MirrorBlast : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Melee";
public bool isShard = true;
public int shardShield = 0;
public bool isShield => shardShield > 0;
private bool hasSpawned = false;
public int shardNum = -1;
private Player player => Main.player[Projectile.owner];
public override void SetStaticDefaults()
{
ProjectileID.Sets.TrailCacheLength[Type] = 10;
ProjectileID.Sets.TrailingMode[Type] = 1;
Main.projFrames[Type] = 3;
}
public override void SetDefaults()
{
Projectile.width = 12;
Projectile.height = 12;
Projectile.width = 16;
Projectile.height = 16;
Projectile.friendly = true;
Projectile.ignoreWater = true;
Projectile.DamageType = DamageClass.Melee;
Projectile.penetrate = 1;
Projectile.timeLeft = 300;
Projectile.timeLeft = 1800;
Projectile.extraUpdates = 0;
Projectile.tileCollide = false;
}
public override bool? CanDamage()
{
return !isShard;
}
public override bool? CanHitNPC(NPC target)
{
if (target.Calamity().DR > 0.9f) {
return false;
}
return base.CanHitNPC(target);
}
public override void AI()
{
int playerOwner = (int)Player.FindClosest(Projectile.Center, 1, 1);
Projectile.ai[1] += 1f;
if (Projectile.ai[1] < 110f && Projectile.ai[1] > 30f)
if (!hasSpawned)
{
float scaleFactor = Projectile.velocity.Length();
Vector2 projDirection = Main.player[playerOwner].Center - Projectile.Center;
projDirection.Normalize();
projDirection *= scaleFactor;
Projectile.velocity = (Projectile.velocity * 24f + projDirection) / 25f;
Projectile.velocity.Normalize();
Projectile.velocity *= scaleFactor;
shardNum = player.ownedProjectileCounts[Projectile.type];
hasSpawned = true;
shardNum = 0;
foreach (var proj in Main.projectile)
{
if (proj.active && proj.type == ModContent.ProjectileType<MirrorBlast>() && proj.owner == Projectile.owner)
{
(proj.ModProjectile as MirrorBlast).shardNum++;
}
}
}
if (isShield)
{
if (shardNum > 10)
{
shardShield = 0;
isShard = false;
Projectile.timeLeft = 1200;
Projectile.velocity = Projectile.DirectionTo(player.Center) * -20f;
return;
}
List<Vector2> positions = new List<Vector2>()
{
new(0,75),
new(10,65),
new(-10,65),
new(20,75),
new(-20,75),
new(30,65),
new(-30,65),
new(14,55),
new(-14,55),
new(0,45)
};
Projectile.velocity = Vector2.Zero;
Projectile.Center = Vector2.Lerp(Projectile.Center,
player.Center + player.DirectionTo(player.Calamity().mouseWorld)
.RotatedBy(MathHelper.ToRadians(positions[shardNum - 1].X))
* positions[shardNum - 1].Y,
0.5f);
Projectile.rotation = Projectile.DirectionTo(player.Center).ToRotation() + MathHelper.PiOver2;
shardShield--;
}
else if (isShard)
{
Projectile.velocity = Vector2.Zero;
var shardCount = 0;
foreach (var proj in Main.projectile)
{
if (proj.active && proj.type == ModContent.ProjectileType<MirrorBlast>() && proj.owner == Projectile.owner && (proj.ModProjectile as MirrorBlast).isShard)
{
shardCount++;
}
}
Projectile.Center = Vector2.Lerp(Projectile.Center, player.Center + new Vector2(0, MathHelper.Lerp(-90, -110, MathF.Sin(player.miscCounter / 300f * MathHelper.TwoPi + MathHelper.Pi * (shardNum % 2)))).RotatedBy(MathHelper.ToRadians(player.miscCounter / 300f * 360f + 360f / shardCount * shardNum)), 0.15f);
Projectile.rotation = Projectile.DirectionTo(player.Center).ToRotation() + MathHelper.PiOver2;
if (shardNum > 10 || Projectile.timeLeft < 2)
{
isShard = false;
Projectile.timeLeft = 1200;
Projectile.velocity = Projectile.DirectionTo(player.Center) * -20f;
}
}
else
{
float homingStrength = 0.025f; // Adjust this value for stronger or weaker homing
NPC target = FindClosestNPC(3200f);
if (target != null)
{
Vector2 direction = target.Center - Projectile.Center;
direction.Normalize();
direction *= 40f; // Adjust speed as needed
Projectile.velocity = Vector2.Lerp(Projectile.velocity, direction, homingStrength);
}
Projectile.rotation = Projectile.velocity.ToRotation();
}
if (Projectile.velocity.Length() < 18f)
Lighting.AddLight(Projectile.Center, 0.96f*0.33f, 0.91f*0.33f, 0.33f);
if (Projectile.FinalExtraUpdate())
Projectile.frameCounter++;
if (Projectile.frameCounter > 8)
{
Projectile.velocity *= 1.02f;
Projectile.frame++;
Projectile.frameCounter = 0;
}
Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver2;
Lighting.AddLight(Projectile.Center, 0f, 0.35f, 0.35f);
if (Projectile.frame >= 3)
Projectile.frame = 0;
}
public override bool PreDraw(ref Color lightColor)
{
if (Projectile.timeLeft > 295)
return false;
CalamityUtils.DrawAfterimagesCentered(Projectile, ProjectileID.Sets.TrailingMode[Type], lightColor, 2);
Texture2D BlastTex = ModContent.Request<Texture2D>("CalamityMod/Projectiles/Melee/MirrorBlast").Value;
Texture2D ShardTex = ModContent.Request<Texture2D>("CalamityMod/Projectiles/Melee/MirrorShard").Value;
Point BlastTextureDim = new Point(60, 26);
Point ShardTextureDim = new Point(32, 14);
Texture2D UsedTex = isShard ? ShardTex : BlastTex;
Point UsedTextureDim = isShard ? ShardTextureDim : BlastTextureDim;
Vector2 origin = isShard ? ShardTextureDim.ToVector2() / 2f : BlastTextureDim.ToVector2() / 2f + new Vector2(14, 0);
Main.spriteBatch.Draw(UsedTex, Projectile.Center - Main.screenPosition, new Rectangle(0, UsedTextureDim.Y * Projectile.frame, UsedTextureDim.X, UsedTextureDim.Y), Color.White, Projectile.rotation, origin, Projectile.scale, SpriteEffects.None, 0f);
return false;
}
private NPC FindClosestNPC(float maxRange)
{
NPC closestNPC = null;
float closestDistance = maxRange;
foreach (NPC npc in Main.npc)
{
if (npc.CanBeChasedBy(this) && !npc.friendly)
{
float distance = Vector2.Distance(Projectile.Center, npc.Center);
if (distance < closestDistance)
{
closestDistance = distance;
closestNPC = npc;
}
}
}
return closestNPC;
}
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 596 B

After

Width:  |  Height:  |  Size: 812 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 613 B