diff --git a/Buffs/Pets/DaawnlightSpiritOriginBuff.cs b/Buffs/Pets/DaawnlightSpiritOriginBuff.cs new file mode 100644 index 0000000000..71889ef390 --- /dev/null +++ b/Buffs/Pets/DaawnlightSpiritOriginBuff.cs @@ -0,0 +1,27 @@ +using CalamityMod.Projectiles.Pets; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Buffs.Pets +{ + public class DaawnlightSpiritOriginBuff : ModBuff + { + public override void SetDefaults() + { + DisplayName.SetDefault("Daawnlight"); + Description.SetDefault("Aim"); + Main.buffNoTimeDisplay[Type] = true; + Main.lightPet[Type] = true; + } + + public override void Update(Player player, ref int buffIndex) + { + player.buffTime[buffIndex] = 2; + player.Calamity().spiritOriginPet = true; + bool petProjectileNotSpawned = player.ownedProjectileCounts[ModContent.ProjectileType()] <= 0; + if (petProjectileNotSpawned && player.whoAmI == Main.myPlayer) + Projectile.NewProjectile(player.Center, -Vector2.UnitY * 3f, ModContent.ProjectileType(), 0, 0f, player.whoAmI, 0f, 0f); + } + } +} diff --git a/Buffs/Pets/DaawnlightSpiritOriginBuff.png b/Buffs/Pets/DaawnlightSpiritOriginBuff.png new file mode 100644 index 0000000000..726d2ab0d5 Binary files /dev/null and b/Buffs/Pets/DaawnlightSpiritOriginBuff.png differ diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index 41b7202091..3c8026abe3 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -245,6 +245,7 @@ namespace CalamityMod.CalPlayer public int auralisAurora = 0; public int fungalSymbioteTimer = 0; public int aBulwarkRareTimer = 0; + public int spiritOriginBullseyeShootCountdown = 0; public const int BeltDodgeCooldown = 3600; public const int MirrorDodgeCooldown = 4500; @@ -337,6 +338,7 @@ namespace CalamityMod.CalPlayer public int ladHearts = 0; public bool sparks = false; public bool sirenPet = false; + public bool spiritOriginPet = false; public bool fox = false; public bool chibii = false; public bool brimling = false; @@ -522,6 +524,7 @@ namespace CalamityMod.CalPlayer public bool abyssalAmulet = false; public bool lumenousAmulet = false; public bool aquaticEmblem = false; + public bool spiritOrigin = false; public bool darkSunRing = false; public bool calamityRing = false; public bool voidOfExtinction = false; @@ -1485,6 +1488,7 @@ namespace CalamityMod.CalPlayer ladShark = false; sparks = false; sirenPet = false; + spiritOriginPet = false; fox = false; chibii = false; brimling = false; @@ -1720,6 +1724,7 @@ namespace CalamityMod.CalPlayer abyssalAmulet = false; lumenousAmulet = false; aquaticEmblem = false; + spiritOrigin = false; astralStarRain = false; diff --git a/CalPlayer/CalamityPlayerMiscEffects.cs b/CalPlayer/CalamityPlayerMiscEffects.cs index 75fa58af1d..679e76a141 100644 --- a/CalPlayer/CalamityPlayerMiscEffects.cs +++ b/CalPlayer/CalamityPlayerMiscEffects.cs @@ -135,6 +135,10 @@ namespace CalamityMod.CalPlayer modPlayer.StandardSync(); } } + + // After everything, reset ranged crit if necessary. + if (modPlayer.spiritOrigin) + player.rangedCrit = 4; } #endregion @@ -550,6 +554,31 @@ namespace CalamityMod.CalPlayer modPlayer.resetHeightandWidth = false; } + // Summon bullseyes on nearby targets. + if (player.Calamity().spiritOrigin) + { + int bullseyeType = ModContent.ProjectileType(); + List alreadyTargetedNPCs = new List(); + for (int i = 0; i < Main.maxProjectiles; i++) + { + if (Main.projectile[i].type != bullseyeType || !Main.projectile[i].active || Main.projectile[i].owner != player.whoAmI) + continue; + + alreadyTargetedNPCs.Add((int)Main.projectile[i].ai[0]); + } + + for (int i = 0; i < Main.maxNPCs; i++) + { + if (!Main.npc[i].active || Main.npc[i].friendly || Main.npc[i].lifeMax < 5 || alreadyTargetedNPCs.Contains(i) || Main.npc[i].realLife >= 0 || Main.npc[i].dontTakeDamage || Main.npc[i].immortal) + continue; + + if (Main.myPlayer == player.whoAmI && Main.npc[i].WithinRange(player.Center, 2000f)) + Projectile.NewProjectile(Main.npc[i].Center, Vector2.Zero, bullseyeType, 0, 0f, player.whoAmI, i); + if (player.Calamity().spiritOriginBullseyeShootCountdown <= 0) + player.Calamity().spiritOriginBullseyeShootCountdown = 45; + } + } + // Proficiency level ups if (CalamityConfig.Instance.Proficiency) modPlayer.GetExactLevelUp(); @@ -1131,6 +1160,8 @@ namespace CalamityMod.CalPlayer } // Cooldowns and timers + if (modPlayer.spiritOriginBullseyeShootCountdown > 0) + modPlayer.spiritOriginBullseyeShootCountdown--; if (modPlayer.phantomicHeartRegen > 0 && modPlayer.phantomicHeartRegen < 1000) modPlayer.phantomicHeartRegen--; if (modPlayer.phantomicBulwarkCooldown > 0) diff --git a/ExtraTextures/DaawnlightSpiritOriginBossBullseye.png b/ExtraTextures/DaawnlightSpiritOriginBossBullseye.png new file mode 100644 index 0000000000..11bb3a7383 Binary files /dev/null and b/ExtraTextures/DaawnlightSpiritOriginBossBullseye.png differ diff --git a/ExtraTextures/DaawnlightSpiritOriginRegularBullseye.png b/ExtraTextures/DaawnlightSpiritOriginRegularBullseye.png new file mode 100644 index 0000000000..18e3b76663 Binary files /dev/null and b/ExtraTextures/DaawnlightSpiritOriginRegularBullseye.png differ diff --git a/Items/Accessories/DaawnlightSpiritOrigin.cs b/Items/Accessories/DaawnlightSpiritOrigin.cs new file mode 100644 index 0000000000..584c217302 --- /dev/null +++ b/Items/Accessories/DaawnlightSpiritOrigin.cs @@ -0,0 +1,66 @@ +using CalamityMod.Buffs.Pets; +using CalamityMod.CalPlayer; +using CalamityMod.Items.Materials; +using CalamityMod.Projectiles.Pets; +using CalamityMod.Tiles.Furniture.CraftingStations; +using CalamityMod.World; +using System.Collections.Generic; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Accessories +{ + public class DaawnlightSpiritOrigin : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Daawnlight Spirit Origin"); + Tooltip.SetDefault("Reduces critical strike chance for ranged weapons but significantly boosts their damage on hit\n" + + "The slower a ranged weapon is, the more damage critical strikes will do\n" + + "Causes all nearby enemies to be marked with a bullseye somewhere on their hitbox\n" + + "If a ranged projectile manages to hit the bullseye you do much more damage than usual\n" + + "Once the bullseye is hit it disappears and a new one appears elsewhere on the enemy's hitbox"); + } + + public override void SetDefaults() + { + item.width = 22; + item.height = 38; + item.rare = ItemRarityID.Purple; + item.value = CalamityGlobalItem.RarityDarkBlueBuyPrice; + item.accessory = true; + item.Calamity().customRarity = CalamityRarity.DarkBlue; + item.Calamity().donorItem = true; + } + + public override void UpdateAccessory(Player player, bool hideVisual) + { + player.Calamity().spiritOrigin = true; + + if (hideVisual) + { + if (player.FindBuffIndex(ModContent.BuffType()) != -1) + player.ClearBuff(ModContent.BuffType()); + } + else if (player.whoAmI == Main.myPlayer) + { + if (player.FindBuffIndex(ModContent.BuffType()) == -1) + player.AddBuff(ModContent.BuffType(), 18000, true); + } + } + + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ModContent.ItemType()); + recipe.AddIngredient(ModContent.ItemType(), 3); + recipe.AddIngredient(ModContent.ItemType(), 15); + recipe.AddIngredient(ModContent.ItemType(), 15); + recipe.AddIngredient(ModContent.ItemType(), 4); + recipe.AddTile(ModContent.TileType()); + recipe.SetResult(this); + recipe.AddRecipe(); + } + } +} diff --git a/Items/Accessories/DaawnlightSpiritOrigin.png b/Items/Accessories/DaawnlightSpiritOrigin.png new file mode 100644 index 0000000000..7e24054bbb Binary files /dev/null and b/Items/Accessories/DaawnlightSpiritOrigin.png differ diff --git a/NPCs/CalamityGlobalNPC.cs b/NPCs/CalamityGlobalNPC.cs index a6c2a82564..cfbcc6d50d 100644 --- a/NPCs/CalamityGlobalNPC.cs +++ b/NPCs/CalamityGlobalNPC.cs @@ -64,13 +64,15 @@ using Terraria.Graphics.Effects; using Terraria.ID; using Terraria.ModLoader; using static Terraria.ModLoader.ModContent; +using CalamityMod.DataStructures; namespace CalamityMod.NPCs { public class CalamityGlobalNPC : GlobalNPC { - #region Variables - public float DR { get; set; } = 0f; + #region Variables + + public float DR { get; set; } = 0f; public int KillTime { get; set; } = 0; @@ -2028,6 +2030,7 @@ namespace CalamityMod.NPCs { if (VulnerabilityHexFireDrawer != null) VulnerabilityHexFireDrawer.Update(); + CalamityGlobalTownNPC.SetPatreonTownNPCName(npc, mod); // Decrement each immune timer if it's greater than 0. @@ -3346,6 +3349,53 @@ namespace CalamityMod.NPCs CalamityGlobalTownNPC.MakeTownNPCsTakeMoreDamage(npc, projectile, mod, ref damage); + int bullseyeType = ProjectileType(); + Projectile bullseye = null; + for (int i = 0; i < Main.maxProjectiles; i++) + { + if (Main.projectile[i].type != bullseyeType || !Main.projectile[i].active || Main.projectile[i].owner != player.whoAmI) + continue; + + bullseye = Main.projectile[i]; + break; + } + + // Don't allow large hitbox projectiles or explosions to "snipe" enemies. + if (projectile.ranged && (projectile.width + projectile.height) / 2 <= 25 && projectile.velocity != Vector2.Zero) + { + if (bullseye != null) + { + float baseBullseyeRadius = npc.IsABoss() ? 116f : 54f; + bool hasCollidedWithBullseye; + if (projectile.penetrate <= 1 && projectile.penetrate != -1) + hasCollidedWithBullseye = projectile.WithinRange(bullseye.Center, bullseye.scale * baseBullseyeRadius); + else + { + Vector2 directionToBullseye = projectile.SafeDirectionTo(bullseye.Center, Vector2.UnitY); + Vector2 orthogonalEdgeOffset = Vector2.UnitX.RotatedBy(directionToBullseye.ToRotation() + MathHelper.PiOver2) * baseBullseyeRadius; + Vector2 edgeVector = projectile.Center - bullseye.Center + orthogonalEdgeOffset; + float inaccuracyLimit = directionToBullseye.AngleBetween(edgeVector); + float orthogonalityToIdealDirection = directionToBullseye.AngleBetween(projectile.velocity); + hasCollidedWithBullseye = orthogonalityToIdealDirection < inaccuracyLimit && projectile.WithinRange(bullseye.Center, bullseye.scale * baseBullseyeRadius); + } + + // Do a very high amount of damage if hitting a bullseye. + if (hasCollidedWithBullseye && bullseye.ai[1] == 0f) + { + crit = true; + bullseye.ai[1] = 1f; + bullseye.netUpdate = true; + damage = (int)(damage * 1.85); + } + } + + // TODO - Use the 1.4 spawn context system for this. + // This suffers from the same issues as current crit logic in vanilla, but I have no idea how to do this + // better without said system. + if (modPlayer.spiritOrigin && crit) + damage = (int)(damage * MathHelper.Lerp(1.2f, 1.85f, Utils.InverseLerp(6f, 72f, player.ActiveItem().useTime, true))); + } + if (!projectile.npcProj && !projectile.trap) { if (projectile.ranged && modPlayer.plagueReaper && pFlames > 0) @@ -4590,8 +4640,8 @@ namespace CalamityMod.NPCs } public override void PostDraw(NPC npc, SpriteBatch spriteBatch, Color drawColor) - { - if (CalamityWorld.revenge || BossRushEvent.BossRushActive || CalamityWorld.malice) + { + if (CalamityWorld.revenge || BossRushEvent.BossRushActive || CalamityWorld.malice) { // His afterimages I can't get to work, so fuck it if (npc.type == NPCID.SkeletronPrime) diff --git a/Projectiles/Pets/DaawnlightSpiritOriginMinion.cs b/Projectiles/Pets/DaawnlightSpiritOriginMinion.cs new file mode 100644 index 0000000000..695d6ce68b --- /dev/null +++ b/Projectiles/Pets/DaawnlightSpiritOriginMinion.cs @@ -0,0 +1,87 @@ +using CalamityMod.Buffs.Pets; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Pets +{ + public class DaawnlightSpiritOriginMinion : ModProjectile + { + public Player Owner => Main.player[projectile.owner]; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Daawnlight"); + Main.projFrames[projectile.type] = 12; + Main.projPet[projectile.type] = true; + } + + public override void SetDefaults() + { + projectile.width = 146; + projectile.height = 164; + projectile.netImportant = true; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.timeLeft = 18000; + projectile.tileCollide = false; + } + + public override void AI() + { + if (!Owner.active) + { + projectile.active = false; + return; + } + HandlePetStuff(); + DoMovement(); + HandleFrames(); + } + + public void HandlePetStuff() + { + if (Owner.dead || !Owner.Calamity().spiritOrigin) + Owner.Calamity().spiritOriginPet = false; + if (Owner.Calamity().spiritOriginPet) + projectile.timeLeft = 2; + } + + public void DoMovement() + { + if (projectile.WithinRange(Owner.Center, 100f)) + projectile.velocity *= 0.975f; + else + { + float flySpeed = MathHelper.Clamp(11f + projectile.Distance(Owner.Center) * 0.015f, 11f, 25f); + projectile.velocity = projectile.velocity.MoveTowards(projectile.SafeDirectionTo(Owner.Center) * flySpeed, flySpeed * 0.02f); + if (!projectile.WithinRange(Owner.Center, 2200f)) + { + projectile.Center = Owner.Center; + projectile.velocity = -Vector2.UnitY * 4f; + projectile.netUpdate = true; + } + } + + if (MathHelper.Distance(projectile.Center.X, Owner.Center.X) > 80f) + projectile.spriteDirection = (projectile.Center.X > Owner.Center.X).ToDirectionInt(); + } + + public void HandleFrames() + { + if (Owner.Calamity().spiritOriginBullseyeShootCountdown > 0) + projectile.frame = (int)MathHelper.Lerp(5f, Main.projFrames[projectile.type] - 0.1f, 1f - Owner.Calamity().spiritOriginBullseyeShootCountdown / 45f); + else + { + projectile.frameCounter++; + if (projectile.frameCounter % 7 == 6) + projectile.frame = (projectile.frame + 1) % 5; + } + } + + public override void Kill(int timeLeft) + { + if (Owner.FindBuffIndex(ModContent.BuffType()) != -1) + Owner.ClearBuff(ModContent.BuffType()); + } + } +} diff --git a/Projectiles/Pets/DaawnlightSpiritOriginMinion.png b/Projectiles/Pets/DaawnlightSpiritOriginMinion.png new file mode 100644 index 0000000000..cfbb514f9f Binary files /dev/null and b/Projectiles/Pets/DaawnlightSpiritOriginMinion.png differ diff --git a/Projectiles/Typeless/SpiritOriginBullseye.cs b/Projectiles/Typeless/SpiritOriginBullseye.cs new file mode 100644 index 0000000000..2eadfc9abf --- /dev/null +++ b/Projectiles/Typeless/SpiritOriginBullseye.cs @@ -0,0 +1,94 @@ +using CalamityMod.Tiles.AstralDesert; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.IO; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Typeless +{ + public class SpiritOriginBullseye : ModProjectile + { + public Player Owner => Main.player[projectile.owner]; + public NPC Target => Main.npc[(int)projectile.ai[0]]; + public bool FadingOut + { + get => projectile.ai[1] == 1f; + set => projectile.ai[1] = value.ToInt(); + } + public Vector2 BullseyeOffsetFromCenter; + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + public override void SetDefaults() + { + projectile.width = projectile.height = 2; + projectile.aiStyle = -1; + projectile.friendly = false; + projectile.hostile = false; + projectile.ignoreWater = true; + projectile.tileCollide = false; + projectile.timeLeft = 300; + projectile.Opacity = 0f; + projectile.penetrate = -1; + } + + public override void SendExtraAI(BinaryWriter writer) => writer.WriteVector2(BullseyeOffsetFromCenter); + + public override void ReceiveExtraAI(BinaryReader reader) => BullseyeOffsetFromCenter = reader.ReadVector2(); + + public override void AI() + { + if (!Main.npc.IndexInRange((int)projectile.ai[0]) || !Owner.Calamity().spiritOrigin || !Target.active || Target.life <= 0 || Target.dontTakeDamage) + { + projectile.Kill(); + return; + } + + if (projectile.timeLeft < 45) + FadingOut = true; + + projectile.Opacity = MathHelper.Clamp(projectile.Opacity + (FadingOut ? -0.08f : 0.04f), 0f, 1f); + projectile.scale = projectile.Opacity; + if (FadingOut && projectile.Opacity <= 0f) + projectile.Kill(); + + if (BullseyeOffsetFromCenter == Vector2.Zero) + { + BullseyeOffsetFromCenter = Main.rand.NextVector2CircularEdge(Target.width, Target.height) * Main.rand.NextFloat(0.925f, 1f) * 0.54f; + if (BullseyeOffsetFromCenter.Y > 0f) + BullseyeOffsetFromCenter.Y *= -1f; + projectile.netUpdate = true; + } + else + projectile.Center = Target.Center + BullseyeOffsetFromCenter; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + if (Main.myPlayer != projectile.owner) + return false; + + float scale = 2f - projectile.scale; + float rotation = MathHelper.TwoPi * projectile.scale; + Vector2 drawPosition = Target.Center + BullseyeOffsetFromCenter - Main.screenPosition; + if (FadingOut) + { + scale = projectile.scale; + rotation = 0f; + } + + Texture2D bullseyeTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/DaawnlightSpiritOriginRegularBullseye"); + Rectangle frame = bullseyeTexture.Frame(); + if (Target.IsABoss()) + { + bullseyeTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/DaawnlightSpiritOriginBossBullseye"); + frame = bullseyeTexture.Frame(1, 4, 0, (int)(Main.GlobalTime * 7f) % 4); + rotation = 0f; + } + + spriteBatch.Draw(bullseyeTexture, drawPosition, frame, Color.White * projectile.Opacity, rotation, frame.Size() * 0.5f, scale, SpriteEffects.None, 0f); + return false; + } + } +}