public void AddGlobalNPC(string name, GlobalNPC globalNPC) { globalNPC.mod = this; globalNPC.Name = name; this.globalNPCs[name] = globalNPC; NPCLoader.globalNPCs.Add(globalNPC); }
private void AutoloadGlobalNPC(Type type) { GlobalNPC globalNPC = (GlobalNPC)Activator.CreateInstance(type); globalNPC.mod = this; string name = type.Name; if (globalNPC.Autoload(ref name)) { AddGlobalNPC(name, globalNPC); } }
/// <summary> /// Create a new instance of this GlobalNPC 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 GlobalNPC NewInstance(NPC npc) { if (CloneNewInstances) { return(Clone()); } GlobalNPC copy = (GlobalNPC)Activator.CreateInstance(GetType()); copy.Mod = Mod; copy.index = index; return(copy); }
internal static void VerifyGlobalNPC(GlobalNPC npc) { var type = npc.GetType(); bool hasInstanceFields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) .Any(f => f.DeclaringType != typeof(GlobalNPC)); if (hasInstanceFields) { if (!npc.InstancePerEntity) { throw new Exception(type + " has instance fields but does not set InstancePerEntity to true. Either use static fields, or per instance globals"); } } }
public void SetGlobalNPC(GlobalNPC globalNPC) { globalNPC.mod = this; this.globalNPC = globalNPC; }
//I'm not sure why I have this internal void Unload() { recipes.Clear(); items.Clear(); globalItem = null; dusts.Clear(); tiles.Clear(); globalNPC = null; }