using Server.Accounting; using Server.Commands.Generic; using Server.Commands; using Server.Items; using Server.Misc; using Server.Mobiles; using Server.Network; using Server.Regions; using Server; using System.Collections.Generic; using System.Collections; using System.IO; using System; using System.Reflection; // Added to access private variables inside BaseSpawner namespace Server.Scripts.Commands { public class BuildWorld { public static void Initialize() { CommandSystem.Register("BuildWorld", AccessLevel.Counselor, new CommandEventHandler( BuildWorlds )); } [Usage("BuildWorld")] [Description("This cleans up the world and rebuilds it, leaving players intact.")] public static void BuildWorlds( CommandEventArgs e ) { // ------- SURGICAL SPAWN SWEEP START ------- e.Mobile.SendMessage( 38, "Sweeping the world for old spawners and orphaned tracking mobs... This may take a moment." ); int spawnerCount = 0; int mobCount = 0; List spawnersToDelete = new List(); List mobsToDelete = new List(); foreach ( Item item in World.Items.Values ) { // 1. Catch standard spawners if ( item is Spawner ) { spawnersToDelete.Add( item ); } // 2. Catch custom BaseSpawners (SpawnAnimals, SpawnBirds, Spawn_A, etc.) else if ( item is BaseSpawner ) { spawnersToDelete.Add( item ); // Use Reflection to grab the private "m_TrackedMobile" field FieldInfo field = typeof(BaseSpawner).GetField( "m_TrackedMobile", BindingFlags.NonPublic | BindingFlags.Instance ); if ( field != null ) { Mobile trackedMob = field.GetValue( item ) as Mobile; // If the spawner is tracking a living mob, mark it for deletion if ( trackedMob != null && !trackedMob.Deleted ) { mobsToDelete.Add( trackedMob ); } } } } // Delete the thousands of orphaned animals/mobs first foreach ( Mobile m in mobsToDelete ) { if ( !m.Deleted ) { m.Delete(); mobCount++; } } // Delete the hidden proxy spawners second foreach ( Item item in spawnersToDelete ) { if ( !item.Deleted ) { item.Delete(); spawnerCount++; } } e.Mobile.SendMessage( 63, "Wipe Complete: {0} spawners and {1} tracked mobs deleted! Rebuilding...", spawnerCount, mobCount ); // ------- SURGICAL SPAWN SWEEP END ------- // Original Generation Commands Server.Commands.Decorate.Decorate_OnCommand( e ); Server.Misc.GenTeleporters.GenTeleporters_OnCommand( e ); Server.SpawnGenerator.Parse( e.Mobile, "towns.map" ); Server.SpawnGenerator.Parse( e.Mobile, "graveyards.map" ); Server.SpawnGenerator.Parse( e.Mobile, "land.map" ); Server.SpawnGenerator.Parse( e.Mobile, "dungeons.map" ); Server.SpawnGenerator.Parse( e.Mobile, "labyrinths.map" ); Server.SpawnGenerator.Parse( e.Mobile, "mazes.map" ); Server.SpawnGenerator.Parse( e.Mobile, "danger.map" ); Server.SpawnGenerator.Parse( e.Mobile, "forts.map" ); if ( Server.Misc.Settings.PopulateTowns() ) { Server.SpawnGenerator.Parse( e.Mobile, "citizens.map" ); } Server.Regions.SpawnEntry.RespawnAllRegions_OnCommand( e ); e.Mobile.SendMessage( 63, "The world has been rebuilt." ); } } }