AvatarsConquest/Scripts/Commands/ExportChests.cs

63 lines
2.2 KiB
C#

using System;
using System.IO;
using Server;
using Server.Items;
using Server.Commands;
namespace Server.Scripts.Commands
{
public class ExportChestsCommand
{
public static void Initialize()
{
CommandSystem.Register( "ExportChests", AccessLevel.Administrator, new CommandEventHandler( ExportChests_OnCommand ) );
}
[Usage( "ExportChests" )]
[Description( "Exports all placed LootChest items on your current map to a cfg file in Data/Decoration." )]
private static void ExportChests_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 );
}
string fileName = String.Format( "ExportedLoot_{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 )
{
if ( item is LootChest && !(item is SunkenShip) && item.Parent == null && item.Map == currentMap )
{
string typeName = item.GetType().Name.ToLower();
int itemID = item.ItemID;
int hue = item.Hue;
string name = item.Name ?? "";
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} chests exported! Check your Data/Decoration folder for {1}.", count, fileName );
}
}
}