diff --git a/Gores/HarvestStaffGores/PumpkinGore1.png b/Gores/HarvestStaffGores/PumpkinGore1.png new file mode 100644 index 0000000000..2cf4881baa Binary files /dev/null and b/Gores/HarvestStaffGores/PumpkinGore1.png differ diff --git a/Gores/HarvestStaffGores/PumpkinGore2.png b/Gores/HarvestStaffGores/PumpkinGore2.png new file mode 100644 index 0000000000..005e5c8d6c Binary files /dev/null and b/Gores/HarvestStaffGores/PumpkinGore2.png differ diff --git a/Gores/HarvestStaffGores/PumpkinGore3.png b/Gores/HarvestStaffGores/PumpkinGore3.png new file mode 100644 index 0000000000..3b19395b52 Binary files /dev/null and b/Gores/HarvestStaffGores/PumpkinGore3.png differ diff --git a/Gores/HarvestStaffGores/PumpkinGore4.png b/Gores/HarvestStaffGores/PumpkinGore4.png new file mode 100644 index 0000000000..327c2eb5d7 Binary files /dev/null and b/Gores/HarvestStaffGores/PumpkinGore4.png differ diff --git a/Gores/HarvestStaffGores/PumpkinGore5.png b/Gores/HarvestStaffGores/PumpkinGore5.png new file mode 100644 index 0000000000..859a2b9d21 Binary files /dev/null and b/Gores/HarvestStaffGores/PumpkinGore5.png differ diff --git a/Gores/HarvestStaffGores/PumpkinGore6.png b/Gores/HarvestStaffGores/PumpkinGore6.png new file mode 100644 index 0000000000..a54d4c9452 Binary files /dev/null and b/Gores/HarvestStaffGores/PumpkinGore6.png differ diff --git a/Items/Weapons/Magic/HarvestStaff.cs b/Items/Weapons/Magic/HarvestStaff.cs deleted file mode 100644 index 3abc3a5778..0000000000 --- a/Items/Weapons/Magic/HarvestStaff.cs +++ /dev/null @@ -1,49 +0,0 @@ -using CalamityMod.Projectiles.Magic; -using Microsoft.Xna.Framework; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.Items.Weapons.Magic -{ - public class HarvestStaff : ModItem, ILocalizedModType - { - public new string LocalizationCategory => "Items.Weapons.Magic"; - public override void SetStaticDefaults() - { - Item.staff[Item.type] = true; - } - - public override void SetDefaults() - { - Item.width = 46; - Item.height = 44; - Item.damage = 22; - Item.DamageType = DamageClass.Magic; - Item.mana = 5; - Item.useTime = 23; - Item.useAnimation = 23; - Item.useStyle = ItemUseStyleID.Shoot; - Item.noMelee = true; - Item.knockBack = 5; - Item.value = CalamityGlobalItem.Rarity2BuyPrice; - Item.rare = ItemRarityID.Green; - Item.UseSound = SoundID.Item20; - Item.autoReuse = true; - Item.shoot = ModContent.ProjectileType(); - Item.shootSpeed = 13f; - Item.scale = 0.9f; - } - - - public override void AddRecipes() - { - CreateRecipe(). - AddRecipeGroup("Wood", 20). - AddIngredient(ItemID.Pumpkin, 20). - AddIngredient(ItemID.PumpkinSeed, 5). - AddTile(TileID.Anvils). - Register(); - } - } -} diff --git a/Items/Weapons/Magic/HarvestStaff.png b/Items/Weapons/Magic/HarvestStaff.png deleted file mode 100644 index 0425b98351..0000000000 Binary files a/Items/Weapons/Magic/HarvestStaff.png and /dev/null differ diff --git a/Items/Weapons/Summon/HarvestStaff.cs b/Items/Weapons/Summon/HarvestStaff.cs new file mode 100644 index 0000000000..168e5de21c --- /dev/null +++ b/Items/Weapons/Summon/HarvestStaff.cs @@ -0,0 +1,59 @@ +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 HarvestStaff : ModItem, ILocalizedModType + { + public new string LocalizationCategory => "Items.Weapons.Summon"; + + public static float PlantedEnemyDistanceDetection = 160f; + public static float NormalEnemyDistanceDetection = 1200f; + public static float PumpkinGravityStrength = 0.8f; + public static float PumpkinMaxGravity = 20f; + + public override void SetStaticDefaults() => Item.staff[Type] = true; + + public override void SetDefaults() + { + Item.damage = 22; + Item.DamageType = DamageClass.Summon; + Item.shoot = ModContent.ProjectileType(); + Item.knockBack = 5f; + + Item.useTime = Item.useAnimation = 15; + Item.mana = 10; + Item.width = 44; + Item.height = 46; + Item.noMelee = true; + Item.autoReuse = true; + Item.value = CalamityGlobalItem.Rarity2BuyPrice; + Item.rare = ItemRarityID.Green; + Item.useStyle = ItemUseStyleID.Shoot; + Item.UseSound = SoundID.Item20; + + Item.shootSpeed = 0.1f; + } + + public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) + { + Projectile.NewProjectileDirect(source, Main.MouseWorld, Vector2.Zero, type, damage, knockback, player.whoAmI); + player.UpdateMaxTurrets(); + return false; + } + + public override void AddRecipes() + { + CreateRecipe(). + AddRecipeGroup("Wood", 20). + AddIngredient(ItemID.Pumpkin, 20). + AddIngredient(ItemID.PumpkinSeed, 5). + AddTile(TileID.Anvils). + Register(); + } + } +} diff --git a/Items/Weapons/Summon/HarvestStaff.png b/Items/Weapons/Summon/HarvestStaff.png new file mode 100644 index 0000000000..3c4ce4deed Binary files /dev/null and b/Items/Weapons/Summon/HarvestStaff.png differ diff --git a/Localization/en-US/Mods.CalamityMod.Items.Weapons.Summon.hjson b/Localization/en-US/Mods.CalamityMod.Items.Weapons.Summon.hjson index 43c9405417..7355498ed3 100644 --- a/Localization/en-US/Mods.CalamityMod.Items.Weapons.Summon.hjson +++ b/Localization/en-US/Mods.CalamityMod.Items.Weapons.Summon.hjson @@ -819,3 +819,8 @@ MutatedTruffle: { There can only be one minion ''' } + +HarvestStaff: { + DisplayName: Harvest Staff + Tooltip: "" +} diff --git a/Localization/en-US/Mods.CalamityMod.Projectiles.Summon.hjson b/Localization/en-US/Mods.CalamityMod.Projectiles.Summon.hjson index 5d0b309674..c52b4ddb79 100644 --- a/Localization/en-US/Mods.CalamityMod.Projectiles.Summon.hjson +++ b/Localization/en-US/Mods.CalamityMod.Projectiles.Summon.hjson @@ -323,3 +323,4 @@ WindRipperArrow.DisplayName: Wind Ripper Arrow HopeShredder.DisplayName: Hope Shredder HopeShredderArrow.DisplayName: Hope Shredder Arrow HopeShredderArrowSplit.DisplayName: Hope Shredder Split Arrow +HarvestStaffMinion.DisplayName: Harvest Staff Minion diff --git a/Projectiles/Magic/FlamingPumpkin.cs b/Projectiles/Magic/FlamingPumpkin.cs deleted file mode 100644 index 1d88d89bd6..0000000000 --- a/Projectiles/Magic/FlamingPumpkin.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; -namespace CalamityMod.Projectiles.Magic -{ - public class FlamingPumpkin : ModProjectile, ILocalizedModType - { - public new string LocalizationCategory => "Projectiles.Magic"; - public override void SetDefaults() - { - Projectile.width = 14; - Projectile.height = 14; - Projectile.aiStyle = ProjAIStyleID.GroundProjectile; - Projectile.penetrate = 2; - Projectile.timeLeft = 200; - Projectile.DamageType = DamageClass.Magic; - Projectile.friendly = true; - Projectile.usesLocalNPCImmunity = true; - Projectile.localNPCHitCooldown = -1; - } - - public override void AI() - { - if (Main.rand.NextBool(3)) - { - Dust.NewDust(Projectile.position + Projectile.velocity, Projectile.width, Projectile.height, 64, Projectile.velocity.X * 0.5f, Projectile.velocity.Y * 0.5f); - } - } - - public override void OnHitNPC(NPC target, NPC.HitInfo hit, int DamageDone) => target.AddBuff(BuffID.OnFire, 60); - } -} diff --git a/Projectiles/Magic/FlamingPumpkin.png b/Projectiles/Magic/FlamingPumpkin.png deleted file mode 100644 index ee9283758a..0000000000 Binary files a/Projectiles/Magic/FlamingPumpkin.png and /dev/null differ diff --git a/Projectiles/Summon/HarvestStaffMinion.cs b/Projectiles/Summon/HarvestStaffMinion.cs new file mode 100644 index 0000000000..194ddad526 --- /dev/null +++ b/Projectiles/Summon/HarvestStaffMinion.cs @@ -0,0 +1,552 @@ +using System; +using System.IO; +using CalamityMod.Particles; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; +using Terraria; +using Terraria.DataStructures; +using Terraria.ID; +using Terraria.ModLoader; +using static CalamityMod.Items.Weapons.Summon.HarvestStaff; + +namespace CalamityMod.Projectiles.Summon +{ + public class HarvestStaffMinion : ModProjectile, ILocalizedModType + { + #region Properties and Enums + + public new string LocalizationCategory => "Projectiles.Summon"; + + /// + /// The size of the pumpkin. + /// + public ref float Variant => ref Projectile.ai[0]; + + /// + /// The states of behaviour of this pumpkin. + /// + public enum AIState { Still, Idle, Attack } + + /// + /// The current state of behaviour of this pumpkin. + /// + public AIState State + { + get => (AIState)Projectile.ai[1]; + set + { + Projectile.ai[1] = (float)value; + + if (value == AIState.Attack) + Animation = AnimationState.Run; + else if (value == AIState.Idle) + Animation = AnimationState.Idle; + + NetUpdate(); + } + } + + /// + /// The maximum time that the pumpkin will walk on its idle state.
+ /// It's set to a random amount at a random moment. + ///
+ public int IdleWalkingTime { get; set; } + + /// + /// The timer on which the pumpkin is while walking.
+ /// When the timer reaches 0, the pumpkin will stop walking. + ///
+ public int IdleWalkingTimer { get; set; } + + /// + /// The direction in which the pumpkin walks while idle.
+ /// If the pumpkin is within a certain range from the sentry (Or if it doesn't exist), it'll go to a random direction.
+ /// Otherwise, it'll try to always be nearby the sentry. + ///
+ public int IdleWalkingDirection { get; set; } + + /// + /// Keeps track of the amount of jumps that the pumpkin has done when the owner is nearby.
+ /// When it reaches a certain amount, the minion will go on a cooldown before jumping again. + ///
+ public int IdleJumpCount { get; set; } + + /// + /// The cooldown of the pumpkin for jumping again.
+ /// When it reaches 0, the pumpkin will stop walking. + ///
+ public int IdleJumpCooldown { get; set; } + + /// + /// The states of the animation that the pumpkin has.
+ /// Their indeces are used when selecting which spritesheet it uses. + ///
+ public enum AnimationState { None = -1, Grow, Rise, Idle, Run, Jump } + + /// + /// The current state of animation of the pumpkin. + /// + public AnimationState Animation + { + get => (AnimationState)Projectile.ai[2]; + set + { + if (value != Animation) + { + Projectile.frame = 0; + Projectile.frameCounter = 0; + } + + Projectile.ai[2] = (float)value; + + switch (value) + { + case AnimationState.Grow: + AnimationFrames = Variant == 0 ? 6 : 4; + FramesUntilNextAnimationFrame = 6; + break; + + case AnimationState.Rise: + AnimationFrames = 10; + FramesUntilNextAnimationFrame = 5; + break; + + case AnimationState.Idle: + case AnimationState.Jump: + AnimationFrames = 1; + FramesUntilNextAnimationFrame = 0; + break; + + case AnimationState.Run: + AnimationFrames = 6; + FramesUntilNextAnimationFrame = 5; + break; + } + + NetUpdate(); + } + } + + /// + /// The amount of frames that the current animation's spritesheet has. + /// + public int AnimationFrames { get; set; } + + /// + /// The amount of time, in frames, that it'll take to go to the next frame of animation. + /// + public int FramesUntilNextAnimationFrame { get; set; } + + /// + /// A convienent bool for when the animation has been completed.
+ /// Ends at - 1 because starts at 0. + ///
+ public bool CompletedAnimation => Projectile.frame >= AnimationFrames - 1; + + /// + /// A convient way to set the direction of the sprite without typing it out the long way. + /// + public int Direction + { + get => Projectile.spriteDirection; + set => Projectile.spriteDirection = Projectile.direction = value; + } + + /// + /// The owner of this minion. + /// + public Player Owner { get; set; } + + /// + /// The target of this minion. + /// + public NPC Target { get; set; } + + /// + /// The sentry of this minion. + /// + public Projectile MySentry + { + get + { + for (int i = 0; i < Main.maxProjectiles; i++) + { + Projectile proj = Main.projectile[i]; + if (proj == null || !proj.active || proj.owner != Projectile.owner || proj.type != ModContent.ProjectileType()) + continue; + + return proj; + } + + return null; + } + } + + #endregion + + #region AI and Collisions + + public override void AI() + { + Target = Projectile.Center.MinionHoming(State == AIState.Still ? PlantedEnemyDistanceDetection : NormalEnemyDistanceDetection, Owner, false); + + switch (State) + { + case AIState.Still: + StillState(); + break; + case AIState.Idle: + IdleState(); + break; + case AIState.Attack: + AttackState(); + break; + } + + if (IdleJumpCooldown > 0) + IdleJumpCooldown--; + + Projectile.timeLeft = 2; + DoGravity(); + DoAnimation(); + } + + public override bool OnTileCollide(Vector2 oldVelocity) + { + // When the pumpkin touches the ground after spawning, start the growing animation. + if (Animation == AnimationState.None) + Animation = AnimationState.Grow; + + if (State == AIState.Idle && Projectile.velocity.Y == 0f) + { + // While the pumpkin's idle and standing still on the ground, when the player gets close it'll jump. + if (Projectile.WithinRange(Owner.Center, 64f) && IdleJumpCooldown == 0) + NearOwnerJump(); + else + Animation = IdleWalkingTimer == 0f ? AnimationState.Idle : AnimationState.Run; + } + + // If the minion's standing still at a certain distance from the target: jump. + if (Target is not null && State == AIState.Attack && Projectile.velocity.Y == 0f) + { + if (MathF.Abs(Target.Center.X - Projectile.Center.X) < 160f && Target.Top.Y < Projectile.Bottom.Y) + { + if (PlatformBetweenMinionAndTarget(out Vector2 platformPosition)) + JumpTowards(platformPosition - Vector2.UnitY * 32f); + else + JumpTowards(Target.Top); + } + else + Animation = AnimationState.Run; + } + + return false; + } + + public override bool TileCollideStyle(ref int width, ref int height, ref bool fallThrough, ref Vector2 hitboxCenterFrac) + { + if (Target is not null) + fallThrough = Projectile.Bottom.Y < Target.Top.Y; + else + fallThrough = false; + + return true; + } + + public override void OnKill(int timeLeft) + { + Projectile.ExpandHitboxBy(3f); + Projectile.Damage(); + + for (int i = 0; i < (int)Utils.Remap(Variant, 0f, 2f, 4f, 2f); i++) + { + float angle = MathHelper.TwoPi / 4 * i; + Vector2 velocity = angle.ToRotationVector2() * Main.rand.NextFloat(3f, 5f); + Gore gore = Gore.NewGoreDirect(Projectile.GetSource_Death(), Projectile.Center, velocity, Mod.Find($"PumpkinGore{Main.rand.Next(6) + 1}").Type, Utils.Remap(Variant, 0f, 2f, 1f, 0.5f)); + gore.timeLeft = 15; + } + + if (Main.dedServ) + return; + + Particle boomRing = new DirectionalPulseRing(Projectile.Center, + Vector2.Zero, + Color.Orange, + Vector2.One, + 0f, + 0.05f, + 0.5f, + 20); + GeneralParticleHandler.SpawnParticle(boomRing); + + for (int i = 0; i < 10; i++) + Dust.NewDustDirect(Projectile.position, Projectile.width, Projectile.height, DustID.Torch); + } + + /// + /// The behaviour of this summon while it is planted on the ground. + /// + public void StillState() + { + // When the pumpkin has done its growing animation and there's a target nearby or the owner's on top of it, + // it'll do the jump out animation. + if ((Target is not null || Projectile.getRect().Intersects(Owner.getRect())) && Animation == AnimationState.Grow && CompletedAnimation) + Animation = AnimationState.Rise; + + // And when they have completed their jumping out animation, they idle until they find a target. + else if (Animation == AnimationState.Rise && CompletedAnimation) + State = AIState.Idle; + } + + /// + /// The behaviour of this usmmon while it's idle. + /// + public void IdleState() + { + // If a target has been detected, go to the attack state. + if (Target is not null) + { + State = AIState.Attack; + return; + } + + // If the pumpkin's not already walking, at a random chance it'll decide to walk. + if (IdleWalkingTimer == 0f && Main.rand.NextBool(400)) + { + IdleWalkingTime = IdleWalkingTimer = Main.rand.Next(60, 180); + IdleWalkingDirection = MySentry == null || Projectile.WithinRange(MySentry.Center, 960f) ? (Main.rand.NextBool() ? -1 : 1) : MathF.Sign(MySentry.Center.X - Projectile.Center.X); + NetUpdate(); + } + + else if (IdleWalkingTimer != 0f) + { + // The pumpkin will accelerate when starting to walk and deaccelerate when it's about to end. + Projectile.velocity.X = MathHelper.Lerp(0f, 3f, CalamityUtils.Convert01To010(Utils.GetLerpValue(0f, IdleWalkingTime, IdleWalkingTimer))) * IdleWalkingDirection; + + Direction = MathF.Sign(Projectile.velocity.X); + + IdleWalkingTimer--; + if (IdleWalkingTimer == 0f) + { + Projectile.velocity.X = 0f; + Animation = AnimationState.Idle; + } + } + + // When the pumpkin encounters a 1-tile-height obstacle, it'll climb it, like the player. + Collision.StepUp(ref Projectile.position, ref Projectile.velocity, Projectile.width, Projectile.height, ref Projectile.stepSpeed, ref Projectile.gfxOffY); + } + + /// + /// The behaviour of this summon in its attack state. + /// + public void AttackState() + { + if (Target is not null) + { + if (Projectile.WithinRange(Target.Center, 32f)) + { + Projectile.Kill(); + return; + } + + MoveToTarget(); + Direction = MathF.Sign(Projectile.velocity.X); + + // When the pumpkin encounters a 1-tile-height obstacle, it'll climb it, like the player. + Collision.StepUp(ref Projectile.position, ref Projectile.velocity, Projectile.width, Projectile.height, ref Projectile.stepSpeed, ref Projectile.gfxOffY); + } + else + { + State = AIState.Idle; + Projectile.velocity.X = 0f; + } + } + + /// + /// The minion does a small jump, to give it some flavor and cuteness. + /// + public void NearOwnerJump() + { + // Actually jumps. + Projectile.velocity.Y = -8f; + + // After 2 hops the summon goes on a cooldown before jumping again. + IdleJumpCount++; + if (IdleJumpCount == 2) + { + IdleJumpCount = 0; + IdleJumpCooldown = 30; + } + + Direction = MathF.Sign(Owner.Center.X - Projectile.Center.X); + Animation = AnimationState.Jump; + NetUpdate(); + } + + /// + /// The minion will start moving to the target with acceleration. + /// + public void MoveToTarget() + { + // If the variant's smaller (Variant 2 is the smallest), it has a faster acceleration and a higher max velocity. + float maxVelocity = Utils.Remap(Variant, 0f, 2f, 5f, 8f); + float acceleration = Utils.Remap(Variant, 0f, 2f, 0.1f, 0.3f); + float accelerationDirection = MathF.Sign(Target.Center.X - Projectile.Center.X); + + Projectile.velocity.X += acceleration * accelerationDirection; + if (MathF.Abs(Projectile.velocity.X) > maxVelocity) + Projectile.velocity.X = maxVelocity * accelerationDirection; + } + + /// + /// The minion will jump towards a destination in the Y-axis. + /// + /// The Y position at which the minion will jump towards + public void JumpTowards(Vector2 destination) + { + // Equation of a free fall independent of time: v = sqrt(2 * gravity * distance). + // Because we want it to go up and now down, we need to negate the constant: v = sqrt(-2 * gravity * distance). + // And now we need to negate the velocity to get it on Terraria's coordinate system: v = -sqrt(-2 * gravity * distance). + Projectile.velocity.Y = -MathF.Sqrt(-2f * PumpkinGravityStrength * (destination.Y - Projectile.Bottom.Y)); + Animation = AnimationState.Jump; + NetUpdate(); + } + + /// + /// Detects a platform between the minion and the target. + /// + /// The position of said platform as a . + /// Whether there's a platform or not. + public bool PlatformBetweenMinionAndTarget(out Vector2 tilePosition) + { + Point minionPosition = Projectile.Center.ToSafeTileCoordinates(); + Point targetPosition = Target.Center.ToSafeTileCoordinates(); + for (int coordY = minionPosition.Y; coordY > targetPosition.Y; coordY--) + { + if (Main.tile[targetPosition.X, coordY].IsTileSolidGround()) + { + tilePosition = new Vector2(targetPosition.X, coordY) * 16f; + return true; + } + } + + tilePosition = Vector2.Zero; + return false; + } + + /// + /// Applies gravity to the minion. + /// + public void DoGravity() + { + float speed = Projectile.velocity.Y; + if (speed < PumpkinMaxGravity) + speed = MathF.Min(speed + PumpkinGravityStrength, PumpkinMaxGravity); + Projectile.velocity.Y = speed; + } + + /// + /// Does the animation of the minion. + /// + public void DoAnimation() + { + // If the state of the animation's spritsheet is only 1 frame, no need to animate. + if (Animation == AnimationState.None || Animation == AnimationState.Idle || Animation == AnimationState.Jump) + return; + + Projectile.frameCounter++; + if (Projectile.frameCounter % FramesUntilNextAnimationFrame == 0) + { + Projectile.frame = Math.Min(Projectile.frame + 1, AnimationFrames - 1); + + // If it's the run animation, loop it. + if (Animation == AnimationState.Run && CompletedAnimation) + Projectile.frame = 0; + } + } + + /// + /// A covenient way to do a while also handling . + /// + public void NetUpdate() + { + Projectile.netUpdate = true; + if (Projectile.netSpam >= 10) + Projectile.netSpam = 9; + } + + #endregion + + #region Other Overrides + + public override void SetStaticDefaults() + { + Main.projFrames[Type] = 68; + ProjectileID.Sets.MinionShot[Type] = true; + } + + public override void SetDefaults() + { + Projectile.DamageType = DamageClass.Summon; + Projectile.localNPCHitCooldown = 30; + Projectile.penetrate = -1; + Projectile.friendly = true; + Projectile.tileCollide = true; + Projectile.usesLocalNPCImmunity = true; + Projectile.netImportant = true; + } + + public override void SendExtraAI(BinaryWriter writer) + { + writer.Write(IdleWalkingTime); + writer.Write(IdleWalkingTimer); + writer.Write(IdleJumpCount); + writer.Write(IdleJumpCooldown); + writer.Write(IdleWalkingDirection); + } + + public override void ReceiveExtraAI(BinaryReader reader) + { + IdleWalkingTime = reader.ReadInt32(); + IdleWalkingTimer = reader.ReadInt32(); + IdleJumpCount = reader.ReadInt32(); + IdleJumpCooldown = reader.ReadInt32(); + IdleWalkingDirection = reader.ReadInt32(); + } + + public override bool? CanDamage() => null; + + public override void OnSpawn(IEntitySource source) + { + Owner = Main.player[Projectile.owner]; + Projectile.width = Projectile.height = Variant == 0 ? 28 : (Variant == 1 ? 22 : 20); + Direction = Main.rand.NextBool() ? -1 : 1; + Animation = AnimationState.None; + } + + #endregion + + #region Drawing + + public override bool PreDraw(ref Color lightColor) + { + if (Animation == AnimationState.None) + return false; + + Asset texture = ModContent.Request(Texture); + Vector2 drawPosition = Projectile.Bottom - Vector2.UnitY * (24f + Projectile.gfxOffY) - Main.screenPosition; + Rectangle frame = texture.Frame(15, 10, (int)Variant * 5 + (int)Animation, Projectile.frame); + Color drawColor = Projectile.GetAlpha(lightColor); + Vector2 rotationPoint = frame.Size() * 0.5f; + SpriteEffects flip = Direction == -1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None; + + Main.EntitySpriteDraw(texture.Value, drawPosition, frame, drawColor, Projectile.rotation, rotationPoint, Projectile.scale, flip); + + return false; + } + + #endregion + } +} diff --git a/Projectiles/Summon/HarvestStaffMinion.png b/Projectiles/Summon/HarvestStaffMinion.png new file mode 100644 index 0000000000..6d8ad1ab73 Binary files /dev/null and b/Projectiles/Summon/HarvestStaffMinion.png differ diff --git a/Projectiles/Summon/HarvestStaffSentry.cs b/Projectiles/Summon/HarvestStaffSentry.cs new file mode 100644 index 0000000000..b9c9bfcfb0 --- /dev/null +++ b/Projectiles/Summon/HarvestStaffSentry.cs @@ -0,0 +1,131 @@ +using System; +using System.Collections.Generic; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + public class HarvestStaffSentry : ModProjectile + { + public new string LocalizationCategory => "Projectiles.Summon"; + + public ref float Timer => ref Projectile.ai[0]; + public static float Gravity = 0.8f; + public static float MaxGravity = 20f; + + public override void SetStaticDefaults() => Main.projFrames[Type] = 4; + + public override void SetDefaults() + { + Projectile.sentry = true; + Projectile.timeLeft = Projectile.SentryLifeTime; + Projectile.tileCollide = true; + Projectile.width = 68; + Projectile.height = 32; + } + + public override void AI() + { + if (PumpkinQuantity() < 5) + Timer++; + + if (Timer > 180f) + { + float randomOffset = 160f; + Vector2 spawnPosition = Projectile.Center + new Vector2(Main.rand.NextFloat(-randomOffset, randomOffset), -80f); + MakeSpawnValid(ref spawnPosition); + + Projectile.NewProjectileDirect( + Projectile.GetSource_FromThis(), + spawnPosition, + Vector2.Zero, + ModContent.ProjectileType(), + Projectile.damage, + Projectile.knockBack, + Projectile.owner, + Main.rand.Next(3)); + + Timer = 0f; + } + + float speed = Projectile.velocity.Y; + if (speed < MaxGravity) + speed = MathF.Min(speed + Gravity, MaxGravity); + Projectile.velocity.Y = speed; + + Projectile.frameCounter++; + if (Projectile.frameCounter > 10) + { + Projectile.frame = (Projectile.frame + 1) % Main.projFrames[Type]; + Projectile.frameCounter = 0; + } + } + + public int PumpkinQuantity() + { + int amount = 0; + for (int i = 0; i < Main.maxProjectiles; i++) + { + Projectile proj = Main.projectile[i]; + if (proj == null || !proj.active || proj.type != ModContent.ProjectileType() || proj.owner != Projectile.owner) + continue; + amount++; + } + + return amount; + } + + public void MakeSpawnValid(ref Vector2 spawnpoint) + { + Point spawnpointTileCoords = spawnpoint.ToSafeTileCoordinates(); + Point sentryTileCoords = Projectile.Top.ToSafeTileCoordinates(); + + if (!Main.tile[spawnpointTileCoords].IsTileSolid()) + return; + else + { + while (Main.tile[spawnpoint.ToSafeTileCoordinates()].IsTileSolid()) + { + for (int coordY = spawnpointTileCoords.Y; coordY < sentryTileCoords.Y; coordY++) + { + Point tileCoords = new Point(spawnpointTileCoords.X, coordY); + if (!Main.tile[tileCoords].IsTileSolid()) + { + spawnpoint = tileCoords.ToVector2(); + break; + } + } + + spawnpoint.X += Main.rand.NextFloat(-160f, 160f); + } + } + } + + public override bool OnTileCollide(Vector2 oldVelocity) => false; + + public override bool TileCollideStyle(ref int width, ref int height, ref bool fallThrough, ref Vector2 hitboxCenterFrac) + { + fallThrough = false; + return true; + } + + public override bool? CanDamage() => false; + + public override bool PreDraw(ref Color lightColor) + { + Texture2D texture = ModContent.Request(Texture).Value; + Vector2 drawPosition = Projectile.Center - Main.screenPosition + Vector2.UnitY * Projectile.gfxOffY; + Rectangle frame = texture.Frame(verticalFrames: Main.projFrames[Type], frameY: Projectile.frame); + Color drawColor = Projectile.GetAlpha(lightColor); + Vector2 rotationPoint = frame.Size() * 0.5f; + + Main.EntitySpriteDraw(texture, drawPosition, frame, drawColor, Projectile.rotation, rotationPoint, Projectile.scale, SpriteEffects.None); + + return false; + } + + public override void DrawBehind(int index, List behindNPCsAndTiles, List behindNPCs, List behindProjectiles, List overPlayers, List overWiresUI) => behindProjectiles.Add(index); + } +} diff --git a/Projectiles/Summon/HarvestStaffSentry.png b/Projectiles/Summon/HarvestStaffSentry.png new file mode 100644 index 0000000000..2668e29a4f Binary files /dev/null and b/Projectiles/Summon/HarvestStaffSentry.png differ