diff --git a/Content/Guardian/GuardianHammerAnchor.cs b/Content/Guardian/GuardianHammerAnchor.cs index c47405cb..af9c2c8b 100644 --- a/Content/Guardian/GuardianHammerAnchor.cs +++ b/Content/Guardian/GuardianHammerAnchor.cs @@ -38,6 +38,8 @@ public class GuardianHammerAnchor : OrchidModGuardianAnchor public int BlockDuration = 0; public bool Ding = false; + + public int HammerAnimFrame = 0; public bool WeakThrow => Projectile.ai[0] == 1; @@ -685,7 +687,7 @@ public override bool OrchidPreDraw(SpriteBatch spriteBatch, ref Color lightColor if (HammerTexture == null) return false; Player player = Main.player[Projectile.owner]; OrchidGuardian guardian = player.GetModPlayer(); - Rectangle drawRectangle = HammerTexture.Bounds; + Rectangle drawRectangle = HammerTexture.Frame(1, HammerItem.HammerFrames, 0, HammerAnimFrame % HammerItem.HammerFrames); if (HammerItem.PreDrawHammer(player, guardian, Projectile, spriteBatch, ref lightColor, ref HammerTexture, ref drawRectangle)) { diff --git a/Content/Guardian/GuardianQuarterstaffAnchor.cs b/Content/Guardian/GuardianQuarterstaffAnchor.cs index d8c7ff15..db109275 100644 --- a/Content/Guardian/GuardianQuarterstaffAnchor.cs +++ b/Content/Guardian/GuardianQuarterstaffAnchor.cs @@ -32,6 +32,7 @@ public class GuardianQuarterstaffAnchor : OrchidModGuardianParryAnchor public Item QuarterstaffItem => Main.player[Projectile.owner].inventory[SelectedItem]; public Texture2D QuarterstaffTexture; public Texture2D QuarterstaffTextureGlow; + public int QuarterstaffAnimFrame = 0; public override void SendExtraAI(BinaryWriter writer) { @@ -762,6 +763,8 @@ public override bool OrchidPreDraw(SpriteBatch spriteBatch, ref Color lightColor if (guardianItem.PreDrawQuarterstaff(spriteBatch, Projectile, player, ref lightColor)) { + Rectangle frame = QuarterstaffTexture.Frame(1, guardianItem.QuarterstaffFrames, 0, QuarterstaffAnimFrame % guardianItem.QuarterstaffFrames); + if (Projectile.ai[0] > 1f || Projectile.ai[0] < 0f || Projectile.ai[2] < 0f) { // attacking = draw trail spriteBatch.End(out SpriteBatchSnapshot spriteBatchSnapshot); @@ -770,7 +773,7 @@ public override bool OrchidPreDraw(SpriteBatch spriteBatch, ref Color lightColor for (int i = 0; i < OldPosition.Count; i++) { Vector2 drawPositionTrail = OldPosition[i] - Main.screenPosition + Vector2.UnitY * player.gfxOffY; - spriteBatch.Draw(QuarterstaffTexture, drawPositionTrail, null, lightColor * 0.05f * (i + 1), OldRotation[i] + rotationoffset, QuarterstaffTexture.Size() * 0.5f, Projectile.scale, effect, 0f); + spriteBatch.Draw(QuarterstaffTexture, drawPositionTrail, frame, lightColor * 0.05f * (i + 1), OldRotation[i] + rotationoffset, QuarterstaffTexture.Size() * 0.5f, Projectile.scale, effect, 0f); } spriteBatch.End(); @@ -778,12 +781,12 @@ public override bool OrchidPreDraw(SpriteBatch spriteBatch, ref Color lightColor } Vector2 drawPosition = Projectile.Center - Main.screenPosition + Vector2.UnitY * player.gfxOffY; - spriteBatch.Draw(QuarterstaffTexture, drawPosition, null, lightColor, Projectile.rotation + rotationoffset, QuarterstaffTexture.Size() * 0.5f, Projectile.scale, effect, 0f); + spriteBatch.Draw(QuarterstaffTexture, drawPosition, frame, lightColor, Projectile.rotation + rotationoffset, QuarterstaffTexture.Size() * 0.5f, Projectile.scale, effect, 0f); if (QuarterstaffTextureGlow != null) { Color glowColor = guardianItem.GetQuarterstaffGlowmaskColor(player, guardian, Projectile, lightColor); - spriteBatch.Draw(QuarterstaffTextureGlow, drawPosition, null, glowColor, Projectile.rotation + rotationoffset, QuarterstaffTextureGlow.Size() * 0.5f, Projectile.scale, effect, 0f); + spriteBatch.Draw(QuarterstaffTextureGlow, drawPosition, frame, glowColor, Projectile.rotation + rotationoffset, QuarterstaffTextureGlow.Size() * 0.5f, Projectile.scale, effect, 0f); } } guardianItem.PostDrawQuarterstaff(spriteBatch, Projectile, player, lightColor); diff --git a/Content/Guardian/GuardianShieldAnchor.cs b/Content/Guardian/GuardianShieldAnchor.cs index 1fd39772..e0e46b68 100644 --- a/Content/Guardian/GuardianShieldAnchor.cs +++ b/Content/Guardian/GuardianShieldAnchor.cs @@ -16,6 +16,8 @@ public class GuardianShieldAnchor : OrchidModGuardianAnchor { public int SelectedItem { get; set; } = -1; public Item ShieldItem => Main.player[Projectile.owner].inventory[this.SelectedItem]; + + public int ShieldAnimFrame = 0; public bool shieldEffectReady = true; public bool NeedNetUpdate = false; @@ -122,9 +124,9 @@ public override void AI() if (IsLocalOwner) { - var texture = ModContent.Request((ShieldItem.ModItem as OrchidModGuardianShield).ShieldTexture).Value; - Projectile.width = (int)(texture.Height * guardian.GuardianWeaponScale); - Projectile.height = (int)(texture.Height * guardian.GuardianWeaponScale); + var texture = ModContent.Request((ShieldItem.ModItem as OrchidModGuardianShield)?.ShieldTexture).Value; + Projectile.width = (int)(texture.Height * guardian.GuardianWeaponScale / guardianItem.ShieldFrames); + Projectile.height = (int)(texture.Height * guardian.GuardianWeaponScale / guardianItem.ShieldFrames); } if (owner.boneGloveItem != null && !owner.boneGloveItem.IsAir && owner.boneGloveTimer == 0) @@ -154,9 +156,9 @@ public override void AI() { Vector2 oldDimensions = new Vector2(Projectile.width, Projectile.height); var texture = ModContent.Request(guardianItem.ShieldTexture).Value; - Projectile.width = (int)(texture.Height * guardian.GuardianWeaponScale); - Projectile.height = (int)(texture.Height * guardian.GuardianWeaponScale); - aimedLocation += (oldDimensions * 0.5f - new Vector2(texture.Height * guardian.GuardianWeaponScale, texture.Height * guardian.GuardianWeaponScale) * 0.5f).Floor(); + Projectile.width = (int)(texture.Height * guardian.GuardianWeaponScale / guardianItem.ShieldFrames); + Projectile.height = (int)(texture.Height * guardian.GuardianWeaponScale / guardianItem.ShieldFrames); + aimedLocation += (oldDimensions * 0.5f - new Vector2(texture.Height * guardian.GuardianWeaponScale / guardianItem.ShieldFrames, texture.Height * guardian.GuardianWeaponScale / guardianItem.ShieldFrames) * 0.5f).Floor(); } aimedLocation += owner.Center.Floor() - oldOwnerPos.Floor(); @@ -389,12 +391,15 @@ public override bool OrchidPreDraw(SpriteBatch spriteBatch, ref Color lightColor SpriteEffects effect = Projectile.spriteDirection == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally; float colorMult = (Projectile.ai[1] + Projectile.ai[0] > 0 ? 1f : (0.4f + Math.Abs((1f * Main.player[Main.myPlayer].GetModPlayer().Timer120 - 60) / 120f))); float flippedRotation = Projectile.rotation + (Projectile.spriteDirection == 1 ? 0 : MathHelper.Pi); - spriteBatch.Draw(texture, drawPosition, null, color * colorMult, flippedRotation, texture.Size() * 0.5f, Projectile.scale, effect, 0f); + + Rectangle frame = texture.Frame(1, guardianItem.ShieldFrames, 0, ShieldAnimFrame % guardianItem.ShieldFrames); + + spriteBatch.Draw(texture, drawPosition, frame, color * colorMult, flippedRotation, frame.Size() * 0.5f, Projectile.scale, effect, 0f); if (ModContent.RequestIfExists(guardianItem.ShieldTexture + "_Glow", out Asset assetglow)) { Color glowColor = guardianItem.GetPaviseGlowmaskColor(player, guardian, Projectile, lightColor); - spriteBatch.Draw(assetglow.Value, drawPosition, null, glowColor, flippedRotation, texture.Size() * 0.5f, Projectile.scale, effect, 0f); + spriteBatch.Draw(assetglow.Value, drawPosition, frame, glowColor, flippedRotation, frame.Size() * 0.5f, Projectile.scale, effect, 0f); } } guardianItem.PostDrawShield(spriteBatch, Projectile, player, color); diff --git a/Content/Guardian/OrchidModGuardianHammer.cs b/Content/Guardian/OrchidModGuardianHammer.cs index 851912f1..527154f9 100644 --- a/Content/Guardian/OrchidModGuardianHammer.cs +++ b/Content/Guardian/OrchidModGuardianHammer.cs @@ -39,6 +39,7 @@ public abstract class OrchidModGuardianHammer : OrchidModGuardianItem /// If true, the anchor will load and use ItemName_Hammer.png as its texture. public bool hasSpecialHammerTexture = false; public virtual string HammerTexture => Texture + "_Hammer"; + public int HammerFrames = 1; public virtual void OnBlockContact(Player player, OrchidGuardian guardian, NPC target, Projectile projectile) { } // Called upon pushing an enemy with a throw (can happen repeatedly) public virtual void OnBlockNPC(Player player, OrchidGuardian guardian, NPC target, Projectile projectile) { } // Called upon blocking an enemy (1 time per throw per enemy) @@ -92,6 +93,8 @@ public sealed override void SetDefaults() BlockDamage = 0.33f; BlockDuration = 180; BlockVelocityMult = 1f; + + HammerFrames = 1; OrchidGlobalItemPerEntity orchidItem = Item.GetGlobalItem(); orchidItem.guardianWeapon = true; diff --git a/Content/Guardian/OrchidModGuardianQuarterstaff.cs b/Content/Guardian/OrchidModGuardianQuarterstaff.cs index 959e5779..6bdc8d12 100644 --- a/Content/Guardian/OrchidModGuardianQuarterstaff.cs +++ b/Content/Guardian/OrchidModGuardianQuarterstaff.cs @@ -66,6 +66,11 @@ public virtual void SafeHoldItem(Player player) { } //public bool SingleSwing = false; // allows a special swing behaviour /// Multiplier for the amount of bonus charge gained from hitting with a jab. public float JabChargeGain = 1; + /// + /// The amount of animation frames of the quarterstaff texture. + ///
The animation frame must be set manually using GuardianQuarterstaffAnchor.QuarterstaffAnimFrame. + ///
+ public int QuarterstaffFrames = 1; public sealed override void SetDefaults() { @@ -78,6 +83,8 @@ public sealed override void SetDefaults() Item.useStyle = ItemUseStyleID.Thrust; Item.useTime = 30; Item.knockBack = 5f; + + QuarterstaffFrames = 1; OrchidGlobalItemPerEntity orchidItem = Item.GetGlobalItem(); orchidItem.guardianWeapon = true; diff --git a/Content/Guardian/OrchidModGuardianShield.cs b/Content/Guardian/OrchidModGuardianShield.cs index e0ea28ad..19916bb8 100644 --- a/Content/Guardian/OrchidModGuardianShield.cs +++ b/Content/Guardian/OrchidModGuardianShield.cs @@ -1,3 +1,4 @@ +using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using OrchidMod.Common; @@ -17,6 +18,8 @@ namespace OrchidMod.Content.Guardian public abstract class OrchidModGuardianShield : OrchidModGuardianItem { public virtual string ShieldTexture => Texture + "_Shield"; + public int ShieldFrames = 1; + public virtual void ExtraAIShield(Projectile projectile) { } public virtual void PostDrawShield(SpriteBatch spriteBatch, Projectile projectile, Player player, Color lightColor) { } public virtual bool PreDrawShield(SpriteBatch spriteBatch, Projectile projectile, Player player, ref Color lightColor) { return true; } @@ -28,6 +31,8 @@ public virtual void SlamHitFirst(Player player, Projectile shield, NPC npc) { } public virtual void SlamHit(Player player, Projectile shield, NPC npc) { } /// Called on the first frame of a slam. public virtual void Slam(Player player, Projectile shield) { } + /// Called on the last frame of a slam. + public virtual void SlamEnd(Player player, Projectile shield) { } /// Called when an enemy collides with the shield during a block. Will be called once per frame per enemy colliding with it. public virtual void Push(Player player, Projectile shield, NPC npc) { } /// Called once per block when the first enemy or projectile is blocked. This is called after Push or Block, but before Block destroys the projectile. @@ -49,6 +54,23 @@ public virtual void BlockStart(Player player, Projectile shield) { } /// Causes the shield's held sprite to flip when facing right. public bool shouldFlip = false; public bool slamAutoReuse = true; + /// + /// If true, the shield will be rotated in discrete steps, instead of a single continuous circle. Defaults to false. + /// + public bool useDiscreteAim = false; + /// + /// The amount of steps per half-rotation that the shield will snap to, if useDiscreteAim is true. + ///
A value of 0 results in only a single possible angle, directly in front of the player. Otherwise, there will be twice as many snap points as this value. + ///
+ public int discreteAimIncrements; + /// + /// The angle, in pi/2 increments, that the base angle will be rotated by. + /// + public int discreteAimRotation; + /// + /// If true, slams performed with the shield will be locked to the rotation they started with, rather than being free to rotate mid-slam. + /// + public bool lockSlamRotation; public sealed override void SetDefaults() { @@ -61,6 +83,11 @@ public sealed override void SetDefaults() Item.useStyle = ItemUseStyleID.Thrust; Item.useTime = 30; Item.knockBack = 6f; + useDiscreteAim = false; + discreteAimIncrements = 2; + discreteAimRotation = 0; + lockSlamRotation = false; + ShieldFrames = 1; OrchidGlobalItemPerEntity orchidItem = Item.GetGlobalItem(); orchidItem.guardianWeapon = true; @@ -243,5 +270,17 @@ public override void ModifyTooltips(List tooltips) OverrideColor = new Color(175, 255, 175) }); } + + public static float GetSnappedAngle(OrchidModGuardianShield shield, Player player, float originalAngle) + { + if (!shield.useDiscreteAim) return originalAngle; + if (shield.discreteAimIncrements == 0) return -player.direction * MathHelper.PiOver2 * shield.discreteAimRotation + (player.direction == -1 ? MathHelper.Pi : 0f); + else + { + float angleIncrement = MathHelper.Pi / shield.discreteAimIncrements; + return (float)Math.Round((Vector2.Normalize(Main.MouseWorld - player.MountedCenter.Floor()).ToRotation() + MathHelper.PiOver2 * shield.discreteAimRotation) / angleIncrement) * angleIncrement - MathHelper.PiOver2 * shield.discreteAimRotation; + } + + } } } diff --git a/Content/Guardian/Weapons/Shields/Skateboard.cs b/Content/Guardian/Weapons/Shields/Skateboard.cs index ca97dc6f..422e4661 100644 --- a/Content/Guardian/Weapons/Shields/Skateboard.cs +++ b/Content/Guardian/Weapons/Shields/Skateboard.cs @@ -2,6 +2,8 @@ using Microsoft.Xna.Framework.Graphics; using OrchidMod.Assets; using System; +using Microsoft.Xna.Framework.Input; +using OrchidMod.Common.ModObjects; using Terraria; using Terraria.Audio; using Terraria.ID; @@ -15,6 +17,7 @@ public class Skateboard : OrchidModGuardianShield public Texture2D TextureWheels; public float playerVelocity; public int TimeSpent = 0; + public int AirTime = 0; public override void SafeSetDefaults() { @@ -30,6 +33,7 @@ public override void SafeSetDefaults() slamDistance = 50f; blockDuration = 240; TextureWheels ??= ModContent.Request(Texture + "_Wheels", ReLogic.Content.AssetRequestMode.ImmediateLoad).Value; + ShieldFrames = 4; } public override void BlockStart(Player player, Projectile shield) @@ -60,8 +64,13 @@ public override void PostDrawShield(SpriteBatch spriteBatch, Projectile projecti var effect = projectile.spriteDirection == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally; for (int i = -1; i < 2; i+= 2) { - Vector2 drawPosition = projectile.Center - new Vector2(4f, 8f * i).RotatedBy(projectile.rotation) - Main.screenPosition; - spriteBatch.Draw(TextureWheels, drawPosition, null, lightColor * (projectile.ai[0] > 0f ? 1f : 0.5f), projectile.rotation + TimeSpent * 0.05f, TextureWheels.Size() * 0.5f, projectile.scale, effect, 0f); + GuardianShieldAnchor anchor = projectile.ModProjectile as GuardianShieldAnchor; + if (anchor != null && anchor.ShieldAnimFrame % 2 == 0) + { + Vector2 drawPosition = projectile.Center - new Vector2(4f, 8f * i).RotatedBy(projectile.rotation) * (anchor.ShieldAnimFrame == 2 ? -1f : 1f) - Main.screenPosition; + spriteBatch.Draw(TextureWheels, drawPosition, null, lightColor * (projectile.ai[0] > 0f ? 1f : 0.5f), projectile.rotation + TimeSpent * 0.05f, TextureWheels.Size() * 0.5f, projectile.scale, effect, 0f); + } + } } @@ -84,7 +93,7 @@ public override void ExtraAIShield(Projectile projectile) projectile.rotation = -MathHelper.PiOver2; // Collision with the ground, do skating stuff - Vector2 collision = Collision.TileCollision(owner.position + new Vector2((owner.width - Item.width) * 0.5f, owner.height), Vector2.UnitY * 12f, Item.width, 14, false, false, (int)owner.gravDir); + Vector2 collision = Collision.TileCollision(owner.position + new Vector2((owner.width - Item.width) * 0.5f, owner.height), Vector2.UnitY * 12f, Item.width, 14, false, owner.controlDown, (int)owner.gravDir); if (collision != Vector2.UnitY * 12f) { owner.fallStart = (int)(owner.position.Y / 16f); @@ -93,27 +102,47 @@ public override void ExtraAIShield(Projectile projectile) owner.velocity.X = playerVelocity; owner.velocity.Y = 0.1f; - if (playerVelocity < 0) - { - TimeSpent -= 10; - } - else if (playerVelocity > 0) - { - TimeSpent += 9; - } + if (playerVelocity < 0) TimeSpent -= 10; + else if (playerVelocity > 0) TimeSpent += 9; + + // owner.eocDash = 0; + + AirTime = 0; + anchor.ShieldAnimFrame = 0; + if (Main.rand.NextBool(4)) SoundEngine.PlaySound(SoundID.Item55, projectile.Center); + // + // if (AirTime == 0 && Main.keyState.IsKeyDown(Keys.Space)) + // { + // owner.velocity.Y = -8f; + // owner.position.Y -= collision.Y + 1.7f; + // owner.wingTime = 0f; + // owner.eocDash = 0; + // SoundEngine.PlaySound(SoundID.Item32); + // } } else { + AirTime++; + if (AirTime % 4 == 0) anchor.ShieldAnimFrame++; + if (anchor.ShieldAnimFrame > 3) anchor.ShieldAnimFrame = 0; + if (playerVelocity == 0) SoundEngine.PlaySound(SoundID.Item53, projectile.Center); playerVelocity = owner.velocity.X; if (playerVelocity < 1f) playerVelocity = 8f * owner.direction; if (Math.Abs(playerVelocity) < 8f) playerVelocity = 8f * Math.Sign(playerVelocity); owner.velocity.X = playerVelocity; + + projectile.ai[0]++; } } } + else + { + AirTime = 0; + ((GuardianShieldAnchor)projectile.ModProjectile).ShieldAnimFrame = 0; + } } } } diff --git a/Content/Guardian/Weapons/Shields/Skateboard_Shield.png b/Content/Guardian/Weapons/Shields/Skateboard_Shield.png index 18ff626a..a76eca5e 100644 Binary files a/Content/Guardian/Weapons/Shields/Skateboard_Shield.png and b/Content/Guardian/Weapons/Shields/Skateboard_Shield.png differ