From 326f22714f8d92a051a4e4365f2f36afc8947676 Mon Sep 17 00:00:00 2001 From: FyloZ Date: Mon, 13 Jul 2020 00:13:28 -0400 Subject: [PATCH] Added The Body trinity item. --- Content/Items/Accessories/Trinity/Body.cs | 91 ++++++++++++++++++ Content/Items/Accessories/Trinity/Body.png | Bin 0 -> 201 bytes .../Accessories/Trinity/TrinityAccessory.cs | 14 +++ 3 files changed, 105 insertions(+) create mode 100644 Content/Items/Accessories/Trinity/Body.cs create mode 100644 Content/Items/Accessories/Trinity/Body.png create mode 100644 Content/Items/Accessories/Trinity/TrinityAccessory.cs diff --git a/Content/Items/Accessories/Trinity/Body.cs b/Content/Items/Accessories/Trinity/Body.cs new file mode 100644 index 0000000..cf64c9e --- /dev/null +++ b/Content/Items/Accessories/Trinity/Body.cs @@ -0,0 +1,91 @@ +using System.Collections.Generic; +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" + + "Increase maximum life by 50\n" + + "You deal 10% more melee damage\n" + + "Your melee critical hit chances are increase 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())) return false; + + 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]; + if (entity != null && entity.active && target.CanHit(newTarget)) + { + float distance = projectile.Distance(entity.Center); + if (distance < 1000f && distance < lastDistance) + { + lastDistance = distance; + newTarget = entity; + } + } + } + + 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; + } + } +} \ No newline at end of file diff --git a/Content/Items/Accessories/Trinity/Body.png b/Content/Items/Accessories/Trinity/Body.png new file mode 100644 index 0000000000000000000000000000000000000000..c2a2330a92ef9b315c849be4d4a558a8ef3d8d44 GIT binary patch literal 201 zcmeAS@N?(olHy`uVBq!ia0vp^AhrMp8<5nmf9C+C`aE46Lo|YuQyiGz`}F*8ZfQ9; zC)H(|)58W84y_hVfiIja(qHOMR~hgcOXexP*Cs!if=4 y&&F1;SjH4_l=(`eDbQsMp00i_>zopr7#IMB3`URu literal 0 HcmV?d00001 diff --git a/Content/Items/Accessories/Trinity/TrinityAccessory.cs b/Content/Items/Accessories/Trinity/TrinityAccessory.cs new file mode 100644 index 0000000..b730210 --- /dev/null +++ b/Content/Items/Accessories/Trinity/TrinityAccessory.cs @@ -0,0 +1,14 @@ +using Decimation.Lib.Items; +using Decimation.Lib.Util; +using Terraria; + +namespace Decimation.Content.Items.Accessories.Trinity +{ + public abstract class TrinityAccessory : DecimationAccessory + { + public override bool CanEquipAccessory(Player player, int slot) + { + return !player.HasEquippedAccessory(item.type); + } + } +} \ No newline at end of file