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 0000000000..a0efadf188 Binary files /dev/null and b/Buffs/Summon/EnchantedBladeStaffBuff.png differ diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index f6c2c62801..57c03570a6 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -1119,6 +1119,7 @@ namespace CalamityMod.CalPlayer public bool KalandraMirror = false; public bool StellarTorus = false; public bool LiliesOfFinalityBool = false; + public bool EnchantedBladeStaffBool = false; #endregion #region Biome @@ -2205,6 +2206,7 @@ namespace CalamityMod.CalPlayer KalandraMirror = false; StellarTorus = false; LiliesOfFinalityBool = false; + EnchantedBladeStaffBool = false; /* Spawn blockers from back when they used to work by being favorited and not a toggleable item noStupidNaturalARSpawns = false diff --git a/Items/Weapons/Summon/EnchantedBladeStaff.cs b/Items/Weapons/Summon/EnchantedBladeStaff.cs new file mode 100644 index 0000000000..eaf04af9ab --- /dev/null +++ b/Items/Weapons/Summon/EnchantedBladeStaff.cs @@ -0,0 +1,50 @@ +using CalamityMod.Projectiles.Summon; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.DataStructures; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Weapons.Summon +{ + public class EnchantedBladeStaff : ModItem, ILocalizedModType + { + public static float SwingTime = 20f; + public static float SwingWait = 10f; + + public new string LocalizationCategory => "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 0000000000..acafcb8fc9 Binary files /dev/null and b/Items/Weapons/Summon/EnchantedBladeStaff.png differ 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 0000000000..dc3a135310 Binary files /dev/null and b/Projectiles/Summon/EnchantedBladeStaffProjectile.png differ diff --git a/Projectiles/Summon/EnchantedBladeSummon.cs b/Projectiles/Summon/EnchantedBladeSummon.cs new file mode 100644 index 0000000000..20af334e06 --- /dev/null +++ b/Projectiles/Summon/EnchantedBladeSummon.cs @@ -0,0 +1,241 @@ +using System; +using System.IO; +using CalamityMod.Buffs.Summon; +using CalamityMod.Projectiles.BaseProjectiles; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.GameContent; +using Terraria.ID; +using static CalamityMod.Items.Weapons.Summon.EnchantedBladeStaff; +using static Terraria.ModLoader.ModContent; + +namespace CalamityMod.Projectiles.Summon +{ + public class EnchantedBladeSummon : BaseMinionProjectile + { + public override int AssociatedProjectileTypeID => 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 0000000000..6536b06034 Binary files /dev/null and b/Projectiles/Summon/EnchantedBladeSummon.png differ