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]; } } }
internal void SetupNPC(NPC npc) { ModNPC newNPC = (ModNPC)Activator.CreateInstance(GetType()); newNPC.npc = npc; npc.modNPC = newNPC; newNPC.mod = mod; newNPC.SetDefaults(); }
internal void SetupNPC(NPC npc) { ModNPC newNPC = (ModNPC)(CloneNewInstances ? MemberwiseClone() : Activator.CreateInstance(GetType())); newNPC.npc = npc; npc.modNPC = newNPC; newNPC.Mod = Mod; newNPC.SetDefaults(); }
public int NPCType(string name) { ModNPC npc = GetNPC(name); if (npc == null) { return(0); } return(npc.npc.type); }
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; }
/// <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); }
//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); }
/// <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); }
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); } } }
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; }