From a3f5d0c71b365d44a6cfbfbdb404dc326bc15f7d Mon Sep 17 00:00:00 2001 From: Ozzatron Date: Sun, 15 Sep 2019 23:07:00 -0400 Subject: [PATCH] Added Glaive (rogue weapon). --- .../CalamityDamageItem.cs | 1 - Items/CalamityCustomThrowingDamage/Glaive.cs | 63 ++++++++ Items/CalamityCustomThrowingDamage/Glaive.png | Bin 0 -> 711 bytes Projectiles/Rogue/GlaiveProj.cs | 150 ++++++++++++++++++ Projectiles/Rogue/GlaiveProj.png | Bin 0 -> 711 bytes 5 files changed, 213 insertions(+), 1 deletion(-) create mode 100644 Items/CalamityCustomThrowingDamage/Glaive.cs create mode 100644 Items/CalamityCustomThrowingDamage/Glaive.png create mode 100644 Projectiles/Rogue/GlaiveProj.cs create mode 100644 Projectiles/Rogue/GlaiveProj.png diff --git a/Items/CalamityCustomThrowingDamage/CalamityDamageItem.cs b/Items/CalamityCustomThrowingDamage/CalamityDamageItem.cs index 1f04a66b9b..9f59cb3f1c 100644 --- a/Items/CalamityCustomThrowingDamage/CalamityDamageItem.cs +++ b/Items/CalamityCustomThrowingDamage/CalamityDamageItem.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using Terraria; using Terraria.ModLoader; -using CalamityMod.CalPlayer; namespace CalamityMod.Items.CalamityCustomThrowingDamage { diff --git a/Items/CalamityCustomThrowingDamage/Glaive.cs b/Items/CalamityCustomThrowingDamage/Glaive.cs new file mode 100644 index 0000000000..2846206818 --- /dev/null +++ b/Items/CalamityCustomThrowingDamage/Glaive.cs @@ -0,0 +1,63 @@ +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; + +namespace CalamityMod.Items.CalamityCustomThrowingDamage +{ + public class Glaive : CalamityDamageItem + { + public static int BaseDamage = 23; + public static float Knockback = 3f; + public static float Speed = 10f; + public static float StealthSpeedMult = 1.8f; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Glaive"); + Tooltip.SetDefault("Stacks up to 3"); + // Add stealth strike tooltip once stealth strikes are implemented + } + + public override void SafeSetDefaults() + { + item.damage = BaseDamage; + item.crit = 4; + item.GetGlobalItem(mod).rogue = true; + item.noMelee = true; + item.noUseGraphic = true; + item.width = 1; + item.height = 1; + item.useTime = 15; + item.useAnimation = 15; + item.useStyle = 1; + item.knockBack = Knockback; + item.value = Item.buyPrice(0, 3, 0, 0); + item.rare = 3; + item.UseSound = SoundID.Item1; + item.maxStack = 3; + + item.shootSpeed = Speed; + item.shoot = mod.ProjectileType("GlaiveProj"); + } + + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + float ai1 = 0f; + if (player.GetCalamityPlayer().StealthStrikeAvailable()) + { + speedX *= StealthSpeedMult; + speedY *= StealthSpeedMult; + ai1 = 1f; + } + + Projectile.NewProjectile(position, new Vector2(speedX, speedY), type, damage, knockBack, player.whoAmI, 0f, ai1); + return false; + } + + public override bool CanUseItem(Player player) + { + return player.ownedProjectileCounts[item.shoot] < item.stack; + } + + } +} diff --git a/Items/CalamityCustomThrowingDamage/Glaive.png b/Items/CalamityCustomThrowingDamage/Glaive.png new file mode 100644 index 0000000000000000000000000000000000000000..810ef352872d6b7252818280f20c96e9ce3d0586 GIT binary patch literal 711 zcmV;&0yzDNP)Px%fk{L`R9J=8m%nRMQ545NuS8>vK z1s%k#leiQ_M6jicqe7twfh^tPAP#Et(rWX=klM7Q4sm!nP43HkuS5`TzfxWfyJ$|wB z4S-ZSWdKwwmC%RiLqteeRuX`Ez19I}w_8B3j-0p6?iQDbka#tJLm5AuaqAFWBF)B* za-rO(Z`O=mngDtvBrCEP&MJnb^&bFSi*G3NtDkm(J`!C$d$aHED;Je{+rH>l)>;FA z-MuED6A^1PtB}}m+!uO15s96U8J|3@tiS#kQ^sDhh5TpV^YtU*RWuqmpqD-I_$dHd ztsRA+=rEEY{SBZQkx&E4_dYw{K1Dn`ek^7H?Ei7=O)8xNpjxT=l9x_T8zPaQ|0h9` z*eR8ZZmghoZpMh}TeVU>Sn@m1ams*3L<0MfAbDdYr2hE!ra{t%NaS!6e_2-204Nml t3Yk**-_Fy9$j~t&3hHCLXCJv3`3t&A<79kWuulL0002ovPDHLkV1lRZNgV(H literal 0 HcmV?d00001 diff --git a/Projectiles/Rogue/GlaiveProj.cs b/Projectiles/Rogue/GlaiveProj.cs new file mode 100644 index 0000000000..b3f1dfdece --- /dev/null +++ b/Projectiles/Rogue/GlaiveProj.cs @@ -0,0 +1,150 @@ +using CalamityMod.Items.CalamityCustomThrowingDamage; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Rogue +{ + public class GlaiveProj : ModProjectile + { + private static int Lifetime = 180; + private static int ReboundTime = 45; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Glaive"); + ProjectileID.Sets.TrailCacheLength[projectile.type] = 3; + ProjectileID.Sets.TrailingMode[projectile.type] = 0; + } + + public override void SetDefaults() + { + projectile.width = 16; + projectile.height = 16; + projectile.friendly = true; + projectile.tileCollide = true; + projectile.penetrate = 3; + projectile.timeLeft = Lifetime; + drawOffsetX = -10; + projectile.GetGlobalProjectile(mod).rogue = true; + } + + public override void AI() + { + // ai[1] = 1 means that the projectile is a stealth strike, in which case it pierces infinitely. + if (projectile.ai[1] == 1f) + projectile.penetrate = projectile.maxPenetrate = -1; + + // Boomerang rotation + projectile.rotation += 0.4f * (float)projectile.direction; + + // Boomerang sound + if (projectile.soundDelay == 0) + { + projectile.soundDelay = 8; + Main.PlaySound(SoundID.Item7, projectile.position); + } + + // Returns after some number of frames in the air + if(projectile.timeLeft < Lifetime - ReboundTime) + projectile.ai[0] = 1f; + + if (projectile.ai[0] != 0f) + { + projectile.tileCollide = false; + + float returnSpeed = Glaive.Speed; + float acceleration = 0.45f; + + if (projectile.ai[1] == 1f) + { + returnSpeed *= Glaive.StealthSpeedMult; + acceleration *= Glaive.StealthSpeedMult; + } + + Player owner = Main.player[projectile.owner]; + + // Delete the projectile if it's excessively far away. + Vector2 playerCenter = owner.Center; + float xDist = playerCenter.X - projectile.Center.X; + float yDist = playerCenter.Y - projectile.Center.Y; + float dist = (float)Math.Sqrt((double)(xDist * xDist + yDist * yDist)); + if (dist > 3000f) + projectile.Kill(); + + dist = returnSpeed / dist; + xDist *= dist; + yDist *= dist; + + // Home back in on the player. + if (projectile.velocity.X < xDist) + { + projectile.velocity.X = projectile.velocity.X + acceleration; + if (projectile.velocity.X < 0f && xDist > 0f) + projectile.velocity.X += acceleration; + } + else if (projectile.velocity.X > xDist) + { + projectile.velocity.X = projectile.velocity.X - acceleration; + if (projectile.velocity.X > 0f && xDist < 0f) + projectile.velocity.X -= acceleration; + } + if (projectile.velocity.Y < yDist) + { + projectile.velocity.Y = projectile.velocity.Y + acceleration; + if (projectile.velocity.Y < 0f && yDist > 0f) + projectile.velocity.Y += acceleration; + } + else if (projectile.velocity.Y > yDist) + { + projectile.velocity.Y = projectile.velocity.Y - acceleration; + if (projectile.velocity.Y > 0f && yDist < 0f) + projectile.velocity.Y -= acceleration; + } + + // Delete the projectile if it touches its owner. + if (Main.myPlayer == projectile.owner) + if (projectile.Hitbox.Intersects(owner.Hitbox)) + projectile.Kill(); + } + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + CalamityGlobalProjectile.DrawCenteredAndAfterimage(projectile, lightColor, ProjectileID.Sets.TrailingMode[projectile.type], 1); + return false; + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + // After its last hit, starts returning instead of vanishing. Can pierce infinitely on the way back. + if (projectile.penetrate == 1) + { + projectile.penetrate = -1; + projectile.ai[0] = 1f; + } + } + + // Make it bounce on tiles. + public override bool OnTileCollide(Vector2 oldVelocity) + { + // Impacts the terrain even though it bounces off. + Main.PlaySound(SoundID.Dig, projectile.Center); + Collision.HitTiles(projectile.position, projectile.velocity, projectile.width, projectile.height); + + if (projectile.velocity.X != oldVelocity.X) + { + projectile.velocity.X = -oldVelocity.X; + } + if (projectile.velocity.Y != oldVelocity.Y) + { + projectile.velocity.Y = -oldVelocity.Y; + } + projectile.ai[0] = 1f; + return false; + } + } +} diff --git a/Projectiles/Rogue/GlaiveProj.png b/Projectiles/Rogue/GlaiveProj.png new file mode 100644 index 0000000000000000000000000000000000000000..810ef352872d6b7252818280f20c96e9ce3d0586 GIT binary patch literal 711 zcmV;&0yzDNP)Px%fk{L`R9J=8m%nRMQ545NuS8>vK z1s%k#leiQ_M6jicqe7twfh^tPAP#Et(rWX=klM7Q4sm!nP43HkuS5`TzfxWfyJ$|wB z4S-ZSWdKwwmC%RiLqteeRuX`Ez19I}w_8B3j-0p6?iQDbka#tJLm5AuaqAFWBF)B* za-rO(Z`O=mngDtvBrCEP&MJnb^&bFSi*G3NtDkm(J`!C$d$aHED;Je{+rH>l)>;FA z-MuED6A^1PtB}}m+!uO15s96U8J|3@tiS#kQ^sDhh5TpV^YtU*RWuqmpqD-I_$dHd ztsRA+=rEEY{SBZQkx&E4_dYw{K1Dn`ek^7H?Ei7=O)8xNpjxT=l9x_T8zPaQ|0h9` z*eR8ZZmghoZpMh}TeVU>Sn@m1ams*3L<0MfAbDdYr2hE!ra{t%NaS!6e_2-204Nml t3Yk**-_Fy9$j~t&3hHCLXCJv3`3t&A<79kWuulL0002ovPDHLkV1lRZNgV(H literal 0 HcmV?d00001