From aa65b6d170167694b1db1be2d3fc5b1ef2a2f06c Mon Sep 17 00:00:00 2001 From: Mr-Memes Date: Tue, 6 Aug 2024 16:52:01 +0200 Subject: [PATCH] Enchanted Blade Staff start. --- Buffs/Summon/EnchantedBladeStaffBuff.cs | 34 +++ Buffs/Summon/EnchantedBladeStaffBuff.png | Bin 0 -> 603 bytes CalPlayer/CalamityPlayer.cs | 2 + Items/Weapons/Summon/EnchantedBladeStaff.cs | 50 ++++ Items/Weapons/Summon/EnchantedBladeStaff.png | Bin 0 -> 986 bytes .../en-US/Mods.CalamityMod.Buffs.hjson | 5 + ...ods.CalamityMod.Items.Weapons.Summon.hjson | 5 + .../Mods.CalamityMod.Projectiles.Summon.hjson | 2 + .../Summon/EnchantedBladeStaffProjectile.cs | 46 ++++ .../Summon/EnchantedBladeStaffProjectile.png | Bin 0 -> 319 bytes Projectiles/Summon/EnchantedBladeSummon.cs | 241 ++++++++++++++++++ Projectiles/Summon/EnchantedBladeSummon.png | Bin 0 -> 532 bytes 12 files changed, 385 insertions(+) create mode 100644 Buffs/Summon/EnchantedBladeStaffBuff.cs create mode 100644 Buffs/Summon/EnchantedBladeStaffBuff.png create mode 100644 Items/Weapons/Summon/EnchantedBladeStaff.cs create mode 100644 Items/Weapons/Summon/EnchantedBladeStaff.png create mode 100644 Projectiles/Summon/EnchantedBladeStaffProjectile.cs create mode 100644 Projectiles/Summon/EnchantedBladeStaffProjectile.png create mode 100644 Projectiles/Summon/EnchantedBladeSummon.cs create mode 100644 Projectiles/Summon/EnchantedBladeSummon.png diff --git a/Buffs/Summon/EnchantedBladeStaffBuff.cs b/Buffs/Summon/EnchantedBladeStaffBuff.cs new file mode 100644 index 0000000000..2bdf655ab3 --- /dev/null +++ b/Buffs/Summon/EnchantedBladeStaffBuff.cs @@ -0,0 +1,34 @@ +using CalamityMod.CalPlayer; +using CalamityMod.Projectiles.Summon; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Buffs.Summon +{ + public class EnchantedBladeStaffBuff : ModBuff + { + public override void SetStaticDefaults() + { + Main.buffNoTimeDisplay[Type] = true; + Main.buffNoSave[Type] = true; + } + + public override void Update(Player player, ref int buffIndex) + { + CalamityPlayer modPlayer = player.Calamity(); + if (player.ownedProjectileCounts[ModContent.ProjectileType()] > 0) + { + modPlayer.EnchantedBladeStaffBool = true; + } + if (!modPlayer.EnchantedBladeStaffBool) + { + player.DelBuff(buffIndex); + buffIndex--; + } + else + { + player.buffTime[buffIndex] = 18000; + } + } + } +} diff --git a/Buffs/Summon/EnchantedBladeStaffBuff.png b/Buffs/Summon/EnchantedBladeStaffBuff.png new file mode 100644 index 0000000000000000000000000000000000000000..a0efadf1887c26fae6d9a1786c549f25d2e7f865 GIT binary patch literal 603 zcmV-h0;K(kP)Px%6-h)vR9J=0mrqDkK^(_F8xJoo9um_<{KG1A*+T~pB1qsN$b%qwu%JY!OVPpm z9=(PKk1m)&`OY3zNC-lZh-WNhL{v)!l6CMPdI{lmc<<{nqeG8UcD|Q+GjDz~^ZU%d z-{ksxh5Zp^L=Wy%_*%Ye~631g5_wX_)3UXMdAC3h&MW zF#2>EfP=ExjtHoqN^0*90m=4UtJaqGzw3OEoz{YjsDA`(6{hn*W3{`8$iq#?T5!pK z0xs!nFF4jfR{2N3KD*CLY8PgVa{mZqmF|w+{~Uln1j4=~weM|7vE0Js9st*G+%f*Y zO3UXSSB-MJ9rYtMoxnd2Ad0q$qV47l;JkEd7ii9O2k2~9)cn3Z-N*Y$^5#X7MxW-= zdR>N{?gT|jw)`P*a<-?Quix$j;O6t6K;!;@Sy=&K?ALg; zOHC(m@-D~+;{XhfF9MCY-InUDmO22~ue}A}VbBA>;c@j$JH0zTS05Smnopq6J_x{Z pyccIN5CNB51Z)MlE "Items.Weapons.Summon"; + + public override void SetDefaults() + { + Item.damage = 10; + Item.DamageType = DamageClass.Summon; + Item.shoot = ModContent.ProjectileType(); + Item.knockBack = 2f; + + Item.useTime = Item.useAnimation = 15; + Item.mana = 10; + Item.noMelee = true; + Item.autoReuse = true; + Item.width = 50; + Item.height = 50; + Item.value = CalamityGlobalItem.RarityBlueBuyPrice; + Item.rare = ItemRarityID.Blue; + Item.useStyle = ItemUseStyleID.Shoot; + Item.UseSound = SoundID.Item8; + + Item.shootSpeed = 1f; + } + + public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) + { + var minion = Projectile.NewProjectileDirect(source, Main.MouseWorld, Vector2.Zero, type, damage, knockback, player.whoAmI); + minion.velocity = minion.DirectionFrom(player.Center); + return false; + } + + public override void AddRecipes() + { + base.AddRecipes(); + } + } +} diff --git a/Items/Weapons/Summon/EnchantedBladeStaff.png b/Items/Weapons/Summon/EnchantedBladeStaff.png new file mode 100644 index 0000000000000000000000000000000000000000..acafcb8fc973e6bc9f08f91bfc1480b08ade1bbd GIT binary patch literal 986 zcmV<0110>4P)Px&lu1NERA_!$lHbxf;3lmLTs6mNeF$xPd8Vw7P#-MCKP$*zD)@s97TM!;L2x#hJdhP(HJ!Uj#?{CMQf(x0Qk8 zTmJ$-d_D(Eo7P%1GAd@=7SCuV(*Pdg+o z3vDf6@tsq^`fc|m;^%L88kbk6hPlfk==kMZ#kB#gcj4vx|xaxC?MuuZXc`4}4o(J38e@t9&KOA>%3*tGiYrX_p=G1|W zyIKY#*N*6UMI(g>)oOZaJaoeyHG@~;8Lt|g@omfRN!%Bz*oj{|kuz3X{aFN2>BCoj zZfcBNx6U3+EUcRi4s~`7z*EgtU}XUV8@KMh;&`>wZi(QxKmSJI{t-xxkx}PJFc6qs z9nX9)@ygmKK>gHXSG+&u!VnT)$4E^CQe)(rb0nBp(%1;T-?uNZzX&EO7dL~G`}csI zyLKeTX+Ioy_G`_BLKKZ)0N&m7HfU;El8F0q^Cs}(J0F1Mi{?epbNUqMzYzD8uHGz0 zZz7NyBg0m$Rmg@SMb*jt6-}r;;UIlaK-3=O>mLg~3P-hp$&O{)+Mhcl|Sro5g!=5`3_8IT( ziC3#DRy+{FjvZfP>`eqxW29i!8qP#my#^DZLyxzKK>Cb?+$hi746^+fkTa2=3xWEY ziU^K$#~pjTO$1V7BpR+tg?&RXQ8i_91Sig2Obm3ROaxM6q-3NfuGhX{tVoZMd=r8E zoS3L40_iale&qLyK&Va=)kGkDM&A13Foyi+npdSJI;k=8AIzIry@=LNPXGV_07*qo IM6N<$f(B2-SO5S3 literal 0 HcmV?d00001 diff --git a/Localization/en-US/Mods.CalamityMod.Buffs.hjson b/Localization/en-US/Mods.CalamityMod.Buffs.hjson index 546fec1f08..edfe6f68ae 100644 --- a/Localization/en-US/Mods.CalamityMod.Buffs.hjson +++ b/Localization/en-US/Mods.CalamityMod.Buffs.hjson @@ -1557,3 +1557,8 @@ Voidfrost: { DisplayName: Voidfrost Description: The emptiness of space devours all warmth and life } + +EnchantedBladeStaffBuff: { + DisplayName: Enchanted Blade Staff Buff + Description: Mods.CalamityMod.Buffs.EnchantedBladeStaffBuff.Description +} diff --git a/Localization/en-US/Mods.CalamityMod.Items.Weapons.Summon.hjson b/Localization/en-US/Mods.CalamityMod.Items.Weapons.Summon.hjson index f60e9dc57e..1e55e2df4a 100644 --- a/Localization/en-US/Mods.CalamityMod.Items.Weapons.Summon.hjson +++ b/Localization/en-US/Mods.CalamityMod.Items.Weapons.Summon.hjson @@ -884,3 +884,8 @@ YharonsKindleStaff: { Requires 5 minion slots to use ''' } + +EnchantedBladeStaff: { + DisplayName: Enchanted Blade Staff + Tooltip: "" +} diff --git a/Localization/en-US/Mods.CalamityMod.Projectiles.Summon.hjson b/Localization/en-US/Mods.CalamityMod.Projectiles.Summon.hjson index 7ae4b8d809..6c079cb668 100644 --- a/Localization/en-US/Mods.CalamityMod.Projectiles.Summon.hjson +++ b/Localization/en-US/Mods.CalamityMod.Projectiles.Summon.hjson @@ -330,3 +330,5 @@ WulfrumDroid.DisplayName: Wulfrum Droid WulfrumEnergyBurst.DisplayName: Wulfrum Bolt WulfrumFusionBolt.DisplayName: Fusion Bolt YharonMinionFireball.DisplayName: Dragon Fireball +EnchantedBladeSummon.DisplayName: Enchanted Blade Summon +EnchantedBladeStaffProjectile.DisplayName: Enchanted Blade Staff Projectile diff --git a/Projectiles/Summon/EnchantedBladeStaffProjectile.cs b/Projectiles/Summon/EnchantedBladeStaffProjectile.cs new file mode 100644 index 0000000000..6c5016b15f --- /dev/null +++ b/Projectiles/Summon/EnchantedBladeStaffProjectile.cs @@ -0,0 +1,46 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.DataStructures; +using Terraria.GameContent; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + public class EnchantedBladeStaffProjectile : ModProjectile, ILocalizedModType + { + public new string LocalizationCategory => "Projectiles.Summon"; + + public override void SetStaticDefaults() => ProjectileID.Sets.MinionShot[Type] = true; + + public override void SetDefaults() + { + Projectile.DamageType = DamageClass.Summon; + Projectile.width = Projectile.height = 32; + Projectile.usesLocalNPCImmunity = true; + Projectile.localNPCHitCooldown = -1; + Projectile.friendly = true; + Projectile.penetrate = -1; + Projectile.tileCollide = false; + Projectile.timeLeft = 300; + } + + public override void OnSpawn(IEntitySource source) => Projectile.rotation = Projectile.velocity.ToRotation(); + + public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) => Projectile.timeLeft = 3; + + public override bool PreDraw(ref Color lightColor) + { + Texture2D texture = TextureAssets.Projectile[Type].Value; + Vector2 drawPosition = Projectile.Center - Main.screenPosition; + Color drawColor = Color.Cyan * 0.6f; + float drawRotation = Projectile.rotation + MathHelper.PiOver2; + Vector2 anchorPoint = texture.Size() * 0.5f; + + Main.EntitySpriteDraw(texture, drawPosition, null, drawColor, drawRotation, anchorPoint, Projectile.scale, SpriteEffects.None); + + return false; + } + } +} diff --git a/Projectiles/Summon/EnchantedBladeStaffProjectile.png b/Projectiles/Summon/EnchantedBladeStaffProjectile.png new file mode 100644 index 0000000000000000000000000000000000000000..dc3a1353103a01afc35d49c1011ec71110e31507 GIT binary patch literal 319 zcmV-F0l@x=P)Px#`AI}UR5*>T)4fVVK@bJtZ(|S<1QE2lklHGsSOv7Tv#}9;B^zJDS4iO-ND3># zLJ(~HAx+3_g098xMFFMWc%q)j9bIt}iCfLFvvKDy4OYRL6#ITzzBKw#|gtlIe zG{Gin9Ab(MRGC*lPIcx3BRqF_^`8!QetA@c^v{o$mVZYYk~aN;GaTjfx;IiK=~UzV zN3+qd3~7w}$SLk}@lmVaK`2BDRpbhD%p@<3aEVXclyVAHOqUwlxW#eK8-EpUJg|bu z2`)O#_rPv3Cz2cY@Roi4fI;9(n!4NtbF52$uR#jAt`{eg+G5*S1z!6geFO9BHC2fm R1!4dI002ovPDHLkV1n< ProjectileType(); + + public override int AssociatedBuffTypeID => BuffType(); + + public override ref bool AssociatedMinionBool => ref ModdedOwner.EnchantedBladeStaffBool; + + public override bool PreHardmodeMinionTileVision => true; + + private Action CurrentState + { + get => _currentState; + set + { + OnStateChange(value); + _currentState = value; + NetUpdate(); + } + } + private Action _currentState; + + private ref float SwingTimer => ref Projectile.ai[0]; + + private ref float SwingDirection => ref Projectile.ai[1]; + + private Vector2 IdlePosition => Owner.MountedCenter + + new Vector2(50f * MathF.Ceiling(Projectile.minionPos / 2f) * (Projectile.minionPos % 2 == 0 ? -1 : 1), -60f + MathF.Ceiling(Projectile.minionPos / 2f) * 15f); + + private Vector2 SwingCenter; + + private float RandomRotationOffset; + + private bool HasStartedSwinging; + + private bool HasSpawned; + + public override void SetDefaults() + { + base.SetDefaults(); + Projectile.width = Projectile.height = 32; + } + + #region AI + + public override void MinionAI() + { + if (!HasSpawned) + { + TrailCacheLength = 4; + CurrentState = GoToOwnerState; + HasSpawned = true; + NetUpdate(); + } + + CurrentState.Invoke(); + } + + private void GoToOwnerState() + { + if (Target is not null) + { + CurrentState = AttackState; + return; + } + + if (Projectile.DistanceSQ(IdlePosition) < 80f * 80f) + CurrentState = IdleState; + + Projectile.velocity = Projectile.velocity.ToRotation().AngleTowards(Projectile.DirectionTo(IdlePosition).ToRotation(), 0.08f).ToRotationVector2() * 10f; + Projectile.rotation = Projectile.velocity.ToRotation(); + } + + private void IdleState() + { + if (Target is not null) + { + CurrentState = AttackState; + return; + } + + if (Projectile.DistanceSQ(IdlePosition) > 160f * 160f) + CurrentState = GoToOwnerState; + + float speed = Utils.Remap(Projectile.DistanceSQ(IdlePosition), 0f, 160f * 160f, 0.25f, 15f); + Projectile.velocity = Vector2.Lerp(Projectile.velocity, Projectile.velocity.ToRotation().AngleTowards(Projectile.DirectionTo(IdlePosition).ToRotation(), 0.4f).ToRotationVector2() * speed, 0.2f); + Projectile.rotation = MathHelper.Lerp(Projectile.rotation, MathHelper.ToRadians(RandomSineFunction(Main.GlobalTimeWrappedHourly + RandomRotationOffset) * 3f) - MathHelper.PiOver2, 0.1f); + } + + private void AttackState() + { + if (Target is null) + { + CurrentState = GoToOwnerState; + return; + } + + var easing = new CalamityUtils.CurveSegment(CalamityUtils.PolyInOutEasing, 0f, 0f, 1f, 4); + + float swingRotation = MathHelper.Lerp(-MathHelper.PiOver2, MathHelper.PiOver2, CalamityUtils.PiecewiseAnimation(Utils.GetLerpValue(SwingWait, SwingWait + SwingTime, SwingTimer, true), easing)) * MathF.Sign(Target.Center.X - SwingCenter.X); + Projectile.Center = SwingCenter + (Projectile.DirectionTo(Target.Center).ToRotation() + swingRotation).ToRotationVector2() * 40f; + Projectile.rotation = Projectile.DirectionFrom(SwingCenter).ToRotation(); + + if (SwingTimer == SwingWait + SwingTime * 0.5f && Main.myPlayer == Projectile.owner) + { + Vector2 predictiveDirection = CalamityUtils.CalculatePredictiveAimToTarget(SwingCenter, Target, 15f); + Vector2 spawnPosition = SwingCenter + predictiveDirection.SafeNormalize(-Vector2.UnitY) * 40f; + Projectile.NewProjectileDirect( + Projectile.GetSource_FromThis(), + spawnPosition, + predictiveDirection, + ProjectileType(), + Projectile.damage, + Projectile.knockBack, + Projectile.owner); + } + + SwingTimer += 1f * SwingDirection; + if (SwingTimer == 0f || SwingTimer == SwingWait + SwingTime + SwingWait) + { + if (HasStartedSwinging) + SwingDirection *= -1f; + else + HasStartedSwinging = true; + } + } + + private void OnStateChange(Action newState) + { + if (newState == IdleState) + RandomRotationOffset = Main.rand.NextFloat(MathHelper.TwoPi); + + if (newState == AttackState) + { + float targetSize = Target.Size.Length(); + Vector2 previousCenter = Projectile.Center; + Vector2 newCenter = Target.Center + Main.rand.NextVector2CircularEdge(targetSize * 0.5f + 160f, targetSize * 0.5f + 160f); + + int maxAttempts = 10; + int attempts = 0; + while (Main.tile[newCenter.ToSafeTileCoordinates()].IsTileSolid() || attempts == maxAttempts) + { + newCenter = Target.Center + Main.rand.NextVector2CircularEdge(targetSize * 0.5f + 160f, targetSize * 0.5f + 160f); + attempts++; + } + + Projectile.Center = newCenter; + SwingCenter = Projectile.Center; + + HasStartedSwinging = false; + SwingDirection = Main.rand.NextBool().ToDirectionInt(); + int totalSwingTime = (int)(2f * SwingWait + SwingTime); + SwingTimer = SwingDirection == 1 ? Main.rand.Next(-30, -2) : Main.rand.Next(totalSwingTime + 1, totalSwingTime + 30 + 1); + + if (!Main.dedServ) + { + int dustAmount = Main.rand.Next(30, 40); + for (int i = 0; i < dustAmount; i++) + { + float angle = MathHelper.TwoPi / dustAmount * i; + Vector2 velocity = angle.ToRotationVector2() * Main.rand.NextFloat(5f); + Dust tpDustStart = Dust.NewDustPerfect(previousCenter, 309, velocity); + Dust tpDustEnd = Dust.NewDustPerfect(SwingCenter, 309, velocity); + tpDustStart.noGravity = true; + tpDustEnd.noGravity = true; + } + } + } + } + + private float RandomSineFunction(float x) => MathF.Sin(3f * x) + MathF.Cos(5f * x) + 2f * MathF.Sin(0.5f * x); + + #endregion + + #region Drawing + + public override bool PreDraw(ref Color lightColor) + { + Texture2D texture = TextureAssets.Projectile[Type].Value; + Vector2 drawPosition = Projectile.Center - Main.screenPosition; + Color drawColor = Projectile.GetAlpha(lightColor); + float drawRotation = Projectile.rotation + MathHelper.PiOver2; + Vector2 anchorPoint = texture.Size() * 0.5f; + + if (CurrentState == AttackState) + { + for (int i = 0; i < 4; i++) + { + Vector2 afterimageDrawPosition = Projectile.oldPos[i] + Projectile.Size * 0.5f - Main.screenPosition; + Color afterimageDrawColor = Color.Cyan * ((4f - i) / 4f) * 0.8f; + float afterimageDrawRotation = Projectile.oldRot[i] + MathHelper.PiOver2; + Main.EntitySpriteDraw(texture, afterimageDrawPosition, null, afterimageDrawColor, afterimageDrawRotation, anchorPoint, Projectile.scale, SpriteEffects.None); + } + } + + Main.EntitySpriteDraw(texture, drawPosition, null, drawColor, drawRotation, anchorPoint, Projectile.scale, SpriteEffects.None); + + return false; + } + + #endregion + + #region Syncing + + private void NetUpdate() + { + Projectile.netUpdate = true; + Projectile.netSpam = 0; + } + + public override void SendExtraAI(BinaryWriter writer) + { + writer.WritePackedVector2(SwingCenter); + writer.Write(RandomRotationOffset); + writer.Write(HasSpawned); + } + + public override void ReceiveExtraAI(BinaryReader reader) + { + SwingCenter = reader.ReadPackedVector2(); + RandomRotationOffset = reader.ReadSingle(); + HasSpawned = reader.ReadBoolean(); + } + + #endregion + } +} diff --git a/Projectiles/Summon/EnchantedBladeSummon.png b/Projectiles/Summon/EnchantedBladeSummon.png new file mode 100644 index 0000000000000000000000000000000000000000..6536b060343521f9c8ba8f10b4977fd7793836eb GIT binary patch literal 532 zcmV+v0_**WP)Px$&PhZ;R7i=<)y+#(Q5?qc&mAX?vH_)L6G}=1y+E7Eq$t5f3pde5av^P`Mc|@! zwFvqHivECJHbH-Yn<8ivQ9(pdq+)MKF^vkQVuRytaqrdcU=eu-dNzl9&hI>YdCvKr z8>rLK(sht8bbyul&mq+E+X9%GdI;W^@2B?V>W%(Y`QI%hB!xpmU~+6UjF*Cq>a!7wI53}V7@XAM$dc&efx&NGI0?UJMUq==lTzx3Nj@Mx{8A#oVa@n?EX*% zFP=u@Jw$3QKF=q#iv)V>gq%Q)0LNvA^Hge WY=^VWLr6OS0000