Formatting #2 (#59)

This commit is contained in:
Kamron Batman 2019-10-05 00:37:03 -07:00 committed by GitHub
parent 096d39609e
commit 8e9221bb5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
400 changed files with 3688 additions and 5969 deletions

View file

@ -71,7 +71,6 @@ namespace Server.Commands
private static void CopyProps(Mobile to, Mobile from)
{
foreach (PropertyInfo prop in _mobProps)
{
try
{
prop.SetValue(to, prop.GetValue(from, null), null);
@ -80,7 +79,6 @@ namespace Server.Commands
{
// ignored
}
}
}
}
}
}

View file

@ -185,7 +185,7 @@ namespace Server.Commands
private static void SaveType(TypeInfo info, StreamWriter nsHtml, string nsFileName, string nsName)
{
if (info.m_Declaring == null)
nsHtml.WriteLine(" <!-- DBG-ST -->" + info.LinkName("../types/") + "<br>");
nsHtml.WriteLine($" <!-- DBG-ST -->{info.LinkName("../types/")}<br>");
using StreamWriter typeHtml = GetWriter(info.FileName);
typeHtml.WriteLine("<html>");
@ -220,11 +220,11 @@ namespace Server.Commands
string rootType = type.Name.Substring(0, index);
StringBuilder nameBuilder = new StringBuilder(rootType);
StringBuilder fnamBuilder = new StringBuilder("docs/types/" + SanitizeType(rootType));
StringBuilder fnamBuilder = new StringBuilder($"docs/types/{SanitizeType(rootType)}");
StringBuilder linkBuilder;
linkBuilder = DontLink(type) ?
new StringBuilder("<font color=\"blue\">" + rootType + "</font>") :
new StringBuilder("<a href=\"" + "@directory@" + rootType + "-T-.html\">" + rootType + "</a>");
new StringBuilder($"<font color=\"blue\">{rootType}</font>") :
new StringBuilder($"<a href=\"@directory@{rootType}-T-.html\">{rootType}</a>");
nameBuilder.Append("&lt;");
fnamBuilder.Append("-");
@ -247,10 +247,10 @@ namespace Server.Commands
nameBuilder.Append(sanitizedName);
fnamBuilder.Append("T");
if (DontLink(typeArguments[i])) //if ( DontLink( typeArguments[i].Name ) )
linkBuilder.Append("<font color=\"blue\">" + aliasedName + "</font>");
linkBuilder.Append($"<font color=\"blue\">{aliasedName}</font>");
else
linkBuilder.Append(
"<a href=\"" + "@directory@" + aliasedName + ".html\">" + aliasedName + "</a>");
$"<a href=\"@directory@{aliasedName}.html\">{aliasedName}</a>");
}
nameBuilder.Append("&gt;");
@ -265,16 +265,15 @@ namespace Server.Commands
typeName = name ?? type.Name;
if (fnam == null) fileName = "docs/types/" + SanitizeType(type.Name) + ".html";
else fileName = fnam + ".html";
if (fnam == null) fileName = $"docs/types/{SanitizeType(type.Name)}.html";
else fileName = $"{fnam}.html";
if (link == null)
{
if (DontLink(type)) //if ( DontLink( type.Name ) )
linkName = "<font color=\"blue\">" + SanitizeType(type.Name) + "</font>";
linkName = $"<font color=\"blue\">{SanitizeType(type.Name)}</font>";
else
linkName = "<a href=\"" + "@directory@" + SanitizeType(type.Name) + ".html\">" +
SanitizeType(type.Name) + "</a>";
linkName = $"<a href=\"@directory@{SanitizeType(type.Name)}.html\">{SanitizeType(type.Name)}</a>";
}
else
{
@ -291,7 +290,7 @@ namespace Server.Commands
for (int i = 0; i < ReplaceChars.Length; ++i)
sb.Replace(ReplaceChars[i], '-');
if (anonymousType) return "(Anonymous-Type)" + sb;
if (anonymousType) return $"(Anonymous-Type){sb}";
return sb.ToString();
}
@ -1818,8 +1817,8 @@ namespace Server.Commands
while (bin.PeekChar() >= 0)
{
int index = (bin.ReadByte() << 8) | bin.ReadByte();
int length = (bin.ReadByte() << 8) | bin.ReadByte();
int index = bin.ReadByte() << 8 | bin.ReadByte();
int length = bin.ReadByte() << 8 | bin.ReadByte();
string text = Encoding.UTF8.GetString(bin.ReadBytes(length)).Trim();
if (text.Length == 0)
@ -2156,10 +2155,7 @@ namespace Server.Commands
for (int j = 0; !anyConstructible && j < ctors.Length; ++j)
anyConstructible = IsConstructible(ctors[j]);
if (anyConstructible)
{
(isItem ? items : mobiles).Add((t, ctors));
}
if (anyConstructible) (isItem ? items : mobiles).Add((t, ctors));
}
using StreamWriter html = GetWriter("docs/", "objects.html");
@ -2418,7 +2414,7 @@ namespace Server.Commands
if (baseInfo == null)
typeHtml.Write(baseType.Name);
else
typeHtml.Write("<!-- DBG-1 -->" + baseInfo.LinkName(null));
typeHtml.Write($"<!-- DBG-1 -->{baseInfo.LinkName(null)}");
++extendCount;
}
@ -2445,7 +2441,7 @@ namespace Server.Commands
}
else
{
typeHtml.Write("<!-- DBG-2.2 -->" + ifaceInfo.LinkName(null));
typeHtml.Write($"<!-- DBG-2.2 -->{ifaceInfo.LinkName(null)}");
}
}
}
@ -2468,7 +2464,7 @@ namespace Server.Commands
typeHtml.Write(", ");
//typeHtml.Write( "<a href=\"{0}\">{1}</a>", derivedInfo.m_FileName, derivedInfo.m_TypeName );
typeHtml.Write("<!-- DBG-3 -->" + derivedInfo.LinkName(null));
typeHtml.Write($"<!-- DBG-3 -->{derivedInfo.LinkName(null)}");
}
typeHtml.WriteLine("</h4>");
@ -2490,7 +2486,7 @@ namespace Server.Commands
typeHtml.Write(", ");
//typeHtml.Write( "<a href=\"{0}\">{1}</a>", nestedInfo.m_FileName, nestedInfo.m_TypeName );
typeHtml.Write("<!-- DBG-4 -->" + nestedInfo.LinkName(null));
typeHtml.Write($"<!-- DBG-4 -->{nestedInfo.LinkName(null)}");
}
typeHtml.WriteLine("</h4>");

View file

@ -250,20 +250,20 @@ namespace Server.Commands
}
public class CategoryTypeSorter : IComparer<CategoryTypeEntry>
{
public int Compare(CategoryTypeEntry x, CategoryTypeEntry y)
{
public int Compare(CategoryTypeEntry x, CategoryTypeEntry y)
{
string a = x?.Type.Name;
string b = y?.Type.Name;
string a = x?.Type.Name;
string b = y?.Type.Name;
if (a == null && b == null)
return 0;
if (a == null && b == null)
return 0;
if (a == null)
return 1;
if (a == null)
return 1;
return a.CompareTo(b);
}
return a.CompareTo(b);
}
}
public class CategoryTypeEntry

View file

@ -229,7 +229,7 @@ namespace Server.Commands.Generic
public override void Construct(TypeBuilder typeBuilder, ILGenerator il, int index)
{
m_Value.Acquire(typeBuilder, il, "v" + index);
m_Value.Acquire(typeBuilder, il, $"v{index}");
}
public override void Compile(MethodEmitter emitter)
@ -358,7 +358,7 @@ namespace Server.Commands.Generic
public override void Construct(TypeBuilder typeBuilder, ILGenerator il, int index)
{
m_Value.Acquire(typeBuilder, il, "v" + index);
m_Value.Acquire(typeBuilder, il, $"v{index}");
}
public override void Compile(MethodEmitter emitter)
@ -446,7 +446,7 @@ namespace Server.Commands.Generic
public static IConditional Compile(AssemblyEmitter assembly, Type objectType, ICondition[] conditions, int index)
{
TypeBuilder typeBuilder = assembly.DefineType(
"__conditional" + index,
$"__conditional{index}",
TypeAttributes.Public,
typeof(object)
);

View file

@ -57,10 +57,8 @@ namespace Server.Commands.Generic
List<object> list = new List<object>();
foreach (Item item in cont.FindItemsByType<Item>())
{
if (ext.IsValid(item))
list.Add(item);
}
ext.Filter(list);

View file

@ -151,89 +151,35 @@ namespace Server.Commands.Generic
prop.BindTo(objectType, PropertyAccess.Read);
prop.CheckAccess(from);
ICondition condition = null;
switch (oper)
var condition = oper switch
{
#region Equality
case "=":
case "==":
case "is":
condition = new ComparisonCondition(prop, inverse, ComparisonOperator.Equal, val);
break;
case "!=":
condition = new ComparisonCondition(prop, inverse, ComparisonOperator.NotEqual, val);
break;
#endregion
#region Relational
case ">":
condition = new ComparisonCondition(prop, inverse, ComparisonOperator.Greater, val);
break;
case "<":
condition = new ComparisonCondition(prop, inverse, ComparisonOperator.Lesser, val);
break;
case ">=":
condition = new ComparisonCondition(prop, inverse, ComparisonOperator.GreaterEqual, val);
break;
case "<=":
condition = new ComparisonCondition(prop, inverse, ComparisonOperator.LesserEqual, val);
break;
#endregion
#region Strings
case "==~":
case "~==":
case "=~":
case "~=":
case "is~":
case "~is":
condition = new StringCondition(prop, inverse, StringOperator.Equal, val, true);
break;
case "!=~":
case "~!=":
condition = new StringCondition(prop, inverse, StringOperator.NotEqual, val, true);
break;
case "starts":
condition = new StringCondition(prop, inverse, StringOperator.StartsWith, val, false);
break;
case "starts~":
case "~starts":
condition = new StringCondition(prop, inverse, StringOperator.StartsWith, val, true);
break;
case "ends":
condition = new StringCondition(prop, inverse, StringOperator.EndsWith, val, false);
break;
case "ends~":
case "~ends":
condition = new StringCondition(prop, inverse, StringOperator.EndsWith, val, true);
break;
case "contains":
condition = new StringCondition(prop, inverse, StringOperator.Contains, val, false);
break;
case "contains~":
case "~contains":
condition = new StringCondition(prop, inverse, StringOperator.Contains, val, true);
break;
#endregion
}
"=" => (ICondition)new ComparisonCondition(prop, inverse, ComparisonOperator.Equal, val),
"==" => new ComparisonCondition(prop, inverse, ComparisonOperator.Equal, val),
"is" => new ComparisonCondition(prop, inverse, ComparisonOperator.Equal, val),
"!=" => new ComparisonCondition(prop, inverse, ComparisonOperator.NotEqual, val),
">" => new ComparisonCondition(prop, inverse, ComparisonOperator.Greater, val),
"<" => new ComparisonCondition(prop, inverse, ComparisonOperator.Lesser, val),
">=" => new ComparisonCondition(prop, inverse, ComparisonOperator.GreaterEqual, val),
"<=" => new ComparisonCondition(prop, inverse, ComparisonOperator.LesserEqual, val),
"==~" => new StringCondition(prop, inverse, StringOperator.Equal, val, true),
"~==" => new StringCondition(prop, inverse, StringOperator.Equal, val, true),
"=~" => new StringCondition(prop, inverse, StringOperator.Equal, val, true),
"~=" => new StringCondition(prop, inverse, StringOperator.Equal, val, true),
"is~" => new StringCondition(prop, inverse, StringOperator.Equal, val, true),
"~is" => new StringCondition(prop, inverse, StringOperator.Equal, val, true),
"!=~" => new StringCondition(prop, inverse, StringOperator.NotEqual, val, true),
"~!=" => new StringCondition(prop, inverse, StringOperator.NotEqual, val, true),
"starts" => new StringCondition(prop, inverse, StringOperator.StartsWith, val, false),
"starts~" => new StringCondition(prop, inverse, StringOperator.StartsWith, val, true),
"~starts" => new StringCondition(prop, inverse, StringOperator.StartsWith, val, true),
"ends" => new StringCondition(prop, inverse, StringOperator.EndsWith, val, false),
"ends~" => new StringCondition(prop, inverse, StringOperator.EndsWith, val, true),
"~ends" => new StringCondition(prop, inverse, StringOperator.EndsWith, val, true),
"contains" => new StringCondition(prop, inverse, StringOperator.Contains, val, false),
"contains~" => new StringCondition(prop, inverse, StringOperator.Contains, val, true),
"~contains" => new StringCondition(prop, inverse, StringOperator.Contains, val, true),
_ => null
};
if (condition == null)
throw new InvalidOperationException($"Unrecognized operator (\"{oper}\").");

View file

@ -45,16 +45,6 @@ namespace Server.Commands.Generic
{
switch (command.ObjectTypes)
{
// case ObjectTypes.Both:
// {
// if (!(obj is Item) && !(obj is Mobile))
// {
// e.Mobile.SendMessage("This command does not work on that.");
// return;
// }
//
// break;
// }
case ObjectTypes.Items:
{
if (!(obj is Item))
@ -93,4 +83,4 @@ namespace Server.Commands.Generic
}
}
}
}
}

View file

@ -125,7 +125,7 @@ namespace Server.Commands
while (reg != null)
{
builder.Append(" <- " + reg);
builder.Append($" <- {reg}");
reg = reg.Parent;
}

View file

@ -82,7 +82,7 @@ namespace Server.Commands
path = Path.Combine(path, $"{name}.log");
using StreamWriter sw = new StreamWriter(path, true);
sw.WriteLine("{0}: {1}: {2}", DateTime.UtcNow, @from.NetState, text);
sw.WriteLine("{0}: {1}: {2}", DateTime.UtcNow, from.NetState, text);
}
catch
{
@ -136,4 +136,4 @@ namespace Server.Commands
value);
}
}
}
}

View file

@ -27,7 +27,7 @@ namespace Server.Commands
{
using StreamWriter sw = new StreamWriter("profiles.log", true);
sw.WriteLine("# Dump on {0:f}", DateTime.UtcNow);
sw.WriteLine("# Core profiling for " + Core.ProfileTime);
sw.WriteLine($"# Core profiling for {Core.ProfileTime}");
sw.WriteLine("# Packet send");
BaseProfile.WriteAll(sw, PacketSendProfile.Profiles);

View file

@ -457,7 +457,7 @@ namespace Server.Commands
if (shouldLog)
CommandLogging.LogChangeProperty(from, logObject, givenName,
toSet == null ? "(-null-)" : toSet.ToString());
toSet?.ToString() ?? "(-null-)");
prop.SetValue(obj, toSet, null);
return "Property has been set.";

View file

@ -57,29 +57,17 @@ namespace Server.Commands
for (int i = 0; i < list.Count; ++i)
{
SignEntry e = list[i];
Map[] maps = null;
switch (e.m_Map)
var maps = e.m_Map switch
{
case 0:
maps = brit;
break; // Trammel and Felucca
case 1:
maps = fel;
break; // Felucca
case 2:
maps = tram;
break; // Trammel
case 3:
maps = ilsh;
break; // Ilshenar
case 4:
maps = malas;
break; // Malas
case 5:
maps = tokuno;
break; // Tokuno Islands
}
0 => brit,
1 => fel,
2 => tram,
3 => ilsh,
4 => malas,
5 => tokuno,
_ => null
};
for (int j = 0; maps?.Length >= j; ++j)
Add_Static(e.m_ItemID, e.m_Location, maps[j], e.m_Text);

View file

@ -536,9 +536,9 @@ namespace Server
int index = 0;
for (int i = 0; i < count; ++i)
staTiles[i].Set((ushort)(m_Buffer[index++] | (m_Buffer[index++] << 8)),
staTiles[i].Set((ushort)(m_Buffer[index++] | m_Buffer[index++] << 8),
m_Buffer[index++], m_Buffer[index++], (sbyte)m_Buffer[index++],
(short)(m_Buffer[index++] | (m_Buffer[index++] << 8)));
(short)(m_Buffer[index++] | m_Buffer[index++] << 8));
}
}
catch