internal static void OnSetDefaults(NPC n, int type, float scaleOverride) { n.P_BHandler = null; n.P_BuffBHandler = new object[NPC.maxBuffs]; n.P_Music = null; n.P_SoundOnHit = null; n.P_SoundOnDeath = null; if (ModLoader.Reloading) { n.RealSetDefaults(type); if (!FillingVanilla) { Logging.LogWarning("Tried to call SetDefaults on an NPC while [re|un]?loading mods."); } return; } NpcBHandler h = null; // will be set to <non-null> only if a behaviour handler will be attached if (type < NPCID.Count && !ModLoader.Reloading && !FillingVanilla && type != 0 && Handler.NpcDef.DefsByType.Count > 0) { n.RealSetDefaults(type < 0 ? Handler.NpcDef.DefsByType[type].Type : type, scaleOverride); } else { n.RealSetDefaults(0, scaleOverride); } if (Handler.NpcDef.DefsByType.ContainsKey(type)) { var d = Handler.NpcDef.DefsByType[type]; n.type = n.netID = type; n.width = n.height = 16; Handler.NpcDef.CopyDefToEntity(d, n); if (Main.expertMode) { n.scaleStats(); } n.life = n.lifeMax; //! BEEP BOOP n.defDamage = n.damage; n.defDefense = n.defense; if (scaleOverride > -1f) { n.scale = scaleOverride; } if (d.CreateBehaviour != null) { h = new NpcBHandler(); var b = d.CreateBehaviour(); if (b != null) { b.Mod = d.Mod == PrismApi.VanillaInfo ? null : ModData.mods[d.Mod]; h.behaviours.Add(b); } } } else { n.RealSetDefaults(type, scaleOverride); } var bs = ModLoader.Reloading ? Empty <NpcBehaviour> .Array : ModData.mods.Values .Select(m => new KeyValuePair <ModDef, NpcBehaviour>(m, m.ContentHandler.CreateGlobalNpcBInternally())) .Where(kvp => kvp.Value != null) .Select(kvp => { kvp.Value.Mod = kvp.Key; return(kvp.Value); }); if (!bs.IsEmpty() && h == null) { h = new NpcBHandler(); } if (h != null) { h.behaviours.AddRange(bs); h.Create(); n.P_BHandler = h; foreach (var b in h.Behaviours) { b.Entity = n; } h.OnInit(); } }
internal static void OnSetDefaults(NPC n, int type, float scaleOverride) { n.P_BHandler = null; n.P_BuffBHandler = new object[NPC.maxBuffs]; n.P_Music = null; n.P_SoundOnHit = null; n.P_SoundOnDeath = null; if (ModLoader.Reloading) { n.RealSetDefaults(type); if (!FillingVanilla) Logging.LogWarning("Tried to call SetDefaults on an NPC while [re|un]?loading mods."); return; } NpcBHandler h = null; // will be set to <non-null> only if a behaviour handler will be attached if (type < NPCID.Count && !ModLoader.Reloading && !FillingVanilla && type != 0 && Handler.NpcDef.DefsByType.Count > 0) n.RealSetDefaults(type < 0 ? Handler.NpcDef.DefsByType[type].Type : type, scaleOverride); else n.RealSetDefaults(0, scaleOverride); if (Handler.NpcDef.DefsByType.ContainsKey(type)) { var d = Handler.NpcDef.DefsByType[type]; n.type = n.netID = type; n.width = n.height = 16; Handler.NpcDef.CopyDefToEntity(d, n); if (Main.expertMode) n.scaleStats(); n.life = n.lifeMax; //! BEEP BOOP n.defDamage = n.damage; n.defDefense = n.defense; if (scaleOverride > -1f) n.scale = scaleOverride; if (d.CreateBehaviour != null) { var b = d.CreateBehaviour(); if (b != null) { h = new NpcBHandler(); b.Mod = d.Mod == PrismApi.VanillaInfo ? null : ModData.mods[d.Mod]; h.behaviours.Add(b); } } } else n.RealSetDefaults(type, scaleOverride); var bs = ModLoader.Reloading ? Empty<NpcBehaviour>.Array : ModData.mods.Values .Select(m => new KeyValuePair<ModDef, NpcBehaviour>(m, m.ContentHandler.CreateGlobalNpcBInternally())) .Where(kvp => kvp.Value != null) .Select(kvp => { kvp.Value.Mod = kvp.Key; return kvp.Value; }); if (!bs.IsEmpty() && h == null) h = new NpcBHandler(); if (h != null) { h.behaviours.AddRange(bs); h.Create(); n.P_BHandler = h; foreach (var b in h.Behaviours) b.Entity = n; //h.OnInit(); } }
internal static void OnSetDefaults(NPC n, int type, float scaleOverride) { NpcBHandler h = null; if (type >= NPCID.Count) { n.RealSetDefaults(0, scaleOverride); if (DefFromType.ContainsKey(type)) { var d = DefFromType[type]; n.type = n.netID = type; n.width = n.height = 16; CopyDefToNpc(n, d); if (scaleOverride > -1f) n.scale = scaleOverride; h = new NpcBHandler(); if (d.CreateBehaviour != null) { var b = d.CreateBehaviour(); if (b != null) h.behaviours.Add(b); } n.BHandler = h; } } else n.RealSetDefaults(type, scaleOverride); //TODO: add global hooks here (and check for null) if (h != null) { h.Create(); n.BHandler = h; foreach (var b in h.Behaviours) b.Entity = n; h.OnInit(); } }