tModLoader NPC has projectile problems

Nexusbeast

Terrarian
My NPC acts normally when spawned, it shoots shurikens at the player. However, when the player moves out of the maximum range (500f) and then gets back within the range it won't shoot projectiles any more.
Code:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace LordsOfTheCosmos.NPCs
{
    public class HeroSkeleton : ModNPC
    {
        const int COOLDOWN = 70;
        int remaining_cooldown = 0;
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Hero Skeleton");
        }

        public override void SetDefaults()
        {
            npc.width = 36;
            npc.height = 36;
            npc.damage = 45;
            npc.defense = 20;
            npc.lifeMax = 280;
            npc.HitSound = SoundID.NPCHit4;
            npc.DeathSound = SoundID.NPCDeath2;
            npc.value = 8600f;
            npc.knockBackResist = 0.1f;
            npc.aiStyle = 3;
            animationType = NPCID.Skeleton;
            Main.npcFrameCount[npc.type] = 15;
        }

        public override float SpawnChance(NPCSpawnInfo spawnInfo)
        {
            if (Main.player[Main.myPlayer].statLifeMax > 260)
            {
                return SpawnCondition.Cavern.Chance * 0.15f;
            }
            else return SpawnCondition.Cavern.Chance * 0f;
        }


        public override void HitEffect(int hitDirection, double damage)
        {
            for (int i = 0; i < 10; i++)
            {
                Dust.NewDust(npc.position, npc.width, npc.height, 42);
            }
            if (npc.life <= 0)
            {
                Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/CGore9"), 1f);
                Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/CGore10"), 1f);
                Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/CGore11"), 1f);
                Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/CGore12"), 1f);
                Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/CGore12"), 1f);

            }
        }

        public override void PostAI()
        {
            Vector2 target = Main.player[npc.target].position;
            float dist = Vector2.Distance(npc.position, target);
            if (dist < 500f && remaining_cooldown == 0)
            {
                Vector2 speed = target - npc.position;
                speed.Normalize();
                speed *= 8f;
                int proj = Projectile.NewProjectile(npc.position.X, npc.position.Y, speed.X, speed.Y, mod.ProjectileType("HeroShurikenHostile"), 15, 1f);
                Main.projectile[proj].hostile = true;

                remaining_cooldown = COOLDOWN;
            }

            remaining_cooldown -= 1;
        }

        public override void NPCLoot()  //Npc drop
        {
            Item.NewItem(npc.getRect(), mod.ItemType("HeroSteel"), Main.rand.Next(3, 8));
        }
    }
}
 
Back
Top Bottom