diff --git a/Projects/UOContent/Commands/ClearCommands.cs b/Projects/UOContent/Commands/ClearCommands.cs new file mode 100644 index 000000000..42fd9d21e --- /dev/null +++ b/Projects/UOContent/Commands/ClearCommands.cs @@ -0,0 +1,117 @@ +using Server.Gumps; +using Server.Network; +using System; +using System.Collections.Generic; + +namespace Server.Commands; + +public static class ClearCommands +{ + public static void Configure() + { + CommandSystem.Register("ClearFacet", AccessLevel.Owner, ClearFacet_OnCommand); + CommandSystem.Register("ClearAll", AccessLevel.Owner, ClearAll_OnCommand); + } + + [Usage("ClearFacet")] + [Description("Deletes all items and mobiles in your facet. Players and their inventory will not be deleted.")] + public static void ClearFacet_OnCommand(CommandEventArgs e) + { + var from = e.Mobile; + var map = from.Map; + var list = GetObjects(entity => entity.Map == map); + + DeleteObjects(list, from, map.Name); + } + + [Usage( "ClearAll" )] + [Description( "Deletes all items and mobiles in all facets. Players and their inventory will not be deleted." )] + public static void ClearAll_OnCommand(CommandEventArgs e) + { + var from = e.Mobile; + var list = GetObjects(); + + DeleteObjects(list, from, "globally"); + } + + private static List GetObjects(Predicate predicate = null) + { + List list = []; + + foreach (var item in World.Items.Values) + { + if (item.Parent == null && predicate?.Invoke(item) != false) + { + list.Add(item); + } + } + + foreach (var mob in World.Mobiles.Values) + { + if (!mob.Player && predicate?.Invoke(mob) != false) + { + list.Add(mob); + } + } + + return list; + } + + private static void DeleteObjects(List list, Mobile from, string facets) + { + if (list.Count <= 0) + { + from.SendMessage("There were no objects found to delete."); + return; + } + + CommandLogging.WriteLine( + from, + $"{from.AccessLevel} {CommandLogging.Format(from)} started cleaning {facets} ({list.Count} object{(list.Count == 1 ? "" : "s")})" + ); + + from.SendGump( + new DeleteObjectsNoticeGump( + list.Count, + facets, + okay => DeleteList_Callback(from, okay, list) + ) + ); + } + + private class DeleteObjectsNoticeGump : StaticWarningGump + { + public override int Width => 360; + public override int Height => 260; + + public override string Content { get; } + + public DeleteObjectsNoticeGump(int count, string facets, Action callback) : base(callback) => + Content = + $"You are about to delete {count} object{(count == 1 ? "" : "s")} from {facets}. Do you really wish to continue?"; + } + + public static void DeleteList_Callback(Mobile from, bool okay, List list) + { + if (!okay) + { + from.SendMessage("You have chosen not to delete those objects."); + return; + } + + CommandLogging.WriteLine( + from, + $"{from.AccessLevel} {CommandLogging.Format(from)} deleting {list.Count} object{(list.Count == 1 ? "" : "s")}" + ); + + NetState.FlushAll(); + + foreach (var entity in list) + { + entity.Delete(); + } + + from.SendMessage($"You have deleted {list.Count} object{(list.Count == 1 ? "" : "s")}."); + } +} + diff --git a/Projects/UOContent/Commands/Generic/Extensions/Compilers/ConditionalCompiler.cs b/Projects/UOContent/Commands/Generic/Extensions/Compilers/ConditionalCompiler.cs index 9722d6f36..18e2a6505 100644 --- a/Projects/UOContent/Commands/Generic/Extensions/Compilers/ConditionalCompiler.cs +++ b/Projects/UOContent/Commands/Generic/Extensions/Compilers/ConditionalCompiler.cs @@ -130,6 +130,10 @@ namespace Server.Commands.Generic { Value = Enum.Parse(Type, toParse, true); } + else if (Type == typeof(bool)) + { + Value = bool.Parse(toParse); + } else { MethodInfo parseMethod; diff --git a/Projects/UOContent/Commands/Handlers.cs b/Projects/UOContent/Commands/Handlers.cs index 9bd0a5023..de1e831e2 100644 --- a/Projects/UOContent/Commands/Handlers.cs +++ b/Projects/UOContent/Commands/Handlers.cs @@ -23,43 +23,24 @@ namespace Server.Commands CommandSystem.Prefix = ServerConfiguration.GetOrUpdateSetting("commandsystem.prefix", "["); Register("Go", AccessLevel.Counselor, Go_OnCommand); - Register("DropHolding", AccessLevel.Counselor, DropHolding_OnCommand); - Register("GetFollowers", AccessLevel.GameMaster, GetFollowers_OnCommand); - - Register("ClearFacet", AccessLevel.Developer, ClearFacet_OnCommand); - Register("Where", AccessLevel.Counselor, Where_OnCommand); - Register("AutoPageNotify", AccessLevel.Counselor, APN_OnCommand); - Register("Animate", AccessLevel.GameMaster, Animate_OnCommand); - Register("Cast", AccessLevel.Counselor, Cast_OnCommand); - Register("Stuck", AccessLevel.Counselor, Stuck_OnCommand); - Register("Help", AccessLevel.Player, Help_OnCommand); - Register("Move", AccessLevel.GameMaster, Move_OnCommand); Register("Client", AccessLevel.Counselor, Client_OnCommand); - Register("SMsg", AccessLevel.Counselor, StaffMessage_OnCommand); - Register("BCast", AccessLevel.GameMaster, BroadcastMessage_OnCommand); - Register("Bank", AccessLevel.GameMaster, Bank_OnCommand); - Register("Echo", AccessLevel.Counselor, Echo_OnCommand); - Register("Sound", AccessLevel.GameMaster, Sound_OnCommand); - Register("ViewEquip", AccessLevel.GameMaster, ViewEquip_OnCommand); - Register("Light", AccessLevel.Counselor, Light_OnCommand); Register("Stats", AccessLevel.Counselor, Stats_OnCommand); - Register("SpeedBoost", AccessLevel.Counselor, SpeedBoost_OnCommand); } @@ -181,99 +162,6 @@ namespace Server.Commands } } - public static void DeleteList_Callback(Mobile from, bool okay, List list) - { - if (okay) - { - CommandLogging.WriteLine( - from, - $"{from.AccessLevel} {CommandLogging.Format(from)} deleting {list.Count} object{(list.Count == 1 ? "" : "s")}" - ); - - NetState.FlushAll(); - - for (var i = 0; i < list.Count; ++i) - { - list[i].Delete(); - } - - if (list.Count == 1) - { - from.SendMessage($"You have deleted {list.Count} object."); - } - else - { - from.SendMessage($"You have deleted {list.Count} objects."); - } - } - else - { - from.SendMessage("You have chosen not to delete those objects."); - } - } - - [Usage("ClearFacet"), - Description("Deletes all items and mobiles in your facet. Players and their inventory will not be deleted.")] - public static void ClearFacet_OnCommand(CommandEventArgs e) - { - var from = e.Mobile; - var map = from.Map; - - if (map == null || map == Map.Internal) - { - from.SendMessage("You may not run that command here."); - return; - } - - var list = new List(); - - foreach (var item in World.Items.Values) - { - if (item.Map == map && item.Parent == null) - { - list.Add(item); - } - } - - foreach (var m in World.Mobiles.Values) - { - if (m.Map == map && !m.Player) - { - list.Add(m); - } - } - - if (list.Count > 0) - { - CommandLogging.WriteLine( - from, - $"{from.AccessLevel} {CommandLogging.Format(from)} starting facet clear of {map} ({list.Count} object{(list.Count == 1 ? "" : "s")})" - ); - - from.SendGump( - new DeleteObjectsNoticeGump( - list.Count, - okay => DeleteList_Callback(from, okay, list) - ) - ); - } - else - { - from.SendMessage("There were no objects found to delete."); - } - } - - private class DeleteObjectsNoticeGump : StaticWarningGump - { - public override int Header => 1060635; //
WARNING
- public override int Width => 360; - public override int Height => 260; - public override string Content { get; } - - public DeleteObjectsNoticeGump(int count, Action callback) : base(callback) => - Content = $"You are about to delete {count} object{(count == 1 ? "" : "s")} from this facet. Do you really wish to continue?"; - } - [Usage("GetFollowers")] [Description("Teleports all pets of a targeted player to your location.")] public static void GetFollowers_OnCommand(CommandEventArgs e) diff --git a/docs/commands/commands.7z b/docs/commands/commands.7z index 00e2f554f..d0d6c0e9b 100644 Binary files a/docs/commands/commands.7z and b/docs/commands/commands.7z differ