Fixes brace style (#248)

This commit is contained in:
Kamron Batman 2020-09-13 21:49:46 -07:00 • committed by GitHub
parent a236617ad9
commit 8149620b0c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
1503 changed files with 28575 additions and 1717 deletions

View file

@ -34,18 +34,26 @@ namespace Server.Commands.Generic
var ext = Extensions.Parse(from, ref args);
if (!CheckObjectTypes(from, command, ext, out var items, out var mobiles))
{
return;
}
if (!(items || mobiles))
{
return;
}
var eable = map.GetObjectsInBounds(rect, items, mobiles);
var objs = new List<object>();
foreach (var obj in eable)
if ((!mobiles || obj is Mobile) && BaseCommand.IsAccessible(from, obj) && ext.IsValid(obj))
{
if ((!mobiles || obj is Mobile) && BaseCommand.IsAccessible(@from, obj) && ext.IsValid(obj))
{
objs.Add(obj);
}
}
eable.Free();
ext.Filter(objs);

View file

@ -86,7 +86,9 @@ namespace Server.Commands.Generic
public virtual void Register(BaseCommand command)
{
for (var i = 0; i < command.Commands.Length; ++i)
{
Commands[command.Commands[i]] = command;
}
}
public bool CheckObjectTypes(Mobile from, BaseCommand command, Extensions ext, out bool items, out bool mobiles)
@ -96,12 +98,14 @@ namespace Server.Commands.Generic
var cond = ObjectConditional.Empty;
foreach (var check in ext)
{
if (check is WhereExtension extension)
{
cond = extension.Conditional;
break;
}
}
var condIsItem = cond.IsItem;
var condIsMobile = cond.IsMobile;
@ -112,10 +116,14 @@ namespace Server.Commands.Generic
case ObjectTypes.Both:
{
if (condIsItem)
{
items = true;
}
if (condIsMobile)
{
mobiles = true;
}
break;
}
@ -171,7 +179,9 @@ namespace Server.Commands.Generic
public string GenerateArgString(string[] args)
{
if (args.Length == 0)
{
return "";
}
// NOTE: this does not preserve the case where quotation marks are used on a single word
@ -180,7 +190,9 @@ namespace Server.Commands.Generic
for (var i = 0; i < args.Length; ++i)
{
if (i > 0)
{
sb.Append(' ');
}
if (args[i].IndexOf(' ') >= 0)
{
@ -204,16 +216,22 @@ namespace Server.Commands.Generic
var e = new CommandEventArgs(from, command.Commands[0], GenerateArgString(args), args);
if (!command.ValidateArgs(this, e))
{
return;
}
var flushToLog = false;
if (obj is List<object> list)
{
if (list.Count > 20)
{
CommandLogging.Enabled = false;
}
else if (list.Count == 0)
{
command.LogFailure("Nothing was found to use this command on.");
}
command.ExecuteList(e, list);
@ -226,9 +244,13 @@ namespace Server.Commands.Generic
else if (obj != null)
{
if (command.ListOptimized)
{
command.ExecuteList(e, new List<object> { obj });
}
else
{
command.Execute(e, obj);
}
}
command.Flush(from, flushToLog);
@ -264,7 +286,9 @@ namespace Server.Commands.Generic
var args = new string[oldArgs.Length - 1];
for (var i = 0; i < args.Length; ++i)
{
args[i] = oldArgs[i + 1];
}
Process(e.Mobile, command, args);
}
@ -278,10 +302,14 @@ namespace Server.Commands.Generic
public void Register()
{
if (Accessors == null)
{
return;
}
for (var i = 0; i < Accessors.Length; ++i)
{
CommandSystem.Register(Accessors[i], AccessLevel, Execute);
}
}
public static void Register(BaseCommandImplementor impl)

View file

@ -20,13 +20,15 @@ namespace Server.Commands.Generic
public override void Process(Mobile from, BaseCommand command, string[] args)
{
if (command.ValidateArgs(this, new CommandEventArgs(from, command.Commands[0], GenerateArgString(args), args)))
from.BeginTarget(
{
@from.BeginTarget(
-1,
command.ObjectTypes == ObjectTypes.All,
TargetFlags.None,
(m, targeted, a) => OnTarget(m, targeted, command, a),
args
);
}
}
public void OnTarget(Mobile from, object targeted, BaseCommand command, string[] args)
@ -38,7 +40,9 @@ namespace Server.Commands.Generic
}
if (command.ObjectTypes == ObjectTypes.Mobiles)
{
return; // sanity check
}
if (!(targeted is Container cont))
{
@ -51,7 +55,9 @@ namespace Server.Commands.Generic
var ext = Extensions.Parse(from, ref args);
if (!CheckObjectTypes(from, command, ext, out var items, out var _))
{
return;
}
if (!items)
{
@ -62,8 +68,12 @@ namespace Server.Commands.Generic
var list = new List<object>();
foreach (var item in cont.FindItemsByType<Item>())
{
if (ext.IsValid(item))
{
list.Add(item);
}
}
ext.Filter(list);

View file

@ -18,12 +18,16 @@ namespace Server.Commands.Generic
var impl = AreaCommandImplementor.Instance;
if (impl == null)
{
return;
}
var map = from.Map;
if (map == null || map == Map.Internal)
{
return;
}
impl.OnTarget(from, map, Point3D.Zero, new Point3D(map.Width - 1, map.Height - 1, 0), command, args);
}

View file

@ -23,19 +23,33 @@ namespace Server.Commands.Generic
var ext = Extensions.Parse(from, ref args);
if (!CheckObjectTypes(from, command, ext, out var items, out var mobiles))
{
return;
}
var list = new List<object>();
if (items)
{
foreach (var item in World.Items.Values)
{
if (ext.IsValid(item))
{
list.Add(item);
}
}
}
if (mobiles)
{
foreach (var mob in World.Mobiles.Values)
{
if (ext.IsValid(mob))
{
list.Add(mob);
}
}
}
ext.Filter(list);

View file

@ -25,7 +25,9 @@ namespace Server.Commands.Generic
var ext = Extensions.Parse(from, ref args);
if (!CheckObjectTypes(from, command, ext, out var _, out var mobiles))
{
return;
}
if (!mobiles) // sanity check
{

View file

@ -16,13 +16,15 @@ namespace Server.Commands.Generic
public override void Process(Mobile from, BaseCommand command, string[] args)
{
if (command.ValidateArgs(this, new CommandEventArgs(from, command.Commands[0], GenerateArgString(args), args)))
from.BeginTarget(
{
@from.BeginTarget(
-1,
command.ObjectTypes == ObjectTypes.All,
TargetFlags.None,
(m, targeted, a) => OnTarget(m, targeted, command, a),
args
);
}
}
public void OnTarget(Mobile from, object targeted, BaseCommand command, string[] args)

View file

@ -35,13 +35,17 @@ namespace Server.Commands.Generic
m_Conditionals = new IConditional[m_Conditions.Length];
for (var i = 0; i < m_Conditionals.Length; ++i)
{
m_Conditionals[i] = ConditionalCompiler.Compile(emitter, Type, m_Conditions[i], i);
}
}
public bool CheckCondition(object obj)
{
if (Type == null)
{
return true; // null type means no condition
}
if (!HasCompiled)
{
@ -51,8 +55,12 @@ namespace Server.Commands.Generic
}
for (var i = 0; i < m_Conditionals.Length; ++i)
{
if (m_Conditionals[i].Verify(obj))
{
return true;
}
}
return false; // all conditions false
}
@ -62,6 +70,7 @@ namespace Server.Commands.Generic
string[] conditionArgs = null;
for (var i = 0; i < args.Length; ++i)
{
if (Insensitive.Equals(args[i], "where"))
{
var origArgs = args;
@ -69,15 +78,20 @@ namespace Server.Commands.Generic
args = new string[i];
for (var j = 0; j < args.Length; ++j)
{
args[j] = origArgs[j];
}
conditionArgs = new string[origArgs.Length - i - 1];
for (var j = 0; j < conditionArgs.Length; ++j)
{
conditionArgs[j] = origArgs[i + j + 1];
}
break;
}
}
return ParseDirect(from, conditionArgs, 0, conditionArgs?.Length ?? 0);
}
@ -85,14 +99,18 @@ namespace Server.Commands.Generic
public static ObjectConditional ParseDirect(Mobile from, string[] args, int offset, int size)
{
if (args == null || size == 0)
{
return Empty;
}
var index = 0;
var objectType = AssemblyHandler.FindFirstTypeForName(args[offset + index], true);
if (objectType == null)
{
throw new Exception($"No type with that name ({args[offset + index]}) was found.");
}
++index;
@ -113,7 +131,9 @@ namespace Server.Commands.Generic
++index;
if (index >= size)
{
throw new Exception("Improperly formatted object conditional.");
}
}
else if (Insensitive.Equals(cur, "or") || cur == "||")
{
@ -134,13 +154,17 @@ namespace Server.Commands.Generic
index++;
if (index >= size)
{
throw new Exception("Improperly formatted object conditional.");
}
var oper = args[offset + index];
index++;
if (index >= size)
{
throw new Exception("Improperly formatted object conditional.");
}
var val = args[offset + index];
index++;
@ -181,7 +205,9 @@ namespace Server.Commands.Generic
};
if (condition == null)
{
throw new InvalidOperationException($"Unrecognized operator (\"{oper}\").");
}
current.Add(condition);
}

View file

@ -24,7 +24,9 @@ namespace Server.Commands.Generic
var ext = Extensions.Parse(from, ref args);
if (!CheckObjectTypes(from, command, ext, out var _, out var mobiles))
{
return;
}
if (!mobiles) // sanity check
{
@ -42,13 +44,19 @@ namespace Server.Commands.Generic
var mob = ns.Mobile;
if (mob == null)
{
continue;
}
if (!BaseCommand.IsAccessible(from, mob))
{
continue;
}
if (ext.IsValid(mob))
{
list.Add(mob);
}
}
ext.Filter(list);

View file

@ -47,7 +47,9 @@ namespace Server.Commands.Generic
var args = new string[oldArgs.Length - 2];
for (var i = 0; i < args.Length; ++i)
{
args[i] = oldArgs[i + 2];
}
Process(range, e.Mobile, command, args);
}
@ -64,12 +66,16 @@ namespace Server.Commands.Generic
var impl = AreaCommandImplementor.Instance;
if (impl == null)
{
return;
}
var map = from.Map;
if (map == null || map == Map.Internal)
{
return;
}
var start = new Point3D(from.X - range, from.Y - range, from.Z);
var end = new Point3D(from.X + range, from.Y + range, from.Z);

View file

@ -23,7 +23,9 @@ namespace Server.Commands.Generic
var ext = Extensions.Parse(from, ref args);
if (!CheckObjectTypes(from, command, ext, out var _, out var mobiles))
{
return;
}
var reg = from.Region;
@ -34,10 +36,14 @@ namespace Server.Commands.Generic
foreach (var mob in reg.GetMobiles())
{
if (!BaseCommand.IsAccessible(from, mob))
{
continue;
}
if (ext.IsValid(mob))
{
list.Add(mob);
}
}
}
else

View file

@ -14,7 +14,9 @@ namespace Server.Commands.Generic
public override void Compile(Mobile from, BaseCommand command, ref string[] args, ref object obj)
{
if (command.ObjectTypes == ObjectTypes.Items)
{
return; // sanity check
}
obj = from;
}

View file

@ -20,9 +20,13 @@ namespace Server.Commands.Generic
object obj = null;
if (serial.IsItem)
{
obj = World.FindItem(serial);
}
else if (serial.IsMobile)
{
obj = World.FindMobile(serial);
}
if (obj == null)
{
@ -72,7 +76,9 @@ namespace Server.Commands.Generic
var args = new string[oldArgs.Length - 2];
for (var i = 0; i < args.Length; ++i)
{
args[i] = oldArgs[i + 2];
}
RunCommand(e.Mobile, obj, command, args);
}

View file

@ -19,7 +19,9 @@ namespace Server.Commands.Generic
base.Register(command);
for (var i = 0; i < command.Commands.Length; ++i)
{
CommandSystem.Register(command.Commands[i], command.AccessLevel, Redirect);
}
}
public void Redirect(CommandEventArgs e)
@ -27,23 +29,31 @@ namespace Server.Commands.Generic
Commands.TryGetValue(e.Command, out var command);
if (command == null)
{
e.Mobile.SendMessage("That is either an invalid command name or one that does not support this modifier.");
}
else if (e.Mobile.AccessLevel < command.AccessLevel)
{
e.Mobile.SendMessage("You do not have access to that command.");
}
else if (command.ValidateArgs(this, e))
{
Process(e.Mobile, command, e.Arguments);
}
}
public override void Process(Mobile from, BaseCommand command, string[] args)
{
if (command.ValidateArgs(this, new CommandEventArgs(from, command.Commands[0], GenerateArgString(args), args)))
from.BeginTarget(
{
@from.BeginTarget(
-1,
command.ObjectTypes == ObjectTypes.All,
TargetFlags.None,
(m, targeted, a) => OnTarget(m, targeted, command, a),
args
);
}
}
public void OnTarget(Mobile from, object targeted, BaseCommand command, string[] args)