Clean up: Bugs, LINQ, constructors, default values, and null checks (#18)

This commit is contained in:
Kamron Batman 2019-03-11 14:29:59 -07:00 • committed by GitHub
parent e748af4430
commit 513e54f70e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
1094 changed files with 15913 additions and 21892 deletions

View file

@ -19,7 +19,6 @@
***************************************************************************/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
@ -132,10 +131,7 @@ namespace Server
public static string Intern(string str)
{
if (str == null)
return null;
return str.Length == 0 ? string.Empty : string.Intern(str);
return str == null ? null : str.Length == 0 ? string.Empty : string.Intern(str);
}
public static void Intern(ref string str)
@ -501,7 +497,7 @@ namespace Server
}
else
{
valid = false; //high & lowpart would be 0 if it got to here.
valid = false; //high & lowp art would be 0 if it got to here.
}
}
}
@ -560,9 +556,7 @@ namespace Server
return Direction.Right;
}
if (dy > 0)
return Direction.Left;
return Direction.Up;
return dy > 0 ? Direction.Left : Direction.Up;
}
/* Should probably be rewritten to use an ITile interface
@ -614,12 +608,7 @@ namespace Server
}
*/
public static object GetArrayCap(Array array, int index)
{
return GetArrayCap(array, index, null);
}
public static object GetArrayCap(Array array, int index, object emptyValue)
public static object GetArrayCap(Array array, int index, object emptyValue = null)
{
if (array.Length > 0)
{
@ -791,18 +780,13 @@ namespace Server
return num < bound2 + allowance && num > bound1 - allowance;
}
public static void AssignRandomHair(Mobile m)
{
AssignRandomHair(m, true);
}
public static void AssignRandomHair(Mobile m, int hue)
{
m.HairItemID = m.Race.RandomHair(m);
m.HairHue = hue;
}
public static void AssignRandomHair(Mobile m, bool randomHue)
public static void AssignRandomHair(Mobile m, bool randomHue = true)
{
m.HairItemID = m.Race.RandomHair(m);
@ -810,18 +794,13 @@ namespace Server
m.HairHue = m.Race.RandomHairHue();
}
public static void AssignRandomFacialHair(Mobile m)
{
AssignRandomFacialHair(m, true);
}
public static void AssignRandomFacialHair(Mobile m, int hue)
{
m.FacialHairItemID = m.Race.RandomFacialHair(m);
m.FacialHairHue = hue;
}
public static void AssignRandomFacialHair(Mobile m, bool randomHue)
public static void AssignRandomFacialHair(Mobile m, bool randomHue = true)
{
m.FacialHairItemID = m.Race.RandomFacialHair(m);
@ -979,12 +958,7 @@ namespace Server
public static string GetAttribute(XmlElement node, string attributeName, string defaultValue = null)
{
if (node == null)
return defaultValue;
XmlAttribute attr = node.Attributes[attributeName];
return attr == null ? defaultValue : attr.Value;
return node?.Attributes[attributeName]?.Value ?? defaultValue;
}
public static string GetText(XmlElement node, string defaultValue)
@ -1237,9 +1211,8 @@ namespace Server
{
if (hue < 2)
return 2;
if (hue > 1001)
return 1001;
return hue;
return hue > 1001 ? 1001 : hue;
}
/// <summary>
@ -1255,10 +1228,8 @@ namespace Server
/// </summary>
public static int RandomBrightHue()
{
if (RandomDouble() < 0.1)
return RandomList(0x62, 0x71);
return RandomList(0x03, 0x0D, 0x13, 0x1C, 0x21, 0x30, 0x37, 0x3A, 0x44, 0x59);
return RandomDouble() < 0.1 ? RandomList(0x62, 0x71) :
RandomList(0x03, 0x0D, 0x13, 0x1C, 0x21, 0x30, 0x37, 0x3A, 0x44, 0x59);
}
#endregion