#W# Command: [ECN command for exporting CitizenNodes.
This commit is contained in:
parent
54e6d4c978
commit
bf549b5386
2 changed files with 135 additions and 0 deletions
68
Projects/UOContent/Commands/ExportCitizenNodes.cs
Normal file
68
Projects/UOContent/Commands/ExportCitizenNodes.cs
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Server;
|
||||
using Server.Commands;
|
||||
using Server.Items;
|
||||
|
||||
namespace Server.Commands
|
||||
{
|
||||
public static class ExportCitizenNodes
|
||||
{
|
||||
public static void Configure()
|
||||
{
|
||||
CommandSystem.Register("ExportCitizenNodes", AccessLevel.GameMaster, ExportCitizenNodes_OnCommand);
|
||||
}
|
||||
|
||||
[Usage("ExportCitizenNodes")]
|
||||
[Aliases("ExportCitizenNodes", "ECN")]
|
||||
[Description("Exports all deployed CitizenNodes into a decoration .cfg file format.")]
|
||||
private static void ExportCitizenNodes_OnCommand(CommandEventArgs e)
|
||||
{
|
||||
var mobile = e.Mobile;
|
||||
|
||||
var nodes = World.Items.Values
|
||||
.OfType<CitizenNode>()
|
||||
.Where(n => !n.Deleted && n.Map != null && n.Map != Map.Internal)
|
||||
.ToList();
|
||||
|
||||
if (nodes.Count == 0)
|
||||
{
|
||||
mobile.SendMessage("No active CitizenNodes were found in the world.");
|
||||
return;
|
||||
}
|
||||
|
||||
string folderPath = Path.Combine(Core.BaseDirectory, "Data", "Decoration", "Exported");
|
||||
if (!Directory.Exists(folderPath))
|
||||
{
|
||||
Directory.CreateDirectory(folderPath);
|
||||
}
|
||||
|
||||
string filePath = Path.Combine(folderPath, "CitizenNodes.cfg");
|
||||
|
||||
using (var writer = new StreamWriter(filePath, false))
|
||||
{
|
||||
writer.WriteLine("# Auto-generated CitizenNode export file");
|
||||
writer.WriteLine($"# Exported on {DateTime.Now:yyyy-MM-dd HH:mm:ss}");
|
||||
writer.WriteLine();
|
||||
|
||||
// Group nodes by NodeType so the config file remains clean and organized
|
||||
foreach (var group in nodes.GroupBy(n => n.NodeType))
|
||||
{
|
||||
int itemID = group.First().ItemID;
|
||||
writer.WriteLine($"CitizenNode 0x{itemID:X} (NodeType={group.Key})");
|
||||
|
||||
foreach (var node in group)
|
||||
{
|
||||
writer.WriteLine($"{node.X} {node.Y} {node.Z}");
|
||||
}
|
||||
|
||||
writer.WriteLine();
|
||||
}
|
||||
}
|
||||
|
||||
mobile.SendMessage($"Successfully exported {nodes.Count} CitizenNode(s) to '{filePath}'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue