diff --git a/Items/Fishing/Spadefish.cs b/Items/Fishing/Spadefish.cs index 37d1e0ed35..6000afb028 100644 --- a/Items/Fishing/Spadefish.cs +++ b/Items/Fishing/Spadefish.cs @@ -1,28 +1,39 @@ using System; +using System.Collections.Generic; +using System.IO; using System.Linq; -using CalamityMod.Graphics.Renderers; using CalamityMod.Items.Weapons.Rogue; -using CalamityMod.Systems; using CalamityMod.Utilities.Daybreak; using CalamityMod.Utilities.Daybreak.Buffers; using Microsoft.CodeAnalysis; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; using Terraria; using Terraria.Audio; using Terraria.DataStructures; using Terraria.GameContent; -using Terraria.Graphics; +using Terraria.GameContent.Achievements; using Terraria.Graphics.Renderers; using Terraria.ID; using Terraria.ModLoader; +using Terraria.ModLoader.IO; namespace CalamityMod.Items.Fishing { public class Spadefish : RogueWeapon, ILocalizedModType { - public static float SpinsToThrow => 3; + + public static float SpinDamageMult => 0.33f; + + public static float SpinAccel => 1.0175f; + + public static float SpinThrowVelocityMult => 1.5f; + + public override float StealthDamageMultiplier => 2f; + + public static int PickPower => 50; public new string LocalizationCategory => "Items.Fishing"; public override void SetDefaults() { @@ -32,7 +43,7 @@ namespace CalamityMod.Items.Fishing Item.knockBack = 2f; Item.useTime = 40; Item.useAnimation = 40; - Item.shootSpeed = 10; + Item.shootSpeed = 12; Item.DamageType = RogueDamageClass.Instance; Item.useTurn = true; @@ -45,6 +56,7 @@ namespace CalamityMod.Items.Fishing Item.shoot = ModContent.ProjectileType(); Item.noMelee = true; Item.noUseGraphic = true; + Item.pick = PickPower; } public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) @@ -52,12 +64,60 @@ namespace CalamityMod.Items.Fishing if (player.Calamity().StealthStrikeAvailable()) { type = ModContent.ProjectileType(); - Projectile.NewProjectile(source, position, velocity, type, damage, knockback, player.whoAmI); - //This proj sets StealthStrike on its own setdefaults + Projectile.NewProjectile(source, position, velocity, type, damage, knockback, player.whoAmI); //This proj sets StealthStrike on its own setdefaults + + player.Calamity().ConsumeStealthByAttacking(); //Due to the holdout, we manually consume stealth here and on spam. return false; } + player.Calamity().rogueStealth = 0; return true; } + + + #region Toggleable Mining + + public bool CanMine = false; + public override void ModifyTooltips(List tooltips) + { + tooltips.FindAndReplace("[TOGGLE]", CanMine ? this.GetLocalizedValue("TextWhileEnabled") : this.GetLocalizedValue("TextWhileDisabled")); + } + public override bool CanRightClick() => Main.keyState.PressingShift(); + public override void RightClick(Player player) + { + CanMine = !CanMine; + Item.NetStateChanged(); + } + public override bool ConsumeItem(Player player) => false; + public override void SaveData(TagCompound tag) + { + tag.Add("CanMine", CanMine); + } + + public override void LoadData(TagCompound tag) + { + CanMine = tag.GetBool("CanMine"); + } + + public override void NetSend(BinaryWriter writer) + { + writer.Write(CanMine); + } + + public override void NetReceive(BinaryReader reader) + { + CanMine = reader.ReadBoolean(); + } + Asset texture; + public override void PostDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale) + { + if (CanMine) + { + var tex = CalamityUtils.GetTextureEfficient(ref texture, "Terraria/Images/Extra_48").Value; + var dotFrame = tex.Frame(8, 39, 4, 23); + spriteBatch.Draw(tex, position + new Vector2(16, 16) * Main.inventoryScale, dotFrame, Color.White, 0, dotFrame.Size() * 0.5f, Main.inventoryScale, SpriteEffects.None, 0); + } + } + #endregion } public class SpadefishThrown : ModProjectile, ILocalizedModType @@ -68,48 +128,151 @@ namespace CalamityMod.Items.Fishing { Projectile.DamageType = RogueDamageClass.Instance; Projectile.usesLocalNPCImmunity = true; - Projectile.localNPCHitCooldown = 30; + Projectile.localNPCHitCooldown = -1; + Projectile.penetrate = 3; Projectile.width = 16; Projectile.height = 16; Projectile.friendly = true; Projectile.stopsDealingDamageAfterPenetrateHits = true; - Projectile.timeLeft = 180; + Projectile.timeLeft = 480; + Projectile.MaxUpdates = 2; + Projectile.ignoreWater = true; } - + bool frameOne = true; public override void AI() { - if (Projectile.ai[0] <= 1) - Projectile.velocity.Y += 0.2f; + if (frameOne) + { + Projectile.velocity /= Projectile.MaxUpdates; + frameOne = false; + } + if (Projectile.ai[0] <= 1 && Projectile.timeLeft < 330) + Projectile.velocity.Y += 0.08f; if (Projectile.ai[0] == 0) Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver4; else if (Projectile.ai[0] == 1) Projectile.rotation += Projectile.velocity.X * 0.15f; + + if (Projectile.timeLeft < 60) + { + Projectile.Opacity = Projectile.timeLeft / 60f; + } } public override bool OnTileCollide(Vector2 oldVelocity) { + if (Projectile.ai[0] == 1) Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver4; Projectile.velocity = Vector2.Zero; - Projectile.Center += oldVelocity * 2; + Projectile.Center += oldVelocity; Projectile.ai[0] = 2; + if (Main.myPlayer == Projectile.owner && Main.LocalPlayer.HeldItem.ModItem is Spadefish s && s.CanMine) + for (var j = -1; j < 2; j++) + for (var k = -1; k < 2; k++) + Dig(Spadefish.PickPower, Projectile.Center.ToTileCoordinates() + new Point(j, k)); return false; } + public static void Dig(int pickPower, Point point) + { + var tile = Main.tile[point]; + var x = tile.X(); + var y = tile.Y(); + + if (!tile.HasTile) + return; + + int hitIndex = Main.LocalPlayer.hitTile.HitObject(x, y, 1); + + if (tile.TileType == TileID.MysticSnakeRope) + return; + + int pickDmg = Main.LocalPlayer.GetPickaxeDamage(x, y, 30, hitIndex, tile); + + + if (!WorldGen.CanKillTile(x, y)) + pickDmg = 0; + + //Normally, Vanilla multiplies pick dmg by 2 for FTW here. I don't want that on spadefish so I am not including it. + + if (Main.LocalPlayer.DoesPickTargetTransformOnKill(Main.LocalPlayer.hitTile, pickDmg, x, y, pickPower, hitIndex, tile)) + pickDmg = 0; + + if (Main.LocalPlayer.hitTile.AddDamage(hitIndex, pickDmg) >= 100) + { + AchievementsHelper.CurrentlyMining = true; + Main.LocalPlayer.ClearMiningCacheAt(x, y, 1); + if (Main.netMode == NetmodeID.MultiplayerClient && Main.tileContainer[tile.TileType]) + { + if (tile.TileType == TileID.DisplayDoll || tile.TileType == TileID.HatRack) + NetMessage.SendData(MessageID.TileManipulation, -1, -1, null, 20, x, y); + else + { + WorldGen.KillTile(x, y, fail: true); + NetMessage.SendData(MessageID.TileManipulation, -1, -1, null, 0, x, y, 1f); + } + if (tile.TileType == TileID.Containers) + { + NetMessage.SendData(MessageID.ChestUpdates, -1, -1, null, 1, x, y); + } + if (tile.TileType == TileID.Containers2) + { + NetMessage.SendData(MessageID.ChestUpdates, -1, -1, null, 5, x, y); + } + if (tile.TileType == TileID.Dressers) + { + NetMessage.SendData(MessageID.ChestUpdates, -1, -1, null, 3, x, y); + } + } + else + { + bool flag = tile.HasTile; + WorldGen.KillTile(x, y); + if (!Main.dedServ && flag && !tile.HasTile) + { + AchievementsHelper.HandleMining(); + } + if (Main.netMode == NetmodeID.MultiplayerClient) + { + NetMessage.SendData(MessageID.TileManipulation, -1, -1, null, 0, x, y); + } + } + AchievementsHelper.CurrentlyMining = false; + } + else + { + WorldGen.KillTile(x, y, fail: true); + if (Main.netMode == NetmodeID.MultiplayerClient) + { + NetMessage.SendData(MessageID.TileManipulation, -1, -1, null, 0, x, y, 1f); + NetMessage.SendData(MessageID.SyncTilePicking, -1, -1, null, Main.myPlayer, x, y, pickDmg); + } + } + if (pickDmg != 0) + { + Main.LocalPlayer.hitTile.Prune(); + } + } + + + + public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) { SoundEngine.PlaySound(SoundID.Item178, Projectile.Center); - Projectile.velocity.X = Projectile.velocity.X.DirectionalSign() * -2; - Projectile.velocity.Y = -3f; + Projectile.velocity.X = -Projectile.velocity.X.DirectionalSign(); + Projectile.velocity.Y = -2f; Projectile.ai[0] = 1; + Projectile.damage /= 2; Projectile.netUpdate = true; } public override bool PreDraw(ref Color lightColor) { var tex = TextureAssets.Projectile[Type]; - Main.EntitySpriteDraw(tex.Value, Projectile.Center - Main.screenPosition, null, lightColor, Projectile.rotation, tex.Size() * 0.5f, Projectile.scale, 0); + Main.EntitySpriteDraw(tex.Value, Projectile.Center - Main.screenPosition, null, lightColor * Projectile.Opacity, Projectile.rotation, tex.Size() * 0.5f, Projectile.scale, 0); return false; } } @@ -122,10 +285,13 @@ namespace CalamityMod.Items.Fishing ref float spin => ref Projectile.ai[0]; ref float startingDir => ref Projectile.ai[1]; - float throwSpeed = 12; + float throwSpeed = 12; //changing this does nothing, as this is set in the code. This is just a fallback value if something breaks. bool reset = false; + float oldSpin = 0; + int digDir = 0; + float spinSin => MathF.Sin(spin); public override void SetDefaults() { @@ -169,7 +335,7 @@ namespace CalamityMod.Items.Fishing bool flip = (Spade.spinSin * Spade.startingDir) < 0; var tex = TextureAssets.Projectile[Type]; - Main.EntitySpriteDraw(tex.Value, drawPlayer.Center + new Vector2(40,0) - Main.screenPosition, null, Lighting.GetColor(Spade.Projectile.Center.ToTileCoordinates()), Spade.Projectile.rotation - (flip ? MathHelper.PiOver2 : 0), tex.Size() * 0.5f, new Vector2(Spade.Projectile.scale, Spade.Projectile.scale), flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None); + Main.EntitySpriteDraw(tex.Value, drawPlayer.Center + new Vector2(40, 0) - Main.screenPosition, null, Lighting.GetColor(Spade.Projectile.Center.ToTileCoordinates()), Spade.Projectile.rotation - (flip ? MathHelper.PiOver2 : 0), tex.Size() * 0.5f, new Vector2(Spade.Projectile.scale, Spade.Projectile.scale), flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None); } float width = Spade.spinSin * Spade.startingDir * drawPlayer.direction; @@ -188,30 +354,34 @@ namespace CalamityMod.Items.Fishing { startingDir = Projectile.velocity.X.DirectionalSign(); throwSpeed = Projectile.velocity.Length(); - Projectile.velocity= Vector2.Zero; - player.Calamity().ConsumeStealthByAttacking(); + Projectile.velocity = Vector2.Zero; } player.direction = 1; - player.SetDummyItemTime(40); + player.SetDummyItemTime((int)(player.HeldItem.useTime * player.GetWeaponAttackSpeed(player.HeldItem))); Projectile.Center = player.Center + new Vector2(48 * spinSin, 0 * MathF.Cos(spin)) * startingDir; Projectile.rotation = Projectile.DirectionFrom(player.Center).ToRotation() + MathHelper.PiOver4; if (spin == 0) { spin = MathHelper.TwoPi; } - spin *= 1.0175f; + spin *= Spadefish.SpinAccel; - if (spinSin < 0.25f && spinSin > -0.25f) + int res = reset ? -1 : 1; + if (res != spinSin.DirectionalSign()) { - if (reset) - Projectile.ResetLocalNPCHitImmunity(); - reset = false; + Projectile.ResetLocalNPCHitImmunity(); + reset = !reset; } - else reset = true; - if (spin > MathHelper.TwoPi * (1+Spadefish.SpinsToThrow)) + if (Projectile.timeLeft % 5 == 0 && Main.myPlayer == Projectile.owner && Main.LocalPlayer.HeldItem.ModItem is Spadefish s && s.CanMine) + for (var j = -1; j < 2; j++) + for (var k = -1; k < 2; k++) + SpadefishThrown.Dig(Spadefish.PickPower, Projectile.Center.ToTileCoordinates() + new Point(j, k)); + + if (spin > MathHelper.TwoPi * (1 + Spadefish.SpinsToThrow)) { - Projectile.NewProjectile(Projectile.GetSource_FromThis(), player.Center, player.Calamity().mouseRotationFromPlayer.ToRotationVector2() * throwSpeed * 1.2f, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, player.whoAmI); + var p = Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), player.Center, player.Calamity().mouseRotationFromPlayer.ToRotationVector2() * throwSpeed * Spadefish.SpinThrowVelocityMult, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, player.whoAmI); + p.Calamity().stealthStrike = true; Projectile.Kill(); } } @@ -225,5 +395,10 @@ namespace CalamityMod.Items.Fishing { SoundEngine.PlaySound(SoundID.Item178, Projectile.Center); } + + public override void ModifyHitNPC(NPC target, ref NPC.HitModifiers modifiers) + { + modifiers.SourceDamage *= Spadefish.SpinDamageMult; + } } } diff --git a/Localization/en-US/Mods.CalamityMod.Items.Fishing.hjson b/Localization/en-US/Mods.CalamityMod.Items.Fishing.hjson index 18379c8318..9d31adda4a 100644 --- a/Localization/en-US/Mods.CalamityMod.Items.Fishing.hjson +++ b/Localization/en-US/Mods.CalamityMod.Items.Fishing.hjson @@ -283,9 +283,12 @@ Spadefish: { ''' Throws a spadefish at enemies Stealth Strikes cause you to spin the spade before throwing, damaging nearby enemies + [c/aaaaaa:Shift- this item in your inventory to [TOGGLE] breaking tiles] 'How can a fish be used to dig through the ground? Some questions are best left unanswered...' ''' + TextWhileEnabled: disable + TextWhileDisabled: enable } StuffedFish: { diff --git a/Localization/en-US/Mods.CalamityMod.Projectiles.Rogue.hjson b/Localization/en-US/Mods.CalamityMod.Projectiles.Rogue.hjson index 228285a23b..721c77a267 100644 --- a/Localization/en-US/Mods.CalamityMod.Projectiles.Rogue.hjson +++ b/Localization/en-US/Mods.CalamityMod.Projectiles.Rogue.hjson @@ -344,3 +344,5 @@ WulfrumKnifeProj.DisplayName: Wulfrum Knife NanoblackLightspeedCarveSlashVisual.DisplayName: Nanoblack Light-speed Carve Visuals LemonNadeHoldout.DisplayName: Lemon 'nade LemonNadeProjectile.DisplayName: Lemon 'nade +SpadefishHoldout.DisplayName: Spinfish +SpadefishThrown.DisplayName: Spadefish