66 lines
2.4 KiB
C#
66 lines
2.4 KiB
C#
using System;
|
|
using System.IO;
|
|
using Server;
|
|
using Server.Items;
|
|
using Server.Commands;
|
|
|
|
namespace Server.Scripts.Commands
|
|
{
|
|
public class ExportTrapsCommand
|
|
{
|
|
public static void Initialize()
|
|
{
|
|
CommandSystem.Register( "ExportTraps", AccessLevel.Administrator, new CommandEventHandler( ExportTraps_OnCommand ) );
|
|
}
|
|
|
|
[Usage( "ExportTraps" )]
|
|
[Description( "Exports all placed BaseTrap items on your current map to a cfg file in Data/Decoration." )]
|
|
private static void ExportTraps_OnCommand( CommandEventArgs e )
|
|
{
|
|
Map currentMap = e.Mobile.Map;
|
|
|
|
if ( currentMap == null || currentMap == Map.Internal )
|
|
{
|
|
e.Mobile.SendMessage( "You cannot export from the internal map." );
|
|
return;
|
|
}
|
|
|
|
string exportDir = Path.Combine( Core.BaseDirectory, "Data", "Decoration" );
|
|
|
|
if ( !Directory.Exists( exportDir ) )
|
|
{
|
|
Directory.CreateDirectory( exportDir );
|
|
}
|
|
|
|
// Appends the map name to prevent overwriting
|
|
string fileName = String.Format( "ExportedTraps_{0}.cfg", currentMap.Name );
|
|
string filePath = Path.Combine( exportDir, fileName );
|
|
|
|
int count = 0;
|
|
|
|
using ( StreamWriter op = new StreamWriter( filePath ) )
|
|
{
|
|
foreach ( Item item in World.Items.Values )
|
|
{
|
|
// Catch anything that inherits from BaseTrap (Axe, Spike, Gas, etc.)
|
|
if ( item is BaseTrap && item.Parent == null && item.Map == currentMap )
|
|
{
|
|
string typeName = item.GetType().Name.ToLower();
|
|
int itemID = item.ItemID;
|
|
int hue = item.Hue;
|
|
string name = item.Name ?? "";
|
|
|
|
// Outputs identically to the Loot Chest format
|
|
op.WriteLine( "{0} {1} (Hue={2}; Name={3})", typeName, itemID, hue, name );
|
|
op.WriteLine( "{0} {1} {2}", item.X, item.Y, item.Z );
|
|
op.WriteLine();
|
|
|
|
count++;
|
|
}
|
|
}
|
|
}
|
|
|
|
e.Mobile.SendMessage( "{0} traps exported! Check your Data/Decoration folder for {1}.", count, fileName );
|
|
}
|
|
}
|
|
}
|