diff --git a/Buffs/Summon/KingofConstellationsBuff.cs b/Buffs/Summon/KingofConstellationsBuff.cs new file mode 100644 index 0000000000..bb837dd790 --- /dev/null +++ b/Buffs/Summon/KingofConstellationsBuff.cs @@ -0,0 +1,35 @@ +using CalamityMod.CalPlayer; +using CalamityMod.Projectiles.Summon; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Buffs.Summon +{ + public class KingofConstellationsBuff : ModBuff + { + public override void SetStaticDefaults() + { + Main.buffNoTimeDisplay[Type] = true; + Main.buffNoSave[Type] = true; + } + + public override void Update(Player player, ref int buffIndex) + { + CalamityPlayer modPlayer = player.Calamity(); + if (player.ownedProjectileCounts[ModContent.ProjectileType()] > 0 || player.ownedProjectileCounts[ModContent.ProjectileType()] > 0) + { + modPlayer.celestialDragons = true; + } + if (!modPlayer.celestialDragons) + { + player.DelBuff(buffIndex); + buffIndex--; + } + else + { + player.buffTime[buffIndex] = 18000; + } + } + } +} diff --git a/Buffs/Summon/KingofConstellationsBuff.png b/Buffs/Summon/KingofConstellationsBuff.png new file mode 100644 index 0000000000..2cfd99f961 Binary files /dev/null and b/Buffs/Summon/KingofConstellationsBuff.png differ diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index be4dd39b27..b0c8396301 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -971,6 +971,7 @@ namespace CalamityMod.CalPlayer public bool perditionBeacon = false; public bool MoonFist = false; public bool AresCannons = false; + public bool celestialDragons = false; public List PendingProjectilesToRespawn = new List(); @@ -2001,6 +2002,7 @@ namespace CalamityMod.CalPlayer perditionBeacon = false; MoonFist = false; AresCannons = false; + celestialDragons = false; disableVoodooSpawns = false; disablePerfCystSpawns = false; diff --git a/Items/Weapons/Summon/KingofConstellationsTenryu.cs b/Items/Weapons/Summon/KingofConstellationsTenryu.cs new file mode 100644 index 0000000000..744530806a --- /dev/null +++ b/Items/Weapons/Summon/KingofConstellationsTenryu.cs @@ -0,0 +1,108 @@ +using Terraria.DataStructures; +using CalamityMod.Buffs.Summon; +using CalamityMod.Items.Materials; +using CalamityMod.Rarities; +using CalamityMod.Projectiles.Summon; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Weapons.Summon +{ + public class KingofConstellationsTenryu : ModItem, ILocalizedModType + { + public string LocalizationCategory => "Items.Weapons.Summon"; + + public override void SetDefaults() + { + Item.mana = 10; + Item.damage = 213; + Item.useStyle = ItemUseStyleID.HoldUp; + Item.shootSpeed = 10f; + Item.shoot = ModContent.ProjectileType(); + Item.width = 44; + Item.height = 62; + Item.UseSound = NPCs.Yharon.Yharon.HitSound; + Item.useAnimation = Item.useTime = 25; + + Item.value = CalamityGlobalItem.Rarity14BuyPrice; + Item.rare = ModContent.RarityType(); + Item.Calamity().donorItem = true; + + Item.noMelee = true; + Item.knockBack = 2f; + Item.DamageType = DamageClass.Summon; + Item.autoReuse = true; + } + + public override bool CanUseItem(Player player) => player.ownedProjectileCounts[Item.shoot] <= 0 && player.maxMinions >= 4; + + public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) + { + Vector2 spawnPos = new Vector2(player.position.X + 200, player.position.Y - 200); + Vector2 spawnPos2 = new Vector2(player.position.X - 200, player.position.Y - 200); + SpawnDragon(ModContent.ProjectileType(), ModContent.ProjectileType(), ModContent.ProjectileType(), spawnPos2, player, source, damage, knockback); + SpawnDragon(ModContent.ProjectileType(), ModContent.ProjectileType(), ModContent.ProjectileType(), spawnPos, player, source, damage, knockback); + return false; + } + + public static void SpawnDragon(int head, int body, int tail, Vector2 spawnPos, Player player, EntitySource_ItemUse_WithAmmo source, int damage, float knockback) + { + bool Exists = false; + int tailID = 0; + foreach (var projectile in Main.projectile) + { + if (projectile.type == head && projectile.owner == player.whoAmI && projectile.active) + { + Exists = true; + } + + if (projectile.type == tail && projectile.owner == player.whoAmI && projectile.active) + { + tailID = projectile.whoAmI; + } + } + float foundSlotsCount = 0f; + for (int i = 0; i < Main.maxProjectiles; i++) + { + Projectile p = Main.projectile[i]; + if (p.active && p.minion && p.owner == player.whoAmI) + { + foundSlotsCount += p.minionSlots; + } + } + if (Exists) + { + if (!(foundSlotsCount + 0.5f > (float)player.maxMinions)) + { + //Projectile.NewProjectile(source, Main.projectile[tailID].Center, Vector2.Zero, body, damage, knockback, player.whoAmI); + } + } + else + { + if (!(foundSlotsCount + 1f > (float)player.maxMinions)) + { + Projectile.NewProjectile(source, spawnPos, player.DirectionTo(Main.MouseWorld) * 3, head, damage, knockback, player.whoAmI); + Projectile.NewProjectile(source, spawnPos, Vector2.Zero * 3, tail, damage, knockback, player.whoAmI); + for (var i = 0; i < 20; i++) + { + Projectile.NewProjectile(source, spawnPos, Vector2.Zero * 3, body, damage, knockback, player.whoAmI); + } + } + } + } + + public override void AddRecipes() + { + CreateRecipe(). + AddIngredient(ItemID.StardustDragonStaff). + AddIngredient(ItemID.LightShard). + AddIngredient(ItemID.DarkShard). + AddIngredient(ModContent.ItemType(), 7). + AddTile(TileID.LunarCraftingStation). + Register(); + } + } +} + diff --git a/Items/Weapons/Summon/KingofConstellationsTenryu.png b/Items/Weapons/Summon/KingofConstellationsTenryu.png new file mode 100644 index 0000000000..a6dbe8424d Binary files /dev/null and b/Items/Weapons/Summon/KingofConstellationsTenryu.png differ diff --git a/Localization/en-US/Mods.CalamityMod.Buffs.hjson b/Localization/en-US/Mods.CalamityMod.Buffs.hjson index 32ec24c6a9..ca2c699258 100644 --- a/Localization/en-US/Mods.CalamityMod.Buffs.hjson +++ b/Localization/en-US/Mods.CalamityMod.Buffs.hjson @@ -1217,6 +1217,11 @@ IgneousExaltationBuff: { Description: A blade is orbiting you } +KingofConstellationsBuff: { + DisplayName: Celestial Dragons + Description: The celestial dragons will protect you +} + LilPlaguebringerBuff: { DisplayName: Lil' Plaguebringer Description: The Plaguebringer will protect you diff --git a/Localization/en-US/Mods.CalamityMod.Items.Weapons.Summon.hjson b/Localization/en-US/Mods.CalamityMod.Items.Weapons.Summon.hjson index 62efd3668d..5ce50790c2 100644 --- a/Localization/en-US/Mods.CalamityMod.Items.Weapons.Summon.hjson +++ b/Localization/en-US/Mods.CalamityMod.Items.Weapons.Summon.hjson @@ -449,6 +449,15 @@ InfectedRemote: { ''' } +KingofConstellationsTenryu: { + DisplayName: King of Constellations, Tenryū + Tooltip: + ''' + Uses 4 minion slots to summon a pair of celestial dragons to fight for you + 'The ones who will devour the Unmoving Star' + ''' +} + Metastasis: { DisplayName: Metastasis Tooltip: diff --git a/Localization/en-US/Mods.CalamityMod.Projectiles.Summon.hjson b/Localization/en-US/Mods.CalamityMod.Projectiles.Summon.hjson index 54b20c22dc..5781200a58 100644 --- a/Localization/en-US/Mods.CalamityMod.Projectiles.Summon.hjson +++ b/Localization/en-US/Mods.CalamityMod.Projectiles.Summon.hjson @@ -27,6 +27,9 @@ BabyBloodCrawler.DisplayName: Baby Blood Crawler BabyPlaguebringer.DisplayName: Baby Plaguebringer BelladonnaPetal.DisplayName: Belladonna Petal BelladonnaSpirit.DisplayName: Belladonna Spirit +BlackDragonBody.DisplayName: Black Celestial Dragon +BlackDragonHead.DisplayName: Black Celestial Dragon +BlackDragonTail.DisplayName: Black Celestial Dragon BlackHawkBullet.DisplayName: Black Hawk Bullet BlackHawkSummon.DisplayName: Black Hawk BloodBreath.DisplayName: Fire @@ -284,6 +287,9 @@ VolcanicFireballSummon.DisplayName: Volcanic Fireball WaterElementalMinion.DisplayName: Anahita WaterElementalSong.DisplayName: Siren Song WaterSpearFriendly.DisplayName: Spear +WhiteDragonBody.DisplayName: White Celestial Dragon +WhiteDragonHead.DisplayName: White Celestial Dragon +WhiteDragonTail.DisplayName: White Celestial Dragon WitherBlossom.DisplayName: Wither Blossom WitherBolt.DisplayName: Wither Bolt WulfrumDroid.DisplayName: Wulfrum Droid diff --git a/ModSupport/WeakReferenceSupport.cs b/ModSupport/WeakReferenceSupport.cs index 9cc33e6384..e185505d62 100644 --- a/ModSupport/WeakReferenceSupport.cs +++ b/ModSupport/WeakReferenceSupport.cs @@ -1175,6 +1175,7 @@ namespace CalamityMod sAssociation.Call("AddMinionInfo", ItemType(), BuffType(), new List() { ProjectileType(), ProjectileType(), ProjectileType()}, new List() {1-(1f/3f), 2f/3f, 2f/3f}); //Entropy's Vigil is a bruh moment sAssociation.Call("AddMinionInfo", ItemType(), BuffType(), new List() { ProjectileType(), ProjectileType()}); + sAssociation.Call("AddMinionInfo", ItemType(), BuffType(), new List() { ProjectileType(), ProjectileType() }); } } } diff --git a/Projectiles/Summon/BlackDragonBody.cs b/Projectiles/Summon/BlackDragonBody.cs new file mode 100644 index 0000000000..e20652e28a --- /dev/null +++ b/Projectiles/Summon/BlackDragonBody.cs @@ -0,0 +1,123 @@ +using CalamityMod.Buffs.Summon; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.DataStructures; +using Terraria.ID; +using Terraria.ModLoader; +namespace CalamityMod.Projectiles.Summon +{ + public class BlackDragonBody : ModProjectile, ILocalizedModType + { + public string LocalizationCategory => "Projectiles.Summon"; + public int segmentIndex = 1; + + public override void SetStaticDefaults() + { + ProjectileID.Sets.MinionSacrificable[Type] = false; + ProjectileID.Sets.MinionTargettingFeature[Type] = true; + } + + public override void SetDefaults() + { + Projectile.timeLeft = 10; + Projectile.width = 26; + Projectile.height = 26; + Projectile.friendly = true; + Projectile.penetrate = -1; + Projectile.timeLeft = 180; + Projectile.idStaticNPCHitCooldown = 4; + Projectile.usesIDStaticNPCImmunity = true; + Projectile.tileCollide = false; + Projectile.extraUpdates = 0; + Projectile.aiStyle = -1; + Projectile.DamageType = DamageClass.Summon; + Projectile.netImportant = true; + + } + + public override void OnSpawn(IEntitySource source) + { + foreach (var projectile in Main.projectile) + { + if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner && projectile.active) + { + segmentIndex = projectile.ModProjectile().segmentIndex; + projectile.ModProjectile().segmentIndex++; + } + } + } + + public override void AI() + { + Player player = Main.player[Projectile.owner]; + if (player.Calamity().celestialDragons) + { + Projectile.timeLeft = 2; + } + } + + internal void SegmentMove() + { + Player player = Main.player[Projectile.owner]; + var live = false; + Projectile nextSegment = new Projectile(); + BlackDragonHead head = new BlackDragonHead(); + for (int i = 0; i < Main.maxProjectiles; i++) + { + var projectile = Main.projectile[i]; + if (projectile.type == Type && projectile.owner == Projectile.owner && projectile.active) + { + if (projectile.ModProjectile().segmentIndex == segmentIndex - 1) + { + live = true; + nextSegment = projectile; + } + } + if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner && projectile.active) + { + if (segmentIndex == 1) + { + live = true; + nextSegment = projectile; + } + head = projectile.ModProjectile(); + } + } + if (!live) Projectile.Kill(); + Vector2 destinationOffset = nextSegment.Center+nextSegment.velocity - Projectile.Center; + if (nextSegment.rotation != Projectile.rotation) + { + float angle = MathHelper.WrapAngle(nextSegment.rotation - Projectile.rotation); + //destinationOffset = Projectile.Center.DirectionTo(nextSegment.Center); + destinationOffset = destinationOffset.RotatedBy(angle * 0.1f); + } + Projectile.rotation = destinationOffset.ToRotation(); + if (destinationOffset != Vector2.Zero) + { + Projectile.Center = nextSegment.Center+nextSegment.velocity - destinationOffset.SafeNormalize(Vector2.Zero) * 20f; + } + } + + public override bool PreDraw(ref Color lightColor) + { + return false; + } + + public override void Kill(int timeLeft) + { + if (Main.player[Projectile.owner].ownedProjectileCounts[ModContent.ProjectileType()] > 0) + { + for (int i = 0; i < Main.maxProjectiles; i++) + { + var projectile = Main.projectile[i]; + if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner && projectile.active) + { + projectile.Kill(); + } + } + } + } + + public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) => target.AddBuff(BuffID.ShadowFlame, 300); + } +} diff --git a/Projectiles/Summon/BlackDragonBody.png b/Projectiles/Summon/BlackDragonBody.png new file mode 100644 index 0000000000..abe048cbcb Binary files /dev/null and b/Projectiles/Summon/BlackDragonBody.png differ diff --git a/Projectiles/Summon/BlackDragonBody2.png b/Projectiles/Summon/BlackDragonBody2.png new file mode 100644 index 0000000000..cc2564f292 Binary files /dev/null and b/Projectiles/Summon/BlackDragonBody2.png differ diff --git a/Projectiles/Summon/BlackDragonHead.cs b/Projectiles/Summon/BlackDragonHead.cs new file mode 100644 index 0000000000..c606bb2dcc --- /dev/null +++ b/Projectiles/Summon/BlackDragonHead.cs @@ -0,0 +1,151 @@ +using CalamityMod.Buffs.Summon; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; +using System; +using System.Collections.Generic; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + // HUGE credit to Dozezoze for lending his worm projectile code + public class BlackDragonHead : ModProjectile, ILocalizedModType + { + public string LocalizationCategory => "Projectiles.Summon"; + Dictionary segments = new Dictionary(); + public override void SetStaticDefaults() + { + ProjectileID.Sets.MinionSacrificable[Type] = true; + ProjectileID.Sets.MinionTargettingFeature[Type] = true; + } + + public override void SetDefaults() + { + Projectile.timeLeft = 10; + Projectile.width = 26; + Projectile.height = 26; + Projectile.friendly = true; + Projectile.penetrate = -1; + Projectile.timeLeft = 180; + Projectile.localNPCHitCooldown = 30; + Projectile.usesLocalNPCImmunity = true; + Projectile.tileCollide = false; + Projectile.extraUpdates = 0; + Projectile.aiStyle = -1; + Projectile.DamageType = DamageClass.Summon; + Projectile.netImportant = true; + Projectile.minionSlots = 2; + + ProjectileID.Sets.TrailingMode[Projectile.type] = 2; + ProjectileID.Sets.TrailCacheLength[Projectile.type] = 100; + } + + public override void AI() + { + Player player = Main.player[Projectile.owner]; + player.AddBuff(ModContent.BuffType(), 1); + if (Projectile.type == ModContent.ProjectileType()) + { + if (player.dead) + { + player.Calamity().celestialDragons = false; + } + if (player.Calamity().celestialDragons) + { + Projectile.timeLeft = 2; + } + } + + Projectile.ChargingMinionAI(2000f, 2500f, 3200f, 300f, 0, 45f, 36f, 8f, new Vector2(0f, -60f), 12f, 12f, true, true, 1); + Projectile.rotation = Projectile.velocity.ToRotation(); + segments.Clear(); + foreach (var projectile in Main.projectile) + { + if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner && projectile.active && !segments.ContainsKey(projectile.ModProjectile().segmentIndex)) + { + segments.Add(projectile.ModProjectile().segmentIndex, projectile); + } + if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner && projectile.active && !segments.ContainsKey(projectile.ModProjectile().segmentIndex)) + { + segments.Add(projectile.ModProjectile().segmentIndex, projectile); + } + } + for (var i = 1; i <= segments.Count; i++) + { + if (i < segments.Count) + { + if (segments.ContainsKey(i)) + segments[i].ModProjectile().SegmentMove(); + } + else + { + if (segments.ContainsKey(i)) + segments[i].ModProjectile().SegmentMove(); + } + } + // Fly away from the white dragon + float pushForce = 0.1f; + for (int k = 0; k < Main.maxProjectiles; k++) + { + Projectile otherProj = Main.projectile[k]; + // Short circuits to make the loop as fast as possible + if (!otherProj.active || k == Projectile.whoAmI) + continue; + + // If the other projectile is indeed the same owned by the same player and they're too close, nudge them away. + bool sameProjType = otherProj.type == ModContent.ProjectileType(); + float taxicabDist = Vector2.Distance(Projectile.Center, otherProj.Center); + float distancegate = 80f; + if (sameProjType && taxicabDist < distancegate) + { + if (Projectile.position.X < otherProj.position.X) + Projectile.velocity.X -= pushForce; + else + Projectile.velocity.X += pushForce; + + if (Projectile.position.Y < otherProj.position.Y) + Projectile.velocity.Y -= pushForce; + else + Projectile.velocity.Y += pushForce; + } + } + } + + public override bool PreDraw(ref Color lightColor) + { + lightColor = Color.White; + Texture2D tex = ModContent.Request(Texture).Value; + Texture2D texBody = ModContent.Request("CalamityMod/Projectiles/Summon/BlackDragonBody").Value; + Texture2D texBody2 = ModContent.Request("CalamityMod/Projectiles/Summon/BlackDragonBody2").Value; + Texture2D texTail = ModContent.Request("CalamityMod/Projectiles/Summon/BlackDragonTail").Value; + Texture2D texTail2 = ModContent.Request("CalamityMod/Projectiles/Summon/BlackDragonTail2").Value; + for (var i = segments.Count; i > 0; i--) + { + if (segments.ContainsKey(i)) + { + SpriteEffects fx = Math.Abs(segments[i].rotation) > MathHelper.PiOver2 ? SpriteEffects.FlipHorizontally : SpriteEffects.None; + if (i < segments.Count - 1) + { + Main.EntitySpriteDraw((i == 5 || i == 16) ? texBody2 : texBody, segments[i].Center - Main.screenPosition, null, segments[i].GetAlpha(lightColor), segments[i].rotation + MathHelper.Pi / 2f, texBody.Size() / 2f, segments[i].scale, fx, 0); + } + else if (i < segments.Count) + { + Main.EntitySpriteDraw(texTail, segments[i].Center - Main.screenPosition, null, segments[i].GetAlpha(lightColor), segments[i].rotation + MathHelper.Pi / 2f, texBody.Size() / 2f, segments[i].scale, fx, 0); + } + else + { + Main.EntitySpriteDraw(texTail2, segments[i].Center - Main.screenPosition - new Vector2(10, 0).RotatedBy(segments[i].rotation), null, segments[i].GetAlpha(lightColor), segments[i].rotation + MathHelper.Pi / 2f, texTail.Size() / 2f, segments[i].scale, fx, 0); + + } + } + } + Main.EntitySpriteDraw(tex, Projectile.Center - Main.screenPosition, null, Projectile.GetAlpha(lightColor), Projectile.rotation + MathHelper.Pi / 2f, tex.Size() / 2f, Projectile.scale, Projectile.velocity.X > 0 ? SpriteEffects.None : SpriteEffects.FlipHorizontally, 0); + return false; + + } + + public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) => target.AddBuff(BuffID.ShadowFlame, 300); + } +} diff --git a/Projectiles/Summon/BlackDragonHead.png b/Projectiles/Summon/BlackDragonHead.png new file mode 100644 index 0000000000..92c3679f44 Binary files /dev/null and b/Projectiles/Summon/BlackDragonHead.png differ diff --git a/Projectiles/Summon/BlackDragonTail.cs b/Projectiles/Summon/BlackDragonTail.cs new file mode 100644 index 0000000000..53714189fc --- /dev/null +++ b/Projectiles/Summon/BlackDragonTail.cs @@ -0,0 +1,111 @@ +using CalamityMod.Buffs.Summon; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.DataStructures; +using Terraria.ID; +using Terraria.ModLoader; +namespace CalamityMod.Projectiles.Summon +{ + public class BlackDragonTail : ModProjectile, ILocalizedModType + { + public string LocalizationCategory => "Projectiles.Summon"; + public int segmentIndex = 1; + + public override void SetStaticDefaults() + { + ProjectileID.Sets.MinionSacrificable[Type] = false; + ProjectileID.Sets.MinionTargettingFeature[Type] = true; + } + + public override void SetDefaults() + { + Projectile.timeLeft = 10; + Projectile.width = 26; + Projectile.height = 26; + Projectile.friendly = true; + Projectile.penetrate = -1; + Projectile.timeLeft = 180; + Projectile.localNPCHitCooldown = 30; + Projectile.usesLocalNPCImmunity = true; + Projectile.tileCollide = false; + Projectile.extraUpdates = 0; + Projectile.aiStyle = -1; + Projectile.DamageType = DamageClass.Summon; + Projectile.netImportant = true; + + } + public override void AI() + { + Player player = Main.player[Projectile.owner]; + if (player.Calamity().celestialDragons) + { + Projectile.timeLeft = 2; + } + } + internal void SegmentMove() + { + Player player = Main.player[Projectile.owner]; + var live = false; + Projectile nextSegment = new Projectile(); + BlackDragonHead head = new BlackDragonHead(); + + for (int i = 0; i < Main.maxProjectiles; i++) + { + var projectile = Main.projectile[i]; + if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner && projectile.active) + { + if (projectile.ModProjectile().segmentIndex == segmentIndex - 1) + { + live = true; + nextSegment = projectile; + } + } + if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner && projectile.active) + { + if (segmentIndex == 1) + { + live = true; + nextSegment = projectile; + } + head = projectile.ModProjectile(); + } + } + if (!live) Projectile.Kill(); + Vector2 destinationOffset = nextSegment.Center - Projectile.Center; + if (nextSegment.rotation != Projectile.rotation) + { + float angle = MathHelper.WrapAngle(nextSegment.rotation - Projectile.rotation); + //destinationOffset = Projectile.Center.DirectionTo(nextSegment.Center); + destinationOffset = destinationOffset.RotatedBy(angle * 0.1f); + } + Projectile.rotation = destinationOffset.ToRotation(); + if (destinationOffset != Vector2.Zero) + { + Projectile.Center = nextSegment.Center - destinationOffset.SafeNormalize(Vector2.Zero) * 20f; + } + Projectile.velocity = Vector2.Zero; + } + + public override bool PreDraw(ref Color lightColor) + { + return false; + } + + public override void Kill(int timeLeft) + { + if (Main.player[Projectile.owner].ownedProjectileCounts[ModContent.ProjectileType()] > 0) + { + for (int i = 0; i < Main.maxProjectiles; i++) + { + var projectile = Main.projectile[i]; + if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner && projectile.active) + { + projectile.Kill(); + } + } + } + } + + public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) => target.AddBuff(BuffID.ShadowFlame, 300); + } +} diff --git a/Projectiles/Summon/BlackDragonTail.png b/Projectiles/Summon/BlackDragonTail.png new file mode 100644 index 0000000000..235544b686 Binary files /dev/null and b/Projectiles/Summon/BlackDragonTail.png differ diff --git a/Projectiles/Summon/BlackDragonTail2.png b/Projectiles/Summon/BlackDragonTail2.png new file mode 100644 index 0000000000..00627c3de3 Binary files /dev/null and b/Projectiles/Summon/BlackDragonTail2.png differ diff --git a/Projectiles/Summon/WhiteDragonBody.cs b/Projectiles/Summon/WhiteDragonBody.cs new file mode 100644 index 0000000000..ebf756e4eb --- /dev/null +++ b/Projectiles/Summon/WhiteDragonBody.cs @@ -0,0 +1,120 @@ +using CalamityMod.Buffs.Summon; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.DataStructures; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + public class WhiteDragonBody : ModProjectile, ILocalizedModType + { + public string LocalizationCategory => "Projectiles.Summon"; + public int segmentIndex = 1; + + public override void SetStaticDefaults() + { + Main.projPet[Projectile.type] = true; + } + + public override void SetDefaults() + { + Projectile.timeLeft = 10; + Projectile.width = 26; + Projectile.height = 26; + Projectile.friendly = true; + Projectile.penetrate = -1; + Projectile.timeLeft = 180; + Projectile.idStaticNPCHitCooldown = 4; + Projectile.usesIDStaticNPCImmunity = true; + Projectile.tileCollide = false; + Projectile.extraUpdates = 0; + Projectile.aiStyle = -1; + Projectile.DamageType = DamageClass.Summon; + Projectile.netImportant = true; + } + + public override void OnSpawn(IEntitySource source) + { + foreach (var projectile in Main.projectile) + { + if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner && projectile.active) + { + segmentIndex = projectile.ModProjectile().segmentIndex; + projectile.ModProjectile().segmentIndex++; + } + } + } + public override void AI() + { + Player player = Main.player[Projectile.owner]; + if (player.Calamity().celestialDragons) + { + Projectile.timeLeft = 2; + } + } + + internal void SegmentMove() + { + Player player = Main.player[Projectile.owner]; + var live = false; + Projectile nextSegment = new Projectile(); + WhiteDragonHead head = new WhiteDragonHead(); + for (int i = 0; i < Main.maxProjectiles; i++) + { + var projectile = Main.projectile[i]; + if (projectile.type == Type && projectile.owner == Projectile.owner && projectile.active) + { + if (projectile.ModProjectile().segmentIndex == segmentIndex - 1) + { + live = true; + nextSegment = projectile; + } + } + if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner && projectile.active) + { + if (segmentIndex == 1) + { + live = true; + nextSegment = projectile; + } + head = projectile.ModProjectile(); + } + } + if (!live) Projectile.Kill(); + Vector2 destinationOffset = nextSegment.Center+nextSegment.velocity - Projectile.Center; + if (nextSegment.rotation != Projectile.rotation) + { + float angle = MathHelper.WrapAngle(nextSegment.rotation - Projectile.rotation); + //destinationOffset = Projectile.Center.DirectionTo(nextSegment.Center); + destinationOffset = destinationOffset.RotatedBy(angle * 0.1f); + } + Projectile.rotation = destinationOffset.ToRotation(); + if (destinationOffset != Vector2.Zero) + { + Projectile.Center = nextSegment.Center+nextSegment.velocity - destinationOffset.SafeNormalize(Vector2.Zero) * 20f; + } + } + + public override bool PreDraw(ref Color lightColor) + { + return false; + } + public override void Kill(int timeLeft) + { + if (Main.player[Projectile.owner].ownedProjectileCounts[ModContent.ProjectileType()] > 0) + { + for (int i = 0; i < Main.maxProjectiles; i++) + { + var projectile = Main.projectile[i]; + if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner && projectile.active) + { + projectile.Kill(); + } + } + } + } + + public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) => target.AddBuff(BuffID.Frostburn2, 300); + } +} diff --git a/Projectiles/Summon/WhiteDragonBody.png b/Projectiles/Summon/WhiteDragonBody.png new file mode 100644 index 0000000000..9a77543417 Binary files /dev/null and b/Projectiles/Summon/WhiteDragonBody.png differ diff --git a/Projectiles/Summon/WhiteDragonBody2.png b/Projectiles/Summon/WhiteDragonBody2.png new file mode 100644 index 0000000000..f25f076d0e Binary files /dev/null and b/Projectiles/Summon/WhiteDragonBody2.png differ diff --git a/Projectiles/Summon/WhiteDragonHead.cs b/Projectiles/Summon/WhiteDragonHead.cs new file mode 100644 index 0000000000..573fbc0b5d --- /dev/null +++ b/Projectiles/Summon/WhiteDragonHead.cs @@ -0,0 +1,150 @@ +using CalamityMod.Buffs.Summon; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; +using System; +using System.Collections.Generic; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + // HUGE credit to Dozezoze for lending his worm projectile code + public class WhiteDragonHead : ModProjectile, ILocalizedModType + { + public string LocalizationCategory => "Projectiles.Summon"; + + Dictionary segments = new Dictionary(); + public override void SetStaticDefaults() + { + ProjectileID.Sets.MinionSacrificable[Type] = true; + ProjectileID.Sets.MinionTargettingFeature[Type] = true; + } + + public override void SetDefaults() + { + Projectile.timeLeft = 10; + Projectile.width = 24; + Projectile.height = 24; + Projectile.friendly = true; + Projectile.penetrate = -1; + Projectile.timeLeft = 180; + Projectile.localNPCHitCooldown = 30; + Projectile.usesLocalNPCImmunity = true; + Projectile.tileCollide = false; + Projectile.extraUpdates = 0; + Projectile.aiStyle = -1; + Projectile.DamageType = DamageClass.Summon; + Projectile.netImportant = true; + Projectile.minionSlots = 2; + + ProjectileID.Sets.TrailingMode[Projectile.type] = 2; + ProjectileID.Sets.TrailCacheLength[Projectile.type] = 100; + } + + public override void AI() + { + Player player = Main.player[Projectile.owner]; + player.AddBuff(ModContent.BuffType(), 1); + if (Projectile.type == ModContent.ProjectileType()) + { + if (player.dead) + { + player.Calamity().celestialDragons = false; + } + if (player.Calamity().celestialDragons) + { + Projectile.timeLeft = 2; + } + } + Projectile.ChargingMinionAI(2000f, 2500f, 3200f, 300f, 0, 45f, 36f, 8f, new Vector2(0f, -60f), 12f, 12f, true, true, 1); + Projectile.rotation = Projectile.velocity.ToRotation(); + segments.Clear(); + foreach (var projectile in Main.projectile) + { + if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner && projectile.active && !segments.ContainsKey(projectile.ModProjectile().segmentIndex)) + { + segments.Add(projectile.ModProjectile().segmentIndex, projectile); + } + if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner && projectile.active) + { + segments.Add(projectile.ModProjectile().segmentIndex, projectile); + } + } + for (var i = 1; i <= segments.Count; i++) + { + if (i < segments.Count) + { + if (segments.ContainsKey(i)) + segments[i].ModProjectile().SegmentMove(); + } + else + { + if (segments.ContainsKey(i)) + segments[i].ModProjectile().SegmentMove(); + } + } + // Fly away from the black dragon + float pushForce = 0.1f; + for (int k = 0; k < Main.maxProjectiles; k++) + { + Projectile otherProj = Main.projectile[k]; + // Short circuits to make the loop as fast as possible + if (!otherProj.active || k == Projectile.whoAmI) + continue; + + // If the other projectile is indeed the same owned by the same player and they're too close, nudge them away. + bool sameProjType = otherProj.type == ModContent.ProjectileType(); + float taxicabDist = Vector2.Distance(Projectile.Center, otherProj.Center); + float distancegate = 80f; + if (sameProjType && taxicabDist < distancegate) + { + if (Projectile.position.X < otherProj.position.X) + Projectile.velocity.X -= pushForce; + else + Projectile.velocity.X += pushForce; + + if (Projectile.position.Y < otherProj.position.Y) + Projectile.velocity.Y -= pushForce; + else + Projectile.velocity.Y += pushForce; + } + } + } + + public override bool PreDraw(ref Color lightColor) + { + lightColor = Color.White; + Texture2D tex = ModContent.Request(Texture).Value; + Texture2D texBody = ModContent.Request("CalamityMod/Projectiles/Summon/WhiteDragonBody").Value; + Texture2D texBody2 = ModContent.Request("CalamityMod/Projectiles/Summon/WhiteDragonBody2").Value; + Texture2D texTail = ModContent.Request("CalamityMod/Projectiles/Summon/WhiteDragonTail").Value; + Texture2D texTail2 = ModContent.Request("CalamityMod/Projectiles/Summon/WhiteDragonTail2").Value; + for (var i = segments.Count; i > 0; i--) + { + if (segments.ContainsKey(i)) + { + SpriteEffects fx = Math.Abs(segments[i].rotation) > MathHelper.PiOver2 ? SpriteEffects.FlipHorizontally : SpriteEffects.None; + if (i < segments.Count - 1) + { + Main.EntitySpriteDraw((i == 5 || i == 16) ? texBody2 : texBody, segments[i].Center - Main.screenPosition, null, segments[i].GetAlpha(lightColor), segments[i].rotation + MathHelper.Pi / 2f, texBody.Size() / 2f, segments[i].scale, fx, 0); + } + else if (i < segments.Count) + { + Main.EntitySpriteDraw(texTail, segments[i].Center - Main.screenPosition, null, segments[i].GetAlpha(lightColor), segments[i].rotation + MathHelper.Pi / 2f, texBody.Size() / 2f, segments[i].scale, fx, 0); + } + else + { + Main.EntitySpriteDraw(texTail2, segments[i].Center - Main.screenPosition - new Vector2(10, 0).RotatedBy(segments[i].rotation), null, segments[i].GetAlpha(lightColor), segments[i].rotation + MathHelper.Pi / 2f, texTail.Size() / 2f, segments[i].scale, fx, 0); + + } + } + } + Main.EntitySpriteDraw(tex, Projectile.Center - Main.screenPosition, null, Projectile.GetAlpha(lightColor), Projectile.rotation + MathHelper.Pi / 2f, tex.Size() / 2f, Projectile.scale, Projectile.velocity.X > 0 ? SpriteEffects.None : SpriteEffects.FlipHorizontally, 0); + return false; + } + + public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) => target.AddBuff(BuffID.Frostburn2, 300); + } +} diff --git a/Projectiles/Summon/WhiteDragonHead.png b/Projectiles/Summon/WhiteDragonHead.png new file mode 100644 index 0000000000..d2674d9938 Binary files /dev/null and b/Projectiles/Summon/WhiteDragonHead.png differ diff --git a/Projectiles/Summon/WhiteDragonTail.cs b/Projectiles/Summon/WhiteDragonTail.cs new file mode 100644 index 0000000000..7eef32556b --- /dev/null +++ b/Projectiles/Summon/WhiteDragonTail.cs @@ -0,0 +1,112 @@ +using CalamityMod.Buffs.Summon; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.DataStructures; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + public class WhiteDragonTail : ModProjectile, ILocalizedModType + { + public string LocalizationCategory => "Projectiles.Summon"; + public int segmentIndex = 1; + + public override void SetStaticDefaults() + { + ProjectileID.Sets.MinionSacrificable[Type] = false; + ProjectileID.Sets.MinionTargettingFeature[Type] = true; + } + + public override void SetDefaults() + { + Projectile.timeLeft = 10; + Projectile.width = 26; + Projectile.height = 26; + Projectile.friendly = true; + Projectile.penetrate = -1; + Projectile.timeLeft = 180; + Projectile.localNPCHitCooldown = 30; + Projectile.usesLocalNPCImmunity = true; + Projectile.tileCollide = false; + Projectile.extraUpdates = 0; + Projectile.aiStyle = -1; + Projectile.DamageType = DamageClass.Summon; + Projectile.netImportant = true; + + } + public override void AI() + { + Player player = Main.player[Projectile.owner]; + if (player.Calamity().celestialDragons) + { + Projectile.timeLeft = 2; + } + } + internal void SegmentMove() + { + Player player = Main.player[Projectile.owner]; + var live = false; + Projectile nextSegment = new Projectile(); + WhiteDragonHead head = new WhiteDragonHead(); + + for (int i = 0; i < Main.maxProjectiles; i++) + { + var projectile = Main.projectile[i]; + if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner && projectile.active) + { + if (projectile.ModProjectile().segmentIndex == segmentIndex - 1) + { + live = true; + nextSegment = projectile; + } + } + if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner && projectile.active) + { + if (segmentIndex == 1) + { + live = true; + nextSegment = projectile; + } + head = projectile.ModProjectile(); + } + } + if (!live) Projectile.Kill(); + Vector2 destinationOffset = nextSegment.Center - Projectile.Center; + if (nextSegment.rotation != Projectile.rotation) + { + float angle = MathHelper.WrapAngle(nextSegment.rotation - Projectile.rotation); + //destinationOffset = Projectile.Center.DirectionTo(nextSegment.Center); + destinationOffset = destinationOffset.RotatedBy(angle * 0.1f); + } + Projectile.rotation = destinationOffset.ToRotation(); + if (destinationOffset != Vector2.Zero) + { + Projectile.Center = nextSegment.Center - destinationOffset.SafeNormalize(Vector2.Zero) * 20f; + } + Projectile.velocity = Vector2.Zero; + } + + public override bool PreDraw(ref Color lightColor) + { + return false; + } + + public override void Kill(int timeLeft) + { + if (Main.player[Projectile.owner].ownedProjectileCounts[ModContent.ProjectileType()] > 0) + { + for (int i = 0; i < Main.maxProjectiles; i++) + { + var projectile = Main.projectile[i]; + if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner && projectile.active) + { + projectile.Kill(); + } + } + } + } + + public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) => target.AddBuff(BuffID.Frostburn2, 300); + } +} diff --git a/Projectiles/Summon/WhiteDragonTail.png b/Projectiles/Summon/WhiteDragonTail.png new file mode 100644 index 0000000000..fc63bd23bc Binary files /dev/null and b/Projectiles/Summon/WhiteDragonTail.png differ diff --git a/Projectiles/Summon/WhiteDragonTail2.png b/Projectiles/Summon/WhiteDragonTail2.png new file mode 100644 index 0000000000..3da75d0a27 Binary files /dev/null and b/Projectiles/Summon/WhiteDragonTail2.png differ