130 lines
4.4 KiB
C#
130 lines
4.4 KiB
C#
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
|
|
{
|
|
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");
|
|
Main.npcFrameCount[npc.type] = 3;
|
|
}
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
npc.width = 40;
|
|
npc.height = 28;
|
|
npc.aiStyle = 1;
|
|
npc.damage = 50;
|
|
npc.defense = 18;
|
|
npc.lifeMax = 630;
|
|
npc.HitSound = SoundID.NPCHit1;
|
|
npc.DeathSound = SoundID.NPCDeath1;
|
|
npc.alpha = 55;
|
|
npc.value = 400f;
|
|
npc.scale = 1.1f;
|
|
npc.buffImmune[24] = true;
|
|
npc.buffImmune[74] = true;
|
|
npc.lavaImmune = true;
|
|
npc.knockBackResist = 0.8f;
|
|
aiType = NPCID.ToxicSludge;
|
|
animationType = NPCID.ToxicSludge;
|
|
npc.lavaImmune = true;
|
|
npc.buffImmune[BuffID.OnFire] = true;
|
|
npc.buffImmune[BuffID.Burning] = true;
|
|
}
|
|
|
|
public override void 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<MagmaBall>(),
|
|
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)
|
|
{
|
|
Main.LocalPlayer.AddBuff(ModContent.BuffType<Singed>(), 600);
|
|
}
|
|
|
|
public override float SpawnChance(NPCSpawnInfo spawnInfo)
|
|
{
|
|
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<ShrineBrick>() ||
|
|
Main.tile[i, j].type == ModContent.TileType<LockedShrineDoor>() ||
|
|
Main.tile[i, j].type == ModContent.TileType<ShrineDoorClosed>() ||
|
|
Main.tile[i, j].type == ModContent.TileType<ShrineDoorOpened>() ||
|
|
Main.tile[i, j].type == ModContent.TileType<RedHotSpike>())
|
|
validBlockCount++;
|
|
|
|
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<TinyLivingMagma>());
|
|
}
|
|
|
|
return dead;
|
|
}
|
|
}
|
|
} |