Moved a few utility methods

This commit is contained in:
DominicKarma authored and Cameron Ewell committed 2021-02-01 22:31:22 -05:00
1 parent 0cd116af6f
commit 51412fcfae
10 files changed
+52 -83

No files matched your search

+1 -1
View File
@@ -690,7 +690,7 @@ namespace CalamityMod.NPCs.Providence
int dustAmt = (int)MathHelper.Lerp(4f, 8f, calamityGlobalNPC.newAI[3] / spawnAnimationTime);
for (int m = 0; m < dustAmt; m++)
{
float fade = MathHelper.Lerp(1.3f, 0.7f, npc.Opacity) * CalamityUtils.GetLerpValue(0f, 120f, calamityGlobalNPC.newAI[3], clamped: true);
float fade = MathHelper.Lerp(1.3f, 0.7f, npc.Opacity) * Utils.InverseLerp(0f, 120f, calamityGlobalNPC.newAI[3], clamped: true);
Color newColor = Main.hslToRgb(calamityGlobalNPC.newAI[3] / 180f, 1f, 0.5f);
if (!nightTime)
+1 -1
View File
@@ -57,7 +57,7 @@ namespace CalamityMod.Projectiles.Boss
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
{
float lerpMult = CalamityUtils.GetLerpValue(15f, 30f, projectile.timeLeft, clamped: true) * CalamityUtils.GetLerpValue(240f, 200f, projectile.timeLeft, clamped: true) * (1f + 0.2f * (float)Math.Cos(Main.GlobalTime % 30f / 0.5f * (MathHelper.Pi * 2f) * 3f)) * 0.8f;
float lerpMult = Utils.InverseLerp(15f, 30f, projectile.timeLeft, clamped: true) * Utils.InverseLerp(240f, 200f, projectile.timeLeft, clamped: true) * (1f + 0.2f * (float)Math.Cos(Main.GlobalTime % 30f / 0.5f * (MathHelper.Pi * 2f) * 3f)) * 0.8f;
Texture2D texture = Main.projectileTexture[projectile.type];
Vector2 drawPos = projectile.Center - Main.screenPosition + new Vector2(0f, projectile.gfxOffY);
+3 -3
View File
@@ -39,9 +39,9 @@ namespace CalamityMod.Projectiles.Boss
float[] hue = new float[drawnAmt];
float[] size = new float[drawnAmt];
int totalTime = 210;
float colorChangeAmt = CalamityUtils.GetLerpValue(0f, 60f, projectile.timeLeft, true) * CalamityUtils.GetLerpValue(totalTime, totalTime - 60, projectile.timeLeft, true);
float colorChangeAmt2 = CalamityUtils.GetLerpValue(0f, 60f, projectile.timeLeft, true) * CalamityUtils.GetLerpValue(totalTime, 90f, projectile.timeLeft, true);
colorChangeAmt2 = CalamityUtils.GetLerpValue(0.2f, 0.5f, colorChangeAmt2, true);
float colorChangeAmt = Utils.InverseLerp(0f, 60f, projectile.timeLeft, true) * Utils.InverseLerp(totalTime, totalTime - 60, projectile.timeLeft, true);
float colorChangeAmt2 = Utils.InverseLerp(0f, 60f, projectile.timeLeft, true) * Utils.InverseLerp(totalTime, 90f, projectile.timeLeft, true);
colorChangeAmt2 = Utils.InverseLerp(0.2f, 0.5f, colorChangeAmt2, true);
float sizeScale = 0.8f;
float sizeScalar = (1f - sizeScale) / drawnAmt;
float yPosOffset = 60f;
+1 -1
View File
@@ -72,7 +72,7 @@ namespace CalamityMod.Projectiles.Boss
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
{
float lerpMult = CalamityUtils.GetLerpValue(15f, 30f, projectile.timeLeft, clamped: true) * CalamityUtils.GetLerpValue(240f, 200f, projectile.timeLeft, clamped: true) * (1f + 0.2f * (float)Math.Cos(Main.GlobalTime % 30f / 0.5f * (MathHelper.Pi * 2f) * 3f)) * 0.8f;
float lerpMult = Utils.InverseLerp(15f, 30f, projectile.timeLeft, clamped: true) * Utils.InverseLerp(240f, 200f, projectile.timeLeft, clamped: true) * (1f + 0.2f * (float)Math.Cos(Main.GlobalTime % 30f / 0.5f * (MathHelper.Pi * 2f) * 3f)) * 0.8f;
Texture2D texture = Main.projectileTexture[projectile.type];
Vector2 drawPos = projectile.Center - Main.screenPosition + new Vector2(0f, projectile.gfxOffY);
+2 -2
View File
@@ -73,14 +73,14 @@ namespace CalamityMod.Projectiles.Boss
Color color34 = color33;
Vector2 origin5 = value.Size() / 2f;
Color color35 = color33 * 0.5f;
float num162 = CalamityUtils.GetLerpValue(15f, 30f, projectile.timeLeft, clamped: true) * CalamityUtils.GetLerpValue(240f, 200f, projectile.timeLeft, clamped: true) * (1f + 0.2f * (float)Math.Cos(Main.GlobalTime % 30f / 0.5f * ((float)Math.PI * 2f) * 3f)) * 0.8f;
float num162 = Utils.InverseLerp(15f, 30f, projectile.timeLeft, clamped: true) * Utils.InverseLerp(240f, 200f, projectile.timeLeft, clamped: true) * (1f + 0.2f * (float)Math.Cos(Main.GlobalTime % 30f / 0.5f * ((float)Math.PI * 2f) * 3f)) * 0.8f;
Vector2 vector29 = new Vector2(0.5f, 1f) * num162;
Vector2 vector30 = new Vector2(0.5f, 1f) * num162;
color34 *= num162;
color35 *= num162;
int num163 = 0;
Vector2 position3 = vector28 + projectile.velocity.SafeNormalize(Vector2.Zero) * CalamityUtils.GetLerpValue(0.5f, 1f, projectile.localAI[0] / 60f, clamped: true) * num163;
Vector2 position3 = vector28 + projectile.velocity.SafeNormalize(Vector2.Zero) * Utils.InverseLerp(0.5f, 1f, projectile.localAI[0] / 60f, clamped: true) * num163;
SpriteEffects spriteEffects = SpriteEffects.None;
if (projectile.spriteDirection == -1)
+1 -1
View File
@@ -137,7 +137,7 @@ namespace CalamityMod.Projectiles.Boss
Color color34 = color33;
Vector2 origin5 = value.Size() / 2f;
Color color35 = color33 * 0.5f;
float num162 = CalamityUtils.GetLerpValue(15f, 30f, projectile.timeLeft, clamped: true) * CalamityUtils.GetLerpValue(240f, 200f, projectile.timeLeft, clamped: true) * (1f + 0.2f * (float)Math.Cos(Main.GlobalTime % 30f / 0.5f * ((float)Math.PI * 2f) * 3f)) * 0.8f;
float num162 = Utils.InverseLerp(15f, 30f, projectile.timeLeft, clamped: true) * Utils.InverseLerp(240f, 200f, projectile.timeLeft, clamped: true) * (1f + 0.2f * (float)Math.Cos(Main.GlobalTime % 30f / 0.5f * ((float)Math.PI * 2f) * 3f)) * 0.8f;
Vector2 vector29 = new Vector2(1f, 1.5f) * num162;
Vector2 vector30 = new Vector2(0.5f, 1f) * num162;
color34 *= num162;
+11
View File
@@ -19,5 +19,16 @@ namespace CalamityMod
/// <param name="v1">The first vector.</param>
/// <param name="v2">The second vector.</param>
public static float AngleBetween(this Vector2 v1, Vector2 v2) => (float)Math.Acos(Vector2.Dot(v1.SafeNormalize(Vector2.Zero), v2.SafeNormalize(Vector2.Zero)));
// REMOVE THIS IN CALAMITY 1.4, it's a 1.4 World.cs function.
// Due to its temporary state, this method will not receive an XML documentation comment.
public static Rectangle ClampToWorld(Rectangle tileRectangle)
{
int num = Math.Max(0, Math.Min(tileRectangle.Left, Main.maxTilesX));
int num2 = Math.Max(0, Math.Min(tileRectangle.Top, Main.maxTilesY));
int num3 = Math.Max(0, Math.Min(tileRectangle.Right, Main.maxTilesX));
int num4 = Math.Max(0, Math.Min(tileRectangle.Bottom, Main.maxTilesY));
return new Rectangle(num, num2, num3 - num, num4 - num2);
}
}
}
-74
View File
@@ -213,38 +213,6 @@ namespace CalamityMod
list.Add(type);
}
public static void Inflict246DebuffsNPC(NPC target, int buff, float timeBase = 2f)
{
if (Main.rand.NextBool(4))
{
target.AddBuff(buff, SecondsToFrames(timeBase * 3f), false);
}
else if (Main.rand.NextBool(2))
{
target.AddBuff(buff, SecondsToFrames(timeBase * 2f), false);
}
else
{
target.AddBuff(buff, SecondsToFrames(timeBase), false);
}
}
public static void Inflict246DebuffsPvp(Player target, int buff, float timeBase = 2f)
{
if (Main.rand.NextBool(4))
{
target.AddBuff(buff, SecondsToFrames(timeBase * 3f), false);
}
else if (Main.rand.NextBool(2))
{
target.AddBuff(buff, SecondsToFrames(timeBase * 2f), false);
}
else
{
target.AddBuff(buff, SecondsToFrames(timeBase), false);
}
}
public static int SecondsToFrames(int seconds) => seconds * 60;
public static int SecondsToFrames(float seconds) => (int)(seconds * 60);
@@ -289,38 +257,6 @@ namespace CalamityMod
public static bool WithinBounds(this int index, int cap) => index >= 0 && index < cap;
// REMOVE THIS IN CALAMITY 1.4, it's a 1.4 Main.cs function
public static float GetLerpValue(float from, float to, float t, bool clamped = false)
{
if (clamped)
{
if (from < to)
{
if (t < from)
{
return 0f;
}
if (t > to)
{
return 1f;
}
}
else
{
if (t < to)
{
return 1f;
}
if (t > from)
{
return 0f;
}
}
}
return (t - from) / (to - from);
}
/// <summary>
/// Clamps the distance between vectors via normalization.
/// </summary>
/// <param name="start">The starting point.</param>
@@ -333,15 +269,5 @@ namespace CalamityMod
end = start + Vector2.Normalize(end - start) * maxDistance;
}
}
// REMOVE THIS IN CALAMITY 1.4, it's a 1.4 World.cs function
public static Rectangle ClampToWorld(Rectangle tileRectangle)
{
int num = Math.Max(0, Math.Min(tileRectangle.Left, Main.maxTilesX));
int num2 = Math.Max(0, Math.Min(tileRectangle.Top, Main.maxTilesY));
int num3 = Math.Max(0, Math.Min(tileRectangle.Right, Main.maxTilesX));
int num4 = Math.Max(0, Math.Min(tileRectangle.Bottom, Main.maxTilesY));
return new Rectangle(num, num2, num3 - num, num4 - num2);
}
}
}
+16
View File
@@ -407,6 +407,22 @@ namespace CalamityMod
}
}
public static void Inflict246DebuffsNPC(NPC target, int buff, float timeBase = 2f)
{
if (Main.rand.NextBool(4))
{
target.AddBuff(buff, SecondsToFrames(timeBase * 3f), false);
}
else if (Main.rand.NextBool(2))
{
target.AddBuff(buff, SecondsToFrames(timeBase * 2f), false);
}
else
{
target.AddBuff(buff, SecondsToFrames(timeBase), false);
}
}
/// Inflict typical exo weapon debuffs. Duration multiplier optional.
/// </summary>
/// <param name="target">The NPC attacked.</param>
+16
View File
@@ -118,6 +118,22 @@ namespace CalamityMod
damageMult += mp.GetAdrenalineDamage();
}
public static void Inflict246DebuffsPvp(Player target, int buff, float timeBase = 2f)
{
if (Main.rand.NextBool(4))
{
target.AddBuff(buff, SecondsToFrames(timeBase * 3f), false);
}
else if (Main.rand.NextBool(2))
{
target.AddBuff(buff, SecondsToFrames(timeBase * 2f), false);
}
else
{
target.AddBuff(buff, SecondsToFrames(timeBase), false);
}
}
/// <summary>
/// Inflict typical exo weapon debuffs in pvp.
/// </summary>