Fixed Timekeeper crash?

This commit is contained in:
FyloZ 2020-07-19 22:40:17 -04:00
parent 847841c181
commit f188eb2757
4 changed files with 30 additions and 22 deletions

View File

@ -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;
}
}
}

View File

@ -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;
}
}

View File

@ -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++)
{

View File

@ -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);
}
}
}