From f188eb2757c88933eebfce07e6926372ba95a1ff Mon Sep 17 00:00:00 2001 From: FyloZ Date: Sun, 19 Jul 2020 22:40:17 -0400 Subject: [PATCH] Fixed Timekeeper crash? --- .../Projectiles/Boss/DuneWyrm/Timekeeper.cs | 42 ++++++++++--------- Lib/Items/DecimationTool.cs | 1 - Lib/Util/DustUtils.cs | 2 +- Lib/Util/LightingUtils.cs | 7 +++- 4 files changed, 30 insertions(+), 22 deletions(-) diff --git a/Content/Projectiles/Boss/DuneWyrm/Timekeeper.cs b/Content/Projectiles/Boss/DuneWyrm/Timekeeper.cs index 45567b4..80b9bdf 100644 --- a/Content/Projectiles/Boss/DuneWyrm/Timekeeper.cs +++ b/Content/Projectiles/Boss/DuneWyrm/Timekeeper.cs @@ -1,5 +1,6 @@ using System; using Decimation.Lib.Items; +using Decimation.Lib.Util; using Microsoft.Xna.Framework; using Terraria; @@ -22,8 +23,7 @@ namespace Decimation.Content.Projectiles.Boss.DuneWyrm set => projectile.localAI[1] = value; } - private Projectile SiblingProjectile => - Sibling >= 0 && Sibling < Main.projectile.Length ? Main.projectile[Sibling] : null; + private Projectile SiblingProjectile => !IsChild && Sibling >= 0 && Sibling < Main.projectile.Length ? Main.projectile[Sibling] : null; private int Counter { @@ -36,6 +36,8 @@ namespace Decimation.Content.Projectiles.Boss.DuneWyrm private float Speed { get; set; } private bool Initialization { get; set; } = true; + private readonly Vector3 _dustColor = LightingUtils.Rgb255ToRgb1(106, 232, 184); + protected override void Init() { projectile.width = 12; @@ -50,24 +52,21 @@ namespace Decimation.Content.Projectiles.Boss.DuneWyrm public override bool PreKill(int timeLeft) { SiblingProjectile?.Kill(); - + return true; } public override void Kill(int timeLeft) { - for (int i = 0; i < 8; i++) - { - Dust.NewDust(projectile.position, projectile.width, projectile.height, 135, 0, - 0, 100, default, 4f * projectile.scale); - } + DustUtils.NewDustCircle(8, projectile.position, projectile.width, projectile.height, 229, + 1.5f * projectile.scale, gravity: true); } public override void AI() { if (!IsChild) { - if (Sibling == -1) + if (SiblingProjectile == null) { projectile.position.Y -= 8f; @@ -85,15 +84,19 @@ namespace Decimation.Content.Projectiles.Boss.DuneWyrm projectile.velocity = parentVelocity.RotatedBy(Rotation); // Sibling - Vector2 siblingVelocity = parentVelocity * new Vector2(1, -1); - SiblingProjectile.velocity = siblingVelocity.RotatedBy(Rotation); - - if (Initialization) + if (SiblingProjectile != null) { - Vector2 offset = new Vector2(projectile.position.X - SiblingProjectile.position.X, -16); - projectile.velocity += offset.RotatedBy(Rotation); + Vector2 siblingVelocity = parentVelocity * new Vector2(1, -1); + SiblingProjectile.velocity = siblingVelocity.RotatedBy(Rotation); - Initialization = false; + + if (Initialization) + { + Vector2 offset = new Vector2(projectile.position.X - SiblingProjectile.position.X, -16); + projectile.velocity += offset.RotatedBy(Rotation); + + Initialization = false; + } } Counter++; @@ -103,9 +106,10 @@ namespace Decimation.Content.Projectiles.Boss.DuneWyrm Sibling = projectile.owner; } - Lighting.AddLight(projectile.Center, 0f, 0f, 1f); - Dust.NewDust(projectile.position, projectile.width, projectile.height, 135, projectile.velocity.X * 0.2f, - projectile.velocity.Y * 0.2f, 100, default, 2f * projectile.scale); + Lighting.AddLight(projectile.Center, _dustColor); + Dust dust = Dust.NewDustDirect(projectile.position, projectile.width, projectile.height, 229, projectile.velocity.X * 0.2f, + projectile.velocity.Y * 0.2f, 100, default, 1f * projectile.scale); + dust.noGravity = true; } } } \ No newline at end of file diff --git a/Lib/Items/DecimationTool.cs b/Lib/Items/DecimationTool.cs index 1ecd54d..f5fb94b 100644 --- a/Lib/Items/DecimationTool.cs +++ b/Lib/Items/DecimationTool.cs @@ -24,7 +24,6 @@ item.axe = AxePower / 5; // Axe power is multiplied by 5 for some reason item.hammer = HammerPower; - item.damage = 1000; if (MeleeDamages > 0) item.noMelee = false; } } diff --git a/Lib/Util/DustUtils.cs b/Lib/Util/DustUtils.cs index d869a8f..8dfec06 100644 --- a/Lib/Util/DustUtils.cs +++ b/Lib/Util/DustUtils.cs @@ -6,7 +6,7 @@ namespace Decimation.Lib.Util { public class DustUtils { - public static void NewDustCircle(int amount, Vector2 position, int width, int height, int type, float scale = 1f, float speedX = 1f, float speedY = 1f, bool gravity = false, int alpha = 0, Color color = default) + public static void NewDustCircle(int amount, Vector2 position, int width, int height, int type, float scale = 1f, float speedX = 0f, float speedY = 0f, bool gravity = false, int alpha = 0, Color color = default) { for (int i = 0; i < amount; i++) { diff --git a/Lib/Util/LightingUtils.cs b/Lib/Util/LightingUtils.cs index 106b62d..13d819b 100644 --- a/Lib/Util/LightingUtils.cs +++ b/Lib/Util/LightingUtils.cs @@ -2,11 +2,16 @@ using Microsoft.Xna.Framework; namespace Decimation.Lib.Util { - public class LightingUtils + public static class LightingUtils { public static Vector3 Rgb255ToRgb1(int r, int g, int b) { return new Vector3(r / 255f, g / 255f, b / 255f); } + + public static Color Rgb1ToColor(this Vector3 rgb) + { + return new Color(rgb.X, rgb.Y, rgb.Z); + } } } \ No newline at end of file