112 lines
4.1 KiB
C#
112 lines
4.1 KiB
C#
using Decimation.Lib.Util;
|
|
using Microsoft.Xna.Framework;
|
|
using Terraria;
|
|
using Terraria.ModLoader;
|
|
|
|
namespace Decimation.Content.Items.Accessories.Trinity
|
|
{
|
|
public class Body : TrinityAccessory
|
|
{
|
|
protected override string ItemName => "The Body";
|
|
|
|
protected override string ItemTooltip => "I feel all...\n" +
|
|
"Increases maximum life by 50\n" +
|
|
"You deal 10% more melee damage\n" +
|
|
"Your melee critical hit chances are increased by 10%\n" +
|
|
"Hostile projectiles have 10% chance to ricochet off you\nand target your enemies with 50% increased damage";
|
|
|
|
protected override void InitAccessory()
|
|
{
|
|
item.width = 10;
|
|
item.height = 16;
|
|
item.expert = true;
|
|
item.expertOnly = true;
|
|
item.rare = Rarity.Rainbow.GetRarityValue();
|
|
item.value = Item.sellPrice(gold: 5);
|
|
}
|
|
|
|
public override void UpdateAccessory(Player player, bool hideVisual)
|
|
{
|
|
player.statLifeMax2 += 50;
|
|
player.meleeDamage *= 1.10f;
|
|
player.meleeCrit = (int) (player.meleeCrit * 1.10f);
|
|
|
|
base.UpdateAccessory(player, hideVisual);
|
|
}
|
|
}
|
|
|
|
class BodyProjectileEffects : GlobalProjectile
|
|
{
|
|
public override void ModifyHitPvp(Projectile projectile, Player target, ref int damage, ref bool crit)
|
|
{
|
|
Ricochet(projectile, target, true, ref damage);
|
|
}
|
|
|
|
public override void ModifyHitPlayer(Projectile projectile, Player target, ref int damage, ref bool crit)
|
|
{
|
|
if (Ricochet(projectile, target, false, ref damage))
|
|
{
|
|
projectile.hostile = false;
|
|
projectile.friendly = true;
|
|
}
|
|
}
|
|
|
|
private bool Ricochet(Projectile projectile, Player target, bool isPlayer, ref int damage)
|
|
{
|
|
if (Main.expertMode && Main.rand.NextBool(10) &&
|
|
target.GetModPlayer().HasEquippedAccessory(ModContent.ItemType<Body>()))
|
|
{
|
|
Entity newTarget = null;
|
|
float lastDistance = float.MaxValue;
|
|
if (isPlayer)
|
|
{
|
|
for (int i = 0; i < Main.player.Length; i++)
|
|
{
|
|
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)
|
|
{
|
|
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;
|
|
|
|
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;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
} |