/// <summary> /// Spawns specified NPC type on specified player /// </summary> /// <param name="player">Instance of player to spawn on</param> /// <param name="playerIndex">Index of player to spawn on</param> /// <param name="Type">Type of NPC to spawn</param> public static void SpawnOnPlayer(Player player, int playerIndex, int Type) { bool flag = false; int num = 0; int num2 = 0; int num3 = (int)(player.Position.X / 16f) - NPC.spawnRangeX * 3; int num4 = (int)(player.Position.X / 16f) + NPC.spawnRangeX * 3; int num5 = (int)(player.Position.Y / 16f) - NPC.spawnRangeY * 3; int num6 = (int)(player.Position.Y / 16f) + NPC.spawnRangeY * 3; int num7 = (int)(player.Position.X / 16f) - NPC.safeRangeX; int num8 = (int)(player.Position.X / 16f) + NPC.safeRangeX; int num9 = (int)(player.Position.Y / 16f) - NPC.safeRangeY; int num10 = (int)(player.Position.Y / 16f) + NPC.safeRangeY; if (num3 < 0) { num3 = 0; } if (num4 >= Main.maxTilesX) { num4 = Main.maxTilesX - 1; } if (num5 < 0) { num5 = 0; } if (num6 >= Main.maxTilesY) { num6 = Main.maxTilesY - 1; } for (int i = 0; i < 1000; i++) { int j = 0; while (j < 100) { int num11 = Main.rand.Next(num3, num4); int num12 = Main.rand.Next(num5, num6); if (Main.tile.At(num11, num12).Active && Main.tileSolid[(int)Main.tile.At(num11, num12).Type]) { goto IL_2E1; } if (Main.tile.At(num11, num12).Wall != 1) { int k = num12; while (k < Main.maxTilesY) { if (Main.tile.At(num11, k).Active && Main.tileSolid[(int)Main.tile.At(num11, k).Type]) { if (num11 < num7 || num11 > num8 || k < num9 || k > num10) { byte arg_220_0 = Main.tile.At(num11, k).Type; num = num11; num2 = k; flag = true; break; } break; } else { k++; } } if (!flag) { goto IL_2E1; } int num13 = num - NPC.spawnSpaceX / 2; int num14 = num + NPC.spawnSpaceX / 2; int num15 = num2 - NPC.spawnSpaceY; int num16 = num2; if (num13 < 0) { flag = false; } if (num14 >= Main.maxTilesX) { flag = false; } if (num15 < 0) { flag = false; } if (num16 >= Main.maxTilesY) { flag = false; } if (flag) { for (int l = num13; l < num14; l++) { for (int m = num15; m < num16; m++) { if (Main.tile.At(l, m).Active && Main.tileSolid[(int)Main.tile.At(l, m).Type]) { flag = false; break; } } } goto IL_2E1; } goto IL_2E1; } IL_2E7: j++; continue; IL_2E1: if (!flag && !flag) { goto IL_2E7; } break; } if (flag) { Rectangle rectangle = new Rectangle(num * 16, num2 * 16, 16, 16); for (int n = 0; n < 255; n++) { if (Main.players[n].Active) { Rectangle rectangle2 = new Rectangle((int)(Main.players[n].Position.X + (float)(Main.players[n].Width / 2) - (float)(NPC.sWidth / 2) - (float)NPC.safeRangeX), (int)(Main.players[n].Position.Y + (float)(Main.players[n].Height / 2) - (float)(NPC.sHeight / 2) - (float)NPC.safeRangeY), NPC.sWidth + NPC.safeRangeX * 2, NPC.sHeight + NPC.safeRangeY * 2); if (rectangle.Intersects(rectangle2)) { flag = false; } } } } if (flag) { break; } } if (flag) { //Boss summon? NPCBossSummonEvent npcEvent = new NPCBossSummonEvent(); npcEvent.BossType = Type; npcEvent.Sender = Main.players[playerIndex]; Program.server.PluginManager.processHook(Hooks.NPC_BOSSSUMMON, npcEvent); if (npcEvent.Cancelled) { return; } int npcIndex = NPC.NewNPC(num * 16 + 8, num2 * 16, Type, 1); Main.npcs[npcIndex].target = playerIndex; String str = Main.npcs[npcIndex].Name; if (Main.npcs[npcIndex].type == NPCType.N13_EATER_OF_WORLDS_HEAD) { str = "Eater of Worlds"; } if (Main.npcs[npcIndex].type == NPCType.N35_SKELETRON_HEAD) { str = "Skeletron"; } if (npcIndex < MAX_NPCS) { NetMessage.SendData(23, -1, -1, "", npcIndex); } NetMessage.SendData(25, -1, -1, str + " has awoken!", 255, 175f, 75f, 255f); } }
/// <summary> /// Hook method for Boss Summons /// </summary> /// <param name="Event">NPCBossSummonEvent info</param> public virtual void onNPCBossSummon(NPCBossSummonEvent Event) { }