diff --git a/Content/NPCs/LivingMagma.cs b/Content/NPCs/LivingMagma.cs index 141da44..742645d 100644 --- a/Content/NPCs/LivingMagma.cs +++ b/Content/NPCs/LivingMagma.cs @@ -1,14 +1,26 @@ -using Decimation.Content.Buffs.Buffs; -using Decimation.Content.Buffs.Debuffs; +using Decimation.Content.Buffs.Debuffs; +using Decimation.Content.Projectiles; using Decimation.Content.Tiles.ShrineoftheMoltenOne; +using Decimation.Lib.Util; +using Microsoft.Xna.Framework; using Terraria; using Terraria.ID; using Terraria.ModLoader; namespace Decimation.Content.NPCs { - class LivingMagma : ModNPC + internal class LivingMagma : ModNPC { + private static readonly int SpitInterval = 60; + private static readonly int SpitDuration = 240; + + private int SpitCounter { get; set; } + private int SpittingCounter { get; set; } = SpitDuration; + private bool Spitting { get; set; } + private bool HasSpit { get; set; } + + private Vector2 MouthPosition => npc.Center + new Vector2(npc.width / 2f * npc.direction, 0); + public override void SetStaticDefaults() { DisplayName.SetDefault("Living Magma"); @@ -17,7 +29,7 @@ namespace Decimation.Content.NPCs public override void SetDefaults() { - npc.width = 34; + npc.width = 40; npc.height = 28; npc.aiStyle = 1; npc.damage = 50; @@ -34,7 +46,6 @@ namespace Decimation.Content.NPCs npc.knockBackResist = 0.8f; aiType = NPCID.ToxicSludge; animationType = NPCID.ToxicSludge; - npc.lavaImmune = true; npc.buffImmune[BuffID.OnFire] = true; npc.buffImmune[BuffID.Burning] = true; @@ -42,8 +53,36 @@ namespace Decimation.Content.NPCs public override void AI() { - Dust.NewDust(npc.position, npc.width, npc.height, DustID.Fire); - base.AI(); + if (npc.velocity.Length() > 0) HasSpit = false; + if (SpitCounter >= SpitInterval && !HasSpit && Main.expertMode && npc.velocity.Length() == 0f && + Main.rand.NextBool(5)) Spitting = true; + + if (Spitting) + { + if (SpittingCounter == 60) + { + Projectile.NewProjectile(MouthPosition, new Vector2(8 * npc.direction, -2), + ModContent.ProjectileType(), + 45, 4); + Main.PlaySound(SoundID.NPCDeath13, MouthPosition); + + HasSpit = true; + } + + if (SpittingCounter-- < 0) + { + Spitting = false; + SpittingCounter = SpitDuration; + } + } + else + { + base.AI(); + } + + if (SpitCounter++ > SpitInterval) SpitCounter = 0; + + Lighting.AddLight(npc.Center, LightingUtils.Rgb255ToRgb1(255, 155, 48)); } public override void HitEffect(int hitDirection, double damage) @@ -53,27 +92,39 @@ namespace Decimation.Content.NPCs public override float SpawnChance(NPCSpawnInfo spawnInfo) { - int x = (int)Main.LocalPlayer.position.X / 16; - int y = (int)Main.LocalPlayer.position.Y / 16; + if (!Main.hardMode) return 0; + + int x = (int) Main.LocalPlayer.position.X / 16; + int y = (int) Main.LocalPlayer.position.Y / 16; int validBlockCount = 0; for (int i = -50 + x; i <= 50 + x; i++) - { - for (int j = -50 + y; j <= 50 + y; j++) - { - if (i >= 0 && i <= Main.maxTilesX && j >= 0 && j <= Main.maxTilesY) - { - if (Main.tile[i, j].type == ModContent.TileType() || (Main.tile[i, j].type == ModContent.TileType() || Main.tile[i, j].type == ModContent.TileType() || Main.tile[i, j].type == ModContent.TileType()) || Main.tile[i, j].type == ModContent.TileType()) - { - validBlockCount++; - } - } - } - } + for (int j = -50 + y; j <= 50 + y; j++) + if (i >= 0 && i <= Main.maxTilesX && j >= 0 && j <= Main.maxTilesY) + if (Main.tile[i, j].type == ModContent.TileType() || + Main.tile[i, j].type == ModContent.TileType() || + Main.tile[i, j].type == ModContent.TileType() || + Main.tile[i, j].type == ModContent.TileType() || + Main.tile[i, j].type == ModContent.TileType()) + validBlockCount++; - if (validBlockCount >= 15 && Main.hardMode) + if (validBlockCount >= 15) return SpawnCondition.Underworld.Chance * 2; return 0; } + + public override bool CheckDead() + { + bool dead = base.CheckDead(); + + if (dead) + { + int tinySlimeAmount = Main.rand.Next(2, 4); + for (int i = 0; i < tinySlimeAmount; i++) + NPC.NewNPC((int) npc.Center.X, (int) npc.Center.Y, ModContent.NPCType()); + } + + return dead; + } } -} +} \ No newline at end of file diff --git a/Content/NPCs/LivingMagma.png b/Content/NPCs/LivingMagma.png index 507f704..4058192 100644 Binary files a/Content/NPCs/LivingMagma.png and b/Content/NPCs/LivingMagma.png differ diff --git a/Content/NPCs/TinyLivingMagma.cs b/Content/NPCs/TinyLivingMagma.cs new file mode 100644 index 0000000..d89f2b1 --- /dev/null +++ b/Content/NPCs/TinyLivingMagma.cs @@ -0,0 +1,40 @@ +using Decimation.Content.Buffs.Debuffs; +using Decimation.Lib.Util; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace Decimation.Content.NPCs +{ + public class TinyLivingMagma : ModNPC + { + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Tiny Living Magma"); + Main.npcFrameCount[npc.type] = 3; + } + + public override void SetDefaults() + { + npc.CloneDefaults(ModContent.NPCType()); + npc.width = 30; + npc.height = 24; + npc.damage = 36; + npc.defense = 14; + npc.lifeMax = 240; + aiType = NPCID.ToxicSludge; + animationType = NPCID.ToxicSludge; + } + + public override void HitEffect(int hitDirection, double damage) + { + Main.LocalPlayer.AddBuff(ModContent.BuffType(), 600); + } + + public override void AI() + { + Lighting.AddLight(npc.Center, LightingUtils.Rgb255ToRgb1(255, 155, 48)); + } + } +} \ No newline at end of file diff --git a/Content/NPCs/TinyLivingMagma.png b/Content/NPCs/TinyLivingMagma.png new file mode 100644 index 0000000..7131fc2 Binary files /dev/null and b/Content/NPCs/TinyLivingMagma.png differ diff --git a/Content/Projectiles/MagmaBall.cs b/Content/Projectiles/MagmaBall.cs new file mode 100644 index 0000000..ee7f1c0 --- /dev/null +++ b/Content/Projectiles/MagmaBall.cs @@ -0,0 +1,71 @@ +using System; +using Decimation.Content.Buffs.Debuffs; +using Decimation.Lib.Util; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace Decimation.Content.Projectiles +{ + public class MagmaBall : DecimationProjectile + { + private bool HitPlayer + { + get => projectile.ai[0] == 1f; + set => projectile.ai[0] = value ? 1 : 0; + } + + protected override void Init() + { + projectile.width = 22; + projectile.height = 20; + projectile.aiStyle = -1; + projectile.hostile = true; + projectile.penetrate = 1; + } + + public override void AI() + { + Lighting.AddLight(projectile.Center, LightingUtils.Rgb255ToRgb1(255, 155, 48)); + Dust.NewDust(projectile.position, projectile.width, projectile.height, DustID.LavaMoss); + + projectile.velocity.Y += 1 / 4f; + } + + public override void OnHitPlayer(Player target, int damage, bool crit) + { + int dustAmount = 16; + for (int i = 0; i < dustAmount; i++) + { + Dust.NewDust(target.position, target.width, target.height, DustID.Fire, 0, + 0, 0, default, projectile.scale * 3f); + } + + target.AddBuff(ModContent.BuffType(), 300); + + HitPlayer = true; + projectile.Kill(); + } + + public override void Kill(int timeLeft) + { + if (HitPlayer) return; + + int dustAmount = 4; + for (int i = 0; i < dustAmount; i++) + { + Vector2 velocity = Vector2.One.RotatedBy(Math.PI * (2f / dustAmount)); + Dust.NewDust(projectile.position, projectile.width, projectile.height, DustID.Fire, velocity.X, + velocity.Y, 0, default, projectile.scale * 3f); + } + + Tile currentTile = Framing.GetTileSafely((int) Math.Floor(projectile.position.X / 16f), + (int) Math.Ceiling(projectile.position.Y / 16f)); + currentTile.liquid = 1; + currentTile.lava(true); + + Main.PlaySound(SoundID.NPCDeath19, projectile.Center); + } + } +} \ No newline at end of file diff --git a/Content/Projectiles/MagmaBall.png b/Content/Projectiles/MagmaBall.png new file mode 100644 index 0000000..5fd08d9 Binary files /dev/null and b/Content/Projectiles/MagmaBall.png differ diff --git a/Lib/Util/LightingUtils.cs b/Lib/Util/LightingUtils.cs new file mode 100644 index 0000000..106b62d --- /dev/null +++ b/Lib/Util/LightingUtils.cs @@ -0,0 +1,12 @@ +using Microsoft.Xna.Framework; + +namespace Decimation.Lib.Util +{ + public class LightingUtils + { + public static Vector3 Rgb255ToRgb1(int r, int g, int b) + { + return new Vector3(r / 255f, g / 255f, b / 255f); + } + } +} \ No newline at end of file