Decimation_Mod/Content/NPCs/CoreSpider.cs

93 lines
3.1 KiB
C#

using System;
using Decimation.Content.Tiles.ShrineoftheMoltenOne;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace Decimation.Content.NPCs
{
// Check line 43861 of NPC.cs
internal class CoreSpider : ModNPC
{
private readonly int shootFrame = 120;
private int _frame;
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Core Spider");
Main.npcFrameCount[npc.type] = 8;
}
public override void SetDefaults()
{
npc.CloneDefaults(NPCID.BlackRecluse);
npc.width = 84;
npc.height = 24;
npc.lifeMax = 750;
animationType = NPCID.BlackRecluse;
npc.lavaImmune = true;
npc.buffImmune[BuffID.OnFire] = true;
npc.buffImmune[BuffID.Burning] = true;
}
public override void AI()
{
int x = (int) npc.Center.X / 16;
int y = (int) npc.Center.Y / 16;
bool onWall = false;
for (int i = x - 1; i <= x + 1; i++)
for (int j = y - 1; j <= y + 1; j++)
if (Main.tile[i, j].wall > 0)
onWall = true;
if (Main.expertMode)
{
if (_frame >= shootFrame)
{
if (Main.rand.Next(4) == 0)
{
Vector2 mouthPos = npc.Center + new Vector2(npc.width / 2f, 0).RotatedBy(npc.rotation);
Vector2 projSpeed = new Vector2(5, 0).RotatedBy(npc.rotation);
Projectile.NewProjectile(mouthPos, projSpeed, ProjectileID.Fireball, 130, 30);
}
_frame = 0;
}
else
{
_frame++;
}
}
if (onWall)
npc.Transform(ModContent.NPCType<CoreSpiderWall>());
else
base.AI();
}
public override float SpawnChance(NPCSpawnInfo spawnInfo)
{
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 && Main.hardMode)
return SpawnCondition.Underworld.Chance * 2;
return 0;
}
}
}