Fixed The Body not ricocheting projectiles.

This commit is contained in:
FyloZ 2020-07-13 11:29:12 -04:00
parent 326f22714f
commit 3e441699c9

View File

@ -1,4 +1,3 @@
using System.Collections.Generic;
using Decimation.Lib.Util; using Decimation.Lib.Util;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Terraria; using Terraria;
@ -54,38 +53,61 @@ namespace Decimation.Content.Items.Accessories.Trinity
private bool Ricochet(Projectile projectile, Player target, bool isPlayer, ref int damage) private bool Ricochet(Projectile projectile, Player target, bool isPlayer, ref int damage)
{ {
if (!Main.expertMode || !Main.rand.NextBool(10) || if (Main.expertMode && Main.rand.NextBool(10) &&
!target.GetModPlayer().HasEquippedAccessory(ModContent.ItemType<Body>())) return false; target.GetModPlayer().HasEquippedAccessory(ModContent.ItemType<Body>()))
Entity newTarget = null;
float lastDistance = float.MaxValue;
for (int i = 0; i < (isPlayer ? Main.player.Length : Main.npc.Length); i++)
{ {
Entity entity = isPlayer ? (Entity) Main.player[i] : Main.npc[i]; Entity newTarget = null;
if (entity != null && entity.active && target.CanHit(newTarget)) float lastDistance = float.MaxValue;
if (isPlayer)
{ {
float distance = projectile.Distance(entity.Center); for (int i = 0; i < Main.player.Length; i++)
if (distance < 1000f && distance < lastDistance)
{ {
lastDistance = distance; Player player = Main.player[i];
newTarget = entity; if (player != null && player.active && !player.dead && player.whoAmI != target.whoAmI)
{
float distance = projectile.Distance(player.Center);
if (distance < 1000f && distance < lastDistance)
{
lastDistance = distance;
newTarget = player;
}
}
} }
} }
else
{
for (int i = 0; i < Main.npc.Length; i++)
{
NPC npc = Main.npc[i];
if (npc != null && npc.active && !npc.friendly)
{
float distance = projectile.Distance(npc.Center);
if (distance < 1000f && distance < lastDistance)
{
lastDistance = distance;
newTarget = npc;
}
}
}
}
if (newTarget == null) return false;
Main.NewText(newTarget.position);
float speed = projectile.velocity.Length();
Vector2 velocity = newTarget.Center - projectile.Center;
velocity.Normalize();
velocity *= speed;
projectile.velocity = velocity;
projectile.damage = (int) (projectile.damage * 1.5f);
damage = 0;
return true;
} }
if (newTarget == null) return false; return false;
float speed = projectile.velocity.Length();
Vector2 velocity = newTarget.Center - projectile.Center;
velocity.Normalize();
velocity *= speed;
projectile.velocity = velocity;
projectile.damage = (int) (projectile.damage * 1.5f);
damage = 0;
return true;
} }
} }
} }