From 91c0b27c698575746bd3dbb6057a8a719e58f910 Mon Sep 17 00:00:00 2001 From: IbanPlay <56191483+IbanPlay@users.noreply.github.com> Date: Tue, 19 Jul 2022 07:46:57 +0200 Subject: [PATCH] Marntie repulsion shield --- Items/Accessories/MarniteRepulsionShield.cs | 202 ++++++++++++++++++ Items/Accessories/MarniteRepulsionShield.png | Bin 0 -> 606 bytes .../MarniteRepulsionShield_Back.png | Bin 0 -> 1325 bytes .../MarniteRepulsionShield_Quill.png | Bin 0 -> 179 bytes 4 files changed, 202 insertions(+) create mode 100644 Items/Accessories/MarniteRepulsionShield.cs create mode 100644 Items/Accessories/MarniteRepulsionShield.png create mode 100644 Items/Accessories/MarniteRepulsionShield_Back.png create mode 100644 Items/Accessories/MarniteRepulsionShield_Quill.png diff --git a/Items/Accessories/MarniteRepulsionShield.cs b/Items/Accessories/MarniteRepulsionShield.cs new file mode 100644 index 0000000000..0eb5b3a697 --- /dev/null +++ b/Items/Accessories/MarniteRepulsionShield.cs @@ -0,0 +1,202 @@ +using CalamityMod.CalPlayer; +using CalamityMod.Projectiles.Typeless; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using System; +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; +using System.Collections.Generic; +using System.Linq; +using static CalamityMod.CalamityUtils; + +namespace CalamityMod.Items.Accessories +{ + [AutoloadEquip(EquipType.Back)] + [LegacyName("MarniteBayonet")] + public class MarniteRepulsionShield : ModItem + { + public override void SetStaticDefaults() + { + SacrificeTotal = 1; + DisplayName.SetDefault("Marnite Repulsion Shield"); + Tooltip.SetDefault("Enemies behind you are struck by high-knockback hardlight quills\n" + + "[c/FFF191:Backstabbers Beware!]"); + } + + public override void SetDefaults() + { + Item.width = 24; + Item.height = 30; + Item.rare = ItemRarityID.Blue; + Item.accessory = true; + Item.defense = 2; + } + + public override void UpdateAccessory(Player player, bool hideVisual) + { + MarniteRepulsionShieldPlayer modPlayer = player.GetModPlayer(); + modPlayer.shieldEquipped = true; + + if (player.whoAmI == Main.myPlayer) + { + int baseDamage = 5; + var source = player.GetSource_Accessory(Item); + if (player.ownedProjectileCounts[ModContent.ProjectileType()] < 1) + { + var hitbox = Projectile.NewProjectileDirect(source, player.Center, Vector2.Zero, ModContent.ProjectileType(), baseDamage, 14f, Main.myPlayer); + hitbox.originalDamage = baseDamage; + } + } + } + + public override void AddRecipes() + { + CreateRecipe(). + AddRecipeGroup("AnyGoldBar", 5). + AddIngredient(ItemID.Granite, 15). + AddIngredient(ItemID.Marble, 15). + AddTile(TileID.Anvils). + Register(); + + } + } + + public class MarniteRepulsionShieldPlayer : ModPlayer + { + public bool shieldEquipped = false; + + public override void ResetEffects() + { + shieldEquipped = false; + } + + public override void UpdateDead() + { + shieldEquipped = false; + } + } + + public class MarniteRepulsionHitbox : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + + public Player Owner => Main.player[Projectile.owner]; + + public static Asset QuillTex; + public List Quills; + public ref float NewQuillCooldown => ref Projectile.localAI[0]; + public static int QuillTime = 50; + public struct QuillVisualData + { + public float rotation; + public int time; + + public QuillVisualData(float _rotation) + { + rotation = _rotation; + time = QuillTime; + } + } + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Repulsion Matrix"); + } + + + public override void SetDefaults() + { + Projectile.width = 40; + Projectile.height = 80; + Projectile.friendly = true; + Projectile.DamageType = TrueMeleeNoSpeedDamageClass.Instance; + Projectile.penetrate = -1; + Projectile.timeLeft = 700; + Projectile.tileCollide = false; + Projectile.netImportant = true; + } + + public override void AI() + { + if (Owner.active && Owner.GetModPlayer().shieldEquipped) + { + Projectile.Center = Owner.Center + Vector2.UnitX * Owner.direction * -20f; + if (Owner.mount.Active) + { + Projectile.Center += -Vector2.UnitY * Owner.mount.PlayerOffset; + } + } + + else + Projectile.active = false; + } + + public override bool? CanHitNPC(NPC target) + { + //Only enemies that are behind the player (shouldn't happen but just in case + if (Math.Sign((Owner.Center - target.Center).X) != Owner.direction) + return false; + + return base.CanHitNPC(target); + } + + public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection) + { + hitDirection = Math.Sign(-Owner.direction); + } + + public override bool? CanCutTiles() => false; + + public CurveSegment burstOut = new CurveSegment(PolyInOutEasing, 0f, 0f, 1f, 3); + public CurveSegment stay = new CurveSegment(LinearEasing, 0.25f, 1f, 0f); + public CurveSegment retract = new CurveSegment(PolyOutEasing, 0.8f, 1f, -0.8f); + internal float QuillDisplace(float quillProgress) => PiecewiseAnimation(quillProgress, new CurveSegment[] { burstOut, stay, retract }); + + + public override bool PreDraw(ref Color lightColor) + { + return false; + + if (QuillTex == null) + QuillTex = ModContent.Request("CalamityMod/Items/Accessories/MarniteRepulsionShield_Quill"); + Texture2D quillTex = QuillTex.Value; + + if (Quills == null) + Quills = new List(); + + NewQuillCooldown--; + if (NewQuillCooldown <= 0) + { + Quills.Add(new QuillVisualData(Main.rand.NextFloat(-MathHelper.PiOver2, MathHelper.PiOver2))); + NewQuillCooldown = QuillTime / 4f; + } + + for (int i = 0; i < Quills.Count; i++) + { + QuillVisualData quill = Quills[i]; + + float rotation = quill.rotation + (Owner.direction < 0 ? MathHelper.Pi : 0); + + float bounce = (float)Math.Sin((quill.time / (float)QuillTime) * MathHelper.Pi) * 2f; + float quillOpacity = Math.Min(bounce, 1f); + float quillDisplacement = QuillDisplace(1 - quill.time / (float)QuillTime) * 14f; + + Vector2 quillPosition = Projectile.Center + Vector2.UnitX * (Projectile.width / 2f - 10f) * Owner.direction; + quillPosition += Vector2.UnitX.RotatedBy(rotation) * quillDisplacement; + + Vector2 quillOrigin = new Vector2(quillTex.Width / 2f, quillTex.Height); + + Main.EntitySpriteDraw(quillTex, quillPosition - Main.screenPosition, null, lightColor * quillOpacity, rotation + MathHelper.PiOver2 * Owner.direction, quillOrigin, 1f, SpriteEffects.None, 0); + + quill.time--; + Quills[i] = quill; + } + + Quills.RemoveAll(q => q.time < 0); + + return false; + } + } +} diff --git a/Items/Accessories/MarniteRepulsionShield.png b/Items/Accessories/MarniteRepulsionShield.png new file mode 100644 index 0000000000000000000000000000000000000000..75d01b3b8f0d1ee6f6e3e7081cad0eb498a94b0a GIT binary patch literal 606 zcmV-k0-^nhP)Px%7)eAyR7i=vmQP3&aTLctlk4s(3oX0oIuc%rx=8AxLYL^UkcqIT@ZiaVlu*#6 zbGI((P4Li72ok}AM1O7(Vv**b*o#Xd?7?Xll|5AKS}`7G9@`roy)^T^%)Iw|znSm% z_ul*ceg+<7uisa8G|>sb(T_d*Uw<9L05~jvQSny!v$8LEfAGIy$cr$KCocm~tL`Yq zX5XZmxc+uR+3{G?0I1cgKtoCJ3WRx2_g?_E3QabgWNdBBp7|lGybhdH61aj$qN5*x zt-_iOF#WU+z|?}v%w;YNy?8W!5rFyES&5U}84yMehVpX&G$ng%fNNJe0C>OfL}<+2Uh{OG^5wl z4>C_6xsa+_Tym5Jui$s&4gim5#$4CSQv2b z1760lPugyKc<55lCmsUgL+7+Yh;X4uInF3*`?!2XcnW?k7s* zS@Jo_WIUHoDZempjn+as(ag*s0P$E7fLgt(l#C8L)m1ngP!pwE7MF@ZgL!*ry8%$y ss{mo%?EIAYL8{BU=D&{OK!`WHWAmcAp>Q$nm;e9(07*qoM6N<$f)Ga=4*&oF literal 0 HcmV?d00001 diff --git a/Items/Accessories/MarniteRepulsionShield_Back.png b/Items/Accessories/MarniteRepulsionShield_Back.png new file mode 100644 index 0000000000000000000000000000000000000000..d178532eaf25f4bf9cff2235fced8f1673ea2773 GIT binary patch literal 1325 zcmeAS@N?(olHy`uVBq!ia0vp^8Vn392^?%d*6dv(^+1ZTILO_JVcj{Imq3~4o-U3d z6?5L++MgF)Ds$}N^@X9$A{pB!aH=>s$qIyUn3Y9H>|_wDV(##E=xFSnD5>bWh&d;Q zVZot0_T1ek8@yaxnR1iatTl5B9cq)0UaOpUbkpb07e9vYmy!3L&%(g);7iZ5zYi~+ zey{F%jc=X0=eK`*W~5HhWGIkFQksEPDN>dUCy<%>N%ZzkK}nFzg`Tg-4Y_Nd(|Bm6Xa=z!?=P3Da=R;9R?e{r-9y;SAyiWPI1@8!4w2p%`+W$ zgurYE#UMi)o(O@(7&AyAv7SjNU1=A!s(;$6#Y=x>;9`Odq<#!G9A9darP&{KYVovB lD{wKHfL2pEIX)=)%loP}JMf?7mROL_JYD@<);T3K0RUPfi{AhM literal 0 HcmV?d00001 diff --git a/Items/Accessories/MarniteRepulsionShield_Quill.png b/Items/Accessories/MarniteRepulsionShield_Quill.png new file mode 100644 index 0000000000000000000000000000000000000000..d22517ed24e6a8ba206cbd867858a7164d24e272 GIT binary patch literal 179 zcmeAS@N?(olHy`uVBq!ia0vp^Y(UJ%0U~+k=c)oJ#^NA%Cx&(BWL^R}xt=bLAre!Q zzx3@t!NB@|p@}jx5C}8#9Z*_x@azE~`0(vmI2#B^$Zzl4ZocnddO||Nhv)@|L6RFZ zAD*h;WA#GuV8)W^ALlm$!QUe#Ak}U2#b*8}-C$rTY3LN{bcg@x<135|vt2}Aq`da) Q1X|4C>FVdQ&MBb@0KKw7xc~qF literal 0 HcmV?d00001