/// <summary> /// Hook method for NPC summoning /// </summary> /// <param name="Event">NPCSpawnEvent info</param> public virtual void onNPCSpawn(NPCSpawnEvent Event) { }
public static int NewNPC(int x, int y, NPC npc, int npcIndex) { npc.Position.X = (float)(x - npc.Width / 2); npc.Position.Y = (float)(y - npc.Height); npc.Active = true; npc.timeLeft = (int)((double)NPC.active_TIME * 1.25); npc.wet = Collision.WetCollision(npc.Position, npc.Width, npc.Height); if (!WorldModify.gen) { NPCSpawnEvent npcEvent = new NPCSpawnEvent(); npcEvent.NPC = npc; Sender sender = new Sender(); sender.Op = true; npcEvent.Sender = sender; Program.server.PluginManager.processHook(Hooks.NPC_SPAWN, npcEvent); if (npcEvent.Cancelled) { return MAX_NPCS; } } Main.npcs[npcIndex] = npc; return npcIndex; }
public static int NewNPC(int x, int y, int type, int start = 0) { int npcIndex = -1; for (int i = start; i < MAX_NPCS; i++) { if (!Main.npcs[i].Active) { npcIndex = i; break; } } if (npcIndex >= 0) { NPC npc = Registries.NPC.Create(type); //NPC oldNPC = Main.npcs[npcIndex]; npc.Position.X = (float)(x - npc.Width / 2); npc.Position.Y = (float)(y - npc.Height); npc.Active = true; npc.timeLeft = (int)((double)NPC.ACTIVE_TIME * 1.25); npc.wet = Collision.WetCollision(npc.Position, npc.Width, npc.Height); if (!WorldGen.gen) { NPCSpawnEvent npcEvent = new NPCSpawnEvent(); npcEvent.NPC = npc; Sender sender = new Sender(); sender.Op = true; npcEvent.Sender = sender; Program.server.PluginManager.processHook(Hooks.NPC_SPAWN, npcEvent); if (npcEvent.Cancelled) { return MAX_NPCS; } } Main.npcs[npcIndex] = npc; if (type == 50) { NetMessage.SendData(25, -1, -1, npc.Name + " has awoken!", 255, 175f, 75f, 255f); } return npcIndex; } return MAX_NPCS; }