Exemple #1
0
        private void AutoloadNPC(Type type)
        {
            ModNPC npc = (ModNPC)Activator.CreateInstance(type);

            npc.mod = this;
            string name           = type.Name;
            string texture        = (type.Namespace + "." + type.Name).Replace('.', '/');
            string defaultTexture = texture;

            if (npc.Autoload(ref name, ref texture))
            {
                AddNPC(name, npc, texture);
                string headTexture     = defaultTexture + "_Head";
                string bossHeadTexture = headTexture + "_Boss";
                npc.AutoloadHead(ref headTexture, ref bossHeadTexture);
                if (ModLoader.TextureExists(headTexture))
                {
                    AddNPCHeadTexture(npc.npc.type, headTexture);
                }
                if (ModLoader.TextureExists(bossHeadTexture))
                {
                    AddBossHeadTexture(bossHeadTexture);
                    NPCHeadLoader.npcToBossHead[npc.npc.type] = NPCHeadLoader.bossHeads[bossHeadTexture];
                }
            }
        }
Exemple #2
0
        internal void SetupNPC(NPC npc)
        {
            ModNPC newNPC = (ModNPC)Activator.CreateInstance(GetType());

            newNPC.npc = npc;
            npc.modNPC = newNPC;
            newNPC.mod = mod;
            newNPC.SetDefaults();
        }
Exemple #3
0
        internal void SetupNPC(NPC npc)
        {
            ModNPC newNPC = (ModNPC)(CloneNewInstances ? MemberwiseClone() : Activator.CreateInstance(GetType()));

            newNPC.npc = npc;
            npc.modNPC = newNPC;
            newNPC.Mod = Mod;
            newNPC.SetDefaults();
        }
Exemple #4
0
        public int NPCType(string name)
        {
            ModNPC npc = GetNPC(name);

            if (npc == null)
            {
                return(0);
            }
            return(npc.npc.type);
        }
Exemple #5
0
        public void AddNPC(string name, ModNPC npc, string texture)
        {
            int id = NPCLoader.ReserveNPCID();

            npc.npc.name       = name;
            npc.npc.type       = id;
            npcs[name]         = npc;
            NPCLoader.npcs[id] = npc;
            npc.texture        = texture;
            npc.mod            = this;
        }
Exemple #6
0
        /// <summary>
        /// Create a new instance of this ModNPC for an NPC instance.
        /// Called at the end of NPC.SetDefaults.
        /// If CloneNewInstances is true, just calls Clone()
        /// Otherwise calls the default constructor and copies fields
        /// </summary>
        public virtual ModNPC NewInstance(NPC npcClone)
        {
            if (CloneNewInstances)
            {
                ModNPC clone = Clone();
                clone.npc = npcClone;
                return(clone);
            }

            ModNPC copy = (ModNPC)Activator.CreateInstance(GetType());

            copy.npc           = npcClone;
            copy.Mod           = Mod;
            copy.aiType        = aiType;
            copy.animationType = animationType;
            copy.bossBag       = bossBag;
            copy.music         = music;
            copy.drawOffsetY   = drawOffsetY;
            copy.banner        = banner;
            copy.bannerItem    = bannerItem;
            return(copy);
        }
Exemple #7
0
        //at beginning of Terraria.Lang.npcName add
        //  if (l >= Main.maxNPCTypes) { return NPCLoader.DisplayName(l); }
        public static string DisplayName(int type)
        {
            ModNPC npc  = GetNPC(type);
            string name = "";

            if (npc != null)
            {
                if (npc.npc.displayName != null)
                {
                    name = npc.npc.displayName;
                }
                if (name == "" && npc.npc.name != null)
                {
                    name = npc.npc.name;
                }
            }
            if (name == "" && Main.npcName[type] != null)
            {
                name = Main.npcName[type];
            }
            return(name);
        }
Exemple #8
0
        /// <summary>
        /// Create a new instance of this ModNPC for an NPC instance.
        /// Called at the end of NPC.SetDefaults.
        /// If CloneNewInstances is true, just calls Clone()
        /// Otherwise calls the default constructor and copies fields
        /// </summary>
        public virtual ModNPC NewInstance(NPC npcClone)
        {
            if (CloneNewInstances)
            {
                ModNPC clone = Clone();
                clone.NPC = npcClone;
                return(clone);
            }

            ModNPC copy = (ModNPC)Activator.CreateInstance(GetType());

            copy.NPC           = npcClone;
            copy.Mod           = Mod;
            copy.AIType        = AIType;
            copy.AnimationType = AnimationType;
            copy.BossBag       = BossBag;
            copy.Music         = Music;
            copy.DrawOffsetY   = DrawOffsetY;
            copy.Banner        = Banner;
            copy.BannerItem    = BannerItem;
            return(copy);
        }
Exemple #9
0
        private void AutoloadNPC(Type type)
        {
            ModNPC npc = (ModNPC)Activator.CreateInstance(type);

            npc.mod = this;
            string name = type.Name;

            if (npc.Autoload(ref name))
            {
                AddNPC(name, npc);
                var autoloadHead = type.GetAttribute <AutoloadHead>();
                if (autoloadHead != null)
                {
                    string headTexture = npc.HeadTexture;
                    AddNPCHeadTexture(npc.npc.type, headTexture);
                }
                var autoloadBossHead = type.GetAttribute <AutoloadBossHead>();
                if (autoloadBossHead != null)
                {
                    string headTexture = npc.BossHeadTexture;
                    AddBossHeadTexture(headTexture, npc.npc.type);
                }
            }
        }
Exemple #10
0
 public void AddNPC(string name, ModNPC npc, string texture)
 {
     int id = NPCLoader.ReserveNPCID();
     npc.npc.name = name;
     npc.npc.type = id;
     npcs[name] = npc;
     NPCLoader.npcs[id] = npc;
     npc.texture = texture;
     npc.mod = this;
 }
Exemple #11
0
		public void AddNPC(string name, ModNPC npc, string texture, string[] altTextures = null)
		{
			int id = NPCLoader.ReserveNPCID();
			npc.npc.name = name;
			npc.npc.type = id;
			npcs[name] = npc;
			NPCLoader.npcs.Add(npc);
			npc.texture = texture;
			npc.altTextures = altTextures;
			npc.mod = this;
		}