This is a real softlock fix moment

This commit is contained in:
IbanPlay authored and Cameron Ewell committed 2022-07-11 19:05:37 -04:00
1 parent 7c4d1762b7
commit 7fdc3cbb0d
6 files changed
+400 -134

No files matched your search

+6 -6
View File
@@ -28,13 +28,13 @@ namespace CalamityMod.Cooldowns
public override void OnCompleted()
{
for (int i = 0; i < 66; i++)
for (int i = 0; i < 6; i++)
{
int d = Dust.NewDust(instance.player.position, instance.player.width, instance.player.height, 20, 0, 0, 100, Color.Transparent, 2.6f);
Main.dust[d].noGravity = true;
Main.dust[d].noLight = true;
Main.dust[d].fadeIn = 1f;
Main.dust[d].velocity *= 6.6f;
Vector2 dustDirection = Main.rand.NextVector2CircularEdge(1f, 1f);
Dust d = Dust.NewDustPerfect(instance.player.Center + dustDirection * Main.rand.NextFloat(0.4f, 10f), 226, dustDirection * Main.rand.NextFloat(1f, 4f), 100, Color.Transparent, Main.rand.NextFloat(0.8f, 1.2f));
d.noGravity = true;
d.noLight = true;
d.fadeIn = 1f;
}
//explode into gores
+144
View File
@@ -0,0 +1,144 @@
using System;
using System.Collections.Generic;
using System.Linq;
using CalamityMod.Cooldowns;
using CalamityMod.Items.BaseItems;
using CalamityMod.Projectiles.Summon;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.Audio;
using Terraria.ID;
using Terraria.ModLoader;
using static CalamityMod.CalamityUtils;
namespace CalamityMod.Items.Armor.Wulfrum
{
public class WulfrumFusionCannon : HeldOnlyItem, IHideFrontArm
{
public static readonly SoundStyle ShootSound = new("CalamityMod/Sounds/Item/WulfrumProthesisShoot") { PitchVariance = 0.1f, Volume = 0.4f };
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Experimental Wulfrum Fusion Array");
Tooltip.SetDefault("Fires quick bursts of medium-range pellets\n" +
"[c/878787:\"Who needs whips when you can simply become the summon yourself?\"]");
//Imaging hiding actually important/interesting/funny lore in there... :drool: that would be so dark souls
}
public override string Texture => "CalamityMod/Items/Armor/Wulfrum/WulfrumFusionCannon";
public bool noAnimation = false;
public override void SetDefaults()
{
Item.damage = 6;
Item.DamageType = DamageClass.Summon;
Item.width = 34;
Item.height = 42;
Item.useStyle = ItemUseStyleID.Shoot;
Item.noMelee = true;
Item.knockBack = 2;
Item.rare = ItemRarityID.Green;
Item.UseSound = ShootSound;
Item.autoReuse = true;
Item.shoot = ModContent.ProjectileType<WulfrumFusionBolt>();
Item.shootSpeed = 18f;
Item.holdStyle = 16; //Custom hold style
Item.useAnimation = 10;
Item.useTime = 4;
Item.reuseDelay = 17;
}
public override void ModifyTooltips(List<TooltipLine> tooltips)
{
var name = tooltips.FirstOrDefault(x => x.Name == "ItemName" && x.Mod == "Terraria");
name.OverrideColor = Color.Lerp(new Color(194, 255, 67), new Color(112, 244, 244), 0.5f + 0.5f * (float)Math.Sin(Main.GlobalTimeWrappedHourly * 3f));
}
public override void HoldItem(Player player)
{
player.Calamity().mouseWorldListener = true;
if (player.whoAmI == Main.myPlayer)
{
if (!WulfrumHat.HasArmorSet(player))
{
Item.type = 0;
Item.SetDefaults(0);
Item.stack = 0;
Main.mouseItem = null;
}
}
Item.noUseGraphic = false;
if (!player.Calamity().cooldowns.TryGetValue(WulfrumBastion.ID, out var cd) || cd.timeLeft > WulfrumHat.BastionCooldown + WulfrumHat.BastionTime - WulfrumHat.BastionBuildTime)
Item.noUseGraphic = true;
}
public override void ModifyShootStats(Player player, ref Vector2 position, ref Vector2 velocity, ref int type, ref int damage, ref float knockback)
{
velocity = velocity.RotatedByRandom(MathHelper.PiOver4 * 0.1f);
}
public override bool CanUseItem(Player player)
{
return player.Calamity().cooldowns.TryGetValue(WulfrumBastion.ID, out var cd) && cd.timeLeft < WulfrumHat.BastionCooldown + WulfrumHat.BastionTime - WulfrumHat.BastionBuildTime;
}
public void SetItemInHand(Player player, Rectangle heldItemFrame)
{
//Make the player face where they're aiming.
if (player.Calamity().mouseWorld.X > player.Center.X)
{
player.ChangeDir(1);
}
else
{
player.ChangeDir(-1);
}
//Hide the cannon till its visible on the player
if (!player.Calamity().cooldowns.TryGetValue(WulfrumBastion.ID, out var cd) || cd.timeLeft > WulfrumHat.BastionCooldown + WulfrumHat.BastionTime - WulfrumHat.BastionBuildTime)
return;
if (player.ItemTimeIsZero)
noAnimation = false;
if (player.itemAnimation > Item.useAnimation)
noAnimation = true;
float animProgress = 1 - player.itemAnimation / (float)player.itemAnimationMax;
if (noAnimation)
animProgress = 1;
//Default
Vector2 itemPosition = player.MountedCenter + new Vector2(-2f * player.direction, -1f * player.gravDir);
float itemRotation = (player.Calamity().mouseWorld - itemPosition).ToRotation();
//Adjust for animation
if (animProgress < 0.9f)
itemPosition -= itemRotation.ToRotationVector2() * (1 - (float)Math.Pow(1 - (0.9f - animProgress) / 0.9f, 4)) * 3f;
if (animProgress < 0.6f)
itemRotation += -0.3f * (float)Math.Pow((0.6f - animProgress) / 0.6f, 2) * player.direction * player.gravDir;
//Shakezzz
itemPosition += Main.rand.NextVector2Circular(2f, 2f) * (1 - animProgress);
Vector2 itemSize = new Vector2(38, 18);
Vector2 itemOrigin = new Vector2(-12, 0);
CleanHoldStyle(player, itemRotation, itemPosition, itemSize, itemOrigin, true);
}
public override void HoldStyle(Player player, Rectangle heldItemFrame) => SetItemInHand(player, heldItemFrame);
public override void UseStyle(Player player, Rectangle heldItemFrame) => SetItemInHand(player, heldItemFrame);
public override bool PreDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale) => false;
}
}
+15 -125
View File
@@ -246,11 +246,15 @@ namespace CalamityMod.Items.Armor.Wulfrum
TooltipLine setBonus3 = new TooltipLine(item.Mod, "CalamityMod:SetBonus3", "Calling down the armor consumes one piece of wulfrum scrap, and the armor will lose durability faster when hit");
setBonus3.OverrideColor = new Color(110, 192, 93);
tooltips.Insert(setBonusIndex + 3, setBonus3);
if (Main.keyState.IsKeyDown(LeftShift))
{
TooltipLine itemDisplay = new TooltipLine(item.Mod, "CalamityMod:ArmorItemDisplay", "Hold SHIFT to see the stats of the fusion cannon");
itemDisplay.OverrideColor = new Color(190, 190, 190);
tooltips.Add(itemDisplay);
}
}
TooltipLine itemDisplay = new TooltipLine(item.Mod, "CalamityMod:ArmorItemDisplay", "Hold SHIFT to see the stats of the fusion cannon");
itemDisplay.OverrideColor = new Color(190, 190, 190);
tooltips.Add(itemDisplay);
}
}
@@ -354,127 +358,6 @@ namespace CalamityMod.Items.Armor.Wulfrum
}
#endregion
public class WulfrumFusionCannon : HeldOnlyItem, IHideFrontArm
{
public static readonly SoundStyle ShootSound = new("CalamityMod/Sounds/Item/WulfrumProthesisShoot") { PitchVariance = 0.1f, Volume = 0.55f };
public static readonly SoundStyle HitSound = new("CalamityMod/Sounds/Item/WulfrumProthesisHit") { PitchVariance = 0.1f, Volume = 0.75f, MaxInstances = 3 };
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Experimental Wulfrum Fusion Array");
Tooltip.SetDefault("Fires quick bursts of medium-range pellets\n" +
"[c/878787:\"Who needs whips when you can simply become the summon yourself?\"]");
//Imaging hiding actually important/interesting/funny lore in there... :drool: that would be so dark souls
}
public override string Texture => "CalamityMod/Items/Armor/Wulfrum/WulfrumFusionCannon";
public override void SetDefaults()
{
Item.damage = 12;
Item.DamageType = DamageClass.Summon;
Item.width = 34;
Item.height = 42;
Item.useStyle = ItemUseStyleID.Shoot;
Item.noMelee = true;
Item.knockBack = 2;
Item.value = Item.buyPrice(0, 1, 0, 0);
Item.rare = ItemRarityID.Green;
Item.UseSound = ShootSound;
Item.autoReuse = true;
Item.shoot = ModContent.ProjectileType<WulfrumBolt>();
Item.shootSpeed = 18f;
Item.holdStyle = 16; //Custom hold style
Item.useAnimation = 10;
Item.useTime = 4;
Item.reuseDelay = 17;
}
public override void ModifyTooltips(List<TooltipLine> tooltips)
{
var name = tooltips.FirstOrDefault(x => x.Name == "ItemName" && x.Mod == "Terraria");
name.OverrideColor = Color.Lerp(new Color(194, 255, 67), new Color(112, 244, 244), 0.5f + 0.5f * (float)Math.Sin(Main.GlobalTimeWrappedHourly * 3f));
}
public override void HoldItem(Player player)
{
player.Calamity().mouseWorldListener = true;
if (player.whoAmI == Main.myPlayer)
{
if (!WulfrumHat.HasArmorSet(player))
{
Item.TurnToAir();
Main.mouseItem = new Item();
}
}
Item.noUseGraphic = false;
if (!player.Calamity().cooldowns.TryGetValue(WulfrumBastion.ID, out var cd) || cd.timeLeft > WulfrumHat.BastionCooldown + WulfrumHat.BastionTime - WulfrumHat.BastionBuildTime)
Item.noUseGraphic = true;
}
public override void ModifyShootStats(Player player, ref Vector2 position, ref Vector2 velocity, ref int type, ref int damage, ref float knockback)
{
velocity = velocity.RotatedByRandom(MathHelper.PiOver4 * 0.1f);
}
public override bool CanUseItem(Player player)
{
return player.Calamity().cooldowns.TryGetValue(WulfrumBastion.ID, out var cd) && cd.timeLeft < WulfrumHat.BastionCooldown + WulfrumHat.BastionTime - WulfrumHat.BastionBuildTime;
}
public void SetItemInHand(Player player, Rectangle heldItemFrame)
{
//Make the player face where they're aiming.
if (player.Calamity().mouseWorld.X > player.Center.X)
{
player.ChangeDir(1);
}
else
{
player.ChangeDir(-1);
}
if (!player.Calamity().cooldowns.TryGetValue(WulfrumBastion.ID, out var cd) || cd.timeLeft > WulfrumHat.BastionCooldown + WulfrumHat.BastionTime - WulfrumHat.BastionBuildTime)
return;
float animProgress = 1 - player.itemAnimation / (float)player.itemAnimationMax;
//Default
Vector2 itemPosition = player.MountedCenter + new Vector2(-2f * player.direction, -1f * player.gravDir);
float itemRotation = (player.Calamity().mouseWorld - itemPosition).ToRotation();
//Adjust for animation
if (animProgress < 0.7f)
itemPosition -= itemRotation.ToRotationVector2() * (1 - (float)Math.Pow(1 - (0.7f - animProgress) / 0.7f, 4)) * 4f;
if (animProgress < 0.4f)
itemRotation += -0.45f * (float)Math.Pow((0.4f - animProgress) / 0.4f, 2) * player.direction * player.gravDir;
//Shakezzz
if (player.itemTime == 1 && Main.projectile.Any(n => n.active && n.owner == player.whoAmI && n.type == ModContent.ProjectileType<WulfrumManaDrain>()))
{
itemPosition += Main.rand.NextVector2Circular(2f, 2f);
}
Vector2 itemSize = new Vector2(38, 18);
Vector2 itemOrigin = new Vector2(-12, 0);
CleanHoldStyle(player, itemRotation, itemPosition, itemSize, itemOrigin, true);
}
public override void HoldStyle(Player player, Rectangle heldItemFrame) => SetItemInHand(player, heldItemFrame);
public override void UseStyle(Player player, Rectangle heldItemFrame) => SetItemInHand(player, heldItemFrame);
public override bool PreDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale) => false;
}
public class WulfrumArmorPlayer : ModPlayer
{
public static int BastionShootDamage = 10;
@@ -564,9 +447,16 @@ namespace CalamityMod.Items.Armor.Wulfrum
}
//This shouldn't ever be possible since the power mode prevents you from using or moving items around
public override void PostUpdateMiscEffects()
{
//This is important. Prevents ppl cheat sheeting the item in from softlocking their mouse button lol
if (Main.mouseItem.ModItem is WulfrumFusionCannon && !WulfrumHat.PowerModeEngaged(Player, out _))
{
Main.mouseItem.TurnToAir();
}
//This shouldn't ever be possible since the power mode prevents you from using or moving items around
if (!wulfrumSet && WulfrumHat.PowerModeEngaged(Player, out var cd))
{
cd.timeLeft = WulfrumHat.BastionCooldown;
+5
View File
@@ -80,6 +80,11 @@ namespace CalamityMod.Particles
{
Rotation = MathHelper.Lerp(RotationOffset, 0f, (float)Math.Pow(LifetimeCompletionAdjusted, 0.8f));
//The gun
if (TimeOffset == 0.6f)
Rotation = (Owner.Calamity().mouseWorld - Owner.Center).ToRotation() + (Owner.direction < 0 ? MathHelper.Pi : 0f);
if (Owner.dead || !Owner.active)
Kill();
}
-3
View File
@@ -60,9 +60,6 @@ namespace CalamityMod.Projectiles.Magic
Projectile.DamageType = DamageClass.Magic;
Projectile.timeLeft = 140;
Projectile.extraUpdates = 2;
ProjectileID.Sets.TrailCacheLength[Projectile.type] = 20;
}
public NPC FindTarget()
+230
View File
@@ -0,0 +1,230 @@
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.Summon
{
//Mostly a retread of the magic one, with altered visuals
public class WulfrumFusionBolt : ModProjectile
{
public ref float OriginalRotation => ref Projectile.ai[0];
public NPC Target
{
get
{
if (Projectile.ai[1] < 0 || Projectile.ai[1] > Main.maxNPCs)
return null;
return Main.npc[(int)Projectile.ai[1]];
}
set
{
if (value == null)
Projectile.ai[1] = -1;
else
Projectile.ai[1] = value.whoAmI;
}
}
public static float MaxDeviationAngle = MathHelper.PiOver4;
public static float HomingRange = 250;
public static float HomingAngle = MathHelper.PiOver4 * 1.65f;
internal PrimitiveTrail TrailDrawer;
internal Color PrimColorMult = Color.White;
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Fusion Bolt");
ProjectileID.Sets.TrailCacheLength[Projectile.type] = 20;
ProjectileID.Sets.TrailingMode[Projectile.type] = 0;
}
public override void SetDefaults()
{
Projectile.width = 8;
Projectile.height = 8;
Projectile.friendly = true;
Projectile.ignoreWater = true;
Projectile.penetrate = 1;
Projectile.DamageType = DamageClass.Summon;
Projectile.timeLeft = 140;
Projectile.extraUpdates = 2;
}
public NPC FindTarget()
{
float bestScore = 0;
NPC bestTarget = null;
for (int i = 0; i < Main.maxNPCs; i++)
{
NPC potentialTarget = Main.npc[i];
if (!potentialTarget.CanBeChasedBy(null, false))
continue;
float distance = potentialTarget.Distance(Projectile.Center);
float angle = Projectile.velocity.AngleBetween((potentialTarget.Center - Projectile.Center));
float extraDistance = potentialTarget.width / 2 + potentialTarget.height / 2;
if (distance - extraDistance < HomingRange && angle < HomingAngle / 2f)
{
if (!Collision.CanHit(Projectile.Center, 1, 1, potentialTarget.Center, 1, 1) && extraDistance < distance)
continue;
float attemptedScore = EvaluatePotentialTarget(distance - extraDistance, angle / 2f);
if (attemptedScore > bestScore)
{
bestTarget = potentialTarget;
bestScore = attemptedScore;
}
}
}
return bestTarget;
}
public float EvaluatePotentialTarget(float distance, float angle)
{
float score = 1 - distance / HomingRange * 0.5f;
score += (1 - Math.Abs(angle) / (HomingAngle / 2f)) * 0.5f;
return score;
}
public override void AI()
{
if (Projectile.timeLeft == 140)
{
Projectile.rotation = Projectile.velocity.ToRotation();
Target = null;
}
else
{
Target = FindTarget();
}
Lighting.AddLight(Projectile.Center, (Color.DeepSkyBlue).ToVector3() * 0.5f);
if (Target != null)
{
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));
}
Projectile.velocity *= 0.983f;
Projectile.velocity = Projectile.rotation.ToRotationVector2() * Projectile.velocity.Length();
//Blast off.
if (Projectile.timeLeft == 140)
{
Vector2 dustCenter = Projectile.Center + Projectile.velocity * 1f;
for (int i = 0; i < 5; i++)
{
Dust chust = Dust.NewDustPerfect(dustCenter, 15, Projectile.velocity.RotatedByRandom(MathHelper.PiOver4) * Main.rand.NextFloat(0.2f, 0.5f), Scale: Main.rand.NextFloat(1.2f, 1.8f));
chust.noGravity = true;
}
}
if (Projectile.timeLeft <= 137)
{
if (Main.rand.NextBool(5))
{
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.2f, 0.5f), Scale: Main.rand.NextFloat(1.2f, 1.8f));
chust.noGravity = true;
}
if (Main.rand.NextBool(8))
{
Vector2 dustCenter = Projectile.Center + Projectile.velocity.RotatedBy(MathHelper.PiOver2).SafeNormalize(Vector2.Zero) * Main.rand.NextFloat(-3f, 3f);
Dust largeDust = Dust.NewDustPerfect(dustCenter, 257, -Projectile.velocity * Main.rand.NextFloat(0.2f, 0.4f), Scale: Main.rand.NextFloat(0.4f, 1f));
largeDust.noGravity = true;
largeDust.noLight = true;
}
if (Main.rand.NextBool(5))
{
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));
}
}
}
internal Color ColorFunction(float completionRatio)
{
float fadeOpacity = (float)Math.Sqrt(1 - completionRatio);
return Color.Lerp(Color.DeepSkyBlue, Color.YellowGreen, Projectile.timeLeft / 140f).MultiplyRGB(PrimColorMult) * fadeOpacity;
}
internal float WidthFunction(float completionRatio)
{
return 6.4f;
}
public override bool PreDraw(ref Color lightColor)
{
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, 0.5f, delegate (Vector2 offset, Color colorMod)
{
PrimColorMult = colorMod;
TrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition + offset, 30);
});
Main.spriteBatch.End();
Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix);
return false;
}
public override void Kill(int timeLeft)
{
SoundEngine.PlaySound(WulfrumProthesis.HitSound with { Volume = WulfrumProthesis.HitSound.Volume * 0.6f }, Projectile.Center);
}
public override bool OnTileCollide(Vector2 oldVelocity)
{
Collision.HitTiles(Projectile.position, Projectile.velocity, Projectile.width, Projectile.height);
return base.OnTileCollide(oldVelocity);
}
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
{
Main.player[Projectile.owner].MinionAttackTargetNPC = target.whoAmI; //There exists a "whoAmIToTargettingIndex but idk if thats needed question mark
int numParticles = Main.rand.Next(1, 3);
for (int i = 0; i < numParticles; i++)
{
Vector2 velocity = Projectile.velocity.SafeNormalize(Vector2.UnitY).RotatedByRandom(MathHelper.Pi / 6f) * Main.rand.NextFloat(3, 14);
GeneralParticleHandler.SpawnParticle(new TechyHoloysquareParticle(target.Center, velocity, Main.rand.NextFloat(2.5f, 3f), Main.rand.NextBool() ? new Color(99, 255, 229) : new Color(25, 132, 247), 25));
}
}
}
}