fix: Fixes parsing booleans in commands. Adds ClearAll command (#1818)
This commit is contained in:
parent
ad26f0a1cb
commit
c69d16a90e
4 changed files with 121 additions and 112 deletions
117
Projects/UOContent/Commands/ClearCommands.cs
Normal file
117
Projects/UOContent/Commands/ClearCommands.cs
Normal file
|
|
@ -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<IEntity> GetObjects(Predicate<IEntity> predicate = null)
|
||||
{
|
||||
List<IEntity> 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<IEntity> 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<DeleteObjectsNoticeGump>
|
||||
{
|
||||
public override int Width => 360;
|
||||
public override int Height => 260;
|
||||
|
||||
public override string Content { get; }
|
||||
|
||||
public DeleteObjectsNoticeGump(int count, string facets, Action<bool> 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<IEntity> 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")}.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<IEntity> 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<IEntity>();
|
||||
|
||||
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<DeleteObjectsNoticeGump>
|
||||
{
|
||||
public override int Header => 1060635; // <CENTER>WARNING</CENTER>
|
||||
public override int Width => 360;
|
||||
public override int Height => 260;
|
||||
public override string Content { get; }
|
||||
|
||||
public DeleteObjectsNoticeGump(int count, Action<bool> 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)
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue