示例#1
0
        public static void SpawnNpcInRange(IMap map, int x, int y, int range, PacketHitList hitlist)
        {
            if (map.Npc.Count == 0) return;

            if (map.SpawnMarker >= map.Npc.Count) map.SpawnMarker = map.Npc.Count - 1;

            for (int i = 0; i < 100; i++) {
                if (Server.Math.Rand(0, 100) < map.Npc[map.SpawnMarker].AppearanceRate && map.WillSpawnNow(map.Npc[map.SpawnMarker])) {
                    break;
                }
                map.SpawnMarker++;
                if (map.SpawnMarker >= map.Npc.Count) map.SpawnMarker = 0;
            }

            MapNpcPreset spawningNpc = new MapNpcPreset();
            spawningNpc.NpcNum = map.Npc[map.SpawnMarker].NpcNum;
            spawningNpc.MinLevel = map.Npc[map.SpawnMarker].MinLevel;
            spawningNpc.MaxLevel = map.Npc[map.SpawnMarker].MaxLevel;
            spawningNpc.StartStatus = Enums.StatusAilment.OK;

            for (int i = 1; i <= 500; i++) {
                int X = Server.Math.Rand(x - range, x + range + 1);
                int Y = Server.Math.Rand(y - range, y + range + 1);

                // Check if the tile is walkable
                if (X >= 0 && X <= map.MaxX && Y >= 0 && Y <= map.MaxY && map.Tile[X, Y].Type == Enums.TileType.Walkable) {
                    spawningNpc.SpawnX = X;
                    spawningNpc.SpawnY = Y;
                    break;
                }
            }

            if (spawningNpc.SpawnX > -1) map.SpawnNpc(spawningNpc);

            map.SpawnMarker++;
            if (map.SpawnMarker >= map.Npc.Count) map.SpawnMarker = 0;
        }