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,26 +53,46 @@ 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; Entity newTarget = null;
float lastDistance = float.MaxValue; float lastDistance = float.MaxValue;
for (int i = 0; i < (isPlayer ? Main.player.Length : Main.npc.Length); i++) if (isPlayer)
{ {
Entity entity = isPlayer ? (Entity) Main.player[i] : Main.npc[i]; for (int i = 0; i < Main.player.Length; i++)
if (entity != null && entity.active && target.CanHit(newTarget))
{ {
float distance = projectile.Distance(entity.Center); Player player = Main.player[i];
if (player != null && player.active && !player.dead && player.whoAmI != target.whoAmI)
{
float distance = projectile.Distance(player.Center);
if (distance < 1000f && distance < lastDistance) if (distance < 1000f && distance < lastDistance)
{ {
lastDistance = distance; lastDistance = distance;
newTarget = entity; 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; if (newTarget == null) return false;
Main.NewText(newTarget.position);
float speed = projectile.velocity.Length(); float speed = projectile.velocity.Length();
Vector2 velocity = newTarget.Center - projectile.Center; Vector2 velocity = newTarget.Center - projectile.Center;
@ -87,5 +106,8 @@ namespace Decimation.Content.Items.Accessories.Trinity
return true; return true;
} }
return false;
}
} }
} }